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