diff --git a/bin/EhViewer.apk b/bin/EhViewer.apk index 87fa53265..3e57a9045 100644 Binary files a/bin/EhViewer.apk and b/bin/EhViewer.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index 982f9608e..5d4048b9a 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index db4827175..cd1a4decf 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/res/layout/gl_root_group.xml b/res/layout/gl_root_group.xml index e42172f3b..d791dd13c 100644 --- a/res/layout/gl_root_group.xml +++ b/res/layout/gl_root_group.xml @@ -6,8 +6,8 @@ android:id="@+id/gl_root_view" android:layout_width="match_parent" android:layout_height="match_parent"/> - + android:background="#ff888888"/--> \ No newline at end of file diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index 6c28ca3a5..3c754cf02 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -126,6 +126,7 @@ 横屏 页面缩放 + 开页位置 设置 缓存 @@ -188,6 +189,13 @@ 未启动 等待中 + + 上一页 + 下一页 + 放大 + 缩小 + 菜单 + 最后一页! 未完成的功能 @@ -219,6 +227,13 @@ 匹配宽度 匹配长度 匹配屏幕 + 固定缩放 + + 左上角 + 右上角 + 左下角 + 右下角 + 中心 收藏 移除 diff --git a/res/values/array.xml b/res/values/array.xml index 6b626ff3b..b044cec90 100644 --- a/res/values/array.xml +++ b/res/values/array.xml @@ -20,6 +20,7 @@ @string/fit_to_width @string/fit_to_height @string/fit_to_screen + @string/fixed_scale @@ -27,6 +28,23 @@ 1 2 3 + 4 + + + + @string/top_left + @string/top_right + @string/bottom_left + @string/bottom_right + @string/center + + + + 0 + 1 + 2 + 3 + 4 diff --git a/res/values/strings.xml b/res/values/strings.xml index 6482b4da2..fc350ebe4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -130,6 +130,7 @@ Portrait Landscape Page scaling + Start position Settings Cache @@ -195,6 +196,13 @@ Not started Waiting + + Previous page + Next page + Zoom in + Zoom out + Menu + Last page ! Sad Panda @@ -227,6 +235,13 @@ Fit to width Fit to height Fit to screen + Fixed + + Top left + Top right + Bottom left + Bottom right + Center Add to favourite Remove diff --git a/res/xml/settings.xml b/res/xml/settings.xml index 7cda1dbc5..1f454d7af 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -17,6 +17,14 @@ android:key="preference_page_scaling" android:summary="%s" android:title="@string/preference_page_scaling" /> + + diff --git a/src/com/hippo/ehviewer/activity/MangaDownloadActivity.java b/src/com/hippo/ehviewer/activity/MangaDownloadActivity.java index f27695399..ce48ddc84 100644 --- a/src/com/hippo/ehviewer/activity/MangaDownloadActivity.java +++ b/src/com/hippo/ehviewer/activity/MangaDownloadActivity.java @@ -31,6 +31,7 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.Toast; public class MangaDownloadActivity extends Activity { private static final String TAG = "MangaDownloadActivity"; @@ -48,8 +49,6 @@ public class MangaDownloadActivity extends Activity { } } - - @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { @@ -75,70 +74,20 @@ public class MangaDownloadActivity extends Activity { ImageSet is = new ImageSet(new File(Config.getDownloadPath(), title), size, 0, size, null); GalleryView isv = new GalleryView(getApplicationContext(), is, 0); - - glrv.setContentPane(isv); - - /* - if (title == null) { - finish(); - return; - } - dir = new File(Config.getDownloadPath(), title); - String[] files; - if (!dir.isDirectory() || (files = dir.list()) == null) { - finish(); - return; - } - fileList = new ArrayList(); - for (String fileName : files) { - String name = Util.getName(fileName); - if (Util.isNumber(name)) - fileList.add(fileName); - } - // TODO do it you self - Collections.sort(fileList); - - pageView = new MangaViewPager(this); - pageView.setBackgroundColor(color.darker_gray); - // For fullscreen - if (Build.VERSION.SDK_INT >= 19) { - pageView.setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); - } - pageView.setAdapter(new PagerAdapter() { + isv.setOnEdgeListener(new GalleryView.OnEdgeListener() { @Override - public void destroyItem(ViewGroup container, int position, Object view) { - container.removeView((View)view); - } - - @Override - public Object instantiateItem(ViewGroup container, int position) { - final String imageName = fileList.get(position); - MangaImage oiv = new MangaImage(MangaDownloadActivity.this); - Bitmap bitmap = BitmapFactory.decodeFile(dir.toString() + "/" + imageName); - oiv.setImageBitmap(bitmap); - //oiv.enableZoomMove(true); - container.addView(oiv); - return oiv; + public void onLastPageEdge() { + Toast.makeText(MangaDownloadActivity.this, getString(R.string.last_page), Toast.LENGTH_SHORT).show(); } @Override - public int getCount() { - return fileList.size(); - } - - @Override - public boolean isViewFromObject(View arg0, Object arg1) { - return arg0==arg1; + public void onFirstPageEdge() { + Toast.makeText(MangaDownloadActivity.this, getString(R.string.first_page), Toast.LENGTH_SHORT).show(); } }); - setContentView(pageView);*/ + glrv.setContentPane(isv); + } @Override diff --git a/src/com/hippo/ehviewer/activity/SettingsActivity.java b/src/com/hippo/ehviewer/activity/SettingsActivity.java index e7c6cd368..3eece2cbf 100644 --- a/src/com/hippo/ehviewer/activity/SettingsActivity.java +++ b/src/com/hippo/ehviewer/activity/SettingsActivity.java @@ -32,7 +32,6 @@ import android.support.v4.util.LruCache; import android.webkit.WebView; import android.widget.Toast; -//TODO Add thanks public class SettingsActivity extends PreferenceActivity { @SuppressWarnings("unused") private static String TAG = "Settings"; @@ -41,17 +40,18 @@ public class SettingsActivity extends PreferenceActivity { public LruCache memoryCache; - private String CP_CACHE = "preference_cp_cache"; - private String CLEAR_CP_CACHE = "preference_clear_cp_cache"; - private String PAGE_CACHE = "preference_page_cache"; - private String CLEAR_PAGE_CACHE = "preference_clear_page_cache"; - private String PAGE_SCALING = "preference_page_scaling"; - private String AUTHOR = "preference_author"; - private String SCREEN_ORI = "preference_screen_ori"; - private String CHANGELOG = "preference_changelog"; - private String THANKS = "preference_thanks"; - private String UPDATE = "preference_update"; - private String RAN = "preference_remove_all_noification"; + private static final String CP_CACHE = "preference_cp_cache"; + private static final String CLEAR_CP_CACHE = "preference_clear_cp_cache"; + private static final String PAGE_CACHE = "preference_page_cache"; + //private static final String START_POSITION = "preference_start_position"; + private static final String CLEAR_PAGE_CACHE = "preference_clear_page_cache"; + private static final String PAGE_SCALING = "preference_page_scaling"; + private static final String AUTHOR = "preference_author"; + private static final String SCREEN_ORI = "preference_screen_ori"; + private static final String CHANGELOG = "preference_changelog"; + private static final String THANKS = "preference_thanks"; + private static final String UPDATE = "preference_update"; + private static final String RAN = "preference_remove_all_noification"; private EditTextPreference cpCachePre; private Preference clearCpCachePre; @@ -227,7 +227,20 @@ public class SettingsActivity extends PreferenceActivity { return true; } }); - + + /* + final AutoListPreference start_position = + (AutoListPreference)screen.findPreference(START_POSITION); + start_position.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, + Object newValue) { + // TODO Auto-generated method stub + return false; + } + });*/ + + // Connect me ! authorPer = screen.findPreference(AUTHOR); authorPer.setOnPreferenceClickListener(new OnPreferenceClickListener() { diff --git a/src/com/hippo/ehviewer/gallery/GalleryView.java b/src/com/hippo/ehviewer/gallery/GalleryView.java index 372412852..76fdcf667 100644 --- a/src/com/hippo/ehviewer/gallery/GalleryView.java +++ b/src/com/hippo/ehviewer/gallery/GalleryView.java @@ -8,18 +8,21 @@ import android.graphics.RectF; import android.util.Log; import android.view.MotionEvent; +import com.hippo.ehviewer.R; import com.hippo.ehviewer.gallery.data.ImageSet; import com.hippo.ehviewer.gallery.glrenderer.BitmapTexture; import com.hippo.ehviewer.gallery.glrenderer.GLCanvas; +import com.hippo.ehviewer.gallery.glrenderer.GLPaint; import com.hippo.ehviewer.gallery.glrenderer.StringTexture; import com.hippo.ehviewer.gallery.ui.GLView; import com.hippo.ehviewer.gallery.ui.GestureRecognizer; -import com.hippo.ehviewer.gallery.ui.GestureRecognizer.Listener; import com.hippo.ehviewer.gallery.util.GalleryUtils; +import com.hippo.ehviewer.util.Config; import com.hippo.ehviewer.util.TimeRunner; +import com.hippo.ehviewer.util.Ui; public class GalleryView extends GLView { - + @SuppressWarnings("unused") private static final String TAG = "ImagesView"; public static final int INVALID_ID = -1; @@ -28,18 +31,21 @@ public class GalleryView extends GLView { private static final int STATE_LAST = 0x2; private static final int STATE_NONE = 0x0; + // scale mode private static final int ORGIN = 0x0; private static final int FIT_WIDTH = 0x1; private static final int FIT_HEIGHT = 0x2; private static final int FIT = 0x3; private static final int FIXED = 0x4; + // start position mode private static final int TOP_LEFT = 0x0; private static final int TOP_RIGHT = 0x1; private static final int BOTTOM_LEFT = 0x2; private static final int BOTTOM_RIGHT = 0x3; private static final int CENTER = 0x4; + // Scroll state private static final int SCROLL_NONE = 0x0; private static final int SCROLL_LEFT = 0x1; private static final int SCROLL_RIGHT = 0x2; @@ -51,8 +57,27 @@ public class GalleryView extends GLView { private static final int NEXT_TARGET_INDEX = 2; private static final int TARGET_INDEX_SIZE = 3; + // Area + private static final float[] LEFT_AREA_SCALE = {0, 0, 2/7.0f, 1}; + private static final float[] TOP_AREA_SCALE = {2/7.0f, 0, 5/7.0f, 3/8.0f}; + private static final float[] RIGHT_AREA_SCALE = {5/7.0f, 0, 1, 1}; + private static final float[] BOTTOM_AREA_SCALE = {2/7.0f, 5/8.0f, 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 MILLSEC_PER_DIX = 0.2f; - private static final float CHANGE_PAGE_PROPORTION = 0.1f; + private static final float CHANGE_PAGE_PROPORTION = 0.05f; + + // TODO in dip + private static final float CHANGE_PAGE_OFFSET = 20; + + // TODO 根据界面的大小调整缩放界限 + private static final float SCALE_MIN = 1/4.0f; + private static final float SCALE_MAX = 4; + + private static final float LINE_WIDTH = Ui.dp2pix(3); + private static final int LINE_COLOR = -1; // White + private static final int TAP_AREA_TEXT_COLOR = -1; // White + private static final int TAP_AREA_TEXT_SIZE = Ui.dp2pix(24); private final GestureRecognizer mGestureRecognizer; private Context mContext; @@ -61,8 +86,8 @@ public class GalleryView extends GLView { private int mState; // scale and scroll only can choose one private boolean isScale = false; - private int scaleMode = FIXED; - private int startMode = TOP_LEFT; + private int scaleMode; + private int startMode; private int mScrollState = SCROLL_NONE; private int scrollXOffset = 0; private int scrollYOffset = 0; @@ -76,17 +101,38 @@ public class GalleryView extends GLView { private int mWidth = -1; private int mHeight = -1; - private static final float SCALE_MIN = 1/4.0f; - private static final float SCALE_MAX = 4; - - // TODO 开页方向 - // at most keep three item private ShowItem[] showItems; private int mCurIndex; private int mSize; private boolean mInit = false; + private int[] leftArea; + private int[] topArea; + private int[] rightArea; + private int[] bottomArea; + private int[] centerArea; + + private Text leftText; + private Text topText; + private Text rightText; + private Text bottomText; + private Text centerText; + + private boolean mShowTapArea = false; + private boolean mShowTapAreaTurn = false; + + public OnEdgeListener mOnEdgeListener; + + public interface OnEdgeListener { + public void onFirstPageEdge(); + public void onLastPageEdge(); + } + + public void setOnEdgeListener(OnEdgeListener l) { + mOnEdgeListener = l; + } + public GalleryView(Context context, ImageSet imageSet, int startIndex) { mContext = context; mImageSet = imageSet; @@ -103,6 +149,10 @@ public class GalleryView extends GLView { setBackgroundColor(GalleryUtils.intColorToFloatARGBArray(Color.GRAY)); showItems = new ShowItem[TARGET_INDEX_SIZE]; + + // Init config + scaleMode = Config.getPageScalingMode(); + startMode = Config.getStartPosition(); } private void setState() { @@ -113,6 +163,33 @@ public class GalleryView extends GLView { mState |= STATE_LAST; } + private void drawTapArea(GLCanvas canvas) { + drawRect(canvas, leftArea); + drawRect(canvas, topArea); + drawRect(canvas, rightArea); + drawRect(canvas, bottomArea); + drawRect(canvas, centerArea); + leftText.draw(canvas); + topText.draw(canvas); + rightText.draw(canvas); + bottomText.draw(canvas); + centerText.draw(canvas); + } + + private void drawRect(GLCanvas canvas, int[] rect) { + + int left = rect[0]; + int top = rect[1]; + int right = rect[2]; + int bottom = rect[3]; + + GLPaint paint = new GLPaint(LINE_COLOR, LINE_WIDTH); + canvas.drawLine(left, top, right, top, paint); + canvas.drawLine(left, bottom, right, bottom, paint); + canvas.drawLine(left, top, left, bottom, paint); + canvas.drawLine(right, top, right, bottom, paint); + } + @Override protected void render(GLCanvas canvas) { super.render(canvas); @@ -146,10 +223,16 @@ public class GalleryView extends GLView { item.draw(canvas, scrollXOffset, scrollYOffset); break; } + + // Add mInit to make show the leftArea or other is not null + if (mShowTapArea && mInit) + drawTapArea(canvas); } private void resetSizePosition() { - + resetSizePosition(PRE_TARGET_INDEX); + resetSizePosition(CUR_TARGET_INDEX); + resetSizePosition(NEXT_TARGET_INDEX); } private void resetSizePosition(int targeIndex) { @@ -188,7 +271,7 @@ public class GalleryView extends GLView { if (showItem instanceof Image) { Image image = (Image)showItem; - // TODO 检查缩放尺寸是否超界 + // Set scale int showWidth = 0; int showHeight = 0; Rect rect = image.mRect; @@ -230,9 +313,20 @@ public class GalleryView extends GLView { break; } + // adjust scale + if (image.imageScale < SCALE_MIN) { + image.imageScale = SCALE_MIN; + showWidth = (int)(image.width * SCALE_MIN); + showHeight = (int)(image.height * SCALE_MIN); + } else if (image.imageScale > SCALE_MAX) { + image.imageScale = SCALE_MAX; + showWidth = (int)(image.width * SCALE_MAX); + showHeight = (int)(image.height * SCALE_MAX); + } + + // set start position int xOffset; int yOffset; - switch (startMode) { case TOP_LEFT: xOffset = 0; @@ -262,12 +356,75 @@ public class GalleryView extends GLView { rect.top = yOffset; rect.bottom = rect.top + showHeight; + // adjust position adjustPosition(image); } invalidate(); } + private void setCenterInArea(int[] area, ShowItem showItem) { + int xOffset = ((area[2] - area[0]) - showItem.width)/2; + int yOffset = ((area[3] - area[1]) - showItem.height)/2; + + Rect rect = showItem.mRect; + + rect.left = area[0] + xOffset; + rect.right = rect.left + showItem.width; + rect.top = area[1] + yOffset; + rect.bottom = rect.top + showItem.height; + } + + private void setTapArea() { + leftArea = new int[]{ + (int)(LEFT_AREA_SCALE[0] * mWidth), + (int)(LEFT_AREA_SCALE[1] * mHeight), + (int)(LEFT_AREA_SCALE[2] * mWidth), + (int)(LEFT_AREA_SCALE[3] * mHeight)}; + topArea = new int[]{ + (int)(TOP_AREA_SCALE[0] * mWidth), + (int)(TOP_AREA_SCALE[1] * mHeight), + (int)(TOP_AREA_SCALE[2] * mWidth), + (int)(TOP_AREA_SCALE[3] * mHeight)}; + rightArea = new int[]{ + (int)(RIGHT_AREA_SCALE[0] * mWidth), + (int)(RIGHT_AREA_SCALE[1] * mHeight), + (int)(RIGHT_AREA_SCALE[2] * mWidth), + (int)(RIGHT_AREA_SCALE[3] * mHeight)}; + bottomArea = new int[]{ + (int)(BOTTOM_AREA_SCALE[0] * mWidth), + (int)(BOTTOM_AREA_SCALE[1] * mHeight), + (int)(BOTTOM_AREA_SCALE[2] * mWidth), + (int)(BOTTOM_AREA_SCALE[3] * mHeight)}; + centerArea = new int[]{ + (int)(CENTER_AREA_SCALE[0] * mWidth), + (int)(CENTER_AREA_SCALE[1] * mHeight), + (int)(CENTER_AREA_SCALE[2] * mWidth), + (int)(CENTER_AREA_SCALE[3] * mHeight)}; + + if (leftText == null) + leftText = new Text(mContext.getString(R.string.pre_page), + TAP_AREA_TEXT_SIZE, TAP_AREA_TEXT_COLOR); + if (topText == null) + topText = new Text(mContext.getString(R.string.zoom_in), + TAP_AREA_TEXT_SIZE, TAP_AREA_TEXT_COLOR); + if (rightText == null) + rightText = new Text(mContext.getString(R.string.next_page), + TAP_AREA_TEXT_SIZE, TAP_AREA_TEXT_COLOR); + if (bottomText == null) + bottomText = new Text(mContext.getString(R.string.zoom_out), + TAP_AREA_TEXT_SIZE, TAP_AREA_TEXT_COLOR); + if (centerText == null) + centerText = new Text(mContext.getString(R.string.menu), + TAP_AREA_TEXT_SIZE, TAP_AREA_TEXT_COLOR); + + setCenterInArea(leftArea, leftText); + setCenterInArea(topArea, topText); + setCenterInArea(rightArea, rightText); + setCenterInArea(bottomArea, bottomText); + setCenterInArea(centerArea, centerText); + } + @Override protected void onLayout( boolean changeSize, int left, int top, int right, int bottom) { @@ -284,6 +441,7 @@ public class GalleryView extends GLView { } else { resetSizePosition(); } + setTapArea(); invalidate(); } @@ -315,6 +473,22 @@ public class GalleryView extends GLView { } } + /** + * If cur page is first page return true + * @return + */ + private boolean isFirstPage() { + return (mState & STATE_FIRST) != 0; + } + + /** + * If cur page is last page return true + * @return + */ + private boolean isLastPage() { + return (mState & STATE_LAST) != 0; + } + class DecodeImageListener implements ImageSet.OnDecodeOverListener { @Override public void onDecodeOver(Bitmap bmp, int index) { @@ -338,6 +512,115 @@ public class GalleryView extends GLView { } } + /** + * + * @param mode + * true zoom in, false zoom out + * @return + */ + private boolean zoom(boolean mode) { + ShowItem curShowItem; + curShowItem = showItems[CUR_TARGET_INDEX]; + + if (curShowItem == null || !(curShowItem instanceof Image)) + return false; + Image image = (Image)curShowItem; + float newScale; + if (mode) { + newScale = image.imageScale * 1.1f; + if (newScale == SCALE_MAX) + return false; + if (newScale > SCALE_MAX) + newScale = SCALE_MAX; + } + else { + newScale = image.imageScale * 0.9f; + if (newScale == SCALE_MIN) + return false; + if (newScale < SCALE_MIN) + newScale = SCALE_MIN; + } + image.imageScale = newScale; + mScale = newScale; + + Rect rect = image.mRect; + int width = (int)(image.width * newScale); + int height = (int)(image.height * newScale); + int xOffset = (width - rect.width())/2; + int yOffset = (height - rect.height())/2; + + rect.set(rect.left - xOffset, rect.top - yOffset, rect.right + xOffset, rect.bottom + yOffset); + + invalidate(); + return true; + } + + /** + * You'd better resetSizePosition(PRE_TARGET_INDEX) before + * @return + */ + private boolean goToPrePage() { + if (isFirstPage()) + return false; + + ShowItem showItem; + showItem = showItems[NEXT_TARGET_INDEX]; + if (showItem != null) + showItem.recycle(); + showItems[NEXT_TARGET_INDEX] = showItems[CUR_TARGET_INDEX]; + showItems[CUR_TARGET_INDEX] = showItems[PRE_TARGET_INDEX]; + showItems[PRE_TARGET_INDEX] = null; + + // adjust rect + showItem = showItems[NEXT_TARGET_INDEX]; + if (showItem != null) { + showItem.mRect.offset(mWidth, 0); + } + showItem = showItems[CUR_TARGET_INDEX]; + if (showItem != null) { + showItem.mRect.offset(mWidth, 0); + } + + mCurIndex--; + setState(); + loadImage(mCurIndex-1, PRE_TARGET_INDEX); + + invalidate(); + return true; + } + + /** + * You'd better resetSizePosition(NEXT_TARGET_INDEX) before + * @return + */ + private boolean goToNextPage() { + if (isLastPage()) + return false; + + ShowItem showItem; + showItem = showItems[PRE_TARGET_INDEX]; + if (showItem != null) + showItem.recycle(); + showItems[PRE_TARGET_INDEX] = showItems[CUR_TARGET_INDEX]; + showItems[CUR_TARGET_INDEX] = showItems[NEXT_TARGET_INDEX]; + showItems[NEXT_TARGET_INDEX] = null; + // adjust rect + showItem = showItems[PRE_TARGET_INDEX]; + if (showItem != null) { + showItem.mRect.offset(-mWidth, 0); + } + showItem = showItems[CUR_TARGET_INDEX]; + if (showItem != null) { + showItem.mRect.offset(-mWidth, 0); + } + + mCurIndex++; + setState(); + loadImage(mCurIndex+1, NEXT_TARGET_INDEX); + + invalidate(); + return true; + } @Override protected boolean onTouch(MotionEvent event) { @@ -354,30 +637,8 @@ public class GalleryView extends GLView { @Override public void onEnd() { scrollXOffset = 0; - - ShowItem showItem; - showItem = showItems[NEXT_TARGET_INDEX]; - if (showItem != null) - showItem.recycle(); - showItems[NEXT_TARGET_INDEX] = showItems[CUR_TARGET_INDEX]; - showItems[CUR_TARGET_INDEX] = showItems[PRE_TARGET_INDEX]; - showItems[PRE_TARGET_INDEX] = null; - // adjust rect - showItem = showItems[NEXT_TARGET_INDEX]; - if (showItem != null) { - showItem.mRect.offset(mWidth, 0); - } - showItem = showItems[CUR_TARGET_INDEX]; - if (showItem != null) { - showItem.mRect.offset(mWidth, 0); - } - - mCurIndex--; - setState(); - loadImage(mCurIndex-1, PRE_TARGET_INDEX); - + goToPrePage(); mScrollState = SCROLL_NONE; - invalidate(); } }); mToNextTimeRunner.setOnTimerListener(new TimeRunner.OnTimeListener() { @@ -386,30 +647,8 @@ public class GalleryView extends GLView { @Override public void onEnd() { scrollXOffset = 0; - - ShowItem showItem; - showItem = showItems[PRE_TARGET_INDEX]; - if (showItem != null) - showItem.recycle(); - showItems[PRE_TARGET_INDEX] = showItems[CUR_TARGET_INDEX]; - showItems[CUR_TARGET_INDEX] = showItems[NEXT_TARGET_INDEX]; - showItems[NEXT_TARGET_INDEX] = null; - // adjust rect - showItem = showItems[PRE_TARGET_INDEX]; - if (showItem != null) { - showItem.mRect.offset(-mWidth, 0); - } - showItem = showItems[CUR_TARGET_INDEX]; - if (showItem != null) { - showItem.mRect.offset(-mWidth, 0); - } - - mCurIndex++; - setState(); - loadImage(mCurIndex+1, NEXT_TARGET_INDEX); - + goToNextPage(); mScrollState = SCROLL_NONE; - invalidate(); } }); mReturnTimeRunner.setOnTimerListener(new TimeRunner.OnTimeListener() { @@ -424,15 +663,48 @@ public class GalleryView extends GLView { }); } + private boolean isInArea(int[] area, int x, int y) { + if (area.length != 4) + throw new IllegalArgumentException( + "area's length should be 4, but it's length is " + area.length); + if (x >= area[0] && x < area[2] && y >= area[1] && y < area[3]) + return true; + else + return false; + } + @Override public boolean onSingleTapUp(float x, float y) { - // TODO Auto-generated method stub + if (mScrollState != SCROLL_NONE || mShowTapAreaTurn) + return false; + + if (isInArea(leftArea, (int)x, (int)y)) { + // TODO goto bottom first the to pre page + resetSizePosition(PRE_TARGET_INDEX); + if (!goToPrePage() && mOnEdgeListener != null) + mOnEdgeListener.onFirstPageEdge(); + } else if (isInArea(topArea, (int)x, (int)y)) { + zoom(true); + } else if (isInArea(rightArea, (int)x, (int)y)) { + // TODO goto bottom first the to pre page + resetSizePosition(NEXT_TARGET_INDEX); + if (!goToNextPage() && mOnEdgeListener != null) + mOnEdgeListener.onLastPageEdge(); + } else if (isInArea(bottomArea, (int)x, (int)y)) { + zoom(false); + } else if (isInArea(centerArea, (int)x, (int)y)) { + mShowTapArea = true; + mShowTapAreaTurn = true; + invalidate(); + } else { + // Can't catch tap + } + return true; } - + @Override public boolean onDoubleTap(float x, float y) { - // TODO Auto-generated method stub return true; } @@ -442,6 +714,9 @@ public class GalleryView extends GLView { return this.onScroll(dx, dy, totalX, totalY); } + /** + * dx 和 totalX 符号相反,为啥 + */ @Override public boolean onScroll(float dx, float dy, float totalX, float totalY) { @@ -455,7 +730,6 @@ public class GalleryView extends GLView { case SCROLL_ANIME_RIGHT: return false; case SCROLL_NONE: - //Image image = null; boolean changePage = false; Rect rect = null; @@ -464,30 +738,41 @@ public class GalleryView extends GLView { changePage = true; else{ rect = curShowItem.mRect; - if ((dx < 0 && rect.left >= 0) || (dx > 0 && rect.right <= mWidth)) + if ( Math.abs(totalX/totalY) > 1 && ((totalX > CHANGE_PAGE_OFFSET && dx < 0 && rect.left >= 0) + || (totalX < -CHANGE_PAGE_OFFSET && dx > 0 && rect.right <= mWidth))) changePage = true; } - if (changePage) { // If change page if (dx < 0) { // Go to left - if ((mState & STATE_FIRST) == 0) { // Not first page + if (!isFirstPage()) { // Not first page + scrollXOffset = 0; mScrollState = SCROLL_LEFT; resetSizePosition(PRE_TARGET_INDEX); - } else if (mShowEdegTip) { // First page - mShowEdegTip = false; - Log.d(TAG, "First page"); + } else { + changePage = false; + if (mShowEdegTip) { // First page + mShowEdegTip = false; + if (mOnEdgeListener != null) + mOnEdgeListener.onFirstPageEdge(); + } } } else { // Go to righ - if ((mState & STATE_LAST) == 0) { // Not last page + if (!isLastPage()) { // Not last page + scrollXOffset = 0; mScrollState = SCROLL_RIGHT; resetSizePosition(NEXT_TARGET_INDEX); - } else if (mShowEdegTip) { // last page - mShowEdegTip = false; - Log.d(TAG, "Last page"); + } else { + changePage = false; + if (mShowEdegTip) { // last page + mShowEdegTip = false; + if (mOnEdgeListener != null) + mOnEdgeListener.onLastPageEdge(); + } } } - } else { // Move cur image + } + if (!changePage){ // Move cur image int actDx = -(int)dx; int actDy = -(int)dy; if (rect.width() <= mWidth) @@ -502,13 +787,19 @@ public class GalleryView extends GLView { break; case SCROLL_LEFT: + scrollXOffset -= dx; + if (scrollXOffset <= 0) { + scrollXOffset = 0; + mScrollState = SCROLL_NONE; + } + break; + case SCROLL_RIGHT: scrollXOffset -= dx; - // adjust - if ((mState & STATE_FIRST) != 0 && scrollXOffset > 0) - scrollXOffset = 0; - if ((mState & STATE_LAST) != 0 && scrollXOffset < 0) + if (scrollXOffset >= 0) { scrollXOffset = 0; + mScrollState = SCROLL_NONE; + } break; } @@ -560,7 +851,6 @@ public class GalleryView extends GLView { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - // TODO Auto-generated method stub return true; } @@ -617,13 +907,15 @@ public class GalleryView extends GLView { @Override public void onDown(float x, float y) { - // TODO Auto-generated method stub - + mShowTapArea = false; + invalidate(); } @Override public void onUp() { mShowEdegTip = true; + if (!mShowTapArea) + mShowTapAreaTurn = false; } // *** TimeRunner *** // @@ -652,13 +944,19 @@ public class GalleryView extends GLView { }; } + /** + * If side is shorter then parent's, make it in parent's center + * If side is longer then parent's, make sure it fill parent + * + * @param showItem + */ public void adjustPosition(ShowItem showItem) { Rect rect = showItem.mRect; int showWidth = rect.width(); int showHeight = rect.height(); int sumXOffset; - int sumYOffset = 0; // TODO + int sumYOffset = 0; int targetIndex = getTargetIndex(showItem); switch (targetIndex) { @@ -841,10 +1139,18 @@ public class GalleryView extends GLView { load(str); } + public Text(String str, float size, int color) { + load(str, size, color); + } + public void load(String str) { + load(str, 100, -1); + } + + public void load(String str, float size, int color) { if (mTexture != null) recycle(); - mTexture = StringTexture.newInstance(str, 100, 0xffffffff); + mTexture = StringTexture.newInstance(str, size, color); width = mTexture.getWidth(); height = mTexture.getHeight(); } diff --git a/src/com/hippo/ehviewer/gallery/data/ImageSet.java b/src/com/hippo/ehviewer/gallery/data/ImageSet.java index 110113ca9..ced699f0f 100644 --- a/src/com/hippo/ehviewer/gallery/data/ImageSet.java +++ b/src/com/hippo/ehviewer/gallery/data/ImageSet.java @@ -108,7 +108,7 @@ public class ImageSet { File file = new File(mFolder, fileName); try { BitmapFactory.Options opt = new BitmapFactory.Options(); - opt.inPreferredConfig = Bitmap.Config.RGB_565; + opt.inPreferredConfig = Bitmap.Config.ARGB_8888; FileInputStream fis = new FileInputStream(file); bmp = BitmapFactory.decodeStream(fis, null, opt); fis.close(); diff --git a/src/com/hippo/ehviewer/gallery/glrenderer/GLPaint.java b/src/com/hippo/ehviewer/gallery/glrenderer/GLPaint.java index f741efc19..bee1a1d8e 100644 --- a/src/com/hippo/ehviewer/gallery/glrenderer/GLPaint.java +++ b/src/com/hippo/ehviewer/gallery/glrenderer/GLPaint.java @@ -21,7 +21,14 @@ import junit.framework.Assert; public class GLPaint { private float mLineWidth = 1f; private int mColor = 0; - + + public GLPaint() {} + + public GLPaint(int color, float width) { + setColor(color); + setLineWidth(width); + } + public void setColor(int color) { mColor = color; } diff --git a/src/com/hippo/ehviewer/gallery/ui/GLRootView.java b/src/com/hippo/ehviewer/gallery/ui/GLRootView.java index 73d7fc02b..716cae4b6 100644 --- a/src/com/hippo/ehviewer/gallery/ui/GLRootView.java +++ b/src/com/hippo/ehviewer/gallery/ui/GLRootView.java @@ -110,7 +110,7 @@ public class GLRootView extends GLSurfaceView private long mLastDrawFinishTime; private boolean mInDownState = false; - private boolean mFirstDraw = true; + //private boolean mFirstDraw = true; public GLRootView(Context context) { this(context, null); @@ -349,7 +349,7 @@ public class GLRootView extends GLSurfaceView } finally { mRenderLock.unlock(); } - +/* // We put a black cover View in front of the SurfaceView and hide it // after the first draw. This prevents the SurfaceView being transparent // before the first draw. @@ -363,7 +363,7 @@ public class GLRootView extends GLSurfaceView cover.setVisibility(GONE); } }); - } + }*/ } private void onDrawFrameLocked(GL10 gl) { diff --git a/src/com/hippo/ehviewer/util/Config.java b/src/com/hippo/ehviewer/util/Config.java index df7c8724e..d97180421 100644 --- a/src/com/hippo/ehviewer/util/Config.java +++ b/src/com/hippo/ehviewer/util/Config.java @@ -25,6 +25,8 @@ public class Config { private static final String AUTO_PAGE_CACHE = "preference_auto_page_cache"; private static final String PAGE_SCALING = "preference_page_scaling"; private static final String PAGE_SCALING_DEFAULT = "3"; + private static final String START_POSITION = "preference_start_position"; + private static final String START_POSITION_DEFAULT = "1"; private static final String SCREEN_ORI = "preference_screen_ori"; private static final String SCREEN_ORI_DEFAULT = "0"; private static final String DOWNLOAD_PATH = "preference_download_path"; @@ -34,8 +36,6 @@ public class Config { private static Context mContext; private static SharedPreferences mConfigPre; - - private static final String EMSG = "Please init Config first."; /** * Init Config @@ -68,9 +68,6 @@ public class Config { * @return True if allowed */ public static boolean isAllowed() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } return mConfigPre.getBoolean(KEY_ALLOWED, false); } @@ -78,9 +75,6 @@ public class Config { * Allowed the appliation to launch */ public static void allowed() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } mConfigPre.edit().putBoolean(KEY_ALLOWED, true).apply(); } @@ -90,9 +84,6 @@ public class Config { * @return */ public static boolean isFirstTime() { - if (!mInit) { - throw new IllegalStateException(); - } return mConfigPre.getBoolean(KEY_FIRST, true); } @@ -144,9 +135,6 @@ public class Config { * @return */ public static int getPageDiskCacheSize() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } try { return Integer.parseInt(mConfigPre.getString(PAGE_CACHE, PAGE_CACHE_DEFAULT)); } catch (Exception e) { @@ -156,16 +144,10 @@ public class Config { } public static boolean isAutoPageCache() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } return mConfigPre.getBoolean(AUTO_PAGE_CACHE, false); } public static int getPageScalingMode() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } int pageScalingMode = 3; try { pageScalingMode = Integer.parseInt(mConfigPre.getString( @@ -177,10 +159,19 @@ public class Config { return pageScalingMode; } - public static int getScreenOriMode() { - if (!mInit) { - throw new IllegalStateException(EMSG); + public static int getStartPosition() { + int startPosition = 1; + try { + startPosition = Integer.parseInt(mConfigPre.getString( + START_POSITION, START_POSITION_DEFAULT)); + } catch (Exception e) { + mConfigPre.edit().putString(START_POSITION, START_POSITION_DEFAULT) + .apply(); } + return startPosition; + } + + public static int getScreenOriMode() { int screenOriMode = 0; try { screenOriMode = Integer.parseInt(mConfigPre.getString( diff --git a/src/com/hippo/ehviewer/util/TimeRunner.java b/src/com/hippo/ehviewer/util/TimeRunner.java index 1535d2a3f..9ded6f4a1 100644 --- a/src/com/hippo/ehviewer/util/TimeRunner.java +++ b/src/com/hippo/ehviewer/util/TimeRunner.java @@ -6,7 +6,7 @@ import android.os.Message; public abstract class TimeRunner { - private static final int INTERVAL = 1; + private static final int INTERVAL = 5; private static final int RUNNING = 0; private static final int START = 1;