separating application. admob library added
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -24,38 +27,38 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public final class AndroidUtils {
|
||||
|
||||
// not intended for instantiation
|
||||
private AndroidUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
// not intended for instantiation
|
||||
private AndroidUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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";
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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()));
|
||||
|
Reference in New Issue
Block a user