Changes
This commit is contained in:
@@ -1,200 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.Html;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.text.TextProcessor;
|
||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||
import org.solovyev.android.view.AutoResizeTextView;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/17/11
|
||||
* Time: 10:58 PM
|
||||
*/
|
||||
public class AndroidCalculatorDisplayView extends AutoResizeTextView implements CalculatorDisplayView {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private final static TextProcessor<TextHighlighter.Result, String> textHighlighter = new TextHighlighter(Color.WHITE, false);
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private volatile CalculatorDisplayViewState state = CalculatorDisplayViewStateImpl.newDefaultInstance();
|
||||
|
||||
private volatile boolean viewStateChange = false;
|
||||
|
||||
@NotNull
|
||||
private final Object lock = new Object();
|
||||
|
||||
@NotNull
|
||||
private final Handler handler = new Handler();
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public AndroidCalculatorDisplayView(Context context) {
|
||||
super(context);
|
||||
this.addTextChangedListener(new TextWatcherImpl());
|
||||
}
|
||||
|
||||
public AndroidCalculatorDisplayView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.addTextChangedListener(new TextWatcherImpl());
|
||||
|
||||
}
|
||||
|
||||
public AndroidCalculatorDisplayView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
this.addTextChangedListener(new TextWatcherImpl());
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public void setState(@NotNull final CalculatorDisplayViewState state) {
|
||||
final CharSequence text = prepareText(state.getStringResult(), state.isValid());
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
viewStateChange = true;
|
||||
|
||||
AndroidCalculatorDisplayView.this.state = state;
|
||||
if (state.isValid()) {
|
||||
setTextColor(getResources().getColor(R.color.default_text_color));
|
||||
setText(text);
|
||||
|
||||
adjustTextSize();
|
||||
|
||||
} else {
|
||||
// update text in order to get rid of HTML tags
|
||||
setText(getText().toString());
|
||||
setTextColor(getResources().getColor(R.color.display_error_text_color));
|
||||
|
||||
// error messages are never shown -> just greyed out text (error message will be shown on click)
|
||||
//setText(state.getErrorMessage());
|
||||
//redraw();
|
||||
}
|
||||
} finally {
|
||||
viewStateChange = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CalculatorDisplayViewState getState() {
|
||||
synchronized (lock) {
|
||||
return this.state;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static CharSequence prepareText(@Nullable String text, boolean valid) {
|
||||
CharSequence result;
|
||||
|
||||
if (valid && text != null) {
|
||||
|
||||
//Log.d(this.getClass().getName(), text);
|
||||
|
||||
try {
|
||||
final TextHighlighter.Result processedText = textHighlighter.process(text);
|
||||
text = processedText.toString();
|
||||
result = Html.fromHtml(text);
|
||||
} catch (CalculatorParseException e) {
|
||||
result = text;
|
||||
}
|
||||
} else {
|
||||
result = text;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void adjustTextSize() {
|
||||
// todo serso: think where to move it (keep in mind org.solovyev.android.view.AutoResizeTextView.resetTextSize())
|
||||
setAddEllipsis(false);
|
||||
setMinTextSize(10);
|
||||
resizeText();
|
||||
}
|
||||
|
||||
|
||||
public void handleTextChange(Editable s) {
|
||||
synchronized (lock) {
|
||||
if (!viewStateChange) {
|
||||
// external text change => need to notify display
|
||||
// todo serso: implement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void init(@NotNull Context context) {
|
||||
if (!initialized) {
|
||||
this.setOnClickListener(new CalculatorDisplayOnClickListener(context));
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private final class TextWatcherImpl implements TextWatcher {
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
handleTextChange(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.util.AttributeSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.text.TextProcessor;
|
||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||
import org.solovyev.android.view.AutoResizeTextView;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/17/11
|
||||
* Time: 10:58 PM
|
||||
*/
|
||||
public class AndroidCalculatorDisplayView extends AutoResizeTextView implements CalculatorDisplayView {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private final static TextProcessor<TextHighlighter.Result, String> textHighlighter = new TextHighlighter(Color.WHITE, false);
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private volatile CalculatorDisplayViewState state = CalculatorDisplayViewStateImpl.newDefaultInstance();
|
||||
|
||||
private volatile boolean viewStateChange = false;
|
||||
|
||||
@NotNull
|
||||
private final Object lock = new Object();
|
||||
|
||||
@NotNull
|
||||
private final Handler handler = new Handler();
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public AndroidCalculatorDisplayView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public AndroidCalculatorDisplayView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
}
|
||||
|
||||
public AndroidCalculatorDisplayView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public void setState(@NotNull final CalculatorDisplayViewState state) {
|
||||
final CharSequence text = prepareText(state.getStringResult(), state.isValid());
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
viewStateChange = true;
|
||||
|
||||
AndroidCalculatorDisplayView.this.state = state;
|
||||
if (state.isValid()) {
|
||||
setTextColor(getResources().getColor(R.color.default_text_color));
|
||||
setText(text);
|
||||
|
||||
adjustTextSize();
|
||||
|
||||
} else {
|
||||
// update text in order to get rid of HTML tags
|
||||
setText(getText().toString());
|
||||
setTextColor(getResources().getColor(R.color.display_error_text_color));
|
||||
|
||||
// error messages are never shown -> just greyed out text (error message will be shown on click)
|
||||
//setText(state.getErrorMessage());
|
||||
//redraw();
|
||||
}
|
||||
} finally {
|
||||
viewStateChange = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CalculatorDisplayViewState getState() {
|
||||
synchronized (lock) {
|
||||
return this.state;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static CharSequence prepareText(@Nullable String text, boolean valid) {
|
||||
CharSequence result;
|
||||
|
||||
if (valid && text != null) {
|
||||
|
||||
//Log.d(this.getClass().getName(), text);
|
||||
|
||||
try {
|
||||
final TextHighlighter.Result processedText = textHighlighter.process(text);
|
||||
text = processedText.toString();
|
||||
result = Html.fromHtml(text);
|
||||
} catch (CalculatorParseException e) {
|
||||
result = text;
|
||||
}
|
||||
} else {
|
||||
result = text;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void adjustTextSize() {
|
||||
// todo serso: think where to move it (keep in mind org.solovyev.android.view.AutoResizeTextView.resetTextSize())
|
||||
setAddEllipsis(false);
|
||||
setMinTextSize(10);
|
||||
resizeText();
|
||||
}
|
||||
|
||||
public synchronized void init(@NotNull Context context) {
|
||||
if (!initialized) {
|
||||
this.setOnClickListener(new CalculatorDisplayOnClickListener(context));
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -130,10 +130,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
||||
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dialogShown) {
|
||||
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.notesppAnnounceShown, R.layout.notespp_announce, R.id.notespp_announce, context);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
|
||||
@@ -316,8 +312,8 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void donateButtonClickHandler(@NotNull View v) {
|
||||
CalculatorApplication.showDonationDialog(this);
|
||||
public void likeButtonClickHandler(@NotNull View v) {
|
||||
CalculatorApplication.likeButtonPressed(this);
|
||||
}
|
||||
|
||||
}
|
@@ -1,16 +1,10 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
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.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
@@ -25,6 +19,8 @@ import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
* Date: 12/1/11
|
||||
* Time: 1:21 PM
|
||||
*/
|
||||
/*@ReportsCrashes(formKey = "dEhDaW1nZU1qcFdsVUpiSnhON0c0ZHc6MQ",
|
||||
mode = ReportingInteractionMode.TOAST)*/
|
||||
@ReportsCrashes(formKey = "",
|
||||
mailTo = "se.solovyev+programming+calculatorpp+crashes@gmail.com",
|
||||
mode = ReportingInteractionMode.DIALOG,
|
||||
@@ -33,7 +29,15 @@ import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
resDialogText = R.string.crash_dialog_text)
|
||||
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";
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public static final String FACEBOOK_APP_URL = "http://www.facebook.com/calculatorpp";
|
||||
|
||||
public static final String AD_FREE_PRODUCT_ID = "ad_free";
|
||||
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
|
||||
@@ -43,14 +47,25 @@ public class CalculatorApplication extends android.app.Application {
|
||||
@NotNull
|
||||
private static CalculatorApplication instance;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public CalculatorApplication() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CalculatorApplication getInstance() {
|
||||
return instance;
|
||||
}
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@@ -86,11 +101,10 @@ public class CalculatorApplication extends android.app.Application {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
BillingController.registerObserver(new CalculatorBillingObserver(this));
|
||||
|
||||
// init billing controller
|
||||
BillingController.checkBillingSupported(this);
|
||||
|
||||
}
|
||||
|
||||
private void setTheme(@NotNull SharedPreferences preferences) {
|
||||
@@ -98,29 +112,6 @@ public class CalculatorApplication extends android.app.Application {
|
||||
setTheme(theme.getThemeId());
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
|
||||
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
||||
@@ -140,4 +131,20 @@ public class CalculatorApplication extends android.app.Application {
|
||||
return new CalculatorFragmentHelperImpl(layoutId, titleResId, listenersOnCreate);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
public static CalculatorApplication getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void likeButtonPressed(@NotNull final Context context) {
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(FACEBOOK_APP_URL)));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,50 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.util.Log;
|
||||
import net.robotmedia.billing.IBillingObserver;
|
||||
import net.robotmedia.billing.ResponseCode;
|
||||
import net.robotmedia.billing.model.Transaction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/10/12
|
||||
* Time: 12:27 AM
|
||||
*/
|
||||
class LoggingBillingObserver implements IBillingObserver {
|
||||
@Override
|
||||
public void onCheckBillingSupportedResponse(boolean supported) {
|
||||
Log.d("CalculatorppBilling", "onCheckBillingSupportedResponse");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseIntentOK(@NotNull String productId, @NotNull PendingIntent purchaseIntent) {
|
||||
Log.d("CalculatorppBilling", "onPurchaseIntentOK");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseIntentFailure(@NotNull String productId, @NotNull ResponseCode responseCode) {
|
||||
Log.d("CalculatorppBilling", "onPurchaseIntentFailure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseStateChanged(@NotNull String productId, @NotNull Transaction.PurchaseState state) {
|
||||
Log.d("CalculatorppBilling", "onPurchaseStateChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPurchaseResponse(@NotNull String productId, @NotNull ResponseCode response) {
|
||||
Log.d("CalculatorppBilling", "onRequestPurchaseResponse");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionsRestored() {
|
||||
Log.d("CalculatorppBilling", "onTransactionsRestored");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onErrorRestoreTransactions(@NotNull ResponseCode responseCode) {
|
||||
Log.d("CalculatorppBilling", "onErrorRestoreTransactions");
|
||||
}
|
||||
}
|
@@ -87,7 +87,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
|
||||
private Input input;
|
||||
|
||||
@NotNull
|
||||
private CalculatorEventData lastCalculatorEventData = CalculatorUtils.createFirstEventDataId();
|
||||
private final CalculatorEventHolder lastEventHolder = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
|
||||
|
||||
private int bgColor;
|
||||
|
||||
@@ -355,13 +355,12 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
|
||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable final Object data) {
|
||||
if (calculatorEventType.isOfType(CalculatorEventType.display_state_changed)) {
|
||||
if (!preparedInput.isFromInputArgs()) {
|
||||
if (calculatorEventData.isAfter(this.lastCalculatorEventData)) {
|
||||
this.lastCalculatorEventData = calculatorEventData;
|
||||
|
||||
final CalculatorEventHolder.Result result = this.lastEventHolder.apply(calculatorEventData);
|
||||
if (result.isNewAfter()) {
|
||||
this.preparedInput = prepareInputFromDisplay(((CalculatorDisplayChangeEventData) data).getNewValue(), null);
|
||||
createChart();
|
||||
|
||||
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -372,6 +371,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user