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">
<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"
a:targetSdkVersion="8"/>
@ -16,6 +19,7 @@
a:name=".ApplicationContext">
<activity a:name=".CalculatorActivity"
a:windowSoftInputMode="adjustPan"
a:label="@string/c_app_name">
<intent-filter>
@ -92,5 +96,17 @@
<activity a:name=".CalculatorPlotActivity"
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>
</manifest>

View File

@ -88,6 +88,14 @@
<systemPath>${additionalLibs}/GoogleAdMobAdsSdk-4.3.1.jar</systemPath>
</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>
<groupId>com.intellij</groupId>
<artifactId>annotations</artifactId>

View File

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

View File

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

View File

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

View File

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

View File

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

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_warning">Warning</string>
<string name="c_error">Error</string>
<string name="c_billing_error">Billing is not supported!</string>
</resources>

View File

@ -2,6 +2,14 @@
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android"
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">
<android.preference.CheckBoxPreference

View File

@ -15,6 +15,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TextView;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull;
/**
@ -33,7 +36,7 @@ public final class AndroidUtils {
int tabCount = tabHost.getTabWidget().getTabCount();
for (int i = 0; i < tabCount; i++) {
final View view = tabHost.getTabWidget().getChildTabViewAt(i);
if ( view != null ) {
if (view != null) {
if (view.getLayoutParams().height > 0) {
// reduce height of the tab
view.getLayoutParams().height *= 0.8;
@ -41,7 +44,7 @@ public final class AndroidUtils {
// get title text view
final View textView = view.findViewById(android.R.id.title);
if ( textView instanceof TextView) {
if (textView instanceof TextView) {
// just in case check the type
// center text
@ -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 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;
import net.robotmedia.billing.BillingController;
import org.jetbrains.annotations.NotNull;
/**
@ -9,6 +10,9 @@ import org.jetbrains.annotations.NotNull;
*/
public class ApplicationContext extends android.app.Application {
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";
@NotNull
private static ApplicationContext instance;
@ -20,4 +24,22 @@ public class ApplicationContext extends android.app.Application {
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";
}
});*/
}
}

View File

@ -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();
}

View File

@ -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,6 +27,35 @@ 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());