Add gallery guide
This commit is contained in:
1 parent
073f6d1b60
commit
4b2801190c
14 files changed
+343
-9
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user