]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/commitdiff
Clean and coment the code.
authorMichal Horn <hornmich@fel.cvut.cz>
Tue, 17 Feb 2015 14:36:43 +0000 (15:36 +0100)
committerMichal Horn <hornmich@fel.cvut.cz>
Tue, 17 Feb 2015 14:36:43 +0000 (15:36 +0100)
17 files changed:
QRScanner/.idea/misc.xml
QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/MainActivity.java
QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java
QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/pdfviewer/PdfPageView.java
QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/pdfviewer/PdfViewActivity.java
QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/pdfviewer/PdfViewerException.java
QRScanner/glass/src/main/res/layout/activity_main.xml
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/MainActivity.java
QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java
QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/pdfviewer/PdfPageView.java
QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/pdfviewer/PdfViewerException.java
QRScanner/mobile/src/main/res/layout-land/activity_preview.xml
QRScanner/mobile/src/main/res/layout/activity_main.xml
QRScanner/mobile/src/main/res/layout/activity_preview.xml
QRScanner/mobile/src/main/res/values/strings.xml

index 99b2e4311daa698afef1eb5d07101e7285265206..e7e605234b1dac3704be86d51b881173860dc2bc 100644 (file)
@@ -3,6 +3,30 @@
   <component name="EntryPointsManager">
     <entry_points version="2.0" />
   </component>
+  <component name="NullableNotNullManager">
+    <option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
+    <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
+    <option name="myNullables">
+      <value>
+        <list size="4">
+          <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
+          <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
+          <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
+          <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
+        </list>
+      </value>
+    </option>
+    <option name="myNotNulls">
+      <value>
+        <list size="4">
+          <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
+          <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
+          <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
+          <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
+        </list>
+      </value>
+    </option>
+  </component>
   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
index 1f9ca08d14e3bcb4c18403100638c912a5ba1d5e..6791d44355a8fe837ddcb18241990a1bf36e3fb5 100644 (file)
@@ -1,55 +1,32 @@
 package cz.cvut.fel.dce.qrscanner;
 
 import com.google.android.glass.media.Sounds;
-import com.google.android.glass.widget.CardBuilder;
-import com.google.android.glass.widget.CardScrollAdapter;
-import com.google.android.glass.widget.CardScrollView;
 
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.media.AudioManager;
-import android.media.SoundPool;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.SoundEffectConstants;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
 
 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
 
 /**
- * An {@link Activity} showing a tuggable "Hello World!" card.
- * <p/>
- * The main content view is composed of a one-card {@link CardScrollView} that provides tugging
- * feedback to the user when swipe gestures are detected.
- * If your Glassware intends to intercept swipe gestures, you should set the content view directly
- * and use a {@link com.google.android.glass.touchpad.GestureDetector}.
- *
- * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
+ * An {@link Activity} showing an immersive card with a Skoda Auto logo, waiting for
+ * user to tap the touchpad to start the QR code scanning.
  */
 public class MainActivity extends Activity {
-       public final static String TAG = "MainActivity";
-
-       /**
-        * {@link CardScrollView} to use as the main content view.
-        */
-       private CardScrollView mCardScroller;
-
        /**
-        * "Hello World!" {@link View} generated by {@link #buildView()}.
+        * An activity tag for debug, error and info messages.
         */
-       private View mView;
+       public final static String TAG = "MainActivity";
 
        @Override
        protected void onCreate(Bundle bundle) {
                super.onCreate(bundle);
                setContentView(R.layout.activity_main);
-
        }
 
        public void onActivityResult(int requestCode, int resultCode, Intent intent) {
@@ -59,12 +36,10 @@ public class MainActivity extends Activity {
                        audio.playSoundEffect(Sounds.SUCCESS);
                        Log.i(TAG, scanResult.toString());
                        Intent preview = new Intent(this, PreviewActivity.class);
-                       preview.putExtra("COMPONENT_ID", scanResult.getContents());
+                       preview.putExtra(PreviewActivity.COMP_ID_INTENT_KEY, scanResult.getContents());
                        startActivity(preview);
 
                }
-               // else continue with any other code you need in the method
-
        }
 
        @Override
@@ -88,19 +63,11 @@ public class MainActivity extends Activity {
                return super.onKeyDown(keyCode, event);
        }
 
+       /**
+        * Start the scan code activity
+        */
        private void startScan() {
                IntentIntegrator integrator = new IntentIntegrator(this);
                integrator.initiateScan();
        }
-
-       /**
-        * Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
-        */
-       private View buildView() {
-               CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
-
-               card.setText(R.string.hello_world);
-               return card.getView();
-       }
-
 }
index a8aafbf4ad4107ffc620eb5ab20afd8dea788b1d..17383b00fac16840f6a0e5deba4724c9f4a955c1 100644 (file)
@@ -3,10 +3,7 @@ package cz.cvut.fel.dce.qrscanner;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.Color;
 import android.media.AudioManager;
-import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.util.Log;
@@ -23,28 +20,81 @@ import com.google.android.glass.media.Sounds;
 
 import java.io.File;
 
-import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
 import cz.cvut.fel.dce.qrscanner.pdfviewer.PdfPageView;
 import cz.cvut.fel.dce.qrscanner.pdfviewer.PdfViewActivity;
 
-
+/**
+ * An activity for component picture preview with menu for selecting documents to be shown.
+ *
+ * The activity is designed to be called via an Intent with a component identifier string passed
+ * with the key COMPONENT_ID.
+ *
+ * The activity loads the component picture from the PDF file asynchronously to not block the UI.
+ */
 public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlobalLayoutListener{
-
+       /**
+        * An activity tag for debug, error and info messages.
+        */
        public static final String TAG = "PreviewActivity";
+       /**
+        * The path to the storage folder, where the application stores its data.
+        * <p>This path should not be hardcoded like this, but the Android API functions were returning
+        * paths tht were not valid on our Android devices.</p>
+        */
        public static final String STORAGE_PATH = "/storage/sdcard0/Pictures";
+       /**
+        * The path in the application data folder, where the component database is.
+        */
        public static final String SKODA_DOCS_PATH_EXTENSION = "/skoda/components/";
+       /**
+        * The name of the PDF file containing the pisture of the component.
+        */
        public static final String SKODA_COMP_PICTURE_NAME = "Abbildung.pdf";
+       /**
+        * The name of the PDF file containing the manufacturing process description.
+        */
        public static final String SKODA_COMP_MANUFACTURING = "Arbeitseinleitung.pdf";
+       /**
+        * The name of the PDF file containing the manufacturing process description with pictures.
+        */
        public static final String SKODA_COMP_MANUFACT_IMAGES = "Bild_Arbeitseinleitung.pdf";
+       /**
+        * The name of the PDF file containing the contacts for the component manufacturer.
+        */
        public static final String SKODA_COMP_CONTACTS = "Angaben.pdf";
+       /**
+        * The name of the PDF file containing the manufacturing guide.
+        */
        public static final String SKODA_COMP_MANUFACT_GUIDE = "Werkstatt_Einleitung.pdf";
+       /**
+        * 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 widget for showing the component preview image.
+        */
        private ImageView mPreviewImg;
+       /**
+        * The container for progress bar widget and text view.
+        * <p>Those two are in the container to make them easily disappear and appear when needed.</p>
+        */
        private RelativeLayout mProgressContainer;
+       /**
+        * The observer of the view tree for detection of the end of the View tree loading.
+        */
        private ViewTreeObserver mPreviewImgObserver;
-       private String mComponentId;
+       /**
+        * The path to the directory containing documents for the component.
+        */
        private String mComponentRootPath;
+       /**
+        * Widget containing loaded page from a PDF file.
+        */
        private PdfPageView mPdfView;
+       /**
+        * Flag signalling whether the PDF page has been loaded.
+        */
        private boolean mPdfLoaded;
 
        @Override
@@ -55,27 +105,28 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                mPreviewImg = (ImageView) findViewById(R.id.imgComponent);
                mProgressContainer = (RelativeLayout) findViewById(R.id.progress_container);
 
-               if (mPreviewImg != null) {
-                       mPreviewImg.setMaxWidth(640);
-                       mPreviewImg.setMaxHeight(360);
-                       mPreviewImg.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
-                       mPreviewImgObserver = mPreviewImg.getViewTreeObserver();
-                       Log.i(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
-                       mPreviewImgObserver.addOnGlobalLayoutListener(this);
+               if (mProgressContainer == null) {
+                       Log.e(TAG, "Progress container not found in the activity layout.");
+                       finish();
                }
-               else {
-                       Log.e(TAG, "ImageView for preview image could not be found in the resources.");
-                       mPreviewImgObserver = null;
+               if (mPreviewImg == null) {
+                       Log.e(TAG, "ImageView for preview image could not be found in the activity layout.");
+                       finish();
                }
 
+               mPreviewImgObserver = mPreviewImg.getViewTreeObserver();
+               Log.d(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
+               mPreviewImgObserver.addOnGlobalLayoutListener(this);
+
                Intent intent = getIntent();
-               mComponentId = intent.getStringExtra("COMPONENT_ID");
+               String mComponentId = intent.getStringExtra(COMP_ID_INTENT_KEY);
 
                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()) {
+                               Log.e(TAG, "Component database root directory " + rootPath.getAbsolutePath() + " does not exist.");
                                Toast toast = Toast.makeText(getApplicationContext(), "Component not found", Toast.LENGTH_LONG);
                                toast.show();
                                AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
@@ -84,7 +135,7 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                        }
                }
                else {
-                       Log.i(TAG, "No component id received");
+                       Log.e(TAG, "No component id received.");
                        finish();
                }
        }
@@ -92,7 +143,7 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
        @Override
        protected void onDestroy() {
                super.onDestroy();
-               Log.i(TAG, "Unregistering mPreviewImgObserver OnGlobalLayoutListener.");
+               Log.d(TAG, "Unregister mPreviewImgObserver OnGlobalLayoutListener.");
                if (mPreviewImgObserver != null && mPreviewImgObserver.isAlive()) {
                        mPreviewImgObserver.removeOnGlobalLayoutListener(this);
                }
@@ -100,7 +151,6 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
 
        @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;
        }
@@ -114,6 +164,7 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                try {
                        String picturePath = mComponentRootPath + SKODA_COMP_PICTURE_NAME;
                        Log.i(TAG, "Path to component files: " + picturePath);
+                       Log.d(TAG, "Loading PDF file " + picturePath);
                        mPdfView = new PdfPageView(getApplicationContext(), picturePath);
                        mPdfView.setPage(0);
                        new LoadPageTask().execute();
@@ -121,6 +172,7 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                        mPdfLoaded = true;
 
                } catch (Exception e) {
+                       Log.e(TAG, "Component picture loading from PDF file failed: " + e.getMessage());
                        Toast toast = Toast.makeText(getApplicationContext(), "Component preview could not be loaded.", Toast.LENGTH_LONG);
                        toast.show();
                        AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
@@ -129,29 +181,33 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                }
        }
 
-       /** Called when the user touches the button */
+       /** Called when the user touches the button Contacts. */
        public void showContacts() {
                showPDF(mComponentRootPath + SKODA_COMP_CONTACTS);
        }
 
-       /** Called when the user touches the button */
+       /** Called when the user touches the button Manufacturing. */
        public void showManufacturing() {
                showPDF(mComponentRootPath + SKODA_COMP_MANUFACTURING);
        }
 
-       /** Called when the user touches the button */
+       /** Called when the user touches the button Manufacturing pictured. */
        public void showManufactImages() {
                showPDF(mComponentRootPath + SKODA_COMP_MANUFACT_IMAGES);
        }
 
-       /** Called when the user touches the button */
+       /** Called when the user touches the button Manufacture guide. */
        public void showManufactGuide() {
                showPDF(mComponentRootPath + SKODA_COMP_MANUFACT_GUIDE);
        }
 
+       /**
+        * Launch an activity to show the PDF file.
+        * @param filePath Path to the PDF file to be shown
+        */
        private void showPDF(String filePath) {
                Intent preview = new Intent(this, PdfViewActivity.class);
-               preview.putExtra("FILE_PATH", filePath);
+               preview.putExtra(PdfViewActivity.FILE_PATH_INTENT_KEY, filePath);
                startActivity(preview);
        }
 
@@ -168,9 +224,6 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
 
        @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();
 
                if (id == R.id.show_contacts) {
@@ -198,6 +251,9 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                }
        }
 
+       /**
+        * Class for asynchronous loading of the PDF page to a bitmap.
+        */
        private class LoadPageTask extends AsyncTask<Void, Void, Void> {
 
                @Override
@@ -219,10 +275,10 @@ public class PreviewActivity extends Activity implements ViewTreeObserver.OnGlob
                        mProgressContainer.setVisibility(View.INVISIBLE);
                        mPreviewImg.setMinimumWidth(640);
                        mPreviewImg.setMinimumHeight(360);
+                       mPreviewImg.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                        mPreviewImg.setImageBitmap(mPdfView.getPageBitmap());
                        mPreviewImg.invalidate();
                        Log.d(TAG, "PDF page loaded.");
                }
        }
-
 }
index 44fcfb02735e230af48f51c66c210dcc8071d60c..8ee3d6e2ed51af8a5a41f56ef3f74cdee4b91f4b 100644 (file)
@@ -8,12 +8,15 @@ import android.util.Log;
 import android.view.View;
 
 import java.io.File;
-import java.sql.Time;
 
 import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
 
 /**
- * Created by Michal Horn on 16.2.15.
+ * View for viewing PDF page.
+ *
+ * This view is designed to be used in two ways.
+ * 1) To view the PDF page itself on the device, which is supported by an interface for scrolling, zooming, switching pages and loading pages.
+ * 2) To load the PDF page to a bitmap, which can be accessed in the program by calling getPageBitmap() method.
  */
 public class PdfPageView  extends View {
        /**
@@ -173,10 +176,18 @@ public class PdfPageView  extends View {
                Log.i(TAG, "Pages: " + mPage.toString());
        }
 
+       /**
+        * Get actual page. The actual page can be selected by setPage() method.
+        * @return actual page.
+        */
        public int getActualPage() {
                return mPage.getValue();
        }
 
+       /**
+        * Get total number of pages in the document
+        * @return total number of pages
+        */
        public int getLastPage() {
                return mPage.getMaximum();
        }
@@ -185,6 +196,12 @@ public class PdfPageView  extends View {
                return mPage.setValue(page);
        }
 
+       /**
+        * Load PDF and convert selected page to a bitmap.
+        *
+        * The page of the PDF document can be selected by setPage() method.
+        * This method can take significant time to finish. Consider calling it in separated thread.
+        */
        public void loadPage() {
                long startTime = System.currentTimeMillis();
                try {
@@ -200,7 +217,7 @@ public class PdfPageView  extends View {
                        mYPosition = new IntervalValue<>(360.0f/2, -mSceneHeight+360.0f/2, mSceneHeight+360.0f/2);
                        mZoom = new IntervalValue<>(1.0f, 0.2f, 2.0f);
                } catch (Exception e) {
-                       Log.e(TAG, "Error in setting page dimensions.");
+                       Log.e(TAG, "Error in setting page dimensions: " + e.getMessage());
                        e.printStackTrace();
                }
                long endTime = System.currentTimeMillis();
@@ -211,12 +228,14 @@ public class PdfPageView  extends View {
                }
        }
 
+       /**
+        * Get PDF page bitmap
+        * @return Bitmap of the PDF page or null, if it has not been yet loaded.
+        */
        public Bitmap getPageBitmap() {
                return mPdfBitmap;
        }
 
-
-
        /**
         * Set a listener of the events
         * @param listener listener of the events
@@ -225,6 +244,9 @@ public class PdfPageView  extends View {
                mListener = listener;
        }
 
+       /**
+        * Clear listener.
+        */
        public void clearListener() {
                mListener = null;
        }
@@ -238,7 +260,7 @@ public class PdfPageView  extends View {
                if (!mPageLoaded) return;
                float ratio = mZoom.getValue();
                ratio += deltaRatio;
-               if (mZoom.setValue(ratio) == true && mListener != null) {
+               if (mZoom.setValue(ratio) && mListener != null) {
                        mListener.onViewChanged(this);
                }
        }
index 28122ebcd00020ab7078db19a6dbe9bba1a7d377..719db79b8b5f98044ab7ab01a8b2aae28a08a2d7 100644 (file)
@@ -12,8 +12,6 @@ import android.os.AsyncTask;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewTreeObserver;
@@ -29,76 +27,164 @@ import java.io.File;
 
 import cz.cvut.fel.dce.qrscanner.R;
 
+/**
+ * PDF Viewer for Google Glass.
+ *
+ * This activity is designed to view PDF in Google Glass. The document can be scrolled by the
+ * moving of the user's head and zoomed in and out by sliding forward and backward on the touchpad.
+ * The activity has two states, which can be toggled by taping on the touchpad. When in the Scrolling
+ * state, the PDF document can be scrolled and zoomed. When in the viewing state, those features are
+ * disabled to let the user read the document comfortably.
+ *
+ * The activity is prepared to switch between pages, which should be implemented in the future by sliding
+ * forward and backward in the viewing state.
+ */
 public class PdfViewActivity extends Activity implements ViewTreeObserver.OnGlobalLayoutListener, PdfPageView.SceneChange, SensorEventListener {
+       /**
+        * The Key of the file path value, passed as a data to the activity launch intent.
+        */
+       public static final String FILE_PATH_INTENT_KEY = "FILE_PATH";
 
+       /**
+        * The states of the PDF viewer.
+        */
        enum ViewStates {
+               /**
+                * Scrolling state - user can scroll in the page by moving of the head and zoom by sliding the touchpad.
+                */
                SCROLLING,
+               /**
+                * Viewing state - user can read the document comfortably and in the future will be able to change the pages.
+                */
                VIEWING
-       };
+       }
 
+       /**
+        * An activity tag for debug, error and info messages.
+        */
        public static final String TAG = "PdfViewActivity";
 
+       /**
+        * The container for progress bar widget and text view.
+        * <p>Those two are in the container to make them easily disappear and appear when needed.</p>
+        */
        private FrameLayout mPdfImageContainer;
+       /**
+        * The text view widget showing the current page numeber.
+        */
        private TextView mCurrentPageNumber;
+       /**
+        * The text view widget showing total number of the pages.
+        */
        private TextView mLastPageNumber;
+       /**
+        * The text view widget showing current state of the viewer.
+        */
        private TextView mViewerStateText;
+       /**
+        * The text view widget showing the zoom in percent.
+        */
        private TextView mZoomValue;
+       /**
+        * The observer of the view tree for detection of the end of the View tree loading.
+        */
        private ViewTreeObserver mPreviewImgObserver;
+       /**
+        * The path to the PDF file to be loaded.
+        */
        private String mFilePath;
+       /**
+        * Widget containing loaded page from a PDF file.
+        */
        private PdfPageView mPdfView;
-       private Boolean mPdfLoaded = false;
+       /**
+        * Flag signalling whether the PDF page has been loaded.
+        */
+       private Boolean mPdfLoaded;
+       /**
+        * Sensor manager for receiving data from gyroscope to scroll the PDF page.
+        */
        private SensorManager mSensorManager;
+       /**
+        * Stores the current state of the PDF viewer.
+        */
        private ViewStates mViewStates;
+       /**
+        * The container for progress bar widget and text view.
+        * <p>Those two are in the container to make them easily disappear and appear when needed.</p>
+        */
        private RelativeLayout mProgressContainer;
-
        /**
-        * Start position of the gesture on touchpad
+        * Start position of the gesture on touchpad.
         */
        private float startX;
 
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
+               mPdfLoaded = false;
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
                setContentView(R.layout.activity_pdf_view);
+
                mPdfImageContainer = (FrameLayout) findViewById(R.id.pdf_view_container);
                mCurrentPageNumber = (TextView) findViewById(R.id.page_number);
                mLastPageNumber = (TextView) findViewById(R.id.total_pages_num);
                mViewerStateText = (TextView) findViewById(R.id.pdf_viewer_state);
                mZoomValue = (TextView) findViewById(R.id.zoom_value);
-               mViewStates = ViewStates.SCROLLING;
                mProgressContainer = (RelativeLayout) findViewById(R.id.progress_container);
-
-               if (mPdfImageContainer != null) {
-                       mPreviewImgObserver = mPdfImageContainer.getViewTreeObserver();
-                       Log.i(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
-                       mPreviewImgObserver.addOnGlobalLayoutListener(this);
+               if (mProgressContainer == null) {
+                       Log.e(TAG, "Progress container not found in the activity layout.");
+                       finish();
                }
-               else {
-                       Log.e(TAG, "ImageView for preview image could not be found in the resources.");
-                       mPreviewImgObserver = null;
+               if (mCurrentPageNumber == null) {
+                       Log.e(TAG, "Current page number view could not be found in the activity layout.");
+                       finish();
+               }
+               if (mLastPageNumber == null) {
+                       Log.e(TAG, "Last page number view could not be found in the activity layout.");
+                       finish();
+               }
+               if (mViewerStateText == null) {
+                       Log.e(TAG, "Viewer state view could not be found in the activity layout.");
+                       finish();
                }
+               if (mZoomValue == null) {
+                       Log.e(TAG, "Zoom number view could not be found in the activity layout.");
+                       finish();
+               }
+               if (mPdfImageContainer == null) {
+                       Log.e(TAG, "Current page number view could not be found in the activity layout.");
+                       finish();
+               }
+               mViewStates = ViewStates.SCROLLING;
+
+
+               mPreviewImgObserver = mPdfImageContainer.getViewTreeObserver();
+               Log.d(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
+               mPreviewImgObserver.addOnGlobalLayoutListener(this);
 
                Intent intent = getIntent();
-               mFilePath = intent.getStringExtra("FILE_PATH");
+               mFilePath = intent.getStringExtra(FILE_PATH_INTENT_KEY);
 
                if (mFilePath != null) {
                        Log.i(TAG, "File path: " + mFilePath);
                        File rootPath = new File(mFilePath);
                        if (!rootPath.exists()) {
+                               Log.e(TAG, "File " + rootPath.getAbsolutePath() + "not found.");
                                Toast toast = Toast.makeText(getApplicationContext(), "Document not found", Toast.LENGTH_LONG);
                                toast.show();
                                finish();
                        }
                }
                else {
-                       Log.i(TAG, "No file path received");
+                       Log.e(TAG, "No file path received");
                        finish();
                }
        }
 
        public void onResume() {
+               Log.d(TAG, "Registering sensor listener");
                mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_NORMAL);
                super.onResume();
        }
@@ -106,6 +192,7 @@ public class PdfViewActivity extends Activity implements ViewTreeObserver.OnGlob
        @Override
        protected void onPause() {
                super.onPause();
+               Log.d(TAG, "Unregister sensor listener.");
                mSensorManager.unregisterListener(this);
        }
 
@@ -118,30 +205,6 @@ public class PdfViewActivity extends Activity implements ViewTreeObserver.OnGlob
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
 
-
-
-       @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_pdf_view, menu);
-               return true;
-       }
-
-       @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);
-       }
-
        @Override
        public void onGlobalLayout() {
                if (mPdfLoaded) {
@@ -152,22 +215,16 @@ public class PdfViewActivity extends Activity implements ViewTreeObserver.OnGlob
                        String picturePath = mFilePath;
                        Log.i(TAG, "Path to component files: " + picturePath);
                        mPdfView = new PdfPageView(getApplicationContext(), picturePath);
+                       mPdfView.setPage(0);
                        mCurrentPageNumber.setText(Integer.toString(mPdfView.getActualPage()+1));
                        mLastPageNumber.setText(Integer.toString(mPdfView.getLastPage() + 1));
                        mPdfView.setListener(this);
-                       mPdfView.setPage(0);
                        new LoadPageTask().execute();
 
-
-                       if (mPdfImageContainer != null) {
-                               mPdfLoaded = true;
-                       }
-                       else {
-                               Log.e(TAG, "Could not find container for PdfPageView.");
-                               finish();
-                       }
+                       mPdfLoaded = true;
                } catch (Exception e) {
-                       Toast toast = Toast.makeText(getApplicationContext(), "Component preview could not be loaded.", Toast.LENGTH_LONG);
+                       Log.e(TAG, "PDF file could not be loaded: " + e.getMessage());
+                       Toast toast = Toast.makeText(getApplicationContext(), "PDF file could not be loaded.", Toast.LENGTH_LONG);
                        toast.show();
                        e.printStackTrace();
                }
@@ -204,18 +261,6 @@ public class PdfViewActivity extends Activity implements ViewTreeObserver.OnGlob
                return super.onKeyDown(keyCode, event);
        }
 
-       private void switchState() {
-               if (mViewStates == ViewStates.SCROLLING) {
-                       mViewStates = ViewStates.VIEWING;
-                       mViewerStateText.setText(getText(R.string.state_viewing));
-               }
-               else {
-                       mViewStates = ViewStates.SCROLLING;
-                       mViewerStateText.setText(getText(R.string.state_scrolling));
-
-               }
-       }
-
        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
 
@@ -246,11 +291,33 @@ public class PdfViewActivity extends Activity implements ViewTreeObserver.OnGlob
 
        }
 
+       /**
+        * Switch the viewer state, update the state text view in the layout.
+        */
+       private void switchState() {
+               if (mViewStates == ViewStates.SCROLLING) {
+                       mViewStates = ViewStates.VIEWING;
+                       mViewerStateText.setText(getText(R.string.state_viewing));
+               }
+               else {
+                       mViewStates = ViewStates.SCROLLING;
+                       mViewerStateText.setText(getText(R.string.state_scrolling));
+
+               }
+       }
+
+       /**
+        * Zoom the PDF page, update the zoom value in the layout.
+        * @param deltaZoom The value how much to zoom the page.
+        */
        private void zoomPage(float deltaZoom) {
                mPdfView.zoom(deltaZoom);
                mZoomValue.setText(Integer.toString(Math.round(mPdfView.getZoomRatio() * 100)));
        }
 
+       /**
+        * Class for asynchronous loading of the PDF page to a bitmap.
+        */
        private class LoadPageTask extends AsyncTask<Void, Void, Void> {
 
                @Override
index 36cf10596da6e22ee970c5fc6a5bf996c3b359aa..5aa1835020016f359f732b782d505d1becff31dc 100644 (file)
@@ -1,7 +1,9 @@
 package cz.cvut.fel.dce.qrscanner.pdfviewer;
 
 /**
- * Created by michal on 16.2.15.
+ * Custom Viewer exception class
+ *
+ * Instances of this Exception class are thrown by the PdfPageView widget.
  */
 public class PdfViewerException extends Exception {
        PdfViewerException(String s){
index 0822edb2052f89288187d8133bce2d4feb95ce74..e463cd83c0df3d8b22a213238d88b78f17d18dcd 100644 (file)
@@ -9,12 +9,12 @@
         android:layout_height="wrap_content"
         android:id="@+id/imageView"
         android:src="@drawable/skoda_logo"
-        android:onClick="findComponent"
         android:scaleType="centerInside"
         android:layout_below="@+id/textView8"
         android:layout_alignParentBottom="true"
         android:layout_alignParentEnd="true"
-        android:layout_alignParentStart="true"/>
+        android:layout_alignParentStart="true"
+        android:contentDescription="@string/skoda_logo_content_desc"/>
 
     <TextView
         android:layout_width="wrap_content"
index e28ceeb98c0ad59cae7dafdd8d40d5e8b1da5cad..1d0d7ea7ebdda0ebb84043703b9167c715920492 100644 (file)
@@ -9,7 +9,8 @@
         android:layout_height="match_parent"
         android:id="@+id/imgComponent"
         android:layout_gravity="center_horizontal"
-        android:scaleType="center"/>
+        android:scaleType="center"
+        android:contentDescription="@string/preview_content_desc"/>
 
     <RelativeLayout
         android:layout_width="73dp"
index 9b586c23c85f0cc21408d395e2d4c4fb75480d51..9a6003ef8d304c8ef0aba8e0f324c9dcc60589f6 100644 (file)
@@ -18,8 +18,8 @@ limitations under the License.
     <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="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>
     <string name="cannot_open_file_Path">Cannot open file: %1$s</string>
@@ -39,5 +39,8 @@ limitations under the License.
     <string name="tap_to_start_scan">Tap to start scanning</string>
     <string name="state_viewing" type="id">viewing</string>
     <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>
+
 
 </resources>
index de3a44ca2062f8d0d7503ccee16203165ef373cf..c8ba7cfb11fb5a4288308d39bce25dd3cbf1f898 100644 (file)
@@ -11,8 +11,14 @@ import android.view.View;
 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
 
-
+/**
+ * An {@link android.app.Activity} showing an immersive card with a Skoda Auto logo, waiting for
+ * user to tap the screen to start the QR code scanning.
+ */
 public class MainActivity extends ActionBarActivity {
+       /**
+        * An activity tag for debug, error and info messages.
+        */
        public static final String TAG = "MainActivity";
 
        @Override
@@ -31,12 +37,8 @@ public class MainActivity extends ActionBarActivity {
 
        @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.start_scan) {
                        startScan();
                }
@@ -49,17 +51,20 @@ public class MainActivity extends ActionBarActivity {
                if (scanResult != null) {
                        Log.i(TAG, scanResult.toString());
                        Intent preview = new Intent(this, PreviewActivity.class);
-                       preview.putExtra("COMPONENT_ID", scanResult.getContents());
+                       preview.putExtra(PreviewActivity.COMP_ID_INTENT_KEY, scanResult.getContents());
                        startActivity(preview);
                }
        }
 
+       /**
+        * Start the scan code activity
+        */
        private void startScan() {
                IntentIntegrator integrator = new IntentIntegrator(this);
                integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
        }
 
-       /** Called when the user touches the button */
+       /** Called when the user touches the screen */
        public void findComponent(View view) {
                startScan();
        }
index 767d4bc78a4512aae7b337d644c129c0e4820d62..7b7db3dd5e37d4472ae643bb3c34aaf2915d21d9 100644 (file)
@@ -1,48 +1,96 @@
 package cz.cvut.fel.dce.qrscanner;
 
-import android.content.Context;
 import android.content.Intent;
-import android.graphics.Bitmap;
-import android.media.AudioManager;
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.support.v7.app.ActionBarActivity;
 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.Button;
 import android.widget.ImageView;
 import android.widget.RelativeLayout;
 import android.widget.Toast;
 
 import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFActivity;
-import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
 import cz.cvut.fel.dce.qrscanner.pdfviewer.PdfPageView;
 
 import java.io.File;
 
+/**
+ * An activity for component picture preview with menu for selecting documents to be shown.
+ *
+ * The activity is designed to be called via an Intent with a component identifier string passed
+ * with the key COMPONENT_ID.
+ *
+ * The activity loads the component picture from the PDF file asynchronously to not block the UI.
+ */
 public class PreviewActivity extends ActionBarActivity implements ViewTreeObserver.OnGlobalLayoutListener {
+       /**
+        * An activity tag for debug, error and info messages.
+        */
        public static final String TAG = "PreviewActivity";
+       /**
+        * The path to the storage folder, where the application stores its data.
+        * <p>This path should not be hardcoded like this, but the Android API functions were returning
+        * paths tht were not valid on our Android devices.</p>
+        */
        public static final String STORAGE_PATH = "/storage/sdcard0/Pictures";
+       /**
+        * The path in the application data folder, where the component database is.
+        */
        public static final String SKODA_DOCS_PATH_EXTENSION = "/skoda/components/";
+       /**
+        * The name of the PDF file containing the pisture of the component.
+        */
        public static final String SKODA_COMP_PICTURE_NAME = "Abbildung.pdf";
+       /**
+        * The name of the PDF file containing the manufacturing process description.
+        */
        public static final String SKODA_COMP_MANUFACTURING = "Arbeitseinleitung.pdf";
+       /**
+        * The name of the PDF file containing the manufacturing process description with pictures.
+        */
        public static final String SKODA_COMP_MANUFACT_IMAGES = "Bild_Arbeitseinleitung.pdf";
+       /**
+        * The name of the PDF file containing the contacts for the component manufacturer.
+        */
        public static final String SKODA_COMP_CONTACTS = "Angaben.pdf";
+       /**
+        * The name of the PDF file containing the manufacturing guide.
+        */
        public static final String SKODA_COMP_MANUFACT_GUIDE = "Werkstatt_Einleitung.pdf";
+       /**
+        * 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 widget for showing the component preview image.
+        */
        private ImageView mPreviewImg;
+       /**
+        * The container for progress bar widget and text view.
+        * <p>Those two are in the container to make them easily disappear and appear when needed.</p>
+        */
        private RelativeLayout mProgressContainer;
+       /**
+        * The observer of the view tree for detection of the end of the View tree loading.
+        */
        private ViewTreeObserver mPreviewImgObserver;
-       private String mComponentId;
+       /**
+        * The path to the directory containing documents for the component.
+        */
        private String mComponentRootPath;
+       /**
+        * Widget containing loaded page from a PDF file.
+        */
        private PdfPageView mPdfView;
+       /**
+        * Flag signalling whether the PDF page has been loaded.
+        */
        private boolean mPdfLoaded;
 
-
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
@@ -50,35 +98,36 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv
                mPdfLoaded = false;
                mPreviewImg = (ImageView) findViewById(R.id.imgComponent);
                mProgressContainer = (RelativeLayout) findViewById(R.id.progress_container);
+
                if (mProgressContainer == null) {
-                       Log.e(TAG, "Progress container was not found.");
+                       Log.e(TAG, "Progress container not found in the activity layout.");
                        finish();
                }
-
-               if (mPreviewImg != null) {
-                       mPreviewImg.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
-                       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;
+               if (mPreviewImg == null) {
+                       Log.e(TAG, "ImageView for preview image could not be found in the activity layout.");
+                       finish();
                }
 
+               mPreviewImgObserver = mPreviewImg.getViewTreeObserver();
+               Log.d(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
+               mPreviewImgObserver.addOnGlobalLayoutListener(this);
+
                Intent intent = getIntent();
-               mComponentId = intent.getStringExtra("COMPONENT_ID");
+               String mComponentId = intent.getStringExtra(COMP_ID_INTENT_KEY);
 
                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()) {
+                               Log.e(TAG, "Component database root directory " + rootPath.getAbsolutePath() + " does not exist.");
                                Toast toast = Toast.makeText(getApplicationContext(), "Component not found", Toast.LENGTH_LONG);
                                toast.show();
                                finish();
                        }
-               } else {
-                       Log.i(TAG, "No component id received");
+               }
+               else {
+                       Log.e(TAG, "No component id received.");
                        finish();
                }
        }
@@ -86,18 +135,12 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv
        @Override
        protected void onDestroy() {
                super.onDestroy();
-               Log.i(TAG, "Unregistering mPreviewImgObserver OnGlobalLayoutListener.");
+               Log.d(TAG, "Unregister 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.
-               return true;
-       }
-
        @Override
        public void onGlobalLayout() {
                if (mPdfLoaded) {
@@ -107,6 +150,7 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv
                try {
                        String picturePath = mComponentRootPath + SKODA_COMP_PICTURE_NAME;
                        Log.i(TAG, "Path to component files: " + picturePath);
+                       Log.d(TAG, "Loading PDF file " + picturePath);
                        mPdfView = new PdfPageView(getApplicationContext(), picturePath);
                        mPdfView.setPage(0);
                        new LoadPageTask().execute();
@@ -114,6 +158,7 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv
                        mPdfLoaded = true;
 
                } catch (Exception e) {
+                       Log.e(TAG, "Component picture loading from PDF file failed: " + e.getMessage());
                        Toast toast = Toast.makeText(getApplicationContext(), "Component preview could not be loaded.", Toast.LENGTH_LONG);
                        toast.show();
                        e.printStackTrace();
@@ -121,33 +166,37 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv
        }
 
        /**
-        * Called when the user touches the button
+        * Called when the user touches the button Contacts.
         */
        public void showContacts(View view) {
                showPDF(mComponentRootPath + SKODA_COMP_CONTACTS);
        }
 
        /**
-        * Called when the user touches the button
+        * Called when the user touches the button Manufacturing.
         */
        public void showManufacturing(View view) {
                showPDF(mComponentRootPath + SKODA_COMP_MANUFACTURING);
        }
 
        /**
-        * Called when the user touches the button
+        * Called when the user touches the button Manufacturing pictured
         */
        public void showManufactImages(View view) {
                showPDF(mComponentRootPath + SKODA_COMP_MANUFACT_IMAGES);
        }
 
        /**
-        * Called when the user touches the button
+        * Called when the user touches the button Manufacture guide
         */
        public void showManufactGuide(View view) {
                showPDF(mComponentRootPath + SKODA_COMP_MANUFACT_GUIDE);
        }
 
+       /**
+        * Launch an activity to show the PDF file.
+        * @param filePath Path to the PDF file to be shown
+        */
        private void showPDF(String filePath) {
                Uri uri = Uri.parse(filePath);
                Intent pdfIntent = new Intent(this, MuPDFActivity.class);
@@ -156,6 +205,9 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv
                startActivity(pdfIntent);
        }
 
+       /**
+        * Class for asynchronous loading of the PDF page to a bitmap.
+        */
        private class LoadPageTask extends AsyncTask<Void, Void, Void> {
 
                @Override
@@ -175,6 +227,7 @@ public class PreviewActivity extends ActionBarActivity implements ViewTreeObserv
                protected void onPostExecute(Void aVoid) {
                        super.onPostExecute(aVoid);
                        mProgressContainer.setVisibility(View.INVISIBLE);
+                       mPreviewImg.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                        mPreviewImg.setImageBitmap(mPdfView.getPageBitmap());
                        mPreviewImg.invalidate();
                        Log.d(TAG, "PDF page loaded.");
index 7e18f177f0a8b0843db1da7c84b626163ae5abfd..af58fc3a2d9d39167902b16709c8728c34948dc2 100644 (file)
@@ -12,9 +12,13 @@ import java.io.File;
 import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
 
 /**
- * Created by Michal Horn on 16.2.15.
+ * View for viewing PDF page.
+ *
+ * This view is designed to be used in two ways.
+ * 1) To view the PDF page itself on the device, which is supported by an interface for scrolling, zooming, switching pages and loading pages.
+ * 2) To load the PDF page to a bitmap, which can be accessed in the program by calling getPageBitmap() method.
  */
-public class PdfPageView  extends View {
+public class PdfPageView extends View {
        /**
         * Value with some allowed minimum and maximum.
         * @author Michal Horn
@@ -172,10 +176,18 @@ public class PdfPageView  extends View {
                Log.i(TAG, "Pages: " + mPage.toString());
        }
 
+       /**
+        * Get actual page. The actual page can be selected by setPage() method.
+        * @return actual page.
+        */
        public int getActualPage() {
                return mPage.getValue();
        }
 
+       /**
+        * Get total number of pages in the document
+        * @return total number of pages
+        */
        public int getLastPage() {
                return mPage.getMaximum();
        }
@@ -184,6 +196,12 @@ public class PdfPageView  extends View {
                return mPage.setValue(page);
        }
 
+       /**
+        * Load PDF and convert selected page to a bitmap.
+        *
+        * The page of the PDF document can be selected by setPage() method.
+        * This method can take significant time to finish. Consider calling it in separated thread.
+        */
        public void loadPage() {
                long startTime = System.currentTimeMillis();
                try {
@@ -199,7 +217,7 @@ public class PdfPageView  extends View {
                        mYPosition = new IntervalValue<>(360.0f/2, -mSceneHeight+360.0f/2, mSceneHeight+360.0f/2);
                        mZoom = new IntervalValue<>(1.0f, 0.2f, 2.0f);
                } catch (Exception e) {
-                       Log.e(TAG, "Error in setting page dimensions.");
+                       Log.e(TAG, "Error in setting page dimensions: " + e.getMessage());
                        e.printStackTrace();
                }
                long endTime = System.currentTimeMillis();
@@ -210,12 +228,14 @@ public class PdfPageView  extends View {
                }
        }
 
+       /**
+        * Get PDF page bitmap
+        * @return Bitmap of the PDF page or null, if it has not been yet loaded.
+        */
        public Bitmap getPageBitmap() {
                return mPdfBitmap;
        }
 
-
-
        /**
         * Set a listener of the events
         * @param listener listener of the events
@@ -224,6 +244,9 @@ public class PdfPageView  extends View {
                mListener = listener;
        }
 
+       /**
+        * Clear listener.
+        */
        public void clearListener() {
                mListener = null;
        }
@@ -237,7 +260,7 @@ public class PdfPageView  extends View {
                if (!mPageLoaded) return;
                float ratio = mZoom.getValue();
                ratio += deltaRatio;
-               if (mZoom.setValue(ratio) == true && mListener != null) {
+               if (mZoom.setValue(ratio) && mListener != null) {
                        mListener.onViewChanged(this);
                }
        }
index 36cf10596da6e22ee970c5fc6a5bf996c3b359aa..5aa1835020016f359f732b782d505d1becff31dc 100644 (file)
@@ -1,7 +1,9 @@
 package cz.cvut.fel.dce.qrscanner.pdfviewer;
 
 /**
- * Created by michal on 16.2.15.
+ * Custom Viewer exception class
+ *
+ * Instances of this Exception class are thrown by the PdfPageView widget.
  */
 public class PdfViewerException extends Exception {
        PdfViewerException(String s){
index 818eb65be30b4a0bd4b5c478a047d63c428f1494..ccb1be8a32b299f7366445451c3e186c42b23edc 100644 (file)
@@ -51,7 +51,6 @@
                     android:id="@+id/butManufactImages"
                     android:onClick="showManufactImages"
                     android:layout_gravity="center_horizontal"
-                    android:layout_column="0"
                     android:layout_below="@+id/textView4"
                     android:layout_alignParentLeft="true"
                     android:layout_alignParentStart="true"
@@ -64,7 +63,6 @@
                     android:id="@+id/butManufactGuide"
                     android:onClick="showManufactGuide"
                     android:layout_gravity="center_horizontal"
-                    android:layout_column="0"
                     android:layout_above="@+id/textView4"
                     android:layout_alignParentLeft="true"
                     android:layout_alignParentStart="true"
@@ -91,7 +89,6 @@
                     android:text="@string/butContacts"
                     android:id="@+id/butContacts"
                     android:onClick="showContacts"
-                    android:layout_column="0"
                     android:layout_below="@+id/textView5"
                     android:layout_alignParentLeft="true"
                     android:layout_alignParentStart="true"
                     android:id="@+id/butManufacturing"
                     android:onClick="showManufacturing"
                     android:layout_gravity="center_horizontal"
-                    android:layout_column="0"
                     android:layout_above="@+id/textView5"
                     android:layout_alignParentLeft="true"
                     android:layout_alignParentStart="true"
             android:layout_height="match_parent"
             android:id="@+id/imgComponent"
             android:layout_gravity="center_horizontal"
-            android:scaleType="center"/>
+            android:scaleType="center"
+            android:contentDescription="@string/preview_content_desc"/>
 
         <RelativeLayout
             android:layout_width="73dp"
index 42faebd255283250e17960bed381b487585e9e51..27c684f171abf443b606a15bba485e504bc7ac0d 100644 (file)
@@ -19,7 +19,8 @@
         android:layout_alignParentLeft="true"
         android:layout_alignParentStart="true"
         android:onClick="findComponent"
-        android:layout_above="@+id/button"/>
+        android:layout_above="@+id/button"
+        android:contentDescription="@string/skoda_logo_content_desc"/>
 
     <Button
         android:layout_width="wrap_content"
index f2afe0295ec9bab9a570dcb5f9f4a1b0ef14ce2f..984c094180f27c59262ebbe5909c870fb954741f 100644 (file)
@@ -59,7 +59,8 @@
             android:layout_height="match_parent"
             android:id="@+id/imgComponent"
             android:layout_gravity="center_vertical"
-            android:scaleType="center"/>
+            android:scaleType="center"
+            android:contentDescription="@string/preview_content_desc"/>
 
         <RelativeLayout
             android:layout_width="73dp"
index 1d7a6c0bdfbee01b06c5a1c16c8d42ffccf36cf6..7a8d7db0ec6eb44317a095f06c2703c06cf9d3d4 100644 (file)
@@ -66,6 +66,8 @@
     <string name="butManufacturingGuide">Workshop manual</string>
     <string name="previewHeading">Select document to view</string>
     <string name="loading_page">Loading...</string>
+    <string name="preview_content_desc">Component preview image</string>
+    <string name="skoda_logo_content_desc">Skoda auto logo</string>
 
 
 </resources>