diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
index 7ebac8139..eaf543e5a 100644
--- a/app/proguard-rules.pro
+++ b/app/proguard-rules.pro
@@ -40,6 +40,10 @@
void setProgress(float);
float getProgress();
}
+-keepclassmembers class com.hippo.drawable.AddDeleteDrawable {
+ void setProgress(float);
+ float getProgress();
+}
#For VectorResources
-keep class android.content.res.VectorResources {*;}
diff --git a/app/src/main/java/com/hippo/drawable/AddDeleteDrawable.java b/app/src/main/java/com/hippo/drawable/AddDeleteDrawable.java
new file mode 100644
index 000000000..e96d63dfb
--- /dev/null
+++ b/app/src/main/java/com/hippo/drawable/AddDeleteDrawable.java
@@ -0,0 +1,129 @@
+/*
+ * 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.drawable;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+
+import com.hippo.ehviewer.R;
+import com.hippo.util.MathUtils;
+
+public class AddDeleteDrawable extends Drawable {
+
+ private final Paint mPaint = new Paint();
+ private final Path mPath = new Path();
+
+ private final int mSize;
+ private final float mBarThickness;
+
+ private float mProgress;
+
+ private boolean mVerticalMirror = false;
+
+ /**
+ * @param context used to get the configuration for the drawable from
+ */
+ public AddDeleteDrawable(Context context) {
+ Resources resources = context.getResources();
+
+ mSize = resources.getDimensionPixelSize(R.dimen.add_size);
+ mBarThickness = Math.round(resources.getDimension(R.dimen.add_thickness));
+
+ mPaint.setColor(resources.getColor(R.color.primary_drawable_light));
+ mPaint.setStyle(Paint.Style.STROKE);
+ mPaint.setStrokeJoin(Paint.Join.MITER);
+ mPaint.setStrokeCap(Paint.Cap.BUTT);
+ mPaint.setStrokeWidth(mBarThickness);
+
+ float halfSize = mSize / 2;
+ mPath.moveTo(0f, -halfSize);
+ mPath.lineTo(0, halfSize);
+ mPath.moveTo(-halfSize, 0);
+ mPath.lineTo(halfSize, 0);
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ Rect bounds = getBounds();
+ float canvasRotate;
+ if (mVerticalMirror) {
+ canvasRotate = MathUtils.lerp(-270, -135f, mProgress);
+ } else {
+ canvasRotate = MathUtils.lerp(0f, -135f, mProgress);
+ }
+
+ canvas.save();
+ canvas.translate(bounds.centerX(), bounds.centerY());
+ canvas.rotate(canvasRotate);
+ canvas.drawPath(mPath, mPaint);
+ canvas.restore();
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ mPaint.setAlpha(alpha);
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ mPaint.setColorFilter(cf);
+ }
+
+ @Override
+ public int getIntrinsicHeight() {
+ return mSize;
+ }
+
+ @Override
+ public int getIntrinsicWidth() {
+ return mSize;
+ }
+
+ /**
+ * If set, canvas is flipped when progress reached to end and going back to start.
+ */
+ protected void setVerticalMirror(boolean verticalMirror) {
+ mVerticalMirror = verticalMirror;
+ }
+
+ @SuppressWarnings("unused")
+ public float getProgress() {
+ return mProgress;
+ }
+
+ @SuppressWarnings("unused")
+ public void setProgress(float progress) {
+ if (progress == 1f) {
+ setVerticalMirror(true);
+ } else if (progress == 0f) {
+ setVerticalMirror(false);
+ }
+ mProgress = progress;
+ invalidateSelf();
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+}
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java
index 9cade1cae..c4be3aaac 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java
+++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java
@@ -83,8 +83,8 @@ class GalleryListScene extends Scene implements SearchBar.Helper{
}
@Override
- public void onClickAdvance() {
-
+ public void onClickAction() {
+ Log.d("onClickAction");
}
@Override
diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
index b3514da58..599aa4299 100644
--- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
+++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
@@ -29,6 +29,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
+import com.hippo.drawable.AddDeleteDrawable;
import com.hippo.drawable.DrawerArrowDrawable;
import com.hippo.ehviewer.R;
import com.hippo.util.UiUtils;
@@ -42,11 +43,11 @@ public class SearchBar extends CardView implements View.OnClickListener,
private SimpleImageView mMenuButton;
private TextView mLogoTextView;
- private View mAdvanceButton;
+ private SimpleImageView mActionButton;
private SearchEditText mEditText;
- private View mSearchButton;
private DrawerArrowDrawable mDrawerArrowDrawable;
+ private AddDeleteDrawable mAddDeleteDrawable;
private Helper mHelper;
@@ -75,19 +76,19 @@ public class SearchBar extends CardView implements View.OnClickListener,
LayoutInflater.from(context).inflate(R.layout.widget_search_bar, this);
mMenuButton = (SimpleImageView) findViewById(R.id.menu);
mLogoTextView = (TextView) findViewById(R.id.logo);
- mAdvanceButton = findViewById(R.id.advance_search);
+ mActionButton = (SimpleImageView) findViewById(R.id.action);
mEditText = (SearchEditText) findViewById(R.id.search_edit_text);
- mSearchButton = findViewById(R.id.search_action);
mDrawerArrowDrawable = new DrawerArrowDrawable(getContext());
+ mAddDeleteDrawable = new AddDeleteDrawable(getContext());
mMenuButton.setDrawable(mDrawerArrowDrawable);
mMenuButton.setOnClickListener(this);
mLogoTextView.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Slabo.ttf"));
- mAdvanceButton.setOnClickListener(this);
+ mActionButton.setDrawable(mAddDeleteDrawable);
+ mActionButton.setOnClickListener(this);
mEditText.setSearchBar(this);
mEditText.setOnEditorActionListener(this);
- mSearchButton.setOnClickListener(this);
}
public void setHelper(Helper helper) {
@@ -104,12 +105,12 @@ public class SearchBar extends CardView implements View.OnClickListener,
} else {
mHelper.onClickMenu();
}
- } else if (v == mAdvanceButton) {
- mHelper.onClickAdvance();
- } else if (v == mSearchButton) {
- String query = mEditText.getText().toString();
- if (!TextUtils.isEmpty(query)) {
- mHelper.onApplySearch(query);
+ } else if (v == mActionButton) {
+ if (mInEditMode) {
+ // TODO when set prefix
+ mEditText.setText("");
+ } else {
+ mHelper.onClickAction();
}
}
}
@@ -133,20 +134,22 @@ public class SearchBar extends CardView implements View.OnClickListener,
mInEditMode = true;
setClickable(false);
ViewUtils.setVisibility(mLogoTextView, View.GONE);
- ViewUtils.setVisibility(mAdvanceButton, View.GONE);
ViewUtils.setVisibility(mEditText, View.VISIBLE);
- ViewUtils.setVisibility(mSearchButton, View.VISIBLE);
mEditText.requestFocus();
// show ime
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
// start animator
- ObjectAnimator oa = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 0f, 1f);
- oa.setDuration(ANIMATION_TIME);
+ ObjectAnimator oa1 = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 0f, 1f);
+ oa1.setDuration(ANIMATION_TIME);
+ ObjectAnimator oa2 = ObjectAnimator.ofFloat(mAddDeleteDrawable, "progress", 0f, 1f);
+ oa2.setDuration(ANIMATION_TIME);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
- oa.setAutoCancel(true);
+ oa1.setAutoCancel(true);
+ oa2.setAutoCancel(true);
}
- oa.start();
+ oa1.start();
+ oa2.start();
}
}
@@ -155,25 +158,27 @@ public class SearchBar extends CardView implements View.OnClickListener,
mInEditMode = false;
setOnClickListener(this);
ViewUtils.setVisibility(mLogoTextView, View.VISIBLE);
- ViewUtils.setVisibility(mAdvanceButton, View.VISIBLE);
ViewUtils.setVisibility(mEditText, View.GONE);
- ViewUtils.setVisibility(mSearchButton, View.GONE);
// hide ime
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getWindowToken(), 0);
// start animator
- ObjectAnimator oa = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 1f, 0f);
- oa.setDuration(ANIMATION_TIME);
+ ObjectAnimator oa1 = ObjectAnimator.ofFloat(mDrawerArrowDrawable, "progress", 1f, 0f);
+ oa1.setDuration(ANIMATION_TIME);
+ ObjectAnimator oa2 = ObjectAnimator.ofFloat(mAddDeleteDrawable, "progress", 1f, 0f);
+ oa2.setDuration(ANIMATION_TIME);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
- oa.setAutoCancel(true);
+ oa1.setAutoCancel(true);
+ oa2.setAutoCancel(true);
}
- oa.start();
+ oa1.start();
+ oa2.start();
}
}
public interface Helper {
void onClickMenu();
- void onClickAdvance();
+ void onClickAction();
void onApplySearch(String query);
}
}
diff --git a/app/src/main/res/layout/widget_search_bar.xml b/app/src/main/res/layout/widget_search_bar.xml
index ec17c3a97..467641896 100644
--- a/app/src/main/res/layout/widget_search_bar.xml
+++ b/app/src/main/res/layout/widget_search_bar.xml
@@ -45,7 +45,7 @@
tools:ignore="RtlHardcoded,RtlSymmetry"/>
-
-
3dp
16dp
-
+
+ 20dp
+ 2dp
24sp