Skip to content

Commit ad00a8d

Browse files
jiteshsinghthestinger
authored andcommitted
setup design config provider
- defines abstraction: NonRelationalProvider - implements SudConfigProvider - provides basic configs - provides overlay config - non-card layout for tablets - navigation bar light/dark mode - status bar light/dark mode
1 parent 11e479f commit ad00a8d

File tree

7 files changed

+137
-76
lines changed

7 files changed

+137
-76
lines changed

AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5038,7 +5038,7 @@
50385038
</activity-alias>
50395039

50405040
<provider
5041-
android:name="com.android.settings.SetupDesignConfigProvider"
5041+
android:name="com.android.settings.sudconfig.SudConfigProvider"
50425042
android:authorities="com.google.android.setupwizard.partner"
50435043
android:directBootAware="true"
50445044
android:exported="true" />

res/values-night/bools.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<bool name="setup_compat_light_navigation_bar">false</bool>
4+
<bool name="setup_compat_light_status_bar">false</bool>
5+
</resources>

res/values/bools.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<bool name="setup_compat_light_navigation_bar">true</bool>
4+
<bool name="setup_compat_light_status_bar">true</bool>
5+
</resources>

res/values/dimens.xml

+2
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,6 @@
471471
<dimen name="sud_progress_bar_margin_top">
472472
@dimen/sud_progress_bar_margin_top_material_you
473473
</dimen>
474+
<dimen name="setup_design_card_view_intrinsic_height">0dp</dimen>
475+
<dimen name="setup_design_card_view_intrinsic_width">0dp</dimen>
474476
</resources>

src/com/android/settings/SetupDesignConfigProvider.java

-75
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.android.settings.sudconfig
2+
3+
import android.content.ContentProvider
4+
import android.content.ContentValues
5+
import android.database.Cursor
6+
import android.net.Uri
7+
8+
/**
9+
* Useful for implementing content provider interfaces that are exclusively for non-relational
10+
* (non-tabular) models. This reduces the boilerplate code by providing empty implementations for
11+
* methods which are unneeded in non-relational models.
12+
*
13+
* @see [ContentProvider.call]
14+
*/
15+
abstract class NonRelationalProvider : ContentProvider() {
16+
17+
final override fun query(
18+
uri: Uri,
19+
projection: Array<out String>?,
20+
selection: String?,
21+
selectionArgs: Array<out String>?,
22+
sortOrder: String?
23+
): Cursor? {
24+
throw UnsupportedOperationException()
25+
}
26+
27+
final override fun getType(uri: Uri): String? {
28+
throw UnsupportedOperationException()
29+
}
30+
31+
final override fun insert(uri: Uri, values: ContentValues?): Uri? {
32+
throw UnsupportedOperationException()
33+
}
34+
35+
final override fun delete(
36+
uri: Uri,
37+
selection: String?,
38+
selectionArgs: Array<out String>?
39+
): Int {
40+
throw UnsupportedOperationException()
41+
}
42+
43+
final override fun update(
44+
uri: Uri,
45+
values: ContentValues?,
46+
selection: String?,
47+
selectionArgs: Array<out String>?
48+
): Int {
49+
throw UnsupportedOperationException()
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.android.settings.sudconfig
2+
3+
import android.os.Build
4+
import android.os.Bundle
5+
import android.provider.Settings
6+
import android.text.TextUtils
7+
import android.util.Log
8+
import com.android.settings.R;
9+
10+
/**
11+
* Provides system-wide config for setup wizard screens.
12+
*/
13+
class SudConfigProvider : NonRelationalProvider() {
14+
companion object {
15+
private const val TAG = "SudConfigProvider"
16+
17+
// resources to be forwarded via overlay config
18+
private val overlayConfigResources = arrayOf(
19+
R.dimen.setup_design_card_view_intrinsic_height,
20+
R.dimen.setup_design_card_view_intrinsic_width,
21+
R.bool.setup_compat_light_navigation_bar,
22+
R.bool.setup_compat_light_status_bar
23+
)
24+
}
25+
26+
override fun onCreate(): Boolean {
27+
return true
28+
}
29+
30+
override fun call(method: String, arg: String?, extras: Bundle?): Bundle {
31+
Log.d(TAG, "method: $method, caller: $callingPackage")
32+
val bundle = Bundle()
33+
when (method) {
34+
"suwDefaultThemeString" -> bundle.putString(method, "glif_v4_light")
35+
36+
"applyGlifThemeControlledTransition",
37+
"isDynamicColorEnabled",
38+
"isEmbeddedActivityOnePaneEnabled",
39+
"isFullDynamicColorEnabled",
40+
"IsMaterialYouStyleEnabled",
41+
"isNeutralButtonStyleEnabled",
42+
"isSuwDayNightEnabled" -> bundle.putBoolean(method, true)
43+
44+
"getDeviceName" -> bundle.putCharSequence(method, getDeviceName())
45+
46+
"getOverlayConfig" -> fillOverlayConfig(bundle)
47+
}
48+
return bundle
49+
}
50+
51+
private fun getDeviceName(): String {
52+
var name = Settings.Global.getString(
53+
requireContext().contentResolver,
54+
Settings.Global.DEVICE_NAME
55+
)
56+
if (TextUtils.isEmpty(name)) {
57+
name = Build.MODEL
58+
}
59+
return name
60+
}
61+
62+
private fun fillOverlayConfig(bundle: Bundle) {
63+
overlayConfigResources.forEach { resId ->
64+
val context = requireContext()
65+
val resName = context.resources.getResourceEntryName(resId)
66+
val config = Bundle()
67+
config.putString("packageName", context.packageName)
68+
config.putString("resourceName", resName)
69+
config.putInt("resourceId", resId)
70+
bundle.putBundle(resName, config)
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)