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;
|
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;
|
2019-12-04 23:05:33 +01:00
|
|
|
|
2020-02-17 00:04:13 +01:00
|
|
|
Button button_results;
|
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);
|
2019-12-06 00:23:53 +01:00
|
|
|
button_help = findViewById(R.id.help_start_button);
|
|
|
|
button_about = findViewById(R.id.about_start_button);
|
2019-12-04 23:05:33 +01:00
|
|
|
|
2020-02-14 23:22:23 +01:00
|
|
|
button_results = findViewById(R.id.results_start_button);
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2019-12-19 23:15:02 +01:00
|
|
|
|
2020-02-14 23:22:23 +01:00
|
|
|
button_results.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
openResults();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-19 23:15:02 +01:00
|
|
|
//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
|
|
|
}
|
|
|
|
|
2019-12-19 23:15:02 +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
|
|
|
}
|
|
|
|
|
2019-12-06 00:23:53 +01:00
|
|
|
public void openHelp(){
|
|
|
|
Intent intent_Help = new Intent(this, Help.class);
|
|
|
|
startActivity(intent_Help);
|
2019-12-04 23:05:33 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 00:23:53 +01:00
|
|
|
public void openAbout(){
|
|
|
|
Intent intent_About = new Intent(this, About.class);
|
|
|
|
startActivity(intent_About);
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:15:02 +01:00
|
|
|
public 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
|
|
|
|
|
|
|
public void openResults(){
|
|
|
|
Intent intent_Results = new Intent(this, Results.class);
|
|
|
|
startActivity(intent_Results);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-19 23:15:02 +01:00
|
|
|
}
|