From 4eb84d8bd5732b4d30e449b73ae716c21cea8b79 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sat, 20 Sep 2014 13:33:27 +0800 Subject: [PATCH] updated .gitignore --- .gitignore | 30 +- twidere/src/main/assets/mapview.html | 42 +- .../mariotaku/gallery3d/GLImageLoader.java | 433 ++++++++-------- .../twidere/app/TwidereApplication.java | 465 +++++++++--------- 4 files changed, 499 insertions(+), 471 deletions(-) diff --git a/.gitignore b/.gitignore index 50231ad61..963f0272a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,28 @@ -.gradle -/local.properties -/.idea/workspace.xml -.DS_Store +# Built application files /build + +# Local configuration file (sdk path, etc) +local.properties + +# Gradle generated files +/gradle +.gradle/ + +# Signing files +.signing/ + +# User-specific configurations +/.idea +*.iml + +# OS-specific files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Private files /signing.properties \ No newline at end of file diff --git a/twidere/src/main/assets/mapview.html b/twidere/src/main/assets/mapview.html index 89f0cf903..5ae8fb33c 100644 --- a/twidere/src/main/assets/mapview.html +++ b/twidere/src/main/assets/mapview.html @@ -1,20 +1,21 @@ - - Google Maps - - - - - + - - -
- + + + + +
+ diff --git a/twidere/src/main/java/org/mariotaku/gallery3d/GLImageLoader.java b/twidere/src/main/java/org/mariotaku/gallery3d/GLImageLoader.java index 83006907d..99f330c33 100644 --- a/twidere/src/main/java/org/mariotaku/gallery3d/GLImageLoader.java +++ b/twidere/src/main/java/org/mariotaku/gallery3d/GLImageLoader.java @@ -51,258 +51,259 @@ import java.io.OutputStream; public class GLImageLoader extends AsyncTaskLoader implements Constants { - private final Uri mUri; - private final Handler mHandler; - private final DownloadListener mListener; - private final ImageDownloader mDownloader; - private final DiskCache mDiskCache; + private final Uri mUri; + private final Handler mHandler; + private final DownloadListener mListener; + private final ImageDownloader mDownloader; + private final DiskCache mDiskCache; - private final float mFallbackSize; - private final long mAccountId; + private final float mFallbackSize; + private final long mAccountId; - public GLImageLoader(final Context context, final DownloadListener listener, final long accountId, final Uri uri) { - super(context); - mHandler = new Handler(); - mAccountId = accountId; - mUri = uri; - mListener = listener; - final TwidereApplication app = TwidereApplication.getInstance(context); - mDownloader = app.getFullImageDownloader(); - mDiskCache = app.getFullDiskCache(); - final Resources res = context.getResources(); - final DisplayMetrics dm = res.getDisplayMetrics(); - mFallbackSize = Math.max(dm.heightPixels, dm.widthPixels); - } + public GLImageLoader(final Context context, final DownloadListener listener, final long accountId, final Uri uri) { + super(context); + mHandler = new Handler(); + mAccountId = accountId; + mUri = uri; + mListener = listener; + final TwidereApplication app = TwidereApplication.getInstance(context); + mDownloader = app.getFullImageDownloader(); + mDiskCache = app.getFullDiskCache(); + final Resources res = context.getResources(); + final DisplayMetrics dm = res.getDisplayMetrics(); + mFallbackSize = Math.max(dm.heightPixels, dm.widthPixels); + } - @Override - public GLImageLoader.Result loadInBackground() { - if (mUri == null) { - Result.nullInstance(); - } - final String scheme = mUri.getScheme(); - if ("http".equals(scheme) || "https".equals(scheme)) { - final String url = ParseUtils.parseString(mUri.toString()); - if (url == null) return Result.nullInstance(); - final File cacheFile = mDiskCache.get(url); - if (cacheFile != null) { - final File cacheDir = cacheFile.getParentFile(); - if (cacheDir != null && !cacheDir.exists()) { - cacheDir.mkdirs(); - } - } else - return Result.nullInstance(); - try { - // from SD cache - if (ImageValidator.checkImageValidity(cacheFile)) return decodeImageInternal(cacheFile); + @Override + public GLImageLoader.Result loadInBackground() { + if (mUri == null) { + return Result.nullInstance(); + } + final String scheme = mUri.getScheme(); + if ("http".equals(scheme) || "https".equals(scheme)) { + final String url = ParseUtils.parseString(mUri.toString()); + if (url == null) return Result.nullInstance(); + final File cacheFile = mDiskCache.get(url); + if (cacheFile != null) { + final File cacheDir = cacheFile.getParentFile(); + if (cacheDir != null && !cacheDir.exists()) { + cacheDir.mkdirs(); + } + } else + return Result.nullInstance(); + try { + // from SD cache + if (ImageValidator.checkImageValidity(cacheFile)) + return decodeImageInternal(cacheFile); - final InputStream is = mDownloader.getStream(url, new AccountExtra(mAccountId)); - if (is == null) return Result.nullInstance(); - final long length = is.available(); - mHandler.post(new DownloadStartRunnable(this, mListener, length)); - final OutputStream os = new FileOutputStream(cacheFile); - try { - dump(is, os); - mHandler.post(new DownloadFinishRunnable(this, mListener)); - } finally { - GalleryUtils.closeSilently(is); - GalleryUtils.closeSilently(os); - } - if (!ImageValidator.checkImageValidity(cacheFile)) { - // The file is corrupted, so we remove it from - // cache. - final Result result = decodeBitmapOnly(cacheFile); - if (cacheFile.isFile()) { - cacheFile.delete(); - } - return result; - } - return decodeImageInternal(cacheFile); - } catch (final Exception e) { - mHandler.post(new DownloadErrorRunnable(this, mListener, e)); - return Result.getInstance(cacheFile, e); - } - } else if (ContentResolver.SCHEME_FILE.equals(scheme)) { - final File file = new File(mUri.getPath()); - try { - return decodeImage(file); - } catch (final Exception e) { - return Result.getInstance(file, e); - } - } - return Result.nullInstance(); - } + final InputStream is = mDownloader.getStream(url, new AccountExtra(mAccountId)); + if (is == null) return Result.nullInstance(); + final long length = is.available(); + mHandler.post(new DownloadStartRunnable(this, mListener, length)); + final OutputStream os = new FileOutputStream(cacheFile); + try { + dump(is, os); + mHandler.post(new DownloadFinishRunnable(this, mListener)); + } finally { + GalleryUtils.closeSilently(is); + GalleryUtils.closeSilently(os); + } + if (!ImageValidator.checkImageValidity(cacheFile)) { + // The file is corrupted, so we remove it from + // cache. + final Result result = decodeBitmapOnly(cacheFile); + if (cacheFile.isFile()) { + cacheFile.delete(); + } + return result; + } + return decodeImageInternal(cacheFile); + } catch (final Exception e) { + mHandler.post(new DownloadErrorRunnable(this, mListener, e)); + return Result.getInstance(cacheFile, e); + } + } else if (ContentResolver.SCHEME_FILE.equals(scheme)) { + final File file = new File(mUri.getPath()); + try { + return decodeImage(file); + } catch (final Exception e) { + return Result.getInstance(file, e); + } + } + return Result.nullInstance(); + } - protected Result decodeBitmapOnly(final File file) { - final String path = file.getAbsolutePath(); - final BitmapFactory.Options o = new BitmapFactory.Options(); - o.inJustDecodeBounds = true; - o.inPreferredConfig = Bitmap.Config.RGB_565; - BitmapFactory.decodeFile(path, o); - final int width = o.outWidth, height = o.outHeight; - if (width <= 0 || height <= 0) return Result.getInstance(file, null); - o.inJustDecodeBounds = false; - o.inSampleSize = BitmapUtils.computeSampleSize(mFallbackSize / Math.max(width, height)); - final Bitmap bitmap = BitmapFactory.decodeFile(path, o); - return Result.getInstance(bitmap, Exif.getOrientation(file), file); - } + protected Result decodeBitmapOnly(final File file) { + final String path = file.getAbsolutePath(); + final BitmapFactory.Options o = new BitmapFactory.Options(); + o.inJustDecodeBounds = true; + o.inPreferredConfig = Bitmap.Config.RGB_565; + BitmapFactory.decodeFile(path, o); + final int width = o.outWidth, height = o.outHeight; + if (width <= 0 || height <= 0) return Result.getInstance(file, null); + o.inJustDecodeBounds = false; + o.inSampleSize = BitmapUtils.computeSampleSize(mFallbackSize / Math.max(width, height)); + final Bitmap bitmap = BitmapFactory.decodeFile(path, o); + return Result.getInstance(bitmap, Exif.getOrientation(file), file); + } - protected Result decodeImage(final File file) { - final String path = file.getAbsolutePath(); - try { - final BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(path, false); - final int width = decoder.getWidth(); - final int height = decoder.getHeight(); - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = BitmapUtils.computeSampleSize(mFallbackSize / Math.max(width, height)); - options.inPreferredConfig = Bitmap.Config.RGB_565; - final Bitmap bitmap = decoder.decodeRegion(new Rect(0, 0, width, height), options); - return Result.getInstance(decoder, bitmap, Exif.getOrientation(file), file); - } catch (final IOException e) { - return decodeBitmapOnly(file); - } - } + protected Result decodeImage(final File file) { + final String path = file.getAbsolutePath(); + try { + final BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(path, false); + final int width = decoder.getWidth(); + final int height = decoder.getHeight(); + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = BitmapUtils.computeSampleSize(mFallbackSize / Math.max(width, height)); + options.inPreferredConfig = Bitmap.Config.RGB_565; + final Bitmap bitmap = decoder.decodeRegion(new Rect(0, 0, width, height), options); + return Result.getInstance(decoder, bitmap, Exif.getOrientation(file), file); + } catch (final IOException e) { + return decodeBitmapOnly(file); + } + } - @Override - protected void onStartLoading() { - forceLoad(); - } + @Override + protected void onStartLoading() { + forceLoad(); + } - private Result decodeImageInternal(final File file) throws IOException { - if (ImageValidator.checkImageValidity(file)) return decodeImage(file); - throw new InvalidImageException(); - } + private Result decodeImageInternal(final File file) throws IOException { + if (ImageValidator.checkImageValidity(file)) return decodeImage(file); + throw new InvalidImageException(); + } - private void dump(final InputStream is, final OutputStream os) throws IOException { - final byte buffer[] = new byte[1024]; - int rc = is.read(buffer, 0, buffer.length); - long downloaded = 0; - while (rc > 0) { - downloaded += rc; - mHandler.post(new ProgressUpdateRunnable(mListener, downloaded)); - os.write(buffer, 0, rc); - rc = is.read(buffer, 0, buffer.length); - } - } + private void dump(final InputStream is, final OutputStream os) throws IOException { + final byte buffer[] = new byte[1024]; + int rc = is.read(buffer, 0, buffer.length); + long downloaded = 0; + while (rc > 0) { + downloaded += rc; + mHandler.post(new ProgressUpdateRunnable(mListener, downloaded)); + os.write(buffer, 0, rc); + rc = is.read(buffer, 0, buffer.length); + } + } - public static interface DownloadListener { - void onDownloadError(Throwable t); + public static interface DownloadListener { + void onDownloadError(Throwable t); - void onDownloadFinished(); + void onDownloadFinished(); - void onDownloadStart(long total); + void onDownloadStart(long total); - void onProgressUpdate(long downloaded); - } + void onProgressUpdate(long downloaded); + } - public static class InvalidImageException extends IOException { + public static class InvalidImageException extends IOException { - private static final long serialVersionUID = 8996099908714452289L; + private static final long serialVersionUID = 8996099908714452289L; - } + } - public static class Result { - public final Bitmap bitmap; - public final File file; - public final Exception exception; - public final BitmapRegionDecoder decoder; - public final int orientation; + public static class Result { + public final Bitmap bitmap; + public final File file; + public final Exception exception; + public final BitmapRegionDecoder decoder; + public final int orientation; - public Result(final BitmapRegionDecoder decoder, final Bitmap bitmap, final int orientation, final File file, - final Exception exception) { - this.bitmap = bitmap; - this.file = file; - this.decoder = decoder; - this.orientation = orientation; - this.exception = exception; - } + public Result(final BitmapRegionDecoder decoder, final Bitmap bitmap, final int orientation, final File file, + final Exception exception) { + this.bitmap = bitmap; + this.file = file; + this.decoder = decoder; + this.orientation = orientation; + this.exception = exception; + } - public static Result getInstance(final Bitmap bitmap, final int orientation, final File file) { - return new Result(null, bitmap, orientation, file, null); - } + public static Result getInstance(final Bitmap bitmap, final int orientation, final File file) { + return new Result(null, bitmap, orientation, file, null); + } - public static Result getInstance(final BitmapRegionDecoder decoder, final Bitmap bitmap, final int orientation, - final File file) { - return new Result(decoder, bitmap, orientation, file, null); - } + public static Result getInstance(final BitmapRegionDecoder decoder, final Bitmap bitmap, final int orientation, + final File file) { + return new Result(decoder, bitmap, orientation, file, null); + } - public static Result getInstance(final File file, final Exception e) { - return new Result(null, null, 0, file, e); - } + public static Result getInstance(final File file, final Exception e) { + return new Result(null, null, 0, file, e); + } - public static Result nullInstance() { - return new Result(null, null, 0, null, null); - } - } + public static Result nullInstance() { + return new Result(null, null, 0, null, null); + } + } - private final static class DownloadErrorRunnable implements Runnable { + private final static class DownloadErrorRunnable implements Runnable { - private final GLImageLoader loader; - private final DownloadListener listener; - private final Throwable t; + private final GLImageLoader loader; + private final DownloadListener listener; + private final Throwable t; - DownloadErrorRunnable(final GLImageLoader loader, final DownloadListener listener, final Throwable t) { - this.loader = loader; - this.listener = listener; - this.t = t; - } + DownloadErrorRunnable(final GLImageLoader loader, final DownloadListener listener, final Throwable t) { + this.loader = loader; + this.listener = listener; + this.t = t; + } - @Override - public void run() { - if (listener == null || loader.isAbandoned() || loader.isReset()) return; - listener.onDownloadError(t); - } - } + @Override + public void run() { + if (listener == null || loader.isAbandoned() || loader.isReset()) return; + listener.onDownloadError(t); + } + } - private final static class DownloadFinishRunnable implements Runnable { + private final static class DownloadFinishRunnable implements Runnable { - private final GLImageLoader loader; - private final DownloadListener listener; + private final GLImageLoader loader; + private final DownloadListener listener; - DownloadFinishRunnable(final GLImageLoader loader, final DownloadListener listener) { - this.loader = loader; - this.listener = listener; - } + DownloadFinishRunnable(final GLImageLoader loader, final DownloadListener listener) { + this.loader = loader; + this.listener = listener; + } - @Override - public void run() { - if (listener == null || loader.isAbandoned() || loader.isReset()) return; - listener.onDownloadFinished(); - } - } + @Override + public void run() { + if (listener == null || loader.isAbandoned() || loader.isReset()) return; + listener.onDownloadFinished(); + } + } - private final static class DownloadStartRunnable implements Runnable { + private final static class DownloadStartRunnable implements Runnable { - private final GLImageLoader loader; - private final DownloadListener listener; - private final long total; + private final GLImageLoader loader; + private final DownloadListener listener; + private final long total; - DownloadStartRunnable(final GLImageLoader loader, final DownloadListener listener, final long total) { - this.loader = loader; - this.listener = listener; - this.total = total; - } + DownloadStartRunnable(final GLImageLoader loader, final DownloadListener listener, final long total) { + this.loader = loader; + this.listener = listener; + this.total = total; + } - @Override - public void run() { - if (listener == null || loader.isAbandoned() || loader.isReset()) return; - listener.onDownloadStart(total); - } - } + @Override + public void run() { + if (listener == null || loader.isAbandoned() || loader.isReset()) return; + listener.onDownloadStart(total); + } + } - private final static class ProgressUpdateRunnable implements Runnable { + private final static class ProgressUpdateRunnable implements Runnable { - private final DownloadListener listener; - private final long current; + private final DownloadListener listener; + private final long current; - ProgressUpdateRunnable(final DownloadListener listener, final long current) { - this.listener = listener; - this.current = current; - } + ProgressUpdateRunnable(final DownloadListener listener, final long current) { + this.listener = listener; + this.current = current; + } - @Override - public void run() { - if (listener == null) return; - listener.onProgressUpdate(current); - } - } + @Override + public void run() { + if (listener == null) return; + listener.onProgressUpdate(current); + } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java index 0e30bff52..991677715 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java +++ b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java @@ -19,13 +19,6 @@ package org.mariotaku.twidere.app; -import static org.mariotaku.twidere.util.UserColorNicknameUtils.initUserColor; -import static org.mariotaku.twidere.util.Utils.getBestCacheDir; -import static org.mariotaku.twidere.util.Utils.getInternalCacheDir; -import static org.mariotaku.twidere.util.Utils.initAccountColor; -import static org.mariotaku.twidere.util.Utils.startProfilingServiceIfNeeded; -import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded; - import android.app.Application; import android.content.ComponentName; import android.content.Context; @@ -48,8 +41,6 @@ import com.nostra13.universalimageloader.core.assist.QueueProcessingType; import com.nostra13.universalimageloader.core.download.ImageDownloader; import com.nostra13.universalimageloader.utils.L; -import edu.ucdavis.earlybird.UCDService; - import org.acra.ACRA; import org.acra.ReportField; import org.acra.annotation.ReportsCrashes; @@ -75,269 +66,281 @@ import org.mariotaku.twidere.util.imageloader.TwidereImageDownloader; import org.mariotaku.twidere.util.imageloader.URLFileNameGenerator; import org.mariotaku.twidere.util.net.TwidereHostAddressResolver; -import twitter4j.http.HostAddressResolver; - import java.io.File; import java.util.Date; import java.util.Locale; +import edu.ucdavis.earlybird.UCDService; +import twitter4j.http.HostAddressResolver; + +import static org.mariotaku.twidere.util.UserColorNicknameUtils.initUserColor; +import static org.mariotaku.twidere.util.Utils.getBestCacheDir; +import static org.mariotaku.twidere.util.Utils.getInternalCacheDir; +import static org.mariotaku.twidere.util.Utils.initAccountColor; +import static org.mariotaku.twidere.util.Utils.startProfilingServiceIfNeeded; +import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded; + @ReportsCrashes(formKey = "", mailTo = Constants.APP_PROJECT_EMAIL, sharedPreferencesMode = Context.MODE_PRIVATE, - sharedPreferencesName = Constants.SHARED_PREFERENCES_NAME) + sharedPreferencesName = Constants.SHARED_PREFERENCES_NAME) public class TwidereApplication extends Application implements Constants, OnSharedPreferenceChangeListener { - private Handler mHandler; + private Handler mHandler; - private ImageLoaderWrapper mImageLoaderWrapper; - private ImageLoader mImageLoader; - private AsyncTaskManager mAsyncTaskManager; - private SharedPreferences mPreferences; - private AsyncTwitterWrapper mTwitterWrapper; - private MultiSelectManager mMultiSelectManager; - private TwidereImageDownloader mImageDownloader, mFullImageDownloader; - private DiskCache mDiskCache, mFullDiskCache; - private MessagesManager mCroutonsManager; - private SQLiteOpenHelper mSQLiteOpenHelper; - private SwipebackScreenshotManager mSwipebackScreenshotManager; - private HostAddressResolver mResolver; - private SQLiteDatabase mDatabase; + private ImageLoaderWrapper mImageLoaderWrapper; + private ImageLoader mImageLoader; + private AsyncTaskManager mAsyncTaskManager; + private SharedPreferences mPreferences; + private AsyncTwitterWrapper mTwitterWrapper; + private MultiSelectManager mMultiSelectManager; + private TwidereImageDownloader mImageDownloader, mFullImageDownloader; + private DiskCache mDiskCache, mFullDiskCache; + private MessagesManager mCroutonsManager; + private SQLiteOpenHelper mSQLiteOpenHelper; + private SwipebackScreenshotManager mSwipebackScreenshotManager; + private HostAddressResolver mResolver; + private SQLiteDatabase mDatabase; - public AsyncTaskManager getAsyncTaskManager() { - if (mAsyncTaskManager != null) return mAsyncTaskManager; - return mAsyncTaskManager = AsyncTaskManager.getInstance(); - } + public AsyncTaskManager getAsyncTaskManager() { + if (mAsyncTaskManager != null) return mAsyncTaskManager; + return mAsyncTaskManager = AsyncTaskManager.getInstance(); + } - public DiskCache getDiskCache() { - if (mDiskCache != null) return mDiskCache; - return mDiskCache = getDiskCache(DIR_NAME_IMAGE_CACHE); - } + public DiskCache getDiskCache() { + if (mDiskCache != null) return mDiskCache; + return mDiskCache = createDiskCache(DIR_NAME_IMAGE_CACHE); + } - public DiskCache getFullDiskCache() { - if (mFullDiskCache != null) return mFullDiskCache; - return mFullDiskCache = getDiskCache(DIR_NAME_FULL_IMAGE_CACHE); - } + public DiskCache getFullDiskCache() { + if (mFullDiskCache != null) return mFullDiskCache; + return mFullDiskCache = createDiskCache(DIR_NAME_FULL_IMAGE_CACHE); + } - public ImageDownloader getFullImageDownloader() { - if (mFullImageDownloader != null) return mFullImageDownloader; - return mFullImageDownloader = new TwidereImageDownloader(this, true); - } + public ImageDownloader getFullImageDownloader() { + if (mFullImageDownloader != null) return mFullImageDownloader; + return mFullImageDownloader = new TwidereImageDownloader(this, true); + } - public Handler getHandler() { - return mHandler; - } + public Handler getHandler() { + return mHandler; + } - public HostAddressResolver getHostAddressResolver() { - if (mResolver != null) return mResolver; - return mResolver = new TwidereHostAddressResolver(this); - } + public HostAddressResolver getHostAddressResolver() { + if (mResolver != null) return mResolver; + return mResolver = new TwidereHostAddressResolver(this); + } - public ImageDownloader getImageDownloader() { - if (mImageDownloader != null) return mImageDownloader; - return mImageDownloader = new TwidereImageDownloader(this, false); - } + public ImageDownloader getImageDownloader() { + if (mImageDownloader != null) return mImageDownloader; + return mImageDownloader = new TwidereImageDownloader(this, false); + } - public ImageLoader getImageLoader() { - if (mImageLoader != null) return mImageLoader; - final ImageLoader loader = ImageLoader.getInstance(); - final ImageLoaderConfiguration.Builder cb = new ImageLoaderConfiguration.Builder(this); - cb.threadPriority(Thread.NORM_PRIORITY - 2); - cb.denyCacheImageMultipleSizesInMemory(); - cb.tasksProcessingOrder(QueueProcessingType.LIFO); - // cb.memoryCache(new ImageMemoryCache(40)); - cb.diskCache(getDiskCache()); - cb.imageDownloader(getImageDownloader()); - L.writeDebugLogs(Utils.isDebugBuild()); - loader.init(cb.build()); - return mImageLoader = loader; - } + public ImageLoader getImageLoader() { + if (mImageLoader != null) return mImageLoader; + final ImageLoader loader = ImageLoader.getInstance(); + final ImageLoaderConfiguration.Builder cb = new ImageLoaderConfiguration.Builder(this); + cb.threadPriority(Thread.NORM_PRIORITY - 2); + cb.denyCacheImageMultipleSizesInMemory(); + cb.tasksProcessingOrder(QueueProcessingType.LIFO); + // cb.memoryCache(new ImageMemoryCache(40)); + cb.diskCache(getDiskCache()); + cb.imageDownloader(getImageDownloader()); + L.writeDebugLogs(Utils.isDebugBuild()); + loader.init(cb.build()); + return mImageLoader = loader; + } - public ImageLoaderWrapper getImageLoaderWrapper() { - if (mImageLoaderWrapper != null) return mImageLoaderWrapper; - return mImageLoaderWrapper = new ImageLoaderWrapper(getImageLoader()); - } + public ImageLoaderWrapper getImageLoaderWrapper() { + if (mImageLoaderWrapper != null) return mImageLoaderWrapper; + return mImageLoaderWrapper = new ImageLoaderWrapper(getImageLoader()); + } - public MessagesManager getMessagesManager() { - if (mCroutonsManager != null) return mCroutonsManager; - return mCroutonsManager = new MessagesManager(this); - } + public MessagesManager getMessagesManager() { + if (mCroutonsManager != null) return mCroutonsManager; + return mCroutonsManager = new MessagesManager(this); + } - public MultiSelectManager getMultiSelectManager() { - if (mMultiSelectManager != null) return mMultiSelectManager; - return mMultiSelectManager = new MultiSelectManager(); - } + public MultiSelectManager getMultiSelectManager() { + if (mMultiSelectManager != null) return mMultiSelectManager; + return mMultiSelectManager = new MultiSelectManager(); + } - public SQLiteDatabase getSQLiteDatabase() { - if (mDatabase != null) return mDatabase; + public SQLiteDatabase getSQLiteDatabase() { + if (mDatabase != null) return mDatabase; - StrictModeUtils.checkDiskIO(); - return mDatabase = getSQLiteOpenHelper().getWritableDatabase(); - } + StrictModeUtils.checkDiskIO(); + return mDatabase = getSQLiteOpenHelper().getWritableDatabase(); + } - public SQLiteOpenHelper getSQLiteOpenHelper() { - if (mSQLiteOpenHelper != null) return mSQLiteOpenHelper; - return mSQLiteOpenHelper = new TwidereSQLiteOpenHelper(this, DATABASES_NAME, DATABASES_VERSION); - } + public SQLiteOpenHelper getSQLiteOpenHelper() { + if (mSQLiteOpenHelper != null) return mSQLiteOpenHelper; + return mSQLiteOpenHelper = new TwidereSQLiteOpenHelper(this, DATABASES_NAME, DATABASES_VERSION); + } - public SwipebackScreenshotManager getSwipebackScreenshotManager() { - if (mSwipebackScreenshotManager != null) return mSwipebackScreenshotManager; - return mSwipebackScreenshotManager = new SwipebackScreenshotManager(this); - } + public SwipebackScreenshotManager getSwipebackScreenshotManager() { + if (mSwipebackScreenshotManager != null) return mSwipebackScreenshotManager; + return mSwipebackScreenshotManager = new SwipebackScreenshotManager(this); + } - public AsyncTwitterWrapper getTwitterWrapper() { - if (mTwitterWrapper != null) return mTwitterWrapper; - return mTwitterWrapper = AsyncTwitterWrapper.getInstance(this); - } + public AsyncTwitterWrapper getTwitterWrapper() { + if (mTwitterWrapper != null) return mTwitterWrapper; + return mTwitterWrapper = AsyncTwitterWrapper.getInstance(this); + } - @Override - public void onCreate() { - if (Utils.isDebugBuild()) { - StrictModeUtils.detectAllVmPolicy(); - } - super.onCreate(); - mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); - mHandler = new Handler(); - mPreferences.registerOnSharedPreferenceChangeListener(this); - configACRA(); - initializeAsyncTask(); - GalleryUtils.initialize(this); - initAccountColor(this); - initUserColor(this); + @Override + public void onCreate() { + if (Utils.isDebugBuild()) { + StrictModeUtils.detectAllVmPolicy(); + } + super.onCreate(); + mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); + mHandler = new Handler(); + mPreferences.registerOnSharedPreferenceChangeListener(this); + configACRA(); + initializeAsyncTask(); + GalleryUtils.initialize(this); + initAccountColor(this); + initUserColor(this); - final PackageManager pm = getPackageManager(); - final ComponentName main = new ComponentName(this, MainActivity.class); - final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class); - final boolean mainDisabled = pm.getComponentEnabledSetting(main) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED; - final boolean main2Disabled = pm.getComponentEnabledSetting(main2) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED; - final boolean no_entry = mainDisabled && main2Disabled; - if (no_entry) { - pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - } else if (!mainDisabled) { - pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, - PackageManager.DONT_KILL_APP); - } + final PackageManager pm = getPackageManager(); + final ComponentName main = new ComponentName(this, MainActivity.class); + final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class); + final boolean mainDisabled = pm.getComponentEnabledSetting(main) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED; + final boolean main2Disabled = pm.getComponentEnabledSetting(main2) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED; + final boolean no_entry = mainDisabled && main2Disabled; + if (no_entry) { + pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP); + } else if (!mainDisabled) { + pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); + } - startProfilingServiceIfNeeded(this); - startRefreshServiceIfNeeded(this); - } + startProfilingServiceIfNeeded(this); + startRefreshServiceIfNeeded(this); + } - @Override - public void onLowMemory() { - if (mImageLoaderWrapper != null) { - mImageLoaderWrapper.clearMemoryCache(); - } - super.onLowMemory(); - } + @Override + public void onLowMemory() { + if (mImageLoaderWrapper != null) { + mImageLoaderWrapper.clearMemoryCache(); + } + super.onLowMemory(); + } - @Override - public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) { - if (KEY_REFRESH_INTERVAL.equals(key)) { - stopService(new Intent(this, RefreshService.class)); - startRefreshServiceIfNeeded(this); - } else if (KEY_ENABLE_PROXY.equals(key) || KEY_CONNECTION_TIMEOUT.equals(key) || KEY_PROXY_HOST.equals(key) - || KEY_PROXY_PORT.equals(key) || KEY_FAST_IMAGE_LOADING.equals(key)) { - reloadConnectivitySettings(); - } else if (KEY_UCD_DATA_PROFILING.equals(key)) { - stopService(new Intent(this, UCDService.class)); - startProfilingServiceIfNeeded(this); - } else if (KEY_CONSUMER_KEY.equals(key) || KEY_CONSUMER_SECRET.equals(key) || KEY_API_URL_FORMAT.equals(key) - || KEY_AUTH_TYPE.equals(key) || KEY_SAME_OAUTH_SIGNING_URL.equals(key)) { - final SharedPreferences.Editor editor = preferences.edit(); - editor.putLong(KEY_API_LAST_CHANGE, System.currentTimeMillis()); - editor.apply(); - } - } + @Override + public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) { + if (KEY_REFRESH_INTERVAL.equals(key)) { + stopService(new Intent(this, RefreshService.class)); + startRefreshServiceIfNeeded(this); + } else if (KEY_ENABLE_PROXY.equals(key) || KEY_CONNECTION_TIMEOUT.equals(key) || KEY_PROXY_HOST.equals(key) + || KEY_PROXY_PORT.equals(key) || KEY_FAST_IMAGE_LOADING.equals(key)) { + reloadConnectivitySettings(); + } else if (KEY_UCD_DATA_PROFILING.equals(key)) { + stopService(new Intent(this, UCDService.class)); + startProfilingServiceIfNeeded(this); + } else if (KEY_CONSUMER_KEY.equals(key) || KEY_CONSUMER_SECRET.equals(key) || KEY_API_URL_FORMAT.equals(key) + || KEY_AUTH_TYPE.equals(key) || KEY_SAME_OAUTH_SIGNING_URL.equals(key)) { + final SharedPreferences.Editor editor = preferences.edit(); + editor.putLong(KEY_API_LAST_CHANGE, System.currentTimeMillis()); + editor.apply(); + } + } - public void reloadConnectivitySettings() { - if (mImageDownloader != null) { - mImageDownloader.reloadConnectivitySettings(); - } - } + public void reloadConnectivitySettings() { + if (mImageDownloader != null) { + mImageDownloader.reloadConnectivitySettings(); + } + } - private void configACRA() { - ACRA.init(this); - ACRA.getErrorReporter().setReportSender(new EmailIntentSender(this)); - } + private void configACRA() { + ACRA.init(this); + ACRA.getErrorReporter().setReportSender(new EmailIntentSender(this)); + } - private DiskCache getDiskCache(final String dirName) { - final File cacheDir = getBestCacheDir(this, dirName); - final File fallbackCacheDir = getInternalCacheDir(this, dirName); - return new UnlimitedDiscCache(cacheDir, fallbackCacheDir, new URLFileNameGenerator()); - } + private DiskCache createDiskCache(final String dirName) { + final File cacheDir = getBestCacheDir(this, dirName); + final File fallbackCacheDir = getInternalCacheDir(this, dirName); +// final LruDiscCache discCache = new LruDiscCache(cacheDir, new URLFileNameGenerator(), 384 * +// 1024 * 1024); +// discCache.setReserveCacheDir(fallbackCacheDir); +// return discCache; + return new UnlimitedDiscCache(cacheDir, fallbackCacheDir, new URLFileNameGenerator()); + } - private void initializeAsyncTask() { - // AsyncTask class needs to be loaded in UI thread. - // So we load it here to comply the rule. - try { - Class.forName(AsyncTask.class.getName()); - } catch (final ClassNotFoundException e) { - } - } + private void initializeAsyncTask() { + // AsyncTask class needs to be loaded in UI thread. + // So we load it here to comply the rule. + try { + Class.forName(AsyncTask.class.getName()); + } catch (final ClassNotFoundException e) { + } + } - public static TwidereApplication getInstance(final Context context) { - if (context == null) return null; - final Context app = context.getApplicationContext(); - return app instanceof TwidereApplication ? (TwidereApplication) app : null; - } + public static TwidereApplication getInstance(final Context context) { + if (context == null) return null; + final Context app = context.getApplicationContext(); + return app instanceof TwidereApplication ? (TwidereApplication) app : null; + } - static class EmailIntentSender implements ReportSender { + static class EmailIntentSender implements ReportSender { - private final Context mContext; + private final Context mContext; - EmailIntentSender(final Context ctx) { - mContext = ctx; - } + EmailIntentSender(final Context ctx) { + mContext = ctx; + } - @Override - public void send(final CrashReportData errorContent) throws ReportSenderException { - final Intent email = new Intent(Intent.ACTION_SEND); - email.setType("text/plain"); - email.putExtra(Intent.EXTRA_SUBJECT, String.format("%s Crash Report", getAppName())); - email.putExtra(Intent.EXTRA_TEXT, buildBody(errorContent)); - email.putExtra(Intent.EXTRA_EMAIL, new String[] { APP_PROJECT_EMAIL }); - final Intent chooser = Intent.createChooser(email, mContext.getString(R.string.send_crash_report)); - chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mContext.startActivity(chooser); - } + @Override + public void send(final CrashReportData errorContent) throws ReportSenderException { + final Intent email = new Intent(Intent.ACTION_SEND); + email.setType("text/plain"); + email.putExtra(Intent.EXTRA_SUBJECT, String.format("%s Crash Report", getAppName())); + email.putExtra(Intent.EXTRA_TEXT, buildBody(errorContent)); + email.putExtra(Intent.EXTRA_EMAIL, new String[]{APP_PROJECT_EMAIL}); + final Intent chooser = Intent.createChooser(email, mContext.getString(R.string.send_crash_report)); + chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(chooser); + } - private String buildBody(final CrashReportData errorContent) { - final String stack_trace = errorContent.getProperty(ReportField.STACK_TRACE); - final StringBuilder builder = new StringBuilder(); - builder.append(String.format(Locale.US, "Report date: %s\n", new Date(System.currentTimeMillis()))); - builder.append(String.format(Locale.US, "Android version: %s\n", Build.VERSION.RELEASE)); - builder.append(String.format(Locale.US, "API version: %d\n", Build.VERSION.SDK_INT)); - builder.append(String.format(Locale.US, "App version name: %s\n", getAppVersionName())); - builder.append(String.format(Locale.US, "App version code: %d\n", getAppVersionCode())); - builder.append(String.format(Locale.US, "Configuration: %s\n", mContext.getResources().getConfiguration())); - builder.append(String.format(Locale.US, "Stack trace:\n%s\n", stack_trace)); - return builder.toString(); - } + private String buildBody(final CrashReportData errorContent) { + final String stack_trace = errorContent.getProperty(ReportField.STACK_TRACE); + final StringBuilder builder = new StringBuilder(); + builder.append(String.format(Locale.US, "Report date: %s\n", new Date(System.currentTimeMillis()))); + builder.append(String.format(Locale.US, "Android version: %s\n", Build.VERSION.RELEASE)); + builder.append(String.format(Locale.US, "API version: %d\n", Build.VERSION.SDK_INT)); + builder.append(String.format(Locale.US, "App version name: %s\n", getAppVersionName())); + builder.append(String.format(Locale.US, "App version code: %d\n", getAppVersionCode())); + builder.append(String.format(Locale.US, "Configuration: %s\n", mContext.getResources().getConfiguration())); + builder.append(String.format(Locale.US, "Stack trace:\n%s\n", stack_trace)); + return builder.toString(); + } - private CharSequence getAppName() { - final PackageManager pm = mContext.getPackageManager(); - try { - return pm.getApplicationLabel(pm.getApplicationInfo(mContext.getPackageName(), 0)); - } catch (final NameNotFoundException e) { - return APP_NAME; - } - } + private CharSequence getAppName() { + final PackageManager pm = mContext.getPackageManager(); + try { + return pm.getApplicationLabel(pm.getApplicationInfo(mContext.getPackageName(), 0)); + } catch (final NameNotFoundException e) { + return APP_NAME; + } + } - private int getAppVersionCode() { - final PackageManager pm = mContext.getPackageManager(); - try { - return pm.getPackageInfo(mContext.getPackageName(), 0).versionCode; - } catch (final NameNotFoundException e) { - return 0; - } - } + private int getAppVersionCode() { + final PackageManager pm = mContext.getPackageManager(); + try { + return pm.getPackageInfo(mContext.getPackageName(), 0).versionCode; + } catch (final NameNotFoundException e) { + return 0; + } + } - private String getAppVersionName() { - final PackageManager pm = mContext.getPackageManager(); - try { - return pm.getPackageInfo(mContext.getPackageName(), 0).versionName; - } catch (final NameNotFoundException e) { - return "unknown"; - } - } - } + private String getAppVersionName() { + final PackageManager pm = mContext.getPackageManager(); + try { + return pm.getPackageInfo(mContext.getPackageName(), 0).versionName; + } catch (final NameNotFoundException e) { + return "unknown"; + } + } + } }