From aeb74635f90e3403a6b6cc995301d3d094d67f4e Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 23 Apr 2015 14:21:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20ViewActivity=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=91=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D1=83=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../everlastingsummer/ViewActivity.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/com/annimon/everlastingsummer/ViewActivity.java b/src/com/annimon/everlastingsummer/ViewActivity.java index 44b8d64..f790b93 100644 --- a/src/com/annimon/everlastingsummer/ViewActivity.java +++ b/src/com/annimon/everlastingsummer/ViewActivity.java @@ -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);