messages + billing
This commit is contained in:
@@ -87,15 +87,17 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
||||
|
||||
@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;
|
||||
|
||||
final CharSequence text = prepareText(state.getStringResult(), state.isValid());
|
||||
|
||||
AndroidCalculatorDisplayView.this.state = state;
|
||||
if (state.isValid()) {
|
||||
setTextColor(getResources().getColor(R.color.default_text_color));
|
||||
|
@@ -1,158 +1,159 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
import net.robotmedia.billing.helper.DefaultBillingObserver;
|
||||
import net.robotmedia.billing.model.BillingDB;
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* 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,
|
||||
resToastText = R.string.crashed,
|
||||
resDialogTitle = R.string.crash_dialog_title,
|
||||
resDialogText = R.string.crash_dialog_text)
|
||||
public class CalculatorApplication extends android.app.Application {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* 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";
|
||||
|
||||
public static final String ADMOB_USER_ID = "a14f02cf9c80cbc";
|
||||
|
||||
@NotNull
|
||||
private static CalculatorApplication instance;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public CalculatorApplication() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
ACRA.init(this);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
CalculatorPreferences.setDefaultValues(preferences);
|
||||
|
||||
setTheme(preferences);
|
||||
|
||||
super.onCreate();
|
||||
|
||||
final AndroidCalculator calculator = new AndroidCalculator();
|
||||
|
||||
CalculatorLocatorImpl.getInstance().init(calculator,
|
||||
new AndroidCalculatorEngine(this),
|
||||
new AndroidCalculatorClipboard(this),
|
||||
new AndroidCalculatorNotifier(this),
|
||||
new AndroidCalculatorHistory(this, calculator));
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
||||
|
||||
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
||||
|
||||
@Override
|
||||
public byte[] getObfuscationSalt() {
|
||||
return new byte[]{81, -114, 32, -127, -32, -104, -40, -15, -47, 57, -13, -41, -33, 67, -114, 7, -11, 53, 126, 82};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPublicKey() {
|
||||
return CalculatorSecurity.getPK();
|
||||
}
|
||||
});
|
||||
|
||||
BillingController.registerObserver(new DefaultBillingObserver(this, null));
|
||||
|
||||
// init billing controller
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BillingDB.init(CalculatorApplication.this);
|
||||
BillingController.checkBillingSupported(CalculatorApplication.this);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void setTheme(@NotNull SharedPreferences preferences) {
|
||||
final CalculatorPreferences.Gui.Theme theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||
setTheme(theme.getThemeId());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
|
||||
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorFragmentHelper createFragmentHelper(int layoutId) {
|
||||
return new CalculatorFragmentHelperImpl(layoutId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorFragmentHelper createFragmentHelper(int layoutId, int titleResId) {
|
||||
return new CalculatorFragmentHelperImpl(layoutId, titleResId);
|
||||
}
|
||||
@NotNull
|
||||
public CalculatorFragmentHelper createFragmentHelper(int layoutId, int titleResId, boolean listenersOnCreate) {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
import net.robotmedia.billing.helper.DefaultBillingObserver;
|
||||
import net.robotmedia.billing.model.BillingDB;
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* 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,
|
||||
resToastText = R.string.crashed,
|
||||
resDialogTitle = R.string.crash_dialog_title,
|
||||
resDialogText = R.string.crash_dialog_text)
|
||||
public class CalculatorApplication extends android.app.Application {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* 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";
|
||||
|
||||
public static final String ADMOB_USER_ID = "a14f02cf9c80cbc";
|
||||
|
||||
@NotNull
|
||||
private static CalculatorApplication instance;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public CalculatorApplication() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
ACRA.init(this);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
CalculatorPreferences.setDefaultValues(preferences);
|
||||
|
||||
setTheme(preferences);
|
||||
|
||||
super.onCreate();
|
||||
|
||||
final AndroidCalculator calculator = new AndroidCalculator();
|
||||
|
||||
CalculatorLocatorImpl.getInstance().init(calculator,
|
||||
new AndroidCalculatorEngine(this),
|
||||
new AndroidCalculatorClipboard(this),
|
||||
new AndroidCalculatorNotifier(this),
|
||||
new AndroidCalculatorHistory(this, calculator));
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
||||
|
||||
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
||||
|
||||
@Override
|
||||
public byte[] getObfuscationSalt() {
|
||||
return new byte[]{81, -114, 32, -127, -32, -104, -40, -15, -47, 57, -13, -41, -33, 67, -114, 7, -11, 53, 126, 82};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPublicKey() {
|
||||
return CalculatorSecurity.getPK();
|
||||
}
|
||||
});
|
||||
|
||||
BillingController.registerObserver(new DefaultBillingObserver(this, null));
|
||||
|
||||
// init billing controller
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BillingDB.init(CalculatorApplication.this);
|
||||
BillingController.checkBillingSupported(CalculatorApplication.this);
|
||||
AdsController.getInstance().isAdFree(CalculatorApplication.this);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void setTheme(@NotNull SharedPreferences preferences) {
|
||||
final CalculatorPreferences.Gui.Theme theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||
setTheme(theme.getThemeId());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
|
||||
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorFragmentHelper createFragmentHelper(int layoutId) {
|
||||
return new CalculatorFragmentHelperImpl(layoutId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorFragmentHelper createFragmentHelper(int layoutId, int titleResId) {
|
||||
return new CalculatorFragmentHelperImpl(layoutId, titleResId);
|
||||
}
|
||||
@NotNull
|
||||
public CalculatorFragmentHelper createFragmentHelper(int layoutId, int titleResId, boolean listenersOnCreate) {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user