зеркало из https://github.com/mozilla/gecko-dev.git
Bug 855431 - Make the gamepad action button work on awesome screen list items. r=sriram
This commit is contained in:
Родитель
879f7a4f1d
Коммит
ac3a9025f6
|
@ -998,6 +998,7 @@ MOZ_ANDROID_DRAWABLES += \
|
|||
mobile/android/base/resources/drawable/address_bar_bg_shadow_repeat.xml \
|
||||
mobile/android/base/resources/drawable/address_bar_nav_button.xml \
|
||||
mobile/android/base/resources/drawable/address_bar_url.xml \
|
||||
mobile/android/base/resources/drawable/awesomebar_header_row.xml \
|
||||
mobile/android/base/resources/drawable/awesomebar_row_favicon_bg.xml \
|
||||
mobile/android/base/resources/drawable/awesomebar_tab_indicator.xml \
|
||||
mobile/android/base/resources/drawable/awesomebar_tab_selected.xml \
|
||||
|
|
|
@ -10,10 +10,11 @@ import org.mozilla.gecko.db.BrowserContract.Combined;
|
|||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
||||
import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.util.UiAsyncTask;
|
||||
import org.mozilla.gecko.util.GamepadUtils;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.UiAsyncTask;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -134,6 +135,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
|
|||
handleItemClick(parent, view, position, id);
|
||||
}
|
||||
});
|
||||
list.setOnKeyListener(GamepadUtils.getListItemClickDispatcher());
|
||||
|
||||
AwesomeBarCursorAdapter adapter = getCursorAdapter();
|
||||
list.setAdapter(adapter);
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.mozilla.gecko.db.BrowserContract.Bookmarks;
|
|||
import org.mozilla.gecko.db.BrowserContract.Combined;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
||||
import org.mozilla.gecko.util.GamepadUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
|
@ -73,6 +74,7 @@ public class BookmarksTab extends AwesomeBarTab {
|
|||
handleItemClick(parent, view, position, id);
|
||||
}
|
||||
});
|
||||
list.setOnKeyListener(GamepadUtils.getListItemClickDispatcher());
|
||||
|
||||
if (mShowReadingList) {
|
||||
String title = getResources().getString(R.string.bookmarks_folder_reading_list);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.mozilla.gecko.AwesomeBar.ContextMenuSubject;
|
|||
import org.mozilla.gecko.db.BrowserContract.Combined;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
||||
import org.mozilla.gecko.util.GamepadUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
|
@ -25,6 +26,7 @@ import android.util.Log;
|
|||
import android.util.Pair;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
|
@ -90,6 +92,25 @@ public class HistoryTab extends AwesomeBarTab {
|
|||
return true;
|
||||
}
|
||||
});
|
||||
list.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (GamepadUtils.isActionKeyDown(event)) {
|
||||
ExpandableListView expando = (ExpandableListView)v;
|
||||
long selected = expando.getSelectedPosition();
|
||||
switch (ExpandableListView.getPackedPositionType(selected)) {
|
||||
case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
|
||||
return handleItemClick(ExpandableListView.getPackedPositionGroup(selected),
|
||||
ExpandableListView.getPackedPositionChild(selected));
|
||||
case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
|
||||
int group = ExpandableListView.getPackedPositionGroup(selected);
|
||||
return (expando.isGroupExpanded(group)
|
||||
? expando.collapseGroup(group)
|
||||
: expando.expandGroup(group));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mView.setOnTouchListener(mListListener);
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true"
|
||||
android:drawable="@color/awesomebar_header_row_focused"/>
|
||||
|
||||
<item android:drawable="@color/awesomebar_header_row"/>
|
||||
|
||||
</selector>
|
|
@ -7,7 +7,7 @@
|
|||
android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/awesomebar_header_row_height"
|
||||
android:background="#D2DAE2"
|
||||
android:background="@drawable/awesomebar_header_row"
|
||||
android:textColor="#222222"
|
||||
android:textSize="13sp"
|
||||
android:textStyle="bold"
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<resources>
|
||||
<color name="awesomebar_header_row">#FFD2DAE2</color>
|
||||
<color name="awesomebar_header_row_focused">#FFA2AAB2</color>
|
||||
<color name="background_normal">#FFCED7DE</color>
|
||||
<color name="background_private">#FF292C29</color>
|
||||
<color name="background_tabs_dark">#FF363B40</color>
|
||||
|
|
|
@ -9,9 +9,12 @@ import android.os.Build;
|
|||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
public final class GamepadUtils {
|
||||
private static View.OnKeyListener sClickDispatcher;
|
||||
private static View.OnKeyListener sListItemClickDispatcher;
|
||||
|
||||
private GamepadUtils() {
|
||||
}
|
||||
|
@ -27,6 +30,10 @@ public final class GamepadUtils {
|
|||
return (isGamepadKey(event) && (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_A));
|
||||
}
|
||||
|
||||
public static boolean isActionKeyDown(KeyEvent event) {
|
||||
return isActionKey(event) && event.getAction() == KeyEvent.ACTION_DOWN;
|
||||
}
|
||||
|
||||
public static boolean isBackKey(KeyEvent event) {
|
||||
return (isGamepadKey(event) && (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B));
|
||||
}
|
||||
|
@ -36,7 +43,7 @@ public final class GamepadUtils {
|
|||
sClickDispatcher = new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN && isActionKey(event)) {
|
||||
if (isActionKeyDown(event)) {
|
||||
return v.performClick();
|
||||
}
|
||||
return false;
|
||||
|
@ -45,4 +52,24 @@ public final class GamepadUtils {
|
|||
}
|
||||
return sClickDispatcher;
|
||||
}
|
||||
|
||||
public static View.OnKeyListener getListItemClickDispatcher() {
|
||||
if (sListItemClickDispatcher == null) {
|
||||
sListItemClickDispatcher = new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (isActionKeyDown(event) && (v instanceof ListView)) {
|
||||
ListView view = (ListView)v;
|
||||
AdapterView.OnItemClickListener listener = view.getOnItemClickListener();
|
||||
if (listener != null) {
|
||||
listener.onItemClick(view, view.getSelectedView(), view.getSelectedItemPosition(), view.getSelectedItemId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
return sListItemClickDispatcher;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче