cpp-113: Checkbox is black on some devices with Material Dark theme
Fixes #113
This commit is contained in:
parent
3ca8a226d8
commit
8e9301832f
@ -45,7 +45,7 @@
|
||||
|
||||
<activity android:clearTaskOnLaunch="true" android:label="@string/c_app_name" android:launchMode="singleTop" android:name=".CalculatorActivityMobile" android:windowSoftInputMode="adjustPan"/>
|
||||
|
||||
<activity android:label="@string/c_app_settings" android:name=".preferences.PreferencesActivity" android:theme="@style/Cpp.Theme.Settings"/>
|
||||
<activity android:label="@string/c_app_settings" android:name=".preferences.PreferencesActivity"/>
|
||||
|
||||
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/>
|
||||
|
||||
@ -87,8 +87,6 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:label="@string/c_settings" android:name=".plot.PlotPreferenceActivity" android:theme="@style/Cpp.Theme.Settings"/>
|
||||
|
||||
<!-- ONSCREEN CONFIG -->
|
||||
|
||||
<activity android:icon="@drawable/ic_launcher_window" android:label="@string/c_app_name_on_screen" android:launchMode="singleInstance" android:name=".onscreen.CalculatorOnscreenStartActivity" android:theme="@style/Cpp.Theme.Dialog.Material">
|
||||
|
@ -33,7 +33,6 @@ import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.preferences.BasePreferencesActivity;
|
||||
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
|
||||
import org.solovyev.android.calculator.wizard.WizardActivity;
|
||||
import org.solovyev.android.prefs.*;
|
||||
@ -48,11 +47,6 @@ import static org.solovyev.android.Android.isPhoneModel;
|
||||
import static org.solovyev.android.DeviceModel.samsung_galaxy_s;
|
||||
import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/20/12
|
||||
* Time: 12:42 PM
|
||||
*/
|
||||
public final class Preferences {
|
||||
|
||||
private Preferences() {
|
||||
@ -115,24 +109,22 @@ public final class Preferences {
|
||||
metro_purple_theme(R.style.cpp_metro_purple_theme),
|
||||
metro_green_theme(R.style.cpp_metro_green_theme),
|
||||
material_theme(R.style.Cpp_Theme_Material),
|
||||
material_light_theme(R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Settings_Light, R.style.Cpp_Theme_Dialog_Material_Light),
|
||||
material_light_theme(R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Dialog_Material_Light),
|
||||
;
|
||||
|
||||
private static final SparseArray<TextColor> textColors = new SparseArray<>();
|
||||
|
||||
private final int themeId;
|
||||
private final int wizardThemeId;
|
||||
private final int settingsThemeId;
|
||||
private final int dialogThemeId;
|
||||
|
||||
Theme(@StyleRes int themeId) {
|
||||
this(themeId, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Settings, R.style.Cpp_Theme_Dialog_Material);
|
||||
this(themeId, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Dialog_Material);
|
||||
}
|
||||
|
||||
Theme(@StyleRes int themeId, @StyleRes int wizardThemeId, @StyleRes int settingsThemeId, int dialogThemeId) {
|
||||
Theme(@StyleRes int themeId, @StyleRes int wizardThemeId, int dialogThemeId) {
|
||||
this.themeId = themeId;
|
||||
this.wizardThemeId = wizardThemeId;
|
||||
this.settingsThemeId = settingsThemeId;
|
||||
this.dialogThemeId = dialogThemeId;
|
||||
}
|
||||
|
||||
@ -144,9 +136,6 @@ public final class Preferences {
|
||||
if (context instanceof WizardActivity) {
|
||||
return wizardThemeId;
|
||||
}
|
||||
if (context instanceof BasePreferencesActivity) {
|
||||
return settingsThemeId;
|
||||
}
|
||||
if (context instanceof PurchaseDialogActivity) {
|
||||
return dialogThemeId;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import org.solovyev.android.Android;
|
||||
import org.solovyev.android.Threads;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.preferences.PreferencesActivity;
|
||||
import org.solovyev.android.menu.*;
|
||||
import org.solovyev.common.JPredicate;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
@ -411,7 +412,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
preferences(R.id.menu_plot_settings) {
|
||||
@Override
|
||||
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
|
||||
context.startActivity(new Intent(context, PlotPreferenceActivity.class));
|
||||
PreferencesActivity.start(context, R.xml.preferences_plot, R.string.prefs_graph_screen_title);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.os.Bundle;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.preferences.BasePreferencesActivity;
|
||||
|
||||
public class PlotPreferenceActivity extends BasePreferencesActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//noinspection deprecation
|
||||
addPreferencesFromResource(R.xml.preferences_plot);
|
||||
}
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import org.solovyev.android.Activities;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.Inventory;
|
||||
import org.solovyev.android.checkout.ProductTypes;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class BasePreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static boolean SUPPORT_HEADERS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
|
||||
private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts());
|
||||
private Inventory inventory;
|
||||
private AdView adView;
|
||||
private Toolbar actionBar;
|
||||
private Preferences.Gui.Theme theme;
|
||||
private boolean paused = true;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
final SharedPreferences preferences = App.getPreferences();
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
theme = Preferences.Gui.getTheme(preferences);
|
||||
setTheme(theme.getThemeId(this));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
actionBar.setTitle(getTitle());
|
||||
|
||||
checkout.start();
|
||||
inventory = checkout.loadInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int layout) {
|
||||
final LayoutInflater inflater = LayoutInflater.from(this);
|
||||
final ViewGroup contentView = (ViewGroup) inflater.inflate(R.layout.cpp_activity_settings, new LinearLayout(this), true);
|
||||
|
||||
actionBar = (Toolbar) contentView.findViewById(R.id.action_bar);
|
||||
actionBar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
final ViewGroup contentWrapper = (ViewGroup) contentView.findViewById(R.id.content_wrapper);
|
||||
inflater.inflate(layout, contentWrapper, true);
|
||||
|
||||
// let's fix padding for parent view of list view
|
||||
Views.processViewsOfType(contentWrapper, ViewGroup.class, new Views.ViewProcessor<ViewGroup>() {
|
||||
@Override
|
||||
public void process(@Nonnull ViewGroup view) {
|
||||
for (int i = 0; i < view.getChildCount(); i++) {
|
||||
final View child = view.getChildAt(i);
|
||||
if (child.getId() == android.R.id.list) {
|
||||
view.setPadding(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
getWindow().setContentView(contentView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (!paused && Preferences.Gui.theme.isSameKey(key)) {
|
||||
ActivityUi.restartIfThemeChanged(this, theme);
|
||||
}
|
||||
}
|
||||
|
||||
private class InventoryListener implements Inventory.Listener {
|
||||
@Override
|
||||
public void onLoaded(@Nonnull Inventory.Products products) {
|
||||
final Inventory.Product product = products.get(ProductTypes.IN_APP);
|
||||
final boolean adFree = product.isPurchased("ad_free");
|
||||
onShowAd(!adFree);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onShowAd(boolean show) {
|
||||
if (!supportsHeaders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ListView listView = getListView();
|
||||
if (show) {
|
||||
if (adView != null) {
|
||||
return;
|
||||
}
|
||||
adView = (AdView) LayoutInflater.from(this).inflate(R.layout.ad, null);
|
||||
adView.show();
|
||||
try {
|
||||
listView.addHeaderView(adView);
|
||||
} catch (IllegalStateException e) {
|
||||
// doesn't support header views
|
||||
SUPPORT_HEADERS = false;
|
||||
adView.hide();
|
||||
adView = null;
|
||||
}
|
||||
} else {
|
||||
if (adView == null) {
|
||||
return;
|
||||
}
|
||||
listView.removeHeaderView(adView);
|
||||
adView.hide();
|
||||
adView = null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean supportsHeaders() {
|
||||
return SUPPORT_HEADERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (checkout.onActivityResult(requestCode, resultCode, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
paused = false;
|
||||
if (adView != null) {
|
||||
adView.resume();
|
||||
}
|
||||
inventory.whenLoaded(new InventoryListener());
|
||||
|
||||
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences());
|
||||
if (!theme.equals(newTheme)) {
|
||||
Activities.restartActivity(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
ActivityUi.reportActivityStart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
ActivityUi.reportActivityStop(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (adView != null) {
|
||||
adView.pause();
|
||||
}
|
||||
paused = true;
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (adView != null) {
|
||||
adView.destroy();
|
||||
}
|
||||
checkout.stop();
|
||||
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
@ -1,51 +1,33 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.annotation.XmlRes;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import org.solovyev.android.calculator.ActivityUi;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.BaseActivity;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.AD_FREE_P_KEY;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.precision;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.roundResult;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
|
||||
import static org.solovyev.android.view.VibratorContainer.Preferences.hapticFeedbackDuration;
|
||||
import static org.solovyev.android.view.VibratorContainer.Preferences.hapticFeedbackEnabled;
|
||||
import static org.solovyev.android.wizard.WizardUi.startWizard;
|
||||
import static android.support.v7.app.ActionBar.NAVIGATION_MODE_STANDARD;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PreferencesActivity extends BasePreferencesActivity {
|
||||
public class PreferencesActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
static final String EXTRA_PREFERENCE = "preference";
|
||||
static final String EXTRA_PREFERENCE_TITLE = "preference-title";
|
||||
|
||||
@Nonnull
|
||||
private static final SparseArray<String> preferences = new SparseArray<String>();
|
||||
private static final SparseArray<String> preferences = new SparseArray<>();
|
||||
|
||||
static {
|
||||
preferences.append(R.xml.preferences, "screen-main");
|
||||
@ -56,90 +38,86 @@ public class PreferencesActivity extends BasePreferencesActivity {
|
||||
preferences.append(R.xml.preferences_onscreen, "screen-onscreen");
|
||||
}
|
||||
|
||||
private Preference adFreePreference;
|
||||
@Nonnull
|
||||
private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts());
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
private boolean paused = true;
|
||||
|
||||
public PreferencesActivity() {
|
||||
super(R.layout.main_empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
App.getPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final int preference = intent.getIntExtra("preference", R.xml.preferences);
|
||||
final String title = intent.getStringExtra("preference-title");
|
||||
setPreference(preference, preferences.get(preference));
|
||||
if (preference == R.xml.preferences) {
|
||||
for (int i = 0; i < preferences.size(); i++) {
|
||||
final int xml = preferences.keyAt(i);
|
||||
final String name = preferences.valueAt(i);
|
||||
setPreferenceIntent(xml, name);
|
||||
final String preferenceTitle = intent.getStringExtra(EXTRA_PREFERENCE_TITLE);
|
||||
if (!TextUtils.isEmpty(preferenceTitle)) {
|
||||
setTitle(preferenceTitle);
|
||||
}
|
||||
final Preference restartWizardPreference = findPreference("restart_wizard");
|
||||
restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
final int preference = intent.getIntExtra(EXTRA_PREFERENCE, R.xml.preferences);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.main_layout, PreferencesFragment.create(preference, R.layout.fragment_preferences))
|
||||
.commit();
|
||||
}
|
||||
|
||||
getSupportActionBar().setNavigationMode(NAVIGATION_MODE_STANDARD);
|
||||
|
||||
checkout.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startWizard(CalculatorApplication.getInstance().getWizards(), DEFAULT_WIZARD_FLOW, PreferencesActivity.this);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
adFreePreference = findPreference(AD_FREE_P_KEY);
|
||||
adFreePreference.setEnabled(false);
|
||||
adFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(PreferencesActivity.this, PurchaseDialogActivity.class));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (title != null) {
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
final SharedPreferences preferences = App.getPreferences();
|
||||
onSharedPreferenceChanged(preferences, roundResult.getKey());
|
||||
onSharedPreferenceChanged(preferences, hapticFeedbackEnabled.getKey());
|
||||
}
|
||||
|
||||
private void setPreference(int xml, @Nonnull String name) {
|
||||
addPreferencesFromResource(xml);
|
||||
}
|
||||
|
||||
private void setPreferenceIntent(int xml, @Nonnull String name) {
|
||||
final Preference preference = findPreference(name);
|
||||
if (preference != null) {
|
||||
final Intent intent = new Intent(getApplicationContext(), PreferencesActivity.class);
|
||||
intent.putExtra("preference", xml);
|
||||
intent.putExtra("preference-title", preference.getTitle());
|
||||
preference.setIntent(intent);
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (!paused && Preferences.Gui.theme.isSameKey(key)) {
|
||||
ActivityUi.restartIfThemeChanged(this, ui.getTheme());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
super.onSharedPreferenceChanged(preferences, key);
|
||||
if (roundResult.getKey().equals(key)) {
|
||||
final Preference preference = findPreference(precision.getKey());
|
||||
if (preference != null) {
|
||||
preference.setEnabled(preferences.getBoolean(key, roundResult.getDefaultValue()));
|
||||
}
|
||||
} else if (hapticFeedbackEnabled.getKey().equals(key)) {
|
||||
final Preference preference = findPreference(hapticFeedbackDuration.getKey());
|
||||
if (preference != null) {
|
||||
preference.setEnabled(hapticFeedbackEnabled.getPreference(preferences));
|
||||
}
|
||||
}
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
paused = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onShowAd(boolean show) {
|
||||
super.onShowAd(show);
|
||||
if (adFreePreference != null) {
|
||||
adFreePreference.setEnabled(show);
|
||||
}
|
||||
protected void onPause() {
|
||||
paused = true;
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
checkout.stop();
|
||||
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static SparseArray<String> getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
public static void start(@Nonnull Context context, @XmlRes int preference, @StringRes int title) {
|
||||
final Intent intent = makeIntent(context, preference, title);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static Intent makeIntent(@Nonnull Context context, int preference, int title) {
|
||||
final Intent intent = new Intent(context, PreferencesActivity.class);
|
||||
intent.putExtra(EXTRA_PREFERENCE, preference);
|
||||
if (title != 0) {
|
||||
intent.putExtra(EXTRA_PREFERENCE_TITLE, context.getString(title));
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
ActivityCheckout getCheckout() {
|
||||
return checkout;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,187 @@
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import org.solovyev.android.calculator.AdView;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.checkout.BillingRequests;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.ProductTypes;
|
||||
import org.solovyev.android.checkout.RequestListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.precision;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.roundResult;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
|
||||
import static org.solovyev.android.view.VibratorContainer.Preferences.hapticFeedbackDuration;
|
||||
import static org.solovyev.android.view.VibratorContainer.Preferences.hapticFeedbackEnabled;
|
||||
import static org.solovyev.android.wizard.WizardUi.startWizard;
|
||||
|
||||
public class PreferencesFragment extends org.solovyev.android.material.preferences.PreferencesFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static boolean SUPPORT_HEADERS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
|
||||
|
||||
@Nonnull
|
||||
public static PreferencesFragment create(int preferencesResId, int layoutResId) {
|
||||
final PreferencesFragment fragment = new PreferencesFragment();
|
||||
fragment.setArguments(createArguments(preferencesResId, layoutResId, NO_THEME));
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Preference buyPremiumPreference;
|
||||
|
||||
@Nullable
|
||||
private AdView adView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
App.getPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
private void setPreferenceIntent(int xml, @Nonnull String name) {
|
||||
final Preference preference = findPreference(name);
|
||||
if (preference != null) {
|
||||
final Intent intent = new Intent(getActivity(), PreferencesActivity.class);
|
||||
intent.putExtra(PreferencesActivity.EXTRA_PREFERENCE, xml);
|
||||
intent.putExtra(PreferencesActivity.EXTRA_PREFERENCE_TITLE, preference.getTitle());
|
||||
preference.setIntent(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
final int preference = getPreferencesResId();
|
||||
if (preference == R.xml.preferences) {
|
||||
final SparseArray<String> preferences = PreferencesActivity.getPreferences();
|
||||
for (int i = 0; i < preferences.size(); i++) {
|
||||
final int xml = preferences.keyAt(i);
|
||||
final String name = preferences.valueAt(i);
|
||||
setPreferenceIntent(xml, name);
|
||||
}
|
||||
final Preference restartWizardPreference = findPreference("restart_wizard");
|
||||
restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startWizard(CalculatorApplication.getInstance().getWizards(), DEFAULT_WIZARD_FLOW, getActivity());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
buyPremiumPreference = findPreference("buy_premium");
|
||||
if (buyPremiumPreference != null) {
|
||||
buyPremiumPreference.setEnabled(false);
|
||||
buyPremiumPreference.setSelectable(false);
|
||||
buyPremiumPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(getActivity(), PurchaseDialogActivity.class));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getCheckout().whenReady(new Checkout.ListenerAdapter() {
|
||||
@Override
|
||||
public void onReady(@Nonnull BillingRequests requests) {
|
||||
requests.isPurchased(ProductTypes.IN_APP, CalculatorApplication.AD_FREE_PRODUCT_ID, new RequestListener<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(@Nonnull Boolean purchased) {
|
||||
if (buyPremiumPreference != null) {
|
||||
buyPremiumPreference.setEnabled(!purchased);
|
||||
buyPremiumPreference.setSelectable(!purchased);
|
||||
}
|
||||
onShowAd(!purchased);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int i, @Nonnull Exception e) {
|
||||
onShowAd(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
final SharedPreferences preferences = App.getPreferences();
|
||||
onSharedPreferenceChanged(preferences, roundResult.getKey());
|
||||
onSharedPreferenceChanged(preferences, hapticFeedbackEnabled.getKey());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Checkout getCheckout() {
|
||||
return ((PreferencesActivity) getActivity()).getCheckout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (roundResult.getKey().equals(key)) {
|
||||
final Preference preference = findPreference(precision.getKey());
|
||||
if (preference != null) {
|
||||
preference.setEnabled(preferences.getBoolean(key, roundResult.getDefaultValue()));
|
||||
}
|
||||
} else if (hapticFeedbackEnabled.getKey().equals(key)) {
|
||||
final Preference preference = findPreference(hapticFeedbackDuration.getKey());
|
||||
if (preference != null) {
|
||||
preference.setEnabled(hapticFeedbackEnabled.getPreference(preferences));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private boolean supportsHeaders() {
|
||||
return SUPPORT_HEADERS;
|
||||
}
|
||||
|
||||
protected void onShowAd(boolean show) {
|
||||
if (!supportsHeaders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ListView listView = getListView();
|
||||
if (show) {
|
||||
if (adView != null) {
|
||||
return;
|
||||
}
|
||||
adView = (AdView) LayoutInflater.from(getActivity()).inflate(R.layout.ad, null);
|
||||
adView.show();
|
||||
try {
|
||||
listView.addHeaderView(adView);
|
||||
} catch (IllegalStateException e) {
|
||||
// doesn't support header views
|
||||
SUPPORT_HEADERS = false;
|
||||
adView.hide();
|
||||
adView = null;
|
||||
}
|
||||
} else {
|
||||
if (adView == null) {
|
||||
return;
|
||||
}
|
||||
listView.removeHeaderView(adView);
|
||||
adView.hide();
|
||||
adView = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/action_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:theme="?attr/cpp_toolbar_theme" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
8
android-app/src/main/res/layout/fragment_preferences.xml
Normal file
8
android-app/src/main/res/layout/fragment_preferences.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
style="@style/CppListView"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
@ -30,7 +30,6 @@
|
||||
<attr name="cpp_main_bg" format="reference"/>
|
||||
<attr name="cpp_pane_bg" format="reference"/>
|
||||
<attr name="cpp_fab_bg" format="reference"/>
|
||||
<attr name="cpp_toolbar_theme" format="reference"/>
|
||||
<attr name="cpp_wizard_button_bg" format="reference"/>
|
||||
|
||||
<attr name="cpp_text_color" format="reference"/>
|
||||
|
@ -88,7 +88,6 @@
|
||||
</string>
|
||||
<string name="p_calc_haptic_feedback_duration" translatable="false">" "</string>
|
||||
|
||||
<string name="p_calc_ad_free_key" translatable="false">org.solovyev.android.calculator_ad_free</string>
|
||||
<string name="p_calc_ad_free" translatable="false">false</string>
|
||||
|
||||
</resources>
|
@ -293,25 +293,4 @@
|
||||
<item name="android:backgroundSplit">@color/cpp_material_actionbar_light</item>
|
||||
</style>
|
||||
|
||||
<style name="CppToolbar" parent="@style/Widget.AppCompat.Toolbar">
|
||||
<item name="background">@color/cpp_material_actionbar</item>
|
||||
<item name="android:background">@color/cpp_material_actionbar</item>
|
||||
<item name="backgroundStacked">@color/cpp_material_actionbar</item>
|
||||
<item name="android:backgroundStacked">@color/cpp_material_actionbar</item>
|
||||
<item name="backgroundSplit">@color/cpp_material_actionbar</item>
|
||||
<item name="android:backgroundSplit">@color/cpp_material_actionbar</item>
|
||||
|
||||
<item name="navigationIcon">?attr/homeAsUpIndicator</item>
|
||||
<item name="android:navigationIcon">?attr/homeAsUpIndicator</item>
|
||||
</style>
|
||||
|
||||
<style name="CppToolbar.Light" parent="CppToolbar">
|
||||
<item name="background">@color/cpp_material_actionbar_light</item>
|
||||
<item name="android:background">@color/cpp_material_actionbar_light</item>
|
||||
<item name="backgroundStacked">@color/cpp_material_actionbar_light</item>
|
||||
<item name="android:backgroundStacked">@color/cpp_material_actionbar_light</item>
|
||||
<item name="backgroundSplit">@color/cpp_material_actionbar_light</item>
|
||||
<item name="android:backgroundSplit">@color/cpp_material_actionbar_light</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -114,27 +114,4 @@
|
||||
<item name="cpp_wizard_button_bg">@color/cpp_wizard_button_selector_light</item>
|
||||
</style>
|
||||
|
||||
<style name="Cpp.Theme.Settings" parent="Cpp.Theme">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowActionBar">false</item>
|
||||
<item name="cpp_toolbar_theme">@style/Cpp.Theme.Toolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="Cpp.Theme.Settings.Light" parent="Cpp.Theme.Light">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowActionBar">false</item>
|
||||
<item name="cpp_toolbar_theme">@style/Cpp.Theme.Toolbar.Light</item>
|
||||
</style>
|
||||
|
||||
<style name="Cpp.Theme.Toolbar" parent="Cpp.Theme">
|
||||
<item name="toolbarStyle">@style/CppToolbar</item>
|
||||
<item name="android:toolbarStyle">@style/CppToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="Cpp.Theme.Toolbar.Light" parent="Cpp.Theme">
|
||||
<item name="toolbarStyle">@style/CppToolbar.Light</item>
|
||||
<item name="android:toolbarStyle">@style/CppToolbar.Light</item>
|
||||
</style>
|
||||
|
||||
|
||||
</resources>
|
@ -26,7 +26,7 @@
|
||||
a:key="screen-main">
|
||||
|
||||
<Preference
|
||||
a:key="@string/p_calc_ad_free_key"
|
||||
a:key="buy_premium"
|
||||
a:title="@string/c_calc_ad_free_title"
|
||||
a:summary="@string/c_calc_ad_free_summary"
|
||||
a:defaultValue="false" />
|
||||
|
Loading…
Reference in New Issue
Block a user