Bug 1129433 - Show "# tabs opened in background" notification in system tray (r=mcomella)
This commit is contained in:
@@ -186,6 +186,20 @@
|
|||||||
|
|
||||||
<!ENTITY tab_queue_toast_message "Open later">
|
<!ENTITY tab_queue_toast_message "Open later">
|
||||||
<!ENTITY tab_queue_toast_action "Open now">
|
<!ENTITY tab_queue_toast_action "Open now">
|
||||||
|
<!-- Localization note (tab_queue_notification_text_plural) : The
|
||||||
|
formatD is replaced with the number of tabs queued. The
|
||||||
|
number of tabs queued is always more than one. We can't use
|
||||||
|
Android plural forms, sadly. See Bug #753859. -->
|
||||||
|
<!ENTITY tab_queue_notification_text_plural "&formatD; tabs queued">
|
||||||
|
<!-- Localization note (tab_queue_notification_title_plural) : This is the
|
||||||
|
title of a notification; we expect more than one tab queued. -->
|
||||||
|
<!ENTITY tab_queue_notification_title_plural "Tabs Queued">
|
||||||
|
<!-- Localization note (tab_queue_notification_title_singular) : This is the
|
||||||
|
title of a notification; we expect only one tab queued. -->
|
||||||
|
<!ENTITY tab_queue_notification_title_singular "Tab Queued">
|
||||||
|
<!-- Localization note (tab_queue_notification_text_singular) : This is the
|
||||||
|
text of a notification; we expect only one tab queued. -->
|
||||||
|
<!ENTITY tab_queue_notification_text_singular "1 tab queued">
|
||||||
|
|
||||||
<!ENTITY pref_char_encoding "Character encoding">
|
<!ENTITY pref_char_encoding "Character encoding">
|
||||||
<!ENTITY pref_char_encoding_on "Show menu">
|
<!ENTITY pref_char_encoding_on "Show menu">
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
|
<item type="id" name="tabQueueNotification"/>
|
||||||
<item type="id" name="guestNotification"/>
|
<item type="id" name="guestNotification"/>
|
||||||
<item type="id" name="original_height"/>
|
<item type="id" name="original_height"/>
|
||||||
<item type="id" name="menu_items"/>
|
<item type="id" name="menu_items"/>
|
||||||
|
|||||||
@@ -241,6 +241,10 @@
|
|||||||
|
|
||||||
<string name="tab_queue_toast_message">&tab_queue_toast_message;</string>
|
<string name="tab_queue_toast_message">&tab_queue_toast_message;</string>
|
||||||
<string name="tab_queue_toast_action">&tab_queue_toast_action;</string>
|
<string name="tab_queue_toast_action">&tab_queue_toast_action;</string>
|
||||||
|
<string name="tab_queue_notification_text_singular">&tab_queue_notification_text_singular;</string>
|
||||||
|
<string name="tab_queue_notification_text_plural">&tab_queue_notification_text_plural;</string>
|
||||||
|
<string name="tab_queue_notification_title_singular">&tab_queue_notification_title_singular;</string>
|
||||||
|
<string name="tab_queue_notification_title_plural">&tab_queue_notification_title_plural;</string>
|
||||||
|
|
||||||
<string name="pref_about_firefox">&pref_about_firefox;</string>
|
<string name="pref_about_firefox">&pref_about_firefox;</string>
|
||||||
<string name="pref_vendor_faqs">&pref_vendor_faqs;</string>
|
<string name="pref_vendor_faqs">&pref_vendor_faqs;</string>
|
||||||
|
|||||||
@@ -5,20 +5,24 @@
|
|||||||
|
|
||||||
package org.mozilla.gecko.tabqueue;
|
package org.mozilla.gecko.tabqueue;
|
||||||
|
|
||||||
import org.mozilla.gecko.GeckoProfile;
|
import android.app.NotificationManager;
|
||||||
import org.mozilla.gecko.util.ThreadUtils;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.content.res.Resources;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.mozilla.gecko.BrowserApp;
|
||||||
|
import org.mozilla.gecko.GeckoProfile;
|
||||||
import java.io.IOException;
|
import org.mozilla.gecko.R;
|
||||||
|
import org.mozilla.gecko.util.ThreadUtils;
|
||||||
|
|
||||||
public class TabQueueHelper {
|
public class TabQueueHelper {
|
||||||
private static final String LOGTAG = "Gecko" + TabQueueHelper.class.getSimpleName();
|
private static final String LOGTAG = "Gecko" + TabQueueHelper.class.getSimpleName();
|
||||||
|
|
||||||
public static final String FILE_NAME = "tab_queue_url_list.json";
|
public static final String FILE_NAME = "tab_queue_url_list.json";
|
||||||
|
public static final String LOAD_URLS_ACTION = "TAB_QUEUE_LOAD_URLS_ACTION";
|
||||||
|
public static final int TAB_QUEUE_NOTIFICATION_ID = R.id.tabQueueNotification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads file and converts any content to JSON, adds passed in URL to the data and writes back to the file,
|
* Reads file and converts any content to JSON, adds passed in URL to the data and writes back to the file,
|
||||||
@@ -27,8 +31,9 @@ public class TabQueueHelper {
|
|||||||
* @param profile
|
* @param profile
|
||||||
* @param url URL to add
|
* @param url URL to add
|
||||||
* @param filename filename to add URL to
|
* @param filename filename to add URL to
|
||||||
|
* @return the number of tabs currently queued
|
||||||
*/
|
*/
|
||||||
public static void queueURL(final GeckoProfile profile, final String url, final String filename) {
|
public static int queueURL(final GeckoProfile profile, final String url, final String filename) {
|
||||||
ThreadUtils.assertNotOnUiThread();
|
ThreadUtils.assertNotOnUiThread();
|
||||||
|
|
||||||
JSONArray jsonArray = profile.readJSONArrayFromFile(filename);
|
JSONArray jsonArray = profile.readJSONArrayFromFile(filename);
|
||||||
@@ -36,5 +41,40 @@ public class TabQueueHelper {
|
|||||||
jsonArray.put(url);
|
jsonArray.put(url);
|
||||||
|
|
||||||
profile.writeFile(filename, jsonArray.toString());
|
profile.writeFile(filename, jsonArray.toString());
|
||||||
|
|
||||||
|
return jsonArray.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a notification showing the total number of tabs queue. If there is already a notification displayed, it
|
||||||
|
* will be replaced.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param tabsQueued
|
||||||
|
*/
|
||||||
|
static public void showNotification(Context context, int tabsQueued) {
|
||||||
|
Intent resultIntent = new Intent(context, BrowserApp.class);
|
||||||
|
resultIntent.setAction(TabQueueHelper.LOAD_URLS_ACTION);
|
||||||
|
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
|
||||||
|
String title, text;
|
||||||
|
final Resources resources = context.getResources();
|
||||||
|
if(tabsQueued == 1) {
|
||||||
|
title = resources.getString(R.string.tab_queue_notification_title_singular);
|
||||||
|
text = resources.getString(R.string.tab_queue_notification_text_singular);
|
||||||
|
} else {
|
||||||
|
title = resources.getString(R.string.tab_queue_notification_title_plural);
|
||||||
|
text = resources.getString(R.string.tab_queue_notification_text_plural, tabsQueued);
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
||||||
|
.setSmallIcon(R.drawable.ic_status_logo)
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(text)
|
||||||
|
.setContentIntent(pendingIntent);
|
||||||
|
|
||||||
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
notificationManager.notify(TabQueueHelper.TAB_QUEUE_NOTIFICATION_ID, builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.mozilla.gecko.tabqueue;
|
package org.mozilla.gecko.tabqueue;
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
@@ -160,8 +161,10 @@ public class TabQueueService extends Service {
|
|||||||
executorService.submit(new Runnable() {
|
executorService.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final GeckoProfile profile = GeckoProfile.get(getApplicationContext());
|
Context applicationContext = getApplicationContext();
|
||||||
TabQueueHelper.queueURL(profile, intentData, filename);
|
final GeckoProfile profile = GeckoProfile.get(applicationContext);
|
||||||
|
int tabsQueued = TabQueueHelper.queueURL(profile, intentData, filename);
|
||||||
|
TabQueueHelper.showNotification(applicationContext, tabsQueued);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user