diff --git a/app/build.gradle b/app/build.gradle index 1ceaf63..bd4621a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:a9c3b63377' + implementation 'com.github.SimpleMobileTools:Simple-Commons:a26066d67d' kapt "androidx.room:room-compiler:2.5.2" implementation "androidx.room:room-runtime:2.5.2" diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt index 2dc524d..23e911b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -179,8 +179,8 @@ class MainActivity : SimpleActivity(), FlingListener { } for (page in 0 until maxPage) { - for (checkedYCell in 0 until COLUMN_COUNT) { - for (checkedXCell in 0 until ROW_COUNT - 1) { + for (checkedYCell in 0 until config.homeColumnCount) { + for (checkedXCell in 0 until config.homeRowCount - 1) { val wantedCell = Triple(page, checkedXCell, checkedYCell) if (!occupiedCells.contains(wantedCell)) { return Pair(page, Rect(wantedCell.second, wantedCell.third, wantedCell.second, wantedCell.third)) @@ -237,6 +237,10 @@ class MainActivity : SimpleActivity(), FlingListener { window.navigationBarColor = Color.TRANSPARENT } + home_screen_grid?.resizeGrid( + newRowCount = config.homeRowCount, + newColumnCount = config.homeColumnCount + ) (all_apps_fragment as? AllAppsFragment)?.onResume() } @@ -455,11 +459,12 @@ class MainActivity : SimpleActivity(), FlingListener { }, ANIMATION_DURATION) } - fun homeScreenLongPressed(x: Float, y: Float) { + fun homeScreenLongPressed(eventX: Float, eventY: Float) { if (isAllAppsFragmentExpanded()) { return } + val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY) mIgnoreMoveEvents = true val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt()) if (clickedGridItem != null) { @@ -471,8 +476,9 @@ class MainActivity : SimpleActivity(), FlingListener { showMainLongPressMenu(x, y) } - fun homeScreenClicked(x: Float, y: Float) { + fun homeScreenClicked(eventX: Float, eventY: Float) { home_screen_grid.hideResizeLines() + val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY) val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt()) if (clickedGridItem != null) { performItemClick(clickedGridItem) @@ -511,7 +517,7 @@ class MainActivity : SimpleActivity(), FlingListener { mLongPressedIcon = gridItem val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) { y - } else if (gridItem.top == ROW_COUNT - 1) { + } else if (gridItem.top == config.homeRowCount - 1) { home_screen_grid.sideMargins.top + (gridItem.top * home_screen_grid.cellHeight.toFloat()) } else { (gridItem.top * home_screen_grid.cellHeight.toFloat()) @@ -758,7 +764,7 @@ class MainActivity : SimpleActivity(), FlingListener { val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply { val dialerIcon = - HomeScreenGridItem(null, 0, ROW_COUNT - 1, 0, ROW_COUNT - 1, 0, defaultDialerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) + HomeScreenGridItem(null, 0, config.homeRowCount - 1, 0, config.homeRowCount - 1, 0, defaultDialerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) homeScreenGridItems.add(dialerIcon) } } catch (e: Exception) { @@ -768,7 +774,7 @@ class MainActivity : SimpleActivity(), FlingListener { val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this) appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply { val SMSMessengerIcon = - HomeScreenGridItem(null, 1, ROW_COUNT - 1, 1, ROW_COUNT - 1, 0, defaultSMSMessengerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) + HomeScreenGridItem(null, 1, config.homeRowCount - 1, 1, config.homeRowCount - 1, 0, defaultSMSMessengerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) homeScreenGridItems.add(SMSMessengerIcon) } } catch (e: Exception) { @@ -780,7 +786,7 @@ class MainActivity : SimpleActivity(), FlingListener { val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply { val browserIcon = - HomeScreenGridItem(null, 2, ROW_COUNT - 1, 2, ROW_COUNT - 1, 0, defaultBrowserPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) + HomeScreenGridItem(null, 2, config.homeRowCount - 1, 2, config.homeRowCount - 1, 0, defaultBrowserPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) homeScreenGridItems.add(browserIcon) } } catch (e: Exception) { @@ -791,7 +797,7 @@ class MainActivity : SimpleActivity(), FlingListener { val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) } if (storePackage != null) { appLaunchers.firstOrNull { it.packageName == storePackage }?.apply { - val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 3, ROW_COUNT - 1, 0, storePackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) + val storeIcon = HomeScreenGridItem(null, 3, config.homeRowCount - 1, 3, config.homeRowCount - 1, 0, storePackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) homeScreenGridItems.add(storeIcon) } } @@ -804,7 +810,7 @@ class MainActivity : SimpleActivity(), FlingListener { val defaultCameraPackage = resolveInfo!!.activityInfo.packageName appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply { val cameraIcon = - HomeScreenGridItem(null, 4, ROW_COUNT - 1, 4, ROW_COUNT - 1, 0, defaultCameraPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) + HomeScreenGridItem(null, 4, config.homeRowCount - 1, 4, config.homeRowCount - 1, 0, defaultCameraPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null) homeScreenGridItems.add(cameraIcon) } } catch (e: Exception) { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt index b42fe3b..374a17c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt @@ -12,6 +12,9 @@ import com.simplemobiletools.launcher.BuildConfig import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.extensions.config import com.simplemobiletools.launcher.helpers.MAX_COLUMN_COUNT +import com.simplemobiletools.launcher.helpers.MAX_ROW_COUNT +import com.simplemobiletools.launcher.helpers.MIN_COLUMN_COUNT +import com.simplemobiletools.launcher.helpers.MIN_ROW_COUNT import kotlinx.android.synthetic.main.activity_settings.* import java.util.Locale import kotlin.system.exitProcess @@ -37,11 +40,13 @@ class SettingsActivity : SimpleActivity() { setupUseEnglish() setupDrawerColumnCount() setupDrawerSearchBar() + setupHomeRowCount() + setupHomeColumnCount() setupLanguage() setupManageHiddenIcons() updateTextColors(settings_holder) - arrayOf(settings_color_customization_section_label, settings_general_settings_label, settings_drawer_settings_label).forEach { + arrayOf(settings_color_customization_section_label, settings_general_settings_label, settings_drawer_settings_label, settings_home_screen_label).forEach { it.setTextColor(getProperPrimaryColor()) } } @@ -115,6 +120,44 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupHomeRowCount() { + val currentRowCount = config.homeRowCount + settings_home_screen_row_count.text = currentRowCount.toString() + settings_home_screen_row_count_holder.setOnClickListener { + val items = ArrayList() + for (i in MIN_ROW_COUNT..MAX_ROW_COUNT) { + items.add(RadioItem(i, resources.getQuantityString(R.plurals.row_counts, i, i))) + } + + RadioGroupDialog(this, items, currentRowCount) { + val newRowCount = it as Int + if (currentRowCount != newRowCount) { + config.homeRowCount = newRowCount + setupHomeRowCount() + } + } + } + } + + private fun setupHomeColumnCount() { + val currentColumnCount = config.homeColumnCount + settings_home_screen_column_count.text = currentColumnCount.toString() + settings_home_screen_column_count_holder.setOnClickListener { + val items = ArrayList() + for (i in MIN_COLUMN_COUNT..MAX_COLUMN_COUNT) { + items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i))) + } + + RadioGroupDialog(this, items, currentColumnCount) { + val newColumnCount = it as Int + if (currentColumnCount != newColumnCount) { + config.homeColumnCount = newColumnCount + setupHomeColumnCount() + } + } + } + } + private fun setupLanguage() { settings_language.text = Locale.getDefault().displayLanguage settings_language_holder.beVisibleIf(isTiramisuPlus()) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt index eb6c8ba..07b5afc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt @@ -18,6 +18,7 @@ import com.simplemobiletools.commons.helpers.isRPlus import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.activities.MainActivity import com.simplemobiletools.launcher.adapters.WidgetsAdapter +import com.simplemobiletools.launcher.extensions.config import com.simplemobiletools.launcher.extensions.getInitialCellSize import com.simplemobiletools.launcher.helpers.ITEM_TYPE_SHORTCUT import com.simplemobiletools.launcher.helpers.ITEM_TYPE_WIDGET @@ -238,6 +239,11 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment } override fun onWidgetLongPressed(appWidget: AppWidget) { + if (appWidget.heightCells > context.config.homeRowCount - 1 || appWidget.widthCells > context.config.homeColumnCount) { + context.showErrorToast(context.getString(R.string.widget_too_big)) + return + } + val type = if (appWidget.isShortcut) { ITEM_TYPE_SHORTCUT } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt index 637394a..3fdfa1b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt @@ -13,6 +13,14 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(WAS_HOME_SCREEN_INIT, false) set(wasHomeScreenInit) = prefs.edit().putBoolean(WAS_HOME_SCREEN_INIT, wasHomeScreenInit).apply() + var homeColumnCount: Int + get() = prefs.getInt(HOME_COLUMN_COUNT, COLUMN_COUNT) + set(homeColumnCount) = prefs.edit().putInt(HOME_COLUMN_COUNT, homeColumnCount).apply() + + var homeRowCount: Int + get() = prefs.getInt(HOME_ROW_COUNT, ROW_COUNT) + set(homeRowCount) = prefs.edit().putInt(HOME_ROW_COUNT, homeRowCount).apply() + var drawerColumnCount: Int get() = prefs.getInt(DRAWER_COLUMN_COUNT, context.resources.getInteger(R.integer.portrait_column_count)) set(drawerColumnCount) = prefs.edit().putInt(DRAWER_COLUMN_COUNT, drawerColumnCount).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt index f543854..8f4ebd2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt @@ -5,12 +5,17 @@ const val WIDGET_LIST_ITEMS_HOLDER = 1 // shared prefs const val WAS_HOME_SCREEN_INIT = "was_home_screen_init" +const val HOME_ROW_COUNT = "home_row_count" +const val HOME_COLUMN_COUNT = "home_column_count" const val DRAWER_COLUMN_COUNT = "drawer_column_count" const val SHOW_SEARCH_BAR = "show_search_bar" // default home screen grid size const val ROW_COUNT = 6 const val COLUMN_COUNT = 5 +const val MIN_ROW_COUNT = 2 +const val MAX_ROW_COUNT = 15 +const val MIN_COLUMN_COUNT = 2 const val MAX_COLUMN_COUNT = 15 const val UNINSTALL_APP_REQUEST_CODE = 50 diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt index ddb38ac..2d68305 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -29,16 +29,29 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.isSPlus import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.activities.MainActivity +import com.simplemobiletools.launcher.extensions.config import com.simplemobiletools.launcher.extensions.getDrawableForPackageName import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB import com.simplemobiletools.launcher.helpers.* import com.simplemobiletools.launcher.models.HomeScreenGridItem import kotlinx.android.synthetic.main.activity_main.view.* +import kotlin.math.abs +import kotlin.math.floor +import kotlin.math.min class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) { constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) - private var iconMargin = context.resources.getDimension(R.dimen.icon_side_margin).toInt() + private var columnCount = context.config.homeColumnCount + private var rowCount = context.config.homeRowCount + private var cellXCoords = ArrayList(columnCount) + private var cellYCoords = ArrayList(rowCount) + var cellWidth = 0 + var cellHeight = 0 + private var extraXMargin = 0 + private var extraYMargin = 0 + + private var iconMargin = (context.resources.getDimension(R.dimen.icon_side_margin) * 5 / columnCount).toInt() private var labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt() private var roundedCornerRadius = context.resources.getDimension(R.dimen.activity_margin) private var textPaint: TextPaint @@ -46,14 +59,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel private var draggedItem: HomeScreenGridItem? = null private var resizedWidget: HomeScreenGridItem? = null private var isFirstDraw = true + private var redrawWidgets = false private var iconSize = 0 - // let's use a 6x5 grid for now with 1 special row at the bottom, prefilled with default apps - private var cellXCoords = ArrayList(COLUMN_COUNT) - private var cellYCoords = ArrayList(ROW_COUNT) - var cellWidth = 0 - var cellHeight = 0 - private var lastPage = 0 private var currentPage = 0 private var pageChangeLastArea = PageChangeArea.MIDDLE @@ -125,6 +133,19 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel } } + fun resizeGrid(newRowCount: Int, newColumnCount: Int) { + if (columnCount != newColumnCount || rowCount != newRowCount) { + rowCount = newRowCount + columnCount = newColumnCount + cellXCoords = ArrayList(columnCount) + cellYCoords = ArrayList(rowCount) + gridCenters.clear() + iconMargin = (context.resources.getDimension(R.dimen.icon_side_margin) * 5 / columnCount).toInt() + redrawWidgets = true + redrawGrid() + } + } + fun removeAppIcon(item: HomeScreenGridItem) { ensureBackgroundThread { removeItemFromHomeScreen(item) @@ -244,10 +265,14 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel item.left = cellsRect.left item.top = cellsRect.top item.right = cellsRect.right - item.bottom = cellsRect.bottom + item.bottom = if (cellsRect.bottom > rowCount - 2) { + rowCount - 2 + } else { + cellsRect.bottom + } updateWidgetPositionAndSize(widgetView, item) ensureBackgroundThread { - context.homeScreenGridItemsDB.updateItemPosition(cellsRect.left, cellsRect.top, cellsRect.right, cellsRect.bottom, item.page, item.id!!) + context.homeScreenGridItemsDB.updateItemPosition(item.left, item.top, item.right, item.bottom, item.page, item.id!!) } } @@ -432,7 +457,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel widgetItem.id!! ) val widgetView = widgetViews.firstOrNull { it.tag == widgetItem.widgetId } - if (widgetView != null) { + if (widgetView != null && !widgetItem.outOfBounds()) { post { widgetView.x = calculateWidgetX(widgetItem.left) widgetView.y = calculateWidgetY(widgetItem.top) @@ -557,9 +582,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel return Size(widgetWidth, widgetHeight) } - private fun calculateWidgetX(leftCell: Int) = leftCell * cellWidth + sideMargins.left.toFloat() + private fun calculateWidgetX(leftCell: Int) = cellXCoords[leftCell] + sideMargins.left.toFloat() + extraXMargin - private fun calculateWidgetY(topCell: Int) = topCell * cellHeight + sideMargins.top.toFloat() + private fun calculateWidgetY(topCell: Int) = cellYCoords[topCell] + sideMargins.top.toFloat() + extraYMargin // convert stuff like 102x192 to grid cells like 0x1 private fun getClosestGridCells(center: Pair): Pair? { @@ -609,19 +634,19 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel fun handleDrawing(item: HomeScreenGridItem, xFactor: Float) { if (item.id != draggedItem?.id) { - val drawableX = cellXCoords[item.left] + iconMargin + sideMargins.left + (width * xFactor).toInt() + val drawableX = cellXCoords[item.left] + iconMargin + extraXMargin + sideMargins.left + (width * xFactor).toInt() + + if (item.top == rowCount - 1) { + val drawableY = cellYCoords[item.top] + cellHeight - iconMargin - iconSize + sideMargins.top - // icons at the bottom are drawn at the bottom of the grid and they have no label - if (item.top == ROW_COUNT - 1) { - val drawableY = cellYCoords[item.top] + cellHeight - iconSize - iconMargin * 2 + sideMargins.top item.drawable!!.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize) } else { - val drawableY = cellYCoords[item.top] + iconSize / 2 + sideMargins.top + val drawableY = cellYCoords[item.top] + iconMargin + extraYMargin + sideMargins.top item.drawable!!.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize) if (item.id != draggedItem?.id && item.title.isNotEmpty()) { val textX = cellXCoords[item.left].toFloat() + labelSideMargin + sideMargins.left + width * xFactor - val textY = cellYCoords[item.top] + iconSize * 1.5f + labelSideMargin + sideMargins.top + val textY = cellYCoords[item.top].toFloat() + iconSize + iconMargin + extraYMargin + labelSideMargin + sideMargins.top val staticLayout = StaticLayout.Builder .obtain(item.title, 0, item.title.length, textPaint, cellWidth - 2 * labelSideMargin) .setMaxLines(2) @@ -641,6 +666,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel } gridItems.filter { (it.drawable != null && it.type == ITEM_TYPE_ICON || it.type == ITEM_TYPE_SHORTCUT) && it.page == currentPage }.forEach { item -> + if (item.outOfBounds()) { + return@forEach + } + handleDrawing(item, currentXFactor) } if (pageChangeAnimLeftPercentage > 0f && pageChangeAnimLeftPercentage < 1f) { @@ -650,11 +679,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel } if (isFirstDraw) { - gridItems.filter { it.type == ITEM_TYPE_WIDGET }.forEach { item -> + gridItems.filter { it.type == ITEM_TYPE_WIDGET && !it.outOfBounds() }.forEach { item -> bindWidget(item, true) } } else { - gridItems.filter { it.type == ITEM_TYPE_WIDGET }.forEach { item -> + gridItems.filter { it.type == ITEM_TYPE_WIDGET && !it.outOfBounds() }.forEach { item -> widgetViews.firstOrNull { it.tag == item.widgetId }?.also { updateWidgetPositionAndSize(it, item) } @@ -665,19 +694,19 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel if (draggedItem!!.type == ITEM_TYPE_ICON || draggedItem!!.type == ITEM_TYPE_SHORTCUT) { // draw a circle under the current cell val center = gridCenters.minBy { - Math.abs(it.first - draggedItemCurrentCoords.first + sideMargins.left) + Math.abs(it.second - draggedItemCurrentCoords.second + sideMargins.top) + abs(it.first - draggedItemCurrentCoords.first + sideMargins.left) + abs(it.second - draggedItemCurrentCoords.second + sideMargins.top) } val gridCells = getClosestGridCells(center) if (gridCells != null) { - val shadowX = cellXCoords[gridCells.first] + iconMargin.toFloat() + iconSize / 2 + sideMargins.left - val shadowY = if (gridCells.second == ROW_COUNT - 1) { - cellYCoords[gridCells.second] + cellHeight - iconSize / 2 - iconMargin * 2 + val shadowX = cellXCoords[gridCells.first] + iconMargin + iconSize / 2f + extraXMargin + sideMargins.left + val shadowY = if (gridCells.second == rowCount - 1) { + cellYCoords[gridCells.second] + cellHeight - iconMargin - iconSize / 2f } else { - cellYCoords[gridCells.second] + iconSize + cellYCoords[gridCells.second] + iconMargin + iconSize / 2f + extraYMargin } + sideMargins.top - canvas.drawCircle(shadowX, shadowY.toFloat(), iconSize / 2f, dragShadowCirclePaint) + canvas.drawCircle(shadowX, shadowY, iconSize / 2f, dragShadowCirclePaint) } // show the app icon itself at dragging, move it above the finger a bit to make it visible @@ -695,10 +724,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel val gridCells = getClosestGridCells(center) if (gridCells != null) { val widgetRect = getWidgetOccupiedRect(gridCells) - val leftSide = widgetRect.left * cellWidth + sideMargins.left + iconMargin.toFloat() - val topSide = widgetRect.top * cellHeight + sideMargins.top + iconMargin.toFloat() - val rightSide = leftSide + draggedItem!!.getWidthInCells() * cellWidth - sideMargins.right - iconMargin.toFloat() - val bottomSide = topSide + draggedItem!!.getHeightInCells() * cellHeight - sideMargins.top + val leftSide = calculateWidgetX(widgetRect.left) + val topSide = calculateWidgetY(widgetRect.top) + val rightSide = leftSide + draggedItem!!.getWidthInCells() * cellWidth + val bottomSide = topSide + draggedItem!!.getHeightInCells() * cellHeight canvas.drawRoundRect(leftSide, topSide, rightSide, bottomSide, roundedCornerRadius, roundedCornerRadius, dragShadowCirclePaint) } @@ -723,14 +752,24 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel } private fun fillCellSizes() { - cellWidth = getFakeWidth() / COLUMN_COUNT - cellHeight = getFakeHeight() / ROW_COUNT - iconSize = cellWidth - 2 * iconMargin - for (i in 0 until COLUMN_COUNT) { + cellWidth = getFakeWidth() / context.config.homeColumnCount + cellHeight = getFakeHeight() / context.config.homeRowCount + extraXMargin = if (cellWidth > cellHeight) { + (cellWidth - cellHeight) / 2 + } else { + 0 + } + extraYMargin = if (cellHeight > cellWidth) { + (cellHeight - cellWidth) / 2 + } else { + 0 + } + iconSize = min(cellWidth, cellHeight) - 2 * iconMargin + for (i in 0 until context.config.homeColumnCount) { cellXCoords.add(i, i * cellWidth) } - for (i in 0 until ROW_COUNT) { + for (i in 0 until context.config.homeRowCount) { cellYCoords.add(i, i * cellHeight) } @@ -759,27 +798,33 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel fillCellSizes() } - val clickableLeft = item.left * cellWidth + sideMargins.left - val clickableTop = cellYCoords[item.top] + iconSize / 3 + sideMargins.top - return Rect(clickableLeft, clickableTop, clickableLeft + cellWidth, clickableTop + iconSize * 2) + val clickableLeft = cellXCoords[item.left] + sideMargins.left + extraXMargin + val clickableTop = if (item.top == rowCount - 1) { + cellYCoords[item.top] + cellHeight - iconSize - iconMargin + } else { + cellYCoords[item.top] - iconMargin + extraYMargin + } + sideMargins.top + return Rect(clickableLeft, clickableTop, clickableLeft + iconSize + 2 * iconMargin, clickableTop + iconSize + 2 * iconMargin) } // drag the center of the widget, not the top left corner private fun getWidgetOccupiedRect(item: Pair): Rect { - val left = item.first - Math.floor((draggedItem!!.getWidthInCells() - 1) / 2.0).toInt() + val left = item.first - floor((draggedItem!!.getWidthInCells() - 1) / 2.0).toInt() val rect = Rect(left, item.second, left + draggedItem!!.getWidthInCells() - 1, item.second + draggedItem!!.getHeightInCells() - 1) if (rect.left < 0) { rect.right -= rect.left rect.left = 0 - } else if (rect.right > COLUMN_COUNT - 1) { - val diff = rect.right - COLUMN_COUNT + 1 + } else if (rect.right > columnCount - 1) { + val diff = rect.right - columnCount + 1 rect.right -= diff rect.left -= diff } - // do not allow placing widgets at the bottom row, that is for pinned default apps - if (rect.bottom >= ROW_COUNT - 1) { - val diff = rect.bottom - ROW_COUNT + 2 + if (rect.top < 0) { + rect.bottom -= rect.top + rect.top = 0 + } else if (rect.bottom > rowCount - 2) { + val diff = rect.bottom - rowCount + 2 rect.bottom -= diff rect.top -= diff } @@ -789,6 +834,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel fun isClickingGridItem(x: Int, y: Int): HomeScreenGridItem? { for (gridItem in gridItems.filter { it.page == currentPage }) { + if (gridItem.outOfBounds()) { + continue + } + if (gridItem.type == ITEM_TYPE_ICON || gridItem.type == ITEM_TYPE_SHORTCUT) { val rect = getClickableRect(gridItem) if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) { @@ -809,6 +858,18 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel return null } + fun intoViewSpaceCoords(screenSpaceX: Float, screenSpaceY: Float): Pair { + val viewLocation = IntArray(2) + getLocationOnScreen(viewLocation) + val x = screenSpaceX - viewLocation[0] + val y = screenSpaceY - viewLocation[1] + return Pair(x, y) + } + + private fun HomeScreenGridItem.outOfBounds(): Boolean { + return (left >= cellXCoords.size || right >= cellXCoords.size || top >= cellYCoords.size || bottom >= cellYCoords.size) + } + private inner class HomeScreenGridTouchHelper(host: View) : ExploreByTouchHelper(host) { override fun getVirtualViewAt(x: Float, y: Float): Int { val item = isClickingGridItem(x.toInt(), y.toInt()) @@ -862,7 +923,6 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel return false } - } private fun getMaxPage() = gridItems.map { it.page }.max() diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt index 40f3f31..b8ad846 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt @@ -9,10 +9,9 @@ import android.util.AttributeSet import android.view.MotionEvent import android.widget.RelativeLayout import com.simplemobiletools.launcher.R +import com.simplemobiletools.launcher.extensions.config import com.simplemobiletools.launcher.extensions.getCellCount -import com.simplemobiletools.launcher.helpers.COLUMN_COUNT import com.simplemobiletools.launcher.helpers.MAX_CLICK_DURATION -import com.simplemobiletools.launcher.helpers.ROW_COUNT import com.simplemobiletools.launcher.models.HomeScreenGridItem @SuppressLint("ViewConstructor") @@ -76,8 +75,8 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In it.provider.className == gridItem.className } ?: return - minResizeWidthCells = Math.min(COLUMN_COUNT, context.getCellCount(providerInfo.minResizeWidth)) - minResizeHeightCells = Math.min(ROW_COUNT, context.getCellCount(providerInfo.minResizeHeight)) + minResizeWidthCells = Math.min(context.config.homeColumnCount, context.getCellCount(providerInfo.minResizeWidth)) + minResizeHeightCells = Math.min(context.config.homeRowCount, context.getCellCount(providerInfo.minResizeHeight)) redrawFrame() occupiedCells.clear() @@ -224,7 +223,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In } } - if (wantedBottomCellY == ROW_COUNT - 1) { + if (wantedBottomCellY == context.config.homeRowCount - 1) { areAllCellsFree = false } @@ -322,7 +321,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In } } - if (wantedBottomCellY == ROW_COUNT - 1) { + if (wantedBottomCellY == context.config.homeRowCount - 1) { areAllCellsFree = false } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 88073cf..5a3bfef 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -176,7 +176,7 @@ style="@style/SettingsHolderTextViewOneLinerStyle" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/ripple_bottom_corners"> + android:background="@drawable/ripple_background"> + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index bc085c1..14f8d76 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -12,8 +12,10 @@ اﻷيقونات المخفية لا يمكن إلغاء تثبيت بعض التطبيقات بسبب قيود النظام، ولكن يمكن إخفاء أيقوناتها لتجنب ظهورها. درج التطبيق + Home screen + Widget is too big for current home screen size - \ No newline at end of file + diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index d74b98e..54af33c 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -12,6 +12,8 @@ Скрити икони Някои приложения не могат да бъдат деинсталирани поради системни ограничения, но можете поне да скриете иконите им, за да не ги виждате. App drawer + Home screen + Widget is too big for current home screen size