Skip to content

Commit

Permalink
Apply new layout selection to charging style
Browse files Browse the repository at this point in the history
  • Loading branch information
Domi04151309 committed Oct 26, 2020
1 parent 294e5bf commit fa34084
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ internal class P(val prefs: SharedPreferences) {
const val DISPLAY_COLOR_FINGERPRINT = "display_color_fingerprint"
const val DISPLAY_COLOR_EDGE_GLOW = "display_color_edge_glow"

const val CHARGING_STYLE = "charging_style"

const val USER_THEME_GOOGLE = "google"
const val USER_THEME_ONEPLUS = "oneplus"
const val USER_THEME_SAMSUNG = "samsung"
Expand All @@ -55,6 +57,10 @@ internal class P(val prefs: SharedPreferences) {
const val USER_THEME_JUNGLE = "jungle"
const val USER_THEME_WESTERN = "western"

const val CHARGING_STYLE_CIRCLE = "circle"
const val CHARGING_STYLE_FLASH = "flash"
const val CHARGING_STYLE_IOS = "ios"

const val ROOT_MODE_DEFAULT = false
const val POWER_SAVING_MODE_DEFAULT = false
const val USER_THEME_DEFAULT = USER_THEME_GOOGLE
Expand Down Expand Up @@ -85,5 +91,7 @@ internal class P(val prefs: SharedPreferences) {
const val DISPLAY_COLOR_MESSAGE_DEFAULT = -1
const val DISPLAY_COLOR_FINGERPRINT_DEFAULT = -1
const val DISPLAY_COLOR_EDGE_GLOW_DEFAULT = -1

const val CHARGING_STYLE_DEFAULT = CHARGING_STYLE_CIRCLE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ package io.github.domi04151309.alwayson.preferences
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.RadioButton
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.github.domi04151309.alwayson.R
import io.github.domi04151309.alwayson.adapters.LayoutListAdapter
import io.github.domi04151309.alwayson.helpers.P
import io.github.domi04151309.alwayson.objects.Theme

class ChargingLookActivity : AppCompatActivity() {

private var value: String = "circle"
private lateinit var prefs: SharedPreferences
private lateinit var preview: ImageView
private lateinit var circleBtn: RadioButton
private lateinit var flashBtn: RadioButton
private lateinit var iosBtn: RadioButton
internal var value: String = P.CHARGING_STYLE_DEFAULT
internal lateinit var preview: ImageView
private lateinit var layoutList: RecyclerView

override fun onCreate(savedInstanceState: Bundle?) {
Theme.set(this)
Expand All @@ -25,47 +28,68 @@ class ChargingLookActivity : AppCompatActivity() {

prefs = PreferenceManager.getDefaultSharedPreferences(this)
preview = findViewById(R.id.preview)
circleBtn = findViewById(R.id.circleBtn)
flashBtn = findViewById(R.id.flashBtn)
iosBtn = findViewById(R.id.iosBtn)
layoutList = findViewById(R.id.layout_list)

circleBtn.setOnClickListener{
preview.setImageResource(R.drawable.charging_0)
value = "circle"
}

flashBtn.setOnClickListener{
preview.setImageResource(R.drawable.charging_1)
value = "flash"
}

iosBtn.setOnClickListener{
preview.setImageResource(R.drawable.charging_2)
value = "ios"
layoutList.layoutManager = LinearLayoutManager(this).apply {
orientation = LinearLayoutManager.HORIZONTAL
}
layoutList.adapter = LayoutListAdapter(
this,
arrayOf(
ContextCompat.getDrawable(this, R.drawable.charging_circle),
ContextCompat.getDrawable(this, R.drawable.charging_flash),
ContextCompat.getDrawable(this, R.drawable.charging_ios)
),
resources.getStringArray(R.array.pref_look_and_feel_charging_array_display),
object : LayoutListAdapter.OnItemClickListener {
override fun onItemClick(view: View, position: Int) {
when (position) {
ITEM_CIRCLE -> {
preview.setImageResource(R.drawable.charging_circle)
value = P.CHARGING_STYLE_CIRCLE
}
ITEM_FLASH -> {
preview.setImageResource(R.drawable.charging_flash)
value = P.CHARGING_STYLE_FLASH
}
ITEM_IOS -> {
preview.setImageResource(R.drawable.charging_ios)
value = P.CHARGING_STYLE_IOS
}
}
}
}
)
}

override fun onStart() {
super.onStart()
value = prefs.getString("charging_style", "circle") ?:"circle"
value = prefs.getString(P.CHARGING_STYLE, P.CHARGING_STYLE_DEFAULT) ?: P.CHARGING_STYLE_DEFAULT
val adapter = layoutList.adapter as LayoutListAdapter
when (value) {
"circle" -> {
preview.setImageResource(R.drawable.charging_0)
circleBtn.isChecked = true
P.CHARGING_STYLE_CIRCLE -> {
preview.setImageResource(R.drawable.charging_circle)
adapter.setSelectedItem(ITEM_CIRCLE)
}
"flash" -> {
preview.setImageResource(R.drawable.charging_1)
flashBtn.isChecked = true
P.CHARGING_STYLE_FLASH -> {
preview.setImageResource(R.drawable.charging_flash)
adapter.setSelectedItem(ITEM_FLASH)
}
"ios" -> {
preview.setImageResource(R.drawable.charging_2)
iosBtn.isChecked = true
P.CHARGING_STYLE_IOS -> {
preview.setImageResource(R.drawable.charging_ios)
adapter.setSelectedItem(ITEM_IOS)
}
}
}

override fun onStop() {
super.onStop()
prefs.edit().putString("charging_style", value).apply()
prefs.edit().putString(P.CHARGING_STYLE, value).apply()
}

companion object {
private const val ITEM_CIRCLE = 0
private const val ITEM_FLASH = 1
private const val ITEM_IOS = 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.github.domi04151309.alwayson.R
import io.github.domi04151309.alwayson.helpers.P
import io.github.domi04151309.alwayson.objects.Theme

class LAFOtherPreferences : AppCompatActivity(),
Expand Down Expand Up @@ -41,7 +42,7 @@ class LAFOtherPreferences : AppCompatActivity(),
startActivity(Intent(context, Preferences::class.java))
true
}
findPreference<Preference>("charging_style")?.setOnPreferenceClickListener {
findPreference<Preference>(P.CHARGING_STYLE)?.setOnPreferenceClickListener {
startActivity(Intent(context, ChargingLookActivity::class.java))
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.github.domi04151309.alwayson.alwayson.AlwaysOn
import io.github.domi04151309.alwayson.charging.Circle
import io.github.domi04151309.alwayson.charging.Flash
import io.github.domi04151309.alwayson.charging.IOS
import io.github.domi04151309.alwayson.helpers.P
import io.github.domi04151309.alwayson.helpers.Rules
import io.github.domi04151309.alwayson.objects.Global

Expand Down Expand Up @@ -38,10 +39,11 @@ class CombinedServiceReceiver : BroadcastReceiver() {
if (prefs.getBoolean("charging_animation", false)) {
if (!isScreenOn || isAlwaysOnRunning) {
if (isAlwaysOnRunning) LocalBroadcastManager.getInstance(c).sendBroadcast(Intent(Global.REQUEST_STOP))
val i: Intent = when (prefs.getString("charging_style", "circle")) {
"ios" -> Intent(c, IOS::class.java)
"circle" -> Intent(c, Circle::class.java)
else -> Intent(c, Flash::class.java)
val i: Intent = when (prefs.getString(P.CHARGING_STYLE, P.CHARGING_STYLE_DEFAULT) ?: P.CHARGING_STYLE_DEFAULT) {
P.CHARGING_STYLE_CIRCLE -> Intent(c, Circle::class.java)
P.CHARGING_STYLE_FLASH -> Intent(c, Flash::class.java)
P.CHARGING_STYLE_IOS -> Intent(c, IOS::class.java)
else -> return
}
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
c.startActivity(i)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_ao_look.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
app:srcCompat="@drawable/always_on_google"
android:contentDescription="@string/AlwaysOn" />


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/layout_list"
android:layout_width="match_parent"
Expand Down
30 changes: 6 additions & 24 deletions app/src/main/res/layout/activity_charging_look.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,16 @@
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/radio"
android:layout_above="@id/layout_list"
android:padding="?dialogPreferredPadding"
app:srcCompat="@drawable/charging_0"
app:srcCompat="@drawable/charging_circle"
android:contentDescription="@string/Charging" />

<RadioGroup
android:id="@+id/radio"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/layout_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="?dialogPreferredPadding">

<RadioButton
android:id="@+id/circleBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pref_look_and_feel_charging_array_display_0"/>

<RadioButton
android:id="@+id/flashBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pref_look_and_feel_charging_array_display_1"/>

<RadioButton
android:id="@+id/iosBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pref_look_and_feel_charging_array_display_2"/>
</RadioGroup>
android:scrollbars="horizontal"
android:fadeScrollbars="false"/>
</RelativeLayout>
3 changes: 0 additions & 3 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@

<string name="pref_look_and_feel_charging">Aussehen der Ladeanimation</string>
<string name="pref_look_and_feel_charging_summary">Ändert das Aussehen der Ladeanimation</string>
<string name="pref_look_and_feel_charging_array_display_0">Kreis Stil</string>
<string name="pref_look_and_feel_charging_array_display_1">Blitz Stil</string>
<string name="pref_look_and_feel_charging_array_display_2">iOS Stil</string>
<string name="pref_look_and_feel_hide_display_cutouts">Bildschirmausschnitte ausblenden</string>
<string name="pref_look_and_feel_hide_display_cutouts_summary">Verstecken von Bildschirmausschnitten im Vollbildmodus</string>
<string name="pref_look_and_feel_orientation">Drehung</string>
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@

<string name="pref_look_and_feel_charging">Mirada de animación de carga</string>
<string name="pref_look_and_feel_charging_summary">Cambia el aspecto de la animación de carga</string>
<string name="pref_look_and_feel_charging_array_display_0">Estilo Círculo</string>
<string name="pref_look_and_feel_charging_array_display_1">Estilo Flash</string>
<string name="pref_look_and_feel_charging_array_display_2">Estilo iOS</string>
<string name="pref_look_and_feel_hide_display_cutouts">Ocultar los recortes de la pantalla</string>
<string name="pref_look_and_feel_hide_display_cutouts_summary">Ocultar recortes de pantalla en el contenido de la pantalla completa</string>
<string name="pref_look_and_feel_orientation">Orientación</string>
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@

<string name="pref_look_and_feel_charging">Oplaadanimatiestijl</string>
<string name="pref_look_and_feel_charging_summary">Pas de stijl aan van de oplaadanimatie</string>
<string name="pref_look_and_feel_charging_array_display_0">Cirkelstijl</string>
<string name="pref_look_and_feel_charging_array_display_1">Knipperstijl</string>
<string name="pref_look_and_feel_charging_array_display_2">iOS-stijl</string>
<string name="pref_look_and_feel_hide_display_cutouts">Scherminkepingen verbergen</string>
<string name="pref_look_and_feel_hide_display_cutouts_summary">Verberg scherminkepingen bij beeldvullende inhoud</string>

Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@

<string name="pref_look_and_feel_charging">Вид анимации зарядки</string>
<string name="pref_look_and_feel_charging_summary">Изменяет внешний вид анимации зарядки</string>
<string name="pref_look_and_feel_charging_array_display_0">Круг</string>
<string name="pref_look_and_feel_charging_array_display_1">Молния</string>
<string name="pref_look_and_feel_charging_array_display_2">iOS</string>
<string name="pref_look_and_feel_hide_display_cutouts">Скрыть вырезы на дисплее</string>
<string name="pref_look_and_feel_hide_display_cutouts_summary">Скрыть вырезы в полноэкранном контенте</string>

Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@

<string name="pref_look_and_feel_charging">Charging animation look</string>
<string name="pref_look_and_feel_charging_summary">Changes the look of the charging animation</string>
<string name="pref_look_and_feel_charging_array_display_0">Circle style</string>
<string name="pref_look_and_feel_charging_array_display_1">Flash style</string>
<string name="pref_look_and_feel_charging_array_display_2">iOS style</string>
<string-array name="pref_look_and_feel_charging_array_display">
<item>Circle</item>
<item>Flash</item>
<item>iOS</item>
</string-array>
<string name="pref_look_and_feel_hide_display_cutouts">Hide display cutouts</string>
<string name="pref_look_and_feel_hide_display_cutouts_summary">Hide display cutouts on fullscreen content</string>
<string name="pref_look_and_feel_orientation">Orientation</string>
Expand Down

0 comments on commit fa34084

Please sign in to comment.