import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
+import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.io.File;
-import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFActivity;
import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview);
mPreviewImg = (ImageView) findViewById(R.id.imgComponent);
+ mPreviewImg.setMaxWidth(640);
+ mPreviewImg.setMaxHeight(360);
+ mPreviewImg.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
+
if (mPreviewImg != null) {
mPreviewImgObserver = mPreviewImg.getViewTreeObserver();
Log.i(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
Log.i(TAG, "Path to component files: " + picturePath);
MuPDFCore core = new MuPDFCore(getApplicationContext(), picturePath);
+ Log.d(TAG, "numpages: "+ core.countPages());
MuPDFCore.Cookie cookie = core.new Cookie();
- int previewW = mPreviewImg.getWidth();
- int previewH = mPreviewImg.getHeight();
+ int pageW = (int)core.getPageSize(0).x;
+ int pageH = (int)core.getPageSize(0).y;
+ Log.d(TAG, "page size: " + pageW + ", " + pageH);
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);
+ Bitmap previewBitmap = Bitmap.createBitmap(pageW, pageH, conf);
+ core.drawPage(previewBitmap, 0, pageW, pageH,0 , 0, pageW, pageH, cookie);
mPreviewImg.setImageBitmap(previewBitmap);
+ mPreviewImg.invalidate();
} catch (Exception e) {
Toast toast = Toast.makeText(getApplicationContext(), "Component preview could not be loaded.", Toast.LENGTH_LONG);
toast.show();
}
/** Called when the user touches the button */
- public void showContacts(View view) {
+ public void showContacts() {
showPDF(mComponentRootPath + SKODA_COMP_CONTACTS);
}
/** Called when the user touches the button */
- public void showManufacturing(View view) {
+ public void showManufacturing() {
showPDF(mComponentRootPath + SKODA_COMP_MANUFACTURING);
}
/** Called when the user touches the button */
- public void showManufactImages(View view) {
+ public void showManufactImages() {
showPDF(mComponentRootPath + SKODA_COMP_MANUFACT_IMAGES);
}
/** Called when the user touches the button */
- public void showManufactGuide(View view) {
+ public void showManufactGuide() {
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);
+ Intent pdfIntent = new Intent("com.artifex.mupdfdemo.VIEW");
+ //pdfIntent.setAction(Intent.ACTION_VIEW);
pdfIntent.setData(uri);
startActivity(pdfIntent);
}
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+ openOptionsMenu();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
+ if (id == R.id.show_contacts) {
+ showContacts();
return true;
}
-
- return super.onOptionsItemSelected(item);
+ else if (id == R.id.show_manufacturing) {
+ showManufacturing();
+ return true;
+ }
+ else if (id == R.id.show_pictured_manufacturing) {
+ showManufactImages();
+ return true;
+ }
+ else if (id == R.id.show_workshop) {
+ showManufactGuide();
+ return true;
+ }
+ else if (id == R.id.stop) {
+ finish();
+ return true;
+ }
+ else {
+ return super.onOptionsItemSelected(item);
+ }
}
}