old files removed

This commit is contained in:
berkut 2015-12-29 23:08:30 +03:00
parent c55abbf670
commit 927e063e47
28 changed files with 4 additions and 2351 deletions

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mobi.MultiCraft"
package="net.MultiCraft.Official"
android:installLocation="auto"
android:versionCode="###ANDROID_VERSION###"
android:versionName="###BASE_VERSION###" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
android:targetSdkVersion="23" />
<supports-screens android:smallScreens="false" />
@ -35,7 +35,8 @@
android:name="mobi.MultiCraft.MCNativeActivity"
android:configChanges="orientation|keyboard|keyboardHidden|navigation|screenSize"
android:launchMode="singleTask"
android:screenOrientation="sensorLandscape" >
android:screenOrientation="sensorLandscape"
android:theme="@style/Theme.Transparent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 835 KiB

View File

@ -1,28 +0,0 @@
<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>

View File

@ -1,70 +0,0 @@
<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/loading"
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"
android:visibility="gone" />
<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"
android:visibility="gone" />
<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"
android:visibility="gone" />
</RelativeLayout>

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@android:color/white" />
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/negative"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@android:color/white" />
<Button
android:id="@+id/positive"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>

View File

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/rta_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/rta_dialog_title" />
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
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:layout_height="64dp"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
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:background="@android:color/transparent"
android:enabled="false"
android:text="@string/rate_submit"
android:textColor="#00ced1" />
</LinearLayout>

View File

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- подготовка к запуску -->
<string name="loading">Загрузка&#8230;</string>
<string name="warning">Игра запустится через несколько секунд&#8230;</string>
<string name="rm_old">Подготовка к обновлению&#8230;</string>
<string name="copy">Копирование&#8230;</string>
<string name="notification_title">Загрузка MultiCraft</string>
<string name="notification_description">Осталось меньше минуты&#8230;</string>
<!-- диалог оценки -->
<string name="rta_dialog_title">Оцените MultiCraft!</string>
<string name="rate_title">Название</string>
<string name="rate_submit">Оценить</string>
<string name="rate_description">Описание</string>
<string name="sad">Очень жаль&#8230;</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">Напомнить позже&#8230;</string>
<string name="update_ignore">Игнорировать</string>
<!-- инструкция -->
<string name="dialog_instruction">Привет! После загрузки игры нажмите Play.\nЧтобы поставить блок, нажмите на экран.\nЧтобы разрушить блок, удерживайте палец на экране.</string>
<string name="ok">Закрыть</string>
<string name="forget">Не напоминать</string>
<!-- недостаточно места -->
<string name="not_enough_space">Недостаточно места для распаковки.\nОсвободите пространство на SD карте</string>
<string name="space_ok">OK</string>
<!-- диалог CPU -->
<string name="cpu_warning">Игра несовместима с вашим типом процессора</string>
</resources>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="semi_transparent">#80000000</color>
</resources>

View File

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

View File

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">MultiCraft</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&#8230;</string>
<!-- preparation for start -->
<string name="loading">Loading&#8230;</string>
<string name="warning">Game will start in few second&#8230;</string>
<string name="rm_old">Preparing to update&#8230;</string>
<string name="copy">Copying&#8230;</string>
<string name="notification_title">Downloading MultiCraft</string>
<string name="notification_description">Less than 1 minute&#8230;</string>
<!-- weak phone dialog -->
<string name="memory_warning">Your device\'s memory is too low for seamless playing</string>
<string name="memory_continue">Got it</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&#8230;</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 a block tap on screen.\nTo destroy a block long tap on screen.</string>
<string name="ok">Close</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>
<!-- CPU dialog -->
<string name="cpu_warning">The game is not compatible with your CPU arch</string>
</resources>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
<style name="MCTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen" />
</resources>

View File

@ -1,22 +0,0 @@
package com.winsontan520.wversionmanager.library;
import org.xml.sax.XMLReader;
import android.text.Editable;
import android.text.Html.TagHandler;
public class CustomTagHandler implements TagHandler{
@Override
public void handleTag(boolean opening, String tag, Editable output,
XMLReader xmlReader) {
// you may add more tag handler which are not supported by android here
if("li".equals(tag)){
if(opening){
output.append(" \u2022 ");
}else{
output.append("\n");
}
}
}
}

View File

@ -1,123 +0,0 @@
package com.winsontan520.wversionmanager.library;
import android.graphics.drawable.Drawable;
public interface IWVersionManager {
/**
* @return Label of update now button
*/
public String getUpdateNowLabel();
/**
* @param updateNowLabel Set the label for update now button
*/
public void setUpdateNowLabel(String updateNowLabel);
/**
* @return label of remind me later button
*/
public String getRemindMeLaterLabel();
/**
* @param remindMeLaterLabel Set label of remind me later button
*/
public void setRemindMeLaterLabel(String remindMeLaterLabel);
/**
* @return label of ignore this version button
*/
public String getIgnoreThisVersionLabel();
/**
* @param ignoreThisVersionLabel Set label of ignore this version button
*/
public void setIgnoreThisVersionLabel(String ignoreThisVersionLabel);
/**
* @param icon Set drawable of icon in dialog
*/
public void setIcon(Drawable icon);
/**
* @param title Set title of dialog
*/
public void setTitle(String title);
/**
* @param message Set message of dialog
*/
public void setMessage(String message);
/**
* @return message of dialog
*/
public String getMessage();
/**
* @return title of dialog
*/
public String getTitle();
/**
* @return drawable of icon
*/
public Drawable getIcon();
/**
* @return url to execute when update now button clicked. Default value is the link in google play based on app package name.
*/
public String getUpdateUrl();
/**
* @param updateUrl Set url to execute when update now button clicked
*/
public void setUpdateUrl(String updateUrl);
/**
* @return url which should return update content in json format
*/
public String getVersionContentUrl();
/**
* @param versionContentUrl Set the update content url
*/
public void setVersionContentUrl(String versionContentUrl);
/**
* @param minutes Set reminder time in minutes when remind me later button clicked
*/
public void setReminderTimer(int minutes);
/**
* @return reminder timer in minutes
*/
public int getReminderTimer();
/**
* @return current version code
*/
public int getCurrentVersionCode();
/**
* @return version code which will be ignored
*/
public int getIgnoreVersionCode();
/**
* @return CustomTagHandler object
*/
public CustomTagHandler getCustomTagHandler();
/**
* @param customTagHandler Set your own custom tag handler
*/
public void setCustomTagHandler(CustomTagHandler customTagHandler);
/**
* @param OnReceiveListener Set your own callback listener when receiving response from server
*/
public void setOnReceiveListener(OnReceiveListener listener);
}

View File

@ -1,11 +0,0 @@
package com.winsontan520.wversionmanager.library;
public interface OnReceiveListener {
/**
* @param status response code from HTTP request
* @param result response data from HTTP request
* @return return true to show default library dialog
*/
boolean onReceive(int status, String result);
}

View File

@ -1,594 +0,0 @@
package com.winsontan520.wversionmanager.library;
import static mobi.MultiCraft.PreferencesHelper.TAG_VERSION_SHOWED;
import static mobi.MultiCraft.PreferencesHelper.saveSettings;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Calendar;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.text.Html;
import android.util.Log;
import mobi.MultiCraft.BuildConfig;
import mobi.MultiCraft.IDialogHelperCallback;
@SuppressWarnings("deprecation")
public class WVersionManager implements IWVersionManager {
private static final String TAG = "WVersionManager";
private static final int MODE_CHECK_VERSION = 100;
private static final int MODE_ASK_FOR_RATE = 200;
private CustomTagHandler customTagHandler;
private IDialogHelperCallback callerActivity;
private String PREF_IGNORE_VERSION_CODE = "w.ignore.version.code";
private String PREF_REMINDER_TIME = "w.reminder.time";
private Activity activity;
private Drawable icon;
private String title;
private String message;
private String updateNowLabel;
private String remindMeLaterLabel;
private String ignoreThisVersionLabel;
private String updateUrl;
private String versionContentUrl;
private int reminderTimer;
private int mVersionCode;
private AlertDialogButtonListener listener;
private boolean mDialogCancelable = true;
private String mAskForRatePositiveLabel;
private String mAskForRateNegativeLabel;
private int mMode = 100; // default mode
private OnReceiveListener mOnReceiveListener;
private String mResult;
public WVersionManager(Activity act) {
this.activity = act;
this.customTagHandler = new CustomTagHandler();
callerActivity = (IDialogHelperCallback) act;
}
private Drawable getDefaultAppIcon() {
Drawable d = activity.getApplicationInfo().loadIcon(activity.getPackageManager());
return d;
}
public void checkVersion() {
mMode = MODE_CHECK_VERSION;
String versionContentUrl = getVersionContentUrl();
if (versionContentUrl == null) {
Log.e(TAG, "Please set versionContentUrl first");
return;
}
Calendar c = Calendar.getInstance();
long currentTimeStamp = c.getTimeInMillis();
long reminderTimeStamp = getReminderTime();
if (BuildConfig.DEBUG) {
Log.v(TAG, "currentTimeStamp=" + currentTimeStamp);
Log.v(TAG, "reminderTimeStamp=" + reminderTimeStamp);
}
if (currentTimeStamp > reminderTimeStamp) {
// fire request to get update version content
if (BuildConfig.DEBUG) {
Log.v(TAG, "getting update content...");
}
VersionContentRequest request = new VersionContentRequest(activity);
request.execute(getVersionContentUrl());
} else
saveSettings(activity, TAG_VERSION_SHOWED, false);
}
public AlertDialog showDialog(int bitMask) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setIcon(getIcon());
builder.setTitle(getTitle());
builder.setMessage(Html.fromHtml(getMessage(), null, getCustomTagHandler()));
switch (mMode) {
case MODE_CHECK_VERSION:
listener = new AlertDialogButtonListener(bitMask);
builder.setPositiveButton(getUpdateNowLabel(), listener);
builder.setNeutralButton(getRemindMeLaterLabel(), listener);
builder.setNegativeButton(getIgnoreThisVersionLabel(), listener);
break;
case MODE_ASK_FOR_RATE:
builder.setPositiveButton(getAskForRatePositiveLabel(), listener);
builder.setNegativeButton(getAskForRateNegativeLabel(), listener);
break;
default:
return null;
}
builder.setCancelable(isDialogCancelable());
AlertDialog dialog = builder.create();
/*
* if (activity != null && !activity.isFinishing()) { dialog.show(); }
*/ return dialog;
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#getUpdateNowLabel()
*/
@Override
public String getUpdateNowLabel() {
return updateNowLabel != null ? updateNowLabel : "Update now";
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#setUpdateNowLabel
* (java.lang.String)
*/
@Override
public void setUpdateNowLabel(String updateNowLabel) {
this.updateNowLabel = updateNowLabel;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* getRemindMeLaterLabel ()
*/
@Override
public String getRemindMeLaterLabel() {
return remindMeLaterLabel != null ? remindMeLaterLabel : "Remind me later";
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* setRemindMeLaterLabel (java.lang.String)
*/
@Override
public void setRemindMeLaterLabel(String remindMeLaterLabel) {
this.remindMeLaterLabel = remindMeLaterLabel;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* getIgnoreThisVersionLabel()
*/
@Override
public String getIgnoreThisVersionLabel() {
return ignoreThisVersionLabel != null ? ignoreThisVersionLabel : "Ignore this version";
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* setIgnoreThisVersionLabel(java.lang.String)
*/
@Override
public void setIgnoreThisVersionLabel(String ignoreThisVersionLabel) {
this.ignoreThisVersionLabel = ignoreThisVersionLabel;
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#setIcon(android
* .graphics.drawable.Drawable)
*/
@Override
public void setIcon(Drawable icon) {
this.icon = icon;
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#setTitle(java.lang
* .String)
*/
@Override
public void setTitle(String title) {
this.title = title;
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#setMessage(java
* .lang.String)
*/
@Override
public void setMessage(String message) {
this.message = message;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#getMessage()
*/
@Override
public String getMessage() {
String defaultMessage = null;
switch (mMode) {
case MODE_CHECK_VERSION:
defaultMessage = "What's new in this version";
break;
case MODE_ASK_FOR_RATE:
defaultMessage = "Please rate us!";
break;
}
return message != null ? message : defaultMessage;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#getTitle()
*/
@Override
public String getTitle() {
String defaultTitle = null;
switch (mMode) {
case MODE_CHECK_VERSION:
defaultTitle = "New Update Available";
break;
case MODE_ASK_FOR_RATE:
defaultTitle = "Rate this app";
break;
}
return title != null ? title : defaultTitle;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#getIcon()
*/
@Override
public Drawable getIcon() {
return icon != null ? icon : getDefaultAppIcon();
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#getUpdateUrl()
*/
@Override
public String getUpdateUrl() {
return updateUrl != null ? updateUrl : getGooglePlayStoreUrl();
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#setUpdateUrl(java
* .lang.String)
*/
@Override
public void setUpdateUrl(String updateUrl) {
this.updateUrl = updateUrl;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* getVersionContentUrl ()
*/
@Override
public String getVersionContentUrl() {
return versionContentUrl;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* setVersionContentUrl (java.lang.String)
*/
@Override
public void setVersionContentUrl(String versionContentUrl) {
this.versionContentUrl = versionContentUrl;
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* setVersionContentUrl (java.lang.String)
*/
@Override
public int getReminderTimer() {
return reminderTimer > 0 ? reminderTimer : (1 * 60); // default value 60
// minutes
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#setReminderTimer
* (int)
*/
@Override
public void setReminderTimer(int minutes) {
if (minutes > 0) {
reminderTimer = minutes;
}
}
private void updateNow(String url) {
if (url != null) {
try {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "is update url correct?" + e);
}
}
}
private void remindMeLater(int reminderTimer) {
Calendar c = Calendar.getInstance();
long currentTimeStamp = c.getTimeInMillis();
c.add(Calendar.MINUTE, reminderTimer);
long reminderTimeStamp = c.getTimeInMillis();
if (BuildConfig.DEBUG) {
Log.v(TAG, "currentTimeStamp=" + currentTimeStamp);
Log.v(TAG, "reminderTimeStamp=" + reminderTimeStamp);
}
setReminderTime(reminderTimeStamp);
}
private void setReminderTime(long reminderTimeStamp) {
PreferenceManager.getDefaultSharedPreferences(activity).edit().putLong(PREF_REMINDER_TIME, reminderTimeStamp)
.commit();
}
private long getReminderTime() {
return PreferenceManager.getDefaultSharedPreferences(activity).getLong(PREF_REMINDER_TIME, 0);
}
private void ignoreThisVersion() {
PreferenceManager.getDefaultSharedPreferences(activity).edit().putInt(PREF_IGNORE_VERSION_CODE, mVersionCode)
.commit();
}
private String getGooglePlayStoreUrl() {
String id = activity.getApplicationInfo().packageName; // current google
// play is using
// package name
// as id
return "market://details?id=" + id;
}
private class AlertDialogButtonListener implements DialogInterface.OnClickListener {
private int bitMask;
public AlertDialogButtonListener(int bitMask) {
this.bitMask = bitMask;
}
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case AlertDialog.BUTTON_POSITIVE:
updateNow(getUpdateUrl());
callerActivity.exit();
break;
case AlertDialog.BUTTON_NEUTRAL:
remindMeLater(getReminderTimer());
callerActivity.showDialogTree(bitMask);
break;
case AlertDialog.BUTTON_NEGATIVE:
ignoreThisVersion();
callerActivity.showDialogTree(bitMask);
break;
}
}
}
class VersionContentRequest extends AsyncTask<String, Void, String> {
Context context;
int statusCode;
public VersionContentRequest(Context context) {
this.context = context;
}
@Override
protected String doInBackground(String... uri) {
DefaultHttpClient client = new DefaultHttpClient();
String responseBody = null;
HttpResponse httpResponse = null;
ByteArrayOutputStream out = null;
try {
HttpGet httpget = new HttpGet(uri[0]);
httpResponse = client.execute(httpget);
statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
out = new ByteArrayOutputStream();
httpResponse.getEntity().writeTo(out);
responseBody = out.toString();
}
} catch (Exception e) {
Log.e(TAG, e.toString());
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
Log.e(TAG, e.toString());
}
}
}
return responseBody;
}
@Override
protected void onPostExecute(String result) {
mVersionCode = 0;
String content = null;
if (statusCode != HttpStatus.SC_OK) {
Log.e(TAG, "Response invalid. status code = " + statusCode);
if (mOnReceiveListener != null) {
mOnReceiveListener.onReceive(statusCode, result);
}
} else {
try {
if (!result.startsWith("{")) { // for response who append
// with unknown char
result = result.substring(1);
}
mResult = result;
if (BuildConfig.DEBUG) {
Log.d(TAG, "status = " + statusCode);
Log.d(TAG, "result = " + mResult);
}
// show default dialog if no listener is set OR return true
if (mOnReceiveListener == null || mOnReceiveListener.onReceive(statusCode, result)) {
// json format from server:
JSONObject json = (JSONObject) new JSONTokener(mResult).nextValue();
mVersionCode = json.optInt("version_code");
content = json.optString("content");
int currentVersionCode = getCurrentVersionCode();
if (currentVersionCode < mVersionCode) {
// new versionCode will always higher than
// currentVersionCode
if (mVersionCode != getIgnoreVersionCode()) {
// set dialog message
setMessage(content);
saveSettings(context, TAG_VERSION_SHOWED, true);
}
}
}
} catch (JSONException e) {
Log.e(TAG, "is your server response have valid json format?");
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
}
}
/*
* (non-Javadoc)
*
* @see com.winsontan520.wversionmanagertest.IWVersionManager#
* getCurrentVersionCode ()
*/
@Override
public int getCurrentVersionCode() {
int currentVersionCode = 0;
PackageInfo pInfo;
try {
pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
currentVersionCode = pInfo.versionCode;
} catch (NameNotFoundException e) {
// return 0
}
return currentVersionCode;
}
@Override
public int getIgnoreVersionCode() {
return PreferenceManager.getDefaultSharedPreferences(activity).getInt(PREF_IGNORE_VERSION_CODE, 1);
}
@Override
public CustomTagHandler getCustomTagHandler() {
return customTagHandler;
}
/*
* (non-Javadoc)
*
* @see
* com.winsontan520.wversionmanagertest.IWVersionManager#setCustomTagHandler
* (com.winsontan520.wversionmanagertest.WVersionManager.CustomTagHandler)
*/
@Override
public void setCustomTagHandler(CustomTagHandler customTagHandler) {
this.customTagHandler = customTagHandler;
}
public boolean isDialogCancelable() {
return mDialogCancelable;
}
public void setDialogCancelable(boolean dialogCancelable) {
mDialogCancelable = dialogCancelable;
}
public void askForRate() {
mMode = MODE_ASK_FOR_RATE;
// showDialog();
}
public String getAskForRatePositiveLabel() {
return mAskForRatePositiveLabel == null ? "OK" : mAskForRatePositiveLabel;
}
public void setAskForRatePositiveLabel(String askForRatePositiveLabel) {
mAskForRatePositiveLabel = askForRatePositiveLabel;
}
public String getAskForRateNegativeLabel() {
return mAskForRateNegativeLabel == null ? "Not now" : mAskForRateNegativeLabel;
}
public void setAskForRateNegativeLabel(String askForRateNegativeLabel) {
mAskForRateNegativeLabel = askForRateNegativeLabel;
}
@Override
public void setOnReceiveListener(OnReceiveListener listener) {
this.mOnReceiveListener = listener;
}
}

View File

@ -1,114 +0,0 @@
package mobi.MultiCraft;
import static mobi.MultiCraft.PreferencesHelper.TAG_HELP_SHOWED;
import static mobi.MultiCraft.PreferencesHelper.*;
import com.winsontan520.wversionmanager.library.WVersionManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
/**
* Helpful utilities used in MainActivity
*/
public class DialogHelper {
private Button positive, negative;
private Dialog dialog;
private Context mContext;
private IDialogHelperCallback callerActivity;
public DialogHelper(Context context) {
mContext = context;
callerActivity = (IDialogHelperCallback) context;
}
private void dialogInit(int panel, int positiveBtn, int negativeBtn, int messageText) {
dialog = new Dialog(mContext);
dialog.requestWindowFeature(panel);
dialog.setContentView(R.layout.dialog_template);
positive = (Button) dialog.findViewById(R.id.positive);
negative = (Button) dialog.findViewById(R.id.negative);
TextView message = (TextView) dialog.findViewById(R.id.message);
positive.setText(positiveBtn);
negative.setText(negativeBtn);
message.setText(messageText);
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(R.color.semi_transparent));
}
@SuppressLint("InflateParams")
public Dialog showHelpDialog(final int bitMask) {
dialogInit(Window.FEATURE_NO_TITLE, R.string.ok, R.string.forget, R.string.dialog_instruction);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
saveSettings(mContext, TAG_HELP_SHOWED, false);
callerActivity.showDialogTree(bitMask);
}
});
negative.setVisibility(View.GONE);
// dialog.show();
return dialog;
}
public Dialog showMemoryDialog(final int bitMask) {
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.memory_continue, R.string.memory_close,
R.string.memory_warning);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Toast.makeText(mContext, R.string.memory_lags, Toast.LENGTH_SHORT).show();
callerActivity.showDialogTree(bitMask);
}
});
negative.setVisibility(View.GONE);
// dialog.show();
return dialog;
}
public Dialog showVersionDialog(int bitMask) {
WVersionManager versionManager = new WVersionManager((Activity) mContext);
versionManager.setVersionContentUrl("http://MultiCraft.mobi/ver/MultiCraft.txt");
versionManager.checkVersion();
versionManager.setUpdateNowLabel((String) mContext.getResources().getText(R.string.update_yes));
versionManager.setRemindMeLaterLabel((String) mContext.getResources().getText(R.string.update_no));
versionManager.setIgnoreThisVersionLabel((String) mContext.getResources().getText(R.string.update_ignore));
return versionManager.showDialog(bitMask);
}
public Dialog showRateDialog(int bitMask) {
return RateThisApp.showRateDialog(mContext, bitMask);
}
/*
* public void showCPUDialog() { dialogInit(Window.FEATURE_OPTIONS_PANEL,
* R.string.memory_continue, R.string.memory_close, R.string.cpu_warning);
* positive.setOnClickListener(new OnClickListener() {
*
* @Override public void onClick(View v) { dialog.dismiss(); } });
* negative.setVisibility(View.GONE); dialog.show(); }
*/
public void showNotEnoughSpaceDialog() {
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.space_ok, R.string.memory_close, R.string.not_enough_space);
negative.setVisibility(View.GONE);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}

View File

@ -1,15 +0,0 @@
package mobi.MultiCraft;
/**
* Callback for MainActivity init and runGame methods
*/
public interface IDialogHelperCallback {
public void init();
public void runGame();
public void exit();
public void showDialogTree(int bitMask);
}

View File

@ -1,109 +0,0 @@
package mobi.MultiCraft;
import android.app.NativeActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
public class MCNativeActivity extends NativeActivity {
private int m_MessagReturnCode;
private String m_MessageReturnValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
m_MessagReturnCode = -1;
m_MessageReturnValue = "";
}
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;
}
}
}
public void copyAssets() {
}
public void showDialog(String acceptButton, String hint, String current,
int editType) {
Intent intent = new Intent(this, MultiCraftTextEntry.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");
System.loadLibrary("gmp");
System.loadLibrary("iconv");
// We don't have to load libminetest.so ourselves,
// but if we do, we get nicer logcat errors when
// loading fails.
System.loadLibrary("minetest");
}
private int m_MessagReturnCode;
private String m_MessageReturnValue;
}

View File

@ -1,380 +0,0 @@
package mobi.MultiCraft;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Locale;
import static mobi.MultiCraft.PreferencesHelper.DIALOGS;
import static mobi.MultiCraft.PreferencesHelper.HELP_DIALOG;
import static mobi.MultiCraft.PreferencesHelper.MEMORY_DIALOG;
import static mobi.MultiCraft.PreferencesHelper.RATE_DIALOG;
import static mobi.MultiCraft.PreferencesHelper.TAG_SHORTCUT_CREATED;
import static mobi.MultiCraft.PreferencesHelper.VERSION_DIALOG;
import static mobi.MultiCraft.PreferencesHelper.getBitMask;
import static mobi.MultiCraft.PreferencesHelper.isCreateShortcut;
import static mobi.MultiCraft.PreferencesHelper.loadSettings;
import static mobi.MultiCraft.PreferencesHelper.saveSettings;
public class MainActivity extends Activity implements IDialogHelperCallback {
public final static String TAG = "Error";
public final static String CREATE_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
public final static String FILES = "Files.zip";
public final static String NOMEDIA = ".nomedia";
public final static String STABLE_VER = "1.0.1";
private ProgressDialog mProgressDialog;
private TextView mProgressTextView, mWarningTextView;
private String unzipLocation = Environment.getExternalStorageDirectory() + "/MultiCraft/";
private DialogHelper dialogHelper;
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);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
RateThisApp.onStart(this);
loadSettings(this);
dialogHelper = new DialogHelper(this);
registerReceivers();
if (!isTaskRoot()) {
finish();
return;
}
showDialogTree(getBitMask());
}
@Override
public void showDialogTree(int bitMask) {
if (bitMask == 0) {
init();
return;
}
for (int dialog : DIALOGS) {
Dialog currentDialog = null;
if ((bitMask & dialog) > 0) {
bitMask -= dialog;
switch (dialog) {
case MEMORY_DIALOG:
currentDialog = dialogHelper.showMemoryDialog(bitMask);
break;
case RATE_DIALOG:
currentDialog = dialogHelper.showRateDialog(bitMask);
break;
case VERSION_DIALOG:
currentDialog = dialogHelper.showVersionDialog(bitMask);
break;
case HELP_DIALOG:
currentDialog = dialogHelper.showHelpDialog(bitMask);
break;
}
if (currentDialog != null) {
currentDialog.show();
}
break;
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
dismissProgressDialog();
unregisterReceiver(myBroadcastReceiver);
unregisterReceiver(myBroadcastReceiver_Update);
}
private void addShortcut() {
saveSettings(this, TAG_SHORTCUT_CREATED, false);
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(CREATE_SHORTCUT);
getApplicationContext().sendBroadcast(addIntent);
}
@Override
@SuppressWarnings("deprecation")
public void init() {
if (isCreateShortcut())
addShortcut();
mProgressTextView = (TextView) findViewById(R.id.progress_textView);
mProgressBar = (ProgressBar) findViewById(R.id.PB1);
mWarningTextView = (TextView) findViewById(R.id.warning);
Drawable draw;
draw = getResources().getDrawable(R.drawable.custom_progress_bar);
mProgressBar.setProgressDrawable(draw);
Utilities util = new Utilities();
util.createDirAndFiles();
util.checkVersion();
}
@Override
public void exit() {
finish();
}
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();
}
}
@Override
public void runGame() {
showSpinnerDialog(R.string.loading);
new Thread(new Runnable() {
public void run() {
Intent intent = new Intent(MainActivity.this, MCNativeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
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)) {
runGame();
}
}
}
public class MyBroadcastReceiver_Update extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int update = intent.getIntExtra(UnzipService.EXTRA_KEY_UPDATE, 0);
mProgressBar.setVisibility(View.VISIBLE);
mProgressTextView.setVisibility(View.VISIBLE);
mWarningTextView.setVisibility(View.VISIBLE);
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();
}
@Override
protected String doInBackground(String... params) {
zipName = params[0];
copyAssets(zipName);
return "Done";
}
@Override
protected void onPostExecute(String result) {
if (PhoneInformation.getAvailableSpaceInMB() > 30) {
try {
startUnzipService(Environment.getExternalStorageDirectory() + "/" + zipName);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
} else
dialogHelper.showNotEnoughSpaceDialog();
}
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);
}
}
}
private class Utilities {
private void createLangFile() {
PrintWriter writer;
try {
writer = new PrintWriter(unzipLocation + "lang.txt", "UTF-8");
if ("Russian".equals(Locale.getDefault().getDisplayLanguage())) {
writer.println("ru");
} else {
writer.println("en");
}
writer.close();
} catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage());
}
}
private void createDirAndFiles() {
try {
File folder = new File(unzipLocation);
if (!(folder.exists()))
folder.mkdirs();
File myFile = new File(unzipLocation, NOMEDIA);
if (!myFile.exists())
myFile.createNewFile();
createLangFile();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
}
private void checkVersion() {
File version = new File(unzipLocation + "ver.txt");
if (version.exists()) {
if (isCurrent(version))
runGame();
else
startDeletion();
} else {
startDeletion();
}
}
private void startDeletion() {
new DeleteTask().execute(unzipLocation + "cache", unzipLocation + "games", unzipLocation + "builtin",
unzipLocation + "fonts", unzipLocation + "debug.txt");
}
@SuppressWarnings("resource")
private boolean isCurrent(File file) {
String line = null;
try {
line = new BufferedReader(new FileReader(file)).readLine();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
if (line == null) {
line = "-999";
}
return line.equals(STABLE_VER);
}
}
}

View File

@ -1,85 +0,0 @@
package mobi.MultiCraft;
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.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;
public class MultiCraftTextEntry extends Activity {
public AlertDialog mTextInputDialog;
public EditText mTextInputWidget;
private final int MultiLineTextInput = 1;
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) {
pushResult(mTextInputWidget.getText().toString());
}
});
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();
}
}

View File

@ -1,83 +0,0 @@
package mobi.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 android.annotation.SuppressLint;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
public class PhoneInformation {
public static 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 static 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());
}
}
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static 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;
}
@SuppressLint("DefaultLocale")
public static boolean getCPUArch() {
String arch = System.getProperty("os.arch");
return arch.toLowerCase().matches(".*x86.*");
}
}

View File

@ -1,59 +0,0 @@
package mobi.MultiCraft;
import com.winsontan520.wversionmanager.library.WVersionManager;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
public class PreferencesHelper {
public static final int MEMORY_DIALOG = 1;
public static final int VERSION_DIALOG = 1 << 1;
public static final int RATE_DIALOG = 1 << 2;
public static final int HELP_DIALOG = 1 << 3;
public static final int[] DIALOGS = { MEMORY_DIALOG, VERSION_DIALOG, RATE_DIALOG, HELP_DIALOG };
public static final String SETTINGS = "settings";
public static final String TAG_SHORTCUT_CREATED = "createShortcut";
public static final String TAG_HELP_SHOWED = "showHelp";
public static final String TAG_RATE_SHOWED = "showRate";
public static final String TAG_CPU_SHOWED = "showCpuCheck";
public static final String TAG_VERSION_SHOWED = "showVersionCheck";
private static boolean disabledADS, createShortcut;
private static int bitMask;
public static boolean isCreateShortcut() {
return createShortcut;
}
public static int getBitMask() {
return bitMask;
}
public static boolean isAdsDisabled() {
return disabledADS;
}
public static void loadSettings(Context c) {
saveSettings(c, TAG_CPU_SHOWED, PhoneInformation.getCoresCount() < 4);
saveSettings(c, TAG_RATE_SHOWED, RateThisApp.shouldShowRateDialog());
WVersionManager versionManager = new WVersionManager((Activity) c);
versionManager.setVersionContentUrl("http://MultiCraft.mobi/ver/MultiCraft.txt");
versionManager.checkVersion();
SharedPreferences settings = c.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
createShortcut = settings.getBoolean(TAG_SHORTCUT_CREATED, true);
boolean showHelp = settings.getBoolean(TAG_HELP_SHOWED, true);
boolean showRate = settings.getBoolean(TAG_RATE_SHOWED, false);
boolean showCPUCheck = settings.getBoolean(TAG_CPU_SHOWED, false);
boolean showVersionCheck = settings.getBoolean(TAG_VERSION_SHOWED, false);
bitMask = (showHelp ? HELP_DIALOG : 0) + (showCPUCheck ? MEMORY_DIALOG : 0) + (showRate ? RATE_DIALOG : 0)
+ (showVersionCheck ? VERSION_DIALOG : 0);
}
public static void saveSettings(Context c, String tag, boolean bool) {
SharedPreferences settings = c.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(tag, bool);
editor.apply();
}
}

View File

@ -1,146 +0,0 @@
package mobi.MultiCraft;
import java.util.Date;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.ColorDrawable;
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 PREF_NAME = "RateThisApp";
private static final String GOOGLE_PLAY = "https://play.google.com/store/apps/details?id=";
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 IDialogHelperCallback callerActivity;
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();
callerActivity = (IDialogHelperCallback) context;
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 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 Dialog showRateDialog(final Context context, final int bitMask) {
// 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);
callerActivity.exit();
} else {
Toast.makeText(context, R.string.sad, Toast.LENGTH_LONG).show();
dialog.dismiss();
clearSharedPreferences(context);
callerActivity.showDialogTree(bitMask);
}
}
});
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(R.color.semi_transparent));
// dialog.show();
return dialog;
}
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);
}
}
}

View File

@ -1,97 +0,0 @@
package mobi.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 = "mobi.MultiCraft.RESPONSE";
public static final String ACTION_MyUpdate = "mobi.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("mobi.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.notification_title))
.setContentText(getString(R.string.notification_description)).setSmallIcon(R.drawable.update);
String file = intent.getStringExtra(EXTRA_KEY_IN_FILE);
String location = intent.getStringExtra(EXTRA_KEY_IN_LOCATION);
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);
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());
}
mNotifyManager.cancel(id);
Intent intentResponse = new Intent();
intentResponse.setAction(ACTION_MyIntentService);
intentResponse.addCategory(Intent.CATEGORY_DEFAULT);
intentResponse.putExtra(EXTRA_KEY_OUT, "Success");
sendBroadcast(intentResponse);
}
}

View File

@ -1,212 +0,0 @@
package mobi.MultiCraft;
import static mobi.MultiCraft.PreferencesHelper.TAG_HELP_SHOWED;
import static mobi.MultiCraft.PreferencesHelper.isShowHelp;
import static mobi.MultiCraft.PreferencesHelper.saveSettings;
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 com.winsontan520.wversionmanager.library.WVersionManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
/**
* Helpful utilities used in MainActivity
*/
public class Utilities {
private Button positive, negative;
private Dialog dialog;
private Context mContext;
public final String STABLE_VER = "1.0.1";
/**
* Callback for MainActivity init and finishMe methods
*/
public interface IUtilitiesCallback {
void init();
void finishMe();
}
private IUtilitiesCallback callerActivity;
public Utilities(Activity activity) {
mContext = activity;
callerActivity = (IUtilitiesCallback) activity;
}
private void dialogInit(int panel, int positiveBtn, int negativeBtn, int messageText) {
dialog = new Dialog(mContext);
dialog.requestWindowFeature(panel);
dialog.setContentView(R.layout.dialog_template);
positive = (Button) dialog.findViewById(R.id.positive);
negative = (Button) dialog.findViewById(R.id.negative);
TextView message = (TextView) dialog.findViewById(R.id.message);
positive.setText(positiveBtn);
negative.setText(negativeBtn);
message.setText(messageText);
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(R.color.semi_transparent));
}
@SuppressLint("InflateParams")
public void showHelpDialog() {
dialogInit(Window.FEATURE_NO_TITLE, R.string.ok, R.string.forget, R.string.dialog_instruction);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
saveSettings(mContext, TAG_HELP_SHOWED, false);
RateThisApp.showRateDialogIfNeeded(mContext);
}
});
negative.setVisibility(View.GONE);
if (isShowHelp()) {
dialog.show();
}
}
public void showVersionDialog() {
WVersionManager versionManager = new WVersionManager((Activity) mContext);
versionManager.setVersionContentUrl("http://MultiCraft.mobi/ver/MultiCraft.txt");
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() {
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.memory_continue, R.string.memory_close,
R.string.memory_warning);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Toast.makeText(mContext, R.string.memory_lags, Toast.LENGTH_SHORT).show();
callerActivity.init();
}
});
negative.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
callerActivity.finishMe();
}
});
dialog.show();
}
public void showNotEnoughSpaceDialog() {
dialogInit(Window.FEATURE_OPTIONS_PANEL, R.string.space_ok, R.string.memory_close, R.string.not_enough_space);
negative.setVisibility(View.GONE);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Toast.makeText(mContext, R.string.memory_lags, Toast.LENGTH_SHORT).show();
callerActivity.init();
}
});
dialog.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());
}
}
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public long getAvailableSpaceInMB() {
final long SIZE_KB = 1024L;
final long SIZE_MB = SIZE_KB * SIZE_KB;
long availableSpace;
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
if (Build.VERSION.SDK_INT > 17) {
availableSpace = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
availableSpace = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}
return availableSpace / SIZE_MB;
}
@SuppressWarnings("resource")
public boolean isCurrent(File file) {
String line = null;
try {
line = new BufferedReader(new FileReader(file)).readLine();
} catch (IOException e) {
Log.e("WTF", e.getMessage());
}
if (line == null) {
line = "-999";
}
return line.equals(STABLE_VER);
}
@SuppressLint("DefaultLocale")
public boolean getCPUArch() {
String arch = System.getProperty("os.arch");
return !arch.toLowerCase().matches(".*arm.*");
}
}