separating application. admob library added

This commit is contained in:
Sergey Solovyev 2012-01-03 17:31:17 +04:00
parent b606fa1618
commit 67a037aade
16 changed files with 163 additions and 34 deletions

View File

@ -7,6 +7,9 @@
a:versionName="1.2.23"> a:versionName="1.2.23">
<uses-permission a:name="android.permission.VIBRATE"/> <uses-permission a:name="android.permission.VIBRATE"/>
<uses-permission a:name="android.permission.INTERNET"/>
<uses-permission a:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission a:name="com.android.vending.BILLING" />
<uses-sdk a:minSdkVersion="4" <uses-sdk a:minSdkVersion="4"
a:targetSdkVersion="8"/> a:targetSdkVersion="8"/>
@ -16,6 +19,7 @@
a:name=".ApplicationContext"> a:name=".ApplicationContext">
<activity a:name=".CalculatorActivity" <activity a:name=".CalculatorActivity"
a:windowSoftInputMode="adjustPan"
a:label="@string/c_app_name"> a:label="@string/c_app_name">
<intent-filter> <intent-filter>
@ -92,5 +96,17 @@
<activity a:name=".CalculatorPlotActivity" <activity a:name=".CalculatorPlotActivity"
a:label="@string/c_plot_graph"/> a:label="@string/c_plot_graph"/>
<activity a:name="com.google.ads.AdActivity"
a:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<service a:name="net.robotmedia.billing.BillingService"/>
<receiver a:name="net.robotmedia.billing.BillingReceiver">
<intent-filter>
<action a:name="com.android.vending.billing.IN_APP_NOTIFY"/>
<action a:name="com.android.vending.billing.RESPONSE_CODE"/>
<action a:name="com.android.vending.billing.PURCHASE_STATE_CHANGED"/>
</intent-filter>
</receiver>
</application> </application>
</manifest> </manifest>

View File

@ -88,6 +88,14 @@
<systemPath>${additionalLibs}/GoogleAdMobAdsSdk-4.3.1.jar</systemPath> <systemPath>${additionalLibs}/GoogleAdMobAdsSdk-4.3.1.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>android-billing-library</groupId>
<artifactId>android-billing-library</artifactId>
<version>0.1</version>
<scope>system</scope>
<systemPath>${additionalLibs}/AndroidBillingLibrary.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>com.intellij</groupId> <groupId>com.intellij</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>

View File

@ -15,6 +15,7 @@
<LinearLayout <LinearLayout
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:id="@+id/ad_parent_view"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:orientation="vertical" a:orientation="vertical"
a:layout_gravity="center"> a:layout_gravity="center">

View File

@ -10,6 +10,7 @@
<LinearLayout <LinearLayout
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:id="@+id/ad_parent_view"
a:orientation="vertical" a:orientation="vertical"
a:layout_gravity="center"> a:layout_gravity="center">

View File

@ -15,6 +15,7 @@
<LinearLayout <LinearLayout
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:id="@+id/ad_parent_view"
a:orientation="vertical" a:orientation="vertical"
a:layout_gravity="center"> a:layout_gravity="center">

View File

@ -9,6 +9,7 @@
<LinearLayout <LinearLayout
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:id="@+id/ad_parent_view"
a:orientation="vertical" a:orientation="vertical"
a:layout_gravity="center"> a:layout_gravity="center">

View File

@ -164,5 +164,7 @@
<string name="c_calc_use_back_button_as_prev_title">Использовать кнопку назад как назад по истории</string> <string name="c_calc_use_back_button_as_prev_title">Использовать кнопку назад как назад по истории</string>
<string name="c_warning">Внимание</string> <string name="c_warning">Внимание</string>
<string name="c_error">Ошибка</string>
<string name="c_billing_error">Биллинг не поддерживается!</string>
</resources> </resources>

View File

@ -58,4 +58,7 @@
<string name="p_calc_haptic_feedback_duration_key">org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key</string> <string name="p_calc_haptic_feedback_duration_key">org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key</string>
<string name="p_calc_haptic_feedback_duration">" "</string> <string name="p_calc_haptic_feedback_duration">" "</string>
<string name="p_calc_ad_free_key">org.solovyev.android.calculator_ad_free_application</string>
<string name="p_calc_ad_free">false</string>
</resources> </resources>

View File

@ -164,5 +164,7 @@
<string name="c_calc_use_back_button_as_prev_title">Use Back button as history prev</string> <string name="c_calc_use_back_button_as_prev_title">Use Back button as history prev</string>
<string name="c_warning">Warning</string> <string name="c_warning">Warning</string>
<string name="c_error">Error</string>
<string name="c_billing_error">Billing is not supported!</string>
</resources> </resources>

View File

@ -2,6 +2,14 @@
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:range="http://schemas.android.com/apk/res/org.solovyev.android.calculator"> xmlns:range="http://schemas.android.com/apk/res/org.solovyev.android.calculator">
<!-- <SwitchPreference
a:key="@string/p_calc_round_result_key"
a:summary="@string/c_calc_round_result_summary"
a:title="@string/c_calc_round_result_title"
a:defaultValue="false"
/>-->
<PreferenceCategory a:title="@string/c_prefs_calculations_category"> <PreferenceCategory a:title="@string/c_prefs_calculations_category">
<android.preference.CheckBoxPreference <android.preference.CheckBoxPreference

View File

@ -15,6 +15,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.TextView; import android.widget.TextView;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@ -24,38 +27,38 @@ import org.jetbrains.annotations.NotNull;
*/ */
public final class AndroidUtils { public final class AndroidUtils {
// not intended for instantiation // not intended for instantiation
private AndroidUtils() { private AndroidUtils() {
throw new AssertionError(); throw new AssertionError();
} }
public static void centerAndWrapTabsFor(@NotNull TabHost tabHost) { public static void centerAndWrapTabsFor(@NotNull TabHost tabHost) {
int tabCount = tabHost.getTabWidget().getTabCount(); int tabCount = tabHost.getTabWidget().getTabCount();
for (int i = 0; i < tabCount; i++) { for (int i = 0; i < tabCount; i++) {
final View view = tabHost.getTabWidget().getChildTabViewAt(i); final View view = tabHost.getTabWidget().getChildTabViewAt(i);
if ( view != null ) { if (view != null) {
if (view.getLayoutParams().height > 0) { if (view.getLayoutParams().height > 0) {
// reduce height of the tab // reduce height of the tab
view.getLayoutParams().height *= 0.8; view.getLayoutParams().height *= 0.8;
} }
// get title text view // get title text view
final View textView = view.findViewById(android.R.id.title); final View textView = view.findViewById(android.R.id.title);
if ( textView instanceof TextView) { if (textView instanceof TextView) {
// just in case check the type // just in case check the type
// center text // center text
((TextView) textView).setGravity(Gravity.CENTER); ((TextView) textView).setGravity(Gravity.CENTER);
// wrap text // wrap text
((TextView) textView).setSingleLine(false); ((TextView) textView).setSingleLine(false);
// explicitly set layout parameters // explicitly set layout parameters
textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT; textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
} }
} }
} }
} }
public static void addTab(@NotNull Context context, public static void addTab(@NotNull Context context,
@NotNull TabHost tabHost, @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. * @param appPackageName - full name of the package of an app, 'com.example.app' for example.
* @return version number we are currently in * @return version number we are currently in
*/ */
@ -88,5 +91,23 @@ public final class AndroidUtils {
return -1; 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 its 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;
}
} }

View File

@ -1,5 +1,6 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import net.robotmedia.billing.BillingController;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@ -9,15 +10,36 @@ import org.jetbrains.annotations.NotNull;
*/ */
public class ApplicationContext extends android.app.Application { public class ApplicationContext extends android.app.Application {
@NotNull public static final String AD_FREE_APPLICATION = "ad_free_application";
private static ApplicationContext instance; 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; instance = this;
} }
@NotNull @NotNull
public static ApplicationContext getInstance() { public static ApplicationContext getInstance() {
return instance; 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";
}
});*/
}
} }

View File

@ -23,6 +23,7 @@ import android.view.*;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import com.google.ads.AdView;
import jscl.AngleUnit; import jscl.AngleUnit;
import jscl.NumeralBase; import jscl.NumeralBase;
import org.jetbrains.annotations.NotNull; 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.IntegerPreference;
import org.solovyev.android.view.prefs.Preference; import org.solovyev.android.view.prefs.Preference;
import org.solovyev.android.view.widgets.*; import org.solovyev.android.view.widgets.*;
import org.solovyev.android.view.widgets.DragEvent;
import org.solovyev.common.utils.Announcer; import org.solovyev.common.utils.Announcer;
import org.solovyev.common.utils.Point2d; import org.solovyev.common.utils.Point2d;
import org.solovyev.common.utils.StringUtils; import org.solovyev.common.utils.StringUtils;
@ -50,6 +52,7 @@ import java.util.Map;
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
private static final int HVGA_WIDTH_PIXELS = 320; private static final int HVGA_WIDTH_PIXELS = 320;
public static final String ADMOB_USER_ID = "a14f02cf9c80cbc";
public static class Preferences { public static class Preferences {
@NotNull @NotNull
@ -85,6 +88,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
private boolean useBackAsPrev = USE_BACK_AS_PREV_DEFAULT; private boolean useBackAsPrev = USE_BACK_AS_PREV_DEFAULT;
@Nullable
private AdView adView;
/** /**
* Called when the activity is first created. * Called when the activity is first created.
*/ */
@ -101,6 +107,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setLayout(preferences); setLayout(preferences);
//adView = AndroidUtils.createAndInflateAdView(this, R.id.ad_parent_view, ADMOB_USER_ID);
if (customTitleSupported) { if (customTitleSupported) {
try { try {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
@ -617,6 +625,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@Override @Override
protected void onDestroy() { protected void onDestroy() {
if ( adView != null ) {
adView.destroy();
}
super.onDestroy(); super.onDestroy();
} }

View File

@ -5,9 +5,12 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.AlertDialog;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import net.robotmedia.billing.BillingController;
import org.solovyev.android.calculator.model.CalculatorEngine; import org.solovyev.android.calculator.model.CalculatorEngine;
import org.solovyev.android.view.widgets.VibratorContainer; import org.solovyev.android.view.widgets.VibratorContainer;
@ -24,13 +27,42 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements
addPreferencesFromResource(R.xml.main_preferences); 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(); final SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(preferences, CalculatorEngine.Preferences.roundResult.getKey()); onSharedPreferenceChanged(preferences, CalculatorEngine.Preferences.roundResult.getKey());
onSharedPreferenceChanged(preferences, VibratorContainer.HAPTIC_FEEDBACK_P_KEY); onSharedPreferenceChanged(preferences, VibratorContainer.HAPTIC_FEEDBACK_P_KEY);
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (CalculatorEngine.Preferences.roundResult.getKey().equals(key)) { if (CalculatorEngine.Preferences.roundResult.getKey().equals(key)) {
findPreference(CalculatorEngine.Preferences.roundResult.getKey()).setEnabled(preferences.getBoolean(key, CalculatorEngine.Preferences.roundResult.getDefaultValue())); findPreference(CalculatorEngine.Preferences.roundResult.getKey()).setEnabled(preferences.getBoolean(key, CalculatorEngine.Preferences.roundResult.getDefaultValue()));