mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Added local logfile containing locat with Warning+ levels.
Maybe fixed bug crashing the game when starting a new game.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.gpl.rpg.AndorsTrail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -7,11 +9,13 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Environment;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
|
||||
import com.gpl.rpg.AndorsTrail.context.WorldContext;
|
||||
import com.gpl.rpg.AndorsTrail.controller.Constants;
|
||||
|
||||
public final class AndorsTrailApplication extends Application {
|
||||
|
||||
@@ -24,7 +28,7 @@ public final class AndorsTrailApplication extends Application {
|
||||
public static final boolean DEVELOPMENT_DEBUGMESSAGES = true;
|
||||
public static final boolean DEVELOPMENT_INCOMPATIBLE_SAVEGAMES = true; //DEVELOPMENT_DEBUGRESOURCES || DEVELOPMENT_DEBUGBUTTONS || DEVELOPMENT_FASTSPEED;
|
||||
public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? 999 : 43;
|
||||
public static final String CURRENT_VERSION_DISPLAY = "0.7.2_alpha1";
|
||||
public static final String CURRENT_VERSION_DISPLAY = "0.7.2_beta1";
|
||||
public static final boolean IS_RELEASE_VERSION = !CURRENT_VERSION_DISPLAY.matches(".*[a-d].*");
|
||||
|
||||
private final AndorsTrailPreferences preferences = new AndorsTrailPreferences();
|
||||
@@ -69,4 +73,58 @@ public final class AndorsTrailApplication extends Application {
|
||||
this.getResources().updateConfiguration(conf, res.getDisplayMetrics());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logging to text file system as found on https://stackoverflow.com/questions/19565685/saving-logcat-to-a-text-file-in-android-device
|
||||
*/
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
if ( DEVELOPMENT_DEBUGMESSAGES && isExternalStorageWritable() ) {
|
||||
|
||||
File root = Environment.getExternalStorageDirectory();
|
||||
File appDirectory = new File(root, Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
File logDirectory = new File( appDirectory, "log" );
|
||||
File logFile = new File( logDirectory, "logcat" + System.currentTimeMillis() + ".txt" );
|
||||
|
||||
// create app folder
|
||||
if ( !appDirectory.exists() ) {
|
||||
appDirectory.mkdir();
|
||||
}
|
||||
|
||||
// create log folder
|
||||
if ( !logDirectory.exists() ) {
|
||||
logDirectory.mkdir();
|
||||
}
|
||||
|
||||
// clear the previous logcat and then write the new one to the file
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("logcat -c");
|
||||
process = Runtime.getRuntime().exec("logcat -f " + logFile+" *:W");
|
||||
} catch ( IOException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Checks if external storage is available for read and write */
|
||||
public boolean isExternalStorageWritable() {
|
||||
String state = Environment.getExternalStorageState();
|
||||
if ( Environment.MEDIA_MOUNTED.equals( state ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Checks if external storage is available to at least read */
|
||||
public boolean isExternalStorageReadable() {
|
||||
String state = Environment.getExternalStorageState();
|
||||
if ( Environment.MEDIA_MOUNTED.equals( state ) ||
|
||||
Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,174 +1,176 @@
|
||||
package com.gpl.rpg.AndorsTrail.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.WorldSetup;
|
||||
import com.gpl.rpg.AndorsTrail.WorldSetup.OnResourcesLoadedListener;
|
||||
import com.gpl.rpg.AndorsTrail.WorldSetup.OnSceneLoadedListener;
|
||||
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
|
||||
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
|
||||
import com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
|
||||
|
||||
public final class LoadingActivity extends Activity implements OnResourcesLoadedListener, OnSceneLoadedListener {
|
||||
|
||||
private WorldSetup setup;
|
||||
private Dialog progressDialog;
|
||||
private CloudsAnimatorView clouds_back, clouds_mid, clouds_front;
|
||||
boolean loaded = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(ThemeHelper.getBaseTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
app.setWindowParameters(this);
|
||||
setContentView(R.layout.startscreen);
|
||||
|
||||
TextView tv = (TextView) findViewById(R.id.startscreen_version);
|
||||
tv.setVisibility(View.GONE);
|
||||
|
||||
clouds_back = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_back);
|
||||
if (clouds_back != null) clouds_back.setCloudsCountAndLayer(40, CloudsAnimatorView.Layer.below);
|
||||
clouds_mid = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_mid);
|
||||
if (clouds_mid != null) clouds_mid.setCloudsCountAndLayer(15, CloudsAnimatorView.Layer.center);
|
||||
clouds_front = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_front);
|
||||
if (clouds_front != null) clouds_front.setCloudsCountAndLayer(8, CloudsAnimatorView.Layer.above);
|
||||
|
||||
this.setup = app.getWorldSetup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus) {
|
||||
((AnimationDrawable)((ImageView)findViewById(R.id.title_logo)).getDrawable()).start();
|
||||
ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
|
||||
int ivWidth = iv.getWidth();
|
||||
int drawableWidth = iv.getDrawable().getIntrinsicWidth();
|
||||
float ratio = ((float)ivWidth) / ((float)drawableWidth);
|
||||
|
||||
if (clouds_back != null) {
|
||||
clouds_back.setScalingRatio(ratio);
|
||||
}
|
||||
if (clouds_mid != null) {
|
||||
clouds_mid.setScalingRatio(ratio);
|
||||
}
|
||||
if (clouds_front != null) {
|
||||
clouds_front.setScalingRatio(ratio);
|
||||
}
|
||||
|
||||
if (progressDialog == null) {
|
||||
progressDialog = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_message),
|
||||
getResources().getDrawable(R.drawable.loading_anim), null, null, false, false);
|
||||
synchronized (progressDialog) {
|
||||
if (!loaded) {
|
||||
progressDialog.setOwnerActivity(this);
|
||||
CustomDialogFactory.show(progressDialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
setup.setOnResourcesLoadedListener(this);
|
||||
|
||||
|
||||
final ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
|
||||
iv.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
float[] point = new float[]{0f,0.25f * iv.getDrawable().getIntrinsicHeight()};
|
||||
iv.getImageMatrix().mapPoints(point);
|
||||
int imgY = (int) (iv.getTop() + point[1]);
|
||||
|
||||
if (clouds_back != null) {
|
||||
clouds_back.setYMax(imgY);
|
||||
}
|
||||
if (clouds_mid != null) {
|
||||
clouds_mid.setYMax(imgY);
|
||||
}
|
||||
if (clouds_front != null) {
|
||||
clouds_front.setYMax(imgY);
|
||||
}
|
||||
iv.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (clouds_back != null)clouds_back.resumeAnimation();
|
||||
if (clouds_mid != null)clouds_mid.resumeAnimation();
|
||||
if (clouds_front != null)clouds_front.resumeAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
setup.setOnResourcesLoadedListener(null);
|
||||
setup.removeOnSceneLoadedListener(this);
|
||||
if (clouds_back != null)clouds_back.pauseAnimation();
|
||||
if (clouds_mid != null)clouds_mid.pauseAnimation();
|
||||
if (clouds_front != null)clouds_front.pauseAnimation();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResourcesLoaded() {
|
||||
loaded = false;
|
||||
setup.startCharacterSetup(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSceneLoaded() {
|
||||
synchronized (progressDialog) {
|
||||
if (progressDialog != null) progressDialog.dismiss();
|
||||
loaded =true;
|
||||
}
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
this.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSceneLoadFailed(Savegames.LoadSavegameResult loadResult) {
|
||||
synchronized (progressDialog) {
|
||||
if (progressDialog != null) progressDialog.dismiss();
|
||||
loaded =true;
|
||||
}
|
||||
if (loadResult == Savegames.LoadSavegameResult.savegameIsFromAFutureVersion) {
|
||||
showLoadingFailedDialog(R.string.dialog_loading_failed_incorrectversion);
|
||||
} else {
|
||||
showLoadingFailedDialog(R.string.dialog_loading_failed_message);
|
||||
}
|
||||
}
|
||||
|
||||
private void showLoadingFailedDialog(int messageResourceID) {
|
||||
final Dialog d = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_failed_title), null, getResources().getString(messageResourceID), null, true);
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
|
||||
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
LoadingActivity.this.finish();
|
||||
}
|
||||
});
|
||||
CustomDialogFactory.show(d);
|
||||
|
||||
}
|
||||
}
|
||||
package com.gpl.rpg.AndorsTrail.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.WorldSetup;
|
||||
import com.gpl.rpg.AndorsTrail.WorldSetup.OnResourcesLoadedListener;
|
||||
import com.gpl.rpg.AndorsTrail.WorldSetup.OnSceneLoadedListener;
|
||||
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
|
||||
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
|
||||
import com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
|
||||
|
||||
public final class LoadingActivity extends Activity implements OnResourcesLoadedListener, OnSceneLoadedListener {
|
||||
|
||||
private WorldSetup setup;
|
||||
private Dialog progressDialog;
|
||||
private CloudsAnimatorView clouds_back, clouds_mid, clouds_front;
|
||||
boolean loaded = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(ThemeHelper.getBaseTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
app.setWindowParameters(this);
|
||||
setContentView(R.layout.startscreen);
|
||||
|
||||
TextView tv = (TextView) findViewById(R.id.startscreen_version);
|
||||
tv.setVisibility(View.GONE);
|
||||
|
||||
clouds_back = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_back);
|
||||
if (clouds_back != null) clouds_back.setCloudsCountAndLayer(40, CloudsAnimatorView.Layer.below);
|
||||
clouds_mid = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_mid);
|
||||
if (clouds_mid != null) clouds_mid.setCloudsCountAndLayer(15, CloudsAnimatorView.Layer.center);
|
||||
clouds_front = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_front);
|
||||
if (clouds_front != null) clouds_front.setCloudsCountAndLayer(8, CloudsAnimatorView.Layer.above);
|
||||
|
||||
this.setup = app.getWorldSetup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus) {
|
||||
((AnimationDrawable)((ImageView)findViewById(R.id.title_logo)).getDrawable()).start();
|
||||
ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
|
||||
int ivWidth = iv.getWidth();
|
||||
int drawableWidth = iv.getDrawable().getIntrinsicWidth();
|
||||
float ratio = ((float)ivWidth) / ((float)drawableWidth);
|
||||
|
||||
if (clouds_back != null) {
|
||||
clouds_back.setScalingRatio(ratio);
|
||||
}
|
||||
if (clouds_mid != null) {
|
||||
clouds_mid.setScalingRatio(ratio);
|
||||
}
|
||||
if (clouds_front != null) {
|
||||
clouds_front.setScalingRatio(ratio);
|
||||
}
|
||||
|
||||
if (progressDialog == null) {
|
||||
progressDialog = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_message),
|
||||
getResources().getDrawable(R.drawable.loading_anim), null, null, false, false);
|
||||
synchronized (progressDialog) {
|
||||
if (!loaded) {
|
||||
progressDialog.setOwnerActivity(this);
|
||||
CustomDialogFactory.show(progressDialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
setup.setOnResourcesLoadedListener(this);
|
||||
|
||||
|
||||
final ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
|
||||
iv.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
float[] point = new float[]{0f,0.25f * iv.getDrawable().getIntrinsicHeight()};
|
||||
iv.getImageMatrix().mapPoints(point);
|
||||
int imgY = (int) (iv.getTop() + point[1]);
|
||||
|
||||
if (clouds_back != null) {
|
||||
clouds_back.setYMax(imgY);
|
||||
}
|
||||
if (clouds_mid != null) {
|
||||
clouds_mid.setYMax(imgY);
|
||||
}
|
||||
if (clouds_front != null) {
|
||||
clouds_front.setYMax(imgY);
|
||||
}
|
||||
iv.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (clouds_back != null)clouds_back.resumeAnimation();
|
||||
if (clouds_mid != null)clouds_mid.resumeAnimation();
|
||||
if (clouds_front != null)clouds_front.resumeAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
setup.setOnResourcesLoadedListener(null);
|
||||
setup.removeOnSceneLoadedListener(this);
|
||||
if (clouds_back != null)clouds_back.pauseAnimation();
|
||||
if (clouds_mid != null)clouds_mid.pauseAnimation();
|
||||
if (clouds_front != null)clouds_front.pauseAnimation();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResourcesLoaded() {
|
||||
loaded = false;
|
||||
setup.startCharacterSetup(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSceneLoaded() {
|
||||
if (progressDialog != null) {
|
||||
synchronized (progressDialog) {
|
||||
if (progressDialog != null) progressDialog.dismiss();
|
||||
loaded =true;
|
||||
}
|
||||
}
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
this.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSceneLoadFailed(Savegames.LoadSavegameResult loadResult) {
|
||||
synchronized (progressDialog) {
|
||||
if (progressDialog != null) progressDialog.dismiss();
|
||||
loaded =true;
|
||||
}
|
||||
if (loadResult == Savegames.LoadSavegameResult.savegameIsFromAFutureVersion) {
|
||||
showLoadingFailedDialog(R.string.dialog_loading_failed_incorrectversion);
|
||||
} else {
|
||||
showLoadingFailedDialog(R.string.dialog_loading_failed_message);
|
||||
}
|
||||
}
|
||||
|
||||
private void showLoadingFailedDialog(int messageResourceID) {
|
||||
final Dialog d = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_failed_title), null, getResources().getString(messageResourceID), null, true);
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
|
||||
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
LoadingActivity.this.finish();
|
||||
}
|
||||
});
|
||||
CustomDialogFactory.show(d);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user