Example usage for android.app Activity getSharedPreferences

List of usage examples for android.app Activity getSharedPreferences

Introduction

In this page you can find the example usage for android.app Activity getSharedPreferences.

Prototype

@Override
    public SharedPreferences getSharedPreferences(String name, int mode) 

Source Link

Usage

From source file:pt.hive.cameo.ProxyRequest.java

public static void logout(Activity activity, String loginPath) {
    SharedPreferences preferences = activity.getSharedPreferences("cameo", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.remove("sessionId");
    editor.commit();/*from w  w w  .j a va  2  s.c o m*/
    ProxyRequest request = new ProxyRequest();
    request.activity = activity;
    request.showLogin();
}

From source file:org.mariotaku.twidere.util.SwipebackActivityUtils.java

public static void setActivityScreenshot(final Activity activity, final Intent target) {
    if (activity == null || target == null)
        return;//from  www  . j ava 2s.  c  o m
    final SharedPreferences prefs = activity.getSharedPreferences(SHARED_PREFERENCES_NAME,
            Context.MODE_PRIVATE);
    if (!prefs.getBoolean(KEY_SWIPE_BACK, false))
        return;
    final TwidereApplication app = TwidereApplication.getInstance(activity);
    final SwipebackScreenshotManager sm = app.getSwipebackScreenshotManager();
    final long key = System.currentTimeMillis();
    final Bitmap sc = getActivityScreenshot(activity, View.DRAWING_CACHE_QUALITY_LOW);
    sm.put(key, sc, ThemeUtils.isTransparentBackground(activity));
    target.putExtra(EXTRA_ACTIVITY_SCREENSHOT_ID, key);
}

From source file:de.vanita5.twittnuker.util.SwipebackActivityUtils.java

public static void setActivityScreenshot(final Activity activity, final Intent target) {
    if (activity == null || target == null)
        return;// ww  w.  j a  va  2 s . co  m
    final SharedPreferences prefs = activity.getSharedPreferences(SHARED_PREFERENCES_NAME,
            Context.MODE_PRIVATE);
    if (!prefs.getBoolean(KEY_SWIPE_BACK, true))
        return;
    final TwittnukerApplication app = TwittnukerApplication.getInstance(activity);
    final SwipebackScreenshotManager sm = app.getSwipebackScreenshotManager();
    final long key = System.currentTimeMillis();
    final Bitmap sc = getActivityScreenshot(activity, View.DRAWING_CACHE_QUALITY_LOW);
    sm.put(key, sc, ThemeUtils.isTransparentBackground(activity));
    target.putExtra(EXTRA_ACTIVITY_SCREENSHOT_ID, key);
}

From source file:com.apptentive.android.sdk.module.messagecenter.ApptentiveMessageCenter.java

protected static void show(Activity activity) {
    SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    Configuration conf = Configuration.load(activity);
    boolean enableMessageCenter = conf.isMessageCenterEnabled(activity);
    boolean emailRequired = conf.isMessageCenterEmailRequired(activity);
    boolean shouldShowIntroDialog = !enableMessageCenter
            || prefs.getBoolean(Constants.PREF_KEY_MESSAGE_CENTER_SHOULD_SHOW_INTRO_DIALOG, true);
    // TODO: What if there is an incoming message that is unread? Shouldn't they see the Message Center right away?
    if (shouldShowIntroDialog) {
        showIntroDialog(activity, emailRequired);
    } else {//w w w  . j  av  a2  s. c  om
        Intent intent = new Intent();
        intent.setClass(activity, ViewActivity.class);
        intent.putExtra(ActivityContent.KEY, ActivityContent.Type.MESSAGE_CENTER.toString());
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_up_in, R.anim.slide_down_out);
    }
}

From source file:com.apptentive.android.sdk.module.messagecenter.ApptentiveMessageCenter.java

public static void clearPendingMessageCenterPushNotification(Activity activity) {
    SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    String pushData = prefs.getString(Constants.PREF_KEY_PENDING_PUSH_NOTIFICATION, null);
    if (pushData != null) {
        try {/*from ww  w . ja va  2 s .  c  om*/
            JSONObject pushJson = new JSONObject(pushData);
            ApptentiveInternal.PushAction action = ApptentiveInternal.PushAction.unknown;
            if (pushJson.has(ApptentiveInternal.PUSH_ACTION)) {
                action = ApptentiveInternal.PushAction
                        .parse(pushJson.getString(ApptentiveInternal.PUSH_ACTION));
            }
            switch (action) {
            case pmc:
                Log.i("Clearing pending Message Center push notification.");
                prefs.edit().remove(Constants.PREF_KEY_PENDING_PUSH_NOTIFICATION).commit();
                break;
            }
        } catch (JSONException e) {
            Log.w("Error parsing JSON from push notification.", e);
            MetricModule.sendError(activity.getApplicationContext(), e, "Parsing Push notification", pushData);
        }
    }
}

From source file:com.repkap11.repcast.utils.Utils.java

public static void showUpdateDialogIfNecessary(Activity activity) {
    try {//from  ww  w  .j av a 2  s.c o m
        SharedPreferences prefs = activity.getSharedPreferences("CHANGELOG", Context.MODE_PRIVATE);
        int currentVersionCode = activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                0).versionCode;
        boolean hasShownPrevious = prefs.getBoolean("has-shown-prefs-" + (currentVersionCode - 1), false);
        boolean hasShownCurrent = prefs.getBoolean("has-shown-prefs-" + currentVersionCode, false);
        //Log.e(TAG, "hasShownPrevious:" + hasShownPrevious + " hasShownCurrent:" + hasShownCurrent);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("has-shown-prefs-" + currentVersionCode, true);
        editor.putBoolean("has-shown-prefs-" + (currentVersionCode - 1), true);
        if ((hasShownPrevious && !hasShownCurrent)) {
            AlertDialog d = new AlertDialog.Builder(activity)
                    .setTitle("Changelog: App Version " + currentVersionCode)
                    .setMessage(activity.getResources().getString(R.string.changelog_message))
                    .setCancelable(false).setNegativeButton("Close", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                        }
                    }).show();
            //DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
            //int width = metrics.widthPixels;
            //int height = metrics.heightPixels;
            //Log.e(TAG, "Width:" + width + " Height:" + height);
            //d.getWindow().setLayout(width,height);
        }
        editor.apply();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:com.tinyhydra.botd.BotdServerOperations.java

public static void GetTopTen(final Activity activity, final Handler handler, boolean override) {
    final SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0);
    final List<JavaShop> TopTen = new ArrayList<JavaShop>();
    for (int i = 0; i < 10; i++) {
        TopTen.add(new JavaShop());
    }/*ww  w.  j  a v  a  2s  .com*/
    if (settings.getLong(Const.LastTopTenQueryTime, 0) > (Calendar.getInstance().getTimeInMillis() - 180000)
            & !override) {
        Message msg = new Message();
        msg.arg1 = Const.CODE_GETTOPTEN;
        handler.sendMessage(msg);
    } else
        new Thread() {
            @Override
            public void run() {
                BufferedReader in = null;
                try {
                    HttpClient client = new DefaultHttpClient();
                    HttpGet request = new HttpGet();
                    request.setURI(new URI(activity.getResources().getString(R.string.server_url)));
                    HttpResponse response = client.execute(request);
                    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                    StringBuffer sb = new StringBuffer("");
                    String line = "";
                    while ((line = in.readLine()) != null) {
                        sb.append(line);
                    }
                    in.close();
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(Const.LastTopTenQueryResults, sb.toString());
                    editor.putLong(Const.LastTopTenQueryTime, Calendar.getInstance().getTimeInMillis());
                    editor.commit();

                    Message msg = new Message();
                    msg.arg1 = Const.CODE_GETTOPTEN;
                    handler.sendMessage(msg);

                    // more generic error handling
                    //TODO: implement better error handling
                } catch (URISyntaxException usex) {
                    usex.printStackTrace();
                    Utils.PostToastMessageToHandler(handler,
                            "Unable to retrieve Brew of the day. Poor signal? Please try again",
                            Toast.LENGTH_LONG);
                } catch (ClientProtocolException cpex) {
                    cpex.printStackTrace();
                    Utils.PostToastMessageToHandler(handler,
                            "Unable to retrieve Brew of the day. Poor signal? Please try again",
                            Toast.LENGTH_LONG);
                } catch (IOException iex) {
                    iex.printStackTrace();
                    Utils.PostToastMessageToHandler(handler,
                            "Unable to retrieve Brew of the day. Poor signal? Please try again",
                            Toast.LENGTH_LONG);
                } finally {
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }.start();
}

From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java

public static String getReceiveAddress(Activity context) {
    SharedPreferences prefs = context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE);
    return prefs.getString(BRConstants.RECEIVE_ADDRESS, "");
}

From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java

public static String getFirstAddress(Activity context) {
    SharedPreferences prefs = context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE);
    return prefs.getString(BRConstants.FIRST_ADDRESS, "");
}

From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java

public static long getFeePerKb(Activity context) {
    SharedPreferences prefs = context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE);
    return prefs.getLong(BRConstants.FEE_KB_PREFS, 0);
}