mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 04:25:33 -04:00
universal7885: parts: Follow Android 12 style
* Use more Settingslib classes and resource layouts Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
parent
723dfbec38
commit
419f6646a3
14 changed files with 89 additions and 459 deletions
|
|
@ -13,10 +13,18 @@ using vendor::eureka::hardware::parts::V1_0::Value;
|
||||||
|
|
||||||
static android::sp<IFlashBrightness> service = IFlashBrightness::getService();
|
static android::sp<IFlashBrightness> service = IFlashBrightness::getService();
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL
|
||||||
|
Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash(JNIEnv *env, __unused jobject obj, jboolean enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
service->setFlashlightEnable(Number::ENABLE);
|
||||||
|
} else {
|
||||||
|
service->setFlashlightEnable(Number::DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL
|
extern "C" JNIEXPORT void JNICALL
|
||||||
Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash(
|
Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash(
|
||||||
JNIEnv *env, __unused jobject obj, jint value) {
|
JNIEnv *env, __unused jobject obj, jint value) {
|
||||||
service->setFlashlightEnable(Number::ENABLE);
|
|
||||||
service->setFlashlightWritable(static_cast<Value>(value));
|
service->setFlashlightWritable(static_cast<Value>(value));
|
||||||
}
|
}
|
||||||
extern "C" JNIEXPORT jint JNICALL
|
extern "C" JNIEXPORT jint JNICALL
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/fastcharge_title">
|
android:title="@string/fastcharge_title">
|
||||||
|
|
||||||
<SwitchPreference
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
android:key="fastcharge_pref"
|
android:key="fastcharge_pref"
|
||||||
android:title="@string/fastcharge_2nd_title"
|
android:title="@string/fastcharge_2nd_title"
|
||||||
android:icon="@drawable/ic_bolt"
|
android:icon="@drawable/ic_bolt"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/clear_speaker_title">
|
android:title="@string/clear_speaker_title">
|
||||||
|
|
||||||
<SwitchPreference
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
android:key="clear_speaker_pref"
|
android:key="clear_speaker_pref"
|
||||||
android:title="@string/clear_speaker_title"
|
android:title="@string/clear_speaker_title"
|
||||||
android:icon="@drawable/ic_sound"
|
android:icon="@drawable/ic_sound"
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,6 @@
|
||||||
android:key="dolby_enable"
|
android:key="dolby_enable"
|
||||||
android:title="@string/dolby_enable_title" />
|
android:title="@string/dolby_enable_title" />
|
||||||
|
|
||||||
<com.android.settingslib.widget.TopIntroPreference
|
|
||||||
android:key="dolby_top_intro"
|
|
||||||
android:title="@string/dolby_top_intro_summary" />
|
|
||||||
|
|
||||||
<com.android.settingslib.widget.RadioButtonPreference
|
<com.android.settingslib.widget.RadioButtonPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="dolby_profile_auto"
|
android:key="dolby_profile_auto"
|
||||||
|
|
@ -47,6 +43,10 @@
|
||||||
|
|
||||||
<com.android.settingslib.widget.RadioButtonPreference
|
<com.android.settingslib.widget.RadioButtonPreference
|
||||||
android:key="dolby_profile_voice"
|
android:key="dolby_profile_voice"
|
||||||
android:title="@string/dolby_profile_voice" />
|
android:title="@string/dolby_profile_voice"/>
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.FooterPreference
|
||||||
|
android:key="dolby_top_intro"
|
||||||
|
android:title="@string/dolby_top_intro_summary" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,12 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/flashlight_title">
|
android:title="@string/flashlight_title">
|
||||||
|
|
||||||
<com.eurekateam.samsungextras.preferences.CustomSeekBarPreference
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="flashlight_enable"
|
||||||
|
android:title="@string/flash_enable_title" />
|
||||||
|
|
||||||
|
<SeekBarPreference
|
||||||
android:key="flashlight_pref"
|
android:key="flashlight_pref"
|
||||||
android:title="@string/flashlight_title"
|
android:title="@string/flashlight_title"
|
||||||
android:icon="@drawable/ic_led"
|
android:icon="@drawable/ic_led"
|
||||||
|
|
|
||||||
|
|
@ -15,30 +15,17 @@
|
||||||
*/
|
*/
|
||||||
package com.eurekateam.samsungextras.battery
|
package com.eurekateam.samsungextras.battery
|
||||||
|
|
||||||
import android.R.id.content
|
|
||||||
import android.R.id.home
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
|
||||||
import androidx.fragment.app.FragmentActivity
|
|
||||||
|
|
||||||
class BatteryActivity : FragmentActivity() {
|
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
|
||||||
|
import com.android.settingslib.collapsingtoolbar.R
|
||||||
|
|
||||||
|
class BatteryActivity : CollapsingToolbarBaseActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val fragment = supportFragmentManager.findFragmentById(content)
|
supportFragmentManager.beginTransaction().replace(
|
||||||
val batteryFragment: BatteryFragment
|
R.id.content_frame,
|
||||||
if (fragment == null) {
|
BatteryFragment()
|
||||||
batteryFragment = BatteryFragment()
|
).commit()
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.add(content, batteryFragment)
|
|
||||||
.commit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
if (item.itemId == home) {
|
|
||||||
finish()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ import androidx.preference.PreferenceManager
|
||||||
import androidx.preference.SwitchPreference
|
import androidx.preference.SwitchPreference
|
||||||
import com.eurekateam.samsungextras.R
|
import com.eurekateam.samsungextras.R
|
||||||
import com.eurekateam.samsungextras.interfaces.Battery
|
import com.eurekateam.samsungextras.interfaces.Battery
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener
|
||||||
|
|
||||||
class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
|
||||||
private lateinit var mFastChargePref: SwitchPreference
|
private lateinit var mFastChargePref: MainSwitchPreference
|
||||||
private lateinit var mChargePref: SwitchPreference
|
private lateinit var mChargePref: SwitchPreference
|
||||||
private lateinit var mSharedPreferences: SharedPreferences
|
private lateinit var mSharedPreferences: SharedPreferences
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
|
|
@ -65,15 +67,15 @@ class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
mChargePref.isChecked = Battery.chargeSysfs == 0
|
mChargePref.isChecked = Battery.chargeSysfs == 0
|
||||||
mSharedPreferences.edit().putBoolean(PREF_CHARGE, Battery.chargeSysfs == 0).apply()
|
mSharedPreferences.edit().putBoolean(PREF_CHARGE, Battery.chargeSysfs == 0).apply()
|
||||||
return true
|
return true
|
||||||
} else if (preference === mFastChargePref) {
|
|
||||||
val value = newValue as Boolean
|
|
||||||
Battery.setFastCharge(if (value) 0 else 1)
|
|
||||||
mFastChargePref.isChecked = Battery.fastChargeSysfs == 0
|
|
||||||
mSharedPreferences.edit().putBoolean(PREF_FASTCHARGE, Battery.fastChargeSysfs == 0).apply()
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
|
||||||
|
Battery.setFastCharge(if (isChecked) 0 else 1)
|
||||||
|
mFastChargePref.isChecked = Battery.fastChargeSysfs
|
||||||
|
== 0
|
||||||
|
mSharedPreferences.edit().putBoolean(PREF_FASTCHARGE, Battery.fastChargeSysfs == 0).apply()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PREF_FASTCHARGE = "fastcharge_pref"
|
const val PREF_FASTCHARGE = "fastcharge_pref"
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,15 @@
|
||||||
|
|
||||||
package com.eurekateam.samsungextras.dolby
|
package com.eurekateam.samsungextras.dolby
|
||||||
|
|
||||||
import android.R.id.content
|
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
|
||||||
import android.os.Bundle
|
import com.android.settingslib.collapsingtoolbar.R
|
||||||
import androidx.fragment.app.FragmentActivity
|
|
||||||
|
|
||||||
class DolbyActivity : FragmentActivity() {
|
class DolbyActivity : CollapsingToolbarBaseActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val fragment = this.supportFragmentManager.findFragmentById(content)
|
fragmentManager.beginTransaction().replace(
|
||||||
val dolbyFragment: DolbyFragment
|
R.id.content_frame,
|
||||||
if (fragment == null) {
|
DolbyFragment()
|
||||||
dolbyFragment = DolbyFragment()
|
).commit()
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.add(content, dolbyFragment)
|
|
||||||
.commit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,30 +15,17 @@
|
||||||
*/
|
*/
|
||||||
package com.eurekateam.samsungextras.flashlight
|
package com.eurekateam.samsungextras.flashlight
|
||||||
|
|
||||||
import android.R.id.content
|
|
||||||
import android.R.id.home
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
|
||||||
import androidx.fragment.app.FragmentActivity
|
|
||||||
|
|
||||||
class FlashLightActivity : FragmentActivity() {
|
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
import com.android.settingslib.collapsingtoolbar.R
|
||||||
|
|
||||||
|
class FlashLightActivity : CollapsingToolbarBaseActivity() {
|
||||||
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val fragment = supportFragmentManager.findFragmentById(content)
|
supportFragmentManager.beginTransaction().replace(
|
||||||
val flashLightFragment: FlashLightFragment
|
R.id.content_frame,
|
||||||
if (fragment == null) {
|
FlashLightFragment()
|
||||||
flashLightFragment = FlashLightFragment()
|
).commit()
|
||||||
this.supportFragmentManager.beginTransaction()
|
|
||||||
.add(content, flashLightFragment)
|
|
||||||
.commit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
if (item.itemId == home) {
|
|
||||||
finish()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,14 @@ import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.eurekateam.samsungextras.R
|
import com.eurekateam.samsungextras.R
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener
|
||||||
import com.eurekateam.samsungextras.interfaces.Flashlight
|
import com.eurekateam.samsungextras.interfaces.Flashlight
|
||||||
import com.eurekateam.samsungextras.preferences.CustomSeekBarPreference
|
|
||||||
|
|
||||||
class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
|
||||||
private lateinit var mFlashLightPref: CustomSeekBarPreference
|
private lateinit var mFlashLightPref: SeekBarPreference
|
||||||
private lateinit var mSharedPreferences: SharedPreferences
|
private lateinit var mSharedPreferences: SharedPreferences
|
||||||
|
private lateinit var mFlashLightEnable : MainSwitchPreference
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
addPreferencesFromResource(R.xml.flashlight_settings)
|
addPreferencesFromResource(R.xml.flashlight_settings)
|
||||||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
|
|
@ -36,6 +38,10 @@ class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceCh
|
||||||
mFlashLightPref.setMax(10)
|
mFlashLightPref.setMax(10)
|
||||||
mFlashLightPref.setMin(1)
|
mFlashLightPref.setMin(1)
|
||||||
mFlashLightPref.value = Flashlight.getFlash(if (Build.DEVICE.contains("a10")) 1 else 0)
|
mFlashLightPref.value = Flashlight.getFlash(if (Build.DEVICE.contains("a10")) 1 else 0)
|
||||||
|
mFlashLightEnable = findPreference(PREF_FLASHLIGHT_ENABLE)!!
|
||||||
|
mFlashLightEnable.isChecked = mSharedPreferences.getBoolean(PREF_FLASHLIGHT_ENABLE, true)
|
||||||
|
mFlashLightEnable.addOnSwitchChangeListener(this)
|
||||||
|
mFlashLightPref.isEnabled = mFlashLightEnable.isChecked
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
||||||
|
|
@ -45,10 +51,17 @@ class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceCh
|
||||||
mSharedPreferences.edit().putInt(PREF_FLASHLIGHT, value).apply()
|
mSharedPreferences.edit().putInt(PREF_FLASHLIGHT, value).apply()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
|
||||||
|
Flashlight.setEnabled(isChecked)
|
||||||
|
mSharedPreferences.edit().putBoolean(PREF_FLASHLIGHT_ENABLE, isChecked)
|
||||||
|
mFlashLightPref.isEnabled = isChecked
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PREF_FLASHLIGHT = "flashlight_pref"
|
const val PREF_FLASHLIGHT = "flashlight_pref"
|
||||||
|
const val PREF_FLASHLIGHT_ENABLE = "flashlight_enable"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,5 @@ package com.eurekateam.samsungextras.interfaces
|
||||||
object Flashlight {
|
object Flashlight {
|
||||||
external fun setFlash(value: Int)
|
external fun setFlash(value: Int)
|
||||||
external fun getFlash(isA10: Int): Int
|
external fun getFlash(isA10: Int): Int
|
||||||
|
external fun setEnabled(enable: Boolean)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,348 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2022 Eureka Team
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.eurekateam.samsungextras.preferences
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.PorterDuff
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
|
||||||
import android.view.View.OnLongClickListener
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.SeekBar
|
|
||||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
|
||||||
import android.widget.TextView
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.core.content.res.TypedArrayUtils
|
|
||||||
import androidx.preference.Preference
|
|
||||||
import androidx.preference.PreferenceViewHolder
|
|
||||||
import androidx.preference.R
|
|
||||||
|
|
||||||
open class CustomSeekBarPreference @JvmOverloads constructor(
|
|
||||||
context: Context,
|
|
||||||
attrs: AttributeSet? = null,
|
|
||||||
defStyleAttr: Int = TypedArrayUtils.getAttr(
|
|
||||||
context,
|
|
||||||
R.attr.preferenceStyle,
|
|
||||||
android.R.attr.preferenceStyle
|
|
||||||
),
|
|
||||||
defStyleRes: Int = 0
|
|
||||||
) : Preference(context, attrs, defStyleAttr, defStyleRes),
|
|
||||||
OnSeekBarChangeListener,
|
|
||||||
View.OnClickListener,
|
|
||||||
OnLongClickListener {
|
|
||||||
private val TAG: String = javaClass.name
|
|
||||||
private var mInterval = 1
|
|
||||||
private var mShowSign = false
|
|
||||||
private var mUnits = ""
|
|
||||||
private var mContinuousUpdates = false
|
|
||||||
private var mMinValue = 1
|
|
||||||
private var mMaxValue = 256
|
|
||||||
private var mDefaultValueExists: Boolean
|
|
||||||
private var mDefaultValue = 0
|
|
||||||
private var mValue = 0
|
|
||||||
private var mValueTextView: TextView? = null
|
|
||||||
private var mResetImageView: ImageView? = null
|
|
||||||
private var mMinusImageView: ImageView? = null
|
|
||||||
private var mPlusImageView: ImageView? = null
|
|
||||||
private var mSeekBar: SeekBar
|
|
||||||
private var mTrackingTouch = false
|
|
||||||
private var mTrackingValue = 0
|
|
||||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
|
||||||
super.onBindViewHolder(holder)
|
|
||||||
try {
|
|
||||||
// move our seekbar to the new view we've been given
|
|
||||||
val oldContainer = mSeekBar.parent
|
|
||||||
val newContainer =
|
|
||||||
holder.findViewById(com.eurekateam.samsungextras.R.id.seekbar) as ViewGroup
|
|
||||||
if (oldContainer !== newContainer) {
|
|
||||||
// remove the seekbar from the old view
|
|
||||||
if (oldContainer != null) {
|
|
||||||
(oldContainer as ViewGroup).removeView(mSeekBar)
|
|
||||||
}
|
|
||||||
// remove the existing seekbar (there may not be one) and add ours
|
|
||||||
newContainer.removeAllViews()
|
|
||||||
newContainer.addView(
|
|
||||||
mSeekBar, ViewGroup.LayoutParams.MATCH_PARENT,
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} catch (ex: Exception) {
|
|
||||||
Log.e(TAG, "Error binding view: $ex")
|
|
||||||
}
|
|
||||||
mSeekBar.max = getSeekValue(mMaxValue)
|
|
||||||
mSeekBar.progress = getSeekValue(mValue)
|
|
||||||
mSeekBar.isEnabled = isEnabled
|
|
||||||
mValueTextView = holder.findViewById(com.eurekateam.samsungextras.R.id.value) as TextView
|
|
||||||
mResetImageView = holder.findViewById(com.eurekateam.samsungextras.R.id.reset) as ImageView
|
|
||||||
mMinusImageView = holder.findViewById(com.eurekateam.samsungextras.R.id.minus) as ImageView
|
|
||||||
mPlusImageView = holder.findViewById(com.eurekateam.samsungextras.R.id.plus) as ImageView
|
|
||||||
updateValueViews()
|
|
||||||
mSeekBar.setOnSeekBarChangeListener(this)
|
|
||||||
mResetImageView!!.setOnClickListener(this)
|
|
||||||
mMinusImageView!!.setOnClickListener(this)
|
|
||||||
mPlusImageView!!.setOnClickListener(this)
|
|
||||||
mResetImageView!!.onLongClickListener = this
|
|
||||||
mMinusImageView!!.onLongClickListener = this
|
|
||||||
mPlusImageView!!.onLongClickListener = this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getLimitedValue(v: Int): Int {
|
|
||||||
return if (v < mMinValue) mMinValue else v.coerceAtMost(mMaxValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSeekValue(v: Int): Int {
|
|
||||||
return -Math.floorDiv(mMinValue - v, mInterval)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getTextValue(v: Int): String {
|
|
||||||
return (if (mShowSign && v > 0) "+" else "") + v + mUnits
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateValueViews() {
|
|
||||||
if (mValueTextView != null) {
|
|
||||||
mValueTextView!!.text = context.getString(
|
|
||||||
com.eurekateam.samsungextras.R.string.custom_seekbar_value,
|
|
||||||
if (!mTrackingTouch || mContinuousUpdates) getTextValue(mValue) +
|
|
||||||
(
|
|
||||||
if (mDefaultValueExists && mValue == mDefaultValue) " (" +
|
|
||||||
context.getString(com.eurekateam.samsungextras.R.string.custom_seekbar_default_value) + ")" else ""
|
|
||||||
) else getTextValue(
|
|
||||||
mTrackingValue
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (mResetImageView != null) {
|
|
||||||
if (!mDefaultValueExists || mValue == mDefaultValue || mTrackingTouch) mResetImageView!!.visibility =
|
|
||||||
View.INVISIBLE else mResetImageView!!.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
if (mMinusImageView != null) {
|
|
||||||
if (mValue == mMinValue || mTrackingTouch) {
|
|
||||||
mMinusImageView!!.isClickable = false
|
|
||||||
mMinusImageView!!.setColorFilter(
|
|
||||||
context.getColor(com.eurekateam.samsungextras.R.color.disabled_text_color),
|
|
||||||
PorterDuff.Mode.MULTIPLY
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
mMinusImageView!!.isClickable = true
|
|
||||||
mMinusImageView!!.clearColorFilter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mPlusImageView != null) {
|
|
||||||
if (mValue == mMaxValue || mTrackingTouch) {
|
|
||||||
mPlusImageView!!.isClickable = false
|
|
||||||
mPlusImageView!!.setColorFilter(
|
|
||||||
context.getColor(com.eurekateam.samsungextras.R.color.disabled_text_color),
|
|
||||||
PorterDuff.Mode.MULTIPLY
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
mPlusImageView!!.isClickable = true
|
|
||||||
mPlusImageView!!.clearColorFilter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun changeValue() {
|
|
||||||
// for subclasses
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
|
||||||
val newValue = getLimitedValue(mMinValue + progress * mInterval)
|
|
||||||
if (mTrackingTouch && !mContinuousUpdates) {
|
|
||||||
mTrackingValue = newValue
|
|
||||||
updateValueViews()
|
|
||||||
} else if (mValue != newValue) {
|
|
||||||
// change rejected, revert to the previous value
|
|
||||||
if (!callChangeListener(newValue)) {
|
|
||||||
mSeekBar.progress = getSeekValue(mValue)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// change accepted, store it
|
|
||||||
changeValue()
|
|
||||||
persistInt(newValue)
|
|
||||||
mValue = newValue
|
|
||||||
updateValueViews()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
|
||||||
mTrackingValue = mValue
|
|
||||||
mTrackingTouch = true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
|
||||||
mTrackingTouch = false
|
|
||||||
if (!mContinuousUpdates) onProgressChanged(mSeekBar, getSeekValue(mTrackingValue), false)
|
|
||||||
notifyChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
|
||||||
when (v.id) {
|
|
||||||
com.eurekateam.samsungextras.R.id.reset -> {
|
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
context.getString(
|
|
||||||
com.eurekateam.samsungextras.R.string.custom_seekbar_default_value_to_set,
|
|
||||||
getTextValue(mDefaultValue)
|
|
||||||
),
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
com.eurekateam.samsungextras.R.id.minus -> {
|
|
||||||
setValue(mValue - mInterval, true)
|
|
||||||
}
|
|
||||||
com.eurekateam.samsungextras.R.id.plus -> {
|
|
||||||
setValue(mValue + mInterval, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLongClick(v: View): Boolean {
|
|
||||||
when (v.id) {
|
|
||||||
com.eurekateam.samsungextras.R.id.reset -> {
|
|
||||||
setValue(mDefaultValue, true)
|
|
||||||
}
|
|
||||||
com.eurekateam.samsungextras.R.id.minus -> {
|
|
||||||
setValue(
|
|
||||||
if (mMaxValue - mMinValue > mInterval * 2 && mMaxValue + mMinValue < mValue * 2) Math.floorDiv(
|
|
||||||
mMaxValue + mMinValue,
|
|
||||||
2
|
|
||||||
) else mMinValue,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
com.eurekateam.samsungextras.R.id.plus -> {
|
|
||||||
setValue(
|
|
||||||
if (mMaxValue - mMinValue > mInterval * 2 && mMaxValue + mMinValue > mValue * 2) -1 * Math.floorDiv(
|
|
||||||
-1 * (mMaxValue + mMinValue),
|
|
||||||
2
|
|
||||||
) else mMaxValue,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// dont need too much shit about initial and default values
|
|
||||||
// its all done in constructor already
|
|
||||||
override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) {
|
|
||||||
if (restoreValue) mValue = getPersistedInt(mValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setDefaultValue(defaultValue: Any) {
|
|
||||||
if (defaultValue is Int) setDefaultValue(
|
|
||||||
defaultValue,
|
|
||||||
true
|
|
||||||
) else setDefaultValue(
|
|
||||||
defaultValue.toString(), true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setDefaultValue(newValue: Int, update: Boolean) {
|
|
||||||
var mNewValue = newValue
|
|
||||||
mNewValue = getLimitedValue(mNewValue)
|
|
||||||
if (!mDefaultValueExists || mDefaultValue != mNewValue) {
|
|
||||||
mDefaultValueExists = true
|
|
||||||
mDefaultValue = mNewValue
|
|
||||||
if (update) updateValueViews()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setDefaultValue(newValue: String?, update: Boolean) {
|
|
||||||
if (mDefaultValueExists && (newValue == null || newValue.isEmpty())) {
|
|
||||||
mDefaultValueExists = false
|
|
||||||
if (update) updateValueViews()
|
|
||||||
} else if (newValue != null && newValue.isNotEmpty()) {
|
|
||||||
setDefaultValue(newValue.toInt(), update)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setMax(max: Int) {
|
|
||||||
mMaxValue = max
|
|
||||||
mSeekBar.max = mMaxValue - mMinValue
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setMin(min: Int) {
|
|
||||||
mMinValue = min
|
|
||||||
mSeekBar.max = mMaxValue - mMinValue
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setValue(newValue: Int, update: Boolean) {
|
|
||||||
var mNewValue = newValue
|
|
||||||
mNewValue = getLimitedValue(mNewValue)
|
|
||||||
if (mValue != mNewValue) {
|
|
||||||
if (update) mSeekBar.progress = getSeekValue(mNewValue) else mValue = mNewValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// need some methods here to set/get other attrs at runtime,
|
|
||||||
var value: Int
|
|
||||||
get() = mValue
|
|
||||||
set(newValue) {
|
|
||||||
mValue = getLimitedValue(newValue)
|
|
||||||
mSeekBar.progress = getSeekValue(mValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
// but who really need this ...
|
|
||||||
companion object {
|
|
||||||
private const val APP_NS = "http://schemas.android.com/apk/res-auto"
|
|
||||||
protected const val ANDROIDNS = "http://schemas.android.com/apk/res/android"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val a = context.obtainStyledAttributes(
|
|
||||||
attrs,
|
|
||||||
com.eurekateam.samsungextras.R.styleable.CustomSeekBarPreference
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
mShowSign = a.getBoolean(
|
|
||||||
com.eurekateam.samsungextras.R.styleable.CustomSeekBarPreference_showSign,
|
|
||||||
mShowSign
|
|
||||||
)
|
|
||||||
val units =
|
|
||||||
a.getString(com.eurekateam.samsungextras.R.styleable.CustomSeekBarPreference_units)
|
|
||||||
if (units != null) mUnits = " $units"
|
|
||||||
mContinuousUpdates = a.getBoolean(
|
|
||||||
com.eurekateam.samsungextras.R.styleable.CustomSeekBarPreference_continuousUpdates,
|
|
||||||
mContinuousUpdates
|
|
||||||
)
|
|
||||||
} finally {
|
|
||||||
a.recycle()
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
val newInterval = attrs!!.getAttributeValue(APP_NS, "interval")
|
|
||||||
if (newInterval != null) mInterval = newInterval.toInt()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Invalid interval value", e)
|
|
||||||
}
|
|
||||||
mMinValue = attrs!!.getAttributeIntValue(APP_NS, "min", mMinValue)
|
|
||||||
mMaxValue = attrs.getAttributeIntValue(ANDROIDNS, "max", mMaxValue)
|
|
||||||
if (mMaxValue < mMinValue) mMaxValue = mMinValue
|
|
||||||
val defaultValue = attrs.getAttributeValue(ANDROIDNS, "defaultValue")
|
|
||||||
mDefaultValueExists = defaultValue != null && defaultValue.isNotEmpty()
|
|
||||||
if (mDefaultValueExists) {
|
|
||||||
mDefaultValue = getLimitedValue(defaultValue!!.toInt())
|
|
||||||
mValue = mDefaultValue
|
|
||||||
} else {
|
|
||||||
mValue = mMinValue
|
|
||||||
}
|
|
||||||
mSeekBar = SeekBar(context, attrs)
|
|
||||||
layoutResource = com.eurekateam.samsungextras.R.layout.preference_custom_seekbar
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -15,30 +15,15 @@
|
||||||
*/
|
*/
|
||||||
package com.eurekateam.samsungextras.speaker
|
package com.eurekateam.samsungextras.speaker
|
||||||
|
|
||||||
import android.R.id.content
|
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
|
||||||
import android.R.id.home
|
import com.android.settingslib.collapsingtoolbar.R
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.MenuItem
|
|
||||||
import androidx.fragment.app.FragmentActivity
|
|
||||||
|
|
||||||
class ClearSpeakerActivity : FragmentActivity() {
|
class ClearSpeakerActivity : CollapsingToolbarBaseActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val fragment = supportFragmentManager.findFragmentById(content)
|
supportFragmentManager.beginTransaction().replace(
|
||||||
val clearSpeakerFragment: ClearSpeakerFragment
|
R.id.content_frame,
|
||||||
if (fragment == null) {
|
ClearSpeakerFragment()
|
||||||
clearSpeakerFragment = ClearSpeakerFragment()
|
).commit()
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.add(content, clearSpeakerFragment)
|
|
||||||
.commit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
if (item.itemId == home) {
|
|
||||||
finish()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,22 +15,21 @@
|
||||||
*/
|
*/
|
||||||
package com.eurekateam.samsungextras.speaker
|
package com.eurekateam.samsungextras.speaker
|
||||||
|
|
||||||
import android.media.AudioManager
|
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.preference.Preference
|
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.SwitchPreference
|
|
||||||
import com.eurekateam.samsungextras.R
|
import com.eurekateam.samsungextras.R
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener
|
||||||
|
|
||||||
class ClearSpeakerFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
class ClearSpeakerFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListener {
|
||||||
private lateinit var mHandler: Handler
|
private lateinit var mHandler: Handler
|
||||||
private lateinit var mMediaPlayer: MediaPlayer
|
private lateinit var mMediaPlayer: MediaPlayer
|
||||||
private lateinit var mClearSpeakerPref: SwitchPreference
|
private lateinit var mClearSpeakerPref: MainSwitchPreference
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
addPreferencesFromResource(R.xml.clear_speaker_settings)
|
addPreferencesFromResource(R.xml.clear_speaker_settings)
|
||||||
mClearSpeakerPref = findPreference(PREF_CLEAR_SPEAKER)!!
|
mClearSpeakerPref = findPreference(PREF_CLEAR_SPEAKER)!!
|
||||||
|
|
@ -38,17 +37,13 @@ class ClearSpeakerFragment : PreferenceFragmentCompat(), Preference.OnPreference
|
||||||
mHandler = Handler(Looper.getMainLooper())
|
mHandler = Handler(Looper.getMainLooper())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
|
||||||
if (preference === mClearSpeakerPref) {
|
if (isChecked) {
|
||||||
val value = newValue as Boolean
|
|
||||||
if (value) {
|
|
||||||
if (startPlaying()) {
|
if (startPlaying()) {
|
||||||
mHandler.removeCallbacksAndMessages(null)
|
mHandler.removeCallbacksAndMessages(null)
|
||||||
mHandler.postDelayed({ stopPlaying() }, 30000)
|
mHandler.postDelayed({ stopPlaying() }, 30000)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue