Bug 1290029 - go back to the playing tab when double clicking the control interface. r=sebastian

MozReview-Commit-ID: JfXm7vBKqfW

--HG--
extra : rebase_source : 517c28f8fec572e7b2a719a7dd365cdd5662c5b6
This commit is contained in:
Alastor Wu 2016-08-09 17:19:11 +08:00
parent d78a374b2d
commit f372aaf404
3 changed files with 22 additions and 3 deletions

View File

@ -144,6 +144,7 @@ public abstract class GeckoApp
public static final String ACTION_LAUNCH_SETTINGS = "org.mozilla.gecko.SETTINGS";
public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD";
public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW";
public static final String ACTION_SWITCH_TAB = "org.mozilla.gecko.SWITCH_TAB";
public static final String INTENT_REGISTER_STUMBLER_LISTENER = "org.mozilla.gecko.STUMBLER_REGISTER_LOCAL_LISTENER";
@ -2077,6 +2078,9 @@ public abstract class GeckoApp
// Copy extras.
settingsIntent.putExtras(intent.getUnsafe());
startActivity(settingsIntent);
} else if (ACTION_SWITCH_TAB.equals(action)) {
final int tabId = intent.getIntExtra("TabId", -1);
Tabs.getInstance().selectTab(tabId);
}
recordStartupActionTelemetry(passedUri, action);

View File

@ -19,6 +19,7 @@ import android.util.Log;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.R;
@ -297,7 +298,7 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
.setLargeIcon(generateCoverArt(tab))
.setContentTitle(tab.getTitle())
.setContentText(tab.getURL())
.setContentIntent(createContentIntent())
.setContentIntent(createContentIntent(tab.getId()))
.setDeleteIntent(createDeleteIntent())
.setStyle(style)
.addAction(createNotificationAction(action))
@ -330,9 +331,11 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
return new Notification.Action.Builder(icon, title, pendingIntent).build();
}
private PendingIntent createContentIntent() {
private PendingIntent createContentIntent(int tabId) {
Intent intent = new Intent(getApplicationContext(), BrowserApp.class);
return PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
intent.setAction(GeckoApp.ACTION_SWITCH_TAB);
intent.putExtra("TabId", tabId);
return PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
private PendingIntent createDeleteIntent() {

View File

@ -38,6 +38,18 @@ public class SafeIntent {
}
}
public int getIntExtra(final String name, final int defaultValue) {
try {
return intent.getIntExtra(name, defaultValue);
} catch (OutOfMemoryError e) {
Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
return defaultValue;
} catch (RuntimeException e) {
Log.w(LOGTAG, "Couldn't get intent extras.", e);
return defaultValue;
}
}
public String getStringExtra(final String name) {
try {
return intent.getStringExtra(name);