Loading packages/SystemUI/res-keyguard/layout/default_clock_preview.xml 0 → 100644 +30 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextClock android:id="@+id/time" style="@style/widget_big" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@id/date" android:letterSpacing="0.03" android:gravity="center_horizontal" android:format12Hour="@string/keyguard_widget_12_hours_format" android:format24Hour="@string/keyguard_widget_24_hours_format" /> <TextClock android:id="@+id/date" style="@stype/widget_big" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:letterSpacing="0.03" android:gravity="center_horizontal" android:format12Hour="EEE, MMM d" android:format24Hour="EEE, MMM d" /> </RelativeLayout> packages/SystemUI/src/com/android/keyguard/clock/ClockManager.java +17 −7 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,9 @@ import javax.inject.Singleton; @Singleton @Singleton public final class ClockManager { public final class ClockManager { private static final String TAG = "ClockOptsProvider"; private static final String DEFAULT_CLOCK_ID = "default"; private final List<ClockInfo> mClockInfos = new ArrayList<>(); private final List<ClockInfo> mClockInfos = new ArrayList<>(); /** /** * Map from expected value stored in settings to supplier of custom clock face. * Map from expected value stored in settings to supplier of custom clock face. Loading @@ -67,6 +70,7 @@ public final class ClockManager { private final Map<String, Supplier<ClockPlugin>> mClocks = new ArrayMap<>(); private final Map<String, Supplier<ClockPlugin>> mClocks = new ArrayMap<>(); @Nullable private ClockPlugin mCurrentClock; @Nullable private ClockPlugin mCurrentClock; private final LayoutInflater mLayoutInflater; private final ContentResolver mContentResolver; private final ContentResolver mContentResolver; private final SettingsWrapper mSettingsWrapper; private final SettingsWrapper mSettingsWrapper; /** /** Loading Loading @@ -122,11 +126,11 @@ public final class ClockManager { Resources res = context.getResources(); Resources res = context.getResources(); mClockInfos.add(ClockInfo.builder() mClockInfos.add(ClockInfo.builder() .setName("default") .setName(DEFAULT_CLOCK_ID) .setTitle(res.getString(R.string.clock_title_default)) .setTitle(res.getString(R.string.clock_title_default)) .setId("default") .setId(DEFAULT_CLOCK_ID) .setThumbnail(() -> BitmapFactory.decodeResource(res, R.drawable.default_thumbnail)) .setThumbnail(() -> BitmapFactory.decodeResource(res, R.drawable.default_thumbnail)) .setPreview(() -> BitmapFactory.decodeResource(res, R.drawable.default_preview)) .setPreview(() -> getClockPreview(DEFAULT_CLOCK_ID)) .build()); .build()); mClockInfos.add(ClockInfo.builder() mClockInfos.add(ClockInfo.builder() .setName("bubble") .setName("bubble") Loading @@ -151,12 +155,15 @@ public final class ClockManager { .build()); .build()); LayoutInflater layoutInflater = injectionInflater.injectable(LayoutInflater.from(context)); LayoutInflater layoutInflater = injectionInflater.injectable(LayoutInflater.from(context)); mClocks.put(DEFAULT_CLOCK_ID, () -> DefaultClockController.build(layoutInflater)); mClocks.put(BubbleClockController.class.getName(), mClocks.put(BubbleClockController.class.getName(), () -> BubbleClockController.build(layoutInflater)); () -> BubbleClockController.build(layoutInflater)); mClocks.put(StretchAnalogClockController.class.getName(), mClocks.put(StretchAnalogClockController.class.getName(), () -> StretchAnalogClockController.build(layoutInflater)); () -> StretchAnalogClockController.build(layoutInflater)); mClocks.put(TypeClockController.class.getName(), mClocks.put(TypeClockController.class.getName(), () -> TypeClockController.build(layoutInflater)); () -> TypeClockController.build(layoutInflater)); mLayoutInflater = layoutInflater; // Store the size of the display for generation of clock preview. // Store the size of the display for generation of clock preview. DisplayMetrics dm = res.getDisplayMetrics(); DisplayMetrics dm = res.getDisplayMetrics(); Loading Loading @@ -218,6 +225,7 @@ public final class ClockManager { */ */ @Nullable @Nullable private Bitmap getClockPreview(String clockId) { private Bitmap getClockPreview(String clockId) { Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); Supplier<ClockPlugin> supplier = mClocks.get(clockId); Supplier<ClockPlugin> supplier = mClocks.get(clockId); if (supplier == null) { if (supplier == null) { return null; return null; Loading @@ -240,15 +248,13 @@ public final class ClockManager { plugin.dozeTimeTick(); plugin.dozeTimeTick(); // Draw clock view hierarchy to canvas. // Draw clock view hierarchy to canvas. Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.BLACK); dispatchVisibilityAggregated(clockView, true); dispatchVisibilityAggregated(clockView, true); clockView.measure(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY), clockView.measure(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY)); MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY)); clockView.layout(0, 0, mWidth, mHeight); clockView.layout(0, 0, mWidth, mHeight); canvas.drawColor(Color.BLACK); clockView.draw(canvas); clockView.draw(canvas); return bitmap; return bitmap; } } Loading Loading @@ -299,8 +305,12 @@ public final class ClockManager { private void reload() { private void reload() { mCurrentClock = getClockPlugin(); mCurrentClock = getClockPlugin(); if (mCurrentClock instanceof DefaultClockController) { notifyClockChanged(null); } else { notifyClockChanged(mCurrentClock); notifyClockChanged(mCurrentClock); } } } private ClockPlugin getClockPlugin() { private ClockPlugin getClockPlugin() { ClockPlugin plugin = null; ClockPlugin plugin = null; Loading packages/SystemUI/src/com/android/keyguard/clock/DefaultClockController.java 0 → 100644 +98 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.keyguard.clock; import android.graphics.Paint.Style; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import com.android.keyguard.R; import com.android.systemui.plugins.ClockPlugin; import java.util.TimeZone; /** * Plugin for the default clock face used only to provide a preview. */ public class DefaultClockController implements ClockPlugin { /** * Root view of preview. */ private View mView; /** * Text clock in preview view hierarchy. */ private TextView mTextTime; private TextView mTextDate; private DefaultClockController() {} /** * Create a DefaultClockController instance. * * @param inflater Inflater used to inflate custom clock views. */ public static DefaultClockController build(LayoutInflater inflater) { DefaultClockController controller = new DefaultClockController(); controller.createViews(inflater); return controller; } private void createViews(LayoutInflater inflater) { mView = inflater.inflate(R.layout.default_clock_preview, null); mTextTime = mView.findViewById(R.id.time); mTextDate = mView.findViewById(R.id.date); } @Override public View getView() { return null; } @Override public View getBigClockView() { return mView; } @Override public void setStyle(Style style) {} @Override public void setTextColor(int color) { mTextTime.setTextColor(color); mTextDate.setTextColor(color); } @Override public void setColorPalette(boolean supportsDarkText, int[] colorPalette) {} @Override public void dozeTimeTick() { } @Override public void setDarkAmount(float darkAmount) {} @Override public void onTimeZoneChanged(TimeZone timeZone) {} @Override public boolean shouldShowStatusArea() { return true; } } Loading
packages/SystemUI/res-keyguard/layout/default_clock_preview.xml 0 → 100644 +30 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextClock android:id="@+id/time" style="@style/widget_big" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@id/date" android:letterSpacing="0.03" android:gravity="center_horizontal" android:format12Hour="@string/keyguard_widget_12_hours_format" android:format24Hour="@string/keyguard_widget_24_hours_format" /> <TextClock android:id="@+id/date" style="@stype/widget_big" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:letterSpacing="0.03" android:gravity="center_horizontal" android:format12Hour="EEE, MMM d" android:format24Hour="EEE, MMM d" /> </RelativeLayout>
packages/SystemUI/src/com/android/keyguard/clock/ClockManager.java +17 −7 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,9 @@ import javax.inject.Singleton; @Singleton @Singleton public final class ClockManager { public final class ClockManager { private static final String TAG = "ClockOptsProvider"; private static final String DEFAULT_CLOCK_ID = "default"; private final List<ClockInfo> mClockInfos = new ArrayList<>(); private final List<ClockInfo> mClockInfos = new ArrayList<>(); /** /** * Map from expected value stored in settings to supplier of custom clock face. * Map from expected value stored in settings to supplier of custom clock face. Loading @@ -67,6 +70,7 @@ public final class ClockManager { private final Map<String, Supplier<ClockPlugin>> mClocks = new ArrayMap<>(); private final Map<String, Supplier<ClockPlugin>> mClocks = new ArrayMap<>(); @Nullable private ClockPlugin mCurrentClock; @Nullable private ClockPlugin mCurrentClock; private final LayoutInflater mLayoutInflater; private final ContentResolver mContentResolver; private final ContentResolver mContentResolver; private final SettingsWrapper mSettingsWrapper; private final SettingsWrapper mSettingsWrapper; /** /** Loading Loading @@ -122,11 +126,11 @@ public final class ClockManager { Resources res = context.getResources(); Resources res = context.getResources(); mClockInfos.add(ClockInfo.builder() mClockInfos.add(ClockInfo.builder() .setName("default") .setName(DEFAULT_CLOCK_ID) .setTitle(res.getString(R.string.clock_title_default)) .setTitle(res.getString(R.string.clock_title_default)) .setId("default") .setId(DEFAULT_CLOCK_ID) .setThumbnail(() -> BitmapFactory.decodeResource(res, R.drawable.default_thumbnail)) .setThumbnail(() -> BitmapFactory.decodeResource(res, R.drawable.default_thumbnail)) .setPreview(() -> BitmapFactory.decodeResource(res, R.drawable.default_preview)) .setPreview(() -> getClockPreview(DEFAULT_CLOCK_ID)) .build()); .build()); mClockInfos.add(ClockInfo.builder() mClockInfos.add(ClockInfo.builder() .setName("bubble") .setName("bubble") Loading @@ -151,12 +155,15 @@ public final class ClockManager { .build()); .build()); LayoutInflater layoutInflater = injectionInflater.injectable(LayoutInflater.from(context)); LayoutInflater layoutInflater = injectionInflater.injectable(LayoutInflater.from(context)); mClocks.put(DEFAULT_CLOCK_ID, () -> DefaultClockController.build(layoutInflater)); mClocks.put(BubbleClockController.class.getName(), mClocks.put(BubbleClockController.class.getName(), () -> BubbleClockController.build(layoutInflater)); () -> BubbleClockController.build(layoutInflater)); mClocks.put(StretchAnalogClockController.class.getName(), mClocks.put(StretchAnalogClockController.class.getName(), () -> StretchAnalogClockController.build(layoutInflater)); () -> StretchAnalogClockController.build(layoutInflater)); mClocks.put(TypeClockController.class.getName(), mClocks.put(TypeClockController.class.getName(), () -> TypeClockController.build(layoutInflater)); () -> TypeClockController.build(layoutInflater)); mLayoutInflater = layoutInflater; // Store the size of the display for generation of clock preview. // Store the size of the display for generation of clock preview. DisplayMetrics dm = res.getDisplayMetrics(); DisplayMetrics dm = res.getDisplayMetrics(); Loading Loading @@ -218,6 +225,7 @@ public final class ClockManager { */ */ @Nullable @Nullable private Bitmap getClockPreview(String clockId) { private Bitmap getClockPreview(String clockId) { Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); Supplier<ClockPlugin> supplier = mClocks.get(clockId); Supplier<ClockPlugin> supplier = mClocks.get(clockId); if (supplier == null) { if (supplier == null) { return null; return null; Loading @@ -240,15 +248,13 @@ public final class ClockManager { plugin.dozeTimeTick(); plugin.dozeTimeTick(); // Draw clock view hierarchy to canvas. // Draw clock view hierarchy to canvas. Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.BLACK); dispatchVisibilityAggregated(clockView, true); dispatchVisibilityAggregated(clockView, true); clockView.measure(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY), clockView.measure(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY)); MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY)); clockView.layout(0, 0, mWidth, mHeight); clockView.layout(0, 0, mWidth, mHeight); canvas.drawColor(Color.BLACK); clockView.draw(canvas); clockView.draw(canvas); return bitmap; return bitmap; } } Loading Loading @@ -299,8 +305,12 @@ public final class ClockManager { private void reload() { private void reload() { mCurrentClock = getClockPlugin(); mCurrentClock = getClockPlugin(); if (mCurrentClock instanceof DefaultClockController) { notifyClockChanged(null); } else { notifyClockChanged(mCurrentClock); notifyClockChanged(mCurrentClock); } } } private ClockPlugin getClockPlugin() { private ClockPlugin getClockPlugin() { ClockPlugin plugin = null; ClockPlugin plugin = null; Loading
packages/SystemUI/src/com/android/keyguard/clock/DefaultClockController.java 0 → 100644 +98 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.keyguard.clock; import android.graphics.Paint.Style; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import com.android.keyguard.R; import com.android.systemui.plugins.ClockPlugin; import java.util.TimeZone; /** * Plugin for the default clock face used only to provide a preview. */ public class DefaultClockController implements ClockPlugin { /** * Root view of preview. */ private View mView; /** * Text clock in preview view hierarchy. */ private TextView mTextTime; private TextView mTextDate; private DefaultClockController() {} /** * Create a DefaultClockController instance. * * @param inflater Inflater used to inflate custom clock views. */ public static DefaultClockController build(LayoutInflater inflater) { DefaultClockController controller = new DefaultClockController(); controller.createViews(inflater); return controller; } private void createViews(LayoutInflater inflater) { mView = inflater.inflate(R.layout.default_clock_preview, null); mTextTime = mView.findViewById(R.id.time); mTextDate = mView.findViewById(R.id.date); } @Override public View getView() { return null; } @Override public View getBigClockView() { return mView; } @Override public void setStyle(Style style) {} @Override public void setTextColor(int color) { mTextTime.setTextColor(color); mTextDate.setTextColor(color); } @Override public void setColorPalette(boolean supportsDarkText, int[] colorPalette) {} @Override public void dozeTimeTick() { } @Override public void setDarkAmount(float darkAmount) {} @Override public void onTimeZoneChanged(TimeZone timeZone) {} @Override public boolean shouldShowStatusArea() { return true; } }