Revision | 2c7c5e3dce116d3d7e62af25cd8ec5fac68c8095 (tree) |
---|---|
Time | 2014-05-27 04:10:27 |
Author | Masahiko, SAWAI <say@user...> |
Commiter | Masahiko, SAWAI |
Added AllCsvFileMediaScanService
@@ -2,23 +2,25 @@ | ||
2 | 2 | <manifest |
3 | 3 | xmlns:android="http://schemas.android.com/apk/res/android" |
4 | 4 | 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" | |
7 | 7 | > |
8 | - <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="11" /> | |
8 | + <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="19" /> | |
9 | 9 | <uses-feature android:name="android.hardware.touchscreen" android:required="false" /> |
10 | 10 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
11 | 11 | <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> |
12 | 12 | |
13 | 13 | <application |
14 | + android:name=".BatteryLoggerApplication" | |
14 | 15 | android:label="@string/app_name" |
15 | 16 | android:icon="@drawable/ic_launcher_battery_log" |
16 | 17 | > |
17 | 18 | |
18 | 19 | <!-- ########## Activity ########## --> |
19 | 20 | <!-- 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" | |
22 | 24 | > |
23 | 25 | <intent-filter> |
24 | 26 | <action android:name="android.intent.action.MAIN" /> |
@@ -107,6 +109,11 @@ | ||
107 | 109 | /> |
108 | 110 | |
109 | 111 | <service |
112 | + android:name=".service.AllCsvFileMediaScanService" | |
113 | + android:label="All CSV File Media Scan Service" | |
114 | + /> | |
115 | + | |
116 | + <service | |
110 | 117 | android:name=".service.CsvFileMediaScanService" |
111 | 118 | android:label="CSV File Media Scan Service" |
112 | 119 | /> |
@@ -19,6 +19,9 @@ | ||
19 | 19 | <string name="csv_export_directory_key">csv_export_directory</string> |
20 | 20 | <string name="csv_export_directory_default_value">simple-battery-logger</string> |
21 | 21 | |
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 | + | |
22 | 25 | <string name="csv_dropbox_uploader_key">csv_dropbox_uploader</string> |
23 | 26 | |
24 | 27 |
@@ -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 | +} |
@@ -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 | +} |
@@ -29,6 +29,7 @@ import android.content.Intent; | ||
29 | 29 | import android.media.MediaScannerConnection; |
30 | 30 | import android.media.MediaScannerConnection.MediaScannerConnectionClient; |
31 | 31 | import android.net.Uri; |
32 | +import android.text.TextUtils; | |
32 | 33 | import java.util.Date; |
33 | 34 | import org.routine_work.simple_battery_logger.BatteryConstants; |
34 | 35 | import org.routine_work.util.Log; |
@@ -40,7 +41,6 @@ import org.routine_work.util.Log; | ||
40 | 41 | public class CsvFileMediaScanService extends IntentService |
41 | 42 | { |
42 | 43 | |
43 | - public static final String EXTRA_DATE = "date"; // yyyy-MM-dd | |
44 | 44 | private static final String LOG_TAG = "simple-battery-logger"; |
45 | 45 | |
46 | 46 | public CsvFileMediaScanService(String name) |
@@ -50,44 +50,40 @@ public class CsvFileMediaScanService extends IntentService | ||
50 | 50 | |
51 | 51 | public CsvFileMediaScanService() |
52 | 52 | { |
53 | - this("StartCsvFileMediaScanService"); | |
53 | + this("CsvFileMediaScanService"); | |
54 | 54 | } |
55 | 55 | |
56 | 56 | @Override |
57 | 57 | protected void onHandleIntent(Intent intent) |
58 | 58 | { |
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()); | |
66 | 60 | |
67 | 61 | String csvFilePath = intent.getStringExtra(BatteryConstants.EXTRA_CSV_FILE_PATH); |
68 | 62 | Log.i(LOG_TAG, "intent.EXTRA_CSV_FILE_PATH => " + csvFilePath); |
69 | 63 | |
70 | - // Scan CSV File | |
71 | - startCsvFileMediaScan(csvFilePath); | |
64 | + if (TextUtils.isEmpty(csvFilePath) == false) | |
65 | + { | |
66 | + startOneCsvFileMediaScan(csvFilePath); | |
67 | + } | |
72 | 68 | |
73 | - Log.i(LOG_TAG, "StartCsvFileMediaScanService : End at " + new Date()); | |
69 | + Log.i(LOG_TAG, "CsvFileMediaScanService : End at " + new Date()); | |
74 | 70 | } |
75 | 71 | |
76 | - private void startCsvFileMediaScan(String csvFilePath) | |
72 | + private void startOneCsvFileMediaScan(String csvFilePath) | |
77 | 73 | { |
78 | 74 | Log.v(LOG_TAG, "Hello"); |
79 | - CsvFileMediaScanClient csvFileMediaScanClient = new CsvFileMediaScanClient(csvFilePath); | |
75 | + OneCsvFileMediaScanClient csvFileMediaScanClient = new OneCsvFileMediaScanClient(csvFilePath); | |
80 | 76 | csvFileMediaScanClient.connectMediaScanner(); |
81 | 77 | Log.v(LOG_TAG, "Bye"); |
82 | 78 | } |
83 | 79 | |
84 | - class CsvFileMediaScanClient implements MediaScannerConnectionClient | |
80 | + class OneCsvFileMediaScanClient implements MediaScannerConnectionClient | |
85 | 81 | { |
86 | 82 | |
87 | 83 | private MediaScannerConnection mediaScannerConnection; |
88 | 84 | private String csvFilePath; |
89 | 85 | |
90 | - public CsvFileMediaScanClient(String csvFilePath) | |
86 | + public OneCsvFileMediaScanClient(String csvFilePath) | |
91 | 87 | { |
92 | 88 | this.csvFilePath = csvFilePath; |
93 | 89 | } |
@@ -25,10 +25,8 @@ package org.routine_work.simple_battery_logger.service; | ||
25 | 25 | |
26 | 26 | import android.app.IntentService; |
27 | 27 | import android.content.Intent; |
28 | -import android.content.SharedPreferences; | |
29 | 28 | import android.database.sqlite.SQLiteDatabase; |
30 | 29 | import java.util.Date; |
31 | -import org.routine_work.simple_battery_logger.R; | |
32 | 30 | import org.routine_work.simple_battery_logger.db.BatteryHistoryDBHelper; |
33 | 31 | import org.routine_work.util.Log; |
34 | 32 | import org.routine_work.simple_battery_logger.util.PreferenceUtils; |
@@ -38,6 +38,7 @@ public class PreferenceUtils | ||
38 | 38 | |
39 | 39 | private static final String LOG_TAG = "simple-battery-logger"; |
40 | 40 | |
41 | + | |
41 | 42 | public static boolean isLoggingServiceEnabled(Context context) |
42 | 43 | { |
43 | 44 | String preferenceName = context.getPackageName() + "_preferences"; |
@@ -146,6 +147,11 @@ public class PreferenceUtils | ||
146 | 147 | return exportedSharedPreferences; |
147 | 148 | } |
148 | 149 | |
150 | + /** | |
151 | + * Copy CSV Directory from private SharedPreferences to exported SharedPreferences | |
152 | + * | |
153 | + * @param context | |
154 | + */ | |
149 | 155 | public static void exportCsvExportDirectoryName(Context context) |
150 | 156 | { |
151 | 157 | Log.v(LOG_TAG, "Hello"); |
@@ -163,4 +169,32 @@ public class PreferenceUtils | ||
163 | 169 | |
164 | 170 | Log.v(LOG_TAG, "Bye"); |
165 | 171 | } |
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 | + } | |
166 | 200 | } |