Java Code Examples for android.widget.RemoteViews#setOnClickPendingIntent()
The following examples show how to use
android.widget.RemoteViews#setOnClickPendingIntent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleWidgetProvider.java From SimpleAndroidWidget with MIT License | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int count = appWidgetIds.length; for (int i = 0; i < count; i++) { int widgetId = appWidgetIds[i]; String number = String.format("%03d", (new Random().nextInt(900) + 100)); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.simple_widget); remoteViews.setTextViewText(R.id.textView, number); Intent intent = new Intent(context, SimpleWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.actionButton, pendingIntent); appWidgetManager.updateAppWidget(widgetId, remoteViews); } }
Example 2
Source File: ShortcutWidgetProvider.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
static RemoteViews buildUpdate(Context context, int appWidgetId) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_shortcut); int action = ShortcutWidgetConfigure.getActionForWidget(context, appWidgetId); if(action >= 0 && action < ShortcutWidgetConfigure.SHORTCUTS.length) { Shortcut sh = ShortcutWidgetConfigure.SHORTCUTS[action]; PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, sh.intent, 0); views.setOnClickPendingIntent(R.id.btn_shortcut, pendingIntent); views.setImageViewResource(R.id.img_account, sh.iconRes); views.setTextViewText(R.id.txt_account, context.getText(sh.nameRes)); }else { Log.w(THIS_FILE, "Invalid action id " + action); } return views; }
Example 3
Source File: EarthAppWidgetProvider.java From earth with GNU General Public License v3.0 | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final Intent intent = new Intent(context, MainActivity.class); final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.app_widget); views.setOnClickPendingIntent(R.id.earth, pendingIntent); final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); final int size = Math.min(metrics.widthPixels, metrics.heightPixels); Glide.with(context) .load(getLatestEarth()) .asBitmap() .error(R.drawable.preview) .transform(new MaskTransformation(context, R.drawable.mask)) .diskCacheStrategy(DiskCacheStrategy.NONE) .into(new AppWidgetTarget(context, views, R.id.earth, size, size, appWidgetIds)); }
Example 4
Source File: MyWidgetProvider.java From TextThing with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int count = appWidgetIds.length; for (int i = 0; i < count; i++) { int widgetId = appWidgetIds[i]; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.retro_widget); Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity( context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT ); remoteViews.setOnClickPendingIntent(R.id.wContent, pendingIntent); appWidgetManager.updateAppWidget(widgetId, remoteViews); } JobIntentService.enqueueWork(context, WidgetUpdateService.class, 1, new Intent()); }
Example 5
Source File: ToggleWidgetProvider.java From HeadsUp with GNU General Public License v2.0 | 6 votes |
private void updateWidgets(Context context) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName cn = new ComponentName(context, ToggleWidgetProvider.class); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(cn); for (int appWidgetId : appWidgetIds) { // Create an Intent to launch ReceiverActivity to toggle AcDisplay. // Probably doing same using BroadcastReceiver would be better solution. Intent intent = new Intent(App.ACTION_TOGGLE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); Resources res = context.getResources(); // Get the layout for the App Widget and attach an on-click listener // to the button RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.appwidget_toggle_layout); rv.setOnClickPendingIntent(R.id.container, pendingIntent); rv.setTextViewText(R.id.title, res.getString( mConfig.isEnabled() ? R.string.enabled : R.string.disabled)); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, rv); } }
Example 6
Source File: WidgetExpense.java From fingen with Apache License 2.0 | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // There may be multiple widgets active, so update all of them RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_expense); Intent configIntent = new Intent(context, ActivityEditTransaction.class); Transaction transaction = new Transaction(PrefUtils.getDefDepID(context)); transaction.setTransactionType(Transaction.TRANSACTION_TYPE_EXPENSE); configIntent.putExtra("transaction", transaction); configIntent.putExtra("update_date", true); configIntent.putExtra("EXIT", true); configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Uri data = Uri.withAppendedPath(Uri.parse("ABCD" + "://widget/id/"),String.valueOf(appWidgetIds[0])); configIntent.setData(data); PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.widgetContainer, configPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); }
Example 7
Source File: PlayingNotificationImpl.java From VinylMusicPlayer with GNU General Public License v3.0 | 6 votes |
private void linkButtons(final RemoteViews notificationLayout, final RemoteViews notificationLayoutBig) { PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(service, MusicService.class); // Previous track pendingIntent = buildPendingIntent(service, MusicService.ACTION_REWIND, serviceName); notificationLayout.setOnClickPendingIntent(R.id.action_prev, pendingIntent); notificationLayoutBig.setOnClickPendingIntent(R.id.action_prev, pendingIntent); // Play and pause pendingIntent = buildPendingIntent(service, MusicService.ACTION_TOGGLE_PAUSE, serviceName); notificationLayout.setOnClickPendingIntent(R.id.action_play_pause, pendingIntent); notificationLayoutBig.setOnClickPendingIntent(R.id.action_play_pause, pendingIntent); // Next track pendingIntent = buildPendingIntent(service, MusicService.ACTION_SKIP, serviceName); notificationLayout.setOnClickPendingIntent(R.id.action_next, pendingIntent); notificationLayoutBig.setOnClickPendingIntent(R.id.action_next, pendingIntent); // Favorite pendingIntent = buildPendingIntent(service, MusicService.TOGGLE_FAVORITE, serviceName); notificationLayout.setOnClickPendingIntent(R.id.action_fav, pendingIntent); notificationLayoutBig.setOnClickPendingIntent(R.id.action_fav, pendingIntent); }
Example 8
Source File: MissWidget.java From UPMiss with GNU General Public License v3.0 | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // Widget button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.layout_miss_widget); Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.btn_start_activity, pending); appWidgetManager.updateAppWidget(appWidgetIds, views); if (mBundle != null) { performUpdate(context, appWidgetManager, appWidgetIds, mBundle); } }
Example 9
Source File: ExpensesWidgetProvider.java From Expense-Tracker-App with MIT License | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds){ Intent expenseDetailActivity = new Intent(context, ExpenseDetailActivity.class); Intent mainActivityIntent = new Intent(context, MainActivity.class); // Creating stack for builder item click TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); taskStackBuilder.addParentStack(MainActivity.class); taskStackBuilder.addNextIntent(mainActivityIntent); taskStackBuilder.addNextIntent(expenseDetailActivity); PendingIntent itemClickPendingIntent = taskStackBuilder.getPendingIntent(0 ,PendingIntent.FLAG_UPDATE_CURRENT); // Create pending intent for clicking the whole view, not an item PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent widgetServiceIntent = new Intent(context, ExpensesWidgetService.class); // widgetServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // widgetServiceIntent.setData(Uri.parse(widgetServiceIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_layout); remoteView.setOnClickPendingIntent(R.id.general_layout, mainPendingIntent); remoteView.setEmptyView(R.id.listViewWidget, R.id.empty_view); remoteView.setRemoteAdapter(appWidgetId, R.id.listViewWidget, widgetServiceIntent); remoteView.setTextViewText(R.id.tv_total, context.getString(R.string.today_expenses_total, Util.getFormattedCurrency(Expense.getTotalExpensesByDateMode(IDateMode.MODE_TODAY)))); remoteView.setPendingIntentTemplate(R.id.listViewWidget, itemClickPendingIntent); ComponentName component=new ComponentName(context, ExpensesWidgetProvider.class); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listViewWidget); appWidgetManager.updateAppWidget(component, remoteView); } }
Example 10
Source File: SkeletonAppWidget.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { // Listing 19-5 // Listing 19-6 RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget_layout); // TODO Update the UI. // Listing 19-7 // Create an Intent to launch an Activity Intent intent = new Intent(context, MainActivity.class); // Wrap it in a Pending Intent so another application // can fire it on your behalf. PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); // Assign the Pending Intent to be triggered when // the assigned View is clicked. views.setOnClickPendingIntent(R.id.widget_text, pendingIntent); // Notify the App Widget Manager to update the widget using // the modified remote view. appWidgetManager.updateAppWidget(appWidgetId, views); }
Example 11
Source File: CustomWidgetProvider3.java From Simple-Search with GNU General Public License v3.0 | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout3); Intent configIntent = new Intent(context, MainActivity.class); PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.search_widget, configPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); }
Example 12
Source File: TextWidgetIMP.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
private static void setOnClickPendingIntent(Context context, RemoteViews views, Location location, boolean touchToRefresh) { // headerContainer. if (touchToRefresh) { views.setOnClickPendingIntent( R.id.widget_text_container, getRefreshPendingIntent( context, GeometricWeather.WIDGET_TEXT_PENDING_INTENT_CODE_REFRESH ) ); } else { views.setOnClickPendingIntent( R.id.widget_text_container, getWeatherPendingIntent( context, location, GeometricWeather.WIDGET_TEXT_PENDING_INTENT_CODE_WEATHER ) ); } // date. views.setOnClickPendingIntent( R.id.widget_text_date, getCalendarPendingIntent( context, GeometricWeather.WIDGET_TEXT_PENDING_INTENT_CODE_CALENDAR ) ); }
Example 13
Source File: ServiceToggle.java From fitnotifications with Apache License 2.0 | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // Perform this loop procedure for each App Widget that belongs to this provider for (int appWidgetId : appWidgetIds) { // Get the layout for the App Widget and attach an on-click listener // to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget); if (NLService.isEnabled()) { views.setImageViewResource(R.id.widgetToggleButton,R.drawable.ic_speaker_notes_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green)); } else { views.setImageViewResource(R.id.widgetToggleButton,R.drawable.ic_speaker_notes_off_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red)); } views.setOnClickPendingIntent( R.id.widgetToggleButton, getPendingSelfIntent(context, appWidgetId, TOGGLE_CLICKED)); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
Example 14
Source File: MainActivity.java From YCNotification with Apache License 2.0 | 5 votes |
private RemoteViews getRemoteViews() { RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_mobile_play); // 设置 点击通知栏的上一首按钮时要执行的意图 remoteViews.setOnClickPendingIntent(R.id.btn_pre, getActivityPendingIntent(11)); // 设置 点击通知栏的下一首按钮时要执行的意图 remoteViews.setOnClickPendingIntent(R.id.btn_next, getActivityPendingIntent(12)); // 设置 点击通知栏的播放暂停按钮时要执行的意图 remoteViews.setOnClickPendingIntent(R.id.btn_start, getActivityPendingIntent(13)); // 设置 点击通知栏的根容器时要执行的意图 remoteViews.setOnClickPendingIntent(R.id.ll_root, getActivityPendingIntent(14)); remoteViews.setTextViewText(R.id.tv_title, "标题"); // 设置通知栏上标题 remoteViews.setTextViewText(R.id.tv_artist, "艺术家"); // 设置通知栏上艺术家 return remoteViews; }
Example 15
Source File: EarthquakeRemoteViewsService.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
public RemoteViews getViewAt(int index) { if (mEarthquakes != null) { // Extract the requested Earthquake. Earthquake earthquake = mEarthquakes.get(index); // Extract the values to be displayed. String id = earthquake.getId(); String magnitude = String.valueOf(earthquake.getMagnitude()); String details = earthquake.getDetails(); // Create a new Remote Views object and use it to populate the // layout used to represent each earthquake in the list. RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.quake_widget); rv.setTextViewText(R.id.widget_magnitude, magnitude); rv.setTextViewText(R.id.widget_details, details); // Create a Pending Intent that will open the main Activity. Intent intent = new Intent(mContext, EarthquakeMainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0); rv.setOnClickPendingIntent(R.id.widget_magnitude, pendingIntent); rv.setOnClickPendingIntent(R.id.widget_details, pendingIntent); return rv; } else { return null; } }
Example 16
Source File: GameWallpaperService.java From homescreenarcade with GNU General Public License v3.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent.getBooleanExtra(ArcadeCommon.STATUS_RESET_SCORE, false)) { score = 0; } else { score += intent.getIntExtra(ArcadeCommon.STATUS_INCREMENT_SCORE, 0); } RemoteViews notifViews = new RemoteViews(context.getPackageName(), R.layout.status_notification); notifViews.setTextViewText(R.id.title, getString(titleResID)); notifViews.setImageViewResource(R.id.notif_icon, notifIconResID); NotificationManager notifMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); notifViews.setTextViewText(R.id.score, getString(R.string.score, score)); int newLevel = intent.getIntExtra(ArcadeCommon.STATUS_LEVEL, level); if (newLevel != level) { setLevel(newLevel); } if (level >= 0) { notifViews.setTextViewText(R.id.level, getString(R.string.level, level)); } setLives(intent.getIntExtra(ArcadeCommon.STATUS_LIVES, lives)); if (previewActive) { return; } notifViews.removeAllViews(R.id.lives_area); if (lives < 0) { // Game over, man RemoteViews gameOver = new RemoteViews(getPackageName(), R.layout.status_text); gameOver.setTextViewText(R.id.status_text, "Game Over"); notifViews.addView(R.id.lives_area, gameOver); if (!isPaused) { onPause(); } } else { Bitmap lifeBitmap = BitmapFactory.decodeResource(getResources(), lifeIconResId); for (int i = 0; i < lives; i++) { RemoteViews thisLife = new RemoteViews(getPackageName(), R.layout.status_life_icon); thisLife.setBitmap(R.id.life_icon, "setImageBitmap", lifeBitmap); notifViews.addView(R.id.lives_area, thisLife); } } Bitmap pauseBtn = BitmapFactory.decodeResource(getResources(), isPaused || (readyTime > 0) ? R.drawable.ic_play_circle_outline_white_48dp : R.drawable.ic_pause_circle_outline_white_48dp); notifViews.setBitmap(R.id.play_pause, "setImageBitmap", pauseBtn); notifViews.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_PAUSE), 0)); final NotificationCompat.Builder notif = new NotificationCompat.Builder(context) .setSmallIcon(notifIconResID) .setContent(notifViews) .setPriority(NotificationCompat.PRIORITY_HIGH) .setVisibility(VISIBILITY_SECRET); // keep the scroreboard off the lock screen if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // This forces a heads-up notification notif.setVibrate(new long[0]); } notifMgr.notify(0, notif.build()); }
Example 17
Source File: DayWidgetIMP.java From GeometricWeather with GNU Lesser General Public License v3.0 | 4 votes |
private static void setOnClickPendingIntent(Context context, RemoteViews views, Location location, String viewStyle, String subtitleData, boolean touchToRefresh) { // weather. if (touchToRefresh) { views.setOnClickPendingIntent( R.id.widget_day_weather, getRefreshPendingIntent( context, GeometricWeather.WIDGET_DAY_PENDING_INTENT_CODE_REFRESH ) ); } else { views.setOnClickPendingIntent( R.id.widget_day_weather, getWeatherPendingIntent( context, location, GeometricWeather.WIDGET_DAY_PENDING_INTENT_CODE_WEATHER ) ); } // title. if (viewStyle.equals("oreo") || viewStyle.equals("oreo_google_sans")) { views.setOnClickPendingIntent( R.id.widget_day_title, getCalendarPendingIntent( context, GeometricWeather.WIDGET_DAY_PENDING_INTENT_CODE_CALENDAR ) ); } // time. if (viewStyle.equals("pixel") || subtitleData.equals("lunar")) { views.setOnClickPendingIntent( R.id.widget_day_time, getCalendarPendingIntent( context, GeometricWeather.WIDGET_DAY_PENDING_INTENT_CODE_CALENDAR ) ); } else if (!touchToRefresh && subtitleData.equals("time")) { views.setOnClickPendingIntent( R.id.widget_day_time, getRefreshPendingIntent( context, GeometricWeather.WIDGET_DAY_PENDING_INTENT_CODE_REFRESH ) ); } }
Example 18
Source File: SoundService.java From volume_control_android with MIT License | 4 votes |
private static RemoteViews buildVolumeSlider(Context context, VolumeControl control, int typeId, String typeName) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notification_volume_slider); views.removeAllViews(R.id.volume_slider); int maxLevel = control.getMaxLevel(typeId); int minLevel = control.getMinLevel(typeId); int currentLevel = control.getLevel(typeId); int maxSliderLevel = Math.min(maxLevel, 8); float delta = maxLevel / (float) maxSliderLevel; for (int i = control.getMinLevel(typeId); i <= maxSliderLevel; i++) { int volumeLevel = (maxLevel * i) / maxSliderLevel; boolean isActive = volumeLevel <= currentLevel; RemoteViews sliderItemView = new RemoteViews( context.getPackageName(), isActive ? R.layout.notification_slider_active : R.layout.notification_slider_inactive ); if (i == maxSliderLevel) { sliderItemView.setViewVisibility(R.id.deliver_item, View.GONE); } int requestId = VOLUME_ID_PREFIX + (volumeLevel + 1) * 100 + typeId; sliderItemView.setOnClickPendingIntent( R.id.notification_slider_item, PendingIntent.getService( context, requestId, setVolumeIntent(context, typeId, volumeLevel), PendingIntent.FLAG_UPDATE_CURRENT) ); views.addView(R.id.volume_slider, sliderItemView); } views.setTextViewText(R.id.volume_title, capitalize(typeName) + " " + (currentLevel - minLevel) + "/" + (maxLevel - minLevel)); views.setOnClickPendingIntent( R.id.volume_up, PendingIntent.getService( context, VOLUME_ID_PREFIX + 10 + typeId, setVolumeByDeltaIntent(context, typeId, delta), PendingIntent.FLAG_UPDATE_CURRENT) ); views.setOnClickPendingIntent( R.id.volume_down, PendingIntent.getService( context, VOLUME_ID_PREFIX + 20 + typeId, setVolumeByDeltaIntent(context, typeId, -delta), PendingIntent.FLAG_UPDATE_CURRENT) ); return views; }
Example 19
Source File: WidgetV24.java From prayer-times-android with Apache License 2.0 | 4 votes |
static void update1x1(Context context, AppWidgetManager appWidgetManager, int widgetId) { Theme theme = WidgetUtils.getTheme(widgetId); Times times = WidgetUtils.getTimes(widgetId); if (times == null) { WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId); return; } WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1); int s = size.width; if (s <= 0) return; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_1x1); remoteViews.setInt(R.id.widget_layout, "setBackgroundResource", theme.background); remoteViews.setViewPadding(R.id.padder, s / 2, s / 2, s / 2, s / 2); int next = times.getNextTime(); String name = times.getName(); remoteViews.setOnClickPendingIntent(R.id.widget_layout, TimesFragment.getPendingIntent(times)); if (Preferences.COUNTDOWN_TYPE.get().equals(Preferences.COUNTDOWN_TYPE_SHOW_SECONDS)) remoteViews .setChronometer(R.id.countdown, times.getTime(LocalDate.now(), next).toDateTime().getMillis() - (System.currentTimeMillis() - SystemClock.elapsedRealtime()), null, true); else { String txt = LocaleUtils.formatPeriod(LocalDateTime.now(), times.getTime(LocalDate.now(), next), false); remoteViews.setString(R.id.countdown, "setFormat", txt); remoteViews.setChronometer(R.id.countdown, 0, txt, false); } remoteViews.setTextViewTextSize(R.id.countdown, TypedValue.COMPLEX_UNIT_PX, s / 4f); remoteViews.setTextViewText(R.id.city, name); remoteViews.setTextViewText(R.id.time, Vakit.getByIndex(next - 1).getString()); remoteViews.setTextColor(R.id.city, theme.textcolor); remoteViews.setTextColor(R.id.countdown, theme.textcolor); remoteViews.setTextColor(R.id.time, theme.textcolor); remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, (float) Math.min(s / 5f, 1.5 * s / name.length())); remoteViews.setTextViewTextSize(R.id.time, TypedValue.COMPLEX_UNIT_PX, s / 5f); remoteViews.setViewPadding(R.id.countdown, 0, -s / 16, 0, -s / 16); appWidgetManager.updateAppWidget(widgetId, remoteViews); }
Example 20
Source File: DesktopPanel.java From Rainville with MIT License | 4 votes |
public void bindLaunchMainActivity(Context context, RemoteViews remoteViews) { Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.launch_activity, pendingIntent); }