This commit is contained in:
Sergey Solovyev 2012-10-09 21:07:49 +04:00
parent c9bd16fa4c
commit 4fd6e94e96
4 changed files with 470 additions and 490 deletions

View File

@ -20,8 +20,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.robotmedia.billing.BillingController;
import net.robotmedia.billing.IBillingObserver;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils; import org.solovyev.android.AndroidUtils;
@ -39,9 +37,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
@NotNull @NotNull
public static final String TAG = CalculatorActivity.class.getSimpleName(); public static final String TAG = CalculatorActivity.class.getSimpleName();
@Nullable
private IBillingObserver billingObserver;
private boolean useBackAsPrev; private boolean useBackAsPrev;
@NotNull @NotNull
@ -52,8 +47,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
*/ */
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
/*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences); final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
@ -81,27 +74,9 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display"); FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard"); FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
/*if (customTitleSupported) {
try {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
additionalAdditionalTitleText.init(preferences);
preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
} catch (ClassCastException e) {
// super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
}
}*/
billingObserver = new CalculatorBillingObserver(this);
BillingController.registerObserver(billingObserver);
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences); this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
firstTimeInit(preferences, this); firstTimeInit(preferences, this);
// init billing controller
BillingController.checkBillingSupported(this);
toggleOrientationChange(preferences); toggleOrientationChange(preferences);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
@ -221,12 +196,10 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
@Override @Override
protected void onDestroy() { protected void onDestroy() {
if (billingObserver != null) {
BillingController.unregisterObserver(billingObserver);
}
activityHelper.onDestroy(this); activityHelper.onDestroy(this);
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy(); super.onDestroy();
} }

View File

@ -85,6 +85,12 @@ public class CalculatorApplication extends android.app.Application {
return CalculatorSecurity.getPK(); return CalculatorSecurity.getPK();
} }
}); });
BillingController.registerObserver(new CalculatorBillingObserver(this));
// init billing controller
BillingController.checkBillingSupported(this);
} }
private void setTheme(@NotNull SharedPreferences preferences) { private void setTheme(@NotNull SharedPreferences preferences) {

View File

@ -6,7 +6,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.content.Context;
import net.robotmedia.billing.ResponseCode; import net.robotmedia.billing.ResponseCode;
import net.robotmedia.billing.helper.AbstractBillingObserver; import net.robotmedia.billing.helper.AbstractBillingObserver;
import net.robotmedia.billing.model.Transaction; import net.robotmedia.billing.model.Transaction;
@ -19,8 +19,8 @@ import org.jetbrains.annotations.NotNull;
*/ */
public class CalculatorBillingObserver extends AbstractBillingObserver { public class CalculatorBillingObserver extends AbstractBillingObserver {
public CalculatorBillingObserver(@NotNull Activity activity) { public CalculatorBillingObserver(@NotNull Context context) {
super(activity); super(context);
} }
@Override @Override

View File

@ -52,7 +52,7 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im
BillingController.checkBillingSupported(CalculatorPreferencesActivity.this); BillingController.checkBillingSupported(CalculatorPreferencesActivity.this);
final SharedPreferences preferences = getPreferenceManager().getSharedPreferences(); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(preferences, AndroidCalculatorEngine.Preferences.roundResult.getKey()); onSharedPreferenceChanged(preferences, AndroidCalculatorEngine.Preferences.roundResult.getKey());
onSharedPreferenceChanged(preferences, VibratorContainer.Preferences.hapticFeedbackEnabled.getKey()); onSharedPreferenceChanged(preferences, VibratorContainer.Preferences.hapticFeedbackEnabled.getKey());
@ -126,6 +126,7 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im
@Override @Override
protected void onDestroy() { protected void onDestroy() {
BillingController.unregisterObserver(this); BillingController.unregisterObserver(this);
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy(); super.onDestroy();
} }