mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 05:30:29 +00:00
Bug 785199 - Add context menu to Remote Tabs home panel. r=margaret
This commit is contained in:
parent
6aa2bf3b81
commit
19a72370fc
@ -5,13 +5,13 @@
|
||||
|
||||
package org.mozilla.gecko.home;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserContract.Combined;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
|
||||
/**
|
||||
* A ContextMenuInfo for HomeListView
|
||||
@ -52,10 +52,17 @@ public class HomeContextMenuInfo extends AdapterContextMenuInfo {
|
||||
return StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS));
|
||||
}
|
||||
|
||||
/*
|
||||
* Interface for creating ContextMenuInfo from cursors
|
||||
/**
|
||||
* Interface for creating ContextMenuInfo instances from cursors.
|
||||
*/
|
||||
public interface Factory {
|
||||
public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for creating ContextMenuInfo instances from ExpandableListAdapters.
|
||||
*/
|
||||
public interface ExpandableFactory {
|
||||
public HomeContextMenuInfo makeInfoForAdapter(View view, int position, long id, ExpandableListAdapter adapter);
|
||||
}
|
||||
}
|
||||
|
68
mobile/android/base/home/HomeExpandableListView.java
Normal file
68
mobile/android/base/home/HomeExpandableListView.java
Normal file
@ -0,0 +1,68 @@
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.home;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.ExpandableListView;
|
||||
|
||||
/**
|
||||
* <code>HomeExpandableListView</code> is a custom extension of
|
||||
* <code>ExpandableListView<code>, that packs a <code>HomeContextMenuInfo</code>
|
||||
* when any of its rows is long pressed.
|
||||
* <p>
|
||||
* This is the <code>ExpandableListView</code> equivalent of
|
||||
* <code>HomeListView</code>.
|
||||
*/
|
||||
public class HomeExpandableListView extends ExpandableListView
|
||||
implements OnItemLongClickListener {
|
||||
|
||||
// ContextMenuInfo associated with the currently long pressed list item.
|
||||
private HomeContextMenuInfo mContextMenuInfo;
|
||||
|
||||
// ContextMenuInfo factory.
|
||||
private HomeContextMenuInfo.ExpandableFactory mContextMenuInfoFactory;
|
||||
|
||||
public HomeExpandableListView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public HomeExpandableListView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public HomeExpandableListView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
setOnItemLongClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (mContextMenuInfoFactory == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// HomeExpandableListView items can correspond to groups and children.
|
||||
// The factory can determine whether to add context menu for either,
|
||||
// both, or none by unpacking the given position.
|
||||
mContextMenuInfo = mContextMenuInfoFactory.makeInfoForAdapter(view, position, id, getExpandableListAdapter());
|
||||
return showContextMenuForChild(HomeExpandableListView.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextMenuInfo getContextMenuInfo() {
|
||||
return mContextMenuInfo;
|
||||
}
|
||||
|
||||
public void setContextMenuInfoFactory(final HomeContextMenuInfo.ExpandableFactory factory) {
|
||||
mContextMenuInfoFactory = factory;
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ public class RemoteTabsExpandableListFragment extends HomeFragment {
|
||||
private RemoteTabsExpandableListAdapter mAdapter;
|
||||
|
||||
// The view shown by the fragment.
|
||||
private ExpandableListView mList;
|
||||
private HomeExpandableListView mList;
|
||||
|
||||
// Reference to the View to display when there are no results.
|
||||
private View mEmptyView;
|
||||
@ -94,7 +94,7 @@ public class RemoteTabsExpandableListFragment extends HomeFragment {
|
||||
mSyncStatusListener = new RemoteTabsSyncListener();
|
||||
FirefoxAccounts.addSyncStatusListener(mSyncStatusListener);
|
||||
|
||||
mList = (ExpandableListView) view.findViewById(R.id.list);
|
||||
mList = (HomeExpandableListView) view.findViewById(R.id.list);
|
||||
mList.setTag(HomePager.LIST_TAG_REMOTE_TABS);
|
||||
|
||||
mList.setOnChildClickListener(new OnChildClickListener() {
|
||||
@ -122,6 +122,31 @@ public class RemoteTabsExpandableListFragment extends HomeFragment {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Show a context menu only for tabs (not for clients).
|
||||
mList.setContextMenuInfoFactory(new HomeContextMenuInfo.ExpandableFactory() {
|
||||
@Override
|
||||
public HomeContextMenuInfo makeInfoForAdapter(View view, int position, long id, ExpandableListAdapter adapter) {
|
||||
long packedPosition = mList.getExpandableListPosition(position);
|
||||
if (ExpandableListView.getPackedPositionType(packedPosition) != ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
|
||||
return null;
|
||||
}
|
||||
final int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);
|
||||
final int childPosition = ExpandableListView.getPackedPositionChild(packedPosition);
|
||||
final Object child = adapter.getChild(groupPosition, childPosition);
|
||||
if (child instanceof RemoteTab) {
|
||||
final RemoteTab tab = (RemoteTab) child;
|
||||
final HomeContextMenuInfo info = new HomeContextMenuInfo(view, position, id);
|
||||
info.url = tab.url;
|
||||
info.title = tab.title;
|
||||
return info;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
registerForContextMenu(mList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -275,6 +275,7 @@ gbjar.sources += [
|
||||
'home/HomeConfigLoader.java',
|
||||
'home/HomeConfigPrefsBackend.java',
|
||||
'home/HomeContextMenuInfo.java',
|
||||
'home/HomeExpandableListView.java',
|
||||
'home/HomeFragment.java',
|
||||
'home/HomeListView.java',
|
||||
'home/HomePager.java',
|
||||
|
@ -18,7 +18,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ExpandableListView
|
||||
<org.mozilla.gecko.home.HomeExpandableListView
|
||||
android:id="@+id/list"
|
||||
style="@style/Widget.RemoteTabsListView"
|
||||
android:groupIndicator="@android:color/transparent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user