一部動作の改善
[ofnhwx.callconfirm.git] / src / jp / gr / java_conf / ofnhwx / callconfirm / utility / Param.java
blob13b02c2de9ced38d2bffaaa28d8cb365c021390a
1 package jp.gr.java_conf.ofnhwx.callconfirm.utility;
3 import jp.gr.java_conf.ofnhwx.callconfirm.R;
4 import jp.gr.java_conf.ofnhwx.olib.utils.OPreference;
5 import android.content.Context;
6 import android.content.pm.PackageInfo;
7 import android.content.pm.PackageManager;
8 import android.content.pm.PackageManager.NameNotFoundException;
9 import android.graphics.Color;
10 import android.text.TextUtils;
12 /**
13 * パラメータの受け渡し用の定数を定義.
14 * @author yuta
16 public abstract class Param {
19 public static final int VERSION_CODE_2_0_0 = 51;
22 public static final String ID = "param_id";
23 public static final String NAME = "param_name";
24 public static final String NUMBER = "param_number";
25 public static final String SCHEME = "param_scheme";
27 // 文字・写真サイズの既定値
28 private static final float DEFAULT_PICTURE_SIZE = 54.0f;
29 private static final float DEFAULT_TITLE_SIZE = 12.0f;
30 private static final float DEFAULT_TEXT_SIZE = 12.0f;
32 // ダイアログに使用する文字色
33 private static final int[] COLORS = {
34 Color.WHITE,
35 Color.LTGRAY,
36 Color.GRAY,
37 Color.DKGRAY,
38 Color.BLACK,
39 Color.MAGENTA,
40 Color.RED,
41 Color.YELLOW,
42 Color.GREEN,
43 Color.CYAN,
44 Color.BLUE
47 // テーマの設定
48 public static final int THEMA_BLACK = 0;
49 public static final int THEMA_WHITE = 1;
50 public static final int THEMA_NONE = 2;
51 public static final int THEMA_DIALOG = 3;
53 // バイブレーションのデフォルトパターン
54 private static final String DEFAULT_VIBRATE_PATTERN = " ^ ^";
56 // 自動通話切断の時間
57 private static final int DEFAULT_AUTO_END_TIME = 300;
59 public static final int getMyPictureSize(Context context) {
60 float size = getFloat(context, R.string.key_picture_size, DEFAULT_PICTURE_SIZE);
61 return (int)(size * getDensity(context));
64 public static final int getMyTitleSize(Context context) {
65 float size = getFloat(context, R.string.key_title_size, DEFAULT_TITLE_SIZE);
66 return (int)(size * getScaledDensity(context));
69 public static final int getMyTitleColor(Context context) {
70 return COLORS[getInteger(context, R.string.key_title_color, 0)];
73 public static final int getMyTextSize(Context context) {
74 final float size = getFloat(context, R.string.key_text_size, DEFAULT_TEXT_SIZE);
75 return (int)(size * getScaledDensity(context));
78 public static final int getMyTextColor(Context context) {
79 return COLORS[getInteger(context, R.string.key_text_color, 0)];
82 public static final int getMyTheme(Context context) {
83 return getInteger(context, R.string.key_theme_color, THEMA_BLACK);
86 public static final long[] getVibrationPattern(Context context) {
87 // パターン文字列の取得
88 OPreference prefs = OPreference.getInstance(context);
89 String pattern = prefs.getString(R.string.key_vibrate_pattern, null);
90 pattern = TextUtils.isEmpty(pattern) ? DEFAULT_VIBRATE_PATTERN : pattern;
91 // パターン文字列からパターン配列を作成
92 long length0 = 50;
93 long length1 = 200;
94 long length2 = 500;
95 long length3 = 1000;
96 long[] array = new long[pattern.length()];
97 for (int i = 0; i < array.length; i++) {
98 switch (pattern.charAt(i)) {
99 case '^': array[i] = length1; break;
100 case '.': array[i] = length2; break;
101 case '_': array[i] = length3; break;
102 default : array[i] = length0; break;
105 return array;
108 public static final int getAutoEndTime(Context context) {
109 return getInteger(context, R.string.key_auto_reject_time, DEFAULT_AUTO_END_TIME);
112 public static final int getVersionCode(Context context) {
113 PackageManager pm = context.getPackageManager();
114 try {
115 PackageInfo info = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
116 return info.versionCode;
117 } catch (NameNotFoundException e) {
118 return 0;
122 public static final int getPrevVersionCode(Context context) {
123 return getInteger(context, R.string.key_version, 0);
126 private static final float getFloat(Context context, int key, float defValue) {
127 OPreference prefs = OPreference.getInstance(context);
128 try {
129 return Float.parseFloat(prefs.getString(key, Float.toString(defValue)));
130 } catch (NumberFormatException e) {
131 return defValue;
135 private static final int getInteger(Context context, int key, int defValue) {
136 OPreference prefs = OPreference.getInstance(context);
137 try {
138 return Integer.parseInt(prefs.getString(key, Integer.toString(defValue)));
139 } catch (NumberFormatException e) {
140 return defValue;
144 private static final float getDensity(Context context) {
145 return context.getResources().getDisplayMetrics().scaledDensity;
148 private static final float getScaledDensity(Context context) {
149 return context.getResources().getDisplayMetrics().scaledDensity;