Update scene
This commit is contained in:
1 parent
a74fb52c9a
commit
b9f0a6c70c
14 files changed
+199
-58
No files matched your search
@@ -16,14 +16,11 @@
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import com.hippo.scene.SceneApplication;
|
||||
import com.hippo.util.UiUtils;
|
||||
|
||||
public class EhApplication extends SceneApplication {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
UiUtils.init(this);
|
||||
}
|
||||
}
|
||||
@@ -182,8 +182,7 @@ public abstract class Scene {
|
||||
StageActivity sa = getStageActivity();
|
||||
mSceneView = new FrameLayout(sa);
|
||||
initBackground(mSceneView);
|
||||
mSceneView.addView(view, new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
mSceneView.addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
||||
private void initBackground(@NonNull View bg) {
|
||||
@@ -212,6 +211,10 @@ public abstract class Scene {
|
||||
protected void onOut() {
|
||||
}
|
||||
|
||||
public View onCreateStageBar() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a view that was identified by the id attribute from the XML that
|
||||
* was processed in {@link #onCreate}.
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.scene;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.util.Log;
|
||||
|
||||
@@ -136,6 +137,10 @@ class SceneManager {
|
||||
scene.setState(Scene.SCENE_STATE_DESTROY);
|
||||
scene.detachFromeStage();
|
||||
}
|
||||
|
||||
// Switch stage bar
|
||||
View stageBarContent = scene.onCreateStageBar();
|
||||
getStageActivity().getStageBar().updateContent(stageBarContent);
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "The scene is not in stage");
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.ui.AbsActionBarActivity;
|
||||
import com.hippo.util.IntIdGenerator;
|
||||
import com.hippo.widget.StageBar;
|
||||
|
||||
public abstract class StageActivity extends AbsActionBarActivity {
|
||||
|
||||
@@ -39,6 +40,8 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
|
||||
public abstract @NonNull StageLayout getStageLayout();
|
||||
|
||||
public abstract @NonNull StageBar getStageBar();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -60,16 +63,6 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void attachSceneToStageAsPreScene(Scene scene) {
|
||||
StageLayout stageLayout = getStageLayout();
|
||||
View sceneView = scene.getSceneView();
|
||||
if (sceneView != null) {
|
||||
stageLayout.addView(sceneView, stageLayout.getChildCount() - 1);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void detachSceneFromStage(Scene scene) {
|
||||
View sceneView = scene.getSceneView();
|
||||
if (sceneView != null) {
|
||||
|
||||
@@ -163,7 +163,6 @@ public class TransitionCurtain extends Curtain {
|
||||
|
||||
mAnimList.add(colorAnim);
|
||||
|
||||
|
||||
// Handle transit part
|
||||
for (ViewPair pair : mViewPairArray) {
|
||||
final View enterView = pair.getFromView(enter);
|
||||
@@ -177,8 +176,6 @@ public class TransitionCurtain extends Curtain {
|
||||
continue;
|
||||
}
|
||||
|
||||
//int[] startloaction = new int[2];
|
||||
//ViewUtils.getLocationInAncestor(exitView, startloaction, exit.getSceneView());
|
||||
int[] endloaction = new int[2];
|
||||
ViewUtils.getLocationInAncestor(enterView, endloaction, enter.getSceneView());
|
||||
int startWidth = exitView.getWidth();
|
||||
|
||||
@@ -16,46 +16,32 @@
|
||||
package com.hippo.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class UiUtils {
|
||||
|
||||
private static float sDensity;
|
||||
private static float sScaledDensity;
|
||||
|
||||
/**
|
||||
* Init UiUtils. Do is in Application.onCreate()
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static void init(Context context) {
|
||||
Resources resources = context.getResources();
|
||||
|
||||
sDensity = resources.getDisplayMetrics().density;
|
||||
sScaledDensity = resources.getDisplayMetrics().scaledDensity;
|
||||
}
|
||||
|
||||
/**
|
||||
* dp conversion to pix
|
||||
*
|
||||
* @param context The context
|
||||
* @param dp The value you want to conversion
|
||||
* @return value in pix
|
||||
*/
|
||||
public static int dp2pix(float dp) {
|
||||
return (int) (sDensity * dp + 0.5f);
|
||||
public static int dp2pix(Context context, float dp) {
|
||||
return (int) (dp * context.getResources().getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* pix conversion to dp
|
||||
*
|
||||
* @param context The context
|
||||
* @param pix The value you want to conversion
|
||||
* @return value in dp
|
||||
*/
|
||||
public static float pix2dp(int pix) {
|
||||
return pix / sDensity;
|
||||
public static float pix2dp(Context context, int pix) {
|
||||
return pix / context.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,8 +50,8 @@ public class UiUtils {
|
||||
* @param sp The value you want to conversion
|
||||
* @return value in pix
|
||||
*/
|
||||
public static int sp2pix(float sp) {
|
||||
return (int) (sp * sScaledDensity + 0.5f);
|
||||
public static int sp2pix(Context context, float sp) {
|
||||
return (int) (sp * context.getResources().getDisplayMetrics().scaledDensity + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,8 +60,8 @@ public class UiUtils {
|
||||
* @param pix The value you want to conversion
|
||||
* @return value in sp
|
||||
*/
|
||||
public static float pix2sp(float pix) {
|
||||
return pix / sScaledDensity;
|
||||
public static float pix2sp(Context context, float pix) {
|
||||
return pix / context.getResources().getDisplayMetrics().scaledDensity;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,11 +35,11 @@ import com.hippo.util.ViewUtils;
|
||||
|
||||
public class FloatingActionButton extends View {
|
||||
|
||||
private static final int DRAWABLE_WIDTH = UiUtils.dp2pix(24);
|
||||
|
||||
private GasketDrawer mGasketDrawer;
|
||||
private Drawable mDrawable;
|
||||
|
||||
private int mDrawableWidth;
|
||||
|
||||
public FloatingActionButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0, 0);
|
||||
@@ -57,6 +57,8 @@ public class FloatingActionButton extends View {
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
mDrawableWidth = UiUtils.dp2pix(context, 24);
|
||||
|
||||
TypedArray a;
|
||||
|
||||
a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, defStyleRes);
|
||||
@@ -95,11 +97,11 @@ public class FloatingActionButton extends View {
|
||||
int bottom;
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int halfDrawableWidth = DRAWABLE_WIDTH / 2;
|
||||
int halfDrawableWidth = mDrawableWidth / 2;
|
||||
left = width / 2 - halfDrawableWidth;
|
||||
top = height / 2 - halfDrawableWidth;
|
||||
right = left + DRAWABLE_WIDTH;
|
||||
bottom = top + DRAWABLE_WIDTH;
|
||||
right = left + mDrawableWidth;
|
||||
bottom = top + mDrawableWidth;
|
||||
mDrawable.setBounds(left, top, right, bottom);
|
||||
mDrawable.draw(canvas);
|
||||
}
|
||||
@@ -125,9 +127,6 @@ public class FloatingActionButton extends View {
|
||||
|
||||
static class GasketDrawerOld implements GasketDrawer {
|
||||
|
||||
private static final int SHADOW_RADIOUS = UiUtils.dp2pix(3);
|
||||
private static final int SHADOW_OFFSET_Y = UiUtils.dp2pix(1);
|
||||
private static final int GASKET_PADDING = SHADOW_RADIOUS + SHADOW_OFFSET_Y; // 4dp
|
||||
private static final int SHADOW_COLOR = 0x43000000;
|
||||
|
||||
private View mView;
|
||||
@@ -140,7 +139,17 @@ public class FloatingActionButton extends View {
|
||||
|
||||
private boolean mIsDark;
|
||||
|
||||
private final int mShadowRadious;
|
||||
private final int mShadowOffsetY;
|
||||
private final int mGasketPadding;
|
||||
|
||||
private GasketDrawerOld(View view, int color) {
|
||||
Context context = view.getContext();
|
||||
|
||||
mShadowRadious = UiUtils.dp2pix(context, 3);
|
||||
mShadowOffsetY = UiUtils.dp2pix(context, 1);
|
||||
mGasketPadding = mShadowRadious + mShadowOffsetY;
|
||||
|
||||
mView = view;
|
||||
mBounds = new RectF();
|
||||
mColor = color;
|
||||
@@ -149,7 +158,7 @@ public class FloatingActionButton extends View {
|
||||
mPaint.setColor(mColor);
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
mPaint.setShadowLayer(SHADOW_RADIOUS, 0, SHADOW_OFFSET_Y, SHADOW_COLOR);
|
||||
mPaint.setShadowLayer(mShadowRadious, 0, mShadowOffsetY, SHADOW_COLOR);
|
||||
ViewUtils.removeHardwareAccelerationSupport(mView);
|
||||
}
|
||||
|
||||
@@ -190,10 +199,10 @@ public class FloatingActionButton extends View {
|
||||
}
|
||||
|
||||
public void draw(Canvas canvas) {
|
||||
mBounds.left = GASKET_PADDING;
|
||||
mBounds.top = GASKET_PADDING;
|
||||
mBounds.right = mView.getWidth() - GASKET_PADDING;
|
||||
mBounds.bottom = mView.getHeight() - GASKET_PADDING;
|
||||
mBounds.left = mGasketPadding;
|
||||
mBounds.top = mGasketPadding;
|
||||
mBounds.right = mView.getWidth() - mGasketPadding;
|
||||
mBounds.bottom = mView.getHeight() - mGasketPadding;
|
||||
canvas.drawOval(mBounds, mPaint);
|
||||
}
|
||||
|
||||
@@ -206,8 +215,6 @@ public class FloatingActionButton extends View {
|
||||
|
||||
static class GasketDrawerLollipop implements GasketDrawer {
|
||||
|
||||
private static final int ELEVATION = UiUtils.dp2pix(4);
|
||||
|
||||
private static final int[][] STATES = new int[][]{
|
||||
new int[]{-android.R.attr.state_enabled},
|
||||
new int[]{android.R.attr.state_pressed},
|
||||
@@ -220,8 +227,12 @@ public class FloatingActionButton extends View {
|
||||
|
||||
private GradientDrawable mGradientDrawable;
|
||||
|
||||
private final int mElevation;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public GasketDrawerLollipop(View view, int color) {
|
||||
mElevation = UiUtils.dp2pix(view.getContext(), 4);
|
||||
|
||||
mView = view;
|
||||
mColor = color;
|
||||
|
||||
@@ -232,7 +243,7 @@ public class FloatingActionButton extends View {
|
||||
new int[] {darkColor, darkColor, darkColor, color}));
|
||||
|
||||
mView.setBackground(mGradientDrawable);
|
||||
mView.setElevation(ELEVATION);
|
||||
mView.setElevation(mElevation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.content.Context;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.util.UiUtils;
|
||||
|
||||
/**
|
||||
* It is shown at the top of stage, just like actionbar
|
||||
*/
|
||||
public class StageBar extends CardView {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public StageBar(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public StageBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public StageBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mContext = context;
|
||||
setRadius(UiUtils.dp2pix(context, 2));
|
||||
}
|
||||
|
||||
public void updateContent(View view) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public void endAnimation() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public boolean hasContent() {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:auto="http://schemas.android.com/apk/res-auto"
|
||||
tools:targetApi="21"
|
||||
|
||||
auto:width="24dp"
|
||||
auto:height="24dp"
|
||||
auto:viewportWidth="24"
|
||||
auto:viewportHeight="24"
|
||||
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
auto:pathData="@string/pd_search"
|
||||
auto:fillColor="#8A000000"
|
||||
|
||||
android:pathData="@string/pd_search"
|
||||
android:fillColor="#8A000000"/>
|
||||
|
||||
</vector>
|
||||
@@ -26,6 +26,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"/>
|
||||
|
||||
<!-- Left Drawer -->
|
||||
<com.hippo.widget.DrawerFrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/stage_bar_height">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/vector_search"
|
||||
android:contentDescription="@string/search"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/vector_search"
|
||||
android:contentDescription="@string/search"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -49,5 +49,6 @@
|
||||
|
||||
|
||||
<string name="keyword">关键字</string>
|
||||
<string name="search">搜索</string>
|
||||
|
||||
</resources>
|
||||
@@ -15,6 +15,11 @@
|
||||
-->
|
||||
<resources>
|
||||
|
||||
|
||||
|
||||
<!-- Stage Bar -->
|
||||
<dimen name="stage_bar_height">56dp</dimen>
|
||||
|
||||
<!-- Search Content -->
|
||||
<dimen name="content_padding_start">0dp</dimen>
|
||||
<dimen name="content_padding_end">0dp</dimen>
|
||||
|
||||
@@ -67,5 +67,6 @@
|
||||
|
||||
|
||||
<string name="keyword">Keyword</string>
|
||||
<string name="search">Search</string>
|
||||
|
||||
</resources>
|
||||
Reference in new issue
Block a user