Example usage for android.provider Settings ACTION_SETTINGS

List of usage examples for android.provider Settings ACTION_SETTINGS

Introduction

In this page you can find the example usage for android.provider Settings ACTION_SETTINGS.

Prototype

String ACTION_SETTINGS

To view the source code for android.provider Settings ACTION_SETTINGS.

Click Source Link

Document

Activity Action: Show system settings.

Usage

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Home.CarBrowse.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == GPS_INTENT) {
        if (networkIntentNeeded) {
            Toast.makeText(getActivity().getApplicationContext(), "Please connect to a network",
                    Toast.LENGTH_LONG).show();

            final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
            startActivityForResult(settingsIntent, SETTINGS_INTENT);
        } else {//from  w w  w.  j a va 2 s .co m
            getAccurateLocation(mMap);
        }
    } else if (requestCode == SETTINGS_INTENT) {
        networkIntentNeeded = false;

        getAccurateLocation(mMap);
    }

}

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.AnalyzeMyDriving.java

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == GPS_INTENT) {
        if (networkIntentNeeded) {
            Toast.makeText(getActivity().getApplicationContext(), "Please connect to a network",
                    Toast.LENGTH_LONG).show();

            final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
            startActivityForResult(settingsIntent, SETTINGS_INTENT);
        } else {//from w  w  w .  j  av  a  2  s.co m
            getAccurateLocation(mMap);
        }
    } else if (requestCode == SETTINGS_INTENT) {
        networkIntentNeeded = false;

        getAccurateLocation(mMap);
    }
}

From source file:com.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java

@Override
public void showText2SpeechAlertDialog() {
    final AlertDialog dialog = new AlertDialog.Builder(this).setMessage(R.string.alert_tts_message)
            //.setTitle(R.string.alert_network_title)
            .setCancelable(true)//from   w w w  . j  a v a 2 s . c om
            .setNegativeButton(R.string.alert_tts_btn_settings, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    userInteraction = true;
                    Intent ttsIntent = new Intent();
                    ttsIntent.setAction(Settings.ACTION_SETTINGS);
                    startActivity(ttsIntent);
                }
            }).setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                    finishActivity();
                    userInteraction = true;
                }
            }).show();
    final Timer t = new Timer();
    t.schedule(new TimerTask() {
        public void run() {
            if (userInteraction == false) {
                dialog.dismiss(); // when the task active then close the dialog
                finishActivity();
            }
            t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
        }
    }, 10000); // after 2 second (or 2000 miliseconds), the task will be active.
}

From source file:nl.hnogames.domoticz.Preference.Preference.java

private void setPreferences() {
    final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference(
            "enableMultiServers");
    android.preference.Preference ServerSettings = findPreference("server_settings");
    android.preference.Preference PermissionsSettings = findPreference("permissionssettings");
    android.preference.Preference NotificationLogged = findPreference("notification_show_logs");
    android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config");
    android.preference.Preference resetApplication = findPreference("reset_settings");
    android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage");
    final android.preference.Preference registrationId = findPreference("notification_registration_id");
    android.preference.Preference GeoSettings = findPreference("geo_settings");
    android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference(
            "enableWearItems");
    android.preference.Preference NFCPreference = findPreference("nfc_settings");
    android.preference.Preference QRCodePreference = findPreference("qrcode_settings");
    android.preference.Preference SpeechPreference = findPreference("speech_settings");
    android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference(
            "enableNFC");
    android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference(
            "enableQRCode");
    android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference(
            "enableSpeech");
    android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference(
            "talkBack");
    MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference(
            "alwayson");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference(
            "settingsscreen");
    android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference(
            "premium_category");
    android.preference.Preference premiumPreference = findPreference("premium_settings");
    NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "suppressNotifications");
    NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "alarmNotifications");
    android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference(
            "darkTheme");
    android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings");
    android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference(
            "enableSecurity");

    if (!BuildConfig.DEBUG) {
        PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference(
                "androidautocategory");
        PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference(
                "notificationscreen");
        oNotificationScreen.removePreference(oAndroidAutoCategory);
    }//from www .  j  a  v  a2s.  c om

    List<String> notifications = mSharedPrefs.getReceivedNotifications();
    if (notifications == null || notifications.size() <= 0) {
        notificationsMultiSelectListPreference.setEnabled(false);
        alarmMultiSelectListPreference.setEnabled(false);
    } else {
        notificationsMultiSelectListPreference.setEnabled(true);
        alarmMultiSelectListPreference.setEnabled(true);
    }

    PermissionsSettings
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    permissionHelper.openSettingsScreen();
                    return true;
                }
            });

    drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
            try {
                final HashSet selectedDrawerItems = (HashSet) newValue;
                if (selectedDrawerItems.size() < 1) {
                    showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer));
                    return false;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }
    });

    ThemePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_theme));
                        return false;
                    } else {
                        ((SettingsActivity) getActivity()).reloadSettings();
                        return true;
                    }
                }
            });

    MultiServerPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.multi_server));
                        return false;
                    }
                    return true;
                }
            });

    ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (!MultiServerPreference.isChecked()) {
                Intent intent = new Intent(mContext, ServerSettingsActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(mContext, ServerListSettingsActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    FingerPrintSettingsPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                    return true;
                }
            });

    fetchServerConfig
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() {
                        @Override
                        public void onReceiveConfig(ConfigInfo settings) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_success));
                        }

                        @Override
                        public void onError(Exception error) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_failed));
                        }
                    }, null);
                    return true;
                }
            });

    displayLanguage
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    showRestartMessage();
                    return true;
                }
            });

    registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!PermissionsUtil.canAccessDeviceState(mContext)) {
                    permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS);
                } else {
                    pushGCMRegistrationIds();
                }
            } else {
                pushGCMRegistrationIds();
            }
            return true;
        }
    });

    GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.geofence));
                return false;
            } else {
                Intent intent = new Intent(mContext, GeoSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    EnableNFCPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_nfc));
                        return false;
                    }

                    if (NfcAdapter.getDefaultAdapter(mContext) == null) {
                        showSnackbar(mContext.getString(R.string.nfc_not_supported));
                        return false;
                    }
                    return true;
                }
            });

    EnableQRCodePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    }

                    return true;
                }
            });

    EnableSpeechPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    }
                    return true;
                }
            });

    EnableTalkBackPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_talk_back));
                        return false;
                    }
                    return true;
                }
            });

    NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.category_nfc));
                return false;
            } else {
                Intent intent = new Intent(mContext, NFCSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    QRCodePreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, QRCodeSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    SpeechPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, SpeechSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    WearPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_wear));
                        return false;
                    }
                    return true;
                }
            });

    AlwaysOnPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.always_on_title));
                        return false;
                    }
                    return true;
                }
            });

    NotificationLogged
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    //show dialog
                    List<String> logs = mSharedPrefs.getLoggedNotifications();
                    if (logs != null && logs.size() > 0) {
                        Collections.reverse(logs);
                        new MaterialDialog.Builder(mContext)
                                .title(mContext.getString(R.string.notification_show_title))
                                .items((CharSequence[]) logs.toArray(new String[0])).show();
                    } else
                        UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing),
                                Toast.LENGTH_LONG);
                    return true;
                }
            });

    //noinspection PointlessBooleanExpression
    if (!BuildConfig.LITE_VERSION) {
        preferenceScreen.removePreference(premiumCategory);
    } else {
        premiumPreference
                .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(android.preference.Preference preference) {
                        String packageID = mContext.getPackageName() + ".premium";
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + packageID)));
                        } catch (android.content.ActivityNotFoundException ignored) {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("https://play.google.com/store/apps/details?id=" + packageID)));
                        }

                        return true;
                    }
                });
    }

    resetApplication
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        new MaterialDialog.Builder(mContext).title(R.string.category_Reset)
                                .content(R.string.are_you_sure).positiveText(R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @SuppressLint("NewApi")
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE))
                                                .clearApplicationUserData();
                                    }
                                }).show();
                    } else {
                        startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
                    }
                    return true;
                }
            });

    FingerPrintPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @SuppressLint("NewApi")
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object o) {
                    if (mSharedPrefs.isStartupSecurityEnabled())
                        return true;
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_startup_security));
                        return false;
                    } else {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                            UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported),
                                    Toast.LENGTH_LONG);
                            return false;
                        }
                        if (!PermissionsUtil.canAccessFingerprint(mContext)) {
                            permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS);
                        } else {
                            FingerprintManager fingerprintManager = (FingerprintManager) mContext
                                    .getSystemService(Context.FINGERPRINT_SERVICE);
                            if (ActivityCompat.checkSelfPermission(mContext,
                                    Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                                return false;
                            }
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                if (!fingerprintManager.isHardwareDetected()) {
                                    return false;
                                } else if (!fingerprintManager.hasEnrolledFingerprints()) {
                                    UsefulBits.showSimpleToast(mContext,
                                            getString(R.string.fingerprint_not_setup_in_android),
                                            Toast.LENGTH_LONG);
                                    return false;
                                } else {
                                    new MaterialDialog.Builder(mContext)
                                            .title(R.string.category_startup_security)
                                            .content(R.string.fingerprint_sure).positiveText(R.string.ok)
                                            .negativeText(R.string.cancel)
                                            .onPositive(new MaterialDialog.SingleButtonCallback() {
                                                @Override
                                                public void onClick(@NonNull MaterialDialog dialog,
                                                        @NonNull DialogAction which) {
                                                    mSharedPrefs.setStartupSecurityEnabled(true);
                                                    ((SettingsActivity) getActivity()).reloadSettings();
                                                }
                                            }).show();

                                    return false;
                                }
                            }
                        }
                    }
                    return false;
                }
            });
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)// www  .  j a va2 s. co  m
@Override
public boolean onPreferenceClick(Preference p) {
    UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
    LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
    boolean appIsValid = isStartButton || isOverflowMenu
            || !launcherApps.getActivityList(getIntent().getStringExtra("package_name"),
                    userManager.getUserForSerialNumber(userId)).isEmpty();

    if (appIsValid)
        switch (p.getKey()) {
        case "app_info":
            startFreeformActivity();
            launcherApps.startAppDetailsActivity(ComponentName.unflattenFromString(componentName),
                    userManager.getUserForSerialNumber(userId), null, null);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "uninstall":
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInMultiWindowMode()) {
                Intent intent2 = new Intent(ContextMenuActivity.this, DummyActivity.class);
                intent2.putExtra("uninstall", packageName);
                intent2.putExtra("user_id", userId);

                startFreeformActivity();
                startActivity(intent2);
            } else {
                startFreeformActivity();

                Intent intent2 = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + packageName));
                intent2.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(userId));

                try {
                    startActivity(intent2);
                } catch (ActivityNotFoundException e) {
                    /* Gracefully fail */ }
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "open_taskbar_settings":
            startFreeformActivity();

            Intent intent2 = new Intent(this, MainActivity.class);
            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent2);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "quit_taskbar":
            Intent quitIntent = new Intent("com.farmerbb.taskbar.QUIT");
            quitIntent.setPackage(BuildConfig.APPLICATION_ID);
            sendBroadcast(quitIntent);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "pin_app":
            PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);
            if (pba.isPinned(componentName))
                pba.removePinnedApp(this, componentName);
            else {
                Intent intent = new Intent();
                intent.setComponent(ComponentName.unflattenFromString(componentName));

                LauncherActivityInfo appInfo = launcherApps.resolveActivity(intent,
                        userManager.getUserForSerialNumber(userId));
                if (appInfo != null) {
                    AppEntry newEntry = new AppEntry(packageName, componentName, appName,
                            IconCache.getInstance(this).getIcon(this, getPackageManager(), appInfo), true);

                    newEntry.setUserId(userId);
                    pba.addPinnedApp(this, newEntry);
                }
            }
            break;
        case "block_app":
            PinnedBlockedApps pba2 = PinnedBlockedApps.getInstance(this);
            if (pba2.isBlocked(componentName))
                pba2.removeBlockedApp(this, componentName);
            else {
                pba2.addBlockedApp(this, new AppEntry(packageName, componentName, appName, null, false));
            }
            break;
        case "show_window_sizes":
            getPreferenceScreen().removeAll();

            addPreferencesFromResource(R.xml.pref_context_menu_window_size_list);
            findPreference("window_size_standard").setOnPreferenceClickListener(this);
            findPreference("window_size_large").setOnPreferenceClickListener(this);
            findPreference("window_size_fullscreen").setOnPreferenceClickListener(this);
            findPreference("window_size_half_left").setOnPreferenceClickListener(this);
            findPreference("window_size_half_right").setOnPreferenceClickListener(this);
            findPreference("window_size_phone_size").setOnPreferenceClickListener(this);

            SharedPreferences pref = U.getSharedPreferences(this);
            if (pref.getBoolean("save_window_sizes", true)) {
                String windowSizePref = SavedWindowSizes.getInstance(this).getWindowSize(this, packageName);
                CharSequence title = findPreference("window_size_" + windowSizePref).getTitle();
                findPreference("window_size_" + windowSizePref).setTitle('\u2713' + " " + title);
            }

            if (U.isOPreview()) {
                U.showToast(this, R.string.window_sizes_not_available);
            }

            secondaryMenu = true;
            break;
        case "window_size_standard":
        case "window_size_large":
        case "window_size_fullscreen":
        case "window_size_half_left":
        case "window_size_half_right":
        case "window_size_phone_size":
            String windowSize = p.getKey().replace("window_size_", "");

            SharedPreferences pref2 = U.getSharedPreferences(this);
            if (pref2.getBoolean("save_window_sizes", true)) {
                SavedWindowSizes.getInstance(this).setWindowSize(this, packageName, windowSize);
            }

            startFreeformActivity();
            U.launchApp(getApplicationContext(), packageName, componentName, userId, windowSize, false, true);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "app_shortcuts":
            getPreferenceScreen().removeAll();
            generateShortcuts();

            secondaryMenu = true;
            break;
        case "shortcut_1":
        case "shortcut_2":
        case "shortcut_3":
        case "shortcut_4":
        case "shortcut_5":
            U.startShortcut(getApplicationContext(), packageName, componentName,
                    shortcuts.get(Integer.parseInt(p.getKey().replace("shortcut_", "")) - 1));

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "start_menu_apps":
            startFreeformActivity();

            Intent intent = null;

            SharedPreferences pref3 = U.getSharedPreferences(this);
            switch (pref3.getString("theme", "light")) {
            case "light":
                intent = new Intent(this, SelectAppActivity.class);
                break;
            case "dark":
                intent = new Intent(this, SelectAppActivityDark.class);
                break;
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref3.getBoolean("freeform_hack", false)
                    && intent != null && isInMultiWindowMode()) {
                intent.putExtra("no_shadow", true);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);

                U.launchAppMaximized(getApplicationContext(), intent);
            } else
                startActivity(intent);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "volume":
            AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE);
            audio.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, AudioManager.USE_DEFAULT_STREAM_TYPE,
                    AudioManager.FLAG_SHOW_UI);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "file_manager":
            Intent fileManagerIntent;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                startFreeformActivity();
                fileManagerIntent = new Intent("android.provider.action.BROWSE");
            } else {
                fileManagerIntent = new Intent("android.provider.action.BROWSE_DOCUMENT_ROOT");
                fileManagerIntent.setComponent(
                        ComponentName.unflattenFromString("com.android.documentsui/.DocumentsActivity"));
            }

            fileManagerIntent.addCategory(Intent.CATEGORY_DEFAULT);
            fileManagerIntent
                    .setData(Uri.parse("content://com.android.externalstorage.documents/root/primary"));

            try {
                startActivity(fileManagerIntent);
            } catch (ActivityNotFoundException e) {
                U.showToast(this, R.string.lock_device_not_supported);
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "system_settings":
            startFreeformActivity();

            Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);

            try {
                startActivity(settingsIntent);
            } catch (ActivityNotFoundException e) {
                U.showToast(this, R.string.lock_device_not_supported);
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "lock_device":
            U.lockDevice(this);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "power_menu":
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "change_wallpaper":
            Intent intent3 = Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
                    getString(R.string.set_wallpaper));
            intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            U.launchAppMaximized(getApplicationContext(), intent3);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        }

    if (!secondaryMenu)
        finish();
    return true;
}

From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java

private boolean setLocationInformation() {
    // returns false if GPS and Network settings are needed
    final ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && (networkInfo != null && networkInfo.isConnected())) {
        if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(getApplicationContext(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return true;
        }//from  www .j a v  a 2  s. com

        locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);

        final List<String> providers = locationManager.getProviders(true);
        Location finalLocation = null;

        for (String provider : providers) {
            if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getApplicationContext(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return true;
            }

            final Location lastKnown = locationManager.getLastKnownLocation(provider);

            if (lastKnown == null) {
                continue;
            }
            if (finalLocation == null || (lastKnown.getAccuracy() < finalLocation.getAccuracy())) {
                finalLocation = lastKnown;
            }
        }

        if (finalLocation == null) {
            Log.e("Location Data", "Not Working!");
        } else {
            Log.d("Location Data", finalLocation.getLatitude() + " " + finalLocation.getLongitude() + "");
            location = finalLocation;
        }

        return true;
    } else {
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Toast.makeText(getApplicationContext(), "Please turn on your GPS", Toast.LENGTH_LONG).show();

            final Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivityForResult(gpsIntent, GPS_INTENT);

            if (networkInfo == null) {
                networkIntentNeeded = true;
            }
            return false;
        } else {
            if (networkInfo == null) {
                Toast.makeText(getApplicationContext(), "Please turn on Mobile Data or WIFI", Toast.LENGTH_LONG)
                        .show();

                final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
                startActivityForResult(settingsIntent, SETTINGS_INTENT);
                return false;
            } else {
                return true;
            }
        }
    }
}

From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == GPS_INTENT) {
        if (networkIntentNeeded) {
            Toast.makeText(getApplicationContext(), "Please connect to a network", Toast.LENGTH_LONG).show();
            final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
            startActivityForResult(settingsIntent, SETTINGS_INTENT);

        } else {//w w  w.  j a v a2s  .  com
            setLocationInformation();
            startApp2();
        }
    } else if (requestCode == SETTINGS_INTENT) {
        networkIntentNeeded = false;
        setLocationInformation();
        startApp2();

    } else if (requestCode == BLUETOOTH_REQUEST) {
        startApp2();
    }
}

From source file:com.android.launcher2.Launcher.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (isWorkspaceLocked()) {
        return false;
    }//from w ww .jav  a2  s .  co  m

    super.onCreateOptionsMenu(menu);

    Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
    manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
    settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    String helpUrl = getString(R.string.help_url);
    Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
    help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

    menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
            .setIcon(android.R.drawable.ic_menu_gallery).setAlphabeticShortcut('W');
    menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps).setIcon(android.R.drawable.ic_menu_manage)
            .setIntent(manageApps).setAlphabeticShortcut('M');
    menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings).setIcon(android.R.drawable.ic_menu_preferences)
            .setIntent(settings).setAlphabeticShortcut('P');
    if (!helpUrl.isEmpty()) {
        menu.add(0, MENU_HELP, 0, R.string.menu_help).setIcon(android.R.drawable.ic_menu_help).setIntent(help)
                .setAlphabeticShortcut('H');
    }
    return true;
}