Android: update Java part (#118)
parent
8efefe95a2
commit
7577cf848b
|
@ -3,7 +3,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,13 @@ task clean(type: Delete) {
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.3"
|
||||
compileSdkVersion 27
|
||||
buildToolsVersion "27.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "mobi.MultiCraft"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 25
|
||||
targetSdkVersion 27
|
||||
}
|
||||
Properties props = new Properties()
|
||||
props.load(new FileInputStream(file("local.properties")))
|
||||
|
@ -47,4 +47,33 @@ android {
|
|||
}
|
||||
}
|
||||
}
|
||||
// for multiple APKs
|
||||
splits {
|
||||
abi {
|
||||
enable true
|
||||
reset()
|
||||
include "armeabi-v7a", "x86"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// build multiple APKs for all ABI
|
||||
ext.abiCodes = ['armeabi-v7a': 1, x86: 2]
|
||||
import com.android.build.OutputFile
|
||||
|
||||
android.applicationVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
def baseAbiVersionCode =
|
||||
project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
|
||||
if (baseAbiVersionCode != null) {
|
||||
output.versionCodeOverride =
|
||||
baseAbiVersionCode + variant.versionCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.android.support:support-compat:27.1.1'
|
||||
}
|
||||
|
||||
|
|
|
@ -2,27 +2,26 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="mobi.MultiCraft"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="56"
|
||||
android:versionName="@string/ver">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:fullBackupContent="@xml/my_backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name">
|
||||
|
||||
<activity
|
||||
android:name="mobi.MultiCraft.MainActivity"
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:theme="@style/AppTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
@ -36,6 +35,7 @@
|
|||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="multicraft" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
|
@ -46,19 +46,9 @@
|
|||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
|
||||
<service
|
||||
android:name="mobi.MultiCraft.UnzipService"
|
||||
android:name=".UnzipService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
<service android:name="mobi.MultiCraft.FireIDService">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service android:name="mobi.MultiCraft.FireMsgService">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
|
||||
public interface CallBackListener {
|
||||
void updateViews(int text, int textVisibility, int progressVisibility);
|
||||
|
||||
void onEvent(String source, String param);
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class CheckConnectionTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private WeakReference<Context> contextRef;
|
||||
private CallBackListener listener;
|
||||
|
||||
CheckConnectionTask(Context context) {
|
||||
contextRef = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
void setListener(CallBackListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
Context context = contextRef.get();
|
||||
return context != null && isReachable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean isStart) {
|
||||
listener.onEvent("CheckConnectionTask", isStart.toString());
|
||||
}
|
||||
|
||||
private boolean isGoogleAvailable(String url, int timeout) {
|
||||
try {
|
||||
HttpURLConnection urlc = (HttpURLConnection)
|
||||
(new URL(url)
|
||||
.openConnection());
|
||||
urlc.setRequestProperty("User-Agent", "Android");
|
||||
urlc.setRequestProperty("Connection", "close");
|
||||
urlc.setConnectTimeout(timeout);
|
||||
urlc.connect();
|
||||
return urlc.getResponseCode() == 204 && urlc.getContentLength() == 0;
|
||||
} catch (IOException e) {
|
||||
Log.e("WTF", "IOException " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isReachable() {
|
||||
return isGoogleAvailable("http://clients3.google.com/generate_204", 1500) ||
|
||||
isGoogleAvailable("http://g.cn/generate_204", 1000);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import static mobi.MultiCraft.MainActivity.unzipLocation;
|
||||
|
||||
|
||||
public class CopyZipTask extends AsyncTask<String, Void, String> {
|
||||
|
||||
private WeakReference<Context> contextRef;
|
||||
private CallBackListener listener;
|
||||
private String[] zips;
|
||||
|
||||
CopyZipTask(Context context) {
|
||||
contextRef = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
zips = params;
|
||||
for (String s : zips) {
|
||||
copyAssets(s);
|
||||
}
|
||||
return "Done";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
listener.updateViews(R.string.loading, View.VISIBLE, View.GONE);
|
||||
startUnzipService(zips);
|
||||
|
||||
}
|
||||
|
||||
private void copyAssets(String zipName) {
|
||||
String filename = zipName.substring(zipName.lastIndexOf("/") + 1);
|
||||
InputStream in;
|
||||
OutputStream out;
|
||||
try {
|
||||
in = contextRef.get().getAssets().open(filename);
|
||||
out = new FileOutputStream(zipName);
|
||||
copyFile(in, out);
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.e("WTF", "Failed to copy asset file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFile(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
private void startUnzipService(String[] file) {
|
||||
// Start MyIntentService
|
||||
Intent intentMyIntentService = new Intent(contextRef.get(), UnzipService.class);
|
||||
intentMyIntentService.putExtra(UnzipService.EXTRA_KEY_IN_FILE, file);
|
||||
intentMyIntentService.putExtra(UnzipService.EXTRA_KEY_IN_LOCATION, unzipLocation);
|
||||
contextRef.get().startService(intentMyIntentService);
|
||||
|
||||
}
|
||||
|
||||
void setListener(CallBackListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class DeleteTask extends AsyncTask<String, Void, Void> {
|
||||
|
||||
private CallBackListener listener;
|
||||
private String location;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
listener.updateViews(R.string.rm_old, View.VISIBLE, View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... params) {
|
||||
location = params[0];
|
||||
for (String p : params) {
|
||||
deleteFiles(p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onEvent("DeleteTask", location);
|
||||
}
|
||||
|
||||
private void deleteFiles(String path) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
String deleteCmd = "rm -r " + path;
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
try {
|
||||
runtime.exec(deleteCmd);
|
||||
} catch (IOException e) {
|
||||
Log.e("WTF", "delete files failed: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setListener(CallBackListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
public interface DialogsCallback {
|
||||
void onPositive(String source);
|
||||
|
||||
void onNegative(String source);
|
||||
|
||||
void onCancelled(String source);
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
import com.google.firebase.iid.FirebaseInstanceIdService;
|
||||
|
||||
public class FireIDService extends FirebaseInstanceIdService {
|
||||
|
||||
@Override
|
||||
public void onTokenRefresh() {
|
||||
String tkn = FirebaseInstanceId.getInstance().getToken();
|
||||
// Log.d("App", "Token [" + tkn + "]");
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||
import com.google.firebase.messaging.RemoteMessage;
|
||||
|
||||
public class FireMsgService extends FirebaseMessagingService {
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
super.onMessageReceived(remoteMessage);
|
||||
|
||||
// Create Notification
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410, intent,
|
||||
PendingIntent.FLAG_ONE_SHOT);
|
||||
|
||||
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.update)
|
||||
.setContentTitle(getString(R.string.message))
|
||||
.setSound(uri)
|
||||
.setContentText(remoteMessage.getNotification().getBody())
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(pendingIntent);
|
||||
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
notificationManager.notify(1410, notificationBuilder.build());
|
||||
}
|
||||
}
|
|
@ -14,12 +14,18 @@ public class GameActivity extends NativeActivity {
|
|||
|
||||
private int messageReturnCode;
|
||||
private String messageReturnValue;
|
||||
private int height, width;
|
||||
private float density;
|
||||
|
||||
public static native void putMessageBoxResult(String text);
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
density = bundle != null ? bundle.getFloat("density", 0) : getResources().getDisplayMetrics().density;
|
||||
height = bundle != null ? bundle.getInt("height", 0) : getResources().getDisplayMetrics().heightPixels;
|
||||
width = bundle != null ? bundle.getInt("width", 0) : getResources().getDisplayMetrics().widthPixels;
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
// if (!isAdsDisabled())
|
||||
// startAd(this, true);
|
||||
|
@ -61,7 +67,8 @@ public class GameActivity extends NativeActivity {
|
|||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
// stopAd();
|
||||
// if (!isAdsDisabled())
|
||||
// stopAd();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,15 +113,15 @@ public class GameActivity extends NativeActivity {
|
|||
}
|
||||
|
||||
public float getDensity() {
|
||||
return getResources().getDisplayMetrics().density;
|
||||
return density;
|
||||
}
|
||||
|
||||
public int getDisplayHeight() {
|
||||
return getResources().getDisplayMetrics().heightPixels;
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getDisplayWidth() {
|
||||
return getResources().getDisplayMetrics().widthPixels;
|
||||
return width;
|
||||
}
|
||||
|
||||
}
|
|
@ -29,7 +29,7 @@ public class InputDialogActivity extends Activity {
|
|||
LayoutInflater inflater = this.getLayoutInflater();
|
||||
View dialogView = inflater.inflate(R.layout.input_dialog, null);
|
||||
builder.setView(dialogView);
|
||||
final EditText editText = (EditText) dialogView.findViewById(R.id.editText);
|
||||
final EditText editText = dialogView.findViewById(R.id.editText);
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||
if (editType == 3) {
|
||||
|
|
|
@ -3,22 +3,28 @@ package mobi.MultiCraft;
|
|||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
@ -28,24 +34,23 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
||||
import static mobi.MultiCraft.PreferencesHelper.TAG_BUILD_NUMBER;
|
||||
import static mobi.MultiCraft.PreferencesHelper.TAG_CONSENT_ASKED;
|
||||
import static mobi.MultiCraft.PreferencesHelper.TAG_LAUNCH_TIMES;
|
||||
import static mobi.MultiCraft.PreferencesHelper.TAG_SHORTCUT_CREATED;
|
||||
import static mobi.MultiCraft.PreferencesHelper.getBuildNumber;
|
||||
import static mobi.MultiCraft.PreferencesHelper.getLaunchTimes;
|
||||
import static mobi.MultiCraft.PreferencesHelper.isAskConsent;
|
||||
import static mobi.MultiCraft.PreferencesHelper.isCreateShortcut;
|
||||
import static mobi.MultiCraft.PreferencesHelper.isRestored;
|
||||
import static mobi.MultiCraft.PreferencesHelper.loadSettings;
|
||||
import static mobi.MultiCraft.PreferencesHelper.saveSettings;
|
||||
|
||||
public class MainActivity extends Activity implements WVersionManager.ActivityListener {
|
||||
public class MainActivity extends Activity implements WVersionManager.ActivityListener, CallBackListener, DialogsCallback {
|
||||
public final static int REQUEST_CODE = 104;
|
||||
private final static String TAG = "Error";
|
||||
private final static String CREATE_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
|
||||
|
@ -57,15 +62,20 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
private final static int WRITE_EXTERNAL_RESULT = 101;
|
||||
private final static int ALL_PERMISSIONS_RESULT = 102;
|
||||
private static final String UPDATE_LINK = "https://raw.githubusercontent.com/MoNTE48/MultiCraft-links/master/ver.txt";
|
||||
|
||||
private String dataFolder = "/Android/data/mobi.MultiCraft/files/";
|
||||
private String unzipLocation = Environment.getExternalStorageDirectory() + dataFolder;
|
||||
private static final String[] EU_COUNTRIES = new String[]{
|
||||
"AT", "BE", "BG", "HR", "CY", "CZ",
|
||||
"DK", "EE", "FI", "FR", "DE", "GR",
|
||||
"HU", "IE", "IT", "LV", "LT", "LU",
|
||||
"MT", "NL", "PL", "PT", "RO", "SK",
|
||||
"SI", "ES", "SE", "GB", "IS", "LI", "NO"};
|
||||
private static String dataFolder = "/Android/data/mobi.MultiCraft/files/";
|
||||
public static String unzipLocation = Environment.getExternalStorageDirectory() + dataFolder;
|
||||
private ProgressBar mProgressBar;
|
||||
private ProgressBar mProgressBarIndeterminate;
|
||||
private TextView mLoading;
|
||||
private ImageView iv;
|
||||
private WVersionManager versionManager = null;
|
||||
|
||||
private ConnectionDialogListener connListener;
|
||||
private PermissionManager pm = null;
|
||||
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
|
@ -99,8 +109,6 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
}
|
||||
addLaunchTimes();
|
||||
getPermissions();
|
||||
// if (!isAdsDisabled())
|
||||
// initAd(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,20 +130,6 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
saveSettings(TAG_LAUNCH_TIMES, i);
|
||||
}
|
||||
|
||||
private void deleteFiles(String path) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
String deleteCmd = "rm -r " + path;
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
try {
|
||||
runtime.exec(deleteCmd);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "delete files failed: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createDataFolder() {
|
||||
File folder = new File(unzipLocation);
|
||||
if (!(folder.exists()))
|
||||
|
@ -163,33 +157,38 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
//interface
|
||||
private void addShortcut() {
|
||||
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
int size = activityManager.getLauncherLargeIconSize();
|
||||
try {
|
||||
Drawable icon = getPackageManager().getApplicationIcon(getPackageName());
|
||||
Bitmap shortcutIconBitmap = ((BitmapDrawable) icon).getBitmap();
|
||||
Bitmap temp;
|
||||
if (shortcutIconBitmap.getWidth() == size && shortcutIconBitmap.getHeight() == size)
|
||||
temp = shortcutIconBitmap;
|
||||
else
|
||||
temp = Bitmap.createScaledBitmap(shortcutIconBitmap, size, size, true);
|
||||
saveSettings(TAG_SHORTCUT_CREATED, false);
|
||||
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
|
||||
shortcutIntent.setAction(Intent.ACTION_MAIN);
|
||||
Intent addIntent = new Intent();
|
||||
addIntent.putExtra("duplicate", false);
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, temp);
|
||||
addIntent.setAction(CREATE_SHORTCUT);
|
||||
getApplicationContext().sendBroadcast(addIntent);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "Shortcut cannot be created");
|
||||
int size = 0;
|
||||
if (activityManager != null) {
|
||||
size = activityManager.getLauncherLargeIconSize();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < 26) {
|
||||
try {
|
||||
Drawable icon = getPackageManager().getApplicationIcon(getPackageName());
|
||||
Bitmap shortcutIconBitmap = ((BitmapDrawable) icon).getBitmap();
|
||||
Bitmap temp;
|
||||
if (shortcutIconBitmap.getWidth() == size && shortcutIconBitmap.getHeight() == size)
|
||||
temp = shortcutIconBitmap;
|
||||
else
|
||||
temp = Bitmap.createScaledBitmap(shortcutIconBitmap, size, size, true);
|
||||
saveSettings(TAG_SHORTCUT_CREATED, false);
|
||||
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
|
||||
shortcutIntent.setAction(Intent.ACTION_MAIN);
|
||||
Intent addIntent = new Intent();
|
||||
addIntent.putExtra("duplicate", false);
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, temp);
|
||||
addIntent.setAction(CREATE_SHORTCUT);
|
||||
getApplicationContext().sendBroadcast(addIntent);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "Shortcut cannot be created");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addImageView(int pos) {
|
||||
int marginTop = pos == 0 ? 48 : 288;
|
||||
RelativeLayout rl = (RelativeLayout) findViewById(R.id.activity_main);
|
||||
RelativeLayout rl = findViewById(R.id.activity_main);
|
||||
iv = new ImageView(this);
|
||||
iv.setBackgroundResource(R.drawable.logo);
|
||||
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
@ -222,15 +221,25 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
private void askGdpr() {
|
||||
if (isAskConsent() && isGdprSubject())
|
||||
showGdprDialog();
|
||||
else {
|
||||
// initAd(this, true);
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
RateMe.onStart(this);
|
||||
if (isCreateShortcut())
|
||||
addShortcut();
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.PB1);
|
||||
mProgressBarIndeterminate = (ProgressBar) findViewById(R.id.PB2);
|
||||
mLoading = (TextView) findViewById(R.id.tv_progress_circle);
|
||||
mProgressBar = findViewById(R.id.PB1);
|
||||
mProgressBarIndeterminate = findViewById(R.id.PB2);
|
||||
mLoading = findViewById(R.id.tv_progress_circle);
|
||||
Drawable draw = ContextCompat.getDrawable(this, R.drawable.custom_progress_bar);
|
||||
mProgressBar.setProgressDrawable(draw);
|
||||
connListener = new ConnectionDialogListener();
|
||||
createDataFolder();
|
||||
checkAppVersion();
|
||||
}
|
||||
|
@ -242,7 +251,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
if (permList.length > 0) {
|
||||
ActivityCompat.requestPermissions(this, permList, ALL_PERMISSIONS_RESULT);
|
||||
} else {
|
||||
init();
|
||||
askGdpr();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -267,7 +276,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
switch (requestCode) {
|
||||
case WRITE_EXTERNAL_RESULT:
|
||||
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
init();
|
||||
askGdpr();
|
||||
} else {
|
||||
requestStoragePermission();
|
||||
}
|
||||
|
@ -281,10 +290,10 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
}
|
||||
}
|
||||
if (PermissionManager.permissionsRejected.size() == 0) {
|
||||
init();
|
||||
askGdpr();
|
||||
} else if (!Arrays.asList(PermissionManager.permissionsRejected.toArray()).contains(WRITE_EXTERNAL_STORAGE)) {
|
||||
Toast.makeText(this, R.string.location, Toast.LENGTH_SHORT).show();
|
||||
init();
|
||||
askGdpr();
|
||||
} else {
|
||||
requestStoragePermission();
|
||||
}
|
||||
|
@ -297,25 +306,10 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
if (RateMe.shouldShowRateDialog()) {
|
||||
hideViews();
|
||||
RateMe.showRateDialog(this);
|
||||
RateMe.setCallback(new RateMe.Callback() {
|
||||
@Override
|
||||
public void onPositive() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative() {
|
||||
Toast.makeText(MainActivity.this, R.string.sad, Toast.LENGTH_LONG).show();
|
||||
startGameActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled() {
|
||||
startGameActivity();
|
||||
}
|
||||
});
|
||||
RateMe.setListener(this);
|
||||
} else {
|
||||
startGameActivity();
|
||||
// startBillingActivity();
|
||||
startNative();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,25 +317,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
public void isShowUpdateDialog(boolean flag) {
|
||||
if (flag) {
|
||||
versionManager.showDialog();
|
||||
versionManager.setCallback(new WVersionManager.Callback() {
|
||||
@Override
|
||||
public void onPositive() {
|
||||
versionManager.updateNow(versionManager.getUpdateUrl());
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative() {
|
||||
versionManager.ignoreThisVersion();
|
||||
checkRateDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemind() {
|
||||
versionManager.remindMeLater(versionManager.getReminderTimer());
|
||||
checkRateDialog();
|
||||
}
|
||||
});
|
||||
versionManager.setListener(this);
|
||||
} else {
|
||||
checkRateDialog();
|
||||
}
|
||||
|
@ -354,46 +330,49 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
|
||||
}
|
||||
|
||||
public void runGame() {
|
||||
private void runGame() {
|
||||
deleteZip(FILES, WORLDS, GAMES);
|
||||
Intent intent = new Intent(this, BillingActivity.class);
|
||||
startActivityForResult(intent, REQUEST_CODE);
|
||||
CheckConnectionTask cct = new CheckConnectionTask(this);
|
||||
cct.setListener(this);
|
||||
cct.execute();
|
||||
}
|
||||
|
||||
// private void startBillingActivity() {
|
||||
// Intent intent = new Intent(this, BillingActivity.class);
|
||||
// startActivityForResult(intent, REQUEST_CODE);
|
||||
// }
|
||||
|
||||
private void startGameActivity() {
|
||||
Intent intent = new Intent(MainActivity.this, GameActivity.class);
|
||||
private void startNative() {
|
||||
Intent intent = new Intent(this, GameActivity.class);
|
||||
intent.putExtra("density", getResources().getDisplayMetrics().density);
|
||||
intent.putExtra("width", getResources().getDisplayMetrics().widthPixels);
|
||||
intent.putExtra("height", getResources().getDisplayMetrics().heightPixels);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void startUnzipService(String[] file) throws IOException {
|
||||
// Start MyIntentService
|
||||
Intent intentMyIntentService = new Intent(this, UnzipService.class);
|
||||
intentMyIntentService.putExtra(UnzipService.EXTRA_KEY_IN_FILE, file);
|
||||
intentMyIntentService.putExtra(UnzipService.EXTRA_KEY_IN_LOCATION, unzipLocation);
|
||||
startService(intentMyIntentService);
|
||||
|
||||
private boolean isGdprSubject() {
|
||||
String locale;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
locale = getResources().getConfiguration().getLocales().get(0).getCountry();
|
||||
} else {
|
||||
locale = getResources().getConfiguration().locale.getCountry();
|
||||
}
|
||||
return Arrays.asList(EU_COUNTRIES).contains(locale.toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// super.onActivityResult(requestCode, resultCode, data);
|
||||
// check if the request code is same as what is passed here it is 2
|
||||
if (requestCode == REQUEST_CODE) {
|
||||
if ((data != null) && (data.getBooleanExtra("isCheckNewVersion", false))) {
|
||||
checkUrlVersion();
|
||||
} else {
|
||||
startGameActivity();
|
||||
}
|
||||
} else startGameActivity();
|
||||
startNative();
|
||||
}
|
||||
|
||||
private void startDeletion(boolean isAll) {
|
||||
private void prepareToRun(boolean isAll) {
|
||||
DeleteTask dt = new DeleteTask();
|
||||
dt.setListener(this);
|
||||
if (isAll) {
|
||||
new DeleteTask().execute(unzipLocation);
|
||||
dt.execute(unzipLocation);
|
||||
} else {
|
||||
new DeleteTask().execute(unzipLocation + "builtin", unzipLocation + "games", unzipLocation + "debug.txt");
|
||||
dt.execute(unzipLocation + "builtin", unzipLocation + "games", unzipLocation + "debug.txt");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,98 +383,139 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
} else if (getBuildNumber().equals("0")) {
|
||||
addImageView(0);
|
||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||
startDeletion(true);
|
||||
prepareToRun(true);
|
||||
} else {
|
||||
addImageView(0);
|
||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||
startDeletion(false);
|
||||
prepareToRun(false);
|
||||
}
|
||||
}
|
||||
|
||||
private class DeleteTask extends AsyncTask<String, Void, Void> {
|
||||
String location;
|
||||
@Override
|
||||
public void updateViews(int text, int textVisibility, int progressVisibility) {
|
||||
mProgressBarIndeterminate.setVisibility(progressVisibility);
|
||||
mLoading.setVisibility(textVisibility);
|
||||
mLoading.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
mProgressBarIndeterminate.setVisibility(View.VISIBLE);
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
mLoading.setText(R.string.rm_old);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... params) {
|
||||
location = params[0];
|
||||
for (String p : params) {
|
||||
deleteFiles(p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
if (isFinishing())
|
||||
return;
|
||||
if (unzipLocation.equals(location)) {
|
||||
new CopyZip().execute(FILES, WORLDS, GAMES);
|
||||
@Override
|
||||
public void onEvent(String source, String param) {
|
||||
if (isFinishing()) return;
|
||||
if ("DeleteTask".equals(source)) {
|
||||
CopyZipTask cpt = new CopyZipTask(this);
|
||||
cpt.setListener(this);
|
||||
if (unzipLocation.equals(param)) {
|
||||
cpt.execute(FILES, WORLDS, GAMES);
|
||||
} else {
|
||||
new CopyZip().execute(FILES, GAMES);
|
||||
cpt.execute(FILES, GAMES);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class CopyZip extends AsyncTask<String, Void, String> {
|
||||
String[] zips;
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
zips = params;
|
||||
for (String s : zips) {
|
||||
copyAssets(s);
|
||||
}
|
||||
return "Done";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
mLoading.setText(R.string.loading);
|
||||
mProgressBarIndeterminate.setVisibility(View.GONE);
|
||||
try {
|
||||
startUnzipService(zips);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "unzip failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void copyAssets(String zipName) {
|
||||
String filename = zipName.substring(zipName.lastIndexOf("/") + 1);
|
||||
InputStream in;
|
||||
OutputStream out;
|
||||
try {
|
||||
in = getAssets().open(filename);
|
||||
out = new FileOutputStream(zipName);
|
||||
copyFile(in, out);
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to copy asset file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFile(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
} else if ("CheckConnectionTask".equals(source)) {
|
||||
if ("true".equals(param)) {
|
||||
checkUrlVersion();
|
||||
} else {
|
||||
showConnectionDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showGdprDialog() {
|
||||
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.CustomLollipopDialogStyle);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
View dialogView = inflater.inflate(R.layout.gdpr_dialog, null);
|
||||
builder.setView(dialogView)
|
||||
.setPositiveButton(R.string.gdpr_agree, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
saveSettings(TAG_CONSENT_ASKED, false);
|
||||
dialog.dismiss();
|
||||
// initAd(MainActivity.this, true);
|
||||
init();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.gdpr_disagree, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
saveSettings(TAG_CONSENT_ASKED, false);
|
||||
dialog.dismiss();
|
||||
// initAd(MainActivity.this, false);
|
||||
init();
|
||||
}
|
||||
});
|
||||
TextView tv = dialogView.findViewById(R.id.gdprTextView);
|
||||
tv.setText(R.string.gdpr_main_text);
|
||||
Dialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
|
||||
tv.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
void showConnectionDialog() {
|
||||
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.CustomLollipopDialogStyle);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
||||
builder.setMessage(getString(R.string.conn_message));
|
||||
|
||||
builder.setPositiveButton(getString(R.string.conn_wifi), connListener);
|
||||
builder.setNegativeButton(getString(R.string.conn_mobile), connListener);
|
||||
builder.setNeutralButton(getString(R.string.ignore), connListener);
|
||||
|
||||
builder.setCancelable(false);
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
if (!isFinishing()) {
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositive(String source) {
|
||||
if ("RateMe".equals(source)) {
|
||||
finish();
|
||||
} else {
|
||||
versionManager.updateNow(versionManager.getUpdateUrl());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative(String source) {
|
||||
if ("RateMe".equals(source)) {
|
||||
Toast.makeText(MainActivity.this, R.string.sad, Toast.LENGTH_LONG).show();
|
||||
// startBillingActivity();
|
||||
startNative();
|
||||
} else {
|
||||
versionManager.ignoreThisVersion();
|
||||
checkRateDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(String source) {
|
||||
if ("RateMe".equals(source)) {
|
||||
// startBillingActivity();
|
||||
startNative();
|
||||
} else {
|
||||
versionManager.remindMeLater(versionManager.getReminderTimer());
|
||||
checkRateDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private class ConnectionDialogListener implements DialogInterface.OnClickListener {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case AlertDialog.BUTTON_POSITIVE:
|
||||
startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS), REQUEST_CODE);
|
||||
break;
|
||||
case AlertDialog.BUTTON_NEUTRAL:
|
||||
startNative();
|
||||
break;
|
||||
case AlertDialog.BUTTON_NEGATIVE:
|
||||
startActivityForResult(new Intent(Settings.ACTION_WIRELESS_SETTINGS), REQUEST_CODE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,10 +8,11 @@ class PreferencesHelper {
|
|||
static final String TAG_BUILD_NUMBER = "buildNumber";
|
||||
static final String TAG_LAUNCH_TIMES = "launchTimes";
|
||||
static final String TAG_RESTORE_BACKUP = "restoredFromBackup";
|
||||
static final String TAG_CONSENT_ASKED = "consentAsked";
|
||||
private static final String SETTINGS = "settings";
|
||||
private static final String TAG_DISABLED_ADS = "disabledADS";
|
||||
private static String buildNumber;
|
||||
private static boolean createShortcut;
|
||||
private static boolean askConsent;
|
||||
|
||||
private static SharedPreferences settings;
|
||||
private static boolean disabledADS;
|
||||
|
@ -20,8 +21,8 @@ class PreferencesHelper {
|
|||
return createShortcut;
|
||||
}
|
||||
|
||||
static boolean isAdsDisabled() {
|
||||
return disabledADS;
|
||||
static boolean isAskConsent() {
|
||||
return askConsent;
|
||||
}
|
||||
|
||||
static String getBuildNumber() {
|
||||
|
@ -32,11 +33,6 @@ class PreferencesHelper {
|
|||
return settings.getBoolean(TAG_RESTORE_BACKUP, false);
|
||||
}
|
||||
|
||||
static void savePurchase(boolean v) {
|
||||
disabledADS = v;
|
||||
settings.edit().putBoolean(TAG_DISABLED_ADS, v).apply();
|
||||
}
|
||||
|
||||
static int getLaunchTimes() {
|
||||
return settings.getInt(TAG_LAUNCH_TIMES, 0);
|
||||
}
|
||||
|
@ -44,8 +40,8 @@ class PreferencesHelper {
|
|||
static void loadSettings(final Context context) {
|
||||
settings = context.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
|
||||
createShortcut = settings.getBoolean(TAG_SHORTCUT_CREATED, true);
|
||||
askConsent = settings.getBoolean(TAG_CONSENT_ASKED, true);
|
||||
buildNumber = settings.getString(TAG_BUILD_NUMBER, "0");
|
||||
disabledADS = settings.getBoolean(TAG_DISABLED_ADS, false);
|
||||
}
|
||||
|
||||
static void saveSettings(String tag, boolean bool) {
|
||||
|
|
|
@ -32,11 +32,11 @@ class RateMe {
|
|||
private static Date mInstallDate = new Date();
|
||||
private static int mLaunchTimes = 0;
|
||||
private static boolean mOptOut = false;
|
||||
private static Callback sCallback = null;
|
||||
private static DialogsCallback sCallback = null;
|
||||
|
||||
private static WeakReference<Activity> mainActivityRef = null;
|
||||
|
||||
static void setCallback(Callback callback) {
|
||||
static void setListener(DialogsCallback callback) {
|
||||
sCallback = callback;
|
||||
}
|
||||
|
||||
|
@ -86,13 +86,13 @@ class RateMe {
|
|||
dialog.setContentView(R.layout.rate_dialog);
|
||||
dialog.setTitle(R.string.rta_dialog_title);
|
||||
|
||||
RatingBar ratingBar = (RatingBar) dialog.findViewById(R.id.ratingBar);
|
||||
RatingBar ratingBar = dialog.findViewById(R.id.ratingBar);
|
||||
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
|
||||
@Override
|
||||
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
|
||||
if (rating >= 3) {
|
||||
if (sCallback != null) {
|
||||
sCallback.onPositive();
|
||||
sCallback.onPositive("RateMe");
|
||||
}
|
||||
dialog.dismiss();
|
||||
String appPackage = context.getPackageName();
|
||||
|
@ -101,7 +101,7 @@ class RateMe {
|
|||
setOptOut(context, true);
|
||||
} else {
|
||||
if (sCallback != null) {
|
||||
sCallback.onNegative();
|
||||
sCallback.onNegative("RateMe");
|
||||
}
|
||||
dialog.dismiss();
|
||||
clearSharedPreferences(context);
|
||||
|
@ -112,7 +112,7 @@ class RateMe {
|
|||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if (sCallback != null) {
|
||||
sCallback.onCancelled();
|
||||
sCallback.onCancelled("RateMe");
|
||||
}
|
||||
clearSharedPreferences(context);
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class RateMe {
|
|||
dialog.show();
|
||||
} else {
|
||||
if (sCallback != null) {
|
||||
sCallback.onNegative();
|
||||
sCallback.onNegative("RateMe");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,11 +168,4 @@ class RateMe {
|
|||
}
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
void onPositive();
|
||||
|
||||
void onNegative();
|
||||
|
||||
void onCancelled();
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -39,14 +41,49 @@ public class UnzipService extends IntentService {
|
|||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
|
||||
mBuilder.setContentTitle(getString(R.string.notification_title))
|
||||
.setContentText(getString(R.string.notification_description)).setSmallIcon(R.drawable.update);
|
||||
createNotification();
|
||||
unzip(intent);
|
||||
|
||||
}
|
||||
|
||||
private void createNotification() {
|
||||
// There are hardcoding only for show it's just strings
|
||||
String name = "mobi.MultiCraft";
|
||||
String channelId = "MultiCraft channel"; // The user-visible name of the channel.
|
||||
String description = "notifications from MultiCraft"; // The user-visible description of the channel.
|
||||
NotificationCompat.Builder builder;
|
||||
if (mNotifyManager == null) {
|
||||
mNotifyManager =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
int importance = NotificationManager.IMPORTANCE_LOW;
|
||||
NotificationChannel mChannel = mNotifyManager.getNotificationChannel(channelId);
|
||||
if (mChannel == null) {
|
||||
mChannel = new NotificationChannel(channelId, name, importance);
|
||||
mChannel.setDescription(description);
|
||||
//Configure the notification channel, NO SOUND
|
||||
mChannel.setSound(null, null);
|
||||
mChannel.enableLights(false);
|
||||
mChannel.enableVibration(false);
|
||||
mNotifyManager.createNotificationChannel(mChannel);
|
||||
}
|
||||
builder = new NotificationCompat.Builder(this, channelId);
|
||||
builder.setContentTitle(getString(R.string.notification_title)) // required
|
||||
.setSmallIcon(R.drawable.update) // required
|
||||
.setContentText(getString(R.string.notification_description)); // required
|
||||
} else {
|
||||
builder = new NotificationCompat.Builder(this);
|
||||
builder.setContentTitle(getString(R.string.notification_title))
|
||||
.setContentText(getString(R.string.notification_description))
|
||||
.setSmallIcon(R.drawable.update);
|
||||
}
|
||||
mNotifyManager.notify(id, builder.build());
|
||||
}
|
||||
|
||||
private void unzip(Intent intent) {
|
||||
String[] file = intent.getStringArrayExtra(EXTRA_KEY_IN_FILE);
|
||||
String location = intent.getStringExtra(EXTRA_KEY_IN_LOCATION);
|
||||
|
||||
mNotifyManager.notify(id, mBuilder.build());
|
||||
int per = 0;
|
||||
int size = getSummarySize(file);
|
||||
for (String f : file) {
|
||||
|
@ -80,7 +117,7 @@ public class UnzipService extends IntentService {
|
|||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getLocalizedMessage());
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.Locale;
|
|||
|
||||
class WVersionManager {
|
||||
private static final String TAG = "WVersionManager";
|
||||
private static WVersionManager.Callback sCallback = null;
|
||||
private DialogsCallback sCallback = null;
|
||||
private CustomTagHandler customTagHandler;
|
||||
private String PREF_IGNORE_VERSION_CODE = "w.ignore.version.code";
|
||||
private String PREF_REMINDER_TIME = "w.reminder.time";
|
||||
|
@ -61,7 +61,7 @@ class WVersionManager {
|
|||
setLaunchTimes();
|
||||
}
|
||||
|
||||
void setCallback(WVersionManager.Callback callback) {
|
||||
void setListener(DialogsCallback callback) {
|
||||
sCallback = callback;
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,6 @@ class WVersionManager {
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
||||
builder.setIcon(getIcon());
|
||||
builder.setTitle(getTitle());
|
||||
//noinspection deprecation
|
||||
builder.setMessage(Html.fromHtml(getMessage(), null, getCustomTagHandler()));
|
||||
|
||||
builder.setPositiveButton(getUpdateNowLabel(), listener);
|
||||
|
@ -268,14 +267,6 @@ class WVersionManager {
|
|||
void isShowUpdateDialog(boolean flag);
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
void onPositive();
|
||||
|
||||
void onNegative();
|
||||
|
||||
void onRemind();
|
||||
}
|
||||
|
||||
private class AlertDialogButtonListener implements DialogInterface.OnClickListener {
|
||||
|
||||
@Override
|
||||
|
@ -283,18 +274,18 @@ class WVersionManager {
|
|||
switch (which) {
|
||||
case AlertDialog.BUTTON_POSITIVE:
|
||||
if (sCallback != null) {
|
||||
sCallback.onPositive();
|
||||
sCallback.onPositive("WVersionManager");
|
||||
}
|
||||
break;
|
||||
case AlertDialog.BUTTON_NEUTRAL:
|
||||
if (sCallback != null) {
|
||||
sCallback.onRemind();
|
||||
sCallback.onCancelled("WVersionManager");
|
||||
}
|
||||
remindMeLater(getReminderTimer());
|
||||
break;
|
||||
case AlertDialog.BUTTON_NEGATIVE:
|
||||
if (sCallback != null) {
|
||||
sCallback.onNegative();
|
||||
sCallback.onNegative("WVersionManager");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
android:id="@+id/tv_progress_circle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_below="@id/PB2"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:text="@string/loading"
|
||||
android:textColor="#FEFEFE"
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/gdprTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center"
|
||||
android:text="@string/recommend"
|
||||
android:textSize="24sp" />
|
||||
android:textSize="16sp" />
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
|
@ -8,19 +8,21 @@
|
|||
<string name="notification_description">Осталось меньше минуты…</string>
|
||||
<!-- разрешения -->
|
||||
<string name="explain">Для корректной работы, игре требуется разрешение записывать в память устройтсва.</string>
|
||||
<string name="location">Знание местоположения обеспечивает Вам лучшее взаимодействие с игрой</string>
|
||||
<string name="location">Доступ к местоположению обеспечивает Вам лучшее взаимодействие с игрой</string>
|
||||
<!-- диалог оценки -->
|
||||
<string name="rta_dialog_title">Оцените MultiCraft!</string>
|
||||
<string name="rate_title">Название</string>
|
||||
<string name="rate_submit">ОЦЕНИТЬ</string>
|
||||
<string name="rate_description">Описание</string>
|
||||
<string name="sad">Нам жаль, что Вам не понравилась игра!</string>
|
||||
<string name="recommend">Загрузка рекомендаций \n для Вас \n%1$s</string>
|
||||
<!-- обновление -->
|
||||
<string name="ignore">Игнорировать</string>
|
||||
<string name="later">Позже</string>
|
||||
<string name="update">Обновить</string>
|
||||
|
||||
<!-- reminder -->
|
||||
<string name="message">Сообщение</string>
|
||||
<!-- Интернет -->
|
||||
<string name="conn_message">Для полноценной игры, MultiCraft требует подключение к интернету.\nВ противном случае невозможно обновление игры, а так же не доступен мультиплеер!</string>
|
||||
<string name="conn_wifi">Wi-Fi</string>
|
||||
<string name="conn_mobile">3G/4G</string>
|
||||
|
||||
</resources>
|
|
@ -7,11 +7,6 @@
|
|||
|
||||
<style name="DialogTheme" parent="android:Theme.Material.Light.Dialog" />
|
||||
|
||||
<style name="CountDialogTheme" parent="android:Theme.Material.Light.Dialog">
|
||||
<item name="android:colorBackground">#70FFFFFF</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Transparent" parent="@android:style/Theme.Material.Light.NoActionBar.Fullscreen">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
|
@ -20,5 +15,5 @@
|
|||
|
||||
<style name="CustomLollipopDialogStyle" parent="android:Theme.Material.Light.Dialog.Alert" />
|
||||
|
||||
<style name="IndeterminateProgressBar" parent="android:Widget.Material.ProgressBar.Large"/>
|
||||
<style name="IndeterminateProgressBar" parent="android:Widget.Material.ProgressBar.Large" />
|
||||
</resources>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#FFFFFF</color>
|
||||
</resources>
|
|
@ -2,7 +2,7 @@
|
|||
<resources>
|
||||
|
||||
<string name="app_name" translatable="false">MultiCraft</string>
|
||||
<string name="ver" translatable="false">1.1.8</string>
|
||||
<string name="ver" translatable="false">1.1.11.2</string>
|
||||
<!-- preparation for start -->
|
||||
|
||||
<string name="rm_old">Preparing to update…</string>
|
||||
|
@ -19,13 +19,19 @@
|
|||
<string name="rate_submit">SUBMIT</string>
|
||||
<string name="rate_description">Description</string>
|
||||
<string name="sad">We are sorry that you did not like the game!</string>
|
||||
<string name="recommend">Loading recommendations \n for you \n %1$s</string>
|
||||
|
||||
<!--update input_dialog -->
|
||||
<string name="update">Update</string>
|
||||
<string name="later">Later</string>
|
||||
<string name="ignore">Ignore</string>
|
||||
|
||||
<!-- reminder -->
|
||||
<string name="message">Message</string>
|
||||
<!-- no connection dialog -->
|
||||
<string name="conn_message">MultiCraft requires an internet connection to use all game features.\nOtherwise, you will not get updates and multiplayer will be not available!</string>
|
||||
<string name="conn_wifi">Wi-Fi</string>
|
||||
<string name="conn_mobile">Mobile Data</string>
|
||||
|
||||
<!-- GDPR -->
|
||||
<string name="gdpr_main_text" translatable="false"><b>We care about your privacy and data security. We keep this app free by showing ads.</b>\n\n<b>Can we continue to use your data to tailor ads for you?</b>\n\n<small>Our partners will collect data and use a unique identifier on your device to show you ads. By agreeing, you confirm that you are 16 years old. You can learn how we and our partners collect and use data on\n<b><a href="https://www.appodeal.com/privacy-policy">Privacy Policy</a></b>.</small></string>
|
||||
<string name="gdpr_agree" translatable="false">Agree</string>
|
||||
<string name="gdpr_disagree" translatable="false">Disagree</string>
|
||||
</resources>
|
|
@ -7,11 +7,6 @@
|
|||
|
||||
<style name="DialogTheme" parent="android:Theme.Holo.Light.Dialog" />
|
||||
|
||||
<style name="CountDialogTheme" parent="android:Theme.Holo.Light.Dialog">
|
||||
<item name="android:colorBackground">#70FFFFFF</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Transparent" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
|
@ -25,6 +20,6 @@
|
|||
<item name="android:maxHeight">20dip</item>
|
||||
</style>
|
||||
|
||||
<style name="IndeterminateProgressBar" parent="android:Widget.Holo.ProgressBar.Large"/>
|
||||
<style name="IndeterminateProgressBar" parent="android:Widget.Holo.ProgressBar.Large" />
|
||||
|
||||
</resources>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<full-backup-content>
|
||||
<exclude
|
||||
domain="sharedpref"
|
||||
path="settings.xml" />
|
||||
</full-backup-content>
|
Loading…
Reference in New Issue