OSDN Git Service

Add Camera cover equivalent to windowBackground to smooth lockscreen startup
authorAlan Newberger <alann@google.com>
Wed, 14 Jan 2015 22:10:05 +0000 (14:10 -0800)
committerAlan Newberger <alann@google.com>
Fri, 16 Jan 2015 17:44:37 +0000 (09:44 -0800)
This CL adds a windowBackground drawable equivalent to the covers shown by lockscreen
and app, to remove the black screen in between. With this CL I mostly see no artifacts
when opening camera from lockscreen. Some issues:

* to improve memory usage in system UI holding the lockscreen preview, a vector
  camera blanket was added in ag/587418 to ic_camera_blanket. That works transparently
  everywhere so far but not in resource drawables that can only handle bitmaps in
  layer-list items. Split the vector and bitmaps here, which means only the lockscreen
  uses the vector -- this also surfaced a color mismatch between the vector and our PNG
  bitmaps, corrected in the new ic_camera_blanket_vector resource. This is a bit fragile
  as we rely on pixel match of the two resources, would like a cleaner solution but the
  layer-list limitation is tough -- without this change the app crashes at runtime within
  BitmapDrawable when the windowBackground is loaded.

* likewise both the lockscreen and app covers explicitly size the bitmap, there are no
  provisions to do so within layer-list. Will follow up with a refactor of in-app cover
  (ModeTransitionView) to remove explicit sizing and then all will rely on bitmap size
  (per above will still need vector file size coordinated with bitmap).

* current implementation relies upon a black window background, we restore that in onCreate.

* Both secure camera and v21 main camera currently use the windowBackground, will submit
  just for secure then introduce for main camera when we always start into Camera mode.

* For L explicitly set android:windowDrawsSystemBarBackgrounds to false to ensure the
  system preview into the DecorView doesn't take the navigation bar into account when
  vertically centering the cover bitmap, to make the preview identical to the other covers.

Bug: 18369862

Change-Id: Ia481e2d1d94bdc5a5d39b4d35b32c29a75bf99ec

AndroidManifest.xml
res/drawable-anydpi-v21/ic_camera_blanket_vector.xml [moved from res/drawable-anydpi-v21/ic_camera_blanket.xml with 94% similarity]
res/drawable/cover.xml [new file with mode: 0644]
res/layout-v21/keyguard_widget.xml [new file with mode: 0644]
res/values-v21/styles.xml
res/values/styles.xml
src/com/android/camera/CameraActivity.java

index 8d0c759..076863d 100644 (file)
             android:excludeFromRecents="true"
             android:label="@string/app_name"
             android:taskAffinity="com.android.camera.SecureCameraActivity"
-            android:theme="@style/Theme.Camera"
+            android:theme="@style/Theme.SecureCamera"
             android:windowSoftInputMode="stateAlwaysHidden|adjustPan" >
             <intent-filter>
                 <action android:name="android.media.action.STILL_IMAGE_CAMERA_SECURE" />
@@ -19,9 +19,9 @@ Copyright (C) 2014 The Android Open Source Project
         android:viewportWidth="48.0"
         android:viewportHeight="48.0">
     <path
-        android:fillColor="#FF5a5b5e"
+        android:fillColor="#FF6d6e71"
         android:pathData="M24.0,24.0m-6.4,0.0a6.4,6.4 0.0,1.0 1.0,12.8 0.0a6.4,6.4 0.0,1.0 1.0,-12.8 0.0"/>
     <path
-        android:fillColor="#FF5a5b5e"
+        android:fillColor="#FF6d6e71"
         android:pathData="M18.0,4.0l-3.66,4.0l-6.34,0.0c-2.21,0.0 -4.0,1.79 -4.0,4.0l0.0,24.0c0.0,2.21 1.79,4.0 4.0,4.0l32.0,0.0c2.21,0.0 4.0,-1.79 4.0,-4.0l0.0,-24.0c0.0,-2.21 -1.79,-4.0 -4.0,-4.0l-6.34,0.0l-3.66,-4.0l-12.0,0.0zm6.0,30.0c-5.52,0.0 -10.0,-4.48 -10.0,-10.0s4.48,-10.0 10.0,-10.0 10.0,4.48 10.0,10.0 -4.48,10.0 -10.0,10.0z"/>
 </vector>
diff --git a/res/drawable/cover.xml b/res/drawable/cover.xml
new file mode 100644 (file)
index 0000000..f340b28
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
+    <item>
+        <color android:color="@color/mode_cover_default_color"/>
+    </item>
+    <item>
+        <bitmap android:src="@drawable/ic_camera_blanket" android:gravity="center" />
+    </item>
+</layer-list>
diff --git a/res/layout-v21/keyguard_widget.xml b/res/layout-v21/keyguard_widget.xml
new file mode 100644 (file)
index 0000000..74f482d
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/mode_cover_default_color" >
+
+    <ImageView
+        android:layout_gravity="center"
+        android:layout_width="@dimen/mode_transition_view_icon_size"
+        android:layout_height="@dimen/mode_transition_view_icon_size"
+        android:scaleType="fitCenter"
+        android:src="@drawable/ic_camera_blanket_vector" />
+
+</FrameLayout>
index dd385ae..fe1e6a4 100644 (file)
@@ -14,7 +14,7 @@
      limitations under the License.
 -->
 
-<resources>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
     <!-- Camera resources below -->
 
     <style name="Theme.Camera" parent="android:style/Theme.Material.Light.DarkActionBar">
         <item name="android:windowActionBar">false</item>
         <item name="android:windowTitleSize">0dp</item>
         <item name="android:windowActionBarOverlay">true</item>
-        <item name="android:windowBackground">@android:color/black</item>
-        <item name="android:colorBackground">@android:color/black</item>
-        <item name="android:colorBackgroundCacheHint">@android:color/black</item>
+        <!-- for background layout, don't draw background under system bar,
+             reactivate within CameraActivity.onCreate(). -->
+        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
+        <!-- TODO: add background as @drawable/cover after Camera mode cold
+                   start default per b/17702056 -->
+        <item name="android:windowBackground">@color/mode_cover_default_color</item>
+        <item name="android:colorBackground">@color/mode_cover_default_color</item>
+        <item name="android:colorBackgroundCacheHint">@color/mode_cover_default_color</item>
         <item name="android:actionBarStyle">@style/Camera.ActionBar</item>
     </style>
 
index 7c0f7ca..bc849ec 100644 (file)
         <item name="android:windowActionBar">false</item>
         <item name="android:windowTitleSize">0dp</item>
         <item name="android:windowActionBarOverlay">true</item>
-        <item name="android:windowBackground">@android:color/black</item>
-        <item name="android:colorBackground">@android:color/black</item>
-        <item name="android:colorBackgroundCacheHint">@android:color/black</item>
+        <item name="android:windowBackground">@color/mode_cover_default_color</item>
+        <item name="android:colorBackground">@color/mode_cover_default_color</item>
+        <item name="android:colorBackgroundCacheHint">@color/mode_cover_default_color</item>
         <item name="android:actionBarStyle">@style/Camera.ActionBar</item>
     </style>
 
+    <style name="Theme.SecureCamera" parent="@style/Theme.Camera">
+        <item name="android:windowBackground">@drawable/cover</item>
+    </style>
+
     <style name="Camera.ActionBar" parent="android:Widget.Holo.Light.ActionBar">
         <item name="android:displayOptions">useLogo|showHome|homeAsUp</item>
         <item name="android:background">@drawable/actionbar_translucent</item>
index c12503d..70fd52d 100644 (file)
@@ -1433,6 +1433,15 @@ public class CameraActivity extends QuickActivity
         Keys.setDefaults(mSettingsManager, mAppContext);
 
         getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
+        // We suppress this flag via theme when drawing the system preview
+        // background, but once we create activity here, reactivate to the
+        // default value. The default is important for L, we don't want to
+        // change app behavior, just starting background drawable layout.
+        if (ApiHelper.isLOrHigher()) {
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+        }
+        // We set a background drawable for startup background, reset to black
+        getWindow().setBackgroundDrawableResource(android.R.color.black);
         setContentView(R.layout.activity_main);
 
         mActionBar = getActionBar();