Improve scene
This commit is contained in:
1 parent
0f0079dea0
commit
2a7e905bac
12 files changed
+228
-12
No files matched your search
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene;
|
||||
import com.hippo.scene.StageActivity;
|
||||
|
||||
public class ContentActivity extends StageActivity {
|
||||
|
||||
private FrameLayout mStage;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_content);
|
||||
|
||||
mStage = (FrameLayout) findViewById(R.id.stage);
|
||||
|
||||
startFirstScene(GalleryListScene.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameLayout getStageView() {
|
||||
return mStage;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ImageView;
|
||||
@@ -50,7 +51,9 @@ public class StartActivity extends AbsActionBarActivity {
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO
|
||||
finish();
|
||||
Intent intent = new Intent(StartActivity.this, ContentActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.scene.Scene;
|
||||
|
||||
public class GalleryDetailScene extends Scene {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
setContentView(R.layout.scene_gallery_detail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
dispatchRemove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
dispatchRemove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.scene.Scene;
|
||||
|
||||
public class GalleryListScene extends Scene {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
setContentView(R.layout.scene_gallery_list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
dispatchRemove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
dispatchRemove();
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import com.hippo.util.AssertUtils;
|
||||
* {@link com.hippo.scene.Scene} is a {@code Activity} of {@link android.app.Activity}.
|
||||
* <p>
|
||||
* When start a new {@code Scene}, previous {@code Scene} can stay at screen for
|
||||
* a while.
|
||||
* a while. Or retain for a while before destroy.
|
||||
*/
|
||||
public abstract class Scene {
|
||||
|
||||
@@ -74,12 +74,14 @@ public abstract class Scene {
|
||||
mStageActivity.addSceneView(this);
|
||||
}
|
||||
|
||||
void pause() {
|
||||
onPause();
|
||||
}
|
||||
|
||||
void resume() {
|
||||
onResume();
|
||||
|
||||
mStageActivity.addSceneView(this);
|
||||
}
|
||||
|
||||
void pause() {
|
||||
onPause();
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
@@ -91,10 +93,10 @@ public abstract class Scene {
|
||||
*/
|
||||
public abstract void onCreate();
|
||||
|
||||
public abstract void onPause();
|
||||
|
||||
public abstract void onResume();
|
||||
|
||||
public abstract void onPause();
|
||||
|
||||
public abstract void onDestroy();
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,7 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
|
||||
Scene lastScene = mCurrentScene;
|
||||
mCurrentScene = scene;
|
||||
mCurrentScene.create();
|
||||
if (lastScene != null) {
|
||||
// It is not the first scense
|
||||
mSceneStack.push(lastScene);
|
||||
@@ -56,7 +57,6 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
mRetainedScene = lastScene;
|
||||
lastScene.pause();
|
||||
}
|
||||
mCurrentScene.create();
|
||||
}
|
||||
|
||||
private void popScense() {
|
||||
@@ -67,10 +67,10 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
} else {
|
||||
Scene previousScene = mCurrentScene;
|
||||
mCurrentScene = mSceneStack.pop();
|
||||
|
||||
mRetainedScene = previousScene;
|
||||
previousScene.destroy();
|
||||
|
||||
mCurrentScene.resume();
|
||||
previousScene.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,15 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
protected void startFirstScene(Class sceneClass) {
|
||||
if (mCurrentScene != null) {
|
||||
throw new IllegalStateException("Only call startFirstScene to start " +
|
||||
"first scene.");
|
||||
}
|
||||
|
||||
pushScene(sceneClass);
|
||||
}
|
||||
|
||||
void startScene(Scene fromScene, Class sceneClass) {
|
||||
if (mRetainedScene == null) {
|
||||
// No retained scene, no animation
|
||||
|
||||
Reference in new issue
Block a user