From c9ddf1e415cf6cb36b353420849fd9265b988644 Mon Sep 17 00:00:00 2001 From: zilmar Date: Wed, 12 Apr 2017 20:30:07 +1000 Subject: [PATCH] [Android] Add patreon support message --- Android/res/layout/input_text.xml | 16 ++ Android/res/values/strings.xml | 6 +- .../src/emu/project64/GalleryActivity.java | 233 ++++++++++++------ 3 files changed, 180 insertions(+), 75 deletions(-) create mode 100644 Android/res/layout/input_text.xml diff --git a/Android/res/layout/input_text.xml b/Android/res/layout/input_text.xml new file mode 100644 index 000000000..c056baf90 --- /dev/null +++ b/Android/res/layout/input_text.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/Android/res/values/strings.xml b/Android/res/values/strings.xml index 7f8b44a92..2f7679aeb 100644 --- a/Android/res/values/strings.xml +++ b/Android/res/values/strings.xml @@ -167,9 +167,9 @@ Reset game? The game will go back to a clear state, all progress made will be lost. - Save Support - Save support is a one time purchase and the only purchase in Project64.\n\nProject64 may not be perfect and making this as an upgrade it allows you to play and test the emulator before you have to spend any money.\n\nThis is also a good way for you to support and give back to the creation of the emulator.. - Purchase + Project64 needs your help + Developing a fully functional emulator is a massive time-consuming project. With donations you can show your appreciation for this effort and at the same time support the development.\n\nClick Support Project64 button below to view our patreon page, if you are interested in supporting us!\n\nIf you are a patreon already then <a href=\"#patreon\">click here to enter your email address</a> to validate it and Project64 will stop prompting you for support. + Support Project64 Starting Up … diff --git a/Android/src/emu/project64/GalleryActivity.java b/Android/src/emu/project64/GalleryActivity.java index 28a9db98c..9aeec3af2 100644 --- a/Android/src/emu/project64/GalleryActivity.java +++ b/Android/src/emu/project64/GalleryActivity.java @@ -19,6 +19,8 @@ import java.util.List; import java.util.Locale; import java.util.Timer; import java.util.TimerTask; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Tracker; @@ -66,6 +68,9 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.text.SpannableStringBuilder; +import android.text.method.LinkMovementMethod; +import android.text.style.ClickableSpan; import android.util.DisplayMetrics; import android.util.Log; import android.view.KeyEvent; @@ -74,8 +79,10 @@ import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.widget.ArrayAdapter; +import android.widget.EditText; import android.widget.ListAdapter; import android.widget.TextView; +import android.widget.TextView.BufferType; public class GalleryActivity extends AppCompatActivity implements IabBroadcastListener { @@ -240,12 +247,12 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } }); UpdateLanguage(); - + ((Project64Application) getApplication()).getDefaultTracker().send(new HitBuilders.EventBuilder() - .setCategory("mobile") - .setAction("start") - .setLabel(NativeExports.appVersion()) - .build()); + .setCategory("mobile") + .setAction("start") + .setLabel(NativeExports.appVersion()) + .build()); } void UpdateLanguage() @@ -256,18 +263,6 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi Strings.SetMenuTitle(mDrawerList.getMenu(), R.id.menuItem_about, LanguageStringID.ANDROID_ABOUT); } - // Enables or disables the "please wait" screen. - void setWaitScreen(boolean set) - { - if (set) - { - WebView webView = (WebView)findViewById(R.id.screen_wait); - webView.loadData(Utility.readAsset("loading.htm", ""), "text/html", "UTF8"); - } - findViewById(R.id.screen_main).setVisibility(set ? View.GONE : View.VISIBLE); - findViewById(R.id.screen_wait).setVisibility(set ? View.VISIBLE : View.GONE); - } - // Listener that's called when we finish querying the items and subscriptions we own IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { @@ -350,8 +345,6 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi mPj64Supporter = true; } } - - setWaitScreen(false); } }; @@ -487,16 +480,8 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } ListmenuItemLst = new ArrayList(); - if (ShouldShowSupportWindow()) - { - menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_lock)); - menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_lock)); - } - else - { - menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_controller)); - menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_play)); - } + menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_controller)); + menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_play)); menuItemLst.add(new Item("Restart", R.drawable.ic_refresh)); if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue())) { @@ -571,20 +556,27 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi @Override public void onClick(DialogInterface dialog, int item) { - if ((item == 0 || item == 1) && ShouldShowSupportWindow()) - { - ShowSupportWindow(); - return; - } if (item == 0) { - launchGameActivity(); + if (ShouldShowSupportWindow()) + { + ShowSupportWindow(false); + } + else + { + launchGameActivity(false); + } } else if (item == 1) { - NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); - NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); - launchGameActivity(); + if (ShouldShowSupportWindow()) + { + ShowSupportWindow(true); + } + else + { + launchGameActivity(true); + } } else if (item == 2) { @@ -604,7 +596,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } SaveDir.delete(); NativeExports.UISettingsSaveDword(UISettingID.Game_RunCount.getValue(), 0); - launchGameActivity(); + launchGameActivity(false); } }) .setNegativeButton(android.R.string.cancel, this) @@ -623,34 +615,23 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi public void onGalleryItemClick( GalleryItem item ) { NativeExports.LoadGame(item.romFile.getAbsolutePath()); + File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); + File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue())); + Boolean ResumeGame = HasAutoSave(GameSaveDir); if (ShouldShowSupportWindow()) { - ShowSupportWindow(); + ShowSupportWindow(ResumeGame); } else { - File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); - final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue())); - if (HasAutoSave(GameSaveDir)) - { - NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); - NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); - } - launchGameActivity(); + launchGameActivity(ResumeGame); } } public boolean onGalleryItemLongClick( GalleryItem item ) { NativeExports.LoadGame(item.romFile.getAbsolutePath()); - if (ShouldShowSupportWindow()) - { - ShowSupportWindow(); - } - else - { - StartGameMenu(true); - } + StartGameMenu(true); Log.d("GalleryActivity", "onGalleryItemLongClick 4"); return true; } @@ -781,9 +762,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi return false; } - File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); - final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue())); - if (GameSaveDir.exists() == false) + boolean PatreonAccount = ValidPatreonAccount(); + Log.d("GalleryActivity", "PatreonAccount = " + PatreonAccount); + if (PatreonAccount) { return false; } @@ -804,27 +785,35 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi return true; } - public void ShowSupportWindow() + private void EnterPatreonEmail(final AlertDialog SupportDialog, final Boolean ResumeGame) { - final Context context = this; - final Activity activity = this; - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getText(R.string.SupportProject64_title)); - builder.setMessage(getText(R.string.GetSaveSupport_message)); - builder.setNeutralButton("Not now", null); - builder.setNegativeButton("Support Project64", null); + final View layout = View.inflate( this, R.layout.input_text, null ); + builder.setTitle("Patreon Email"); + builder.setPositiveButton("OK", null); + builder.setNegativeButton("Cancel", null); builder.setCancelable(false); + builder.setView(layout); final AlertDialog dialog = builder.create(); dialog.show(); - dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener( new View.OnClickListener() + EditText et = (EditText)dialog.findViewById(R.id.EditText); + et.setText(NativeExports.UISettingsLoadString(UISettingID.SupportWindow_PatreonEmail.getValue())); + + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { + EditText et = (EditText)dialog.findViewById(R.id.EditText); + String email = et.getText().toString(); + NativeExports.UISettingsSaveString(UISettingID.SupportWindow_PatreonEmail.getValue(), email); dialog.dismiss(); - StartGameMenu(false); + if (ValidPatreonAccount()) + { + SupportDialog.dismiss(); + launchGameActivity(ResumeGame); + } } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener( new View.OnClickListener() @@ -835,11 +824,113 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi dialog.dismiss(); } }); + + } + + private boolean ValidPatreonAccount() + { + String PatreonEmail = NativeExports.UISettingsLoadString(UISettingID.SupportWindow_PatreonEmail.getValue()); + String regex = "^(.+)@(.+)$"; + + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(PatreonEmail); + return matcher.matches(); + } + + public void ShowSupportWindow(final Boolean ResumeGame) + { + Boolean TimeDelayed = NativeExports.UISettingsLoadDword(UISettingID.Game_RunCount.getValue()) > 15; + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getText(R.string.SupportProject64_title)); + builder.setMessage(getText(R.string.SupportProject64_message)); + builder.setNeutralButton("Not now", null); + builder.setNegativeButton(R.string.SupportProject64_OkButton, null); + builder.setCancelable(false); + + final AlertDialog dialog = builder.create(); + dialog.show(); + + CharSequence text = getString(R.string.SupportProject64_message); + SpannableStringBuilder spanTxt = new SpannableStringBuilder(); + int start = 0; + for (int i = 0, n = text.length(); i < n; i++) + { + if (text.charAt(i) == '<' && text.charAt(i+1) == 'a') + { + int anchor_stat_end = 0; + for (int a_i = i, a_n = text.length() - 4; a_i < a_n; a_i++) + { + if (text.charAt(a_i) == '>') + { + anchor_stat_end = a_i; + } + if (text.charAt(a_i) == '<' && text.charAt(a_i + 1) == '/' && text.charAt(a_i + 2) == 'a' && text.charAt(a_i + 3) == '>') + { + spanTxt.append(text.subSequence(start, i)); + CharSequence anchor_text = text.subSequence(anchor_stat_end + 1, a_i); + spanTxt.append(anchor_text); + spanTxt.setSpan(new ClickableSpan() + { + @Override + public void onClick(View widget) + { + EnterPatreonEmail(dialog, ResumeGame); + } + }, spanTxt.length() - anchor_text.length(), spanTxt.length(), 0); + start = a_i + 4; + i = start; + break; + } + } + } + } + spanTxt.append(text.subSequence(start, text.length())); + + TextView view = ((TextView)dialog.findViewById(android.R.id.message)); + view.setMovementMethod(LinkMovementMethod.getInstance()); + view.setText(spanTxt, BufferType.SPANNABLE); + if (TimeDelayed) + { + dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(false); + Handler handler = new Handler(); + handler.postDelayed(new Runnable() + { + @Override + public void run() + { + dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(true); + } + }, 20000); + } + dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener( new View.OnClickListener() + { + @Override + public void onClick(View v) + { + dialog.dismiss(); + launchGameActivity(ResumeGame); + } + }); + dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener( new View.OnClickListener() + { + @Override + public void onClick(View v) + { + Intent browse = new Intent( Intent.ACTION_VIEW , Uri.parse( "https://www.patreon.com/bePatron?u=841905" ) ); + startActivity( browse ); + } + }); dialog.setCanceledOnTouchOutside(false); } - public void launchGameActivity() + public void launchGameActivity(boolean ResumeGame) { + if (ResumeGame) + { + NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); + NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); + } // Launch the game activity boolean isXperiaPlay = false; @@ -899,8 +990,6 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi { mRecentItems = new ArrayList(); - Log.d("GalleryActivity","File_RecentGameFileCount = " + NativeExports.UISettingsLoadDword(UISettingID.File_RecentGameFileCount.getValue())); - for (int i = 0, n = NativeExports.UISettingsLoadDword(UISettingID.File_RecentGameFileCount.getValue()); i < n; i++) { String RecentFile = NativeExports.UISettingsLoadStringIndex(UISettingID.File_RecentGameFileIndex.getValue(), i);