android_calculator-56: Billing doesn't work if internet was off on the start of application
This commit is contained in:
parent
20392b00ad
commit
c005610cb5
13
res/layout/admob_pref.xml
Normal file
13
res/layout/admob_pref.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2009-2012. Created by serso aka se.solovyev.
|
||||||
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
|
~ or visit http://se.solovyev.org
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" android:orientation="vertical">
|
||||||
|
</LinearLayout>
|
@ -6,11 +6,16 @@
|
|||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:id="@+id/ad_parent_view"
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
a:text="@string/c_faq_content"
|
a:text="@string/c_faq_content"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
@ -20,5 +25,7 @@
|
|||||||
a:scrollbars="vertical"
|
a:scrollbars="vertical"
|
||||||
style="@style/about_style"/>
|
style="@style/about_style"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:id="@+id/ad_parent_view"
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:text="@string/c_hints_content"
|
a:text="@string/c_hints_content"
|
||||||
@ -16,5 +22,6 @@
|
|||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:scrollbars="vertical"
|
a:scrollbars="vertical"
|
||||||
style="@style/about_style"/>
|
style="@style/about_style"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
@ -9,6 +9,12 @@
|
|||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:id="@+id/ad_parent_view"
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:text="@string/c_screens_content"
|
a:text="@string/c_screens_content"
|
||||||
@ -17,4 +23,6 @@
|
|||||||
a:scrollbars="vertical"
|
a:scrollbars="vertical"
|
||||||
style="@style/about_style"/>
|
style="@style/about_style"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
@ -12,6 +12,10 @@
|
|||||||
|
|
||||||
<PreferenceCategory a:title="@string/c_prefs_calculations_category">
|
<PreferenceCategory a:title="@string/c_prefs_calculations_category">
|
||||||
|
|
||||||
|
<org.solovyev.android.view.prefs.AdViewPreference
|
||||||
|
a:key="admob_01"
|
||||||
|
a:layout="@layout/admob_pref"/>
|
||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
<android.preference.CheckBoxPreference
|
||||||
a:key="@string/p_calc_round_result_key"
|
a:key="@string/p_calc_round_result_key"
|
||||||
a:summary="@string/c_calc_round_result_summary"
|
a:summary="@string/c_calc_round_result_summary"
|
||||||
@ -54,6 +58,10 @@
|
|||||||
|
|
||||||
<PreferenceCategory a:title="@string/c_prefs_appearance_category">
|
<PreferenceCategory a:title="@string/c_prefs_appearance_category">
|
||||||
|
|
||||||
|
<org.solovyev.android.view.prefs.AdViewPreference
|
||||||
|
a:key="admob_02"
|
||||||
|
a:layout="@layout/admob_pref"/>
|
||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
<android.preference.CheckBoxPreference
|
||||||
a:key="@string/p_calc_color_display_key"
|
a:key="@string/p_calc_color_display_key"
|
||||||
a:summary="@string/c_calc_color_display_summary"
|
a:summary="@string/c_calc_color_display_summary"
|
||||||
|
@ -129,13 +129,14 @@ public final class AndroidUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static AdView createAndInflateAdView(@NotNull Activity activity,
|
public static AdView createAndInflateAdView(@NotNull Activity activity,
|
||||||
@NotNull String admobAccountId,
|
@NotNull String admobAccountId,
|
||||||
|
@Nullable ViewGroup parentView,
|
||||||
int layoutId,
|
int layoutId,
|
||||||
@NotNull List<String> keywords) {
|
@NotNull List<String> keywords) {
|
||||||
|
final ViewGroup layout = parentView != null ? parentView : (ViewGroup) activity.findViewById(layoutId);
|
||||||
|
|
||||||
// Create the adView
|
// Create the adView
|
||||||
final AdView adView = new AdView(activity, AdSize.BANNER, admobAccountId);
|
final AdView adView = new AdView(activity, AdSize.BANNER, admobAccountId);
|
||||||
|
|
||||||
final ViewGroup layout = (ViewGroup) activity.findViewById(layoutId);
|
|
||||||
|
|
||||||
// Add the adView to it
|
// Add the adView to it
|
||||||
layout.addView(adView);
|
layout.addView(adView);
|
||||||
|
|
||||||
@ -184,5 +185,23 @@ public final class AndroidUtils {
|
|||||||
void process(@NotNull V view);
|
void process(@NotNull V view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void restartActivity(@NotNull Activity activity) {
|
||||||
|
final Intent intent = activity.getIntent();
|
||||||
|
/*
|
||||||
|
for compatibility with android_1.6_compatibility
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);*/
|
||||||
|
|
||||||
|
Log.d(activity.getClass().getName(), "Finishing current activity!");
|
||||||
|
activity.finish();
|
||||||
|
|
||||||
|
/*
|
||||||
|
for compatibility with android_1.6_compatibility
|
||||||
|
|
||||||
|
overridePendingTransition(0, 0);*/
|
||||||
|
Log.d(activity.getClass().getName(), "Starting new activity!");
|
||||||
|
activity.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,24 +599,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio);
|
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restart() {
|
|
||||||
final Intent intent = getIntent();
|
|
||||||
/*
|
|
||||||
for compatibility with android_1.6_compatibility
|
|
||||||
overridePendingTransition(0, 0);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);*/
|
|
||||||
|
|
||||||
Log.d(this.getClass().getName(), "Finishing current activity!");
|
|
||||||
finish();
|
|
||||||
|
|
||||||
/*
|
|
||||||
for compatibility with android_1.6_compatibility
|
|
||||||
|
|
||||||
overridePendingTransition(0, 0);*/
|
|
||||||
Log.d(this.getClass().getName(), "Starting new activity!");
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@ -626,7 +608,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
final String newLayoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout));
|
final String newLayoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout));
|
||||||
final String newThemeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme));
|
final String newThemeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme));
|
||||||
if (!themeName.equals(newThemeName) || !layoutName.equals(newLayoutName)) {
|
if (!themeName.equals(newThemeName) || !layoutName.equals(newLayoutName)) {
|
||||||
restart();
|
AndroidUtils.restartActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
|
calculatorModel = CalculatorModel.instance.init(this, preferences, CalculatorEngine.instance);
|
||||||
|
@ -3,6 +3,7 @@ package org.solovyev.android.calculator;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import com.google.ads.AdView;
|
import com.google.ads.AdView;
|
||||||
import net.robotmedia.billing.BillingController;
|
import net.robotmedia.billing.BillingController;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -60,16 +61,16 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static AdView inflateAd(@NotNull Activity activity) {
|
public static AdView inflateAd(@NotNull Activity activity) {
|
||||||
return inflateAd(activity, R.id.ad_parent_view);
|
return inflateAd(activity, null, R.id.ad_parent_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static AdView inflateAd(@NotNull Activity activity, int parentViewId) {
|
public static AdView inflateAd(@NotNull Activity activity, @Nullable ViewGroup parentView, int parentViewId) {
|
||||||
AdView result = null;
|
AdView result = null;
|
||||||
if ( !isAdFree(activity) ) {
|
if ( !isAdFree(activity) ) {
|
||||||
Log.d(activity.getClass().getName(), "Application is not ad free - inflating ad!");
|
Log.d(activity.getClass().getName(), "Application is not ad free - inflating ad!");
|
||||||
final List<String> keywords = Collections.emptyList();
|
final List<String> keywords = Collections.emptyList();
|
||||||
result = AndroidUtils.createAndInflateAdView(activity, ADMOB_USER_ID, parentViewId, keywords);
|
result = AndroidUtils.createAndInflateAdView(activity, ADMOB_USER_ID, parentView, parentViewId, keywords);
|
||||||
} else {
|
} else {
|
||||||
Log.d(activity.getClass().getName(), "Application is ad free - no ads!");
|
Log.d(activity.getClass().getName(), "Application is ad free - no ads!");
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import net.robotmedia.billing.BillingController;
|
|||||||
import net.robotmedia.billing.BillingRequest;
|
import net.robotmedia.billing.BillingRequest;
|
||||||
import net.robotmedia.billing.IBillingObserver;
|
import net.robotmedia.billing.IBillingObserver;
|
||||||
import net.robotmedia.billing.model.Transaction;
|
import net.robotmedia.billing.model.Transaction;
|
||||||
|
import org.solovyev.android.AndroidUtils;
|
||||||
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;
|
||||||
|
|
||||||
@ -135,17 +136,19 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void onPurchaseStateChanged(String itemId, Transaction.PurchaseState state) {
|
public void onPurchaseStateChanged(String itemId, Transaction.PurchaseState state) {
|
||||||
if (CalculatorApplication.AD_FREE_PRODUCT_ID.equals(itemId)) {
|
if (CalculatorApplication.AD_FREE_PRODUCT_ID.equals(itemId)) {
|
||||||
final Preference addFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||||
if (addFreePreference != null) {
|
if (adFreePreference != null) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case PURCHASED:
|
case PURCHASED:
|
||||||
addFreePreference.setEnabled(false);
|
adFreePreference.setEnabled(false);
|
||||||
|
// restart activity to disable ads
|
||||||
|
AndroidUtils.restartActivity(this);
|
||||||
break;
|
break;
|
||||||
case CANCELLED:
|
case CANCELLED:
|
||||||
addFreePreference.setEnabled(true);
|
adFreePreference.setEnabled(true);
|
||||||
break;
|
break;
|
||||||
case REFUNDED:
|
case REFUNDED:
|
||||||
addFreePreference.setEnabled(true);
|
adFreePreference.setEnabled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,6 +10,7 @@ import android.app.Activity;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.google.ads.AdView;
|
import com.google.ads.AdView;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -34,7 +35,7 @@ public class AbstractHelpActivity extends Activity {
|
|||||||
setContentView(layoutId);
|
setContentView(layoutId);
|
||||||
|
|
||||||
// do not inflate ad in help (as some problems were encountered dut to ScrollView - no space for ad banner)
|
// do not inflate ad in help (as some problems were encountered dut to ScrollView - no space for ad banner)
|
||||||
//adView = CalculatorApplication.inflateAd(this);
|
adView = CalculatorApplication.inflateAd(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2012. Created by serso aka se.solovyev.
|
||||||
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
|
* or visit http://se.solovyev.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.solovyev.android.view.prefs;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import com.google.ads.AdView;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 1/14/12
|
||||||
|
* Time: 6:47 PM
|
||||||
|
*/
|
||||||
|
public class AdViewPreference extends android.preference.Preference {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private AdView adView;
|
||||||
|
|
||||||
|
public AdViewPreference(Context context) {
|
||||||
|
super(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdViewPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View onCreateView(ViewGroup parent) {
|
||||||
|
// this will create the linear layout defined in ads_layout.xml
|
||||||
|
View view = super.onCreateView(parent);
|
||||||
|
|
||||||
|
if (view instanceof ViewGroup) {
|
||||||
|
adView = CalculatorApplication.inflateAd((Activity) getContext(), ((ViewGroup) view), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user