-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add transparent background to media widget (#4618)
* add transparent background support to media widget Allow users to configure the media widget to have a transparent background. * add helper to create widget background option adapter remove duplicated logic to check for dynamic colour support and when displayed the currently selected value. * Update import ordering
- Loading branch information
1 parent
ece89d4
commit b6a9934
Showing
7 changed files
with
67 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/io/homeassistant/companion/android/widgets/common/WidgetUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.homeassistant.companion.android.widgets.common | ||
|
||
import android.content.Context | ||
import com.google.android.material.color.DynamicColors | ||
import io.homeassistant.companion.android.common.R | ||
import io.homeassistant.companion.android.database.widget.WidgetBackgroundType | ||
|
||
/** | ||
* Shared helpers for working with widgets. | ||
*/ | ||
object WidgetUtils { | ||
|
||
/** | ||
* Create an adapter for the list of background colour options for a widget. | ||
*/ | ||
fun getBackgroundOptionList(context: Context): Array<String> { | ||
val backgroundTypeValues = mutableListOf( | ||
context.getString(R.string.widget_background_type_daynight), | ||
context.getString(R.string.widget_background_type_transparent) | ||
) | ||
if (DynamicColors.isDynamicColorAvailable()) { | ||
backgroundTypeValues.add(0, context.getString(R.string.widget_background_type_dynamiccolor)) | ||
} | ||
return backgroundTypeValues.toTypedArray() | ||
} | ||
|
||
fun getSelectedBackgroundOption(context: Context, selectedType: WidgetBackgroundType, options: Array<String>) = when { | ||
selectedType == WidgetBackgroundType.DYNAMICCOLOR && DynamicColors.isDynamicColorAvailable() -> | ||
options.indexOf(context.getString(R.string.widget_background_type_dynamiccolor)) | ||
selectedType == WidgetBackgroundType.TRANSPARENT -> | ||
options.indexOf(context.getString(R.string.widget_background_type_transparent)) | ||
else -> | ||
options.indexOf(context.getString(R.string.widget_background_type_daynight)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters