Search in sources :

Example 81 with Activity

use of android.app.Activity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DisplaySettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    final ContentResolver resolver = activity.getContentResolver();
    addPreferencesFromResource(R.xml.display_settings);
    PreferenceCategory displayPrefs = (PreferenceCategory) findPreference(KEY_CATEGORY_DISPLAY);
    mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER);
    if (mScreenSaverPreference != null && getResources().getBoolean(com.android.internal.R.bool.config_dreamsSupported) == false) {
        getPreferenceScreen().removePreference(mScreenSaverPreference);
    }
    mScreenTimeoutPreference = (TimeoutListPreference) findPreference(KEY_SCREEN_TIMEOUT);
    if (displayPrefs != null) {
        mAutoBrightnessPreference = (SwitchPreference) findPreference(KEY_AUTO_BRIGHTNESS);
        if (mAutoBrightnessPreference != null) {
            if (isAutomaticBrightnessAvailable(getResources())) {
                mAutoBrightnessPreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mAutoBrightnessPreference);
            }
        }
        if (!NightDisplayController.isAvailable(activity)) {
            removePreference(KEY_NIGHT_DISPLAY);
        }
        mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
        if (mLiftToWakePreference != null) {
            if (isLiftToWakeAvailable(activity)) {
                mLiftToWakePreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mLiftToWakePreference);
            }
        }
        mTapToWakePreference = (SwitchPreference) findPreference(KEY_TAP_TO_WAKE);
        if (mTapToWakePreference != null) {
            if (isTapToWakeAvailable(getResources())) {
                mTapToWakePreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mTapToWakePreference);
            }
        }
        mCameraGesturePreference = (SwitchPreference) findPreference(KEY_CAMERA_GESTURE);
        if (mCameraGesturePreference != null) {
            if (isCameraGestureAvailable(getResources())) {
                mCameraGesturePreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mCameraGesturePreference);
            }
        }
        DropDownPreference rotatePreference = (DropDownPreference) findPreference(KEY_AUTO_ROTATE);
        if (rotatePreference != null) {
            if (RotationPolicy.isRotationLockToggleVisible(activity)) {
                int rotateLockedResourceId;
                // rotation), then we use a different string to include this information.
                if (allowAllRotations(activity)) {
                    rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current;
                } else {
                    if (RotationPolicy.getRotationLockOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) {
                        rotateLockedResourceId = R.string.display_auto_rotate_stay_in_portrait;
                    } else {
                        rotateLockedResourceId = R.string.display_auto_rotate_stay_in_landscape;
                    }
                }
                rotatePreference.setEntries(new CharSequence[] { activity.getString(R.string.display_auto_rotate_rotate), activity.getString(rotateLockedResourceId) });
                rotatePreference.setEntryValues(new CharSequence[] { "0", "1" });
                rotatePreference.setValueIndex(RotationPolicy.isRotationLocked(activity) ? 1 : 0);
                rotatePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        final boolean locked = Integer.parseInt((String) newValue) != 0;
                        MetricsLogger.action(getActivity(), MetricsEvent.ACTION_ROTATION_LOCK, locked);
                        RotationPolicy.setRotationLock(activity, locked);
                        return true;
                    }
                });
            } else {
                displayPrefs.removePreference(rotatePreference);
            }
        }
        DropDownPreference vrDisplayPref = (DropDownPreference) findPreference(KEY_VR_DISPLAY_PREF);
        if (vrDisplayPref != null) {
            if (isVrDisplayModeAvailable(activity)) {
                vrDisplayPref.setEntries(new CharSequence[] { activity.getString(R.string.display_vr_pref_low_persistence), activity.getString(R.string.display_vr_pref_off) });
                vrDisplayPref.setEntryValues(new CharSequence[] { "0", "1" });
                final Context c = activity;
                int currentUser = ActivityManager.getCurrentUser();
                int current = Settings.Secure.getIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, /*default*/
                Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE, currentUser);
                vrDisplayPref.setValueIndex(current);
                vrDisplayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        int i = Integer.parseInt((String) newValue);
                        int u = ActivityManager.getCurrentUser();
                        if (!Settings.Secure.putIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, i, u)) {
                            Log.e(TAG, "Could not change setting for " + Settings.Secure.VR_DISPLAY_MODE);
                        }
                        return true;
                    }
                });
            } else {
                displayPrefs.removePreference(vrDisplayPref);
            }
        }
    }
    mNightModePreference = (ListPreference) findPreference(KEY_NIGHT_MODE);
    if (mNightModePreference != null) {
        final UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
        final int currentNightMode = uiManager.getNightMode();
        mNightModePreference.setValue(String.valueOf(currentNightMode));
        mNightModePreference.setOnPreferenceChangeListener(this);
    }
}
Also used : Context(android.content.Context) PreferenceCategory(android.support.v7.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) DropDownPreference(android.support.v7.preference.DropDownPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) UiModeManager(android.app.UiModeManager) Activity(android.app.Activity) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener) ContentResolver(android.content.ContentResolver) DropDownPreference(android.support.v7.preference.DropDownPreference)

Example 82 with Activity

use of android.app.Activity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminSettings method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Object o = l.getAdapter().getItem(position);
    DeviceAdminInfo dpi = (DeviceAdminInfo) o;
    final UserHandle user = new UserHandle(getUserId(dpi));
    final Activity activity = getActivity();
    Intent intent = new Intent(activity, DeviceAdminAdd.class);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, dpi.getComponent());
    activity.startActivityAsUser(intent, user);
}
Also used : DeviceAdminInfo(android.app.admin.DeviceAdminInfo) UserHandle(android.os.UserHandle) Activity(android.app.Activity) Intent(android.content.Intent)

Example 83 with Activity

use of android.app.Activity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WirelessSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
    }
    log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
    mContext = getActivity();
    mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mPm = getPackageManager();
    mUm = (UserManager) getSystemService(Context.USER_SERVICE);
    addPreferencesFromResource(R.xml.wireless_settings);
    final boolean isAdmin = mUm.isAdminUser();
    final Activity activity = getActivity();
    mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
    SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
    RestrictedPreference androidBeam = (RestrictedPreference) findPreference(KEY_ANDROID_BEAM_SETTINGS);
    PreferenceScreen nfcPayment = (PreferenceScreen) findPreference(KEY_NFC_PAYMENT_SETTINGS);
    PreferenceCategory nfcCategory = (PreferenceCategory) findPreference(KEY_NFC_CATEGORY_SETTINGS);
    mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
    mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam, nfcPayment);
    mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
    String toggleable = Settings.Global.getString(activity.getContentResolver(), Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
    //enable/disable wimax depending on the value in config.xml
    final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(com.android.internal.R.bool.config_wimaxEnabled);
    if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        PreferenceScreen root = getPreferenceScreen();
        Preference ps = findPreference(KEY_WIMAX_SETTINGS);
        if (ps != null)
            root.removePreference(ps);
    } else {
        if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX) && isWimaxEnabled) {
            Preference ps = findPreference(KEY_WIMAX_SETTINGS);
            ps.setDependency(KEY_TOGGLE_AIRPLANE);
        }
    }
    // Manually set dependencies for Wifi when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
        findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // TODO: http://b/23693383
    if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
        removePreference(KEY_VPN_SETTINGS);
    }
    // Manually set dependencies for Bluetooth when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
    // No bluetooth-dependent items in the list. Code kept in case one is added later.
    }
    // Manually set dependencies for NFC when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
        findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_NFC_PAYMENT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // Remove NFC if not available
    mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
    if (mNfcAdapter == null) {
        getPreferenceScreen().removePreference(nfcCategory);
        mNfcEnabler = null;
    } else if (!mPm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
        // Only show if we have the HCE feature
        nfcCategory.removePreference(nfcPayment);
    }
    // if it's a wifi-only device, or for MSIM devices
    if (!isAdmin || Utils.isWifiOnly(getActivity()) || Utils.showSimCardTile(getActivity()) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        removePreference(KEY_MOBILE_NETWORK_SETTINGS);
        removePreference(KEY_MANAGE_MOBILE_PLAN);
    }
    // Remove Mobile Network Settings and Manage Mobile Plan
    // if config_show_mobile_plan sets false.
    final boolean isMobilePlanEnabled = this.getResources().getBoolean(R.bool.config_show_mobile_plan);
    if (!isMobilePlanEnabled) {
        Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
        if (pref != null) {
            removePreference(KEY_MANAGE_MOBILE_PLAN);
        }
    }
    // Remove Airplane Mode settings if it's a stationary device such as a TV.
    if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
        removePreference(KEY_TOGGLE_AIRPLANE);
    }
    // Enable Proxy selector settings if allowed.
    Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
    final DevicePolicyManager mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    // proxy UI disabled until we have better app support
    getPreferenceScreen().removePreference(mGlobalProxy);
    mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
    // Disable Tethering if it's not allowed or if it's a wifi-only device
    final ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
    if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
        getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
    } else if (!adminDisallowedTetherConfig) {
        Preference p = findPreference(KEY_TETHER_SETTINGS);
        p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
        // Grey out if provisioning is not available.
        p.setEnabled(!TetherSettings.isProvisioningNeededButUnavailable(getActivity()));
    }
    // Remove network reset if not allowed
    if (RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
        removePreference(KEY_NETWORK_RESET);
    }
    // Enable link to CMAS app settings depending on the value in config.xml.
    boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(com.android.internal.R.bool.config_cellBroadcastAppLinks);
    try {
        if (isCellBroadcastAppLinkEnabled) {
            if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
                // CMAS app disabled
                isCellBroadcastAppLinkEnabled = false;
            }
        }
    } catch (IllegalArgumentException ignored) {
        // CMAS app not installed
        isCellBroadcastAppLinkEnabled = false;
    }
    if (!mUm.isAdminUser() || !isCellBroadcastAppLinkEnabled || RestrictedLockUtils.hasBaseUserRestriction(mContext, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserHandle.myUserId())) {
        removePreference(KEY_CELL_BROADCAST_SETTINGS);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(android.support.v14.preference.SwitchPreference) NfcEnabler(com.android.settings.nfc.NfcEnabler) ConnectivityManager(android.net.ConnectivityManager) Activity(android.app.Activity) RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 84 with Activity

use of android.app.Activity in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.rr_notif_settings);
    final Activity activity = getActivity();
    ContentResolver resolver = getActivity().getContentResolver();
    mDisableIM = (SwitchPreference) findPreference(DISABLE_IMMERSIVE_MESSAGE);
    mDisableIM.setOnPreferenceChangeListener(this);
    int DisableIM = Settings.System.getInt(getContentResolver(), DISABLE_IMMERSIVE_MESSAGE, 0);
    mDisableIM.setChecked(DisableIM != 0);
    mNotificationKill = (SwitchPreference) findPreference(NOTIFICATION_GUTS_KILL_APP_BUTTON);
    mNotificationKill.setOnPreferenceChangeListener(this);
    mNoNavigationNotification = (SwitchPreference) findPreference(NO_NAVIGATION_NOTIFICATION);
    boolean isNavNotificationEnabled = Settings.System.getIntForUser(resolver, Settings.System.NO_NAVIGATION_NOTIFICATION, 1, UserHandle.USER_CURRENT) != 0;
    mNoNavigationNotification.setChecked(isNavNotificationEnabled);
    mNoNavigationNotification.setOnPreferenceChangeListener(this);
}
Also used : Activity(android.app.Activity) ContentResolver(android.content.ContentResolver)

Example 85 with Activity

use of android.app.Activity in project CompactCalendarView by SundeepK.

the class ApplicationTest method setHeight.

public void setHeight(final float height) {
    final Context context = compactCalendarView.getContext();
    ((Activity) context).runOnUiThread(new Runnable() {

        @Override
        public void run() {
            int newHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height, context.getResources().getDisplayMetrics());
            compactCalendarView.getLayoutParams().height = newHeight;
            compactCalendarView.setTargetHeight(newHeight);
            compactCalendarView.requestLayout();
            compactCalendarView.invalidate();
        }
    });
}
Also used : Context(android.content.Context) Activity(android.app.Activity)

Aggregations

Activity (android.app.Activity)3220 Intent (android.content.Intent)612 View (android.view.View)535 Test (org.junit.Test)456 TextView (android.widget.TextView)263 Context (android.content.Context)220 ArrayList (java.util.ArrayList)201 Bundle (android.os.Bundle)197 DialogInterface (android.content.DialogInterface)167 SettingsActivity (com.android.settings.SettingsActivity)167 ViewGroup (android.view.ViewGroup)133 ImageView (android.widget.ImageView)116 AlertDialog (android.app.AlertDialog)109 LayoutInflater (android.view.LayoutInflater)109 Preference (android.support.v7.preference.Preference)83 PackageManager (android.content.pm.PackageManager)76 Uri (android.net.Uri)76 EditText (android.widget.EditText)72 ComponentName (android.content.ComponentName)71 Handler (android.os.Handler)71