ManagePreferences.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.epson.iprint.shared;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import java.util.Map;
  7. import epson.common.Constants;
  8. import epson.print.screen.PrintSetting;
  9. public class ManagePreferences {
  10. public static final String PREFS_INFO_PRINT_CLONE = "PrintSettingClone";
  11. public boolean pushPreferrences(Context context) {
  12. SharedPreferences sharedPreferences = context.getSharedPreferences("PrintSetting", 0);
  13. SharedPreferences.Editor edit = context.getSharedPreferences(PREFS_INFO_PRINT_CLONE, 0).edit();
  14. edit.clear();
  15. for (Map.Entry next : sharedPreferences.getAll().entrySet()) {
  16. Log.v("hoge PUSH", String.format("%s=%s", new Object[]{(String) next.getKey(), next.getValue()}));
  17. if (next.getValue() != null) {
  18. putInPrefs(edit, (String) next.getKey(), next.getValue());
  19. }
  20. }
  21. return edit.commit();
  22. }
  23. public boolean popPreferrences(Context context) {
  24. SharedPreferences sharedPreferences = context.getSharedPreferences("PrintSetting", 0);
  25. SharedPreferences sharedPreferences2 = context.getSharedPreferences(PREFS_INFO_PRINT_CLONE, 0);
  26. SharedPreferences.Editor edit = sharedPreferences.edit();
  27. for (Map.Entry next : sharedPreferences2.getAll().entrySet()) {
  28. Log.v("hoge POP", String.format("%s=%s", new Object[]{(String) next.getKey(), next.getValue()}));
  29. if (next.getValue() != null) {
  30. putInPrefs(edit, (String) next.getKey(), next.getValue());
  31. }
  32. }
  33. return edit.commit();
  34. }
  35. public void resetSavedFlag(Context context, String str) {
  36. context.getSharedPreferences(str, 0).edit().putInt(Constants.PREFS_INFO_PRINT_SAVE, 0).commit();
  37. }
  38. public int getSavedFlag(Context context, String str) {
  39. return context.getSharedPreferences(str, 0).getInt(Constants.PREFS_INFO_PRINT_SAVE, 0);
  40. }
  41. public boolean setPreferences(String str, Context context) {
  42. if (str.indexOf(EpsoniPrintSharedActivity.PACKAGE_PANASONIC_FAX) == -1) {
  43. return false;
  44. }
  45. PrintSetting printSetting = new PrintSetting(context, PrintSetting.Kind.photo);
  46. printSetting.loadSettings();
  47. printSetting.paperSizeValue = 0;
  48. printSetting.paperTypeValue = 0;
  49. printSetting.colorValue = 1;
  50. printSetting.layoutValue = 2;
  51. printSetting.copiesValue = 1;
  52. printSetting.saveSettings();
  53. return true;
  54. }
  55. public boolean setPreferences(int i, int i2, int i3, int i4, Context context) {
  56. PrintSetting printSetting = new PrintSetting(context, PrintSetting.Kind.photo);
  57. printSetting.loadSettings();
  58. printSetting.paperTypeValue = i;
  59. printSetting.paperSizeValue = i2;
  60. printSetting.colorValue = i3;
  61. printSetting.layoutValue = i4;
  62. printSetting.copiesValue = 1;
  63. printSetting.saveSettings();
  64. return true;
  65. }
  66. public static SharedPreferences.Editor putInPrefs(SharedPreferences.Editor editor, String str, Object obj) {
  67. Class<?> cls = obj.getClass();
  68. if (Boolean.class.isAssignableFrom(cls)) {
  69. editor.putBoolean(str, ((Boolean) obj).booleanValue());
  70. } else if (Integer.class.isAssignableFrom(cls)) {
  71. editor.putInt(str, ((Integer) obj).intValue());
  72. } else if (Float.class.isAssignableFrom(cls)) {
  73. editor.putFloat(str, ((Float) obj).floatValue());
  74. } else if (Long.class.isAssignableFrom(cls)) {
  75. editor.putLong(str, ((Long) obj).longValue());
  76. } else if (String.class.isAssignableFrom(cls)) {
  77. editor.putString(str, (String) obj);
  78. } else if (Bundle.class.isAssignableFrom(cls)) {
  79. Bundle bundle = (Bundle) obj;
  80. for (String str2 : bundle.keySet()) {
  81. putInPrefs(editor, getStoredBundleParamKey(str, str2), bundle.get(str2));
  82. }
  83. }
  84. return editor;
  85. }
  86. private static String getStoredBundleParamKey(String str, String str2) {
  87. return str + "__" + str2;
  88. }
  89. }