am 6bd267f4: Merge "Add new attributes to our notification" into lmp-dev
* commit '6bd267f4f7b23ba3ecf24a0b70829cc11dbe5832': Add new attributes to our notificationmain
commit
3ef26ac13b
|
@ -82,4 +82,6 @@
|
|||
<color name="setup_text_action">@android:color/holo_blue_light</color>
|
||||
<color name="setup_step_background">@android:color/background_light</color>
|
||||
<color name="setup_welcome_video_margin_color">#FFCCCCCC</color>
|
||||
<!-- Accent color for the notification. We need to match this to the OS build -->
|
||||
<color name="notification_accent_color">#FF607D8B</color>
|
||||
</resources>
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.inputmethod.compat;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.os.Build;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class NotificationCompatUtils {
|
||||
// Note that TextInfo.getCharSequence() is supposed to be available in API level 21 and later.
|
||||
private static final Method METHOD_setColor =
|
||||
CompatUtils.getMethod(Notification.Builder.class, "setColor", int.class);
|
||||
private static final Method METHOD_setVisibility =
|
||||
CompatUtils.getMethod(Notification.Builder.class, "setVisibility", int.class);
|
||||
private static final Method METHOD_setCategory =
|
||||
CompatUtils.getMethod(Notification.Builder.class, "setCategory", String.class);
|
||||
private static final Method METHOD_setPriority =
|
||||
CompatUtils.getMethod(Notification.Builder.class, "setPriority", int.class);
|
||||
private static final Method METHOD_build =
|
||||
CompatUtils.getMethod(Notification.Builder.class, "build");
|
||||
private static final Field FIELD_VISIBILITY_SECRET =
|
||||
CompatUtils.getField(Notification.class, "VISIBILITY_SECRET");
|
||||
private static final int VISIBILITY_SECRET = null == FIELD_VISIBILITY_SECRET ? 0
|
||||
: (Integer) CompatUtils.getFieldValue(null /* receiver */, null /* defaultValue */,
|
||||
FIELD_VISIBILITY_SECRET);
|
||||
private static final Field FIELD_CATEGORY_RECOMMENDATION =
|
||||
CompatUtils.getField(Notification.class, "CATEGORY_RECOMMENDATION");
|
||||
private static final String CATEGORY_RECOMMENDATION = null == FIELD_CATEGORY_RECOMMENDATION ? ""
|
||||
: (String) CompatUtils.getFieldValue(null /* receiver */, null /* defaultValue */,
|
||||
FIELD_CATEGORY_RECOMMENDATION);
|
||||
private static final Field FIELD_PRIORITY_LOW =
|
||||
CompatUtils.getField(Notification.class, "PRIORITY_LOW");
|
||||
private static final int PRIORITY_LOW = null == FIELD_PRIORITY_LOW ? 0
|
||||
: (Integer) CompatUtils.getFieldValue(null /* receiver */, null /* defaultValue */,
|
||||
FIELD_PRIORITY_LOW);
|
||||
|
||||
private NotificationCompatUtils() {
|
||||
// This class is non-instantiable.
|
||||
}
|
||||
|
||||
// Sets the accent color
|
||||
public static void setColor(final Notification.Builder builder, final int color) {
|
||||
CompatUtils.invoke(builder, null, METHOD_setColor, color);
|
||||
}
|
||||
|
||||
public static void setVisibilityToSecret(final Notification.Builder builder) {
|
||||
CompatUtils.invoke(builder, null, METHOD_setVisibility, VISIBILITY_SECRET);
|
||||
}
|
||||
|
||||
public static void setCategoryToRecommendation(final Notification.Builder builder) {
|
||||
CompatUtils.invoke(builder, null, METHOD_setCategory, CATEGORY_RECOMMENDATION);
|
||||
}
|
||||
|
||||
public static void setPriorityToLow(final Notification.Builder builder) {
|
||||
CompatUtils.invoke(builder, null, METHOD_setPriority, PRIORITY_LOW);
|
||||
}
|
||||
|
||||
public static Notification build(final Notification.Builder builder) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
// #build was added in API level 16, JELLY_BEAN
|
||||
return (Notification) CompatUtils.invoke(builder, null, METHOD_build);
|
||||
} else {
|
||||
// #getNotification was deprecated in API level 16, JELLY_BEAN
|
||||
return builder.getNotification();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,12 +31,14 @@ import android.database.Cursor;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.inputmethod.compat.ConnectivityManagerCompatUtils;
|
||||
import com.android.inputmethod.compat.DownloadManagerCompatUtils;
|
||||
import com.android.inputmethod.compat.NotificationCompatUtils;
|
||||
import com.android.inputmethod.latin.R;
|
||||
import com.android.inputmethod.latin.utils.ApplicationUtils;
|
||||
import com.android.inputmethod.latin.utils.DebugLogUtils;
|
||||
|
@ -858,7 +860,7 @@ public final class UpdateHandler {
|
|||
final String language = (null == locale ? "" : locale.getDisplayLanguage());
|
||||
final String titleFormat = context.getString(R.string.dict_available_notification_title);
|
||||
final String notificationTitle = String.format(titleFormat, language);
|
||||
final Notification notification = new Notification.Builder(context)
|
||||
final Notification.Builder builder = new Notification.Builder(context)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(notificationIntent)
|
||||
.setContentTitle(notificationTitle)
|
||||
|
@ -866,8 +868,13 @@ public final class UpdateHandler {
|
|||
.setTicker(notificationTitle)
|
||||
.setOngoing(false)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setSmallIcon(R.drawable.ic_notify_dictionary)
|
||||
.getNotification();
|
||||
.setSmallIcon(R.drawable.ic_notify_dictionary);
|
||||
NotificationCompatUtils.setColor(builder,
|
||||
context.getResources().getColor(R.color.notification_accent_color));
|
||||
NotificationCompatUtils.setPriorityToLow(builder);
|
||||
NotificationCompatUtils.setVisibilityToSecret(builder);
|
||||
NotificationCompatUtils.setCategoryToRecommendation(builder);
|
||||
final Notification notification = NotificationCompatUtils.build(builder);
|
||||
notificationManager.notify(DICT_AVAILABLE_NOTIFICATION_ID, notification);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue