Last active
December 19, 2016 20:15
-
-
Save Thomas-Vos/6d44b4920dbdc8482a2467d95f66c5df to your computer and use it in GitHub Desktop.
Open redeem dialog on Google Play
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.your.packagename | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.support.v7.app.AlertDialog; | |
import android.text.InputFilter; | |
import android.text.InputType; | |
import android.view.inputmethod.EditorInfo; | |
import android.widget.EditText; | |
import java.net.URLEncoder; | |
public class RedeemHelper { | |
public static void showRedeemDialog(final Context context) { | |
final EditText editText = new EditText(context); | |
editText.setImeOptions(EditorInfo.IME_ACTION_DONE); | |
editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS); | |
editText.setSingleLine(true); | |
editText.setFilters(new InputFilter[]{new InputFilter.AllCaps()}); | |
new AlertDialog.Builder(context, R.style.AppDialog) | |
.setTitle(R.string.redeem) | |
.setMessage(R.string.redeem_message) | |
.setIcon(R.drawable.ic_redeem_black_24dp) | |
.setView(editText) | |
.setPositiveButton(R.string.redeem, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialogInterface, int i) { | |
try { | |
String code = editText.getText().toString(); | |
String url = "https://play.google.com/redeem?code=" + URLEncoder.encode(code, "UTF-8"); | |
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
// Error | |
} | |
} | |
}) | |
.setNegativeButton(R.string.cancel, null) | |
.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment