diff --git a/Emoji Switcher/Emoji Switcher.iml b/Emoji Switcher/Emoji Switcher.iml index e31f93e..e1d6068 100644 --- a/Emoji Switcher/Emoji Switcher.iml +++ b/Emoji Switcher/Emoji Switcher.iml @@ -98,8 +98,8 @@ - + diff --git a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/EmojiSetSelectionAdapter.java b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/EmojiSetSelectionAdapter.java new file mode 100644 index 0000000..e55bca9 --- /dev/null +++ b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/EmojiSetSelectionAdapter.java @@ -0,0 +1,16 @@ +package com.stevenschoen.emojiswitcher; + +import android.content.Context; +import android.widget.ArrayAdapter; + +import com.stevenschoen.emojiswitcher.network.EmojiSetListing; + +import java.util.List; + +public class EmojiSetSelectionAdapter extends ArrayAdapter { + + public EmojiSetSelectionAdapter(Context context, List objects) { + super(context, android.R.layout.simple_spinner_item, objects); + setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + } +} \ No newline at end of file diff --git a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/EmojiSwitcherUtils.java b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/EmojiSwitcherUtils.java index 0c8d7a4..9a5bafc 100644 --- a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/EmojiSwitcherUtils.java +++ b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/EmojiSwitcherUtils.java @@ -286,28 +286,6 @@ public void onClick(DialogInterface dialog, int which) { return builder.create(); } -// private static class InstallEmojiSetTask extends AsyncTask { -// @Override -// protected Void doInBackground(Object... params) { -// final Activity activity = (Activity) params[0]; -// EmojiSet emojiSet = (EmojiSet) params[1]; -// -// File systemEmojiSetFile = new File(systemEmojiFilePath); -// File backupFile = new File(systemEmojiBackupFilePath(activity)); -// if (backupFile.length() == 0) { -// RootTools.copyFile(systemEmojiSetFile.getAbsolutePath(), -// backupFile.getAbsolutePath(), true, false); -// } -// -// File emojiSetFile = emojiSet.path; -// RootTools.copyFile(emojiSetFile.getAbsolutePath(), -// systemEmojiSetFile.getAbsolutePath(), true, false); -// applyPermissions(activity, "644", systemEmojiFilePath); -// -// return null; -// } -// } - public static Observable currentEmojiSet(final Context context, final List sets) { return Observable.create(new Observable.OnSubscribe() { @Override diff --git a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/InstallEmojiFragment.java b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/InstallEmojiFragment.java index 2ad7157..814ca2f 100644 --- a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/InstallEmojiFragment.java +++ b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/InstallEmojiFragment.java @@ -107,7 +107,9 @@ public void onNext(EmojiSwitcherUtils.InstallProgress installProgress) { final AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setView(view) .setTitle(getString(R.string.installing_x_emoji, listing.name)) + .setCancelable(false) .create(); + dialog.setCanceledOnTouchOutside(false); laterView.setOnClickListener(new View.OnClickListener() { @Override diff --git a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SetListingUtils.java b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SetListingUtils.java index c8bce30..b812723 100644 --- a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SetListingUtils.java +++ b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SetListingUtils.java @@ -1,11 +1,31 @@ package com.stevenschoen.emojiswitcher; +import android.app.Activity; + +import com.stevenschoen.emojiswitcher.billing.IabException; import com.stevenschoen.emojiswitcher.billing.IabHelper; import com.stevenschoen.emojiswitcher.network.EmojiSetListing; +import java.util.ArrayList; +import java.util.List; + public class SetListingUtils { public static boolean userOwnsSet(EmojiSetListing listing, IabHelper billingHelper) { - // TODO - return true; + if (listing.googlePlaySku == null) { + return true; + } else { + List skuList = new ArrayList<>(); + skuList.add(listing.googlePlaySku); + try { + return billingHelper.queryInventory(true, skuList, null).hasPurchase(listing.googlePlaySku); + } catch (IabException e) { + e.printStackTrace(); + return false; + } + } + } + + public static void purchaseSet(Activity activity, EmojiSetListing listing, IabHelper billingHelper, IabHelper.OnIabPurchaseFinishedListener listener) { + billingHelper.launchPurchaseFlow(activity, listing.googlePlaySku, 0, listener); } } \ No newline at end of file diff --git a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SwitcherActivity.java b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SwitcherActivity.java index 931a7ac..dd905c6 100644 --- a/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SwitcherActivity.java +++ b/Emoji Switcher/src/main/java/com/stevenschoen/emojiswitcher/SwitcherActivity.java @@ -1,6 +1,8 @@ package com.stevenschoen.emojiswitcher; +import android.content.Context; import android.content.Intent; +import android.net.ConnectivityManager; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; @@ -14,6 +16,7 @@ import android.widget.ImageButton; import android.widget.Spinner; import android.widget.TextView; +import android.widget.Toast; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdSize; @@ -50,6 +53,14 @@ public class SwitcherActivity extends RxAppCompatActivity implements InstallEmoj @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm.getActiveNetworkInfo() == null || !cm.getActiveNetworkInfo().isConnected()) { + Toast.makeText(this, "This app needs internet access to work.", Toast.LENGTH_LONG).show(); + finish(); + return; + } + setContentView(R.layout.activity_emojiswitcher); verifyRoot(); @@ -97,21 +108,28 @@ public void onClick(View v) { }); spinnerInstallEmojis = (Spinner) findViewById(R.id.spinner_pickemojiset); - emojiSetsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, emojiSetListings); - emojiSetsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + emojiSetsAdapter = new EmojiSetSelectionAdapter(this, emojiSetListings); spinnerInstallEmojis.setAdapter(emojiSetsAdapter); spinnerInstallEmojis.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { int lastSelectedSetPosition; @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { + public void onItemSelected(final AdapterView parent, View view, final int position, long id) { EmojiSetListing listing = (EmojiSetListing) parent.getItemAtPosition(position); if (SetListingUtils.userOwnsSet(listing, billingHelper)) { lastSelectedSetPosition = position; } else { parent.setSelection(lastSelectedSetPosition); -// buy + SetListingUtils.purchaseSet(SwitcherActivity.this, listing, billingHelper, + new IabHelper.OnIabPurchaseFinishedListener() { + @Override + public void onIabPurchaseFinished(IabResult result, Purchase info) { + if (result.isSuccess()) { + parent.setSelection(position); + } + } + }); } } @@ -123,14 +141,19 @@ public void onNothingSelected(AdapterView parent) { } buttonInstallEmojiSet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - EmojiSetListing listing = (EmojiSetListing) spinnerInstallEmojis.getSelectedItem(); + final EmojiSetListing listing = (EmojiSetListing) spinnerInstallEmojis.getSelectedItem(); if (SetListingUtils.userOwnsSet(listing, billingHelper)) { - Bundle options = new Bundle(); - options.putParcelable("listing", (EmojiSetListing) spinnerInstallEmojis.getSelectedItem()); - InstallEmojiFragment installFragment = (InstallEmojiFragment) Fragment.instantiate(SwitcherActivity.this, InstallEmojiFragment.class.getName(), options); - installFragment.show(getSupportFragmentManager(), "install"); + installSet(listing); } else { -// buy + SetListingUtils.purchaseSet(SwitcherActivity.this, listing, billingHelper, + new IabHelper.OnIabPurchaseFinishedListener() { + @Override + public void onIabPurchaseFinished(IabResult result, Purchase info) { + if (result.isSuccess()) { + installSet(listing); + } + } + }); } } }); @@ -140,6 +163,13 @@ public void onClick(View v) { setupBilling(); } + private void installSet(EmojiSetListing listing) { + Bundle options = new Bundle(); + options.putParcelable("listing", listing); + InstallEmojiFragment installFragment = (InstallEmojiFragment) Fragment.instantiate(SwitcherActivity.this, InstallEmojiFragment.class.getName(), options); + installFragment.show(getSupportFragmentManager(), "install"); + } + private void refreshCurrentSystemEmojiSet() { verifyRoot(); diff --git a/Emoji Switcher/src/main/res/layout/install_emoji.xml b/Emoji Switcher/src/main/res/layout/install_emoji.xml index d0b45f5..73b79bc 100644 --- a/Emoji Switcher/src/main/res/layout/install_emoji.xml +++ b/Emoji Switcher/src/main/res/layout/install_emoji.xml @@ -23,13 +23,22 @@ android:id="@+id/install_emoji_reboot_holder" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical" - android:paddingStart="16dp"> + android:orientation="vertical"> + + Refresh Try again Check root - There was a problem getting root access, which is needed to modify the built-in emoji data.\n\nDoes this app have root permissions? + There was a problem getting root access.\n\nRoot access is given after you "root" your device, which lets apps do advanced things like modify system files. +It\'s a different process for each device.\n\nDoes this app have root permissions? Are you rooted? Failed to get root! Switch emojis to…