Merge java part
@ -1,35 +1,64 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="net.minetest.minetest"
|
package="mobi.MultiCraft"
|
||||||
android:versionCode="###ANDROID_VERSION###"
|
android:versionCode="###ANDROID_VERSION###"
|
||||||
android:versionName="###BASE_VERSION###.###ANDROID_VERSION###"
|
android:versionName="###BASE_VERSION###.###ANDROID_VERSION###" >
|
||||||
android:installLocation="auto">
|
|
||||||
<uses-sdk android:minSdkVersion="9"/>
|
<uses-sdk
|
||||||
<uses-feature android:glEsVersion="0x00010000" android:required="true"/>
|
android:minSdkVersion="16"
|
||||||
|
android:targetSdkVersion="22" />
|
||||||
|
|
||||||
|
<supports-screens android:smallScreens="false" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
###DEBUG_BUILD###
|
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||||
<application android:icon="@drawable/irr_icon" android:label="Minetest" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" ###DEBUG_FLAG###>
|
|
||||||
<activity android:name=".MtNativeActivity"
|
<application
|
||||||
android:label="Minetest"
|
android:allowBackup="true"
|
||||||
android:launchMode="singleTask"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:configChanges="orientation|keyboard|keyboardHidden|navigation"
|
android:label="@string/app_name"
|
||||||
android:screenOrientation="sensorLandscape"
|
android:theme="@style/MTTheme" >
|
||||||
android:clearTaskOnLaunch="true">
|
<meta-data
|
||||||
|
android:name="com.google.android.gms.version"
|
||||||
|
android:value="@integer/google_play_services_version" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="com.MoNTE48.MultiCraft.MainActivity"
|
||||||
|
android:screenOrientation="sensorLandscape" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<meta-data android:name="android.app.lib_name" android:value="minetest" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".MinetestTextEntry"
|
<activity
|
||||||
android:theme="@style/Theme.Transparent"
|
android:name="net.minetest.minetest.MtNativeActivity"
|
||||||
android:excludeFromRecents="true">
|
android:clearTaskOnLaunch="true"
|
||||||
</activity>
|
android:configChanges="orientation|keyboard|keyboardHidden|navigation"
|
||||||
<activity android:name=".MinetestAssetCopy"
|
android:excludeFromRecents="true"
|
||||||
android:theme="@style/Theme.Transparent"
|
android:launchMode="singleTask"
|
||||||
android:excludeFromRecents="true">
|
android:screenOrientation="sensorLandscape" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.lib_name"
|
||||||
|
android:value="minetest" />
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name="net.minetest.minetest.MinetestTextEntry"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:theme="@style/Theme.Transparent" />
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name="com.MoNTE48.MultiCraft.UnzipService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
4
build/android/lint.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<lint>
|
||||||
|
<issue id="NewApi" severity="ignore" />
|
||||||
|
</lint>
|
20
build/android/proguard-project.txt
Normal 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 *;
|
||||||
|
#}
|
@ -1 +1,2 @@
|
|||||||
target=android-10
|
target=android-22
|
||||||
|
android.library.reference.1=../google-play-services_lib
|
Before Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 3.0 KiB |
BIN
build/android/res/drawable-xhdpi/header.png
Normal file
After Width: | Height: | Size: 127 KiB |
BIN
build/android/res/drawable-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 7.4 KiB |
BIN
build/android/res/drawable-xhdpi/wallpaper.png
Normal file
After Width: | Height: | Size: 666 KiB |
12
build/android/res/drawable/button.xml
Normal 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="#50B623" />
|
||||||
|
|
||||||
|
<corners
|
||||||
|
android:bottomLeftRadius="25dp"
|
||||||
|
android:bottomRightRadius="25dp"
|
||||||
|
android:topLeftRadius="25dp"
|
||||||
|
android:topRightRadius="25dp" />
|
||||||
|
|
||||||
|
</shape>
|
19
build/android/res/drawable/button_wp.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle" >
|
||||||
|
|
||||||
|
<gradient
|
||||||
|
android:angle="45"
|
||||||
|
android:centerColor="#5CA80F"
|
||||||
|
android:centerX="100%"
|
||||||
|
android:endColor="#FFFFFF"
|
||||||
|
android:startColor="#09E8E1"
|
||||||
|
android:type="linear" />
|
||||||
|
|
||||||
|
<corners
|
||||||
|
android:bottomLeftRadius="25dp"
|
||||||
|
android:bottomRightRadius="25dp"
|
||||||
|
android:topLeftRadius="25dp"
|
||||||
|
android:topRightRadius="25dp" />
|
||||||
|
|
||||||
|
</shape>
|
28
build/android/res/drawable/custom_progress_bar.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<!-- Define the background properties like color etc -->
|
||||||
|
<item android:id="@android:id/background">
|
||||||
|
<shape>
|
||||||
|
<gradient
|
||||||
|
android:startColor="#000001"
|
||||||
|
android:centerColor="#0b131e"
|
||||||
|
android:centerY="1.0"
|
||||||
|
android:endColor="#0d1522"
|
||||||
|
android:angle="270" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<!-- Define the progress properties like start color, end color etc -->
|
||||||
|
<item android:id="@android:id/progress">
|
||||||
|
<clip>
|
||||||
|
<shape>
|
||||||
|
<gradient
|
||||||
|
android:startColor="#007A00"
|
||||||
|
android:centerColor="#007A00"
|
||||||
|
android:centerY="1.0"
|
||||||
|
android:endColor="#06101d"
|
||||||
|
android:angle="270" />
|
||||||
|
</shape>
|
||||||
|
</clip>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
66
build/android/res/layout/activity_main.xml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/wallpaper">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="120dp"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:src="@drawable/header" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/progress_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_above="@+id/PB1"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:text="@string/starting"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/PB1"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:max="100"
|
||||||
|
android:progressDrawable="@drawable/custom_progress_bar" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/progress_textView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/PB1"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/warning"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentStart="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" />
|
||||||
|
</RelativeLayout>
|
@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progressBar1"
|
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:text="preparing media ..."
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
17
build/android/res/layout/instruction_dialog.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="2dip"
|
||||||
|
android:paddingLeft="12dip"
|
||||||
|
android:paddingRight="12dip"
|
||||||
|
android:paddingTop="6dip">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="4dip"
|
||||||
|
android:text="@string/app_description" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
50
build/android/res/layout/rate_layout.xml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/rta_message"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/rta_dialog_title"
|
||||||
|
android:layout_gravity="center" />
|
||||||
|
|
||||||
|
<RatingBar
|
||||||
|
android:id="@+id/ratingBar"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:numStars="5"
|
||||||
|
android:stepSize="1.0" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:cursorVisible="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
android:hint="@string/rate_title" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:clickable="false"
|
||||||
|
android:cursorVisible="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:hint="@string/rate_description" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/rate_submit"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:enabled="false"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:textColor="#00ced1"
|
||||||
|
android:text="@string/rate_submit" />
|
||||||
|
</LinearLayout>
|
40
build/android/res/values-ru/strings.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<!-- подготовка к запуску -->
|
||||||
|
<string name="loading">Загрузка…</string>
|
||||||
|
<string name="warning">Во время загрузки не закрывайте приложение. \nИгра запустится через несколько секунд…</string>
|
||||||
|
<string name="rm_old">Подготовка к обновлению…</string>
|
||||||
|
<string name="copy">Копирование…</string>
|
||||||
|
<string name="notification_title">Загрузка</string>
|
||||||
|
<string name="notification_description">Загрузка файлов игры…</string>
|
||||||
|
|
||||||
|
<!-- диалог оценки -->
|
||||||
|
<string name="rta_dialog_title">Оцените MultiCraft Beta — Бесплатный Майнер!</string>
|
||||||
|
<string name="rate_title">Название</string>
|
||||||
|
<string name="rate_submit">Оценить</string>
|
||||||
|
<string name="rate_description">Описание</string>
|
||||||
|
<string name="sad">Очень жаль…</string>
|
||||||
|
|
||||||
|
<!-- диалог для слабых девайсов -->
|
||||||
|
<string name="memory_title">Внимание!</string>
|
||||||
|
<string name="memory_lags">Возможны лаги при игре. Пожалуйста, не оценивайте приложение плохо,\nтак как у вас слабый аппарат.</string>
|
||||||
|
<string name="memory_continue">Играть!</string>
|
||||||
|
<string name="memory_close">Закрыть</string>
|
||||||
|
<string name="memory_warning">У Вашего устройства недостаточно оперативной памяти для игры без лагов. Требуется более мощное устройство!</string>
|
||||||
|
|
||||||
|
<!-- диалог обновления -->
|
||||||
|
<string name="update_yes">Обновиться!</string>
|
||||||
|
<string name="update_no">Напомнить позже…</string>
|
||||||
|
<string name="update_ignore">Игнорировать</string>
|
||||||
|
|
||||||
|
<!-- инструкция -->
|
||||||
|
<string name="dialog_instruction">Привет! После загрузки игры нажмите Play.\nЧтобы поставить блок, быстро тапните 2 раза там, куда хотите его поставить!\nЧтобы разъединить блоки в инвентаре, возьмите блок в руку и одновременно прикоснитесь пальцами к двум ячейкам. Вставится половина стопки. Нажмите на другую ячейку и вставится вторая половина!</string>
|
||||||
|
<string name="ok">Понял</string>
|
||||||
|
<string name="forget">Не напоминать</string>
|
||||||
|
|
||||||
|
<!-- недостаточно места -->
|
||||||
|
<string name="not_enough_space">Недостаточно места для распаковки.\nОсвободите пространство на SD карте</string>
|
||||||
|
<string name="space_ok">OK</string>
|
||||||
|
|
||||||
|
</resources>
|
6
build/android/res/values-w820dp/dimens.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<resources>
|
||||||
|
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||||
|
(such as screen margins) for screens with more than 820dp of available width. This
|
||||||
|
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||||
|
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||||
|
</resources>
|
5
build/android/res/values/dimens.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<resources>
|
||||||
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
|
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||||
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
|
</resources>
|
43
build/android/res/values/strings.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="app_name" translatable="false">MultiCraft 3-DEV</string>
|
||||||
|
<string name="ver" translatable="false">1.0.1</string>
|
||||||
|
|
||||||
|
<!-- rate dialog -->
|
||||||
|
<string name="rta_dialog_title">Please, rate MultiCraft!</string>
|
||||||
|
<string name="rate_title">Title</string>
|
||||||
|
<string name="rate_submit">Submit</string>
|
||||||
|
<string name="rate_description">Description</string>
|
||||||
|
<string name="sad">Too bad…</string>
|
||||||
|
|
||||||
|
<!-- preparation for start -->
|
||||||
|
<string name="loading">Loading…</string>
|
||||||
|
<string name="warning">When unpacking, do not wrap application.\nGame will start in few second…</string>
|
||||||
|
<string name="rm_old">Preparing to update…</string>
|
||||||
|
<string name="copy">Copying…</string>
|
||||||
|
<string name="notification_title">Downloading</string>
|
||||||
|
<string name="notification_description">Downloading game data…</string>
|
||||||
|
|
||||||
|
<!-- weak phone dialog -->
|
||||||
|
<string name="memory_title">Warning!</string>
|
||||||
|
<string name="memory_warning">Your device\'s memory is too low for seamless playing</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>
|
||||||
|
|
||||||
|
<!-- update dialog -->
|
||||||
|
<string name="update_yes">Update now!</string>
|
||||||
|
<string name="update_no">Remind me later…</string>
|
||||||
|
<string name="update_ignore">Ignore</string>
|
||||||
|
|
||||||
|
<!-- instruction dialog -->
|
||||||
|
<string name="dialog_instruction">Hello! After game loading select the world and press Play. \nTo put the block quickly tap 2 times where you want to put it on!\nTo split blocks inside inventory take the block and simultaneously touch the two cells. The first half will be inserted on first cell. Click on another cell for inserting second half!</string>
|
||||||
|
<string name="ok">Got it</string>
|
||||||
|
<string name="forget">Don\'t remind</string>
|
||||||
|
|
||||||
|
<!-- free space dialog -->
|
||||||
|
<string name="not_enough_space">Not enough space for unzipping.\nPlease free some space on the SD card</string>
|
||||||
|
<string name="space_ok">OK</string>
|
||||||
|
|
||||||
|
</resources>
|
@ -1,11 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<style name="Theme.Transparent" parent="android:Theme">
|
|
||||||
<item name="android:windowIsTranslucent">true</item>
|
<style name="Theme.Transparent" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
|
||||||
<item name="android:windowBackground">@android:color/transparent</item>
|
|
||||||
<item name="android:windowContentOverlay">@null</item>
|
|
||||||
<item name="android:windowNoTitle">true</item>
|
<item name="android:windowNoTitle">true</item>
|
||||||
<item name="android:windowIsFloating">true</item>
|
<item name="android:background">@android:color/transparent</item>
|
||||||
<item name="android:backgroundDimEnabled">false</item>
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
|
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||||
|
<item name="android:windowIsTranslucent">true</item>
|
||||||
|
<item name="android:windowAnimationStyle">@android:style/Animation</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="MTTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen" />
|
||||||
|
|
||||||
</resources>
|
</resources>
|
319
build/android/src/com/MoNTE48/MultiCraft/MainActivity.java
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
package com.MoNTE48.MultiCraft;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import mobi.MultiCraft.R;
|
||||||
|
import net.minetest.minetest.MtNativeActivity;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.MoNTE48.MultiCraft.Utilities.IUtilitiesCallback;
|
||||||
|
|
||||||
|
public class MainActivity extends Activity implements IUtilitiesCallback {
|
||||||
|
public static final String SHORTCUT_NAME = "shortcut";
|
||||||
|
private final String TAG = MainActivity.class.getName();
|
||||||
|
public final String FILES = "Files.zip";
|
||||||
|
public final String NOMEDIA = ".nomedia";
|
||||||
|
private ProgressDialog mProgressDialog;
|
||||||
|
private TextView mProgressTextView;
|
||||||
|
private String unzipLocation = Environment.getExternalStorageDirectory()
|
||||||
|
+ "/Minetest/";
|
||||||
|
private File version;
|
||||||
|
private Utilities util;
|
||||||
|
private ProgressBar mProgressBar;
|
||||||
|
private MyBroadcastReceiver myBroadcastReceiver;
|
||||||
|
private MyBroadcastReceiver_Update myBroadcastReceiver_Update;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
util = new Utilities(this);
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
registerReceivers();
|
||||||
|
SharedPreferences settings = getSharedPreferences(SHORTCUT_NAME, 0);
|
||||||
|
boolean doNotExecute = settings.getBoolean("doNotExecute", false);
|
||||||
|
if (!doNotExecute)
|
||||||
|
addShortcut();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
if (util.getTotalMemoryInMB() < 800 || util.getCoresCount() < 2) {
|
||||||
|
util.showMemoryDialog(MainActivity.this);
|
||||||
|
} else {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createDirAndNoMedia() {
|
||||||
|
try {
|
||||||
|
File folder = new File(unzipLocation);
|
||||||
|
if (!(folder.exists()))
|
||||||
|
folder.mkdirs();
|
||||||
|
File myFile = new File(unzipLocation, NOMEDIA);
|
||||||
|
if (!myFile.exists())
|
||||||
|
myFile.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addShortcut() {
|
||||||
|
SharedPreferences settings = getSharedPreferences(SHORTCUT_NAME, 0);
|
||||||
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
editor.putBoolean("doNotExecute", true);
|
||||||
|
editor.apply();
|
||||||
|
Intent shortcutIntent = new Intent(getApplicationContext(),
|
||||||
|
MainActivity.class);
|
||||||
|
shortcutIntent.setAction(Intent.ACTION_MAIN);
|
||||||
|
Intent addIntent = new Intent();
|
||||||
|
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||||
|
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
|
||||||
|
getString(R.string.app_name));
|
||||||
|
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||||
|
Intent.ShortcutIconResource.fromContext(
|
||||||
|
getApplicationContext(), R.drawable.ic_launcher));
|
||||||
|
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
||||||
|
getApplicationContext().sendBroadcast(addIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void init() {
|
||||||
|
mProgressTextView = (TextView) findViewById(R.id.progress_textView);
|
||||||
|
mProgressBar = (ProgressBar) findViewById(R.id.PB1);
|
||||||
|
Drawable draw;
|
||||||
|
if (Build.VERSION.SDK_INT > 21) {
|
||||||
|
draw = getResources().getDrawable(R.drawable.custom_progress_bar,
|
||||||
|
null);
|
||||||
|
} else {
|
||||||
|
draw = getResources().getDrawable(R.drawable.custom_progress_bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
mProgressBar.setProgressDrawable(draw);
|
||||||
|
createDirAndNoMedia();
|
||||||
|
version = new File(unzipLocation + "ver.txt");
|
||||||
|
checkVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerReceivers() {
|
||||||
|
myBroadcastReceiver = new MyBroadcastReceiver();
|
||||||
|
myBroadcastReceiver_Update = new MyBroadcastReceiver_Update();
|
||||||
|
IntentFilter intentFilter = new IntentFilter(
|
||||||
|
UnzipService.ACTION_MyIntentService);
|
||||||
|
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
registerReceiver(myBroadcastReceiver, intentFilter);
|
||||||
|
IntentFilter intentFilter_update = new IntentFilter(
|
||||||
|
UnzipService.ACTION_MyUpdate);
|
||||||
|
intentFilter_update.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
registerReceiver(myBroadcastReceiver_Update, intentFilter_update);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSpinnerDialog(int message) {
|
||||||
|
if (mProgressDialog == null) {
|
||||||
|
mProgressDialog = new ProgressDialog(MainActivity.this);
|
||||||
|
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||||
|
mProgressDialog.setCancelable(false);
|
||||||
|
}
|
||||||
|
mProgressDialog.setMessage(getString(message));
|
||||||
|
mProgressDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismissProgressDialog() {
|
||||||
|
if (mProgressDialog != null && mProgressDialog.isShowing()) {
|
||||||
|
mProgressDialog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkVersion() {
|
||||||
|
if (version.exists()) {
|
||||||
|
switch (util.compareVersions(version)) {
|
||||||
|
case OLD:
|
||||||
|
new DeleteTask().execute(unzipLocation + "cache", unzipLocation
|
||||||
|
+ "games/MultiCraft II", unzipLocation + "tmp");
|
||||||
|
break;
|
||||||
|
case CURRENT:
|
||||||
|
startBetweenActivity();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new DeleteTask().execute(unzipLocation + "cache", unzipLocation
|
||||||
|
+ "games/MultiCraft II", unzipLocation + "tmp");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startBetweenActivity() {
|
||||||
|
showSpinnerDialog(R.string.starting);
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Intent intent = new Intent(MainActivity.this,
|
||||||
|
MtNativeActivity.class);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
if (isFinishing())
|
||||||
|
return;
|
||||||
|
dismissProgressDialog();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
File file = new File(Environment.getExternalStorageDirectory(), FILES);
|
||||||
|
if (file.exists())
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startUnzipService(String file) throws IOException {
|
||||||
|
// 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);
|
||||||
|
startService(intentMyIntentService);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MyBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String result = intent.getStringExtra(UnzipService.EXTRA_KEY_OUT);
|
||||||
|
if ("Success".equals(result))
|
||||||
|
startBetweenActivity();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MyBroadcastReceiver_Update extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
int update = intent.getIntExtra(UnzipService.EXTRA_KEY_UPDATE, 0);
|
||||||
|
mProgressBar.setProgress(update);
|
||||||
|
mProgressTextView.setText(update + "%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DeleteTask extends AsyncTask<String, Void, Void> {
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
showSpinnerDialog(R.string.rm_old);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(String... params) {
|
||||||
|
for (String p : params) {
|
||||||
|
deleteFiles(p);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
if (isFinishing())
|
||||||
|
return;
|
||||||
|
dismissProgressDialog();
|
||||||
|
new CopyZip().execute(FILES);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteFiles(String path) {
|
||||||
|
File file = new File(path);
|
||||||
|
if (file.exists()) {
|
||||||
|
String deleteCmd = "rm -r " + path;
|
||||||
|
Runtime runtime = Runtime.getRuntime();
|
||||||
|
try {
|
||||||
|
runtime.exec(deleteCmd);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CopyZip extends AsyncTask<String, Void, String> {
|
||||||
|
String zipName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
showSpinnerDialog(R.string.copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(String... params) {
|
||||||
|
zipName = params[0];
|
||||||
|
copyAssets(zipName);
|
||||||
|
return "Done";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String result) {
|
||||||
|
if (isFinishing())
|
||||||
|
return;
|
||||||
|
dismissProgressDialog();
|
||||||
|
if (util.getAvailableSpaceInMB() > 30) {
|
||||||
|
try {
|
||||||
|
startUnzipService(Environment.getExternalStorageDirectory()
|
||||||
|
+ "/" + zipName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getMessage());
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
util.showNotEnoughSpaceDialog(MainActivity.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyAssets(String zipName) {
|
||||||
|
InputStream in;
|
||||||
|
OutputStream out;
|
||||||
|
try {
|
||||||
|
in = getAssets().open(zipName);
|
||||||
|
out = new FileOutputStream(
|
||||||
|
Environment.getExternalStorageDirectory() + "/"
|
||||||
|
+ zipName);
|
||||||
|
copyFile(in, out);
|
||||||
|
in.close();
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, "Failed to copy asset file: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyFile(InputStream in, OutputStream out)
|
||||||
|
throws IOException {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int read;
|
||||||
|
while ((read = in.read(buffer)) != -1) {
|
||||||
|
out.write(buffer, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
dismissProgressDialog();
|
||||||
|
unregisterReceiver(myBroadcastReceiver);
|
||||||
|
unregisterReceiver(myBroadcastReceiver_Update);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
}
|
106
build/android/src/com/MoNTE48/MultiCraft/UnzipService.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package com.MoNTE48.MultiCraft;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
import mobi.MultiCraft.R;
|
||||||
|
import android.app.IntentService;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class UnzipService extends IntentService {
|
||||||
|
public final String TAG = UnzipService.class.getSimpleName();
|
||||||
|
public static final String ACTION_MyIntentService = "com.MoNTE48.MultiCraft.RESPONSE";
|
||||||
|
public static final String ACTION_MyUpdate = "com.MoNTE48.MultiCraft.UPDATE";
|
||||||
|
public static final String EXTRA_KEY_IN_FILE = "file";
|
||||||
|
public static final String EXTRA_KEY_IN_LOCATION = "location";
|
||||||
|
public static final String EXTRA_KEY_OUT = "EXTRA_OUT";
|
||||||
|
public static final String EXTRA_KEY_UPDATE = "EXTRA_UPDATE";
|
||||||
|
|
||||||
|
public UnzipService() {
|
||||||
|
super("com.MoNTE48.MultiCraft.UnzipService");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _dirChecker(String dir, String unzipLocation) {
|
||||||
|
File f = new File(unzipLocation + dir);
|
||||||
|
|
||||||
|
if (!f.isDirectory()) {
|
||||||
|
f.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onHandleIntent(Intent intent) {
|
||||||
|
NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
Notification.Builder mBuilder = new Notification.Builder(this);
|
||||||
|
mBuilder.setContentTitle(getString(R.string.extract))
|
||||||
|
.setContentText(getString(R.string.unpack))
|
||||||
|
.setSmallIcon(R.drawable.ic_launcher);
|
||||||
|
String file = intent.getStringExtra(EXTRA_KEY_IN_FILE);
|
||||||
|
String location = intent.getStringExtra(EXTRA_KEY_IN_LOCATION);
|
||||||
|
// Displays the progress bar for the first time.
|
||||||
|
mBuilder.setProgress(100, 0, false);
|
||||||
|
int id = 1;
|
||||||
|
mNotifyManager.notify(id, mBuilder.build());
|
||||||
|
int per = 0;
|
||||||
|
try {
|
||||||
|
ZipFile zipSize = new ZipFile(file);
|
||||||
|
try {
|
||||||
|
FileInputStream fin = new FileInputStream(file);
|
||||||
|
ZipInputStream zin = new ZipInputStream(fin);
|
||||||
|
ZipEntry ze;
|
||||||
|
while ((ze = zin.getNextEntry()) != null) {
|
||||||
|
if (ze.isDirectory()) {
|
||||||
|
per++;
|
||||||
|
_dirChecker(ze.getName(), location);
|
||||||
|
} else {
|
||||||
|
per++;
|
||||||
|
int progress = 100 * per / zipSize.size();
|
||||||
|
// send update
|
||||||
|
Intent intentUpdate = new Intent();
|
||||||
|
intentUpdate.setAction(ACTION_MyUpdate);
|
||||||
|
intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
intentUpdate.putExtra(EXTRA_KEY_UPDATE, progress);
|
||||||
|
sendBroadcast(intentUpdate);
|
||||||
|
mBuilder.setProgress(100, progress, false);
|
||||||
|
mNotifyManager.notify(id, mBuilder.build());
|
||||||
|
FileOutputStream f_out = new FileOutputStream(location
|
||||||
|
+ ze.getName());
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
int len;
|
||||||
|
while ((len = zin.read(buffer)) != -1) {
|
||||||
|
f_out.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
f_out.close();
|
||||||
|
zin.closeEntry();
|
||||||
|
f_out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
zin.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
Log.e(TAG, e.getMessage());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
// mBuilder.setContentText(getString(R.string.complete));
|
||||||
|
// mBuilder.setProgress(0, 0, false);
|
||||||
|
// mNotifyManager.notify(id, mBuilder.build());
|
||||||
|
mNotifyManager.cancel(id);
|
||||||
|
Intent intentResponse = new Intent();
|
||||||
|
intentResponse.setAction(ACTION_MyIntentService);
|
||||||
|
intentResponse.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
intentResponse.putExtra(EXTRA_KEY_OUT, "Success");
|
||||||
|
sendBroadcast(intentResponse);
|
||||||
|
}
|
||||||
|
}
|
226
build/android/src/com/MoNTE48/MultiCraft/Utilities.java
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
package com.MoNTE48.MultiCraft;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import mobi.MultiCraft.R;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.os.StatFs;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.MoNTE48.RateME.RateThisApp;
|
||||||
|
import com.winsontan520.wversionmanager.library.WVersionManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helpful utilities used in MainActivity
|
||||||
|
*/
|
||||||
|
public class Utilities {
|
||||||
|
public enum VERSIONS {
|
||||||
|
CURRENT, OLD
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String TAG = Utilities.class.getName();
|
||||||
|
private Context mContext;
|
||||||
|
public static final String PREFS_NAME = "ShowFirstTime";
|
||||||
|
|
||||||
|
public final String STABLE_VER = "1.0.1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for MainActivity init method
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IUtilitiesCallback {
|
||||||
|
void init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IUtilitiesCallback callerActivity;
|
||||||
|
|
||||||
|
public Utilities(Activity activity) {
|
||||||
|
mContext = activity;
|
||||||
|
callerActivity = (IUtilitiesCallback) activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
|
public void showHelpDialog() {
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
|
View messageView = inflater.inflate(R.layout.instruction_dialog, null,
|
||||||
|
false);
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||||
|
builder.setView(messageView);
|
||||||
|
builder.setPositiveButton(R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
RateThisApp.showRateDialogIfNeeded(mContext);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.forget,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
String checkBoxResult = "checked";
|
||||||
|
SharedPreferences settings = mContext
|
||||||
|
.getSharedPreferences(PREFS_NAME, 0);
|
||||||
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
editor.putString("skipMessage", checkBoxResult);
|
||||||
|
editor.apply();
|
||||||
|
RateThisApp.showRateDialogIfNeeded(mContext);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
SharedPreferences settings = mContext.getSharedPreferences(PREFS_NAME,
|
||||||
|
0);
|
||||||
|
String skipMessage = settings.getString("skipMessage", "NOT checked");
|
||||||
|
if (!"checked".equalsIgnoreCase(skipMessage))
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showVersionDialog() {
|
||||||
|
WVersionManager versionManager = new WVersionManager(
|
||||||
|
(Activity) mContext);
|
||||||
|
versionManager
|
||||||
|
.setVersionContentUrl("http://185.61.149.209/ver/MC2.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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showMemoryDialog(final Activity activity) {
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||||
|
builder.setTitle(R.string.memory_title);
|
||||||
|
builder.setMessage(R.string.memory_warning);
|
||||||
|
builder.setPositiveButton(R.string.memory_continue,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Toast.makeText(mContext, R.string.memory_lags,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
callerActivity.init();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.memory_close,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
activity.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setCancelable(false);
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showNotEnoughSpaceDialog(final Activity activity) {
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||||
|
builder.setTitle(R.string.memory_title);
|
||||||
|
builder.setMessage(R.string.not_enough_space);
|
||||||
|
builder.setPositiveButton(R.string.space_ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
activity.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setCancelable(false);
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTotalMemoryInMB() {
|
||||||
|
long initial_memory;
|
||||||
|
if (Build.VERSION.SDK_INT > 17) {
|
||||||
|
ActivityManager actManager = (ActivityManager) mContext
|
||||||
|
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||||
|
actManager.getMemoryInfo(memInfo);
|
||||||
|
initial_memory = memInfo.totalMem;
|
||||||
|
} else {
|
||||||
|
String str1 = "/proc/meminfo";
|
||||||
|
String str2;
|
||||||
|
String[] arrayOfString;
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileReader localFileReader = new FileReader(str1);
|
||||||
|
BufferedReader localBufferedReader = new BufferedReader(
|
||||||
|
localFileReader, 8192);
|
||||||
|
str2 = localBufferedReader.readLine();// meminfo
|
||||||
|
arrayOfString = str2.split("\\s+");
|
||||||
|
// total Memory
|
||||||
|
initial_memory = Integer.valueOf(arrayOfString[1]) * 1024;
|
||||||
|
localBufferedReader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return initial_memory / 1024 / 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCoresCount() {
|
||||||
|
class CpuFilter implements FileFilter {
|
||||||
|
@Override
|
||||||
|
public boolean accept(final File pathname) {
|
||||||
|
return Pattern.matches("cpu[0-9]+", pathname.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final File dir = new File("/sys/devices/system/cpu/");
|
||||||
|
final File[] files = dir.listFiles(new CpuFilter());
|
||||||
|
return files.length;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
return Math.max(1, Runtime.getRuntime().availableProcessors());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
if (Build.VERSION.SDK_INT > 17) {
|
||||||
|
availableSpace = stat.getAvailableBlocksLong()
|
||||||
|
* stat.getBlockSizeLong();
|
||||||
|
} else {
|
||||||
|
availableSpace = (long) stat.getAvailableBlocks()
|
||||||
|
* (long) stat.getBlockSize();
|
||||||
|
}
|
||||||
|
return availableSpace / SIZE_MB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VERSIONS compareVersions(File file) {
|
||||||
|
VERSIONS result;
|
||||||
|
String line = null;
|
||||||
|
try {
|
||||||
|
line = new BufferedReader(new FileReader(file)).readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line == null) {
|
||||||
|
line = "-999";
|
||||||
|
}
|
||||||
|
if (line.equals(STABLE_VER)) {
|
||||||
|
result = VERSIONS.CURRENT;
|
||||||
|
} else
|
||||||
|
result = VERSIONS.OLD;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
156
build/android/src/com/MoNTE48/RateME/RateThisApp.java
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
package com.MoNTE48.RateME;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import mobi.MultiCraft.R;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.Editor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.RatingBar;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RateThisApp<br>
|
||||||
|
* A library to show the app rate dialog
|
||||||
|
*
|
||||||
|
* @author Keisuke Kobayashi <k.kobayashi.122@gmail.com>
|
||||||
|
*/
|
||||||
|
public class RateThisApp {
|
||||||
|
private static final String TAG = RateThisApp.class.getSimpleName();
|
||||||
|
private static final String GOOGLE_PLAY = "https://play.google.com/store/apps/details?id=";
|
||||||
|
private static final String PREF_NAME = "RateThisApp";
|
||||||
|
private static final String KEY_INSTALL_DATE = "rta_install_date";
|
||||||
|
private static final String KEY_LAUNCH_TIMES = "rta_launch_times";
|
||||||
|
private static final String KEY_OPT_OUT = "rta_opt_out";
|
||||||
|
|
||||||
|
private static Date mInstallDate = new Date();
|
||||||
|
private static int mLaunchTimes = 0;
|
||||||
|
private static boolean mOptOut = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Days after installation until showing rate dialog
|
||||||
|
*/
|
||||||
|
public static final int INSTALL_DAYS = 3;
|
||||||
|
/**
|
||||||
|
* App launching times until showing rate dialog
|
||||||
|
*/
|
||||||
|
public static final int LAUNCH_TIMES = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, print LogCat
|
||||||
|
*/
|
||||||
|
public static final boolean DEBUG = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this API when the launcher activity is launched.<br>
|
||||||
|
* It is better to call this API in onStart() of the launcher activity.
|
||||||
|
*/
|
||||||
|
public static void onStart(Context context) {
|
||||||
|
SharedPreferences pref = context.getSharedPreferences(PREF_NAME,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
Editor editor = pref.edit();
|
||||||
|
// If it is the first launch, save the date in shared preference.
|
||||||
|
if (pref.getLong(KEY_INSTALL_DATE, 0) == 0L) {
|
||||||
|
Date now = new Date();
|
||||||
|
editor.putLong(KEY_INSTALL_DATE, now.getTime());
|
||||||
|
log("First install: " + now.toString());
|
||||||
|
}
|
||||||
|
// Increment launch times
|
||||||
|
int launchTimes = pref.getInt(KEY_LAUNCH_TIMES, 0);
|
||||||
|
launchTimes++;
|
||||||
|
editor.putInt(KEY_LAUNCH_TIMES, launchTimes);
|
||||||
|
log("Launch times; " + launchTimes);
|
||||||
|
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
mInstallDate = new Date(pref.getLong(KEY_INSTALL_DATE, 0));
|
||||||
|
mLaunchTimes = pref.getInt(KEY_LAUNCH_TIMES, 0);
|
||||||
|
mOptOut = pref.getBoolean(KEY_OPT_OUT, false);
|
||||||
|
|
||||||
|
printStatus(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showRateDialogIfNeeded(final Context context) {
|
||||||
|
if (shouldShowRateDialog()) {
|
||||||
|
showRateDialog(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean shouldShowRateDialog() {
|
||||||
|
if (mOptOut) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (mLaunchTimes >= LAUNCH_TIMES) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
long threshold = INSTALL_DAYS * 24 * 60 * 60 * 1000L; // msec
|
||||||
|
return new Date().getTime() - mInstallDate.getTime() >= threshold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showRateDialog(final Context context) {
|
||||||
|
// custom dialog
|
||||||
|
final Dialog dialog = new Dialog(context);
|
||||||
|
dialog.setContentView(R.layout.rate_layout);
|
||||||
|
dialog.setTitle(R.string.rta_dialog_title);
|
||||||
|
|
||||||
|
RatingBar ratingBar = (RatingBar) dialog.findViewById(R.id.ratingBar);
|
||||||
|
ratingBar
|
||||||
|
.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onRatingChanged(RatingBar ratingBar,
|
||||||
|
float rating, boolean fromUser) {
|
||||||
|
if (rating > 3) {
|
||||||
|
dialog.dismiss();
|
||||||
|
String appPackage = context.getPackageName();
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
|
||||||
|
.parse(GOOGLE_PLAY + appPackage));
|
||||||
|
context.startActivity(intent);
|
||||||
|
setOptOut(context, true);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, R.string.sad,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
dialog.dismiss();
|
||||||
|
clearSharedPreferences(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void clearSharedPreferences(Context context) {
|
||||||
|
SharedPreferences pref = context.getSharedPreferences(PREF_NAME,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
Editor editor = pref.edit();
|
||||||
|
editor.remove(KEY_INSTALL_DATE);
|
||||||
|
editor.remove(KEY_LAUNCH_TIMES);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setOptOut(final Context context, boolean optOut) {
|
||||||
|
SharedPreferences pref = context.getSharedPreferences(PREF_NAME,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
Editor editor = pref.edit();
|
||||||
|
editor.putBoolean(KEY_OPT_OUT, optOut);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printStatus(final Context context) {
|
||||||
|
SharedPreferences pref = context.getSharedPreferences(PREF_NAME,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
log("*** RateThisApp Status ***");
|
||||||
|
log("Install Date: " + new Date(pref.getLong(KEY_INSTALL_DATE, 0)));
|
||||||
|
log("Launch Times: " + pref.getInt(KEY_LAUNCH_TIMES, 0));
|
||||||
|
log("Opt out: " + pref.getBoolean(KEY_OPT_OUT, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(String message) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.v(TAG, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,456 +0,0 @@
|
|||||||
package net.minetest.minetest;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Vector;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.lang.Object;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.res.AssetFileDescriptor;
|
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Display;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.text.TextPaint;
|
|
||||||
|
|
||||||
public class MinetestAssetCopy extends Activity
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState)
|
|
||||||
{
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setContentView(R.layout.assetcopy);
|
|
||||||
|
|
||||||
m_ProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
|
|
||||||
m_Filename = (TextView) findViewById(R.id.textView1);
|
|
||||||
|
|
||||||
Display display = getWindowManager().getDefaultDisplay();
|
|
||||||
m_ProgressBar.getLayoutParams().width = (int) (display.getWidth() * 0.8);
|
|
||||||
m_ProgressBar.invalidate();
|
|
||||||
|
|
||||||
/* check if there's already a copy in progress and reuse in case it is*/
|
|
||||||
MinetestAssetCopy prevActivity =
|
|
||||||
(MinetestAssetCopy) getLastNonConfigurationInstance();
|
|
||||||
if(prevActivity!= null) {
|
|
||||||
m_AssetCopy = prevActivity.m_AssetCopy;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_AssetCopy = new copyAssetTask();
|
|
||||||
m_AssetCopy.execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* preserve asset copy background task to prevent restart of copying */
|
|
||||||
/* this way of doing it is not recommended for latest android version */
|
|
||||||
/* but the recommended way isn't available on android 2.x */
|
|
||||||
public Object onRetainNonConfigurationInstance()
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressBar m_ProgressBar;
|
|
||||||
TextView m_Filename;
|
|
||||||
|
|
||||||
copyAssetTask m_AssetCopy;
|
|
||||||
|
|
||||||
private class copyAssetTask extends AsyncTask<String, Integer, String>
|
|
||||||
{
|
|
||||||
private long getFullSize(String filename)
|
|
||||||
{
|
|
||||||
long size = 0;
|
|
||||||
try {
|
|
||||||
InputStream src = getAssets().open(filename);
|
|
||||||
byte[] buf = new byte[4096];
|
|
||||||
|
|
||||||
int len = 0;
|
|
||||||
while ((len = src.read(buf)) > 0)
|
|
||||||
{
|
|
||||||
size += len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String doInBackground(String... files)
|
|
||||||
{
|
|
||||||
m_foldernames = new Vector<String>();
|
|
||||||
m_filenames = new Vector<String>();
|
|
||||||
m_tocopy = new Vector<String>();
|
|
||||||
m_asset_size_unknown = new Vector<String>();
|
|
||||||
String baseDir =
|
|
||||||
Environment.getExternalStorageDirectory().getAbsolutePath()
|
|
||||||
+ "/";
|
|
||||||
|
|
||||||
|
|
||||||
// prepare temp folder
|
|
||||||
File TempFolder = new File(baseDir + "Minetest/tmp/");
|
|
||||||
|
|
||||||
if (!TempFolder.exists())
|
|
||||||
{
|
|
||||||
TempFolder.mkdir();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
File[] todel = TempFolder.listFiles();
|
|
||||||
|
|
||||||
for(int i=0; i < todel.length; i++)
|
|
||||||
{
|
|
||||||
Log.v("MinetestAssetCopy","deleting: " + todel[i].getAbsolutePath());
|
|
||||||
todel[i].delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add a .nomedia file
|
|
||||||
try {
|
|
||||||
OutputStream dst = new FileOutputStream(baseDir + "Minetest/.nomedia");
|
|
||||||
dst.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e("MinetestAssetCopy","Failed to create .nomedia file");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// build lists from prepared data
|
|
||||||
BuildFolderList();
|
|
||||||
BuildFileList();
|
|
||||||
|
|
||||||
// scan filelist
|
|
||||||
ProcessFileList();
|
|
||||||
|
|
||||||
// doing work
|
|
||||||
m_copy_started = true;
|
|
||||||
m_ProgressBar.setMax(m_tocopy.size());
|
|
||||||
|
|
||||||
for (int i = 0; i < m_tocopy.size(); i++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String filename = m_tocopy.get(i);
|
|
||||||
publishProgress(i);
|
|
||||||
|
|
||||||
boolean asset_size_unknown = false;
|
|
||||||
long filesize = -1;
|
|
||||||
|
|
||||||
if (m_asset_size_unknown.contains(filename))
|
|
||||||
{
|
|
||||||
File testme = new File(baseDir + "/" + filename);
|
|
||||||
|
|
||||||
if(testme.exists())
|
|
||||||
{
|
|
||||||
filesize = testme.length();
|
|
||||||
}
|
|
||||||
asset_size_unknown = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream src;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
src = getAssets().open(filename);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e("MinetestAssetCopy","Copying file: " + filename + " FAILED (not in assets)");
|
|
||||||
e.printStackTrace();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transfer bytes from in to out
|
|
||||||
byte[] buf = new byte[1*1024];
|
|
||||||
int len = src.read(buf, 0, 1024);
|
|
||||||
|
|
||||||
/* following handling is crazy but we need to deal with */
|
|
||||||
/* compressed assets.Flash chips limited livetime due to */
|
|
||||||
/* write operations, we can't allow large files to destroy */
|
|
||||||
/* users flash. */
|
|
||||||
if (asset_size_unknown)
|
|
||||||
{
|
|
||||||
if ( (len > 0) && (len < buf.length) && (len == filesize))
|
|
||||||
{
|
|
||||||
src.close();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len == buf.length)
|
|
||||||
{
|
|
||||||
src.close();
|
|
||||||
long size = getFullSize(filename);
|
|
||||||
if ( size == filesize)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
src = getAssets().open(filename);
|
|
||||||
len = src.read(buf, 0, 1024);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
int total_filesize = 0;
|
|
||||||
OutputStream dst;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
dst = new FileOutputStream(baseDir + "/" + filename);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e("MinetestAssetCopy","Copying file: " + baseDir +
|
|
||||||
"/" + filename + " FAILED (couldn't open output file)");
|
|
||||||
e.printStackTrace();
|
|
||||||
src.close();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dst.write(buf, 0, len);
|
|
||||||
total_filesize += len;
|
|
||||||
|
|
||||||
while ((len = src.read(buf)) > 0)
|
|
||||||
{
|
|
||||||
dst.write(buf, 0, len);
|
|
||||||
total_filesize += len;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst.close();
|
|
||||||
Log.v("MinetestAssetCopy","Copied file: " +
|
|
||||||
m_tocopy.get(i) + " (" + total_filesize +
|
|
||||||
" bytes)");
|
|
||||||
}
|
|
||||||
else if (len < 0)
|
|
||||||
{
|
|
||||||
Log.e("MinetestAssetCopy","Copying file: " +
|
|
||||||
m_tocopy.get(i) + " failed, size < 0");
|
|
||||||
}
|
|
||||||
src.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
Log.e("MinetestAssetCopy","Copying file: " +
|
|
||||||
m_tocopy.get(i) + " failed");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* update progress bar
|
|
||||||
*/
|
|
||||||
protected void onProgressUpdate(Integer... progress)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (m_copy_started)
|
|
||||||
{
|
|
||||||
boolean shortened = false;
|
|
||||||
String todisplay = m_tocopy.get(progress[0]);
|
|
||||||
m_ProgressBar.setProgress(progress[0]);
|
|
||||||
|
|
||||||
// make sure our text doesn't exceed our layout width
|
|
||||||
Rect bounds = new Rect();
|
|
||||||
Paint textPaint = m_Filename.getPaint();
|
|
||||||
textPaint.getTextBounds(todisplay, 0, todisplay.length(), bounds);
|
|
||||||
|
|
||||||
while (bounds.width() > getResources().getDisplayMetrics().widthPixels * 0.7) {
|
|
||||||
if (todisplay.length() < 2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
todisplay = todisplay.substring(1);
|
|
||||||
textPaint.getTextBounds(todisplay, 0, todisplay.length(), bounds);
|
|
||||||
shortened = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! shortened) {
|
|
||||||
m_Filename.setText(todisplay);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_Filename.setText(".." + todisplay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boolean shortened = false;
|
|
||||||
String todisplay = m_Foldername;
|
|
||||||
String full_text = "scanning " + todisplay + " ...";
|
|
||||||
// make sure our text doesn't exceed our layout width
|
|
||||||
Rect bounds = new Rect();
|
|
||||||
Paint textPaint = m_Filename.getPaint();
|
|
||||||
textPaint.getTextBounds(full_text, 0, full_text.length(), bounds);
|
|
||||||
|
|
||||||
while (bounds.width() > getResources().getDisplayMetrics().widthPixels * 0.7) {
|
|
||||||
if (todisplay.length() < 2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
todisplay = todisplay.substring(1);
|
|
||||||
full_text = "scanning " + todisplay + " ...";
|
|
||||||
textPaint.getTextBounds(full_text, 0, full_text.length(), bounds);
|
|
||||||
shortened = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! shortened) {
|
|
||||||
m_Filename.setText(full_text);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_Filename.setText("scanning .." + todisplay + " ...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check al files and folders in filelist
|
|
||||||
*/
|
|
||||||
protected void ProcessFileList()
|
|
||||||
{
|
|
||||||
String FlashBaseDir =
|
|
||||||
Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
||||||
|
|
||||||
Iterator itr = m_filenames.iterator();
|
|
||||||
|
|
||||||
while (itr.hasNext())
|
|
||||||
{
|
|
||||||
String current_path = (String) itr.next();
|
|
||||||
String FlashPath = FlashBaseDir + "/" + current_path;
|
|
||||||
|
|
||||||
if (isAssetFolder(current_path))
|
|
||||||
{
|
|
||||||
/* store information and update gui */
|
|
||||||
m_Foldername = current_path;
|
|
||||||
publishProgress(0);
|
|
||||||
|
|
||||||
/* open file in order to check if it's a folder */
|
|
||||||
File current_folder = new File(FlashPath);
|
|
||||||
if (!current_folder.exists())
|
|
||||||
{
|
|
||||||
if (!current_folder.mkdirs())
|
|
||||||
{
|
|
||||||
Log.e("MinetestAssetCopy","\t failed create folder: " +
|
|
||||||
FlashPath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.v("MinetestAssetCopy","\t created folder: " +
|
|
||||||
FlashPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if it's not a folder it's most likely a file */
|
|
||||||
boolean refresh = true;
|
|
||||||
|
|
||||||
File testme = new File(FlashPath);
|
|
||||||
|
|
||||||
long asset_filesize = -1;
|
|
||||||
long stored_filesize = -1;
|
|
||||||
|
|
||||||
if (testme.exists())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
AssetFileDescriptor fd = getAssets().openFd(current_path);
|
|
||||||
asset_filesize = fd.getLength();
|
|
||||||
fd.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
refresh = true;
|
|
||||||
m_asset_size_unknown.add(current_path);
|
|
||||||
Log.e("MinetestAssetCopy","Failed to open asset file \"" +
|
|
||||||
FlashPath + "\" for size check");
|
|
||||||
}
|
|
||||||
|
|
||||||
stored_filesize = testme.length();
|
|
||||||
|
|
||||||
if (asset_filesize == stored_filesize)
|
|
||||||
{
|
|
||||||
refresh = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (refresh)
|
|
||||||
{
|
|
||||||
m_tocopy.add(current_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* read list of folders prepared on package build
|
|
||||||
*/
|
|
||||||
protected void BuildFolderList()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
InputStream is = getAssets().open("index.txt");
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
||||||
|
|
||||||
String line = reader.readLine();
|
|
||||||
while (line != null)
|
|
||||||
{
|
|
||||||
m_foldernames.add(line);
|
|
||||||
line = reader.readLine();
|
|
||||||
}
|
|
||||||
is.close();
|
|
||||||
} catch (IOException e1)
|
|
||||||
{
|
|
||||||
Log.e("MinetestAssetCopy","Error on processing index.txt");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* read list of asset files prepared on package build
|
|
||||||
*/
|
|
||||||
protected void BuildFileList()
|
|
||||||
{
|
|
||||||
long entrycount = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
InputStream is = getAssets().open("filelist.txt");
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
||||||
|
|
||||||
String line = reader.readLine();
|
|
||||||
while (line != null)
|
|
||||||
{
|
|
||||||
m_filenames.add(line);
|
|
||||||
line = reader.readLine();
|
|
||||||
entrycount ++;
|
|
||||||
}
|
|
||||||
is.close();
|
|
||||||
}
|
|
||||||
catch (IOException e1)
|
|
||||||
{
|
|
||||||
Log.e("MinetestAssetCopy","Error on processing filelist.txt");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPostExecute (String result)
|
|
||||||
{
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isAssetFolder(String path)
|
|
||||||
{
|
|
||||||
return m_foldernames.contains(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean m_copy_started = false;
|
|
||||||
String m_Foldername = "media";
|
|
||||||
Vector<String> m_foldernames;
|
|
||||||
Vector<String> m_filenames;
|
|
||||||
Vector<String> m_tocopy;
|
|
||||||
Vector<String> m_asset_size_unknown;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnKeyListener;
|
import android.view.View.OnKeyListener;
|
||||||
@ -17,7 +16,6 @@ public class MinetestTextEntry extends Activity {
|
|||||||
public EditText mTextInputWidget;
|
public EditText mTextInputWidget;
|
||||||
|
|
||||||
private final int MultiLineTextInput = 1;
|
private final int MultiLineTextInput = 1;
|
||||||
private final int SingleLineTextInput = 2;
|
|
||||||
private final int SingleLinePasswordInput = 3;
|
private final int SingleLinePasswordInput = 3;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,33 +34,34 @@ public class MinetestTextEntry extends Activity {
|
|||||||
mTextInputWidget.setText(current);
|
mTextInputWidget.setText(current);
|
||||||
mTextInputWidget.setMinWidth(300);
|
mTextInputWidget.setMinWidth(300);
|
||||||
if (editType == SingleLinePasswordInput) {
|
if (editType == SingleLinePasswordInput) {
|
||||||
mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT |
|
mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT
|
||||||
InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT);
|
mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
builder.setView(mTextInputWidget);
|
builder.setView(mTextInputWidget);
|
||||||
|
|
||||||
if (editType == MultiLineTextInput) {
|
if (editType == MultiLineTextInput) {
|
||||||
builder.setPositiveButton(acceptButton, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(acceptButton,
|
||||||
public void onClick(DialogInterface dialog, int whichButton)
|
new DialogInterface.OnClickListener() {
|
||||||
{ pushResult(mTextInputWidget.getText().toString()); }
|
public void onClick(DialogInterface dialog,
|
||||||
|
int whichButton) {
|
||||||
|
pushResult(mTextInputWidget.getText().toString());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
cancelDialog();
|
pushResult(mTextInputWidget.getText().toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mTextInputWidget.setOnKeyListener(new OnKeyListener() {
|
mTextInputWidget.setOnKeyListener(new OnKeyListener() {
|
||||||
@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) {
|
||||||
|
|
||||||
pushResult(mTextInputWidget.getText().toString());
|
pushResult(mTextInputWidget.getText().toString());
|
||||||
return true;
|
return true;
|
||||||
@ -78,14 +77,9 @@ public class MinetestTextEntry extends Activity {
|
|||||||
public void pushResult(String text) {
|
public void pushResult(String 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);
|
||||||
mTextInputDialog.dismiss();
|
mTextInputDialog.dismiss();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelDialog() {
|
|
||||||
setResult(Activity.RESULT_CANCELED);
|
|
||||||
mTextInputDialog.dismiss();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,33 +2,56 @@ package net.minetest.minetest;
|
|||||||
|
|
||||||
import android.app.NativeActivity;
|
import android.app.NativeActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.os.Handler;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
public class MtNativeActivity extends NativeActivity {
|
import com.MoNTE48.MultiCraft.Utilities;
|
||||||
|
import com.MoNTE48.MultiCraft.Utilities.IUtilitiesCallback;
|
||||||
|
import com.MoNTE48.RateME.RateThisApp;
|
||||||
|
|
||||||
|
public class MtNativeActivity extends NativeActivity implements
|
||||||
|
IUtilitiesCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
m_MessagReturnCode = -1;
|
m_MessagReturnCode = -1;
|
||||||
m_MessageReturnValue = "";
|
m_MessageReturnValue = "";
|
||||||
|
RateThisApp.onStart(this);
|
||||||
|
startDialogs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startDialogs() {
|
||||||
|
final Handler handler = new Handler();
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void run() {
|
||||||
super.onDestroy();
|
Utilities util = new Utilities(MtNativeActivity.this);
|
||||||
|
util.showHelpDialog();
|
||||||
|
SharedPreferences settings = MtNativeActivity.this
|
||||||
|
.getSharedPreferences(Utilities.PREFS_NAME, 0);
|
||||||
|
String skipMessage = settings.getString("skipMessage",
|
||||||
|
"NOT checked");
|
||||||
|
if ("checked".equalsIgnoreCase(skipMessage)) {
|
||||||
|
if (RateThisApp.shouldShowRateDialog()) {
|
||||||
|
RateThisApp
|
||||||
|
.showRateDialogIfNeeded(MtNativeActivity.this);
|
||||||
|
} else
|
||||||
|
util.showVersionDialog();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void copyAssets() {
|
public void copyAssets() {
|
||||||
Intent intent = new Intent(this, MinetestAssetCopy.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog(String acceptButton, String hint, String current,
|
public void showDialog(String acceptButton, String hint, String current,
|
||||||
int editType) {
|
int editType) {
|
||||||
|
|
||||||
Intent intent = new Intent(this, MinetestTextEntry.class);
|
Intent intent = new Intent(this, MinetestTextEntry.class);
|
||||||
Bundle params = new Bundle();
|
Bundle params = new Bundle();
|
||||||
params.putString("acceptButton", acceptButton);
|
params.putString("acceptButton", acceptButton);
|
||||||
@ -43,7 +66,6 @@ public class MtNativeActivity extends NativeActivity {
|
|||||||
|
|
||||||
public static native void putMessageBoxResult(String text);
|
public static native void putMessageBoxResult(String text);
|
||||||
|
|
||||||
/* ugly code to workaround putMessageBoxResult not beeing found */
|
|
||||||
public int getDialogState() {
|
public int getDialogState() {
|
||||||
return m_MessagReturnCode;
|
return m_MessagReturnCode;
|
||||||
}
|
}
|
||||||
@ -66,15 +88,13 @@ public class MtNativeActivity extends NativeActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode,
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
Intent data) {
|
|
||||||
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;
|
m_MessagReturnCode = 0;
|
||||||
m_MessageReturnValue = text;
|
m_MessageReturnValue = text;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
m_MessagReturnCode = 1;
|
m_MessagReturnCode = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,4 +110,9 @@ public class MtNativeActivity extends NativeActivity {
|
|||||||
|
|
||||||
private int m_MessagReturnCode;
|
private int m_MessagReturnCode;
|
||||||
private String m_MessageReturnValue;
|
private String m_MessageReturnValue;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|