-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
20 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 1 addition & 55 deletions
56
bannerview/src/main/java/com/zhpan/bannerview/utils/PositionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,8 @@ | ||
package com.zhpan.bannerview.utils; | ||
|
||
import com.zhpan.bannerview.constants.PageStyle; | ||
|
||
public class PositionUtils { | ||
|
||
public static int toUnrealPosition(boolean isCanLoop, int position, int pageSize, int pageStyle) { | ||
if (isCanLoop) { | ||
if (pageStyle == PageStyle.NORMAL) { | ||
return (position < pageSize) ? (++position) : pageSize; | ||
} else { | ||
return (position < pageSize) ? position + 2 : pageSize + 1; | ||
} | ||
} else { | ||
return position; | ||
} | ||
} | ||
|
||
public static int getRealPosition(boolean isCanLoop, int position, int pageSize) { | ||
int realPosition; | ||
if (pageSize <= 0) | ||
return 0; | ||
if (isCanLoop) { | ||
realPosition = (position - 1 + pageSize) % pageSize; | ||
} else { | ||
realPosition = (position + pageSize) % pageSize; | ||
} | ||
if (realPosition < 0) | ||
realPosition += pageSize; | ||
return realPosition; | ||
return isCanLoop ? (position - 1 + pageSize) % pageSize : (position + pageSize) % pageSize; | ||
} | ||
|
||
public static int getRealPosition(boolean isCanLoop, int position, int pageSize, int pageStyle) { | ||
if (isCanLoop) { | ||
if (pageStyle == PageStyle.NORMAL) { | ||
if (position == 0) { | ||
return pageSize - 1; | ||
} else if (position == pageSize + 1) { | ||
return 0; | ||
} else { | ||
return --position; | ||
} | ||
} else { | ||
if (position == 0) { | ||
return pageSize == 1 ? 0 : pageSize - 2; | ||
} else if (position == 1) { | ||
return pageSize - 1; | ||
} else if (position == pageSize + 3) { | ||
return 1; | ||
} else if (position == pageSize + 2) { | ||
return 0; | ||
} else { | ||
return position - 2; | ||
} | ||
} | ||
|
||
} else { | ||
return position; | ||
} | ||
} | ||
|
||
} |