OSDN Git Service

Add donation preference and strings
authorfarmerbb <farmerbb@gmail.com>
Sat, 17 Sep 2016 19:33:00 +0000 (13:33 -0600)
committerfarmerbb <farmerbb@gmail.com>
Sat, 17 Sep 2016 19:33:00 +0000 (13:33 -0600)
app/src/main/java/com/farmerbb/taskbar/fragment/SettingsFragment.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/pref_about_donate.xml [new file with mode: 0644]

index 93535a6..54fe6cd 100644 (file)
@@ -29,6 +29,7 @@ import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.graphics.Rect;
 import android.hardware.display.DisplayManager;
+import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.CheckBoxPreference;
@@ -62,10 +63,15 @@ import com.farmerbb.taskbar.util.PinnedBlockedApps;
 import com.farmerbb.taskbar.util.SavedWindowSizes;
 import com.farmerbb.taskbar.util.U;
 
+import java.text.NumberFormat;
+import java.util.Currency;
+import java.util.Locale;
+
 public class SettingsFragment extends PreferenceFragment implements OnPreferenceClickListener {
 
     private boolean finishedLoadingPrefs;
     private boolean showReminderToast = false;
+    private int noThanksCount = 0;
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
@@ -110,7 +116,21 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
         }
 
         addPreferencesFromResource(R.xml.pref_advanced);
-        addPreferencesFromResource(R.xml.pref_about);
+
+        boolean playStoreInstalled = true;
+        try {
+            getActivity().getPackageManager().getPackageInfo("com.android.vending", 0);
+        } catch (PackageManager.NameNotFoundException e) {
+            playStoreInstalled = false;
+        }
+
+        if(BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID)
+                && playStoreInstalled
+                && !pref.getBoolean("hide_donate", false)) {
+            addPreferencesFromResource(R.xml.pref_about_donate);
+            findPreference("donate").setOnPreferenceClickListener(this);
+        } else
+            addPreferencesFromResource(R.xml.pref_about);
 
         // Set OnClickListeners for certain preferences
         findPreference("clear_pinned_apps").setOnPreferenceClickListener(this);
@@ -225,6 +245,8 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
     @TargetApi(Build.VERSION_CODES.N)
     @Override
     public boolean onPreferenceClick(final Preference p) {
+        final SharedPreferences pref = U.getSharedPreferences(getActivity());
+
         switch(p.getKey()) {
             case "clear_pinned_apps":
                 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@@ -304,7 +326,6 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
                         dialog2.setCancelable(false);
                     }
 
-                    SharedPreferences pref = U.getSharedPreferences(getActivity());
                     if(pref.getBoolean("taskbar_active", false)
                             && getActivity().isInMultiWindowMode()
                             && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
@@ -332,7 +353,6 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
             case "blacklist":
                 Intent intent = null;
 
-                SharedPreferences pref = U.getSharedPreferences(getActivity());
                 switch(pref.getString("theme", "light")) {
                     case "light":
                         intent = new Intent(getActivity(), SelectAppActivity.class);
@@ -344,6 +364,40 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
 
                 startActivity(intent);
                 break;
+            case "donate":
+                NumberFormat format = NumberFormat.getCurrencyInstance();
+                format.setCurrency(Currency.getInstance(Locale.US));
+
+                AlertDialog.Builder builder3 = new AlertDialog.Builder(getActivity());
+                builder3.setTitle(R.string.pref_title_donate)
+                        .setMessage(getString(R.string.dialog_donate_message, format.format(1.99)))
+                        .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+                                Intent intent = new Intent(Intent.ACTION_VIEW);
+                                intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.BASE_APPLICATION_ID + ".paid"));
+                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+                                try {
+                                    startActivity(intent);
+                                } catch (ActivityNotFoundException e) { /* Gracefully fail */ }
+                            }
+                        })
+                        .setNegativeButton(R.string.action_no_thanks, new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+                                noThanksCount++;
+
+                                if(noThanksCount == 3) {
+                                    pref.edit().putBoolean("hide_donate", true).apply();
+                                    findPreference("donate").setEnabled(false);
+                                }
+                            }
+                        });
+
+                AlertDialog dialog3 = builder3.create();
+                dialog3.show();
+                break;
         }
 
         return true;
index a515900..e1690c5 100644 (file)
     <string name="enable_developer_options">Enable Developer Options by tapping on the build number 7 times</string>
 
     <string name="pref_title_anchor">Anchor Taskbar when screen rotates</string>
+    <string name="pref_title_donate">Donate</string>
+    <string name="pref_summary_donate">Support the development of Taskbar with a small donation by upgrading to the Donate Version</string>
+    <string name="dialog_donate_message">Support the development of Taskbar by upgrading to the Donate Version for %1$s!\n\nThe Donate Version is identical to the free version and your preferences will automatically transfer over.\n\nTaskbar is and will always be 100%% free, open source, with absolutely no ads.  However, your support is greatly appreciated!</string>
+    <string name="action_no_thanks">No thanks</string>
 
 </resources>
index 491d906..30bdcc0 100644 (file)
     <string name="enable_developer_options">Enable Developer Options by tapping on the build number 7 times</string>
 
     <string name="pref_title_anchor">Anchor Taskbar when screen rotates</string>
+    <string name="pref_title_donate">Donate</string>
+    <string name="pref_summary_donate">Support the development of Taskbar with a small donation by upgrading to the Donate Version</string>
+    <string name="dialog_donate_message">Support the development of Taskbar by upgrading to the Donate Version for %1$s!\n\nThe Donate Version is identical to the free version and your preferences will automatically transfer over.\n\nTaskbar is and will always be 100%% free, open source, with absolutely no ads.  However, your support is greatly appreciated!</string>
+    <string name="action_no_thanks">No thanks</string>
 
 </resources>
diff --git a/app/src/main/res/xml/pref_about_donate.xml b/app/src/main/res/xml/pref_about_donate.xml
new file mode 100644 (file)
index 0000000..0ae271b
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2016 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <PreferenceCategory android:title="@string/pref_header_about">
+
+        <Preference android:key="about" />
+
+        <Preference
+            android:key="donate"
+            android:title="@string/pref_title_donate"
+            android:summary="@string/pref_summary_donate"/>
+
+    </PreferenceCategory>
+
+    <PreferenceCategory android:title="\n\n" />
+
+</PreferenceScreen>