master
MoNTE48 2014-10-26 09:46:01 +02:00
parent 249f4ad902
commit 919f8a3cec
27 changed files with 1202 additions and 0 deletions

9
.classpath Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

33
.project Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Minetest Mobile</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

66
AndroidManifest.xml Normal file
View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Minetest.Mobile.FREE"
android:installLocation="auto"
android:versionCode="10"
android:versionName="@string/ver" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="20" />
<supports-screens
android:requiresSmallestWidthDp="480"
android:smallScreens="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.Minetest.Mobile.MainActivity"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.minetest.minetest.MtNativeActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTask"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="minetest" />
</activity>
<activity
android:name="org.minetest.minetest.MinetestTextEntry"
android:excludeFromRecents="true"
android:theme="@style/Theme.Transparent" >
</activity>
<activity
android:name="com.Minetest.Mobile.Start"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
</activity>
<activity
android:name="com.Minetest.Mobile.About"
android:theme="@android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity android:name="com.Minetest.Mobile.DownloadActivity" >
</activity>
</application>
</manifest>

6
libs/README.txt Normal file
View File

@ -0,0 +1,6 @@
Go to:
https://github.com/minetest/minetest
(I use official libs, no change!).
Get this repo on your pc.
cd build/android
Make or CMake

4
lint.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="SdCardPath" severity="ignore" />
</lint>

20
proguard-project.txt Normal file
View File

@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

3
project.properties Normal file
View File

@ -0,0 +1,3 @@
target=android-19
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
android.library.reference.1=../library

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

12
res/drawable/button.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
</shape>

BIN
res/drawable/wallpaper.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

95
res/layout/about.xml Normal file
View File

@ -0,0 +1,95 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/ver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/aboutt"
android:gravity="center"
android:text="@string/ver" />
<TextView
android:id="@+id/aboutt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="@string/app_name"
android:textSize="20dp" />
<Button
android:id="@+id/wiki"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/ver"
android:layout_marginTop="15dp"
android:background="@drawable/button"
android:onClick="wiki"
android:text="@string/site" />
<Button
android:id="@+id/RateMeSourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/MinetestReadme"
android:layout_marginTop="10dp"
android:background="@drawable/button"
android:onClick="RateMeSourse"
android:text="Rate Me Sourse" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/RateMeSourse"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="URL on build sourse you can found on Google Play!" />
<TextView
android:id="@+id/dev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="@string/dev" />
<TextView
android:id="@+id/SourseText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/wiki"
android:layout_marginTop="50dp"
android:gravity="center"
android:text="Open Sourse!"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/MinetestReadme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/SourseText"
android:layout_marginTop="10dp"
android:background="@drawable/button"
android:onClick="MinetestReadme"
android:text="Minetest README" />
</RelativeLayout>

View File

@ -0,0 +1,77 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:paddingBottom="0.0dip"
android:paddingLeft="0.0dip"
android:paddingRight="0.0dip"
android:paddingTop="0.0dip" >
<ImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/wallpaper" />
<Button
android:id="@+id/nextbtn"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:alpha="0.9"
android:background="#00FF00"
android:onClick="start"
android:text="@string/open"
android:textSize="30sp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:alpha="0.8"
android:onClick="About"
android:background="#ceff99"
android:text="@string/About"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/button1"
android:alpha="0.8"
android:background="#ceff99"
android:text="Official site: Minetest.net" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:src="@drawable/header" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:alpha="0.8"
android:background="#ceff99"
android:gravity="center"
android:text="@string/hello"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>

80
res/layout/cache.xml Normal file
View File

@ -0,0 +1,80 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:paddingBottom="0.0dip"
android:paddingLeft="0.0dip"
android:paddingRight="0.0dip"
android:paddingTop="0.0dip" >
<ImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/wallpaper" />
<Button
android:id="@+id/nextbtn"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:alpha="0.9"
android:background="#00FF00"
android:text="@string/start"
android:textSize="30sp" />
<TextView
android:id="@+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:alpha="0.9"
android:background="#ceff99"
android:gravity="center"
android:text="@string/warning"
android:textColor="#FF0000"
android:textSize="20sp" />
<ProgressBar
android:id="@+id/PB1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="gone" />
<TextView
android:id="@+id/unpack"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/PB1"
android:alpha="0.9"
android:background="#ceff99"
android:gravity="center"
android:text="@string/unpack"
android:textColor="#000000"
android:textSize="15sp"
android:visibility="gone" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:src="@drawable/header" />
</RelativeLayout>

18
res/values-ru/strings.xml Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="start">Повторить</string>
<string name="About">О проекте "Minetest for Android"</string>
<string name="unpack">Установка обновлений&#8230;</string>
<string name="hello">Minetest for Android — проект с открытым исходным кодом на основе Minetest.</string>
<string name="open">Нажмите для продолжения</string>
<string name="warning">Во время распаковки не сворачивайте приложение. Иначе распаковка пройдёт с ошибками.</string>
<string name="check">Проверка обновлений&#8230;</string>
<string name="stgame">Для начала игры нажмите "Start Singleplayer"!</string>
<string name="disconnect">Отсутствует подключение к Интернету! Повторите попытку.</string>
<string name="download">Загрузка необходимых файлн&#8230;</string>
<string name="wiki">http://minetest.ru/wiki/</string>
<string name="rmold">Удаление устаревших файлов&#8230;</string>
<string name="bad">Ваш игровой мир будет пересоздан&#8230;</string>
</resources>

7
res/values/dimens.xml Normal file
View File

@ -0,0 +1,7 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

23
res/values/strings.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Minetest for Android</string>
<string name="start">Restart</string>
<string name="About">About project "Minetest for Android"</string>
<string name="unpack">Installing updates&#8230;</string>
<string name="hello">Minetest for Android — Open Sourse Project, based on Minetest. </string>
<string name="open">Tap to continue</string>
<string name="warning">When unpacking, do not wrap application. Otherwise, unpacking may take with errors.</string>
<string name="check">Checking the version&#8230;</string>
<string name="extract">Extract files&#8230;</string>
<string name="stgame">To start the game, click "Start Singleplayer"!</string>
<string name="disconnect">No network available! Try again.</string>
<string name="download">Downloading Zip File..</string>
<string name="site"><i>Open Minetest Wiki</i></string>
<string name="dev">Dev by MoNTE48 (MoNTE48@mail.ua), 2014</string>
<string name="wiki">http://wiki.minetest.com/wiki/</string>
<string name="rmold">Remove old files&#8230;</string>
<string name="ver">0.4.10 | build 1.4.3</string>
<string name="bad">Your game world is recreated!</string>
</resources>

13
res/values/styles.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme.Holo.Light">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>

View File

@ -0,0 +1,75 @@
package com.Minetest.Mobile;
/* Ðàçðàáîòàíî MoNTE48, 2014.
* Êîä çàïðåùåíî èçìåíÿòü èëè ðàñïðîñòðàíÿòü,
* áåç ðàçðåøåíèÿ àâòîðà!
* Êîíòàêòû: MoNTE48@mail.ua
*/
import com.Minetest.Mobile.FREE.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
public class About extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Drawable d = new ColorDrawable(Color.WHITE);
d.setAlpha(180);
getWindow().setBackgroundDrawable(d);
setContentView(R.layout.about);
}
public void RateMeSourse(View view) {
// âûâîæó òîñò
Toast toast = Toast.makeText(getApplicationContext(), "Opening...",
Toast.LENGTH_LONG);
toast.show();
// îòêðûâàþ ñàéò ÷-ç Uri
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri
.parse("https://github.com/kskkbys/Android-RateThisApp"));
startActivity(intent);
}
public void MinetestReadme(View view) {
// âûâîæó òîñò
Toast toast = Toast.makeText(getApplicationContext(), "Opening...",
Toast.LENGTH_LONG);
toast.show();
// îòêðûâàþ ñàéò ÷-ç Uri
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri
.parse("https://github.com/minetest/minetest/blob/master/README.txt"));
startActivity(intent);
}
public void wiki(View view) {
// âûâîæó òîñò
Toast toast = Toast.makeText(getApplicationContext(), "Opening...",
Toast.LENGTH_LONG);
toast.show();
// îòêðûâàþ ñàéò ÷-ç Uri
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri
.parse((String) getResources().getText(R.string.wiki)));
startActivity(intent);
}
}

View File

@ -0,0 +1,44 @@
package com.Minetest.Mobile;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.Minetest.Mobile.FREE.R;
import com.kskkbys.rate.RateThisApp;
public class MainActivity extends Activity {
Button button3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// init rate plugin
RateThisApp.onStart(this);
RateThisApp.showRateDialogIfNeeded(this);
button3 = (Button) findViewById(R.id.button3);
button3.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://minetest.net/"));
startActivity(intent);
}
});
}
public void About(View view) {
Intent intent = new Intent(this, About.class);
startActivity(intent);
}
public void start(View view) {
Intent intent = new Intent(this, Start.class);
startActivity(intent);
}
}

View File

@ -0,0 +1,371 @@
package com.Minetest.Mobile;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.minetest.minetest.MtNativeActivity;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.Minetest.Mobile.FREE.R;
public class Start extends Activity {
Activity activity;
private ProgressDialog mProgressDialog;
String unzipLocation = Environment.getExternalStorageDirectory()
+ "/minetest/";
String zipFile = Environment.getExternalStorageDirectory() + "/Files.zip";
final String URLZIP = "http://95.215.44.248/cache/mt/1.5.43/Files.zip";
private String const_ver = "1.5.43";
// òóò ïåðå÷èñëÿåøü ìàññèâ ïëîõèõ âåðñèé
private String[] bad_ver = new String[] { "1.4", "1.3", "1.5" };
String SDAllPath = "";
public 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) {
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cache);
// Initialization
String path = "/minetest/";
File folder = new File(Environment.getExternalStorageDirectory() + path);
if (!(folder.exists())) {
folder.mkdirs();
}
SDAllPath = folder.getPath() + "/";
final File version = new File(SDAllPath + "ver.txt");
final Button next = (Button) findViewById(R.id.nextbtn);
// Starting game
Toast.makeText(getBaseContext(), R.string.check, Toast.LENGTH_SHORT)
.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if (find_ver(version) == 0) {
next.setVisibility(View.GONE);
download();
} else if (find_ver(version) == 1) {
nnext();
} else if (find_ver(version) == -1) {
Toast.makeText(Start.this, R.string.bad, Toast.LENGTH_SHORT)
.show();
deleteFiles("/sdcard/minetest/worlds");
Handler handler1 = new Handler();
handler1.postDelayed(new Runnable() {
@Override
public void run() {
download();
}
}, 3000);
}
}
}, 1000); // * ms
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(getBaseContext(), R.string.check,
Toast.LENGTH_SHORT).show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if (find_ver(version) == 0) {
next.setVisibility(View.GONE);
download();
} else {
if (find_ver(version) == 1) {
nnext();
} else if (find_ver(version) == -1) {
Toast.makeText(Start.this, R.string.bad,
Toast.LENGTH_SHORT).show();
deleteFiles("/sdcard/minetest/worlds");
Handler handler1 = new Handler();
handler1.postDelayed(new Runnable() {
@Override
public void run() {
download();
}
}, 3000);
nnext();
}
}
}
}, 1000); // * ms
}
});
}
private int find_ver(File file) {
int result = 0;
String line = null;
try {
BufferedReader br = new BufferedReader(new FileReader(file));
line = br.readLine();
} catch (IOException e) {
}
if (const_ver.equals(line)) {
result = 1;
} else if (isBad(line)) {
result = -1;
} else
result = 0;
return result;
}
private boolean isBad(String line) {
for (String item : bad_ver) {
if (line.equals(item))
return true;
}
return false;
}
private void nnext() {
Toast.makeText(getBaseContext(), R.string.stgame, Toast.LENGTH_LONG)
.show();
Intent intent = new Intent(this, MtNativeActivity.class);
startActivity(intent);
}
class DownloadZip extends AsyncTask<String, String, String> {
String result = "";
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(Start.this);
mProgressDialog.setMessage(getString(R.string.download));
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
@Override
protected String doInBackground(String... aurl) {
int count;
try {
URL url = new URL(aurl[0]);
URLConnection connection = url.openConnection();
connection.connect();
int lenghtOfFile = connection.getContentLength();
int code = ((HttpURLConnection) connection).getResponseCode();
Log.d("WTF", String.valueOf(code));
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(zipFile);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress("" + (int) ((total * 100) / lenghtOfFile));
output.write(data, 0, count);
}
output.close();
input.close();
result = "true";
} catch (FileNotFoundException ex) {
Log.e("WTF", ex.getLocalizedMessage(), ex.fillInStackTrace());
} catch (IOException e) {
Log.e("WTF", e.getLocalizedMessage(), e.fillInStackTrace());
result = "false";
}
return null;
}
protected void onProgressUpdate(String... progress) {
Log.d("WTF", progress[0]);
mProgressDialog.setProgress(Integer.parseInt(progress[0]));
}
@Override
protected void onPostExecute(String unused) {
mProgressDialog.dismiss();
if (result.equalsIgnoreCase("true")) {
try {
unzip();
} catch (IOException e) {
e.printStackTrace();
}
} else {
}
}
}
public void unzip() throws IOException {
mProgressDialog = new ProgressDialog(Start.this);
mProgressDialog.setMessage(getString(R.string.unpack));
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
new UnZipTask().execute(zipFile, unzipLocation);
}
private class UnZipTask extends AsyncTask<String, Void, Boolean> {
@SuppressWarnings("rawtypes")
@Override
protected Boolean doInBackground(String... params) {
String filePath = params[0];
String destinationPath = params[1];
File archive = new File(filePath);
try {
ZipFile zipfile = new ZipFile(archive);
for (Enumeration e = zipfile.entries(); e.hasMoreElements();) {
ZipEntry entry = (ZipEntry) e.nextElement();
unzipEntry(zipfile, entry, destinationPath);
}
UnzipUtil d = new UnzipUtil(zipFile, unzipLocation);
d.unzip();
} catch (Exception e) {
return false;
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
mProgressDialog.dismiss();
File del = new File(zipFile);
del.delete();
nnext();
}
private void unzipEntry(ZipFile zipfile, ZipEntry entry,
String outputDir) throws IOException {
if (entry.isDirectory()) {
createDir(new File(outputDir, entry.getName()));
return;
}
File outputFile = new File(outputDir, entry.getName());
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
BufferedInputStream inputStream = new BufferedInputStream(
zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(
new FileOutputStream(outputFile));
try {
} finally {
outputStream.flush();
outputStream.close();
inputStream.close();
}
}
private void createDir(File dir) {
if (dir.exists()) {
return;
}
if (!dir.mkdirs()) {
throw new RuntimeException("Can not create directory " + dir);
}
}
}
private void download() {
final Button next = (Button) findViewById(R.id.nextbtn);
if (isNetworkAvailable()) {
Toast.makeText(Start.this, R.string.rmold, Toast.LENGTH_SHORT)
.show();
/* DEL older folders */
deleteFiles("/sdcard/minetest/cache");
deleteFiles("/sdcard/minetest/builtin");
deleteFiles("/sdcard/minetest/games");
deleteFiles("/sdcard/minetest/textures");
/* END */
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if (isFileExist()) {
File del = new File(zipFile);
del.delete();
}
DownloadZip mew = new DownloadZip();
mew.execute(URLZIP);
}
}, 2000); // * ms
} else
Toast.makeText(Start.this, R.string.disconnect, Toast.LENGTH_LONG)
.show();
next.setVisibility(View.VISIBLE);
}
private boolean isFileExist() {
File file = new File(Environment.getExternalStorageDirectory()
.getPath() + "/Files.zip");
if (file.exists()) {
return true;
} else
return false;
}
private boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return (activeNetwork != null && activeNetwork
.isConnectedOrConnecting());
}
}

View File

@ -0,0 +1,63 @@
package com.Minetest.Mobile;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class UnzipUtil {
private String _zipFile;
private String _location;
public UnzipUtil(String zipFile, String location) {
_zipFile = zipFile;
_location = location;
_dirChecker("");
}
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if (ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location
+ ze.getName());
byte[] buffer = new byte[8192];
int len;
while ((len = zin.read(buffer)) != -1) {
fout.write(buffer, 0, len);
}
fout.close();
// }
zin.closeEntry();
// fout.close();
}
}
zin.close();
} catch (Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
if (!f.isDirectory()) {
f.mkdirs();
}
}
}

View File

@ -0,0 +1,91 @@
package org.minetest.minetest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;
public class MinetestTextEntry extends Activity {
public AlertDialog mTextInputDialog;
public EditText mTextInputWidget;
private final int MultiLineTextInput = 1;
private final int SingleLineTextInput = 2;
private final int SingleLinePasswordInput = 3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
String acceptButton = b.getString("EnterButton");
String hint = b.getString("hint");
String current = b.getString("current");
int editType = b.getInt("editType");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
mTextInputWidget = new EditText(this);
mTextInputWidget.setHint(hint);
mTextInputWidget.setText(current);
mTextInputWidget.setMinWidth(300);
if (editType == SingleLinePasswordInput) {
mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
else {
mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT);
}
builder.setView(mTextInputWidget);
if (editType == MultiLineTextInput) {
builder.setPositiveButton(acceptButton, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton)
{ pushResult(mTextInputWidget.getText().toString()); }
});
}
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
cancelDialog();
}
});
mTextInputWidget.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View view, int KeyCode, KeyEvent event) {
if ( KeyCode == KeyEvent.KEYCODE_ENTER){
pushResult(mTextInputWidget.getText().toString());
return true;
}
return false;
}
});
mTextInputDialog = builder.create();
mTextInputDialog.show();
}
public void pushResult(String text) {
Intent resultData = new Intent();
resultData.putExtra("text", text);
setResult(Activity.RESULT_OK,resultData);
mTextInputDialog.dismiss();
finish();
}
public void cancelDialog() {
setResult(Activity.RESULT_CANCELED);
mTextInputDialog.dismiss();
finish();
}
}

View File

@ -0,0 +1,92 @@
package org.minetest.minetest;
import android.app.NativeActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
public class MtNativeActivity extends NativeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_MessagReturnCode = -1;
m_MessageReturnValue = "";
}
@Override
public void onDestroy() {
super.onDestroy();
}
public void copyAssets() {
/*NO! Cache copy on Start Activity.*/
}
public void showDialog(String acceptButton, String hint, String current,
int editType) {
Intent intent = new Intent(this, MinetestTextEntry.class);
Bundle params = new Bundle();
params.putString("acceptButton", acceptButton);
params.putString("hint", hint);
params.putString("current", current);
params.putInt("editType", editType);
intent.putExtras(params);
startActivityForResult(intent, 101);
m_MessageReturnValue = "";
m_MessagReturnCode = -1;
}
public static native void putMessageBoxResult(String text);
/* ugly code to workaround putMessageBoxResult not beeing found */
public int getDialogState() {
return m_MessagReturnCode;
}
public String getDialogValue() {
m_MessagReturnCode = -1;
return m_MessageReturnValue;
}
public float getDensity() {
return getResources().getDisplayMetrics().density;
}
public int getDisplayWidth() {
return getResources().getDisplayMetrics().widthPixels;
}
public int getDisplayHeight() {
return getResources().getDisplayMetrics().heightPixels;
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == 101) {
if (resultCode == RESULT_OK) {
String text = data.getStringExtra("text");
m_MessagReturnCode = 0;
m_MessageReturnValue = text;
}
else {
m_MessagReturnCode = 1;
}
}
}
static {
System.loadLibrary("openal");
System.loadLibrary("ogg");
System.loadLibrary("vorbis");
System.loadLibrary("ssl");
System.loadLibrary("crypto");
}
private int m_MessagReturnCode;
private String m_MessageReturnValue;
}