use of android.widget.RemoteViews in project android_frameworks_base by ResurrectionRemix.
the class BaseStatusBar method inflateViews.
protected boolean inflateViews(Entry entry, ViewGroup parent) {
PackageManager pmUser = getPackageManagerForUser(mContext, entry.notification.getUser().getIdentifier());
final StatusBarNotification sbn = entry.notification;
try {
entry.cacheContentViews(mContext, null);
} catch (RuntimeException e) {
Log.e(TAG, "Unable to get notification remote views", e);
return false;
}
final RemoteViews contentView = entry.cachedContentView;
final RemoteViews bigContentView = entry.cachedBigContentView;
final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView;
final RemoteViews publicContentView = entry.cachedPublicContentView;
if (contentView == null) {
Log.v(TAG, "no contentView for: " + sbn.getNotification());
return false;
}
if (DEBUG) {
Log.v(TAG, "publicContentView: " + publicContentView);
}
ExpandableNotificationRow row;
// Stash away previous user expansion state so we can restore it at
// the end.
boolean hasUserChangedExpansion = false;
boolean userExpanded = false;
boolean userLocked = false;
if (entry.row != null) {
row = entry.row;
hasUserChangedExpansion = row.hasUserChangedExpansion();
userExpanded = row.isUserExpanded();
userLocked = row.isUserLocked();
entry.reset();
if (hasUserChangedExpansion) {
row.setUserExpanded(userExpanded);
}
} else {
// create the row view
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// cannot use isMediaNotification()
if (sbn.getNotification().category != null && sbn.getNotification().category.equals(Notification.CATEGORY_TRANSPORT)) {
Log.d("ro", "inflating media notification");
row = (MediaExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row_media, parent, false);
((MediaExpandableNotificationRow) row).setMediaController(getCurrentMediaController());
} else {
row = (ExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row, parent, false);
}
row.setExpansionLogger(this, entry.notification.getKey());
row.setGroupManager(mGroupManager);
row.setHeadsUpManager(mHeadsUpManager);
row.setRemoteInputController(mRemoteInputController);
row.setOnExpandClickListener(this);
// Get the app name.
// Note that Notification.Builder#bindHeaderAppName has similar logic
// but since this field is used in the guts, it must be accurate.
// Therefore we will only show the application label, or, failing that, the
// package name. No substitutions.
final String pkg = sbn.getPackageName();
String appname = pkg;
try {
final ApplicationInfo info = pmUser.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
if (info != null) {
appname = String.valueOf(pmUser.getApplicationLabel(info));
}
} catch (NameNotFoundException e) {
// Do nothing
}
row.setAppName(appname);
}
workAroundBadLayerDrawableOpacity(row);
bindDismissListener(row);
// NB: the large icon is now handled entirely by the template
// bind the click event to the content area
NotificationContentView contentContainer = row.getPrivateLayout();
NotificationContentView contentContainerPublic = row.getPublicLayout();
row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
if (ENABLE_REMOTE_INPUT) {
row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
}
mNotificationClicker.register(row, sbn);
// set up the adaptive layout
View contentViewLocal = null;
View bigContentViewLocal = null;
View headsUpContentViewLocal = null;
View publicViewLocal = null;
try {
contentViewLocal = contentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
if (bigContentView != null) {
bigContentViewLocal = bigContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
}
if (headsUpContentView != null) {
headsUpContentViewLocal = headsUpContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
}
if (publicContentView != null) {
publicViewLocal = publicContentView.apply(sbn.getPackageContext(mContext), contentContainerPublic, mOnClickHandler);
}
if (contentViewLocal != null) {
contentViewLocal.setIsRootNamespace(true);
contentContainer.setContractedChild(contentViewLocal);
}
if (bigContentViewLocal != null) {
bigContentViewLocal.setIsRootNamespace(true);
contentContainer.setExpandedChild(bigContentViewLocal);
}
if (headsUpContentViewLocal != null) {
headsUpContentViewLocal.setIsRootNamespace(true);
contentContainer.setHeadsUpChild(headsUpContentViewLocal);
}
if (publicViewLocal != null) {
publicViewLocal.setIsRootNamespace(true);
contentContainerPublic.setContractedChild(publicViewLocal);
}
} catch (RuntimeException e) {
final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
Log.e(TAG, "couldn't inflate view for notification " + ident, e);
return false;
}
// Extract target SDK version.
try {
ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0);
entry.targetSdk = info.targetSdkVersion;
} catch (NameNotFoundException ex) {
Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex);
}
entry.autoRedacted = entry.notification.getNotification().publicVersion == null;
if (MULTIUSER_DEBUG) {
TextView debug = (TextView) row.findViewById(R.id.debug_info);
if (debug != null) {
debug.setVisibility(View.VISIBLE);
debug.setText("CU " + mCurrentUserId + " NU " + entry.notification.getUserId());
}
}
entry.row = row;
entry.row.setOnActivatedListener(this);
entry.row.setExpandable(bigContentViewLocal != null);
applyColorsAndBackgrounds(sbn, entry);
// Restore previous flags.
if (hasUserChangedExpansion) {
// Note: setUserExpanded() conveniently ignores calls with
// userExpanded=true if !isExpandable().
row.setUserExpanded(userExpanded);
}
row.setUserLocked(userLocked);
row.onNotificationUpdated(entry);
return true;
}
use of android.widget.RemoteViews in project android_frameworks_base by ResurrectionRemix.
the class BaseStatusBar method updateNotificationViews.
private void updateNotificationViews(Entry entry, StatusBarNotification sbn) {
final RemoteViews contentView = entry.cachedContentView;
final RemoteViews bigContentView = entry.cachedBigContentView;
final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView;
final RemoteViews publicContentView = entry.cachedPublicContentView;
// Reapply the RemoteViews
contentView.reapply(mContext, entry.getContentView(), mOnClickHandler);
if (bigContentView != null && entry.getExpandedContentView() != null) {
bigContentView.reapply(sbn.getPackageContext(mContext), entry.getExpandedContentView(), mOnClickHandler);
}
View headsUpChild = entry.getHeadsUpContentView();
if (headsUpContentView != null && headsUpChild != null) {
headsUpContentView.reapply(sbn.getPackageContext(mContext), headsUpChild, mOnClickHandler);
}
if (publicContentView != null && entry.getPublicContentView() != null) {
publicContentView.reapply(sbn.getPackageContext(mContext), entry.getPublicContentView(), mOnClickHandler);
}
// update the contentIntent
mNotificationClicker.register(entry.row, sbn);
entry.row.onNotificationUpdated(entry);
entry.row.resetHeight();
}
use of android.widget.RemoteViews in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsAppWidgetProvider method updateWidget.
/**
* Updates the widget when something changes, or when a button is pushed.
*
* @param context
*/
public static void updateWidget(Context context) {
RemoteViews views = buildUpdate(context);
// Update specific list of appWidgetIds if given, otherwise default to all
final AppWidgetManager gm = AppWidgetManager.getInstance(context);
gm.updateAppWidget(THIS_APPWIDGET, views);
checkObserver(context);
}
use of android.widget.RemoteViews in project android_frameworks_base by ResurrectionRemix.
the class NotificationListenerService method maybePopulateRemoteViews.
/**
* Populates remote views for pre-N targeting apps.
*/
private void maybePopulateRemoteViews(Notification notification) {
if (getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
Builder builder = Builder.recoverBuilder(getContext(), notification);
// Some styles wrap Notification's contentView, bigContentView and headsUpContentView.
// First inflate them all, only then set them to avoid recursive wrapping.
RemoteViews content = builder.createContentView();
RemoteViews big = builder.createBigContentView();
RemoteViews headsUp = builder.createHeadsUpContentView();
notification.contentView = content;
notification.bigContentView = big;
notification.headsUpContentView = headsUp;
}
}
use of android.widget.RemoteViews in project newsrob by marianokamp.
the class UnreadWidgetProvider method buildUpdate.
public static RemoteViews buildUpdate(Context context, int appWidgetId) {
RemoteViews updateViews = null;
Timing t = new Timing("buildUpdate for widget " + appWidgetId, context);
try {
EntryManager entryManager = EntryManager.getInstance(context);
WidgetPreferences wp = entryManager.getWidgetPreferences(appWidgetId);
updateViews = new RemoteViews(context.getPackageName(), R.layout.unread_widget);
if (wp == null) {
PL.log(TAG + "Nothing stored for appWidgetId=" + appWidgetId, context);
updateViews.setTextViewText(R.id.unread_count, "oops!");
updateViews.setViewVisibility(R.id.unread_count, View.VISIBLE);
return updateViews;
}
int count = getCount(entryManager, wp.getDBQuery());
updateViews.setViewVisibility(R.id.unread_count, count > 0 ? View.VISIBLE : View.INVISIBLE);
updateViews.setTextViewText(R.id.unread_count, String.valueOf(count));
updateViews.setViewVisibility(R.id.label, wp.getLabel() != null && wp.getLabel().trim().length() > 0 ? View.VISIBLE : View.INVISIBLE);
updateViews.setTextViewText(R.id.label, wp.getLabel() == null ? "" : wp.getLabel());
Class startingActivityClass = ArticleListActivity.class;
if (wp.getStartingActivityName() != null) {
try {
startingActivityClass = Class.forName(wp.getStartingActivityName());
} catch (ClassNotFoundException e) {
throw e;
}
}
Intent intent = new Intent(context, startingActivityClass);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// intent.addCategory(Intent.CATEGORY_LAUNCHER);
// intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
// Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
// | Intent.FLAG_ACTIVITY_CLEAR_TOP);
UIHelper.addExtrasFromDBQuery(intent, wp.getDBQuery());
//
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// | Intent.FLAG_DEBUG_LOG_RESOLUTION
updateViews.setOnClickPendingIntent(R.id.container, pendingIntent);
} catch (Throwable throwable) {
PL.log("Exception during buildUpdate()", throwable, context);
} finally {
t.stop();
return updateViews;
}
}
Aggregations