X-Git-Url: http://rtime.felk.cvut.cz/gitweb/hornmich/skoda-qr-demo.git/blobdiff_plain/8afa504c5cab05d99489a6cf22622d31970bff3d..50cc2c5e8a28aeb1497959e38270abf4df4d1a62:/QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java diff --git a/QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java b/QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java index 7b7db3d..077656f 100644 --- a/QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java +++ b/QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java @@ -1,6 +1,8 @@ package cz.cvut.fel.dce.qrscanner; +import android.content.Context; import android.content.Intent; +import android.media.AudioManager; import android.net.Uri; import android.os.AsyncTask; import android.support.v7.app.ActionBarActivity; @@ -10,12 +12,17 @@ import android.view.View; import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.RelativeLayout; +import android.widget.TextView; import android.widget.Toast; import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFActivity; import cz.cvut.fel.dce.qrscanner.pdfviewer.PdfPageView; +import java.io.BufferedReader; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; /** * An activity for component picture preview with menu for selecting documents to be shown. @@ -64,6 +71,10 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv * The Key of the Component Identifier value, passed as a data to the activity launch intent. */ public static final String COMP_ID_INTENT_KEY = "COMPONENT_ID"; + /** + * The name of the file containing aditional information about the component. + */ + public static final String SKODA_COMPONENT_INFO_NAME = "iteminfo.txt"; /** * The widget for showing the component preview image. @@ -90,6 +101,11 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv * Flag signalling whether the PDF page has been loaded. */ private boolean mPdfLoaded; + /** + * The widget showing the value of the components compartment. + */ + private TextView mCompartmentValue; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -98,6 +114,7 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv mPdfLoaded = false; mPreviewImg = (ImageView) findViewById(R.id.imgComponent); mProgressContainer = (RelativeLayout) findViewById(R.id.progress_container); + mCompartmentValue = (TextView) findViewById(R.id.compartment_value); if (mProgressContainer == null) { Log.e(TAG, "Progress container not found in the activity layout."); @@ -107,6 +124,11 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv Log.e(TAG, "ImageView for preview image could not be found in the activity layout."); finish(); } + if (mCompartmentValue == null) { + Log.e(TAG, "TextView for compartment value could not be found in the activity layout."); + finish(); + } + mPreviewImgObserver = mPreviewImg.getViewTreeObserver(); Log.d(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener."); @@ -130,6 +152,36 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv Log.e(TAG, "No component id received."); finish(); } + File infoFile = new File(mComponentRootPath + SKODA_COMPONENT_INFO_NAME); + if (!infoFile.exists()) { + Log.e(TAG, "Aditional information file " + infoFile.getAbsolutePath() + " does not exist."); + Toast toast = Toast.makeText(getApplicationContext(), "Database not complete", Toast.LENGTH_LONG); + toast.show(); + finish(); + } + try { + BufferedReader br = new BufferedReader(new FileReader(infoFile)); + String compartmentLine = br.readLine(); + if (compartmentLine != null) { + mCompartmentValue.setText(compartmentLine); + } + else { + mCompartmentValue.setText("-"); + } + } catch (FileNotFoundException e) { + Log.e(TAG, "Aditional information file " + infoFile.getAbsolutePath() + " does not exist."); + Toast toast = Toast.makeText(getApplicationContext(), "Database not complete", Toast.LENGTH_LONG); + toast.show(); + e.printStackTrace(); + finish(); + } catch (IOException e) { + Log.e(TAG, "Error while reading the aditional information file " + infoFile.getAbsolutePath()); + Toast toast = Toast.makeText(getApplicationContext(), "Database reading failed", Toast.LENGTH_LONG); + toast.show(); + e.printStackTrace(); + finish(); + } + } @Override