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;
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.
* 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.
* 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) {
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.");
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.");
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