Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9332e66 authored by chihhangchuang's avatar chihhangchuang
Browse files

Use real date for theme preview

Screenshot:
  - Launcher date: https://screenshot.googleplex.com/kVY7RxFra4s.png
  - Preview date: https://screenshot.googleplex.com/DaMKPJKentj.png

Also update status bar clock to accept 12/24HR format
  - 12HR: https://screenshot.googleplex.com/jWreQpk0UjU.png
  - 24HR: https://screenshot.googleplex.com/Rb5Kwh7hdTa.png

Test: Manually
Bug: 146475648
Change-Id: I8b59609b31e328ebde15a62ac0198c963be05b05
parent 4c26f4f9
Loading
Loading
Loading
Loading
+24 −24
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
@@ -47,14 +48,16 @@ import com.android.wallpaper.R;
import com.android.wallpaper.util.ScreenSizeCalculator;
import com.android.wallpaper.util.TimeTicker;

import java.text.DateFormat;
import java.text.FieldPosition;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

/** A class to load the {@link ThemeBundle} preview to the view. */
class ThemeOptionPreviewer implements LifecycleObserver {
    private static final String DATE_FORMAT = "EEEE, MMM d";

    // Maps which icon from ResourceConstants#ICONS_FOR_PREVIEW.
    private static final int ICON_WIFI = 0;
    private static final int ICON_BLUETOOTH = 1;
@@ -95,7 +98,8 @@ class ThemeOptionPreviewer implements LifecycleObserver {
    private final Context mContext;

    private View mContentView;
    private TextView mClock;
    private TextView mStatusBarClock;
    private TextView mSmartSpaceDate;
    private TimeTicker mTicker;

    ThemeOptionPreviewer(Lifecycle lifecycle, Context context, ViewGroup previewContainer) {
@@ -104,7 +108,8 @@ class ThemeOptionPreviewer implements LifecycleObserver {
        mContext = context;
        mContentView = LayoutInflater.from(context).inflate(
                R.layout.theme_preview_content_v2, /* root= */ null);
        mClock = mContentView.findViewById(R.id.theme_preview_clock);
        mStatusBarClock = mContentView.findViewById(R.id.theme_preview_clock);
        mSmartSpaceDate = mContentView.findViewById(R.id.smart_space_date);
        updateTime();
        final float screenAspectRatio =
                ScreenSizeCalculator.getInstance().getScreenAspectRatio(mContext);
@@ -167,7 +172,7 @@ class ThemeOptionPreviewer implements LifecycleObserver {
                        ? R.color.text_color_light
                        : R.color.text_color_dark);
        // Update the top status bar clock text color.
        mClock.setTextColor(color);
        mStatusBarClock.setTextColor(color);
        // Update the top status bar icon color.
        ViewGroup iconsContainer = mContentView.findViewById(R.id.theme_preview_top_bar_icons);
        for (int i = 0; i < iconsContainer.getChildCount(); i++) {
@@ -198,14 +203,8 @@ class ThemeOptionPreviewer implements LifecycleObserver {
    }

    private void setHeadlineFont(Typeface headlineFont) {
        // Update font of status bar clock.
        mClock.setTypeface(headlineFont);

        // Update font of the smart space date.
        TextView date = mContentView.findViewById(R.id.smart_space_date);
        date.setTypeface(headlineFont);
        // TODO(chihhangchuang): Use real date.
        date.setText("Friday, Nov 12");
        mStatusBarClock.setTypeface(headlineFont);
        mSmartSpaceDate.setTypeface(headlineFont);

        // Update font of app names.
        for (int id : mShapeIconAppNameIds) {
@@ -292,20 +291,21 @@ class ThemeOptionPreviewer implements LifecycleObserver {
    }

    private void updateTime() {
        if (mClock != null) {
            mClock.setText(getFormattedTime());
        }
    }

    private String getFormattedTime() {
        DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
        Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
        if (mStatusBarClock != null) {
            StringBuffer time = new StringBuffer();
        FieldPosition amPmPosition = new FieldPosition(DateFormat.Field.AM_PM);
        df.format(Calendar.getInstance(TimeZone.getDefault()).getTime(), time, amPmPosition);
            FieldPosition amPmPosition = new FieldPosition(java.text.DateFormat.Field.AM_PM);
            DateFormat.getTimeFormat(mContext).format(calendar.getTime(), time, amPmPosition);
            if (amPmPosition.getBeginIndex() > 0) {
                time.delete(amPmPosition.getBeginIndex(), amPmPosition.getEndIndex());
            }
        return time.toString();
            mStatusBarClock.setText(time);
        }
        if (mSmartSpaceDate != null) {
            String datePattern =
                    DateFormat.getBestDateTimePattern(Locale.getDefault(), DATE_FORMAT);
            mSmartSpaceDate.setText(DateFormat.format(datePattern, calendar));
        }
    }

    private boolean useRoundedQSB(int cornerRadius) {