• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision33c43ca8019d3de907239f940664cd0866c55220 (tree)
Time2014-06-02 05:06:27
AuthorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

Changed date and datetime format

Change Summary

Incremental Difference

--- a/simple-battery-logger/simple-battery-logger-app/res/values-ja/strings_preferences.xml
+++ b/simple-battery-logger/simple-battery-logger-app/res/values-ja/strings_preferences.xml
@@ -18,7 +18,7 @@
1818 <string name="preferences_view_category_title">表示</string>
1919 <string name="date_format">日付フォーマット</string>
2020 <string name="date_format_title">日付フォーマット</string>
21- <string name="date_format_row">書式なし</string>
21+ <string name="date_format_raw">書式なし</string>
2222 <string name="date_format_system">システム書式</string>
2323
2424 <string name="preferences_csv_category_title">CSV</string>
--- a/simple-battery-logger/simple-battery-logger-app/res/values/arrays_date_format.xml
+++ b/simple-battery-logger/simple-battery-logger-app/res/values/arrays_date_format.xml
@@ -1,11 +1,11 @@
11 <?xml version="1.0" encoding="utf-8"?>
22 <resources>
33 <string-array name="date_format_entries" >
4- <item>@string/date_format_row</item>
4+ <item>@string/date_format_raw</item>
55 <item>@string/date_format_system</item>
66 </string-array>
77 <string-array name="date_format_values" >
8- <item>DATE_FORMAT_ROW</item>
9- <item>DATE_FORMAT_SYSTEM</item>
8+ <item>@string/date_format_value_raw</item>
9+ <item>@string/date_format_value_system</item>
1010 </string-array>
1111 </resources>
--- a/simple-battery-logger/simple-battery-logger-app/res/values/preferences_key_value.xml
+++ b/simple-battery-logger/simple-battery-logger-app/res/values/preferences_key_value.xml
@@ -11,7 +11,9 @@
1111 <string name="data_keeping_period_default_value">30</string>
1212
1313 <string name="date_format_key">date_format</string>
14- <string name="date_format_default_value">DATE_FORMAT_ROW</string>
14+ <string name="date_format_default_value">@string/date_format_value_raw</string>
15+ <string name="date_format_value_raw">DATE_FORMAT_RAW</string>
16+ <string name="date_format_value_system">DATE_FORMAT_SYSTEM</string>
1517
1618 <string name="csv_auto_export_enabled_key">csv_auto_export_enabled</string>
1719 <bool name="csv_auto_export_enabled_default_value">true</bool>
--- a/simple-battery-logger/simple-battery-logger-app/res/values/strings_preferences.xml
+++ b/simple-battery-logger/simple-battery-logger-app/res/values/strings_preferences.xml
@@ -18,7 +18,7 @@
1818 <string name="preferences_view_category_title">View</string>
1919 <string name="date_format">Date Format</string>
2020 <string name="date_format_title">Date Format</string>
21- <string name="date_format_row">Row Format</string>
21+ <string name="date_format_raw">Raw Format</string>
2222 <string name="date_format_system">System Format</string>
2323
2424 <string name="preferences_csv_category_title">CSV</string>
--- a/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/BatteryUtils.java
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/BatteryUtils.java
@@ -24,8 +24,15 @@
2424 package org.routine_work.simple_battery_logger;
2525
2626 import android.content.Context;
27+import android.text.format.DateFormat;
28+import android.util.Log;
29+import java.text.ParseException;
30+import java.text.SimpleDateFormat;
31+import java.util.Date;
2732 import java.util.HashMap;
2833 import java.util.Map;
34+import org.routine_work.simple_battery_logger.db.DBConstants;
35+import org.routine_work.simple_battery_logger.util.PreferenceUtils;
2936
3037 /**
3138 *
@@ -34,6 +41,7 @@ import java.util.Map;
3441 public class BatteryUtils
3542 {
3643
44+ private static final String LOG_TAG = "simple-battery-logger";
3745 private static final Map<Integer, Integer> STATUS_CODE_AND_RESOURCE_MAP = new HashMap<Integer, Integer>();
3846 private static final Map<Integer, Integer> HEALTH_CODE_AND_RESOURCE_MAP = new HashMap<Integer, Integer>();
3947 private static final Map<Integer, Integer> PLUGGED_CODE_AND_RESOURCE_MAP = new HashMap<Integer, Integer>();
@@ -110,4 +118,63 @@ public class BatteryUtils
110118 }
111119 return pluggedText;
112120 }
121+
122+ public static String getFormattedDate(Context context, String rawDateString)
123+ {
124+ String formattedDate = null;
125+
126+ String dateFormatValueSystem = context.getString(R.string.date_format_value_system);
127+ if (dateFormatValueSystem.equals(PreferenceUtils.getDateFormat(context)))
128+ {
129+ SimpleDateFormat rawDateFormat = new SimpleDateFormat(DBConstants.DATE_FORMAT);
130+ try
131+ {
132+ Date datetime = rawDateFormat.parse(rawDateString);
133+
134+ java.text.DateFormat dateFormat = DateFormat.getLongDateFormat(context);
135+ formattedDate = dateFormat.format(datetime);
136+ }
137+ catch (ParseException ex)
138+ {
139+ Log.e(LOG_TAG, "Parse date failed.", ex);
140+ }
141+ }
142+
143+ if (formattedDate == null)
144+ {
145+ formattedDate = rawDateString;
146+ }
147+
148+ return formattedDate;
149+ }
150+
151+ public static String getFormattedDatetime(Context context, String rawDatetimeString)
152+ {
153+ String formattedDatetime = null;
154+
155+ String dateFormatValueSystem = context.getString(R.string.date_format_value_system);
156+ if (dateFormatValueSystem.equals(PreferenceUtils.getDateFormat(context)))
157+ {
158+ SimpleDateFormat rawDatetimeFormat = new SimpleDateFormat(DBConstants.DATETIME_FORMAT);
159+ try
160+ {
161+ Date datetime = rawDatetimeFormat.parse(rawDatetimeString);
162+
163+ java.text.DateFormat dateFormat = DateFormat.getDateFormat(context);
164+ java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
165+ formattedDatetime = dateFormat.format(datetime) + " " + timeFormat.format(datetime);
166+ }
167+ catch (ParseException ex)
168+ {
169+ Log.e(LOG_TAG, "Parse datetime failed.", ex);
170+ }
171+ }
172+
173+ if (formattedDatetime == null)
174+ {
175+ formattedDatetime = rawDatetimeString;
176+ }
177+
178+ return formattedDatetime;
179+ }
113180 }
--- a/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/DatabaseDateListActivity.java
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/DatabaseDateListActivity.java
@@ -32,6 +32,7 @@ import android.content.SharedPreferences;
3232 import android.database.Cursor;
3333 import android.database.sqlite.SQLiteDatabase;
3434 import android.os.Bundle;
35+import android.text.TextUtils;
3536 import android.view.ContextMenu;
3637 import android.view.ContextMenu.ContextMenuInfo;
3738 import android.view.Menu;
@@ -54,18 +55,20 @@ import org.routine_work.util.SystemResourceUtils;
5455
5556 public class DatabaseDateListActivity extends ListActivity
5657 implements SharedPreferences.OnSharedPreferenceChangeListener,
58+ SimpleCursorAdapter.ViewBinder,
5759 OnItemClickListener, DBConstants
5860 {
5961
60- private static final int REQUEST_CODE_BATTERY_HISTORY_LIST_ACTIVITY = 100;
6162 private static final String LOG_TAG = "simple-battery-logger";
6263 private static final String[] MAPPING_FROM = new String[]
6364 {
6465 BatteryHistoryDate.Columns.DATE,
66+ BatteryHistoryDate.Columns.DATE,
6567 };
6668 private static final int[] MAPPING_TO = new int[]
6769 {
68- android.R.id.text1
70+ android.R.id.text1, // for formatted date text
71+ android.R.id.text2 // for raw date text
6972 };
7073 private BatteryHistoryDBHelper dbHelper;
7174 private SQLiteDatabase db;
@@ -155,15 +158,17 @@ public class DatabaseDateListActivity extends ListActivity
155158 public void onItemClick(AdapterView<?> parentView, View itemView, int position, long id)
156159 {
157160 Log.v(LOG_TAG, "Hello");
158- if (itemView instanceof TextView)
161+ View text2View = itemView.findViewById(android.R.id.text2);
162+ if (text2View instanceof TextView)
159163 {
160- TextView dateTextView = (TextView) itemView;
161- String dateTextString = dateTextView.getText().toString();
162- Log.d(LOG_TAG, "clicked date text => " + dateTextString);
163- if (dateTextString != null && dateTextString.length() > 0)
164+ TextView dateTextView = (TextView) text2View;
165+ String rawDateText = dateTextView.getText().toString();
166+ Log.d(LOG_TAG, "clicked date text => " + rawDateText);
167+
168+ if (TextUtils.isEmpty(rawDateText) == false)
164169 {
165170 Intent intent = new Intent(this, DatabaseDateViewerActivity.class);
166- intent.putExtra(DatabaseDateViewerActivity.EXTRA_DATE, dateTextString);
171+ intent.putExtra(DatabaseDateViewerActivity.EXTRA_DATE, rawDateText);
167172 startActivity(intent);
168173 }
169174 }
@@ -244,11 +249,12 @@ public class DatabaseDateListActivity extends ListActivity
244249 switch (itemId)
245250 {
246251 case R.id.export_csv_menuitem:
247- if (menuInfo.targetView instanceof TextView)
252+ View text2View = menuInfo.targetView.findViewById(android.R.id.text2);
253+ if (text2View instanceof TextView)
248254 {
249- TextView textView = (TextView) menuInfo.targetView;
250- String dateText = textView.getText().toString();
251- exportCsvFile(dateText);
255+ TextView textView = (TextView) text2View;
256+ String rawDateText = textView.getText().toString();
257+ exportCsvFile(rawDateText);
252258 }
253259 result = true;
254260 break;
@@ -260,6 +266,36 @@ public class DatabaseDateListActivity extends ListActivity
260266 return result;
261267 }
262268
269+ @Override
270+ public boolean setViewValue(View view, Cursor cursor, int columnIndex)
271+ {
272+
273+ String textValue = null;
274+ if (columnIndex == cursor.getColumnIndex(BatteryHistoryDate.Columns.DATE))
275+ {
276+ if (android.R.id.text1 == view.getId())
277+ {
278+ String rawDateString = cursor.getString(columnIndex);
279+ textValue = BatteryUtils.getFormattedDate(this, rawDateString);
280+ }
281+ }
282+
283+ if (textValue == null)
284+ {
285+ textValue = cursor.getString(columnIndex);
286+ }
287+
288+ TextView textView = (TextView) view;
289+ textView.setText(textValue);
290+
291+// if (android.R.id.text2 == view.getId())
292+// {
293+// view.setVisibility(View.GONE);
294+// }
295+
296+ return true;
297+ }
298+
263299 private void initializeListData()
264300 {
265301 Log.v(LOG_TAG, "Hello");
@@ -273,9 +309,11 @@ public class DatabaseDateListActivity extends ListActivity
273309 cursor = dbHelper.getBatteryHistoryDateListCursor(db);
274310
275311 adapter = new SimpleCursorAdapter(this,
276- android.R.layout.simple_list_item_1,
312+ android.R.layout.simple_list_item_2,
277313 cursor, MAPPING_FROM, MAPPING_TO);
314+ adapter.setViewBinder(this);
278315 setListAdapter(adapter);
316+
279317 Log.v(LOG_TAG, "Bye");
280318 }
281319
@@ -308,15 +346,15 @@ public class DatabaseDateListActivity extends ListActivity
308346 Log.v(LOG_TAG, " Bye");
309347 }
310348
311- private void exportCsvFile(String dateText)
349+ private void exportCsvFile(String rawDateText)
312350 {
313351 Log.v(LOG_TAG, "Hello");
352+ Log.d(LOG_TAG, "rawDateText => " + rawDateText);
314353
315- Log.d(LOG_TAG, "dateText => " + dateText);
316- if (dateText != null)
354+ if (TextUtils.isEmpty(rawDateText) == false)
317355 {
318356 Intent intent = new Intent(this, ExportOneDayDataCsvFileService.class);
319- intent.putExtra(ExportOneDayDataCsvFileService.EXTRA_DATE, dateText);
357+ intent.putExtra(ExportOneDayDataCsvFileService.EXTRA_DATE, rawDateText);
320358 startService(intent);
321359 }
322360
--- a/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/DatabaseDateViewerActivity.java
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/DatabaseDateViewerActivity.java
@@ -199,7 +199,7 @@ public class DatabaseDateViewerActivity extends ListActivity
199199 public boolean setViewValue(View view, Cursor cursor, int columnIndex)
200200 {
201201
202- String textValue = "?";
202+ String textValue;
203203 if (columnIndex == cursor.getColumnIndex(BatteryHistory.Columns.STATUS))
204204 {
205205 int statusCode = cursor.getInt(columnIndex);
@@ -210,6 +210,11 @@ public class DatabaseDateViewerActivity extends ListActivity
210210 int pluggedCode = cursor.getInt(columnIndex);
211211 textValue = BatteryUtils.getPluggedText(this, pluggedCode);
212212 }
213+ else if (columnIndex == cursor.getColumnIndex(BatteryHistory.Columns.DATETIME))
214+ {
215+ String datetimeString = cursor.getString(columnIndex);
216+ textValue = BatteryUtils.getFormattedDatetime(this, datetimeString);
217+ }
213218 else if (columnIndex == cursor.getColumnIndex(BatteryHistory.Columns.TEMPERATURE))
214219 {
215220 int temperature = cursor.getInt(columnIndex);
@@ -243,6 +248,7 @@ public class DatabaseDateViewerActivity extends ListActivity
243248 R.layout.battery_history_list_item, cursor, MAPPING_FROM, MAPPING_TO);
244249 adapter.setViewBinder(this);
245250 setListAdapter(adapter);
251+
246252 Log.v(LOG_TAG, "Bye");
247253 }
248254