Update
This commit is contained in:
1 parent
0804bfc88d
commit
9817a3c74d
9 files changed
+154
-14
No files matched your search
@@ -16,6 +16,7 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -24,6 +25,7 @@ import com.hippo.scene.StageActivity;
|
||||
|
||||
public class ContentActivity extends StageActivity {
|
||||
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private FrameLayout mStage;
|
||||
|
||||
@Override
|
||||
@@ -31,7 +33,9 @@ public class ContentActivity extends StageActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_content);
|
||||
|
||||
mStage = (FrameLayout) findViewById(R.id.stage);
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
|
||||
mStage = (FrameLayout) mDrawerLayout.findViewById(R.id.stage);
|
||||
|
||||
|
||||
startFirstScene(GalleryListScene.class);
|
||||
}
|
||||
|
||||
@@ -106,4 +106,8 @@ public abstract class Scene {
|
||||
mStageActivity.stopSceneRetain(this);
|
||||
}
|
||||
|
||||
public void onBackPressed() {
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -133,9 +133,11 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
|
||||
void finishScene(Scene scene) {
|
||||
if (scene != mRetainedScene && scene != mCurrentScene) {
|
||||
// Remove with out animation
|
||||
getStageView().removeView(scene.getRootView());
|
||||
mSceneStack.remove(scene);
|
||||
if (mSceneStack.contains(scene)) {
|
||||
// Remove without animation
|
||||
getStageView().removeView(scene.getRootView());
|
||||
mSceneStack.remove(scene);
|
||||
}
|
||||
} else {
|
||||
if (mRetainedScene == null) {
|
||||
// Because scene can't be null, so scene == mCurrentScene
|
||||
@@ -149,10 +151,8 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mRetainedScene == null) {
|
||||
// No retained scene, no animation
|
||||
// If not, just miss it.
|
||||
popScense();
|
||||
if (mCurrentScene != null) {
|
||||
mCurrentScene.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,7 @@ import com.hippo.util.ViewUtils;
|
||||
|
||||
/**
|
||||
* aspect is width / height
|
||||
*
|
||||
* @author Hippo
|
||||
*
|
||||
*/
|
||||
|
||||
public class FixedAspectImageView extends ImageView {
|
||||
|
||||
private static final String TAG = FixedAspectImageView.class.getSimpleName();
|
||||
@@ -69,7 +65,7 @@ public class FixedAspectImageView extends ImageView {
|
||||
|
||||
a = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.FixedAspectImageView, defStyle, 0);
|
||||
setAspect(a.getFloat(R.styleable.FixedAspectImageView_aspect, -1f));
|
||||
setAspect(a.getFloat(R.styleable.FixedAspectImageView_faiAspect, -1f));
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
/**
|
||||
* aspect is width / height
|
||||
*/
|
||||
public class FixedAspectLayout extends FrameLayout {
|
||||
|
||||
private float mAspect = -1f;
|
||||
|
||||
public FixedAspectLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public FixedAspectLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0, 0);
|
||||
}
|
||||
|
||||
public FixedAspectLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public FixedAspectLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
TypedArray a = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.FixedAspectLayout, defStyleAttr, defStyleRes);
|
||||
setAspect(a.getFloat(R.styleable.FixedAspectLayout_falAspect, -1f));
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setAspect(float ratio) {
|
||||
if (ratio > 0) {
|
||||
mAspect = ratio;
|
||||
} else {
|
||||
mAspect = -1f;
|
||||
}
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
if (mAspect > 0.0f) {
|
||||
final int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
final int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int width;
|
||||
int height;
|
||||
if (widthSpecMode == MeasureSpec.EXACTLY && heightSpecMode != MeasureSpec.EXACTLY) {
|
||||
width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int maxheight;
|
||||
if (heightSpecMode == MeasureSpec.AT_MOST) {
|
||||
maxheight = MeasureSpec.getSize(heightMeasureSpec);
|
||||
} else {
|
||||
maxheight = Integer.MAX_VALUE;
|
||||
}
|
||||
height = Math.min((int) (width / mAspect), maxheight);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
||||
} else if (heightSpecMode == MeasureSpec.EXACTLY && widthSpecMode != MeasureSpec.EXACTLY) {
|
||||
height = MeasureSpec.getSize(heightMeasureSpec);
|
||||
int maxWidth;
|
||||
if (widthSpecMode == MeasureSpec.AT_MOST) {
|
||||
maxWidth = MeasureSpec.getSize(widthSpecMode);
|
||||
} else {
|
||||
maxWidth = Integer.MAX_VALUE;
|
||||
}
|
||||
width = Math.min((int) (height * mAspect), maxWidth);
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
|
||||
}
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user