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')
}
<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="iocommons" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
+ <orderEntry type="library" exported="" name="PdfViewer" level="project" />
</component>
</module>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.cvut.fel.dce.qrscanner" >
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19"
+ android:maxSdkVersion="21" />
<application
android:allowBackup="true"
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name=".PreviewActivity"
+ android:label="@string/title_activity_preview" >
+ </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;
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
Log.i(TAG, scanResult.toString());
+ Intent preview = new Intent(this, PreviewActivity.class);
+ preview.putExtra("COMPONENT_ID", scanResult.getContents());
+ startActivity(preview);
}
// else continue with any other code you need in the method
--- /dev/null
+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.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 java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+
+public class PreviewActivity extends ActionBarActivity {
+ public static final String TAG = "PreviewActivity";
+ public static final String SKODA_DOCS_PATH_EXTENSION = "/skoda/components/";
+ public static final String SKODA_COMP_PICTURE_NAME = "Abbildung.png";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_preview);
+ 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);
+ toast.show();
+ finish();
+ }
+ }
+ else {
+ Log.i(TAG, "No component id received");
+ finish();
+ }
+ }
+
+
+ @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 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);
+ }
+
+ /**
+ * 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 {
+ try {
+ if (inStream != null) {
+ inStream.close();
+ }
+ } catch (IOException e) {
+ // do nothing because the stream has already been closed
+ }
+ }
+ return bi;
+ }
+
+ /**
+ * 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
+ }
+ }
+ return bi;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="299dp"
+ android:layout_height="match_parent"
+ android:weightSum="1">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="Select document to view"
+ android:id="@+id/textView2"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Kontakty"
+ android:id="@+id/button"
+ android:layout_gravity="center_horizontal"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Vyrobni postup"
+ android:id="@+id/button2"
+ android:layout_gravity="center_horizontal"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Obrazovy vyrobni postup"
+ android:id="@+id/button3"
+ android:layout_gravity="center_horizontal"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Dilenska prirucka"
+ android:id="@+id/button4"
+ android:layout_gravity="center_horizontal"/>
+ </LinearLayout>
+
+ <ImageView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/imgComponent"
+ android:layout_weight="0.95"
+ android:layout_gravity="center_horizontal"/>
+
+</LinearLayout>
\ No newline at end of file
--- /dev/null
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ tools:context="cz.cvut.fel.dce.qrscanner.PreviewActivity"
+ android:weightSum="1"
+ android:orientation="vertical">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="Select document to view"
+ android:id="@+id/textView"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Kontakty"
+ android:id="@+id/butContacts"
+ android:layout_gravity="center_horizontal"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Vyrobni postup"
+ android:id="@+id/butManufacturing"
+ android:layout_gravity="center_horizontal"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Obrazovy vyrobni postup"
+ android:id="@+id/butManufactImages"
+ android:layout_gravity="center_horizontal"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Dilenska prirucka"
+ android:id="@+id/butManufactGuide"
+ android:layout_gravity="center_horizontal"/>
+
+ <ImageView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/imgComponent"
+ android:layout_weight="0.95"
+ android:layout_gravity="center_vertical"/>
+
+</LinearLayout>
--- /dev/null
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ tools:context="cz.cvut.fel.dce.qrscanner.PreviewActivity">
+ <item android:id="@+id/action_settings"
+ android:title="@string/action_settings"
+ android:orderInCategory="100"
+ app:showAsAction="never"/>
+</menu>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="start_scan">Scan</string>
+ <string name="title_activity_preview">PreviewActivity</string>
</resources>