From 7267fa58693549894999db17359ce26f8bc7b4a7 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Thu, 26 Sep 2013 15:29:57 -0700 Subject: [PATCH] Make some changes for transparent system bars -Move transparent bars from just GEL to Launcher3 -When wallpaper strip animates, render it under the nav bar -Disable rotation of wallpaper picker on phones Bug: 10814785 Bug: 10852650 Bug: 10852554 Change-Id: I9efeccbc4ad1933689266a5dede201ccfd34acf4 --- res/layout/wallpaper_picker.xml | 8 +-- src/com/android/launcher3/CropView.java | 2 +- src/com/android/launcher3/Launcher.java | 35 +++--------- .../LauncherViewPropertyAnimator.java | 11 +++- .../android/launcher3/TransparentBars.java | 54 +++++++++++++++++++ .../launcher3/WallpaperCropActivity.java | 9 ++++ .../launcher3/WallpaperPickerActivity.java | 32 +++++++---- .../android/launcher3/WallpaperRootView.java | 39 ++++++++++++++ 8 files changed, 146 insertions(+), 44 deletions(-) create mode 100644 src/com/android/launcher3/TransparentBars.java create mode 100644 src/com/android/launcher3/WallpaperRootView.java diff --git a/res/layout/wallpaper_picker.xml b/res/layout/wallpaper_picker.xml index 53c529c2a7..3058a3c57e 100644 --- a/res/layout/wallpaper_picker.xml +++ b/res/layout/wallpaper_picker.xml @@ -18,7 +18,8 @@ */ --> - @@ -41,8 +42,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" - android:orientation="vertical" - android:fitsSystemWindows="true" > + android:orientation="vertical" > - + diff --git a/src/com/android/launcher3/CropView.java b/src/com/android/launcher3/CropView.java index c4d1475c68..f68f739d70 100644 --- a/src/com/android/launcher3/CropView.java +++ b/src/com/android/launcher3/CropView.java @@ -22,8 +22,8 @@ import android.graphics.RectF; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ScaleGestureDetector; -import android.view.ViewConfiguration; import android.view.ScaleGestureDetector.OnScaleGestureListener; +import android.view.ViewConfiguration; import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 7ae429dae1..c131aac470 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -88,7 +88,6 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.view.animation.AccelerateDecelerateInterpolator; -import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.inputmethod.InputMethodManager; import android.widget.Advanceable; @@ -103,12 +102,9 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileDescriptor; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.io.PrintWriter; import java.text.DateFormat; import java.util.ArrayList; @@ -330,6 +326,8 @@ public class Launcher extends Activity private BubbleTextView mWaitingForResume; + protected TransparentBars mTransparentBars; + private HideFromAccessibilityHelper mHideFromAccessibilityHelper = new HideFromAccessibilityHelper(); @@ -344,7 +342,7 @@ public class Launcher extends Activity private static ArrayList sPendingAddList = new ArrayList(); - private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); + public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); private static class PendingAddArguments { int requestCode; @@ -425,6 +423,10 @@ public class Launcher extends Activity checkForLocaleChange(); setContentView(R.layout.launcher); + + mTransparentBars = new TransparentBars(findViewById(R.id.launcher)); + mTransparentBars.requestTransparentBars(true); + setupViews(); grid.layout(this); @@ -2851,8 +2853,6 @@ public class Launcher extends Activity mStateAnimation.play(alphaAnim).after(startDelay); mStateAnimation.addListener(new AnimatorListenerAdapter() { - boolean animationCancelled = false; - @Override public void onAnimationStart(Animator animation) { // Prepare the position @@ -2871,11 +2871,6 @@ public class Launcher extends Activity mSearchDropTargetBar.hideSearchBar(false); } } - - @Override - public void onAnimationCancel(Animator animation) { - animationCancelled = true; - } }); if (workspaceAnim != null) { @@ -3625,22 +3620,6 @@ public class Launcher extends Activity return show; } - private boolean emailSent() { - String spKey = LauncherAppState.getSharedPreferencesKey(); - SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); - boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false); - return show; - } - - private void setEmailSent(boolean sent) { - String spKey = LauncherAppState.getSharedPreferencesKey(); - SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); - - SharedPreferences.Editor editor = sp.edit(); - editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent); - editor.commit(); - } - private void toggleShowWeightWatcher() { String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); diff --git a/src/com/android/launcher3/LauncherViewPropertyAnimator.java b/src/com/android/launcher3/LauncherViewPropertyAnimator.java index 8a9c35dda3..4cafbbfa66 100644 --- a/src/com/android/launcher3/LauncherViewPropertyAnimator.java +++ b/src/com/android/launcher3/LauncherViewPropertyAnimator.java @@ -35,7 +35,8 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi ALPHA, START_DELAY, DURATION, - INTERPOLATOR + INTERPOLATOR, + WITH_LAYER } EnumSet mPropertiesToSet = EnumSet.noneOf(Properties.class); ViewPropertyAnimator mViewPropertyAnimator; @@ -223,6 +224,9 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi if (mPropertiesToSet.contains(Properties.INTERPOLATOR)) { mViewPropertyAnimator.setInterpolator(mInterpolator); } + if (mPropertiesToSet.contains(Properties.WITH_LAYER)) { + mViewPropertyAnimator.withLayer(); + } mViewPropertyAnimator.setListener(this); mViewPropertyAnimator.start(); LauncherAnimUtils.cancelOnDestroyActivity(this); @@ -263,4 +267,9 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi mAlpha = value; return this; } + + public LauncherViewPropertyAnimator withLayer() { + mPropertiesToSet.add(Properties.WITH_LAYER); + return this; + } } diff --git a/src/com/android/launcher3/TransparentBars.java b/src/com/android/launcher3/TransparentBars.java new file mode 100644 index 0000000000..a12da9e6f5 --- /dev/null +++ b/src/com/android/launcher3/TransparentBars.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2013 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.launcher3; + +import android.view.View; + +public class TransparentBars { + private static final int SYSTEM_UI_FLAG_TRANSPARENT_STATUS = 0x00001000; + private static final int SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION = 0x00002000; + + // Behave properly on early K builds. Replace with api check once sdk is baked. + public static final boolean SUPPORTED = !hasSystemUiFlag("ALLOW_TRANSIENT") + && hasSystemUiFlag("TRANSPARENT_STATUS") + && hasSystemUiFlag("TRANSPARENT_NAVIGATION"); + + private final View mTarget; + + public TransparentBars(View target) { + mTarget = target; + } + + public void requestTransparentBars(boolean transparent) { + if (!SUPPORTED) return; + int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; + if (transparent) { + flags |= SYSTEM_UI_FLAG_TRANSPARENT_STATUS | SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION; + } + mTarget.setSystemUiVisibility(flags); + } + + private static boolean hasSystemUiFlag(String name) { + try { + return View.class.getField("SYSTEM_UI_FLAG_" + name) != null; + } catch (NoSuchFieldException e) { + return false; + } + } +} diff --git a/src/com/android/launcher3/WallpaperCropActivity.java b/src/com/android/launcher3/WallpaperCropActivity.java index cdfcd1c00c..343d0ffbff 100644 --- a/src/com/android/launcher3/WallpaperCropActivity.java +++ b/src/com/android/launcher3/WallpaperCropActivity.java @@ -75,6 +75,9 @@ public class WallpaperCropActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); init(); + if (!enableRotation()) { + setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT); + } } protected void init() { @@ -99,6 +102,12 @@ public class WallpaperCropActivity extends Activity { cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone); } }); + TransparentBars transparentBars = new TransparentBars(findViewById(R.id.wallpaper_root)); + transparentBars.requestTransparentBars(true); + } + + public boolean enableRotation() { + return getResources().getBoolean(R.bool.allow_rotation); } public static String getSharedPreferencesKey() { diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java index ef94fe86e9..7f49c86d3b 100644 --- a/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/src/com/android/launcher3/WallpaperPickerActivity.java @@ -77,6 +77,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private OnClickListener mThumbnailOnClickListener; private LinearLayout mWallpapersView; + private View mWallpaperStrip; private ActionMode.Callback mActionModeCallback; private ActionMode mActionMode; @@ -169,12 +170,19 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } + public void setWallpaperStripYOffset(float offset) { + mWallpaperStrip.setPadding(0, 0, 0, (int) offset); + } + // called by onCreate; this is subclassed to overwrite WallpaperCropActivity protected void init() { setContentView(R.layout.wallpaper_picker); + final WallpaperRootView root = (WallpaperRootView) findViewById(R.id.wallpaper_root); + TransparentBars transparentBars = new TransparentBars(root); + transparentBars.requestTransparentBars(true); mCropView = (CropView) findViewById(R.id.cropView); - final View wallpaperStrip = findViewById(R.id.wallpaper_strip); + mWallpaperStrip = findViewById(R.id.wallpaper_strip); mCropView.setTouchCallback(new CropView.TouchCallback() { LauncherViewPropertyAnimator mAnim; @Override @@ -182,11 +190,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { if (mAnim != null) { mAnim.cancel(); } - if (wallpaperStrip.getTranslationY() == 0) { + if (mWallpaperStrip.getTranslationY() == 0) { mIgnoreNextTap = true; } - mAnim = new LauncherViewPropertyAnimator(wallpaperStrip); - mAnim.translationY(wallpaperStrip.getHeight()).alpha(0f) + mAnim = new LauncherViewPropertyAnimator(mWallpaperStrip); + mAnim.translationY(mWallpaperStrip.getHeight()).alpha(0f) .setInterpolator(new DecelerateInterpolator(0.75f)); mAnim.start(); } @@ -202,8 +210,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { if (mAnim != null) { mAnim.cancel(); } - mAnim = new LauncherViewPropertyAnimator(wallpaperStrip); - mAnim.translationY(0).alpha(1f) + mAnim = new LauncherViewPropertyAnimator(mWallpaperStrip); + mAnim.translationY(0f).alpha(1f) .setInterpolator(new DecelerateInterpolator(0.75f)); mAnim.start(); } @@ -401,6 +409,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { }; } + public boolean enableRotation() { + return super.enableRotation() || Launcher.sForceEnableRotation; + } + protected Bitmap getThumbnailOfLastPhoto() { Cursor cursor = MediaStore.Images.Media.query(getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, @@ -419,10 +431,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { protected void onStop() { super.onStop(); - final View wallpaperStrip = findViewById(R.id.wallpaper_strip); - if (wallpaperStrip.getTranslationY() > 0) { - wallpaperStrip.setTranslationY(0); - wallpaperStrip.setAlpha(1f); + mWallpaperStrip = findViewById(R.id.wallpaper_strip); + if (mWallpaperStrip.getTranslationY() > 0f) { + mWallpaperStrip.setTranslationY(0f); + mWallpaperStrip.setAlpha(1f); } } diff --git a/src/com/android/launcher3/WallpaperRootView.java b/src/com/android/launcher3/WallpaperRootView.java new file mode 100644 index 0000000000..ceaa043a78 --- /dev/null +++ b/src/com/android/launcher3/WallpaperRootView.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2013 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.launcher3; + +import android.content.Context; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.widget.RelativeLayout; + +public class WallpaperRootView extends RelativeLayout { + private final WallpaperPickerActivity a; + public WallpaperRootView(Context context, AttributeSet attrs) { + super(context, attrs); + a = (WallpaperPickerActivity) context; + } + public WallpaperRootView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + a = (WallpaperPickerActivity) context; + } + + protected boolean fitSystemWindows(Rect insets) { + a.setWallpaperStripYOffset(insets.bottom); + return true; + } +}