Java Code Examples for android.widget.RemoteViews#setTextViewText()

The following examples show how to use android.widget.RemoteViews#setTextViewText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InfoWidget.java    From AndroidPirateBox with MIT License 6 votes vote down vote up
private RemoteViews createRemoteViews(Context context) {
	RemoteViews views = new RemoteViews(context.getPackageName(),
			R.layout.widget_info_layout);
	
	CharSequence noValue = context.getText(R.string.pref_dev_info_default_summary);
	
	views.setTextViewText(R.id.textUploads, serverRunning ? String.valueOf(uploads) : noValue);
	views.setTextViewText(R.id.textShouts, serverRunning ? String.valueOf(shouts) : noValue);
	views.setTextViewText(R.id.textConnections, serverRunning ? String.valueOf(connections) : noValue);
	
	Intent msg = new Intent(WIDGET_INTENT_CLICKED);
       PendingIntent intent = PendingIntent.getBroadcast(context, -1 /*not used*/, msg, PendingIntent.FLAG_UPDATE_CURRENT);
       views.setOnClickPendingIntent(R.id.main, intent);

	return views;
}
 
Example 2
Source File: ChannelNotificationManager.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
private RemoteViews createMessagesView(Context context, String header) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notification_layout);
    int[] messageIds = new int[] { R.id.message_0, R.id.message_1, R.id.message_2, R.id.message_3, R.id.message_4, R.id.message_5 };
    views.setTextViewText(R.id.message_channel, header);
    synchronized (this) {
        for (int i = messageIds.length - 1; i >= 0; i--) {
            int ii = mMessages.size() - messageIds.length + i;
            if (ii < 0) {
                views.setViewVisibility(messageIds[i], View.GONE);
                continue;
            }
            views.setViewVisibility(messageIds[i], View.VISIBLE);
            views.setTextViewText(messageIds[i], mMessages.get(ii).getNotificationText(context));
        }
    }
    return views;
}
 
Example 3
Source File: SolsticeLayout.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Apply the provided data to the RemoteViews this layout knows about.
 * @param context the android application context
 * @param appWidgetId the android widget ID to update
 * @param views the RemoteViews to apply the data to
 * @param data the data object to apply to the views
 */
public void updateViews(Context context, int appWidgetId, RemoteViews views, SuntimesEquinoxSolsticeData data)
{
    // update title
    String titlePattern = WidgetSettings.loadTitleTextPref(context, appWidgetId);
    String titleText = utils.displayStringForTitlePattern(context, titlePattern, data);
    CharSequence title = (boldTitle ? SuntimesUtils.createBoldSpan(null, titleText, titleText) : titleText);
    views.setTextViewText(R.id.text_title, title);
    //Log.v("DEBUG", "title text: " + titleText);
}
 
Example 4
Source File: KcaTimerWidget.java    From kcanotify with GNU General Public License v3.0 5 votes vote down vote up
public void setWidget(Context context, AppWidgetManager manager, int widgetId, int status) {
    int layout_id = R.layout.widget_timer;
    int[] menu_list = { R.id.menu_1, R.id.menu_2, R.id.menu_3 };
    int[] menu_text_list = { R.string.viewmenu_excheck, R.string.viewmenu_docking, R.string.viewmenu_construction };

    RemoteViews views = new RemoteViews(context.getPackageName(), layout_id);
    for (int i = 0; i < menu_list.length; i++) {
        int color = status == i + 1 ? R.color.colorAccent : R.color.white;
        views.setTextColor(menu_list[i], ContextCompat.getColor(context, color));
        views.setTextViewText(menu_list[i], getStringWithLocale(context, menu_text_list[i]));

        Intent changeIntent = new Intent(context, KcaTimerWidget.class);
        changeIntent.setAction(KcaUtils.format(WIDGET_MENU_CHANGE_FORMAT+"%d", i+1));
        changeIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        changeIntent.putExtra("menu", i + 1);

        PendingIntent changePendingIntent = PendingIntent.getBroadcast(context, widgetId+10, changeIntent, 0);
        views.setOnClickPendingIntent(menu_list[i], changePendingIntent);
    }

    List<AbstractMap.SimpleEntry<String, String>> data = getTimerData(context, status);
    for (int i = 0; i < data.size(); i++) {
        int name = KcaUtils.getId(KcaUtils.format("item%d_name", i+1), R.id.class);
        int time = KcaUtils.getId(KcaUtils.format("item%d_time", i+1), R.id.class);
        AbstractMap.SimpleEntry<String, String> item = data.get(i);
        String name_value = item.getKey();
        String time_value = item.getValue();
        views.setTextViewText(name, name_value);
        views.setTextViewText(time, time_value);
        if (time_value.contains(":") && Integer.parseInt(time_value.replace(":", "")) == 0) {
            views.setTextColor(time, ContextCompat.getColor(context, R.color.colorWidgetAlert));
        } else {
            views.setTextColor(time, ContextCompat.getColor(context, R.color.white));
        }
    }
    manager.updateAppWidget(widgetId, views);
}
 
Example 5
Source File: PostUndoAction.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Context context, ContentProviderClient contentProviderClient, RowDataSnapshot<TaskContract.Instances> data, Uri taskUri) throws RemoteException, OperationApplicationException
{
    int id = (int) ContentUris.parseId(taskUri);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ActionService.CHANNEL_DUE_DATES);
    builder.setContentTitle(context.getString(R.string.task_completed));
    builder.setSmallIcon(R.drawable.ic_notification);
    builder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
    builder.setDefaults(new NoSignal().value());

    final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification);
    undoView.setTextViewText(R.id.description_text, context.getString(R.string.task_completed));

    undoView.setOnClickPendingIntent(
            R.id.status_bar_latest_event_content,
            PendingIntent.getBroadcast(
                    context,
                    id,
                    new Intent(context, ActionReceiver.class).setData(taskUri).setAction(ActionService.ACTION_UNDO_COMPLETE),
                    PendingIntent.FLAG_CANCEL_CURRENT));
    builder.setContent(undoView);

    // When the notification is cleared, we perform the destructive action
    builder.setDeleteIntent(PendingIntent.getBroadcast(
            context,
            id,
            new Intent(context, ActionReceiver.class).setData(taskUri).setAction(ActionService.ACTION_FINISH_COMPLETE),
            PendingIntent.FLAG_CANCEL_CURRENT));
    builder.setShowWhen(false);
    if (Build.VERSION.SDK_INT >= 21)
    {
        // don't execute this on Android 4, otherwise no notification will show up
        builder.setGroup(GROUP_UNDO);
    }
    builder.setColor(new ResourceColor(context, R.color.primary).argb());

    NotificationManagerCompat.from(context).notify("tasks.undo", id, builder.build());
}
 
Example 6
Source File: MainActivity.java    From YCNotification with Apache License 2.0 5 votes vote down vote up
private RemoteViews getRemoteViews() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_mobile_play);
    // 设置 点击通知栏的上一首按钮时要执行的意图
    remoteViews.setOnClickPendingIntent(R.id.btn_pre, getActivityPendingIntent(11));
    // 设置 点击通知栏的下一首按钮时要执行的意图
    remoteViews.setOnClickPendingIntent(R.id.btn_next, getActivityPendingIntent(12));
    // 设置 点击通知栏的播放暂停按钮时要执行的意图
    remoteViews.setOnClickPendingIntent(R.id.btn_start, getActivityPendingIntent(13));
    // 设置 点击通知栏的根容器时要执行的意图
    remoteViews.setOnClickPendingIntent(R.id.ll_root, getActivityPendingIntent(14));
    remoteViews.setTextViewText(R.id.tv_title, "标题");     // 设置通知栏上标题
    remoteViews.setTextViewText(R.id.tv_artist, "艺术家");   // 设置通知栏上艺术家
    return remoteViews;
}
 
Example 7
Source File: VpnNotificationManager.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return a custom remote view for notifications for API 16 - 19
 */
private RemoteViews getKitkatCustomRemoteView(ConnectionStatus status, String title, String message) {
    int iconResource = getIconByConnectionStatus(status);
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.v_custom_notification);
    remoteViews.setImageViewResource(R.id.image_icon, iconResource);
    remoteViews.setTextViewText(R.id.message, message);
    remoteViews.setTextViewText(R.id.title, title);

    return remoteViews;
}
 
Example 8
Source File: MainActivity.java    From Android-Tech with Apache License 2.0 5 votes vote down vote up
private void testNotification() {
    final RemoteViews rv = new RemoteViews(this.getPackageName(), R.layout.remoteview_notification);
    rv.setImageViewResource(R.id.remoteview_notification_icon, R.mipmap.ic_launcher);

    rv.setTextViewText(R.id.remoteview_notification_headline, "Headline");
    rv.setTextViewText(R.id.remoteview_notification_short_message, "Short Message");

    // build notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Content Title")
            .setContentText("Content Text")
            .setContent(rv)
            .setPriority(NotificationCompat.PRIORITY_MIN);

    final Notification notification = mBuilder.build();

    // set big content view for newer androids
    if (Build.VERSION.SDK_INT >= 16) {
        notification.bigContentView = rv;
    }
    NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_ID, notification);

    NotificationTarget notificationTarget = new NotificationTarget(this, rv, R.id.remoteview_notification_icon, notification, NOTIFICATION_ID);

    Glide.with(this.getApplicationContext())// safer!
    .load(eatFoodyImages[3]).asBitmap().into(notificationTarget);
}
 
Example 9
Source File: KcaTimerWidget.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
public void setWidget(Context context, AppWidgetManager manager, int widgetId, int status) {
    int layout_id = R.layout.widget_timer;
    int[] menu_list = { R.id.menu_1, R.id.menu_2, R.id.menu_3 };
    int[] menu_text_list = { R.string.viewmenu_excheck, R.string.viewmenu_docking, R.string.viewmenu_construction };

    RemoteViews views = new RemoteViews(context.getPackageName(), layout_id);
    for (int i = 0; i < menu_list.length; i++) {
        int color = status == i + 1 ? R.color.colorAccent : R.color.white;
        views.setTextColor(menu_list[i], ContextCompat.getColor(context, color));
        views.setTextViewText(menu_list[i], getStringWithLocale(context, menu_text_list[i]));

        Intent changeIntent = new Intent(context, KcaTimerWidget.class);
        changeIntent.setAction(KcaUtils.format(WIDGET_MENU_CHANGE_FORMAT+"%d", i+1));
        changeIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        changeIntent.putExtra("menu", i + 1);

        PendingIntent changePendingIntent = PendingIntent.getBroadcast(context, widgetId+10, changeIntent, 0);
        views.setOnClickPendingIntent(menu_list[i], changePendingIntent);
    }

    List<AbstractMap.SimpleEntry<String, String>> data = getTimerData(context, status);
    for (int i = 0; i < data.size(); i++) {
        int name = KcaUtils.getId(KcaUtils.format("item%d_name", i+1), R.id.class);
        int time = KcaUtils.getId(KcaUtils.format("item%d_time", i+1), R.id.class);
        AbstractMap.SimpleEntry<String, String> item = data.get(i);
        String name_value = item.getKey();
        String time_value = item.getValue();
        views.setTextViewText(name, name_value);
        views.setTextViewText(time, time_value);
        if (time_value.contains(":") && Integer.parseInt(time_value.replace(":", "")) == 0) {
            views.setTextColor(time, ContextCompat.getColor(context, R.color.colorWidgetAlert));
        } else {
            views.setTextColor(time, ContextCompat.getColor(context, R.color.white));
        }
    }
    manager.updateAppWidget(widgetId, views);
}
 
Example 10
Source File: RemoteViewsFactory.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
private RemoteViews setError(RemoteViews remote, String title) {
    remote.setTextViewText(R.id.title, title);
    remote.setOnClickPendingIntent(R.id.control_play, server.status().pendingGet());
    remote.setImageViewResource(R.id.control_play, R.drawable.ic_menu_refresh);
    remote.setImageViewResource(R.id.art, R.drawable.albumart_mp_unknown);
    remote.setViewVisibility(R.id.control_prev, View.GONE);
    remote.setViewVisibility(R.id.control_next, View.GONE);
    resetText(remote, R.id.text, R.id.text1, R.id.text2);
    return remote;
}
 
Example 11
Source File: RssfeedWidgetProvider.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private static RemoteViews createWidgetLayout(Context context, int appWidgetId) {
	
	// create layout
	Intent intent = new Intent(context, RssfeedWidgetService.class);
	intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
	intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
       RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
       views.setRemoteAdapter(R.id.feeds_list, intent);
       views.setEmptyView(R.id.feeds_list, R.layout.widget_empty_layout);

       // set last update time
       String time = DateFormat.getTimeFormat(context).format(new Date());
       String date = DateFormat.getDateFormat(context).format(new Date());
       views.setTextViewText(R.id.last_update, String.format("%1$s, %2$s", time, date));
       
       // assign onRefresh handler
       Intent onRefreshIntent = new Intent(context, RssfeedWidgetProvider.class);
       onRefreshIntent.setAction(ACTION_REFRESH);
       PendingIntent onRefreshPending = PendingIntent.getBroadcast(
       		context, 0, onRefreshIntent, PendingIntent.FLAG_UPDATE_CURRENT);
       views.setOnClickPendingIntent(R.id.refresh, onRefreshPending);
	
       // assign onItemClick handler
       Intent onItemClickIntent = new Intent(context, RssfeedWidgetProvider.class);
       onItemClickIntent.setAction(ACTION_SHOW_LINK);
       onItemClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
       onItemClickIntent.setData(Uri.parse(onItemClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
       final PendingIntent onItemClickPending = PendingIntent.getBroadcast(context, 0,
       		onItemClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
       views.setPendingIntentTemplate(R.id.feeds_list, onItemClickPending);
       
	return views;
}
 
Example 12
Source File: MyWidgetProviderSimple.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
		int[] appWidgetIds) {
	// TODO 0 Make it possible to add the simple widget to the homescreen
	// via Android Manifest

	// TODO 1 Get the component name for MyWidgetProviderSimple.class
	// instead of Void.class
	ComponentName thisWidget = new ComponentName(context, Void.class);
	int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
	for (int widgetId : allWidgetIds) {
		// Create some random data
		int number = (new Random().nextInt(100));

		// TODO 2 Use widgetsimple_layout.xml as layout instead of -1
		RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
				-1);
		Log.w("WidgetExample", String.valueOf(number));
		// TODO 3 Set the text to the view with the id R.id.update
		// instead of -1
		remoteViews.setTextViewText(-1, String.valueOf(number));

		// Register an onClickListener
		Intent intent = new Intent(context, MyWidgetProviderSimple.class);

		intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
		intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

		PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
				0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
		// TODO 4 Add pending intent to the text view with the id
		// R.id.update
		// remoteViews.setOnClickPendingIntent();

		appWidgetManager.updateAppWidget(widgetId, remoteViews);
	}
}
 
Example 13
Source File: WeatherWidget.java    From privacy-friendly-weather with GNU General Public License v3.0 5 votes vote down vote up
public static void updateView(Context context, AppWidgetManager appWidgetManager, RemoteViews views, int appWidgetId, City city, CurrentWeatherData weatherData) {
    AppPreferencesManager prefManager =
            new AppPreferencesManager(PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()));
    DecimalFormat decimalFormat = new DecimalFormat("#.0");
    String temperature = String.format(
            "%s%s",
            decimalFormat.format(prefManager.convertTemperatureFromCelsius(weatherData.getTemperatureCurrent())),
            prefManager.getWeatherUnit()
    );
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
    timeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

    //correct for timezone differences
    int zoneseconds = weatherData.getTimeZoneSeconds();

    Date riseTime = new Date((weatherData.getTimeSunrise() + zoneseconds) * 1000L);
    String sunRise = timeFormat.format(riseTime);
    Date setTime = new Date((weatherData.getTimeSunset() + zoneseconds) * 1000L);
    String sunSet = timeFormat.format(setTime);

    String windSpeed = String.format("%s m/s", weatherData.getWindSpeed());

    views.setTextViewText(R.id.widget_city_weather_temperature, temperature);
    views.setTextViewText(R.id.widget_city_weather_humidity, String.format("%s %%", (int) weatherData.getHumidity()));
    views.setTextViewText(R.id.widget_city_name, city.getCityName());
    views.setTextViewText(R.id.widget_city_weather_rise, sunRise);
    views.setTextViewText(R.id.widget_city_weather_set, sunSet);
    views.setTextViewText(R.id.widget_city_weather_wind, windSpeed);

    views.setImageViewResource(R.id.widget_city_weather_image_view, UiResourceProvider.getIconResourceForWeatherCategory(weatherData.getWeatherID()));

    Intent intent = new Intent(context, ForecastCityActivity.class);
    intent.putExtra("cityId", city.getCityId());
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
    views.setOnClickPendingIntent(R.id.widget1day_layout, pendingIntent);

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 14
Source File: CalenderWidget.java    From MuslimMateAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function fire on system update widget
 *
 * @param context          Context of application
 * @param appWidgetManager App widget manger
 * @param appWidgetIds     Widget system ids
 */
@Override
public void onUpdate(Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int count = appWidgetIds.length;

    //set widget language with the system language
    Locale locale = new Locale(Resources.getSystem().getConfiguration().locale.getLanguage());
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    this.context = context;

    //loop in all widgets
    for (int i = 0; i < count; i++) {
        svcIntent = new Intent(context, CalenderRemoteViewsService.class);
        final int widgetId = appWidgetIds[i];
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_calender);
        remoteViews.setRemoteAdapter(R.id.calendar_pager, svcIntent);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.calendar_pager);
        HGDate hgDate = new HGDate();
        hgDate.toHigri();
        remoteViews.setTextViewText(R.id.textView8, Dates.getCurrentWeekDay());
        remoteViews.setTextViewText(R.id.textView7, NumbersLocal.convertToNumberTypeSystem(context, hgDate.getDay() + ""));
        remoteViews.setTextViewText(R.id.textView24, NumbersLocal.convertToNumberTypeSystem(context, hgDate.getYear() + ""));
        remoteViews.setTextViewText(R.id.curr_month_txt, Dates.islamicMonthName(context, hgDate.getMonth() - 1));
        remoteViews.setTextViewText(R.id.curr_month_txt_other, showOtherMonth(hgDate));

        PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
        remoteViews.setOnClickPendingIntent(R.id.relativeLayout, configPendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);

    }
}
 
Example 15
Source File: RemoteViewsHelper.java    From input-samples with Apache License 2.0 5 votes vote down vote up
private static RemoteViews simpleRemoteViews(String packageName, String remoteViewsText,
        @DrawableRes int drawableId) {
    RemoteViews presentation = new RemoteViews(packageName,
            R.layout.multidataset_service_list_item);
    presentation.setTextViewText(R.id.text, remoteViewsText);
    presentation.setImageViewResource(R.id.icon, drawableId);
    return presentation;
}
 
Example 16
Source File: WidgetHelper.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static void updateWidget(Context context, AppWidgetManager manager, int appWidgetId, boolean serviceRunning) {


        RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_recording);

        // change the subtext depending on whether the service is running or not
        CharSequence subtext = context.getText(
                serviceRunning ? R.string.widget_recording_in_progress : R.string.widget_start_recording);
        updateViews.setTextViewText(R.id.widget_subtext, subtext);

        // if service not running, don't show the "recording" icon
        updateViews.setViewVisibility(R.id.record_badge_image_view, serviceRunning ? View.VISIBLE : View.INVISIBLE);

        PendingIntent pendingIntent = getPendingIntent(context, appWidgetId);

        updateViews.setOnClickPendingIntent(R.id.clickable_linear_layout, pendingIntent);

        manager.updateAppWidget(appWidgetId, updateViews);

    }
 
Example 17
Source File: WidgetV24.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
static void update2x2(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    Theme theme = WidgetUtils.getTheme(widgetId);
    Times times = WidgetUtils.getTimes(widgetId);
    if (times == null) {
        WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId);
        return;
    }

    WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 130f / 160f);
    int w = size.width;
    int h = size.height;
    if (w <= 0 || h <= 0)
        return;
    float scale = w / 10.5f;

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_2x2);
    remoteViews.setInt(R.id.widget_layout, "setBackgroundResource", theme.background);
    remoteViews.setViewPadding(R.id.padder, w / 2, h / 2, w / 2, h / 2);
    LocalDate date = LocalDate.now();
    LocalDateTime[] daytimes = {times.getTime(date, Vakit.FAJR.ordinal()), times.getTime(date, Vakit.SUN.ordinal()), times.getTime(date, Vakit.DHUHR.ordinal()), times.getTime(date, Vakit.ASR.ordinal()), times.getTime(date, Vakit.MAGHRIB.ordinal()),
            times.getTime(date, Vakit.ISHAA.ordinal())};


    remoteViews.setOnClickPendingIntent(R.id.widget_layout, TimesFragment.getPendingIntent(times));


    remoteViews.setTextViewText(R.id.city, times.getName());
    remoteViews.setTextColor(R.id.city, theme.textcolor);
    int current = times.getCurrentTime();
    int next = current + 1;
    int indicator = current;
    if ("next".equals(Preferences.VAKIT_INDICATOR_TYPE.get()))
        indicator = indicator + 1;
    int[] idsText = {R.id.fajrText, R.id.sunText, R.id.zuhrText, R.id.asrText, R.id.maghribText, R.id.ishaaText};
    int[] ids = {R.id.fajr, R.id.sun, R.id.zuhr, R.id.asr, R.id.maghrib, R.id.ishaa};

    boolean rtl = Utils.isRTL(context);

    for (Vakit v : Vakit.values()) {
        int i = v.ordinal();
        remoteViews.setTextViewTextSize(idsText[i], TypedValue.COMPLEX_UNIT_PX, scale * 1f);
        remoteViews.setTextViewTextSize(ids[i], TypedValue.COMPLEX_UNIT_PX, scale * 1f);
        remoteViews.setTextColor(idsText[i], theme.textcolor);
        remoteViews.setTextColor(ids[i], theme.textcolor);

        String name = Vakit.getByIndex(i).getString();
        String time = LocaleUtils.formatTime(daytimes[i].toLocalTime());
        if (Preferences.CLOCK_12H.get()) {
            time = time.replace(" ", "<sup><small>") + "</small></sup>";
        }

        if (Preferences.SHOW_ALT_WIDGET_HIGHLIGHT.get()) {
            if (v.ordinal() == indicator) {
                name = "<b><i>" + name + "</i></b>";
                time = "<b><i>" + time + "</i></b>";
            }
            remoteViews.setInt(idsText[i], "setBackgroundColor", 0);
            remoteViews.setInt(ids[i], "setBackgroundColor", 0);
        } else {
            if (v.ordinal() == indicator) {
                remoteViews.setInt(idsText[i], "setBackgroundColor", theme.hovercolor);
                remoteViews.setInt(ids[i], "setBackgroundColor", theme.hovercolor);
            } else {
                remoteViews.setInt(idsText[i], "setBackgroundColor", 0);
                remoteViews.setInt(ids[i], "setBackgroundColor", 0);
            }
        }

        remoteViews.setTextViewText(idsText[i], Html.fromHtml(!rtl ? name : time));
        remoteViews.setTextViewText(ids[i], Html.fromHtml(!rtl ? time : name));

        remoteViews.setViewPadding(idsText[i], (int) ((Preferences.CLOCK_12H.get() ? 1.25 : 1.75) * scale), 0, (int) scale / 4, 0);
        remoteViews.setViewPadding(ids[i], 0, 0, (int) ((Preferences.CLOCK_12H.get() ? 1.25 : 1.75) * scale), 0);

    }

    remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, scale * 1.3f);
    remoteViews.setTextColor(R.id.countdown, theme.textcolor);
    remoteViews.setViewPadding(R.id.city, (int) scale / 2, 0, (int) scale / 2, (int) scale / 4);

    if (Preferences.COUNTDOWN_TYPE.get().equals(Preferences.COUNTDOWN_TYPE_SHOW_SECONDS))
        remoteViews
                .setChronometer(R.id.countdown, times.getTime(LocalDate.now(), next).toDateTime().getMillis() - (System.currentTimeMillis() - SystemClock.elapsedRealtime()), null, true);
    else {
        String txt = LocaleUtils.formatPeriod(LocalDateTime.now(), times.getTime(LocalDate.now(), next), false);
        remoteViews.setString(R.id.countdown, "setFormat", txt);
        remoteViews.setChronometer(R.id.countdown, 0, txt, false);
    }
    remoteViews.setTextViewTextSize(R.id.countdown, TypedValue.COMPLEX_UNIT_PX, scale * 1.3f);
    appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
 
Example 18
Source File: MoonLayout.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
protected void updateViewsMoonRiseSetText(Context context, RemoteViews views, SuntimesMoonData data, boolean showSeconds, WidgetSettings.RiseSetOrder order)
{
    Calendar moonrise, moonset;
    if (order == WidgetSettings.RiseSetOrder.TODAY)
    {
        moonrise = data.moonriseCalendarToday();
        moonset = data.moonsetCalendarToday();

    } else {
        Calendar now = Calendar.getInstance();
        Calendar[] moon1 = new Calendar[] { data.moonriseCalendarToday(), data.moonsetCalendarToday() };
        if (moon1[0] == null || moon1[0].before(moon1[1]))
        {
            // today: rising, then setting
            if (now.before(moon1[0]))
            {
                // waiting for moonrise
                moonset = data.moonsetCalendarYesterday();  // last: moonset yesterday
                moonrise = data.moonriseCalendarToday();    // next: moonrise today
                if (moonrise == null) {
                    moonrise = data.moonriseCalendarTomorrow();   // .. or moonrise tomorrow
                }

            } else if (now.before(moon1[1])) {
                // waiting for moonset (past rise)
                moonrise = data.moonriseCalendarToday();    // last: moonrise today
                if (moonrise == null) {
                    moonrise = data.moonriseCalendarYesterday();  // .. or moonrise yesterday
                }
                moonset = data.moonsetCalendarToday();      // next: moonset today
                if (moonset == null) {
                    moonset = data.moonsetCalendarTomorrow();     // .. or moonset tomorrow
                }

            } else {
                // waiting for moonrise (tomorrow)
                moonset = data.moonsetCalendarToday();       // last: moonset today
                if (moonset == null) {
                    moonset = data.moonsetCalendarYesterday();    // .. or moonset yesterday
                }
                moonrise = data.moonriseCalendarTomorrow();  // next: moonrise tomorrow
            }

        } else {
            // today: setting, then rising
            if (now.before(moon1[1]))
            {
                // waiting for moonset
                moonrise = data.moonriseCalendarYesterday();   // last: moonrise yesterday
                moonset = data.moonsetCalendarToday();         // next: moonset today
                if (moonset == null) {
                    moonset = data.moonsetCalendarTomorrow();      // .. or moonset tomorrow
                }

            } else if (now.before(moon1[0])) {
                // waiting for moonrise (past set)
                moonset = data.moonsetCalendarToday();         // next: moonset today
                if (moonset == null) {
                    moonset = data.moonsetCalendarYesterday();     // .. or moonset yesterday
                }
                moonrise = data.moonriseCalendarToday();       // next: moonrise today
                if (moonrise == null) {
                    moonrise = data.moonriseCalendarTomorrow();    // .. or moonrise tomorrow
                }

            } else {
                // waiting for moonset (tomorrow)
                moonrise = data.moonriseCalendarToday();       // last: moonrise today
                if (moonrise == null) {
                    moonrise = data.moonriseCalendarYesterday();    // .. or moonrise yesterday
                }
                moonset = data.moonsetCalendarTomorrow();      // next: moonset tomorrow
            }
        }
    }

    SuntimesUtils.TimeDisplayText riseText = utils.calendarTimeShortDisplayString(context, moonrise, showSeconds);
    String riseString = riseText.getValue();
    CharSequence riseSequence = (boldTime ? SuntimesUtils.createBoldSpan(null, riseString, riseString) : riseString);
    views.setTextViewText(R.id.text_time_moonrise, riseSequence);
    views.setTextViewText(R.id.text_time_moonrise_suffix, riseText.getSuffix());

    SuntimesUtils.TimeDisplayText setText = utils.calendarTimeShortDisplayString(context, moonset, showSeconds);
    String setString = setText.getValue();
    CharSequence setSequence = (boldTime ? SuntimesUtils.createBoldSpan(null, setString, setString) : setString);
    views.setTextViewText(R.id.text_time_moonset, setSequence);
    views.setTextViewText(R.id.text_time_moonset_suffix, setText.getSuffix());
}
 
Example 19
Source File: PlayNotifyManager.java    From Musicoco with Apache License 2.0 4 votes vote down vote up
private void setCommonView(RemoteViews view) {

        final String name = currentSong.getTitle();
        final String arts = currentSong.getArtist();
        final Bitmap cover = createCover(currentSong.getAlbum_path());

        view.setImageViewBitmap(R.id.play_notify_cover, cover);

        view.setTextViewText(R.id.play_notify_name, name);
        view.setTextViewText(R.id.play_notify_arts, arts + " - " + name);

        view.setImageViewResource(R.id.play_notify_play,
                play ? R.drawable.ic_pause
                        : R.drawable.ic_play_arrow);

    }
 
Example 20
Source File: WidgetUpdateTask.java    From rpicheck with MIT License 4 votes vote down vote up
private void updateMemory(String memUsedPercent, RemoteViews views) {
    int memUsedPercentInt = (int) (Double.parseDouble(memUsedPercent) * 100);
    views.setTextViewText(R.id.textMemoryValue, FormatHelper.formatPercentage(memUsedPercentInt));
    updateProgressbar(views, R.id.progressBarMemory, 0, 100, memUsedPercentInt);
}