Add an translucent overlay with icon and clock on lock screen preview.
Also move TimeTicker from ThemePicker to WallPapaerPicker2.
Screenshot: https://screenshot.googleplex.com/2CLp9iUHRzM.png
Bug: 156129610
Change-Id: Iba7d0580099971ace47dd2d0a44c8a1ccd5c4436
diff --git a/res/layout/wallpaper_preview_card.xml b/res/layout/wallpaper_preview_card.xml
index 5430772..4d61fa5 100644
--- a/res/layout/wallpaper_preview_card.xml
+++ b/res/layout/wallpaper_preview_card.xml
@@ -14,6 +14,7 @@
limitations under the License.
-->
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/FullContentPreviewCard"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -34,6 +35,51 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
+ <androidx.constraintlayout.widget.ConstraintLayout
+ android:id="@+id/lock_overlay"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/black_24_alpha"
+ android:visibility="gone">
+
+ <ImageView
+ android:id="@+id/lock_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/ic_lock_outline_24px"
+ android:tint="@color/white_88_alpha"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_bias="0.1" />
+
+ <TextView
+ android:id="@+id/lock_time"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="@style/TitleTextAppearance"
+ android:textColor="@color/white_88_alpha"
+ android:textSize="@dimen/lock_screen_preview_time_text_size"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_bias="0.3" />
+
+ <TextView
+ android:id="@+id/lock_date"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="@style/TitleTextAppearance"
+ android:textColor="@color/white_88_alpha"
+ android:textSize="@dimen/lock_screen_preview_date_text_size"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/lock_time" />
+
+ </androidx.constraintlayout.widget.ConstraintLayout>
+
<View
android:id="@+id/fade_cover"
android:layout_width="match_parent"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 2e3224b..45d73ce 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -234,4 +234,7 @@
<dimen name="option_selected_border_width">3dp</dimen>
<dimen name="option_title_font_text_size">12sp</dimen>
<dimen name="option_title_line_height">16dp</dimen>
+
+ <dimen name="lock_screen_preview_time_text_size">24sp</dimen>
+ <dimen name="lock_screen_preview_date_text_size">12sp</dimen>
</resources>
diff --git a/src/com/android/wallpaper/picker/CategoryFragment.java b/src/com/android/wallpaper/picker/CategoryFragment.java
index 223411a..fbd870b 100755
--- a/src/com/android/wallpaper/picker/CategoryFragment.java
+++ b/src/com/android/wallpaper/picker/CategoryFragment.java
@@ -32,6 +32,7 @@
import android.os.RemoteException;
import android.provider.Settings;
import android.service.wallpaper.WallpaperService;
+import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.SurfaceControlViewHost;
@@ -72,6 +73,7 @@
import com.android.wallpaper.util.PreviewUtils;
import com.android.wallpaper.util.SizeCalculator;
import com.android.wallpaper.util.SurfaceViewUtils;
+import com.android.wallpaper.util.TimeTicker;
import com.android.wallpaper.util.WallpaperConnection;
import com.android.wallpaper.util.WallpaperConnection.WallpaperConnectionListener;
import com.android.wallpaper.widget.LiveTileOverlay;
@@ -82,8 +84,11 @@
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
/**
* Displays the Main UI for picking a category of wallpapers to choose from.
@@ -120,6 +125,10 @@
private static final String PERMISSION_READ_WALLPAPER_INTERNAL =
"android.permission.READ_WALLPAPER_INTERNAL";
+ private static final String TIME_PATTERN = "h:mm";
+ private static final String DEFAULT_DATE_PATTERN = "EEE, MMM d";
+
+ private String mDatePattern;
private ImageView mHomePreview;
private SurfaceView mWorkspaceSurface;
private SurfaceView mWallpaperSurface;
@@ -143,6 +152,9 @@
// the live wallpaper. This view is rendered on mWallpaperSurface for home image wallpaper.
private ImageView mHomeImageWallpaper;
private boolean mIsCollapsingByUserSelecting;
+ private TimeTicker mTicker;
+ private TextView mLockTime;
+ private TextView mLockDate;
public CategoryFragment() {
mCategorySelectorFragment = new CategorySelectorFragment();
@@ -167,6 +179,9 @@
mLockscreenPreview = lockscreenPreviewCard.findViewById(R.id.wallpaper_preview_image);
lockscreenPreviewCard.findViewById(R.id.workspace_surface).setVisibility(View.GONE);
lockscreenPreviewCard.findViewById(R.id.wallpaper_surface).setVisibility(View.GONE);
+ lockscreenPreviewCard.findViewById(R.id.lock_overlay).setVisibility(View.VISIBLE);
+ mLockTime = lockscreenPreviewCard.findViewById(R.id.lock_time);
+ mLockDate = lockscreenPreviewCard.findViewById(R.id.lock_date);
mWallPaperPreviews.add(lockscreenPreviewCard);
mPreviewPager = view.findViewById(R.id.wallpaper_preview_pager);
@@ -263,6 +278,7 @@
mPreviewUtils = new PreviewUtils(getContext(),
getString(R.string.grid_control_metadata_name));
+ mDatePattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), DEFAULT_DATE_PATTERN);
setUpToolbar(view);
@@ -288,6 +304,9 @@
public void onResume() {
super.onResume();
+ mTicker = TimeTicker.registerNewReceiver(getContext(), this::updateDateTime);
+ updateDateTime();
+
WallpaperPreferences preferences = InjectorProvider.getInjector().getPreferences(getActivity());
preferences.setLastAppActiveTimestamp(new Date().getTime());
@@ -311,6 +330,9 @@
if (mWallpaperConnection != null) {
mWallpaperConnection.setVisibility(false);
}
+ if (getContext() != null) {
+ getContext().unregisterReceiver(mTicker);
+ }
}
@Override
@@ -445,6 +467,14 @@
mCategorySelectorFragment.doneFetchingCategories();
}
+ private void updateDateTime() {
+ Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
+ CharSequence time = DateFormat.format(TIME_PATTERN, calendar);
+ CharSequence date = DateFormat.format(mDatePattern, calendar);
+ mLockTime.setText(time);
+ mLockDate.setText(date);
+ }
+
private boolean canShowCurrentWallpaper() {
Activity activity = getActivity();
CategoryFragmentHost host = getFragmentHost();
diff --git a/src/com/android/wallpaper/util/TimeTicker.java b/src/com/android/wallpaper/util/TimeTicker.java
new file mode 100644
index 0000000..38818c2
--- /dev/null
+++ b/src/com/android/wallpaper/util/TimeTicker.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2020 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.wallpaper.util;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+
+import androidx.annotation.Nullable;
+
+/**
+ * BroadcastReceiver that can notify a listener when the system time (minutes) changes.
+ * Use {@link #registerNewReceiver(Context, TimeListener)} to create a new instance that will be
+ * automatically registered using the given Context.
+ */
+public class TimeTicker extends BroadcastReceiver {
+
+ /**
+ * Listener for the system time's change.
+ */
+ public interface TimeListener {
+ /**
+ * Called when the system time (minutes) changes.
+ */
+ void onCurrentTimeChanged();
+ }
+
+ /**
+ * Registers a broadcast receiver for time tick.
+ */
+ public static TimeTicker registerNewReceiver(Context context, @Nullable TimeListener listener) {
+ TimeTicker receiver = new TimeTicker(listener);
+ // Register broadcast receiver for time tick
+ final IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK);
+ context.registerReceiver(receiver, filter);
+ return receiver;
+ }
+
+ private TimeListener mListener;
+
+ private TimeTicker(@Nullable TimeListener listener) {
+ mListener = listener;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (mListener != null) {
+ mListener.onCurrentTimeChanged();
+ }
+ }
+}