• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoapythonrubywindowsphpgameguibathyscaphec翻訳omegatframework計画中(planning stage)twitterdombtronvb.nettestarduinodirectxpreviewerゲームエンジン

Commit MetaInfo

Revision2c7c5e3dce116d3d7e62af25cd8ec5fac68c8095 (tree)
Time2014-05-27 04:10:27
AuthorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

Added AllCsvFileMediaScanService

Change Summary

Incremental Difference

--- a/simple-battery-logger/simple-battery-logger-app/AndroidManifest.xml
+++ b/simple-battery-logger/simple-battery-logger-app/AndroidManifest.xml
@@ -2,23 +2,25 @@
22 <manifest
33 xmlns:android="http://schemas.android.com/apk/res/android"
44 package="org.routine_work.simple_battery_logger"
5- android:versionCode="12"
6- android:versionName="1.2.01rc1"
5+ android:versionCode="13"
6+ android:versionName="1.2.01"
77 >
8- <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="11" />
8+ <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="19" />
99 <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
1010 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1111 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
1212
1313 <application
14+ android:name=".BatteryLoggerApplication"
1415 android:label="@string/app_name"
1516 android:icon="@drawable/ic_launcher_battery_log"
1617 >
1718
1819 <!-- ########## Activity ########## -->
1920 <!-- main activity -->
20- <activity android:name=".DashboardActivity"
21- android:label="@string/app_name"
21+ <activity
22+ android:name=".DashboardActivity"
23+ android:label="@string/app_name"
2224 >
2325 <intent-filter>
2426 <action android:name="android.intent.action.MAIN" />
@@ -107,6 +109,11 @@
107109 />
108110
109111 <service
112+ android:name=".service.AllCsvFileMediaScanService"
113+ android:label="All CSV File Media Scan Service"
114+ />
115+
116+ <service
110117 android:name=".service.CsvFileMediaScanService"
111118 android:label="CSV File Media Scan Service"
112119 />
--- 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
@@ -19,6 +19,9 @@
1919 <string name="csv_export_directory_key">csv_export_directory</string>
2020 <string name="csv_export_directory_default_value">simple-battery-logger</string>
2121
22+ <string name="csv_media_scan_completed_key">csv_media_scan_completed</string>
23+ <bool name="csv_media_scan_completed_default_value">false</bool>
24+
2225 <string name="csv_dropbox_uploader_key">csv_dropbox_uploader</string>
2326
2427
--- /dev/null
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/BatteryLoggerApplication.java
@@ -0,0 +1,56 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package org.routine_work.simple_battery_logger;
25+
26+import android.app.Application;
27+import android.content.Intent;
28+import org.routine_work.simple_battery_logger.service.AllCsvFileMediaScanService;
29+import org.routine_work.simple_battery_logger.util.PreferenceUtils;
30+import org.routine_work.util.Log;
31+
32+/**
33+ *
34+ * @author Masahiko, SAWAI <masahiko.sawai@gmail.com>
35+ */
36+public class BatteryLoggerApplication extends Application
37+{
38+
39+ private static final String LOG_TAG = "simple-battery-logger";
40+
41+ @Override
42+ public void onCreate()
43+ {
44+ Log.v(LOG_TAG, "Hello");
45+ super.onCreate();
46+
47+ boolean csvMediaScanCompleted = PreferenceUtils.isCsvMediaScanCompleted(this);
48+ Log.d(LOG_TAG, "csvMediaScanCompleted => " + csvMediaScanCompleted);
49+ if (csvMediaScanCompleted == false)
50+ {
51+ Intent intent = new Intent(getApplicationContext(), AllCsvFileMediaScanService.class);
52+ startService(intent);
53+ }
54+ Log.v(LOG_TAG, "Bye");
55+ }
56+}
--- /dev/null
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/service/AllCsvFileMediaScanService.java
@@ -0,0 +1,90 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package org.routine_work.simple_battery_logger.service;
25+
26+import android.app.IntentService;
27+import android.content.Context;
28+import android.content.Intent;
29+import android.os.Environment;
30+import java.io.File;
31+import java.util.Date;
32+import org.routine_work.simple_battery_logger.BatteryConstants;
33+import org.routine_work.simple_battery_logger.util.CsvFilenameFilter;
34+import org.routine_work.simple_battery_logger.util.PreferenceUtils;
35+import org.routine_work.util.Log;
36+
37+/**
38+ *
39+ * @author sawai
40+ */
41+public class AllCsvFileMediaScanService extends IntentService
42+{
43+
44+ private static final String LOG_TAG = "simple-battery-logger";
45+
46+ public AllCsvFileMediaScanService(String name)
47+ {
48+ super(name);
49+ }
50+
51+ public AllCsvFileMediaScanService()
52+ {
53+ this("AllCsvFileMediaScanService");
54+ }
55+
56+ @Override
57+ protected void onHandleIntent(Intent intent)
58+ {
59+ Log.i(LOG_TAG, "AllCsvFileMediaScanService : Start at " + new Date());
60+
61+ Context context = this.getApplicationContext();
62+ if (PreferenceUtils.isCsvAutoExportEnabled(context) == false)
63+ {
64+ String csvExportDirectoryName = PreferenceUtils.getCsvExportDirectoryName(context);
65+ File externalStorageDirectory = Environment.getExternalStorageDirectory();
66+ File csvExportDirectory = new File(externalStorageDirectory, csvExportDirectoryName);
67+ if (csvExportDirectory.exists()
68+ && csvExportDirectory.isDirectory()
69+ && csvExportDirectory.canRead())
70+ {
71+ File[] csvFiles = csvExportDirectory.listFiles(new CsvFilenameFilter());
72+ if (csvFiles != null)
73+ {
74+ Log.d(LOG_TAG, "AllCsvFileMediaScanService : csvFiles.length => " + csvFiles.length);
75+ for (File csvFile : csvFiles)
76+ {
77+ String csvFilePath = csvFile.getAbsolutePath();
78+ Intent startCsvFileMediaScanService = new Intent(context, CsvFileMediaScanService.class);
79+ startCsvFileMediaScanService.putExtra(BatteryConstants.EXTRA_CSV_FILE_PATH, csvFilePath);
80+ context.startService(startCsvFileMediaScanService);
81+ }
82+ }
83+ }
84+
85+ PreferenceUtils.putCsvMediaScanCompleted(context, true);
86+ }
87+
88+ Log.i(LOG_TAG, "AllCsvFileMediaScanService : End at " + new Date());
89+ }
90+}
--- a/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/service/CsvFileMediaScanService.java
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/service/CsvFileMediaScanService.java
@@ -29,6 +29,7 @@ import android.content.Intent;
2929 import android.media.MediaScannerConnection;
3030 import android.media.MediaScannerConnection.MediaScannerConnectionClient;
3131 import android.net.Uri;
32+import android.text.TextUtils;
3233 import java.util.Date;
3334 import org.routine_work.simple_battery_logger.BatteryConstants;
3435 import org.routine_work.util.Log;
@@ -40,7 +41,6 @@ import org.routine_work.util.Log;
4041 public class CsvFileMediaScanService extends IntentService
4142 {
4243
43- public static final String EXTRA_DATE = "date"; // yyyy-MM-dd
4444 private static final String LOG_TAG = "simple-battery-logger";
4545
4646 public CsvFileMediaScanService(String name)
@@ -50,44 +50,40 @@ public class CsvFileMediaScanService extends IntentService
5050
5151 public CsvFileMediaScanService()
5252 {
53- this("StartCsvFileMediaScanService");
53+ this("CsvFileMediaScanService");
5454 }
5555
5656 @Override
5757 protected void onHandleIntent(Intent intent)
5858 {
59- Log.i(LOG_TAG, "StartCsvFileMediaScanService : Start at " + new Date());
60-
61- boolean exportCsvFileResult = intent.getBooleanExtra(BatteryConstants.EXTRA_RESULT, true);
62- Log.d(LOG_TAG, "intent.EXTRA_RESULT => " + exportCsvFileResult);
63-
64- String dateString = intent.getStringExtra(BatteryConstants.EXTRA_DATE);
65- Log.d(LOG_TAG, "intent.EXTRA_DATE => " + dateString);
59+ Log.i(LOG_TAG, "CsvFileMediaScanService : Start at " + new Date());
6660
6761 String csvFilePath = intent.getStringExtra(BatteryConstants.EXTRA_CSV_FILE_PATH);
6862 Log.i(LOG_TAG, "intent.EXTRA_CSV_FILE_PATH => " + csvFilePath);
6963
70- // Scan CSV File
71- startCsvFileMediaScan(csvFilePath);
64+ if (TextUtils.isEmpty(csvFilePath) == false)
65+ {
66+ startOneCsvFileMediaScan(csvFilePath);
67+ }
7268
73- Log.i(LOG_TAG, "StartCsvFileMediaScanService : End at " + new Date());
69+ Log.i(LOG_TAG, "CsvFileMediaScanService : End at " + new Date());
7470 }
7571
76- private void startCsvFileMediaScan(String csvFilePath)
72+ private void startOneCsvFileMediaScan(String csvFilePath)
7773 {
7874 Log.v(LOG_TAG, "Hello");
79- CsvFileMediaScanClient csvFileMediaScanClient = new CsvFileMediaScanClient(csvFilePath);
75+ OneCsvFileMediaScanClient csvFileMediaScanClient = new OneCsvFileMediaScanClient(csvFilePath);
8076 csvFileMediaScanClient.connectMediaScanner();
8177 Log.v(LOG_TAG, "Bye");
8278 }
8379
84- class CsvFileMediaScanClient implements MediaScannerConnectionClient
80+ class OneCsvFileMediaScanClient implements MediaScannerConnectionClient
8581 {
8682
8783 private MediaScannerConnection mediaScannerConnection;
8884 private String csvFilePath;
8985
90- public CsvFileMediaScanClient(String csvFilePath)
86+ public OneCsvFileMediaScanClient(String csvFilePath)
9187 {
9288 this.csvFilePath = csvFilePath;
9389 }
--- a/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/service/DeleteOldDataService.java
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/service/DeleteOldDataService.java
@@ -25,10 +25,8 @@ package org.routine_work.simple_battery_logger.service;
2525
2626 import android.app.IntentService;
2727 import android.content.Intent;
28-import android.content.SharedPreferences;
2928 import android.database.sqlite.SQLiteDatabase;
3029 import java.util.Date;
31-import org.routine_work.simple_battery_logger.R;
3230 import org.routine_work.simple_battery_logger.db.BatteryHistoryDBHelper;
3331 import org.routine_work.util.Log;
3432 import org.routine_work.simple_battery_logger.util.PreferenceUtils;
--- a/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/util/PreferenceUtils.java
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/util/PreferenceUtils.java
@@ -38,6 +38,7 @@ public class PreferenceUtils
3838
3939 private static final String LOG_TAG = "simple-battery-logger";
4040
41+
4142 public static boolean isLoggingServiceEnabled(Context context)
4243 {
4344 String preferenceName = context.getPackageName() + "_preferences";
@@ -146,6 +147,11 @@ public class PreferenceUtils
146147 return exportedSharedPreferences;
147148 }
148149
150+ /**
151+ * Copy CSV Directory from private SharedPreferences to exported SharedPreferences
152+ *
153+ * @param context
154+ */
149155 public static void exportCsvExportDirectoryName(Context context)
150156 {
151157 Log.v(LOG_TAG, "Hello");
@@ -163,4 +169,32 @@ public class PreferenceUtils
163169
164170 Log.v(LOG_TAG, "Bye");
165171 }
172+
173+ public static boolean isCsvMediaScanCompleted(Context context)
174+ {
175+ String preferenceName = context.getPackageName() + "_preferences";
176+ SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
177+ Resources resources = context.getResources();
178+
179+ String key = resources.getString(R.string.csv_media_scan_completed_key);
180+ boolean defaultValue = resources.getBoolean(R.bool.csv_media_scan_completed_default_value);
181+ boolean value = sharedPreferences.getBoolean(key, defaultValue);
182+
183+ Log.v(LOG_TAG, "csvMediaScanCompleted => " + value);
184+ return value;
185+ }
186+
187+ public static void putCsvMediaScanCompleted(Context context, boolean value)
188+ {
189+ Log.v(LOG_TAG, "csvMediaScanCompleted => " + value);
190+ String preferenceName = context.getPackageName() + "_preferences";
191+ SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
192+ Resources resources = context.getResources();
193+
194+ String key = resources.getString(R.string.csv_media_scan_completed_key);
195+ SharedPreferences.Editor editor = sharedPreferences.edit();
196+ editor.putBoolean(key, value);
197+ editor.commit();
198+
199+ }
166200 }