1 |
package dk.thoerup.side9; |
package dk.thoerup.side9; |
2 |
|
|
3 |
import java.io.File; |
|
|
import java.io.IOException; |
|
|
import java.io.RandomAccessFile; |
|
4 |
import java.util.ArrayList; |
import java.util.ArrayList; |
5 |
|
|
6 |
import android.app.Activity; |
import android.app.Activity; |
25 |
TextView mDescription; |
TextView mDescription; |
26 |
TextView mCaption; |
TextView mCaption; |
27 |
ImageView mImageView; |
ImageView mImageView; |
28 |
ArrayList<String> mImagePaths; |
ArrayList<ImageEntry> mImagePaths; |
29 |
int mIndex; |
int mIndex; |
30 |
|
|
31 |
|
|
37 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
38 |
setContentView(R.layout.pictureview); |
setContentView(R.layout.pictureview); |
39 |
|
|
40 |
mImagePaths = (ArrayList<String>) getIntent().getSerializableExtra("files"); |
mImagePaths = (ArrayList<ImageEntry>) getIntent().getSerializableExtra("images"); |
41 |
mIndex = getIntent().getIntExtra("index", 0); |
mIndex = getIntent().getIntExtra("index", 0); |
42 |
|
|
43 |
|
|
63 |
} |
} |
64 |
|
|
65 |
private void loadImage() { |
private void loadImage() { |
66 |
String currentFile = mImagePaths.get(mIndex); |
ImageEntry currentImage = mImagePaths.get(mIndex); |
67 |
mBitmap = BitmapFactory.decodeFile( currentFile ); |
mBitmap = BitmapFactory.decodeFile( currentImage.path ); |
68 |
mImageView.setImageBitmap(mBitmap); |
mImageView.setImageBitmap(mBitmap); |
69 |
|
|
70 |
|
|
71 |
String pathParts[] = currentFile.split("/"); |
if (currentImage.caption.length() > 0) { |
|
String fileName = pathParts[ pathParts.length -1]; |
|
|
String desc = "" + (mIndex +1) + "/" + mImagePaths.size() + " - " + fileName; |
|
|
mDescription.setText(desc); |
|
|
|
|
|
String infoFileName = currentFile.replace(".jpg", ".txt"); |
|
|
|
|
|
File infoFile = new File(infoFileName); |
|
|
if (infoFile.exists() ) { |
|
|
String caption = getFileContent(infoFile); |
|
72 |
mCaption.setVisibility(View.VISIBLE); |
mCaption.setVisibility(View.VISIBLE); |
73 |
mCaption.setText(caption); |
mCaption.setText(currentImage.caption); |
|
|
|
74 |
} else { |
} else { |
75 |
mCaption.setVisibility(View.INVISIBLE); |
mCaption.setVisibility(View.INVISIBLE); |
76 |
} |
} |
77 |
|
|
78 |
|
String pathParts[] = currentImage.path.split("/"); |
79 |
|
String fileName = pathParts[ pathParts.length -1]; |
80 |
|
String desc = "" + (mIndex +1) + "/" + mImagePaths.size() + " - " + fileName; |
81 |
|
mDescription.setText(desc); |
82 |
} |
} |
83 |
|
|
|
String getFileContent(File filename) { |
|
|
try { |
|
|
RandomAccessFile raf = new RandomAccessFile(filename, "r"); |
|
|
int size = (int)raf.length(); |
|
|
byte buf[] = new byte[size]; |
|
|
|
|
|
raf.readFully(buf); |
|
|
return new String(buf); |
|
|
} catch (IOException e) { |
|
|
Log.e(TAG, "Error", e); |
|
|
return ""; |
|
|
} |
|
|
} |
|
84 |
|
|
85 |
|
|
|
|
|
86 |
@Override |
@Override |
87 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
88 |
MenuItem item = menu.add(Menu.NONE, CONTEXT_VIEWIMG, Menu.NONE, "Built-in viewer"); |
MenuItem item = menu.add(Menu.NONE, CONTEXT_VIEWIMG, Menu.NONE, "Built-in viewer"); |