Example usage for android.net Uri getPath

List of usage examples for android.net Uri getPath

Introduction

In this page you can find the example usage for android.net Uri getPath.

Prototype

@Nullable
public abstract String getPath();

Source Link

Document

Gets the decoded path.

Usage

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

private void sendFiles(final ArrayList<Uri> filesToSend) {
    // send files in a separate task without a dialog so we don't leave the previous progress dialog behind on
    // screen rotation - this is a bit of a hack, but it works
    runImmediateBackgroundTask(new BackgroundRunnable() {
        @Override// w w  w .  ja v  a2 s.c  om
        public int getTaskId() {
            return 0;
        }

        @Override
        public boolean getShowDialog() {
            return false;
        }

        @Override
        public void run() {
            if (filesToSend == null || filesToSend.size() <= 0) {
                return;
            }

            // ensure files are accessible to send - bit of a last-ditch effort for when temp is on internal storage
            for (Uri fileUri : filesToSend) {
                IOUtilities.setFullyPublic(new File(fileUri.getPath()));
            }

            // also see: http://stackoverflow.com/questions/2344768/
            // could use application/smil+xml (or html), or video/quicktime, but then there's no bluetooth option
            final Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
            sendIntent.setType(getString(R.string.export_mime_type));
            sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend);

            final Intent chooserIntent = Intent.createChooser(sendIntent,
                    getString(R.string.export_narrative_title));

            // an extra activity at the start of the list that moves exported files to SD, but only if SD available
            if (IOUtilities.externalStorageIsWritable()) {
                final Intent targetedShareIntent = new Intent(MediaPhoneActivity.this,
                        SaveNarrativeActivity.class);
                targetedShareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                targetedShareIntent.setType(getString(R.string.export_mime_type));
                targetedShareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend);
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] { targetedShareIntent });
            }

            startActivity(chooserIntent); // single task mode; no return value given
        }
    });
}

From source file:com.abc.driver.PersonalActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == CellSiteConstants.TAKE_USER_PORTRAIT
            || requestCode == CellSiteConstants.PICK_USER_PORTRAIT) {
        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_USER_PORTRAIT) {
            uri = imageUri;//ww  w  . j  a va 2 s .  co m

        } else if (requestCode == CellSiteConstants.PICK_USER_PORTRAIT) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            imageUri = Uri.fromFile(new File(filePath));
        } else // This is a bug, in some cases, some images like
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().setProfileImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        doCrop();
        Log.d(TAG, "onActivityResult PICK_PICTURE");

    } else if (requestCode == CellSiteConstants.CROP_PICTURE) {
        Log.d(TAG, "crop picture");
        // processFile();

        if (data != null) {
            Bundle extras = data.getExtras();
            Bitmap photo = extras.getParcelable("data");

            app.setPortaritBitmap(photo);
            mUserPortraitIv.setImageBitmap(photo);
            mUpdateImageTask = new UpdateImageTask();
            mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(photo),
                    CellSiteConstants.UPDATE_USER_PORTRAIT_URL);

            isPortraitChanged = true;
        }
    } else if (requestCode == CellSiteConstants.TAKE_IDENTITY
            || requestCode == CellSiteConstants.PICK_IDENTITY) {

        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_IDENTITY) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_IDENTITY) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().setIdentityImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IDENTITY_IMAGE_WIDTH,
                CellSiteConstants.IDENTITY_IMAGE_HEIGHT, false);

        mUserIdentityIv.setImageBitmap(scaledBmp);
        // s isChanged = true;
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(scaledBmp),
                CellSiteConstants.UPDATE_USER_IDENTITY_URL);

    } else if (requestCode == CellSiteConstants.TAKE_DRIVER_LICENSE
            || requestCode == CellSiteConstants.PICK_DRIVER_LICENSE) {

        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_DRIVER_LICENSE) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_DRIVER_LICENSE) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().setDriverLicenseImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IDENTITY_IMAGE_WIDTH,
                CellSiteConstants.IDENTITY_IMAGE_HEIGHT, false);

        mUserDriverLicenseIv.setImageBitmap(scaledBmp);
        // s isChanged = true;
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), Utils.bitmap2String(scaledBmp),
                CellSiteConstants.UPDATE_DRIVER_LICENSE_URL);

    }
}

From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.//w  w  w .j  av a  2 s . c om
 *
 * @param context The context.
 * @param uri     The Uri to query.
 * @author paulburke
 */
@SuppressLint("NewApi")
public static String getPath(final Context context, final Uri uri) {

    String path = "";

    if (uri == null || uri.equals(Uri.EMPTY))
        return "";

    try {
        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
        // DocumentProvider
        if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
            if (isTurboDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                path = "/" + split[1];
            }
            // ExternalStorageProvider
            else if (isExternalStorageDocument(uri)) {

                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    path = Environment.getExternalStorageDirectory() + "/" + split[1];
                }

                // TODO handle non-primary volumes
            }
            // DownloadsProvider
            else if (isDownloadsDocument(uri)) {

                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris
                        .withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

                path = getDataColumn(context, contentUri, null, null);
            }
            // MediaProvider
            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }

                final String selection = "_id=?";
                final String[] selectionArgs = new String[] { split[1] };

                path = getDataColumn(context, contentUri, selection, selectionArgs);
            }
        }
        // MediaStore (and general)
        else if ("content".equalsIgnoreCase(uri.getScheme())) {
            path = getDataColumn(context, uri, null, null);
        }
        // File
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            path = uri.getPath();
        }
    } catch (Exception ex) {
        return "";
    }

    return path;
}

From source file:com.blueshit.activity.ChatActivity.java

/**
 * ??//from w  w  w .  j  ava2s  .c o m
 *
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        String st7 = getResources().getString(R.string.File_does_not_exist);
        Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_SHORT).show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m);
        Toast.makeText(getApplicationContext(), st6, Toast.LENGTH_SHORT).show();
        return;
    }

    // ?
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // ?chattype,??
    if (chatType == CHATTYPE_GROUP)
        message.setChatType(ChatType.GroupChat);

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}

From source file:com.abc.driver.TruckActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == CellSiteConstants.TAKE_PICTURE || requestCode == CellSiteConstants.PICK_PICTURE) {

        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_PICTURE) {
            uri = imageUri;//w  w  w.j av a2 s  . com

        } else if (requestCode == CellSiteConstants.PICK_PICTURE) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().getMyTruck().setLicenseImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        // doCrop();

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false);

        mTLPiv.setImageBitmap(scaledBmp);
        isPortraitChanged = true;
        Log.d(TAG, "onActivityResult PICK_PICTURE");
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(),
                Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_LICENSE_URL);

    } else if (requestCode == CellSiteConstants.CROP_PICTURE) {
        Log.d(TAG, "crop picture");
        // processFile();

        if (data != null) {
            Bundle extras = data.getExtras();
            Bitmap photo = extras.getParcelable("data");

            trcukLicenseBmp = photo;
            mTLPiv.setImageBitmap(trcukLicenseBmp);
            mUpdateImageTask = new UpdateImageTask();
            mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(),
                    Utils.bitmap2String(trcukLicenseBmp), CellSiteConstants.UPDATE_DRIVER_LICENSE_URL);

            isPortraitChanged = true;
        }
    } else if (requestCode == CellSiteConstants.TAKE_PICTURE2
            || requestCode == CellSiteConstants.PICK_PICTURE2) {

        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_PICTURE2) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_PICTURE2) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().getMyTruck().setPhotoImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        // doCrop();

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false);

        mTPiv.setImageBitmap(scaledBmp);
        // s isChanged = true;
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(),
                Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_PHOTO_URL);

    } else if (requestCode == CellSiteConstants.UPDATE_TRUCK_MOBILE_REQUSET) {
        Log.d(TAG, "mobile changed");
        if (app.getUser().getMyTruck().getMobileNum() == null) {
            mTMtv.setText(app.getUser().getMobileNum());
            app.getUser().getMyTruck().setMobileNum(app.getUser().getMobileNum());

        } else {
            mTMtv.setText(app.getUser().getMyTruck().getMobileNum());
        }
    }
}

From source file:com.ccxt.whl.activity.SettingsFragment.java

/**
 * ?uri?/* w w w .  ja v  a  2s  . c o m*/
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getActivity().getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        //copyFile(picturePath,imageUri.getPath());
        cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        //copyFile(selectedImage.getPath(),imageUri.getPath()); 
        cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(file.getAbsolutePath());
    }

}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void copyImageFile(final Uri selectedImage) {
    final ContentResolver cr = mActivity.getContentResolver();
    final ProgressDialog progressDialog = showProcessing();

    new SafeAsyncTask<Object, Object, Boolean>() {
        @Override//from   w  ww.j  a  v a 2s.  c o m
        protected Boolean safeDoInBackground(Object... params) {
            L.d("Processing picture: " + selectedImage.toString());

            try {
                String fileType = cr.getType(selectedImage);
                L.d("fileType: " + fileType);
                if (fileType == null || AttachmentViewerActivity.CONTENT_TYPE_JPEG.equalsIgnoreCase(fileType)) {
                    mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_JPEG;
                } else {
                    mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_JPEG;
                }

                if (mTmpUploadFile.getAbsolutePath().equals(selectedImage.getPath())) {
                    return true;
                } else {
                    InputStream is = cr.openInputStream(selectedImage);
                    if (is != null) {
                        try {
                            OutputStream out = new FileOutputStream(mTmpUploadFile);
                            try {
                                IOUtils.copy(is, out, 1024);
                            } finally {
                                out.close();
                            }
                        } finally {
                            is.close();
                        }
                        return true;
                    }
                }

            } catch (FileNotFoundException e) {
                L.d(e);
            } catch (Exception e) {
                L.bug("Unknown exception occured while processing picture: " + selectedImage.toString(), e);
            }

            return false;
        };

        @Override
        protected void safeOnPostExecute(Boolean result) {
            progressDialog.dismiss();
            if (result) {
                setPictureSelected();
            } else {
                UIUtils.showLongToast(mActivity, mActivity.getString(R.string.error_please_try_again));
            }
        }

        @Override
        protected void safeOnCancelled(Boolean result) {
        }

        @Override
        protected void safeOnProgressUpdate(Object... values) {
        }

        @Override
        protected void safeOnPreExecute() {
        };
    }.execute();
}

From source file:com.ccxt.whl.activity.ChatActivity.java

/**
 * ??//from w w w. j  ava2  s .com
 * 
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        Toast.makeText(getApplicationContext(), "?", 0).show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        Toast.makeText(getApplicationContext(), "?10M", 0).show();
        return;
    }

    // ?
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // ?chattype,??
    if (chatType == CHATTYPE_GROUP)
        message.setChatType(ChatType.GroupChat);

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);

    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}

From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    View v = inflater.inflate(R.layout.intent_editor_general, container, false);

    // Prepare form
    mActionText = (AutoCompleteTextView) v.findViewById(R.id.action);
    mActionsSpinner = (Spinner) v.findViewById(R.id.action_spinner);
    mDataText = (AutoCompleteTextView) v.findViewById(R.id.data);
    mDataTextWrapper = v.findViewById(R.id.data_wrapper);
    mDataTextHeader = v.findViewById(R.id.data_header);
    mDataTypeHeader = v.findViewById(R.id.data_type_header);
    mDataTypeText = (TextView) v.findViewById(R.id.data_type);
    mDataTypeSpinner = (Spinner) v.findViewById(R.id.data_type_spinner);
    mDataTypeSpinnerWrapper = v.findViewById(R.id.data_type_spinner_wrapper);
    mDataTypeSlash = v.findViewById(R.id.data_type_slash);
    mDataSubtypeText = (TextView) v.findViewById(R.id.data_type_after_slash);
    mComponentText = (TextView) v.findViewById(R.id.component);

    mComponentTypeSpinner = (Spinner) v.findViewById(R.id.componenttype);
    mComponentTypeSpinner.setAdapter(new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.componenttypes)));

    mMethodSpinner = (Spinner) v.findViewById(R.id.method);

    mCategoriesContainer = (ViewGroup) v.findViewById(R.id.categories);
    mAddCategoryButton = (Button) v.findViewById(R.id.category_add);
    mCategoriesHeader = v.findViewById(R.id.categories_header);
    mResponseCodeTextView = (TextView) v.findViewById(R.id.response_code);
    mPackageNameText = (AutoCompleteTextView) v.findViewById(R.id.package_name);

    mResultCodeWrapper = v.findViewById(R.id.result_intent_wrapper);
    mComponentTypeAndMethodSpinners = v.findViewById(R.id.component_and_method_spinners);
    mComponentHeader = v.findViewById(R.id.component_header);
    mComponentFieldWithButtons = v.findViewById(R.id.component_field_with_buttons);
    mPackageNameHeader = v.findViewById(R.id.package_name_header);
    mIntentTrackerSummary = (TextView) v.findViewById(R.id.intent_tracker_summary);
    mIntentTrackerSummary.setMovementMethod(LinkMovementMethod.getInstance());

    // Apparently using android:scrollHorizontally="true" does not work.
    // http://stackoverflow.com/questions/9011944/android-ice-cream-sandwich-edittext-disabling-spell-check-and-word-wrap
    mComponentText.setHorizontallyScrolling(true);

    // Bind button actions (android:onClick="" applies to hosting activity)
    mAddCategoryButton.setOnClickListener(new OnClickListener() {
        @Override//from ww w.jav  a 2 s  .  co m
        public void onClick(View v) {
            addCategoryTextField("");
        }
    });
    v.findViewById(R.id.component_pick).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pickComponent();
        }
    });
    v.findViewById(R.id.component_pick).setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            findComponent();
            return true;
        }
    });
    v.findViewById(R.id.component_clear).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mComponentText.setText("");
        }
    });
    v.findViewById(R.id.data_query_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getIntentEditor().updateIntent();
            startActivity(
                    new Intent(getActivity(), AdvancedQueryActivity.class).setData(mEditedIntent.getData()));
        }
    });
    v.findViewById(R.id.data_query_button)
            .setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                @Override
                public void onCreateContextMenu(ContextMenu menu, View v,
                        ContextMenu.ContextMenuInfo menuInfo) {
                    getIntentEditor().updateIntent();
                    final Uri uri = mEditedIntent.getData();
                    if (uri != null) {
                        final String scheme = uri.getScheme();
                        final String authority = uri.getAuthority();
                        if ("content".equals(scheme) && authority != null) {
                            menu.add("Wrap").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                                @Override
                                public boolean onMenuItemClick(MenuItem item) {
                                    mDataText.setText("content://" + ((mEditedIntent.getFlags()
                                            & (Intent.FLAG_GRANT_READ_URI_PERMISSION
                                                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)) != 0
                                                            ? ProxyProviderForGrantUriPermission.AUTHORITY
                                                            : ProxyProvider.AUTHORITY)
                                            + "/" + authority + uri.getPath());
                                    return true;
                                }
                            });
                        }
                    }
                }
            });

    // Set up autocomplete
    mUriAutocompleteAdapter = new UriAutocompleteAdapter(getActivity());
    mDataText.setAdapter(mUriAutocompleteAdapter);
    mPackageNameText.setAdapter(new PackageNameAutocompleteAdapter(getActivity()));

    // Get edited intent for form filling
    mEditedIntent = getEditedIntent();

    // Component field, affects options menu
    if (mEditedIntent.getComponent() != null) {
        mComponentText.setText(mEditedIntent.getComponent().flattenToShortString());
    }
    mComponentText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateIntentComponent();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    // Fill the form
    setupActionSpinnerOrField();
    updateNonActionIntentFilter(true);
    mDataText.setText(mEditedIntent.getDataString());
    mPackageNameText.setText(mEditedIntent.getPackage());

    showOrHideFieldsForResultIntent();
    showOrHideAdvancedFields();
    if (getComponentType() == IntentEditorConstants.RESULT) {
        mResponseCodeTextView.setText(String.valueOf(getIntentEditor().getMethodId()));
        mResponseCodeTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                try {
                    getIntentEditor().setMethodId(Integer.parseInt(s.toString()));
                    mResponseCodeTextView.setError(null);
                } catch (NumberFormatException e) {
                    mResponseCodeTextView.setError(getIntentEditor().getText(R.string.value_parse_error));
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
    } else {
        initComponentAndMethodSpinners();
    }

    setupActionAutocomplete();

    // Prepare intent tracker
    {
        IntentTracker tracker = getIntentEditor().getIntentTracker();
        if (tracker != null) {
            tracker.setUpdateListener(this, true);
        } else {
            onNoTracker();
        }
    }

    return v;
}

From source file:com.vanco.abplayer.BiliVideoViewActivity.java

@SuppressLint("SimpleDateFormat")
@Override//from w  ww.ja v a 2s. c om
public void snapshot() {
    if (!com.vanco.abplayer.view.FileUtils.sdAvailable()) {
        ToastUtils.showToast(R.string.file_explorer_sdcard_not_available);
    } else {
        Uri imgUri = null;
        Bitmap bitmap = vPlayer.getCurrentFrame();
        if (bitmap != null) {
            File screenshotsDirectory = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                            + VP.SNAP_SHOT_PATH);
            if (!screenshotsDirectory.exists()) {
                screenshotsDirectory.mkdirs();
            }

            File savePath = new File(screenshotsDirectory.getPath() + "/"
                    + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".jpg");
            if (ImageUtils.saveBitmap(savePath.getPath(), bitmap)) {
                imgUri = Uri.fromFile(savePath);
            }
        }
        if (imgUri != null) {
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, imgUri));
            ToastUtils.showLongToast(getString(R.string.video_screenshot_save_in, imgUri.getPath()));
        } else {
            ToastUtils.showToast(R.string.video_screenshot_failed);
        }
    }
}