Example usage for android.content SharedPreferences getBoolean

List of usage examples for android.content SharedPreferences getBoolean

Introduction

In this page you can find the example usage for android.content SharedPreferences getBoolean.

Prototype

boolean getBoolean(String key, boolean defValue);

Source Link

Document

Retrieve a boolean value from the preferences.

Usage

From source file:com.rothconsulting.android.websms.connector.mbudget.ConnectorMBudget.java

/**
 * {@inheritDoc}//w  w  w.  ja v a 2  s.com
 */
@Override
public final ConnectorSpec updateSpec(final Context context, final ConnectorSpec connectorSpec) {
    this.log("*************************************");
    this.log("** Start updateSpec");
    this.log("*************************************");
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    if (p.getBoolean(Preferences.PREFS_ENABLED, false)) {
        if (p.getString(Preferences.PREFS_USER, "").length() > 0 && p.getString(Preferences.PREFS_PASSWORD, "") // .
                .length() > 0) {
            connectorSpec.setReady();
        } else {
            connectorSpec.setStatus(ConnectorSpec.STATUS_ENABLED);
        }
    } else {
        connectorSpec.setStatus(ConnectorSpec.STATUS_INACTIVE);
    }
    this.log("*************************************");
    this.log("** Ende updateSpec");
    this.log("*************************************");
    return connectorSpec;
}

From source file:jieehd.villain.updater.VillainUpdater.java

public void getPrefs() {
    boolean info_show_check;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    info_show_check = prefs.getBoolean("info_show", true);

    if (info_show_check == true) {
        showInfo();/*from   w ww  .j a  v a2  s.  co m*/
    } else {

    }
}

From source file:com.dngames.mobilewebcam.PhotoSettings.java

public static void GETSettings(final Context context) {
    // check for new settings when done
    final SharedPreferences prefs = context.getSharedPreferences(MobileWebCam.SHARED_PREFS_NAME, 0);
    final String settingsurl = prefs.getString("remote_config_url", "");
    final int settingsfreq = Math.max(1, PhotoSettings.getEditInt(context, prefs, "remote_config_every", 1));
    final String login = prefs.getString("remote_config_login", "");
    final String password = prefs.getString("remote_config_password", "");
    final boolean noToasts = prefs.getBoolean("no_messages", false);
    if (settingsurl.length() > 0 && gLastGETSettingsPictureCnt < MobileWebCam.gPictureCounter
            && (MobileWebCam.gPictureCounter % settingsfreq) == 0) {
        gLastGETSettingsPictureCnt = MobileWebCam.gPictureCounter;

        Handler h = new Handler(context.getMainLooper());
        h.post(new Runnable() {
            @Override/* w  ww.j  a v a 2 s  .  c  o m*/
            public void run() {
                new AsyncTask<String, Void, String>() {
                    @Override
                    protected String doInBackground(String... params) {
                        try {
                            DefaultHttpClient httpclient = new DefaultHttpClient();
                            if (login.length() > 0) {
                                try {
                                    ((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
                                            new AuthScope(null, -1),
                                            new UsernamePasswordCredentials(login, password));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    if (e.getMessage() != null)
                                        MobileWebCam.LogE("http login " + e.getMessage());
                                    else
                                        MobileWebCam.LogE("http: unable to log in");

                                    return null;
                                }
                            }
                            HttpGet get = new HttpGet(settingsurl);
                            HttpResponse response = httpclient.execute(get);
                            HttpEntity ht = response.getEntity();
                            BufferedHttpEntity buf = new BufferedHttpEntity(ht);
                            InputStream is = buf.getContent();
                            BufferedReader r = new BufferedReader(new InputStreamReader(is));
                            StringBuilder total = new StringBuilder();
                            String line;
                            while ((line = r.readLine()) != null)
                                total.append(line + "\n");

                            if (ht.getContentType().getValue().startsWith("text/plain"))
                                return total.toString();
                            else
                                return "GET Config Error!\n" + total.toString();
                        } catch (Exception e) {
                            e.printStackTrace();
                            if (e.getMessage() != null) {
                                MobileWebCam.LogE(e.getMessage());
                                return "GET Config Error!\n" + e.getMessage();
                            }
                        }

                        return null;
                    }

                    @Override
                    protected void onPostExecute(String result) {
                        if (result != null) {
                            if (result.startsWith("GET Config Error!\n")) {
                                if (!noToasts)
                                    Toast.makeText(context, result, Toast.LENGTH_SHORT).show();
                            } else {
                                PhotoSettings.GETSettings(context, result, prefs);
                            }
                        } else if (!noToasts)
                            Toast.makeText(context, "GET config failed!", Toast.LENGTH_SHORT).show();
                    }
                }.execute();
            }
        });
    }
}

From source file:com.asksven.betterbatterystats.data.KbReader.java

public KbData read(Context ctx) {
    if (LogSettings.DEBUG) {
        Log.i(TAG, "read called");
    }/*  ww  w . j av a2 s  .  com*/
    if (m_cache == null) {
        if (LogSettings.DEBUG) {
            Log.i(TAG, "Cache is empty");
        }
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);

        // first check if cache is present and not outdated
        KbDbHelper myDB = KbDbHelper.getInstance(ctx);

        List<KbEntry> myEntries = myDB.fetchAllRows();

        // if cache exists and is not outdaten use it
        long cachedMillis = sharedPrefs.getLong("cache_updated", 0);
        long dateMillis = Calendar.getInstance().getTimeInMillis();
        boolean useCaching = sharedPrefs.getBoolean("cache_kb", true);

        // if cache is not empty, cache not older than 24 hours and caching is on
        if ((myEntries != null) && (myEntries.size() > 0) && (useCaching)
                && ((dateMillis - cachedMillis) < MAX_CACHE_AGE_MILLIS)) {
            m_cache = new KbData();
            m_cache.setEntries(myEntries);
        } else {
            if (LogSettings.DEBUG) {
                Log.i(TAG, "Starting service to retrieve KB");
            }
            // start async service to retrieve KB if not already running
            if (!KbReaderService.isTransactional()) {
                Intent serviceIntent = new Intent(ctx, KbReaderService.class);
                ctx.startService(serviceIntent);
            }
        }
    } else {
        if (LogSettings.DEBUG) {
            Log.i(TAG, "returning cached KB");
        }
    }
    return m_cache;
}

From source file:com.example.ronald.tracle.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new DownloadTask().execute("https://flifo-qa.api.aero/flifo/v3/flight/sin/sq/998/d");
    /*//from   ww w. j  av a  2s  .  c  o  m
    Parsing of data from previous activity
     */
    String username = getIntent().getStringExtra("name");
    String password = getIntent().getStringExtra("password");
    String alias = getIntent().getStringExtra("alias");
    myUser = username;
    pw = password;
    /*
    Declare your layout here
     */

    Button sendBtn = (Button) findViewById(R.id.buttonSendAll);

    TextView nametv = (TextView) findViewById(R.id.username);
    TextView emailtv = (TextView) findViewById(R.id.email);
    emailtv.setText(username);
    nametv.setText(alias);

    // Initializing Toolbar and setting it as the actionbar
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //Initializing NavigationView
    navigationView = (NavigationView) findViewById(R.id.navigation_view);

    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            //Checking if the item is in checked state or not, if not make it in checked state
            if (menuItem.isChecked())
                menuItem.setChecked(false);
            else
                menuItem.setChecked(true);

            //Closing drawer on item click
            drawerLayout.closeDrawers();

            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {

            //Replacing the main content with ContentFragment Which is our Inbox View;
            case R.id.home:
                Intent intent = new Intent(MainActivity.this, MainActivity.class);
                startActivity(intent);
                return true;
            case R.id.explore:
                Intent intente = new Intent(MainActivity.this, SlideTab.class);
                startActivity(intente);
                return true;
            case R.id.network:
                Intent intentk = new Intent(MainActivity.this, SlideTab.class);
                startActivity(intentk);
                return true;
            case R.id.announcement:
                Intent intenti = new Intent(MainActivity.this, AnnounceActivity.class);
                startActivity(intenti);
                return true;
            case R.id.setting:
                String username = "";
                String pw = "";
                String PREFS_LOGIN_USERNAME_KEY = "";
                String PREFS_LOGIN_PASSWORD_KEY = "";
                PrefUtils.saveToPrefs(getApplication(), PREFS_LOGIN_USERNAME_KEY, username);
                PrefUtils.saveToPrefs(getApplication(), PREFS_LOGIN_PASSWORD_KEY, pw);
                System.exit(0);
                return true;
            // For rest of the options we just show a toast on click
            default:
                Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
                return true;

            }
        }
    });

    // Initializing Drawer Layout and ActionBarToggle
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.openDrawer, R.string.closeDrawer) {

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank

            super.onDrawerOpened(drawerView);
        }
    };

    //Setting the actionbarToggle to drawer layout
    drawerLayout.setDrawerListener(actionBarDrawerToggle);

    //Toast.makeText(this, "username: "+username+" pw: "+password, Toast.LENGTH_SHORT).show();

    //calling sync state is necessay or else your hamburger icon wont show up
    actionBarDrawerToggle.syncState();

    /*
    This is the initial step in getting back the token from GCM
     */
    //mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                //  mInformationTextView.setText(getString(R.string.gcm_send_message));
            } else {
                // mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };
    //mInformationTextView = (TextView) findViewById(R.id.informationTextView);

    /*
    Check play services, if not GCM won't work.
     */
    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        Bundle localBundle = new Bundle();
        localBundle.putString("name", username);
        localBundle.putString("password", password);
        intent.putExtras(localBundle);
        startService(intent);
    }

}

From source file:by.zatta.pilight.connection.ConnectionService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    //??/*from   w w  w.j a  va 2s  .c  o  m*/

    sendMessageToUI(MSG_SET_STATUS, mCurrentNotif.name());
    if (intent.hasExtra("command") && isConnectionUp) {
        Server.CONNECTION
                .sentCommand("{\"message\":\"send\",\"code\":{" + intent.getStringExtra("command") + "}}");
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(aCtx);
        boolean useService = prefs.getBoolean("useService", true);
        if (!useService) {
            if (mWM == null || !mWM.isAlive()) {
                mWM = new WriteMonitor();
                mWM.setName("WriteMonitor");
                mWM.start();
            }
        }
    }
    return START_STICKY;
}

From source file:de.ub0r.android.websms.connector.fishtext.ConnectorFishtext.java

/**
 * Login to fishtext.com./*from   w w w .  j  a v  a  2  s  .  com*/
 * 
 * @param context
 *            {@link Context}
 * @param command
 *            {@link ConnectorCommand}
 * @throws IOException
 *             IOException
 */
private void doLogin(final Context context, final ConnectorCommand command) throws IOException {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);

    ArrayList<BasicNameValuePair> postData = // .
            new ArrayList<BasicNameValuePair>(NUM_VARS_LOGIN);
    postData.add(new BasicNameValuePair("action", "login"));
    String genlogin;
    if (p.getBoolean(PREFS_LOGIN_WTIH_DEFAULT, false)) {
        genlogin = command.getDefSender();
    } else {
        genlogin = Utils.getSender(context, command.getDefSender());
    }
    Log.d(TAG, "genlogin:  " + genlogin);
    if (genlogin.startsWith("+")) {
        genlogin = genlogin.substring(1);
    } else if (genlogin.startsWith("00")) {
        genlogin = genlogin.substring(2);
    }
    Log.d(TAG, "genlogin:  " + genlogin);
    // postData.add(new BasicNameValuePair("mobile", userlogin));
    postData.add(new BasicNameValuePair("mobile", genlogin));
    Log.d(TAG, "genlogin:  " + genlogin);
    postData.add(new BasicNameValuePair("password", p.getString(Preferences.PREFS_PASSWORD, "")));
    postData.add(new BasicNameValuePair("rememberSession", "yes"));

    HttpResponse response = Utils.getHttpClient(URL_LOGIN, null, postData, TARGET_AGENT, null, ENCODING, false);
    postData = null;
    int resp = response.getStatusLine().getStatusCode();
    if (resp != HttpURLConnection.HTTP_OK) {
        throw new WebSMSException(context, R.string.error_http, "" + resp);
    }
    final String htmlText = Utils.stream2str(response.getEntity().getContent());
    Log.d(TAG, "----HTTP RESPONSE---");
    Log.d(TAG, htmlText);
    Log.d(TAG, "----HTTP RESPONSE---");

    final int i = htmlText.indexOf(CHECK_BALANCE);
    if (i < 0) {
        Utils.clearCookies();
        throw new WebSMSException(context, R.string.error_pw);
    }
    final int j = htmlText.indexOf("<p>", i);
    if (j > 0) {
        final int h = htmlText.indexOf("</p>", j);
        if (h > 0) {
            String b = htmlText.substring(j + 3, h);
            if (b.startsWith("&euro;")) {
                b = b.substring(6) + "\u20AC";
            }
            b.replaceAll("&pound; *", "\u00A3");
            Log.d(TAG, "balance: " + b);
            this.getSpec(context).setBalance(b);
        }
    }
}

From source file:ota.otaupdates.MainActivity.java

private void trigger_autoinstall(final String file_path) {
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final CoordinatorLayout coordinator_root = (CoordinatorLayout) findViewById(R.id.coordinator_root);
    if (sharedPreferences.getBoolean("enable_auto_install", true)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.auto_install_title));
        builder.setMessage(getString(R.string.auto_install_message));
        builder.setPositiveButton(getString(R.string.button_yes), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                if (Shell.SU.available()) {
                    Shell.SU.run("rm -rf /cache/recovery/openrecoveryscript");
                    Shell.SU.run("echo \"install " + file_path + "\" >> /cache/recovery/openrecoveryscript");

                    if (sharedPreferences.getBoolean("wipe_cache", true))
                        Shell.SU.run("echo \"wipe cache\" >> /cache/recovery/openrecoveryscript");

                    if (sharedPreferences.getBoolean("wipe_dalvik", true))
                        Shell.SU.run("echo \"wipe dalvik\" >> /cache/recovery/openrecoveryscript");

                    if (sharedPreferences.getBoolean("auto_reboot", true))
                        Shell.SU.run("reboot recovery");
                } else {
                    sb_no_su = Snackbar.make(coordinator_root, "SU access is not available",
                            Snackbar.LENGTH_SHORT);
                    sb_no_su.getView()/* w w  w.  jav  a  2  s .  c  o m*/
                            .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorSecond));
                    sb_no_su.show();
                }
            }
        });
        builder.setNegativeButton(getString(R.string.button_no), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        AlertDialog alert = builder.create();
        alert.setCancelable(false);
        alert.show();
    }
}

From source file:com.gimranov.zandy.app.task.ZoteroAPITask.java

public ZoteroAPITask(Context c) {
    this.queue = new ArrayList<APIRequest>();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    userID = settings.getString("user_id", null);
    key = settings.getString("user_key", null);
    if (settings.getBoolean("sync_aggressively", false))
        syncMode = AUTO_SYNC_STALE_COLLECTIONS;
    deletions = APIRequest.delete(c);//from  www .  j  av a 2s. co m
    db = new Database(c);
}

From source file:com.gimranov.zandy.app.task.ZoteroAPITask.java

public ZoteroAPITask(Context c, CursorAdapter adapter) {
    this.queue = new ArrayList<APIRequest>();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    userID = settings.getString("user_id", null);
    key = settings.getString("user_key", null);
    if (settings.getBoolean("sync_aggressively", false))
        syncMode = AUTO_SYNC_STALE_COLLECTIONS;
    deletions = APIRequest.delete(c);/*from   w  w  w  .j  a  v  a2s. co  m*/
    db = new Database(c);

}