diff options
author | Leon Scroggins <scroggo@google.com> | 2011-01-13 12:26:52 -0500 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2011-01-13 13:40:07 -0500 |
commit | 504433a185c3e60110590ce2aacd9b76b204b129 (patch) | |
tree | 95acc6a502ef5f554ffdeefc7ee4d30556a8fb82 /src/com/android/browser/addbookmark/FolderSpinner.java | |
parent | 0333f2cdfb7f6d77c3995102d09e4093eccab00e (diff) | |
download | packages_apps_browser-504433a185c3e60110590ce2aacd9b76b204b129.zip packages_apps_browser-504433a185c3e60110590ce2aacd9b76b204b129.tar.gz packages_apps_browser-504433a185c3e60110590ce2aacd9b76b204b129.tar.bz2 |
Tapping star for bookmarked page now edits that bookmark.
Rather than creating a new bookmark.
Bug:3222677
Use a CursorLoader to find the existing bookmark, if any, and
another to find the root folder.
Change-Id: I92bd28124b75d0cbb534480cc674ee352fb72ab7
Diffstat (limited to 'src/com/android/browser/addbookmark/FolderSpinner.java')
-rw-r--r-- | src/com/android/browser/addbookmark/FolderSpinner.java | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/src/com/android/browser/addbookmark/FolderSpinner.java b/src/com/android/browser/addbookmark/FolderSpinner.java index 789c1f1..dd85cda 100644 --- a/src/com/android/browser/addbookmark/FolderSpinner.java +++ b/src/com/android/browser/addbookmark/FolderSpinner.java @@ -19,27 +19,74 @@ package com.android.browser.addbookmark; import android.content.Context; import android.view.View; import android.util.AttributeSet; +import android.widget.AdapterView; import android.widget.Spinner; /** - * Special Spinner class which calls onItemSelected even if the item selected - * was already selected. In that case, it passes null for the View. + * Special Spinner class with its own callback for when the selection is set, which + * can be ignored by calling setSelectionIgnoringSelectionChange */ -public class FolderSpinner extends Spinner { +public class FolderSpinner extends Spinner + implements AdapterView.OnItemSelectedListener { + private OnSetSelectionListener mOnSetSelectionListener; + private boolean mFireSetSelection; + + /** + * Callback for knowing when the selection has been manually set. Does not + * get called until the selected view has changed. + */ + public interface OnSetSelectionListener { + public void onSetSelection(long id); + } + public FolderSpinner(Context context, AttributeSet attrs) { super(context, attrs); + super.setOnItemSelectedListener(this); + } + + @Override + public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener l) { + // Disallow setting an OnItemSelectedListener, since it is used by us + // to fire onSetSelection. + throw new RuntimeException("Cannot set an OnItemSelectedListener on a FolderSpinner"); + } + + public void setOnSetSelectionListener(OnSetSelectionListener l) { + mOnSetSelectionListener = l; + } + + /** + * Call setSelection, without firing the callback + * @param position New position to select. + */ + public void setSelectionIgnoringSelectionChange(int position) { + super.setSelection(position); } @Override public void setSelection(int position) { + mFireSetSelection = true; int oldPosition = getSelectedItemPosition(); super.setSelection(position); - if (oldPosition == position) { - // Normally this is not called because the item did not actually - // change, but in this case, we still want it to be called. - long id = getAdapter().getItemId(position); - getOnItemSelectedListener().onItemSelected(this, null, position, id); + if (mOnSetSelectionListener != null) { + if (oldPosition == position) { + long id = getAdapter().getItemId(position); + // Normally this is not called because the item did not actually + // change, but in this case, we still want it to be called. + onItemSelected(this, null, position, id); + } + } + } + + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + if (mFireSetSelection) { + mOnSetSelectionListener.onSetSelection(id); + mFireSetSelection = false; } } + + @Override + public void onNothingSelected(AdapterView<?> parent) {} } |