Commit dfc7491d authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Fix insets related issue

parent 0d532748
Pipeline #132988 passed with stage
in 6 minutes and 31 seconds
......@@ -2,6 +2,7 @@ package foundation.e.blisslauncher.core.customviews
import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.View
......@@ -76,5 +77,5 @@ class BlurBackgroundView(context: Context, attrs: AttributeSet?) : View(context,
createFullBlurDrawable()
}
override fun setInsets(insets: WindowInsets) {}
override fun setInsets(insets: Rect) {}
}
......@@ -2,6 +2,7 @@ package foundation.e.blisslauncher.core.customviews
import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.WindowInsets
......@@ -73,15 +74,15 @@ class DockGridLayout @JvmOverloads constructor(
}
}
override fun setInsets(insets: WindowInsets?) {
override fun setInsets(insets: Rect) {
if (insets == null) return
val deviceProfile = BlissLauncher.getApplication(context).deviceProfile
val lp =
layoutParams as InsettableRelativeLayout.LayoutParams
lp.height = deviceProfile.hotseatCellHeightPx + insets.systemWindowInsetBottom
lp.height = deviceProfile.hotseatCellHeightPx + insets.bottom
setPadding(
deviceProfile.iconDrawablePaddingPx / 2, 0,
deviceProfile.iconDrawablePaddingPx / 2, insets.systemWindowInsetBottom
deviceProfile.iconDrawablePaddingPx / 2, insets.bottom
)
layoutParams = lp
}
......
......@@ -62,7 +62,7 @@ public class HorizontalPager extends ViewGroup implements Insettable {
private Set<OnScrollListener> mListeners = new HashSet<>();
private boolean mIsUiCreated;
private GestureDetectorCompat gestureDetectorCompat;
private WindowInsets insets;
private Rect insets;
private float mLastMotionRawY;
public HorizontalPager(Context context, AttributeSet attrs) {
......@@ -540,10 +540,10 @@ public class HorizontalPager extends ViewGroup implements Insettable {
}
@Override
public void setInsets(WindowInsets insets) {
public void setInsets(Rect insets) {
if(insets == null) return;
InsettableRelativeLayout.LayoutParams lp = (InsettableRelativeLayout.LayoutParams) getLayoutParams();
lp.topMargin = insets.getSystemWindowInsetTop();
lp.topMargin = insets.top;
setLayoutParams(lp);
updateInsetsForChildren();
this.insets = insets;
......
package foundation.e.blisslauncher.core.customviews;
import android.graphics.Rect;
import android.view.View;
import android.view.WindowInsets;
import androidx.annotation.NonNull;
/**
* Allows the implementing {@link View} to not draw underneath system bars.
......@@ -10,5 +11,5 @@ import android.view.WindowInsets;
*/
public interface Insettable {
void setInsets(WindowInsets insets);
void setInsets(@NonNull Rect insets);
}
......@@ -3,10 +3,8 @@ package foundation.e.blisslauncher.core.customviews
import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.widget.FrameLayout
import foundation.e.blisslauncher.R
......@@ -14,9 +12,7 @@ open class InsettableFrameLayout(mContext: Context, attrs: AttributeSet?) : Fram
mContext, attrs
), Insettable {
var windowInsets: WindowInsets? = null
val insets: Rect
/*val insets: Rect
get() {
var tempInsets = Rect()
if (this.windowInsets != null) {
......@@ -26,55 +22,40 @@ open class InsettableFrameLayout(mContext: Context, attrs: AttributeSet?) : Fram
tempInsets.bottom = this.windowInsets!!.systemWindowInsetBottom
}
return tempInsets
}
}*/
private fun setFrameLayoutChildInsets(child: View, newInsets: WindowInsets?, oldInsets: Rect) {
if (newInsets == null) return
@JvmField
val mInsets = Rect()
private fun setFrameLayoutChildInsets(child: View, newInsets: Rect, oldInsets: Rect) {
val lp: FrameLayout.LayoutParams =
child.layoutParams as FrameLayout.LayoutParams
if (child is Insettable) {
Log.i("Insettable", "setIsnets for child")
(child as Insettable).setInsets(newInsets)
} /*else {
lp.topMargin += newInsets.systemWindowInsetTop - oldInsets.top
lp.leftMargin += newInsets.systemWindowInsetLeft - oldInsets.left
lp.rightMargin += newInsets.systemWindowInsetRight - oldInsets.right
lp.bottomMargin += newInsets.systemWindowInsetBottom - oldInsets.bottom
}*/
} else {
lp.topMargin += newInsets.top - oldInsets.top
lp.leftMargin += newInsets.left - oldInsets.left
lp.rightMargin += newInsets.right - oldInsets.right
lp.bottomMargin += newInsets.bottom - oldInsets.bottom
}
child.layoutParams = lp
}
override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets? {
// BlissLauncher.getApplication(mContext).resetDeviceProfile()
setInsets(insets)
Log.d("InsettableFrameLayout", "On applyWindowInsets insets with: insets = $tag")
return insets
}
override fun setInsets(insets: WindowInsets?) {
Log.d("InsettableFrameLayout", "Setting insets with: insets = $tag")
if (insets == null) return
override fun setInsets(insets: Rect) {
for (i in 0 until childCount) {
val child = getChildAt(i)
var oldInsets = Rect()
if (this.windowInsets != null) {
oldInsets.left = this.windowInsets!!.systemWindowInsetLeft
oldInsets.top = this.windowInsets!!.systemWindowInsetTop
oldInsets.right = this.windowInsets!!.systemWindowInsetRight
oldInsets.bottom = this.windowInsets!!.systemWindowInsetBottom
}
setFrameLayoutChildInsets(child, insets, oldInsets)
setFrameLayoutChildInsets(child, insets, mInsets)
}
this.windowInsets = insets
mInsets.set(insets)
}
override fun onViewAdded(child: View) {
super.onViewAdded(child)
setFrameLayoutChildInsets(child, windowInsets, Rect())
setFrameLayoutChildInsets(child, mInsets, Rect())
}
companion object {
fun dispatchInsets(parent: ViewGroup, insets: WindowInsets) {
fun dispatchInsets(parent: ViewGroup, insets: Rect) {
val n = parent.childCount
for (i in 0 until n) {
val child = parent.getChildAt(i)
......@@ -98,7 +79,7 @@ open class InsettableFrameLayout(mContext: Context, attrs: AttributeSet?) : Fram
a.recycle()
}
constructor(width: Int, height: Int) : super(width, height) {}
constructor(lp: ViewGroup.LayoutParams?) : super(lp!!) {}
constructor(width: Int, height: Int) : super(width, height)
constructor(lp: ViewGroup.LayoutParams?) : super(lp!!)
}
}
......@@ -3,6 +3,7 @@ package foundation.e.blisslauncher.core.customviews;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
......@@ -14,7 +15,7 @@ import foundation.e.blisslauncher.R;
public class InsettableRelativeLayout extends RelativeLayout {
private final Context mContext;
protected WindowInsets mInsets;
protected Rect mInsets;
public InsettableRelativeLayout(Context context, AttributeSet attrs) {
......@@ -25,12 +26,12 @@ public class InsettableRelativeLayout extends RelativeLayout {
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
BlissLauncher.getApplication(mContext).resetDeviceProfile();
updateChildInsets(insets);
mInsets = new WindowInsets(insets);
mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
updateChildInsets(mInsets);
return insets;
}
private void updateChildInsets(WindowInsets insets) {
private void updateChildInsets(Rect insets) {
if(insets == null) return;
int childCount = getChildCount();
for (int index = 0; index < childCount; ++index){
......
......@@ -34,6 +34,7 @@ import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.GridLayout;
import android.widget.Toast;
import foundation.e.blisslauncher.BuildConfig;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Utilities;
......@@ -69,11 +70,13 @@ import foundation.e.blisslauncher.features.test.dragndrop.DropTarget;
import foundation.e.blisslauncher.features.test.dragndrop.SpringLoadedDragController;
import foundation.e.blisslauncher.features.test.graphics.DragPreviewProvider;
import foundation.e.blisslauncher.features.test.uninstall.UninstallHelper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import org.jetbrains.annotations.NotNull;
public class LauncherPagedView extends PagedView<PageIndicatorDots> implements View.OnTouchListener,
......@@ -175,7 +178,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
private Alarm wobbleExpireAlarm = new Alarm();
private static final int WOBBLE_EXPIRATION_TIMEOUT = 25000;
public LauncherPagedView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
}
......@@ -235,13 +237,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
}
@Override
public void setInsets(WindowInsets insets) {
mInsets.set(
insets.getSystemWindowInsetLeft(),
insets.getSystemWindowInsetTop(),
insets.getSystemWindowInsetRight(),
insets.getSystemWindowInsetBottom()
);
public void setInsets(Rect insets) {
mInsets.set(insets);
VariantDeviceProfile grid = mLauncher.getDeviceProfile();
mMaxDistanceForFolderCreation = (0.55f * grid.getIconSizePx());
......@@ -725,7 +722,14 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
* @param y The Y position of the child in the screen's grid.
* @param animate If the view should start to animate after drag and drop.
*/
private void addInScreen(View child, long container, long screenId, int x, int y, boolean animate) {
private void addInScreen(
View child,
long container,
long screenId,
int x,
int y,
boolean animate
) {
int index = y * mLauncher.getDeviceProfile().getInv().getNumColumns() + x;
addInScreen(
child,
......@@ -735,11 +739,12 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
);
post(() -> {
if(animate) {
if(index % 2 == 0) {
if (animate) {
if (index % 2 == 0) {
child.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble));
} else {
child.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble_reverse));
child.startAnimation(AnimationUtils
.loadAnimation(getContext(), R.anim.wobble_reverse));
}
}
});
......@@ -1430,7 +1435,14 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
throw new NullPointerException("mDragInfo.cell has null parent");
}
addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1], true);
addInScreen(
cell,
container,
screenId,
mTargetCell[0],
mTargetCell[1],
true
);
}
// update the item's position after drop
......@@ -1503,9 +1515,11 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
final long screenId = getIdForScreen(target);
boolean aboveShortcut =
(targetView.getTag() instanceof ApplicationItem) || (targetView.getTag() instanceof ShortcutItem);
(targetView.getTag() instanceof ApplicationItem) || (targetView
.getTag() instanceof ShortcutItem);
boolean willBecomeShortcut =
(targetView.getTag() instanceof ApplicationItem) || (targetView.getTag() instanceof ShortcutItem);
(targetView.getTag() instanceof ApplicationItem) || (targetView
.getTag() instanceof ShortcutItem);
if (aboveShortcut && willBecomeShortcut) {
LauncherItem sourceItem = (LauncherItem) newView.getTag();
......@@ -1847,7 +1861,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
float targetCellDistance = mDragTargetLayout.getDistanceFromCell(
mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
//TODO: Enable when supporting foler
manageFolderFeedback(mDragTargetLayout, mTargetCell, targetCellDistance, d);
boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied((int)
......@@ -2093,16 +2106,15 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
CellLayout targetLayout,
int[] targetCell, float distance, DragObject dragObject
) {
Log.d(
TAG,
"manageFolderFeedback() called with: targetLayout = [" + targetLayout + "], targetCell = [" + targetCell + "], distance = [" + distance + "], dragObject = [" + dragObject + "]"
);
if (distance > mMaxDistanceForFolderCreation) return;
final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], mTargetCell[1]);
LauncherItem info = dragObject.dragInfo;
// Return early in case of dragged item is a folder because we don't support nested folders.
if (info instanceof FolderItem) return;
boolean userFolderPending = willCreateUserFolder(info, dragOverView, false);
Log.i(TAG, "manageFolderFeedback: userFolderPending: " + userFolderPending);
if (mDragMode == DRAG_MODE_NONE && userFolderPending &&
!mFolderCreationAlarm.alarmPending()) {
......@@ -2125,8 +2137,11 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
}
boolean willAddToFolder = willAddToExistingUserFolder(info, dragOverView);
if (willAddToFolder && mDragMode == DRAG_MODE_NONE && !mFolderCreationAlarm
.alarmPending()) {
Log.i(TAG, "manageFolderFeedback: willAddToFolder: " + willAddToFolder);
FolderCreationAlarmListener listener = new
FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1], false);
......@@ -2215,7 +2230,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
&& info.user.equals(user);
final LauncherPagedView.ItemOperator packageAndUserAndApp =
(LauncherItem info, View view, int index) ->
packageAndUser.evaluate(info, view, index) && info.itemType == ITEM_TYPE_APPLICATION;
packageAndUser
.evaluate(info, view, index) && info.itemType == ITEM_TYPE_APPLICATION;
return getFirstMatch(
new CellLayout[]{mLauncher.getHotseat(), currentPage},
......@@ -2391,7 +2407,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
public void wobbleLayouts() {
// Adds uninstall icon.
Animation wobbleAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.wobble);
Animation reverseWobbleAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.wobble_reverse);
Animation reverseWobbleAnimation =
AnimationUtils.loadAnimation(getContext(), R.anim.wobble_reverse);
mapOverItems(MAP_NO_RECURSE, (info, v, itemIdx) -> {
if ((info instanceof ApplicationItem || info instanceof ShortcutItem)
&& v instanceof IconTextView
......@@ -2399,21 +2416,21 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
.isUninstallDisabled(info.user.getRealHandle(), getContext())) {
// Return early if this app is system app
if(info instanceof ApplicationItem) {
if (info instanceof ApplicationItem) {
ApplicationItem applicationItem = (ApplicationItem) info;
if (applicationItem.isSystemApp != ApplicationItem.FLAG_SYSTEM_UNKNOWN) {
if ((applicationItem.isSystemApp & ApplicationItem.FLAG_SYSTEM_NO) != 0) {
((IconTextView)v).applyUninstallIconState(true);
((IconTextView) v).applyUninstallIconState(true);
}
} else {
((IconTextView)v).applyUninstallIconState(true);
((IconTextView) v).applyUninstallIconState(true);
}
} else {
((IconTextView)v).applyUninstallIconState(true);
((IconTextView) v).applyUninstallIconState(true);
}
}
if(itemIdx % 2 == 0) {
if (itemIdx % 2 == 0) {
v.startAnimation(wobbleAnimation);
} else {
v.startAnimation(reverseWobbleAnimation);
......@@ -2425,6 +2442,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
/**
* Triggered when wobble animation expire after timeout.
*
* @param alarm
*/
@Override
......@@ -2432,7 +2450,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
// Adds uninstall icon.
mapOverItems(MAP_NO_RECURSE, (info, v, idx) -> {
if (v instanceof IconTextView) {
((IconTextView)v).applyUninstallIconState(false);
((IconTextView) v).applyUninstallIconState(false);
}
// Clears if there is any running animation on the view.
......@@ -2447,8 +2465,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
/**
* Process the next itemInfo, possibly with side-effect on the next item.
*
* @param info info for the shortcut
* @param view view for the shortcut
* @param info info for the shortcut
* @param view view for the shortcut
* @param index index of the view in the parent layout.
* @return true if done, false to continue the map
*/
......
......@@ -9,13 +9,13 @@ import android.content.Context
import android.graphics.Canvas
import android.graphics.Outline
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.util.AttributeSet
import android.util.Property
import android.view.Gravity
import android.view.View
import android.view.ViewOutlineProvider
import android.view.WindowInsets
import android.view.animation.Interpolator
import android.view.animation.OvershootInterpolator
import foundation.e.blisslauncher.R
......@@ -315,12 +315,12 @@ class PageIndicatorDots(context: Context, attrs: AttributeSet?, defStyleAttr: In
// mIsRtl = Utilities.isRtl(getResources())
}
override fun setInsets(insets: WindowInsets) {
override fun setInsets(insets: Rect) {
val deviceProfile = mLauncher.deviceProfile
val lp = layoutParams as BaseDragLayer.LayoutParams
lp.leftMargin = 0.also { lp.rightMargin = it }
lp.gravity = Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM
lp.bottomMargin = deviceProfile.hotseatBarSizePx + resources.getDimensionPixelSize(R.dimen.dotPadding) * 2 + insets.systemWindowInsetBottom
lp.bottomMargin = deviceProfile.hotseatBarSizePx + resources.getDimensionPixelSize(R.dimen.dotPadding) * 2 + insets.bottom
layoutParams = lp
}
}
......@@ -6,9 +6,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import java.util.List;
......@@ -45,11 +47,14 @@ public class FolderPagerAdapter extends PagerAdapter {
viewGroup.setRowCount(3);
viewGroup.setColumnCount(3);
viewGroup.setPadding(
mDeviceProfile.getIconDrawablePaddingPx() / 2,
mDeviceProfile.getIconDrawablePaddingPx() / 2,
mDeviceProfile.getIconDrawablePaddingPx() / 2,
mDeviceProfile.getIconDrawablePaddingPx() / 2
mContext.getResources().getDimensionPixelSize(R.dimen.folder_padding) ,
mContext.getResources().getDimensionPixelSize(R.dimen.folder_padding),
mContext.getResources().getDimensionPixelSize(R.dimen.folder_padding),
mContext.getResources().getDimensionPixelSize(R.dimen.folder_padding)
);
ViewPager.LayoutParams params = (ViewPager.LayoutParams) viewGroup.getLayoutParams();
params.width = GridLayout.LayoutParams.WRAP_CONTENT;
params.height = GridLayout.LayoutParams.WRAP_CONTENT;
int i = 0;
while (9 * position + i < mFolderAppItems.size() && i < 9) {
LauncherItem appItem = mFolderAppItems.get(9 * position + i);
......@@ -60,7 +65,7 @@ public class FolderPagerAdapter extends PagerAdapter {
appView.setOnClickListener(ItemClickHandler.INSTANCE);
appView.setOnLongClickListener(ItemLongClickListener.INSTANCE_WORKSPACE);
GridLayout.LayoutParams iconLayoutParams = new GridLayout.LayoutParams();
iconLayoutParams.height = mDeviceProfile.getCellHeightPx();
iconLayoutParams.height = mDeviceProfile.getCellHeightPx() + mDeviceProfile.getIconDrawablePaddingPx()*2;
iconLayoutParams.width = mDeviceProfile.getCellHeightPx();
iconLayoutParams.setGravity(Gravity.CENTER);
appView.setLayoutParams(iconLayoutParams);
......
......@@ -78,13 +78,12 @@ public class Hotseat extends CellLayout implements Insettable {
}
@Override
public void setInsets(WindowInsets insets) {
public void setInsets(Rect insets) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
VariantDeviceProfile grid = mLauncher.getDeviceProfile();
lp.gravity = Gravity.BOTTOM;
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
Log.d(TAG, "Bottom inset: "+insets.getSystemWindowInsetBottom());
lp.height = grid.getHotseatBarSizePx() + insets.getSystemWindowInsetBottom();
lp.height = grid.getHotseatBarSizePx() + insets.bottom;
Rect padding = grid.getHotseatLayoutPadding();
getLayout().setPadding(padding.left, padding.top, padding.right, padding.bottom);
setLayoutParams(lp);
......
......@@ -4,6 +4,7 @@ import static foundation.e.blisslauncher.features.test.SystemUiController.FLAG_D
import static foundation.e.blisslauncher.features.test.SystemUiController.UI_STATE_NORMAL;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
......@@ -11,6 +12,7 @@ import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewDebug;
import android.view.WindowInsets;
......@@ -22,6 +24,8 @@ import org.jetbrains.annotations.Nullable;
public class LauncherRootView extends InsettableFrameLayout {
private final Rect mTempRect = new Rect();
private final TestActivity mLauncher;
private final Paint mOpaquePaint;
......@@ -56,18 +60,30 @@ public class LauncherRootView extends InsettableFrameLayout {
super.onFinishInflate();
}
@Nullable
@Override
public WindowInsets onApplyWindowInsets(@Nullable WindowInsets insets) {
private void handleSystemWindowInsets(Rect insets) {
mConsumedInsets.setEmpty();
boolean drawInsetBar = false;
if (mLauncher.isInMultiWindowMode()
&& (insets.left > 0 || insets.right > 0 || insets.bottom > 0)) {
mConsumedInsets.left = insets.left;
mConsumedInsets.right = insets.right;
mConsumedInsets.bottom = insets.bottom;
insets.set(0, insets.top, 0, 0);
drawInsetBar = true;
} else if ((insets.right > 0 || insets.left > 0) &&
getContext().getSystemService(ActivityManager.class).isLowRamDevice()) {