]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/commitdiff
Implement viewing of the item compartment number
authorMichal Horn <hornmich@fel.cvut.cz>
Fri, 20 Feb 2015 14:55:12 +0000 (15:55 +0100)
committerMichal Horn <hornmich@fel.cvut.cz>
Fri, 20 Feb 2015 14:55:12 +0000 (15:55 +0100)
QRScanner/database/1K0947105N/Abbildung.png [deleted file]
QRScanner/database/1K0947105N/iteminfo.txt [new file with mode: 0644]
QRScanner/database/3T0947105M/iteminfo.txt [new file with mode: 0644]
QRScanner/database/5E0947105E/iteminfo.txt [new file with mode: 0644]
QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java
QRScanner/glass/src/main/res/layout/activity_preview.xml
QRScanner/glass/src/main/res/values/strings.xml
QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java
QRScanner/mobile/src/main/res/layout-land/activity_preview.xml
QRScanner/mobile/src/main/res/layout/activity_preview.xml
QRScanner/mobile/src/main/res/values/strings.xml

diff --git a/QRScanner/database/1K0947105N/Abbildung.png b/QRScanner/database/1K0947105N/Abbildung.png
deleted file mode 100644 (file)
index 63e4dd3..0000000
Binary files a/QRScanner/database/1K0947105N/Abbildung.png and /dev/null differ
diff --git a/QRScanner/database/1K0947105N/iteminfo.txt b/QRScanner/database/1K0947105N/iteminfo.txt
new file mode 100644 (file)
index 0000000..56a6051
--- /dev/null
@@ -0,0 +1 @@
+1
\ No newline at end of file
diff --git a/QRScanner/database/3T0947105M/iteminfo.txt b/QRScanner/database/3T0947105M/iteminfo.txt
new file mode 100644 (file)
index 0000000..d8263ee
--- /dev/null
@@ -0,0 +1 @@
+2
\ No newline at end of file
diff --git a/QRScanner/database/5E0947105E/iteminfo.txt b/QRScanner/database/5E0947105E/iteminfo.txt
new file mode 100644 (file)
index 0000000..e440e5c
--- /dev/null
@@ -0,0 +1 @@
+3
\ No newline at end of file
index 17383b00fac16840f6a0e5deba4724c9f4a955c1..571bb0eaba573fb425e5c5520290f83d8068c5f9 100644 (file)
@@ -14,11 +14,18 @@ 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 com.google.android.glass.media.Sounds;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 
 import cz.cvut.fel.dce.qrscanner.pdfviewer.PdfPageView;
 import cz.cvut.fel.dce.qrscanner.pdfviewer.PdfViewActivity;
@@ -66,6 +73,10 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
         * The name of the PDF file containing the manufacturing guide.
         */
        public static final String SKODA_COMP_MANUFACT_GUIDE = "Werkstatt_Einleitung.pdf";
+       /**
+        * The name of the file containing aditional information about the component.
+        */
+       public static final String SKODA_COMPONENT_INFO_NAME = "iteminfo.txt";
        /**
         * The Key of the Component Identifier value, passed as a data to the activity launch intent.
         */
@@ -96,6 +107,10 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
         * 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) {
@@ -104,6 +119,7 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                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.");
@@ -113,6 +129,10 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                        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.");
@@ -133,6 +153,41 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                                audio.playSoundEffect(Sounds.ERROR);
                                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();
+                               AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+                               audio.playSoundEffect(Sounds.ERROR);
+                               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();
+                               AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+                               audio.playSoundEffect(Sounds.ERROR);
+                               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();
+                               AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+                               audio.playSoundEffect(Sounds.ERROR);
+                               e.printStackTrace();
+                               finish();
+                       }
                }
                else {
                        Log.e(TAG, "No component id received.");
index 1d0d7ea7ebdda0ebb84043703b9167c715920492..837cd870c2fb3c401e5fcafb6341e85e1dd618f4 100644 (file)
@@ -4,38 +4,78 @@
               android:layout_width="match_parent"
               android:layout_height="match_parent">
 
-    <ImageView
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:id="@+id/imgComponent"
-        android:layout_gravity="center_horizontal"
-        android:scaleType="center"
-        android:contentDescription="@string/preview_content_desc"/>
-
     <RelativeLayout
-        android:layout_width="73dp"
-        android:layout_height="match_parent"
-        android:id="@+id/progress_container"
+        android:layout_width="120dp"
+        android:layout_height="fill_parent"
+        android:layout_alignParentBottom="true"
         android:layout_alignParentTop="true"
-        android:layout_alignParentEnd="true"
-        android:layout_alignParentStart="true">
+        android:id="@+id/relativeLayout">
 
-        <ProgressBar
-            style="?android:attr/progressBarStyleLarge"
+        <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:id="@+id/progressBar2"
-            android:layout_centerVertical="true"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:text="@string/compartment_label"
+            android:id="@+id/textView9"
+            android:layout_alignParentTop="true"
             android:layout_centerHorizontal="true"/>
 
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:text="@string/loading_page"
-            android:id="@+id/textView5"
-            android:layout_below="@+id/progressBar2"
-            android:layout_alignStart="@+id/progressBar2"/>
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:text="1"
+            android:id="@+id/compartment_value"
+            android:layout_centerVertical="true"
+            android:layout_centerHorizontal="true"
+            android:textSize="200dp"/>
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:layout_width="100dp"
+        android:layout_height="fill_parent"
+        android:layout_alignParentTop="true"
+        android:layout_alignParentEnd="true"
+        android:layout_toEndOf="@+id/relativeLayout">
+
+        <ImageView
+            android:layout_width="100dp"
+            android:layout_height="100dp"
+            android:id="@+id/imgComponent"
+            android:layout_gravity="center_horizontal"
+            android:scaleType="center"
+            android:contentDescription="@string/preview_content_desc"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentEnd="true"
+            android:layout_alignParentBottom="true"
+            android:layout_alignParentStart="true"/>
+
+        <RelativeLayout
+            android:layout_width="73dp"
+            android:layout_height="100dp"
+            android:id="@+id/progress_container"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentEnd="true"
+            android:layout_alignParentBottom="true"
+            android:layout_alignParentStart="true">
+
+            <ProgressBar
+                style="?android:attr/progressBarStyleLarge"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:id="@+id/progressBar2"
+                android:layout_centerVertical="true"
+                android:layout_centerHorizontal="true"/>
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceMedium"
+                android:text="@string/loading_page"
+                android:id="@+id/textView5"
+                android:layout_below="@+id/progressBar2"
+                android:layout_centerHorizontal="true"/>
+        </RelativeLayout>
     </RelativeLayout>
 
 </RelativeLayout>
\ No newline at end of file
index 69615eb3dc9f71f454557e40c7af1a227e043659..e2112097b62afd3ffe0020480f6aa785cc3d36f9 100644 (file)
@@ -41,6 +41,7 @@ limitations under the License.
     <string name="state_scrolling" type="id">scrolling</string>
     <string name="preview_content_desc">Component preview image</string>
     <string name="skoda_logo_content_desc">Skoda auto logo</string>
+    <string name="compartment_label">Compartment:</string>
 
 
 </resources>
index 7b7db3dd5e37d4472ae643bb3c34aaf2915d21d9..077656f4dfaa481d06898968976744d1b22b4588 100644 (file)
@@ -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
index d85e88312cc1a6207628275dd145dad50753c357..49a3f371f5922f8de4cd27bdcc0982dd32d5950b 100644 (file)
@@ -1,14 +1,20 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:orientation="horizontal"
               android:layout_width="match_parent"
-              android:layout_height="match_parent">
+              android:layout_height="match_parent"
+              android:weightSum="1">
 
     <LinearLayout
         android:orientation="vertical"
-        android:layout_width="299dp"
+        android:layout_width="wrap_content"
         android:layout_height="match_parent"
-        android:weightSum="1">
+        android:weightSum="1"
+        android:layout_alignParentLeft="true"
+        android:layout_marginLeft="0dp"
+        android:layout_alignParentTop="true"
+        android:layout_marginTop="0dp"
+        android:id="@+id/linearLayout">
 
         <TextView
             android:layout_width="wrap_content"
 
     </LinearLayout>
 
+    <RelativeLayout
+        android:layout_width="wrap_content"
+        android:layout_height="fill_parent"
+        android:layout_marginLeft="27dp"
+        android:layout_marginStart="27dp"
+        android:layout_alignParentTop="true"
+        android:layout_toRightOf="@+id/linearLayout"
+        android:layout_toEndOf="@+id/linearLayout"
+        android:id="@+id/relativeLayout">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:text="@string/compartment_label"
+            android:id="@+id/textView13"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true"/>
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:text="1"
+            android:id="@+id/compartment_value"
+            android:textSize="200dp"
+            android:layout_centerVertical="true"
+            android:layout_centerHorizontal="true"/>
+
+    </RelativeLayout>
+
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     android:orientation="horizontal"
                     android:layout_width="match_parent"
-                    android:layout_height="match_parent">
+                    android:layout_height="match_parent"
+                    android:layout_alignParentTop="true"
+                    android:layout_marginTop="0dp"
+                    android:layout_toRightOf="@+id/relativeLayout"
+                    android:layout_toEndOf="@+id/relativeLayout">
 
         <ImageView
             android:layout_width="match_parent"
             android:id="@+id/imgComponent"
             android:layout_gravity="center_horizontal"
             android:scaleType="center"
-            android:contentDescription="@string/preview_content_desc"/>
+            android:contentDescription="@string/preview_content_desc"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true"/>
 
         <RelativeLayout
             android:layout_width="73dp"
             android:layout_height="match_parent"
             android:id="@+id/progress_container"
             android:layout_alignParentTop="true"
+            android:layout_alignParentRight="true"
             android:layout_alignParentEnd="true"
-            android:layout_alignParentStart="true"
             android:layout_alignParentLeft="true"
-            android:layout_alignParentRight="true">
+            android:layout_alignParentStart="true">
 
             <ProgressBar
                 style="?android:attr/progressBarStyleLarge"
                 android:text="@string/loading_page"
                 android:id="@+id/textView7"
                 android:layout_below="@+id/progressBar"
-                android:layout_alignStart="@+id/progressBar"
-                android:layout_alignLeft="@+id/progressBar"/>
+                android:layout_centerHorizontal="true"/>
         </RelativeLayout>
+
     </RelativeLayout>
 
-</LinearLayout>
\ No newline at end of file
+</RelativeLayout>
\ No newline at end of file
index 804a01f0618ade332af7c0997a544311491690b3..91152e021088c5b8cf95b81acf41ea63148fb0ad 100644 (file)
                 android:weightSum="1"
                 android:orientation="vertical">
 
-    <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:text="@string/previewHeading"
-        android:id="@+id/textView"/>
-
-    <Button
+    <LinearLayout
+        android:orientation="horizontal"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/butManufacturing"
-        android:id="@+id/butManufacturing"
-        android:onClick="showManufacturing"
-        />
+        android:layout_height="wrap_content">
 
-    <Button
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/butPicturedmanufacturing"
-        android:id="@+id/butManufactImages"
-        android:onClick="showManufactImages"
-        />
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent">
 
-    <Button
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/butManufacturingGuide"
-        android:id="@+id/butManufactGuide"
-        android:onClick="showManufactGuide"
-        />
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceMedium"
+                android:text="@string/previewHeading"
+                android:id="@+id/textView"/>
 
-    <Button
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/butContacts"
-        android:id="@+id/butContacts"
-        android:onClick="showContacts"
-        />
+            <Button
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/butManufacturing"
+                android:id="@+id/butManufacturing"
+                android:onClick="showManufacturing"
+                />
+
+            <Button
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/butPicturedmanufacturing"
+                android:id="@+id/butManufactImages"
+                android:onClick="showManufactImages"
+                />
+
+            <Button
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/butManufacturingGuide"
+                android:id="@+id/butManufactGuide"
+                android:onClick="showManufactGuide"
+                />
+
+            <Button
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/butContacts"
+                android:id="@+id/butContacts"
+                android:onClick="showContacts"
+                />
+
+        </LinearLayout>
+
+        <RelativeLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:text="1"
+                android:id="@+id/compartment_value"
+                android:layout_centerVertical="true"
+                android:layout_centerHorizontal="true"
+                android:textSize="200dp"/>
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceMedium"
+                android:text="@string/compartment_label"
+                android:id="@+id/textView11"
+                android:layout_alignParentTop="true"
+                android:layout_centerHorizontal="true"/>
+
+        </RelativeLayout>
+
+    </LinearLayout>
 
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     android:orientation="horizontal"
index 18f7c3d064466ef10913f0976bd07d9cf2252970..bc77b404bfc8a00bcaf8dc01ac3d0548c13fdadd 100644 (file)
@@ -69,6 +69,7 @@
     <string name="preview_content_desc">Component preview image</string>
     <string name="skoda_logo_content_desc">Skoda auto logo</string>
     <string name="touch_to_start_scan">Touch the screen to scan the code.</string>
+    <string name="compartment_label">Compartment</string>
 
 
 </resources>