}
}
+task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs') {
+ destinationDir file("$buildDir/native-libs")
+ baseName 'native-libs'
+ extension 'jar'
+ from fileTree(dir: 'libs', include: '**/*.so')
+ into 'lib/'
+}
+
+tasks.withType(JavaCompile) {
+ compileTask -> compileTask.dependsOn(nativeLibsToJar)
+}
+
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
- compile files('libs/PdfViewer.jar')
- compile files('libs/iocommons.jar')
+ compile files('build/native-libs/native-libs.jar')
}
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+ <excludeFolder url="file://$MODULE_DIR$/build/native-libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
+ <orderEntry type="library" exported="" name="native-libs" level="project" />
<orderEntry type="library" exported="" name="iocommons" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="PdfViewer" level="project" />
android:name=".PreviewActivity"
android:label="@string/title_activity_preview" >
</activity>
+ <activity
+ android:name="cz.cvut.fel.dce.qrscanner.mupdf.MuPDFActivity"
+ android:label="@string/app_name"> // android:theme="@style/AppBaseTheme"
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+
+ <data android:mimeType="application/vnd.ms-xpsdocument" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+
+ <data android:mimeType="application/pdf" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+
+ <data android:mimeType="application/x-cbz" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data android:scheme="file" />
+ <data android:mimeType="*/*" />
+ <data android:pathPattern=".*\\.xps" />
+ <data android:host="*" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data android:scheme="file" />
+ <data android:mimeType="*/*" />
+ <data android:pathPattern=".*\\.pdf" />
+ <data android:host="*" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data android:scheme="file" />
+ <data android:mimeType="*/*" />
+ <data android:pathPattern=".*\\.cbz" />
+ <data android:host="*" />
+ </intent-filter>
+ </activity>
</application>
</manifest>
package cz.cvut.fel.dce.qrscanner;
-import android.content.Context;
import android.content.Intent;
-import android.content.res.AssetManager;
-import android.graphics.Bitmap;
-import android.graphics.RectF;
-import android.support.annotation.Nullable;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import com.sun.pdfview.PDFFile;
-import com.sun.pdfview.PDFPage;
-
-import net.sf.andpdf.nio.ByteBuffer;
-
-import org.apache.commons.io.IOUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-
import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
package cz.cvut.fel.dce.qrscanner;
-import android.content.Context;
import android.content.Intent;
-import android.content.res.AssetManager;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.RectF;
-import android.net.Uri;
-import android.os.Environment;
-import android.support.annotation.Nullable;
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.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.Toast;
-import com.sun.pdfview.PDFFile;
-import com.sun.pdfview.PDFPage;
-
-import net.sf.andpdf.nio.ByteBuffer;
-
-import org.apache.commons.io.IOUtils;
-
+import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-public class PreviewActivity extends ActionBarActivity {
+public class PreviewActivity extends ActionBarActivity 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.png";
+ public static final String SKODA_COMP_PICTURE_NAME = "Abbildung.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);
+ mPreviewImgObserver = mPreviewImg.getViewTreeObserver();
+ Log.i(TAG, "Registering mPreviewImgObserver OnGlobalLayoutListener.");
+ mPreviewImgObserver.addOnGlobalLayoutListener(this);
+
Intent intent = getIntent();
- String comp_id = intent.getStringExtra("COMPONENT_ID");
- if (comp_id != null) {
- Log.i(TAG, "Received component id: " + comp_id);
- String path = "/storage/sdcard0/Pictures" + SKODA_DOCS_PATH_EXTENSION + comp_id + "/";
- String picturePath = path + SKODA_COMP_PICTURE_NAME;
- Log.i(TAG, "Path to files: " + picturePath);
- Bitmap previewBitmap = new BitmapFactory().decodeFile(picturePath);
- if (previewBitmap != null) {
- ImageView previewImg = (ImageView) findViewById(R.id.imgComponent);
- previewImg.setImageBitmap(previewBitmap);
- Uri uri = Uri.parse(path + "Bild_Arbeitseinleitung.pdf");
- Intent pdfIntent = new Intent(this,MuPDFActivity.class);
- pdfIntent.setAction(Intent.ACTION_VIEW);
- pdfIntent.setData(uri);
- startActivity(intent);
- }
- else {
- Toast toast = Toast.makeText(getApplicationContext(), "File not found", Toast.LENGTH_LONG);
+ 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();
}
}
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ Log.i(TAG, "Unregistering mPreviewImgObserver OnGlobalLayoutListener.");
+ if (mPreviewImgObserver.isAlive()) {
+ mPreviewImgObserver.removeOnGlobalLayoutListener(this);
+ }
+ }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onOptionsItemSelected(item);
}
- /**
- * Use this to load a pdf file from your assets and render it to a Bitmap.
- *
- * @param context
- * current context.
- * @param filePath
- * of the pdf file in the assets.
- * @return a bitmap.
- */
- @Nullable
- private static Bitmap renderToBitmap(Context context, String filePath) {
- Bitmap bi = null;
- InputStream inStream = null;
- try {
- Log.d(TAG, "Attempting to copy this file: " + filePath);
- inStream = new FileInputStream(new File(filePath));
- bi = renderToBitmap(context, inStream);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
+ @Override
+ public void onGlobalLayout() {
+ if (mPreviewImg != null) {
try {
- if (inStream != null) {
- inStream.close();
- }
- } catch (IOException e) {
- // do nothing because the stream has already been closed
- }
- }
- return bi;
- }
+ String picturePath = mComponentRootPath + SKODA_COMP_PICTURE_NAME;
+ Log.i(TAG, "Path to component files: " + picturePath);
- /**
- * Use this to render a pdf file given as InputStream to a Bitmap.
- *
- * @param context
- * current context.
- * @param inStream
- * the inputStream of the pdf file.
- * @return a bitmap.
- */
- @Nullable
- private static Bitmap renderToBitmap(Context context, InputStream inStream) {
- Bitmap bi = null;
- try {
- byte[] decode = IOUtils.toByteArray(inStream);
- ByteBuffer buf = ByteBuffer.wrap(decode);
- PDFFile pdfFile = new PDFFile(buf);
- int numPages = pdfFile.getNumPages();
- Log.i(TAG, "Num pages: " + Integer.toString(numPages));
- PDFPage mPdfPage = new PDFFile(buf).getPage(0);
- float width = mPdfPage.getWidth();
- float height = mPdfPage.getHeight();
- RectF clip = null;
- bi = mPdfPage.getImage((int) (width), (int) (height), clip, false,
- true);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- inStream.close();
- } catch (IOException e) {
- // do nothing because the stream has already been closed
+ 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();
}
}
- return bi;
+ else {
+ Log.e(TAG, "ImageView for preview image could not be found in the resources.");
+ }
}
}
<string name="action_settings">Settings</string>
<string name="start_scan">Scan</string>
<string name="title_activity_preview">PreviewActivity</string>
+ <string name="version">1.6 (git build)</string>
+ <string name="no_media_warning">Storage media not present</string>
+ <string name="no_media_hint">Sharing the storage media with a PC can make it inaccessible</string>
+ <string name="cancel">Cancel</string>
+ <string name="search_backwards">Search backwards</string>
+ <string name="search_forwards">Search forwards</string>
+ <string name="search_document">Search document</string>
+ <string name="picker_title_App_Ver_Dir">%1$s %2$s: %3$s</string>
+ <string name="outline_title">Table of Contents</string>
+ <string name="enter_password">Enter password</string>
+ <string name="text_not_found">Text not found</string>
+ <string name="searching_">Searching…</string>
+ <string name="toggle_links">Highlight and enable links</string>
+ <string name="no_further_occurrences_found">No further occurrences found</string>
+ <string name="select">Select</string>
+ <string name="search">Search</string>
+ <string name="copy">Copy</string>
+ <string name="strike_out">Strike-out</string>
+ <string name="delete">Delete</string>
+ <string name="highlight">Highlight</string>
+ <string name="underline">Underline</string>
+ <string name="edit_annotations">Edit annotations</string>
+ <string name="ink">Ink</string>
+ <string name="save">Save</string>
+ <string name="print">Print</string>
+ <string name="dismiss">Dismiss</string>
+ <string name="parent_directory">[Up one level]</string>
+ <string name="yes">Yes</string>
+ <string name="no">No</string>
+ <string name="entering_reflow_mode">Entering reflow mode</string>
+ <string name="leaving_reflow_mode">Leaving reflow mode</string>
+ <string name="print_failed">Print failed</string>
+ <string name="select_text">Select text</string>
+ <string name="copied_to_clipboard">Copied to clipboard</string>
+ <string name="no_text_selected">No text selected</string>
+ <string name="draw_annotation">Draw annotation</string>
+ <string name="nothing_to_save">Nothing to save</string>
+ <string name="document_has_changes_save_them_">Document has changes. Save them?</string>
+ <string name="cannot_open_document">Cannot open document</string>
+ <string name="cannot_open_document_Reason">Cannot open document: %1$s</string>
+ <string name="cannot_open_file_Path">Cannot open file: %1$s</string>
+ <string name="cannot_open_buffer">Cannot open buffer</string>
+ <string name="fill_out_text_field">Fill out text field</string>
+ <string name="okay">Okay</string>
+ <string name="choose_value">Choose value</string>
+ <string name="not_supported">Not supported</string>
+ <string name="copy_text_to_the_clipboard">Copy text to the clipboard</string>
+ <string name="more">More</string>
+ <string name="accept">Accept</string>
+ <string name="copy_text">copy text</string>
+ <string name="format_currently_not_supported">Format currently not supported</string>
+ <string name="toggle_reflow_mode">Toggle reflow mode</string>
</resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
-
+ <style name="AppBaseTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
+ <item name="android:windowBackground">@drawable/tiled_background</item>
+ </style>
</resources>