Add preview for default clock face.

Bug: 123704608
Test: Checked image provided by ContentProvider
Change-Id: I485e02c287a0d26e1eb0e37cf2a519f009a708ca
This commit is contained in:
Robert Snoeberger
2019-02-27 16:44:04 -05:00
parent 8e95f0bfb9
commit 0025751930
3 changed files with 145 additions and 7 deletions

View File

@@ -0,0 +1,30 @@
<?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>

View File

@@ -60,6 +60,9 @@ import javax.inject.Singleton;
@Singleton
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<>();
/**
* Map from expected value stored in settings to supplier of custom clock face.
@@ -67,6 +70,7 @@ public final class ClockManager {
private final Map<String, Supplier<ClockPlugin>> mClocks = new ArrayMap<>();
@Nullable private ClockPlugin mCurrentClock;
private final LayoutInflater mLayoutInflater;
private final ContentResolver mContentResolver;
private final SettingsWrapper mSettingsWrapper;
/**
@@ -122,11 +126,11 @@ public final class ClockManager {
Resources res = context.getResources();
mClockInfos.add(ClockInfo.builder()
.setName("default")
.setName(DEFAULT_CLOCK_ID)
.setTitle(res.getString(R.string.clock_title_default))
.setId("default")
.setId(DEFAULT_CLOCK_ID)
.setThumbnail(() -> BitmapFactory.decodeResource(res, R.drawable.default_thumbnail))
.setPreview(() -> BitmapFactory.decodeResource(res, R.drawable.default_preview))
.setPreview(() -> getClockPreview(DEFAULT_CLOCK_ID))
.build());
mClockInfos.add(ClockInfo.builder()
.setName("bubble")
@@ -151,12 +155,15 @@ public final class ClockManager {
.build());
LayoutInflater layoutInflater = injectionInflater.injectable(LayoutInflater.from(context));
mClocks.put(DEFAULT_CLOCK_ID,
() -> DefaultClockController.build(layoutInflater));
mClocks.put(BubbleClockController.class.getName(),
() -> BubbleClockController.build(layoutInflater));
mClocks.put(StretchAnalogClockController.class.getName(),
() -> StretchAnalogClockController.build(layoutInflater));
mClocks.put(TypeClockController.class.getName(),
() -> TypeClockController.build(layoutInflater));
mLayoutInflater = layoutInflater;
// Store the size of the display for generation of clock preview.
DisplayMetrics dm = res.getDisplayMetrics();
@@ -218,6 +225,7 @@ public final class ClockManager {
*/
@Nullable
private Bitmap getClockPreview(String clockId) {
Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
Supplier<ClockPlugin> supplier = mClocks.get(clockId);
if (supplier == null) {
return null;
@@ -240,15 +248,13 @@ public final class ClockManager {
plugin.dozeTimeTick();
// Draw clock view hierarchy to canvas.
Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.BLACK);
dispatchVisibilityAggregated(clockView, true);
clockView.measure(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY));
clockView.layout(0, 0, mWidth, mHeight);
canvas.drawColor(Color.BLACK);
clockView.draw(canvas);
return bitmap;
}
@@ -299,7 +305,11 @@ public final class ClockManager {
private void reload() {
mCurrentClock = getClockPlugin();
notifyClockChanged(mCurrentClock);
if (mCurrentClock instanceof DefaultClockController) {
notifyClockChanged(null);
} else {
notifyClockChanged(mCurrentClock);
}
}
private ClockPlugin getClockPlugin() {

View File

@@ -0,0 +1,98 @@
/*
* 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;
}
}