Jelajahi Sumber

add show/hide status bar functionality

sduduzog 7 tahun lalu
induk
melakukan
b820188a48

+ 6 - 6
app/build.gradle

@@ -13,7 +13,7 @@ android {
         minSdkVersion 16
         targetSdkVersion 28
         versionCode 21
-        versionName "2.1.3"
+        versionName "2.1.2"
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         vectorDrawables.useSupportLibrary = true
     }
@@ -39,15 +39,15 @@ dependencies {
 
     // Support Libraries
     implementation 'androidx.appcompat:appcompat:1.0.2'
-    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
     implementation 'androidx.cardview:cardview:1.0.0'
     implementation 'androidx.recyclerview:recyclerview:1.0.0'
+    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
 
     // Google Libraries
     implementation 'com.google.android.material:material:1.0.0'
 
     // Arch Components
-    implementation 'androidx.core:core-ktx:1.0.1'
+    implementation 'androidx.core:core-ktx:1.1.0-alpha03'
     implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
     implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha09'
     implementation 'androidx.room:room-runtime:2.1.0-alpha03'
@@ -68,7 +68,7 @@ dependencies {
     androidTestImplementation 'androidx.test:runner:1.1.1'
     androidTestImplementation 'androidx.test:rules:1.1.1'
     androidTestImplementation "androidx.arch.core:core-testing:2.0.0"
-    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
-    androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
-    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
+
 }

+ 30 - 15
app/src/main/java/com/sduduzog/slimlauncher/MainActivity.kt

@@ -3,7 +3,6 @@ package com.sduduzog.slimlauncher
 import android.content.SharedPreferences
 import android.content.pm.PackageManager
 import android.content.res.Resources
-import android.os.Build
 import android.os.Bundle
 import android.view.View
 import androidx.appcompat.app.AppCompatActivity
@@ -18,10 +17,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
 
     // TODO: Hide and show status bar (possibly bottom nav too) in preferences
     // TODO: Click on date, opens calendar app
-    // TODO: Support more devices, screen densities
 
     // TODO: Setup Wizard redesign to include,
-    // TODO: Have different text sizes, and typefaces
     // TODO: Move some apps to bottom sheet.
     // TODO: Clickable apps while in preferences, intuitiveness
     // TODO: Lock screen on double tap
@@ -59,7 +56,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
         settings = getSharedPreferences(getString(R.string.prefs_settings), MODE_PRIVATE)
         settings.registerOnSharedPreferenceChangeListener(this)
         navigator = findNavController(this, R.id.nav_host_fragment)
-//        navigator.addOnNavigatedListener(this) : removed. a breaking change
         navigator.addOnDestinationChangedListener(this)
         viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
     }
@@ -71,23 +67,22 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
 
     override fun onResume() {
         super.onResume()
-//        val isHidden = settings.getBoolean(getString(R.string.prefs_settings_key_hide_status_bar), true)
-//        if (isHidden) {
-//        window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN)
-//        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
-//        }
-        val flags = window.decorView.systemUiVisibility or if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
-             View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
-        } else {
-            0
-        }
-        window.decorView.systemUiVisibility = flags
+        toggleStatusBar()
+    }
+
+    override fun onWindowFocusChanged(hasFocus: Boolean) {
+        super.onWindowFocusChanged(hasFocus)
+        if (hasFocus) toggleStatusBar()
     }
 
+
     override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, s: String?) {
         if (s.equals(getString(R.string.prefs_settings_key_theme), true)) {
             recreate()
         }
+        if (s.equals(getString(R.string.prefs_settings_key_hide_status_bar), true)) {
+            toggleStatusBar()
+        }
     }
 
     override fun getTheme(): Resources.Theme {
@@ -128,6 +123,26 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
         // permissions this app might request
     }
 
+    private fun showSystemUI() {
+        window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
+    }
+
+    private fun hideSystemUI() {
+        window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                or View.SYSTEM_UI_FLAG_FULLSCREEN)
+    }
+
+    private fun toggleStatusBar() {
+        val isHidden = settings.getBoolean(getString(R.string.prefs_settings_key_hide_status_bar), false)
+        if (isHidden) {
+            hideSystemUI()
+        } else {
+            showSystemUI()
+        }
+    }
+
     companion object {
 
         fun resolveTheme(i: Int): Int {

+ 7 - 0
app/src/main/java/com/sduduzog/slimlauncher/ui/main/settings/SettingsFragment.kt

@@ -96,5 +96,12 @@ class SettingsFragment : StatusBarThemeFragment() {
                 putBoolean(getString(R.string.prefs_settings_key_app_dialer), b)
             }
         }
+
+        statusBarSwitch.isChecked = settings.getBoolean(getString(R.string.prefs_settings_key_hide_status_bar), false)
+        statusBarSwitch.setOnCheckedChangeListener { _, b ->
+            settings.edit {
+                putBoolean(getString(R.string.prefs_settings_key_hide_status_bar), b)
+            }
+        }
     }
 }

+ 57 - 21
app/src/main/res/layout/settings_fragment.xml

@@ -12,7 +12,8 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="16dp"
-        android:layout_marginTop="8dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginTop="24dp"
         android:alpha="0.5"
         android:text="@string/settings_title"
         app:layout_constraintStart_toStartOf="parent"
@@ -30,22 +31,61 @@
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/textView3" />
 
+    <TextView
+        android:id="@+id/textView14"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:layout_marginLeft="16dp"
+        android:text="@string/settings_hide_status_bar"
+        android:textAppearance="@style/TextAppearance.AppCompat"
+        android:textSize="18sp"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/divider4" />
+
+    <TextView
+        android:id="@+id/textView16"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="8dp"
+        android:layout_marginRight="8dp"
+        android:text="@string/settings_status_bar_when_switched"
+        app:layout_constraintEnd_toStartOf="@+id/statusBarSwitch"
+        app:layout_constraintStart_toStartOf="@+id/textView14"
+        app:layout_constraintTop_toBottomOf="@+id/textView14" />
+
+    <Switch
+        android:id="@+id/statusBarSwitch"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="8dp"
+        android:layout_marginEnd="24dp"
+        android:layout_marginRight="24dp"
+        android:layout_marginBottom="8dp"
+        android:padding="4dp"
+        app:layout_constraintBottom_toBottomOf="@+id/textView16"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="@+id/textView14" />
+
     <TextView
         android:id="@+id/textView2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="16dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginTop="16dp"
         android:text="@string/settings_text_use_24_hour_clock"
         android:textAppearance="@style/TextAppearance.AppCompat"
         android:textSize="18sp"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/divider4" />
+        app:layout_constraintTop_toBottomOf="@+id/textView16" />
 
     <TextView
         android:id="@+id/textView4"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_marginEnd="8dp"
+        android:layout_marginRight="8dp"
         android:text="@string/settings_text_tap_to_check_between_24_hour_or_12_hour"
         app:layout_constraintEnd_toStartOf="@+id/clockSwitch"
         app:layout_constraintStart_toStartOf="@+id/textView2"
@@ -61,7 +101,8 @@
         android:padding="4dp"
         app:layout_constraintBottom_toBottomOf="@+id/textView4"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintTop_toTopOf="@+id/textView2" />
+        app:layout_constraintTop_toTopOf="@+id/textView2"
+        android:layout_marginRight="24dp" />
 
     <TextView
         android:id="@+id/textView9"
@@ -73,7 +114,8 @@
         android:textAppearance="@style/TextAppearance.AppCompat"
         android:textSize="18sp"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/textView4" />
+        app:layout_constraintTop_toBottomOf="@+id/textView4"
+        android:layout_marginLeft="16dp" />
 
     <TextView
         android:id="@+id/textView10"
@@ -93,7 +135,8 @@
         android:padding="4dp"
         app:layout_constraintBottom_toBottomOf="@+id/textView10"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintTop_toTopOf="@+id/textView9" />
+        app:layout_constraintTop_toTopOf="@+id/textView9"
+        android:layout_marginRight="24dp" />
 
     <TextView
         android:id="@+id/changeThemeText"
@@ -105,7 +148,8 @@
         android:textAppearance="@style/TextAppearance.AppCompat"
         android:textSize="18sp"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/textView10" />
+        app:layout_constraintTop_toBottomOf="@+id/textView10"
+        android:layout_marginLeft="16dp" />
 
     <TextView
         android:id="@+id/textView7"
@@ -120,7 +164,8 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="16dp"
-        android:layout_marginTop="16dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginTop="8dp"
         android:alpha="0.5"
         android:text="@string/settings_text_home_screen_apps"
         app:layout_constraintStart_toStartOf="parent"
@@ -137,17 +182,6 @@
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/textView8" />
 
-    <TextView
-        android:id="@+id/textView6"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:text="@string/settings_list_item_subtext"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="@+id/textView8"
-        app:layout_constraintTop_toBottomOf="@+id/divider2" />
-
     <androidx.recyclerview.widget.RecyclerView
         android:id="@+id/settingsAppList"
         android:layout_width="0dp"
@@ -159,7 +193,7 @@
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/textView6"
+        app:layout_constraintTop_toBottomOf="@+id/divider2"
         tools:listitem="@layout/settings_list_item" />
 
     <androidx.appcompat.widget.AppCompatCheckBox
@@ -172,7 +206,8 @@
         android:textAppearance="@style/TextAppearance.AppCompat"
         android:visibility="gone"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintTop_toTopOf="@+id/textView2" />
+        app:layout_constraintTop_toTopOf="@+id/textView2"
+        android:layout_marginRight="24dp" />
 
     <Button
         android:id="@+id/buttonChangeTheme"
@@ -185,6 +220,7 @@
         android:text="@string/settings_button_change_theme"
         app:layout_constraintBottom_toBottomOf="@+id/textView7"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintTop_toTopOf="@+id/changeThemeText" />
+        app:layout_constraintTop_toTopOf="@+id/changeThemeText"
+        android:layout_marginRight="16dp" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 5 - 2
app/src/main/res/values/strings.xml

@@ -42,6 +42,10 @@
     <string name="settings_text_tap_to_change_app_theme">Choose from a variety of themes</string>
     <string name="settings_text_home_screen_apps">Home screen apps</string>
     <string name="settings_title">Preferences</string>
+    <string name="settings_use_slim_s_built_in_dialer">Use Slim\'s built-in dialer</string>
+    <string name="settings_faster_shortcut_to_your_calls">Faster shortcut to your calls</string>
+    <string name="settings_status_bar_when_switched">When switched on, you can still drag down from the top to reveal it</string>
+    <string name="settings_hide_status_bar">Hide status bar</string>
 
     <string name="settings_list_item_button_set_app">Set app</string>
     <string name="settings_list_item_text">Slot empty</string>
@@ -95,11 +99,10 @@
     <string name="setup_home_screenshot">Screenshot</string>
     <string name="setup_clock_type_text_description">This is also changeable in preferences. Whether you prefer a 12hr clock type or a 24hr clock type</string>
     <string name="setup_clock_type">Clock Type</string>
-    <string name="settings_use_slim_s_built_in_dialer">Use Slim\'s built-in dialer</string>
-    <string name="settings_faster_shortcut_to_your_calls">Faster shortcut to your calls</string>
 
 
     <!-- Content Description For Image Resources-->
     <string name="content_description_my_phone">My phone</string>
 
+
 </resources>