mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 650209 - Allow DOMDesktopNotification to use a custom icon in the expanded android notification r=dougt
This commit is contained in:
parent
2b253e251c
commit
456c4cb22e
@ -101,11 +101,7 @@ nsDOMDesktopNotification::nsDOMDesktopNotification(const nsAString & title,
|
||||
nsIURI* uri)
|
||||
: mTitle(title)
|
||||
, mDescription(description)
|
||||
#ifdef ANDROID
|
||||
, mIconURL((PRUnichar*)L"drawable://desktop_notification")
|
||||
#else
|
||||
, mIconURL(iconURL)
|
||||
#endif
|
||||
, mURI(uri)
|
||||
, mAllow(PR_FALSE)
|
||||
, mShowHasBeenCalled(PR_FALSE)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: Java; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
@ -40,7 +40,11 @@ package org.mozilla.gecko;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.*;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
import java.net.*;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class AlertNotification
|
||||
@ -56,6 +60,7 @@ public class AlertNotification
|
||||
double mPrevPercent = -1;
|
||||
String mPrevAlertText = "";
|
||||
static final double UPDATE_THRESHOLD = .01;
|
||||
Uri mIconUri = null;
|
||||
|
||||
public AlertNotification(Context aContext, int aNotificationId, int aIcon,
|
||||
String aTitle, String aText, long aWhen) {
|
||||
@ -80,10 +85,31 @@ public class AlertNotification
|
||||
mNotificationManager.notify(mId, this);
|
||||
}
|
||||
|
||||
public void setCustomIcon(Uri aIconUri) {
|
||||
mIconUri = aIconUri;
|
||||
// Custom view
|
||||
int layout = R.layout.notification_icon_text;
|
||||
RemoteViews view = new RemoteViews(GeckoApp.mAppContext.getPackageName(), layout);
|
||||
try {
|
||||
URL url = new URL(aIconUri.toString());
|
||||
Bitmap bm = BitmapFactory.decodeStream(url.openStream());
|
||||
view.setImageViewBitmap(R.id.notificationImage, bm);
|
||||
view.setTextViewText(R.id.notificationTitle, mTitle);
|
||||
if (mText.length() > 0) {
|
||||
view.setTextViewText(R.id.notificationText, mText);
|
||||
}
|
||||
contentView = view;
|
||||
mNotificationManager.notify(mId, this);
|
||||
} catch(Exception ex) {
|
||||
Log.e("GeckoAlert", "failed to create bitmap", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateProgress(String aAlertText, long aProgress, long aProgressMax) {
|
||||
if (!mProgressStyle) {
|
||||
// Custom view
|
||||
int layout = aAlertText.length() > 0 ? R.layout.notification_progress_text : R.layout.notification_progress;
|
||||
int layout = aAlertText.length() > 0 ? R.layout.notification_progress_text : R.layout.notification_progress;
|
||||
|
||||
RemoteViews view = new RemoteViews(GeckoApp.mAppContext.getPackageName(), layout);
|
||||
view.setImageViewResource(R.id.notificationImage, mIcon);
|
||||
|
@ -829,6 +829,7 @@ public class GeckoAppShell
|
||||
Field f = drawableClass.getField(resource);
|
||||
icon = f.getInt(null);
|
||||
} catch (Exception e) {} // just means the resource doesn't exist
|
||||
imageUri = null;
|
||||
}
|
||||
|
||||
int notificationID = aAlertName.hashCode();
|
||||
@ -836,8 +837,10 @@ public class GeckoAppShell
|
||||
// Remove the old notification with the same ID, if any
|
||||
removeNotification(notificationID);
|
||||
|
||||
AlertNotification notification = new AlertNotification(GeckoApp.mAppContext,
|
||||
notificationID, icon, aAlertTitle, aAlertText, System.currentTimeMillis());
|
||||
AlertNotification notification =
|
||||
new AlertNotification(GeckoApp.mAppContext,notificationID, icon,
|
||||
aAlertTitle, aAlertText,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The intent to launch when the user clicks the expanded notification
|
||||
Intent notificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLICK);
|
||||
@ -850,7 +853,7 @@ public class GeckoAppShell
|
||||
|
||||
PendingIntent contentIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, notificationIntent, 0);
|
||||
notification.setLatestEventInfo(GeckoApp.mAppContext, aAlertTitle, aAlertText, contentIntent);
|
||||
|
||||
notification.setCustomIcon(imageUri);
|
||||
// The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button
|
||||
Intent clearNotificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLEAR);
|
||||
clearNotificationIntent.setClassName(GeckoApp.mAppContext,
|
||||
|
@ -106,6 +106,7 @@ endif
|
||||
RES_LAYOUT = \
|
||||
res/layout/notification_progress.xml \
|
||||
res/layout/notification_progress_text.xml \
|
||||
res/layout/notification_icon_text.xml \
|
||||
$(NULL)
|
||||
|
||||
RES_VALUES = res/values/colors.xml res/values/themes.xml
|
||||
|
@ -0,0 +1,34 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="5dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<ImageView android:id="@+id/notificationImage"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:scaleType="fitCenter" />
|
||||
<TextView android:id="@+id/notificationTitle"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal"
|
||||
android:textStyle="bold"
|
||||
android:textSize="18sp"
|
||||
android:paddingLeft="4dp"
|
||||
android:textColor="#ff000000" />
|
||||
</LinearLayout>
|
||||
<TextView android:id="@+id/notificationText"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="4dp"
|
||||
android:textColor="#ff000000" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user