]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/commitdiff
Implement first version of the Preview activity
authorMichal Horn <hornmich@fel.cvut.cz>
Wed, 11 Feb 2015 16:46:14 +0000 (17:46 +0100)
committerMichal Horn <hornmich@fel.cvut.cz>
Wed, 11 Feb 2015 16:46:14 +0000 (17:46 +0100)
The Glass module is not compilable because MuPDF dependecies are not fulfulled.

QRScanner/glass/src/main/AndroidManifest.xml
QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java [new file with mode: 0644]
QRScanner/glass/src/main/res/values/strings.xml

index b08a3d5e9d3cea6f090a82c0844a67e63780fdbd..f67d177568060534aa8ab08420a95cae8fe41deb 100644 (file)
                 android:name="com.google.android.glass.VoiceTrigger"
                 android:resource="@xml/voice_trigger" />
         </activity>
+        <activity
+            android:name=".PreviewActivity"
+            android:label="@string/title_activity_preview" >
+        </activity>
     </application>
 
 </manifest>
diff --git a/QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java b/QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java
new file mode 100644 (file)
index 0000000..5ae8e59
--- /dev/null
@@ -0,0 +1,150 @@
+package cz.cvut.fel.dce.qrscanner;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.widget.ImageView;
+import android.widget.Toast;
+
+import java.io.File;
+
+import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFActivity;
+import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
+
+
+public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlobalLayoutListener{
+
+       public static final String TAG = "PreviewActivity";
+       public static final String STORAGE_PATH = "/storage/sdcard0/Pictures";
+       public static final String SKODA_DOCS_PATH_EXTENSION = "/skoda/components/";
+       public static final String SKODA_COMP_PICTURE_NAME = "Abbildung.pdf";
+       public static final String SKODA_COMP_MANUFACTURING = "Arbeitseinleitung.pdf";
+       public static final String SKODA_COMP_MANUFACT_IMAGES = "Bild_Arbeitseinleitung.pdf";
+       public static final String SKODA_COMP_CONTACTS = "Angaben.pdf";
+       public static final String SKODA_COMP_MANUFACT_GUIDE = "Werkstatt_Einleitung.pdf";
+
+       private ImageView mPreviewImg;
+       private ViewTreeObserver mPreviewImgObserver;
+       private String mComponentId;
+       private String mComponentRootPath;
+
+       @Override
+       protected void onCreate(Bundle savedInstanceState) {
+               super.onCreate(savedInstanceState);
+               setContentView(R.layout.activity_preview);
+               mPreviewImg = (ImageView) findViewById(R.id.imgComponent);
+               if (mPreviewImg != null) {
+                       mPreviewImgObserver = mPreviewImg.getViewTreeObserver();
+                       Log.i(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
+                       mPreviewImgObserver.addOnGlobalLayoutListener(this);
+               }
+               else {
+                       Log.e(TAG, "ImageView for preview image could not be found in the resources.");
+                       mPreviewImgObserver = null;
+               }
+
+               Intent intent = getIntent();
+               mComponentId = intent.getStringExtra("COMPONENT_ID");
+
+               if (mComponentId != null) {
+                       Log.i(TAG, "Received component id: " + mComponentId);
+                       mComponentRootPath = STORAGE_PATH + SKODA_DOCS_PATH_EXTENSION + mComponentId + "/";
+                       File rootPath = new File(mComponentRootPath);
+                       if (!rootPath.isDirectory()) {
+                               Toast toast = Toast.makeText(getApplicationContext(), "Component not found", Toast.LENGTH_LONG);
+                               toast.show();
+                               finish();
+                       }
+               }
+               else {
+                       Log.i(TAG, "No component id received");
+                       finish();
+               }
+       }
+
+       @Override
+       protected void onDestroy() {
+               super.onDestroy();
+               Log.i(TAG, "Unregistering mPreviewImgObserver OnGlobalLayoutListener.");
+               if (mPreviewImgObserver != null && mPreviewImgObserver.isAlive()) {
+                       mPreviewImgObserver.removeOnGlobalLayoutListener(this);
+               }
+       }
+
+       @Override
+       public boolean onCreateOptionsMenu(Menu menu) {
+               // Inflate the menu; this adds items to the action bar if it is present.
+               getMenuInflater().inflate(R.menu.menu_preview, menu);
+               return true;
+       }
+
+       @Override
+       public void onGlobalLayout() {
+               try {
+                       String picturePath = mComponentRootPath + SKODA_COMP_PICTURE_NAME;
+                       Log.i(TAG, "Path to component files: " + picturePath);
+
+                       MuPDFCore core = new MuPDFCore(getApplicationContext(), picturePath);
+                       MuPDFCore.Cookie cookie = core.new Cookie();
+                       int previewW = mPreviewImg.getWidth();
+                       int previewH = mPreviewImg.getHeight();
+                       Bitmap.Config conf = Bitmap.Config.ARGB_8888;
+                       Bitmap previewBitmap = Bitmap.createBitmap(previewW, previewH, conf);
+                       core.updatePage(previewBitmap, 0, previewW, previewH, 0, 0, previewW, previewH, cookie);
+                       mPreviewImg.setImageBitmap(previewBitmap);
+               } catch (Exception e) {
+                       Toast toast = Toast.makeText(getApplicationContext(), "Component preview could not be loaded.", Toast.LENGTH_LONG);
+                       toast.show();
+                       e.printStackTrace();
+               }
+       }
+
+       /** Called when the user touches the button */
+       public void showContacts(View view) {
+               showPDF(mComponentRootPath + SKODA_COMP_CONTACTS);
+       }
+
+       /** Called when the user touches the button */
+       public void showManufacturing(View view) {
+               showPDF(mComponentRootPath + SKODA_COMP_MANUFACTURING);
+       }
+
+       /** Called when the user touches the button */
+       public void showManufactImages(View view) {
+               showPDF(mComponentRootPath + SKODA_COMP_MANUFACT_IMAGES);
+       }
+
+       /** Called when the user touches the button */
+       public void showManufactGuide(View view) {
+               showPDF(mComponentRootPath + SKODA_COMP_MANUFACT_GUIDE);
+       }
+
+       private void showPDF(String filePath) {
+               Uri uri = Uri.parse(filePath);
+               Intent pdfIntent = new Intent(this,MuPDFActivity.class);
+               pdfIntent.setAction(Intent.ACTION_VIEW);
+               pdfIntent.setData(uri);
+               startActivity(pdfIntent);
+       }
+       @Override
+       public boolean onOptionsItemSelected(MenuItem item) {
+               // Handle action bar item clicks here. The action bar will
+               // automatically handle clicks on the Home/Up button, so long
+               // as you specify a parent activity in AndroidManifest.xml.
+               int id = item.getItemId();
+
+               //noinspection SimplifiableIfStatement
+               if (id == R.id.action_settings) {
+                       return true;
+               }
+
+               return super.onOptionsItemSelected(item);
+       }
+}
index cf430732d8e5e549a5906c672fc9b5f0a55f762b..e277cdf33c4f42a8c2119a3b48a55644ec26060c 100644 (file)
@@ -15,8 +15,12 @@ See the License for the specific language governing permissions and
 limitations under the License.
 -->
 <resources>
-  <string name="app_name">Skoda Demo</string>
+    <string name="app_name">Skoda Manufacturer Helper</string>
+    <string name="start_scan">Scan</string>
+    <string name="title_activity_preview">Component preview</string>
   <string name="title_activity_main">Skoda Demo</string>
   <string name="hello_world">Skoda Demo</string>
+    <string name="action_stop">Stop</string>
+    <string name="action_scan">Scan code</string>
 
 </resources>