阅读界面添加亮度控制
This commit is contained in:
1 parent
2dcbdb2e12
commit
c0acbe816a
7 files changed
+167
-46
No files matched your search
@@ -85,4 +85,9 @@
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<com.hippo.ehviewer.widget.ColorView
|
||||
android:id="@+id/mask"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</FrameLayout>
|
||||
@@ -20,21 +20,29 @@ import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class OvalDrawable extends Drawable {
|
||||
|
||||
private final Paint mPaint;
|
||||
private final RectF mRectF;
|
||||
|
||||
public OvalDrawable(int color) {
|
||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
|
||||
mPaint.setColor(color);
|
||||
mRectF = new RectF();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
mRectF.set(bounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
canvas.drawOval(new RectF(this.getBounds()), mPaint);
|
||||
canvas.drawOval(mRectF, mPaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -95,6 +95,9 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
5 / 7.0f, 1 };
|
||||
private static final float[] CENTER_AREA_SCALE = { 2 / 7.0f, 3 / 8.0f,
|
||||
5 / 7.0f, 5 / 8.0f };
|
||||
private static final float[] LIGHTNESS_SLIDING_AREA = {
|
||||
0, 5 / 6.0f, 1, 1 };
|
||||
|
||||
|
||||
private static final float MILLSEC_PER_DIX = 0.2f;
|
||||
private static final float CHANGE_PAGE_PROPORTION = 0.1f;
|
||||
@@ -148,6 +151,7 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
private int[] rightArea;
|
||||
private int[] bottomArea;
|
||||
private int[] centerArea;
|
||||
private int[] mLightnessSlidingArea;
|
||||
|
||||
private Text leftText;
|
||||
private Text topText;
|
||||
@@ -157,6 +161,8 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
|
||||
private boolean mDoubleTapAnimating = false;
|
||||
|
||||
private boolean mLightnessSliding = false;
|
||||
|
||||
private boolean mShowTapArea = false;
|
||||
private boolean mShowTapAreaTurn = false;
|
||||
|
||||
@@ -172,6 +178,8 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
public void onPageChanged(int index);
|
||||
|
||||
public void onSizeUpdate(int size);
|
||||
|
||||
public void onSlideBottom(float dx);
|
||||
}
|
||||
|
||||
public interface OnTapTextListener {
|
||||
@@ -602,6 +610,10 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
(int) (CENTER_AREA_SCALE[1] * mScreenHeight),
|
||||
(int) (CENTER_AREA_SCALE[2] * mScreenWidth),
|
||||
(int) (CENTER_AREA_SCALE[3] * mScreenHeight) };
|
||||
mLightnessSlidingArea = new int[] { (int) (LIGHTNESS_SLIDING_AREA[0] * mScreenWidth),
|
||||
(int) (LIGHTNESS_SLIDING_AREA[1] * mScreenHeight),
|
||||
(int) (LIGHTNESS_SLIDING_AREA[2] * mScreenWidth),
|
||||
(int) (LIGHTNESS_SLIDING_AREA[3] * mScreenHeight) };
|
||||
|
||||
if (leftText == null)
|
||||
leftText = new Text(mContext.getString(R.string.pre_page),
|
||||
@@ -1188,16 +1200,17 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScrollBegin(float dx, float dy, float totalX,
|
||||
float totalY) {
|
||||
return onScroll(dx, dy, totalX, totalY);
|
||||
public boolean onScrollBegin(float dx, float dy, MotionEvent e1, MotionEvent e2) {
|
||||
mLightnessSliding = Utils.isInArea(mLightnessSlidingArea,
|
||||
(int) e2.getX(), (int) e2.getY());
|
||||
return onScroll(dx, dy, e1, e2);
|
||||
}
|
||||
|
||||
/**
|
||||
* dx 和 totalX 符号相反,为啥
|
||||
*/
|
||||
@Override
|
||||
public boolean onScroll(float dx, float dy, float totalX, float totalY) {
|
||||
public boolean onScroll(float dx, float dy, MotionEvent e1, MotionEvent e2) {
|
||||
|
||||
if (isScale)
|
||||
return false;
|
||||
@@ -1210,6 +1223,15 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
if (mDoubleTapAnimating)
|
||||
return false;
|
||||
|
||||
if (mLightnessSliding) {
|
||||
if (mGalleryViewListener != null)
|
||||
mGalleryViewListener.onSlideBottom(dx);
|
||||
return true;
|
||||
}
|
||||
|
||||
float totalX = e2.getX() - e1.getX();
|
||||
float totalY = e2.getY() - e1.getY();
|
||||
|
||||
switch (mScrollState) {
|
||||
case SCROLL_ANIME_LEFT:
|
||||
case SCROLL_ANIME_RIGHT:
|
||||
@@ -1300,6 +1322,8 @@ public class GalleryView extends GLView implements ImageSet.ImageListener,
|
||||
return false;
|
||||
if (mDoubleTapAnimating)
|
||||
return false;
|
||||
if (mLightnessSliding)
|
||||
return false;
|
||||
|
||||
switch (mScrollState) {
|
||||
case SCROLL_ANIME_LEFT:
|
||||
|
||||
@@ -33,8 +33,8 @@ public class GestureRecognizer {
|
||||
boolean onDoubleTap(float x, float y);
|
||||
boolean onDoubleTapConfirmed(float x, float y);
|
||||
void onLongPress(MotionEvent e);
|
||||
boolean onScrollBegin(float dx, float dy, float totalX, float totalY);
|
||||
boolean onScroll(float dx, float dy, float totalX, float totalY);
|
||||
boolean onScrollBegin(float dx, float dy, MotionEvent e1, MotionEvent e2);
|
||||
boolean onScroll(float dx, float dy, MotionEvent e1, MotionEvent e2);
|
||||
boolean onScrollEnd(float totalX, float totalY);
|
||||
boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);
|
||||
boolean onScaleBegin(float focusX, float focusY);
|
||||
@@ -107,18 +107,15 @@ public class GestureRecognizer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(
|
||||
MotionEvent e1, MotionEvent e2, float dx, float dy) {
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float dx, float dy) {
|
||||
if (e1.getX() != firstX || e1.getY() != firstY) {
|
||||
mStillScroll = true;
|
||||
firstX = e1.getX();
|
||||
firstY = e1.getY();
|
||||
return mListener.onScrollBegin(
|
||||
dx, dy, e2.getX() - e1.getX(), e2.getY() - e1.getY());
|
||||
return mListener.onScrollBegin(dx, dy, e1, e2);
|
||||
} else {
|
||||
return mListener.onScroll(dx, dy, e1, e2);
|
||||
}
|
||||
else
|
||||
return mListener.onScroll(
|
||||
dx, dy, e2.getX() - e1.getX(), e2.getY() - e1.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,14 +19,13 @@ package com.hippo.ehviewer.ui;
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Animation.AnimationListener;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -40,9 +39,10 @@ import com.hippo.ehviewer.gallery.GalleryView;
|
||||
import com.hippo.ehviewer.gallery.data.ImageSet;
|
||||
import com.hippo.ehviewer.gallery.ui.GLRootView;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Constants;
|
||||
import com.hippo.ehviewer.util.FullScreenHelper;
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.widget.ColorView;
|
||||
|
||||
public class GalleryActivity extends Activity
|
||||
implements GalleryView.GalleryViewListener, SeekBar.OnSeekBarChangeListener,
|
||||
@@ -54,6 +54,9 @@ public class GalleryActivity extends Activity
|
||||
public final static String KEY_GALLERY_INFO = "gallery_info";
|
||||
public final static String KEY_START_INDEX = "start_index";
|
||||
|
||||
public final static String KEY_LIGHTNESS = "lightness";
|
||||
public final static float DEFAULT_LIGHTNESS = 0.5f;
|
||||
|
||||
private View mFooter;
|
||||
private TextView mSeekerBubble;
|
||||
|
||||
@@ -65,11 +68,14 @@ public class GalleryActivity extends Activity
|
||||
|
||||
private GalleryView mGalleryView;
|
||||
|
||||
private ColorView mMaskView;
|
||||
|
||||
private GalleryInfo mGi;
|
||||
|
||||
private FullScreenHelper mFullScreenHelper;
|
||||
|
||||
private boolean mFirstTime = true;
|
||||
private float mLightness;
|
||||
private int mLightnessScale = 0;
|
||||
|
||||
private final Runnable mFullScreenTask = new Runnable() {
|
||||
@Override public void run() {
|
||||
@@ -88,33 +94,7 @@ public class GalleryActivity extends Activity
|
||||
void setFullScreen(final boolean fullScreen) {
|
||||
|
||||
mFullScreenHelper.setFullScreen(fullScreen);
|
||||
|
||||
if (!mFirstTime) {
|
||||
AlphaAnimation aa = fullScreen ? new AlphaAnimation(1.0f, 0.0f) :
|
||||
new AlphaAnimation(0.0f, 1.0f);
|
||||
aa.setDuration(Constants.ANIMATE_TIME);
|
||||
aa.setAnimationListener(new AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
if (!fullScreen)
|
||||
mFooter.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
if (fullScreen)
|
||||
mFooter.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
// Empty
|
||||
}
|
||||
});
|
||||
mFooter.startAnimation(aa);
|
||||
} else {
|
||||
mFirstTime = false;
|
||||
}
|
||||
mFooter.setVisibility(fullScreen ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (!fullScreen)
|
||||
startFullScreenTask();
|
||||
@@ -134,12 +114,37 @@ public class GalleryActivity extends Activity
|
||||
setFullScreen(!fullScreen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Need update mLightnessScale
|
||||
mLightnessScale = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
setFullScreen(true);
|
||||
}
|
||||
|
||||
private void setLightness(float l) {
|
||||
l = MathUtils.clamp(l, -1.0f, 1.0f);
|
||||
Window w = getWindow();
|
||||
WindowManager.LayoutParams lp = w.getAttributes();
|
||||
if (l >= 0.0f) {
|
||||
lp.screenBrightness = l;
|
||||
w.setAttributes(lp);
|
||||
mMaskView.setColor(0);
|
||||
} else {
|
||||
if (lp.screenBrightness != 0.0f) {
|
||||
lp.screenBrightness = 0.0f;
|
||||
w.setAttributes(lp);
|
||||
}
|
||||
mMaskView.setColor(MathUtils.lerp(0x00, 0xde, -l) << 24);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -152,6 +157,7 @@ public class GalleryActivity extends Activity
|
||||
mFooter = findViewById(R.id.footer);
|
||||
mPageSeeker = (SeekBar) findViewById(R.id.page_seeker);
|
||||
mSeekerBubble = (TextView) findViewById(R.id.seeker_bubble);
|
||||
mMaskView = (ColorView)findViewById(R.id.mask);
|
||||
mActionBar = getActionBar();
|
||||
|
||||
Intent intent = getIntent();
|
||||
@@ -211,6 +217,10 @@ public class GalleryActivity extends Activity
|
||||
.setButtonListener(this)
|
||||
.show();
|
||||
}
|
||||
|
||||
// lightness
|
||||
mLightness = Config.getFloat(KEY_LIGHTNESS, DEFAULT_LIGHTNESS);
|
||||
setLightness(mLightness);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,6 +280,16 @@ public class GalleryActivity extends Activity
|
||||
mPageSeeker.setProgress(mGalleryView.getCurIndex() + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideBottom(float dx) {
|
||||
if (mLightnessScale == 0)
|
||||
mLightnessScale = mMaskView.getWidth();
|
||||
|
||||
mLightness = MathUtils.clamp(mLightness - (dx / mLightnessScale), -1.0f, 1.0f);
|
||||
setLightness(mLightness);
|
||||
Config.setFloat(KEY_LIGHTNESS, mLightness);
|
||||
}
|
||||
|
||||
private void showSeekBubble() {
|
||||
mSeekerBubble.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -105,6 +105,14 @@ public final class Config {
|
||||
mConfigPre.edit().putString(key, Integer.toString(value)).apply();
|
||||
}
|
||||
|
||||
public static float getFloat(String key, float defValue) {
|
||||
return mConfigPre.getFloat(key, defValue);
|
||||
}
|
||||
|
||||
public static void setFloat(String key, float value) {
|
||||
mConfigPre.edit().putFloat(key, value).apply();
|
||||
}
|
||||
|
||||
|
||||
/****** Display ******/
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class ColorView extends View {
|
||||
|
||||
private int mColor;
|
||||
|
||||
public ColorView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ColorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ColorView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public ColorView(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
if (mColor != color) {
|
||||
mColor = color;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
canvas.drawColor(mColor);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user