commit
a3754330bd
|
@ -3,7 +3,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,13 @@ task clean(type: Delete) {
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 24
|
||||
buildToolsVersion "24.0.3"
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "mobi.MultiCraft"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 24
|
||||
targetSdkVersion 25
|
||||
}
|
||||
Properties props = new Properties()
|
||||
props.load(new FileInputStream(file("local.properties")))
|
||||
|
@ -50,5 +50,5 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.android.support:support-v4:24.2.0'
|
||||
compile 'com.android.support:support-v4:25.3.1'
|
||||
}
|
|
@ -2,11 +2,10 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="mobi.MultiCraft"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="25"
|
||||
android:versionCode="52"
|
||||
android:versionName="@string/ver">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
import com.google.firebase.iid.FirebaseInstanceIdService;
|
||||
|
||||
public class FireIDService extends FirebaseInstanceIdService {
|
||||
|
||||
@Override
|
||||
public void onTokenRefresh() {
|
||||
String tkn = FirebaseInstanceId.getInstance().getToken();
|
||||
// Log.d("App", "Token [" + tkn + "]");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||
import com.google.firebase.messaging.RemoteMessage;
|
||||
|
||||
public class FireMsgService extends FirebaseMessagingService {
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
super.onMessageReceived(remoteMessage);
|
||||
|
||||
// Create Notification
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410, intent,
|
||||
PendingIntent.FLAG_ONE_SHOT);
|
||||
|
||||
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.update)
|
||||
.setContentTitle(getString(R.string.message))
|
||||
.setSound(uri)
|
||||
.setContentText(remoteMessage.getNotification().getBody())
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(pendingIntent);
|
||||
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
notificationManager.notify(1410, notificationBuilder.build());
|
||||
}
|
||||
}
|
|
@ -21,7 +21,8 @@ public class GameActivity extends NativeActivity {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
// startAd(this, true);
|
||||
// if (!isAdsDisabled())
|
||||
// startAd(this, true);
|
||||
messageReturnCode = -1;
|
||||
messageReturnValue = "";
|
||||
makeFullScreen();
|
||||
|
@ -47,7 +48,8 @@ public class GameActivity extends NativeActivity {
|
|||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
// startAd(this, false);
|
||||
// if (!isAdsDisabled())
|
||||
// startAd(this, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@ import android.view.View.OnKeyListener;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
|
||||
public class InputDialogActivity extends Activity {
|
||||
private AlertDialog alertDialog;
|
||||
|
||||
|
@ -28,7 +27,7 @@ public class InputDialogActivity extends Activity {
|
|||
int editType = b.getInt("editType");
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
LayoutInflater inflater = this.getLayoutInflater();
|
||||
View dialogView = inflater.inflate(R.layout.dialog, null);
|
||||
View dialogView = inflater.inflate(R.layout.input_dialog, null);
|
||||
builder.setView(dialogView);
|
||||
final EditText editText = (EditText) dialogView.findViewById(R.id.editText);
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
@ -10,18 +9,20 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -32,34 +33,34 @@ import java.io.OutputStream;
|
|||
import java.util.Arrays;
|
||||
|
||||
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
||||
import static mobi.MultiCraft.PermissionManager.permissionsRejected;
|
||||
import static mobi.MultiCraft.PermissionManager.permissionsToRequest;
|
||||
import static mobi.MultiCraft.PreferencesHelper.TAG_BUILD_NUMBER;
|
||||
import static mobi.MultiCraft.PreferencesHelper.TAG_LAUNCH_TIMES;
|
||||
import static mobi.MultiCraft.PreferencesHelper.TAG_SHORTCUT_CREATED;
|
||||
import static mobi.MultiCraft.PreferencesHelper.getBuildNumber;
|
||||
import static mobi.MultiCraft.PreferencesHelper.getLaunchTimes;
|
||||
import static mobi.MultiCraft.PreferencesHelper.isCreateShortcut;
|
||||
import static mobi.MultiCraft.PreferencesHelper.isRestored;
|
||||
import static mobi.MultiCraft.PreferencesHelper.loadSettings;
|
||||
import static mobi.MultiCraft.PreferencesHelper.saveSettings;
|
||||
|
||||
public class MainActivity extends Activity implements WVersionManager.ActivityListener {
|
||||
public final static int REQUEST_CODE = 104;
|
||||
private final static String TAG = "Error";
|
||||
private final static String FILES = Environment.getExternalStorageDirectory() + "/Files.zip";
|
||||
private final static String WORLDS = Environment.getExternalStorageDirectory() + "/worlds.zip";
|
||||
private final static String GAMES = Environment.getExternalStorageDirectory() + "/games.zip";
|
||||
private final static String NOMEDIA = ".nomedia";
|
||||
private final static int COARSE_LOCATION_RESULT = 100;
|
||||
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";
|
||||
|
||||
public final static String TAG = "Error";
|
||||
public final static String CREATE_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
|
||||
public final static String FILES = Environment.getExternalStorageDirectory() + "/Files.zip";
|
||||
public final static String WORLDS = Environment.getExternalStorageDirectory() + "/worlds.zip";
|
||||
public final static String GAMES = Environment.getExternalStorageDirectory() + "/games.zip";
|
||||
public final static String NOMEDIA = ".nomedia";
|
||||
private ProgressDialog mProgressDialog;
|
||||
private String dataFolder = "/Android/data/mobi.MultiCraft/files/";
|
||||
private String unzipLocation = Environment.getExternalStorageDirectory() + dataFolder;
|
||||
private ProgressBar mProgressBar;
|
||||
private Utilities util;
|
||||
private TextView mLoading;
|
||||
private ImageView iv;
|
||||
private WVersionManager versionManager = null;
|
||||
|
||||
private PermissionManager pm = null;
|
||||
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
|
@ -69,12 +70,13 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setProgress(progress);
|
||||
} else {
|
||||
util.createNomedia();
|
||||
createNomedia();
|
||||
runGame();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -87,52 +89,88 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
finish();
|
||||
return;
|
||||
}
|
||||
int i = getLaunchTimes();
|
||||
i++;
|
||||
saveSettings(TAG_LAUNCH_TIMES, i);
|
||||
pm = new PermissionManager(this);
|
||||
String[] permList = pm.requestPermissions();
|
||||
if (permList.length > 0) {
|
||||
ActivityCompat.requestPermissions(this, permList, ALL_PERMISSIONS_RESULT);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
|
||||
addLaunchTimes();
|
||||
getPermissions();
|
||||
// if (!isAdsDisabled())
|
||||
// initAd(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isShowUpdateDialog(boolean flag) {
|
||||
if (flag) {
|
||||
versionManager.showDialog();
|
||||
versionManager.setCallback(new WVersionManager.Callback() {
|
||||
@Override
|
||||
public void onPositive() {
|
||||
versionManager.updateNow(versionManager.getUpdateUrl());
|
||||
finish();
|
||||
}
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
makeFullScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative() {
|
||||
versionManager.ignoreThisVersion();
|
||||
checkRateDialog();
|
||||
}
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
dismissProgressDialog();
|
||||
unregisterReceiver(myReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemind() {
|
||||
versionManager.remindMeLater(versionManager.getReminderTimer());
|
||||
checkRateDialog();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
checkRateDialog();
|
||||
//helpful utilities
|
||||
private void addLaunchTimes() {
|
||||
int i = getLaunchTimes();
|
||||
i++;
|
||||
saveSettings(TAG_LAUNCH_TIMES, i);
|
||||
}
|
||||
|
||||
private void deleteFiles(String path) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
String deleteCmd = "rm -r " + path;
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
try {
|
||||
runtime.exec(deleteCmd);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "delete files failed: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNewVersion() {
|
||||
versionManager = new WVersionManager(this);
|
||||
versionManager.setVersionContentUrl("http://pastebin.com/raw/aeM2bmSB");
|
||||
versionManager.checkVersion();
|
||||
|
||||
private void createDataFolder() {
|
||||
File folder = new File(unzipLocation);
|
||||
if (!(folder.exists()))
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
private void deleteZip(String... filesArray) {
|
||||
for (String fileName : filesArray) {
|
||||
File file = new File(fileName);
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private void createNomedia() {
|
||||
File myFile = new File(unzipLocation, NOMEDIA);
|
||||
if (!myFile.exists())
|
||||
try {
|
||||
myFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "nomedia has not been created: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//interface
|
||||
private void addImageView(int pos) {
|
||||
int marginTop = pos == 0 ? 48 : 288;
|
||||
RelativeLayout rl = (RelativeLayout) findViewById(R.id.activity_main);
|
||||
iv = new ImageView(this);
|
||||
iv.setBackgroundResource(R.drawable.logo);
|
||||
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
||||
lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
|
||||
lp.setMargins(0, marginTop, 0, 0);
|
||||
iv.requestLayout();
|
||||
iv.setLayoutParams(lp);
|
||||
rl.addView(iv);
|
||||
}
|
||||
|
||||
private void hideViews() {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
iv.setVisibility(View.GONE);
|
||||
mLoading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void makeFullScreen() {
|
||||
|
@ -150,50 +188,41 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
dismissProgressDialog();
|
||||
unregisterReceiver(myReceiver);
|
||||
private void showSpinnerDialog(int message) {
|
||||
if (mProgressDialog == null) {
|
||||
mProgressDialog = new ProgressDialog(MainActivity.this);
|
||||
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
mProgressDialog.setCancelable(false);
|
||||
}
|
||||
mProgressDialog.setMessage(getString(message));
|
||||
mProgressDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
makeFullScreen();
|
||||
private void dismissProgressDialog() {
|
||||
if (mProgressDialog != null && mProgressDialog.isShowing()) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private void addShortcut() {
|
||||
saveSettings(TAG_SHORTCUT_CREATED, false);
|
||||
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
|
||||
shortcutIntent.setAction(Intent.ACTION_MAIN);
|
||||
Intent addIntent = new Intent();
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||
Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
|
||||
addIntent.setAction(CREATE_SHORTCUT);
|
||||
getApplicationContext().sendBroadcast(addIntent);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void init() {
|
||||
RateMe.onStart(this);
|
||||
if (isCreateShortcut())
|
||||
addShortcut();
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.PB1);
|
||||
Drawable draw;
|
||||
draw = getResources().getDrawable(R.drawable.custom_progress_bar);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mLoading = (TextView) findViewById(R.id.tv_progress_circle);
|
||||
Drawable draw = ContextCompat.getDrawable(this, R.drawable.custom_progress_bar);
|
||||
mProgressBar.setProgressDrawable(draw);
|
||||
util = new Utilities();
|
||||
util.createDataFolder();
|
||||
util.checkVersion();
|
||||
createDataFolder();
|
||||
checkAppVersion();
|
||||
}
|
||||
|
||||
private boolean isNetworkConnected() {
|
||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm.getActiveNetworkInfo() != null;
|
||||
//permission block
|
||||
private void getPermissions() {
|
||||
pm = new PermissionManager(this);
|
||||
String[] permList = pm.requestPermissions();
|
||||
if (permList.length > 0) {
|
||||
ActivityCompat.requestPermissions(this, permList, ALL_PERMISSIONS_RESULT);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
private void requestPermissionAfterExplain() {
|
||||
|
@ -225,14 +254,14 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
case COARSE_LOCATION_RESULT:
|
||||
break;
|
||||
case ALL_PERMISSIONS_RESULT:
|
||||
for (String perms : permissionsToRequest) {
|
||||
for (String perms : PermissionManager.permissionsToRequest) {
|
||||
if (!pm.hasPermission(perms)) {
|
||||
permissionsRejected.add(perms);
|
||||
PermissionManager.permissionsRejected.add(perms);
|
||||
}
|
||||
}
|
||||
if (permissionsRejected.size() == 0) {
|
||||
if (PermissionManager.permissionsRejected.size() == 0) {
|
||||
init();
|
||||
} else if (!Arrays.asList(permissionsRejected.toArray()).contains(WRITE_EXTERNAL_STORAGE)) {
|
||||
} else if (!Arrays.asList(PermissionManager.permissionsRejected.toArray()).contains(WRITE_EXTERNAL_STORAGE)) {
|
||||
Toast.makeText(this, R.string.location, Toast.LENGTH_SHORT).show();
|
||||
init();
|
||||
} else {
|
||||
|
@ -242,22 +271,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
}
|
||||
}
|
||||
|
||||
private void showSpinnerDialog(int message) {
|
||||
if (mProgressDialog == null) {
|
||||
mProgressDialog = new ProgressDialog(MainActivity.this);
|
||||
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
mProgressDialog.setCancelable(false);
|
||||
}
|
||||
mProgressDialog.setMessage(getString(message));
|
||||
mProgressDialog.show();
|
||||
}
|
||||
|
||||
private void dismissProgressDialog() {
|
||||
if (mProgressDialog != null && mProgressDialog.isShowing()) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
//game logic
|
||||
private void checkRateDialog() {
|
||||
if (RateMe.shouldShowRateDialog()) {
|
||||
hideViews();
|
||||
|
@ -284,23 +298,49 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
}
|
||||
}
|
||||
|
||||
public void runGame() {
|
||||
util.deleteZip(FILES);
|
||||
util.deleteZip(WORLDS);
|
||||
util.deleteZip(GAMES);
|
||||
if (isNetworkConnected()) {
|
||||
checkNewVersion();
|
||||
@Override
|
||||
public void isShowUpdateDialog(boolean flag) {
|
||||
if (flag) {
|
||||
versionManager.showDialog();
|
||||
versionManager.setCallback(new WVersionManager.Callback() {
|
||||
@Override
|
||||
public void onPositive() {
|
||||
versionManager.updateNow(versionManager.getUpdateUrl());
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative() {
|
||||
versionManager.ignoreThisVersion();
|
||||
checkRateDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemind() {
|
||||
versionManager.remindMeLater(versionManager.getReminderTimer());
|
||||
checkRateDialog();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
startGameActivity();
|
||||
checkRateDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void hideViews() {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
findViewById(R.id.imageView).setVisibility(View.GONE);
|
||||
findViewById(R.id.tv_progress_circle).setVisibility(View.GONE);
|
||||
private void checkUrlVersion() {
|
||||
versionManager = new WVersionManager(this);
|
||||
versionManager.setVersionContentUrl(UPDATE_LINK);
|
||||
versionManager.checkVersion();
|
||||
|
||||
}
|
||||
|
||||
public void runGame() {
|
||||
deleteZip(FILES, WORLDS, GAMES);
|
||||
Intent intent = new Intent(this, BillingActivity.class);
|
||||
startActivityForResult(intent, REQUEST_CODE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void startGameActivity() {
|
||||
Intent intent = new Intent(MainActivity.this, GameActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
|
@ -316,6 +356,42 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// super.onActivityResult(requestCode, resultCode, data);
|
||||
// check if the request code is same as what is passed here it is 2
|
||||
if (requestCode == REQUEST_CODE) {
|
||||
if ((data != null) && (data.getBooleanExtra("isCheckNewVersion", false))) {
|
||||
checkUrlVersion();
|
||||
} else {
|
||||
startGameActivity();
|
||||
}
|
||||
} else startGameActivity();
|
||||
}
|
||||
|
||||
private void startDeletion(boolean isAll) {
|
||||
if (isAll) {
|
||||
new DeleteTask().execute(unzipLocation);
|
||||
} else {
|
||||
new DeleteTask().execute(unzipLocation + "builtin", unzipLocation + "games", unzipLocation + "debug.txt");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAppVersion() {
|
||||
if (!isRestored() && getBuildNumber().equals(getString(R.string.ver))) {
|
||||
addImageView(1);
|
||||
runGame();
|
||||
} else if (getBuildNumber().equals("0")) {
|
||||
addImageView(0);
|
||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||
startDeletion(true);
|
||||
} else {
|
||||
addImageView(0);
|
||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||
startDeletion(false);
|
||||
}
|
||||
}
|
||||
|
||||
private class DeleteTask extends AsyncTask<String, Void, Void> {
|
||||
String location;
|
||||
|
||||
|
@ -329,7 +405,7 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
protected Void doInBackground(String... params) {
|
||||
location = params[0];
|
||||
for (String p : params) {
|
||||
util.deleteFiles(p);
|
||||
deleteFiles(p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -354,7 +430,8 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -369,14 +446,11 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
if (util.getAvailableSpaceInMB() > 15) {
|
||||
try {
|
||||
startUnzipService(zips);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "unzip failed: " + e.getMessage());
|
||||
}
|
||||
} else
|
||||
Toast.makeText(MainActivity.this, R.string.not_enough_space, Toast.LENGTH_LONG).show();
|
||||
try {
|
||||
startUnzipService(zips);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "unzip failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void copyAssets(String zipName) {
|
||||
|
@ -404,76 +478,5 @@ public class MainActivity extends Activity implements WVersionManager.ActivityLi
|
|||
}
|
||||
}
|
||||
|
||||
private class Utilities {
|
||||
|
||||
private void createDataFolder() {
|
||||
File folder = new File(unzipLocation);
|
||||
if (!(folder.exists()))
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
private void deleteZip(String fileName) {
|
||||
File file = new File(fileName);
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
}
|
||||
|
||||
private void startDeletion(boolean isAll) {
|
||||
if (isAll) {
|
||||
new DeleteTask().execute(unzipLocation);
|
||||
} else {
|
||||
new DeleteTask().execute(unzipLocation + "games", unzipLocation + "debug.txt");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint("NewApi")
|
||||
private long getAvailableSpaceInMB() {
|
||||
final long SIZE_KB = 1024L;
|
||||
final long SIZE_MB = SIZE_KB * SIZE_KB;
|
||||
long availableSpace;
|
||||
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
||||
if (Build.VERSION.SDK_INT > 17) {
|
||||
availableSpace = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
|
||||
} else {
|
||||
availableSpace = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
|
||||
}
|
||||
return availableSpace / SIZE_MB;
|
||||
}
|
||||
|
||||
void checkVersion() {
|
||||
if (getBuildNumber().equals(getString(R.string.ver))) {
|
||||
runGame();
|
||||
} else if (getBuildNumber().equals("0")) {
|
||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||
startDeletion(true);
|
||||
} else {
|
||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||
startDeletion(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteFiles(String path) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
String deleteCmd = "rm -r " + path;
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
try {
|
||||
runtime.exec(deleteCmd);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "delete files failed: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createNomedia() {
|
||||
File myFile = new File(unzipLocation, NOMEDIA);
|
||||
if (!myFile.exists())
|
||||
try {
|
||||
myFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "nomedia has not been created: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,13 +10,15 @@ 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;
|
||||
import static mobi.MultiCraft.PreferencesHelper.getLaunchTimes;
|
||||
import static mobi.MultiCraft.PreferencesHelper.saveSettings;
|
||||
|
||||
class PermissionManager {
|
||||
private Activity activity;
|
||||
private SharedPreferences sharedPreferences;
|
||||
static ArrayList<String> permissionsToRequest;
|
||||
static ArrayList<String> permissionsRejected;
|
||||
private Activity activity;
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
PermissionManager(Activity activity) {
|
||||
this.activity = activity;
|
||||
|
@ -26,9 +28,7 @@ class PermissionManager {
|
|||
String[] requestPermissions() {
|
||||
ArrayList<String> permissions = new ArrayList<>();
|
||||
permissions.add(WRITE_EXTERNAL_STORAGE);
|
||||
if (getLaunchTimes() > 2) {
|
||||
permissions.add(ACCESS_COARSE_LOCATION);
|
||||
}
|
||||
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..
|
||||
|
@ -46,10 +46,14 @@ class PermissionManager {
|
|||
}
|
||||
|
||||
boolean hasPermission(String permission) {
|
||||
return (ActivityCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED);
|
||||
return ActivityCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
private boolean shouldWeAsk(String permission) {
|
||||
if (getLaunchTimes() > 1 && permission.equals(WRITE_EXTERNAL_STORAGE)) {
|
||||
sharedPreferences.edit().clear().apply();
|
||||
saveSettings(TAG_RESTORE_BACKUP, true);
|
||||
}
|
||||
return sharedPreferences.getBoolean(permission, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,36 +4,47 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
|
||||
class PreferencesHelper {
|
||||
private static final String SETTINGS = "settings";
|
||||
static final String TAG_SHORTCUT_CREATED = "createShortcut";
|
||||
static final String TAG_BUILD_NUMBER = "buildNumber";
|
||||
static final String TAG_LAUNCH_TIMES = "launchTimes";
|
||||
private static boolean createShortcut;
|
||||
static final String TAG_RESTORE_BACKUP = "restoredFromBackup";
|
||||
private static final String SETTINGS = "settings";
|
||||
private static final String TAG_DISABLED_ADS = "disabledADS";
|
||||
private static String buildNumber;
|
||||
private static SharedPreferences settings;
|
||||
|
||||
static boolean isCreateShortcut() {
|
||||
return createShortcut;
|
||||
private static SharedPreferences settings;
|
||||
private static boolean disabledADS;
|
||||
|
||||
static boolean isAdsDisabled() {
|
||||
return disabledADS;
|
||||
}
|
||||
|
||||
static String getBuildNumber() {
|
||||
return buildNumber;
|
||||
}
|
||||
|
||||
static void loadSettings(final Context context) {
|
||||
settings = context.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
|
||||
createShortcut = settings.getBoolean(TAG_SHORTCUT_CREATED, true);
|
||||
buildNumber = settings.getString(TAG_BUILD_NUMBER, "0");
|
||||
static boolean isRestored() {
|
||||
return settings.getBoolean(TAG_RESTORE_BACKUP, false);
|
||||
}
|
||||
|
||||
static void saveSettings(String tag, boolean bool) {
|
||||
settings.edit().putBoolean(tag, bool).apply();
|
||||
static void savePurchase(boolean v) {
|
||||
disabledADS = v;
|
||||
settings.edit().putBoolean(TAG_DISABLED_ADS, v).apply();
|
||||
}
|
||||
|
||||
static int getLaunchTimes() {
|
||||
return settings.getInt(TAG_LAUNCH_TIMES, 0);
|
||||
}
|
||||
|
||||
static void loadSettings(final Context context) {
|
||||
settings = context.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
|
||||
buildNumber = settings.getString(TAG_BUILD_NUMBER, "0");
|
||||
disabledADS = settings.getBoolean(TAG_DISABLED_ADS, false);
|
||||
}
|
||||
|
||||
static void saveSettings(String tag, boolean bool) {
|
||||
settings.edit().putBoolean(tag, bool).apply();
|
||||
}
|
||||
|
||||
static void saveSettings(String tag, String value) {
|
||||
settings.edit().putString(tag, value).apply();
|
||||
}
|
||||
|
@ -41,4 +52,5 @@ class PreferencesHelper {
|
|||
static void saveSettings(String tag, int value) {
|
||||
settings.edit().putInt(tag, value).apply();
|
||||
}
|
||||
|
||||
}
|
|
@ -18,8 +18,8 @@ import java.util.Date;
|
|||
|
||||
class RateMe {
|
||||
|
||||
private static final int INSTALL_DAYS = 3;
|
||||
private static final int LAUNCH_TIMES = 2;
|
||||
private static final int INSTALL_DAYS = 2;
|
||||
private static final int LAUNCH_TIMES = 3;
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String TAG = RateMe.class.getSimpleName();
|
||||
private static final String GOOGLE_PLAY = "https://play.google.com/store/apps/details?id=";
|
||||
|
@ -78,7 +78,7 @@ class RateMe {
|
|||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||
}
|
||||
dialog.setContentView(R.layout.rate_layout);
|
||||
dialog.setContentView(R.layout.rate_dialog);
|
||||
dialog.setTitle(R.string.rta_dialog_title);
|
||||
|
||||
RatingBar ratingBar = (RatingBar) dialog.findViewById(R.id.ratingBar);
|
||||
|
@ -133,14 +133,12 @@ class RateMe {
|
|||
|
||||
private static void storeInstallDate(final Context context, SharedPreferences.Editor editor) {
|
||||
Date installDate = new Date();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
PackageManager packMan = context.getPackageManager();
|
||||
try {
|
||||
PackageInfo pkgInfo = packMan.getPackageInfo(context.getPackageName(), 0);
|
||||
installDate = new Date(pkgInfo.firstInstallTime);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PackageManager packMan = context.getPackageManager();
|
||||
try {
|
||||
PackageInfo pkgInfo = packMan.getPackageInfo(context.getPackageName(), 0);
|
||||
installDate = new Date(pkgInfo.firstInstallTime);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
editor.putLong(KEY_INSTALL_DATE, installDate.getTime());
|
||||
log("First install: " + installDate.toString());
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package mobi.MultiCraft;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -40,7 +40,7 @@ public class UnzipService extends IntentService {
|
|||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Notification.Builder mBuilder = new Notification.Builder(this);
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
|
||||
mBuilder.setContentTitle(getString(R.string.notification_title))
|
||||
.setContentText(getString(R.string.notification_description)).setSmallIcon(R.drawable.update);
|
||||
String[] file = intent.getStringArrayExtra(EXTRA_KEY_IN_FILE);
|
||||
|
|
|
@ -33,13 +33,11 @@ import java.util.Locale;
|
|||
|
||||
class WVersionManager {
|
||||
private static final String TAG = "WVersionManager";
|
||||
|
||||
private static WVersionManager.Callback sCallback = null;
|
||||
private CustomTagHandler customTagHandler;
|
||||
|
||||
private String PREF_IGNORE_VERSION_CODE = "w.ignore.version.code";
|
||||
private String PREF_REMINDER_TIME = "w.reminder.time";
|
||||
private String PREF_LAUNCH_TIMES = "w.launch.times";
|
||||
|
||||
private Activity activity;
|
||||
private Drawable icon;
|
||||
private String title;
|
||||
|
@ -53,17 +51,8 @@ class WVersionManager {
|
|||
private int mVersionCode;
|
||||
private AlertDialogButtonListener listener;
|
||||
private boolean mDialogCancelable = false;
|
||||
private static WVersionManager.Callback sCallback = null;
|
||||
private ActivityListener al;
|
||||
|
||||
void setCallback(WVersionManager.Callback callback) {
|
||||
sCallback = callback;
|
||||
}
|
||||
|
||||
interface ActivityListener {
|
||||
void isShowUpdateDialog(boolean flag);
|
||||
}
|
||||
|
||||
WVersionManager(Activity act) {
|
||||
this.activity = act;
|
||||
al = (ActivityListener) act;
|
||||
|
@ -72,6 +61,10 @@ class WVersionManager {
|
|||
setLaunchTimes();
|
||||
}
|
||||
|
||||
void setCallback(WVersionManager.Callback callback) {
|
||||
sCallback = callback;
|
||||
}
|
||||
|
||||
private Drawable getDefaultAppIcon() {
|
||||
return activity.getApplicationInfo().loadIcon(activity.getPackageManager());
|
||||
}
|
||||
|
@ -126,19 +119,24 @@ class WVersionManager {
|
|||
return updateNowLabel != null ? updateNowLabel : activity.getString(R.string.update);
|
||||
}
|
||||
|
||||
public void setUpdateNowLabel(String updateNowLabel) {
|
||||
this.updateNowLabel = updateNowLabel;
|
||||
}
|
||||
|
||||
private String getRemindMeLaterLabel() {
|
||||
return remindMeLaterLabel != null ? remindMeLaterLabel : activity.getString(R.string.later);
|
||||
}
|
||||
|
||||
public void setRemindMeLaterLabel(String remindMeLaterLabel) {
|
||||
this.remindMeLaterLabel = remindMeLaterLabel;
|
||||
}
|
||||
|
||||
private String getIgnoreThisVersionLabel() {
|
||||
return ignoreThisVersionLabel != null ? ignoreThisVersionLabel : activity.getString(R.string.ignore);
|
||||
}
|
||||
|
||||
|
||||
private void setMessage(String message) {
|
||||
this.message = message;
|
||||
public void setIgnoreThisVersionLabel(String ignoreThisVersionLabel) {
|
||||
this.ignoreThisVersionLabel = ignoreThisVersionLabel;
|
||||
}
|
||||
|
||||
private String getMessage() {
|
||||
|
@ -146,29 +144,52 @@ class WVersionManager {
|
|||
return message != null ? message : defaultMessage;
|
||||
}
|
||||
|
||||
private void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
private String getTitle() {
|
||||
String defaultTitle = "New Update Available";
|
||||
return title != null ? title : defaultTitle;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
private Drawable getIcon() {
|
||||
return icon != null ? icon : getDefaultAppIcon();
|
||||
}
|
||||
|
||||
public void setIcon(Drawable icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
String getUpdateUrl() {
|
||||
return updateUrl != null ? updateUrl : getGooglePlayStoreUrl();
|
||||
}
|
||||
|
||||
private void setUpdateUrl(String updateUrl) {
|
||||
this.updateUrl = updateUrl;
|
||||
}
|
||||
|
||||
private String getVersionContentUrl() {
|
||||
return versionContentUrl;
|
||||
}
|
||||
|
||||
void setVersionContentUrl(String versionContentUrl) {
|
||||
this.versionContentUrl = versionContentUrl;
|
||||
}
|
||||
|
||||
int getReminderTimer() {
|
||||
return reminderTimer > 0 ? reminderTimer : 1;
|
||||
}
|
||||
|
||||
public void setReminderTimer(int minutes) {
|
||||
if (minutes > 0) {
|
||||
reminderTimer = minutes;
|
||||
}
|
||||
}
|
||||
|
||||
void updateNow(String url) {
|
||||
if (url != null) {
|
||||
|
@ -183,10 +204,6 @@ class WVersionManager {
|
|||
|
||||
}
|
||||
|
||||
void setVersionContentUrl(String versionContentUrl) {
|
||||
this.versionContentUrl = versionContentUrl;
|
||||
}
|
||||
|
||||
void remindMeLater(int reminderTimer) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
|
||||
|
@ -196,15 +213,15 @@ class WVersionManager {
|
|||
setReminderTime(reminderTimeStamp);
|
||||
}
|
||||
|
||||
private long getReminderTime() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(activity).getLong(PREF_REMINDER_TIME, 0);
|
||||
}
|
||||
|
||||
private void setReminderTime(long reminderTimeStamp) {
|
||||
PreferenceManager.getDefaultSharedPreferences(activity).edit().putLong(PREF_REMINDER_TIME, reminderTimeStamp)
|
||||
.apply();
|
||||
}
|
||||
|
||||
private long getReminderTime() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(activity).getLong(PREF_REMINDER_TIME, 0);
|
||||
}
|
||||
|
||||
void ignoreThisVersion() {
|
||||
PreferenceManager.getDefaultSharedPreferences(activity).edit().putInt(PREF_IGNORE_VERSION_CODE, mVersionCode)
|
||||
.apply();
|
||||
|
@ -215,6 +232,50 @@ class WVersionManager {
|
|||
return "market://details?id=" + id;
|
||||
}
|
||||
|
||||
private int getLaunchTimes() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(activity).getInt(PREF_LAUNCH_TIMES, 0);
|
||||
}
|
||||
|
||||
private int getCurrentVersionCode() {
|
||||
int currentVersionCode = 0;
|
||||
PackageInfo pInfo;
|
||||
try {
|
||||
pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
|
||||
currentVersionCode = pInfo.versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
// return 0
|
||||
}
|
||||
return currentVersionCode;
|
||||
}
|
||||
|
||||
private int getIgnoreVersionCode() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(activity).getInt(PREF_IGNORE_VERSION_CODE, 1);
|
||||
}
|
||||
|
||||
private CustomTagHandler getCustomTagHandler() {
|
||||
return customTagHandler;
|
||||
}
|
||||
|
||||
private boolean isDialogCancelable() {
|
||||
return mDialogCancelable;
|
||||
}
|
||||
|
||||
public void setDialogCancelable(boolean dialogCancelable) {
|
||||
mDialogCancelable = dialogCancelable;
|
||||
}
|
||||
|
||||
interface ActivityListener {
|
||||
void isShowUpdateDialog(boolean flag);
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
void onPositive();
|
||||
|
||||
void onNegative();
|
||||
|
||||
void onRemind();
|
||||
}
|
||||
|
||||
private class AlertDialogButtonListener implements DialogInterface.OnClickListener {
|
||||
|
||||
@Override
|
||||
|
@ -278,75 +339,52 @@ class WVersionManager {
|
|||
mVersionCode = 0;
|
||||
String content;
|
||||
String packageName;
|
||||
try {
|
||||
if (!result.startsWith("{")) { // for response who append with unknown char
|
||||
result = result.substring(1);
|
||||
}
|
||||
String mResult = result;
|
||||
// json format from server:
|
||||
JSONObject json = (JSONObject) new JSONTokener(mResult).nextValue();
|
||||
mVersionCode = json.optInt("version_code");
|
||||
String lang = Locale.getDefault().getLanguage();
|
||||
if (lang.equals("ru")) {
|
||||
content = json.optString("content_ru");
|
||||
} else {
|
||||
content = json.optString("content_en");
|
||||
}
|
||||
packageName = json.optString("package");
|
||||
setUpdateUrl("market://details?id=" + packageName);
|
||||
int currentVersionCode = getCurrentVersionCode();
|
||||
if (currentVersionCode < mVersionCode) {
|
||||
if (mVersionCode != getIgnoreVersionCode()) {
|
||||
setMessage(content);
|
||||
al.isShowUpdateDialog(true);
|
||||
} else if (mVersionCode == getIgnoreVersionCode() && getLaunchTimes() % 3 == 0) {
|
||||
PreferenceManager.getDefaultSharedPreferences(activity).edit().putInt(PREF_LAUNCH_TIMES, 0)
|
||||
.apply();
|
||||
setMessage(content);
|
||||
al.isShowUpdateDialog(true);
|
||||
if (result != null) {
|
||||
try {
|
||||
if (!result.startsWith("{")) { // for response who append with unknown char
|
||||
result = result.substring(1);
|
||||
}
|
||||
String mResult = result;
|
||||
// json format from server:
|
||||
JSONObject json = (JSONObject) new JSONTokener(mResult).nextValue();
|
||||
mVersionCode = json.optInt("version_code");
|
||||
String lang = Locale.getDefault().getLanguage();
|
||||
if (lang.equals("ru")) {
|
||||
content = json.optString("content_ru");
|
||||
} else {
|
||||
content = json.optString("content_en");
|
||||
}
|
||||
packageName = json.optString("package");
|
||||
setUpdateUrl("market://details?id=" + packageName);
|
||||
int currentVersionCode = getCurrentVersionCode();
|
||||
if (currentVersionCode < mVersionCode) {
|
||||
if (mVersionCode != getIgnoreVersionCode()) {
|
||||
setMessage(content);
|
||||
al.isShowUpdateDialog(true);
|
||||
} else if (mVersionCode == getIgnoreVersionCode() && getLaunchTimes() % 3 == 0) {
|
||||
PreferenceManager.getDefaultSharedPreferences(activity).edit().putInt(PREF_LAUNCH_TIMES, 0)
|
||||
.apply();
|
||||
setMessage(content);
|
||||
al.isShowUpdateDialog(true);
|
||||
} else {
|
||||
al.isShowUpdateDialog(false);
|
||||
}
|
||||
} else {
|
||||
al.isShowUpdateDialog(false);
|
||||
}
|
||||
} else {
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "is your server response have valid json format?");
|
||||
al.isShowUpdateDialog(false);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
al.isShowUpdateDialog(false);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "is your server response have valid json format?");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
} else {
|
||||
al.isShowUpdateDialog(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getLaunchTimes() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(activity).getInt(PREF_LAUNCH_TIMES, 0);
|
||||
}
|
||||
|
||||
private int getCurrentVersionCode() {
|
||||
int currentVersionCode = 0;
|
||||
PackageInfo pInfo;
|
||||
try {
|
||||
pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
|
||||
currentVersionCode = pInfo.versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
// return 0
|
||||
}
|
||||
return currentVersionCode;
|
||||
}
|
||||
|
||||
private int getIgnoreVersionCode() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(activity).getInt(PREF_IGNORE_VERSION_CODE, 1);
|
||||
}
|
||||
|
||||
private CustomTagHandler getCustomTagHandler() {
|
||||
return customTagHandler;
|
||||
}
|
||||
|
||||
private boolean isDialogCancelable() {
|
||||
return mDialogCancelable;
|
||||
}
|
||||
|
||||
|
||||
private class CustomTagHandler implements Html.TagHandler {
|
||||
|
||||
@Override
|
||||
|
@ -362,47 +400,4 @@ class WVersionManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
void onPositive();
|
||||
|
||||
void onNegative();
|
||||
|
||||
void onRemind();
|
||||
}
|
||||
|
||||
public void setUpdateNowLabel(String updateNowLabel) {
|
||||
this.updateNowLabel = updateNowLabel;
|
||||
}
|
||||
|
||||
public void setRemindMeLaterLabel(String remindMeLaterLabel) {
|
||||
this.remindMeLaterLabel = remindMeLaterLabel;
|
||||
}
|
||||
|
||||
public void setIgnoreThisVersionLabel(String ignoreThisVersionLabel) {
|
||||
this.ignoreThisVersionLabel = ignoreThisVersionLabel;
|
||||
}
|
||||
|
||||
public void setIcon(Drawable icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
private void setUpdateUrl(String updateUrl) {
|
||||
this.updateUrl = updateUrl;
|
||||
}
|
||||
|
||||
|
||||
public void setReminderTimer(int minutes) {
|
||||
if (minutes > 0) {
|
||||
reminderTimer = minutes;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDialogCancelable(boolean dialogCancelable) {
|
||||
mDialogCancelable = dialogCancelable;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 26 KiB |
|
@ -1,14 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<shape>
|
||||
<padding
|
||||
android:bottom="3dip"
|
||||
android:left="3dip"
|
||||
android:right="3dip"
|
||||
android:top="3dip" />
|
||||
<corners android:radius="5dip" />
|
||||
<gradient
|
||||
android:centerY="0.50"
|
||||
android:endColor="#2a2b2f"
|
||||
android:startColor="#2a2b2f" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@android:id/progress">
|
||||
<clip>
|
||||
<shape>
|
||||
<corners android:radius="5dip" />
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:centerColor="#808080"
|
||||
android:centerY="1.0"
|
||||
android:endColor="#808080"
|
||||
android:startColor="#808080" />
|
||||
android:endColor="#37C830"
|
||||
android:startColor="#37C830" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
</layer-list>
|
||||
</layer-list>
|
Binary file not shown.
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
@ -4,42 +4,26 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
<ProgressBar
|
||||
android:id="@+id/PB1"
|
||||
style="@style/CustomProgressBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="30dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginLeft="90dp"
|
||||
android:layout_marginRight="90dp"
|
||||
android:indeterminate="false"
|
||||
android:max="100"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_progress_circle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="40dp"
|
||||
android:src="@drawable/logo" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginLeft="96dp"
|
||||
android:layout_marginRight="96dp">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/PB1"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="28dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="#404040"
|
||||
android:visibility="gone"
|
||||
android:indeterminate="false"
|
||||
android:max="100" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_progress_circle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:gravity="center"
|
||||
android:text="@string/loading"
|
||||
android:textColor="#FEFEFE" />
|
||||
</RelativeLayout>
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:gravity="center"
|
||||
android:text="@string/loading"
|
||||
android:textColor="#FEFEFE"
|
||||
android:visibility="gone" />
|
||||
</RelativeLayout>
|
|
@ -32,7 +32,6 @@
|
|||
android:hint="@string/rate_description" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/rate_submit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
|
@ -6,7 +6,7 @@
|
|||
<string name="loading">Загрузка…</string>
|
||||
<string name="notification_title">Загрузка MultiCraft</string>
|
||||
<string name="notification_description">Осталось меньше минуты…</string>
|
||||
<string name="not_enough_space">Недостаточно места для распаковки.\nОсвободите пространство в памяти устройства!</string>
|
||||
|
||||
<!-- разрешения -->
|
||||
<string name="explain">Для корректной работы, игре требуется разрешение записывать в память устройтсва.</string>
|
||||
<string name="location">Знание местоположения обеспечивает Вам лучшее взаимодействие с игрой</string>
|
||||
|
@ -21,4 +21,6 @@
|
|||
<string name="ignore">Игнорировать</string>
|
||||
<string name="later">Позже</string>
|
||||
<string name="update">Обновить</string>
|
||||
<!-- reminder -->
|
||||
<string name="message">Сообщение</string>
|
||||
</resources>
|
|
@ -18,5 +18,5 @@
|
|||
<item name="android:windowIsTranslucent">true</item>
|
||||
</style>
|
||||
|
||||
<style name="CustomLollipopDialogStyle" parent="android:Theme.Material.Light.Dialog.Alert"/>
|
||||
<style name="CustomLollipopDialogStyle" parent="android:Theme.Material.Light.Dialog.Alert" />
|
||||
</resources>
|
|
@ -2,8 +2,8 @@
|
|||
<resources>
|
||||
|
||||
<string name="app_name" translatable="false">MultiCraft</string>
|
||||
<string name="ver" translatable="false">1.1.5</string>
|
||||
<string name="google_app_id" translatable="false">312077575425</string>
|
||||
<string name="ver" translatable="false">1.1.7</string>
|
||||
|
||||
<!-- preparation for start -->
|
||||
|
||||
<string name="rm_old">Preparing to update…</string>
|
||||
|
@ -11,9 +11,6 @@
|
|||
<string name="notification_title">Loading MultiCraft</string>
|
||||
<string name="notification_description">Less than 1 minute…</string>
|
||||
|
||||
<!-- free space dialog -->
|
||||
<string name="not_enough_space">Not enough space for unpack game data.\nPlease free some space on the storage memory!</string>
|
||||
|
||||
<!-- permission block -->
|
||||
<string name="explain">Game need permission to write files to storage memory.</string>
|
||||
<string name="location">Location permission provide you better interaction with game</string>
|
||||
|
@ -30,4 +27,6 @@
|
|||
<string name="later">Later</string>
|
||||
<string name="ignore">Ignore</string>
|
||||
|
||||
<!-- reminder -->
|
||||
<string name="message">Message</string>
|
||||
</resources>
|
|
@ -18,4 +18,10 @@
|
|||
<item name="android:windowIsTranslucent">true</item>
|
||||
</style>
|
||||
|
||||
<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal">
|
||||
<item name="android:indeterminateOnly">false</item>
|
||||
<item name="android:progressDrawable">@drawable/custom_progress_bar</item>
|
||||
<item name="android:minHeight">10dip</item>
|
||||
<item name="android:maxHeight">20dip</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in New Issue