From: Michal Horn Date: Wed, 11 Feb 2015 16:46:14 +0000 (+0100) Subject: Implement first version of the Preview activity X-Git-Url: http://rtime.felk.cvut.cz/gitweb/hornmich/skoda-qr-demo.git/commitdiff_plain/0a44a316d4f3c76afd6ed023ff4f7ccdfb21795f Implement first version of the Preview activity The Glass module is not compilable because MuPDF dependecies are not fulfulled. --- diff --git a/QRScanner/glass/src/main/AndroidManifest.xml b/QRScanner/glass/src/main/AndroidManifest.xml index b08a3d5..f67d177 100644 --- a/QRScanner/glass/src/main/AndroidManifest.xml +++ b/QRScanner/glass/src/main/AndroidManifest.xml @@ -18,6 +18,10 @@ android:name="com.google.android.glass.VoiceTrigger" android:resource="@xml/voice_trigger" /> + + 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 index 0000000..5ae8e59 --- /dev/null +++ b/QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/PreviewActivity.java @@ -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); + } +} diff --git a/QRScanner/glass/src/main/res/values/strings.xml b/QRScanner/glass/src/main/res/values/strings.xml index cf43073..e277cdf 100644 --- a/QRScanner/glass/src/main/res/values/strings.xml +++ b/QRScanner/glass/src/main/res/values/strings.xml @@ -15,8 +15,12 @@ See the License for the specific language governing permissions and limitations under the License. --> - Skoda Demo + Skoda Manufacturer Helper + Scan + Component preview Skoda Demo Skoda Demo + Stop + Scan code