Commit 7f20cc77 authored by Kristin Muterspaw's avatar Kristin Muterspaw
Browse files

Updated MyDocumentViewer to display images as well as pdfs.

parent 66e79553
......@@ -2,6 +2,7 @@ package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.pdf.PdfRenderer;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
......@@ -17,35 +18,44 @@ public class MyDocumentViewer extends Activity {
File fileToOpen;
private static int index = 0;
private ImageView pdfImageView;
private ImageView docImageView;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mydocviewier);
pdfImageView = (ImageView) findViewById(R.id.pdfView);
docImageView = (ImageView) findViewById(R.id.myDocView);
fileToOpen = (File) getIntent().getExtras().get("fileToOpen");
if (fileToOpen.getName().endsWith(".pdf")){
openPDF();
Log.d("Open PDF", fileToOpen.getName());
} else if (fileToOpen.getName().endsWith(".jpeg") || fileToOpen.getName().endsWith("jpg") ||
fileToOpen.getName().endsWith(".png")){
displayImage();
Log.d("Open JPEG", fileToOpen.getName());
}
}
public void openPDF(){
public void openPDF() {
try {
ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.open(fileToOpen, ParcelFileDescriptor.MODE_READ_ONLY);
PdfRenderer pdfRenderer = new PdfRenderer(fileDescriptor);
PdfRenderer.Page page = pdfRenderer.openPage(index);
int count = pdfRenderer.getPageCount();
Bitmap pdf = Bitmap.createBitmap(page.getWidth(), page.getHeight(), Bitmap.Config.ARGB_8888);
page.render(pdf, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
pdfImageView.setImageBitmap(pdf);
docImageView.setImageBitmap(pdf);
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
}
public void displayImage() {
Bitmap image = BitmapFactory.decodeFile(fileToOpen.getAbsolutePath());
docImageView.setImageBitmap(image);
}
}
......@@ -6,34 +6,9 @@
android:layout_height="match_parent">
<ImageView
android:id="@+id/pdfView"
android:id="@+id/myDocView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/white"
android:scaleType="fitCenter" />
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:measureWithLargestChild="true"
android:orientation="horizontal" >
<Button
android:id="@+id/previous"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Previous" />
<Button
android:id="@+id/next"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Next" />
</LinearLayout>
android:background="@android:color/black"
android:layout_weight="1" />
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment