Add fab animate, fix screen rotate fit padding bottom zero
This commit is contained in:
1 parent
6eb8fe3c71
commit
3578477121
15 files changed
+127
-128
No files matched your search
@@ -79,6 +79,11 @@ public class AddDeleteDrawable extends Drawable {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
mPaint.setColor(color);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
mPaint.setAlpha(alpha);
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
||||
public abstract class AbsActionBarActivity extends ActionBarActivity {
|
||||
|
||||
public boolean post(Runnable action) {
|
||||
Window w = getWindow();
|
||||
if (w != null) {
|
||||
View v = w.getDecorView();
|
||||
return v != null && v.post(action);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean postDelayed(Runnable action, long delayMillis) {
|
||||
Window w = getWindow();
|
||||
if (w != null) {
|
||||
View v = w.getDecorView();
|
||||
return v != null && v.postDelayed(action, delayMillis);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -26,7 +27,7 @@ import com.larvalabs.svgandroid.SVG;
|
||||
import com.larvalabs.svgandroid.SVGBuilder;
|
||||
import com.larvalabs.svgandroid.SVGParseException;
|
||||
|
||||
public class StartActivity extends AbsActionBarActivity {
|
||||
public class StartActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = StartActivity.class.getSimpleName();
|
||||
|
||||
@@ -46,16 +47,8 @@ public class StartActivity extends AbsActionBarActivity {
|
||||
// Empty, I think this exception will never be caught.
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
// Only do this when first time
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finish();
|
||||
Intent intent = new Intent(StartActivity.this, ContentActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
finish();
|
||||
Intent intent = new Intent(StartActivity.this, ContentActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,23 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.PropertyValuesHolder;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.animation.FastOutLinearInInterpolator;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.hippo.animation.SimpleAnimatorListener;
|
||||
import com.hippo.drawable.AddDeleteDrawable;
|
||||
import com.hippo.effect.ViewTransition;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
@@ -37,9 +45,11 @@ import com.hippo.scene.Scene;
|
||||
import com.hippo.util.Log;
|
||||
import com.hippo.util.MathUtils;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.FloatingActionButton;
|
||||
|
||||
public
|
||||
class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
// TODO disable click action when animating
|
||||
public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
View.OnClickListener {
|
||||
|
||||
private static final long ANIMATE_TIME = 300l;
|
||||
|
||||
@@ -48,6 +58,11 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
private final static int STATE_SEARCH = 2;
|
||||
private final static int STATE_SEARCH_SHOW_LIST = 3;
|
||||
|
||||
private final static int FAB_STATE_NORMAL = 0;
|
||||
private final static int FAB_STATE_SEARCH = 1;
|
||||
|
||||
private final static Interpolator FAST_OUT_LINEAR_IN_INTERPOLATOR = new FastOutLinearInInterpolator();
|
||||
|
||||
private ContentActivity mActivity;
|
||||
private Resources mResources;
|
||||
private SearchDatabase mSearchDatabase;
|
||||
@@ -57,6 +72,7 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
private RecyclerView mContentRecyclerView;
|
||||
private SearchLayout mSearchLayout;
|
||||
private RecyclerView mSearchRecyclerView;
|
||||
private FloatingActionButton mCornerFab;
|
||||
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
@@ -64,8 +80,14 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
private int mSearchBarOriginalBottom;
|
||||
private ValueAnimator mSearchBarMoveAnimator;
|
||||
|
||||
private int mState = STATE_NORMAL;
|
||||
private int mCornerFabOriginalBottom;
|
||||
private AddDeleteDrawable mAddDeleteDrawable;
|
||||
private Drawable mSearchDrawable;
|
||||
|
||||
private int mState = STATE_NORMAL;
|
||||
private int mFabState = FAB_STATE_NORMAL;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -80,6 +102,7 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
mContentRecyclerView = mContentLayout.getRecyclerView();
|
||||
mSearchLayout = (SearchLayout) findViewById(R.id.search_layout);
|
||||
mSearchRecyclerView = mSearchLayout.getRecyclerView();
|
||||
mCornerFab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
|
||||
mViewTransition = new ViewTransition(mContentLayout, mSearchLayout);
|
||||
|
||||
@@ -95,18 +118,59 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
ViewUtils.removeOnGlobalLayoutListener(mSearchBar.getViewTreeObserver(), this);
|
||||
mSearchBarOriginalTop = mSearchBar.getTop();
|
||||
mSearchBarOriginalBottom = mSearchBar.getBottom();
|
||||
mSearchLayout.setFitPaddingTop(mSearchBar.getHeight() +
|
||||
mResources.getDimensionPixelOffset(R.dimen.search_bar_padding_vertical));
|
||||
mSearchLayout.setFitPaddingTop(mSearchBar.getHeight() + mResources.getDimensionPixelOffset(R.dimen.search_bar_padding_vertical));
|
||||
}
|
||||
});
|
||||
|
||||
// Corner Fab
|
||||
mCornerFab.setOnClickListener(this);
|
||||
mCornerFabOriginalBottom = mResources.getDimensionPixelOffset(R.dimen.corner_fab_padding_bottom);
|
||||
mAddDeleteDrawable = new AddDeleteDrawable(getStageActivity());
|
||||
mAddDeleteDrawable.setColor(mResources.getColor(R.color.primary_drawable_dark));
|
||||
mSearchDrawable = mResources.getDrawable(R.drawable.ic_search_dark);
|
||||
mCornerFab.setDrawable(mAddDeleteDrawable);
|
||||
|
||||
// TEST
|
||||
mContentLayout.showText("四姑拉斯基");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onGetFitPaddingBottom(int b) {
|
||||
// Search Layout
|
||||
mSearchLayout.setFitPaddingBottom(b);
|
||||
// Corner Fab
|
||||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mCornerFab.getLayoutParams();
|
||||
lp.bottomMargin = b + mCornerFabOriginalBottom;
|
||||
mCornerFab.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
private void setFabState(int fabState) {
|
||||
if (mFabState != fabState) {
|
||||
mFabState = fabState;
|
||||
Drawable drawable = null;
|
||||
if (mFabState == FAB_STATE_NORMAL) {
|
||||
drawable = mAddDeleteDrawable;
|
||||
} else if (mFabState == FAB_STATE_SEARCH) {
|
||||
drawable = mSearchDrawable;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
PropertyValuesHolder scaleXPvh = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f);
|
||||
PropertyValuesHolder scaleYPvh = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f);
|
||||
ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mCornerFab, scaleXPvh, scaleYPvh);
|
||||
oa.setDuration(ANIMATE_TIME / 2);
|
||||
oa.setInterpolator(FAST_OUT_LINEAR_IN_INTERPOLATOR);
|
||||
oa.setRepeatCount(1);
|
||||
oa.setRepeatMode(ValueAnimator.REVERSE);
|
||||
final Drawable finalDrawable = drawable;
|
||||
oa.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
mCornerFab.setDrawable(finalDrawable);
|
||||
}
|
||||
});
|
||||
oa.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,12 +183,14 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
mState = STATE_NORMAL;
|
||||
mSearchBar.setInNormalMode();
|
||||
returnSearchBarPosition();
|
||||
setFabState(FAB_STATE_NORMAL);
|
||||
break;
|
||||
case STATE_SEARCH:
|
||||
mState = STATE_NORMAL;
|
||||
mViewTransition.showFirstView();
|
||||
mSearchBar.setInNormalMode();
|
||||
returnSearchBarPosition();
|
||||
setFabState(FAB_STATE_NORMAL);
|
||||
break;
|
||||
case STATE_SEARCH_SHOW_LIST:
|
||||
mState = STATE_SEARCH;
|
||||
@@ -134,12 +200,24 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mCornerFab) {
|
||||
if (mFabState == FAB_STATE_NORMAL) {
|
||||
//
|
||||
} else if (mFabState == FAB_STATE_SEARCH) {
|
||||
onApplySearch(mSearchBar.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickTitle() {
|
||||
if (mState == STATE_NORMAL) {
|
||||
mState = STATE_SIMPLE_SEARCH;
|
||||
mSearchBar.setInEditMode(true);
|
||||
returnSearchBarPosition();
|
||||
setFabState(FAB_STATE_SEARCH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +239,7 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
mSearchLayout.scrollSearchContainerToTop();
|
||||
mSearchBar.setInEditMode(false);
|
||||
returnSearchBarPosition();
|
||||
setFabState(FAB_STATE_SEARCH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +254,7 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
|
||||
@Override
|
||||
public void onApplySearch(String query) {
|
||||
// TODO Query may be "", should not do search if it is
|
||||
Log.d("onApplySearch " + query);
|
||||
mSearchDatabase.addQuery(query);
|
||||
|
||||
@@ -182,6 +262,7 @@ class GalleryListScene extends Scene implements SearchBar.Helper {
|
||||
mViewTransition.showFirstView();
|
||||
mSearchBar.setInNormalMode();
|
||||
returnSearchBarPosition();
|
||||
setFabState(FAB_STATE_NORMAL);
|
||||
}
|
||||
|
||||
private RecyclerView getVaildRecyclerView() {
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.support.v7.widget.CardView;
|
||||
import android.text.Editable;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.AttributeSet;
|
||||
@@ -183,6 +182,10 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
mHelper = helper;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return mEditText.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mTitleTextView) {
|
||||
@@ -207,9 +210,7 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
if (v == mEditText) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_NULL) {
|
||||
String query = mEditText.getText().toString();
|
||||
if (!TextUtils.isEmpty(query)) {
|
||||
mHelper.onApplySearch(query);
|
||||
}
|
||||
mHelper.onApplySearch(query);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.scene.SimpleDialog;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.FloatLabelEditText;
|
||||
import com.hippo.widget.FloatingActionButton;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
|
||||
// TODO requst returnSearchBarPosition when content of recycler changed
|
||||
@@ -79,7 +78,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
private boolean mEnableAdvance = false;
|
||||
|
||||
private EasyRecyclerView mSearchContainer;
|
||||
private FloatingActionButton mFab;
|
||||
|
||||
private View mNormalView;
|
||||
private CategoryTable mTableCategory;
|
||||
@@ -111,7 +109,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
|
||||
private Bitmap mSearchImage;
|
||||
|
||||
private int mFabMarginBottomOrigin;
|
||||
private int mSearchPaddingTopOrigin;
|
||||
private int mSearchPaddingBottomOrigin;
|
||||
|
||||
@@ -137,7 +134,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
LayoutInflater.from(context).inflate(R.layout.widget_search_layout, this);
|
||||
|
||||
mSearchContainer = (EasyRecyclerView) getChildAt(0);
|
||||
mFab = (FloatingActionButton) getChildAt(1);
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(mContext);
|
||||
mAdapter = new SearchAdapter();
|
||||
@@ -147,11 +143,9 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
mSearchContainer.setHasFixedSize(true);
|
||||
mSearchContainer.setItemAnimator(mAnimator);
|
||||
|
||||
mFab.setOnClickListener(this);
|
||||
mFabMarginBottomOrigin = mResources.getDimensionPixelSize(R.dimen.content_fab_margin_bottom);
|
||||
|
||||
// Search Container
|
||||
mSearchPaddingTopOrigin = mSearchContainer.getPaddingTop();
|
||||
// Original padding bottom and the padding bottom to make it above fab
|
||||
mSearchPaddingBottomOrigin = mSearchContainer.getPaddingBottom() +
|
||||
mResources.getDimensionPixelSize(R.dimen.content_padding_bottom);
|
||||
mSearchContainer.setPadding( mSearchContainer.getPaddingLeft(),
|
||||
@@ -179,10 +173,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
mSearchContainer.getPaddingRight(),
|
||||
mSearchPaddingBottomOrigin + fitPaddingBottom
|
||||
);
|
||||
|
||||
LayoutParams lp = (LayoutParams) mFab.getLayoutParams();
|
||||
lp.bottomMargin = mFabMarginBottomOrigin + fitPaddingBottom;
|
||||
mFab.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
public void setHelper(SearhLayoutHelper helper) {
|
||||
@@ -263,10 +253,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
|
||||
// TODO add quick search
|
||||
} else if (v == mAction2) {
|
||||
taggleSearchMode();
|
||||
} else if (v == mFab) {
|
||||
if (mHelper != null) {
|
||||
mHelper.onRequestSearch(getListUrlBuilder(null));
|
||||
}
|
||||
} else if (v == mSearchTagHelp) {
|
||||
int[] location = new int [2];
|
||||
ViewUtils.getLocationInAncestor(mSearchTagHelp, location, R.id.stage);
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.Log;
|
||||
|
||||
public class StatusBarLayout extends ViewGroup {
|
||||
|
||||
|
||||
@@ -59,8 +59,6 @@ public abstract class Scene {
|
||||
|
||||
protected static SceneManager sSceneManager;
|
||||
|
||||
private int mFitPaddingBottom = -1;
|
||||
|
||||
static void setSceneManager(SceneManager sceneManager) {
|
||||
sSceneManager = sceneManager;
|
||||
}
|
||||
@@ -173,11 +171,8 @@ public abstract class Scene {
|
||||
onOut();
|
||||
}
|
||||
|
||||
void getFitPaddingBottom(int b) {
|
||||
if (mFitPaddingBottom != b) {
|
||||
mFitPaddingBottom = b;
|
||||
onGetFitPaddingBottom(b);
|
||||
}
|
||||
void setFitPaddingBottom(int b) {
|
||||
onGetFitPaddingBottom(b);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -103,7 +103,7 @@ class SceneManager {
|
||||
// Update fit padding
|
||||
int fitPaddingBottom = getStageActivity().getFitPaddingBottom();
|
||||
if (fitPaddingBottom > 0) {
|
||||
scene.getFitPaddingBottom(fitPaddingBottom);
|
||||
scene.setFitPaddingBottom(fitPaddingBottom);
|
||||
}
|
||||
|
||||
if (curtain != null && previousState != null) {
|
||||
|
||||
@@ -19,13 +19,13 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.ui.AbsActionBarActivity;
|
||||
import com.hippo.util.IntIdGenerator;
|
||||
|
||||
public abstract class StageActivity extends AbsActionBarActivity {
|
||||
public abstract class StageActivity extends AppCompatActivity {
|
||||
|
||||
private IntIdGenerator mActivityResultIdGenerator = IntIdGenerator.create();
|
||||
private SparseArray<Scene.ActivityResultListener> mActivityResultListenerMap =
|
||||
@@ -41,8 +41,6 @@ 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);
|
||||
@@ -65,7 +63,7 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
if (mFitPaddingBottom != b) {
|
||||
mFitPaddingBottom = b;
|
||||
for (Scene scene : sSceneManager.getSceneStack()) {
|
||||
scene.getFitPaddingBottom(b);
|
||||
scene.setFitPaddingBottom(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ public class FloatingActionButton extends View {
|
||||
ViewUtils.getSuitableSize(getSuggestedMinimumHeight(), heightMeasureSpec));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
mGasketDrawer.draw(canvas);
|
||||
|
||||
|
||||
Reference in new issue
Block a user