From 4b2801190cebbf8947e00875df9fbf779b0722ac Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 17 Mar 2016 01:28:38 +0800 Subject: [PATCH] Add gallery guide --- .../java/com/hippo/ehviewer/Settings.java | 11 + .../ehviewer/gallery/gl/GalleryView.java | 4 +- .../hippo/ehviewer/ui/GalleryActivity.java | 8 + .../ehviewer/widget/GalleryGuideView.java | 211 ++++++++++++++++++ app/src/main/res/layout/activity_gallery.xml | 9 +- .../res/layout/widget_gallery_guide_1.xml | 49 ++++ .../res/layout/widget_gallery_guide_2.xml | 28 +++ app/src/main/res/values-zh-rCN/strings.xml | 5 + app/src/main/res/values-zh-rHK/strings.xml | 5 + app/src/main/res/values-zh-rTW/strings.xml | 5 + app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/dimens.xml | 8 +- app/src/main/res/values/strings.xml | 5 + app/src/main/res/values/styles.xml | 2 +- 14 files changed, 343 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java create mode 100644 app/src/main/res/layout/widget_gallery_guide_1.xml create mode 100644 app/src/main/res/layout/widget_gallery_guide_2.xml diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index 78d31c0d7..546afd21d 100644 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -682,4 +682,15 @@ public class Settings { public static void puttGuideDownloadLabels(boolean value) { putBoolean(KEY_GUIDE_DOWNLOAD_LABELS, value); } + + private static final String KEY_GUIDE_GALLERY = "guide_gallery"; + private static final boolean DEFAULT_GUIDE_GALLERY = true; + + public static boolean getGuideGallery() { + return getBoolean(KEY_GUIDE_GALLERY, DEFAULT_GUIDE_GALLERY); + } + + public static void putGuideGallery(boolean value) { + putBoolean(KEY_GUIDE_GALLERY, value); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java b/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java index b95591706..92cb08d03 100644 --- a/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java +++ b/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java @@ -64,8 +64,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener { private static final float[] LEFT_AREA = {0.0f, 0.0f, 1.0f / 3.0f, 1f}; private static final float[] RIGHT_AREA = {2.0f / 3.0f, 0.0f, 1.0f, 1f}; - private static final float[] MENU_AREA = {1.0f / 3.0f, 0.0f, 2.0f / 3.0f, 3.0f / 4.0f}; - private static final float[] SLIDER_AREA = {1.0f / 3.0f, 3.0f / 4.0f, 2.0f / 3.0f, 1.0f}; + private static final float[] MENU_AREA = {1.0f / 3.0f, 0.0f, 2.0f / 3.0f, 2.0f / 3.0f}; + private static final float[] SLIDER_AREA = {1.0f / 3.0f, 2.0f / 3.0f, 2.0f / 3.0f, 1.0f}; private static final int METHOD_ON_SINGLE_TAP_UP = 0; private static final int METHOD_ON_SINGLE_TAP_CONFIRMED = 1; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java index 5efe2fd56..59e2e6f37 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java @@ -33,6 +33,7 @@ import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import android.webkit.MimeTypeMap; +import android.widget.FrameLayout; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -49,6 +50,7 @@ import com.hippo.ehviewer.gallery.ZipGalleryProvider; import com.hippo.ehviewer.gallery.gl.GalleryPageView; import com.hippo.ehviewer.gallery.gl.GalleryView; import com.hippo.ehviewer.gallery.gl.ImageView; +import com.hippo.ehviewer.widget.GalleryGuideView; import com.hippo.gl.glrenderer.ImageTexture; import com.hippo.gl.view.GLRootView; import com.hippo.image.Image; @@ -59,6 +61,7 @@ import com.hippo.yorozuya.AnimationUtils; import com.hippo.yorozuya.ConcurrentPool; import com.hippo.yorozuya.SimpleAnimatorListener; import com.hippo.yorozuya.SimpleHandler; +import com.hippo.yorozuya.ViewUtils; import java.io.File; @@ -276,6 +279,11 @@ public class GalleryActivity extends TrackedActivity } else { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } + + if (Settings.getGuideGallery()) { + FrameLayout mainLayout = (FrameLayout) ViewUtils.$$(this, R.id.main); + mainLayout.addView(new GalleryGuideView(this)); + } } @Override diff --git a/app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java b/app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java new file mode 100644 index 000000000..87b7c945c --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java @@ -0,0 +1,211 @@ +/* + * Copyright 2016 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * 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.widget; + +import android.annotation.TargetApi; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.os.Build; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.Settings; +import com.hippo.yorozuya.ViewUtils; + +public class GalleryGuideView extends ViewGroup implements View.OnClickListener { + + private int mBgColor; + private Paint mPaint; + private final float[] mPoints = new float[3 * 4]; + private int mStep; + + private TextView mLeftText; + private TextView mRightText; + private TextView mMenuText; + private TextView mProgressText; + private TextView mLongClickText; + + public GalleryGuideView(Context context) { + super(context); + init(context); + } + + public GalleryGuideView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public GalleryGuideView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public GalleryGuideView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(context); + } + + @SuppressWarnings("deprecation") + private void init(Context context) { + mBgColor = context.getResources().getColor(R.color.guide_bg); + mPaint = new Paint(); + mPaint.setColor(Color.WHITE); + mPaint.setStyle(Paint.Style.STROKE); + mPaint.setStrokeWidth(context.getResources().getDimension(R.dimen.gallery_guide_divider_width)); + setOnClickListener(this); + setWillNotDraw(false); + bind(); + } + + private void bind() { + // Clear up + removeAllViews(); + mLeftText = null; + mRightText = null; + mMenuText = null; + mProgressText = null; + mLongClickText = null; + + switch (mStep) { + case 0: + bind1(); + break; + default: + case 1: + bind2(); + break; + } + } + + private void bind1() { + LayoutInflater inflater = LayoutInflater.from(getContext()); + inflater.inflate(R.layout.widget_gallery_guide_1, this); + mLeftText = (TextView) getChildAt(0); + mRightText = (TextView) getChildAt(1); + mMenuText = (TextView) getChildAt(2); + mProgressText = (TextView) getChildAt(3); + } + + private void bind2() { + LayoutInflater inflater = LayoutInflater.from(getContext()); + inflater.inflate(R.layout.widget_gallery_guide_2, this); + mLongClickText = (TextView) getChildAt(0); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int widthSize = MeasureSpec.getSize(widthMeasureSpec); + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int heightSize = MeasureSpec.getSize(heightMeasureSpec); + int heightMode = MeasureSpec.getMode(heightMeasureSpec); + if (MeasureSpec.EXACTLY != widthMode || MeasureSpec.EXACTLY != heightMode) { + throw new IllegalStateException(); + } + + switch (mStep) { + case 0: + mLeftText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); + mRightText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); + mMenuText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(heightSize * 2 / 3, MeasureSpec.EXACTLY)); + mProgressText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(heightSize / 3, MeasureSpec.EXACTLY)); + break; + default: + case 1: + mLongClickText.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); + break; + } + + setMeasuredDimension(widthSize, heightSize); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + int width = r - l; + int height = b - t; + + switch (mStep) { + case 0: + mLeftText.layout(0, 0, width / 3, height); + mRightText.layout(width * 2 / 3, 0, width, height); + mMenuText.layout(width / 3, 0, width * 2 / 3, height * 2 / 3); + mProgressText.layout(width / 3, height * 2 / 3, width * 2 / 3, height); + break; + default: + case 1: + mLongClickText.layout(0, 0, width, height); + break; + } + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + + if (0 == mStep) { + mPoints[0] = w / 3; + mPoints[1] = 0; + mPoints[2] = w / 3; + mPoints[3] = h; + + mPoints[4] = w * 2 / 3; + mPoints[5] = 0; + mPoints[6] = w * 2 / 3; + mPoints[7] = h; + + mPoints[8] = w / 3; + mPoints[9] = h * 2 / 3; + mPoints[10] = w * 2 / 3; + mPoints[11] = h * 2 / 3; + } + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + canvas.drawColor(mBgColor); + if (0 == mStep) { + canvas.drawLines(mPoints, mPaint); + } + } + + @Override + public void onClick(View v) { + switch (mStep) { + case 0: + mStep++; + bind(); + break; + default: + case 1: + Settings.putGuideGallery(false); + ViewUtils.removeFromParent(this); + break; + } + } +} diff --git a/app/src/main/res/layout/activity_gallery.xml b/app/src/main/res/layout/activity_gallery.xml index 5e1501005..41e641720 100644 --- a/app/src/main/res/layout/activity_gallery.xml +++ b/app/src/main/res/layout/activity_gallery.xml @@ -15,8 +15,11 @@ ~ limitations under the License. --> - + - + diff --git a/app/src/main/res/layout/widget_gallery_guide_1.xml b/app/src/main/res/layout/widget_gallery_guide_1.xml new file mode 100644 index 000000000..0fe2659bf --- /dev/null +++ b/app/src/main/res/layout/widget_gallery_guide_1.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/widget_gallery_guide_2.xml b/app/src/main/res/layout/widget_gallery_guide_2.xml new file mode 100644 index 000000000..684b73943 --- /dev/null +++ b/app/src/main/res/layout/widget_gallery_guide_2.xml @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 68fc29943..c45e0988f 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -424,6 +424,11 @@ 从右侧滑动打开下载标签面板 画廊详情 点击缩略图查看画廊详情 + 翻页 + 翻页 + 菜单 + 进度条 + 长按打开页面菜单 来自未来 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index a43be99c7..df14570e4 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -424,6 +424,11 @@ 從右側滑動打開下載標籤面板 畫廊詳情 點擊縮略圖查看畫廊詳情 + 翻頁 + 翻頁 + 菜單 + 進度條 + 長按打開頁面菜單 來自未來 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 2125b99fd..284282e41 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -424,6 +424,11 @@ 從右側滑動開啟下載標籤面板 畫廊詳情 點選縮圖檢視畫廊詳情 + 翻頁 + 翻頁 + 選單 + 進度條 + 長按開啟頁面選單 來自未來 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e2dd4b0c0..f5229f26a 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -107,4 +107,6 @@ #1f000000 + #e5009688 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 587d4b37e..335b09755 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -47,9 +47,9 @@ 77dp 80dp - 320dp - 120dp - 120dp + 240dp + 80dp + 80dp 24dp @@ -98,4 +98,6 @@ 12dp 12dp + 3dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d7e706a4a..c61df6e3b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -468,6 +468,11 @@ Swipe right to open download labels panel Gallery Detail Click thumb to view gallery detail + Turn Page + Turn Page + Menu + Progress + Long click to open page menu From the future diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 18ccb040c..badbf481c 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -146,7 +146,7 @@