Lawnchair: Fix icon size and label size reload, implement launcher restart
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
-->
|
||||
|
||||
<application
|
||||
android:name="app.lawnchair.LawnchairApp"
|
||||
android:backupAgent="com.android.launcher3.LauncherBackupAgent"
|
||||
android:fullBackupOnly="true"
|
||||
android:fullBackupContent="@xml/backupscheme"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application android:name="app.lawnchair.ui.LawnchairApp">
|
||||
<application>
|
||||
<activity
|
||||
android:name="app.lawnchair.ui.preferences.PreferenceActivity"
|
||||
android:autoRemoveFromRecents="true"
|
||||
|
||||
@@ -25,7 +25,9 @@ import android.net.Uri
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import app.lawnchair.util.SingletonHolder
|
||||
import app.lawnchair.util.ensureOnMainThread
|
||||
import app.lawnchair.util.preferences.LawnchairPreferences
|
||||
import app.lawnchair.util.useApplicationContext
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
|
||||
+5
-7
@@ -15,7 +15,7 @@
|
||||
* along with Lawnchair Launcher. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package app.lawnchair.ui
|
||||
package app.lawnchair
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
@@ -25,6 +25,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.annotation.Keep
|
||||
import app.lawnchair.util.restartLauncher
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.quickstep.RecentsActivity
|
||||
|
||||
@@ -35,9 +36,6 @@ class LawnchairApp : Application() {
|
||||
val recentsEnabled by lazy { checkRecentsComponent() }
|
||||
val TAG = "LawnchairApp"
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
fun onLauncherAppStateCreated() {
|
||||
registerActivityLifecycleCallbacks(activityHandler)
|
||||
}
|
||||
@@ -45,9 +43,9 @@ class LawnchairApp : Application() {
|
||||
fun restart(recreateLauncher: Boolean = true) {
|
||||
if (recreateLauncher) {
|
||||
activityHandler.finishAll()
|
||||
} /*else {
|
||||
Utilities.restartLauncher(this)
|
||||
}*/
|
||||
} else {
|
||||
restartLauncher(this)
|
||||
}
|
||||
}
|
||||
|
||||
class ActivityHandler : ActivityLifecycleCallbacks {
|
||||
@@ -1,13 +0,0 @@
|
||||
package app.lawnchair;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager;
|
||||
|
||||
import app.lawnchair.nexuslauncher.OverlayCallbackImpl;
|
||||
|
||||
public class LawnchairLauncher extends Launcher {
|
||||
@Override
|
||||
protected LauncherOverlayManager getDefaultOverlay() {
|
||||
return new OverlayCallbackImpl(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package app.lawnchair
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import com.android.launcher3.Launcher
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager
|
||||
import app.lawnchair.nexuslauncher.OverlayCallbackImpl
|
||||
import app.lawnchair.util.restartLauncher
|
||||
import com.android.launcher3.LauncherAppState
|
||||
|
||||
open class LawnchairLauncher : Launcher() {
|
||||
private var paused = false
|
||||
|
||||
override fun getDefaultOverlay(): LauncherOverlayManager {
|
||||
return OverlayCallbackImpl(this)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
restartIfPending()
|
||||
|
||||
paused = false
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
paused = true
|
||||
}
|
||||
|
||||
open fun restartIfPending() {
|
||||
if (sRestart) {
|
||||
lawnchairApp.restart(false)
|
||||
}
|
||||
}
|
||||
|
||||
fun scheduleRestart() {
|
||||
if (paused) {
|
||||
sRestart = true
|
||||
} else {
|
||||
restartLauncher(this)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
var sRestart = false
|
||||
@JvmStatic
|
||||
fun getLauncher(context: Context): LawnchairLauncher {
|
||||
return context as? LawnchairLauncher
|
||||
?: (context as ContextWrapper).baseContext as? LawnchairLauncher
|
||||
?: LauncherAppState.getInstance(context).launcher as LawnchairLauncher
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package app.lawnchair;
|
||||
|
||||
import com.android.launcher3.uioverrides.QuickstepLauncher;
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager;
|
||||
|
||||
import app.lawnchair.nexuslauncher.OverlayCallbackImpl;
|
||||
|
||||
public class LawnchairLauncherQuickstep extends QuickstepLauncher {
|
||||
@Override
|
||||
protected LauncherOverlayManager getDefaultOverlay() {
|
||||
return new OverlayCallbackImpl(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package app.lawnchair
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import com.android.launcher3.uioverrides.QuickstepLauncher
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager
|
||||
import app.lawnchair.nexuslauncher.OverlayCallbackImpl
|
||||
import app.lawnchair.util.restartLauncher
|
||||
import com.android.launcher3.LauncherAppState
|
||||
|
||||
open class LawnchairLauncherQuickstep : QuickstepLauncher() {
|
||||
private var paused = false
|
||||
|
||||
override fun getDefaultOverlay(): LauncherOverlayManager {
|
||||
return OverlayCallbackImpl(this)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
restartIfPending()
|
||||
|
||||
paused = false
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
paused = true
|
||||
}
|
||||
|
||||
open fun restartIfPending() {
|
||||
if (sRestart) {
|
||||
lawnchairApp.restart(false)
|
||||
}
|
||||
}
|
||||
|
||||
fun scheduleRestart() {
|
||||
if (paused) {
|
||||
sRestart = true
|
||||
} else {
|
||||
restartLauncher(this)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
var sRestart = false
|
||||
@JvmStatic
|
||||
fun getLauncher(context: Context): LawnchairLauncherQuickstep {
|
||||
return context as? LawnchairLauncherQuickstep
|
||||
?: (context as ContextWrapper).baseContext as? LawnchairLauncherQuickstep
|
||||
?: LauncherAppState.getInstance(context).launcher as LawnchairLauncherQuickstep
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,21 @@
|
||||
* along with Lawnchair Launcher. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package app.lawnchair
|
||||
package app.lawnchair.util
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Looper
|
||||
|
||||
import com.android.launcher3.util.Executors.MAIN_EXECUTOR
|
||||
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
fun <T, A>ensureOnMainThread(creator: (A) -> T): (A) -> T {
|
||||
return { it ->
|
||||
@@ -43,4 +50,34 @@ fun <T, A>ensureOnMainThread(creator: (A) -> T): (A) -> T {
|
||||
|
||||
fun <T>useApplicationContext(creator: (Context) -> T): (Context) -> T {
|
||||
return { it -> creator(it.applicationContext) }
|
||||
}
|
||||
|
||||
fun restartLauncher(context: Context) {
|
||||
val pm = context.packageManager
|
||||
var intent: Intent? = Intent(Intent.ACTION_MAIN)
|
||||
intent!!.addCategory(Intent.CATEGORY_HOME)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
val componentName = intent.resolveActivity(pm)
|
||||
if (context.packageName != componentName.packageName) {
|
||||
intent = pm.getLaunchIntentForPackage(context.packageName)
|
||||
intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
}
|
||||
restartLauncher(context, intent)
|
||||
}
|
||||
|
||||
fun restartLauncher(context: Context, intent: Intent?) {
|
||||
context.startActivity(intent)
|
||||
|
||||
// Create a pending intent so the application is restarted after System.exit(0) was called.
|
||||
// We use an AlarmManager to call this intent in 100ms
|
||||
val mPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
val mgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
mgr[AlarmManager.RTC, System.currentTimeMillis() + 100] = mPendingIntent
|
||||
|
||||
// Kill the application
|
||||
killLauncher()
|
||||
}
|
||||
|
||||
fun killLauncher() {
|
||||
exitProcess(0)
|
||||
}
|
||||
@@ -18,8 +18,6 @@
|
||||
package app.lawnchair.util
|
||||
|
||||
import android.content.Context
|
||||
import app.lawnchair.ensureOnMainThread
|
||||
import app.lawnchair.useApplicationContext
|
||||
|
||||
// Source: https://medium.com/@BladeCoder/kotlin-singletons-with-argument-194ef06edd9e
|
||||
open class SingletonHolder<out T, in A>(creator: (A) -> T) {
|
||||
|
||||
@@ -2,6 +2,9 @@ package app.lawnchair.util.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import app.lawnchair.LawnchairLauncher
|
||||
import app.lawnchair.LawnchairLauncherQuickstep
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.Utilities
|
||||
|
||||
@@ -21,6 +24,14 @@ class LawnchairPreferences(val context: Context) {
|
||||
LauncherAppState.getInstance(context).invariantDeviceProfile.reInitGrid()
|
||||
LauncherAppState.getInstance(context).model.forceReload()
|
||||
}
|
||||
|
||||
TEXT_SIZE_FACTOR, ICON_SIZE_FACTOR, ALL_APPS_ICON_SIZE_FACTOR, ALL_APPS_TEXT_SIZE_FACTOR -> {
|
||||
if (BuildConfig.FLAVOR_recents == "withQuickstep") {
|
||||
LawnchairLauncherQuickstep.getLauncher(context).scheduleRestart()
|
||||
} else {
|
||||
LawnchairLauncher.getLauncher(context).scheduleRestart()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
-->
|
||||
|
||||
<application
|
||||
android:name="app.lawnchair.LawnchairApp"
|
||||
android:backupAgent="com.android.launcher3.LauncherBackupAgent"
|
||||
android:fullBackupOnly="true"
|
||||
android:fullBackupContent="@xml/backupscheme"
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
@@ -31,6 +32,8 @@ import com.android.launcher3.icons.IconNormalizer;
|
||||
import com.android.launcher3.util.DefaultDisplay;
|
||||
import com.android.launcher3.util.WindowBounds;
|
||||
|
||||
import app.lawnchair.util.preferences.LawnchairPreferences;
|
||||
|
||||
public class DeviceProfile {
|
||||
|
||||
private static final float TABLET_MIN_DPS = 600;
|
||||
@@ -140,10 +143,13 @@ public class DeviceProfile {
|
||||
public DotRenderer mDotRendererWorkSpace;
|
||||
public DotRenderer mDotRendererAllApps;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
DeviceProfile(Context context, InvariantDeviceProfile inv, DefaultDisplay.Info info,
|
||||
Point minSize, Point maxSize, int width, int height, boolean isLandscape,
|
||||
boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
|
||||
Point windowPosition) {
|
||||
mContext = context;
|
||||
|
||||
this.inv = inv;
|
||||
this.isLandscape = isLandscape;
|
||||
@@ -241,7 +247,6 @@ public class DeviceProfile {
|
||||
updateAvailableDimensions(res);
|
||||
}
|
||||
updateWorkspacePadding();
|
||||
|
||||
// This is done last, after iconSizePx is calculated above.
|
||||
mDotRendererWorkSpace = new DotRenderer(iconSizePx, IconShape.getShapePath(),
|
||||
IconShape.DEFAULT_PATH_SIZE);
|
||||
@@ -408,6 +413,16 @@ public class DeviceProfile {
|
||||
// Folder icon
|
||||
folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
|
||||
folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
|
||||
|
||||
// Lawnchair prefs
|
||||
SharedPreferences prefs = LawnchairPreferences.Companion.getInstance(mContext);
|
||||
if (prefs == null) return;
|
||||
|
||||
// Lawnchair icon and text sizes
|
||||
iconSizePx *= prefs.getFloat(LawnchairPreferences.ICON_SIZE_FACTOR, 1f);
|
||||
iconTextSizePx *= prefs.getFloat(LawnchairPreferences.TEXT_SIZE_FACTOR, 1f);;
|
||||
allAppsIconSizePx *= prefs.getFloat(LawnchairPreferences.ALL_APPS_ICON_SIZE_FACTOR, 1f);
|
||||
allAppsIconTextSizePx *= prefs.getFloat(LawnchairPreferences.ALL_APPS_TEXT_SIZE_FACTOR, 1f);
|
||||
}
|
||||
|
||||
private void updateAvailableFolderCellDimensions(Resources res) {
|
||||
|
||||
@@ -319,13 +319,6 @@ public class InvariantDeviceProfile {
|
||||
numAllAppsColumns = Math.round(prefs.getFloat(LawnchairPreferences.ALL_APPS_COLUMNS, numAllAppsColumns));
|
||||
numFolderRows = Math.round(prefs.getFloat(LawnchairPreferences.FOLDER_ROWS, numFolderRows));
|
||||
numFolderColumns = Math.round(prefs.getFloat(LawnchairPreferences.FOLDER_COLUMNS, numFolderColumns));
|
||||
|
||||
// Lawnchair icon and text sizes
|
||||
iconSize *= prefs.getFloat(LawnchairPreferences.ICON_SIZE_FACTOR, 1f);
|
||||
iconTextSize *= prefs.getFloat(LawnchairPreferences.TEXT_SIZE_FACTOR, 1f);;
|
||||
allAppsIconSize *= prefs.getFloat(LawnchairPreferences.ALL_APPS_ICON_SIZE_FACTOR, 1f);
|
||||
allAppsIconTextSize *= prefs.getFloat(LawnchairPreferences.ALL_APPS_TEXT_SIZE_FACTOR, 1f);
|
||||
|
||||
}
|
||||
|
||||
public void reInitGrid() {
|
||||
|
||||
@@ -372,6 +372,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
LauncherAppState app = LauncherAppState.getInstance(this);
|
||||
app.setLauncher(this);
|
||||
mOldConfig = new Configuration(getResources().getConfiguration());
|
||||
mModel = app.getModel();
|
||||
|
||||
|
||||
@@ -45,13 +45,21 @@ import com.android.launcher3.util.SecureSettingsObserver;
|
||||
import com.android.launcher3.util.SimpleBroadcastReceiver;
|
||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
|
||||
import app.lawnchair.LawnchairAppKt;
|
||||
|
||||
public class LauncherAppState {
|
||||
|
||||
public static final String ACTION_FORCE_ROLOAD = "force-reload-launcher";
|
||||
|
||||
// We do not need any synchronization for this variable as its only written on UI thread.
|
||||
public static final MainThreadInitializedObject<LauncherAppState> INSTANCE =
|
||||
new MainThreadInitializedObject<>(LauncherAppState::new);
|
||||
new MainThreadInitializedObject<LauncherAppState>(LauncherAppState::new) {
|
||||
@Override
|
||||
protected void onPostInit(Context context) {
|
||||
super.onPostInit(context);
|
||||
LawnchairAppKt.getLawnchairApp(context).onLauncherAppStateCreated();
|
||||
}
|
||||
};
|
||||
|
||||
private final Context mContext;
|
||||
private final LauncherModel mModel;
|
||||
@@ -65,6 +73,7 @@ public class LauncherAppState {
|
||||
private SimpleBroadcastReceiver mModelChangeReceiver;
|
||||
private SafeCloseable mCalendarChangeTracker;
|
||||
private SafeCloseable mUserChangeListener;
|
||||
private Launcher mLauncher;
|
||||
|
||||
public static LauncherAppState getInstance(final Context context) {
|
||||
return INSTANCE.get(context);
|
||||
@@ -177,6 +186,14 @@ public class LauncherAppState {
|
||||
}
|
||||
}
|
||||
|
||||
public void setLauncher(Launcher launcher) {
|
||||
mLauncher = launcher;
|
||||
}
|
||||
|
||||
public Launcher getLauncher() {
|
||||
return mLauncher;
|
||||
}
|
||||
|
||||
public IconCache getIconCache() {
|
||||
return mIconCache;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public class MainThreadInitializedObject<T> {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
mValue = TraceHelper.allowIpcs("main.thread.object",
|
||||
() -> mProvider.get(context.getApplicationContext()));
|
||||
onPostInit(context);
|
||||
} else {
|
||||
try {
|
||||
return MAIN_EXECUTOR.submit(() -> get(context)).get();
|
||||
@@ -59,6 +60,8 @@ public class MainThreadInitializedObject<T> {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
protected void onPostInit(Context context) { }
|
||||
|
||||
public T getNoCreate() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user