2019-12-19 23:15:02 +01:00
|
|
|
package com.example.lookifyv2;
|
|
|
|
import android.Manifest;
|
2019-12-06 00:23:53 +01:00
|
|
|
import android.content.Intent;
|
2019-12-19 23:15:02 +01:00
|
|
|
import android.content.pm.PackageManager;
|
2020-02-23 00:20:49 +01:00
|
|
|
import android.graphics.PorterDuff;
|
2019-12-06 00:23:53 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
2019-12-19 23:15:02 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
2019-12-04 23:05:33 +01:00
|
|
|
|
2019-12-06 00:23:53 +01:00
|
|
|
public class MainActivity extends AppCompatActivity {
|
2019-12-04 23:05:33 +01:00
|
|
|
|
2020-02-17 00:04:13 +01:00
|
|
|
Button button_scan;
|
|
|
|
Button button_help;
|
|
|
|
Button button_about;
|
2020-02-23 00:20:49 +01:00
|
|
|
Button button_favourites;
|
2020-02-14 23:22:23 +01:00
|
|
|
|
2019-12-04 23:05:33 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
2019-12-19 23:15:02 +01:00
|
|
|
button_scan = findViewById(R.id.scan_start_button);
|
2020-02-23 00:20:49 +01:00
|
|
|
button_scan.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
|
2019-12-06 00:23:53 +01:00
|
|
|
button_help = findViewById(R.id.help_start_button);
|
2020-02-23 00:20:49 +01:00
|
|
|
button_help.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
|
2019-12-06 00:23:53 +01:00
|
|
|
button_about = findViewById(R.id.about_start_button);
|
2020-02-23 00:20:49 +01:00
|
|
|
button_about.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
|
|
|
|
button_favourites = findViewById(R.id.favourites_start_button);
|
|
|
|
button_favourites.getBackground().setColorFilter(0xFF67BAFF, PorterDuff.Mode.MULTIPLY);
|
2020-02-14 23:22:23 +01:00
|
|
|
|
2019-12-06 00:23:53 +01:00
|
|
|
button_scan.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-12-19 23:15:02 +01:00
|
|
|
openScan();
|
2019-12-06 00:23:53 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2020-02-23 00:20:49 +01:00
|
|
|
button_favourites.setOnClickListener(new View.OnClickListener() {
|
2020-02-14 23:22:23 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2020-02-23 00:20:49 +01:00
|
|
|
openFavourites();
|
2020-02-14 23:22:23 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-20 00:58:53 +02:00
|
|
|
//Dezaktywacja przycisku skanowania, jeśli nie ma dostępu do kamery; żądanie dostępu do kamery i zapisu.
|
2019-12-19 23:15:02 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-06-20 00:58:53 +02:00
|
|
|
//Aktywacja przycisku skanowania, jeśli uprawnienia zostały przyznane.
|
2019-12-19 23:15:02 +01:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2020-06-20 00:58:53 +02:00
|
|
|
private void openHelp(){
|
2019-12-06 00:23:53 +01:00
|
|
|
Intent intent_Help = new Intent(this, Help.class);
|
|
|
|
startActivity(intent_Help);
|
2019-12-04 23:05:33 +01:00
|
|
|
}
|
|
|
|
|
2020-06-20 00:58:53 +02:00
|
|
|
private void openAbout(){
|
2019-12-06 00:23:53 +01:00
|
|
|
Intent intent_About = new Intent(this, About.class);
|
|
|
|
startActivity(intent_About);
|
|
|
|
}
|
|
|
|
|
2020-06-20 00:58:53 +02:00
|
|
|
private void openScan(){
|
2019-12-27 21:54:37 +01:00
|
|
|
Intent intent_Scan = new Intent(this, TakePhoto.class);
|
2019-12-19 23:15:02 +01:00
|
|
|
startActivity(intent_Scan);
|
|
|
|
}
|
2020-02-14 23:22:23 +01:00
|
|
|
|
2020-06-20 00:58:53 +02:00
|
|
|
private void openFavourites(){
|
2020-02-23 00:20:49 +01:00
|
|
|
Intent intent_Favourites = new Intent(this, Favourites.class);
|
|
|
|
startActivity(intent_Favourites);
|
2020-02-14 23:22:23 +01:00
|
|
|
}
|
2019-12-19 23:15:02 +01:00
|
|
|
}
|