Skip to content

Commit

Permalink
Improved Settings management
Browse files Browse the repository at this point in the history
  • Loading branch information
nyancrimew committed Jun 14, 2017
1 parent 1dec195 commit e4ddd02
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/ch/deletescape/lawnchair/BubbleTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
defaultIconSize = grid.allAppsIconSizePx;
if (Utilities.getPrefs(getContext()).getFloat("pref_allAppsOpacitySB", 1f) < .5f) {
setTextColor(Utilities.getColor(getContext(), ExtractedColors.DOMINANT_FOREGROUND_INDEX, Color.WHITE));
setTextColor(Utilities.getColor(getContext(), ExtractedColors.VIBRANT_FOREGROUND_INDEX, Color.WHITE));
}
} else if (display == DISPLAY_FOLDER) {
setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
Expand Down
3 changes: 1 addition & 2 deletions src/ch/deletescape/lawnchair/Hotseat.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
Expand Down Expand Up @@ -115,7 +114,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
}

public void updateColor(ExtractedColors extractedColors, boolean animate) {
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
int color = extractedColors.getHotseatColor(getContext());
if (mBackgroundColorAnimator != null) {
mBackgroundColorAnimator.cancel();
}
Expand Down
11 changes: 11 additions & 0 deletions src/ch/deletescape/lawnchair/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import ch.deletescape.lawnchair.folder.FolderIcon;
import ch.deletescape.lawnchair.keyboard.ViewGroupFocusHelper;
import ch.deletescape.lawnchair.model.WidgetsModel;
import ch.deletescape.lawnchair.settings.Settings;
import ch.deletescape.lawnchair.shortcuts.DeepShortcutManager;
import ch.deletescape.lawnchair.shortcuts.DeepShortcutsContainer;
import ch.deletescape.lawnchair.shortcuts.ShortcutKey;
Expand Down Expand Up @@ -391,6 +392,8 @@ protected void onCreate(Bundle savedInstanceState) {
registerReceiver(mUiBroadcastReceiver, filter);

mLauncherTab = new LauncherTab(this);

Settings.init(this);
}

@Override
Expand All @@ -407,6 +410,14 @@ private void loadExtractedColorsAndColorItems() {
activateLightStatusBar(isAllAppsVisible());
}

public ExtractedColors getExtractedColors() {
return mExtractedColors;
}

public AllAppsTransitionController getAllAppsController() {
return mAllAppsController;
}

/**
* Sets the status bar to be light or not. Light status bar means dark icons.
*
Expand Down
5 changes: 5 additions & 0 deletions src/ch/deletescape/lawnchair/LauncherAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public void reloadWorkspace() {
mModel.startLoaderFromBackground();
}

public void reloadAllApps() {
mModel.resetLoadedState(true, false);
mModel.startLoaderFromBackground();
}

public void reloadAll(boolean showWorkspace) {
mModel.resetLoadedState(true, true);
mModel.startLoaderFromBackground();
Expand Down
2 changes: 1 addition & 1 deletion src/ch/deletescape/lawnchair/LauncherModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ public void run() {
runOnMainThread(r);
}

private void loadAllApps() {
public void loadAllApps() {

final Callbacks oldCallbacks = mCallbacks.get();
if (oldCallbacks == null) {
Expand Down
4 changes: 0 additions & 4 deletions src/ch/deletescape/lawnchair/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
@Override
public void onDestroy() {
super.onDestroy();
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
if (app != null) {
app.reloadAll(true);
}
}
}
}
34 changes: 21 additions & 13 deletions src/ch/deletescape/lawnchair/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,24 @@ public void bindAndInitFirstWorkspaceScreen(View qsb) {

// Add the first page
CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, 0);
initPullDownToSearch();
// Always add a QSB on the first screen.
if (qsb == null) {
// In transposed layout, we add the QSB in the Grid. As workspace does not touch the
// edges, we do not need a full width QSB.
qsb = mLauncher.getLayoutInflater().inflate(R.layout.qsb_blocker_view,
firstPage, false);
}

CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
lp.canReorder = false;
if (!firstPage.addViewToCellLayout(qsb, 0, getEmbeddedQsbId(), lp, FeatureFlags.showPixelBar(getContext()))) {
Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
}
}

public void initPullDownToSearch() {
CellLayout firstPage = mWorkspaceScreens.get(FIRST_SCREEN_ID);
if (FeatureFlags.pulldownSearch(getContext().getApplicationContext())) {
firstPage.setOnTouchListener(new VerticalFlingDetector(mLauncher) {
// detect fling when touch started from empty space
Expand All @@ -597,19 +615,9 @@ public boolean onTouch(View v, MotionEvent ev) {
return false;
}
});
}
// Always add a QSB on the first screen.
if (qsb == null) {
// In transposed layout, we add the QSB in the Grid. As workspace does not touch the
// edges, we do not need a full width QSB.
qsb = mLauncher.getLayoutInflater().inflate(R.layout.qsb_blocker_view,
firstPage, false);
}

CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
lp.canReorder = false;
if (!firstPage.addViewToCellLayout(qsb, 0, getEmbeddedQsbId(), lp, FeatureFlags.showPixelBar(getContext()))) {
Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
} else {
firstPage.setOnTouchListener(null);
firstPage.setOnInterceptTouchListener(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import ch.deletescape.lawnchair.LauncherAppWidgetHostView;
import ch.deletescape.lawnchair.R;
import ch.deletescape.lawnchair.ShortcutAndWidgetContainer;
import ch.deletescape.lawnchair.Utilities;
import ch.deletescape.lawnchair.Workspace;
import ch.deletescape.lawnchair.util.TouchController;

Expand Down Expand Up @@ -90,6 +89,8 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
private boolean mIsTranslateWithoutWorkspace = false;
private AnimatorSet mDiscoBounceAnimation;

private int allAppsAlpha;

public AllAppsTransitionController(Launcher l) {
mLauncher = l;
mDetector = new VerticalPullDetector(l);
Expand All @@ -100,6 +101,10 @@ public AllAppsTransitionController(Launcher l) {
mAllAppsBackgroundColor = ContextCompat.getColor(l, R.color.all_apps_container_color);
}

public void setAllAppsAlpha(int allAppsAlpha) {
this.allAppsAlpha = allAppsAlpha;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
Expand Down Expand Up @@ -269,8 +274,7 @@ public void setProgress(float progress) {
float alpha = 1f - progress;
float interpolation = mAccelInterpolator.getInterpolation(progress);

int tmpAlpha = (int) (Utilities.getPrefs(mLauncher.getApplicationContext()).getFloat("pref_allAppsOpacitySB", 1f) * 255);
int allAppsBg = ColorUtils.setAlphaComponent(mAllAppsBackgroundColor, tmpAlpha);
int allAppsBg = ColorUtils.setAlphaComponent(mAllAppsBackgroundColor, allAppsAlpha);
int color = (int) mEvaluator.evaluate(mDecelInterpolator.getInterpolation(alpha), mHotseatBackgroundColor, allAppsBg);

mAppsView.setRevealDrawableColor(color);
Expand Down
6 changes: 6 additions & 0 deletions src/ch/deletescape/lawnchair/dragndrop/DragLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class DragLayer extends InsettableFrameLayout {
private AllAppsTransitionController mAllAppsController;

private TouchController mActiveController;
public boolean mIsAccesibilityEnabled;

/**
* Used to create a new DragLayer from XML.
Expand Down Expand Up @@ -179,6 +180,7 @@ public boolean dispatchKeyEvent(KeyEvent event) {
}

public void onAccessibilityStateChanged(boolean isAccessibilityEnabled) {
mIsAccesibilityEnabled = isAccessibilityEnabled;
mPinchListener = !FeatureFlags.pinchToOverview(getContext().getApplicationContext()) || isAccessibilityEnabled
? null : new PinchToOverviewListener(mLauncher);
}
Expand Down Expand Up @@ -627,6 +629,7 @@ public int getY() {
}
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
int count = getChildCount();
Expand Down Expand Up @@ -739,6 +742,7 @@ public void animateViewIntoPosition(DragView dragView, final View child, int dur
final int fromY = r.top;
child.setVisibility(INVISIBLE);
Runnable onCompleteRunnable = new Runnable() {
@Override
public void run() {
child.setVisibility(VISIBLE);
if (onFinishAnimationRunnable != null) {
Expand Down Expand Up @@ -881,6 +885,7 @@ public void animateView(final DragView view, AnimatorUpdateListener updateCb, in
mDropAnim.setFloatValues(0f, 1f);
mDropAnim.addUpdateListener(updateCb);
mDropAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (onCompleteRunnable != null) {
onCompleteRunnable.run();
Expand Down Expand Up @@ -1043,6 +1048,7 @@ private void drawPageHints(Canvas canvas) {
}
}

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean ret = super.drawChild(canvas, child, drawingTime);

Expand Down
21 changes: 9 additions & 12 deletions src/ch/deletescape/lawnchair/dynamicui/ColorExtractionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import ch.deletescape.lawnchair.LauncherProvider;
import ch.deletescape.lawnchair.LauncherSettings;
import ch.deletescape.lawnchair.R;
import ch.deletescape.lawnchair.config.FeatureFlags;

/**
* Extracts colors from the wallpaper, and saves results to {@link LauncherProvider}.
Expand All @@ -51,7 +50,7 @@ protected void onHandleIntent(Intent intent) {
if (wallpaperManager.getWallpaperInfo() != null) {
// We can't extract colors from live wallpapers, so just use the default color always.
extractedColors.updatePalette(null);
extractedColors.updateHotseatPalette(getApplicationContext(), null);
extractedColors.updateHotseatPalette(null);
} else {
Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
Palette palette = Palette.from(wallpaper).generate();
Expand All @@ -63,17 +62,15 @@ protected void onHandleIntent(Intent intent) {
wallpaper.getWidth(), wallpaper.getHeight())
.clearFilters()
.generate();
extractedColors.updateHotseatPalette(getApplicationContext(), hotseatPalette);
extractedColors.updateHotseatPalette(hotseatPalette);

if (FeatureFlags.lightStatusBar(getApplicationContext())) {
int statusBarHeight = getResources()
.getDimensionPixelSize(R.dimen.status_bar_height);
Palette statusBarPalette = Palette.from(wallpaper)
.setRegion(0, 0, wallpaper.getWidth(), statusBarHeight)
.clearFilters()
.generate();
extractedColors.updateStatusBarPalette(statusBarPalette);
}
int statusBarHeight = getResources()
.getDimensionPixelSize(R.dimen.status_bar_height);
Palette statusBarPalette = Palette.from(wallpaper)
.setRegion(0, 0, wallpaper.getWidth(), statusBarHeight)
.clearFilters()
.generate();
extractedColors.updateStatusBarPalette(statusBarPalette);
}

// Save the extracted colors and wallpaper id to LauncherProvider.
Expand Down
76 changes: 48 additions & 28 deletions src/ch/deletescape/lawnchair/dynamicui/ExtractedColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ExtractedColors {
// These color profile indices should NOT be changed, since they are used when saving and
// loading extracted colors. New colors should always be added at the end.
public static final int VERSION_INDEX = 0;
public static final int HOTSEAT_INDEX = 1;
private static final int HOTSEAT_LIGHT_MUTED_INDEX = 1;
public static final int STATUS_BAR_INDEX = 2;
public static final int DOMINANT_INDEX = 3;
public static final int VIBRANT_INDEX = 4;
Expand All @@ -49,9 +49,14 @@ public class ExtractedColors {
public static final int MUTED_LIGHT_INDEX = 9;
public static final int VIBRANT_FOREGROUND_INDEX = 10;
public static final int DOMINANT_FOREGROUND_INDEX = 11;
private static final int HOTSEAT_DARK_MUTED_INDEX = 12;
private static final int HOTSEAT_LIGHT_VIBRANT_INDEX = 13;
private static final int HOTSEAT_DARK_VIBRANT_INDEX = 14;
private static final int IS_SUPER_LIGHT = 15;
private static final int IS_SUPER_DARK = 16;

public static final int NUM_COLOR_PROFILES = 11;
private static final int VERSION = 6;
public static final int NUM_COLOR_PROFILES = 16;
private static final int VERSION = 7;

private static final String COLOR_SEPARATOR = ",";

Expand Down Expand Up @@ -148,42 +153,57 @@ public void updatePalette(Palette palette) {
}
}

public void updateHotseatPalette(Palette hotseatPalette) {
if (hotseatPalette != null) {
if (ExtractionUtils.isSuperLight(hotseatPalette)) {
setColorAtIndex(IS_SUPER_LIGHT, 1);
setColorAtIndex(IS_SUPER_DARK, 0);
} else if (ExtractionUtils.isSuperDark(hotseatPalette)) {
setColorAtIndex(IS_SUPER_LIGHT, 0);
setColorAtIndex(IS_SUPER_DARK, 1);
} else {
setColorAtIndex(IS_SUPER_LIGHT, 0);
setColorAtIndex(IS_SUPER_DARK, 0);
}
setColorAtIndex(HOTSEAT_DARK_MUTED_INDEX, hotseatPalette.getDarkMutedColor(-1));
setColorAtIndex(HOTSEAT_DARK_VIBRANT_INDEX, hotseatPalette.getDarkVibrantColor(-1));
setColorAtIndex(HOTSEAT_LIGHT_MUTED_INDEX, hotseatPalette.getLightMutedColor(-1));
setColorAtIndex(HOTSEAT_LIGHT_VIBRANT_INDEX, hotseatPalette.getLightVibrantColor(-1));
}
}

/**
* The hotseat's color is defined as follows:
* - 20% darkMuted or 12% black for super light wallpaper
* - 25% lightMuted or 18% white for super dark
* - 40% lightVibrant or 25% white otherwise
*/
public void updateHotseatPalette(Context context, Palette hotseatPalette) {
public int getHotseatColor(Context context) {
int hotseatColor;
if (hotseatPalette != null) {
boolean shouldUseExtractedColors = FeatureFlags.hotseatShouldUseExtractedColors(context);
if (ExtractionUtils.isSuperLight(hotseatPalette)) {
if (shouldUseExtractedColors) {
int baseColor = hotseatPalette.getDarkMutedColor(hotseatPalette.getDarkVibrantColor(Color.BLACK));
hotseatColor = ColorUtils.setAlphaComponent(baseColor, (int) (0.20f * 255));
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
}
} else if (ExtractionUtils.isSuperDark(hotseatPalette)) {
if (shouldUseExtractedColors) {
int baseColor = hotseatPalette.getLightMutedColor(hotseatPalette.getLightVibrantColor(Color.WHITE));
hotseatColor = ColorUtils.setAlphaComponent(baseColor, (int) (0.25f * 255));
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
}
boolean shouldUseExtractedColors = FeatureFlags.hotseatShouldUseExtractedColors(context);
if (getColor(IS_SUPER_LIGHT, 0) == 1) {
if (shouldUseExtractedColors) {
int baseColor = getColor(HOTSEAT_DARK_MUTED_INDEX, getColor(HOTSEAT_DARK_VIBRANT_INDEX, Color.BLACK));
hotseatColor = ColorUtils.setAlphaComponent(baseColor, (int) (0.20f * 255));
} else {
if (shouldUseExtractedColors) {
int baseColor = hotseatPalette.getLightVibrantColor(hotseatPalette.getLightMutedColor(Color.WHITE));
hotseatColor = ColorUtils.setAlphaComponent(baseColor, (int) (0.40f * 255));
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
}
hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
}
} else if (getColor(IS_SUPER_DARK, 0) == 1) {
if (shouldUseExtractedColors) {
int baseColor = getColor(HOTSEAT_LIGHT_MUTED_INDEX, getColor(HOTSEAT_LIGHT_VIBRANT_INDEX, Color.WHITE));
hotseatColor = ColorUtils.setAlphaComponent(baseColor, (int) (0.25f * 255));
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
}
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
if (shouldUseExtractedColors) {
int baseColor = getColor(HOTSEAT_LIGHT_VIBRANT_INDEX, getColor(HOTSEAT_LIGHT_MUTED_INDEX, Color.WHITE));
hotseatColor = ColorUtils.setAlphaComponent(baseColor, (int) (0.40f * 255));
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
}
}
setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
return hotseatColor;
}

public void updateStatusBarPalette(Palette statusBarPalette) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ protected void onPageCountChanged() {
}
}

@Override
public void setShouldAutoHide(boolean shouldAutoHide) {
mShouldAutoHide = shouldAutoHide;
if (shouldAutoHide && mLinePaint.getAlpha() > 0) {
Expand All @@ -211,9 +212,10 @@ public void setShouldAutoHide(boolean shouldAutoHide) {
* - mostly opaque white if the hotseat is white (ignoring alpha)
* - mostly opaque black if the hotseat is black (ignoring alpha)
*/
@Override
public void updateColor(ExtractedColors extractedColors) {
int originalLineAlpha = mLinePaint.getAlpha();
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
int color = extractedColors.getHotseatColor(getContext());
if (color != Color.TRANSPARENT) {
color = ColorUtils.setAlphaComponent(color, 255);
int diffToWhite = Color.WHITE - color;
Expand Down
Loading

0 comments on commit e4ddd02

Please sign in to comment.