OSDN Git Service

Taskbar 3.0.7
authorBraden Farmer <farmerbb@gmail.com>
Sat, 11 Feb 2017 19:25:26 +0000 (12:25 -0700)
committerBraden Farmer <farmerbb@gmail.com>
Sat, 11 Feb 2017 19:25:26 +0000 (12:25 -0700)
• Fix toast memory leak + small toast bugfix

app/build.gradle
app/src/main/java/com/farmerbb/taskbar/util/ToastHelper.java [new file with mode: 0644]
app/src/main/java/com/farmerbb/taskbar/util/U.java

index 414b13a..7b718a3 100644 (file)
@@ -31,7 +31,7 @@ android {
         minSdkVersion 21
         targetSdkVersion 25
 
-        versionCode 119
+        versionCode 120
         versionName "3.0.7"
 
         resConfigs "en", "ja", "ru", "de"
diff --git a/app/src/main/java/com/farmerbb/taskbar/util/ToastHelper.java b/app/src/main/java/com/farmerbb/taskbar/util/ToastHelper.java
new file mode 100644 (file)
index 0000000..7262394
--- /dev/null
@@ -0,0 +1,41 @@
+/* Copyright 2017 Braden Farmer
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.farmerbb.taskbar.util;
+
+import moe.banana.support.ToastCompat;
+
+class ToastHelper {
+
+    private ToastCompat lastToast;
+
+    private static ToastHelper theInstance;
+
+    private ToastHelper() {}
+
+    public static ToastHelper getInstance() {
+        if(theInstance == null) theInstance = new ToastHelper();
+
+        return theInstance;
+    }
+
+    ToastCompat getLastToast() {
+        return lastToast;
+    }
+
+    void setLastToast(ToastCompat lastToast) {
+        this.lastToast = lastToast;
+    }
+}
\ No newline at end of file
index ce74d34..4f6ddf4 100644 (file)
@@ -71,7 +71,6 @@ public class U {
 
     private static SharedPreferences pref;
     private static Integer cachedRotation;
-    private static ToastCompat toast;
 
     private static final int FULLSCREEN = 0;
     private static final int LEFT = -1;
@@ -170,11 +169,14 @@ public class U {
     public static void showToast(Context context, String message, int length) {
         cancelToast();
 
-        toast = ToastCompat.makeText(context, message, length);
+        ToastCompat toast = ToastCompat.makeText(context, message, length);
         toast.show();
+
+        ToastHelper.getInstance().setLastToast(toast);
     }
 
     public static void cancelToast() {
+        ToastCompat toast = ToastHelper.getInstance().getLastToast();
         if(toast != null) toast.cancel();
     }