@ -19,14 +19,37 @@ package com.cyanogenmod.settings.device;
import com.android.internal.util.cm.ScreenType ;
import android.os.Bundle ;
import android.preference.Preference ;
import android.preference.PreferenceActivity ;
import android.preference.SwitchPreference ;
import android.provider.Settings ;
public class TouchscreenGestureSettings extends PreferenceActivity {
private static final String KEY_AMBIENT_DISPLAY_ENABLE = "ambient_display_enable" ;
private static final String KEY_HAND_WAVE = "gesture_hand_wave" ;
private static final String KEY_GESTURE_POCKET = "gesture_pocket" ;
private SwitchPreference mAmbientDisplayPreference ;
private SwitchPreference mHandwavePreference ;
private SwitchPreference mPocketPreference ;
@Override
public void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState ) ;
addPreferencesFromResource ( R . xml . gesture_panel ) ;
boolean dozeEnabled = isDozeEnabled ( ) ;
mAmbientDisplayPreference =
( SwitchPreference ) findPreference ( KEY_AMBIENT_DISPLAY_ENABLE ) ;
// Read from DOZE_ENABLED secure setting
mAmbientDisplayPreference . setChecked ( dozeEnabled ) ;
mAmbientDisplayPreference . setOnPreferenceChangeListener ( mAmbientDisplayPrefListener ) ;
mHandwavePreference =
( SwitchPreference ) findPreference ( KEY_HAND_WAVE ) ;
mHandwavePreference . setEnabled ( dozeEnabled ) ;
mPocketPreference =
( SwitchPreference ) findPreference ( KEY_GESTURE_POCKET ) ;
mPocketPreference . setEnabled ( dozeEnabled ) ;
}
@Override
@ -38,4 +61,28 @@ public class TouchscreenGestureSettings extends PreferenceActivity {
getListView ( ) . setPadding ( 0 , 0 , 0 , 0 ) ;
}
}
private boolean enableDoze ( boolean enable ) {
return Settings . Secure . putInt ( getContentResolver ( ) ,
Settings . Secure . DOZE_ENABLED , enable ? 1 : 0 ) ;
}
private boolean isDozeEnabled ( ) {
return Settings . Secure . getInt ( getContentResolver ( ) ,
Settings . Secure . DOZE_ENABLED , 1 ) ! = 0 ;
}
private Preference . OnPreferenceChangeListener mAmbientDisplayPrefListener =
new Preference . OnPreferenceChangeListener ( ) {
@Override
public boolean onPreferenceChange ( Preference preference , Object newValue ) {
boolean enable = ( boolean ) newValue ;
boolean ret = enableDoze ( enable ) ;
if ( ret ) {
mHandwavePreference . setEnabled ( enable ) ;
mPocketPreference . setEnabled ( enable ) ;
}
return ret ;
}
} ;
}