public RemoteViews GetViewAt (int position) { var remoteView = new RemoteViews (context.PackageName, Resource.Layout.widget_list_item); var rowData = itemList [position]; // set if is running if (rowData.IsRunning) { remoteView.SetImageViewResource (Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetStop); } else { remoteView.SetImageViewResource (Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay); } // set color remoteView.SetInt (Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor (rowData.Color)); remoteView.SetOnClickFillInIntent (Resource.Id.WidgetContinueImageButton, ConstructFillIntent (rowData)); // set content remoteView.SetTextViewText ( Resource.Id.DescriptionTextView, String.IsNullOrWhiteSpace (rowData.Description) ? context.Resources.GetString (Resource.String.RunningWidgetNoDescription) : rowData.Description); remoteView.SetTextViewText ( Resource.Id.ProjectTextView, String.IsNullOrWhiteSpace (rowData.ProjectName) ? context.Resources.GetString (Resource.String.RunningWidgetNoProject) : rowData.ProjectName); remoteView.SetTextViewText (Resource.Id.DurationTextView, rowData.TimeValue); return remoteView; }
private RemoteViews GetViews(Context context, ulong profileId) { Console.WriteLine("Getting profile for id: " + profileId); var task = api.GetUserData(profileId); var userInfo = task.GetAwaiter().GetResult(); Console.WriteLine("Creating RemoteViews for username: "******"Username: {userInfo.Username} Rank: {userInfo.GlobalRank}"); views.SetTextViewText(Resource.Id.username, userInfo.Username); views.SetTextViewText(Resource.Id.rank, "#" + userInfo.GlobalRank.ToString()); //var actionIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(api.GetProfileUrl(profileId))); //var pending = PendingIntent.GetActivity(context, 0, actionIntent, 0); //views.SetOnClickPendingIntent(Resource.Id.widget, pending); var intent = new Intent(context, Java.Lang.Class.FromType(typeof(RefreshActivity))); var editIntent = new Intent(context, Java.Lang.Class.FromType(typeof(ConfigurationActivity))); var refreshPending = PendingIntent.GetActivity(context, 0, intent, 0); var editPending = PendingIntent.GetActivity(context, 0, editIntent, 0); views.SetOnClickPendingIntent(Resource.Id.refresh, refreshPending); views.SetOnClickPendingIntent(Resource.Id.edit, editPending); Console.WriteLine("Created RemoveViews!"); return(views); }
public override async void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { var me = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name); var widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget); InternetStatus status = new InternetStatus(); NetCredential credential = new NetCredential(); credential.State = await status.SuggestAsync(); var helper = credential.GetHelper(); if (helper != null) { FluxUser user = await helper.GetFluxAsync(); widgetView.SetTextViewText(Resource.Id.widgetTitle, user.Username); widgetView.SetTextViewText(Resource.Id.widgetFlux, $"流量:{user.Flux}"); widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Format(CultureInfo.GetCultureInfo("zh-CN"), "余额:{0:C2}", user.Balance)); } var intent = new Intent(context, typeof(AppWidget)); intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate); intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetIds); var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent); widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground); appWidgetManager.UpdateAppWidget(me, widgetView); }
public RemoteViews GetViewAt(int position) { var remoteView = new RemoteViews(context.PackageName, Resource.Layout.widget_list_item); var rowData = itemList [position]; // set if is running if (rowData.IsRunning) { remoteView.SetImageViewResource(Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetStop); } else { remoteView.SetImageViewResource(Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay); } // set color remoteView.SetInt(Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor(rowData.Color)); remoteView.SetOnClickFillInIntent(Resource.Id.WidgetContinueImageButton, ConstructFillIntent(rowData)); // set content remoteView.SetTextViewText( Resource.Id.DescriptionTextView, String.IsNullOrWhiteSpace(rowData.Description) ? context.Resources.GetString(Resource.String.RunningWidgetNoDescription) : rowData.Description); remoteView.SetTextViewText( Resource.Id.ProjectTextView, String.IsNullOrWhiteSpace(rowData.ProjectName) ? context.Resources.GetString(Resource.String.RunningWidgetNoProject) : rowData.ProjectName); remoteView.SetTextViewText(Resource.Id.DurationTextView, rowData.TimeValue); return(remoteView); }
private void ShowError(RemoteViews widgetView, ErrorType error) { switch (error) { case ErrorType.None: widgetView.SetViewVisibility(Resource.Id.MainLayout, ViewStates.Visible); widgetView.SetViewVisibility(Resource.Id.PlaceName, ViewStates.Visible); widgetView.SetViewVisibility(Resource.Id.Description, ViewStates.Visible); widgetView.SetViewVisibility(Resource.Id.ErrorConnection, ViewStates.Gone); break; case ErrorType.LocalizationError: widgetView.SetViewVisibility(Resource.Id.MainLayout, ViewStates.Gone); widgetView.SetViewVisibility(Resource.Id.PlaceName, ViewStates.Gone); widgetView.SetViewVisibility(Resource.Id.Description, ViewStates.Gone); widgetView.SetTextViewText(Resource.Id.ErrorConnection, Resources.Translations.GetMissingLocalizationPermissionsText()); widgetView.SetViewVisibility(Resource.Id.ErrorConnection, ViewStates.Visible); break; case ErrorType.InternetConnectionError: widgetView.SetViewVisibility(Resource.Id.MainLayout, ViewStates.Gone); widgetView.SetViewVisibility(Resource.Id.PlaceName, ViewStates.Gone); widgetView.SetViewVisibility(Resource.Id.Description, ViewStates.Gone); widgetView.SetTextViewText(Resource.Id.ErrorConnection, Resources.Translations.GetNoInternetConnectionText()); widgetView.SetViewVisibility(Resource.Id.ErrorConnection, ViewStates.Visible); break; } }
Notification buildCustomNotification(ServiceActions action) { PendingIntent pi = PendingIntent.GetActivity(ApplicationContext, 0, new Intent(ApplicationContext, typeof(MainActivity)), PendingIntentFlags.CancelCurrent); PendingIntent play = PendingIntent.GetService(ApplicationContext, 1, new Intent(ActionPlay), PendingIntentFlags.CancelCurrent); PendingIntent pause = PendingIntent.GetService(ApplicationContext, 2, new Intent(ActionPause), PendingIntentFlags.CancelCurrent); Android.App.Notification.Builder builder = new Notification.Builder(ApplicationContext); var myRemoteView = new RemoteViews(PackageName, Resource.Layout.Notification); builder.SetContent(myRemoteView); // if play if (action == ServiceActions.Play) { builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay); myRemoteView.SetTextViewText(Resource.Id.notifyTitle, "KQED 88.5FM LiveStream"); } else if (action == ServiceActions.Pause) { builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPause); myRemoteView.SetTextViewText(Resource.Id.notifyTitle, "Paused: KQED 88.5FM LiveStream"); } myRemoteView.SetOnClickPendingIntent(Resource.Id.notifyBtnPause, pause); myRemoteView.SetOnClickPendingIntent(Resource.Id.notifyBtnPlay, play); myRemoteView.SetOnClickPendingIntent(Resource.Id.notifyTitle, pi); myRemoteView.SetImageViewResource(Resource.Id.notifyImage, Resource.Drawable.KQED); return(builder.Notification); }
private void SetView(Context context, int appWidgetId, RemoteViews widgetView) { Realm realm = Realm.GetInstance(DB.RealmConfiguration); // Set TextViews string title = realm.All <Chapter>().OrderBy(c => c.ID).Last().Title; long lastUpdate = Data.Instance.ReadLong(context, Data.LastUpdateTime); widgetView.SetTextViewText(Resource.Id.chapter_title, title); widgetView.SetTextViewText(Resource.Id.last_update, string.Format("{0:MM/dd/yy H:mm:ss}", new DateTime(lastUpdate))); // Bind the click intent for the chapter on the widget Intent chapterIntent = new Intent(context, typeof(Widget)); chapterIntent.SetAction(OpenChapterClick); chapterIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetId); PendingIntent chapterPendingIntent = PendingIntent.GetBroadcast(context, appWidgetId, chapterIntent, 0); widgetView.SetOnClickPendingIntent(Resource.Id.container, chapterPendingIntent); // Bind the click intent for the refresh button on the widget Intent refreshIntent = new Intent(context, typeof(Widget)); refreshIntent.SetAction(RefreshClick); refreshIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetId); PendingIntent refreshPendingIntent = PendingIntent.GetBroadcast(context, appWidgetId, refreshIntent, PendingIntentFlags.UpdateCurrent); widgetView.SetOnClickPendingIntent(Resource.Id.btn_refresh, refreshPendingIntent); realm.Dispose(); }
public RemoteViews GetViewAt(int position) { var view = new RemoteViews(context.PackageName, Resource.Layout.SuggestionsWidgetItem); var item = items[position]; var hasDescription = !string.IsNullOrEmpty(item.Description); var hasProject = !string.IsNullOrEmpty(item.ProjectName); view.SetViewVisibility(Resource.Id.DescriptionTextView, hasDescription.ToVisibility()); if (hasDescription) { view.SetTextViewText(Resource.Id.DescriptionTextView, item.Description); } view.SetViewVisibility(Resource.Id.ProjectClientRow, hasProject.ToVisibility()); if (hasProject) { view.SetTextViewText(Resource.Id.ProjectNameTextView, item.ProjectName); view.SetTextColor(Resource.Id.ProjectNameTextView, Color.ParseColor(item.ProjectColor)); view.SetTextViewText(Resource.Id.ClientNameTextView, item.ClientName); } var bottomBorderVisibility = (position != Count - 1).ToVisibility(); view.SetViewVisibility(Resource.Id.BottomSeparator, bottomBorderVisibility); var intent = new Intent(); intent.PutExtra(TappedSuggestionIndex, position); view.SetOnClickFillInIntent(Resource.Id.RootLayout, intent); return(view); }
void SetHead(RemoteViews rv, Lesson lesson, bool prevEqual) { if (prevEqual) { //viewHolder.LessonOrder.Visibility = ViewStates.Gone; //viewHolder.LessonTime.Visibility = ViewStates.Gone; //viewHolder.Divider.Visibility = ViewStates.Visible; //viewHolder.Indicator.Visibility = ViewStates.Gone; rv.SetInt(Resource.Id.layout_schedule, "setBackgroundResource", Resource.Color.mtrl_btn_transparent_bg_color); } else { //if (this.currLessonOrder == lesson.Order) //{ // viewHolder.Indicator.Visibility = ViewStates.Visible; // viewHolder.LessonTime.SetTextColor(this.headCurrentColor); //} //else //{ // viewHolder.Indicator.Visibility = ViewStates.Gone; // viewHolder.LessonTime.SetTextColor(this.headColor); //} //viewHolder.LessonOrder.Visibility = ViewStates.Visible; //viewHolder.LessonTime.Visibility = ViewStates.Visible; //viewHolder.Divider.Visibility = ViewStates.Visible; rv.SetInt(Resource.Id.layout_schedule, "setBackgroundResource", Resource.Drawable.top_stroke); var(StartTime, EndTime) = lesson.GetTime(); rv.SetTextViewText(Resource.Id.text_schedule_time, StartTime + " - " + EndTime); rv.SetTextViewText(Resource.Id.text_schedule_order, "#" + (lesson.Order + 1)); } }
public static void Update(Context context, AppWidgetManager appWidgetManager, params int[] appWidgetIds) { foreach (int appWidgetId in appWidgetIds) { Step step; if (!TramUrWayApplication.Config.StepWidgets.TryGetValue(appWidgetId, out step)) { return; } RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.StepWidget); Intent intent = new Intent(context, typeof(StopActivity)); intent.PutExtra("Stop", step.Stop.Id); intent.PutExtra("Route", step.Route.Id); int code = Util.Hash(step.Stop.Id, step.Route.Id); PendingIntent pendingIntent = PendingIntent.GetActivity(context, code, intent, 0); remoteViews.SetOnClickPendingIntent(Resource.Id.StepWidget_Button, pendingIntent); // Update widget UI remoteViews.SetTextViewText(Resource.Id.StepWidget_Name, step.Stop.Name); remoteViews.SetViewVisibility(Resource.Id.StepWidget_Description, TramUrWayApplication.Config.EnableWidgetRefresh ? ViewStates.Visible : ViewStates.Gone); Bitmap bitmap = Utils.GetTransportIconForLine(context, step.Route.Line, 48); remoteViews.SetImageViewBitmap(Resource.Id.StepWidget_Icon, bitmap); // Get step information if (TramUrWayApplication.Config.EnableWidgetRefresh) { DateTime now = DateTime.Now; TimeStep[] timeSteps = null; try { timeSteps = TramUrWayApplication.Service.GetLiveTimeSteps(step.Route.Line).Where(t => t.Step.Stop == step.Stop).OrderBy(t => t.Date).Take(2).ToArray(); } catch (Exception e) { timeSteps = TramUrWayApplication.Lines.SelectMany(l => l.Routes) .SelectMany(r => r.Steps.Where(s => s.Stop.Name == step.Stop.Name)) .SelectMany(s => s.Route.TimeTable?.GetStepsFromStep(s, now)?.Take(3) ?? Enumerable.Empty <TimeStep>()) .Take(2) .ToArray(); } remoteViews.SetTextViewText(Resource.Id.StepWidget_Description, timeSteps == null ? "???" : Utils.GetReadableTimes(timeSteps, now, false)); } try { appWidgetManager.UpdateAppWidget(appWidgetId, remoteViews); } catch (Exception e) { Toast.MakeText(context, "Exception while updating widget: " + e, ToastLength.Long).Show(); } } }
public RemoteViews Setup(Context context, int widgetId) { var view = new RemoteViews(context.PackageName, Resource.Layout.SuggestionsWidget); var intent = new Intent(context, JavaUtils.ToClass <SuggestionsWidgetService>()); intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, widgetId); view.SetRemoteAdapter(Resource.Id.SuggestionsList, intent); view.SetEmptyView(Resource.Id.SuggestionsList, Resource.Id.NoData); var tapIntent = new Intent(context, JavaUtils.ToClass <WidgetsForegroundService>()); tapIntent.SetAction(SuggestionTapped); tapIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, widgetId); var tapPendingIntent = context.SafeGetForegroundService(0, tapIntent, UpdateCurrent); view.SetPendingIntentTemplate(Resource.Id.SuggestionsList, tapPendingIntent); view.SetTextViewText(Resource.Id.Title, Resources.WorkingOnThese); view.SetTextViewText(Resource.Id.NoData, Resources.NoSuggestionsAvailable); view.SetTextViewText(Resource.Id.ShowAllTimeEntriesLabel, Resources.ShowAllTimEntries); var openAppIntent = new Intent(context, typeof(SplashScreen)).SetFlags(TaskOnHome); var openAppPendingIntent = PendingIntent.GetActivity(context, 0, openAppIntent, UpdateCurrent); view.SetOnClickPendingIntent(Resource.Id.ShowAllTimeEntriesLabel, openAppPendingIntent); return(view); }
public static Notification GetNotification(Context context, MedicationDosage medication, DateTime occurrenceDate, Intent notificationIntent) { var builder = new NotificationCompat.Builder(context); builder.SetContentTitle(medication.Name); builder.SetTicker($"[PILLER] {medication.Name}"); builder.SetSmallIcon(Resource.Drawable.pill64x64); builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm)); builder.SetPriority((int)NotificationPriority.High); builder.SetVisibility((int)NotificationVisibility.Public); // visible on locked screen RemoteViews contentView = new RemoteViews(context.PackageName, Resource.Layout.customNotification); contentView.SetTextViewText(Resource.Id.titleTextView, medication.Name); contentView.SetTextViewText(Resource.Id.descTextView, medication.Dosage + " - " + FormatOccurrence(occurrenceDate)); if (medication?.ThumbnailName == null) { contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64)); } else { ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>(); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length)); } RemoteViews contentBigView = new RemoteViews(context.PackageName, Resource.Layout.customBigNotification); contentBigView.SetTextViewText(Resource.Id.titleTextView, medication.Name); contentBigView.SetTextViewText(Resource.Id.descTextView, medication.Dosage + " - " + FormatOccurrence(occurrenceDate)); PendingIntent intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.okButton, intent); intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.noButton, intent); intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.laterButton, intent); if (medication?.ThumbnailName == null) { contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64)); } else { ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>(); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length)); } builder.SetCustomContentView(contentView); builder.SetCustomBigContentView(contentBigView); return(builder.Build()); }
public static RemoteViews BuildListView(string packageName, string text, string subtext, int iconId) { var view = new RemoteViews(packageName, Resource.Layout.autofill_listitem); view.SetTextViewText(Resource.Id.text, text); view.SetTextViewText(Resource.Id.text2, subtext); view.SetImageViewResource(Resource.Id.icon, iconId); return(view); }
public static RemoteViews BuildOverlayPresentation(string text, string subtext, int iconId, Context context) { var packageName = context.PackageName; var view = new RemoteViews(packageName, Resource.Layout.autofill_listitem); view.SetTextViewText(Resource.Id.text1, text); view.SetTextViewText(Resource.Id.text2, subtext); view.SetImageViewResource(Resource.Id.icon, iconId); return(view); }
private void SetTextViewText(RemoteViews widgetView) { widgetView.SetTextViewText(Resource.Id.widgetMedium, "ServerTrackerWidget"); widgetView.SetTextViewText(Resource.Id.widgetSmall, string.Format("Last update: {0:H:mm:ss}", DateTime.Now)); //8.8.8.8 (Google DNS) const string IP = "8.8.8.8"; widgetView.SetTextViewText(Resource.Id.widgetTiny, $"{IP} {(new ServerTest().Ping(IP) == IPStatus.Success ? "Online" : "Offline") }"); }
private void UpdateTime(RemoteViews widgetView) { BindingContext bindingContext = new BindingContext(); widgetView.SetTextViewText(Resource.Id.widgetCurrent, "Current: " + bindingContext.CurrentTotalTime); widgetView.SetTextViewText(Resource.Id.widgetDay, "Day: " + bindingContext.DayTotalTime); widgetView.SetTextViewText(Resource.Id.widgetWeek, "Week: " + bindingContext.WeekTotalTime); widgetView.SetTextViewText(Resource.Id.widgetMonth, "Month: " + bindingContext.MonthTotalTime); widgetView.SetTextViewText(Resource.Id.widgetTotal, "Total: " + bindingContext.TotalTime); }
private void ShowNotificationConnected(bool show) { var nm = GetNotifyManager(); if (show) { NotificationCompat.Builder nb = new NotificationCompat.Builder(ApplicationContext); var remoteView = new RemoteViews(PackageName, Resource.Layout.layout_notify_connected); remoteView.SetTextViewText(Resource.Id.tvNotifyTitle, GetString(Resource.String.app_name)); remoteView.SetTextViewText(Resource.Id.tvNotifyCnctdWith, $"Connected with {_dsp.device.Model}"); Intent itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 0); PendingIntent piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction1, piAction); itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 1); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction2, piAction); itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 2); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction3, piAction); itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 3); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction4, piAction); Intent intent = new Intent(this, typeof(HomeActivity)); intent.PutExtra(INTENT_HOME_TAB, 0); intent.AddFlags(ActivityFlags.ClearTop); intent.AddFlags(ActivityFlags.SingleTop); PendingIntent pendingIntent = PendingIntent.GetActivity(this, IntentHelper.GetId(), intent, 0); nb.SetContentIntent(pendingIntent); nb.SetSmallIcon(Resource.Drawable.av_receiver_100_black); nb.SetOngoing(true); nb.SetCustomBigContentView(remoteView); var x = remoteView.Clone(); x.SetViewVisibility(Resource.Id.llNotifyExp, ViewStates.Gone); nb.SetCustomContentView(x); nm.Notify(notifyIdConnected, nb.Build()); } else { nm.CancelAll(); } }
/// <summary> /// Renders the visual contents of a specific widget contents into a RemoteViews object /// </summary> /// <param name="widgetContext">Widget context.</param> /// <param name="widgetId">Widget identifier.</param> private RemoteViews RenderWidgetContents(Context context, int widgetId) { // Initialise the persistent storage PersistentStorage.StorageMechanism = new StorageMechanism(context); PersistentStorage.UseCache = false; // Create a RemoteView for the widget RemoteViews widgetView = new RemoteViews(context.PackageName, Resource.Layout.widget); // Extract the current trip details and display them. // The trip details and selected trip can be changed independently by the main app so a new set of train trip details need to be read TrainTrips.Reset(); TrainTrip selectedTrip = TrainTrips.SelectedTrip; if (selectedTrip != null) { widgetView.SetTextViewText(Resource.Id.widgetTrip, string.Format("{0}:{1}", selectedTrip.FromCode, selectedTrip.ToCode)); } // Extract the next departure time and display it DateTime departureTime = NextDeparture.DepartureTime; widgetView.SetTextViewText(Resource.Id.widgetDeparture, departureTime.ToString("HH:mm")); // Register pending intents for clicking on the displayed fields RegisterClicks(context, widgetView); // Show the correct image for the running state of the update service if (PersistentStorage.GetBoolItem(UpdateInProgressName, false) == true) { // An update is actually in progress, so show the progress indicator and hide // the service status flags widgetView.SetViewVisibility(Resource.Id.layoutProgressBar, Android.Views.ViewStates.Visible); widgetView.SetViewVisibility(Resource.Id.imageStart, Android.Views.ViewStates.Gone); widgetView.SetViewVisibility(Resource.Id.imageStop, Android.Views.ViewStates.Gone); } else { // Hide the progress indicator and show the servide state widgetView.SetViewVisibility(Resource.Id.layoutProgressBar, Android.Views.ViewStates.Gone); if (PersistentStorage.GetBoolItem(UpdateServiceRunningName, false) == true) { widgetView.SetViewVisibility(Resource.Id.imageStart, Android.Views.ViewStates.Gone); widgetView.SetViewVisibility(Resource.Id.imageStop, Android.Views.ViewStates.Visible); } else { widgetView.SetViewVisibility(Resource.Id.imageStart, Android.Views.ViewStates.Visible); widgetView.SetViewVisibility(Resource.Id.imageStop, Android.Views.ViewStates.Gone); } } return(widgetView); }
public RemoteViews GetViewAt(int position) { var remoteView = new RemoteViews(context.PackageName, Resource.Layout.widget_list_item); var rowData = itemList [position]; // set if is running if (rowData.IsRunning) { remoteView.SetImageViewResource(Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetStop); remoteView.SetViewVisibility(Resource.Id.DurationChronometer, Android.Views.ViewStates.Visible); remoteView.SetViewVisibility(Resource.Id.DurationTextView, Android.Views.ViewStates.Gone); } else { remoteView.SetImageViewResource(Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay); remoteView.SetViewVisibility(Resource.Id.DurationChronometer, Android.Views.ViewStates.Gone); remoteView.SetViewVisibility(Resource.Id.DurationTextView, Android.Views.ViewStates.Visible); } // set color remoteView.SetInt(Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor(rowData.Color)); remoteView.SetOnClickFillInIntent(Resource.Id.WidgetContinueImageButton, ConstructFillIntent(rowData)); // set content remoteView.SetTextViewText( Resource.Id.DescriptionTextView, String.IsNullOrWhiteSpace(rowData.Description) ? context.Resources.GetString(Resource.String.RunningWidgetNoDescription) : rowData.Description); remoteView.SetTextViewText( Resource.Id.ProjectTextView, String.IsNullOrWhiteSpace(rowData.ProjectName) ? context.Resources.GetString(Resource.String.RunningWidgetNoProject) : rowData.ProjectName); remoteView.SetTextViewText(Resource.Id.DurationTextView, rowData.TimeValue); var time = (long)rowData.Duration.TotalMilliseconds; // Format chronometer correctly. string format = "00:%s"; if (time >= 3600000 && time < 36000000) { format = "0%s"; } else if (time >= 36000000) { format = "%s"; } var baseTime = SystemClock.ElapsedRealtime(); remoteView.SetChronometer(Resource.Id.DurationChronometer, baseTime - (long)rowData.Duration.TotalMilliseconds, format, true); return(remoteView); }
private void SetupRunningBtn(Context ctx, RemoteViews views) { var entry = new WidgetSyncManager.WidgetEntryData(); var isRunning = false; // Check if an entry is running. foreach (var item in UpdateService.LastEntries) { if (item.IsRunning) { entry = item; isRunning = true; } } var baseTime = SystemClock.ElapsedRealtime(); if (isRunning) { views.SetInt(Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor(Resource.Color.bright_red)); views.SetInt(Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStopButtonText); views.SetInt(Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor(entry.Color)); views.SetViewVisibility(Resource.Id.WidgetRunningEntry, ViewStates.Visible); views.SetTextViewText( Resource.Id.WidgetRunningDescriptionTextView, String.IsNullOrWhiteSpace(entry.Description) ? ctx.Resources.GetString(Resource.String.RunningWidgetNoDescription) : entry.Description); var time = (long)entry.Duration.TotalMilliseconds; // Format chronometer correctly. string format = "00:%s"; if (time >= 3600000 && time < 36000000) { format = "0%s"; } else if (time >= 36000000) { format = "%s"; } views.SetChronometer(Resource.Id.Chronometer, baseTime - (long)entry.Duration.TotalMilliseconds, format, true); } else { views.SetInt(Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor(Resource.Color.bright_green)); views.SetInt(Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStartButtonText); views.SetViewVisibility(Resource.Id.WidgetRunningEntry, ViewStates.Invisible); views.SetChronometer(Resource.Id.Chronometer, baseTime, "00:%s", false); views.SetTextViewText(Resource.Id.Chronometer, "00:00:00"); } }
public void UpdateWidgets(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, string updateMessage, string totalVal, string profitVal, Color profCol, bool updating, bool setIntents = false) { for (int i = 0; i < appWidgetIds.Length; i++) { int widgetId = appWidgetIds[i]; RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.Widget); remoteViews.SetViewVisibility(Resource.Id.widgetButton, (updating)? Android.Views.ViewStates.Gone : Android.Views.ViewStates.Visible); remoteViews.SetViewVisibility(Resource.Id.widgetLoading, (updating)? Android.Views.ViewStates.Visible : Android.Views.ViewStates.Gone); if (!string.IsNullOrWhiteSpace(profitVal)) { remoteViews.SetTextViewText(Resource.Id.widgetProfit, profitVal); remoteViews.SetTextColor(Resource.Id.widgetProfit, profCol); } if (!string.IsNullOrWhiteSpace(totalVal)) { remoteViews.SetTextViewText(Resource.Id.widgetTotal, totalVal); } if (!string.IsNullOrWhiteSpace(updateMessage)) { remoteViews.SetTextViewText(Resource.Id.widgetTime, updateMessage); } if (setIntents) { Intent intent = new Intent(context, typeof(HodlrWidgetProvider)); intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate); intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds); PendingIntent pendingIntent = PendingIntent.GetBroadcast( context, 0, intent, PendingIntentFlags.UpdateCurrent); remoteViews.SetOnClickPendingIntent(Resource.Id.widgetButton, pendingIntent); Intent activityIntent = new Intent(context, typeof(MainActivity)); PendingIntent pendingAct = PendingIntent.GetActivity(context, 0, activityIntent, 0); remoteViews.SetOnClickPendingIntent(Resource.Id.widgetImage, pendingAct); } appWidgetManager.UpdateAppWidget(widgetId, remoteViews); } }
public static void UpdateWidget(Context context, AppWidgetManager appWidgetManager, int widgetID) { RemoteViews widgetView = new RemoteViews(context.PackageName, Resource.Layout.layout1); _SecondsLeft -= 5; TimeSpan differ = (DateTime.Now.AddSeconds(_SecondsLeft) - DateTime.Now); widgetView.SetTextViewText(2131296412, "Осталось целых дней: " + Math.Floor((DateTime.Now.AddSeconds(_SecondsLeft) - DateTime.Now).TotalDays) + "\nОсталось минут: " + (int)differ.TotalMinutes); if (_SecondsLeft < 0) { notificationEventStarted(context, widgetID); } Intent configIntent = new Intent(context, Java.Lang.Class.FromType(typeof(CalendarActivity))); configIntent.SetAction(AppWidgetManager.ActionAppwidgetConfigure); configIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, widgetID); PendingIntent pIntent = PendingIntent.GetActivity(context, widgetID, configIntent, 0); widgetView.SetOnClickPendingIntent(2131296411, pIntent); appWidgetManager.UpdateAppWidget(widgetID, widgetView); }
void SetLessonType(RemoteViews rv, Lesson lesson, bool enabled = true) { rv.SetTextColor(Resource.Id.text_schedule_type, enabled ? (lesson.IsImportant() ? this.lessonTypeColors[0] : this.lessonTypeColors[1]) : this.disabledColor); rv.SetTextViewText(Resource.Id.text_schedule_type, lesson.Type.ToUpper()); //viewHolder.LessonType.Enabled = enabled; }
//public static RemoteViews UpdateTimes(Context context) public static void UpdateTimes(Context context) { var widgetView = new RemoteViews(context.PackageName, Resource.Layout.true_time_widget); MainPage.UpdateClock(); widgetView.SetTextViewText(Resource.Id.TrueTimeText, MainPage.TrueTime.ToString("HH:mm:ss")); widgetView.SetTextViewText(Resource.Id.FalseTimeText, MainPage.FalseTime.ToString("HH:mm")); ComponentName thisWidget = new ComponentName(context, Java.Lang.Class.FromType(typeof(TrueTimeWidget)).Name); AppWidgetManager manager = AppWidgetManager.GetInstance(context); manager.UpdateAppWidget(thisWidget, widgetView); //return widgetView; }
public RemoteViews GetViewAt(int position) { Realm other = Realm.GetInstance(DB.RealmConfiguration); if (!RealmInstance.IsSameInstance(other)) { RealmInstance.Dispose(); RealmInstance = other; } RemoteViews page = new RemoteViews(context.PackageName, ItemLayout); Chapter chapter = Descending ? RealmInstance.Find <Chapter>(FirstChapterId + Count - 1 - position) : RealmInstance.Find <Chapter>(FirstChapterId + position); if (chapter == null) { return(page); } page.SetTextViewText(Resource.Id.chapter_title, chapter.Title); Intent chapterClick = new Intent(); chapterClick.SetData(Uri.Parse(chapter.URL)); page.SetOnClickFillInIntent(Resource.Id.root, chapterClick); return(page); }
public RemoteViews GetViewAt (int position) { IList<RichPushMessage> messages = RichPushManager.Shared ().RichPushUser.Inbox.Messages; if (position > messages.Count) { return null; } // Get the data for this position from the content provider RichPushMessage message = messages [position]; // Return a proper item String formatStr = context.Resources.GetString (Resource.String.item_format_string); int itemId = Resource.Layout.widget_item; RemoteViews rv = new RemoteViews (context.PackageName, itemId); rv.SetTextViewText (Resource.Id.widget_item_text, Java.Lang.String.Format (formatStr, message.Title)); int iconDrawable = message.IsRead ? Resource.Drawable.mark_read : Resource.Drawable.mark_unread; rv.SetImageViewResource (Resource.Id.widget_item_icon, iconDrawable); SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm"); rv.SetTextViewText (Resource.Id.date_sent, dateFormat.Format (message.SentDate)); // Add the message id to the intent Intent fillInIntent = new Intent (); Bundle extras = new Bundle (); extras.PutString (RichPushApplication.MESSAGE_ID_RECEIVED_KEY, message.MessageId); fillInIntent.PutExtras (extras); rv.SetOnClickFillInIntent (Resource.Id.widget_item, fillInIntent); return rv; }
protected override void OnCreate (Bundle bundle) { RequestWindowFeature(WindowFeatures.NoTitle); base.OnCreate (bundle); this.SetContentView(Resource.Layout.Home); String package = PackageName; Glistener = new GestureListener(); Gdetector = new GestureDetector (this, Glistener); var trans = FragmentManager.BeginTransaction (); trans.Add (Resource.Id.frame_home,mHomeFragment3,"HomeFragment3"); trans.Hide (mHomeFragment3); trans.Add (Resource.Id.frame_home,mHomeFragment2,"HomeFragment2"); trans.Hide (mHomeFragment2); trans.Add (Resource.Id.frame_home,mHomeFragment1,"HomeFragment1"); trans.Commit(); currentFragment = mHomeFragment1; Button haz_plif = FindViewById <Button> (Resource.Id.haz_plif); FrameLayout fcontainer = FindViewById<FrameLayout> (Resource.Id.frame_home); haz_plif.Click += (object sender, EventArgs e) => { StartActivity(typeof(login)); Finish (); }; fcontainer.Touch += Fcontainer_Touch; RemoteViews rmv = new RemoteViews(package, Resource.Layout.Home); rmv.SetTextViewText(Resource.Id.haz_plif,"Elias was here"); }
public RemoteViews GetViewAt(int position) { RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.task_item); var item = TaskWidget.Items[position]; var imageName = item.IconPath.Split('/')[1].Split('.')[0]; var background = Resource.Drawable.task_item_background_false; if (item.Status) { background = Resource.Drawable.task_item_background_true; } var extras = new Bundle(); extras.PutInt("ItemNo", item.No); var fiIntent = new Intent(); fiIntent.PutExtras(extras); remoteViews.SetOnClickFillInIntent(Resource.Id.task_layout, fiIntent); remoteViews.SetInt(Resource.Id.task_layout, "setBackgroundResource", background); remoteViews.SetImageViewResource(Resource.Id.task_icon, context.Resources.GetIdentifier(imageName, "drawable", context.PackageName)); remoteViews.SetTextViewText(Resource.Id.task_content, item.Content); return(remoteViews); }
private async void UpdateDataNotification() { while (true) { if (info_radio != null && info_radio.track != current_name_track) { contentView.SetImageViewBitmap(Resource.Id.notification_image, GetImageBitmapFromUrl(info_radio.image)); contentView.SetTextViewText(Resource.Id.notification_text_title, info_radio.track); contentView.SetTextViewText(Resource.Id.notification_text_artist, info_radio.artist); mNotifyManager.Notify(Id_Notification, notification); current_name_track = info_radio.track; } await Task.Delay(3000); } }
private void ShowNotification(bool setPlayImage) { var mainActivity = (MainActivity)CrossCurrentActivity.Current.Activity; NotificationCompat.Builder builder = new NotificationCompat.Builder(mainActivity) .SetOngoing(true) .SetSmallIcon(Resource.Drawable.ic_headset_white); var contentView = new RemoteViews(mainActivity.PackageName, Resource.Layout.audioNotificationView); contentView.SetOnClickPendingIntent(Resource.Id.btnPlayPause, GetIntentForAction(PlayPauseAction)); contentView.SetOnClickPendingIntent(Resource.Id.btnStop, GetIntentForAction(StopAction)); contentView.SetTextViewText(Resource.Id.textViewTitle, AudioTitle); contentView.SetImageViewResource(Resource.Id.btnPlayPause, setPlayImage ? Resource.Drawable.ic_pause : Resource.Drawable.ic_play_arrow); contentView.SetProgressBar(Resource.Id.audio_progress_bar, mediaPlayer.Duration, mediaPlayer.CurrentPosition, false); builder = builder.SetCustomContentView(contentView); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { builder.SetVisibility((int)NotificationVisibility.Public); } // Finally, publish the notification var notificationManager = (NotificationManager)mainActivity.GetSystemService(Context.NotificationService); //notificationManager.Notify(AudioPlayerNotificationId, notificationBuilder.Build ()); notificationManager.Notify(AudioPlayerNotificationId, builder.Build()); }
public static void BuildNotification(String songId) { MediaMetadataRetriever metadata = SongMetadata.GetMetadata(songId); string title = metadata.ExtractMetadata(MetadataKey.Title); string content = metadata.ExtractMetadata(MetadataKey.Artist); if (title == null || content == null) { title = "TubeLoad"; content = AndroidSongsManager.Instance.GetSong(songId).Name.Replace(".mp3", ""); } builder.SetSmallIcon(Resource.Drawable.icon); Drawable drawable = SongMetadata.GetSongPicture(songId); Bitmap bitmap; if (drawable != null) { bitmap = ((BitmapDrawable)SongMetadata.GetSongPicture(songId)).Bitmap; } else { bitmap = BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Drawable.default_song_image); } if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.M) { RemoteViews notificationLayoutExpanded = new RemoteViews(Application.Context.PackageName, Resource.Layout.view_notification_actions); notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationTitle, title); notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationContent, content); notificationLayoutExpanded.SetImageViewBitmap(Resource.Id.songImg, bitmap); CreateNotificationMediaActions(notificationLayoutExpanded); builder.SetCustomBigContentView(notificationLayoutExpanded); builder.SetContentTitle(title); } else { builder.SetLargeIcon(bitmap); builder.SetContentTitle(title); builder.SetContentText(content); } songNotification = builder.Build(); notificationManager.Notify(SONG_NOTIFICATION_ID, songNotification); }
void UpdateTextAndImage(Context context, RemoteViews viewsToUpdate) { int hour = DateTime.Now.Hour; int month = DateTime.Now.Month; int day = DateTime.Now.Day; string date = $"{month}/{day}"; viewsToUpdate.SetTextViewText(Resource.Id.date, date); if (0 <= hour && hour < 3) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[0].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[0].timeText); } else if (3 <= hour && hour < 6) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[1].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[1].timeText); } else if (6 <= hour && hour < 9) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[2].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[2].timeText); } else if (9 <= hour && hour < 12) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[3].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[3].timeText); } else if (12 <= hour && hour < 15) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[4].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[4].timeText); } else if (15 <= hour && hour < 18) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[5].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[5].timeText); } else if (18 <= hour && hour < 21) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[6].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[6].timeText); } else if (21 <= hour) { viewsToUpdate.SetImageViewResource(Resource.Id.image, timeContainers[7].imageId); viewsToUpdate.SetTextViewText(Resource.Id.timeText, timeContainers[7].timeText); } }
public static RemoteViews NewRemoteViews(string packageName, string remoteViewsText, int drawableId) { RemoteViews presentation = new RemoteViews(packageName, Resource.Layout.autofill_service_list_item); presentation.SetTextViewText(Resource.Id.text, remoteViewsText); presentation.SetImageViewResource(Resource.Id.icon, drawableId); return(presentation); }
// Build a widget update to show the current Wiktionary // "Word of the day." Will block until the online API returns. public RemoteViews buildUpdate (Context context) { var entry = BlogPost.GetBlogPost (); // Build an update that holds the updated widget contents var updateViews = new RemoteViews (context.PackageName, Resource.Layout.widget_word); updateViews.SetTextViewText (Resource.Id.blog_title, entry.Title); updateViews.SetTextViewText (Resource.Id.creator, entry.Creator); // When user clicks on widget, launch to Wiktionary definition page if (!string.IsNullOrEmpty (entry.Link)) { Intent defineIntent = new Intent (Intent.ActionView, Android.Net.Uri.Parse (entry.Link)); PendingIntent pendingIntent = PendingIntent.GetActivity (context, 0, defineIntent, 0); updateViews.SetOnClickPendingIntent (Resource.Id.widget, pendingIntent); } return updateViews; }
public RemoteViews GetViewAt (int position) { var remoteView = new RemoteViews (context.PackageName, Resource.Layout.widget_list_item); var rowData = itemList [position]; // set if is running if (rowData.IsRunning) { remoteView.SetImageViewResource (Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetStop); remoteView.SetViewVisibility (Resource.Id.DurationChronometer, Android.Views.ViewStates.Visible); remoteView.SetViewVisibility (Resource.Id.DurationTextView, Android.Views.ViewStates.Gone); } else { remoteView.SetImageViewResource (Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay); remoteView.SetViewVisibility (Resource.Id.DurationChronometer, Android.Views.ViewStates.Gone); remoteView.SetViewVisibility (Resource.Id.DurationTextView, Android.Views.ViewStates.Visible); } // set color remoteView.SetInt (Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor (rowData.Color)); remoteView.SetOnClickFillInIntent (Resource.Id.WidgetContinueImageButton, ConstructFillIntent (rowData)); // set content remoteView.SetTextViewText ( Resource.Id.DescriptionTextView, String.IsNullOrWhiteSpace (rowData.Description) ? context.Resources.GetString (Resource.String.RunningWidgetNoDescription) : rowData.Description); remoteView.SetTextViewText ( Resource.Id.ProjectTextView, String.IsNullOrWhiteSpace (rowData.ProjectName) ? context.Resources.GetString (Resource.String.RunningWidgetNoProject) : rowData.ProjectName); remoteView.SetTextViewText (Resource.Id.DurationTextView, rowData.TimeValue); var time = (long)rowData.Duration.TotalMilliseconds; // Format chronometer correctly. string format = "00:%s"; if (time >= 3600000 && time < 36000000) { format = "0%s"; } else if (time >= 36000000) { format = "%s"; } var baseTime = SystemClock.ElapsedRealtime (); remoteView.SetChronometer (Resource.Id.DurationChronometer, baseTime - (long)rowData.Duration.TotalMilliseconds, format, true); return remoteView; }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { if (livecard == null) { livecard = new LiveCard (Application, "beacon"); remoteViews = new RemoteViews (PackageName, Resource.Layout.LiveCardBeacon); remoteViews.SetTextViewText (Resource.Id.LivecardContent, "Finding the monkey..."); livecard.SetViews (remoteViews); // Set up the live card's action with a pending intent // to show a menu when tapped var menuIntent = new Intent(this, typeof(MenuActivity)); menuIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); livecard.SetAction(PendingIntent.GetActivity(this, 0, menuIntent, 0)); livecard.Publish (LiveCard.PublishMode.Reveal); } return StartCommandResult.Sticky; }
private void onShowViewModel(GlassShowViewModelMessage request) { var shouldPublish = ensureLiveCard(request); if (GlassViewModelAnnotator.Annotators.ContainsKey(request.ViewModelType) && shouldPublish) { var rendererType = GlassViewModelAnnotator.Annotators[request.ViewModelType]; if (rendererType.IsSubclassOf(typeof(GlassDirectRenderingCallbackTarget))) { var renderer = Activator.CreateInstance(rendererType, new[] {request.SenderAsService}) as GlassDirectRenderingCallbackTarget; renderer.attachedService(request.SenderAsService); request.SenderAsService.attachedRenderer(renderer); try { _liveCard .SetDirectRenderingEnabled(true) .SurfaceHolder .AddCallback(renderer.RenderingCallbackWrapper); _liveCard.Attach(request.SenderAsService); var menuIntent = new Intent(request.SenderAsService, typeof(CompassMenuActivity)); menuIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); _liveCard.SetAction(PendingIntent.GetActivity(request.SenderAsService, 0, menuIntent, 0)); } catch (Exception ex) { } } else { //var rv = new RemoteViews(request.SenderAsService.PackageName, Resource.Layout.ViewMapNotFound); //rv.SetTextViewText(Resource.Id.LivecardContent, "Unsupported view type: " + request.ViewModelType.Name); //_liveCard.SetViews(rv); } //var rv = new RemoteViews(request.SenderAsService.PackageName, Resource.Layout.ViewMapNotFound); //rv.SetTextViewText(Resource.Id.LivecardContent, "Up and running " + request.ViewModelType.Name); //_liveCard.SetViews(rv); } else if (shouldPublish) { var rv = new RemoteViews(request.SenderAsService.PackageName, Resource.Layout.ViewMapNotFound); rv.SetTextViewText(Resource.Id.LivecardContent, "Could not locate annotation for view model: " + request.ViewModelType.Name); _liveCard.SetViews(rv); var menuIntent = new Intent(request.SenderAsService, typeof(CompassMenuActivity)); menuIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); _liveCard.SetAction(PendingIntent.GetActivity(request.SenderAsService, 0, menuIntent, 0)); _liveCard.Attach(request.SenderAsService); } if (shouldPublish) _liveCard.Publish(LiveCard.PublishMode.Reveal); _liveCard.Navigate(); }
private void SetupRunningBtn (Context ctx, RemoteViews views) { var entry = new WidgetSyncManager.WidgetEntryData(); var isRunning = false; // Check if an entry is running. foreach (var item in UpdateService.LastEntries) if (item.IsRunning) { entry = item; isRunning = true; } var baseTime = SystemClock.ElapsedRealtime (); if (isRunning) { views.SetInt (Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor (Resource.Color.bright_red)); views.SetInt (Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStopButtonText); views.SetInt (Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor (entry.Color)); views.SetViewVisibility (Resource.Id.WidgetRunningEntry, ViewStates.Visible); views.SetTextViewText ( Resource.Id.WidgetRunningDescriptionTextView, String.IsNullOrWhiteSpace (entry.Description) ? ctx.Resources.GetString (Resource.String.RunningWidgetNoDescription) : entry.Description); var time = (long)entry.Duration.TotalMilliseconds; // Format chronometer correctly. string format = "00:%s"; if (time >= 3600000 && time < 36000000) { format = "0%s"; } else if (time >= 36000000) { format = "%s"; } views.SetChronometer (Resource.Id.Chronometer, baseTime - (long)entry.Duration.TotalMilliseconds, format, true); } else { views.SetInt (Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor (Resource.Color.bright_green)); views.SetInt (Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStartButtonText); views.SetViewVisibility (Resource.Id.WidgetRunningEntry, ViewStates.Invisible); views.SetChronometer (Resource.Id.Chronometer, baseTime, "00:%s", false); views.SetTextViewText (Resource.Id.Chronometer, "00:00:00"); } }
// Build a widget update to show the current Wiktionary // "Word of the day." Will block until the online API returns. public RemoteViews BuildUpdate(Context context) { // var entry = WordEntry.GetWordOfTheDay(); // Build an update that holds the updated widget contents var updateViews = new RemoteViews(context.PackageName, Resource.Layout.taskwidget); try { var launchAppIntent = new Intent(this, typeof (MainActivity)); launchAppIntent.AddFlags(ActivityFlags.SingleTop); launchAppIntent.AddFlags(ActivityFlags.ClearTop); launchAppIntent.PutExtra("CameFromWidget", true); var pendingIntent = PendingIntent.GetActivity(context, 0, launchAppIntent, 0); updateViews.SetOnClickPendingIntent(Resource.Id.widget_top_action_bar, pendingIntent); var launchAppIntent2 = new Intent(this, typeof(MainActivity)); launchAppIntent2.AddFlags(ActivityFlags.SingleTop); launchAppIntent2.AddFlags(ActivityFlags.ClearTop); var pendingIntent2 = PendingIntent.GetActivity(context, 0, launchAppIntent, 0); updateViews.SetOnClickPendingIntent(Resource.Id.widget_main_area, pendingIntent2); var newTasks = new List<string>(); var newTasksChecked = new List<bool>(); var lineVisibility = new List<ViewStates>(); for(int i = 0; i < 15; i++) { newTasks.Add(string.Empty); newTasksChecked.Add(false); lineVisibility.Add(ViewStates.Gone); } var tasks = DataManager.GetTasks(SortOption.Newest); var count = tasks.Count(); count = count > m_TextViews.Length ? m_TextViews.Length : count; for (int i = 0; i < count; i++) { var task = tasks.ElementAt(i); newTasks[i] = task.Task; newTasksChecked[i] = task.Checked; if (i != 0) lineVisibility[i - 1] = ViewStates.Visible; } if (newTasks[0] == string.Empty) newTasks[0] = "No Tasks Added."; for(int i = 0; i < m_TextViews.Length; i++) { updateViews.SetTextViewText(m_TextViews[i], newTasks[i]); updateViews.SetTextColor(m_TextViews[i], newTasksChecked[i] ? Android.Graphics.Color.DarkGray : Android.Graphics.Color.Black ); } for(int i = 0; i < m_TextViewsLines.Length; i++) updateViews.SetViewVisibility(m_TextViewsLines[i], lineVisibility[i]); } catch (Exception ex) { updateViews.SetTextViewText(Resource.Id.widget_task_1, "Error loading widget"); } return updateViews; }
/// <summary> /// Update the notification. /// </summary> /// <param name="context"> /// The context. /// </param> /// <returns> /// The updated notification. /// </returns> public Notification UpdateNotification(Context context) { bool hasPausedText = this.PausedText != null; bool mustUpdate = this.lastHasPausedText != hasPausedText; // Build the RemoteView object if (expandedView == null) { expandedView = new RemoteViews(context.PackageName, Resource.Layout.status_bar_ongoing_event_progress_bar); expandedView.SetImageViewResource(Resource.Id.appIcon, this.Icon); expandedView.SetTextViewText(Resource.Id.paused_text, this.PausedText); expandedView.SetTextViewText(Resource.Id.title, this.Title); this.notification.ContentView = expandedView; mustUpdate = true; } if (mustUpdate) { expandedView.SetViewVisibility(Resource.Id.progress_bar_frame, hasPausedText ? ViewStates.Gone : ViewStates.Visible); expandedView.SetViewVisibility(Resource.Id.description, hasPausedText ? ViewStates.Gone : ViewStates.Visible); expandedView.SetViewVisibility(Resource.Id.time_remaining, hasPausedText ? ViewStates.Gone : ViewStates.Visible); expandedView.SetViewVisibility(Resource.Id.paused_text, hasPausedText ? ViewStates.Visible : ViewStates.Gone); } if (!hasPausedText) { expandedView.SetTextViewText(Resource.Id.progress_text, Helpers.GetDownloadProgressPercent(this.CurrentBytes, this.TotalBytes)); expandedView.SetTextViewText(Resource.Id.description, Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes)); expandedView.SetProgressBar( Resource.Id.progress_bar, (int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), this.TotalBytes <= 0); expandedView.SetTextViewText(Resource.Id.time_remaining, string.Format("Time remaining: {0}", Helpers.GetTimeRemaining(this.TimeRemaining))); } this.lastHasPausedText = hasPausedText; return this.notification; }
private void UpdateWidgetView() { if (_isShutDowning) return; Console.WriteLine("WidgetService - UpdateWidgetView"); try { // Update widget Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (0)..."); RemoteViews viewWidget = new RemoteViews(PackageName, Resource.Layout.WidgetPlayer); Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (1)..."); AppWidgetManager manager = AppWidgetManager.GetInstance(this); Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (2) - appWidgetIds count: {0}", _widgetIds.Length); // Update metadata on widget if (_audioFile != null) { viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblArtistName, _audioFile.ArtistName); viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblAlbumTitle, _audioFile.AlbumTitle); viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblSongTitle, _audioFile.Title); } else { viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblArtistName, ""); viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblAlbumTitle, ""); viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblSongTitle, ""); } if (_status == PlayerStatusType.Initialized || _status == PlayerStatusType.Paused || _status == PlayerStatusType.Stopped) { viewWidget.SetImageViewResource(Resource.Id.widgetPlayer_btnPlayPause, Resource.Drawable.player_play); } else { viewWidget.SetImageViewResource(Resource.Id.widgetPlayer_btnPlayPause, Resource.Drawable.player_pause); } // Update album art on widget if (_bitmapAlbumArt == null) viewWidget.SetImageViewResource(Resource.Id.widgetPlayer_imageAlbum, 0); else viewWidget.SetImageViewBitmap(Resource.Id.widgetPlayer_imageAlbum, _bitmapAlbumArt); Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (3) - appWidgetIds count: {0}", _widgetIds.Length); foreach (int id in _widgetIds) { Console.WriteLine("WidgetService - UpdateWidgetView - Updating widgets - id: {0}", id); manager.UpdateAppWidget(id, viewWidget); } } catch (Exception ex) { Console.WriteLine("WidgetService - UpdateWidgetView - Widget exception: {0}", ex); } }
void ShowNotification(bool custom) { Resources res = Resources; NotificationManager notificationManager = (NotificationManager) GetSystemService ( NotificationService); Notification.Builder builder = new Notification.Builder (this) .SetSmallIcon (Resource.Drawable.ic_stat_notify_example) .SetAutoCancel (true) .SetTicker (GetString(Resource.String.notification_text)) .SetContentIntent (GetDialogPendingIntent ("Tapped the notification entry.")); if (custom) { // Sets a custom content view for the notification, including an image button. RemoteViews layout = new RemoteViews (PackageName, Resource.Layout.notification); layout.SetTextViewText (Resource.Id.notification_title, GetString (Resource.String.app_name)); layout.SetOnClickPendingIntent (Resource.Id.notification_button, GetDialogPendingIntent ("Tapped the 'dialog' button in the notification.")); builder.SetContent (layout); // Notifications in Android 3.0 now have a standard mechanism for displaying large // bitmaps such as contact avatars. Here, we load an example image and resize it to the // appropriate size for large bitmaps in notifications. Bitmap largeIconTemp = BitmapFactory.DecodeResource (res, Resource.Drawable.notification_default_largeicon); Bitmap largeIcon = Bitmap.CreateScaledBitmap ( largeIconTemp, res.GetDimensionPixelSize (Android.Resource.Dimension.NotificationLargeIconWidth), res.GetDimensionPixelSize (Android.Resource.Dimension.NotificationLargeIconHeight), false); largeIconTemp.Recycle (); builder.SetLargeIcon (largeIcon); } else { builder .SetNumber (7) // An example number. .SetContentTitle (GetString (Resource.String.app_name)) .SetContentText (GetString (Resource.String.notification_text)); } notificationManager.Notify (NotificationDefault, builder.Notification); }
/** * Creates a small layout for the app widget * * * @param context Application context * @param appWidgetId id of the widget * @return RemoteViews for the small layout */ private static RemoteViews CreateSmallLayout(Context context, int appWidgetId) { RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.widget_layout_small); // Update the header for the current unread message count int count = RichPushManager.Shared().RichPushUser.Inbox.UnreadCount; String inboxName = context.GetString(Resource.String.inbox_name); String header = context.GetString(Resource.String.header_format_string, count, inboxName); remoteViews.SetTextViewText(Resource.Id.widget_header_text, header); // Add a click pending intent to launch the inbox remoteViews.SetOnClickPendingIntent(Resource.Id.widget_header, CreateInboxActivityPendingIntent(context)); return remoteViews; }
private Notification BuildNotification() { _notificationBuilder = new NotificationCompat.Builder(ApplicationContext); _notificationBuilder.SetOngoing(true); _notificationBuilder.SetAutoCancel(false); _notificationBuilder.SetSmallIcon(Resource.Drawable.NotifIcon); //Open up the player screen when the user taps on the notification. var launchNowPlayingIntent = new Intent(); launchNowPlayingIntent.SetAction(LaunchNowPlayingAction); var launchNowPlayingPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, launchNowPlayingIntent, 0); _notificationBuilder.SetContentIntent(launchNowPlayingPendingIntent); //Grab the notification layouts. var notificationView = new RemoteViews(ApplicationContext.PackageName, Resource.Layout.notification_custom_layout); var expNotificationView = new RemoteViews(ApplicationContext.PackageName, Resource.Layout.notification_custom_expanded_layout); //Initialize the notification layout buttons. var previousTrackIntent = new Intent(); previousTrackIntent.SetAction(PrevAction); var previousTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, previousTrackIntent, 0); var playPauseTrackIntent = new Intent(); playPauseTrackIntent.SetAction(PlayPauseAction); var playPauseTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, playPauseTrackIntent, 0); var nextTrackIntent = new Intent(); nextTrackIntent.SetAction(NextAction); var nextTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, nextTrackIntent, 0); var stopServiceIntent = new Intent(); stopServiceIntent.SetAction(StopAction); var stopServicePendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, stopServiceIntent, 0); //Check if audio is playing and set the appropriate play/pause button. if (App.Current.AudioServiceConnection.GetPlaybackService().IsPlayingMusic) { notificationView.SetImageViewResource(Resource.Id.notification_base_play, Resource.Drawable.btn_playback_pause_light); expNotificationView.SetImageViewResource(Resource.Id.notification_expanded_base_play, Resource.Drawable.btn_playback_pause_light); } else { notificationView.SetImageViewResource(Resource.Id.notification_base_play, Resource.Drawable.btn_playback_play_light); expNotificationView.SetImageViewResource(Resource.Id.notification_expanded_base_play, Resource.Drawable.btn_playback_play_light); } var song = AudioPlayerHelper.CurrentQueueSong.Song; //Set the notification content. expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_one, song.Name); expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_two, song.ArtistName); expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_three, song.Album.Name); notificationView.SetTextViewText(Resource.Id.notification_base_line_one, song.Name); notificationView.SetTextViewText(Resource.Id.notification_base_line_two, song.ArtistName); //the previous and next buttons, always enabled. expNotificationView.SetViewVisibility(Resource.Id.notification_expanded_base_previous, ViewStates.Visible); expNotificationView.SetViewVisibility(Resource.Id.notification_expanded_base_next, ViewStates.Visible); expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_next, nextTrackPendingIntent); expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_previous, previousTrackPendingIntent); notificationView.SetViewVisibility(Resource.Id.notification_base_previous, ViewStates.Visible); notificationView.SetViewVisibility(Resource.Id.notification_base_next, ViewStates.Visible); notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_play, playPauseTrackPendingIntent); notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_next, nextTrackPendingIntent); notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_previous, previousTrackPendingIntent); //Set the "Stop Service" pending intents. expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_collapse, stopServicePendingIntent); notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_collapse, stopServicePendingIntent); //Set the album art. if (song.Album.Artwork != null) { if (song.Album.Artwork.Image != null) { expNotificationView.SetImageViewBitmap(Resource.Id.notification_expanded_base_image, song.Album.Artwork.Image as Bitmap); notificationView.SetImageViewBitmap(Resource.Id.notification_base_image, song.Album.Artwork.Image as Bitmap); } else ((PclBitmapImage) song.Album.Artwork).PropertyChanged += OnPropertyChanged; } else song.Album.PropertyChanged += OnPropertyChanged; //Attach the shrunken layout to the notification. _notificationBuilder.SetContent(notificationView); //Build the notification object. var notification = _notificationBuilder.Build(); //Attach the expanded layout to the notification and set its flags. notification.BigContentView = expNotificationView; notification.Flags = NotificationFlags.ForegroundService | NotificationFlags.NoClear | NotificationFlags.OngoingEvent; return notification; }