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.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.robotmedia.billing.BillingController;
import net.robotmedia.billing.IBillingObserver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils;
@ -39,9 +37,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
@NotNull
public static final String TAG = CalculatorActivity.class.getSimpleName();
@Nullable
private IBillingObserver billingObserver;
private boolean useBackAsPrev;
@NotNull
@ -52,8 +47,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
*/
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
/*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
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, 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);
firstTimeInit(preferences, this);
// init billing controller
BillingController.checkBillingSupported(this);
toggleOrientationChange(preferences);
preferences.registerOnSharedPreferenceChangeListener(this);
@ -221,12 +196,10 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
@Override
protected void onDestroy() {
if (billingObserver != null) {
BillingController.unregisterObserver(billingObserver);
}
activityHelper.onDestroy(this);
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}

View File

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

View File

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

View File

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