Skip to content

Commit

Permalink
Hacky fix for Samsung Marshmallow
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Jun 7, 2016
1 parent e3320e8 commit 7548c71
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 76 deletions.
5 changes: 3 additions & 2 deletions Emoji Switcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ android {
buildToolsVersion '23.0.3'

defaultConfig {
applicationId 'com.stevenschoen.emojiswitcher'
minSdkVersion 19
targetSdkVersion 23
versionCode 16
versionName "2.0.2"
versionCode 19
versionName "2.1"
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,23 @@ public class EmojiSwitcherUtils {
public static final String SKU_REMOVEADS = "emojiswitcher_removeads";

private static final String systemFontsPath = "/system/fonts/";
private static final String systemEmojiFilePath = systemFontsPath + "NotoColorEmoji.ttf";
private static String systemFontFilePath;
private static final String htcFilePath = systemFontsPath + "AndroidEmoji-htc.ttf";
private static final String htcBackupFilePath = htcFilePath + ".bak";

public static String getSystemFontFilePath() {
if (systemFontFilePath == null) {
String path = systemFontsPath;
if (RootTools.exists(systemFontsPath + "SamsungColorEmoji.ttf")) {
systemFontFilePath = path + "SamsungColorEmoji.ttf";
} else {
systemFontFilePath = path + "NotoColorEmoji.ttf";
}
}

return systemFontFilePath;
}

public static NetworkInterface getNetworkInterface(Context context) {
return ((EmojiSwitcherApplication) context.getApplicationContext()).getNetworkInterface();
}
Expand Down Expand Up @@ -110,7 +123,7 @@ public void onNext(Boolean ready) {
InstallProgress progress = new InstallProgress();
progress.currentStage = InstallProgress.Stage.Backup;
subscriber.onNext(progress);
File systemEmojiSetFile = new File(systemEmojiFilePath);
File systemEmojiSetFile = new File(getSystemFontFilePath());
File backupFile = new File(systemEmojiBackupFilePath(context));
RootTools.copyFile(systemEmojiSetFile.getAbsolutePath(),
backupFile.getAbsolutePath(), true, false);
Expand All @@ -121,9 +134,9 @@ public void onNext(Boolean ready) {
subscriber.onNext(progress);

RootTools.copyFile(emojiSet.path.getAbsolutePath(),
new File(systemEmojiFilePath).getAbsolutePath(), true, false);
new File(getSystemFontFilePath()).getAbsolutePath(), true, false);
try {
applyPermissions("644", systemEmojiFilePath);
applyPermissions("644", getSystemFontFilePath());
} catch (Exception e) {
subscriber.onError(e);
}
Expand Down Expand Up @@ -320,7 +333,7 @@ public static Observable<EmojiSetListing> currentEmojiSet(final Context context,
@Override
public void call(Subscriber<? super EmojiSetListing> subscriber) {
File emojiSetDestinationFile = new File(context.getFilesDir() + File.separator + "systemcurrent.ttf");
RootTools.copyFile(systemEmojiFilePath, emojiSetDestinationFile.getAbsolutePath(), true, false);
RootTools.copyFile(getSystemFontFilePath(), emojiSetDestinationFile.getAbsolutePath(), true, false);
try {
applyPermissions("777", emojiSetDestinationFile.getAbsolutePath());
} catch (Exception e) {
Expand Down Expand Up @@ -358,9 +371,9 @@ protected Void doInBackground(Activity... activity) {
undoHtcFix();
}

RootTools.copyFile(systemEmojiBackupFilePath(activity[0]), systemEmojiFilePath, true, true);
RootTools.copyFile(systemEmojiBackupFilePath(activity[0]), getSystemFontFilePath(), true, true);
try {
applyPermissions("644", systemEmojiFilePath);
applyPermissions("644", getSystemFontFilePath());
} catch (TimeoutException | RootDeniedException | IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.stevenschoen.emojiswitcher;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -25,7 +21,6 @@
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.stevenschoen.emojiswitcher.billing.IabException;
import com.stevenschoen.emojiswitcher.billing.IabHelper;
import com.stevenschoen.emojiswitcher.billing.IabResult;
import com.stevenschoen.emojiswitcher.billing.Inventory;
Expand All @@ -35,15 +30,10 @@
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func2;
import rx.subjects.BehaviorSubject;

public class SwitcherActivity extends RxAppCompatActivity implements InstallEmojiFragment.Callbacks {
Expand Down Expand Up @@ -234,7 +224,6 @@ private void setupBilling() {
public void onIabSetupFinished(IabResult result) {
if (result.isSuccess()) {
checkAds();
notifyEmojiOnePurchasers();
} else {
Log.d("asdf", "Problem setting up in-app billing: " + result);
}
Expand Down Expand Up @@ -290,62 +279,6 @@ public void run() {
});
}

private void notifyEmojiOnePurchasers() {
Observable.combineLatest(
Observable.fromCallable(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return PreferenceManager.getDefaultSharedPreferences(SwitcherActivity.this).getBoolean("notifiedEmojiOne", false);
}
}),
emojiSetsResponseObservable,
new Func2<Boolean, EmojiSetsResponse, Boolean>() {
@Override
public Boolean call(Boolean alreadyNotified, EmojiSetsResponse emojiSetsResponse) {
if (alreadyNotified) return false;
for (EmojiSetListing listing : emojiSetsResponse.emojiSets) {
if (Objects.equals(listing.googlePlaySku, "emojiswitcher_set_emojione")) {
try {
return billingHelper.queryInventory(true, Collections.singletonList(listing.googlePlaySku), null)
.hasPurchase(listing.googlePlaySku);
} catch (IabException e) {
e.printStackTrace();
return false;
}
}
}
return false;
}
}).observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Boolean>() {
@Override
public void call(Boolean notify) {
if (notify) {
new AlertDialog.Builder(SwitcherActivity.this)
.setMessage("Emoji One is now available to everyone for free! You're entitled to a full refund for purchasing it.")
.setPositiveButton("Request refund", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent sendEmailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:steven@stevenschoen.com"));
sendEmailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"steven@stevenschoen.com"});
sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, "Emoji One refund request");
sendEmailIntent.putExtra(Intent.EXTRA_TEXT, "My Google Play email is: \n(Enter your Google Play email above.)");
startActivity(Intent.createChooser(sendEmailIntent, "Request refund by email"));
}
})
.setNegativeButton("Cancel", null)
.show();
PreferenceManager.getDefaultSharedPreferences(SwitcherActivity.this).edit().putBoolean("notifiedEmojiOne", true).apply();
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
throwable.printStackTrace();
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.ServiceConnection;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
Expand Down

0 comments on commit 7548c71

Please sign in to comment.