ObjectViewerpublic class ObjectViewer extends android.app.Activity implements View.OnClickListenerA view to display the properties of an object. |
Fields Summary |
---|
private static final String | TAG | private MtpClient | mClient | private String | mDeviceName | private int | mStorageID | private int | mObjectID | private String | mFileName | private android.widget.Button | mImportButton | private android.widget.Button | mDeleteButton | private DeviceDisconnectedReceiver | mDisconnectedReceiver | private android.media.MediaScannerConnection | mScannerConnection | private ScannerClient | mScannerClient |
Methods Summary |
---|
private void | deleteObject()
if (mClient.deleteObject(mDeviceName, mObjectID)) {
Toast.makeText(this, R.string.object_deleted_message, Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(this, R.string.delete_failed_message, Toast.LENGTH_SHORT).show();
}
| private void | importObject()
// copy file to /mnt/sdcard/imported/<filename>
File dest = Environment.getExternalStorageDirectory();
dest = new File(dest, "imported");
dest.mkdirs();
dest = new File(dest, mFileName);
if (mClient.importFile(mDeviceName, mObjectID, dest.getAbsolutePath())) {
Toast.makeText(this, R.string.object_saved_message, Toast.LENGTH_SHORT).show();
mScannerClient.setScanPath(dest.getAbsolutePath());
mScannerConnection.connect();
} else {
Toast.makeText(this, R.string.save_failed_message, Toast.LENGTH_SHORT).show();
}
| public void | onClick(android.view.View v)
if (v == mImportButton) {
importObject();
} else if (v == mDeleteButton) {
deleteObject();
}
| protected void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
mClient = ((CameraBrowserApplication)getApplication()).getMtpClient();
setContentView(R.layout.object_info);
mImportButton = (Button)findViewById(R.id.import_button);
mImportButton.setOnClickListener(this);
mDeleteButton = (Button)findViewById(R.id.delete_button);
mDeleteButton.setOnClickListener(this);
mDeviceName = getIntent().getStringExtra("device");
mStorageID = getIntent().getIntExtra("storage", 0);
mObjectID = getIntent().getIntExtra("object", 0);
mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceName);
mScannerClient = new ScannerClient(this);
mScannerConnection = new MediaScannerConnection(this, mScannerClient);
| protected void | onDestroy()
unregisterReceiver(mDisconnectedReceiver);
super.onDestroy();
| protected void | onResume()
super.onResume();
MtpObjectInfo info = mClient.getObjectInfo(mDeviceName, mObjectID);
if (info != null) {
TextView view = (TextView)findViewById(R.id.name);
mFileName = info.getName();
view.setText(mFileName);
view = (TextView)findViewById(R.id.format);
view.setText(Integer.toHexString(info.getFormat()).toUpperCase(Locale.ROOT));
view = (TextView)findViewById(R.id.size);
view.setText(Long.toString(info.getCompressedSize()));
view = (TextView)findViewById(R.id.thumb_width);
view.setText(Long.toString(info.getThumbPixWidth()));
view = (TextView)findViewById(R.id.thumb_height);
view.setText(Long.toString(info.getThumbPixHeight()));
view = (TextView)findViewById(R.id.thumb_size);
view.setText(Long.toString(info.getThumbCompressedSize()));
view = (TextView)findViewById(R.id.width);
view.setText(Long.toString(info.getImagePixWidth()));
view = (TextView)findViewById(R.id.height);
view.setText(Long.toString(info.getImagePixHeight()));
view = (TextView)findViewById(R.id.depth);
view.setText(Long.toString(info.getImagePixDepth()));
view = (TextView)findViewById(R.id.sequence);
view.setText(Long.toString(info.getSequenceNumber()));
view = (TextView)findViewById(R.id.created);
Date date = new Date(info.getDateCreated() * 1000);
view.setText(date.toString());
view = (TextView)findViewById(R.id.modified);
date = new Date(info.getDateModified() * 1000);
view.setText(date.toString());
view = (TextView)findViewById(R.id.keywords);
view.setText(info.getKeywords());
int thumbFormat = info.getThumbFormat();
if (thumbFormat == MtpConstants.FORMAT_EXIF_JPEG
|| thumbFormat == MtpConstants.FORMAT_JFIF) {
byte[] thumbnail = mClient.getThumbnail(mDeviceName, info.getObjectHandle());
if (thumbnail != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length);
if (bitmap != null) {
ImageView thumbView = (ImageView)findViewById(R.id.thumbnail);
thumbView.setImageBitmap(bitmap);
}
}
}
}
|
|