diff --git a/AndroidManifest.xml b/AndroidManifest.xml index d80ff689..d52a6a15 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -7,6 +7,9 @@ a:versionName="1.2.23"> + + + @@ -16,6 +19,7 @@ a:name=".ApplicationContext"> @@ -92,5 +96,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8f971170..603af87e 100644 --- a/pom.xml +++ b/pom.xml @@ -88,6 +88,14 @@ ${additionalLibs}/GoogleAdMobAdsSdk-4.3.1.jar + + android-billing-library + android-billing-library + 0.1 + system + ${additionalLibs}/AndroidBillingLibrary.jar + + com.intellij annotations diff --git a/res/layout-land/main_calculator.xml b/res/layout-land/main_calculator.xml index bacab745..9a81dc59 100644 --- a/res/layout-land/main_calculator.xml +++ b/res/layout-land/main_calculator.xml @@ -15,6 +15,7 @@ diff --git a/res/layout-land/main_cellphone.xml b/res/layout-land/main_cellphone.xml index 239fb97b..fd84a51b 100644 --- a/res/layout-land/main_cellphone.xml +++ b/res/layout-land/main_cellphone.xml @@ -10,6 +10,7 @@ diff --git a/res/layout-port/main_calculator.xml b/res/layout-port/main_calculator.xml index aa51b1d6..4776a3bb 100644 --- a/res/layout-port/main_calculator.xml +++ b/res/layout-port/main_calculator.xml @@ -15,6 +15,7 @@ diff --git a/res/layout-port/main_cellphone.xml b/res/layout-port/main_cellphone.xml index 2f2fd2c4..cdea70f1 100644 --- a/res/layout-port/main_cellphone.xml +++ b/res/layout-port/main_cellphone.xml @@ -9,6 +9,7 @@ diff --git a/res/values-ru/text_strings.xml b/res/values-ru/text_strings.xml index d0d9c85a..d425bc56 100644 --- a/res/values-ru/text_strings.xml +++ b/res/values-ru/text_strings.xml @@ -164,5 +164,7 @@ Использовать кнопку назад как назад по истории Внимание + Ошибка + Биллинг не поддерживается! \ No newline at end of file diff --git a/res/values/default_values.xml b/res/values/default_values.xml index afb1d38c..1ceed36f 100644 --- a/res/values/default_values.xml +++ b/res/values/default_values.xml @@ -58,4 +58,7 @@ org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key " " + org.solovyev.android.calculator_ad_free_application + false + \ No newline at end of file diff --git a/res/values/text_strings.xml b/res/values/text_strings.xml index 0af0ee85..74b1e29f 100644 --- a/res/values/text_strings.xml +++ b/res/values/text_strings.xml @@ -164,5 +164,7 @@ Use Back button as history prev Warning + Error + Billing is not supported! \ No newline at end of file diff --git a/res/xml/main_preferences.xml b/res/xml/main_preferences.xml index c730f26f..c3bd8ca8 100644 --- a/res/xml/main_preferences.xml +++ b/res/xml/main_preferences.xml @@ -2,6 +2,14 @@ + + + 0) { - // reduce height of the tab - view.getLayoutParams().height *= 0.8; - } + public static void centerAndWrapTabsFor(@NotNull TabHost tabHost) { + int tabCount = tabHost.getTabWidget().getTabCount(); + for (int i = 0; i < tabCount; i++) { + final View view = tabHost.getTabWidget().getChildTabViewAt(i); + if (view != null) { + if (view.getLayoutParams().height > 0) { + // reduce height of the tab + view.getLayoutParams().height *= 0.8; + } - // get title text view - final View textView = view.findViewById(android.R.id.title); - if ( textView instanceof TextView) { - // just in case check the type + // get title text view + final View textView = view.findViewById(android.R.id.title); + if (textView instanceof TextView) { + // just in case check the type - // center text - ((TextView) textView).setGravity(Gravity.CENTER); - // wrap text - ((TextView) textView).setSingleLine(false); + // center text + ((TextView) textView).setGravity(Gravity.CENTER); + // wrap text + ((TextView) textView).setSingleLine(false); - // explicitly set layout parameters - textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT; - textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; - } - } - } - } + // explicitly set layout parameters + textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT; + textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; + } + } + } + } public static void addTab(@NotNull Context context, @NotNull TabHost tabHost, @@ -75,7 +78,7 @@ public final class AndroidUtils { /** - * @param context context + * @param context context * @param appPackageName - full name of the package of an app, 'com.example.app' for example. * @return version number we are currently in */ @@ -88,5 +91,23 @@ public final class AndroidUtils { return -1; } + @NotNull + public static AdView createAndInflateAdView(@NotNull Activity activity, int layoutId, String admobAccountId) { + // Create the adView + final AdView adView = new AdView(activity, AdSize.BANNER, admobAccountId); + + // Lookup your LinearLayout assuming it’s been given + // the attribute android:id="@+id/mainLayout" + final ViewGroup layout = (ViewGroup) activity.findViewById(layoutId); + + // Add the adView to it + layout.addView(adView); + + // Initiate a generic request to load it with an ad + adView.loadAd(new AdRequest()); + + return adView; + } + } diff --git a/src/main/java/org/solovyev/android/calculator/ApplicationContext.java b/src/main/java/org/solovyev/android/calculator/ApplicationContext.java index 2d440493..24dc38c3 100644 --- a/src/main/java/org/solovyev/android/calculator/ApplicationContext.java +++ b/src/main/java/org/solovyev/android/calculator/ApplicationContext.java @@ -1,5 +1,6 @@ package org.solovyev.android.calculator; +import net.robotmedia.billing.BillingController; import org.jetbrains.annotations.NotNull; /** @@ -9,15 +10,36 @@ import org.jetbrains.annotations.NotNull; */ public class ApplicationContext extends android.app.Application { - @NotNull - private static ApplicationContext instance; + public static final String AD_FREE_APPLICATION = "ad_free_application"; + public static final String AD_FREE_APPLICATION_P_KEY = "org.solovyev.android.calculator_ad_free_application"; - public ApplicationContext() { + @NotNull + private static ApplicationContext instance; + + public ApplicationContext() { instance = this; - } + } @NotNull public static ApplicationContext getInstance() { return instance; } + + @Override + public void onCreate() { + super.onCreate(); + /*BillingController.setDebug(true); + BillingController.setConfiguration(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 "org.solovyev.android.calculator"; + } + });*/ + } } diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index c3ce2267..bb373b44 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -23,6 +23,7 @@ import android.view.*; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; +import com.google.ads.AdView; import jscl.AngleUnit; import jscl.NumeralBase; import org.jetbrains.annotations.NotNull; @@ -38,6 +39,7 @@ import org.solovyev.android.view.FontSizeAdjuster; import org.solovyev.android.view.prefs.IntegerPreference; import org.solovyev.android.view.prefs.Preference; import org.solovyev.android.view.widgets.*; +import org.solovyev.android.view.widgets.DragEvent; import org.solovyev.common.utils.Announcer; import org.solovyev.common.utils.Point2d; import org.solovyev.common.utils.StringUtils; @@ -50,6 +52,7 @@ import java.util.Map; public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { private static final int HVGA_WIDTH_PIXELS = 320; + public static final String ADMOB_USER_ID = "a14f02cf9c80cbc"; public static class Preferences { @NotNull @@ -85,6 +88,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private boolean useBackAsPrev = USE_BACK_AS_PREV_DEFAULT; + @Nullable + private AdView adView; + /** * Called when the activity is first created. */ @@ -101,6 +107,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh super.onCreate(savedInstanceState); setLayout(preferences); + //adView = AndroidUtils.createAndInflateAdView(this, R.id.ad_parent_view, ADMOB_USER_ID); + if (customTitleSupported) { try { getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title); @@ -617,6 +625,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh @Override protected void onDestroy() { + if ( adView != null ) { + adView.destroy(); + } super.onDestroy(); } diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java index 41a022c2..210d5a0a 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java @@ -5,9 +5,12 @@ package org.solovyev.android.calculator; +import android.app.AlertDialog; import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.Preference; import android.preference.PreferenceActivity; +import net.robotmedia.billing.BillingController; import org.solovyev.android.calculator.model.CalculatorEngine; import org.solovyev.android.view.widgets.VibratorContainer; @@ -24,13 +27,42 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements addPreferencesFromResource(R.xml.main_preferences); + /*final Preference buyPref = findPreference(ApplicationContext.AD_FREE_APPLICATION_P_KEY); + buyPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + // при нажатии на кнопку Убрать рекламу в настройках + public boolean onPreferenceClick(Preference preference) { + // проверяем поддерживается ли покупка в приложениях + if (BillingController.checkBillingSupported(CalculatorPreferencesActivity.this) != BillingController.BillingStatus.SUPPORTED) { + // показываем сообщение, что покупка не поддерживается + new AlertDialog.Builder(CalculatorPreferencesActivity.this).setTitle(R.string.c_error).setMessage(R.string.c_billing_error).create().show(); + } else { + // проверяем не купил ли пользователь уже нашу опцию + boolean purchased = BillingController.isPurchased(getApplicationContext(), ApplicationContext.AD_FREE_APPLICATION); + if (!purchased) { + // если не купил (или мы просто об этом пока не знаем? пользователь удалял + // приложение со всем данными?), то пытаемся восстановить транзакции + BillingController.restoreTransactions(CalculatorPreferencesActivity.this); + // следующая строка (проверка еще раз не купил ли пользователь приложение) - + // не очень правильный подход - вызвав restoreTransactions, + // ответ мы получим не сразу + purchased = BillingController.isPurchased(getApplicationContext(), ApplicationContext.AD_FREE_APPLICATION); + if (!purchased) { + // наконец, показываем пользователю стандартное окно для покупки опции + BillingController.requestPurchase(CalculatorPreferencesActivity.this, ApplicationContext.AD_FREE_APPLICATION); + } + } + } + return true; + } + });*/ + final SharedPreferences preferences = getPreferenceManager().getSharedPreferences(); preferences.registerOnSharedPreferenceChangeListener(this); onSharedPreferenceChanged(preferences, CalculatorEngine.Preferences.roundResult.getKey()); onSharedPreferenceChanged(preferences, VibratorContainer.HAPTIC_FEEDBACK_P_KEY); } - @Override + @Override public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { if (CalculatorEngine.Preferences.roundResult.getKey().equals(key)) { findPreference(CalculatorEngine.Preferences.roundResult.getKey()).setEnabled(preferences.getBoolean(key, CalculatorEngine.Preferences.roundResult.getDefaultValue())); diff --git a/src/misc/doc/GoogleAdMobAdsSdk-4.3.1.jar b/src/misc/doc/GoogleAdMobAdsSdk-4.3.1-javadocs.zip similarity index 100% rename from src/misc/doc/GoogleAdMobAdsSdk-4.3.1.jar rename to src/misc/doc/GoogleAdMobAdsSdk-4.3.1-javadocs.zip diff --git a/src/misc/src/achartengine-0.7.0-javadocs.zip b/src/misc/doc/achartengine-0.7.0-javadocs.zip similarity index 100% rename from src/misc/src/achartengine-0.7.0-javadocs.zip rename to src/misc/doc/achartengine-0.7.0-javadocs.zip