Search in sources :

Example 1 with RingModeSettings

use of cyanogenmod.profiles.RingModeSettings in project android_packages_apps_CMParts by LineageOS.

the class SetupActionsFragment method fillProfileWithCurrentSettings.

public static void fillProfileWithCurrentSettings(Context context, Profile profile) {
    // bt
    if (DeviceUtils.deviceSupportsBluetooth()) {
        profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_BLUETOOTH, BluetoothAdapter.getDefaultAdapter().isEnabled() ? 1 : 0, true));
    }
    // gps
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_GPS, gpsEnabled ? 1 : 0, true));
    // wifi
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFI, wifiManager.isWifiEnabled() ? 1 : 0, true));
    // auto sync data
    profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_SYNC, ContentResolver.getMasterSyncAutomatically() ? 1 : 0, true));
    // mobile data
    if (DeviceUtils.deviceSupportsMobileData(context)) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA, cm.getMobileDataEnabled() ? 1 : 0, true));
    }
    // wifi hotspot
    profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFIAP, wifiManager.isWifiApEnabled() ? 1 : 0, true));
    // nfc
    if (DeviceUtils.deviceSupportsNfc(context)) {
        NfcManager nfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
        profile.setConnectionSettings(new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_NFC, nfcManager.getDefaultAdapter().isEnabled() ? 1 : 0, true));
    }
    // alarm volume
    final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_ALARM, am.getStreamVolume(AudioManager.STREAM_ALARM), true));
    // media volume
    profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_MUSIC, am.getStreamVolume(AudioManager.STREAM_MUSIC), true));
    // ringtone volume
    profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_RING, am.getStreamVolume(AudioManager.STREAM_RING), true));
    // notification volume
    profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_NOTIFICATION, am.getStreamVolume(AudioManager.STREAM_NOTIFICATION), true));
    // ring mode
    String ringValue;
    switch(am.getRingerMode()) {
        default:
        case AudioManager.RINGER_MODE_NORMAL:
            ringValue = "normal";
            break;
        case AudioManager.RINGER_MODE_SILENT:
            ringValue = "mute";
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            ringValue = "vibrate";
            break;
    }
    profile.setRingMode(new RingModeSettings(ringValue, true));
    // airplane mode
    boolean airplaneMode = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
    profile.setAirplaneMode(new AirplaneModeSettings(airplaneMode ? 1 : 0, true));
// lock screen mode
// populated only from profiles, so we can read the current profile,
// but let's skip this one
}
Also used : LocationManager(android.location.LocationManager) WifiManager(android.net.wifi.WifiManager) AudioManager(android.media.AudioManager) StreamSettings(cyanogenmod.profiles.StreamSettings) ConnectivityManager(android.net.ConnectivityManager) RingModeSettings(cyanogenmod.profiles.RingModeSettings) NfcManager(android.nfc.NfcManager) AirplaneModeSettings(cyanogenmod.profiles.AirplaneModeSettings) ConnectionSettings(cyanogenmod.profiles.ConnectionSettings)

Aggregations

LocationManager (android.location.LocationManager)1 AudioManager (android.media.AudioManager)1 ConnectivityManager (android.net.ConnectivityManager)1 WifiManager (android.net.wifi.WifiManager)1 NfcManager (android.nfc.NfcManager)1 AirplaneModeSettings (cyanogenmod.profiles.AirplaneModeSettings)1 ConnectionSettings (cyanogenmod.profiles.ConnectionSettings)1 RingModeSettings (cyanogenmod.profiles.RingModeSettings)1 StreamSettings (cyanogenmod.profiles.StreamSettings)1