Skip to content

Commit

Permalink
Add an option to hide some or most parts of the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlecat committed Dec 31, 2024
1 parent fe3723d commit 56f5955
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/me/tsukanov/counter/SharedPrefKeys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package me.tsukanov.counter
enum class SharedPrefKeys(val key: String) {
ACTIVE_COUNTER("activeKey"),
KEEP_SCREEN_ON("keepScreenOn"),
HIDE_CONTROLS("hideControls"),
HIDE_LAST_UPDATE("hideLastUpdate"),
LABEL_CONTROL_ON("labelControlOn"),
HARDWARE_BTN_CONTROL_ON("hardControlOn"),
VIBRATION_ON("vibrationOn"),
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/me/tsukanov/counter/view/CounterFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import java.util.Locale
import java.util.Map

class CounterFragment : Fragment() {

/** Name is used as a key to look up and modify counter value in storage. */
private var name: String? = null

Expand Down Expand Up @@ -112,15 +113,25 @@ class CounterFragment : Fragment() {
): View? {
val view = inflater.inflate(R.layout.counter, container, false)

counterLabel = view.findViewById(R.id.counterLabel)

incrementButton = view.findViewById(R.id.incrementButton)
incrementButton!!.setOnClickListener { v: View? -> increment() }

decrementButton = view.findViewById(R.id.decrementButton)
decrementButton!!.setOnClickListener { v: View? -> decrement() }

counterLabel = view.findViewById(R.id.counterLabel)
if (sharedPrefs!!.getBoolean(SharedPrefKeys.HIDE_CONTROLS.key, false)) {
incrementButton!!.visibility = View.GONE;
decrementButton!!.visibility = View.GONE;
}

updateTimestampLabel = view.findViewById(R.id.updateTimestampLabel)

if (sharedPrefs!!.getBoolean(SharedPrefKeys.HIDE_LAST_UPDATE.key, false)) {
updateTimestampLabel!!.visibility = View.GONE;
}

view.findViewById<View>(R.id.counterFrame)
.setOnClickListener { v: View? ->
if (sharedPrefs!!.getBoolean(SharedPrefKeys.LABEL_CONTROL_ON.key, true)) {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_display.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="?colorPrimary"
android:pathData="M20,3H4C2.89,3 2,3.89 2,5v12c0,1.1 0.89,2 2,2h4v2h8v-2h4c1.1,0 2,-0.9 2,-2V5C22,3.89 21.1,3 20,3zM20,17H4V5h16V17z" />

<path
android:fillColor="?colorPrimary"
android:pathData="M6,8.25h8v1.5h-8z" />

<path
android:fillColor="?colorPrimary"
android:pathData="M16.5,9.75l1.5,0l0,-1.5l-1.5,0l0,-1.25l-1.5,0l0,4l1.5,0z" />

<path
android:fillColor="?colorPrimary"
android:pathData="M10,12.25h8v1.5h-8z" />

<path
android:fillColor="?colorPrimary"
android:pathData="M7.5,15l1.5,0l0,-4l-1.5,0l0,1.25l-1.5,0l0,1.5l1.5,0z" />

</vector>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_time.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="?colorPrimary"
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z" />

<path
android:fillColor="?colorPrimary"
android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z" />

</vector>
10 changes: 8 additions & 2 deletions app/src/main/res/layout/counter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@
android:id="@+id/updateTimestampLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_above="@+id/anchor"
android:layout_marginTop="12dp"
android:layout_marginBottom="16dp"
android:textAlignment="center"
android:textSize="16sp"
android:textStyle="italic"
tools:text="42" />

<View
android:id="@+id/anchor"
android:layout_width="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_height="1dp" />

</RelativeLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<string name="settings_keep_on_title">Keep the screen on</string>
<string name="settings_keep_on_summary">Keep the screen on while app is active</string>
<string name="settings_controls">Controls</string>
<string name="settings_hide_controls_title">Hide the buttons</string>
<string name="settings_hide_controls_summary">You might want to turn on volume buttons use or the tap to increment option</string>
<string name="settings_sounds_title">Turn on sounds</string>
<string name="settings_sounds_summary">Play sounds when changing values</string>
<string name="settings_vibration_title">Turn on vibration</string>
Expand All @@ -47,6 +49,7 @@
<string name="settings_hard_summary">Change counter value using volume buttons</string>
<string name="settings_label_increment_title">Tap value to increment</string>
<string name="settings_label_increment_summary">Increment a counter by tapping the current value</string>
<string name="settings_hide_last_update_title">Hide the last change timestamp</string>
<string name="settings_other">Other</string>
<string name="settings_version_title">Version</string>
<string name="settings_wipe_title">Remove all counters</string>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
android:key="keepScreenOn"
android:summary="@string/settings_keep_on_summary"
android:title="@string/settings_keep_on_title" />
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_display"
android:key="hideControls"
android:summary="@string/settings_hide_controls_summary"
android:title="@string/settings_hide_controls_title" />
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_time"
android:key="hideLastUpdate"
android:title="@string/settings_hide_last_update_title" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/settings_other">
Expand Down

0 comments on commit 56f5955

Please sign in to comment.