Example usage for android.net Uri equals

List of usage examples for android.net Uri equals

Introduction

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

Prototype

public boolean equals(Object o) 

Source Link

Document

Compares this Uri to another object for equality.

Usage

From source file:Main.java

/** Checks whether two URI are equal, taking care of the case where either is null. */
public static boolean areEqual(Uri uri1, Uri uri2) {
    if (uri1 == null && uri2 == null) {
        return true;
    }/*  ww  w  .  j ava 2 s .c  o m*/
    if (uri1 == null || uri2 == null) {
        return false;
    }
    return uri1.equals(uri2);
}

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

public static String getName(Context context, Uri uri) {

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

    String fileName = "";
    try {/*from   w  w  w . j a  v a2  s.c o  m*/
        String scheme = uri.getScheme();
        if (scheme.equals("file")) {
            fileName = uri.getLastPathSegment();
        } else if (scheme.equals("content")) {
            String[] proj = { MediaStore.Images.Media.DISPLAY_NAME };
            Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
            if (cursor != null && cursor.getCount() != 0) {
                int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
                cursor.moveToFirst();
                fileName = cursor.getString(columnIndex);
            }
            if (cursor != null) {
                cursor.close();
            }
        }
    } catch (Exception ex) {
        return "";
    }
    return fileName;
}

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.//from w w w.  j a  v a2  s.  co  m
 *
 * @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:org.thialfihar.android.apg.ui.ViewKeyCertsFragment.java

private void loadData(Uri dataUri) {
    if (dataUri.equals(mDataUri)) {
        Log.d(Constants.TAG, "Same URI, no need to load the data again!");
        return;//  w  w  w  . j  a v a  2  s  .c  om
    }

    mDataUri = dataUri;

    Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());

    mActionCertify.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            certifyKey(mDataUri);
        }
    });

}

From source file:com.cerema.cloud2.lib.common.SingleSessionManager.java

private void keepUriUpdated(OwnCloudAccount account, OwnCloudClient reusedClient) {
    Uri recentUri = account.getBaseUri();
    if (!recentUri.equals(reusedClient.getBaseUri())) {
        reusedClient.setBaseUri(recentUri);
    }//from  ww  w  .j  a v a  2 s.c  o  m

}

From source file:ir.keloud.android.lib.common.SingleSessionManager.java

private void keepUriUpdated(KeloudAccount account, KeloudClient reusedClient) {
    Uri recentUri = account.getBaseUri();
    if (!recentUri.equals(reusedClient.getBaseUri())) {
        reusedClient.setBaseUri(recentUri);
    }//from w w w  .  ja v a  2  s.  c  o m

}

From source file:tk.wasdennnoch.androidn_ify.ui.emergency.preferences.ContactPreference.java

public void setUri(@NonNull Uri contactUri) {
    if (mContact != null && !contactUri.equals(mContact.getContactUri()) && mRemoveContactDialog != null) {
        mRemoveContactDialog.dismiss();//w w w .  j  a va 2s . c  om
    }

    mContact = EmergencyContactManager.getContact(getContext(), contactUri);

    setTitle(mContact.getName());
    setKey(mContact.getContactUri().toString());
    String summary = mContact.getPhoneType() == null ? mContact.getPhoneNumber()
            : String.format(getContext().getResources().getString(R.string.phone_type_and_phone_number),
                    mContact.getPhoneType(), BidiFormatter.getInstance().unicodeWrap(mContact.getPhoneNumber(),
                            TextDirectionHeuristics.LTR));
    setSummary(summary);

    // Update the message to show the correct name.
    if (mRemoveContactDialog != null) {
        mRemoveContactDialog
                .setMessage(String.format(getContext().getString(R.string.remove_contact), mContact.getName()));
    }

    //TODO: Consider doing the following in a non-UI thread.
    Drawable icon;
    if (mContact.getPhoto() != null) {
        icon = new CircleFramedDrawable(mContact.getPhoto(),
                (int) getContext().getResources().getDimension(R.dimen.circle_avatar_size));
    } else {
        icon = getContext().getResources().getDrawable(R.drawable.ic_person_black_24dp);
    }
    setIcon(icon);
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

private static boolean uriEquals(Uri uri1, Uri uri2) {
    if (uri1 != null && uri1.equals(uri2)) {
        return true;
    } else if (uri1 == null && uri2 == null) {
        return true;
    }/*from ww w .j  a  v a2s  . c  om*/
    return false;
}

From source file:com.eutectoid.dosomething.usersettings.UserSettingsFragment.java

private void updateUI() {
    if (!isAdded()) {
        return;//from   w ww .j  a va  2 s  .c  om
    }
    if (AccessToken.getCurrentAccessToken() != null) {
        connectedStateLabel
                .setTextColor(getResources().getColor(R.color.usersettings_fragment_connected_text_color));
        connectedStateLabel.setShadowLayer(1f, 0f, -1f,
                getResources().getColor(R.color.usersettings_fragment_connected_shadow_color));

        if (user != null) {
            ImageRequest request = getImageRequest();
            if (request != null) {
                Uri requestUri = request.getImageUri();
                // Do we already have the right picture? If so, leave it alone.
                if (!requestUri.equals(connectedStateLabel.getTag())) {
                    if (user.optString("id").equals(userProfilePicID)) {
                        connectedStateLabel.setCompoundDrawables(null, userProfilePic, null, null);
                        connectedStateLabel.setTag(requestUri);
                    } else {
                        ImageDownloader.downloadAsync(request);
                    }
                }
            }
            connectedStateLabel.setText(user.optString("name"));
        } else {
            connectedStateLabel.setText(getResources().getString(R.string.usersettings_fragment_logged_in));
            Drawable noProfilePic = getResources().getDrawable(R.drawable.profile_default_icon);
            noProfilePic.setBounds(0, 0,
                    getResources().getDimensionPixelSize(R.dimen.usersettings_fragment_profile_picture_width),
                    getResources().getDimensionPixelSize(R.dimen.usersettings_fragment_profile_picture_height));
            connectedStateLabel.setCompoundDrawables(null, noProfilePic, null, null);
        }
    } else {
        int textColor = getResources().getColor(R.color.usersettings_fragment_not_connected_text_color);
        connectedStateLabel.setTextColor(textColor);
        connectedStateLabel.setShadowLayer(0f, 0f, 0f, textColor);
        connectedStateLabel.setText(getResources().getString(R.string.usersettings_fragment_not_logged_in));
        connectedStateLabel.setCompoundDrawables(null, null, null, null);
        connectedStateLabel.setTag(null);
    }
}

From source file:org.thialfihar.android.apg.ui.ViewKeyMainFragment.java

private void loadData(Uri dataUri) {
    if (dataUri.equals(mDataUri)) {
        Log.d(Constants.TAG, "Same URI, no need to load the data again!");
        return;/*  ww  w .  jav  a 2s  .com*/
    }

    mDataUri = dataUri;

    Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());

    { // label whether secret key is available, and edit button if it is
        final long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), mDataUri);
        if (ProviderHelper.hasSecretKeyByMasterKeyId(getActivity(), masterKeyId)) {
            // set this attribute. this is a LITTLE unclean, but we have the info available
            // right here, so why not.
            mSecretKey.setTextColor(getResources().getColor(R.color.emphasis));
            mSecretKey.setText(R.string.secret_key_yes);

            // certify button
            // TODO this button MIGHT be useful if the user wants to
            // certify a private key with another...
            // mActionCertify.setVisibility(View.GONE);

            // edit button
            mActionEdit.setVisibility(View.VISIBLE);
            mActionEdit.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
                    editIntent.setData(KeychainContract.KeyRings
                            .buildSecretKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId)));
                    editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
                    startActivityForResult(editIntent, 0);
                }
            });
        } else {
            mSecretKey.setText(getResources().getString(R.string.secret_key_no));

            // certify button
            mActionCertify.setVisibility(View.VISIBLE);
            // edit button
            mActionEdit.setVisibility(View.GONE);
        }

        // TODO see todo note above, doing this here for now
        mActionCertify.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                certifyKey(KeychainContract.KeyRings
                        .buildPublicKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId)));
            }
        });

    }

    mActionEncrypt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            encryptToContact(mDataUri);
        }
    });

    mUserIdsAdapter = new ViewKeyUserIdsAdapter(getActivity(), null, 0);
    mUserIds.setAdapter(mUserIdsAdapter);

    mKeysAdapter = new ViewKeyKeysAdapter(getActivity(), null, 0);
    mKeys.setAdapter(mKeysAdapter);

    // Prepare the loaders. Either re-connect with an existing ones,
    // or start new ones.
    getActivity().getSupportLoaderManager().initLoader(LOADER_ID_KEYRING, null, this);
    getActivity().getSupportLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
    getActivity().getSupportLoaderManager().initLoader(LOADER_ID_KEYS, null, this);
}