android.widget.TextClock#setTextColor ( )源码实例Demo

下面列出了android.widget.TextClock#setTextColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: androidtv-daydream   文件: Drifter.java
public void run() {
    final View parent = (View) getParent();
    if (parent == null) return;

    // reposition in parent using setX() and setY()
    final float width = getMeasuredWidth();
    final float height = getMeasuredHeight();
    final float parentw = parent.getMeasuredWidth();
    final float parenth = parent.getMeasuredHeight();
    setX((float) Math.random() * width + (parentw/2 - width));
    setY((float) Math.random() * height + (parenth/2 - height));

    Random rand = new Random();
    // generate the random integers for r, g and b value
    int r = rand.nextInt(COLOR_MAX);
    int g = rand.nextInt(COLOR_MAX);
    int b = rand.nextInt(COLOR_MAX);
    int randomColor = Color.rgb(r, g, b);
    TextClock tc = (TextClock) findViewById(R.id.text_clock);
    tc.setTextColor(randomColor);

    postDelayed(this, DRIFT_DELAY); // let’s do this again, soon
}
 
@SuppressLint({"SetTextI18n", "InflateParams"})
public FirstCardHeaderController(@NonNull GeoActivity activity, @NonNull Location location) {
    this.activity = activity;
    this.view = LayoutInflater.from(activity).inflate(R.layout.container_main_first_card_header, null);

    AppCompatImageView timeIcon = view.findViewById(R.id.container_main_first_card_header_timeIcon);
    TextView refreshTime = view.findViewById(R.id.container_main_first_card_header_timeText);
    TextClock localTime = view.findViewById(R.id.container_main_first_card_header_localTimeText);
    TextView alert = view.findViewById(R.id.container_main_first_card_header_alert);
    View line = view.findViewById(R.id.container_main_first_card_header_line);

    ThemeManager themeManager = ThemeManager.getInstance(activity);

    if (location.getWeather() != null) {
        this.weather = location.getWeather();

        view.setOnClickListener(v ->
                IntentHelper.startManageActivityForResult(activity, MainActivity.MANAGE_ACTIVITY));
        view.setEnabled(!MainDisplayUtils.isMultiFragmentEnabled(activity));

        if (weather.getAlertList().size() == 0) {
            timeIcon.setEnabled(false);
            timeIcon.setImageResource(R.drawable.ic_time);
        } else {
            timeIcon.setEnabled(true);
            timeIcon.setImageResource(R.drawable.ic_alert);
        }
        ImageViewCompat.setImageTintList(
                timeIcon,
                ColorStateList.valueOf(themeManager.getTextContentColor(activity))
        );
        timeIcon.setOnClickListener(this);

        refreshTime.setText(
                activity.getString(R.string.refresh_at)
                        + " "
                        + Base.getTime(activity, weather.getBase().getUpdateDate())
        );
        refreshTime.setTextColor(themeManager.getTextContentColor(activity));

        long time = System.currentTimeMillis();
        if (TimeZone.getDefault().getOffset(time) == location.getTimeZone().getOffset(time)) {
            // same time zone.
            localTime.setVisibility(View.GONE);
        } else {
            localTime.setVisibility(View.VISIBLE);
            localTime.setTimeZone(location.getTimeZone().getID());
            localTime.setTextColor(themeManager.getTextSubtitleColor(activity));
            localTime.setFormat12Hour(
                    activity.getString(R.string.date_format_widget_long) + ", h:mm aa"
            );
            localTime.setFormat24Hour(
                    activity.getString(R.string.date_format_widget_long) + ", HH:mm"
            );
        }

        if (weather.getAlertList().size() == 0) {
            alert.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
        } else {
            alert.setVisibility(View.VISIBLE);
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < weather.getAlertList().size(); i ++) {
                builder.append(weather.getAlertList().get(i).getDescription())
                        .append(", ")
                        .append(
                                DateFormat.getDateTimeInstance(
                                        DateFormat.LONG,
                                        DateFormat.DEFAULT
                                ).format(weather.getAlertList().get(i).getDate())
                        );
                if (i != weather.getAlertList().size() - 1) {
                    builder.append("\n");
                }
            }
            alert.setText(builder.toString());
            alert.setTextColor(themeManager.getTextSubtitleColor(activity));

            line.setVisibility(View.VISIBLE);
            line.setBackgroundColor(themeManager.getRootColor(activity));
        }
        alert.setOnClickListener(this);
    }
}
 
 方法所在类
 同类方法