转换部分java代码

old
zlj 5 years ago
parent 13e9fa78b3
commit 44e6210c38
  1. 2
      app/src/main/assets/litepal.xml
  2. 2
      app/src/main/java/com/novel/read/activity/NovelBookTypeListActivity.kt
  3. 6
      app/src/main/java/com/novel/read/fragment/BookFragment.kt
  4. 1
      app/src/main/java/com/novel/read/fragment/MoreFragment.kt
  5. 1
      app/src/main/java/com/novel/read/http/AccountManager.kt
  6. 43
      app/src/main/java/com/novel/read/model/db/BookRecordBean.java
  7. 17
      app/src/main/java/com/novel/read/model/db/BookRecordBean.kt
  8. 4
      app/src/main/java/com/novel/read/model/db/CollBookBean.java
  9. 2
      app/src/main/java/com/novel/read/model/db/DownloadTaskBean.java
  10. 42
      app/src/main/java/com/novel/read/model/db/SearchListTable.java
  11. 29
      app/src/main/java/com/novel/read/model/db/SearchListTable.kt
  12. 10
      app/src/main/java/com/novel/read/model/db/dbManage/BookManager.java
  13. 2
      app/src/main/java/com/novel/read/model/protocol/BookArticleResp.java
  14. 6
      app/src/main/java/com/novel/read/model/protocol/BookDetailResp.java
  15. 2
      app/src/main/java/com/novel/read/model/protocol/ChapterInfoPackage.kt
  16. 5
      app/src/main/java/com/novel/read/service/DownloadMessage.java
  17. 4
      app/src/main/java/com/novel/read/service/DownloadService.java
  18. 234
      app/src/main/java/com/novel/read/utlis/PermissionUtil.java
  19. 59
      app/src/main/java/com/novel/read/widget/RefreshLayout.java
  20. 2
      app/src/main/java/com/novel/read/widget/page/PageLoader.java
  21. 2
      app/src/main/java/com/novel/read/widget/page/PageView.java
  22. 4
      app/src/main/java/com/novel/read/widget/page/TxtPage.java
  23. 16
      app/src/main/java/com/novel/read/widget/page/anim/SimulationPageAnim.kt
  24. 8
      app/src/main/java/com/novel/read/widget/page/anim/SlidePageAnim.kt

@ -2,7 +2,7 @@
<litepal>
<dbname value="readDb" />
<version value="8" />
<version value="9" />
<list>
<!--搜索记录表-->

@ -58,7 +58,7 @@ class NovelBookTypeListActivity : NovelBaseActivity() {
refresh.setOnReloadingListener { this.getData() }
getData()
toolbar.title = mTitle
toolbar.setNavigationOnClickListener { view -> finish() }
toolbar.setNavigationOnClickListener { finish() }
}

@ -121,12 +121,12 @@ class BookFragment : NovelBaseFragment() {
}
true
}
tv_cancel.setOnClickListener { view ->
tv_cancel.setOnClickListener {
EventManager.instance.postEvent(HideBottomBarEvent(false))
updateBook(UpdateBookEvent())
}
tv_delete.setOnClickListener { view ->
tv_delete.setOnClickListener {
val deleteList = mAdapter.selectList
for (i in deleteList.indices) {
if (deleteList[i].isSaved) {
@ -140,7 +140,7 @@ class BookFragment : NovelBaseFragment() {
updateBook(UpdateBookEvent())
}
mAdapter.setOnItemClickListener { view, pos ->
mAdapter.setOnItemClickListener { _, _ ->
EventManager.instance.postEvent(
SwitchFragmentEvent()
)

@ -101,7 +101,6 @@ class MoreFragment : NovelBaseFragment() {
fragment.arguments = args
return fragment
}
}
override fun onDestroy() {

@ -42,7 +42,6 @@ import io.reactivex.schedulers.Schedulers
import okhttp3.MediaType
import okhttp3.RequestBody
import retrofit2.Callback
import java.util.Map
/**
* Created by zlj on 2017/2/14.

@ -1,43 +0,0 @@
package com.novel.read.model.db;
import org.litepal.crud.LitePalSupport;
import java.io.Serializable;
/**
* Created by newbiechen on 17-5-20.
*/
public class BookRecordBean extends LitePalSupport implements Serializable {
//所属的书的id
private String bookId;
//阅读到了第几章
private int chapter;
//当前的页码
private int pagePos;
public String getBookId() {
return bookId;
}
public void setBookId(String bookId) {
this.bookId = bookId;
}
public int getChapter() {
return chapter;
}
public void setChapter(int chapter) {
this.chapter = chapter;
}
public int getPagePos() {
return pagePos;
}
public void setPagePos(int pagePos) {
this.pagePos = pagePos;
}
}

@ -0,0 +1,17 @@
package com.novel.read.model.db
import org.litepal.crud.LitePalSupport
import java.io.Serializable
/**
* Created by zlj
*/
class BookRecordBean : LitePalSupport(), Serializable {
//所属的书的id
var bookId: String = ""
//阅读到了第几章
var chapter: Int = 0
//当前的页码
var pagePos: Int = 0
}

@ -14,9 +14,7 @@ import java.util.List;
*/
public class CollBookBean extends LitePalSupport implements Serializable {
public static final int STATUS_UNCACHE = 0; //未缓存
public static final int STATUS_CACHING = 1; //正在缓存
public static final int STATUS_CACHED = 2; //已经缓存
/**
* _id : 53663ae356bdc93e49004474
* title : 逍遥派

@ -7,7 +7,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* Created by newbiechen on 17-5-11.
* Created by zlj
*/
public class DownloadTaskBean extends LitePalSupport {
public static final int STATUS_LOADING = 1;

@ -1,42 +0,0 @@
package com.novel.read.model.db;
import androidx.annotation.Nullable;
import org.litepal.crud.LitePalSupport;
import java.io.Serializable;
/**
* create by zlj on 2019/6/19
* describe:
*/
public class SearchListTable extends LitePalSupport implements Serializable {
private String key;
private long saveTime;
public String getKey() {
return key == null ? "" : key;
}
public void setKey(String key) {
this.key = key;
}
public long getSaveTime() {
return saveTime;
}
public void setSaveTime(long saveTime) {
this.saveTime = saveTime;
}
@Override
public boolean equals(@Nullable Object obj) {
if (obj != null && obj.toString().equals(key)) {
return true;
}
return super.equals(obj);
}
}

@ -0,0 +1,29 @@
package com.novel.read.model.db
import org.litepal.crud.LitePalSupport
import java.io.Serializable
/**
* create by zlj on 2019/6/19
* describe:
*/
class SearchListTable : LitePalSupport(), Serializable {
var key: String = ""
var saveTime: Long = 0
override fun equals(other: Any?): Boolean {
return if (other != null && other.toString() == key) {
true
} else super.equals(other)
}
override fun hashCode(): Int {
var result = key.hashCode()
result = 31 * result + saveTime.hashCode()
return result
}
}

@ -53,7 +53,7 @@ public class BookManager {
File file = getBookFile(bookId, chapterName);
//TODO:数据加载默认utf-8(以后会增加判断),FileUtils采用Reader获取数据的,可能用byte会更好一点
char[] array = FileUtils.getFileContent(file).toCharArray();
WeakReference<char[]> charReference = new WeakReference<char[]>(array);
WeakReference<char[]> charReference = new WeakReference<>(array);
cache.size = array.length;
cache.data = charReference;
cacheMap.put(chapterName, cache);
@ -167,9 +167,9 @@ public class BookManager {
/**
* 创建或获取存储文件
* @param folderName
* @param fileName
* @return
* @param folderName 文件夹
* @param fileName 文件
* @return 文件
*/
public static File getBookFile(String folderName, String fileName){
return FileUtils.getFile(Constant.BOOK_CACHE_PATH + folderName
@ -186,7 +186,7 @@ public class BookManager {
* )
* @param folderName : bookId
* @param fileName: chapterName
* @return
* @return 是否被缓存过
*/
public static boolean isChapterCached(String folderName, String fileName){
File file = new File(Constant.BOOK_CACHE_PATH + folderName

@ -82,7 +82,7 @@ public class BookArticleResp implements Serializable {
return bookChapterBean;
}
public List<BookChapterBean> createChapterBean() {
private List<BookChapterBean> createChapterBean() {
List<BookChapterBean> mList = new ArrayList<>();
for (ArticleBean articleBean:getArticle()){
mList.add(new BookChapterBean(String.valueOf(articleBean.getId()),articleBean.getTitle()));

@ -182,7 +182,7 @@ public class BookDetailResp {
return collBookBean;
}
public CollBookBean createCollBookBean(){
private CollBookBean createCollBookBean(){
CollBookBean bean = new CollBookBean();
bean.setId(String.valueOf(getBook().getId()));
bean.setTitle(getBook().getTitle());
@ -190,14 +190,10 @@ public class BookDetailResp {
bean.setShortIntro(getBook().getDescription());
bean.setCover(getBook().getCover());
bean.setInclude_image(getBook().getInclude_image());
// bean.setHasCp(getBook().isHasCp());
// bean.setLatelyFollower(getBook().getLatelyFollower());
// bean.setRetentionRatio(Double.parseDouble(getBook().getRetentionRatio()));
if (getLast_article()!=null){
bean.setUpdated(String.valueOf(getLast_article().getCreate_time()));
bean.setLastChapter(getLast_article().getTitle());
}
// bean.setChaptersCount(getBook().getChaptersCount());
return bean;
}
}

@ -6,7 +6,7 @@ import java.io.Serializable
class ChapterInfoPackage : Serializable {
var article: List<ChapterInfoBean>? = null
var article: List<ChapterInfoBean> = ArrayList()
}

@ -2,11 +2,6 @@ package com.novel.read.service;
import com.mango.mangolib.event.BaseEvent;
/**
* Created by newbiechen on 17-5-10.
* 下载进度事件
*/
public class DownloadMessage extends BaseEvent {
public String message;

@ -34,10 +34,6 @@ import java.util.concurrent.Executors;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
/**
* Created by newbiechen on 17-5-10.
*/
public class DownloadService extends BaseService {
private static final String TAG = "DownloadService";
//加载状态

@ -11,150 +11,118 @@ import com.novel.read.R;
import java.util.ArrayList;
import java.util.List;
/**
* Created by loki
* Date 2018/9/3.
*/
public class PermissionUtil {
private static PermissionUtil permissionUtil = null;
private static List<String> mListPermissions;
private static String[] PERMISSIONS_LIST = {
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE,
// Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, // not work
// Manifest.permission.WRITE_SETTINGS, // not grant
// Manifest.permission.GET_TASKS // dep
};
private static final String PERMISSIONS_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE;
private static final String PERMISSIONS_PHONE = Manifest.permission.READ_PHONE_STATE;
private static final String PERMISSIONS_SETTINGS = Manifest.permission.WRITE_SETTINGS;
/**
* 添加权限
* author LH
* data 2016/7/27 11:27
*/
private void addAllPermissions(List<String> mListPermissions) {
mListPermissions.add(PERMISSIONS_STORAGE);
// mListPermissions.add(PERMISSIONS_PHONE);
}
/**
* 单例模式初始化
* author LH
* data 2016/7/27 11:27
*/
public static PermissionUtil getInstance() {
if (permissionUtil == null) {
permissionUtil = new PermissionUtil();
}
return permissionUtil;
}
/**
* 判断当前为M以上版本
* author LH
* data 2016/7/27 11:29
*/
public boolean isOverMarshmallow() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
/**
* 获得没有授权的权限
* author LH
* data 2016/7/27 11:46
*/
@TargetApi(value = Build.VERSION_CODES.M)
public List<String> findDeniedPermissions(Activity activity, List<String> permissions) {
List<String> denyPermissions = new ArrayList<>();
for (String value : permissions) {
if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) {
denyPermissions.add(value);
}
private static PermissionUtil permissionUtil = null;
private static List<String> mListPermissions;
private static String[] PERMISSIONS_LIST = {
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE,
};
private static final String PERMISSIONS_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE;
private static final String PERMISSIONS_PHONE = Manifest.permission.READ_PHONE_STATE;
private static final String PERMISSIONS_SETTINGS = Manifest.permission.WRITE_SETTINGS;
private void addAllPermissions(List<String> mListPermissions) {
mListPermissions.add(PERMISSIONS_STORAGE);
}
return denyPermissions;
}
/**
* 获取所有权限
* author LH
* data 2016/7/27 13:37
*/
@TargetApi(value = Build.VERSION_CODES.M)
public void requestPermissions(Activity activity, int requestCode, PermissionCallBack permissionCallBack) {
if (mListPermissions == null) {
mListPermissions = new ArrayList<>();
addAllPermissions(mListPermissions);
public static PermissionUtil getInstance() {
if (permissionUtil == null) {
permissionUtil = new PermissionUtil();
}
return permissionUtil;
}
if (!isOverMarshmallow()) {
permissionCallBack.onPermissionSuccess();
return;
public boolean isOverMarshmallow() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
mListPermissions = findDeniedPermissions(activity, mListPermissions);
if (mListPermissions != null && mListPermissions.size() > 0) {
activity.requestPermissions(mListPermissions.toArray(new String[mListPermissions.size()]),
requestCode);
} else {
permissionCallBack.onPermissionSuccess();
@TargetApi(value = Build.VERSION_CODES.M)
public List<String> findDeniedPermissions(Activity activity, List<String> permissions) {
List<String> denyPermissions = new ArrayList<>();
for (String value : permissions) {
if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) {
denyPermissions.add(value);
}
}
return denyPermissions;
}
}
public void requestResult(Activity activity, String[] permissions, int[] grantResults, PermissionCallBack permissionCallBack) {
mListPermissions = new ArrayList<>();
ArrayList<String> noPermissions = new ArrayList<>();
ArrayList<String> rejectPermissons = new ArrayList<>();
for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
if (isOverMarshmallow()) {
boolean isShould = activity.shouldShowRequestPermissionRationale(permissions[i]);
mListPermissions.add(permissions[i]);
if (isShould) {
noPermissions.add(permissions[i]);
} else {
rejectPermissons.add(permissions[i]);
}
@TargetApi(value = Build.VERSION_CODES.M)
public void requestPermissions(Activity activity, int requestCode, PermissionCallBack permissionCallBack) {
if (mListPermissions == null) {
mListPermissions = new ArrayList<>();
addAllPermissions(mListPermissions);
}
if (!isOverMarshmallow()) {
permissionCallBack.onPermissionSuccess();
return;
}
mListPermissions = findDeniedPermissions(activity, mListPermissions);
if (mListPermissions != null && mListPermissions.size() > 0) {
activity.requestPermissions(mListPermissions.toArray(new String[mListPermissions.size()]),
requestCode);
} else {
permissionCallBack.onPermissionSuccess();
}
}
}
if (noPermissions.size() > 0) {
permissionCallBack.onPermissionFail();
} else if (rejectPermissons.size() > 0) {
ArrayList<String> permissonsList = new ArrayList<>();
for (int i = 0; i < rejectPermissons.size(); i++) {
String strPermissons = rejectPermissons.get(i);
if (PERMISSIONS_STORAGE.equals(strPermissons)) {
permissonsList.add("storage");
} else if (PERMISSIONS_PHONE.equals(strPermissons)) {
permissonsList.add("phone");
public void requestResult(Activity activity, String[] permissions, int[] grantResults, PermissionCallBack permissionCallBack) {
mListPermissions = new ArrayList<>();
ArrayList<String> noPermissions = new ArrayList<>();
ArrayList<String> rejectPermissons = new ArrayList<>();
for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
if (isOverMarshmallow()) {
boolean isShould = activity.shouldShowRequestPermissionRationale(permissions[i]);
mListPermissions.add(permissions[i]);
if (isShould) {
noPermissions.add(permissions[i]);
} else {
rejectPermissons.add(permissions[i]);
}
}
}
}
if (noPermissions.size() > 0) {
permissionCallBack.onPermissionFail();
} else if (rejectPermissons.size() > 0) {
ArrayList<String> permissonsList = new ArrayList<>();
for (int i = 0; i < rejectPermissons.size(); i++) {
String strPermissons = rejectPermissons.get(i);
if (PERMISSIONS_STORAGE.equals(strPermissons)) {
permissonsList.add("storage");
} else if (PERMISSIONS_PHONE.equals(strPermissons)) {
permissonsList.add("phone");
}
}
String strPermissons = permissonsList.toString();
strPermissons = strPermissons.replace("[", "");
strPermissons = strPermissons.replace("]", "");
strPermissons = strPermissons.replace(",", "、");
String strAppName = activity.getString(R.string.app_name);
String strMessage = "permission";
strMessage = String.format(strMessage, strAppName, strPermissons, "\"");
permissionCallBack.onPermissionReject(strMessage);
} else {
permissionCallBack.onPermissionSuccess();
}
}
String strPermissons = permissonsList.toString();
strPermissons = strPermissons.replace("[", "");
strPermissons = strPermissons.replace("]", "");
strPermissons = strPermissons.replace(",", "、");
String strAppName = activity.getString(R.string.app_name);
String strMessage = "permission";
strMessage = String.format(strMessage, strAppName, strPermissons, "\"");
permissionCallBack.onPermissionReject(strMessage);
} else {
permissionCallBack.onPermissionSuccess();
}
}
public interface PermissionCallBack {
void onPermissionSuccess();
public interface PermissionCallBack {
void onPermissionSuccess();
void onPermissionReject(String strMessage);
void onPermissionReject(String strMessage);
void onPermissionFail();
}
void onPermissionFail();
}
}

@ -36,11 +36,11 @@ public class RefreshLayout extends FrameLayout {
private int mStatus = 0;
public RefreshLayout(Context context) {
this(context,null);
this(context, null);
}
public RefreshLayout(Context context, AttributeSet attrs) {
this(context, attrs,0);
this(context, attrs, 0);
}
public RefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
@ -50,16 +50,16 @@ public class RefreshLayout extends FrameLayout {
initView();
}
private void initAttrs(AttributeSet attrs){
private void initAttrs(AttributeSet attrs) {
TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.RefreshLayout);
mEmptyViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_empty,R.layout.view_empty);
mErrorViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_error,R.layout.view_net_error);
mLoadingViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_loading,R.layout.view_loading);
mEmptyViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_empty, R.layout.view_empty);
mErrorViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_error, R.layout.view_net_error);
mLoadingViewId = typedArray.getResourceId(R.styleable.RefreshLayout_layout_refresh_loading, R.layout.view_loading);
typedArray.recycle();
}
private void initView(){
private void initView() {
//添加在empty、error、loading 情况下的布局
mEmptyView = inflateView(mEmptyViewId);
@ -73,7 +73,7 @@ public class RefreshLayout extends FrameLayout {
//设置监听器
mErrorView.setOnClickListener(
(view) -> {
if (mListener != null){
if (mListener != null) {
toggleStatus(STATUS_LOADING);
mListener.onReload();
}
@ -90,7 +90,7 @@ public class RefreshLayout extends FrameLayout {
@Override
public void onViewAdded(View child) {
super.onViewAdded(child);
if (getChildCount() == 4){
if (getChildCount() == 4) {
mContentView = child;
}
}
@ -131,43 +131,43 @@ public class RefreshLayout extends FrameLayout {
super.addView(child, index, params);
}
public void showLoading(){
if (mStatus != STATUS_LOADING){
public void showLoading() {
if (mStatus != STATUS_LOADING) {
toggleStatus(STATUS_LOADING);
}
}
public void showFinish(){
if (mStatus == STATUS_LOADING){
public void showFinish() {
if (mStatus == STATUS_LOADING) {
toggleStatus(STATUS_FINISH);
}
}
public void showError(){
if (mStatus != STATUS_ERROR){
public void showError() {
if (mStatus != STATUS_ERROR) {
toggleStatus(STATUS_ERROR);
}
}
public void showEmpty(){
if (mStatus != STATUS_EMPTY){
public void showEmpty() {
if (mStatus != STATUS_EMPTY) {
toggleStatus(STATUS_EMPTY);
}
}
//视图根据状态切换
private void toggleStatus(int status){
switch (status){
private void toggleStatus(int status) {
switch (status) {
case STATUS_LOADING:
mLoadingView.setVisibility(VISIBLE);
mEmptyView.setVisibility(GONE);
mErrorView.setVisibility(GONE);
if (mContentView != null){
if (mContentView != null) {
mContentView.setVisibility(GONE);
}
break;
case STATUS_FINISH:
if (mContentView != null){
if (mContentView != null) {
mContentView.setVisibility(VISIBLE);
}
mLoadingView.setVisibility(GONE);
@ -178,7 +178,7 @@ public class RefreshLayout extends FrameLayout {
mErrorView.setVisibility(VISIBLE);
mLoadingView.setVisibility(GONE);
mEmptyView.setVisibility(GONE);
if (mContentView != null){
if (mContentView != null) {
mContentView.setVisibility(GONE);
}
break;
@ -186,7 +186,7 @@ public class RefreshLayout extends FrameLayout {
mEmptyView.setVisibility(VISIBLE);
mErrorView.setVisibility(GONE);
mLoadingView.setVisibility(GONE);
if (mContentView != null){
if (mContentView != null) {
mContentView.setVisibility(GONE);
}
break;
@ -194,17 +194,12 @@ public class RefreshLayout extends FrameLayout {
mStatus = status;
}
protected int getStatus(){
return mStatus;
}
public void setOnReloadingListener(OnReloadingListener listener){
public void setOnReloadingListener(OnReloadingListener listener) {
mListener = listener;
}
private View inflateView(int id){
return LayoutInflater.from(mContext)
.inflate(id,this,false);
private View inflateView(int id) {
return LayoutInflater.from(mContext).inflate(id, this, false);
}
//数据存储
@ -255,7 +250,7 @@ public class RefreshLayout extends FrameLayout {
}
//添加错误重新加载的监听
public interface OnReloadingListener{
public interface OnReloadingListener {
void onReload();
}
}

@ -874,7 +874,7 @@ public abstract class PageLoader {
int para = mTextPara + (int) mTextPaint.getTextSize();
int titleInterval = mTitleInterval + (int) mTitlePaint.getTextSize();
int titlePara = mTitlePara + (int) mTextPaint.getTextSize();
String str = null;
String str;
//对标题进行绘制
for (int i = 0; i < mCurPage.titleLines; ++i) {

@ -24,8 +24,6 @@ import com.novel.read.widget.page.anim.SlidePageAnim;
*/
public class PageView extends View {
private final static String TAG = "BookPageWidget";
private int mViewWidth = 0; // 当前View的宽
private int mViewHeight = 0; // 当前View的高

@ -18,9 +18,7 @@ public class TxtPage {
return title == null ? "" : title;
}
public int getTitleLines() {
return titleLines;
}
public List<String> getLines() {
if (lines == null) {

@ -74,7 +74,7 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
override fun drawMove(canvas: Canvas) {
when (mDirection) {
PageAnimation.Direction.NEXT -> {
Direction.NEXT -> {
calcPoints()
drawCurrentPageArea(canvas, mCurBitmap, mPath0)
drawNextPageAreaAndShadow(canvas, mNextBitmap)
@ -108,13 +108,13 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
// dy 垂直方向滑动的距离,负值会使滚动向上滚动
if (isCancel) {
if (mCornerX > 0 && mDirection == PageAnimation.Direction.NEXT) {
if (mCornerX > 0 && mDirection == Direction.NEXT) {
dx = (mScreenWidth - mTouchX).toInt()
} else {
dx = -mTouchX.toInt()
}
if (mDirection != PageAnimation.Direction.NEXT) {
if (mDirection != Direction.NEXT) {
dx = (-(mScreenWidth + mTouchX)).toInt()
}
@ -124,7 +124,7 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
dy = -mTouchY.toInt() // 防止mTouchY最终变为0
}
} else {
if (mCornerX > 0 && mDirection == PageAnimation.Direction.NEXT) {
if (mCornerX > 0 && mDirection == Direction.NEXT) {
dx = -(mScreenWidth + mTouchX).toInt()
} else {
dx = (mScreenWidth - mTouchX + mScreenWidth).toInt()
@ -142,14 +142,14 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
super.setDirection(direction)
when (direction) {
PageAnimation.Direction.PRE ->
Direction.PRE ->
//上一页滑动不出现对角
if (mStartX > mScreenWidth / 2) {
calcCornerXY(mStartX, mScreenHeight.toFloat())
} else {
calcCornerXY(mScreenWidth - mStartX, mScreenHeight.toFloat())
}
PageAnimation.Direction.NEXT -> if (mScreenWidth / 2 > mStartX) {
Direction.NEXT -> if (mScreenWidth / 2 > mStartX) {
calcCornerXY(mScreenWidth - mStartX, mStartY)
}
}
@ -163,11 +163,11 @@ class SimulationPageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListe
override fun setTouchPoint(x: Float, y: Float) {
super.setTouchPoint(x, y)
//触摸y中间位置吧y变成屏幕高度
if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight * 2 / 3 || mDirection == PageAnimation.Direction.PRE) {
if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight * 2 / 3 || mDirection == Direction.PRE) {
mTouchY = mScreenHeight.toFloat()
}
if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight / 2 && mDirection == PageAnimation.Direction.NEXT) {
if (mStartY > mScreenHeight / 3 && mStartY < mScreenHeight / 2 && mDirection == Direction.NEXT) {
mTouchY = 1f
}
}

@ -26,9 +26,9 @@ class SlidePageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListener)
}
override fun drawMove(canvas: Canvas) {
var dis = 0
var dis: Int
when (mDirection) {
PageAnimation.Direction.NEXT -> {
Direction.NEXT -> {
//左半边的剩余区域
dis = (mScreenWidth - mStartX + mTouchX).toInt()
if (dis > mScreenWidth) {
@ -68,9 +68,9 @@ class SlidePageAnim(w: Int, h: Int, view: View, listener: OnPageChangeListener)
override fun startAnim() {
super.startAnim()
var dx = 0
val dx: Int
when (mDirection) {
PageAnimation.Direction.NEXT -> if (isCancel) {
Direction.NEXT -> if (isCancel) {
var dis = (mScreenWidth - mStartX + mTouchX).toInt()
if (dis > mScreenWidth) {
dis = mScreenWidth

Loading…
Cancel
Save