Skip to content

Commit c9a69cc

Browse files
committed
very simple presets
1 parent fc3e77b commit c9a69cc

5 files changed

Lines changed: 95 additions & 0 deletions

File tree

app/src/main/java/com/caniwebview/android/ui/config/ConfigFragment.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ class ConfigFragment : Fragment() {
7272
}
7373

7474
private fun setupUI() {
75+
// Presets
76+
binding.selectAllButton.setOnClickListener {
77+
setPreset("all")
78+
}
79+
80+
binding.selectNoneButton.setOnClickListener {
81+
setPreset("none")
82+
}
83+
84+
binding.selectCordovaButton.setOnClickListener {
85+
setPreset("cordova")
86+
}
87+
88+
// Settings
7589
binding.javaScriptEnabledCheckBox.setOnCheckedChangeListener { _, isChecked ->
7690
saveSetting("javaScriptEnabled", isChecked)
7791
}
@@ -102,6 +116,29 @@ class ConfigFragment : Fragment() {
102116
}
103117
}
104118

119+
private fun setPreset(preset: String) {
120+
when (preset) {
121+
"all" -> {
122+
binding.javaScriptEnabledCheckBox.isChecked = true
123+
binding.javaScriptCanOpenWindowsCheckBox.isChecked = true
124+
binding.domStorageEnabledCheckBox.isChecked = true
125+
binding.geolocationEnabledCheckBox.isChecked = true
126+
}
127+
"none" -> {
128+
binding.javaScriptEnabledCheckBox.isChecked = false
129+
binding.javaScriptCanOpenWindowsCheckBox.isChecked = false
130+
binding.domStorageEnabledCheckBox.isChecked = false
131+
binding.geolocationEnabledCheckBox.isChecked = false
132+
}
133+
"cordova" -> {
134+
binding.javaScriptEnabledCheckBox.isChecked = true
135+
binding.javaScriptCanOpenWindowsCheckBox.isChecked = true
136+
binding.domStorageEnabledCheckBox.isChecked = true
137+
binding.geolocationEnabledCheckBox.isChecked = true
138+
}
139+
}
140+
}
141+
105142
private fun openGitHub() {
106143
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/WebView-CG/CanIAndroidWebView"))
107144
startActivity(intent)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- res/drawable/button_outline.xml -->
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<solid android:color="@android:color/transparent" />
4+
<stroke
5+
android:width="2dp"
6+
android:color="@android:color/black" />
7+
<corners android:radius="4dp" />
8+
<padding
9+
android:left="10dp"
10+
android:top="10dp"
11+
android:right="10dp"
12+
android:bottom="10dp" />
13+
</shape>

app/src/main/res/layout/fragment_config.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,46 @@
55
android:orientation="vertical"
66
android:padding="16dp">
77

8+
<TextView
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:gravity="center"
12+
android:text="@string/presets"
13+
android:textSize="16sp"
14+
android:textColor="@color/black" />
15+
16+
<LinearLayout
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:orientation="horizontal"
20+
android:gravity="center">
21+
22+
<Button
23+
android:id="@+id/select_all_button"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:background="@drawable/button_outline"
27+
android:text="@string/all"
28+
android:textColor="@color/button_text_color" />
29+
30+
<Button
31+
android:id="@+id/select_none_button"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:background="@drawable/button_outline"
35+
android:text="@string/none"
36+
android:textColor="@color/button_text_color" />
37+
38+
<Button
39+
android:id="@+id/select_cordova_button"
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
android:background="@drawable/button_outline"
43+
android:text="@string/cordova"
44+
android:textColor="@color/button_text_color" />
45+
46+
</LinearLayout>
47+
848
<CheckBox
949
android:id="@+id/javaScriptEnabledCheckBox"
1050
android:layout_width="match_parent"

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
99
<color name="white">#FFFFFFFF</color>
10+
<color name="button_text_color">#000000</color>
1011
</resources>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
<string name="load">Load</string>
1212
<string name="code">Code</string>
1313
<string name="github">GitHub</string>
14+
<string name="cordova">Cordova</string>
15+
<string name="none">None</string>
16+
<string name="all">All</string>
17+
<string name="presets">Presets</string>
1418
</resources>

0 commit comments

Comments
 (0)