use of android.mtp.MtpObjectInfo in project android_frameworks_base by crdroidandroid.
the class MtpClient method getObjectList.
/**
* Retrieves a list of {@link android.mtp.MtpObjectInfo} for all objects
* on the MTP or PTP device with the given USB device name and given storage ID
* and/or object handle.
* If the object handle is zero, then all objects in the root of the storage unit
* will be returned. Otherwise, all immediate children of the object will be returned.
* If the storage ID is also zero, then all objects on all storage units will be returned.
*
* @param deviceName the name of the USB device
* @param storageId the ID of the storage unit to query, or zero for all
* @param objectHandle the handle of the parent object to query, or zero for the storage root
* @return the list of MtpObjectInfo
*/
public List<MtpObjectInfo> getObjectList(String deviceName, int storageId, int objectHandle) {
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
if (objectHandle == 0) {
// all objects in root of storage
objectHandle = 0xFFFFFFFF;
}
int[] handles = device.getObjectHandles(storageId, 0, objectHandle);
if (handles == null) {
return null;
}
int length = handles.length;
ArrayList<MtpObjectInfo> objectList = new ArrayList<MtpObjectInfo>(length);
for (int i = 0; i < length; i++) {
MtpObjectInfo info = device.getObjectInfo(handles[i]);
if (info == null) {
Log.w(TAG, "getObjectInfo failed");
} else {
objectList.add(info);
}
}
return objectList;
}
use of android.mtp.MtpObjectInfo in project android_frameworks_base by crdroidandroid.
the class ObjectBrowser method onListItemClick.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
MtpObjectInfo info = mObjectList.get(position);
Intent intent;
if (info.getFormat() == MtpConstants.FORMAT_ASSOCIATION) {
intent = new Intent(this, ObjectBrowser.class);
} else {
intent = new Intent(this, ObjectViewer.class);
}
intent.putExtra("device", mDeviceName);
intent.putExtra("storage", mStorageID);
intent.putExtra("object", info.getObjectHandle());
startActivity(intent);
}
use of android.mtp.MtpObjectInfo in project android_frameworks_base by crdroidandroid.
the class ObjectViewer method onResume.
@Override
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);
}
}
}
}
}
Aggregations