Commit f6f7b79f authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Remove a lot of useless classes and files

parent b486aa46
package com.example.qrquest;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;
public class FirstFragment extends Fragment {
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState
) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first, container, false);
}
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NavHostFragment.findNavController(FirstFragment.this)
.navigate(R.id.action_FirstFragment_to_SecondFragment);
}
});
}
}
......@@ -9,13 +9,11 @@ import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import com.example.qrquest.QR.handling.QRCodeDefaultDetectionModeStrategy;
import com.example.qrquest.QR.handling.QRCodeDetectionModeStrategy;
import com.example.qrquest.QR.handling.QRCodeBuilder;
import com.example.qrquest.QR.model.QRCode;
import com.example.qrquest.QR.model.QRCodeCollection;
import com.example.qrquest.QR.model.QRContent;
import com.example.qrquest.QR.model.QRText;
import com.example.qrquest.utils.OnSwipeTouchListener;
import com.example.qrquest.exceptions.UnhandledQRException;
import com.example.qrquest.exceptions.UnsupportedQRException;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.vision.CameraSource;
import com.google.android.gms.vision.Detector;
......@@ -32,12 +30,12 @@ import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.util.SparseArray;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
......@@ -60,25 +58,6 @@ public class MainActivity extends AppCompatActivity {
private final int CAMERA_DETECTING_STATE = 40;
private int m_detectionProgress;
public final static int NO_QR_DETECTED = 50;
public final static int FIRST_QR_DETECTED = 60;
public final static int MULTIPLE_QR_DETECTED = 100;
private boolean m_isApplicationDetecting;
private boolean m_marshmallowOrHigher;
private boolean m_lollipopOrHigher;
private QRCodeCollection m_detectedQRCodes;
/**
* List of the current QRContent (url or text) which have been extracted from the detected QRCodes
*/
private List<QRContent> m_currentReading;
/**
* Strategy in charge of the behaviour of detecting the QRCodes, starting the reading and handling the user actions
* It depends on the type of QRCodes that the user is currently detecting
*/
private QRCodeDetectionModeStrategy m_currentDetectionModeStrategy;
/**
* Current position in m_currentReading
*/
private int m_currentPos;
/**
* The main layout where all happens
*/
......@@ -98,7 +77,7 @@ public class MainActivity extends AppCompatActivity {
}
});
// from QRLudo
m_gga = GoogleApiAvailability.getInstance();
int status = m_gga.isGooglePlayServicesAvailable(getApplicationContext());
if(status != ConnectionResult.SUCCESS) {
......@@ -107,23 +86,37 @@ public class MainActivity extends AppCompatActivity {
errorDia.show();
}
initializeAttributes();
setUpDetector();
initializeListeners();
}
// From QRLudo
/**
* Starts the detection of new QRCodes
*/
private void startDetection() {
if(savedInstanceState != null) {
cameraState = savedInstanceState.getInt("STATE");
switch (cameraState) {
case CAMERA_DETECTING_STATE: {
startDetection();
break;
}
final AppCompatActivity activity = this;
activity.runOnUiThread(new Runnable() {
public void run() {
m_cameraView.setVisibility(View.VISIBLE);
}
}
initializeListeners();
// end of from QRLudo
});
}
private void initializeAttributes() {
m_cameraView = (SurfaceView) findViewById(R.id.camera_view);
m_cameraView.setVisibility(View.INVISIBLE);
PackageManager manager = getPackageManager();
m_mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
cameraState = CAMERA_INACTIVE_STATE;
m_detectionProgress = NO_QR_DETECTED;
}
//setRecognitionListener(android.speech.RecognitionListener)
private void initializeListeners() {
FloatingActionButton photo = findViewById(R.id.photo);
// Should open camera to take a picture of a QR code
FloatingActionButton photo = findViewById(R.id.photo);
// Should open camera to take a picture of a QR code
photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......@@ -167,69 +160,6 @@ public class MainActivity extends AppCompatActivity {
});
}
// From QRLudo
/**
* Starts the detection of new QRCodes
*/
private void startDetection() {
final AppCompatActivity activity = this;
activity.runOnUiThread(new Runnable() {
public void run() {
if(true /*m_ttsready*/) {
m_cameraView.setVisibility(View.VISIBLE);
m_isApplicationDetecting = true;
}else{
cameraState = CAMERA_DETECTING_STATE;
}
}
});
}
private void initializeAttributes() {
m_cameraView = (SurfaceView) findViewById(R.id.camera_view);
m_cameraView.setVisibility(View.INVISIBLE);
PackageManager manager = getPackageManager();
m_mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
cameraState = CAMERA_INACTIVE_STATE;
m_detectionProgress = NO_QR_DETECTED;
m_marshmallowOrHigher = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M;
m_lollipopOrHigher = android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ;
m_detectedQRCodes = new QRCodeCollection();
m_currentReading = new ArrayList<>();
m_currentDetectionModeStrategy = new QRCodeDefaultDetectionModeStrategy(this);
setUpDetector();
}
private void initializeListeners() {
m_mainLayout.setOnTouchListener(new OnSwipeTouchListener(MainActivity.this) {
/**
* Relying on m_currentDetectionModeStrategy to manage the swipe top
*/
public void onSwipeTop() {
m_currentDetectionModeStrategy.onSwipeTop();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
......@@ -291,6 +221,15 @@ public class MainActivity extends AppCompatActivity {
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
}
public void SetQRContent(String qr_result) // to display listening results
{
//end detection
m_cameraView.setVisibility(View.INVISIBLE);
Log.d("Debug", "QR content (from main activity): " + qr_result);
Toast.makeText(getApplicationContext(), qr_result, Toast.LENGTH_LONG).show();
}
private void requestRecordAudioPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String requiredPermission = Manifest.permission.RECORD_AUDIO;
......@@ -315,21 +254,6 @@ public class MainActivity extends AppCompatActivity {
}
}
/**
* Unregisters the MainActivity as a listener of the current QRFile if necessary
* Called when the user swipes right or left
*/
public void unregisterToQRFile(){
QRContent currentContent = m_currentReading.get(m_currentPos);
// if (currentContent != null && currentContent instanceof QRFile){
// ((QRFile) currentContent).unregisterAsDownloadListener();
//}
}
private void setUpDetector() {
requestPhotoPermission();
/*
......@@ -339,14 +263,11 @@ public class MainActivity extends AppCompatActivity {
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if (!detector.isOperational()) {
Log.e("DETECTOR","Could not set up detector.");
return;
}
m_cameraSource = new CameraSource
.Builder(this, detector)
.setRequestedPreviewSize(640, 480)
......@@ -394,8 +315,7 @@ public class MainActivity extends AppCompatActivity {
}
}
});
/*
The processor of the detector, where the events from the detector are handled
*/
......@@ -411,172 +331,51 @@ public class MainActivity extends AppCompatActivity {
* @param detections
*/
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
public void receiveDetections(Detector.Detections<Barcode> detections) { // no usages found in QRLudo, called by API
//Log.d("Debug", "receiveDetections() called");
final SparseArray<Barcode> barcodes = detections.getDetectedItems();
if (barcodes.size() != 0)
{
if(barcodes.size() == 1) Log.d("Debug", "one barcode detected");
else Log.d("Debug", "several barcodes detected");
String rawValue = barcodes.valueAt(0).rawValue;
//ignoring if the QRCode has already been recorded or ignored
try {
QRCode detectedQR = QRCodeBuilder.build(rawValue);
// SetQRContent(rawValue);
listQR.add(detectedQR);
} catch (UnhandledQRException e) {
Log.d("Debug", "QR code non pris en charge");
} catch (UnsupportedQRException e) {
Log.d("Debug", "QR code non pris en charge");
}
}
}
};
detector.setProcessor(detector_processor);
}
/**
* Called when a single QRCode has been detected.
* Reads the first content of the QRCode and allows the user to hear the others content by swiping the screen
*/
public void singleReading(){
//Getting the first detected QRCode only
m_currentReading = m_detectedQRCodes.getContentFirstQR();
readCurrentContent();
}
/**
* Called in case of multiple reading of QR Codes which don't belong to a family
* Also called during a family reading if QRCodes not belonging to a family have been detected first
* In those cases, a QR code is already printed/told
*/
public void classicMultipleReading(){
//Fetching the content of all the detected QR but the first because it has already been read by singleReading()
m_currentReading.addAll(m_detectedQRCodes.getContentAllQRButFirst());
}
/**
* Called in case of detection of QRCodeEnsemble
* Can be called by QRCodeEnsemble at the end of a multiple detection or by the MultipleDetectionTimer if only one QRCodeEnsemble has been detected
*/
/**
* Detects the type of the current content and calls the methods adequately
* If the current content is a QRFile, tests if it has already been downloaded. If not, waits for it
*/
public void readCurrentContent(){
QRContent currentContent = m_currentReading.get(m_currentPos);
if (currentContent instanceof QRText){
// sayTextContent();
}
// else if (currentContent instanceof QRFile){
//If the file is already downloaded, playing the m_mediaPlayer
// if (((QRFile) currentContent).isFileInMemory()){
// playCurrentSoundFromFile();
// }
//The file is not downloaded
else {
/*
//Registering as listener of the QRFile. The method onQRFileDownloadComplete() will then be called when the downloading is over.
((QRFile) currentContent).registerAsDownloadListener(this);
if (isOnline()) {
toSpeech("Téléchargement en cours", TextToSpeech.QUEUE_ADD);
} else {
toSpeech("Pas de connexion internet, téléchargement impossible.", TextToSpeech.QUEUE_ADD);
}
*/
// }
}
}
public void readAllContent(){
for(m_currentPos = 0; m_currentPos<m_currentReading.size();m_currentPos++){
readCurrentContent();
}
}
/**
* Plays the current QRFile
*/
public void playCurrentSoundFromFile(){
Log.i("%%%%APRESTELECHARGEMENT", "Lecture directe du fichier");
QRContent currentContent = m_currentReading.get(m_currentPos);
// if (currentContent instanceof QRFile) {
//If the file is already downloaded, playing the m_mediaPlayer
// if (((QRFile) currentContent).isFileInMemory()) {
// String pathToFile = ((QRFile) currentContent).getDownloadedFilePath();
/*
try {
m_mediaPlayer.stop();
m_mediaPlayer = new MediaPlayer();
m_mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
m_mediaPlayer.setDataSource(pathToFile);
m_mediaPlayer.prepare();
m_mediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}*/
// }
// }
}
/**
* Stops the detection : the application is no longer trying to detect QRCodes
* The cameraView becomes white
*/
public void stopDetection() {
// ToneGeneratorSingleton.getInstance().endOfDetectionTone();
final AppCompatActivity activity = this;
activity.runOnUiThread(new Runnable() {
public void run() {
if(true/*m_ttsready*/) {
m_cameraView.setVisibility(View.INVISIBLE);
m_isApplicationDetecting = false;
}else{
cameraState = CAMERA_INACTIVE_STATE;
}
}
});
}
/* ************************************************************************************** */
/* Getters and setters of the fields. Used by the subclasses of QRCodeDetectionModeStrategy */
/* ************************************************************************************** */
public void setDetectionProgress(int state){
m_detectionProgress = state;
}
public int getDetectionProgress(){
return m_detectionProgress;
}
public QRCodeCollection getDetectedQRCodes(){
return m_detectedQRCodes;
}
public void setDetectionStrategy(QRCodeDetectionModeStrategy strategy){
m_currentDetectionModeStrategy = strategy;
}
public boolean isApplicationDetecting(){
return m_isApplicationDetecting;
}
public int getCurrentPos(){
return m_currentPos;
}
public void incrementCurrentPos(){
m_currentPos++;
}
public void decrementCurrentPos(){
m_currentPos--;
}
public void setCurrentReading(List<QRContent> contents, int currentPos){
m_currentReading = contents;
m_currentPos = currentPos;
}
public int getContentSize(){
return m_currentReading.size();
}
}
......@@ -2,7 +2,6 @@ package com.example.qrquest.QR.handling;
import android.util.Log;
import com.example.qrquest.QR.model.FileJson;
import com.example.qrquest.QR.model.QRCode;
import com.example.qrquest.QR.model.QRCodeAtomique;
import com.example.qrquest.QR.model.QRCodeEnsemble;
......@@ -10,23 +9,22 @@ import com.example.qrquest.QR.model.QrCodeJson;
import com.example.qrquest.exceptions.UnhandledQRException;
import com.example.qrquest.exceptions.UnsupportedQRException;
import com.example.qrquest.utils.DecompressionJSON;
import com.example.qrquest.utils.JSONDownloader;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.LinkedTreeMap;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
/**
* Created by Jules Leguy on 20/01/18.
* Modified by Florian Lherbeil
* Modified by Martin Loiseau for QRQuest
* Builds a QRCode object from a Json object
*/
public class QRCodeBuilder {
public static QRCode build(String dataQR, int current_version) throws UnhandledQRException, UnsupportedQRException {
public static QRCode build(String dataQR) throws UnhandledQRException, UnsupportedQRException {
Log.d("Debug", "QR CODE DETECT2");
// On stocke la valeur brute initiale pour pouvoir effetuer la détection multiple
final String rawvalue = dataQR;
String result;
......@@ -57,35 +55,10 @@ public class QRCodeBuilder {
Log.i("build","Miss Build : "+code.getType());
if(code.getVersion()>current_version){
throw new UnsupportedQRException("Ce QRCode ne peut pas être lu par cette application, veuillez mettre à jour QRLudo ou QRLudoGénérator");
}
// Si le json est trop gros et est stocké sur le drive dans un fichier texte
// Manque tests avec un qrcode réel
// LinkedTreeMap est la classe qui est instanciée lorsque GSON trouve du JSON
if ((code.getData().size() > 0) && (code.getData().get(0) instanceof LinkedTreeMap)) {
FileJson file = QRCode.createJsonFile((LinkedTreeMap) code.getData().get(0));
if (file.getType().equalsIgnoreCase("json")) {
JSONDownloader downloader = new JSONDownloader(file.getUrl());
downloader.execute();
try {
result = downloader.get();
System.out.println("result : "+result);
dataQR = DecompressionJSON.decompresser(result);
Gson gsonResult = new GsonBuilder().create();
code = gsonResult.fromJson(dataQR, QrCodeJson.class);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (code.getType().equalsIgnoreCase("atomique")||code.getType().equalsIgnoreCase("unique")||code.getType().equalsIgnoreCase("xl")) {
QRCodeAtomique qr = new QRCodeAtomique(code, dataQR);
......
package com.example.qrquest.QR.handling;
import android.util.Log;
import com.example.qrquest.MainActivity;
import com.example.qrquest.QR.model.QRCode;
import com.example.qrquest.QR.model.QRCodeAtomique;
import com.example.qrquest.QR.model.QRCodeEnsemble;
/**
* Created by Jules Leguy on 29/01/18.
*
* Default detecting strategy used while no special QRCode has been detected
*
* If a QRCodeEnsemble is detected and is the first of the current detection, launching QREnsembleDetectionStrategy by calling
* startEnsembleDetection(). Otherwise, ignoring it.
*/
public class QRCodeDefaultDetectionModeStrategy extends QRCodeDetectionModeStrategy {
public QRCodeDefaultDetectionModeStrategy(MainActivity mainActivity) {
super(mainActivity);
}
@Override
public void onFirstDetectionWithTimeNotNull(QRCode detectedQR) {
//Applies a family or ensemble related behaviour if necessary or launches the reading of the detected QR Code
if (!ensembleBehaviour(detectedQR, true)){
if(detectedQR instanceof QRCodeAtomique) {
QRCodeAtomique tmpQr = (QRCodeAtomique) detectedQR;
if (tmpQr.isWebsite()) ;
//m_mainActivity.setNextQRIsWeb();
}
//adding it to the detected QRCodes
m_detectedQRCodes.addQR(detectedQR);
//Changing curent detection state
m_mainActivity.setDetectionProgress(MainActivity.FIRST_QR_DETECTED);
//Reading the QR
m_mainActivity.singleReading();