@ -17,28 +17,24 @@
package org.lineageos.settings.doze ;
import android.app.ActionBar ;
import android.os.Bundle ;
import android.os.Handler ;
import android.view.LayoutInflater ;
import android.view.MenuItem ;
import android.view.View ;
import android.view.ViewGroup ;
import android.widget.CompoundButton ;
import android.widget.Switch ;
import android.widget.TextView ;
import androidx.preference.Preference ;
import androidx.preference.Preference.OnPreferenceChangeListener ;
import androidx.preference.PreferenceFragment ;
import androidx.preference.SwitchPreference ;
import com.android.settingslib.widget.MainSwitchPreference ;
import com.android.settingslib.widget.OnMainSwitchChangeListener ;
import org.lineageos.internal.util.ScreenType ;
public class SamsungDozeSettings extends PreferenceFragment
implements CompoundButton . OnCheckedChangeListener , Preference . OnPreference ChangeListener {
implements OnPreferenceChangeListener , OnMainSwitch ChangeListener {
private TextView mTextView ;
private View mSwitchBar ;
private MainSwitchPreference mSwitchBar ;
private SwitchPreference mAlwaysOnDisplayPreference ;
private SwitchPreference mHandwavePreference ;
@ -50,11 +46,13 @@ public class SamsungDozeSettings extends PreferenceFragment
@Override
public void onCreatePreferences ( Bundle savedInstanceState , String rootKey ) {
addPreferencesFromResource ( R . xml . gesture_panel ) ;
final ActionBar actionBar = getActivity ( ) . getActionBar ( ) ;
actionBar . setDisplayHomeAsUpEnabled ( true ) ;
boolean dozeEnabled = Utils . isDozeEnabled ( getActivity ( ) ) ;
mSwitchBar = ( MainSwitchPreference ) findPreference ( Utils . DOZE_ENABLE ) ;
mSwitchBar . addOnSwitchChangeListener ( this ) ;
mSwitchBar . setChecked ( dozeEnabled ) ;
mAlwaysOnDisplayPreference = findPreference ( Utils . ALWAYS_ON_DISPLAY ) ;
mAlwaysOnDisplayPreference . setEnabled ( dozeEnabled ) ;
mAlwaysOnDisplayPreference . setChecked ( Utils . isAlwaysOnEnabled ( getActivity ( ) ) ) ;
@ -92,36 +90,6 @@ public class SamsungDozeSettings extends PreferenceFragment
}
}
@Override
public View onCreateView ( LayoutInflater inflater , ViewGroup container ,
Bundle savedInstanceState ) {
final View view =
LayoutInflater . from ( getContext ( ) ) . inflate ( R . layout . doze , container , false ) ;
( ( ViewGroup ) view ) . addView ( super . onCreateView ( inflater , container , savedInstanceState ) ) ;
return view ;
}
@Override
public void onViewCreated ( View view , Bundle savedInstanceState ) {
super . onViewCreated ( view , savedInstanceState ) ;
boolean dozeEnabled = Utils . isDozeEnabled ( getActivity ( ) ) ;
mTextView = view . findViewById ( R . id . switch_text ) ;
mTextView . setText ( getString ( dozeEnabled ?
R . string . switch_bar_on : R . string . switch_bar_off ) ) ;
mSwitchBar = view . findViewById ( R . id . switch_bar ) ;
Switch switchWidget = mSwitchBar . findViewById ( android . R . id . switch_widget ) ;
switchWidget . setChecked ( dozeEnabled ) ;
switchWidget . setOnCheckedChangeListener ( this ) ;
mSwitchBar . setActivated ( dozeEnabled ) ;
mSwitchBar . setOnClickListener ( v - > {
switchWidget . setChecked ( ! switchWidget . isChecked ( ) ) ;
mSwitchBar . setActivated ( switchWidget . isChecked ( ) ) ;
} ) ;
}
@Override
public boolean onPreferenceChange ( Preference preference , Object newValue ) {
if ( Utils . ALWAYS_ON_DISPLAY . equals ( preference . getKey ( ) ) ) {
@ -134,12 +102,11 @@ public class SamsungDozeSettings extends PreferenceFragment
}
@Override
public void onCheckedChanged ( CompoundButton compoundButton , boolean isChecked ) {
public void onSwitchChanged ( Switch switchView , boolean isChecked ) {
Utils . enableDoze ( getActivity ( ) , isChecked ) ;
Utils . checkDozeService ( getActivity ( ) ) ;
mTextView . setText ( getString ( isChecked ? R . string . switch_bar_on : R . string . switch_bar_off ) ) ;
mSwitchBar . setActivated ( isChecked ) ;
mSwitchBar . setChecked ( isChecked ) ;
if ( ! isChecked ) {
Utils . enableAlwaysOn ( getActivity ( ) , false ) ;
@ -151,13 +118,4 @@ public class SamsungDozeSettings extends PreferenceFragment
mPocketPreference . setEnabled ( isChecked ) ;
mWakeOnGesturePreference . setEnabled ( isChecked ) ;
}
@Override
public boolean onOptionsItemSelected ( MenuItem item ) {
if ( item . getItemId ( ) = = android . R . id . home ) {
getActivity ( ) . onBackPressed ( ) ;
return true ;
}
return false ;
}
}