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 b0fb232c2..30b6e1e90 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 @@ -28,6 +28,8 @@ 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.SimpleDialog; +import com.hippo.util.AppHandler; import com.hippo.util.Log; import com.hippo.util.ViewUtils; @@ -77,6 +79,13 @@ class GalleryListScene extends Scene implements SearchBar.Helper { // TEST mContentLayout.showText("四姑拉斯基"); + + AppHandler.getInstance().postDelayed(new Runnable() { + @Override + public void run() { + new SimpleDialog.Builder().setTitle("NIhao").show(); + } + }, 2000); } @Override diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java index 00c24134e..1918df294 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.java @@ -25,7 +25,6 @@ import android.support.annotation.Nullable; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SwitchCompat; -import android.text.TextUtils; import android.util.AttributeSet; import android.util.SparseArray; import android.view.LayoutInflater; @@ -83,7 +82,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke private View mNormalView; private CategoryTable mTableCategory; private CheckBox mCheckSpecifyAuthor; - private FloatLabelEditText mTextSearch; private SwitchCompat mSwitchEnableAdvance; private View mAdvanceView; @@ -224,7 +222,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView == mCheckSpecifyAuthor) { - mTextSearch.setPrefix(isChecked ? "uploader:" : null); + // TODO } else if (buttonView == mSwitchEnableAdvance) { mEnableAdvance = isChecked; @@ -288,10 +286,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke if (mTableCategory != null) { lub.setCategory(mTableCategory.getCategory()); } - if (mTextSearch != null) { - String searchKey = mTextSearch.getText().toString(); - lub.setSearchKey(TextUtils.isEmpty(searchKey) ? null : searchKey); - } + // TODO if (mSwitchEnableAdvance.isChecked() && mTableAdvanceSearch != null) { lub.setAdvanceSearch(mTableAdvanceSearch.getAdvanceSearch()); lub.setMinRating(mTableAdvanceSearch.getMinRating()); @@ -377,7 +372,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke bindActionView((ActionHolder) holder); } else { View view = mInflater.inflate(R.layout.search_category, parent, false); - // ViewCompat.setElevation(view, UiUtils.dp2pix(4)); // TODO holder = new SearchHolder(view); switch (viewType) { case ITEM_TYPE_NORMAL:{ @@ -410,7 +404,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke mNormalView = holder.content.getChildAt(0); mTableCategory = (CategoryTable) mNormalView.findViewById(R.id.search_category_table); mCheckSpecifyAuthor = (CheckBox) mNormalView.findViewById(R.id.search_specify_author); - mTextSearch = (FloatLabelEditText) mNormalView.findViewById(R.id.search_text); mSwitchEnableAdvance = (SwitchCompat) mNormalView.findViewById(R.id.search_enable_advance); // Restore state diff --git a/app/src/main/java/com/hippo/scene/Scene.java b/app/src/main/java/com/hippo/scene/Scene.java index e1b8b777d..6a0aa4d4b 100644 --- a/app/src/main/java/com/hippo/scene/Scene.java +++ b/app/src/main/java/com/hippo/scene/Scene.java @@ -15,6 +15,7 @@ package com.hippo.scene; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; @@ -48,6 +49,8 @@ public abstract class Scene { private @Nullable Curtain mCurtain; + private @Nullable Announcer mAnnouncer; + @SuppressWarnings("deprecation") private @Nullable AbsoluteLayout mSceneView; @@ -55,7 +58,7 @@ public abstract class Scene { private int mState; - private static SceneManager sSceneManager; + protected static SceneManager sSceneManager; private int mFitPaddingBottom = -1; @@ -67,10 +70,18 @@ public abstract class Scene { mCurtain = curtain; } + void setAnnouncer(@Nullable Announcer announcer) { + mAnnouncer = announcer; + } + @Nullable Curtain getCurtain() { return mCurtain; } + @Nullable Announcer getAnnouncer() { + return mAnnouncer; + } + // If there is no StageActivity for SceneManager, yout will get AssertError public @NonNull StageActivity getStageActivity() { StageActivity stageActivity = sSceneManager.getStageActivity(); @@ -108,6 +119,11 @@ public abstract class Scene { mState = state; } + @SuppressWarnings("deprecation") + protected AbsoluteLayout createSceneView(Context context) { + return new AbsoluteLayout(context); + } + public final void finish() { sSceneManager.finishScene(this); } @@ -116,8 +132,7 @@ public abstract class Scene { onCreate(savedInstanceState); if (mSceneView == null) { - //noinspection deprecation - mSceneView = new AbsoluteLayout(getStageActivity()); + mSceneView = createSceneView(getStageActivity()); initBackground(mSceneView); } @@ -190,8 +205,7 @@ public abstract class Scene { protected void setContentView(int resId) { StageActivity sa = getStageActivity(); - //noinspection deprecation - mSceneView = new AbsoluteLayout(sa); + mSceneView = createSceneView(sa); initBackground(mSceneView); mSceneView.setBackgroundColor(mBackgroundColor); sa.getLayoutInflater().inflate(resId, mSceneView); @@ -199,15 +213,18 @@ public abstract class Scene { protected void setContentView(View view) { StageActivity sa = getStageActivity(); - //noinspection deprecation - mSceneView = new AbsoluteLayout(sa); + mSceneView = createSceneView(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) { bg.setBackgroundColor(mBackgroundColor); bg.setClickable(true); + bg.setFocusable(true); + bg.setFocusableInTouchMode(true); + bg.requestFocus(); } protected void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/app/src/main/java/com/hippo/scene/SceneDialog.java b/app/src/main/java/com/hippo/scene/SceneDialog.java new file mode 100644 index 000000000..11d91d912 --- /dev/null +++ b/app/src/main/java/com/hippo/scene/SceneDialog.java @@ -0,0 +1,29 @@ +/* + * 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.scene; + +import android.support.annotation.Nullable; + +public abstract class SceneDialog extends Scene { + + public void show() { + sSceneManager.showDialog(this, null); + } + + public void show(@Nullable Curtain curtain) { + sSceneManager.showDialog(this, curtain); + } +} diff --git a/app/src/main/java/com/hippo/scene/SceneManager.java b/app/src/main/java/com/hippo/scene/SceneManager.java index b7ff81dd1..88e6eae52 100644 --- a/app/src/main/java/com/hippo/scene/SceneManager.java +++ b/app/src/main/java/com/hippo/scene/SceneManager.java @@ -44,9 +44,18 @@ class SceneManager { return mStageActivity; } + private boolean isStageAlive() { + return mStageActivity != null; + } + // TODO check previousState state void startScene(@NonNull Class sceneClass, @Nullable Announcer announcer, @Nullable Curtain curtain) { + if (!isStageAlive()) { + Log.w(TAG, "Stage is not alive, but attemp to create " + sceneClass.getSimpleName()); + return; + } + Scene scene; try { scene = (Scene) sceneClass.newInstance(); @@ -58,8 +67,24 @@ class SceneManager { } catch (ClassCastException e) { throw new IllegalStateException(sceneClass.getName() + " can not cast to scene"); } + scene.setAnnouncer(announcer); scene.setCurtain(curtain); + startScene(scene, curtain); + } + + void showDialog(@NonNull SceneDialog dialog, @Nullable Curtain curtain) { + if (!isStageAlive()) { + Log.w(TAG, "Stage is not alive, but attemp to show dialog " + dialog.toString()); + return; + } + + dialog.setCurtain(curtain); + + startScene(dialog, curtain); + } + + private void startScene(Scene scene, Curtain curtain) { Scene previousState = getTopState(); mSceneStack.push(scene); diff --git a/app/src/main/java/com/hippo/scene/SimpleDialog.java b/app/src/main/java/com/hippo/scene/SimpleDialog.java new file mode 100644 index 000000000..4fa102270 --- /dev/null +++ b/app/src/main/java/com/hippo/scene/SimpleDialog.java @@ -0,0 +1,85 @@ +/* + * 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.scene; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.widget.TextView; + +import com.hippo.ehviewer.R; + +public class SimpleDialog extends SceneDialog { + + private static final int BACKGROUND_COLOR = 0x61000000; + + private Builder mBuilder; + + private StageActivity mActivity; + + private SimpleDialogFrame mFrame; + private TextView mTitle; + + private SimpleDialog(Builder builder) { + mBuilder = builder; + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // TODO + setBackgroundColor(BACKGROUND_COLOR); + + mActivity = getStageActivity(); + + mFrame = new SimpleDialogFrame(mActivity); + setContentView(mFrame); + + mActivity.getLayoutInflater().inflate(R.layout.simple_dialog, mFrame); + + mTitle = (TextView) findViewById(R.id.title); + + bindDialog(); + } + + private void bindDialog() { + mTitle.setText(mBuilder.mTitle); + } + + @Override + protected void onGetFitPaddingBottom(int b) { + mFrame.setFitPaddingBottom(b); + } + + public static class Builder { + + private String mTitle; + + public Builder setTitle(String title) { + mTitle = title; + return this; + } + + public @NonNull SceneDialog build() { + return new SimpleDialog(this); + } + + public void show() { + new SimpleDialog(this).show(); + } + } +} diff --git a/app/src/main/java/com/hippo/scene/SimpleDialogFrame.java b/app/src/main/java/com/hippo/scene/SimpleDialogFrame.java new file mode 100644 index 000000000..c04463e77 --- /dev/null +++ b/app/src/main/java/com/hippo/scene/SimpleDialogFrame.java @@ -0,0 +1,91 @@ +/* + * 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.scene; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v7.widget.CardView; +import android.util.AttributeSet; +import android.widget.AbsoluteLayout; + +import com.hippo.ehviewer.R; +import com.hippo.util.ResourcesUtils; + +public class SimpleDialogFrame extends CardView { + + private int mPadding; + private int mFixedWidth; + private float mFixedWidthPercent; + private float mFixedHeightPercent; + private int mFitPaddingBottom; + + public SimpleDialogFrame(Context context) { + super(context); + init(context); + } + + public SimpleDialogFrame(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public SimpleDialogFrame(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + private void init(Context context) { + Resources resources = context.getResources(); + mPadding = resources.getDimensionPixelOffset(R.dimen.simple_dialog_padding); + mFixedWidth = resources.getDimensionPixelOffset(R.dimen.simple_dialog_fixed_width); + mFixedWidthPercent = ResourcesUtils.getFloat(resources, R.dimen.simple_dialog_fixed_width_percent); + mFixedHeightPercent = ResourcesUtils.getFloat(resources, R.dimen.simple_dialog_fixed_height_percent); + } + + public void setFitPaddingBottom(int fitPaddingBottom) { + if (mFitPaddingBottom != fitPaddingBottom) { + mFitPaddingBottom = fitPaddingBottom; + requestLayout(); + } + } + + @SuppressWarnings("deprecation") + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // Width + int originalWidth = MeasureSpec.getSize(widthMeasureSpec); + if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED) { + int fixedWidth = Math.min((int) (originalWidth * mFixedWidthPercent), mFixedWidth) - + (2 * mPadding); + widthMeasureSpec = MeasureSpec.makeMeasureSpec(fixedWidth, MeasureSpec.EXACTLY); + } + // Height + int originalHeight = MeasureSpec.getSize(heightMeasureSpec); + if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.UNSPECIFIED) { + int fixedHeight = (int) ((originalHeight - mFitPaddingBottom) * mFixedHeightPercent) - + (2 * mPadding); + heightMeasureSpec = MeasureSpec.makeMeasureSpec(fixedHeight, MeasureSpec.AT_MOST); + } + // Measure + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + // Update x, y + int width = getMeasuredWidth(); + int height = getMeasuredHeight(); + AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) getLayoutParams(); + lp.x = (originalWidth - width) / 2; + lp.y = (originalHeight - mFitPaddingBottom - height) / 2; + } +} diff --git a/app/src/main/java/com/hippo/util/ResourcesUtils.java b/app/src/main/java/com/hippo/util/ResourcesUtils.java new file mode 100644 index 000000000..8c0925aa9 --- /dev/null +++ b/app/src/main/java/com/hippo/util/ResourcesUtils.java @@ -0,0 +1,28 @@ +/* + * 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.util; + +import android.content.res.Resources; +import android.util.TypedValue; + +public final class ResourcesUtils { + + public static float getFloat(Resources resources, int resId) { + TypedValue outValue = new TypedValue(); + resources.getValue(resId, outValue, true); + return outValue.getFloat(); + } +} diff --git a/app/src/main/res/color/text_button_text.xml b/app/src/main/res/color/text_button_text.xml new file mode 100644 index 000000000..5af7942d6 --- /dev/null +++ b/app/src/main/res/color/text_button_text.xml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_help_circle.xml b/app/src/main/res/drawable/ic_help_circle.xml new file mode 100644 index 000000000..5ee7d43a0 --- /dev/null +++ b/app/src/main/res/drawable/ic_help_circle.xml @@ -0,0 +1,40 @@ + + + + + + + + diff --git a/app/src/main/res/layout/search_normal.xml b/app/src/main/res/layout/search_normal.xml index c5e9e7c74..be59b2244 100644 --- a/app/src/main/res/layout/search_normal.xml +++ b/app/src/main/res/layout/search_normal.xml @@ -15,6 +15,7 @@ --> @@ -32,22 +33,34 @@ android:layout_marginBottom="@dimen/search_item_interval" android:text="@string/search_specify_author"/> - + android:orientation="horizontal"> + + + + + + + android:text="@string/search_enable_advance" + tools:ignore="RtlHardcoded"/> diff --git a/app/src/main/res/layout/simple_dialog.xml b/app/src/main/res/layout/simple_dialog.xml new file mode 100644 index 000000000..19288d477 --- /dev/null +++ b/app/src/main/res/layout/simple_dialog.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 612d702a0..3bdd398f6 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -24,6 +24,7 @@ 标签搜索 图片搜索 指定上传者 + 指定标签 没关键字也行 启用高级选项 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index fb163d163..38b69f1cc 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -24,6 +24,7 @@ --> + #8a000000 #42000000 #ffffffff @@ -66,6 +67,8 @@ #deffffff #61ffffff + + #ff303030 #ffeeeeee #ffe1e1e0 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index cc9c74418..62b3a5c7b 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -15,6 +15,9 @@ --> + 16dp + 320dp + 8dp 8dp diff --git a/app/src/main/res/values/floats.xml b/app/src/main/res/values/floats.xml new file mode 100644 index 000000000..12fc8c07f --- /dev/null +++ b/app/src/main/res/values/floats.xml @@ -0,0 +1,19 @@ + + + + 1.0 + 0.8 + diff --git a/app/src/main/res/values/pathdata.xml b/app/src/main/res/values/pathdata.xml index 803770212..f1942c3f7 100644 --- a/app/src/main/res/values/pathdata.xml +++ b/app/src/main/res/values/pathdata.xml @@ -20,5 +20,6 @@ M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z M15,9A1,1 0 0,1 14,8A1,1 0 0,1 15,7A1,1 0 0,1 16,8A1,1 0 0,1 15,9M9,9A1,1 0 0,1 8,8A1,1 0 0,1 9,7A1,1 0 0,1 10,8A1,1 0 0,1 9,9M16.12,4.37L18.22,2.27L17.4,1.44L15.09,3.75C14.16,3.28 13.11,3 12,3C10.88,3 9.84,3.28 8.91,3.75L6.6,1.44L5.78,2.27L7.88,4.37C6.14,5.64 5,7.68 5,10V11H19V10C19,7.68 17.86,5.64 16.12,4.37M5,16C5,19.86 8.13,23 12,23A7,7 0 0,0 19,16V12H5V16Z + M15.07,11.25L14.17,12.17C13.45,12.89 13,13.5 13,15H11V14.5C11,13.39 11.45,12.39 12.17,11.67L13.41,10.41C13.78,10.05 14,9.55 14,9C14,7.89 13.1,7 12,7A2,2 0 0,0 10,9H8A4,4 0 0,1 12,5A4,4 0 0,1 16,9C16,9.88 15.64,10.67 15.07,11.25M13,19H11V17H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fce917c85..49c75a52d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,7 +41,8 @@ Advance Options Tag Search Image Search - Specify Uploader + Specify uploader + Specify tag No keyword is OK Enable advance options diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ee85af3ff..ef42157f7 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -83,4 +83,18 @@ @drawable/progress_large_material + + + +