2021-02-02 17:12:08 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2021 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.taskbar;
|
|
|
|
|
|
2021-05-20 09:50:23 +00:00
|
|
|
import android.content.ContextWrapper;
|
2021-05-06 12:11:44 -07:00
|
|
|
import android.graphics.Point;
|
2021-02-02 17:12:08 -08:00
|
|
|
import android.graphics.Rect;
|
2021-05-06 12:11:44 -07:00
|
|
|
import android.graphics.drawable.Drawable;
|
2021-02-02 17:12:08 -08:00
|
|
|
import android.view.LayoutInflater;
|
2021-05-06 12:11:44 -07:00
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
2021-02-02 17:12:08 -08:00
|
|
|
|
2021-05-20 09:50:23 +00:00
|
|
|
import com.android.launcher3.BaseQuickstepLauncher;
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
2021-05-06 12:11:44 -07:00
|
|
|
import com.android.launcher3.DragSource;
|
|
|
|
|
import com.android.launcher3.DropTarget;
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.R;
|
2021-05-06 12:11:44 -07:00
|
|
|
import com.android.launcher3.dragndrop.DragController;
|
|
|
|
|
import com.android.launcher3.dragndrop.DragOptions;
|
|
|
|
|
import com.android.launcher3.dragndrop.DragView;
|
|
|
|
|
import com.android.launcher3.dragndrop.DraggableView;
|
|
|
|
|
import com.android.launcher3.model.data.ItemInfo;
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.views.ActivityContext;
|
2021-05-20 09:50:23 +00:00
|
|
|
import com.android.launcher3.views.BaseDragLayer;
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The {@link ActivityContext} with which we inflate Taskbar-related Views. This allows UI elements
|
|
|
|
|
* that are used by both Launcher and Taskbar (such as Folder) to reference a generic
|
|
|
|
|
* ActivityContext and BaseDragLayer instead of the Launcher activity and its DragLayer.
|
|
|
|
|
*/
|
2021-05-20 09:50:23 +00:00
|
|
|
public class TaskbarActivityContext extends ContextWrapper implements ActivityContext {
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
private final DeviceProfile mDeviceProfile;
|
|
|
|
|
private final LayoutInflater mLayoutInflater;
|
|
|
|
|
private final TaskbarContainerView mTaskbarContainerView;
|
2021-05-06 12:11:44 -07:00
|
|
|
private final MyDragController mDragController;
|
2021-02-02 17:12:08 -08:00
|
|
|
|
2021-05-20 09:50:23 +00:00
|
|
|
public TaskbarActivityContext(BaseQuickstepLauncher launcher) {
|
|
|
|
|
super(launcher);
|
|
|
|
|
mDeviceProfile = launcher.getDeviceProfile().copy(this);
|
2021-02-02 17:12:08 -08:00
|
|
|
float taskbarIconSize = getResources().getDimension(R.dimen.taskbar_icon_size);
|
2021-03-22 17:19:41 -07:00
|
|
|
float iconScale = taskbarIconSize / mDeviceProfile.iconSizePx;
|
|
|
|
|
mDeviceProfile.updateIconSize(iconScale, getResources());
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
mLayoutInflater = LayoutInflater.from(this).cloneInContext(this);
|
2021-05-20 09:50:23 +00:00
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
mTaskbarContainerView = (TaskbarContainerView) mLayoutInflater
|
|
|
|
|
.inflate(R.layout.taskbar, null, false);
|
2021-05-06 12:11:44 -07:00
|
|
|
mDragController = new MyDragController(this);
|
2021-05-05 14:04:11 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-20 09:50:23 +00:00
|
|
|
public TaskbarContainerView getTaskbarContainerView() {
|
|
|
|
|
return mTaskbarContainerView;
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 14:43:58 -07:00
|
|
|
@Override
|
2021-02-02 17:12:08 -08:00
|
|
|
public LayoutInflater getLayoutInflater() {
|
|
|
|
|
return mLayoutInflater;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-05-20 09:50:23 +00:00
|
|
|
public BaseDragLayer<TaskbarActivityContext> getDragLayer() {
|
2021-02-02 17:12:08 -08:00
|
|
|
return mTaskbarContainerView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeviceProfile getDeviceProfile() {
|
|
|
|
|
return mDeviceProfile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Rect getFolderBoundingBox() {
|
|
|
|
|
return mTaskbarContainerView.getFolderBoundingBox();
|
|
|
|
|
}
|
2021-05-06 12:11:44 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DragController getDragController() {
|
|
|
|
|
return mDragController;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class MyDragController extends DragController<TaskbarActivityContext> {
|
|
|
|
|
MyDragController(TaskbarActivityContext activity) {
|
|
|
|
|
super(activity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected DragView startDrag(@Nullable Drawable drawable, @Nullable View view,
|
|
|
|
|
DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source,
|
|
|
|
|
ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale,
|
|
|
|
|
float dragViewScaleOnDrop, DragOptions options) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-05-20 09:50:23 +00:00
|
|
|
protected void exitDrag() { }
|
2021-05-06 12:11:44 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected DropTarget getDefaultDropTarget(int[] dropCoordinates) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|