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
This commit is contained in:
Michael Jurka 2013-09-26 15:29:57 -07:00
parent e269ca4298
commit 7267fa5869
8 changed files with 146 additions and 44 deletions

View File

@ -18,7 +18,8 @@
*/
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.launcher3.WallpaperRootView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wallpaper_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -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" >
<View
android:layout_width="match_parent"
android:layout_height="2dp"
@ -73,4 +73,4 @@
android:layout_height="2dp"
android:background="@drawable/tile_shadow_bottom" />
</LinearLayout>
</RelativeLayout>
</com.android.launcher3.WallpaperRootView>

View File

@ -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;

View File

@ -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<PendingAddArguments> sPendingAddList
= new ArrayList<PendingAddArguments>();
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);

View File

@ -35,7 +35,8 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi
ALPHA,
START_DELAY,
DURATION,
INTERPOLATOR
INTERPOLATOR,
WITH_LAYER
}
EnumSet<Properties> 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;
}
}

View File

@ -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;
}
}
}

View File

@ -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() {

View File

@ -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);
}
}

View File

@ -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;
}
}