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:cn.edu.nju.dapenti.activity.MainActivity.java

private void selectDrawerItem(int position) {
    mCurrentDrawerPos = position;//from   w  ww  .ja v  a  2 s  . c  om
    mIcon = null;

    Uri newUri;
    boolean showFeedInfo = true;

    switch (position) {
    case 0:
        newUri = FeedData.EntryColumns.CONTENT_URI;
        break;
    case 1:
        newUri = FeedData.EntryColumns.FAVORITES_CONTENT_URI;
        break;
    default:
        long feedOrGroupId = mDrawerAdapter.getItemId(position);
        if (mDrawerAdapter.isItemAGroup(position)) {
            newUri = FeedData.EntryColumns.ENTRIES_FOR_GROUP_CONTENT_URI(feedOrGroupId);
        } else {
            byte[] iconBytes = mDrawerAdapter.getItemIcon(position);
            if (iconBytes != null && iconBytes.length > 0) {
                int bitmapSizeInDip = UiUtils.dpToPixel(24);
                Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length);
                if (bitmap != null) {
                    if (bitmap.getHeight() != bitmapSizeInDip) {
                        bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false);
                    }

                    mIcon = new BitmapDrawable(getResources(), bitmap);
                }
            }

            newUri = FeedData.EntryColumns.ENTRIES_FOR_FEED_CONTENT_URI(feedOrGroupId);
            showFeedInfo = false;
        }
        mTitle = mDrawerAdapter.getItemName(position);
        break;
    }

    if (!newUri.equals(mEntriesFragment.getUri())) {
        mEntriesFragment.setData(newUri, showFeedInfo);
    }

    mDrawerList.setItemChecked(position, true);

    // First open => we open the drawer for you
    if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) {
        PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false);
        mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mDrawerLayout.openDrawer(mDrawerList);
            }
        }, 500);
    }
}

From source file:com.android.mail.ui.FolderListFragment.java

/**
 * Builds the drawer items for the list of accounts.
 *///  w  w w  . ja va2 s  .  com
private List<DrawerItem> buildAccountListDrawerItems() {
    final Account[] allAccounts = getAllAccounts();
    final List<DrawerItem> accountList = new ArrayList<>(allAccounts.length);
    // Add all accounts and then the current account
    final Uri currentAccountUri = getCurrentAccountUri();
    for (final Account account : allAccounts) {
        final int unreadCount = getUnreadCount(account);
        accountList.add(DrawerItem.ofAccount(mActivity, account, unreadCount,
                currentAccountUri.equals(account.uri), mImagesCache, mContactResolver));
    }
    if (mCurrentAccount == null) {
        LogUtils.wtf(LOG_TAG, "buildAccountListDrawerItems() with null current account.");
    }
    return accountList;
}

From source file:com.tct.mail.ui.FolderListFragment.java

/**
 * Builds the list of accounts./* ww w  .  ja va 2s .  c om*/
 */
private List<DrawerItem> buildAccountList() {
    final Account[] allAccounts = getAllAccounts();
    final List<DrawerItem> accountList = new ArrayList<DrawerItem>(allAccounts.length);
    // Add all accounts and then the current account
    final Uri currentAccountUri = getCurrentAccountUri();
    for (final Account account : allAccounts) {
        final int unreadCount = getUnreadCount(account);
        //TS: jian.xu 2015-10-28 EMAIL BUGFIX-834751 MOD-S
        //NOTE: Add a parameter which indicate whether to show account color block.
        accountList.add(
                DrawerItem.ofAccount(mActivity, account, unreadCount, currentAccountUri.equals(account.uri),
                        isAccountColorBlockVisible(account), mImagesCache, mContactResolver));
        //TS: jian.xu 2015-10-28 EMAIL BUGFIX-834751 MOD-E
    }
    if (mCurrentAccount == null) {
        LogUtils.wtf(LOG_TAG, "buildAccountList() with null current account.");
    }
    return accountList;
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

private int getRingtonePosition(Uri ringtoneUri, int tabName, String were) {

    if (ringtoneUri == null)
        return -1;

    final Cursor cursor = getCursor(tabName, were);
    final int cursorCount = cursor.getCount();
    final String musicId = MediaStore.Audio.Media._ID;

    if (!cursor.moveToFirst()) {
        Log.e("zxw", "getRingtonePosition 1");
        return -1;
    }//from  www.j  av a2  s.com

    // Only create Uri objects when the actual URI changes
    Uri BaseUri = null;
    Uri currentUri = null;
    String previousUriString = null;
    if (tabName == SYSTEM_TONE) {
        BaseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
    } else {
        BaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    }

    for (int i = 0; i < cursorCount; i++) {

        int position = cursor.getInt(cursor.getColumnIndex(musicId));

        currentUri = ContentUris.withAppendedId(BaseUri, position);

        //if( position == mSelectedId) {
        if (ringtoneUri.equals(currentUri)) {
            Log.e("zxw", "getRingtonePosition i" + i);
            cursor.close();
            return i;
        }

        //            String uriString = cursor.getString(URI_COLUMN_INDEX);
        //            if (currentUri == null || !uriString.equals(previousUriString)) {
        //                currentUri = Uri.parse(uriString);
        //            }            
        //            if (ringtoneUri.equals(ContentUris.withAppendedId(currentUri, cursor
        //                    .getLong(ID_COLUMN_INDEX)))) {
        //                Log.e("zxw","getRingtonePosition i" + i);
        //                return i;
        //            }

        cursor.move(1);

        //            previousUriString = uriString;
    }
    cursor.close();
    Log.e("zxw", "getRingtonePosition 2");
    return -1;
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Creates new {@link #mFileSelector} to select appropriate file after
 * loading a folder's content. It's either the parent path of last path, or
 * the file provided by key {@link FileChooserActivity#EXTRA_SELECT_FILE}.
 * Note that this also cancels previous selector if there is such one.
 *//*from  ww  w.  j  a  v a 2s  .  com*/
private void createFileSelector() {
    if (mFileSelector != null)
        mFileSelector.cancel(true);

    mFileSelector = new LoadingDialog<Void, Void, Integer>(getActivity(), true) {

        @Override
        protected Integer doInBackground(Void... params) {
            final Cursor cursor = mFileAdapter.getCursor();
            if (cursor == null || cursor.isClosed())
                return -1;

            final Uri selectedFile = (Uri) getArguments().getParcelable(FileChooserActivity.EXTRA_SELECT_FILE);
            final int colUri = cursor.getColumnIndex(BaseFile.COLUMN_URI);
            if (selectedFile != null)
                getArguments().remove(FileChooserActivity.EXTRA_SELECT_FILE);

            int shouldBeSelectedIdx = -1;
            final Uri uri = selectedFile != null ? selectedFile : getLastLocation();
            if (uri == null || !BaseFileProviderUtils.fileExists(getActivity(), uri))
                return -1;

            final String fileName = BaseFileProviderUtils.getFileName(getActivity(), uri);
            if (fileName == null)
                return -1;

            Uri parentUri = BaseFileProviderUtils.getParentFile(getActivity(), uri);
            if ((uri == getLastLocation() && !getCurrentLocation().equals(getLastLocation())
                    && BaseFileProviderUtils.isAncestorOf(getActivity(), getCurrentLocation(), uri))
                    || getCurrentLocation().equals(parentUri)) {
                if (cursor.moveToFirst()) {
                    while (!cursor.isLast()) {
                        if (isCancelled())
                            return -1;

                        Uri subUri = Uri.parse(cursor.getString(colUri));
                        if (uri == getLastLocation()) {
                            if (cursor.getInt(cursor
                                    .getColumnIndex(BaseFile.COLUMN_TYPE)) == BaseFile.FILE_TYPE_DIRECTORY) {
                                if (subUri.equals(uri)
                                        || BaseFileProviderUtils.isAncestorOf(getActivity(), subUri, uri)) {
                                    shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                    break;
                                }
                            }
                        } else {
                            if (uri.equals(subUri)) {
                                shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                break;
                            }
                        }

                        cursor.moveToNext();
                    } // while
                } // if
            } // if

            return shouldBeSelectedIdx;
        }// doInBackground()

        @Override
        protected void onPostExecute(final Integer result) {
            super.onPostExecute(result);

            if (isCancelled() || mFileAdapter.isEmpty())
                return;

            /*
             * Use a Runnable to make sure this works. Because if the list
             * view is handling data, this might not work.
             * 
             * Also sometimes it doesn't work without a delay.
             */
            mViewFiles.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (result >= 0 && result < mFileAdapter.getCount())
                        mViewFiles.setSelection(result);
                    else if (!mFileAdapter.isEmpty())
                        mViewFiles.setSelection(0);
                }// run()
            }, DisplayPrefs.DELAY_TIME_FOR_VERY_SHORT_ANIMATION);
        }// onPostExecute()

    };

    mFileSelector.execute();
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

private void refreshList(@Nullable GreatUri thisUri, boolean add, boolean delete) {
    int max_recent_files = 15;
    if (add)//ww  w .  j  av a  2s .  c  om
        max_recent_files--;

    // File paths saved in preferences
    String[] savedPaths = PreferenceHelper.getSavedPaths(this);
    int first_index_of_array = savedPaths.length > max_recent_files ? savedPaths.length - max_recent_files : 0;
    savedPaths = ArrayUtils.subarray(savedPaths, first_index_of_array, savedPaths.length);
    // File names for the list
    greatUris.clear();
    // StringBuilder that will contain the file paths
    StringBuilder sb = new StringBuilder();

    // for cycle to convert paths to names
    for (int i = 0; i < savedPaths.length; i++) {
        Uri particularUri = Uri.parse(savedPaths[i]);
        String name = AccessStorageApi.getName(this, particularUri);
        // Check that the file exist
        // if is null or empty the particular url we dont use it
        if (particularUri != null && !particularUri.equals(Uri.EMPTY) && !TextUtils.isEmpty(name)) {
            // if the particular uri is good
            boolean good = false;
            if (thisUri == null || thisUri.getUri() == null || thisUri.getUri() == Uri.EMPTY)
                good = true;
            else {
                if (delete == false)
                    good = true;
                else if (!thisUri.getUri().equals(particularUri))
                    good = true;
                else
                    good = false;
            }
            if (good) {
                greatUris.addFirst(
                        new GreatUri(particularUri, AccessStorageApi.getPath(this, particularUri), name));
                sb.append(savedPaths[i]).append(",");
            }
        }
        //}
    }
    // if is not null, empty, we have to add something and we dont already have this uri
    if (thisUri != null && !thisUri.getUri().equals(Uri.EMPTY) && add
            && !ArrayUtils.contains(savedPaths, thisUri.getUri().toString())) {
        sb.append(thisUri.getUri().toString()).append(",");
        greatUris.addFirst(thisUri);
    }
    // save list without empty or non existed files
    PreferenceHelper.setSavedPaths(this, sb);
    // Set adapter
    arrayAdapter.notifyDataSetChanged();
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Creates new {@link #mFileSelector} to select appropriate file after
 * loading a folder's content. It's either the parent path of last path, or
 * the file provided by key {@link FileChooserActivity#EXTRA_SELECT_FILE}.
 * Note that this also cancels previous selector if there is such one.
 *///from   w  ww. ja  v  a  2  s. c  om
private void createFileSelector() {
    if (mFileSelector != null)
        mFileSelector.cancel(true);

    mFileSelector = new LoadingDialog<Void, Void, Integer>(getActivity(), true) {

        @Override
        protected Integer doInBackground(Void... params) {
            final Cursor cursor = mFileAdapter.getCursor();
            if (cursor == null || cursor.isClosed())
                return -1;

            final Uri selectedFile = (Uri) getArguments().getParcelable(FileChooserActivity.EXTRA_SELECT_FILE);
            final int colUri = cursor.getColumnIndex(BaseFile.COLUMN_URI);
            if (selectedFile != null)
                getArguments().remove(FileChooserActivity.EXTRA_SELECT_FILE);

            int shouldBeSelectedIdx = -1;
            final Uri uri = selectedFile != null ? selectedFile : getLastLocation();
            if (uri == null || !BaseFileProviderUtils.fileExists(getActivity(), uri))
                return -1;

            final String fileName = BaseFileProviderUtils.getFileName(getActivity(), uri);
            if (fileName == null)
                return -1;

            Uri parentUri = BaseFileProviderUtils.getParentFile(getActivity(), uri);
            if ((uri == getLastLocation() && !getCurrentLocation().equals(getLastLocation())
                    && BaseFileProviderUtils.isAncestorOf(getActivity(), getCurrentLocation(), uri))
                    || getCurrentLocation().equals(parentUri)) {
                if (cursor.moveToFirst()) {
                    while (!cursor.isLast()) {
                        if (isCancelled())
                            return -1;

                        Uri subUri = Uri.parse(cursor.getString(colUri));
                        if (uri == getLastLocation()) {
                            if (cursor.getInt(cursor
                                    .getColumnIndex(BaseFile.COLUMN_TYPE)) == BaseFile.FILE_TYPE_DIRECTORY) {
                                if (subUri.equals(uri)
                                        || BaseFileProviderUtils.isAncestorOf(getActivity(), subUri, uri)) {
                                    shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                    break;
                                }
                            }
                        } else {
                            if (uri.equals(subUri)) {
                                shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                break;
                            }
                        }

                        cursor.moveToNext();
                    } // while
                } // if
            } // if

            return shouldBeSelectedIdx;
        }// doInBackground()

        @Override
        protected void onPostExecute(final Integer result) {
            super.onPostExecute(result);

            if (isCancelled() || mFileAdapter.isEmpty())
                return;

            /*
             * Use a Runnable to make sure this works. Because if the list
             * view is handling data, this might not work.
             * 
             * Also sometimes it doesn't work without a delay.
             */
            mViewFiles.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (result >= 0 && result < mFileAdapter.getCount())
                        mViewFiles.setSelection(result);
                    else if (!mFileAdapter.isEmpty())
                        mViewFiles.setSelection(0);
                }// run()
            }, Display.DELAY_TIME_FOR_VERY_SHORT_ANIMATION);
        }// onPostExecute()

    };

    mFileSelector.execute();
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Shows history manager./*from  w  w w .  ja va 2 s  .  co  m*/
 */
private void showHistoryManager() {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "doShowHistoryManager()");

    // Create and show the dialog.
    final HistoryFragment fragment = HistoryFragment.newInstance();
    fragment.setOnHistoryItemClickListener(new HistoryFragment.OnHistoryItemClickListener() {

        @Override
        public void onItemClick(String providerId, final Uri uri) {
            /*
             * TODO what to do with `providerId`?
             */

            /*
             * Check if `uri` is in internal list, then use it instead of
             * that.
             */
            if (!mHistory.find(new HistoryFilter<Uri>() {

                @Override
                public boolean accept(Uri item) {
                    if (uri.equals(item)) {
                        goTo(item);
                        return true;
                    }

                    return false;
                }// accept()
            }, false))
                goTo(uri);
        }// onItemClick()
    });

    /*
     * DialogFragment.show() will take care of adding the fragment in a
     * transaction. We also want to remove any currently showing dialog, so
     * make our own transaction and take care of that here.
     */
    fragment.show(getChildFragmentManager(), HistoryFragment.class.getName());
}

From source file:nl.privacybarometer.privacyvandaag.activity.HomeActivity.java

private void selectDrawerItem(int position) {
    mCurrentDrawerPos = position;/*from w  ww .  j ava2 s.c  om*/
    Drawable mDrawable = null;
    Bitmap bitmap = null;
    BitmapDrawable mIcon = null;

    Uri newUri;
    boolean showFeedInfo = true;

    switch (position) {
    case SEARCH_DRAWER_POSITION:
        newUri = EntryColumns.SEARCH_URI(mEntriesFragment.getCurrentSearch());
        break;
    case 0:
        newUri = EntryColumns.ALL_ENTRIES_CONTENT_URI;
        //   Rescale the app-icon from the resources to the right size for use in the actionBar
        mDrawable = ContextCompat.getDrawable(this, R.drawable.ic_statusbar_pv);
        bitmap = ((BitmapDrawable) mDrawable).getBitmap();
        if (bitmap != null) {
            mIcon = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 36, 36, true));
        }
        break;
    case 1:
        newUri = EntryColumns.FAVORITES_CONTENT_URI;
        break;
    default:
        long feedOrGroupId = mDrawerAdapter.getItemId(position);
        mTitle = mDrawerAdapter.getItemName(position);
        if (mDrawerAdapter.isItemAGroup(position)) { // TODO: remove groups from the app. Not going to use this.
            newUri = EntryColumns.ENTRIES_FOR_GROUP_CONTENT_URI(feedOrGroupId);
        } else {
            // Get icons from resources instead of fetching favicons from websites on the internet.
            // Rescale the resources to the right size for use as drawer icon
            int mIconResourceId = mDrawerAdapter.getIconResourceId(position);
            if (mIconResourceId > 0) {
                mDrawable = ContextCompat.getDrawable(this, mIconResourceId);
                bitmap = ((BitmapDrawable) mDrawable).getBitmap();
                if (bitmap != null) {
                    mIcon = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 36, 36, true));
                }
            }
            //  If favicons from websites are used, they are feteched and stored as bitmaps in database
            /*
            byte[] iconBytes = mDrawerAdapter.getItemIcon(position);
            Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
            if (bitmap != null) {
               mIcon = new BitmapDrawable(getResources(), bitmap);
            }
            */
            newUri = EntryColumns.ENTRIES_FOR_FEED_CONTENT_URI(feedOrGroupId);
            showFeedInfo = false;
        }
        break;
    }
    if (!newUri.equals(mEntriesFragment.getUri())) {
        mEntriesFragment.setData(newUri, showFeedInfo);
    }

    mDrawerList.setItemChecked(position, true);

    // First run of the app => we open the drawer for you
    if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) {
        PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false);
        if (mDrawerLayout != null) {
            mDrawerLayout.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mDrawerLayout.openDrawer(mLeftDrawer);
                }
            }, 500);
        }
        // Dialog popup that can be shown at first run after installation.
        /*
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.welcome_title);
        builder.show();
        */

        /* On first run after installation, try to add these feeds in database */
        FeedData.addPredefinedFeeds(this);
    } // end of settings on first run of the app.

    // Set title and icon in left drawer menu
    switch (mCurrentDrawerPos) {
    case SEARCH_DRAWER_POSITION:
        getSupportActionBar().setTitle(android.R.string.search_go);
        getSupportActionBar().setIcon(R.drawable.action_search);
        break;
    case 0:
        getSupportActionBar().setTitle(R.string.all);
        if (mIcon != null) {
            getSupportActionBar().setIcon(mIcon);
        } else {
            getSupportActionBar().setIcon(null);
        }
        break;
    case 1:
        getSupportActionBar().setTitle(R.string.favorites);
        getSupportActionBar().setIcon(R.drawable.rating_important);
        break;
    default:
        getSupportActionBar().setTitle(mTitle);
        if (mIcon != null) {
            getSupportActionBar().setIcon(mIcon);
        } else {
            getSupportActionBar().setIcon(null);
        }
        break;
    }

    // Put the good menu
    invalidateOptionsMenu();
}

From source file:com.android.tv.MainActivity.java

private void startTv(Uri channelUri) {
    if (DEBUG)/*from  w ww. jav a2  s.  c om*/
        Log.d(TAG, "startTv Uri=" + channelUri);
    if ((channelUri == null || !TvContract.isChannelUriForPassthroughInput(channelUri))
            && mChannelTuner.isCurrentChannelPassthrough()) {
        // For passthrough TV input, channelUri is always given. If TV app is launched
        // by TV app icon in a launcher, channelUri is null. So if passthrough TV input
        // is playing, we stop the passthrough TV input.
        stopTv();
    }
    SoftPreconditions.checkState(
            TvContract.isChannelUriForPassthroughInput(channelUri) || mChannelTuner.areAllChannelsLoaded(), TAG,
            "startTV assumes that ChannelDataManager is already loaded.");
    if (mTvView.isPlaying()) {
        // TV has already started.
        if (channelUri == null) {
            // Simply adjust the volume without tune.
            setVolumeByAudioFocusStatus();
            return;
        }
        if (channelUri.equals(mChannelTuner.getCurrentChannelUri())) {
            // The requested channel is already tuned.
            setVolumeByAudioFocusStatus();
            return;
        }
        stopTv();
    }
    if (mChannelTuner.getCurrentChannel() != null) {
        Log.w(TAG, "The current channel should be reset before");
        mChannelTuner.resetCurrentChannel();
    }
    if (channelUri == null) {
        // If any initial channel id is not given, remember the last channel the user watched.
        long channelId = Utils.getLastWatchedChannelId(this);
        if (channelId != Channel.INVALID_ID) {
            channelUri = TvContract.buildChannelUri(channelId);
        }
    }

    if (channelUri == null) {
        mChannelTuner.moveToChannel(mChannelTuner.findNearestBrowsableChannel(0));
    } else {
        if (TvContract.isChannelUriForPassthroughInput(channelUri)) {
            Channel channel = Channel.createPassthroughChannel(channelUri);
            mChannelTuner.moveToChannel(channel);
        } else {
            long channelId = ContentUris.parseId(channelUri);
            Channel channel = mChannelDataManager.getChannel(channelId);
            if (channel == null || !mChannelTuner.moveToChannel(channel)) {
                mChannelTuner.moveToChannel(mChannelTuner.findNearestBrowsableChannel(0));
                Log.w(TAG, "The requested channel (id=" + channelId + ") doesn't exist. "
                        + "The first channel will be tuned to.");
            }
        }
    }

    mTvView.start(mTvInputManagerHelper);
    setVolumeByAudioFocusStatus();
    if (mRecordingUri != null) {
        playRecording(mRecordingUri);
        mRecordingUri = null;
    } else {
        tune();
    }
}