forked from arco/android_device_htc_buzz
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normally the wallpaper is drawn by the system in a separate window. This means that the wallpaper can often be drawn out of sync with the launcher. This hack gets the wallpaper bitmap and draws it manually (in sync with the rest of the launcher). This increases performance greatly. This is a port from the cm-10.1 branch http://review.cyanogenmod.org/#/c/27326/3
- Loading branch information
Showing
2 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
#!/bin/sh | ||
echo "removing old patches..." | ||
rm ../../../../packages/apps/Trebuchet/*.patch | ||
|
||
echo | ||
echo "Copying files..." | ||
cp packages_apps_Trebuchet* ../../../../packages/apps/Trebuchet/ | ||
echo | ||
|
||
echo "cd packages/apps/Trebuchet" | ||
cd ../../../../packages/apps/Trebuchet/ | ||
echo "apply patch" | ||
git am *.patch | ||
echo | ||
|
||
cd ../../../ |
307 changes: 307 additions & 0 deletions
307
patches/packages_apps_Trebuchet_0001-Trebuchet-port-wallpaper-hack.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,307 @@ | ||
From 500ee5e5918f337385b37ca4314f4a264a524087 Mon Sep 17 00:00:00 2001 | ||
From: Erwin Pannecoucke <erwin.pannecoucke@gmail.com> | ||
Date: Sat, 29 Dec 2012 12:20:24 +0100 | ||
Subject: [PATCH] Trebuchet: port wallpaper hack | ||
|
||
Normally the wallpaper is drawn by the system in a separate window. | ||
This means that the wallpaper can often be drawn out of sync with | ||
the launcher. This hack gets the wallpaper bitmap and draws it | ||
manually (in sync with the rest of the launcher). This increases | ||
performance greatly. | ||
|
||
This is a port from the cm-10.1 branch | ||
http://review.cyanogenmod.org/#/c/27326/3 | ||
|
||
Change-Id: I10d8586b011f205b36c8604f993256cb23045663 | ||
--- | ||
res/layout-port/launcher.xml | 26 ++++--- | ||
res/values/strings.xml | 2 + | ||
res/xml/preferences.xml | 4 ++ | ||
src/com/cyanogenmod/trebuchet/Launcher.java | 12 +++- | ||
src/com/cyanogenmod/trebuchet/Workspace.java | 75 ++++++++++++++++++-- | ||
.../trebuchet/preference/PreferencesProvider.java | 4 ++ | ||
6 files changed, 102 insertions(+), 21 deletions(-) | ||
|
||
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml | ||
index fd3a843..80cc763 100644 | ||
--- a/res/layout-port/launcher.xml | ||
+++ b/res/layout-port/launcher.xml | ||
@@ -22,9 +22,18 @@ | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
- <!-- Keep these behind the workspace so that they are not visible when | ||
- we go into AllApps --> | ||
- <include | ||
+ <!-- The workspace contains 5 screens of cells --> | ||
+ <com.cyanogenmod.trebuchet.Workspace | ||
+ android:id="@+id/workspace" | ||
+ android:layout_width="match_parent" | ||
+ android:layout_height="match_parent" | ||
+ android:paddingTop="@dimen/qsb_bar_height_inset" | ||
+ android:paddingBottom="@dimen/button_bar_height" | ||
+ launcher:pageSpacing="@dimen/workspace_page_spacing" | ||
+ launcher:scrollIndicatorPaddingLeft="@dimen/workspace_divider_padding_left" | ||
+ launcher:scrollIndicatorPaddingRight="@dimen/workspace_divider_padding_right" /> | ||
+ | ||
+ <include | ||
android:id="@+id/dock_divider" | ||
layout="@layout/workspace_divider" | ||
android:layout_width="match_parent" | ||
@@ -39,17 +48,6 @@ | ||
android:layout_gravity="bottom" | ||
android:layout_marginBottom="@dimen/button_bar_height" /> | ||
|
||
- <!-- The workspace contains 5 screens of cells --> | ||
- <com.cyanogenmod.trebuchet.Workspace | ||
- android:id="@+id/workspace" | ||
- android:layout_width="match_parent" | ||
- android:layout_height="match_parent" | ||
- android:paddingTop="@dimen/qsb_bar_height_inset" | ||
- android:paddingBottom="@dimen/button_bar_height" | ||
- launcher:pageSpacing="@dimen/workspace_page_spacing" | ||
- launcher:scrollIndicatorPaddingLeft="@dimen/workspace_divider_padding_left" | ||
- launcher:scrollIndicatorPaddingRight="@dimen/workspace_divider_padding_right" /> | ||
- | ||
<include layout="@layout/hotseat" | ||
android:id="@+id/hotseat" | ||
android:layout_width="match_parent" | ||
diff --git a/res/values/strings.xml b/res/values/strings.xml | ||
index 64feba6..2c23691 100644 | ||
--- a/res/values/strings.xml | ||
+++ b/res/values/strings.xml | ||
@@ -312,6 +312,8 @@ s --> | ||
<string name="preferences_interface_homescreen_scrolling_fade_adjacent_screens_summary">Fade the side pages when scrolling homescreens</string> | ||
<string name="preferences_interface_homescreen_scrolling_scroll_wallpaper_title">Scroll wallpaper</string> | ||
<string name="preferences_interface_homescreen_scrolling_scroll_wallpaper_summary">Scroll wallpaper when scrolling homescreens</string> | ||
+<string name="preferences_interface_homescreen_scrolling_wallpaper_hack_title">Wallpaper quick render</string> | ||
+ <string name="preferences_interface_homescreen_scrolling_wallpaper_hack_summary">Use wallpaper hack that increases smoothness on static image wallpapers</string> | ||
<string name="preferences_interface_homescreen_indicator_category">Indicator</string> | ||
<string name="preferences_interface_homescreen_indicator_enable_title">Show page indicator</string> | ||
<string name="preferences_interface_homescreen_indicator_enable_summary">Show current page indicator at the bottom of the screen</string> | ||
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml | ||
index 1bbc9ac..0351d47 100644 | ||
--- a/res/xml/preferences.xml | ||
+++ b/res/xml/preferences.xml | ||
@@ -84,6 +84,10 @@ | ||
android:title="@string/preferences_interface_homescreen_scrolling_scroll_wallpaper_title" | ||
android:summary="@string/preferences_interface_homescreen_scrolling_scroll_wallpaper_summary" | ||
android:defaultValue="true" /> | ||
+ <CheckBoxPreference android:key="ui_homescreen_scrolling_wallpaper_hack" | ||
+ android:title="@string/preferences_interface_homescreen_scrolling_wallpaper_hack_title" | ||
+ android:summary="@string/preferences_interface_homescreen_scrolling_wallpaper_hack_summary" | ||
+ android:defaultValue="true" /> | ||
</PreferenceCategory> | ||
<PreferenceCategory android:key="ui_homescreen_indicator" | ||
android:title="@string/preferences_interface_homescreen_indicator_category"> | ||
diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java | ||
index 9283243..50e4260 100644 | ||
--- a/src/com/cyanogenmod/trebuchet/Launcher.java | ||
+++ b/src/com/cyanogenmod/trebuchet/Launcher.java | ||
@@ -263,6 +263,8 @@ public final class Launcher extends Activity | ||
private boolean mHideIconLabels; | ||
private boolean mAutoRotate; | ||
|
||
+ private boolean mWallpaperVisible; | ||
+ | ||
private Runnable mBuildLayersRunnable = new Runnable() { | ||
public void run() { | ||
if (mWorkspace != null) { | ||
@@ -1093,6 +1095,8 @@ public final class Launcher extends Activity | ||
} else if (Intent.ACTION_USER_PRESENT.equals(action)) { | ||
mUserPresent = true; | ||
updateRunning(); | ||
+ } else if (Intent.ACTION_SET_WALLPAPER.equals(action)) { | ||
+ mWorkspace.checkWallpaper(); | ||
} | ||
} | ||
}; | ||
@@ -1105,6 +1109,7 @@ public final class Launcher extends Activity | ||
final IntentFilter filter = new IntentFilter(); | ||
filter.addAction(Intent.ACTION_SCREEN_OFF); | ||
filter.addAction(Intent.ACTION_USER_PRESENT); | ||
+ filter.addAction(Intent.ACTION_SET_WALLPAPER); | ||
registerReceiver(mReceiver, filter); | ||
|
||
mAttached = true; | ||
@@ -2282,8 +2287,13 @@ public final class Launcher extends Activity | ||
view.setPivotY(view.getHeight() / 2.0f); | ||
} | ||
|
||
+ void setWallpaperVisibility(boolean visible) { | ||
+ mWallpaperVisible = visible; | ||
+ updateWallpaperVisibility(visible); | ||
+ } | ||
+ | ||
void updateWallpaperVisibility(boolean visible) { | ||
- int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; | ||
+ int wpflags = visible && mWallpaperVisible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; | ||
int curflags = getWindow().getAttributes().flags | ||
& WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; | ||
if (wpflags != curflags) { | ||
diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java | ||
index 5a03a2f..e7763e7 100644 | ||
--- a/src/com/cyanogenmod/trebuchet/Workspace.java | ||
+++ b/src/com/cyanogenmod/trebuchet/Workspace.java | ||
@@ -49,6 +49,7 @@ import android.graphics.PorterDuff; | ||
import android.graphics.Rect; | ||
import android.graphics.RectF; | ||
import android.graphics.Region.Op; | ||
+import android.graphics.drawable.BitmapDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.os.IBinder; | ||
import android.os.Parcelable; | ||
@@ -118,8 +119,14 @@ public class Workspace extends PagedView | ||
private float mWallpaperScrollRatio = 1.0f; | ||
|
||
private final WallpaperManager mWallpaperManager; | ||
+ private boolean mWallpaperHack; | ||
+ private Bitmap mWallpaperBitmap; | ||
+ private float mWallpaperScrollX; | ||
+ private float mWallpaperScrollY; | ||
+ private int[] mWallpaperOffsets = new int[2]; | ||
+ private Paint mPaint = new Paint(); | ||
private IBinder mWindowToken; | ||
- private static final float WALLPAPER_SCREENS_SPAN = 2f; | ||
+ private static final float DEFAULT_WALLPAPER_SCREENS_SPAN = 2f; | ||
|
||
/** | ||
* CellInfo for the cell that is currently being dragged | ||
@@ -343,12 +350,14 @@ public class Workspace extends PagedView | ||
res.getString(R.string.config_workspaceDefaultTransitionEffect)); | ||
mFadeInAdjacentScreens = PreferencesProvider.Interface.Homescreen.Scrolling.getFadeInAdjacentScreens(context, | ||
res.getBoolean(R.bool.config_workspaceDefualtFadeInAdjacentScreens)); | ||
+ mWallpaperHack = PreferencesProvider.Interface.Homescreen.Scrolling.getWallpaperHack(context); | ||
mShowScrollingIndicator = PreferencesProvider.Interface.Homescreen.Indicator.getShowScrollingIndicator(context); | ||
mFadeScrollingIndicator = PreferencesProvider.Interface.Homescreen.Indicator.getFadeScrollingIndicator(context); | ||
mShowDockDivider = PreferencesProvider.Interface.Homescreen.Indicator.getShowDockDivider(context); | ||
|
||
mLauncher = (Launcher) context; | ||
initWorkspace(); | ||
+ checkWallpaper(); | ||
|
||
// Disable multitouch across the workspace/all apps/customize tray | ||
setMotionEventSplittingEnabled(true); | ||
@@ -519,6 +528,21 @@ public class Workspace extends PagedView | ||
} | ||
} | ||
|
||
+ protected void checkWallpaper() { | ||
+ if (mWallpaperHack) { | ||
+ if (mWallpaperBitmap != null) { | ||
+ mWallpaperBitmap = null; | ||
+ } | ||
+ if (mWallpaperManager.getWallpaperInfo() == null) { | ||
+ Drawable wallpaper = mWallpaperManager.getDrawable(); | ||
+ if (wallpaper instanceof BitmapDrawable) { | ||
+ mWallpaperBitmap = ((BitmapDrawable) wallpaper).getBitmap(); | ||
+ } | ||
+ } | ||
+ } | ||
+ mLauncher.setWallpaperVisibility(mWallpaperBitmap == null); | ||
+ } | ||
+ | ||
@Override | ||
protected void onViewAdded(View child) { | ||
super.onViewAdded(child); | ||
@@ -887,7 +911,7 @@ public class Workspace extends PagedView | ||
mWallpaperWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim)); | ||
mWallpaperHeight = maxDim; | ||
} else { | ||
- mWallpaperWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim); | ||
+ mWallpaperWidth = Math.max((int) (minDim * DEFAULT_WALLPAPER_SCREENS_SPAN), maxDim); | ||
mWallpaperHeight = maxDim; | ||
} | ||
new Thread("setWallpaperDimension") { | ||
@@ -948,9 +972,13 @@ public class Workspace extends PagedView | ||
} | ||
|
||
private void centerWallpaperOffset() { | ||
- mWallpaperManager.setWallpaperOffsetSteps(0.5f, 0); | ||
- mWallpaperManager.setWallpaperOffsets(getWindowToken(), 0.5f, 0); | ||
- } | ||
+ if (mWallpaperHack) { | ||
+ mWallpaperScrollX = 0.5f; | ||
+ } else if (mWindowToken != null) { | ||
+ mWallpaperManager.setWallpaperOffsetSteps(0.5f, 0); | ||
+ mWallpaperManager.setWallpaperOffsets(getWindowToken(), 0.5f, 0); | ||
+ } | ||
+ } | ||
|
||
public void updateWallpaperOffsetImmediately() { | ||
mUpdateWallpaperOffsetImmediately = true; | ||
@@ -968,7 +996,10 @@ public class Workspace extends PagedView | ||
updateNow = keepUpdating = mWallpaperOffset.computeScrollOffset(); | ||
} | ||
if (updateNow) { | ||
- if (mWindowToken != null) { | ||
+ if (mWallpaperHack) { | ||
+ mWallpaperScrollX = mWallpaperOffset.getCurrX(); | ||
+ mWallpaperScrollY = mWallpaperOffset.getCurrY(); | ||
+ } else if (mWindowToken != null) { | ||
mWallpaperManager.setWallpaperOffsets(mWindowToken, | ||
mWallpaperOffset.getCurrX(), mWallpaperOffset.getCurrY()); | ||
} | ||
@@ -1549,12 +1580,44 @@ public class Workspace extends PagedView | ||
} | ||
} | ||
|
||
+ protected void onSizeChanged (int w, int h, int oldw, int oldh) { | ||
+ super.onSizeChanged(w, h, oldw, oldh); | ||
+ | ||
+ getLocationOnScreen(mWallpaperOffsets); 1429 | ||
+ } | ||
+ | ||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
if (mScrollWallpaper) { | ||
updateWallpaperOffsets(); | ||
} | ||
|
||
+ // Draw the wallpaper if necessary | ||
+ if (mWallpaperHack && mWallpaperBitmap != null) { | ||
+ float x = getScrollX(); | ||
+ float y = getScrollY(); | ||
+ | ||
+ int width = getWidth(); | ||
+ int height = getHeight(); | ||
+ int wallpaperWidth = mWallpaperBitmap.getWidth(); | ||
+ int wallpaperHeight = mWallpaperBitmap.getHeight(); | ||
+ | ||
+ if (width + mWallpaperOffsets[0] > wallpaperWidth) { | ||
+ // Wallpaper is smaller than screen | ||
+ x += (width - wallpaperWidth) / 2; | ||
+ } else { | ||
+ x -= mWallpaperScrollX * (wallpaperWidth - width) + mWallpaperOffsets[0]; | ||
+ } | ||
+ if (height + mWallpaperOffsets[1] > wallpaperHeight) { | ||
+ // Wallpaper is smaller than screen | ||
+ y += (height - wallpaperHeight) / 2; | ||
+ } else { | ||
+ y -= mWallpaperScrollY * (wallpaperHeight - height) + mWallpaperOffsets[1]; | ||
+ } | ||
+ | ||
+ canvas.drawBitmap(mWallpaperBitmap, x, y, mPaint); | ||
+ } | ||
+ | ||
// Draw the background gradient if necessary | ||
if (mBackground != null && mBackgroundAlpha > 0.0f && mDrawBackground) { | ||
int alpha = (int) (mBackgroundAlpha * 255); | ||
diff --git a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java | ||
index 2b68ffd..61f05bd 100644 | ||
--- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java | ||
+++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java | ||
@@ -83,6 +83,10 @@ public final class PreferencesProvider { | ||
final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); | ||
return preferences.getBoolean("ui_homescreen_scrolling_scroll_wallpaper", true); | ||
} | ||
+ public static boolean getWallpaperHack(Context context) { | ||
+ final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); | ||
+ return preferences.getBoolean("ui_homescreen_scrolling_wallpaper_hack", true); | ||
+ } | ||
public static Workspace.TransitionEffect getTransitionEffect(Context context, String def) { | ||
final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); | ||
return Workspace.TransitionEffect.valueOf( | ||
-- | ||
1.7.9.5 | ||
|