Example usage for android.provider Settings ACTION_ACCESSIBILITY_SETTINGS

List of usage examples for android.provider Settings ACTION_ACCESSIBILITY_SETTINGS

Introduction

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

Prototype

String ACTION_ACCESSIBILITY_SETTINGS

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

Click Source Link

Document

Activity Action: Show settings for accessibility modules.

Usage

From source file:mobi.espier.lgc.LgcActivity.java

private void startAccessibilitySetting() {
    try {/* www .  j  a v a  2  s  .  c om*/
        startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
    } catch (Exception e) {
        startActivity(new Intent(Settings.ACTION_SETTINGS));
        e.printStackTrace();
    }
}

From source file:com.futerox.flashlight.MsgPrefs.java

@Override
public boolean onPreferenceClick(Preference preference) {

    if (CallerFlashlight.LOG)
        Log.d(TAG, "preference clicked: " + preference.getKey());
    if (preference.getKey().equals("app_list")) {
        startActivity(new Intent(this, AppList.class));
    } else if (preference.getKey().equals("app_list_check")) {
        //         Toast.makeText(this, "Please enable Notification Service at Accessibility Settings", Toast.LENGTH_LONG).show();
        startActivityForResult(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS), 0);
    }/* w  w  w  . ja  v a2 s  .co m*/

    return false;
}

From source file:com.odo.kcl.mobileminer.activities.MainActivity.java

private void accessibilityNag() {
    AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
    myAlertDialog.setTitle("Store Notifications?");
    myAlertDialog.setMessage("If MobileMiner is to archive notifications from net-enabled apps, "
            + "you need to authorize it as an Accessibility Service. Do this now?");
    myAlertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
        }/*from   w w  w .j a  va  2 s .c o  m*/
    });

    myAlertDialog.setNegativeButton("Not Now", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            // do something when the Cancel button is clicked
        }
    });

    myAlertDialog.show();
}

From source file:com.pluscubed.velociraptor.SettingsActivity.java

@SuppressWarnings("ConstantConditions")
@Override/*from   ww  w. j  a  v  a2  s. c o m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    ButterKnife.bind(this);

    setSupportActionBar(toolbar);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        View marshmallowPermissionsCard = findViewById(R.id.card_m_permissions);
        marshmallowPermissionsCard.setVisibility(View.GONE);
    }

    openStreetMapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ShareCompat.IntentBuilder.from(SettingsActivity.this).setText("https://www.openstreetmap.org")
                    .setType("text/plain").startChooser();
        }
    });

    checkCoverageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mGoogleApiClient = new GoogleApiClient.Builder(SettingsActivity.this)
                    .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                        @Override
                        @SuppressWarnings("MissingPermission")
                        public void onConnected(@Nullable Bundle bundle) {
                            String uriString = "http://product.itoworld.com/map/124";
                            if (isLocationPermissionGranted()) {
                                Location lastLocation = LocationServices.FusedLocationApi
                                        .getLastLocation(mGoogleApiClient);
                                if (lastLocation != null) {
                                    uriString += "?lon=" + lastLocation.getLongitude() + "&lat="
                                            + lastLocation.getLatitude() + "&zoom=12";
                                }
                            }
                            Intent intent = new Intent();
                            intent.setData(Uri.parse(uriString));
                            intent.setAction(Intent.ACTION_VIEW);
                            try {
                                startActivity(intent);
                            } catch (ActivityNotFoundException e) {
                                Snackbar.make(enableFloatingButton, R.string.open_coverage_map_failed,
                                        Snackbar.LENGTH_LONG).show();
                            }

                            mGoogleApiClient.disconnect();
                        }

                        @Override
                        public void onConnectionSuspended(int i) {
                        }
                    }).addApi(LocationServices.API).build();

            mGoogleApiClient.connect();
        }
    });

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    View notifControls = findViewById(R.id.switch_notif_controls);
    notifControls.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(SettingsActivity.this, FloatingService.class);
            intent.putExtra(FloatingService.EXTRA_NOTIF_START, true);
            PendingIntent pending = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent intentClose = new Intent(SettingsActivity.this, FloatingService.class);
            intentClose.putExtra(FloatingService.EXTRA_NOTIF_CLOSE, true);
            PendingIntent pendingClose = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE_CLOSE,
                    intentClose, PendingIntent.FLAG_CANCEL_CURRENT);

            Intent settings = new Intent(SettingsActivity.this, SettingsActivity.class);
            PendingIntent settingsIntent = PendingIntent.getActivity(SettingsActivity.this, PENDING_SETTINGS,
                    settings, PendingIntent.FLAG_CANCEL_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(SettingsActivity.this)
                    .setSmallIcon(R.drawable.ic_speedometer)
                    .setContentTitle(getString(R.string.controls_notif_title))
                    .setContentText(getString(R.string.controls_notif_desc))
                    .addAction(0, getString(R.string.show), pending)
                    .addAction(0, getString(R.string.hide), pendingClose).setDeleteIntent(pendingClose)
                    .setContentIntent(settingsIntent);
            Notification notification = builder.build();
            notificationManager.notify(NOTIFICATION_CONTROLS, notification);
        }
    });

    Button openAppSelection = (Button) findViewById(R.id.button_app_selection);
    openAppSelection.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(SettingsActivity.this, AppSelectionActivity.class));
        }
    });

    autoDisplaySwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this));
    autoDisplaySwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean autoDisplayEnabled = autoDisplaySwitch.isChecked();
            PrefUtils.setAutoDisplay(SettingsActivity.this, autoDisplayEnabled);
            updateAppDetectionEnabled(autoDisplayEnabled);
        }
    });

    enableServiceButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
            } catch (ActivityNotFoundException e) {
                Snackbar.make(enableServiceButton, R.string.open_settings_failed_accessibility,
                        Snackbar.LENGTH_LONG).show();
            }
        }
    });

    enableFloatingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                //Open the current default browswer App Info page
                openSettings(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, BuildConfig.APPLICATION_ID);
            } catch (ActivityNotFoundException ignored) {
                Snackbar.make(enableFloatingButton, R.string.open_settings_failed_overlay, Snackbar.LENGTH_LONG)
                        .show();
            }
        }
    });

    enableLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityCompat.requestPermissions(SettingsActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION);
        }
    });

    ArrayAdapter<String> unitAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text,
            new String[] { "mph", "km/h" });
    unitAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    unitSpinner.setAdapter(unitAdapter);
    unitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (PrefUtils.getUseMetric(SettingsActivity.this) != (position == 1)) {
                PrefUtils.setUseMetric(SettingsActivity.this, position == 1);
                unitSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this,
                        unitSpinner.getSelectedItemPosition() * -48));

                updateFloatingServicePrefs();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    unitSpinner.setSelection(PrefUtils.getUseMetric(this) ? 1 : 0);
    unitSpinner
            .setDropDownVerticalOffset(Utils.convertDpToPx(this, unitSpinner.getSelectedItemPosition() * -48));

    ArrayAdapter<String> styleAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text,
            new String[] { getString(R.string.united_states), getString(R.string.international) });
    styleAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    styleSpinner.setAdapter(styleAdapter);
    styleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position != PrefUtils.getSignStyle(SettingsActivity.this)) {
                PrefUtils.setSignStyle(SettingsActivity.this, position);
                styleSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this,
                        styleSpinner.getSelectedItemPosition() * -48));

                updateFloatingServicePrefs();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    styleSpinner.setSelection(PrefUtils.getSignStyle(this));
    styleSpinner
            .setDropDownVerticalOffset(Utils.convertDpToPx(this, styleSpinner.getSelectedItemPosition() * -48));

    toleranceView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new ToleranceDialogFragment().show(getFragmentManager(), "dialog_tolerance");
        }
    });

    showSpeedometerSwitch.setChecked(PrefUtils.getShowSpeedometer(this));
    ((View) showSpeedometerSwitch.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSpeedometerSwitch.setChecked(!showSpeedometerSwitch.isChecked());

            PrefUtils.setShowSpeedometer(SettingsActivity.this, showSpeedometerSwitch.isChecked());

            updateFloatingServicePrefs();
        }
    });

    debuggingSwitch.setChecked(PrefUtils.isDebuggingEnabled(this));
    ((View) debuggingSwitch.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            debuggingSwitch.setChecked(!debuggingSwitch.isChecked());

            PrefUtils.setDebugging(SettingsActivity.this, debuggingSwitch.isChecked());

            updateFloatingServicePrefs();
        }
    });

    beepSwitch.setChecked(PrefUtils.isBeepAlertEnabled(this));
    beepSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PrefUtils.setBeepAlertEnabled(SettingsActivity.this, beepSwitch.isChecked());
        }
    });
    testBeepButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.playBeep();
        }
    });

    androidAutoSwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this));
    androidAutoSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean checked = androidAutoSwitch.isChecked();
            if (checked) {
                new MaterialDialog.Builder(SettingsActivity.this)
                        .content(R.string.android_auto_instruction_dialog).positiveText(android.R.string.ok)
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, true);
                            }
                        }).show();
            } else {
                PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, checked);
            }
        }
    });

    invalidateStates();

    if (BuildConfig.VERSION_CODE > PrefUtils.getVersionCode(this) && !PrefUtils.isFirstRun(this)) {
        showChangelog();
    }

    billingProcessor = new BillingProcessor(this, getString(R.string.play_license_key),
            new BillingProcessor.IBillingHandler() {
                @Override
                public void onProductPurchased(String productId, TransactionDetails details) {
                    PrefUtils.setSupported(SettingsActivity.this, true);
                    if (Arrays.asList(PURCHASES).contains(productId))
                        billingProcessor.consumePurchase(productId);
                }

                @Override
                public void onPurchaseHistoryRestored() {

                }

                @Override
                public void onBillingError(int errorCode, Throwable error) {
                    if (errorCode != 110) {
                        Snackbar.make(findViewById(android.R.id.content),
                                "Billing error: code = " + errorCode + ", error: "
                                        + (error != null ? error.getMessage() : "?"),
                                Snackbar.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onBillingInitialized() {
                    billingProcessor.loadOwnedPurchasesFromGoogle();
                }
            });

    PrefUtils.setFirstRun(this, false);
    PrefUtils.setVersionCode(this, BuildConfig.VERSION_CODE);
}

From source file:com.pluscubed.velociraptor.settings.SettingsActivity.java

@SuppressWarnings("ConstantConditions")
@Override/*from   w  ww.  j  a  v a 2 s.  com*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    ButterKnife.bind(this);

    setSupportActionBar(toolbar);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        View marshmallowPermissionsCard = findViewById(R.id.card_m_permissions);
        marshmallowPermissionsCard.setVisibility(View.GONE);
    }

    openStreetMapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ShareCompat.IntentBuilder.from(SettingsActivity.this).setText("https://www.openstreetmap.org")
                    .setType("text/plain").startChooser();
        }
    });

    checkCoverageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            googleApiClient = new GoogleApiClient.Builder(SettingsActivity.this)
                    .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                        @Override
                        @SuppressWarnings("MissingPermission")
                        public void onConnected(@Nullable Bundle bundle) {
                            String uriString = "http://product.itoworld.com/map/124";
                            if (Utils.isLocationPermissionGranted(SettingsActivity.this)) {
                                Location lastLocation = LocationServices.FusedLocationApi
                                        .getLastLocation(googleApiClient);
                                if (lastLocation != null) {
                                    uriString += "?lon=" + lastLocation.getLongitude() + "&lat="
                                            + lastLocation.getLatitude() + "&zoom=12";
                                }
                            }
                            Intent intent = new Intent();
                            intent.setData(Uri.parse(uriString));
                            intent.setAction(Intent.ACTION_VIEW);
                            try {
                                startActivity(intent);
                            } catch (ActivityNotFoundException e) {
                                Snackbar.make(enableFloatingButton, R.string.open_coverage_map_failed,
                                        Snackbar.LENGTH_LONG).show();
                            }

                            googleApiClient.disconnect();
                        }

                        @Override
                        public void onConnectionSuspended(int i) {
                        }
                    }).addApi(LocationServices.API).build();

            googleApiClient.connect();
        }
    });

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notifControlsContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(SettingsActivity.this, SpeedLimitService.class);
            intent.putExtra(SpeedLimitService.EXTRA_NOTIF_START, true);
            PendingIntent pending = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent intentClose = new Intent(SettingsActivity.this, SpeedLimitService.class);
            intentClose.putExtra(SpeedLimitService.EXTRA_NOTIF_CLOSE, true);
            PendingIntent pendingClose = PendingIntent.getService(SettingsActivity.this, PENDING_SERVICE_CLOSE,
                    intentClose, PendingIntent.FLAG_CANCEL_CURRENT);

            Intent settings = new Intent(SettingsActivity.this, SettingsActivity.class);
            PendingIntent settingsIntent = PendingIntent.getActivity(SettingsActivity.this, PENDING_SETTINGS,
                    settings, PendingIntent.FLAG_CANCEL_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(SettingsActivity.this)
                    .setSmallIcon(R.drawable.ic_speedometer)
                    .setContentTitle(getString(R.string.controls_notif_title))
                    .setContentText(getString(R.string.controls_notif_desc))
                    .addAction(0, getString(R.string.show), pending)
                    .addAction(0, getString(R.string.hide), pendingClose).setDeleteIntent(pendingClose)
                    .setContentIntent(settingsIntent);
            Notification notification = builder.build();
            notificationManager.notify(NOTIFICATION_CONTROLS, notification);
        }
    });

    appSelectionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(SettingsActivity.this, AppSelectionActivity.class));
        }
    });

    appDetectionSwitch.setChecked(PrefUtils.isAutoDisplayEnabled(this));
    appDetectionContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            appDetectionSwitch.toggle();
            boolean autoDisplayEnabled = appDetectionSwitch.isChecked();
            PrefUtils.setAutoDisplay(SettingsActivity.this, autoDisplayEnabled);
            updateAppDetectionOptionStates();
        }
    });

    enableServiceButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
            } catch (ActivityNotFoundException e) {
                Snackbar.make(enableServiceButton, R.string.open_settings_failed_accessibility,
                        Snackbar.LENGTH_LONG).show();
            }
        }
    });

    enableFloatingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                //Open the current default browswer App Info page
                openSettings(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, BuildConfig.APPLICATION_ID);
            } catch (ActivityNotFoundException ignored) {
                Snackbar.make(enableFloatingButton, R.string.open_settings_failed_overlay, Snackbar.LENGTH_LONG)
                        .show();
            }
        }
    });

    enableLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityCompat.requestPermissions(SettingsActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION);
        }
    });

    ArrayAdapter<String> unitAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text,
            new String[] { "mph", "km/h" });
    unitAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    unitSpinner.setAdapter(unitAdapter);
    unitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (PrefUtils.getUseMetric(SettingsActivity.this) != (position == 1)) {
                PrefUtils.setUseMetric(SettingsActivity.this, position == 1);
                unitSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this,
                        unitSpinner.getSelectedItemPosition() * -48));

                Utils.updateFloatingServicePrefs(SettingsActivity.this);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    unitSpinner.setSelection(PrefUtils.getUseMetric(this) ? 1 : 0);
    unitSpinner
            .setDropDownVerticalOffset(Utils.convertDpToPx(this, unitSpinner.getSelectedItemPosition() * -48));

    ArrayAdapter<String> styleAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_text,
            new String[] { getString(R.string.united_states), getString(R.string.international) });
    styleAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    styleSpinner.setAdapter(styleAdapter);
    styleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position != PrefUtils.getSignStyle(SettingsActivity.this)) {
                PrefUtils.setSignStyle(SettingsActivity.this, position);
                styleSpinner.setDropDownVerticalOffset(Utils.convertDpToPx(SettingsActivity.this,
                        styleSpinner.getSelectedItemPosition() * -48));

                Utils.updateFloatingServicePrefs(SettingsActivity.this);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    styleSpinner.setSelection(PrefUtils.getSignStyle(this));
    styleSpinner
            .setDropDownVerticalOffset(Utils.convertDpToPx(this, styleSpinner.getSelectedItemPosition() * -48));

    toleranceView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new ToleranceDialogFragment().show(getFragmentManager(), "dialog_tolerance");
        }
    });

    sizeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new SizeDialogFragment().show(getFragmentManager(), "dialog_size");
        }
    });

    opacityView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new OpacityDialogFragment().show(getFragmentManager(), "dialog_opacity");
        }
    });

    showSpeedometerSwitch.setChecked(PrefUtils.getShowSpeedometer(this));
    ((View) showSpeedometerSwitch.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSpeedometerSwitch.setChecked(!showSpeedometerSwitch.isChecked());

            PrefUtils.setShowSpeedometer(SettingsActivity.this, showSpeedometerSwitch.isChecked());

            Utils.updateFloatingServicePrefs(SettingsActivity.this);
        }
    });

    debuggingSwitch.setChecked(PrefUtils.isDebuggingEnabled(this));
    ((View) debuggingSwitch.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            debuggingSwitch.setChecked(!debuggingSwitch.isChecked());

            PrefUtils.setDebugging(SettingsActivity.this, debuggingSwitch.isChecked());

            Utils.updateFloatingServicePrefs(SettingsActivity.this);
        }
    });

    beepSwitch.setChecked(PrefUtils.isBeepAlertEnabled(this));
    beepSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PrefUtils.setBeepAlertEnabled(SettingsActivity.this, beepSwitch.isChecked());
        }
    });
    testBeepButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.playBeep();
        }
    });

    androidAutoSwitch.setChecked(PrefUtils.isAutoIntegrationEnabled(this));
    androidAutoContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BuildConfig.FLAVOR.equals("play")) {
                Snackbar.make(findViewById(android.R.id.content), R.string.auto_not_available,
                        Snackbar.LENGTH_LONG).show();
                return;
            }
            if (!androidAutoSwitch.isEnabled()) {
                return;
            }
            androidAutoSwitch.toggle();
            boolean checked = androidAutoSwitch.isChecked();
            if (checked) {
                new MaterialDialog.Builder(SettingsActivity.this)
                        .content(R.string.android_auto_instruction_dialog).positiveText(android.R.string.ok)
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, true);
                            }
                        }).show();
            } else {
                PrefUtils.setAutoIntegrationEnabled(SettingsActivity.this, checked);
            }
        }
    });

    invalidateStates();

    if (BuildConfig.VERSION_CODE > PrefUtils.getVersionCode(this) && !PrefUtils.isFirstRun(this)) {
        showChangelog();
    }

    billingProcessor = new BillingProcessor(this, getString(R.string.play_license_key),
            new BillingProcessor.IBillingHandler() {
                @Override
                public void onProductPurchased(String productId, TransactionDetails details) {
                    PrefUtils.setSupported(SettingsActivity.this, true);
                    if (Arrays.asList(PURCHASES).contains(productId))
                        billingProcessor.consumePurchase(productId);
                }

                @Override
                public void onPurchaseHistoryRestored() {

                }

                @Override
                public void onBillingError(int errorCode, Throwable error) {
                    if (errorCode != 110) {
                        Snackbar.make(findViewById(android.R.id.content),
                                "Billing error: code = " + errorCode + ", error: "
                                        + (error != null ? error.getMessage() : "?"),
                                Snackbar.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onBillingInitialized() {
                    billingProcessor.loadOwnedPurchasesFromGoogle();
                }
            });

    PrefUtils.setFirstRun(this, false);
    PrefUtils.setVersionCode(this, BuildConfig.VERSION_CODE);
}