packages\apps\Launcher3\quickstep\src\com\android\quickstep\views\RecentsView.java 中 protected void applyLoadPlan(ArrayList<GroupTask> taskGroups) 的作用
时间: 2023-08-21 09:08:22 浏览: 33
`RecentsView.java` 是 Android 桌面系统中的一个类,其中的 `applyLoadPlan(ArrayList<GroupTask> taskGroups)` 方法用于应用加载计划,即根据传入的任务组列表,为每个任务组创建一个加载任务并启动它们。
具体来说,这个方法会为每个任务组创建一个 `TaskLoader` 对象,并将其加入到 `TaskLoaderCallbacks` 中。然后,使用 `TaskLoaders` 类来启动这些加载任务。在加载完成后,`RecentsView` 将会更新 UI,显示出加载完成后的任务列表。
其中,`GroupTask` 是一个包含多个 `Task` 对象的任务组,每个 `Task` 对象代表一个应用程序窗口。`TaskLoader` 是一个负责从系统获取应用程序窗口信息的对象。`TaskLoaderCallbacks` 是一个回调接口,用于在加载任务完成时通知 `RecentsView`。
总之,`applyLoadPlan` 方法的作用是根据传入的任务组列表,创建并启动加载任务,并更新 UI 显示加载完成后的任务列表。
相关问题
/packages/apps/Launcher3/src/com/android/launcher3/graphics/IconShapeOverride.java源码
以下是 IconShapeOverride.java 的源代码:
```java
package com.android.launcher3.graphics;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.launcher3.Utilities;
import com.android.launcher3.icons.GraphicsUtils;
import com.android.launcher3.icons.IconProvider;
import com.android.launcher3.icons.ShapeData;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.ResourceBasedOverride;
/**
* Provides custom icon shapes based on user preferences.
*/
public class IconShapeOverride extends ResourceBasedOverride {
public static final String KEY_PREFERENCE = "pref_override_icon_shape";
private static final String TAG = "IconShapeOverride";
private final IconProvider mIconProvider;
public IconShapeOverride(Context context) {
this(context, IconProvider.INSTANCE);
}
@VisibleForTesting
public IconShapeOverride(Context context, IconProvider iconProvider) {
super(context, KEY_PREFERENCE);
mIconProvider = iconProvider;
}
/**
* @return the current shape path, or null if not defined.
*/
@Nullable
public ShapeData getShape() {
String pathString = getStringValue();
if (pathString == null) {
return null;
}
try {
return ShapeData.parse(pathString);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Unable to parse shape", e);
return null;
}
}
/**
* @return the current shape path as a {@link Path} instance, or null if not defined.
*/
@Nullable
public Path getShapePath() {
ShapeData data = getShape();
return data != null ? data.getPath() : null;
}
/**
* @return the current shape path bounds, or null if not defined.
*/
@Nullable
public Rect getShapeBounds() {
ShapeData data = getShape();
return data != null ? data.getBounds() : null;
}
/**
* Returns the shape path for the given context, or null if none is specified.
*/
public static Path getShapePath(Resources res, SharedPreferences prefs) {
IconShapeOverride override = new IconShapeOverride(res);
override.setSharedPreferences(prefs);
return override.getShapePath();
}
/**
* Tests whether the current shape is a circle, by checking if all corners of the shape are at
* the same distance from the center.
*/
public boolean isShapeCircle() {
Path shape = getShapePath();
if (shape == null) {
return false;
}
Rect bounds = getShapeBounds();
if (bounds == null) {
return false;
}
Rect outBounds = new Rect();
shape.computeBounds(outBounds, true);
float centerX = bounds.exactCenterX();
float centerY = bounds.exactCenterY();
float radius = Math.max(centerX - bounds.left, centerY - bounds.top);
float maxDeviation = 0;
float[] radii = new float[9];
shape.approximate(1f, radii);
for (int i = 0; i < radii.length; i += 2) {
float deviation = Math.abs(radii[i] - radius);
if (deviation > maxDeviation) {
maxDeviation = deviation;
}
}
return maxDeviation < GraphicsUtils.EPSILON;
}
/**
* Updates the default icon shape, if the user has not overridden it.
*/
public static void updateDefaultShape(Context context) {
SharedPreferences prefs = Utilities.getPrefs(context);
if (prefs.contains(KEY_PREFERENCE)) {
return;
}
IconShapeOverride override = new IconShapeOverride(context);
Path path = override.getDefaultShape();
if (path != null) {
prefs.edit().putString(KEY_PREFERENCE, ShapeData.toString(path)).apply();
}
}
/**
* @return the default shape path for the current device.
*/
@Nullable
public Path getDefaultShape() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return IconShape.applyMaskIfNeeded(mIconProvider.getDeviceProfile(),
mIconProvider.getIconMask());
}
return null;
}
@Override
protected void onValueChanged() {
super.onValueChanged();
mIconProvider.clearCaches();
}
}
```
该类提供了自定义应用图标的形状的功能,它会根据用户的偏好设置提供自定义图标形状。其中包含了获取、设置、更新默认图标形状等方法。此外,还包含一些辅助方法,如测试当前形状是否为圆形。在 Android Oreo 及以上版本中,会调用 IconShape 类提供的方法来获取默认图标形状。
packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothEnabler.java
`BluetoothEnabler.java` 是 Android 系统中设置应用中蓝牙开关的实现类。它继承自 `SwitchWidgetController.OnSwitchChangeListener` 接口,实现了蓝牙开关的状态监听和设置。
在 `onSwitchChanged(SwitchWidgetController controller, boolean isChecked)` 方法中,当用户在界面上点击蓝牙开关时,会触发状态的变化。如果用户打开了蓝牙开关,就会通过 `BluetoothAdapter.enable()` 方法来打开蓝牙功能;如果用户关闭了蓝牙开关,就会通过 `BluetoothAdapter.disable()` 方法来关闭蓝牙功能。
此外,`BluetoothEnabler.java` 还会监听蓝牙的状态变化,并根据蓝牙的实际状态来更新开关的显示状态。如果蓝牙被打开了,就会将开关设置为打开状态;如果蓝牙被关闭了,就会将开关设置为关闭状态。