NPE fixed
This commit is contained in:
parent
c47cccf04a
commit
07ee83b89e
@ -29,6 +29,7 @@
|
||||
|
||||
</activity>
|
||||
|
||||
<!--NOTE: a:configChanges="orientation|keyboardHidden" is needed to correct work of dialog windows (not to close them on orientation change) -->
|
||||
<activity a:name=".CalculatorPreferencesActivity"
|
||||
a:label="@string/c_app_settings"
|
||||
a:configChanges="orientation|keyboardHidden"/>
|
||||
|
@ -7,16 +7,12 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.*;
|
||||
@ -43,7 +39,7 @@ import org.solovyev.android.calculator.view.NumeralBasesButton;
|
||||
import org.solovyev.android.history.HistoryDragProcessor;
|
||||
import org.solovyev.android.prefs.IntegerPreference;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
import org.solovyev.android.view.*;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
import org.solovyev.android.view.drag.*;
|
||||
import org.solovyev.common.utils.Announcer;
|
||||
import org.solovyev.common.utils.Point2d;
|
||||
@ -124,7 +120,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
|
||||
} catch (ClassCastException e) {
|
||||
// super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
|
||||
Log.d(CalculatorActivity.class.getName(), e.getMessage(), e);
|
||||
Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +190,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
}
|
||||
|
||||
|
||||
CalculatorEngine.instance.reset(this, preferences);
|
||||
CalculatorEngine.instance.softReset(this, preferences);
|
||||
|
||||
initMultiplicationButton();
|
||||
|
||||
@ -420,7 +416,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
}
|
||||
|
||||
ResourceCache.instance.init(R.id.class, this);
|
||||
CalculatorEngine.instance.init(this, preferences);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
@ -512,30 +507,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
CalculatorActivityLauncher.showVars(this);
|
||||
}
|
||||
|
||||
private final static String paypalDonateUrl = "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted";
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void donateButtonClickHandler(@NotNull View v) {
|
||||
final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
final View view = layoutInflater.inflate(R.layout.donate, null);
|
||||
|
||||
final TextView donate = (TextView) view.findViewById(R.id.donateText);
|
||||
donate.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(R.string.c_cancel, null)
|
||||
.setPositiveButton(R.string.c_donate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse(paypalDonateUrl));
|
||||
startActivity(i);
|
||||
}
|
||||
})
|
||||
.setView(view);
|
||||
|
||||
builder.create().show();
|
||||
CalculatorApplication.showDonationDialog(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -639,7 +613,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
}
|
||||
|
||||
if (CalculatorEngine.Preferences.getPreferenceKeys().contains(key)) {
|
||||
CalculatorEngine.instance.reset(this, preferences);
|
||||
CalculatorEngine.instance.softReset(this, preferences);
|
||||
this.calculatorModel.evaluate();
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,19 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@ -11,6 +22,8 @@ import org.solovyev.android.ads.AdsController;
|
||||
*/
|
||||
public class CalculatorApplication extends android.app.Application {
|
||||
|
||||
private static final String paypalDonateUrl = "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted";
|
||||
|
||||
public static final String AD_FREE_PRODUCT_ID = "ad_free";
|
||||
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
|
||||
|
||||
@ -44,5 +57,31 @@ public class CalculatorApplication extends android.app.Application {
|
||||
return CalculatorSecurity.getPK();
|
||||
}
|
||||
});
|
||||
|
||||
CalculatorEngine.instance.init(this, PreferenceManager.getDefaultSharedPreferences(this));
|
||||
|
||||
}
|
||||
|
||||
public static void showDonationDialog(@NotNull final Context context) {
|
||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
final View view = layoutInflater.inflate(R.layout.donate, null);
|
||||
|
||||
final TextView donate = (TextView) view.findViewById(R.id.donateText);
|
||||
donate.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(R.string.c_cancel, null)
|
||||
.setPositiveButton(R.string.c_donate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse(paypalDonateUrl));
|
||||
context.startActivity(i);
|
||||
}
|
||||
})
|
||||
.setView(view);
|
||||
|
||||
builder.create().show();
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ public class CalculatorEditor extends EditText implements SharedPreferences.OnSh
|
||||
super.onCreateContextMenu(menu);
|
||||
|
||||
menu.removeItem(android.R.id.selectAll);
|
||||
menu.removeItem(android.R.id.startSelectingText);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +46,7 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
|
||||
|
||||
protected final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
private MathEntityArrayAdapter<T> adapter;
|
||||
|
||||
@Nullable
|
||||
@ -168,11 +168,6 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
|
||||
return t != null && EqualsTool.areEqual(getMathEntityCategory(t), category);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MathEntityArrayAdapter<T> getAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract MathEntityDescriptionGetter getDescriptionGetter();
|
||||
|
||||
@ -183,15 +178,18 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
|
||||
abstract String getMathEntityCategory(@NotNull T t);
|
||||
|
||||
protected void sort() {
|
||||
AbstractMathEntityListActivity.this.adapter.sort(new Comparator<T>() {
|
||||
@Override
|
||||
public int compare(T function1, T function2) {
|
||||
return function1.getName().compareTo(function2.getName());
|
||||
}
|
||||
});
|
||||
final MathEntityArrayAdapter<T> localAdapter = adapter;
|
||||
if (localAdapter != null) {
|
||||
localAdapter.sort(new Comparator<T>() {
|
||||
@Override
|
||||
public int compare(T function1, T function2) {
|
||||
return function1.getName().compareTo(function2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
AbstractMathEntityListActivity.this.adapter.notifyDataSetChanged();
|
||||
}
|
||||
localAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
|
||||
|
||||
@ -257,4 +255,22 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
|
||||
@Nullable
|
||||
String getDescription(@NotNull Context context, @NotNull String mathEntityName);
|
||||
}
|
||||
|
||||
public void addToAdapter(@NotNull T mathEntity) {
|
||||
if (this.adapter != null) {
|
||||
this.adapter.add(mathEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromAdapter(@NotNull T mathEntity) {
|
||||
if (this.adapter != null) {
|
||||
this.adapter.remove(mathEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyAdapter() {
|
||||
if (this.adapter != null) {
|
||||
this.adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,9 +140,9 @@ public class FunctionEditorSaver implements DialogInterface.OnClickListener{
|
||||
final Function addedVar = mathRegistry.add(varBuilder);
|
||||
if (activity.isInCategory(addedVar)) {
|
||||
if (editedInstance != null) {
|
||||
activity.getAdapter().remove(editedInstance);
|
||||
activity.removeFromAdapter(editedInstance);
|
||||
}
|
||||
activity.getAdapter().add(addedVar);
|
||||
activity.addToAdapter(addedVar);
|
||||
}
|
||||
|
||||
mathRegistry.save(activity);
|
||||
|
@ -61,13 +61,13 @@ class MathEntityRemover<T extends MathEntity> implements DialogInterface.OnClick
|
||||
showConfirmationDialog();
|
||||
} else {
|
||||
if (activity.isInCategory(mathEntity)) {
|
||||
activity.getAdapter().remove(mathEntity);
|
||||
activity.removeFromAdapter(mathEntity);
|
||||
}
|
||||
|
||||
varsRegistry.remove(mathEntity);
|
||||
varsRegistry.save(activity);
|
||||
if (activity.isInCategory(mathEntity)) {
|
||||
activity.getAdapter().notifyDataSetChanged();
|
||||
activity.notifyAdapter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,9 +137,9 @@ class VarEditorSaver<T extends MathEntity> implements DialogInterface.OnClickLis
|
||||
final T addedVar = mathRegistry.add(varBuilder);
|
||||
if (activity.isInCategory(addedVar)) {
|
||||
if (editedInstance != null) {
|
||||
activity.getAdapter().remove(editedInstance);
|
||||
activity.removeFromAdapter(editedInstance);
|
||||
}
|
||||
activity.getAdapter().add(addedVar);
|
||||
activity.addToAdapter(addedVar);
|
||||
}
|
||||
|
||||
mathRegistry.save(activity);
|
||||
|
@ -319,6 +319,27 @@ public enum CalculatorEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public void softReset(@Nullable Context context, @Nullable SharedPreferences preferences) {
|
||||
synchronized (lock) {
|
||||
if (preferences != null) {
|
||||
this.setPrecision(Preferences.precision.getPreference(preferences));
|
||||
this.setRoundResult(Preferences.roundResult.getPreference(preferences));
|
||||
this.setAngleUnits(getAngleUnitsFromPrefs(preferences));
|
||||
this.setNumeralBase(getNumeralBaseFromPrefs(preferences));
|
||||
this.setMultiplicationSign(Preferences.multiplicationSign.getPreference(preferences));
|
||||
|
||||
final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences);
|
||||
if (StringUtils.isEmpty(groupingSeparator)) {
|
||||
this.getEngine().setUseGroupingSeparator(false);
|
||||
} else {
|
||||
this.getEngine().setUseGroupingSeparator(true);
|
||||
this.getEngine().setGroupingSeparator(groupingSeparator.charAt(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public NumeralBase getNumeralBaseFromPrefs(@NotNull SharedPreferences preferences) {
|
||||
return Preferences.numeralBase.getPreference(preferences);
|
||||
|
Loading…
Reference in New Issue
Block a user