Example #1
1
 /**
  * Download a file using Android download manager.
  *
  * @param url URL to download
  * @param fileName Destination file name
  * @param title Notification title
  * @param description Notification description
  */
 public static void downloadFile(
     Context context, String url, String fileName, String title, String description) {
   String authToken = PreferenceUtil.getAuthToken(context);
   DownloadManager downloadManager =
       (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
   DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
   request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
   request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
   request.addRequestHeader("Cookie", "auth_token=" + authToken);
   request.setTitle(title);
   request.setDescription(description);
   downloadManager.enqueue(request);
 }
Example #2
0
  /**
   * Check if there was an out of memory error, and if so, display a corresponding message.
   *
   * @param activity the triggering activity
   */
  public static void checkOutOfMemoryError(@NonNull final Activity activity) {
    boolean hadOutOfMemoryError =
        PreferenceUtil.getSharedPreferenceBoolean(R.string.key_internal_outofmemoryerror);

    if (hadOutOfMemoryError) {
      displayError(activity, R.string.message_dialog_outofmemoryerror, false);

      PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_outofmemoryerror, false);
    }
  }
 @SmallTest
 public void testGetEnum() {
   SharedPreferences sharedPreferences =
       MozcPreferenceUtil.getSharedPreferences(
           getInstrumentation().getContext(), "CLIENT_SIDE_PREF");
   SharedPreferences.Editor editor = sharedPreferences.edit();
   String key1 = "key1";
   editor.putString(key1, "ALPHA");
   String key2 = "key2";
   editor.putString(key2, "DELTA");
   editor.commit();
   assertEquals(
       TestGetEnum.BETA,
       PreferenceUtil.getEnum(
           sharedPreferences, key1, TestGetEnum.class, TestGetEnum.GAMMA, TestGetEnum.BETA));
   assertEquals(
       TestGetEnum.GAMMA,
       PreferenceUtil.getEnum(sharedPreferences, key1, TestGetEnum.class, TestGetEnum.GAMMA));
   assertEquals(
       TestGetEnum.DELTA,
       PreferenceUtil.getEnum(sharedPreferences, key2, TestGetEnum.class, TestGetEnum.GAMMA));
 }
  /** Load from preferences file. */
  private void loadPrefs() {
    try {
      XMLBeanReader doc = new XMLBeanReader();

      FileWrapper prefFile = PreferenceUtil.getPreferenceFileToReadFrom(plugin);

      doc.load(prefFile, _prefs.getClass().getClassLoader());

      Iterator<Object> it = doc.iterator();

      if (it.hasNext()) {
        _prefs = (IQueryTokenizerPreferenceBean) it.next();
      }
    } catch (FileNotFoundException ignore) {
      s_log.info(USER_PREFS_FILE_NAME + " not found - will be created");
    } catch (Exception ex) {
      s_log.error("Error occurred reading from preferences file: " + USER_PREFS_FILE_NAME, ex);
    }

    _prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName());
    _prefs.setClientVersion(Version.getShortVersion() + "/" + plugin.getVersion());
  }
Example #5
0
  /**
   * Display a tip.
   *
   * @param activity the triggering activity
   * @param titleResource The resource containing the title.
   * @param iconResource The resource containing the icon.
   * @param messageResource The resource containing the text of the tip.
   * @param preferenceResource The resource for the key of the preference storing the information if
   *     the tip should be skipped later.
   */
  private static void displayTip(
      @NonNull final Activity activity,
      final int titleResource,
      final int iconResource,
      final int messageResource,
      final int preferenceResource) {
    String message = activity.getString(messageResource);

    boolean skip = PreferenceUtil.getSharedPreferenceBoolean(preferenceResource);

    if (!skip) {
      Bundle bundle = new Bundle();
      bundle.putString(PARAM_TITLE, activity.getString(titleResource));
      bundle.putInt(PARAM_ICON, iconResource);
      bundle.putString(PARAM_MESSAGE, message);
      bundle.putInt(PARAM_PREFERENCE_KEY, preferenceResource);

      DisplayTipFragment fragment = new DisplayTipFragment();
      fragment.setArguments(bundle);
      fragment.show(activity.getFragmentManager(), DisplayTipFragment.class.toString());
    }
  }
Example #6
0
 public static void setVisistor(boolean bl) {
   PreferenceUtil.setBooleanValue(Config.VISISTOR_MODE, bl);
 }
Example #7
0
 public static boolean isVisistor() {
   return PreferenceUtil.getBoolean(Config.VISISTOR_MODE, false);
 }
Example #8
0
 public static int getMaxLine() {
   return PreferenceUtil.getInt(Config.MAX_LINE, 6);
 }
Example #9
0
 public static String getSignatrue() {
   return PreferenceUtil.getString(
       Config.USER_SIGNATRUE, AppApplication.getContext().getString(R.string.un_login));
 }
Example #10
0
 public static void setRegistDate() {
   PreferenceUtil.setLongValue(Config.LOGIN_REGIST, System.currentTimeMillis());
 }
 public void saveRules() {
   IPreferenceStore store = SchemeScriptPlugin.getDefault().getPreferenceStore();
   PreferenceUtil.setIndentationSchemes(store, IndentationPreferences.INDENT_SCHEMES, getRules());
 }
Example #12
0
 public static String getUserLogo() {
   return PreferenceUtil.getString(
       Config.USER_LOG, AppApplication.getContext().getString(R.string.default_user_logo));
 }
Example #13
0
 public static String getLoginEmail() {
   return PreferenceUtil.getString(Config.USER_LOGIN_EMAIL, "");
 }
Example #14
0
 public static void setLoginEmail(String email) {
   PreferenceUtil.setStringValue(Config.USER_LOGIN_EMAIL, email);
 }
Example #15
0
 public static int getGender() {
   return PreferenceUtil.getInt(Config.USER_GENDER, -4);
 }
Example #16
0
 public static void setGender(int gender) {
   PreferenceUtil.setIntValue(Config.USER_GENDER, gender);
 }
Example #17
0
 public static Long getRegDate() {
   return PreferenceUtil.getLong(Config.USER_DATE, 0l);
 }
Example #18
0
 public static void setRegDate(Long date) {
   PreferenceUtil.setLongValue(Config.USER_DATE, date);
 }
Example #19
0
 public static String getUserName() {
   return PreferenceUtil.getString(
       Config.USERNAME, AppApplication.getContext().getString(R.string.un_login));
 }
Example #20
0
 public static void setUserName(String name) {
   PreferenceUtil.setStringValue(Config.USERNAME, name);
 }
Example #21
0
 public static int getTextSize() {
   return PreferenceUtil.getInt(Config.TEXTSIZE, 1); // default 1
 }
Example #22
0
 public static void setUserLogo(String str) {
   PreferenceUtil.setStringValue(Config.USER_LOG, str);
 }
Example #23
0
 public static Long getRegist() {
   return PreferenceUtil.getLong(Config.LOGIN_REGIST, 0l);
 }
Example #24
0
 public static void setLoginStatus(String str) {
   PreferenceUtil.setStringValue(Config.LOGIN_STATUS, str);
 }
Example #25
0
 public static void setMode(int mode) {
   PreferenceUtil.setIntValue(Config.MODE, mode == 0 ? Config.MODE_IMAGE : Config.MODE_TEXT_ONLY);
 }
Example #26
0
 public static void setTextSize(int size) {
   PreferenceUtil.setIntValue(Config.TEXTSIZE, size);
 }
Example #27
0
 public static void setSignatrue(String sign) {
   PreferenceUtil.setStringValue(Config.USER_SIGNATRUE, sign);
 }
Example #28
0
 public static int getMode() {
   int mode = PreferenceUtil.getInt(Config.MODE, Config.MODE_IMAGE); // default
   return mode == Config.MODE_TEXT_ONLY ? 1 : 0;
 }
Example #29
0
 public static String getLoginStatus() {
   return PreferenceUtil.getString(Config.LOGIN_STATUS, Config.LOGIN_OUT);
 }