Update
This commit is contained in:
1 parent
00dbd94c84
commit
10ca8b352c
12 files changed
+191
-147
No files matched your search
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.effect;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.animation.SimpleAnimatorListener;
|
||||
import com.hippo.util.ViewUtils;
|
||||
|
||||
public class ViewTransition {
|
||||
|
||||
private static long ANIMATE_TIME = 300L;
|
||||
|
||||
private View mView1;
|
||||
private View mView2;
|
||||
private boolean mSwitch = false;
|
||||
|
||||
public ViewTransition(@NonNull View view1, @NonNull View view2) {
|
||||
mView1 = view1;
|
||||
mView2 = view2;
|
||||
|
||||
ViewUtils.setVisibility(view1, View.VISIBLE);
|
||||
ViewUtils.setVisibility(view2, View.GONE);
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
if (mSwitch) {
|
||||
showFirstView();
|
||||
} else {
|
||||
showSecondView();
|
||||
}
|
||||
}
|
||||
|
||||
public void showFirstView() {
|
||||
if (mSwitch) {
|
||||
mSwitch = false;
|
||||
|
||||
ObjectAnimator oa1 = ObjectAnimator.ofFloat(mView1, "alpha", 0f, 1f);
|
||||
oa1.setDuration(ANIMATE_TIME);
|
||||
oa1.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
ViewUtils.setVisibility(mView1, View.VISIBLE);
|
||||
}
|
||||
});
|
||||
ObjectAnimator oa2 = ObjectAnimator.ofFloat(mView2, "alpha", 1f, 0f);
|
||||
oa2.setDuration(ANIMATE_TIME);
|
||||
oa2.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
ViewUtils.setVisibility(mView2, View.GONE);
|
||||
}
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
oa1.setAutoCancel(true);
|
||||
oa2.setAutoCancel(true);
|
||||
}
|
||||
oa1.start();
|
||||
oa2.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void showSecondView() {
|
||||
if (!mSwitch) {
|
||||
mSwitch = true;
|
||||
|
||||
ObjectAnimator oa1 = ObjectAnimator.ofFloat(mView1, "alpha", 1f, 0f);
|
||||
oa1.setDuration(ANIMATE_TIME);
|
||||
oa1.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
ViewUtils.setVisibility(mView1, View.GONE);
|
||||
}
|
||||
});
|
||||
ObjectAnimator oa2 = ObjectAnimator.ofFloat(mView2, "alpha", 0f, 1f);
|
||||
oa2.setDuration(ANIMATE_TIME);
|
||||
oa2.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
ViewUtils.setVisibility(mView2, View.VISIBLE);
|
||||
}
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
oa1.setAutoCancel(true);
|
||||
oa2.setAutoCancel(true);
|
||||
}
|
||||
oa1.start();
|
||||
oa2.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,23 @@ package com.hippo.ehviewer.ui.scene;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.hippo.effect.ViewTransition;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
import com.hippo.ehviewer.widget.ContentLayout;
|
||||
import com.hippo.ehviewer.widget.SearchBar;
|
||||
import com.hippo.ehviewer.widget.SearchDatabase;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.TransitionCurtain;
|
||||
import com.hippo.util.Log;
|
||||
import com.hippo.util.ViewUtils;
|
||||
|
||||
public
|
||||
class GalleryListScene extends Scene implements SearchBar.Helper{
|
||||
class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
||||
private final static int PAGE_INDEX_SEARCH = 0;
|
||||
private final static int PAGE_INDEX_LIST = 1;
|
||||
@@ -42,6 +46,9 @@ class GalleryListScene extends Scene implements SearchBar.Helper{
|
||||
|
||||
private SearchBar mSearchBar;
|
||||
private ContentLayout mContentLayout;
|
||||
private SearchLayout mSearchLayout;
|
||||
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -54,26 +61,22 @@ class GalleryListScene extends Scene implements SearchBar.Helper{
|
||||
|
||||
mSearchBar = (SearchBar) findViewById(R.id.search_bar);
|
||||
mContentLayout = (ContentLayout) findViewById(R.id.content_layout);
|
||||
mSearchLayout = (SearchLayout) findViewById(R.id.search_layout);
|
||||
|
||||
mViewTransition = new ViewTransition(mContentLayout, mSearchLayout);
|
||||
|
||||
// Search Bar
|
||||
mSearchBar.setHelper(this);
|
||||
mContentLayout.showText("无法连接网络");
|
||||
ViewUtils.measureView(mSearchBar, ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
View view = getSceneView();
|
||||
assert view != null;
|
||||
view.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Search Layout
|
||||
mSearchLayout.setFitPaddingTop(mSearchBar.getMeasuredHeight() +
|
||||
(int) (2 * mResources.getDimension(R.dimen.search_bar_padding_vertical)));
|
||||
|
||||
TransitionCurtain tc = new TransitionCurtain(
|
||||
new TransitionCurtain.ViewPair[]{
|
||||
new TransitionCurtain.ViewPair(R.id.haha, R.id.haha),
|
||||
new TransitionCurtain.ViewPair(R.id.bbbbbb, R.id.bbbbbb)
|
||||
}
|
||||
);
|
||||
|
||||
startScene(TestScene.class, null, tc);
|
||||
}
|
||||
}, 1000);
|
||||
// TEST
|
||||
mContentLayout.showText("四姑拉斯基");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,6 +84,11 @@ class GalleryListScene extends Scene implements SearchBar.Helper{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickMenu() {
|
||||
mActivity.toggleDrawer();
|
||||
@@ -88,7 +96,7 @@ class GalleryListScene extends Scene implements SearchBar.Helper{
|
||||
|
||||
@Override
|
||||
public void onClickAction() {
|
||||
Log.d("onClickAction");
|
||||
mViewTransition.showSecondView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,6 @@ import android.widget.TextView;
|
||||
import com.hippo.effect.ripple.RippleSalon;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.util.UiUtils;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.FloatLabelEditText;
|
||||
import com.hippo.widget.FloatingActionButton;
|
||||
@@ -111,6 +110,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
private Bitmap mSearchImage;
|
||||
|
||||
private int mFabMarginBottomOrigin;
|
||||
private int mSearchPaddingTopOrigin;
|
||||
private int mSearchPaddingBottomOrigin;
|
||||
|
||||
public SearchLayout(Context context) {
|
||||
@@ -147,21 +147,30 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
|
||||
mFab.setOnClickListener(this);
|
||||
mFabMarginBottomOrigin = mResources.getDimensionPixelSize(R.dimen.content_fab_margin_bottom);
|
||||
mSearchPaddingTopOrigin = 0;
|
||||
mSearchPaddingBottomOrigin = mResources.getDimensionPixelSize(R.dimen.content_padding_bottom);
|
||||
}
|
||||
|
||||
public void setFitPaddingTop(int fitPaddingTop) {
|
||||
mSearchContainer.setPadding(
|
||||
mSearchContainer.getPaddingLeft(),
|
||||
mSearchPaddingTopOrigin + fitPaddingTop,
|
||||
mSearchContainer.getPaddingRight(),
|
||||
mSearchContainer.getPaddingBottom()
|
||||
);
|
||||
}
|
||||
|
||||
public void setFitPaddingBottom(int paddingBottom) {
|
||||
mSearchContainer.setPadding(
|
||||
mSearchContainer.getPaddingLeft(),
|
||||
mSearchContainer.getPaddingTop(),
|
||||
mSearchContainer.getPaddingRight(),
|
||||
mSearchPaddingBottomOrigin + paddingBottom);
|
||||
mSearchPaddingBottomOrigin + paddingBottom
|
||||
);
|
||||
|
||||
if (!UiUtils.isTable(mContext)) {
|
||||
LayoutParams lp = (LayoutParams) mFab.getLayoutParams();
|
||||
lp.bottomMargin = mFabMarginBottomOrigin + paddingBottom;
|
||||
mFab.setLayoutParams(lp);
|
||||
}
|
||||
LayoutParams lp = (LayoutParams) mFab.getLayoutParams();
|
||||
lp.bottomMargin = mFabMarginBottomOrigin + paddingBottom;
|
||||
mFab.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
public void setHelper(SearhLayoutHelper helper) {
|
||||
|
||||
@@ -166,6 +166,13 @@ public abstract class Scene {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if it is close or about to close
|
||||
*/
|
||||
public boolean isFinishing() {
|
||||
return mState == SCENE_STATE_CLOSE || mState == SCENE_STATE_DESTROY;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(int bgColor) {
|
||||
if (mBackgroundColor != bgColor) {
|
||||
mBackgroundColor = bgColor;
|
||||
|
||||
@@ -32,8 +32,6 @@ class SceneManager {
|
||||
|
||||
private Scene mLegacyScene;
|
||||
|
||||
private int[] mTemp = new int[2];
|
||||
|
||||
// Should only be called by SceneApplication
|
||||
SceneManager() {
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user