List of usage examples for android.widget RemoteViews setTextColor
public void setTextColor(int viewId, @ColorInt ColorStateList colors)
From source file:org.physical_web.physicalweb.UriBeaconDiscoveryService.java
private void updateSummaryNotificationRemoteViewsFirstBeacon(String url, RemoteViews remoteViews) { MetadataResolver.UrlMetadata urlMetadata_firstBeacon = mUrlToUrlMetadata.get(url); if (urlMetadata_firstBeacon != null) { String title = mUrlToUrlMetadata.get(url).title; String description = mUrlToUrlMetadata.get(url).description; Bitmap icon = mUrlToUrlMetadata.get(url).icon; remoteViews.setImageViewBitmap(R.id.icon_firstBeacon, icon); remoteViews.setTextViewText(R.id.title_firstBeacon, title); remoteViews.setTextViewText(R.id.url_firstBeacon, url); remoteViews.setTextViewText(R.id.description_firstBeacon, description); // Recolor notifications to have light text for non-Lollipop devices if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) { remoteViews.setTextColor(R.id.title_firstBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR); remoteViews.setTextColor(R.id.url_firstBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR); remoteViews.setTextColor(R.id.description_firstBeacon, NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR); }//from w w w. j a v a 2 s . co m // Create an intent that will open the browser to the beacon's url // if the user taps the notification PendingIntent pendingIntent = createNavigateToUrlPendingIntent(url); remoteViews.setOnClickPendingIntent(R.id.first_beacon_main_layout, pendingIntent); remoteViews.setViewVisibility(R.id.firstBeaconLayout, View.VISIBLE); } else { remoteViews.setViewVisibility(R.id.firstBeaconLayout, View.GONE); } }
From source file:org.physical_web.physicalweb.UriBeaconDiscoveryService.java
private void updateSummaryNotificationRemoteViewsSecondBeacon(String url, RemoteViews remoteViews) { MetadataResolver.UrlMetadata urlMetadata_secondBeacon = mUrlToUrlMetadata.get(url); if (urlMetadata_secondBeacon != null) { String title = mUrlToUrlMetadata.get(url).title; String description = mUrlToUrlMetadata.get(url).description; Bitmap icon = mUrlToUrlMetadata.get(url).icon; remoteViews.setImageViewBitmap(R.id.icon_secondBeacon, icon); remoteViews.setTextViewText(R.id.title_secondBeacon, title); remoteViews.setTextViewText(R.id.url_secondBeacon, url); remoteViews.setTextViewText(R.id.description_secondBeacon, description); // Recolor notifications to have light text for non-Lollipop devices if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) { remoteViews.setTextColor(R.id.title_secondBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR); remoteViews.setTextColor(R.id.url_secondBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR); remoteViews.setTextColor(R.id.description_secondBeacon, NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR); }//w ww . j a va2 s . c o m // Create an intent that will open the browser to the beacon's url // if the user taps the notification PendingIntent pendingIntent = createNavigateToUrlPendingIntent(url); remoteViews.setOnClickPendingIntent(R.id.second_beacon_main_layout, pendingIntent); remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.VISIBLE); } else { remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.GONE); } }
From source file:github.daneren2005.dsub.util.Util.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {//from ww w.j av a2 s. co m int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { rv.setTextColor(R.id.notification_title, colors.getFirst()); } if (colors.getSecond() != null) { rv.setTextColor(R.id.notification_artist, colors.getSecond()); } if (!playing) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play); rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop); } // Create actions for media buttons PendingIntent pendingIntent; if (playing) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(R.id.control_pause, pendingIntent); Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(R.id.control_next, pendingIntent); }
From source file:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java
@Override protected void updateView(Context context, RemoteViews remoteViews, Bundle widgetOptions) { if (isMobileDataEnabled && isMobileOutOfService) { setStateColor(context, remoteViews, STATE_ON); remoteViews.setTextViewText(R.id.mobileNameTextView, context.getString(R.string.mobile_data)); remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_enabled); remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE); remoteViews.setTextViewText(R.id.mobileInfoTopTextView, context.getString(R.string.no_service)); remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.GONE); return;/* w w w. j a va2 s .co m*/ } if (dataState == TelephonyManager.DATA_DISCONNECTED) { remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE); remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.VISIBLE); if (isMobileDataEnabled && !isAirplaneModeOn) { setStateColor(context, remoteViews, STATE_ON); remoteViews.setTextViewText(R.id.mobileNameTextView, networkOperatorAndServiceProvider); remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_enabled); remoteViews.setTextViewText(R.id.mobileInfoTopTextView, context.getString(R.string.not_connected)); remoteViews.setTextColor(R.id.mobileInfoBottomTextView, ContextCompat.getColor(context, R.color.medium_gray)); remoteViews.setTextViewText(R.id.mobileInfoBottomTextView, MobileDataUtils.getDataUsageString(context, NetworkStateService.getDataUsageBytes())); } else { setStateColor(context, remoteViews, STATE_OFF); remoteViews.setTextViewText(R.id.mobileNameTextView, isAirplaneModeOn ? context.getString(R.string.mobile_data) : networkOperatorAndServiceProvider); remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_off); if (isAirplaneModeOn) { remoteViews.setTextViewText(R.id.mobileInfoTopTextView, context.getString(R.string.flight_mode)); remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.GONE); } else { remoteViews.setTextViewText(R.id.mobileInfoTopTextView, MobileDataUtils.getNetworkTypeString(telephonyManager.getNetworkType()) + (isDataRoaming ? " - " + context.getString(R.string.roaming) : "")); remoteViews.setTextViewText(R.id.mobileInfoBottomTextView, MobileDataUtils.getDataUsageString(context, NetworkStateService.getDataUsageBytes())); } } } else { setStateColor(context, remoteViews, STATE_ON); remoteViews.setTextViewText(R.id.mobileNameTextView, networkOperatorAndServiceProvider); remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_on); remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE); remoteViews.setTextViewText(R.id.mobileInfoTopTextView, MobileDataUtils.getNetworkTypeString(telephonyManager.getNetworkType()) + (isDataRoaming ? " - " + context.getString(R.string.roaming) : "")); remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.VISIBLE); boolean isConnecting = ((dataState == TelephonyManager.DATA_CONNECTING) || NetworkStateService.isWaitingForDataUsage()); remoteViews.setTextViewText(R.id.mobileInfoBottomTextView, isConnecting ? context.getString(R.string.connecting) : MobileDataUtils.getDataUsageString(context, dataUsageBytes)); } }
From source file:github.madmarty.madsonic.util.Util.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {// w ww . j ava 2s . c o m int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { LOG.warn("Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } rv.setImageViewResource(R.id.control_starred, song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { rv.setTextColor(R.id.notification_title, colors.getFirst()); } if (colors.getSecond() != null) { rv.setTextColor(R.id.notification_artist, colors.getSecond()); } if (!playing) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play); rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop); } // Create actions for media buttons PendingIntent pendingIntent; if (playing) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } Intent starredIntent = new Intent("KEYCODE_MEDIA_STARRED"); starredIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); starredIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_STAR)); pendingIntent = PendingIntent.getService(context, 0, starredIntent, 0); rv.setOnClickPendingIntent(R.id.control_starred, pendingIntent); Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(R.id.control_pause, pendingIntent); Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(R.id.control_next, pendingIntent); }
From source file:eu.trentorise.smartcampus.widget.shortcuts.StackWidgetService.java
@Override public RemoteViews getViewAt(int position) { // position will always range from 0 to getCount() - 1. // We construct a remote views item based on our widget item xml // file, and set the // text based on the position. RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item); ShapeDrawable sd1 = new ShapeDrawable(new RectShape()); sd1.getPaint().setColor(0xFFFFFFFF); sd1.getPaint().setStyle(Style.STROKE); sd1.getPaint().setStrokeWidth(1);/*from ww w .j a v a2s . c om*/ Canvas c = new Canvas(); sd1.draw(c); Bitmap b = Bitmap.createBitmap(120, 120, Bitmap.Config.ARGB_8888); c.drawBitmap(b, 0, 0, sd1.getPaint()); // Next, we set a fill-intent which will be used to fill-in the // pending intent template // which is set on the collection view in StackWidgetProvider. if (ALLPREFERENCES != null && ALLPREFERENCES[position] != null) { //ALLPREFERENCES dimensionato come le preferenze selezionate BookmarkDescriptor myDescriptor = ALLPREFERENCES[position]; // set the widgetbutton if (WidgetHelper.PARAM_TYPE.equals(myDescriptor.params.get(0).name)) { //controllare con gli input da config activity? String type = myDescriptor.params.get(0).value; if (WidgetHelper.TYPE_DT.equals(type)) { // dt -> put icons and hide text rv.setViewVisibility(R.id.text_widget_item, View.GONE); rv.setImageViewResource(R.id.image_widget_item, Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_dt); } else if (WidgetHelper.TYPE_JP.equals(type)) { // jp -> put text and hide icon rv.setViewVisibility(R.id.image_widget_item, View.GONE); // rv.setImageViewBitmap(R.id.text_widget_item, // getBackground(Color.parseColor("#6EB046"))); if (!("0".equals(myDescriptor.params.get(2).value))) { //bus rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 80); rv.setTextViewText(R.id.text_widget_item, RoutesHelper.getShortNameByRouteIdAndAgencyID( myDescriptor.params.get(4).value, myDescriptor.params.get(3).value)); //4,3 rv.setTextColor(R.id.text_widget_item, Integer.parseInt(myDescriptor.params.get(2).value));//rv.setInt(R.id.text_widget_item, "setBackgroundColor", //Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } else { //train rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 12); //controllo contesto getRouteDescriptor i vari parametri rv.setTextViewText(R.id.text_widget_item, mContext.getString( RoutesHelper.getRouteDescriptorByRouteId(myDescriptor.params.get(3).value, myDescriptor.params.get(4).value).getNameResource())); rv.setTextColor(R.id.text_widget_item, Color.BLACK);//Int(R.id.text_widget_item, "setBackgroundColor",Color.BLACK); rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } } else if (WidgetHelper.TYPE_JP_PARKINGS.equals(type)) { // jp parcheggio -> put text and hide icon rv.setViewVisibility(R.id.text_widget_item, View.GONE); rv.setImageViewResource(R.id.image_widget_item, Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } BookmarkDescriptor bookmark = myDescriptor; Bundle extras = new Bundle(); extras.putString(StackWidgetProvider.EXTRA_INTENT, bookmark.getIntent()); if (bookmark.getParams() != null) { for (Param param : bookmark.getParams()) { extras.putString(param.name, param.value); } } Intent fillInIntent = new Intent(bookmark.getIntent()); fillInIntent.putExtras(extras); rv.setOnClickFillInIntent(R.id.layout, fillInIntent); } } // Return the remote views object. // AppWidgetManager manager = AppWidgetManager.getInstance(mContext); // manager.updateAppWidget(thisWidget, rv); return rv; }
From source file:ua.mkh.weather.MainActivity.java
private void create_notif() { // TODO Auto-generated method stub // Prepare intent which is triggered if the // notification is selected String tittle = textView3.getText().toString(); String subject = textView3.getText().toString(); String body = ""; /*//from w w w. j a va2 s. c o m NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Notification notify=new Notification((Integer)img1.getTag(),tittle,System.currentTimeMillis()); PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0); notify.setLatestEventInfo(getApplicationContext(),subject,body,pending); notif.notify(0, notify); final NotificationManager mgr= (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); Notification note=new Notification((Integer)img1.getTag(), "", System.currentTimeMillis()); // This pending intent will open after notification click PendingIntent i=PendingIntent.getActivity(this, 0, new Intent(), 0); note.setLatestEventInfo(this, tittle, "", i); //After uncomment this line you will see number of notification arrived //note.number=2; mgr.notify(1, note); PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); Resources r = getResources(); Notification notification = new NotificationCompat.Builder(this) .setTicker("Tiket") .setSmallIcon(android.R.drawable.ic_menu_report_image) .setContentTitle("Title") .setContentText("Context Text") .setContentIntent(pi) .setAutoCancel(true) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, notification); */ RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContent(remoteViews); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for // the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent); remoteViews.setTextViewText(R.id.textView1, nnn); remoteViews.setTextColor(R.id.textView1, getResources().getColor(R.color.white)); remoteViews.setImageViewResource(R.id.imageView1, (Integer) img1.getTag()); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(100, mBuilder.build()); }
From source file:com.piusvelte.sonet.core.SonetService.java
private void buildWidgetButtons(Integer appWidgetId, boolean updatesReady, int page, boolean hasbuttons, int scrollable, int buttons_bg_color, int buttons_color, int buttons_textsize, boolean display_profile, int margin) { final String widget = Integer.toString(appWidgetId); // Push update for this widget to the home screen int layout;// w w w .ja v a 2 s.co m if (hasbuttons) { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_margin_scrollable; else layout = R.layout.widget_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_margin; else layout = R.layout.widget; } else { if (margin > 0) layout = R.layout.widget_noprofile_margin; else layout = R.layout.widget_noprofile; } } else { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_nobuttons_margin_scrollable; else layout = R.layout.widget_nobuttons_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_nobuttons_margin; else layout = R.layout.widget_nobuttons; } else { if (margin > 0) layout = R.layout.widget_nobuttons_noprofile_margin; else layout = R.layout.widget_nobuttons_noprofile; } } // wrap RemoteViews for backward compatibility RemoteViews views = new RemoteViews(getPackageName(), layout); if (hasbuttons) { Bitmap buttons_bg = Bitmap.createBitmap(1, 1, Config.ARGB_8888); Canvas buttons_bg_canvas = new Canvas(buttons_bg); buttons_bg_canvas.drawColor(buttons_bg_color); views.setImageViewBitmap(R.id.buttons_bg, buttons_bg); views.setTextColor(R.id.buttons_bg_clear, buttons_bg_color); views.setFloat(R.id.buttons_bg_clear, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_post, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetCreatePost.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)), 0)); views.setTextColor(R.id.button_post, buttons_color); views.setFloat(R.id.button_post, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_configure, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, ManageAccounts.class).setAction(widget), 0)); views.setTextColor(R.id.button_configure, buttons_color); views.setFloat(R.id.button_configure, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_refresh, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(widget), 0)); views.setTextColor(R.id.button_refresh, buttons_color); views.setFloat(R.id.button_refresh, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_up, buttons_color); views.setFloat(R.id.page_up, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_down, buttons_color); views.setFloat(R.id.page_down, "setTextSize", buttons_textsize); } // set margin if (scrollable == 0) { final AppWidgetManager mgr = AppWidgetManager.getInstance(SonetService.this); // check if native scrolling is supported if (sNativeScrollingSupported) { // native scrolling try { final Intent intent = SonetRemoteViewsServiceWrapper.getRemoteAdapterIntent(SonetService.this); if (intent != null) { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Widgets.DISPLAY_PROFILE, display_profile); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); sSetRemoteAdapter.invoke(views, appWidgetId, R.id.messages, intent); // empty sSetEmptyView.invoke(views, R.id.messages, R.id.empty_messages); // onclick // Bind a click listener template for the contents of the message list final Intent onClickIntent = Sonet.getPackageIntent(SonetService.this, SonetWidget.class); onClickIntent.setAction(ACTION_ON_CLICK); onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(SonetService.this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); sSetPendingIntentTemplate.invoke(views, R.id.messages, onClickPendingIntent); } else { // fallback on non-scrolling widget sNativeScrollingSupported = false; } } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } if (!sNativeScrollingSupported) { Cursor statuses_styles = getContentResolver().query( Uri.withAppendedPath(Statuses_styles.getContentUri(SonetService.this), widget), new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }, null, null, Statuses_styles.CREATED + " DESC LIMIT " + page + ",-1"); if (statuses_styles.moveToFirst()) { int count_status = 0; views.removeAllViews(R.id.messages); while (!statuses_styles.isAfterLast() && (count_status < 16)) { int friend_color = statuses_styles.getInt(6), created_color = statuses_styles.getInt(7), friend_textsize = statuses_styles.getInt(9), created_textsize = statuses_styles.getInt(10), messages_color = statuses_styles.getInt(5), messages_textsize = statuses_styles.getInt(8); // get the item wrapper RemoteViews itemView; if (display_profile) { itemView = new RemoteViews(getPackageName(), R.layout.widget_item); // set profiles background byte[] profile_bg = statuses_styles.getBlob(13); if (profile_bg != null) { Bitmap profile_bgbmp = BitmapFactory.decodeByteArray(profile_bg, 0, profile_bg.length, sBFOptions); if (profile_bgbmp != null) itemView.setImageViewBitmap(R.id.profile_bg, profile_bgbmp); } byte[] profile = statuses_styles.getBlob(2); if (profile != null) { Bitmap profilebmp = BitmapFactory.decodeByteArray(profile, 0, profile.length, sBFOptions); if (profilebmp != null) itemView.setImageViewBitmap(R.id.profile, profilebmp); } } else itemView = new RemoteViews(getPackageName(), R.layout.widget_item_noprofile); itemView.setTextViewText(R.id.friend_bg_clear, statuses_styles.getString(1)); itemView.setFloat(R.id.friend_bg_clear, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.message_bg_clear, statuses_styles.getString(3)); itemView.setFloat(R.id.message_bg_clear, "setTextSize", messages_textsize); // set friends background byte[] friend_bg = statuses_styles.getBlob(14); if (friend_bg != null) { Bitmap friend_bgbmp = BitmapFactory.decodeByteArray(friend_bg, 0, friend_bg.length, sBFOptions); if (friend_bgbmp != null) itemView.setImageViewBitmap(R.id.friend_bg, friend_bgbmp); } // set messages background byte[] status_bg = statuses_styles.getBlob(11); if (status_bg != null) { Bitmap status_bgbmp = BitmapFactory.decodeByteArray(status_bg, 0, status_bg.length, sBFOptions); if (status_bgbmp != null) itemView.setImageViewBitmap(R.id.status_bg, status_bgbmp); } // set an image byte[] image_bg = statuses_styles.getBlob(15); byte[] image = statuses_styles.getBlob(16); if ((image_bg != null) && (image != null)) { Bitmap image_bgBmp = BitmapFactory.decodeByteArray(image_bg, 0, image_bg.length, sBFOptions); if (image_bgBmp != null) { Bitmap imageBmp = BitmapFactory.decodeByteArray(image, 0, image.length, sBFOptions); itemView.setImageViewBitmap(R.id.image_clear, image_bgBmp); itemView.setImageViewBitmap(R.id.image, imageBmp); } } itemView.setTextViewText(R.id.message, statuses_styles.getString(3)); itemView.setTextColor(R.id.message, messages_color); itemView.setFloat(R.id.message, "setTextSize", messages_textsize); itemView.setOnClickPendingIntent(R.id.item, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, StatusDialog.class) .setData(Uri.withAppendedPath( Statuses_styles.getContentUri(SonetService.this), Long.toString(statuses_styles.getLong(0)))), 0)); itemView.setTextViewText(R.id.friend, statuses_styles.getString(1)); itemView.setTextColor(R.id.friend, friend_color); itemView.setFloat(R.id.friend, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.created, statuses_styles.getString(4)); itemView.setTextColor(R.id.created, created_color); itemView.setFloat(R.id.created, "setTextSize", created_textsize); // set icons byte[] icon = statuses_styles.getBlob(12); if (icon != null) { Bitmap iconbmp = BitmapFactory.decodeByteArray(icon, 0, icon.length, sBFOptions); if (iconbmp != null) itemView.setImageViewBitmap(R.id.icon, iconbmp); } views.addView(R.id.messages, itemView); count_status++; statuses_styles.moveToNext(); } if (hasbuttons && (page < statuses_styles.getCount())) { // there are more statuses to show, allow paging down views.setOnClickPendingIntent(R.id.page_down, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class) .setAction(ACTION_PAGE_DOWN) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)) .putExtra(ACTION_PAGE_DOWN, page + 1), PendingIntent.FLAG_UPDATE_CURRENT)); } } statuses_styles.close(); if (hasbuttons && (page > 0)) views.setOnClickPendingIntent(R.id.page_up, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(ACTION_PAGE_UP) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)) .putExtra(ACTION_PAGE_UP, page - 1), PendingIntent.FLAG_UPDATE_CURRENT)); } Log.d(TAG, "update native widget: " + appWidgetId); mgr.updateAppWidget(appWidgetId, views); if (sNativeScrollingSupported) { Log.d(TAG, "trigger widget query: " + appWidgetId); try { // trigger query sNotifyAppWidgetViewDataChanged.invoke(mgr, appWidgetId, R.id.messages); } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } } else if (updatesReady) { // Log.d(TAG, "notify updatesReady"); getContentResolver().notifyChange(Statuses_styles.getContentUri(SonetService.this), null); } else { AppWidgetManager.getInstance(SonetService.this).updateAppWidget(Integer.parseInt(widget), views); buildScrollableWidget(appWidgetId, scrollable, display_profile); } }
From source file:com.shafiq.myfeedle.core.MyfeedleService.java
private void buildWidgetButtons(Integer appWidgetId, boolean updatesReady, int page, boolean hasbuttons, int scrollable, int buttons_bg_color, int buttons_color, int buttons_textsize, boolean display_profile, int margin) { final String widget = Integer.toString(appWidgetId); // Push update for this widget to the home screen int layout;/* w w w. ja v a 2s. c om*/ if (hasbuttons) { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_margin_scrollable; else layout = R.layout.widget_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_margin; else layout = R.layout.widget; } else { if (margin > 0) layout = R.layout.widget_noprofile_margin; else layout = R.layout.widget_noprofile; } } else { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_nobuttons_margin_scrollable; else layout = R.layout.widget_nobuttons_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_nobuttons_margin; else layout = R.layout.widget_nobuttons; } else { if (margin > 0) layout = R.layout.widget_nobuttons_noprofile_margin; else layout = R.layout.widget_nobuttons_noprofile; } } // wrap RemoteViews for backward compatibility RemoteViews views = new RemoteViews(getPackageName(), layout); if (hasbuttons) { Bitmap buttons_bg = Bitmap.createBitmap(1, 1, Config.ARGB_8888); Canvas buttons_bg_canvas = new Canvas(buttons_bg); buttons_bg_canvas.drawColor(buttons_bg_color); views.setImageViewBitmap(R.id.buttons_bg, buttons_bg); views.setTextColor(R.id.buttons_bg_clear, buttons_bg_color); views.setFloat(R.id.buttons_bg_clear, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_post, PendingIntent.getActivity(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleCreatePost.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK).setData(Uri .withAppendedPath(Widgets.getContentUri(MyfeedleService.this), widget)), 0)); views.setTextColor(R.id.button_post, buttons_color); views.setFloat(R.id.button_post, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_configure, PendingIntent.getActivity(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, ManageAccounts.class).setAction(widget), 0)); views.setTextColor(R.id.button_configure, buttons_color); views.setFloat(R.id.button_configure, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_refresh, PendingIntent.getService(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class).setAction(widget), 0)); views.setTextColor(R.id.button_refresh, buttons_color); views.setFloat(R.id.button_refresh, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_up, buttons_color); views.setFloat(R.id.page_up, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_down, buttons_color); views.setFloat(R.id.page_down, "setTextSize", buttons_textsize); } // set margin if (scrollable == 0) { final AppWidgetManager mgr = AppWidgetManager.getInstance(MyfeedleService.this); // check if native scrolling is supported if (sNativeScrollingSupported) { // native scrolling try { final Intent intent = MyfeedleRemoteViewsServiceWrapper .getRemoteAdapterIntent(MyfeedleService.this); if (intent != null) { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Widgets.DISPLAY_PROFILE, display_profile); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); sSetRemoteAdapter.invoke(views, appWidgetId, R.id.messages, intent); // empty sSetEmptyView.invoke(views, R.id.messages, R.id.empty_messages); // onclick // Bind a click listener template for the contents of the message list final Intent onClickIntent = Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleWidget.class); onClickIntent.setAction(ACTION_ON_CLICK); onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(MyfeedleService.this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); sSetPendingIntentTemplate.invoke(views, R.id.messages, onClickPendingIntent); } else { // fallback on non-scrolling widget sNativeScrollingSupported = false; } } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } if (!sNativeScrollingSupported) { Cursor statuses_styles = getContentResolver().query( Uri.withAppendedPath(Statuses_styles.getContentUri(MyfeedleService.this), widget), new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }, null, null, Statuses_styles.CREATED + " DESC LIMIT " + page + ",-1"); if (statuses_styles.moveToFirst()) { int count_status = 0; views.removeAllViews(R.id.messages); while (!statuses_styles.isAfterLast() && (count_status < 16)) { int friend_color = statuses_styles.getInt(6), created_color = statuses_styles.getInt(7), friend_textsize = statuses_styles.getInt(9), created_textsize = statuses_styles.getInt(10), messages_color = statuses_styles.getInt(5), messages_textsize = statuses_styles.getInt(8); // get the item wrapper RemoteViews itemView; if (display_profile) { itemView = new RemoteViews(getPackageName(), R.layout.widget_item); // set profiles background byte[] profile_bg = statuses_styles.getBlob(13); if (profile_bg != null) { Bitmap profile_bgbmp = BitmapFactory.decodeByteArray(profile_bg, 0, profile_bg.length, sBFOptions); if (profile_bgbmp != null) itemView.setImageViewBitmap(R.id.profile_bg, profile_bgbmp); } byte[] profile = statuses_styles.getBlob(2); if (profile != null) { Bitmap profilebmp = BitmapFactory.decodeByteArray(profile, 0, profile.length, sBFOptions); if (profilebmp != null) itemView.setImageViewBitmap(R.id.profile, profilebmp); } } else itemView = new RemoteViews(getPackageName(), R.layout.widget_item_noprofile); itemView.setTextViewText(R.id.friend_bg_clear, statuses_styles.getString(1)); itemView.setFloat(R.id.friend_bg_clear, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.message_bg_clear, statuses_styles.getString(3)); itemView.setFloat(R.id.message_bg_clear, "setTextSize", messages_textsize); // set friends background byte[] friend_bg = statuses_styles.getBlob(14); if (friend_bg != null) { Bitmap friend_bgbmp = BitmapFactory.decodeByteArray(friend_bg, 0, friend_bg.length, sBFOptions); if (friend_bgbmp != null) itemView.setImageViewBitmap(R.id.friend_bg, friend_bgbmp); } // set messages background byte[] status_bg = statuses_styles.getBlob(11); if (status_bg != null) { Bitmap status_bgbmp = BitmapFactory.decodeByteArray(status_bg, 0, status_bg.length, sBFOptions); if (status_bgbmp != null) itemView.setImageViewBitmap(R.id.status_bg, status_bgbmp); } // set an image byte[] image_bg = statuses_styles.getBlob(15); byte[] image = statuses_styles.getBlob(16); if ((image_bg != null) && (image != null)) { Bitmap image_bgBmp = BitmapFactory.decodeByteArray(image_bg, 0, image_bg.length, sBFOptions); if (image_bgBmp != null) { Bitmap imageBmp = BitmapFactory.decodeByteArray(image, 0, image.length, sBFOptions); itemView.setImageViewBitmap(R.id.image_clear, image_bgBmp); itemView.setImageViewBitmap(R.id.image, imageBmp); } } itemView.setTextViewText(R.id.message, statuses_styles.getString(3)); itemView.setTextColor(R.id.message, messages_color); itemView.setFloat(R.id.message, "setTextSize", messages_textsize); itemView.setOnClickPendingIntent(R.id.item, PendingIntent.getActivity(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, StatusDialog.class) .setData(Uri.withAppendedPath( Statuses_styles.getContentUri(MyfeedleService.this), Long.toString(statuses_styles.getLong(0)))), 0)); itemView.setTextViewText(R.id.friend, statuses_styles.getString(1)); itemView.setTextColor(R.id.friend, friend_color); itemView.setFloat(R.id.friend, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.created, statuses_styles.getString(4)); itemView.setTextColor(R.id.created, created_color); itemView.setFloat(R.id.created, "setTextSize", created_textsize); // set icons byte[] icon = statuses_styles.getBlob(12); if (icon != null) { Bitmap iconbmp = BitmapFactory.decodeByteArray(icon, 0, icon.length, sBFOptions); if (iconbmp != null) itemView.setImageViewBitmap(R.id.icon, iconbmp); } views.addView(R.id.messages, itemView); count_status++; statuses_styles.moveToNext(); } if (hasbuttons && (page < statuses_styles.getCount())) { // there are more statuses to show, allow paging down views.setOnClickPendingIntent(R.id.page_down, PendingIntent.getService(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class) .setAction(ACTION_PAGE_DOWN) .setData(Uri.withAppendedPath(Widgets.getContentUri(MyfeedleService.this), widget)) .putExtra(ACTION_PAGE_DOWN, page + 1), PendingIntent.FLAG_UPDATE_CURRENT)); } } statuses_styles.close(); if (hasbuttons && (page > 0)) views.setOnClickPendingIntent(R.id.page_up, PendingIntent.getService(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class) .setAction(ACTION_PAGE_UP) .setData(Uri.withAppendedPath(Widgets.getContentUri(MyfeedleService.this), widget)) .putExtra(ACTION_PAGE_UP, page - 1), PendingIntent.FLAG_UPDATE_CURRENT)); } Log.d(TAG, "update native widget: " + appWidgetId); mgr.updateAppWidget(appWidgetId, views); if (sNativeScrollingSupported) { Log.d(TAG, "trigger widget query: " + appWidgetId); try { // trigger query sNotifyAppWidgetViewDataChanged.invoke(mgr, appWidgetId, R.id.messages); } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } } else if (updatesReady) { // Log.d(TAG, "notify updatesReady"); getContentResolver().notifyChange(Statuses_styles.getContentUri(MyfeedleService.this), null); } else { AppWidgetManager.getInstance(MyfeedleService.this).updateAppWidget(Integer.parseInt(widget), views); buildScrollableWidget(appWidgetId, scrollable, display_profile); } }