Search in sources :

Example 6 with MtpObjectInfo

use of android.mtp.MtpObjectInfo in project android_frameworks_base by ParanoidAndroid.

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;
}
Also used : MtpDevice(android.mtp.MtpDevice) ArrayList(java.util.ArrayList) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 7 with MtpObjectInfo

use of android.mtp.MtpObjectInfo in project android_frameworks_base by ParanoidAndroid.

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());
        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);
                }
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Date(java.util.Date) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 8 with MtpObjectInfo

use of android.mtp.MtpObjectInfo in project android_frameworks_base by ResurrectionRemix.

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;
}
Also used : MtpDevice(android.mtp.MtpDevice) ArrayList(java.util.ArrayList) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 9 with MtpObjectInfo

use of android.mtp.MtpObjectInfo in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : Intent(android.content.Intent) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 10 with MtpObjectInfo

use of android.mtp.MtpObjectInfo in project android_frameworks_base by ResurrectionRemix.

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);
                }
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Date(java.util.Date) MtpObjectInfo(android.mtp.MtpObjectInfo)

Aggregations

MtpObjectInfo (android.mtp.MtpObjectInfo)53 IOException (java.io.IOException)20 ParcelFileDescriptor (android.os.ParcelFileDescriptor)15 Cursor (android.database.Cursor)10 Intent (android.content.Intent)6 Bitmap (android.graphics.Bitmap)6 MtpDevice (android.mtp.MtpDevice)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)5 Point (android.graphics.Point)5 FileNotFoundException (java.io.FileNotFoundException)5