Example usage for android.preference Preference isEnabled

List of usage examples for android.preference Preference isEnabled

Introduction

In this page you can find the example usage for android.preference Preference isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Checks whether this Preference should be enabled in the list.

Usage

From source file:net.sf.aria2.MainActivity.java

private boolean changeAriaServiceState(Preference p) {
    if (p.isEnabled()) {
        // it looks unsightly when current session overlaps with previous one...
        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(R.id.nf_status);

        pref.setEnabled(false);//from ww w  .j  av a  2 s  .  c o m
        uiThreadHandler.postDelayed(() -> pref.setEnabled(true), 4000);

        if (pref.isChecked()) {
            try {
                serviceLink.askToStop();
            } catch (RemoteException e) {
                // likely service process dying during the call
                // let's hope, that onSerivceDisconnected will fix it for us
                e.printStackTrace();

                setPrefEnabled(false);
            }
        } else {
            final Intent intent;
            try {
                intent = new ConfigBuilder(this).constructServiceCommand(new Intent(sericeMoniker))
                        .putExtra(Config.EXTRA_INTERACTIVE, true);

                if (startService(intent) == null)
                    setPrefEnabled(false);
            } catch (Exception e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    }

    return true;
}