diff options
Diffstat (limited to 'src/com/android/browser')
-rw-r--r-- | src/com/android/browser/BookmarkDragHandler.java | 177 | ||||
-rw-r--r-- | src/com/android/browser/BrowserBookmarksPage.java | 47 | ||||
-rw-r--r-- | src/com/android/browser/view/BookmarkExpandableView.java | 60 |
3 files changed, 0 insertions, 284 deletions
diff --git a/src/com/android/browser/BookmarkDragHandler.java b/src/com/android/browser/BookmarkDragHandler.java deleted file mode 100644 index fc0752f..0000000 --- a/src/com/android/browser/BookmarkDragHandler.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.browser; - -import android.app.Activity; -import android.content.ClipData; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; -import android.provider.BrowserContract; -import android.view.ActionMode; -import android.view.ActionMode.Callback; -import android.view.DragEvent; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnDragListener; -import android.view.ViewGroup; - -public class BookmarkDragHandler implements Callback { - - public static interface BookmarkDragController { - boolean startDrag(Cursor item); - - ViewGroup getActionModeView(ActionMode mode, BookmarkDragState state); - void actionItemClicked(View v, BookmarkDragState state); - } - - public static interface BookmarkDragAdapter { - void setBookmarkDragHandler(BookmarkDragHandler handler); - Cursor getItemForView(View v); - } - - public static class BookmarkDragState { - public long id; - public long parent; - public Object extraState; - } - - static final String BOOKMARK_DRAG_LABEL = "com.android.browser.BOOKMARK_LABEL"; - - private Activity mActivity; - private BookmarkDragController mDragController; - private BookmarkDragAdapter mDragAdapter; - private ActionMode mActionMode; - private BookmarkDragState mDragState; - - public BookmarkDragHandler(Activity activity, BookmarkDragController controller, - BookmarkDragAdapter adapter) { - mActivity = activity; - mDragController = controller; - mDragAdapter = adapter; - mDragAdapter.setBookmarkDragHandler(this); - } - - public boolean startDrag(View view, Cursor item, long id, Object extraState) { - if (!mDragController.startDrag(item)) { - return false; - } - Uri uri = ContentUris.withAppendedId( - BrowserContract.Bookmarks.CONTENT_URI, id); - ClipData data = ClipData.newRawUri(BOOKMARK_DRAG_LABEL, uri); - BookmarkDragState state = new BookmarkDragState(); - state.id = id; - state.parent = item.getLong(BookmarksLoader.COLUMN_INDEX_PARENT); - state.extraState = extraState; - mDragState = state; - view.startDrag(data, new View.DragShadowBuilder(view), state, 0); - mActionMode = view.startActionMode(this); - return true; - } - - public void registerBookmarkDragHandler(View view) { - view.setOnDragListener(mBookmarkDragListener); - } - - private OnDragListener mBookmarkDragListener = new OnDragListener() { - - @Override - public boolean onDrag(View v, DragEvent event) { - Cursor c = mDragAdapter.getItemForView(v); - BookmarkDragState state = (BookmarkDragState) event.getLocalState(); - switch (event.getAction()) { - case DragEvent.ACTION_DRAG_STARTED: - return true; - case DragEvent.ACTION_DROP: - long id = c.getLong(BookmarksLoader.COLUMN_INDEX_ID); - if (id == state.id) { - // We dropped onto ourselves, show the context menu - v.showContextMenu(); - return false; - } - long parent = c.getLong(BookmarksLoader.COLUMN_INDEX_PARENT); - if (isFolder(c)) { - parent = c.getLong(BookmarksLoader.COLUMN_INDEX_ID); - } - if (parent != state.parent) { - ContentResolver cr = mActivity.getContentResolver(); - ContentValues values = new ContentValues(); - values.put(BrowserContract.Bookmarks.PARENT, parent); - Uri uri = event.getClipData().getItemAt(0).getUri(); - cr.update(uri, values, null, null); - } - break; - } - return false; - } - }; - - private OnDragListener mActionModeDragListener = new OnDragListener() { - - @Override - public boolean onDrag(View v, DragEvent event) { - BookmarkDragState state = (BookmarkDragState) event.getLocalState(); - switch (event.getAction()) { - case DragEvent.ACTION_DRAG_STARTED: - return true; - case DragEvent.ACTION_DROP: - mDragController.actionItemClicked(v, state); - // fall through - case DragEvent.ACTION_DRAG_ENDED: - if (mActionMode != null) { - mActionMode.finish(); - mActionMode = null; - } - return true; - } - return false; - } - }; - - static boolean isFolder(Cursor c) { - return c.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; - } - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - ViewGroup view = mDragController.getActionModeView(mode, mDragState); - int count = view.getChildCount(); - for (int i = 0; i < count; i++) { - view.getChildAt(i).setOnDragListener(mActionModeDragListener); - } - mode.setCustomView(view); - return true; - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return true; - } - - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - return false; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - } - -} diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java index 597abf7..b11162c 100644 --- a/src/com/android/browser/BrowserBookmarksPage.java +++ b/src/com/android/browser/BrowserBookmarksPage.java @@ -38,7 +38,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.provider.BrowserContract; import android.provider.BrowserContract.Accounts; -import android.view.ActionMode; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; @@ -48,12 +47,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.Toast; -import com.android.browser.BookmarkDragHandler.BookmarkDragController; -import com.android.browser.BookmarkDragHandler.BookmarkDragState; import com.android.browser.provider.BrowserProvider2; import com.android.browser.view.BookmarkExpandableView; import com.android.browser.view.BookmarkExpandableView.BookmarkContextMenuInfo; @@ -101,7 +96,6 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte View mEmptyView; View mHeader; HashMap<Integer, BrowserBookmarksAdapter> mBookmarkAdapters = new HashMap<Integer, BrowserBookmarksAdapter>(); - BookmarkDragHandler mDragHandler; JSONObject mState; @Override @@ -401,8 +395,6 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte mGrid.setColumnWidthFromLayout(R.layout.bookmark_thumbnail); mGrid.setBreadcrumbController(this); setEnableContextMenu(mEnableContextMenu); - mDragHandler = new BookmarkDragHandler(getActivity(), mDragController, - mGrid.getDragAdapter()); // Start the loaders LoaderManager lm = getLoaderManager(); @@ -619,45 +611,6 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte } } - private BookmarkDragController mDragController = new BookmarkDragController() { - - @Override - public boolean startDrag(Cursor item) { - return canEdit(item); - } - - @Override - public ViewGroup getActionModeView(ActionMode mode, - BookmarkDragState state) { - LayoutInflater inflater = LayoutInflater.from(getActivity()); - LinearLayout view = (LinearLayout) inflater.inflate( - R.layout.bookmarks_drag_actionmode, null); - view.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); - ExtraDragState extraState = (ExtraDragState) state.extraState; - BrowserBookmarksAdapter adapter = getChildAdapter(extraState.groupPosition); - Cursor c = adapter.getItem(extraState.childPosition); - boolean isFolder = c.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; - if (isFolder) { - view.findViewById(R.id.open_context_menu_id).setVisibility(View.GONE); - ImageView iv = (ImageView) view.findViewById( - R.id.new_window_context_menu_id); - iv.setImageResource(R.drawable.ic_windows_holo_dark); - } - return view; - } - - @Override - public void actionItemClicked(View v, BookmarkDragState state) { - if (v.getId() == R.id.info) { - mGrid.showContextMenuForState(state); - } else { - ExtraDragState extraState = (ExtraDragState) state.extraState; - handleContextItem(v.getId(), extraState.groupPosition, - extraState.childPosition); - } - } - }; - private static class LookupBookmarkCount extends AsyncTask<Long, Void, Integer> { Context mContext; BookmarkItem mHeader; diff --git a/src/com/android/browser/view/BookmarkExpandableView.java b/src/com/android/browser/view/BookmarkExpandableView.java index da96438..095bb7b 100644 --- a/src/com/android/browser/view/BookmarkExpandableView.java +++ b/src/com/android/browser/view/BookmarkExpandableView.java @@ -17,7 +17,6 @@ package com.android.browser.view; import android.content.Context; -import android.database.Cursor; import android.database.DataSetObserver; import android.provider.BrowserContract; import android.util.AttributeSet; @@ -33,12 +32,8 @@ import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; -import com.android.browser.BookmarkDragHandler; -import com.android.browser.BookmarkDragHandler.BookmarkDragAdapter; -import com.android.browser.BookmarkDragHandler.BookmarkDragState; import com.android.browser.BreadCrumbView; import com.android.browser.BrowserBookmarksAdapter; -import com.android.browser.BrowserBookmarksPage.ExtraDragState; import com.android.browser.R; import com.android.internal.view.menu.MenuBuilder; @@ -53,9 +48,6 @@ public class BookmarkExpandableView extends ExpandableListView public static final String LOCAL_ACCOUNT_NAME = "local"; - // Experimental drag & drop - private static final boolean ENABLE_DRAG_DROP = false; - private BookmarkAccountAdapter mAdapter; private int mColumnWidth; private Context mContext; @@ -64,7 +56,6 @@ public class BookmarkExpandableView extends ExpandableListView private OnCreateContextMenuListener mOnCreateContextMenuListener; private boolean mLongClickable; private BreadCrumbView.Controller mBreadcrumbController; - private BookmarkDragHandler mDragHandler; private int mMaxColumnCount; public BookmarkExpandableView(Context context) { @@ -224,36 +215,6 @@ public class BookmarkExpandableView extends ExpandableListView return mAdapter.mChildren.get(groupPosition); } - public BookmarkDragAdapter getDragAdapter() { - return mDragAdapter; - } - - public void showContextMenuForState(BookmarkDragState state) { - ExtraDragState extraState = (ExtraDragState) state.extraState; - mContextMenuInfo = new BookmarkContextMenuInfo( - extraState.childPosition, - extraState.groupPosition); - if (getParent() != null) { - getParent().showContextMenuForChild(BookmarkExpandableView.this); - } - } - - private BookmarkDragAdapter mDragAdapter = new BookmarkDragAdapter() { - - @Override - public void setBookmarkDragHandler(BookmarkDragHandler handler) { - mDragHandler = handler; - } - - @Override - public Cursor getItemForView(View v) { - int groupPosition = (Integer) v.getTag(R.id.group_position); - int childPosition = (Integer) v.getTag(R.id.child_position); - return getChildAdapter(groupPosition).getItem(childPosition); - } - - }; - private OnClickListener mChildClickListener = new OnClickListener() { @Override @@ -288,23 +249,6 @@ public class BookmarkExpandableView extends ExpandableListView } }; - private OnLongClickListener mChildOnLongClickListener = new OnLongClickListener() { - - @Override - public boolean onLongClick(View v) { - if (!ENABLE_DRAG_DROP) { - return false; - } - ExtraDragState state = new ExtraDragState(); - state.groupPosition = (Integer) v.getTag(R.id.group_position); - state.childPosition = (Integer) v.getTag(R.id.child_position); - long id = (Long) v.getTag(R.id.child_id); - Cursor c = getChildAdapter(state.groupPosition) - .getItem(state.childPosition); - return mDragHandler.startDrag(v, c, id, state); - } - }; - public BreadCrumbView getBreadCrumbs(int groupPosition) { return mAdapter.getBreadCrumbView(groupPosition); } @@ -390,10 +334,6 @@ public class BookmarkExpandableView extends ExpandableListView v.setTag(R.id.child_id, childAdapter.getItemId(realChildPosition)); v.setOnClickListener(mChildClickListener); v.setLongClickable(mLongClickable); - if (mDragHandler != null) { - v.setOnLongClickListener(mChildOnLongClickListener); - mDragHandler.registerBookmarkDragHandler(v); - } if (cv == null) { row.addView(v); } else if (cv != v) { |