Version check, help dialog were changed. ANR after screen off fixed. CPU check was added. Locale check was added
This commit is contained in:
parent
a899fdf13e
commit
8343e4c47b
@ -25,6 +25,7 @@
|
||||
android:theme="@style/MCTheme" >
|
||||
<activity
|
||||
android:name="mobi.MultiCraft.MainActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:screenOrientation="sensorLandscape" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@ -35,7 +36,7 @@
|
||||
<activity
|
||||
android:name="mobi.MultiCraft.MCNativeActivity"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|navigation"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|navigation|screenSize"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="sensorLandscape" >
|
||||
|
@ -21,7 +21,7 @@
|
||||
<string name="memory_lags">Возможны лаги при игре. Пожалуйста, не оценивайте приложение плохо,\nтак как у вас слабый аппарат.</string>
|
||||
<string name="memory_continue">Играть!</string>
|
||||
<string name="memory_close">Закрыть</string>
|
||||
<string name="memory_warning">У Вашего устройства недостаточно оперативной памяти для игры без лагов. Требуется более мощное устройство!</string>
|
||||
<string name="memory_warning">У Вашего устройства недостаточно оперативной памяти для игры без лагов. Требуется более мощное устройство!\nЛибо игра несовместима с вашим типом процессора</string>
|
||||
|
||||
<!-- диалог обновления -->
|
||||
<string name="update_yes">Обновиться!</string>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<string name="notification_description">Less than 1 minute…</string>
|
||||
|
||||
<!-- weak phone dialog -->
|
||||
<string name="memory_warning">Your device\'s memory is too low for seamless playing</string>
|
||||
<string name="memory_warning">Your device\'s memory is too low for seamless playing or\n game is not compatible with your CPU</string>
|
||||
<string name="memory_continue">Continue</string>
|
||||
<string name="memory_close">Close</string>
|
||||
<string name="memory_lags">Lags are possible. Please don\'t rate this game badly.</string>
|
||||
|
@ -5,12 +5,16 @@ import static mobi.MultiCraft.PreferencesHelper.isCreateShortcut;
|
||||
import static mobi.MultiCraft.PreferencesHelper.saveSettings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Locale;
|
||||
|
||||
import mobi.MultiCraft.R;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -34,9 +38,8 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
public final String NOMEDIA = ".nomedia";
|
||||
private ProgressDialog mProgressDialog;
|
||||
private TextView mProgressTextView;
|
||||
private String unzipLocation = Environment.getExternalStorageDirectory()
|
||||
+ "/MultiCraft/";
|
||||
private File version;
|
||||
private String unzipLocation = Environment.getExternalStorageDirectory() + "/MultiCraft/";
|
||||
private Utilities util;
|
||||
private ProgressBar mProgressBar;
|
||||
private MyBroadcastReceiver myBroadcastReceiver;
|
||||
@ -54,13 +57,31 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (util.getTotalMemoryInMB() < 800 || util.getCoresCount() < 2) {
|
||||
if (util.getTotalMemoryInMB() < 800 || util.getCoresCount() < 2 || util.getCPUArch()) {
|
||||
util.showMemoryDialog();
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
private void createLangFile() {
|
||||
PrintWriter writer;
|
||||
try {
|
||||
writer = new PrintWriter(unzipLocation + "lang.txt", "UTF-8");
|
||||
if ("Russian".equals(Locale.getDefault().getDisplayLanguage())) {
|
||||
writer.println("ru");
|
||||
} else {
|
||||
writer.println("en");
|
||||
}
|
||||
writer.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e("WTF", e.getLocalizedMessage());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e("WTF", e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createDirAndNoMedia() {
|
||||
try {
|
||||
File folder = new File(unzipLocation);
|
||||
@ -76,20 +97,18 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
|
||||
private void addShortcut() {
|
||||
saveSettings(this, TAG_SHORTCUT_CREATED, false);
|
||||
Intent shortcutIntent = new Intent(getApplicationContext(),
|
||||
MainActivity.class);
|
||||
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_NAME, getString(R.string.app_name));
|
||||
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||
Intent.ShortcutIconResource.fromContext(
|
||||
getApplicationContext(), R.drawable.ic_launcher));
|
||||
Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
|
||||
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
||||
getApplicationContext().sendBroadcast(addIntent);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressWarnings("deprecation")
|
||||
public void init() {
|
||||
PreferencesHelper.loadSettings(this);
|
||||
@ -99,8 +118,7 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.PB1);
|
||||
Drawable draw;
|
||||
if (Build.VERSION.SDK_INT > 21) {
|
||||
draw = getResources().getDrawable(R.drawable.custom_progress_bar,
|
||||
null);
|
||||
draw = getResources().getDrawable(R.drawable.custom_progress_bar, null);
|
||||
} else {
|
||||
draw = getResources().getDrawable(R.drawable.custom_progress_bar);
|
||||
}
|
||||
@ -108,6 +126,7 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
mProgressBar.setProgressDrawable(draw);
|
||||
createDirAndNoMedia();
|
||||
version = new File(unzipLocation + "ver.txt");
|
||||
createLangFile();
|
||||
checkVersion();
|
||||
}
|
||||
|
||||
@ -115,15 +134,31 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
finish();
|
||||
}
|
||||
|
||||
private void checkVersion() {
|
||||
if (version.exists()) {
|
||||
if (util.isCurrent(version))
|
||||
startNativeActivity();
|
||||
else
|
||||
startDeletion();
|
||||
|
||||
} else {
|
||||
startDeletion();
|
||||
}
|
||||
}
|
||||
|
||||
private void startDeletion() {
|
||||
new DeleteTask().execute(unzipLocation + "cache", unzipLocation + "games", unzipLocation + "builtin",
|
||||
unzipLocation + "fonts", unzipLocation + "debug.txt");
|
||||
|
||||
}
|
||||
|
||||
private void registerReceivers() {
|
||||
myBroadcastReceiver = new MyBroadcastReceiver();
|
||||
myBroadcastReceiver_Update = new MyBroadcastReceiver_Update();
|
||||
IntentFilter intentFilter = new IntentFilter(
|
||||
UnzipService.ACTION_MyIntentService);
|
||||
IntentFilter intentFilter = new IntentFilter(UnzipService.ACTION_MyIntentService);
|
||||
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
registerReceiver(myBroadcastReceiver, intentFilter);
|
||||
IntentFilter intentFilter_update = new IntentFilter(
|
||||
UnzipService.ACTION_MyUpdate);
|
||||
IntentFilter intentFilter_update = new IntentFilter(UnzipService.ACTION_MyUpdate);
|
||||
intentFilter_update.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
registerReceiver(myBroadcastReceiver_Update, intentFilter_update);
|
||||
}
|
||||
@ -144,31 +179,12 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkVersion() {
|
||||
if (version.exists()) {
|
||||
switch (util.compareVersions(version)) {
|
||||
case OLD:
|
||||
new DeleteTask().execute(unzipLocation + "cache", unzipLocation
|
||||
+ "games/MultiCraft", unzipLocation + "tmp");
|
||||
break;
|
||||
case CURRENT:
|
||||
startNativeActivity();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
new DeleteTask().execute(unzipLocation + "cache", unzipLocation
|
||||
+ "games/MultiCraft", unzipLocation + "tmp");
|
||||
}
|
||||
}
|
||||
|
||||
private void startNativeActivity() {
|
||||
showSpinnerDialog(R.string.loading);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Intent intent = new Intent(MainActivity.this,
|
||||
MCNativeActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
Intent intent = new Intent(MainActivity.this, MCNativeActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
if (isFinishing())
|
||||
return;
|
||||
@ -184,8 +200,7 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
// Start MyIntentService
|
||||
Intent intentMyIntentService = new Intent(this, UnzipService.class);
|
||||
intentMyIntentService.putExtra(UnzipService.EXTRA_KEY_IN_FILE, file);
|
||||
intentMyIntentService.putExtra(UnzipService.EXTRA_KEY_IN_LOCATION,
|
||||
unzipLocation);
|
||||
intentMyIntentService.putExtra(UnzipService.EXTRA_KEY_IN_LOCATION, unzipLocation);
|
||||
startService(intentMyIntentService);
|
||||
|
||||
}
|
||||
@ -254,7 +269,6 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
showSpinnerDialog(R.string.copy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -267,13 +281,9 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
if (isFinishing())
|
||||
return;
|
||||
dismissProgressDialog();
|
||||
if (util.getAvailableSpaceInMB() > 30) {
|
||||
try {
|
||||
startUnzipService(Environment.getExternalStorageDirectory()
|
||||
+ "/" + zipName);
|
||||
startUnzipService(Environment.getExternalStorageDirectory() + "/" + zipName);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
@ -286,9 +296,7 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
OutputStream out;
|
||||
try {
|
||||
in = getAssets().open(zipName);
|
||||
out = new FileOutputStream(
|
||||
Environment.getExternalStorageDirectory() + "/"
|
||||
+ zipName);
|
||||
out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/" + zipName);
|
||||
copyFile(in, out);
|
||||
in.close();
|
||||
out.flush();
|
||||
@ -298,8 +306,7 @@ public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFile(InputStream in, OutputStream out)
|
||||
throws IOException {
|
||||
private void copyFile(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
|
@ -11,7 +11,8 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import mobi.MultiCraft.R;
|
||||
import com.winsontan520.wversionmanager.library.WVersionManager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
@ -29,23 +30,13 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import mobi.MultiCraft.RateThisApp;
|
||||
import com.winsontan520.wversionmanager.library.WVersionManager;
|
||||
|
||||
/**
|
||||
* Helpful utilities used in MainActivity
|
||||
*/
|
||||
public class Utilities {
|
||||
private Button positive, negative;
|
||||
private Dialog dialog;
|
||||
|
||||
public enum VERSIONS {
|
||||
CURRENT, OLD
|
||||
}
|
||||
|
||||
private final String TAG = Utilities.class.getName();
|
||||
private Context mContext;
|
||||
|
||||
public final String STABLE_VER = "1.0.1";
|
||||
|
||||
/**
|
||||
@ -64,8 +55,7 @@ public class Utilities {
|
||||
callerActivity = (IUtilitiesCallback) activity;
|
||||
}
|
||||
|
||||
private void dialogInit(int panel, int positiveBtn, int negativeBtn,
|
||||
int messageText) {
|
||||
private void dialogInit(int panel, int positiveBtn, int negativeBtn, int messageText) {
|
||||
dialog = new Dialog(mContext);
|
||||
dialog.requestWindowFeature(panel);
|
||||
dialog.setContentView(R.layout.dialog_template);
|
||||
@ -76,23 +66,13 @@ public class Utilities {
|
||||
negative.setText(negativeBtn);
|
||||
message.setText(messageText);
|
||||
dialog.setCancelable(false);
|
||||
dialog.getWindow().setBackgroundDrawable(
|
||||
new ColorDrawable(R.color.semi_transparent));
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(R.color.semi_transparent));
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public void showHelpDialog() {
|
||||
dialogInit(Window.FEATURE_NO_TITLE, R.string.ok, R.string.forget,
|
||||
R.string.dialog_instruction);
|
||||
dialogInit(Window.FEATURE_NO_TITLE, R.string.ok, R.string.forget, R.string.dialog_instruction);
|
||||
positive.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
RateThisApp.showRateDialogIfNeeded(mContext);
|
||||
}
|
||||
});
|
||||
negative.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
@ -100,34 +80,29 @@ public class Utilities {
|
||||
RateThisApp.showRateDialogIfNeeded(mContext);
|
||||
}
|
||||
});
|
||||
negative.setVisibility(View.GONE);
|
||||
if (isShowHelp()) {
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void showVersionDialog() {
|
||||
WVersionManager versionManager = new WVersionManager(
|
||||
(Activity) mContext);
|
||||
versionManager
|
||||
.setVersionContentUrl("http://MultiCraft.mobi/ver/MultiCraft.txt");
|
||||
WVersionManager versionManager = new WVersionManager((Activity) mContext);
|
||||
versionManager.setVersionContentUrl("http://MultiCraft.mobi/ver/MultiCraft.txt");
|
||||
versionManager.checkVersion();
|
||||
versionManager.setUpdateNowLabel((String) mContext.getResources()
|
||||
.getText(R.string.update_yes));
|
||||
versionManager.setRemindMeLaterLabel((String) mContext.getResources()
|
||||
.getText(R.string.update_no));
|
||||
versionManager.setIgnoreThisVersionLabel((String) mContext
|
||||
.getResources().getText(R.string.update_ignore));
|
||||
versionManager.setUpdateNowLabel((String) mContext.getResources().getText(R.string.update_yes));
|
||||
versionManager.setRemindMeLaterLabel((String) mContext.getResources().getText(R.string.update_no));
|
||||
versionManager.setIgnoreThisVersionLabel((String) mContext.getResources().getText(R.string.update_ignore));
|
||||
}
|
||||
|
||||
public void showMemoryDialog() {
|
||||
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.memory_continue,
|
||||
R.string.memory_close, R.string.memory_warning);
|
||||
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.memory_continue, R.string.memory_close,
|
||||
R.string.memory_warning);
|
||||
positive.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
Toast.makeText(mContext, R.string.memory_lags,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(mContext, R.string.memory_lags, Toast.LENGTH_SHORT).show();
|
||||
callerActivity.init();
|
||||
}
|
||||
});
|
||||
@ -143,15 +118,13 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public void showNotEnoughSpaceDialog() {
|
||||
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.space_ok,
|
||||
R.string.memory_close, R.string.not_enough_space);
|
||||
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.space_ok, R.string.memory_close, R.string.not_enough_space);
|
||||
negative.setVisibility(View.GONE);
|
||||
positive.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
Toast.makeText(mContext, R.string.memory_lags,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(mContext, R.string.memory_lags, Toast.LENGTH_SHORT).show();
|
||||
callerActivity.init();
|
||||
}
|
||||
});
|
||||
@ -161,8 +134,7 @@ public class Utilities {
|
||||
public long getTotalMemoryInMB() {
|
||||
long initial_memory;
|
||||
if (Build.VERSION.SDK_INT > 17) {
|
||||
ActivityManager actManager = (ActivityManager) mContext
|
||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ActivityManager actManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||
actManager.getMemoryInfo(memInfo);
|
||||
initial_memory = memInfo.totalMem;
|
||||
@ -173,8 +145,7 @@ public class Utilities {
|
||||
|
||||
try {
|
||||
FileReader localFileReader = new FileReader(str1);
|
||||
BufferedReader localBufferedReader = new BufferedReader(
|
||||
localFileReader, 8192);
|
||||
BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
|
||||
str2 = localBufferedReader.readLine();// meminfo
|
||||
arrayOfString = str2.split("\\s+");
|
||||
// total Memory
|
||||
@ -203,40 +174,38 @@ public class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressWarnings("deprecation")
|
||||
public long getAvailableSpaceInMB() {
|
||||
final long SIZE_KB = 1024L;
|
||||
final long SIZE_MB = SIZE_KB * SIZE_KB;
|
||||
long availableSpace;
|
||||
StatFs stat = new StatFs(Environment.getExternalStorageDirectory()
|
||||
.getPath());
|
||||
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
||||
if (Build.VERSION.SDK_INT > 17) {
|
||||
availableSpace = stat.getAvailableBlocksLong()
|
||||
* stat.getBlockSizeLong();
|
||||
availableSpace = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
|
||||
} else {
|
||||
availableSpace = (long) stat.getAvailableBlocks()
|
||||
* (long) stat.getBlockSize();
|
||||
availableSpace = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
|
||||
}
|
||||
return availableSpace / SIZE_MB;
|
||||
}
|
||||
|
||||
public VERSIONS compareVersions(File file) {
|
||||
VERSIONS result;
|
||||
@SuppressWarnings("resource")
|
||||
public boolean isCurrent(File file) {
|
||||
String line = null;
|
||||
try {
|
||||
line = new BufferedReader(new FileReader(file)).readLine();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
Log.e("WTF", e.getMessage());
|
||||
}
|
||||
|
||||
if (line == null) {
|
||||
line = "-999";
|
||||
}
|
||||
if (line.equals(STABLE_VER)) {
|
||||
result = VERSIONS.CURRENT;
|
||||
} else
|
||||
result = VERSIONS.OLD;
|
||||
return result;
|
||||
return line.equals(STABLE_VER);
|
||||
}
|
||||
|
||||
public boolean getCPUArch() {
|
||||
String arch = System.getProperty("os.arch");
|
||||
return !arch.matches(".*arm.*");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user