Android: update java part
This commit is contained in:
parent
54634e616f
commit
33192bd4a1
|
@ -14,15 +14,14 @@ set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
# Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing
|
# Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing
|
||||||
set(VERSION_MAJOR 1)
|
set(VERSION_MAJOR 1)
|
||||||
set(VERSION_MINOR 1)
|
set(VERSION_MINOR 2)
|
||||||
set(VERSION_PATCH 10)
|
set(VERSION_PATCH 0)
|
||||||
set(VERSION_TWEAK 0)
|
|
||||||
set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
|
set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
|
||||||
|
|
||||||
# Change to false for releases
|
# Change to false for releases
|
||||||
set(DEVELOPMENT_BUILD FALSE)
|
set(DEVELOPMENT_BUILD FALSE)
|
||||||
|
|
||||||
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_TWEAK}")
|
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
if(VERSION_EXTRA)
|
if(VERSION_EXTRA)
|
||||||
set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
|
set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
|
||||||
elseif(DEVELOPMENT_BUILD)
|
elseif(DEVELOPMENT_BUILD)
|
||||||
|
|
|
@ -70,14 +70,14 @@ VORBIS_TIMESTAMP = $(VORBIS_DIR)/timestamp
|
||||||
VORBIS_TIMESTAMP_INT = $(ANDR_ROOT)/deps/vorbis_timestamp
|
VORBIS_TIMESTAMP_INT = $(ANDR_ROOT)/deps/vorbis_timestamp
|
||||||
VORBIS_URL_GIT = https://github.com/MoNTE48/libvorbis-android
|
VORBIS_URL_GIT = https://github.com/MoNTE48/libvorbis-android
|
||||||
|
|
||||||
IRRLICHT_COMMIT = 990d475fbbb2653c95b992937906eb49960d02fb
|
IRRLICHT_COMMIT = 237eb07bf4b6957f2e103adcaf835e6a2afe3486
|
||||||
IRRLICHT_DIR = $(ANDR_ROOT)/deps/irrlicht
|
IRRLICHT_DIR = $(ANDR_ROOT)/deps/irrlicht
|
||||||
IRRLICHT_LIB = $(IRRLICHT_DIR)/lib/Android/libIrrlicht.a
|
IRRLICHT_LIB = $(IRRLICHT_DIR)/lib/Android/libIrrlicht.a
|
||||||
IRRLICHT_TIMESTAMP = $(IRRLICHT_DIR)/timestamp
|
IRRLICHT_TIMESTAMP = $(IRRLICHT_DIR)/timestamp
|
||||||
IRRLICHT_TIMESTAMP_INT = $(ANDR_ROOT)/deps/irrlicht_timestamp
|
IRRLICHT_TIMESTAMP_INT = $(ANDR_ROOT)/deps/irrlicht_timestamp
|
||||||
IRRLICHT_URL_HTTP = https://github.com/zaki/irrlicht/archive/$(IRRLICHT_COMMIT).zip
|
IRRLICHT_URL_HTTP = https://github.com/zaki/irrlicht/archive/$(IRRLICHT_COMMIT).zip
|
||||||
|
|
||||||
CURL_VERSION = 7.64.0
|
CURL_VERSION = 7.64.1
|
||||||
CURL_DIR = $(ANDR_ROOT)/deps/curl
|
CURL_DIR = $(ANDR_ROOT)/deps/curl
|
||||||
CURL_LIB = $(CURL_DIR)/lib/.libs/libcurl.a
|
CURL_LIB = $(CURL_DIR)/lib/.libs/libcurl.a
|
||||||
CURL_TIMESTAMP = $(CURL_DIR)/timestamp
|
CURL_TIMESTAMP = $(CURL_DIR)/timestamp
|
||||||
|
@ -89,10 +89,9 @@ FREETYPE_DIR = $(ANDR_ROOT)/deps/freetype
|
||||||
FREETYPE_LIB = $(FREETYPE_DIR)/objs/.libs/libfreetype.a
|
FREETYPE_LIB = $(FREETYPE_DIR)/objs/.libs/libfreetype.a
|
||||||
FREETYPE_TIMESTAMP = $(FREETYPE_DIR)/timestamp
|
FREETYPE_TIMESTAMP = $(FREETYPE_DIR)/timestamp
|
||||||
FREETYPE_TIMESTAMP_INT = $(ANDR_ROOT)/deps/freetype_timestamp
|
FREETYPE_TIMESTAMP_INT = $(ANDR_ROOT)/deps/freetype_timestamp
|
||||||
FREETYPE_URL_HTTP = https://sourceforge.net/projects/freetype/files/freetype2/2.10.0/freetype-$(FREETYPE_VERSION).tar.bz2
|
FREETYPE_URL_HTTP = https://sourceforge.net/projects/freetype/files/freetype2/$(FREETYPE_VERSION)/freetype-$(FREETYPE_VERSION).tar.bz2
|
||||||
|
|
||||||
|
ICONV_VERSION = 1.16
|
||||||
ICONV_VERSION = 1.15
|
|
||||||
ICONV_DIR = $(ANDR_ROOT)/deps/libiconv
|
ICONV_DIR = $(ANDR_ROOT)/deps/libiconv
|
||||||
ICONV_URL_HTTP = https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$(ICONV_VERSION).tar.gz
|
ICONV_URL_HTTP = https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$(ICONV_VERSION).tar.gz
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'https://maven.google.com' }
|
maven { url 'https://maven.google.com' }
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
google()
|
||||||
dependencies {
|
}
|
||||||
classpath 'com.android.tools.build:gradle:3.3.1'
|
dependencies {
|
||||||
}
|
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'https://maven.google.com' }
|
maven { url 'https://maven.google.com' }
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
@ -20,12 +21,12 @@ android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
buildToolsVersion "28.0.3"
|
buildToolsVersion "28.0.3"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'mobi.MultiCraft'
|
applicationId 'com.multicraft.game'
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 114
|
versionCode 1
|
||||||
}
|
}
|
||||||
Properties props = new Properties()
|
Properties props = new Properties()
|
||||||
props.load(new FileInputStream(file("local.properties")))
|
props.load(new FileInputStream(file("local.properties")))
|
||||||
|
|
||||||
|
@ -39,23 +40,23 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||||
signingConfig signingConfigs.release
|
signingConfig signingConfigs.release
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for multiple APKs
|
// for multiple APKs
|
||||||
splits {
|
splits {
|
||||||
abi {
|
abi {
|
||||||
enable true
|
enable true
|
||||||
reset()
|
reset()
|
||||||
include "armeabi-v7a", "x86"
|
include "armeabi-v7a", "x86"
|
||||||
//include 'armeabi-v7a', 'arm64-v8a', 'x86'
|
//include 'armeabi-v7a', 'arm64-v8a', 'x86'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// build multiple APKs for all ABI
|
// build multiple APKs for all ABI
|
||||||
|
@ -64,16 +65,21 @@ ext.abiCodes = ['armeabi-v7a': 0, 'x86': 1]
|
||||||
import com.android.build.OutputFile
|
import com.android.build.OutputFile
|
||||||
|
|
||||||
android.applicationVariants.all { variant ->
|
android.applicationVariants.all { variant ->
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
def baseAbiVersionCode =
|
def baseAbiVersionCode =
|
||||||
project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
|
project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
|
||||||
if (baseAbiVersionCode != null) {
|
if (baseAbiVersionCode != null) {
|
||||||
output.versionCodeOverride =
|
output.versionCodeOverride =
|
||||||
baseAbiVersionCode + variant.versionCode
|
baseAbiVersionCode + variant.versionCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||||
|
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.0'
|
||||||
|
// Third-party libraries
|
||||||
|
implementation 'com.itlgl:iosdialog:1.0.0'
|
||||||
|
implementation 'gun0912.ted:tedpermission:2.2.2'
|
||||||
|
implementation 'org.apache.commons:commons-io:1.3.2'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#Fri Feb 22 20:02:06 CET 2019
|
#Mon Apr 22 16:21:42 CEST 2019
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
|
||||||
|
|
|
@ -1,22 +1,43 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="mobi.MultiCraft"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="com.multicraft.game"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
android:versionName="@string/ver">
|
android:versionName="@string/ver">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission
|
||||||
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
|
tools:node="replace" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||||
|
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.touchscreen"
|
||||||
|
android:required="false" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:fullBackupContent="@xml/my_backup_rules"
|
android:fullBackupContent="@xml/my_backup_rules"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name"
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
|
android:resizeableActivity="false"
|
||||||
|
tools:ignore="GoogleAppIndexingWarning">
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.max_aspect"
|
||||||
|
android:value="2.1" />
|
||||||
|
|
||||||
|
<uses-library
|
||||||
|
android:name="org.apache.http.legacy"
|
||||||
|
android:required="false" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name="com.multicraft.game.MainActivity"
|
||||||
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
|
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
|
||||||
android:screenOrientation="sensorLandscape"
|
android:screenOrientation="sensorLandscape"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
@ -26,7 +47,7 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".GameActivity"
|
android:name="com.multicraft.game.GameActivity"
|
||||||
android:configChanges="orientation|keyboard|keyboardHidden|navigation|screenSize|smallestScreenSize"
|
android:configChanges="orientation|keyboard|keyboardHidden|navigation|screenSize|smallestScreenSize"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
|
@ -41,12 +62,12 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".InputDialogActivity"
|
android:name="com.multicraft.game.InputDialogActivity"
|
||||||
android:theme="@style/Theme.Transparent"
|
android:theme="@style/Theme.Transparent"
|
||||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".UnzipService"
|
android:name="com.multicraft.game.UnzipService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
</application>
|
</application>
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
package com.multicraft.game;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
|
||||||
|
|
||||||
|
public class AlertDialogHelper {
|
||||||
|
private DialogsCallback sCallback = null;
|
||||||
|
private Drawable icon = null;
|
||||||
|
private String title = null;
|
||||||
|
private CharSequence message = null;
|
||||||
|
private String buttonPositive = null;
|
||||||
|
private String buttonNegative = null;
|
||||||
|
private String buttonNeutral = null;
|
||||||
|
private Activity activity;
|
||||||
|
|
||||||
|
AlertDialogHelper(Activity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(Drawable icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CharSequence getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMessage(CharSequence message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getButtonPositive() {
|
||||||
|
return buttonPositive;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setButtonPositive(String buttonPositive) {
|
||||||
|
this.buttonPositive = buttonPositive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getButtonNegative() {
|
||||||
|
return buttonNegative;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setButtonNegative(String buttonNegative) {
|
||||||
|
this.buttonNegative = buttonNegative;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getButtonNeutral() {
|
||||||
|
return buttonNeutral;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setButtonNeutral(String buttonNeutral) {
|
||||||
|
this.buttonNeutral = buttonNeutral;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setListener(DialogsCallback callback) {
|
||||||
|
sCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void showAlert(final String source) {
|
||||||
|
ContextThemeWrapper ctw = new ContextThemeWrapper(activity, R.style.CustomLollipopDialogStyle);
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
||||||
|
if (getIcon() != null) builder.setIcon(getIcon());
|
||||||
|
if (getTitle() != null) builder.setTitle(getTitle());
|
||||||
|
if (getMessage() != null) builder.setMessage(getMessage());
|
||||||
|
if (getButtonPositive() != null)
|
||||||
|
builder.setPositiveButton(getButtonPositive(), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
sCallback.onPositive(source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (getButtonNegative() != null)
|
||||||
|
builder.setNegativeButton(getButtonNegative(), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
sCallback.onNegative(source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (getButtonNeutral() != null)
|
||||||
|
builder.setNeutralButton(getButtonNeutral(), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
sCallback.onNeutral(source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setCancelable(false);
|
||||||
|
final AlertDialog dialog = builder.create();
|
||||||
|
if (!activity.isFinishing()) {
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
|
|
||||||
public interface CallBackListener {
|
public interface CallBackListener {
|
||||||
void updateViews(int text, int textVisibility, int progressVisibility);
|
void updateViews(int text, int textVisibility, int progressVisibility);
|
|
@ -1,8 +1,9 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -42,9 +43,9 @@ public class CheckConnectionTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
urlc.setRequestProperty("Connection", "close");
|
urlc.setRequestProperty("Connection", "close");
|
||||||
urlc.setConnectTimeout(timeout);
|
urlc.setConnectTimeout(timeout);
|
||||||
urlc.connect();
|
urlc.connect();
|
||||||
return urlc.getResponseCode() == 204 && urlc.getContentLength() == 0;
|
return urlc.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT && urlc.getContentLength() == 0;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("WTF", "IOException " + e.getMessage());
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -54,4 +55,3 @@ public class CheckConnectionTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
isGoogleAvailable("http://g.cn/generate_204", 1000);
|
isGoogleAvailable("http://g.cn/generate_204", 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,139 @@
|
||||||
|
package com.multicraft.game;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import static com.multicraft.game.MainActivity.unzipLocation;
|
||||||
|
|
||||||
|
public class CopyZipTask extends AsyncTask<String, Void, String[]> implements DialogsCallback {
|
||||||
|
|
||||||
|
private WeakReference<Context> contextRef;
|
||||||
|
private CallBackListener listener;
|
||||||
|
private boolean isCancel = false;
|
||||||
|
|
||||||
|
CopyZipTask(Context context) {
|
||||||
|
contextRef = new WeakReference<>(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] doInBackground(String... params) {
|
||||||
|
while (!isCancel) {
|
||||||
|
copyAssets(params);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String[] result) {
|
||||||
|
listener.updateViews(R.string.loading, View.VISIBLE, View.GONE);
|
||||||
|
startUnzipService(result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyAsset(String zipName) throws IOException {
|
||||||
|
String filename = zipName.substring(zipName.lastIndexOf("/") + 1);
|
||||||
|
InputStream in;
|
||||||
|
OutputStream out;
|
||||||
|
in = contextRef.get().getAssets().open(filename);
|
||||||
|
out = new FileOutputStream(zipName);
|
||||||
|
copyFile(in, out);
|
||||||
|
in.close();
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyAssets(String[] zips) {
|
||||||
|
try {
|
||||||
|
for (String zipName : zips) {
|
||||||
|
copyAsset(zipName);
|
||||||
|
}
|
||||||
|
isCancel = true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
isCancel = true;
|
||||||
|
cancel(true);
|
||||||
|
if (e.getMessage().contains("ENOSPC")) {
|
||||||
|
showRestartDialog("ENOSPC");
|
||||||
|
} else {
|
||||||
|
showRestartDialog("UKNWN");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 showRestartDialog(final String source) {
|
||||||
|
String message;
|
||||||
|
if ("ENOSPC".equals(source)) {
|
||||||
|
message = contextRef.get().getString(R.string.no_space);
|
||||||
|
} else {
|
||||||
|
message = contextRef.get().getString(R.string.restart);
|
||||||
|
}
|
||||||
|
final AlertDialogHelper dialogHelper = new AlertDialogHelper((Activity) contextRef.get());
|
||||||
|
dialogHelper.setListener(this);
|
||||||
|
dialogHelper.setMessage(message);
|
||||||
|
dialogHelper.setButtonPositive(contextRef.get().getString(android.R.string.ok));
|
||||||
|
((Activity) contextRef.get()).runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
dialogHelper.showAlert(source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restartApp() {
|
||||||
|
Context context = contextRef.get().getApplicationContext();
|
||||||
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
|
int mPendingIntentId = 1337;
|
||||||
|
PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
mgr.set(AlarmManager.RTC, System.currentTimeMillis(), mPendingIntent);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setListener(CallBackListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPositive(String source) {
|
||||||
|
restartApp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative(String source) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNeutral(String source) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -37,12 +40,10 @@ public class DeleteTask extends AsyncTask<String, Void, Void> {
|
||||||
private void deleteFiles(String path) {
|
private void deleteFiles(String path) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
String deleteCmd = "rm -r " + path;
|
|
||||||
Runtime runtime = Runtime.getRuntime();
|
|
||||||
try {
|
try {
|
||||||
runtime.exec(deleteCmd);
|
FileUtils.deleteDirectory(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("WTF", "delete files failed: " + e.getLocalizedMessage());
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
public interface DialogsCallback {
|
public interface DialogsCallback {
|
||||||
void onPositive(String source);
|
void onPositive(String source);
|
||||||
|
|
||||||
void onNegative(String source);
|
void onNegative(String source);
|
||||||
|
|
||||||
void onCancelled(String source);
|
void onNeutral(String source);
|
||||||
}
|
}
|
|
@ -1,20 +1,33 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.NativeActivity;
|
import android.app.NativeActivity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
|
/*import static com.multicraft.game.AdManager.initAd;
|
||||||
|
import static com.multicraft.game.AdManager.setAdsCallback;
|
||||||
|
import static com.multicraft.game.AdManager.startAd;
|
||||||
|
import static com.multicraft.game.AdManager.stopAd;*/
|
||||||
|
|
||||||
public class GameActivity extends NativeActivity {
|
public class GameActivity extends NativeActivity {
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("MultiCraft");
|
System.loadLibrary("MultiCraft");
|
||||||
|
//System.loadLibrary("c++_shared");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int messageReturnCode;
|
private int messageReturnCode;
|
||||||
private String messageReturnValue;
|
private String messageReturnValue;
|
||||||
private int height, width;
|
private int height, width;
|
||||||
|
private boolean consent;
|
||||||
|
|
||||||
public static native void putMessageBoxResult(String text);
|
public static native void putMessageBoxResult(String text);
|
||||||
|
|
||||||
|
@ -24,14 +37,13 @@ public class GameActivity extends NativeActivity {
|
||||||
Bundle bundle = getIntent().getExtras();
|
Bundle bundle = getIntent().getExtras();
|
||||||
height = bundle != null ? bundle.getInt("height", 0) : getResources().getDisplayMetrics().heightPixels;
|
height = bundle != null ? bundle.getInt("height", 0) : getResources().getDisplayMetrics().heightPixels;
|
||||||
width = bundle != null ? bundle.getInt("width", 0) : getResources().getDisplayMetrics().widthPixels;
|
width = bundle != null ? bundle.getInt("width", 0) : getResources().getDisplayMetrics().widthPixels;
|
||||||
// pf = PreferencesHelper.getInstance(this);
|
consent = bundle == null || bundle.getBoolean("consent", true);
|
||||||
// if (pf.isAdsEnabled()) setAdsCallbacks(this);
|
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
messageReturnCode = -1;
|
messageReturnCode = -1;
|
||||||
messageReturnValue = "";
|
messageReturnValue = "";
|
||||||
|
new AdInitTask().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void makeFullScreen() {
|
public void makeFullScreen() {
|
||||||
if (Build.VERSION.SDK_INT >= 19) {
|
if (Build.VERSION.SDK_INT >= 19) {
|
||||||
this.getWindow().getDecorView().setSystemUiVisibility(
|
this.getWindow().getDecorView().setSystemUiVisibility(
|
||||||
|
@ -51,10 +63,8 @@ public class GameActivity extends NativeActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onRestart() {
|
protected void onRestart() {
|
||||||
super.onRestart();
|
super.onRestart();
|
||||||
/*if (pf.isAdsEnabled()) {
|
/*stopAd();
|
||||||
stopAd();
|
startAd(this, false);*/
|
||||||
startAd(this, false);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,8 +76,7 @@ public class GameActivity extends NativeActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
/*if (pf.isAdsEnabled())
|
/*stopAd();*/
|
||||||
stopAd();*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,4 +132,42 @@ public class GameActivity extends NativeActivity {
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMemoryMax() {
|
||||||
|
ActivityManager actManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||||
|
if (actManager != null) {
|
||||||
|
actManager.getMemoryInfo(memInfo);
|
||||||
|
return (int) Math.floor(memInfo.totalMem / 1024 * 1024 * 1024 * 1.0);
|
||||||
|
} else {
|
||||||
|
Crashlytics.log(1, "RAM", "Cannot get RAM");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyServerConnect(boolean isMultiplayer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyAbortLoading() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyExitGame() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
class AdInitTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
/*initAd(GameActivity.this, consent);*/
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
/*setAdsCallback(GameActivity.this);*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -16,6 +16,7 @@ import android.view.View.OnKeyListener;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
|
||||||
public class InputDialogActivity extends Activity {
|
public class InputDialogActivity extends Activity {
|
||||||
private AlertDialog alertDialog;
|
private AlertDialog alertDialog;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
@ -15,15 +15,14 @@ import android.graphics.Bitmap;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v4.app.ActivityCompat;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -35,37 +34,43 @@ import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
import com.gun0912.tedpermission.PermissionListener;
|
||||||
|
import com.gun0912.tedpermission.TedPermission;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
||||||
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
||||||
|
import static com.multicraft.game.PreferencesHelper.TAG_BUILD_NUMBER;
|
||||||
import static mobi.MultiCraft.PreferencesHelper.TAG_BUILD_NUMBER;
|
import static com.multicraft.game.PreferencesHelper.TAG_CONSENT_ASKED;
|
||||||
import static mobi.MultiCraft.PreferencesHelper.TAG_CONSENT_ASKED;
|
import static com.multicraft.game.PreferencesHelper.TAG_COPY_WORLDS;
|
||||||
import static mobi.MultiCraft.PreferencesHelper.TAG_LAUNCH_TIMES;
|
import static com.multicraft.game.PreferencesHelper.TAG_LAUNCH_TIMES;
|
||||||
import static mobi.MultiCraft.PreferencesHelper.TAG_SHORTCUT_CREATED;
|
import static com.multicraft.game.PreferencesHelper.TAG_SHORTCUT_CREATED;
|
||||||
|
|
||||||
public class MainActivity extends Activity implements WVersionManager.ActivityListener, CallBackListener, DialogsCallback {
|
public class MainActivity extends Activity implements WVersionManager.ActivityListener, CallBackListener, DialogsCallback {
|
||||||
public final static int REQUEST_CODE = 104;
|
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";
|
private final static String CREATE_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
|
||||||
private final static String FILES = Environment.getExternalStorageDirectory() + "/Files.zip";
|
private final static String EXTERNAL_STORAGE = Environment.getExternalStorageDirectory().toString();
|
||||||
private final static String WORLDS = Environment.getExternalStorageDirectory() + "/worlds.zip";
|
private final static String FILES = EXTERNAL_STORAGE + "/Files.zip";
|
||||||
private final static String GAMES = Environment.getExternalStorageDirectory() + "/games.zip";
|
private final static String WORLDS = EXTERNAL_STORAGE + "/worlds.zip";
|
||||||
|
private final static String GAMES = EXTERNAL_STORAGE + "/games.zip";
|
||||||
private final static String NOMEDIA = ".nomedia";
|
private final static String NOMEDIA = ".nomedia";
|
||||||
private final static int COARSE_LOCATION_RESULT = 100;
|
private static final String UPDATE_LINK = "https://raw.githubusercontent.com/ubulem/coronahtml5/master/ver.txt";
|
||||||
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 static final String[] EU_COUNTRIES = new String[]{
|
private static final String[] EU_COUNTRIES = new String[]{
|
||||||
"AT", "BE", "BG", "HR", "CY", "CZ",
|
"AT", "BE", "BG", "HR", "CY", "CZ",
|
||||||
"DK", "EE", "FI", "FR", "DE", "GR",
|
"DK", "EE", "FI", "FR", "DE", "GR",
|
||||||
"HU", "IE", "IT", "LV", "LT", "LU",
|
"HU", "IE", "IT", "LV", "LT", "LU",
|
||||||
"MT", "NL", "PL", "PT", "RO", "SK",
|
"MT", "NL", "PL", "PT", "RO", "SK",
|
||||||
"SI", "ES", "SE", "GB", "IS", "LI", "NO"};
|
"SI", "ES", "SE", "GB", "IS", "LI", "NO"};
|
||||||
private static String dataFolder = "/Android/data/mobi.MultiCraft/files/";
|
private static String dataFolder = "/Android/data/com.multicraft.game/files/";
|
||||||
public static String unzipLocation = Environment.getExternalStorageDirectory() + dataFolder;
|
public static String unzipLocation = EXTERNAL_STORAGE + dataFolder;
|
||||||
|
private static String worldPath = EXTERNAL_STORAGE + "/Android/data/mobi.MultiCraft/files/worlds";
|
||||||
private int height, width;
|
private int height, width;
|
||||||
private boolean consent;
|
private boolean consent;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
|
@ -73,8 +78,6 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
private TextView mLoading;
|
private TextView mLoading;
|
||||||
private ImageView iv;
|
private ImageView iv;
|
||||||
private WVersionManager versionManager = null;
|
private WVersionManager versionManager = null;
|
||||||
private ConnectionDialogListener connListener;
|
|
||||||
private PermissionManager pm = null;
|
|
||||||
private PreferencesHelper pf;
|
private PreferencesHelper pf;
|
||||||
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -84,10 +87,15 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
progress = intent.getIntExtra(UnzipService.ACTION_PROGRESS, 0);
|
progress = intent.getIntExtra(UnzipService.ACTION_PROGRESS, 0);
|
||||||
}
|
}
|
||||||
if (progress >= 0) {
|
if (progress >= 0) {
|
||||||
mProgressBar.setVisibility(View.VISIBLE);
|
if (mProgressBar != null) {
|
||||||
mProgressBar.setProgress(progress);
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
mProgressBar.setProgress(progress);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
createNomedia();
|
createNomedia();
|
||||||
|
File folder = new File(worldPath);
|
||||||
|
if (folder.exists() && !pf.isWorldsCopied())
|
||||||
|
copyWorldsToNewFolder();
|
||||||
runGame();
|
runGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +115,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addLaunchTimes();
|
addLaunchTimes();
|
||||||
getPermissions();
|
askStoragePermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,6 +131,17 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
}
|
}
|
||||||
|
|
||||||
//helpful utilities
|
//helpful utilities
|
||||||
|
private void copyWorldsToNewFolder() {
|
||||||
|
File source = new File(worldPath);
|
||||||
|
File dest = new File(unzipLocation + "worlds");
|
||||||
|
try {
|
||||||
|
FileUtils.copyDirectory(source, dest);
|
||||||
|
pf.saveSettings(TAG_COPY_WORLDS, true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addLaunchTimes() {
|
private void addLaunchTimes() {
|
||||||
int i = pf.getLaunchTimes();
|
int i = pf.getLaunchTimes();
|
||||||
i++;
|
i++;
|
||||||
|
@ -149,7 +168,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
try {
|
try {
|
||||||
myFile.createNewFile();
|
myFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "nomedia has not been created: " + e.getMessage());
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +198,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
addIntent.setAction(CREATE_SHORTCUT);
|
addIntent.setAction(CREATE_SHORTCUT);
|
||||||
getApplicationContext().sendBroadcast(addIntent);
|
getApplicationContext().sendBroadcast(addIntent);
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
Log.e(TAG, "Shortcut cannot be created");
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +250,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
}
|
}
|
||||||
|
|
||||||
private void askGdpr() {
|
private void askGdpr() {
|
||||||
if (pf.isAskConsent() && isGdprSubject() && pf.isAdsEnabled())
|
if (pf.isAskConsent() && isGdprSubject())
|
||||||
showGdprDialog();
|
showGdprDialog();
|
||||||
else {
|
else {
|
||||||
consent = true;
|
consent = true;
|
||||||
|
@ -240,74 +259,149 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
RateMe.onStart(this);
|
|
||||||
if (pf.isCreateShortcut() && Build.VERSION.SDK_INT < 26)
|
|
||||||
addShortcut();
|
|
||||||
mProgressBar = findViewById(R.id.PB1);
|
mProgressBar = findViewById(R.id.PB1);
|
||||||
mProgressBarIndeterminate = findViewById(R.id.PB2);
|
mProgressBarIndeterminate = findViewById(R.id.PB2);
|
||||||
mLoading = findViewById(R.id.tv_progress_circle);
|
mLoading = findViewById(R.id.tv_progress_circle);
|
||||||
Drawable draw = ContextCompat.getDrawable(this, R.drawable.custom_progress_bar);
|
Drawable draw = ContextCompat.getDrawable(this, R.drawable.custom_progress_bar);
|
||||||
mProgressBar.setProgressDrawable(draw);
|
mProgressBar.setProgressDrawable(draw);
|
||||||
connListener = new ConnectionDialogListener();
|
RateMe.onStart(this);
|
||||||
|
if (pf.isCreateShortcut() && Build.VERSION.SDK_INT < 26)
|
||||||
|
addShortcut();
|
||||||
createDataFolder();
|
createDataFolder();
|
||||||
checkAppVersion();
|
checkAppVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
//permission block
|
//permission block
|
||||||
private void getPermissions() {
|
private void askStoragePermissions() {
|
||||||
pm = new PermissionManager(this);
|
PermissionListener permissionlistener = new PermissionListener() {
|
||||||
String[] permList = pm.requestPermissions();
|
@Override
|
||||||
if (permList.length > 0) {
|
public void onPermissionGranted() {
|
||||||
ActivityCompat.requestPermissions(this, permList, ALL_PERMISSIONS_RESULT);
|
if (pf.getLaunchTimes() % 3 == 1) {
|
||||||
} else {
|
askLocationPermissions();
|
||||||
askGdpr();
|
} else askGdpr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPermissionDenied(List<String> deniedPermissions) {
|
||||||
|
if (TedPermission.canRequestPermission(MainActivity.this, WRITE_EXTERNAL_STORAGE))
|
||||||
|
askStorageRationalePermissions();
|
||||||
|
else askStorageWhenDoNotShow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TedPermission.with(this)
|
||||||
|
.setPermissionListener(permissionlistener)
|
||||||
|
.setPermissions(WRITE_EXTERNAL_STORAGE)
|
||||||
|
.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestPermissionAfterExplain() {
|
//storage permissions block
|
||||||
Toast.makeText(this, R.string.explain, Toast.LENGTH_LONG).show();
|
private void askStorageRationalePermissions() {
|
||||||
ActivityCompat.requestPermissions(MainActivity.this,
|
PermissionListener permissionlistener = new PermissionListener() {
|
||||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_RESULT);
|
@Override
|
||||||
|
public void onPermissionGranted() {
|
||||||
|
if (pf.getLaunchTimes() % 3 == 1) {
|
||||||
|
askLocationPermissions();
|
||||||
|
} else askGdpr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPermissionDenied(List<String> deniedPermissions) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TedPermission.with(this)
|
||||||
|
.setPermissionListener(permissionlistener)
|
||||||
|
.setPermissions(WRITE_EXTERNAL_STORAGE)
|
||||||
|
.setRationaleMessage(R.string.explain)
|
||||||
|
.setDeniedMessage(R.string.denied)
|
||||||
|
.setDeniedCloseButtonText(R.string.close_game)
|
||||||
|
.setGotoSettingButtonText(R.string.settings)
|
||||||
|
.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestStoragePermission() {
|
private void askStorageWhenDoNotShow() {
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
PermissionListener permissionlistener = new PermissionListener() {
|
||||||
requestPermissionAfterExplain();
|
@Override
|
||||||
} else {
|
public void onPermissionGranted() {
|
||||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
if (pf.getLaunchTimes() % 3 == 1) {
|
||||||
WRITE_EXTERNAL_RESULT);
|
askLocationPermissions();
|
||||||
}
|
} else askGdpr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPermissionDenied(List<String> deniedPermissions) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TedPermission.with(this)
|
||||||
|
.setPermissionListener(permissionlistener)
|
||||||
|
.setPermissions(WRITE_EXTERNAL_STORAGE)
|
||||||
|
.setDeniedMessage(R.string.denied)
|
||||||
|
.setDeniedCloseButtonText(R.string.close_game)
|
||||||
|
.setGotoSettingButtonText(R.string.settings)
|
||||||
|
.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
//location permissions block
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
private void askLocationPermissions() {
|
||||||
@NonNull int[] grantResults) {
|
PermissionListener permissionlistener = new PermissionListener() {
|
||||||
switch (requestCode) {
|
@Override
|
||||||
case WRITE_EXTERNAL_RESULT:
|
public void onPermissionGranted() {
|
||||||
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
askGdpr();
|
||||||
askGdpr();
|
}
|
||||||
} else {
|
|
||||||
requestStoragePermission();
|
@Override
|
||||||
}
|
public void onPermissionDenied(List<String> deniedPermissions) {
|
||||||
break;
|
if (TedPermission.canRequestPermission(MainActivity.this, ACCESS_COARSE_LOCATION))
|
||||||
case COARSE_LOCATION_RESULT:
|
askLocationRationalePermissions();
|
||||||
break;
|
else askLocationWhenDoNotShow();
|
||||||
case ALL_PERMISSIONS_RESULT:
|
}
|
||||||
for (String perms : PermissionManager.permissionsToRequest) {
|
};
|
||||||
if (!pm.hasPermission(perms)) {
|
TedPermission.with(this)
|
||||||
PermissionManager.permissionsRejected.add(perms);
|
.setPermissionListener(permissionlistener)
|
||||||
}
|
.setPermissions(ACCESS_COARSE_LOCATION)
|
||||||
}
|
.check();
|
||||||
if (PermissionManager.permissionsRejected.size() == 0) {
|
}
|
||||||
askGdpr();
|
|
||||||
} else if (!Arrays.asList(PermissionManager.permissionsRejected.toArray()).contains(WRITE_EXTERNAL_STORAGE)) {
|
private void askLocationRationalePermissions() {
|
||||||
Toast.makeText(this, R.string.location, Toast.LENGTH_SHORT).show();
|
PermissionListener permissionlistener = new PermissionListener() {
|
||||||
askGdpr();
|
@Override
|
||||||
} else {
|
public void onPermissionGranted() {
|
||||||
requestStoragePermission();
|
askGdpr();
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
@Override
|
||||||
|
public void onPermissionDenied(List<String> deniedPermissions) {
|
||||||
|
askGdpr();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TedPermission.with(this)
|
||||||
|
.setPermissionListener(permissionlistener)
|
||||||
|
.setPermissions(ACCESS_COARSE_LOCATION)
|
||||||
|
.setRationaleMessage(R.string.location)
|
||||||
|
.check();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void askLocationWhenDoNotShow() {
|
||||||
|
PermissionListener permissionlistener = new PermissionListener() {
|
||||||
|
@Override
|
||||||
|
public void onPermissionGranted() {
|
||||||
|
if (pf.getLaunchTimes() % 3 == 1) {
|
||||||
|
askLocationPermissions();
|
||||||
|
} else askGdpr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPermissionDenied(List<String> deniedPermissions) {
|
||||||
|
askGdpr();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TedPermission.with(this)
|
||||||
|
.setPermissionListener(permissionlistener)
|
||||||
|
.setPermissions(ACCESS_COARSE_LOCATION)
|
||||||
|
.setDeniedMessage(R.string.location)
|
||||||
|
.setGotoSettingButtonText(R.string.settings)
|
||||||
|
.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
//game logic
|
//game logic
|
||||||
|
@ -317,8 +411,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
RateMe.showRateDialog();
|
RateMe.showRateDialog();
|
||||||
RateMe.setListener(this);
|
RateMe.setListener(this);
|
||||||
} else {
|
} else {
|
||||||
// startBillingActivity();
|
getNativeResolutionAndStart();
|
||||||
startNative();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,26 +432,34 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getNativeResolutionAndStart() {
|
||||||
|
getDefaultResolution();
|
||||||
|
startNative();
|
||||||
|
}
|
||||||
|
|
||||||
private void runGame() {
|
private void runGame() {
|
||||||
deleteZip(FILES, WORLDS, GAMES);
|
deleteZip(FILES, WORLDS, GAMES);
|
||||||
pf.saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
pf.saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||||
CheckConnectionTask cct = new CheckConnectionTask(this);
|
final CheckConnectionTask cct = new CheckConnectionTask(this);
|
||||||
cct.setListener(this);
|
cct.setListener(this);
|
||||||
cct.execute();
|
cct.execute();
|
||||||
|
Handler handler = new Handler();
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (cct.getStatus() == AsyncTask.Status.RUNNING) {
|
||||||
|
cct.cancel(true);
|
||||||
|
onEvent("CheckConnectionTask", "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private void startBillingActivity() {
|
|
||||||
Intent intent = new Intent(this, BillingActivity.class);
|
|
||||||
startActivityForResult(intent, REQUEST_CODE);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private void startNative() {
|
private void startNative() {
|
||||||
/*if (pf.isAdsEnabled()) {
|
|
||||||
initAd(MainActivity.this, consent);
|
|
||||||
}*/
|
|
||||||
Intent intent = new Intent(this, GameActivity.class);
|
Intent intent = new Intent(this, GameActivity.class);
|
||||||
intent.putExtra("height", height);
|
intent.putExtra("height", height);
|
||||||
intent.putExtra("width", width);
|
intent.putExtra("width", width);
|
||||||
|
intent.putExtra("consent", consent);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
@ -375,8 +476,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
getDefaultResolution();
|
getNativeResolutionAndStart();
|
||||||
startNative();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareToRun(boolean isAll) {
|
private void prepareToRun(boolean isAll) {
|
||||||
|
@ -385,12 +485,12 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
if (isAll) {
|
if (isAll) {
|
||||||
dt.execute(unzipLocation);
|
dt.execute(unzipLocation);
|
||||||
} else {
|
} else {
|
||||||
dt.execute(unzipLocation + "builtin", unzipLocation + "games", unzipLocation + "textures", unzipLocation + "debug.txt");
|
dt.execute(unzipLocation + "builtin", unzipLocation + "games", unzipLocation + "textures"/*, unzipLocation + "debug.txt"*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAppVersion() {
|
private void checkAppVersion() {
|
||||||
if (!pf.isRestored() && pf.getBuildNumber().equals(getString(R.string.ver))) {
|
if (pf.getBuildNumber().equals(getString(R.string.ver))) {
|
||||||
addImageView(1);
|
addImageView(1);
|
||||||
runGame();
|
runGame();
|
||||||
} else if (pf.getBuildNumber().equals("0")) {
|
} else if (pf.getBuildNumber().equals("0")) {
|
||||||
|
@ -433,7 +533,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.CustomLollipopDialogStyle);
|
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.CustomLollipopDialogStyle);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
View dialogView = inflater.inflate(R.layout.gdpr_dialog, null);
|
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.gdpr_dialog, null);
|
||||||
builder.setView(dialogView)
|
builder.setView(dialogView)
|
||||||
.setPositiveButton(R.string.gdpr_agree, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.gdpr_agree, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -463,26 +563,21 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
}
|
}
|
||||||
|
|
||||||
void showConnectionDialog() {
|
void showConnectionDialog() {
|
||||||
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.CustomLollipopDialogStyle);
|
AlertDialogHelper dialogHelper = new AlertDialogHelper(this);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
dialogHelper.setListener(this);
|
||||||
builder.setMessage(getString(R.string.conn_message));
|
dialogHelper.setMessage(getString(R.string.conn_message));
|
||||||
|
dialogHelper.setButtonPositive(getString(R.string.conn_wifi));
|
||||||
builder.setPositiveButton(getString(R.string.conn_wifi), connListener);
|
dialogHelper.setButtonNegative(getString(R.string.conn_mobile));
|
||||||
builder.setNegativeButton(getString(R.string.conn_mobile), connListener);
|
dialogHelper.setButtonNeutral(getString(R.string.ignore));
|
||||||
builder.setNeutralButton(getString(R.string.ignore), connListener);
|
dialogHelper.showAlert("ConnectionDialog");
|
||||||
|
|
||||||
builder.setCancelable(false);
|
|
||||||
|
|
||||||
AlertDialog dialog = builder.create();
|
|
||||||
if (!isFinishing()) {
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPositive(String source) {
|
public void onPositive(String source) {
|
||||||
if ("RateMe".equals(source)) {
|
if ("RateMe".equals(source)) {
|
||||||
finish();
|
finish();
|
||||||
|
} else if ("ConnectionDialog".equals(source)) {
|
||||||
|
startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS), REQUEST_CODE);
|
||||||
} else {
|
} else {
|
||||||
versionManager.updateNow(versionManager.getUpdateUrl());
|
versionManager.updateNow(versionManager.getUpdateUrl());
|
||||||
finish();
|
finish();
|
||||||
|
@ -493,8 +588,9 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
public void onNegative(String source) {
|
public void onNegative(String source) {
|
||||||
if ("RateMe".equals(source)) {
|
if ("RateMe".equals(source)) {
|
||||||
Toast.makeText(MainActivity.this, R.string.sad, Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.this, R.string.sad, Toast.LENGTH_LONG).show();
|
||||||
// startBillingActivity();
|
getNativeResolutionAndStart();
|
||||||
startNative();
|
} else if ("ConnectionDialog".equals(source)) {
|
||||||
|
startActivityForResult(new Intent(Settings.ACTION_WIRELESS_SETTINGS), REQUEST_CODE);
|
||||||
} else {
|
} else {
|
||||||
versionManager.ignoreThisVersion();
|
versionManager.ignoreThisVersion();
|
||||||
checkRateDialog();
|
checkRateDialog();
|
||||||
|
@ -502,32 +598,15 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(String source) {
|
public void onNeutral(String source) {
|
||||||
if ("RateMe".equals(source)) {
|
if ("RateMe".equals(source)) {
|
||||||
// startBillingActivity();
|
getNativeResolutionAndStart();
|
||||||
startNative();
|
} else if ("ConnectionDialog".equals(source)) {
|
||||||
|
getNativeResolutionAndStart();
|
||||||
} else {
|
} else {
|
||||||
versionManager.remindMeLater(versionManager.getReminderTimer());
|
versionManager.remindMeLater(versionManager.getReminderTimer());
|
||||||
checkRateDialog();
|
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:
|
|
||||||
getDefaultResolution();
|
|
||||||
startNative();
|
|
||||||
break;
|
|
||||||
case AlertDialog.BUTTON_NEGATIVE:
|
|
||||||
startActivityForResult(new Intent(Settings.ACTION_WIRELESS_SETTINGS), REQUEST_CODE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -8,11 +8,12 @@ class PreferencesHelper {
|
||||||
static final String TAG_BUILD_NUMBER = "buildNumber";
|
static final String TAG_BUILD_NUMBER = "buildNumber";
|
||||||
static final String TAG_LAUNCH_TIMES = "launchTimes";
|
static final String TAG_LAUNCH_TIMES = "launchTimes";
|
||||||
static final String TAG_CONSENT_ASKED = "consentAsked";
|
static final String TAG_CONSENT_ASKED = "consentAsked";
|
||||||
static final String TAG_RESTORE_BACKUP = "restoredFromBackup";
|
static final String TAG_COPY_WORLDS = "copyWorlds";
|
||||||
static final String IS_LOADED = "interstitialLoaded";
|
static final String IS_LOADED = "interstitialLoaded";
|
||||||
static final String RV_LOADED = "rewardedVideoLoaded";
|
static final String RV_LOADED = "rewardedVideoLoaded";
|
||||||
|
static final String ADS_DELAY = "adsDelay";
|
||||||
|
static final String ADS_REPEAT = "adsRepeat";
|
||||||
private static final String SETTINGS = "MultiCraftSettings";
|
private static final String SETTINGS = "MultiCraftSettings";
|
||||||
private static final String TAG_DISABLED_ADS = "disabledADS";
|
|
||||||
|
|
||||||
private static PreferencesHelper instance;
|
private static PreferencesHelper instance;
|
||||||
private static SharedPreferences sharedPreferences;
|
private static SharedPreferences sharedPreferences;
|
||||||
|
@ -49,26 +50,26 @@ class PreferencesHelper {
|
||||||
return sharedPreferences.getBoolean(TAG_CONSENT_ASKED, true);
|
return sharedPreferences.getBoolean(TAG_CONSENT_ASKED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isRestored() {
|
boolean isWorldsCopied() {
|
||||||
return sharedPreferences.getBoolean(TAG_RESTORE_BACKUP, false);
|
return sharedPreferences.getBoolean(TAG_COPY_WORLDS, true);
|
||||||
}
|
|
||||||
|
|
||||||
boolean isAdsEnabled() {
|
|
||||||
return !sharedPreferences.getBoolean(TAG_DISABLED_ADS, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getBuildNumber() {
|
String getBuildNumber() {
|
||||||
return sharedPreferences.getString(TAG_BUILD_NUMBER, "0");
|
return sharedPreferences.getString(TAG_BUILD_NUMBER, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void savePurchase(boolean v) {
|
|
||||||
sharedPreferences.edit().putBoolean(TAG_DISABLED_ADS, v).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
int getLaunchTimes() {
|
int getLaunchTimes() {
|
||||||
return sharedPreferences.getInt(TAG_LAUNCH_TIMES, 0);
|
return sharedPreferences.getInt(TAG_LAUNCH_TIMES, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getAdsDelay() {
|
||||||
|
return sharedPreferences.getInt(ADS_DELAY, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getAdsRepeat() {
|
||||||
|
return sharedPreferences.getInt(ADS_REPEAT, 300);
|
||||||
|
}
|
||||||
|
|
||||||
void saveSettings(String tag, boolean bool) {
|
void saveSettings(String tag, boolean bool) {
|
||||||
sharedPreferences.edit().putBoolean(tag, bool).apply();
|
sharedPreferences.edit().putBoolean(tag, bool).apply();
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
@ -20,7 +20,7 @@ import java.util.Date;
|
||||||
|
|
||||||
class RateMe {
|
class RateMe {
|
||||||
|
|
||||||
private static final int INSTALL_DAYS = 2;
|
private static final int INSTALL_DAYS = 3;
|
||||||
private static final int LAUNCH_TIMES = 3;
|
private static final int LAUNCH_TIMES = 3;
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
private static final String TAG = RateMe.class.getSimpleName();
|
private static final String TAG = RateMe.class.getSimpleName();
|
||||||
|
@ -91,7 +91,7 @@ class RateMe {
|
||||||
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
|
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
|
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
|
||||||
if (rating >= 3) {
|
if (rating >= 4) {
|
||||||
if (sCallback != null) {
|
if (sCallback != null) {
|
||||||
sCallback.onPositive("RateMe");
|
sCallback.onPositive("RateMe");
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ class RateMe {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
if (sCallback != null) {
|
if (sCallback != null) {
|
||||||
sCallback.onCancelled("RateMe");
|
sCallback.onNeutral("RateMe");
|
||||||
}
|
}
|
||||||
clearSharedPreferences(activity);
|
clearSharedPreferences(activity);
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
class Transliteration {
|
class Transliteration {
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class Transliteration {
|
||||||
* Не русские символы останутся прежними.
|
* Не русские символы останутся прежними.
|
||||||
*/
|
*/
|
||||||
static String toLatin(String text) {
|
static String toLatin(String text) {
|
||||||
char charBuffer[] = text.toCharArray();
|
char[] charBuffer = text.toCharArray();
|
||||||
StringBuilder sb = new StringBuilder(text.length());
|
StringBuilder sb = new StringBuilder(text.length());
|
||||||
for (char symbol : charBuffer) {
|
for (char symbol : charBuffer) {
|
||||||
int i = symbol - START_CHAR;
|
int i = symbol - START_CHAR;
|
|
@ -1,4 +1,4 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
import android.app.IntentService;
|
import android.app.IntentService;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
@ -7,9 +7,9 @@ import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -26,17 +26,24 @@ public class UnzipService extends IntentService {
|
||||||
public static final String ACTION_PROGRESS = "progress";
|
public static final String ACTION_PROGRESS = "progress";
|
||||||
private NotificationManager mNotifyManager;
|
private NotificationManager mNotifyManager;
|
||||||
private int id = 1;
|
private int id = 1;
|
||||||
private int percent = 0;
|
|
||||||
private int size;
|
|
||||||
|
|
||||||
public UnzipService() {
|
public UnzipService() {
|
||||||
super("mobi.MultiCraft.UnzipService");
|
super("com.multicraft.game.UnzipService");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void isDir(String dir, String unzipLocation) {
|
||||||
|
File f = new File(unzipLocation + dir);
|
||||||
|
|
||||||
|
if (!f.isDirectory()) {
|
||||||
|
f.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
createNotification();
|
createNotification();
|
||||||
unzipLoop(intent);
|
unzip(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,51 +85,44 @@ public class UnzipService extends IntentService {
|
||||||
mNotifyManager.notify(id, builder.build());
|
mNotifyManager.notify(id, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unzipLoop(Intent intent) {
|
private void unzip(Intent intent) {
|
||||||
String[] zips = intent.getStringArrayExtra(EXTRA_KEY_IN_FILE);
|
String[] file = intent.getStringArrayExtra(EXTRA_KEY_IN_FILE);
|
||||||
String location = intent.getStringExtra(EXTRA_KEY_IN_LOCATION);
|
String location = intent.getStringExtra(EXTRA_KEY_IN_LOCATION);
|
||||||
size = getSummarySize(zips);
|
int per = 0;
|
||||||
try {
|
int size = getSummarySize(file);
|
||||||
for (String z : zips) {
|
for (String f : file) {
|
||||||
unzipFile(z, location);
|
try {
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e("WTF", e.getMessage() == null ? "Unzip failed" : e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("TryFinallyCanBeTryWithResources")
|
|
||||||
private void unzipFile(String zipFile, String targetDirectory) throws IOException {
|
|
||||||
ZipInputStream zis = new ZipInputStream(
|
|
||||||
new BufferedInputStream(new FileInputStream(zipFile)));
|
|
||||||
try {
|
|
||||||
ZipEntry ze;
|
|
||||||
int count;
|
|
||||||
byte[] buffer = new byte[8192];
|
|
||||||
while ((ze = zis.getNextEntry()) != null) {
|
|
||||||
File file = new File(targetDirectory, ze.getName());
|
|
||||||
File dir = ze.isDirectory() ? file : file.getParentFile();
|
|
||||||
if (!dir.isDirectory() && !dir.mkdirs())
|
|
||||||
throw new FileNotFoundException("Failed to ensure directory: " +
|
|
||||||
dir.getAbsolutePath());
|
|
||||||
if (ze.isDirectory()) {
|
|
||||||
percent++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
|
||||||
try {
|
try {
|
||||||
while ((count = zis.read(buffer)) != -1) {
|
FileInputStream fin = new FileInputStream(f);
|
||||||
fileOutputStream.write(buffer, 0, count);
|
ZipInputStream zin = new ZipInputStream(fin);
|
||||||
percent++;
|
ZipEntry ze;
|
||||||
int progress = 100 * percent / size;
|
while ((ze = zin.getNextEntry()) != null) {
|
||||||
publishProgress(progress);
|
if (ze.isDirectory()) {
|
||||||
|
per++;
|
||||||
|
isDir(ze.getName(), location);
|
||||||
|
} else {
|
||||||
|
per++;
|
||||||
|
int progress = 100 * per / size;
|
||||||
|
// send update
|
||||||
|
publishProgress(progress);
|
||||||
|
FileOutputStream f_out = new FileOutputStream(location + ze.getName());
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
int len;
|
||||||
|
while ((len = zin.read(buffer)) != -1) {
|
||||||
|
f_out.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
f_out.close();
|
||||||
|
zin.closeEntry();
|
||||||
|
f_out.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
zin.close();
|
||||||
fileOutputStream.close();
|
} catch (FileNotFoundException e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
zis.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ public class UnzipService extends IntentService {
|
||||||
ZipFile zipSize = new ZipFile(z);
|
ZipFile zipSize = new ZipFile(z);
|
||||||
size += zipSize.size();
|
size += zipSize.size();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("WTF", e.getMessage() == null ? "Unzip failed" : e.getMessage());
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
|
@ -1,9 +1,8 @@
|
||||||
package mobi.MultiCraft;
|
package com.multicraft.game;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
@ -13,8 +12,8 @@ import android.os.AsyncTask;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.ContextThemeWrapper;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -31,8 +30,8 @@ import java.net.URL;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
class WVersionManager {
|
|
||||||
private static final String TAG = "WVersionManager";
|
class WVersionManager implements DialogsCallback {
|
||||||
private DialogsCallback sCallback = null;
|
private DialogsCallback sCallback = null;
|
||||||
private CustomTagHandler customTagHandler;
|
private CustomTagHandler customTagHandler;
|
||||||
private String PREF_IGNORE_VERSION_CODE = "w.ignore.version.code";
|
private String PREF_IGNORE_VERSION_CODE = "w.ignore.version.code";
|
||||||
|
@ -42,21 +41,14 @@ class WVersionManager {
|
||||||
private Drawable icon;
|
private Drawable icon;
|
||||||
private String title;
|
private String title;
|
||||||
private String message;
|
private String message;
|
||||||
private String updateNowLabel;
|
|
||||||
private String remindMeLaterLabel;
|
|
||||||
private String ignoreThisVersionLabel;
|
|
||||||
private String updateUrl;
|
private String updateUrl;
|
||||||
private String versionContentUrl;
|
private String versionContentUrl;
|
||||||
private int reminderTimer;
|
|
||||||
private int mVersionCode;
|
private int mVersionCode;
|
||||||
private AlertDialogButtonListener listener;
|
|
||||||
private boolean mDialogCancelable = false;
|
|
||||||
private ActivityListener al;
|
private ActivityListener al;
|
||||||
|
|
||||||
WVersionManager(Activity act) {
|
WVersionManager(Activity act) {
|
||||||
this.activity = act;
|
this.activity = act;
|
||||||
al = (ActivityListener) act;
|
al = (ActivityListener) act;
|
||||||
this.listener = new AlertDialogButtonListener();
|
|
||||||
this.customTagHandler = new CustomTagHandler();
|
this.customTagHandler = new CustomTagHandler();
|
||||||
setLaunchTimes();
|
setLaunchTimes();
|
||||||
}
|
}
|
||||||
|
@ -72,7 +64,7 @@ class WVersionManager {
|
||||||
void checkVersion() {
|
void checkVersion() {
|
||||||
String versionContentUrl = getVersionContentUrl();
|
String versionContentUrl = getVersionContentUrl();
|
||||||
if (versionContentUrl == null) {
|
if (versionContentUrl == null) {
|
||||||
Log.e(TAG, "Please set versionContentUrl first");
|
Crashlytics.log("Please set versionContentUrl first");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,22 +81,15 @@ class WVersionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
void showDialog() {
|
void showDialog() {
|
||||||
ContextThemeWrapper ctw = new ContextThemeWrapper(activity, R.style.CustomLollipopDialogStyle);
|
AlertDialogHelper dialogHelper = new AlertDialogHelper(activity);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
|
dialogHelper.setListener(this);
|
||||||
builder.setIcon(getIcon());
|
dialogHelper.setIcon(getIcon());
|
||||||
builder.setTitle(getTitle());
|
dialogHelper.setTitle(getTitle());
|
||||||
builder.setMessage(Html.fromHtml(getMessage(), null, getCustomTagHandler()));
|
dialogHelper.setMessage(Html.fromHtml(getMessage(), null, getCustomTagHandler()));
|
||||||
|
dialogHelper.setButtonPositive(getUpdateNowLabel());
|
||||||
builder.setPositiveButton(getUpdateNowLabel(), listener);
|
dialogHelper.setButtonNeutral(getRemindMeLaterLabel());
|
||||||
builder.setNeutralButton(getRemindMeLaterLabel(), listener);
|
dialogHelper.setButtonNegative(getIgnoreThisVersionLabel());
|
||||||
builder.setNegativeButton(getIgnoreThisVersionLabel(), listener);
|
dialogHelper.showAlert("WVersionManager");
|
||||||
|
|
||||||
builder.setCancelable(isDialogCancelable());
|
|
||||||
|
|
||||||
AlertDialog dialog = builder.create();
|
|
||||||
if (activity != null && !activity.isFinishing()) {
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLaunchTimes() {
|
private void setLaunchTimes() {
|
||||||
|
@ -115,27 +100,15 @@ class WVersionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUpdateNowLabel() {
|
private String getUpdateNowLabel() {
|
||||||
return updateNowLabel != null ? updateNowLabel : activity.getString(R.string.update);
|
return activity.getString(R.string.update);
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdateNowLabel(String updateNowLabel) {
|
|
||||||
this.updateNowLabel = updateNowLabel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRemindMeLaterLabel() {
|
private String getRemindMeLaterLabel() {
|
||||||
return remindMeLaterLabel != null ? remindMeLaterLabel : activity.getString(R.string.later);
|
return activity.getString(R.string.later);
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemindMeLaterLabel(String remindMeLaterLabel) {
|
|
||||||
this.remindMeLaterLabel = remindMeLaterLabel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIgnoreThisVersionLabel() {
|
private String getIgnoreThisVersionLabel() {
|
||||||
return ignoreThisVersionLabel != null ? ignoreThisVersionLabel : activity.getString(R.string.ignore);
|
return activity.getString(R.string.ignore);
|
||||||
}
|
|
||||||
|
|
||||||
public void setIgnoreThisVersionLabel(String ignoreThisVersionLabel) {
|
|
||||||
this.ignoreThisVersionLabel = ignoreThisVersionLabel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMessage() {
|
private String getMessage() {
|
||||||
|
@ -181,13 +154,7 @@ class WVersionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
int getReminderTimer() {
|
int getReminderTimer() {
|
||||||
return reminderTimer > 0 ? reminderTimer : 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
public void setReminderTimer(int minutes) {
|
|
||||||
if (minutes > 0) {
|
|
||||||
reminderTimer = minutes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateNow(String url) {
|
void updateNow(String url) {
|
||||||
|
@ -197,7 +164,7 @@ class WVersionManager {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "is update url correct?" + e);
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,43 +222,26 @@ class WVersionManager {
|
||||||
return customTagHandler;
|
return customTagHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDialogCancelable() {
|
@Override
|
||||||
return mDialogCancelable;
|
public void onPositive(String source) {
|
||||||
|
sCallback.onPositive("WVersionManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDialogCancelable(boolean dialogCancelable) {
|
@Override
|
||||||
mDialogCancelable = dialogCancelable;
|
public void onNegative(String source) {
|
||||||
|
sCallback.onNegative("WVersionManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNeutral(String source) {
|
||||||
|
sCallback.onNeutral("WVersionManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ActivityListener {
|
interface ActivityListener {
|
||||||
void isShowUpdateDialog(boolean flag);
|
void isShowUpdateDialog(boolean flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AlertDialogButtonListener implements DialogInterface.OnClickListener {
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
switch (which) {
|
|
||||||
case AlertDialog.BUTTON_POSITIVE:
|
|
||||||
if (sCallback != null) {
|
|
||||||
sCallback.onPositive("WVersionManager");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case AlertDialog.BUTTON_NEUTRAL:
|
|
||||||
if (sCallback != null) {
|
|
||||||
sCallback.onCancelled("WVersionManager");
|
|
||||||
}
|
|
||||||
remindMeLater(getReminderTimer());
|
|
||||||
break;
|
|
||||||
case AlertDialog.BUTTON_NEGATIVE:
|
|
||||||
if (sCallback != null) {
|
|
||||||
sCallback.onNegative("WVersionManager");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class VersionContentRequest extends AsyncTask<String, Void, String> {
|
private class VersionContentRequest extends AsyncTask<String, Void, String> {
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
|
@ -316,22 +266,22 @@ class WVersionManager {
|
||||||
result = bo.toString();
|
result = bo.toString();
|
||||||
bo.close();
|
bo.close();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
Log.e("WTF", "Malformed content: " + e.getMessage());
|
Crashlytics.logException(e);
|
||||||
} catch (ProtocolException e) {
|
} catch (ProtocolException e) {
|
||||||
Log.e("WTF", "Protocol error: " + e.getMessage());
|
Crashlytics.logException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("WTF", "IO error: " + e.getMessage());
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String result) {
|
protected void onPostExecute(String result) {
|
||||||
|
PreferencesHelper pf = PreferencesHelper.getInstance(activity);
|
||||||
mVersionCode = 0;
|
mVersionCode = 0;
|
||||||
String content;
|
|
||||||
String packageName;
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
try {
|
try {
|
||||||
|
String content;
|
||||||
if (!result.startsWith("{")) { // for response who append with unknown char
|
if (!result.startsWith("{")) { // for response who append with unknown char
|
||||||
result = result.substring(1);
|
result = result.substring(1);
|
||||||
}
|
}
|
||||||
|
@ -345,8 +295,12 @@ class WVersionManager {
|
||||||
} else {
|
} else {
|
||||||
content = json.optString("content_en");
|
content = json.optString("content_en");
|
||||||
}
|
}
|
||||||
packageName = json.optString("package");
|
String packageName = json.optString("package");
|
||||||
setUpdateUrl("market://details?id=" + packageName);
|
setUpdateUrl("market://details?id=" + packageName);
|
||||||
|
int adsDelay = json.optInt("ads_delay");
|
||||||
|
int adsRepeat = json.optInt("ads_repeat");
|
||||||
|
pf.saveSettings(PreferencesHelper.ADS_DELAY, adsDelay);
|
||||||
|
pf.saveSettings(PreferencesHelper.ADS_REPEAT, adsRepeat);
|
||||||
int currentVersionCode = getCurrentVersionCode();
|
int currentVersionCode = getCurrentVersionCode();
|
||||||
if (currentVersionCode < mVersionCode) {
|
if (currentVersionCode < mVersionCode) {
|
||||||
if (mVersionCode != getIgnoreVersionCode()) {
|
if (mVersionCode != getIgnoreVersionCode()) {
|
||||||
|
@ -364,10 +318,10 @@ class WVersionManager {
|
||||||
al.isShowUpdateDialog(false);
|
al.isShowUpdateDialog(false);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG, "is your server response have valid json format?");
|
Crashlytics.logException(e);
|
||||||
al.isShowUpdateDialog(false);
|
al.isShowUpdateDialog(false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, e.toString());
|
Crashlytics.logException(e);
|
||||||
al.isShowUpdateDialog(false);
|
al.isShowUpdateDialog(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
|
@ -1,82 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
package mobi.MultiCraft;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.v4.app.ActivityCompat;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
|
||||||
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
|
||||||
import static mobi.MultiCraft.PreferencesHelper.TAG_RESTORE_BACKUP;
|
|
||||||
|
|
||||||
class PermissionManager {
|
|
||||||
static ArrayList<String> permissionsToRequest;
|
|
||||||
static ArrayList<String> permissionsRejected;
|
|
||||||
private Activity activity;
|
|
||||||
private SharedPreferences sharedPreferences;
|
|
||||||
private PreferencesHelper pf;
|
|
||||||
|
|
||||||
PermissionManager(Activity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
pf = PreferencesHelper.getInstance(activity);
|
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] requestPermissions() {
|
|
||||||
ArrayList<String> permissions = new ArrayList<>();
|
|
||||||
permissions.add(WRITE_EXTERNAL_STORAGE);
|
|
||||||
permissions.add(ACCESS_COARSE_LOCATION);
|
|
||||||
//filter out the permissions we have already accepted
|
|
||||||
permissionsToRequest = findUnAskedPermissions(permissions);
|
|
||||||
//get the permissions we have asked for before but are not granted..
|
|
||||||
//we will store this in a global list to access later.
|
|
||||||
permissionsRejected = findRejectedPermissions(permissions);
|
|
||||||
if (permissionsToRequest.size() > 0) {//we need to ask for permissions
|
|
||||||
for (String perm : permissionsToRequest) {
|
|
||||||
markAsAsked(perm);
|
|
||||||
}
|
|
||||||
return permissionsToRequest.toArray(new String[permissionsToRequest.size()]);
|
|
||||||
} else if (permissionsRejected.size() > 0 && pf.getLaunchTimes() % 3 == 0) {
|
|
||||||
return permissionsRejected.toArray(new String[permissionsRejected.size()]);
|
|
||||||
}
|
|
||||||
return new String[]{};
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasPermission(String permission) {
|
|
||||||
return ActivityCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean shouldWeAsk(String permission) {
|
|
||||||
if (pf.getLaunchTimes() > 1 && permission.equals(WRITE_EXTERNAL_STORAGE)) {
|
|
||||||
sharedPreferences.edit().clear().apply();
|
|
||||||
pf.saveSettings(TAG_RESTORE_BACKUP, true);
|
|
||||||
}
|
|
||||||
return sharedPreferences.getBoolean(permission, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void markAsAsked(String permission) {
|
|
||||||
sharedPreferences.edit().putBoolean(permission, false).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<String> findUnAskedPermissions(ArrayList<String> wanted) {
|
|
||||||
ArrayList<String> result = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String perm : wanted) {
|
|
||||||
if (!hasPermission(perm) && shouldWeAsk(perm)) {
|
|
||||||
result.add(perm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<String> findRejectedPermissions(ArrayList<String> wanted) {
|
|
||||||
ArrayList<String> result = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String perm : wanted) {
|
|
||||||
if (!hasPermission(perm) && !shouldWeAsk(perm)) {
|
|
||||||
result.add(perm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
|
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/editText"
|
android:id="@+id/editText"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="50dp" />
|
|
@ -35,9 +35,9 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:text="@string/rate_submit"
|
android:text="@string/rate_submit"
|
||||||
|
|
|
@ -6,29 +6,26 @@
|
||||||
<string name="loading">Загрузка…</string>
|
<string name="loading">Загрузка…</string>
|
||||||
<string name="notification_title">Загрузка MultiCraft</string>
|
<string name="notification_title">Загрузка MultiCraft</string>
|
||||||
<string name="notification_description">Осталось меньше минуты…</string>
|
<string name="notification_description">Осталось меньше минуты…</string>
|
||||||
|
<string name="restart">Произошла ошибка, игра будет перезапущена автоматически</string>
|
||||||
|
<string name="no_space">Недостаточно места для записи файлов игры, пожалуйста освободите место SD карте</string>
|
||||||
<!-- разрешения -->
|
<!-- разрешения -->
|
||||||
<string name="explain">Для корректной работы, игре требуется разрешение записывать в память устройтсва.</string>
|
<string name="explain">Разрешение на запись необходимо для распаковки текстур и игровых файлов.</string>
|
||||||
<string name="location">Доступ к местоположению обеспечивает Вам лучшее взаимодействие с игрой</string>
|
<string name="location">Доступ к местоположению обеспечивает Вам лучшее взаимодействие с игрой</string>
|
||||||
|
<string name="close_game">Закрыть игру</string>
|
||||||
|
<string name="settings">Настройки</string>
|
||||||
|
<string name="denied">Вы не можете использовать MultiCraft без разрешения на запись. \nПожалуйста, включите его в [Настройки] -> [Разрешения]></string>
|
||||||
<!-- диалог оценки -->
|
<!-- диалог оценки -->
|
||||||
<string name="rta_dialog_title">Оцените MultiCraft!</string>
|
<string name="rta_dialog_title">Оцените MultiCraft!</string>
|
||||||
<string name="rate_title">Название</string>
|
<string name="rate_title">Название</string>
|
||||||
<string name="rate_submit">ОЦЕНИТЬ</string>
|
|
||||||
<string name="rate_description">Описание</string>
|
<string name="rate_description">Описание</string>
|
||||||
|
<string name="rate_submit">ОЦЕНИТЬ</string>
|
||||||
<string name="sad">Нам жаль, что Вам не понравилась игра!</string>
|
<string name="sad">Нам жаль, что Вам не понравилась игра!</string>
|
||||||
<string name="recommend">Загрузка рекомендаций \n для Вас \n%1$s</string>
|
|
||||||
<!-- обновление -->
|
<!-- обновление -->
|
||||||
<string name="ignore">Игнорировать</string>
|
<string name="ignore">Игнорировать</string>
|
||||||
<string name="later">Позже</string>
|
<string name="later">Позже</string>
|
||||||
<string name="update">Обновить</string>
|
<string name="update">Обновить</string>
|
||||||
|
|
||||||
<!-- reminder -->
|
<!-- reminder -->
|
||||||
<string name="message">Сообщение</string>
|
|
||||||
|
|
||||||
<!-- in-app -->
|
|
||||||
<string name="buy_title">Супер предложение!</string>
|
|
||||||
<string name="buy_message">Полностью отключите рекламу \n и активируйте Pro-режим со скидкой 75%!</string>
|
|
||||||
<string name="close">Закрыть</string>
|
|
||||||
<string name="disable">Отключить рекламу!</string>
|
|
||||||
|
|
||||||
<!-- no connection dialog -->
|
<!-- no connection dialog -->
|
||||||
<string name="conn_message">Для полноценной игры, MultiCraft требует подключение к интернету.\nВ противном случае невозможно обновление игры, а так же не доступен мультиплеер!</string>
|
<string name="conn_message">Для полноценной игры, MultiCraft требует подключение к интернету.\nВ противном случае невозможно обновление игры, а так же не доступен мультиплеер!</string>
|
||||||
|
|
|
@ -2,24 +2,28 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name" translatable="false">MultiCraft</string>
|
<string name="app_name" translatable="false">MultiCraft</string>
|
||||||
<string name="ver" translatable="false">1.1.11.6</string>
|
<string name="ver" translatable="false">1.2</string>
|
||||||
<!-- preparation for start -->
|
<!-- preparation for start -->
|
||||||
|
|
||||||
<string name="rm_old">Preparing to update…</string>
|
<string name="rm_old">Preparing to update…</string>
|
||||||
<string name="loading">Loading…</string>
|
<string name="loading">Loading…</string>
|
||||||
<string name="notification_title">Loading MultiCraft</string>
|
<string name="notification_title">Loading MultiCraft</string>
|
||||||
<string name="notification_description">Less than 1 minute…</string>
|
<string name="notification_description">Less than 1 minute…</string>
|
||||||
|
<string name="restart">Unexpected issue, the game will be restarted automatically</string>
|
||||||
|
<string name="no_space">No space left for game files, please free space on SD card</string>
|
||||||
|
|
||||||
<!-- permission block -->
|
<!-- permission block -->
|
||||||
<string name="explain">Game need permission to write files to storage memory.</string>
|
<string name="explain">Storage permissions is necessary to unpack textures and game data.</string>
|
||||||
<string name="location">Location permission provide you better interaction with game</string>
|
<string name="location">Location permission provide you better interaction with game</string>
|
||||||
|
<string name="close_game">Close game</string>
|
||||||
|
<string name="settings">App settings</string>
|
||||||
|
<string name="denied">You cannot use MultiCraft without storage permission. \nPlease turn on it at [Settings] -> [Permissions]></string>
|
||||||
<!-- rate input_dialog -->
|
<!-- rate input_dialog -->
|
||||||
<string name="rta_dialog_title">Please, rate MultiCraft!</string>
|
<string name="rta_dialog_title">Please, rate MultiCraft!</string>
|
||||||
<string name="rate_title">Title</string>
|
<string name="rate_title">Title</string>
|
||||||
<string name="rate_submit">SUBMIT</string>
|
|
||||||
<string name="rate_description">Description</string>
|
<string name="rate_description">Description</string>
|
||||||
|
<string name="rate_submit">SUBMIT</string>
|
||||||
<string name="sad">We are sorry that you did not like the game!</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 -->
|
<!--update input_dialog -->
|
||||||
<string name="update">Update</string>
|
<string name="update">Update</string>
|
||||||
|
@ -27,13 +31,6 @@
|
||||||
<string name="ignore">Ignore</string>
|
<string name="ignore">Ignore</string>
|
||||||
|
|
||||||
<!-- reminder -->
|
<!-- reminder -->
|
||||||
<string name="message">Message</string>
|
|
||||||
|
|
||||||
<!-- in-app -->
|
|
||||||
<string name="buy_title">Special Offer!</string>
|
|
||||||
<string name="buy_message">Only for 0.99$ \nDisable ads forever \nand activate Pro features!</string>
|
|
||||||
<string name="close">Close</string>
|
|
||||||
<string name="disable">Disable Ads!</string>
|
|
||||||
|
|
||||||
<!-- no connection dialog -->
|
<!-- 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_message">MultiCraft requires an internet connection to use all game features.\nOtherwise, you will not get updates and multiplayer will be not available!</string>
|
||||||
|
@ -44,4 +41,5 @@
|
||||||
<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_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_agree" translatable="false">Agree</string>
|
||||||
<string name="gdpr_disagree" translatable="false">Disagree</string>
|
<string name="gdpr_disagree" translatable="false">Disagree</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<network-security-config>
|
||||||
|
<base-config cleartextTrafficPermitted="true">
|
||||||
|
<trust-anchors>
|
||||||
|
<certificates src="system" />
|
||||||
|
</trust-anchors>
|
||||||
|
</base-config>
|
||||||
|
</network-security-config>
|
Binary file not shown.
Before Width: | Height: | Size: 468 B After Width: | Height: | Size: 1015 B |
Loading…
Reference in New Issue