2019-pracownia-programowani.../Lookify/app/src/main/java/com/example/lookifyv2/MainActivity.java

97 lines
3.5 KiB
Java
Raw Normal View History

package com.example.lookifyv2;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
2019-12-04 23:05:33 +01:00
public class MainActivity extends AppCompatActivity {
2019-12-04 23:05:33 +01:00
Button button_scan;
Button button_help;
Button button_about;
Button button_favourites;
2019-12-04 23:05:33 +01:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button_scan = findViewById(R.id.scan_start_button);
button_scan.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_help = findViewById(R.id.help_start_button);
button_help.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_about = findViewById(R.id.about_start_button);
button_about.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_favourites = findViewById(R.id.favourites_start_button);
button_favourites.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
button_scan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openScan();
}
});
button_help.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openHelp();
}
});
button_about.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openAbout();
}
});
button_favourites.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openFavourites();
}
});
//Dezaktywacja przycisku skanowania, jeśli nie ma dostępu do kamery; żądanie dostępu do kamery i zapisu.
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
button_scan.setEnabled(false);
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
}
2019-12-04 23:05:33 +01:00
}
//Aktywacja przycisku skanowania, jeśli uprawnienia zostały przyznane.
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 0) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
button_scan.setEnabled(true);
}
}
2019-12-04 23:05:33 +01:00
}
private void openHelp(){
Intent intent_Help = new Intent(this, Help.class);
startActivity(intent_Help);
2019-12-04 23:05:33 +01:00
}
private void openAbout(){
Intent intent_About = new Intent(this, About.class);
startActivity(intent_About);
}
private void openScan(){
Intent intent_Scan = new Intent(this, TakePhoto.class);
startActivity(intent_Scan);
}
private void openFavourites(){
Intent intent_Favourites = new Intent(this, Favourites.class);
startActivity(intent_Favourites);
}
}