Возможность инициализации ViewActivity по сохранённому состоянию
This commit is contained in:
parent
a8bb640f91
commit
aeb74635f9
@ -1,11 +1,13 @@
|
||||
package com.annimon.everlastingsummer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.annimon.everlastingsummer.TouchGesture.TouchGestureType;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.media.MediaPlayer;
|
||||
@ -30,6 +32,8 @@ import android.widget.Toast;
|
||||
public final class ViewActivity extends Activity implements TouchGesture.OnTouchGestureListener {
|
||||
|
||||
public static final String EXTRA_NAME = "name";
|
||||
public static final String EXTRA_SAVE = "save";
|
||||
|
||||
private static final FadeInfo NO_FADE = new FadeInfo(false, false, 0);
|
||||
private static ViewActivity instance;
|
||||
|
||||
@ -37,6 +41,8 @@ public final class ViewActivity extends Activity implements TouchGesture.OnTouch
|
||||
return instance;
|
||||
}
|
||||
|
||||
private String scriptPath;
|
||||
|
||||
private ImageView background;
|
||||
private FrameLayout container;
|
||||
private TextView textview;
|
||||
@ -72,17 +78,17 @@ public final class ViewActivity extends Activity implements TouchGesture.OnTouch
|
||||
characters = new CharactersES();
|
||||
characters.makeNamesKnown();
|
||||
|
||||
String scriptpath = "";
|
||||
final Intent intent = getIntent();
|
||||
final SaveInfo save = intent.getParcelableExtra(EXTRA_SAVE);
|
||||
try {
|
||||
InputStream stream = null;
|
||||
if (intent.hasExtra(EXTRA_NAME)) {
|
||||
scriptpath = PathResolver.script( intent.getStringExtra(EXTRA_NAME) );
|
||||
stream = getAssets().open(scriptpath);
|
||||
if (save != null) {
|
||||
stream = fromSave(save);
|
||||
Toast.makeText(this, "Загружено", Toast.LENGTH_SHORT).show();
|
||||
} else if (intent.hasExtra(EXTRA_NAME)) {
|
||||
stream = fromAssets( PathResolver.script(intent.getStringExtra(EXTRA_NAME)) );
|
||||
} else if (intent.getData() != null) {
|
||||
final Uri fileUri = intent.getData();
|
||||
scriptpath = fileUri.getPath();
|
||||
stream = getContentResolver().openInputStream(fileUri);
|
||||
stream = fromFile(intent.getData());
|
||||
} else {
|
||||
Toast.makeText(this, "Нет данных для отображения", Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
@ -92,13 +98,30 @@ public final class ViewActivity extends Activity implements TouchGesture.OnTouch
|
||||
Parser.getInstance().next();
|
||||
stream = null;
|
||||
} catch (Exception ex) {
|
||||
final String message = "Ошибка при открытии файла " + scriptpath;
|
||||
final String message = "Ошибка при открытии файла " + scriptPath;
|
||||
if (Logger.DEBUG) Logger.log(message, ex);
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream fromAssets(String path) throws IOException {
|
||||
scriptPath = path;
|
||||
return getAssets().open(scriptPath);
|
||||
}
|
||||
|
||||
private InputStream fromFile(Uri fileUri) throws IOException {
|
||||
scriptPath = fileUri.toString();
|
||||
return getContentResolver().openInputStream(fileUri);
|
||||
}
|
||||
|
||||
private InputStream fromSave(SaveInfo save) throws IOException {
|
||||
if (save.getPath().startsWith(ContentResolver.SCHEME_FILE)) {
|
||||
return fromFile(Uri.parse(save.getPath()));
|
||||
}
|
||||
return fromAssets(save.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
stopMusic(NO_FADE);
|
||||
|
Loading…
Reference in New Issue
Block a user