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;
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) {
}
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);
@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());
dialog2.setCancelable(false);
}
- SharedPreferences pref = U.getSharedPreferences(getActivity());
if(pref.getBoolean("taskbar_active", false)
&& getActivity().isInMultiWindowMode()
&& !FreeformHackHelper.getInstance().isFreeformHackActive()) {
case "blacklist":
Intent intent = null;
- SharedPreferences pref = U.getSharedPreferences(getActivity());
switch(pref.getString("theme", "light")) {
case "light":
intent = new Intent(getActivity(), SelectAppActivity.class);
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;
--- /dev/null
+<?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>