Bug 855016 - Allow gamepad action button to trigger the row items on about:home. r=sriram

This commit is contained in:
Kartikaya Gupta 2013-03-28 11:35:04 -04:00
parent 680343c1d7
commit af2eae9ced
2 changed files with 22 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper; import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper;
import org.mozilla.gecko.sync.setup.SyncAccounts; import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.util.ActivityResultHandler; import org.mozilla.gecko.util.ActivityResultHandler;
import org.mozilla.gecko.util.GamepadUtils;
import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask; import org.mozilla.gecko.util.UiAsyncTask;
@ -616,6 +617,7 @@ public class AboutHomeContent extends ScrollView
mUriLoadCallback.callback(homepageUrl); mUriLoadCallback.callback(homepageUrl);
} }
}); });
row.setOnKeyListener(GamepadUtils.getClickDispatcher());
Favicons favicons = Favicons.getInstance(); Favicons favicons = Favicons.getInstance();
favicons.loadFavicon(pageUrl, iconUrl, true, favicons.loadFavicon(pageUrl, iconUrl, true,
@ -681,6 +683,7 @@ public class AboutHomeContent extends ScrollView
Tabs.getInstance().loadUrl(url, flags); Tabs.getInstance().loadUrl(url, flags);
} }
}); });
container.setOnKeyListener(GamepadUtils.getClickDispatcher());
mLastTabs.addItem(container); mLastTabs.addItem(container);
} }
@ -752,6 +755,7 @@ public class AboutHomeContent extends ScrollView
row.setTag(tab.url); row.setTag(tab.url);
mRemoteTabs.addItem(row); mRemoteTabs.addItem(row);
row.setOnClickListener(mRemoteTabClickListener); row.setOnClickListener(mRemoteTabClickListener);
row.setOnKeyListener(GamepadUtils.getClickDispatcher());
} }
mRemoteTabs.setSubtitle(client); mRemoteTabs.setSubtitle(client);

View File

@ -8,8 +8,11 @@ package org.mozilla.gecko.util;
import android.os.Build; import android.os.Build;
import android.view.InputDevice; import android.view.InputDevice;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View;
public final class GamepadUtils { public final class GamepadUtils {
private static View.OnKeyListener sClickDispatcher;
private GamepadUtils() { private GamepadUtils() {
} }
@ -27,4 +30,19 @@ public final class GamepadUtils {
public static boolean isBackKey(KeyEvent event) { public static boolean isBackKey(KeyEvent event) {
return (isGamepadKey(event) && (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B)); return (isGamepadKey(event) && (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B));
} }
public static View.OnKeyListener getClickDispatcher() {
if (sClickDispatcher == null) {
sClickDispatcher = new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && isActionKey(event)) {
return v.performClick();
}
return false;
}
};
}
return sClickDispatcher;
}
} }