universal7885: parts: Refactor battery fragment

* Show live data of battery

Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
roynatech2544 2022-04-14 15:39:13 +09:00
commit c813e0984a
No known key found for this signature in database
GPG key ID: 50ABF73F0D19445D
22 changed files with 135 additions and 393 deletions

View file

@ -152,7 +152,7 @@ class CameraLightSensorService : Service() {
Log.w(TAG, "onReady: Session is NULL")
}
cameraDevice!!.close()
session.close()
session.close()
} catch (e: Exception) {
Log.e(TAG, "Camera is in use")
e.printStackTrace()

View file

@ -34,9 +34,6 @@
<meta-data
android:name="com.android.settings.dismiss"
android:value="9,13,30" />
<meta-data
android:name="com.android.settings.bg.hint"
android:resource="@color/homepage_parts_background" />
<meta-data
android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage" />

View file

@ -14,7 +14,8 @@ using vendor::eureka::hardware::parts::V1_0::Value;
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) {
Java_com_eurekateam_samsungextras_interfaces_Flashlight_setEnabled
(JNIEnv *env, __unused jobject obj, jboolean enabled) {
if (enabled) {
service->setFlashlightEnable(Number::ENABLE);
} else {

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 crDroid Android Project
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0" >
<path
android:fillColor="?android:attr/colorControlNormal"
android:pathData="M14.102040767669678,13 H0.10204076766967773 V11 H14.102040767669678 V13 z" />
</vector>

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2018 crDroid Android Project
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="48.0"
android:viewportHeight="48.0" >
<path
android:fillColor="?android:attr/colorControlNormal"
android:pathData="M38.0,26.0L26.0,26.0l0.0,12.0l-4.0,0.0L22.0,26.0L10.0,26.0l0.0,-4.0l12.0,0.0L22.0,10.0l4.0,0.0l0.0,12.0l12.0,0.0l0.0,4.0z" />
</vector>

View file

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 Havoc-OS
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal" >
<path
android:fillColor="#FFFFFFFF"
android:pathData="M14.123456746339798,12.042328000068665 c0,-0.7430335164070133 -0.6079365134239197,-1.3509700298309326 -1.3509700298309326,-1.3509700298309326 s-1.3509700298309326,0.6079365134239197 -1.3509700298309326,1.3509700298309326 s0.6079365134239197,1.3509700298309326 1.3509700298309326,1.3509700298309326 s1.3509700298309326,-0.6079365134239197 1.3509700298309326,-1.3509700298309326 zM12.772486716508865,5.962962865829468 c-3.3571605241298674,0 -6.079365134239197,2.7222046101093293 -6.079365134239197,6.079365134239197 L4.66666653752327,12.042328000068665 l2.7019400596618652,2.7019400596618652 l2.7019400596618652,-2.7019400596618652 L8.044091612100601,12.042328000068665 c0,-2.6141270077228547 2.1142680966854095,-4.728395104408264 4.728395104408264,-4.728395104408264 s4.728395104408264,2.1142680966854095 4.728395104408264,4.728395104408264 s-2.1142680966854095,4.728395104408264 -4.728395104408264,4.728395104408264 c-1.0199823725223542,0 -1.965661393404007,-0.3309876573085789 -2.742469160556793,-0.8781305193901066 l-0.9591887211799618,0.9726984214782719 C10.097566057443618,17.648853623867033 11.380987585783004,18.12169313430786 12.772486716508865,18.12169313430786 c3.3571605241298674,0 6.079365134239197,-2.7222046101093293 6.079365134239197,-6.079365134239197 s-2.7222046101093293,-6.079365134239197 -6.079365134239197,-6.079365134239197 z" />
</vector>

View file

@ -1,146 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014-2016 The Android Open Source Project
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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/activatedBackgroundIndicator"
android:clipToPadding="false"
android:baselineAligned="false">
<LinearLayout
android:id="@android:id/icon_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="-4dp"
android:minWidth="60dp"
android:gravity="start|center_vertical"
android:orientation="horizontal"
android:paddingEnd="12dp"
android:paddingTop="4dp"
android:paddingBottom="4dp">
<com.android.internal.widget.PreferenceImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="48dp"
android:maxHeight="48dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee" />
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="10"
android:ellipsize="end" />
<RelativeLayout
android:id="@+id/value_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_below="@android:id/summary"
android:layout_alignStart="@android:id/title" >
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="1"
android:ellipsize="end" />
<ImageView
android:id="@+id/reset"
android:src="@drawable/ic_custom_seekbar_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_toEndOf="@id/value"
android:layout_centerVertical="true" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/seekbar_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/value_frame"
android:layout_alignStart="@android:id/title" >
<ImageView
android:id="@+id/minus"
android:src="@drawable/ic_custom_seekbar_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" />
<ImageView
android:id="@+id/plus"
android:src="@drawable/ic_custom_seekbar_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true" />
<LinearLayout
android:id="@+id/seekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:layout_toEndOf="@id/minus"
android:layout_toStartOf="@id/plus"
android:layout_centerVertical="true"
android:orientation="horizontal" />
</RelativeLayout>
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end|center_vertical"
android:paddingStart="16dp"
android:orientation="vertical" />
</LinearLayout>

View file

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/switch_bar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@drawable/switchbar_background"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:clickable="true"
android:gravity="center">
<TextView android:id="@+id/switch_text"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:paddingStart="48dp"
android:maxLines="2"
android:ellipsize="end"
android:textAppearance="@android:style/TextAppearance.Material.Title"
android:textColor="?android:attr/textColorPrimary"
android:text="@string/switch_bar_on" />
<androidx.appcompat.widget.SwitchCompat
android:id="@android:id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@null"
android:theme="@style/DeviceSettings.SwitchBar" />
</LinearLayout>

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="batt_info_menu">
<item>@string/battery_max_capa</item>
<item>@string/battery_chrged_up_to</item>
<item>@string/battery_chrged_up_to_mah</item>
<item>@string/battery_current</item>
<item>@string/battery_status</item>
<item>@string/battery_temp</item>
</string-array>
<string-array name="dolby_modes">
<item>@string/dolby_profile_auto</item>
<item>@string/dolby_profile_movie</item>
<item>@string/dolby_profile_music</item>
<item>@string/dolby_profile_voice</item>
</string-array>
</resources>

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base attributes available to CustomSeekBarPreference. -->
<declare-styleable name="CustomSeekBarPreference">
<attr name="interval" format="integer" />
<attr name="showSign" format="boolean" />
<attr name="units" format="string|reference" />
<attr name="continuousUpdates" format="boolean" />
</declare-styleable>
</resources>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 Havoc-OS
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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<color name="disabled_text_color">#66000000</color>
<color name="homepage_parts_background">#FFFF6700</color>
<color name="red">#FF0000</color>
<color name="green">#00FF00</color>
<color name="blue">#0000FF</color>
</resources>

View file

@ -17,7 +17,8 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="advanced_settings">SamsungParts</string>
<string name="advanced_settings_summary">Device specific tweaks</string>
<string name="not_shown">Not shown due to user settings</string>
<string name="show_data">Show the battery data</string>
<!-- Display category -->
<string name="display_category">Display</string>
<!-- FPS Info -->
@ -26,7 +27,7 @@
<!-- Speaker category -->
<string name="speaker_category">Audio</string>
<string name="flash_enable_title">Enable Eureka flash control feature</string>
<!-- Clear Speaker -->
<string name="clear_speaker_title">Clear speaker</string>
<string name="clear_speaker_summary">Play a 30-second audio to clear the speaker</string>
@ -94,11 +95,4 @@
<!-- Label for feature switch -->
<string name="switch_bar_off">Off</string>
<!-- Custom seekbar -->
<string name="custom_seekbar_value">Value: <xliff:g id="v">%s</xliff:g></string>
<string name="custom_seekbar_default_value">Default</string>
<string name="custom_seekbar_default_value_to_set">Default value: <xliff:g id="v">%s</xliff:g>\nLong press to set</string>
<string name="custom_seekbar_default_value_is_set">Default value is set</string>
</resources>

View file

@ -3,7 +3,11 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/fastcharge_title">
<com.android.settingslib.widget.MainSwitchPreference
<com.android.settingslib.widget.MainSwitchPreference
android:key="show_data"
android:title="@string/show_data"/>
<SwitchPreference
android:key="fastcharge_pref"
android:title="@string/fastcharge_2nd_title"
android:icon="@drawable/ic_bolt"
@ -15,12 +19,35 @@
android:icon="@drawable/ic_bolt"
android:summary="@string/charge_summary"/>
<ListPreference
android:key="battery_info"
android:title="@string/battery_info_title"
android:summary="@string/battery_info_summary"
android:icon="@drawable/ic_battery"
android:entries="@array/batt_info_menu"/>
<Preference
android:key="battery_capacity"
android:title="@string/battery_max_capa"
android:summary="@string/not_shown"/>
<Preference
android:key="battery_charged_up_to"
android:title="@string/battery_chrged_up_to"
android:summary="@string/not_shown"/>
<Preference
android:key="battery_charged_up_to_mah"
android:title="@string/battery_chrged_up_to_mah"
android:summary="@string/not_shown"/>
<Preference
android:key="battery_current"
android:title="@string/battery_current"
android:summary="@string/not_shown"/>
<Preference
android:key="battery_status"
android:title="@string/battery_status"
android:summary="@string/not_shown"/>
<Preference
android:key="battery_temp"
android:title="@string/battery_temp"
android:summary="@string/not_shown"/>
<com.android.settingslib.widget.FooterPreference
android:key="footer_preference"

View file

@ -16,7 +16,6 @@
package com.eurekateam.samsungextras.battery
import android.os.Bundle
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
import com.android.settingslib.collapsingtoolbar.R
@ -24,8 +23,8 @@ class BatteryActivity : CollapsingToolbarBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportFragmentManager.beginTransaction().replace(
R.id.content_frame,
BatteryFragment()
R.id.content_frame,
BatteryFragment()
).commit()
}
}

View file

@ -17,20 +17,23 @@ package com.eurekateam.samsungextras.battery
import android.content.SharedPreferences
import android.os.Bundle
import android.widget.Toast
import androidx.preference.ListPreference
import android.widget.Switch
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import androidx.preference.SwitchPreference
import com.eurekateam.samsungextras.R
import com.eurekateam.samsungextras.interfaces.Battery
import com.android.settingslib.widget.MainSwitchPreference
import com.android.settingslib.widget.OnMainSwitchChangeListener
import com.eurekateam.samsungextras.R
import com.eurekateam.samsungextras.interfaces.Battery
import java.util.concurrent.ScheduledThreadPoolExecutor
import java.util.concurrent.TimeUnit
class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
private lateinit var mFastChargePref: MainSwitchPreference
private lateinit var mFastChargePref: SwitchPreference
private var mPoolExecutor: ScheduledThreadPoolExecutor? = null
private lateinit var mChargePref: SwitchPreference
private lateinit var mShowDataPref: MainSwitchPreference
private lateinit var mSharedPreferences: SharedPreferences
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.battery_settings)
@ -41,45 +44,73 @@ class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChang
mChargePref = findPreference(PREF_CHARGE)!!
mChargePref.onPreferenceChangeListener = this
mChargePref.isChecked = mSharedPreferences.getBoolean(PREF_CHARGE, true)
val mBatteryInfo: ListPreference = findPreference(BATTERY_INFO)!!
val items = arrayOf<CharSequence>(
Battery.getGeneralBatteryStats(1).toString() + " mAh",
Battery.getGeneralBatteryStats(2).toString() + " %",
Battery.getGeneralBatteryStats(3).toString() + " mAh",
Battery.getGeneralBatteryStats(6).toString() + " mAh",
if (Battery.getGeneralBatteryStats(4) == 1) "Charging" else "Discharging",
Battery.getGeneralBatteryStats(5).toString() + " \u2103"
)
mBatteryInfo.entryValues = items
mBatteryInfo.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any? ->
Toast.makeText(
context, newValue as String, Toast.LENGTH_SHORT
).show()
true
}
mShowDataPref = findPreference(PREF_SHOW_DATA)!!
mShowDataPref.isChecked = mSharedPreferences.getBoolean(PREF_SHOW_DATA, true)
mShowDataPref.addOnSwitchChangeListener(this)
if (mShowDataPref.isChecked) {
mPoolExecutor = ScheduledThreadPoolExecutor(3)
mPoolExecutor!!.scheduleWithFixedDelay(mScheduler, 0, 2, TimeUnit.SECONDS)
}
}
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
if (preference === mChargePref) {
if (preference == mChargePref) {
val value = newValue as Boolean
Battery.chargeSysfs = if (value) 0 else 1
mChargePref.isChecked = Battery.chargeSysfs == 0
mSharedPreferences.edit().putBoolean(PREF_CHARGE, Battery.chargeSysfs == 0).apply()
return true
} else if (preference == mFastChargePref) {
Battery.setFastCharge(if (newValue as Boolean) 0 else 1)
mFastChargePref.isChecked = Battery.fastChargeSysfs == 0
mSharedPreferences.edit().putBoolean(PREF_FASTCHARGE, Battery.fastChargeSysfs == 0).apply()
}
return false
}
private val mScheduler = Runnable {
requireActivity().runOnUiThread {
findPreference<Preference>(INFO_MAX_CAP)!!.summary = Battery.getGeneralBatteryStats(1).toString() + " mAh"
findPreference<Preference>(INFO_CHARGED_UP_TO)!!.summary = Battery.getGeneralBatteryStats(2).toString() + " %"
findPreference<Preference>(INFO_CHARGED_MAH)!!.summary = Battery.getGeneralBatteryStats(3).toString() + " mAh"
findPreference<Preference>(INFO_CURRENT)!!.summary = Battery.getGeneralBatteryStats(6).toString() + " mA"
findPreference<Preference>(INFO_STATUS)!!.summary = if (Battery.getGeneralBatteryStats(4) == 1) "Charging" else "Discharging"
findPreference<Preference>(INFO_TEMP)!!.summary = Battery.getGeneralBatteryStats(5).toString() + " \u2103"
}
}
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()
if (isChecked) {
if (mPoolExecutor == null) {
mPoolExecutor = ScheduledThreadPoolExecutor(2)
mPoolExecutor!!.scheduleWithFixedDelay(
mScheduler, 0, 2, TimeUnit.SECONDS
)
}
} else {
if (mPoolExecutor != null) {
mPoolExecutor!!.shutdown()
mPoolExecutor = null
}
val mNotShown = requireContext().getString(R.string.not_shown)
findPreference<Preference>(INFO_MAX_CAP)!!.summary = mNotShown
findPreference<Preference>(INFO_CHARGED_UP_TO)!!.summary = mNotShown
findPreference<Preference>(INFO_CHARGED_MAH)!!.summary = mNotShown
findPreference<Preference>(INFO_CURRENT)!!.summary = mNotShown
findPreference<Preference>(INFO_STATUS)!!.summary = mNotShown
findPreference<Preference>(INFO_TEMP)!!.summary = mNotShown
}
mSharedPreferences.edit().putBoolean(PREF_SHOW_DATA, isChecked).apply()
}
companion object {
const val PREF_FASTCHARGE = "fastcharge_pref"
const val PREF_CHARGE = "charge_pref"
const val INFO_MAX_CAP = "battery_capacity"
const val INFO_CHARGED_UP_TO = "battery_charged_up_to"
const val INFO_CHARGED_MAH = "battery_charged_up_to_mah"
const val INFO_CURRENT = "battery_current"
const val INFO_STATUS = "battery_status"
const val INFO_TEMP = "battery_temp"
const val PREF_SHOW_DATA = "show_data"
private const val BATTERY_INFO = "battery_info"
}
}

View file

@ -16,15 +16,16 @@
package com.eurekateam.samsungextras.dolby
import android.os.Bundle
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
import com.android.settingslib.collapsingtoolbar.R
class DolbyActivity : CollapsingToolbarBaseActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
fragmentManager.beginTransaction().replace(
R.id.content_frame,
DolbyFragment()
supportFragmentManager.beginTransaction().replace(
R.id.content_frame,
DolbyFragment()
).commit()
}
}

View file

@ -16,7 +16,6 @@
package com.eurekateam.samsungextras.flashlight
import android.os.Bundle
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
import com.android.settingslib.collapsingtoolbar.R
@ -24,8 +23,8 @@ class FlashLightActivity : CollapsingToolbarBaseActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportFragmentManager.beginTransaction().replace(
R.id.content_frame,
FlashLightFragment()
R.id.content_frame,
FlashLightFragment()
).commit()
}
}

View file

@ -18,18 +18,20 @@ package com.eurekateam.samsungextras.flashlight
import android.content.SharedPreferences
import android.os.Build
import android.os.Bundle
import android.widget.Switch
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.eurekateam.samsungextras.R
import androidx.preference.SeekBarPreference
import com.android.settingslib.widget.MainSwitchPreference
import com.android.settingslib.widget.OnMainSwitchChangeListener
import com.eurekateam.samsungextras.R
import com.eurekateam.samsungextras.interfaces.Flashlight
class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
private lateinit var mFlashLightPref: SeekBarPreference
private lateinit var mSharedPreferences: SharedPreferences
private lateinit var mFlashLightEnable : MainSwitchPreference
private lateinit var mFlashLightEnable: MainSwitchPreference
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.flashlight_settings)
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
@ -38,10 +40,10 @@ class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceCh
mFlashLightPref.setMax(10)
mFlashLightPref.setMin(1)
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
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 {
@ -51,17 +53,15 @@ class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceCh
mSharedPreferences.edit().putInt(PREF_FLASHLIGHT, value).apply()
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 {
Flashlight.setEnabled(isChecked)
mSharedPreferences.edit().putBoolean(PREF_FLASHLIGHT_ENABLE, isChecked)
mFlashLightPref.isEnabled = isChecked
} companion object {
const val PREF_FLASHLIGHT = "flashlight_pref"
const val PREF_FLASHLIGHT_ENABLE = "flashlight_enable"
const val PREF_FLASHLIGHT_ENABLE = "flashlight_enable"
}
}

View file

@ -19,5 +19,4 @@ package com.eurekateam.samsungextras.interfaces
object Flashlight {
external fun setFlash(value: Int)
external fun getFlash(isA10: Int): Int
external fun setEnabled(enable: Boolean)
}
external fun setEnabled(enable: Boolean) }

View file

@ -15,6 +15,7 @@
*/
package com.eurekateam.samsungextras.speaker
import android.os.Bundle
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
import com.android.settingslib.collapsingtoolbar.R
@ -22,8 +23,8 @@ class ClearSpeakerActivity : CollapsingToolbarBaseActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportFragmentManager.beginTransaction().replace(
R.id.content_frame,
ClearSpeakerFragment()
R.id.content_frame,
ClearSpeakerFragment()
).commit()
}
}

View file

@ -15,16 +15,18 @@
*/
package com.eurekateam.samsungextras.speaker
import android.media.AudioManager
import android.media.MediaPlayer
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Switch
import androidx.preference.PreferenceFragmentCompat
import com.eurekateam.samsungextras.R
import java.io.IOException
import com.android.settingslib.widget.MainSwitchPreference
import com.android.settingslib.widget.OnMainSwitchChangeListener
import com.eurekateam.samsungextras.R
import java.io.IOException
class ClearSpeakerFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListener {
private lateinit var mHandler: Handler
@ -33,18 +35,17 @@ class ClearSpeakerFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListe
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.clear_speaker_settings)
mClearSpeakerPref = findPreference(PREF_CLEAR_SPEAKER)!!
mClearSpeakerPref.onPreferenceChangeListener = this
mClearSpeakerPref.addOnSwitchChangeListener(this)
mHandler = Handler(Looper.getMainLooper())
}
override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
if (isChecked) {
if (startPlaying()) {
mHandler.removeCallbacksAndMessages(null)
mHandler.postDelayed({ stopPlaying() }, 30000)
}
if (isChecked) {
if (startPlaying()) {
mHandler.removeCallbacksAndMessages(null)
mHandler.postDelayed({ stopPlaying() }, 30000)
}
return false
}
}
override fun onStop() {

View file

@ -41,7 +41,7 @@ Return<void> FlashBrightness::setFlashlightEnable(parts::V1_0::Number enable) {
Return<void> FlashBrightness::setFlashlightWritable(parts::V1_0::Value value) {
std::ofstream file;
std::string writevalue = std::to_string((int) value);
std::string writevalue = std::to_string((int)value);
file.open("/sys/class/camera/flash/torch_brightness_lvl");
file << writevalue;
file.close();