Search in sources :

Example 51 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class AppWidgetResizeFrame method setupForWidget.

private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout, DragLayer dragLayer) {
    mCellLayout = cellLayout;
    if (mWidgetView != null) {
        mWidgetView.removeOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
    }
    mWidgetView = widgetView;
    mWidgetView.addOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
    LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) widgetView.getAppWidgetInfo();
    mDragLayer = dragLayer;
    mMinHSpan = info.minSpanX;
    mMinVSpan = info.minSpanY;
    mMaxHSpan = info.maxSpanX;
    mMaxVSpan = info.maxSpanY;
    mWidgetPadding = getDefaultPaddingForWidget(getContext(), widgetView.getAppWidgetInfo().provider, null);
    mReconfigureButton = (ImageButton) findViewById(R.id.widget_reconfigure_button);
    if (info.isReconfigurable()) {
        mReconfigureButton.setVisibility(VISIBLE);
        mReconfigureButton.setOnClickListener(view -> {
            mLauncher.setWaitingForResult(PendingRequestArgs.forWidgetInfo(mWidgetView.getAppWidgetId(), /* widgetHandler= */
            null, (ItemInfo) mWidgetView.getTag()));
            mLauncher.getAppWidgetHost().startConfigActivity(mLauncher, mWidgetView.getAppWidgetId(), Launcher.REQUEST_RECONFIGURE_APPWIDGET);
        });
        if (!hasSeenReconfigurableWidgetEducationTip()) {
            post(() -> {
                if (showReconfigurableWidgetEducationTip() != null) {
                    mLauncher.getSharedPrefs().edit().putBoolean(KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN, true).apply();
                }
            });
        }
    }
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mWidgetView.getLayoutParams();
    ItemInfo widgetInfo = (ItemInfo) mWidgetView.getTag();
    lp.cellX = lp.tmpCellX = widgetInfo.cellX;
    lp.cellY = lp.tmpCellY = widgetInfo.cellY;
    lp.cellHSpan = widgetInfo.spanX;
    lp.cellVSpan = widgetInfo.spanY;
    lp.isLockedToGrid = true;
    // When we create the resize frame, we first mark all cells as unoccupied. The appropriate
    // cells (same if not resized, or different) will be marked as occupied when the resize
    // frame is dismissed.
    mCellLayout.markCellsAsUnoccupiedForView(mWidgetView);
    mLauncher.getStatsLogManager().logger().withInstanceId(logInstanceId).withItemInfo(widgetInfo).log(LAUNCHER_WIDGET_RESIZE_STARTED);
    setOnKeyListener(this);
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo)

Example 52 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class LauncherAppWidgetProviderInfoTest method initSpans_minResizeWidthWithCellSpacingAndWidgetInset_shouldInitializeMinSpans.

@Test
public void initSpans_minResizeWidthWithCellSpacingAndWidgetInset_shouldInitializeMinSpans() {
    InvariantDeviceProfile idp = createIDP();
    DeviceProfile dp = idp.supportedProfiles.get(0);
    Rect padding = new Rect();
    AppWidgetHostView.getDefaultPaddingForWidget(mContext, null, padding);
    int maxPadding = Math.max(Math.max(padding.left, padding.right), Math.max(padding.top, padding.bottom));
    dp.cellLayoutBorderSpacePx.x = dp.cellLayoutBorderSpacePx.y = maxPadding + 1;
    Mockito.when(dp.shouldInsetWidgets()).thenReturn(true);
    LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
    info.minWidth = CELL_SIZE * 3;
    info.minHeight = CELL_SIZE * 3;
    info.minResizeWidth = CELL_SIZE * 2 + maxPadding;
    info.minResizeHeight = CELL_SIZE * 2 + maxPadding;
    info.initSpans(mContext, idp);
    assertThat(info.minSpanX).isEqualTo(2);
    assertThat(info.minSpanY).isEqualTo(2);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) Rect(android.graphics.Rect) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) Point(android.graphics.Point) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 53 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class LauncherAppWidgetProviderInfoTest method initSpans_minResizeWidthHeightLargerThanMinWidth_shouldUseMinWidthHeightAsMinSpans.

@Test
public void initSpans_minResizeWidthHeightLargerThanMinWidth_shouldUseMinWidthHeightAsMinSpans() {
    LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
    info.minWidth = 20;
    info.minHeight = 20;
    info.minResizeWidth = 80;
    info.minResizeHeight = 80;
    InvariantDeviceProfile idp = createIDP();
    info.initSpans(mContext, idp);
    assertThat(info.minSpanX).isEqualTo(1);
    assertThat(info.minSpanY).isEqualTo(1);
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 54 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class LauncherAppWidgetProviderInfoTest method isMinSizeFulfilled_minWidthAndMinResizeWidthExceededGridColumns_shouldReturnFalse.

@Test
public void isMinSizeFulfilled_minWidthAndMinResizeWidthExceededGridColumns_shouldReturnFalse() {
    LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
    info.minWidth = CELL_SIZE * (NUM_OF_COLS + 2);
    info.minHeight = 80;
    info.minResizeWidth = CELL_SIZE * (NUM_OF_COLS + 1);
    info.minResizeHeight = 50;
    InvariantDeviceProfile idp = createIDP();
    info.initSpans(mContext, idp);
    assertThat(info.isMinSizeFulfilled()).isFalse();
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 55 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class LauncherAppWidgetProviderInfoTest method initSpans_minWidthSmallerThanCellWidth_shouldInitializeSpansToOne.

@Test
public void initSpans_minWidthSmallerThanCellWidth_shouldInitializeSpansToOne() {
    LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
    info.minWidth = 20;
    info.minHeight = 20;
    InvariantDeviceProfile idp = createIDP();
    info.initSpans(mContext, idp);
    assertThat(info.spanX).isEqualTo(1);
    assertThat(info.spanY).isEqualTo(1);
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)108 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)81 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)77 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)65 SmallTest (androidx.test.filters.SmallTest)52 LargeTest (androidx.test.filters.LargeTest)42 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)42 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)33 Bundle (android.os.Bundle)32 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)31 Point (android.graphics.Point)29 LauncherAppWidgetProviderInfo (com.android.launcher3.LauncherAppWidgetProviderInfo)28 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)23 Context (android.content.Context)23 DeviceProfile (com.android.launcher3.DeviceProfile)23 ArrayList (java.util.ArrayList)21 AppWidgetHostView (android.appwidget.AppWidgetHostView)20 WidgetItem (com.android.launcher3.model.WidgetItem)17 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)14 WidgetAddFlowHandler (com.android.launcher3.widget.WidgetAddFlowHandler)14