Purchase dialog
This commit is contained in:
@@ -24,6 +24,7 @@ import org.solovyev.android.calculator.math.edit.*;
|
||||
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
import org.solovyev.android.calculator.preferences.CalculatorPreferencesActivity;
|
||||
import org.solovyev.common.msg.Message;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
@@ -97,6 +98,7 @@ public class CalculatorDialogActivity extends SherlockFragmentActivity {
|
||||
|
||||
if (dialogData != null) {
|
||||
final TextView messageTextView = (TextView) root.findViewById(R.id.cpp_dialog_message_textview);
|
||||
messageTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
|
||||
messageTextView.setText(dialogData.getMessage());
|
||||
|
||||
if ( dialogData.getMessageType() == MessageType.error || dialogData.getMessageType() == MessageType.warning ) {
|
||||
|
@@ -35,6 +35,8 @@ public enum CalculatorFragmentType {
|
||||
plotter_function_settings(CalculatorPlotFunctionSettingsActivity.CalculatorPlotFunctionSettingsFragment.class, R.layout.cpp_plot_function_settings_fragment, R.string.cpp_plot_function_settings),
|
||||
plotter_range(CalculatorPlotRangeActivity.CalculatorPlotRangeFragment.class, R.layout.cpp_plot_range_fragment, R.string.cpp_plot_range),
|
||||
|
||||
purchase_dialog(CalculatorPlotRangeActivity.CalculatorPlotRangeFragment.class, R.layout.cpp_purchase_dialog_fragment, R.string.cpp_purchase_title),
|
||||
|
||||
dialog(CalculatorDialogActivity.CalculatorDialogFragment.class, R.layout.cpp_dialog_fragment, R.string.cpp_message),
|
||||
|
||||
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
|
||||
|
@@ -43,6 +43,17 @@ enum CalculatorMenu implements LabeledMenuItem<MenuItem> {
|
||||
}
|
||||
},
|
||||
|
||||
exit(R.string.c_exit) {
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
if (context instanceof Activity) {
|
||||
((Activity) context).finish();
|
||||
} else {
|
||||
Log.e(CalculatorActivity.TAG, "Activity menu used with context");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
help(R.string.c_help) {
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
@@ -55,17 +66,6 @@ enum CalculatorMenu implements LabeledMenuItem<MenuItem> {
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
CalculatorActivityLauncher.showAbout(context);
|
||||
}
|
||||
},
|
||||
|
||||
exit(R.string.c_exit) {
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
if (context instanceof Activity) {
|
||||
((Activity) context).finish();
|
||||
} else {
|
||||
Log.e(CalculatorActivity.TAG, "Activity menu used with context");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final int captionResId;
|
||||
|
@@ -3,11 +3,11 @@
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
@@ -22,9 +22,14 @@ import net.robotmedia.billing.helper.AbstractBillingObserver;
|
||||
import net.robotmedia.billing.model.Transaction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.App;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.msg.AndroidMessage;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
import org.solovyev.common.msg.Message;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -93,31 +98,9 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im
|
||||
|
||||
adFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
// check billing availability
|
||||
if (BillingController.checkBillingSupported(CalculatorPreferencesActivity.this) != BillingController.BillingStatus.SUPPORTED) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is not supported - warn user!");
|
||||
// warn about not supported billing
|
||||
new AlertDialog.Builder(CalculatorPreferencesActivity.this).setTitle(R.string.c_error).setMessage(R.string.c_billing_error).create().show();
|
||||
} else {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is supported - continue!");
|
||||
if (!AdsController.getInstance().isAdFree(CalculatorPreferencesActivity.this)) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Item not purchased - try to purchase!");
|
||||
|
||||
// not purchased => purchasing
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_purchasing, Toast.LENGTH_SHORT).show();
|
||||
|
||||
// show purchase window for user
|
||||
BillingController.requestPurchase(CalculatorPreferencesActivity.this, CalculatorApplication.AD_FREE_PRODUCT_ID, true);
|
||||
} else {
|
||||
// disable preference
|
||||
adFreePreference.setEnabled(false);
|
||||
// and show message to user
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_already_purchased, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
final Context context = CalculatorPreferencesActivity.this;
|
||||
context.startActivity(new Intent(context, CalculatorPurchaseDialogActivity.class));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
adFreePreference.setEnabled(true);
|
||||
@@ -189,7 +172,15 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im
|
||||
|
||||
@Override
|
||||
public void onRequestPurchaseResponse(@NotNull String itemId, @NotNull ResponseCode response) {
|
||||
// do nothing
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
if (adFreePreference != null) {
|
||||
if (response == ResponseCode.RESULT_OK) {
|
||||
adFreePreference.setEnabled(false);
|
||||
|
||||
final Message message = new AndroidMessage(R.string.cpp_purchase_thank_you_text, MessageType.info, App.getInstance().getApplication());
|
||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_message_dialog, MessageDialogData.newInstance(message, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
@@ -0,0 +1,84 @@
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Bundle;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/20/13
|
||||
* Time: 2:36 PM
|
||||
*/
|
||||
public class CalculatorPurchaseDialogActivity extends SherlockFragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.cpp_dialog);
|
||||
|
||||
FragmentUtils.createFragment(this, PurchaseDialogFragment.class, R.id.dialog_layout, "purchase-dialog");
|
||||
}
|
||||
|
||||
public static class PurchaseDialogFragment extends CalculatorFragment {
|
||||
|
||||
public PurchaseDialogFragment() {
|
||||
super(CalculatorFragmentType.purchase_dialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NotNull View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
((TextView) root.findViewById(R.id.cpp_purchase_text)).setMovementMethod(ScrollingMovementMethod.getInstance());
|
||||
root.findViewById(R.id.cpp_continue_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
final Activity activity = getActivity();
|
||||
|
||||
if (activity != null) {
|
||||
// check billing availability
|
||||
if (BillingController.checkBillingSupported(activity) != BillingController.BillingStatus.SUPPORTED) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is not supported - warn user!");
|
||||
// warn about not supported billing
|
||||
new AlertDialog.Builder(activity).setTitle(R.string.c_error).setMessage(R.string.c_billing_error).create().show();
|
||||
} else {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is supported - continue!");
|
||||
if (!AdsController.getInstance().isAdFree(activity)) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Item not purchased - try to purchase!");
|
||||
|
||||
// not purchased => purchasing
|
||||
Toast.makeText(activity, R.string.c_calc_purchasing, Toast.LENGTH_SHORT).show();
|
||||
|
||||
// show purchase window for user
|
||||
BillingController.requestPurchase(activity, CalculatorApplication.AD_FREE_PRODUCT_ID, true);
|
||||
} else {
|
||||
// and show message to user
|
||||
Toast.makeText(activity, R.string.c_calc_already_purchased, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user