Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfd4c6a5 authored by Shamali P's avatar Shamali P
Browse files

Define shared data types representing the data needs of widget picker

Later these could themselves be different libraries, however, at the
moment, these are hosted in widget picker library.

Note: As we progress with the implementation, the structure of these
 types may change.

Bug: 408283627
Flag: EXEMPT refactor
Test: Not applicable
Change-Id: I994a9914dbbd63f30dc9968d4a3b109251dbbedf
parent aa46f810
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -39,3 +39,16 @@ android_library {
        "widget_picker_dagger_annotations",
    ],
}

// Data types that are accessible & potentially provided by hosts using the widget picker library
android_library {
    name: "widget_picker_shared_data_types",
    srcs: [
        "src/com/android/widgetpicker/shared/model/PickableWidget.kt",
        "src/com/android/widgetpicker/shared/model/WidgetAppIcon.kt",
        "src/com/android/widgetpicker/shared/model/WidgetAppId.kt",
        "src/com/android/widgetpicker/shared/model/WidgetId.kt",
        "src/com/android/widgetpicker/shared/model/WidgetPreview.kt",
        "src/com/android/widgetpicker/shared/model/WidgetUserProfiles.kt",
    ],
}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.widgetpicker.shared.model

import android.appwidget.AppWidgetProviderInfo

/**
 * Raw information about a widget that can be considered for display in widget picker list.
 *
 * Note: It is widget picker's responsibility to run eligibility checks to see if the widget can be
 * displayed in picker.
 *
 * @property id a unique identifier for the widget
 * @property appId a unique identifier for the app group that this widget could belong to
 * @property label a user friendly label for the widget.
 * @property description a user friendly description for the widget
 * @property appWidgetProviderInfo widget info associated with the widget as configured by the
 *   developer; note: this should be a local clone and not the object that was received from
 *   appwidget manager.
 */
data class PickableWidget(
    val id: WidgetId,
    val appId: WidgetAppId,
    val label: String,
    val description: String,
    val appWidgetProviderInfo: AppWidgetProviderInfo,
)
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.widgetpicker.shared.model

import android.annotation.DrawableRes
import android.graphics.Bitmap

/**
 * Icon to be displayed for an app that hosts widgets.
 *
 * @property icon an icon representing the app
 * @property badge an icon that can be placed over the app [icon] to highlight additional important
 *   characteristics about the app e.g. if app belongs to a work profile.
 */
data class WidgetAppIcon(val icon: AppIcon, val badge: AppIconBadge)

/** A data type holding information for rendering an icon */
sealed class AppIcon {
    /** An icon that can be rendered as a [Bitmap]. */
    data class HighResBitmapIcon(val bitmap: Bitmap) : AppIcon()

    /**
     * A low res icon that should be rendered by filling the icon slot with the provided [color].
     */
    data class LowResColorIcon(val color: Int) : AppIcon()

    /** Represents a missing app icon. */
    data object PlaceHolderAppIcon : AppIcon()
}

sealed class AppIconBadge {
    /**
     * A badge that should be rendered using the provided drawable [drawableResId] and tinted with
     * provided [tintColor].
     */
    data class DrawableBadge(@DrawableRes val drawableResId: Int, val tintColor: Int) :
        AppIconBadge()

    /** Indicates there is no badge available for an app icon. */
    data object NoBadge : AppIconBadge()
}
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.widgetpicker.shared.model

import android.os.UserHandle

/**
 * A unique identifier to represent a specific app hosting widgets
 *
 * @property packageName package of the app hosting widgets; e.g. for widget such as
 *   "com.example.app/widget.MyWidgetReceiver", the app package should be "com.example.app".
 * @property userHandle the user to which this specific app instance belongs to; for example, work
 *   profile user will have a separate app instance from a personal app instance.
 * @property category a unique identifier representing a custom group that is not an app but is
 *   visually displayed as an app hosting certain types of widgets.
 */
data class WidgetAppId(val packageName: String, val userHandle: UserHandle, val category: Int?)
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.widgetpicker.shared.model

import android.content.ComponentName
import android.os.UserHandle

/**
 * Combination of properties that can be used to uniquely identify a widget in the widget picker.
 *
 * The information may be also used to combine with other data sources or other purposes such as
 * logging.
 *
 * @property componentName [ComponentName] of the widget's broadcast receiver e.g.
 *   "com.example.app/widget.MyWidgetReceiver".
 * @property userHandle the user to which this specific widget instance belongs to; for example, a
 *   work profile user will have a separate app instance holding a separate widget from a personal
 *   app instance.
 */
data class WidgetId(val componentName: ComponentName, val userHandle: UserHandle)
Loading