Skip to content

Commit

Permalink
Apply dynamic color
Browse files Browse the repository at this point in the history
  • Loading branch information
Domi04151309 committed Dec 26, 2023
1 parent 7370300 commit 8ff5716
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 55 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".Application"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_descriptor"
android:icon="@mipmap/ic_launcher"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/io/github/domi04151309/powerapp/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.domi04151309.powerapp

import com.google.android.material.color.DynamicColors

class Application : android.app.Application() {
override fun onCreate() {
super.onCreate()
DynamicColors.applyToActivitiesIfAvailable(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package io.github.domi04151309.powerapp.activities
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import io.github.domi04151309.powerapp.BuildConfig
import io.github.domi04151309.powerapp.R

class AboutActivity : AppCompatActivity() {
class AboutActivity : BaseActivity() {
companion object {
internal const val GITHUB_REPOSITORY: String = "Domi04151309/PowerApp"
private const val REPOSITORY_URL: String = "https://github.com/$GITHUB_REPOSITORY"
Expand All @@ -28,7 +27,7 @@ class AboutActivity : AppCompatActivity() {
class GeneralPreferenceFragment : PreferenceFragmentCompat() {
@Suppress("SameReturnValue")
private fun onIconsClicked(): Boolean {
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.about_icons)
.setItems(resources.getStringArray(R.array.about_icons_array)) { _, which ->
startActivity(
Expand All @@ -50,7 +49,7 @@ class AboutActivity : AppCompatActivity() {

@Suppress("SameReturnValue")
private fun onContributorsClicked(): Boolean {
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.about_privacy)
.setMessage(R.string.about_privacy_desc)
.setPositiveButton(android.R.string.ok) { _, _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.domi04151309.powerapp.activities

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.elevation.SurfaceColors

abstract class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val color = SurfaceColors.SURFACE_2.getColor(this)
window.statusBarColor = color
window.navigationBarColor = color
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.graphics.drawable.Drawable
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
Expand All @@ -16,7 +15,7 @@ import com.android.volley.toolbox.Volley
import io.github.domi04151309.powerapp.R
import org.json.JSONObject

class ContributorActivity : AppCompatActivity() {
class ContributorActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.github.domi04151309.powerapp.activities

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.github.domi04151309.powerapp.R

class LibraryActivity : AppCompatActivity() {
class LibraryActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.domi04151309.powerapp.activities

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.elevation.SurfaceColors
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import io.github.domi04151309.powerapp.R
import io.github.domi04151309.powerapp.adapters.SimpleListAdapter
Expand All @@ -18,7 +18,7 @@ import io.github.domi04151309.powerapp.interfaces.RecyclerViewHelperInterface
import java.io.DataOutputStream
import java.io.IOException

class MainActivity : AppCompatActivity(), RecyclerViewHelperInterface {
class MainActivity : BaseActivity(), RecyclerViewHelperInterface {
companion object {
private const val LIST_ITEM_SHUTDOWN = 1
private const val LIST_ITEM_REBOOT = 2
Expand All @@ -31,49 +31,52 @@ class MainActivity : AppCompatActivity(), RecyclerViewHelperInterface {
private const val LIST_ITEM_TURN_OFF_SCREEN = 9
}

private fun getListItems() = listOf(
SimpleListItem(
title = resources.getString(R.string.Shutdown),
icon = R.drawable.ic_round_shutdown
),
SimpleListItem(
title = resources.getString(R.string.Reboot),
icon = R.drawable.ic_round_reboot
),
SimpleListItem(
title = resources.getString(R.string.SafeMode),
icon = R.drawable.ic_round_safe_mode
),
SimpleListItem(
title = resources.getString(R.string.Recovery),
icon = R.drawable.ic_round_recovery
),
SimpleListItem(
title = resources.getString(R.string.Bootloader),
icon = R.drawable.ic_round_bootloader
),
SimpleListItem(
title = resources.getString(R.string.EDL),
icon = R.drawable.ic_round_edl
),
SimpleListItem(
title = resources.getString(R.string.SoftReboot),
icon = R.drawable.ic_round_soft_reboot
),
SimpleListItem(
title = resources.getString(R.string.SystemUI),
icon = R.drawable.ic_round_restart_system_ui
),
SimpleListItem(
title = resources.getString(R.string.ScreenOff),
icon = R.drawable.ic_round_screen_off
),
)
private fun getListItems() =
listOf(
SimpleListItem(
title = resources.getString(R.string.Shutdown),
icon = R.drawable.ic_round_shutdown,
),
SimpleListItem(
title = resources.getString(R.string.Reboot),
icon = R.drawable.ic_round_reboot,
),
SimpleListItem(
title = resources.getString(R.string.SafeMode),
icon = R.drawable.ic_round_safe_mode,
),
SimpleListItem(
title = resources.getString(R.string.Recovery),
icon = R.drawable.ic_round_recovery,
),
SimpleListItem(
title = resources.getString(R.string.Bootloader),
icon = R.drawable.ic_round_bootloader,
),
SimpleListItem(
title = resources.getString(R.string.EDL),
icon = R.drawable.ic_round_edl,
),
SimpleListItem(
title = resources.getString(R.string.SoftReboot),
icon = R.drawable.ic_round_soft_reboot,
),
SimpleListItem(
title = resources.getString(R.string.SystemUI),
icon = R.drawable.ic_round_restart_system_ui,
),
SimpleListItem(
title = resources.getString(R.string.ScreenOff),
icon = R.drawable.ic_round_screen_off,
),
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

window.statusBarColor = SurfaceColors.SURFACE_0.getColor(this)

findViewById<MaterialToolbar>(R.id.toolbar).setOnMenuItemClickListener {
startActivity(
Intent(
Expand Down Expand Up @@ -122,7 +125,7 @@ class MainActivity : AppCompatActivity(), RecyclerViewHelperInterface {
if (PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(P.CONFIRM_DIALOG, P.CONFIRM_DIALOG_DEFAULT)
) {
AlertDialog.Builder(this)
MaterialAlertDialogBuilder(this)
.setTitle(R.string.confirm_dialog)
.setMessage(R.string.confirm_dialog_summary)
.setPositiveButton(android.R.string.ok) { _, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package io.github.domi04151309.powerapp.activities

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.github.domi04151309.powerapp.R

class SettingsActivity : AppCompatActivity() {
class SettingsActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.domi04151309.powerapp.helpers

import android.app.AlertDialog
import android.content.Context
import android.util.Log
import android.widget.Toast
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import io.github.domi04151309.powerapp.R
import java.io.IOException

Expand All @@ -13,7 +13,7 @@ class PowerOptions(private val context: Context, private val dialog: Boolean = f
Runtime.getRuntime().exec(arrayOf("su", "-c", command)).waitFor()
} catch (exception: IOException) {
if (dialog) {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle(R.string.action_failed)
.setMessage(R.string.action_failed_summary)
.setPositiveButton(android.R.string.ok) { _, _ -> }
Expand Down

0 comments on commit 8ff5716

Please sign in to comment.