latest changes
This commit is contained in:
parent
966f919a4c
commit
72f08ab8f3
@ -49,7 +49,6 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".InputDialogActivity"
|
android:name=".InputDialogActivity"
|
||||||
android:excludeFromRecents="true"
|
|
||||||
android:theme="@style/Theme.Transparent" />
|
android:theme="@style/Theme.Transparent" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
|
BIN
build/android/res/drawable/background.png
Normal file
BIN
build/android/res/drawable/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.2 KiB |
4
build/android/res/drawable/bg.xml
Normal file
4
build/android/res/drawable/bg.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<!--?xml version="1.0" encoding="utf-8"??-->
|
||||||
|
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:src="@drawable/background"
|
||||||
|
android:tileMode="repeat" />
|
@ -1,14 +1,13 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<!-- Define the progress properties like start color, end color etc -->
|
|
||||||
<item android:id="@android:id/progress">
|
<item android:id="@android:id/progress">
|
||||||
<clip>
|
<clip>
|
||||||
<shape>
|
<shape>
|
||||||
<gradient
|
<gradient
|
||||||
android:angle="270"
|
android:angle="270"
|
||||||
android:centerColor="#007A00"
|
android:centerColor="#808080"
|
||||||
android:centerY="1.0"
|
android:centerY="1.0"
|
||||||
android:endColor="#06101d"
|
android:endColor="#808080"
|
||||||
android:startColor="#007A00" />
|
android:startColor="#808080" />
|
||||||
</shape>
|
</shape>
|
||||||
</clip>
|
</clip>
|
||||||
</item>
|
</item>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
android:id="@+id/activity_main"
|
android:id="@+id/activity_main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#000000">
|
android:background="@drawable/bg">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imageView"
|
android:id="@+id/imageView"
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
<string name="loading">Загрузка…</string>
|
<string name="loading">Загрузка…</string>
|
||||||
<string name="notification_title">Загрузка MultiCraft</string>
|
<string name="notification_title">Загрузка MultiCraft</string>
|
||||||
<string name="notification_description">Осталось меньше минуты…</string>
|
<string name="notification_description">Осталось меньше минуты…</string>
|
||||||
<string name="ok">Закрыть</string>
|
|
||||||
<string name="not_enough_space">Недостаточно места для распаковки.\nОсвободите пространство в памяти устройства!</string>
|
<string name="not_enough_space">Недостаточно места для распаковки.\nОсвободите пространство в памяти устройства!</string>
|
||||||
<string name="space_ok">OK</string>
|
|
||||||
<string name="explain">Для корректной работы, игре требуется разрешение записывать в память устройтсва.</string>
|
<string name="explain">Для корректной работы, игре требуется разрешение записывать в память устройтсва.</string>
|
||||||
</resources>
|
</resources>
|
10
build/android/res/values-v21/styles.xml
Normal file
10
build/android/res/values-v21/styles.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<style name="Theme.Transparent" parent="@android:style/Theme.Material.NoActionBar.Fullscreen">
|
||||||
|
<item name="android:windowNoTitle">true</item>
|
||||||
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
|
<item name="android:windowIsTranslucent">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
@ -2,7 +2,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name" translatable="false">MultiCraft</string>
|
<string name="app_name" translatable="false">MultiCraft</string>
|
||||||
<string name="ver" translatable="false">1.1.2.2</string>
|
<string name="ver" translatable="false">1.1.3</string>
|
||||||
<string name="google_app_id" translatable="false">312077575425</string>
|
<string name="google_app_id" translatable="false">312077575425</string>
|
||||||
<!-- preparation for start -->
|
<!-- preparation for start -->
|
||||||
|
|
||||||
@ -10,11 +10,9 @@
|
|||||||
<string name="loading">Loading…</string>
|
<string name="loading">Loading…</string>
|
||||||
<string name="notification_title">Loading MultiCraft</string>
|
<string name="notification_title">Loading MultiCraft</string>
|
||||||
<string name="notification_description">Less than 1 minute…</string>
|
<string name="notification_description">Less than 1 minute…</string>
|
||||||
<string name="ok">Close</string>
|
|
||||||
|
|
||||||
<!-- free space dialog -->
|
<!-- free space dialog -->
|
||||||
<string name="not_enough_space">Not enough space for unpack game data.\nPlease free some space on the storage memory!</string>
|
<string name="not_enough_space">Not enough space for unpack game data.\nPlease free some space on the storage memory!</string>
|
||||||
<string name="space_ok">OK</string>
|
|
||||||
|
|
||||||
<!-- permission block -->
|
<!-- permission block -->
|
||||||
<string name="explain">Game need permission to write files to storage memory.</string>
|
<string name="explain">Game need permission to write files to storage memory.</string>
|
||||||
|
@ -3,11 +3,8 @@
|
|||||||
|
|
||||||
<style name="Theme.Transparent" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
|
<style name="Theme.Transparent" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
|
||||||
<item name="android:windowNoTitle">true</item>
|
<item name="android:windowNoTitle">true</item>
|
||||||
<item name="android:background">@android:color/transparent</item>
|
|
||||||
<item name="android:windowBackground">@android:color/transparent</item>
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
|
||||||
<item name="android:windowIsTranslucent">true</item>
|
<item name="android:windowIsTranslucent">true</item>
|
||||||
<item name="android:windowAnimationStyle">@android:style/Animation</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -9,16 +9,12 @@ import android.view.WindowManager;
|
|||||||
|
|
||||||
public class GameActivity extends NativeActivity {
|
public class GameActivity extends NativeActivity {
|
||||||
static {
|
static {
|
||||||
|
|
||||||
System.loadLibrary("vorbis");
|
|
||||||
System.loadLibrary("gmp");
|
System.loadLibrary("gmp");
|
||||||
System.loadLibrary("ssl");
|
|
||||||
System.loadLibrary("crypto");
|
|
||||||
System.loadLibrary("multicraft");
|
System.loadLibrary("multicraft");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int m_MessagReturnCode;
|
private int messageReturnCode;
|
||||||
private String m_MessageReturnValue;
|
private String messageReturnValue;
|
||||||
|
|
||||||
public static native void putMessageBoxResult(String text);
|
public static native void putMessageBoxResult(String text);
|
||||||
|
|
||||||
@ -27,8 +23,9 @@ public class GameActivity extends NativeActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
// startAd(this, true);
|
// startAd(this, true);
|
||||||
m_MessagReturnCode = -1;
|
messageReturnCode = -1;
|
||||||
m_MessageReturnValue = "";
|
messageReturnValue = "";
|
||||||
|
makeFullScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,10 +66,10 @@ public class GameActivity extends NativeActivity {
|
|||||||
if (requestCode == 101) {
|
if (requestCode == 101) {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
String text = data.getStringExtra("text");
|
String text = data.getStringExtra("text");
|
||||||
m_MessagReturnCode = 0;
|
messageReturnCode = 0;
|
||||||
m_MessageReturnValue = text;
|
messageReturnValue = text;
|
||||||
} else {
|
} else {
|
||||||
m_MessagReturnCode = 1;
|
messageReturnCode = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,17 +86,17 @@ public class GameActivity extends NativeActivity {
|
|||||||
params.putInt("editType", editType);
|
params.putInt("editType", editType);
|
||||||
intent.putExtras(params);
|
intent.putExtras(params);
|
||||||
startActivityForResult(intent, 101);
|
startActivityForResult(intent, 101);
|
||||||
m_MessageReturnValue = "";
|
messageReturnValue = "";
|
||||||
m_MessagReturnCode = -1;
|
messageReturnCode = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDialogState() {
|
public int getDialogState() {
|
||||||
return m_MessagReturnCode;
|
return messageReturnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDialogValue() {
|
public String getDialogValue() {
|
||||||
m_MessagReturnCode = -1;
|
messageReturnCode = -1;
|
||||||
return m_MessageReturnValue;
|
return messageReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDensity() {
|
public float getDensity() {
|
||||||
|
@ -1,30 +1,38 @@
|
|||||||
package mobi.MultiCraft;
|
package mobi.MultiCraft;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnKeyListener;
|
import android.view.View.OnKeyListener;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
|
||||||
public class InputDialogActivity extends Activity {
|
public class InputDialogActivity extends Activity {
|
||||||
private AlertDialog alertDialog;
|
private AlertDialog alertDialog;
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Bundle b = getIntent().getExtras();
|
Bundle b = getIntent().getExtras();
|
||||||
int editType = b.getInt("editType");
|
int editType = b.getInt("editType");
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
LayoutInflater inflater = this.getLayoutInflater();
|
LayoutInflater inflater = this.getLayoutInflater();
|
||||||
View dialogView = inflater.inflate(R.layout.dialog, null);
|
View dialogView = inflater.inflate(R.layout.dialog, null);
|
||||||
builder.setView(dialogView);
|
builder.setView(dialogView);
|
||||||
final EditText editText = (EditText) dialogView.findViewById(R.id.editText);
|
final EditText editText = (EditText) dialogView.findViewById(R.id.editText);
|
||||||
|
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||||
if (editType == 3) {
|
if (editType == 3) {
|
||||||
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
} else {
|
} else {
|
||||||
@ -34,23 +42,34 @@ public class InputDialogActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKey(View view, int KeyCode, KeyEvent event) {
|
public boolean onKey(View view, int KeyCode, KeyEvent event) {
|
||||||
if (KeyCode == KeyEvent.KEYCODE_ENTER) {
|
if (KeyCode == KeyEvent.KEYCODE_ENTER) {
|
||||||
|
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
||||||
pushResult(editText.getText().toString());
|
pushResult(editText.getText().toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
alertDialog = builder.create();
|
alertDialog = builder.create();
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
|
alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
pushResult(editText.getText().toString());
|
||||||
|
setResult(Activity.RESULT_CANCELED);
|
||||||
|
alertDialog.dismiss();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushResult(String text) {
|
public void pushResult(String text) {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && text.matches(".*[А-я].*")) {
|
||||||
|
text = Transliteration.toLatin(text);
|
||||||
|
}
|
||||||
Intent resultData = new Intent();
|
Intent resultData = new Intent();
|
||||||
resultData.putExtra("text", text);
|
resultData.putExtra("text", text);
|
||||||
setResult(Activity.RESULT_OK, resultData);
|
setResult(Activity.RESULT_OK, resultData);
|
||||||
alertDialog.dismiss();
|
alertDialog.dismiss();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -24,7 +24,6 @@ import android.widget.ProgressBar;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -46,17 +45,10 @@ public class MainActivity extends Activity {
|
|||||||
public final static String NOMEDIA = ".nomedia";
|
public final static String NOMEDIA = ".nomedia";
|
||||||
private final static int REQUEST_STORAGE = 0;
|
private final static int REQUEST_STORAGE = 0;
|
||||||
private ProgressDialog mProgressDialog;
|
private ProgressDialog mProgressDialog;
|
||||||
private String oldDataFolder = "/MultiCraft";
|
|
||||||
private String dataFolder = "/Android/data/mobi.MultiCraft/files/";
|
private String dataFolder = "/Android/data/mobi.MultiCraft/files/";
|
||||||
private String unzipLocation = Environment.getExternalStorageDirectory() + dataFolder;
|
private String unzipLocation = Environment.getExternalStorageDirectory() + dataFolder;
|
||||||
private String oldUnzipLocation = Environment.getExternalStorageDirectory() + oldDataFolder;
|
|
||||||
private String oldWorldLocation = oldUnzipLocation + "/worlds";
|
|
||||||
private String oldGamesLocation = oldUnzipLocation + "/games/MultiCraft_game";
|
|
||||||
private String newWorldLocation = unzipLocation + "/worlds";
|
|
||||||
private String newGamesLocation = unzipLocation + "/games/MultiCraft_game";
|
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
private Utilities util;
|
private Utilities util;
|
||||||
private boolean isCopyOld = false;
|
|
||||||
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@ -66,13 +58,9 @@ public class MainActivity extends Activity {
|
|||||||
mProgressBar.setProgress(progress);
|
mProgressBar.setProgress(progress);
|
||||||
} else {
|
} else {
|
||||||
util.createNomedia();
|
util.createNomedia();
|
||||||
if (isCopyOld) {
|
|
||||||
new CopyFolderTask().execute(new String[]{oldWorldLocation, newWorldLocation}, new String[]{oldGamesLocation, newGamesLocation});
|
|
||||||
} else {
|
|
||||||
runGame();
|
runGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -103,6 +91,14 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
|
super.onWindowFocusChanged(hasFocus);
|
||||||
|
if (hasFocus) {
|
||||||
|
makeFullScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@ -237,29 +233,6 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CopyFolderTask extends AsyncTask<String[], Void, Void> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(String[]... params) {
|
|
||||||
for (String[] p : params) {
|
|
||||||
File src = new File(p[0]);
|
|
||||||
File dest = new File(p[1]);
|
|
||||||
try {
|
|
||||||
util.copyDirectory(src, dest);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "copy failed: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void aVoid) {
|
|
||||||
util.deleteFiles(oldUnzipLocation);
|
|
||||||
runGame();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CopyZip extends AsyncTask<String, Void, String> {
|
private class CopyZip extends AsyncTask<String, Void, String> {
|
||||||
String[] zips;
|
String[] zips;
|
||||||
|
|
||||||
@ -317,17 +290,6 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
private class Utilities {
|
private class Utilities {
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 (Exception e) { Log.e(TAG,
|
|
||||||
* e.getLocalizedMessage()); }
|
|
||||||
*
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void createDataFolder() {
|
private void createDataFolder() {
|
||||||
File folder = new File(unzipLocation);
|
File folder = new File(unzipLocation);
|
||||||
if (!(folder.exists()))
|
if (!(folder.exists()))
|
||||||
@ -371,13 +333,9 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkVersion() {
|
public void checkVersion() {
|
||||||
if (isFolderEmpty(oldUnzipLocation) && isFolderEmpty(unzipLocation)) {
|
if (isFolderEmpty(unzipLocation)) {
|
||||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
||||||
startDeletion(true);
|
startDeletion(true);
|
||||||
} else if (!isFolderEmpty(oldUnzipLocation)) {
|
|
||||||
saveSettings(TAG_BUILD_NUMBER, getString(R.string.ver));
|
|
||||||
isCopyOld = true;
|
|
||||||
startDeletion(true);
|
|
||||||
} else if (getBuildNumber().equals(getString(R.string.ver))) {
|
} else if (getBuildNumber().equals(getString(R.string.ver))) {
|
||||||
runGame();
|
runGame();
|
||||||
} else {
|
} else {
|
||||||
@ -386,40 +344,6 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyDirectory(File sourceLocation, File targetLocation)
|
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
if (sourceLocation.isDirectory()) {
|
|
||||||
if (!targetLocation.exists() && !targetLocation.mkdirs()) {
|
|
||||||
throw new IOException("Cannot create dir " + targetLocation.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] children = sourceLocation.list();
|
|
||||||
for (String aChildren : children) {
|
|
||||||
copyDirectory(new File(sourceLocation, aChildren),
|
|
||||||
new File(targetLocation, aChildren));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// make sure the directory we plan to store the recording in exists
|
|
||||||
File directory = targetLocation.getParentFile();
|
|
||||||
if (directory != null && !directory.exists() && !directory.mkdirs()) {
|
|
||||||
throw new IOException("Cannot create dir " + directory.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream in = new FileInputStream(sourceLocation);
|
|
||||||
OutputStream out = new FileOutputStream(targetLocation);
|
|
||||||
|
|
||||||
// Copy the bits from in stream to out stream
|
|
||||||
byte[] buf = new byte[1024];
|
|
||||||
int len;
|
|
||||||
while ((len = in.read(buf)) > 0) {
|
|
||||||
out.write(buf, 0, len);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteFiles(String path) {
|
private void deleteFiles(String path) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
72
build/android/src/mobi/MultiCraft/Transliteration.java
Normal file
72
build/android/src/mobi/MultiCraft/Transliteration.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package mobi.MultiCraft;
|
||||||
|
|
||||||
|
public class Transliteration {
|
||||||
|
|
||||||
|
private static final String[] CHAR_TABLE = new String[81];
|
||||||
|
private static final char START_CHAR = 'Ё';
|
||||||
|
|
||||||
|
|
||||||
|
static {
|
||||||
|
CHAR_TABLE['А' - START_CHAR] = "A";
|
||||||
|
CHAR_TABLE['Б' - START_CHAR] = "B";
|
||||||
|
CHAR_TABLE['В' - START_CHAR] = "V";
|
||||||
|
CHAR_TABLE['Г' - START_CHAR] = "G";
|
||||||
|
CHAR_TABLE['Д' - START_CHAR] = "D";
|
||||||
|
CHAR_TABLE['Е' - START_CHAR] = "E";
|
||||||
|
CHAR_TABLE['Ё' - START_CHAR] = "E";
|
||||||
|
CHAR_TABLE['Ж' - START_CHAR] = "ZH";
|
||||||
|
CHAR_TABLE['З' - START_CHAR] = "Z";
|
||||||
|
CHAR_TABLE['И' - START_CHAR] = "I";
|
||||||
|
CHAR_TABLE['Й' - START_CHAR] = "J";
|
||||||
|
CHAR_TABLE['К' - START_CHAR] = "K";
|
||||||
|
CHAR_TABLE['Л' - START_CHAR] = "L";
|
||||||
|
CHAR_TABLE['М' - START_CHAR] = "M";
|
||||||
|
CHAR_TABLE['Н' - START_CHAR] = "N";
|
||||||
|
CHAR_TABLE['О' - START_CHAR] = "O";
|
||||||
|
CHAR_TABLE['П' - START_CHAR] = "P";
|
||||||
|
CHAR_TABLE['Р' - START_CHAR] = "R";
|
||||||
|
CHAR_TABLE['С' - START_CHAR] = "TS";
|
||||||
|
CHAR_TABLE['Т' - START_CHAR] = "T";
|
||||||
|
CHAR_TABLE['У' - START_CHAR] = "U";
|
||||||
|
CHAR_TABLE['Ф' - START_CHAR] = "F";
|
||||||
|
CHAR_TABLE['Х' - START_CHAR] = "H";
|
||||||
|
CHAR_TABLE['Ц' - START_CHAR] = "C";
|
||||||
|
CHAR_TABLE['Ч' - START_CHAR] = "CH";
|
||||||
|
CHAR_TABLE['Ш' - START_CHAR] = "SH";
|
||||||
|
CHAR_TABLE['Щ' - START_CHAR] = "SHCH";
|
||||||
|
CHAR_TABLE['Ъ' - START_CHAR] = "";
|
||||||
|
CHAR_TABLE['Ы' - START_CHAR] = "Y";
|
||||||
|
CHAR_TABLE['Ь' - START_CHAR] = "";
|
||||||
|
CHAR_TABLE['Э' - START_CHAR] = "E";
|
||||||
|
CHAR_TABLE['Ю' - START_CHAR] = "U";
|
||||||
|
CHAR_TABLE['Я' - START_CHAR] = "YA";
|
||||||
|
|
||||||
|
for (int i = 0; i < CHAR_TABLE.length; i++) {
|
||||||
|
char idx = (char) ((char) i + START_CHAR);
|
||||||
|
char lower = new String(new char[]{idx}).toLowerCase().charAt(0);
|
||||||
|
if (CHAR_TABLE[i] != null) {
|
||||||
|
CHAR_TABLE[lower - START_CHAR] = CHAR_TABLE[i].toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Переводит русский текст в транслит. В результирующей строке
|
||||||
|
* каждая русская буква будет заменена на соответствующую английскую.
|
||||||
|
* Не русские символы останутся прежними.
|
||||||
|
*/
|
||||||
|
public static String toLatin(String text) {
|
||||||
|
char charBuffer[] = text.toCharArray();
|
||||||
|
StringBuilder sb = new StringBuilder(text.length());
|
||||||
|
for (char symbol : charBuffer) {
|
||||||
|
int i = symbol - START_CHAR;
|
||||||
|
if (i >= 0 && i < CHAR_TABLE.length) {
|
||||||
|
String replace = CHAR_TABLE[i];
|
||||||
|
sb.append(replace == null ? symbol : replace);
|
||||||
|
} else {
|
||||||
|
sb.append(symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ public class UnzipService extends IntentService {
|
|||||||
super("mobi.MultiCraft.UnzipService");
|
super("mobi.MultiCraft.UnzipService");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _dirChecker(String dir, String unzipLocation) {
|
private void isDir(String dir, String unzipLocation) {
|
||||||
File f = new File(unzipLocation + dir);
|
File f = new File(unzipLocation + dir);
|
||||||
|
|
||||||
if (!f.isDirectory()) {
|
if (!f.isDirectory()) {
|
||||||
@ -48,11 +48,9 @@ public class UnzipService extends IntentService {
|
|||||||
|
|
||||||
mNotifyManager.notify(id, mBuilder.build());
|
mNotifyManager.notify(id, mBuilder.build());
|
||||||
int per = 0;
|
int per = 0;
|
||||||
|
int size = getSummarySize(file);
|
||||||
for (String f : file) {
|
for (String f : file) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ZipFile zipSize = new ZipFile(f);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileInputStream fin = new FileInputStream(f);
|
FileInputStream fin = new FileInputStream(f);
|
||||||
ZipInputStream zin = new ZipInputStream(fin);
|
ZipInputStream zin = new ZipInputStream(fin);
|
||||||
@ -60,10 +58,10 @@ public class UnzipService extends IntentService {
|
|||||||
while ((ze = zin.getNextEntry()) != null) {
|
while ((ze = zin.getNextEntry()) != null) {
|
||||||
if (ze.isDirectory()) {
|
if (ze.isDirectory()) {
|
||||||
per++;
|
per++;
|
||||||
_dirChecker(ze.getName(), location);
|
isDir(ze.getName(), location);
|
||||||
} else {
|
} else {
|
||||||
per++;
|
per++;
|
||||||
int progress = 100 * per / zipSize.size();
|
int progress = 100 * per / size;
|
||||||
// send update
|
// send update
|
||||||
publishProgress(progress);
|
publishProgress(progress);
|
||||||
FileOutputStream f_out = new FileOutputStream(location + ze.getName());
|
FileOutputStream f_out = new FileOutputStream(location + ze.getName());
|
||||||
@ -79,7 +77,7 @@ public class UnzipService extends IntentService {
|
|||||||
}
|
}
|
||||||
zin.close();
|
zin.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.e(TAG, e.getMessage(), e.fillInStackTrace());
|
Log.e(TAG, e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, e.getLocalizedMessage());
|
Log.e(TAG, e.getLocalizedMessage());
|
||||||
@ -93,6 +91,19 @@ public class UnzipService extends IntentService {
|
|||||||
sendBroadcast(intentUpdate);
|
sendBroadcast(intentUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getSummarySize(String[] zips) {
|
||||||
|
int size = 0;
|
||||||
|
for (String z : zips) {
|
||||||
|
try {
|
||||||
|
ZipFile zipSize = new ZipFile(z);
|
||||||
|
size += zipSize.size();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user