@Override public RemoteViews getViewAt(int position) { RemoteViews rView = new RemoteViews(mContext.getPackageName(), R.layout.widget_view_lesson); Lesson lesson = mLessons[position]; rView.setTextViewText(R.id.widget_lesson_name, lesson.fields.get("subject")); rView.setTextViewText(R.id.widget_lesson_time, lesson.fields.get("timePeriod")); rView.setTextViewText(R.id.widget_lesson_teacher, lesson.fields.get("teacher")); if (!lesson.fields.get("auditorium").equals("")) { rView.setTextViewText(R.id.widget_lesson_auditorium, lesson.fields.get("auditorium")); } String lessonType = lesson.fields.get("subjectType"); if (lessonType.equals("лр")) { rView.setInt( R.id.widget_lesson_type_color, "setBackgroundColor", (Color.parseColor("#FF4444"))); } else if (lessonType.equals("пз")) { rView.setInt( R.id.widget_lesson_type_color, "setBackgroundColor", (Color.parseColor("#FFBB33"))); } else if (lessonType.equals("лк")) { rView.setInt( R.id.widget_lesson_type_color, "setBackgroundColor", (Color.parseColor("#99CC00"))); } else { rView.setInt(R.id.widget_lesson_type_color, "setBackgroundColor", (Color.WHITE)); } rView.setInt(R.id.widget_separateline, "setBackgroundColor", Color.WHITE); return rView; }
private static void updateWidget( Context context, AppWidgetManager appWidgetManager, WidgetModel widgetModel, ArrayList<ArrivalModel> arrivals) { // Set the base layout to use int layoutResId = widgetModel.getSize() == WidgetUtils.SIZE_1X1 ? R.layout.widget_layout_1x1 : R.layout.widget_layout_2x1; RemoteViews updatedViews = new RemoteViews(context.getPackageName(), layoutResId); // Set widget background colors updatedViews.setInt( R.id.tv_widget_title, SET_BACKGROUND_COLOR, WidgetUtils.getPrimaryColorInt(context, widgetModel.getBgColor())); updatedViews.setInt( R.id.layout_widget_arrivals, SET_BACKGROUND_COLOR, WidgetUtils.getSecondaryColorInt(context, widgetModel.getBgColor())); // If the user set the widget color to white, we have to change the colors of // some UI elements so that they show properly. if (widgetModel.getBgColor() == WidgetUtils.BG_WHITE) { updatedViews.setTextColor(R.id.tv_widget_title, Color.DKGRAY); updatedViews.setTextColor(R.id.tv_widget_arrival_1, Color.DKGRAY); updatedViews.setTextColor(R.id.tv_widget_arrival_2, Color.DKGRAY); updatedViews.setInt(R.id.iv_widget_divider_1, SET_BACKGROUND_COLOR, Color.DKGRAY); if (getNumArrivalsToShow(widgetModel) == 3) { // There is a third arrival text to update updatedViews.setTextColor(R.id.tv_widget_arrival_3, Color.DKGRAY); updatedViews.setInt(R.id.iv_widget_divider_2, SET_BACKGROUND_COLOR, Color.DKGRAY); } } // Set the widget title updatedViews.setTextViewText(R.id.tv_widget_title, widgetModel.getTitle()); // Update the shown arrival times for (int i = 0; i < Math.min(arrivals.size(), getNumArrivalsToShow(widgetModel)); i++) { updatedViews.setTextViewText( ARRIVAL_TEXTVIEW_RES_ID[i], String.valueOf(arrivals.get(i).getMinsUntilArrival())); } // Set the widget to refresh on click updatedViews.setOnClickPendingIntent( R.id.tv_widget_title, createRefreshIntent(context, widgetModel.getWidgetId())); updatedViews.setOnClickPendingIntent( R.id.layout_widget_arrivals, createRefreshIntent(context, widgetModel.getWidgetId())); // Update the widget view appWidgetManager.updateAppWidget(widgetModel.getWidgetId(), updatedViews); }
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { Intent svcIntent = new Intent(context, WidgetService.class); svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); svcIntent.putExtra( AppWidgetManager.EXTRA_CUSTOM_INFO, PrefUtils.getInt(appWidgetId + ".fontsize", 0)); svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget); widget.setOnClickPendingIntent( R.id.feed_icon, PendingIntent.getActivity(context, 0, new Intent(context, HomeActivity.class), 0)); widget.setPendingIntentTemplate( R.id.feedsListView, PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW), 0)); widget.setRemoteAdapter(R.id.feedsListView, svcIntent); widget.setInt( R.id.feedsListView, "setBackgroundColor", PrefUtils.getInt(appWidgetId + ".background", STANDARD_BACKGROUND)); appWidgetManager.updateAppWidget(appWidgetId, widget); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
public RemoteViews buildUpdate(int position) { try { Task task = getTask(position); String textContent; Resources r = context.getResources(); int textColor = r.getColor(dark ? R.color.widget_text_color_dark : R.color.widget_text_color_light); textContent = task.getTitle(); RemoteViews row = new RemoteViews(Constants.PACKAGE, R.layout.widget_row); if (task.isCompleted()) { textColor = r.getColor(R.color.task_list_done); row.setInt(R.id.text, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); } else { row.setInt(R.id.text, "setPaintFlags", Paint.ANTI_ALIAS_FLAG); if (task.hasDueDate() && task.isOverdue()) { textColor = r.getColor(R.color.task_list_overdue); } } row.setTextViewText(R.id.text, textContent); row.setTextColor(R.id.text, textColor); row.setImageViewResource(R.id.completeBox, getCheckbox(task)); Intent editIntent = new Intent(); editIntent.setAction(TasksWidget.EDIT_TASK); editIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId()); editIntent.putExtra(TaskListActivity.OPEN_TASK, task.getId()); row.setOnClickFillInIntent(R.id.text, editIntent); Intent completeIntent = new Intent(); completeIntent.setAction(TasksWidget.COMPLETE_TASK); completeIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId()); row.setOnClickFillInIntent(R.id.completeBox, completeIntent); return row; } catch (Exception e) { // can happen if database is not ready Log.e("WIDGET-UPDATE", "Error updating widget", e); } return null; }
private void configureSettingsButton(RemoteViews bigView) { if (mSettingsAction == null) { return; } bigView.setOnClickPendingIntent(R.id.origin, mSettingsAction.intent); if (useMaterial()) { bigView.setInt(R.id.origin_settings_icon, "setColorFilter", BUTTON_ICON_COLOR_MATERIAL); } }
/** Update the widget appWidgetId */ private static void updateWidget(Context context, int appWidgetId) { Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); PendingIntent clickIntent; // Launch an intent to avoid ANRs final Intent intent = new Intent(context, WidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent); remoteViews.setTextViewText( R.id.widget_label, context.getString(R.string.title_conversation_list)); remoteViews.setTextColor(R.id.widget_label, ThemeManager.getTextOnColorPrimary()); remoteViews.setInt( R.id.conversation_list_background, "setColorFilter", ThemeManager.getBackgroundColor()); remoteViews.setInt(R.id.header_background, "setColorFilter", ThemeManager.getColor()); // Open Mms's app conversation list when click on header final Intent convIntent = new Intent(context, MainActivity.class); clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent); // On click intent for Compose final Intent composeIntent = new Intent(context, QKComposeActivity.class); clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent); // On click intent for Conversation Intent startActivityIntent = new Intent(context, MainActivity.class); PendingIntent startActivityPendingIntent = PendingIntent.getActivity( context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.conversation_list, startActivityPendingIntent); AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews); }
public void configureBackground(Context context, RemoteViews rv) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(CalendarPreferences.PREF_SHOW_HEADER, true)) { rv.setViewVisibility(R.id.action_bar, View.VISIBLE); } else { rv.setViewVisibility(R.id.action_bar, View.GONE); } int bgTrans = prefs.getInt( CalendarPreferences.PREF_BACKGROUND_TRANSPARENCY, PREF_BACKGROUND_TRANSPARENCY_DEFAULT); rv.setInt( R.id.widget_background, METHOD_SET_BACKGROUND_RESOURCE, transparencyToDrawableRes(bgTrans)); }
/** If there are actions, shows the button related views, and adds a button for each action. */ private void addActionButtons(RemoteViews bigView) { // Remove the existing buttons in case an existing notification is being updated. bigView.removeAllViews(R.id.buttons); // Always set the visibility of the views associated with the action buttons. The current // visibility state is not known as perhaps an existing notification is being updated. int visibility = mActions.isEmpty() ? View.GONE : View.VISIBLE; bigView.setViewVisibility(R.id.button_divider, visibility); bigView.setViewVisibility(R.id.buttons, visibility); Resources resources = mContext.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); for (Action action : mActions) { RemoteViews view = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_button); // If there is an icon then set it and add some padding. if (action.iconBitmap != null || action.iconId != 0) { if (useMaterial()) { view.setInt(R.id.button_icon, "setColorFilter", BUTTON_ICON_COLOR_MATERIAL); } int iconWidth = 0; if (action.iconBitmap != null) { view.setImageViewBitmap(R.id.button_icon, action.iconBitmap); iconWidth = action.iconBitmap.getWidth(); } else if (action.iconId != 0) { view.setImageViewResource(R.id.button_icon, action.iconId); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(resources, action.iconId, options); iconWidth = options.outWidth; } iconWidth = dpToPx(Math.min(pxToDp(iconWidth, metrics), MAX_ACTION_ICON_WIDTH_DP), metrics); // Set the padding of the button so the text does not overlap with the icon. Flip // between left and right manually as RemoteViews does not expose a method that sets // padding in a writing-direction independent way. int buttonPadding = dpToPx(BUTTON_PADDING_START_DP + BUTTON_ICON_PADDING_DP, metrics) + iconWidth; int buttonPaddingLeft = LocalizationUtils.isLayoutRtl() ? 0 : buttonPadding; int buttonPaddingRight = LocalizationUtils.isLayoutRtl() ? buttonPadding : 0; view.setViewPadding(R.id.button, buttonPaddingLeft, 0, buttonPaddingRight, 0); } view.setTextViewText(R.id.button, action.title); view.setOnClickPendingIntent(R.id.button, action.intent); bigView.addView(R.id.buttons, view); } }
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int i = 0; i < appWidgetIds.length; i++) { Intent svcIntent = new Intent(context, TimeTableWidget.class); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int thema = prefs.getInt("thema" + appWidgetIds[i], 0); svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); svcIntent.putExtra("thema", thema); RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_layout); widget.setRemoteAdapter(appWidgetIds[i], R.id.words, svcIntent); Intent clickIntent = new Intent(context, MainActivity.class); PendingIntent clickPI = PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); widget.setPendingIntentTemplate(R.id.words, clickPI); widget.setTextViewText(R.id.weekday, TimeTableControl.today()); if (thema == 1) { widget.setInt(R.id.weekday, "setBackgroundResource", R.drawable.white_top_round_shape); widget.setInt(R.id.table, "setBackgroundResource", R.drawable.white_drop_shadow); } else { widget.setInt(R.id.weekday, "setBackgroundResource", R.drawable.grey_top_round_shape); widget.setInt(R.id.table, "setBackgroundResource", R.drawable.drop_shadow); } appWidgetManager.updateAppWidget(appWidgetIds[i], widget); } appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.words); super.onUpdate(context, appWidgetManager, appWidgetIds); }
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); Log.d("WidgetBroadcast", "OnUpdate called"); // TODO intent.getextra().getint() db.getchain(int) ComponentName thisWidget = new ComponentName(context, WidgetBroadcaster.class); DBHelper db = new DBHelper(context); int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); Intent buttonIntent = new Intent(context, WidgetBroadcaster.class); buttonIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); buttonIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds); PendingIntent pi = PendingIntent.getBroadcast(context, 0, buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT); for (int widgetId : allWidgetIds) { Chain chain = db.getWidgetChain(widgetId); if (chain == null) { Log.d("WidgetBroadcast.onUpdate", "Widget: " + widgetId + " == null"); } else { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); // Set the text remoteViews.setTextViewText(R.id.tv_widget, chain.getName()); remoteViews.setInt(R.id.tv_widget, "setBackgroundColor", chain.getDisplayColor()); remoteViews.setOnClickPendingIntent(R.id.tv_widget, pi); // TODO intent run dialogfragment --> in dialog run update appwidgetManager(widgetId, // remoteViews); appWidgetManager.updateAppWidget(widgetId, remoteViews); } } }
@Override public void setTextViewMaxLines(int viewId, int maxLines) { mRemoteViews.setInt(viewId, "setMaxLines", maxLines); }
public static RemoteViews configureItem( RemoteViews rv, Task task, Context context, int listId, boolean isMinimal, int widgetId) { Intent openIntent = new Intent(context, MainActivity.class); openIntent.setAction(MainActivity.SHOW_TASK); openIntent.putExtra(MainActivity.EXTRA_ID, task.getId()); openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent pOpenIntent = PendingIntent.getActivity(context, 0, openIntent, 0); rv.setOnClickPendingIntent(R.id.tasks_row, pOpenIntent); rv.setOnClickPendingIntent(R.id.tasks_row_name, pOpenIntent); if (isMinimal) { if (task.getDue() != null) { rv.setTextViewText(R.id.tasks_row_due, DateTimeHelper.formatDate(context, task.getDue())); } else { rv.setViewVisibility(R.id.tasks_row_due, View.GONE); } rv.setInt( R.id.tasks_row_priority, "setBackgroundColor", TaskHelper.getPrioColor(task.getPriority(), context)); } rv.setTextColor(R.id.tasks_row_name, WidgetHelper.getFontColor(context, widgetId)); rv.setTextColor(R.id.tasks_row_due, WidgetHelper.getFontColor(context, widgetId)); rv.setTextViewText(R.id.tasks_row_name, task.getName()); if (task.isDone()) { rv.setTextColor(R.id.tasks_row_name, context.getResources().getColor(R.color.Grey)); } else { /* * Is this meaningful? I mean the widget is transparent… * rv.setTextColor( R.id.tasks_row_name, context.getResources() * .getColor( preferences.getBoolean("darkWidget", false) ? * R.color.White : R.color.Black)); */ } if (!isMinimal) { rv.setTextViewText(R.id.tasks_row_priority, task.getPriority() + ""); rv.setTextColor(R.id.tasks_row_priority, context.getResources().getColor(R.color.Black)); GradientDrawable drawable = (GradientDrawable) context.getResources().getDrawable(R.drawable.priority_rectangle); drawable.setColor(TaskHelper.getPrioColor(task.getPriority(), context)); Bitmap bitmap = Bitmap.createBitmap(40, 40, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); rv.setImageViewBitmap(R.id.label_bg, bitmap); if (listId <= 0) { rv.setViewVisibility(R.id.tasks_row_list_name, View.VISIBLE); rv.setTextViewText(R.id.tasks_row_list_name, task.getList().getName()); } else { rv.setViewVisibility(R.id.tasks_row_list_name, View.GONE); } if (task.getContent().length() != 0 || task.getSubtaskCount() > 0 || task.getFiles().size() > 0) { rv.setViewVisibility(R.id.tasks_row_has_content, View.VISIBLE); } else { rv.setViewVisibility(R.id.tasks_row_has_content, View.GONE); } if (task.getDue() != null) { rv.setViewVisibility(R.id.tasks_row_due, View.VISIBLE); rv.setTextViewText(R.id.tasks_row_due, DateTimeHelper.formatDate(context, task.getDue())); if (!isMinimal) { rv.setTextColor( R.id.tasks_row_due, context .getResources() .getColor(TaskHelper.getTaskDueColor(task.getDue(), task.isDone()))); } } else { rv.setViewVisibility(R.id.tasks_row_due, View.GONE); } } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { rv.setTextColor( R.id.tasks_row_name, context .getResources() .getColor(WidgetHelper.isDark(context, widgetId) ? R.color.White : R.color.Black)); } return rv; }
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(WidgetUtils.BRIGHTNESS)) { mSettings = context.getSharedPreferences(PREFS_NAME, 0); mEditor = mSettings.edit(); String BorderOfWidgetIDs = mSettings.getString("Table_Of_Widget_IDs", "-1"); String[] setupItemsArray = context.getResources().getStringArray(R.array.setup_items_array); mConverter = new Converter(); int[] border = mConverter.String_to_tabInt(BorderOfWidgetIDs, setupItemsArray.length); mTheID = border[1]; mViews = new RemoteViews(context.getPackageName(), R.layout.widget_main_layout); // Setting up max brightness level NEED it here int curBrightnessValue = 100; try { curBrightnessValue = android.provider.Settings.System.getInt( context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS); } catch (SettingNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (curBrightnessValue < 130) { mState = 1; Settings.System.putInt( context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 0); Settings.System.putInt( context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255); mViews.setInt(R.id.main_one_one_one, "setAlpha", 1000); mViews.setInt(R.id.main_one_one_one, "setBackgroundResource", R.drawable.w_backbround_on); } else { mState = 0; Settings.System.putInt( context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 0); Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 30); mViews.setInt(R.id.main_one_one_one, "setAlpha", 40); mViews.setInt(R.id.main_one_one_one, "setBackgroundResource", R.drawable.w_backbround_off); } mEditor.putInt("Screen_Brightness_State", mState); mEditor.commit(); ComponentName thisWidget = new ComponentName(context, MyWidgetProviderOneOne.class); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); for (int widgetId : appWidgetIds) { if (mTheID == widgetId) { appWidgetManager.updateAppWidget(widgetId, mViews); break; } } try { Intent myIntent = new Intent(context, RefreshClass.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, myIntent, 0); pendingIntent.send(context, 0, myIntent); } catch (CanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
@Override public Notification build() { // A note about RemoteViews and updating notifications. When a notification is passed to the // {@code NotificationManager} with the same tag and id as a previous notification, an // in-place update will be performed. In that case, the actions of all new // {@link RemoteViews} will be applied to the views of the old notification. This is safe // for actions that overwrite old values such as setting the text of a {@code TextView}, but // care must be taken for additive actions. Especially in the case of // {@link RemoteViews#addView} the result could be to append new views below stale ones. In // that case {@link RemoteViews#removeAllViews} must be called before adding new ones. RemoteViews compactView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification); RemoteViews bigView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_big); float fontScale = mContext.getResources().getConfiguration().fontScale; bigView.setInt(R.id.body, "setMaxLines", calculateMaxBodyLines(fontScale)); int scaledPadding = calculateScaledPadding(fontScale, mContext.getResources().getDisplayMetrics()); String formattedTime = ""; // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577185 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { long time = SystemClock.elapsedRealtime(); formattedTime = DateFormat.getTimeFormat(mContext).format(new Date()); RecordHistogram.recordTimesHistogram( "Android.StrictMode.NotificationUIBuildTime", SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); } finally { StrictMode.setThreadPolicy(oldPolicy); } for (RemoteViews view : new RemoteViews[] {compactView, bigView}) { view.setTextViewText(R.id.time, formattedTime); view.setTextViewText(R.id.title, mTitle); view.setTextViewText(R.id.body, mBody); view.setTextViewText(R.id.origin, mOrigin); view.setImageViewBitmap(R.id.icon, getNormalizedLargeIcon()); view.setViewPadding(R.id.title, 0, scaledPadding, 0, 0); view.setViewPadding(R.id.body_container, 0, scaledPadding, 0, scaledPadding); addWorkProfileBadge(view); int smallIconId = useMaterial() ? R.id.small_icon_overlay : R.id.small_icon_footer; view.setViewVisibility(smallIconId, View.VISIBLE); if (mSmallIconBitmap != null) { view.setImageViewBitmap(smallIconId, mSmallIconBitmap); } else { view.setImageViewResource(smallIconId, mSmallIconId); } } addActionButtons(bigView); configureSettingsButton(bigView); // Note: this is not a NotificationCompat builder so be mindful of the // API level of methods you call on the builder. Notification.Builder builder = new Notification.Builder(mContext); builder.setTicker(mTickerText); builder.setContentIntent(mContentIntent); builder.setDeleteIntent(mDeleteIntent); builder.setDefaults(mDefaults); builder.setVibrate(mVibratePattern); builder.setWhen(mTimestamp); builder.setOnlyAlertOnce(!mRenotify); builder.setContent(compactView); // Some things are duplicated in the builder to ensure the notification shows correctly on // Wear devices and custom lock screens. builder.setContentTitle(mTitle); builder.setContentText(mBody); builder.setSubText(mOrigin); builder.setLargeIcon(getNormalizedLargeIcon()); setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap); for (Action action : mActions) { addActionToBuilder(builder, action); } if (mSettingsAction != null) { addActionToBuilder(builder, mSettingsAction); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Notification.Builder.setPublicVersion was added in Android L. builder.setPublicVersion(createPublicNotification(mContext)); } Notification notification = builder.build(); notification.bigContentView = bigView; return notification; }
@Override public void setLinearLayoutGravity(int viewId, int gravity) { mRemoteViews.setInt(viewId, "setGravity", gravity); }
@Override public void setViewBackgroundColor(int viewId, int color) { mRemoteViews.setInt(viewId, "setBackgroundColor", color); }
static void updateAppWidget( final android.content.Context androidContext, AppWidgetManager appWidgetManager, int appWidgetId, String queryName) { Log.d(cTag, "updateAppWidget appWidgetId=" + appWidgetId + " queryName=" + queryName); // TODO inject ContentResolverProvider provider = new ContentResolverProvider() { @Override public ContentResolver get() { return androidContext.getContentResolver(); } }; TaskPersister taskPersister = new TaskPersister(provider); ProjectPersister projectPersister = new ProjectPersister(provider); EntityCache<Project> projectCache = new DefaultEntityCache<Project>(projectPersister); ContextPersister contextPersister = new ContextPersister(provider); EntityCache<Context> contextCache = new DefaultEntityCache<Context>(contextPersister); RemoteViews views = new RemoteViews(androidContext.getPackageName(), R.layout.widget); TaskQuery query = StandardTaskQueries.getQuery(queryName); if (query == null) return; int titleId = getIdentifier(androidContext, "title_" + queryName, cStringType); views.setTextViewText(R.id.title, androidContext.getString(titleId)); Intent intent = new Intent(Intent.ACTION_INSERT, TaskProvider.Tasks.CONTENT_URI); PendingIntent pendingIntent = PendingIntent.getActivity(androidContext, 0, intent, 0); views.setOnClickPendingIntent(R.id.add_task, pendingIntent); Cursor taskCursor = androidContext .getContentResolver() .query( TaskProvider.Tasks.CONTENT_URI, TaskProvider.Tasks.cFullProjection, query.getSelection(), query.getSelectionArgs(), query.getSortOrder()); for (int taskCount = 1; taskCount <= 4; taskCount++) { Task task = null; Project project = null; Context context = null; if (taskCursor.moveToNext()) { task = taskPersister.read(taskCursor); project = projectCache.findById(task.getProjectId()); context = contextCache.findById(task.getContextId()); } int descriptionViewId = getIdIdentifier(androidContext, "description_" + taskCount); views.setTextViewText(descriptionViewId, task != null ? task.getDescription() : ""); views.setInt(descriptionViewId, "setLines", project == null ? 2 : 1); int projectViewId = getIdIdentifier(androidContext, "project_" + taskCount); views.setViewVisibility(projectViewId, project == null ? View.GONE : View.VISIBLE); views.setTextViewText(projectViewId, project != null ? project.getName() : ""); int contextIconId = getIdIdentifier(androidContext, "context_icon_" + taskCount); String iconName = context != null ? context.getIconName() : null; ContextIcon icon = ContextIcon.createIcon(iconName, androidContext.getResources()); if (icon != ContextIcon.NONE) { views.setImageViewResource(contextIconId, icon.smallIconId); views.setViewVisibility(contextIconId, View.VISIBLE); } else { views.setViewVisibility(contextIconId, View.INVISIBLE); } if (task != null) { Uri.Builder builder = TaskProvider.Tasks.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, task.getLocalId().getId()); Uri taskUri = builder.build(); intent = new Intent(Intent.ACTION_EDIT, taskUri); Log.d(cTag, "Adding pending event for viewing uri " + taskUri); pendingIntent = PendingIntent.getActivity(androidContext, 0, intent, 0); views.setOnClickPendingIntent(descriptionViewId, pendingIntent); views.setOnClickPendingIntent(projectViewId, pendingIntent); views.setOnClickPendingIntent(contextIconId, pendingIntent); } } taskCursor.close(); appWidgetManager.updateAppWidget(appWidgetId, views); }
@SuppressLint("NewApi") @Override protected Boolean doInBackground(String... params) { // Perform this loop procedure for each App Widget that belongs to this mApp for (int i = 0; i < mNumWidgets; i++) { currentAppWidgetId = mAppWidgetIds[i]; String widgetColor = mApp.getSharedPreferences().getString("" + currentAppWidgetId, "DARK"); views = new RemoteViews(mContext.getPackageName(), R.layout.small_widget_layout); if (widgetColor.equals("DARK")) { views.setInt( R.id.small_widget_parent_layout, "setBackgroundResource", R.drawable.appwidget_dark_bg); views.setImageViewResource( R.id.app_widget_small_previous, R.drawable.btn_playback_previous_light); views.setImageViewResource(R.id.app_widget_small_next, R.drawable.btn_playback_next_light); } else if (widgetColor.equals("LIGHT")) { views.setInt( R.id.small_widget_parent_layout, "setBackgroundResource", R.drawable.appwidget_bg); views.setImageViewResource( R.id.app_widget_small_previous, R.drawable.btn_playback_previous); views.setImageViewResource(R.id.app_widget_small_next, R.drawable.btn_playback_next); } Intent playPauseIntent = new Intent(); playPauseIntent.setAction(PLAY_PAUSE_ACTION); PendingIntent playPausePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, playPauseIntent, 0); Intent nextIntent = new Intent(); nextIntent.setAction(NEXT_ACTION); PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, nextIntent, 0); Intent previousIntent = new Intent(); previousIntent.setAction(PREVIOUS_ACTION); PendingIntent previousPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, previousIntent, 0); // Get the layout of the widget and attach a click listener to each element. views.setOnClickPendingIntent(R.id.app_widget_small_play, playPausePendingIntent); views.setOnClickPendingIntent(R.id.app_widget_small_previous, previousPendingIntent); views.setOnClickPendingIntent(R.id.app_widget_small_next, nextPendingIntent); // Get the downsampled image of the current song's album art. views.setImageViewBitmap(R.id.app_widget_small_image, getAlbumArt()); if (mApp.isServiceRunning()) { final Intent notificationIntent = new Intent(mContext, NowPlayingActivity.class); notificationIntent.putExtra("CALLED_FROM_FOOTER", true); notificationIntent.putExtra("CALLED_FROM_NOTIF", true); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0); views.setOnClickPendingIntent(R.id.app_widget_small_image, pendingIntent); } else { views.setImageViewResource(R.id.app_widget_small_image, R.drawable.default_album_art); if (widgetColor.equals("DARK")) { views.setImageViewResource( R.id.app_widget_small_play, R.drawable.btn_playback_play_light); } else if (widgetColor.equals("LIGHT")) { views.setImageViewResource(R.id.app_widget_small_play, R.drawable.btn_playback_play); } final Intent intent = new Intent(mContext, LauncherActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0); views.setOnClickPendingIntent(R.id.app_widget_small_image, pendingIntent); } views.setTextViewText( R.id.app_widget_small_line_one, mApp.getService().getCurrentSong().getTitle()); views.setTextViewText( R.id.app_widget_small_line_two, mApp.getService().getCurrentSong().getAlbum() + mApp.getService().getCurrentSong().getArtist()); if (widgetColor.equals("LIGHT")) { views.setTextColor(R.id.app_widget_small_line_one, Color.BLACK); views.setTextColor(R.id.app_widget_small_line_two, Color.BLACK); } if (mApp.isServiceRunning()) { try { if (mApp.getService().getCurrentMediaPlayer().isPlaying()) { if (widgetColor.equals("DARK")) { views.setImageViewResource( R.id.app_widget_small_play, R.drawable.btn_playback_pause_light); } else if (widgetColor.equals("LIGHT")) { views.setImageViewResource(R.id.app_widget_small_play, R.drawable.btn_playback_pause); } } else { if (widgetColor.equals("DARK")) { views.setImageViewResource( R.id.app_widget_small_play, R.drawable.btn_playback_play_light); } else if (widgetColor.equals("LIGHT")) { views.setImageViewResource(R.id.app_widget_small_play, R.drawable.btn_playback_play); } } } catch (Exception e) { // TODO Auto-generated method stub e.printStackTrace(); } } // Tell the AppWidgetManager to perform an update on the current app widget\ try { mAppWidgetManager.updateAppWidget(currentAppWidgetId, views); } catch (Exception e) { continue; } } return true; }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public void widget4_4Setting(RemoteViews views, AppWidgetManager manager, Bitmap bitmap) { Intent main4 = new Intent(Common.ACTION_HOME4_4); PendingIntent mainP4 = PendingIntent.getBroadcast(this, 0, main4, 0); views.setOnClickPendingIntent(R.id.btHome, mainP4); Intent home = new Intent(Common.ACTION_HOME4_4); PendingIntent dialP = PendingIntent.getBroadcast(this, 0, home, 0); views.setOnClickPendingIntent(R.id.ivWeek, dialP); Intent month4 = new Intent(Common.ACTION_MONTH4_4); PendingIntent monthP4 = PendingIntent.getBroadcast(this, 0, month4, 0); views.setOnClickPendingIntent(R.id.btMonth, monthP4); Intent week4 = new Intent(Common.ACTION_WEEK4_4); PendingIntent weekP4 = PendingIntent.getBroadcast(this, 0, week4, 0); views.setOnClickPendingIntent(R.id.btWeek, weekP4); Intent back4 = new Intent(Common.ACTION_BACK4_4); PendingIntent backP4 = PendingIntent.getBroadcast(this, 0, back4, 0); views.setOnClickPendingIntent(R.id.btBack, backP4); Intent forward4 = new Intent(Common.ACTION_FORWARD4_4); PendingIntent forwardP4 = PendingIntent.getBroadcast(this, 0, forward4, 0); views.setOnClickPendingIntent(R.id.btForward, forwardP4); if (viewMode != 0) { for (int i = 0; i < 42; i++) { int llID = getResources().getIdentifier("ll" + i, "id", "com.daemin.timetable"); int tvID = getResources().getIdentifier("tv" + i, "id", "com.daemin.timetable"); if (i >= Dates.NOW.dayOfWeek + 1 && i < Dates.NOW.dayOfWeek + Dates.NOW.dayNumOfMonth + 1) { Intent in = new Intent(this, DialSchedule.class); in.putExtra("widgetFlag", true); in.putExtra("widget4_4", true); in.putExtra("dayCnt", i); in.putExtra("day", Dates.NOW.mData[i]); PendingIntent dP = PendingIntent.getActivity(this, i + 200, in, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(llID, dP); if (Dates.NOW.isToday) { if (i == Dates.NOW.dayOfMonth + Dates.NOW.dayOfWeek) { views.setInt(llID, "setBackgroundResource", R.color.transmaincolor); } } else { views.setInt(llID, "setBackgroundResource", R.drawable.bt_click); } int j = i % 7; switch (j) { case 0: views.setTextColor(tvID, getResources().getColor(R.color.red)); break; case 6: views.setTextColor(tvID, getResources().getColor(R.color.blue)); break; default: views.setTextColor(tvID, getResources().getColor(android.R.color.black)); break; } views.setTextViewText(tvID, Dates.NOW.mData[i]); } else { // 달력에서 월에 해당하는 날짜 이외의 날짜들은 회색으로 표시 Intent in = new Intent(Common.ACTION_DUMMY4_4); PendingIntent dP = PendingIntent.getBroadcast(this, 0, in, 0); views.setOnClickPendingIntent(llID, dP); views.setTextViewText(tvID, Dates.NOW.mData[i]); views.setTextColor(tvID, getResources().getColor(R.color.middlegray)); views.setInt(llID, "setBackgroundResource", android.R.color.white); } } fetchMonthData(views); } for (int appWidgetId : manager.getAppWidgetIds(new ComponentName(this, Widget4_4.class))) { manager.updateAppWidget(appWidgetId, views); } if (bitmap != null) bitmap.recycle(); }