Skip to content

Commit de0afcb

Browse files
committed
优化代码,修改手机设置仅一次时不在加载其他屏幕问题
1 parent 97023bd commit de0afcb

File tree

12 files changed

+127
-84
lines changed

12 files changed

+127
-84
lines changed

effectivecard/src/main/java/com/codemx/effectivecard/LauncherOverlayView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* TIME 18:16
1717
*/
1818
public class LauncherOverlayView extends FrameLayout {
19+
1920
public LauncherOverlayView(@NonNull Context context) {
2021
super(context);
2122
}

src/com/android/launcher3/Launcher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,7 @@ public void startBinding() {
19031903

19041904
@Override
19051905
public void bindScreens(ArrayList<Long> orderedScreenIds) {
1906+
XLog.e(XLog.getTag(), XLog.TAG_GU + orderedScreenIds);
19061907
// Make sure the first screen is always at the start.
19071908
if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
19081909
orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
@@ -1931,6 +1932,7 @@ public void bindScreens(ArrayList<Long> orderedScreenIds) {
19311932
}
19321933

19331934
private void bindAddScreens(ArrayList<Long> orderedScreenIds) {
1935+
XLog.e(XLog.getTag(), XLog.TAG_GU + orderedScreenIds);
19341936
int count = orderedScreenIds.size();
19351937
for (int i = 0; i < count; i++) {
19361938
long screenId = orderedScreenIds.get(i);

src/com/android/launcher3/LauncherModel.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.os.Looper;
2929
import android.os.Process;
3030
import android.os.UserHandle;
31-
import androidx.annotation.Nullable;
3231
import android.text.TextUtils;
3332
import android.util.Log;
3433
import android.util.Pair;
@@ -61,6 +60,7 @@
6160
import com.android.launcher3.util.Thunk;
6261
import com.android.launcher3.util.ViewOnDrawExecutor;
6362
import com.android.launcher3.widget.WidgetListRowEntry;
63+
import com.android.mxlibrary.util.XLog;
6464

6565
import java.io.FileDescriptor;
6666
import java.io.PrintWriter;
@@ -72,6 +72,8 @@
7272
import java.util.concurrent.CancellationException;
7373
import java.util.concurrent.Executor;
7474

75+
import androidx.annotation.Nullable;
76+
7577
import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD;
7678
import static com.android.launcher3.config.FeatureFlags.IS_DOGFOOD_BUILD;
7779

@@ -197,12 +199,18 @@ public void bindAppsAdded(ArrayList<Long> newScreens,
197199
* Runs the specified runnable immediately if called from the worker thread, otherwise it is
198200
* posted on the worker thread handler.
199201
*/
200-
private static void runOnWorkerThread(Runnable r) {
202+
private static void runOnWorkerThread(Runnable r, boolean isRemoveAfterRun) {
201203
if (sWorkerThread.getThreadId() == Process.myTid()) {
204+
XLog.e(XLog.getTag(), XLog.TAG_GU);
202205
r.run();
203206
} else {
207+
XLog.e(XLog.getTag(), XLog.TAG_GU);
204208
// If we are not on the worker thread, then post to the worker handler
205209
sWorker.post(r);
210+
// TODO 存在部分系统会重新调用问题
211+
if (isRemoveAfterRun) {
212+
sWorker.removeCallbacks(r);
213+
}
206214
}
207215
}
208216

@@ -289,18 +297,19 @@ public void run() {
289297
}
290298
}
291299
};
292-
runOnWorkerThread(r);
300+
runOnWorkerThread(r, false);
293301
}
294302

295303
/**
296304
* Update the order of the workspace screens in the database. The array list contains
297305
* a list of screen ids in the order that they should appear.
298306
*/
299307
public static void updateWorkspaceScreenOrder(Context context, final ArrayList<Long> screens) {
300-
final ArrayList<Long> screensCopy = new ArrayList<Long>(screens);
308+
XLog.e(XLog.getTag(), XLog.TAG_GU + screens);
309+
final ArrayList<Long> screensCopy = new ArrayList<>(screens);
301310
final ContentResolver cr = context.getContentResolver();
302311
final Uri uri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
303-
312+
XLog.e(XLog.getTag(), XLog.TAG_GU);
304313
// Remove any negative screen ids -- these aren't persisted
305314
Iterator<Long> iter = screensCopy.iterator();
306315
while (iter.hasNext()) {
@@ -309,13 +318,14 @@ public static void updateWorkspaceScreenOrder(Context context, final ArrayList<L
309318
iter.remove();
310319
}
311320
}
312-
321+
XLog.e(XLog.getTag(), XLog.TAG_GU);
313322
Runnable r = new Runnable() {
314323
@Override
315324
public void run() {
316325
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
317326
// Clear the table
318327
ops.add(ContentProviderOperation.newDelete(uri).build());
328+
XLog.e(XLog.getTag(), XLog.TAG_GU + screensCopy);
319329
int count = screensCopy.size();
320330
for (int i = 0; i < count; i++) {
321331
ContentValues v = new ContentValues();
@@ -326,8 +336,10 @@ public void run() {
326336
}
327337

328338
try {
339+
XLog.e(XLog.getTag(), XLog.TAG_GU + ops);
329340
cr.applyBatch(LauncherProvider.AUTHORITY, ops);
330341
} catch (Exception ex) {
342+
XLog.e(XLog.getTag(), XLog.TAG_GU + ex.getMessage());
331343
throw new RuntimeException(ex);
332344
}
333345

@@ -337,7 +349,8 @@ public void run() {
337349
}
338350
}
339351
};
340-
runOnWorkerThread(r);
352+
XLog.e(XLog.getTag(), XLog.TAG_GU);
353+
runOnWorkerThread(r, true);
341354
}
342355

343356
/**
@@ -455,6 +468,7 @@ public void onReceive(Context context, Intent intent) {
455468
* not be called as DB updates are automatically followed by UI update
456469
*/
457470
public void forceReload() {
471+
XLog.e(XLog.getTag(), XLog.TAG_GU);
458472
synchronized (mLock) {
459473
// Stop any existing loaders first, so they don't set mModelLoaded to true later
460474
stopLoader();
@@ -479,6 +493,7 @@ public boolean isCurrentCallbacks(Callbacks callbacks) {
479493
* @return true if the page could be bound synchronously.
480494
*/
481495
public boolean startLoader(int synchronousBindPage) {
496+
XLog.e(XLog.getTag(), XLog.TAG_GU);
482497
// Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
483498
InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_LOADER_RUNNING);
484499
synchronized (mLock) {
@@ -527,7 +542,7 @@ public void startLoaderForResults(LoaderResults results) {
527542
synchronized (mLock) {
528543
stopLoader();
529544
mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, sBgDataModel, results);
530-
runOnWorkerThread(mLoaderTask);
545+
runOnWorkerThread(mLoaderTask, false);
531546
}
532547
}
533548

@@ -614,7 +629,7 @@ public void onPackageIconsUpdated(HashSet<String> updatedPackages, UserHandle us
614629

615630
public void enqueueModelUpdateTask(ModelUpdateTask task) {
616631
task.init(mApp, this, sBgDataModel, mBgAllAppsList, mUiExecutor);
617-
runOnWorkerThread(task);
632+
runOnWorkerThread(task, false);
618633
}
619634

620635
/**

src/com/android/launcher3/LauncherProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
import java.util.HashSet;
7373
import java.util.LinkedHashSet;
7474

75+
import androidx.annotation.NonNull;
76+
7577
public class LauncherProvider extends ContentProvider {
7678
private static final String TAG = "LauncherProvider";
7779
private static final boolean LOGD = false;
@@ -306,8 +308,9 @@ public int bulkInsert(Uri uri, ContentValues[] values) {
306308
}
307309

308310
@Override
309-
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
311+
public @NonNull ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
310312
throws OperationApplicationException {
313+
XLog.e(XLog.getTag(), XLog.TAG_GU + operations);
311314
createDbIfNotExists();
312315
try (SQLiteTransaction t = new SQLiteTransaction(mOpenHelper.getWritableDatabase())) {
313316
ContentProviderResult[] result = super.applyBatch(operations);

src/com/android/launcher3/Workspace.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ private void convertFinalScreenToEmptyScreenIfNecessary() {
655655
// if this is the last screen, convert it to the empty screen
656656
mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, finalScreen);
657657
mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID);
658-
658+
XLog.e(XLog.getTag(), XLog.TAG_GU + mScreenOrder);
659659
// Update the model if we have changed any screens
660660
LauncherModel.updateWorkspaceScreenOrder(mLauncher, mScreenOrder);
661661
}
@@ -766,7 +766,7 @@ public long commitExtraEmptyScreen() {
766766
.getLong(LauncherSettings.Settings.EXTRA_VALUE);
767767
mWorkspaceScreens.put(newId, cl);
768768
mScreenOrder.add(newId);
769-
769+
XLog.e(XLog.getTag(),XLog.TAG_GU + mScreenOrder);
770770
// Update the model for the new screen
771771
LauncherModel.updateWorkspaceScreenOrder(mLauncher, mScreenOrder);
772772

src/com/android/launcher3/config/BaseFlags.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ abstract class BaseFlags {
5454
public static final boolean OVERVIEW_USE_SCREENSHOT_ORIENTATION = true;
5555

5656
// 是否禁用双指捏掐到预览模式
57-
public static final boolean LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW = false;
57+
public static final boolean LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW = true;
5858

5959
// 是否循环滑动
60-
public static final boolean LAUNCHER3_CIRCLE_SCROLL = false;
60+
public static final boolean LAUNCHER3_CIRCLE_SCROLL = true;
6161

6262
// 是否开启负一屏,当LAUNCHER_OVERLAY_ENABLED = false才起作用
63-
public static final boolean CUSTOM_CONTENT_ENABLED = true;
63+
public static final boolean CUSTOM_CONTENT_ENABLED = false;
6464
// 是否开启跨进程的负一屏,如果开启,则不会开启CustomContent负一屏
6565
public static final boolean LAUNCHER_OVERLAY_ENABLED = false;
6666

src/com/android/launcher3/dragndrop/DragLayer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public boolean onHoverEvent(MotionEvent ev) {
212212
return false;
213213
}
214214

215-
216215
private boolean isInAccessibleDrag() {
217216
return mActivity.getAccessibilityDelegate().isInAccessibleDrag();
218217
}

src/com/android/launcher3/menu/CircleMenuView.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import android.content.Context;
55
import android.content.res.TypedArray;
66
import android.graphics.Rect;
7-
import androidx.annotation.NonNull;
8-
import androidx.annotation.Nullable;
97
import android.util.AttributeSet;
108
import android.view.Gravity;
119
import android.view.LayoutInflater;
@@ -26,11 +24,15 @@
2624

2725
import java.util.List;
2826

27+
import androidx.annotation.NonNull;
28+
import androidx.annotation.Nullable;
29+
2930

3031
/**
3132
* CircleMenuView
3233
*/
33-
public class CircleMenuView extends ViewGroup implements View.OnClickListener, Insettable, View.OnLongClickListener {
34+
public class CircleMenuView extends ViewGroup implements View.OnClickListener, Insettable,
35+
View.OnLongClickListener {
3436

3537
private static final int DEFAULT_BUTTON_SIZE = 56;
3638
private static final float DEFAULT_DISTANCE = DEFAULT_BUTTON_SIZE * 1.5f;

src/com/android/launcher3/model/AddWorkspaceItemsNoPositionTask.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.android.launcher3.ItemInfo;
77
import com.android.launcher3.LauncherAppState;
88
import com.android.launcher3.LauncherModel;
9+
import com.android.launcher3.LauncherSettings;
910
import com.android.mxlibrary.util.XLog;
1011

1112
import java.util.ArrayList;
@@ -35,10 +36,30 @@ public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList app
3536
// called.
3637
ArrayList<Long> workspaceScreens = LauncherModel.loadWorkspaceScreensDb(context);
3738

39+
XLog.e(XLog.getTag(), XLog.TAG_GU + workspaceScreens);
3840
XLog.e(XLog.getTag(), XLog.TAG_GU + mAllAppsNoPotion.size());
41+
synchronized (dataModel) {
42+
List<ItemInfo> filteredItems = new ArrayList<>();
43+
for (ItemInfo itemInfo : mAllAppsNoPotion) {
44+
if (itemInfo == null) {
45+
continue;
46+
}
47+
if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
48+
itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT ||
49+
itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET ||
50+
itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET ||
51+
itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
52+
// Short-circuit this logic if the icon exists somewhere on the workspace
53+
if (shortcutExists(dataModel, itemInfo.getIntent(), itemInfo.user)) {
54+
continue;
55+
}
56+
}
57+
filteredItems.add(itemInfo);
58+
}
3959

40-
filterAddedItemsFinal(app, dataModel, apps, workspaceScreens, mAllAppsNoPotion, addedWorkspaceScreensFinal, addedItemsFinal);
41-
60+
filterAddedItemsFinal(app, dataModel, apps, workspaceScreens, filteredItems, addedWorkspaceScreensFinal, addedItemsFinal);
61+
XLog.e(XLog.getTag(), XLog.TAG_GU + workspaceScreens + " final " + addedWorkspaceScreensFinal);
62+
}
4263
// Update the workspace screens
4364
updateScreens(context, workspaceScreens);
4465

src/com/android/launcher3/model/AddWorkspaceItemsTask.java

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
package com.android.launcher3.model;
1717

1818
import android.content.Context;
19-
import android.content.Intent;
20-
import android.os.UserHandle;
2119
import android.util.Pair;
2220

2321
import com.android.launcher3.AllAppsList;
2422
import com.android.launcher3.ItemInfo;
2523
import com.android.launcher3.LauncherAppState;
2624
import com.android.launcher3.LauncherModel;
2725
import com.android.launcher3.LauncherSettings;
28-
import com.android.launcher3.ShortcutInfo;
29-
import com.android.launcher3.Utilities;
26+
import com.android.mxlibrary.util.XLog;
3027

3128
import java.util.ArrayList;
3229
import java.util.List;
@@ -80,68 +77,13 @@ public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList app
8077

8178
filterAddedItemsFinal(app, dataModel, apps, workspaceScreens, filteredItems, addedWorkspaceScreensFinal, addedItemsFinal);
8279
}
83-
80+
XLog.d(XLog.getTag(), workspaceScreens + " final " + addedWorkspaceScreensFinal);
8481
// Update the workspace screens
8582
updateScreens(context, workspaceScreens);
8683

8784
bindAddedItemsFinal(addedWorkspaceScreensFinal, addedItemsFinal);
8885
}
8986

9087

91-
/**
92-
* Returns true if the shortcuts already exists on the workspace. This must be called after
93-
* the workspace has been loaded. We identify a shortcut by its intent.
94-
*/
95-
protected boolean shortcutExists(BgDataModel dataModel, Intent intent, UserHandle user) {
96-
final String compPkgName, intentWithPkg, intentWithoutPkg;
97-
if (intent == null) {
98-
// Skip items with null intents
99-
return true;
100-
}
101-
if (intent.getComponent() != null) {
102-
// If component is not null, an intent with null package will produce
103-
// the same result and should also be a match.
104-
compPkgName = intent.getComponent().getPackageName();
105-
if (intent.getPackage() != null) {
106-
intentWithPkg = intent.toUri(0);
107-
intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
108-
} else {
109-
intentWithPkg = new Intent(intent).setPackage(compPkgName).toUri(0);
110-
intentWithoutPkg = intent.toUri(0);
111-
}
112-
} else {
113-
compPkgName = null;
114-
intentWithPkg = intent.toUri(0);
115-
intentWithoutPkg = intent.toUri(0);
116-
}
117-
118-
boolean isLauncherAppTarget = Utilities.isLauncherAppTarget(intent);
119-
synchronized (dataModel) {
120-
for (ItemInfo item : dataModel.itemsIdMap) {
121-
if (item instanceof ShortcutInfo) {
122-
ShortcutInfo info = (ShortcutInfo) item;
123-
if (item.getIntent() != null && info.user.equals(user)) {
124-
Intent copyIntent = new Intent(item.getIntent());
125-
copyIntent.setSourceBounds(intent.getSourceBounds());
126-
String s = copyIntent.toUri(0);
127-
if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
128-
return true;
129-
}
130-
131-
// checking for existing promise icon with same package name
132-
if (isLauncherAppTarget
133-
&& info.isPromise()
134-
&& info.hasStatusFlag(ShortcutInfo.FLAG_AUTOINSTALL_ICON)
135-
&& info.getTargetComponent() != null
136-
&& compPkgName != null
137-
&& compPkgName.equals(info.getTargetComponent().getPackageName())) {
138-
return true;
139-
}
140-
}
141-
}
142-
}
143-
}
144-
return false;
145-
}
14688

14789
}

0 commit comments

Comments
 (0)