/
AndroFotoFinderApp.java
202 lines (163 loc) · 7.92 KB
/
AndroFotoFinderApp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* Copyright (c) 2015-2019 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>
*/
package de.k3b.android.androFotoFinder;
import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import org.osmdroid.api.IMapView;
import org.osmdroid.config.Configuration;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import de.k3b.LibGlobal;
import de.k3b.android.GuiUtil;
import de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.FotoSqlBase;
import de.k3b.android.androFotoFinder.queries.MediaDBContentprovider;
import de.k3b.android.osmdroid.forge.MapsForgeSupport;
import de.k3b.android.util.LogCat;
import de.k3b.android.widget.ActivityWithCallContext;
import de.k3b.database.QueryParameter;
import de.k3b.io.PhotoAutoprocessingDto;
import de.k3b.media.ExifInterface;
import de.k3b.media.PhotoPropertiesImageReader;
import de.k3b.zip.ZipConfigRepository;
import uk.co.senab.photoview.PhotoViewAttacher;
import uk.co.senab.photoview.gestures.CupcakeGestureDetector;
// import com.squareup.leakcanary.LeakCanary;
// import com.squareup.leakcanary.RefWatcher;
/**
* Created by k3b on 14.07.2015.
*/
public class AndroFotoFinderApp extends Application {
private static String fileNamePrefix = "androFotofinder.logcat-";
private LogCat mCrashSaveToFile = null;
public static final String LINK_URL_SQL = "https://github.com/k3b/APhotoManager/wiki/intentapi#sql";
public static final String LINK_URL_ZIP_CONFIG = "https://github.com/k3b/APhotoManager/wiki/Backup-to-zip#TechnicalDetails";
public static final String LINK_URL_CSV = "https://github.com/k3b/APhotoManager/wiki/Backup-to-zip#csv";
public static final String LINK_URL_AUTOPROCESSING = "https://github.com/k3b/APhotoManager/wiki/AutoProcessing#TechnicalDetails";
public static String getGetTeaserText(Context context, String linkUrlForDetails) {
final String result = context.getString(R.string.bookmark_file_comment_format,
context.getString(R.string.app_name),
GuiUtil.getAppVersionName(context),
new Date().toString());
if (linkUrlForDetails != null)
return result.replace(LINK_URL_SQL, linkUrlForDetails);
return result;
}
/*
private RefWatcher refWatcher;
public static RefWatcher getRefWatcher(Context context) {
AndroFotoFinderApp application = (AndroFotoFinderApp) context.getApplicationContext();
return application.refWatcher;
}
@Override public void onCreate() {
super.onCreate();
LeakCanary.install(this);
}
*/
@Override public void onCreate() {
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
FotoSqlBase.init();
/// #155: todo: depending on android-api version set IMediaDBApi
FotoSql.setMediaDBApi(new MediaDBContentprovider(this));
super.onCreate();
LibGlobal.appName = getString(R.string.app_name);
LibGlobal.appVersion = GuiUtil.getAppVersionName(this);
Global.pickHistoryFile = getDatabasePath("pickHistory.geouri.txt");
SettingsActivity.prefs2Global(this);
// create sensible defaults for andorid-independant files from android string resources
QueryParameter.sFileComment = getGetTeaserText(this, null);
PhotoAutoprocessingDto.sFileComment = getGetTeaserText(this, LINK_URL_AUTOPROCESSING);
ZipConfigRepository.sFileComment = "# " + getGetTeaserText(this, LINK_URL_ZIP_CONFIG);
QueryParameter.sParserDefaultFrom = FotoSql.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE.toString();
QueryParameter.sParserDefaultQueryTypeId = FotoSql.QUERY_TYPE_DEFAULT;
QueryParameter.sParserDefaultSelect = new ArrayList<String>();
Collections.addAll(QueryParameter.sParserDefaultSelect, FotoSql.DEFAULT_GALLERY_COLUMNS);
mCrashSaveToFile = new LogCat(Global.LOG_CONTEXT, HugeImageLoader.LOG_TAG,
PhotoViewAttacher.LOG_TAG, CupcakeGestureDetector.LOG_TAG,
LibGlobal.LOG_TAG, ThumbNailUtils.LOG_TAG, IMapView.LOGTAG,
ExifInterface.LOG_TAG, PhotoPropertiesImageReader.LOG_TAG) {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(mTags[0], "\n\nUncaughtException. Last know Activity\n "
+ ActivityWithCallContext.lastKnownCallContext + "\n");
super.uncaughtException(thread, ex);
}
public void saveToFile() {
final File logFile = getOutpuFile();
String message = (logFile != null)
? "saving errorlog ('LocCat') to " + logFile.getAbsolutePath()
: "Saving errorlog ('LocCat') is disabled. See Settings 'Diagnostics' for details";
Log.e(Global.LOG_CONTEXT, message);
Toast.makeText(AndroFotoFinderApp.this , message, Toast.LENGTH_LONG).show();
saveLogCat(logFile, null, mTags);
}
private File getOutpuFile() {
File logDirectory = Global.logCatDir;
if (logDirectory == null) return null;
// Datetime as part of the crash-log-filename
// i.e. /mnt/sdcard/copy/log/androFotofinder.logcat-20160509-195217.txt
File logFile = new File(logDirectory,
getLocalLogFileName(fileNamePrefix));
// create log folder
logDirectory.mkdirs();
return logFile;
}
};
ThumbNailUtils.init(this, null);
//https://github.com/osmdroid/osmdroid/issues/366
//super important. Many tile servers, including open street maps, will BAN applications by user
//??? OpenStreetMapTileProviderConstants.setUserAgentValue(getAppId() + " https://github.com/k3b/APhotoManager"); // BuildConfig.APPLICATION_ID);
// https://github.com/k3b/APhotoManager/issues/143
Configuration.getInstance().setUserAgentValue(getAppId() + " https://github.com/k3b/APhotoManager"); // BuildConfig.APPLICATION_ID);
// #60: configure some of the mapsforge settings first
MapsForgeSupport.createInstance(this);
FotoSql.deleteMediaWithNullPath();
Log.i(Global.LOG_CONTEXT, getAppId() + " created");
}
@NonNull
private String getAppId() {
return getString(R.string.app_name) + " " + GuiUtil.getAppVersionName(this);
}
@Override
public void onTerminate() {
Log.i(Global.LOG_CONTEXT, getAppId() + " terminated");
if (mCrashSaveToFile != null) {
mCrashSaveToFile.close();
}
mCrashSaveToFile = null;
super.onTerminate();
}
public void saveToFile() {
if (mCrashSaveToFile != null) {
mCrashSaveToFile.saveToFile();
}
}
public void clear() {
if (mCrashSaveToFile != null) {
mCrashSaveToFile.clear();
}
}
}