Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
567b0a2c19 | ||
|
|
5e28481684 | ||
|
|
90ed3d40f3 | ||
|
|
366285f625 | ||
|
|
7945b0facd | ||
|
|
556429a4d6 | ||
|
|
601d426721 | ||
|
|
aa3d3ca57c | ||
|
|
471cf5df85 | ||
|
|
177920a1eb |
No files matched your search
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hippo.ehviewer"
|
||||
android:versionCode="7"
|
||||
android:versionName="0.3.2" >
|
||||
android:versionCode="9"
|
||||
android:versionName="0.3.4" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hippo.ehviewer"
|
||||
android:versionCode="7"
|
||||
android:versionName="0.3.2" >
|
||||
android:versionCode="9"
|
||||
android:versionName="0.3.4" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
|
||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
@@ -1,69 +1,69 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fitsSystemWindows="true" >
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/manga_detail_scrollview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fadingEdge="vertical"
|
||||
android:scrollbars="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/manga_detail"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<com.hippo.ehviewer.view.OlImageView
|
||||
android:id="@+id/detail_cover"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_normal"
|
||||
layout="@layout/detail_normal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_offensive"
|
||||
layout="@layout/detail_offensive"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_pining"
|
||||
layout="@layout/detail_pining"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/detail_wait"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/detail_refresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:onClick="buttonRefresh"
|
||||
android:text="@string/refresh"
|
||||
android:visibility="gone" />
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fitsSystemWindows="true" >
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/manga_detail_scrollview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fadingEdge="vertical"
|
||||
android:scrollbars="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/manga_detail"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<com.hippo.ehviewer.view.OlImageView
|
||||
android:id="@+id/detail_cover"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_normal"
|
||||
layout="@layout/detail_normal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_offensive"
|
||||
layout="@layout/detail_offensive"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_pining"
|
||||
layout="@layout/detail_pining"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/detail_wait"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/detail_refresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:onClick="buttonRefresh"
|
||||
android:text="@string/refresh"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -1,86 +1,86 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/detail_type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_uploader"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_posted"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_pages"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_language"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/detail_rate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation = "horizontal"
|
||||
android:layout_marginBottom="8dp" >
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_average"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_people"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tags_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation = "vertical"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_marginBottom="8dp" >
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_read"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:text="@string/detail_button_read"
|
||||
android:onClick="buttonRead" />
|
||||
|
||||
<include
|
||||
layout="@layout/page_list"
|
||||
android:id="@+id/page_list"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/detail_type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_uploader"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_posted"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_pages"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_language"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/detail_rate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation = "horizontal"
|
||||
android:layout_marginBottom="8dp" >
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_average"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detail_people"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tags_layout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation = "vertical"
|
||||
android:layout_marginLeft="18dp"
|
||||
android:layout_marginRight="18dp"
|
||||
android:layout_marginBottom="8dp" >
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_read"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:text="@string/detail_button_read"
|
||||
android:onClick="buttonRead" />
|
||||
|
||||
<include
|
||||
layout="@layout/page_list"
|
||||
android:id="@+id/page_list"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,4 +1,5 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:auto="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginBottom="12dp"
|
||||
@@ -13,7 +14,8 @@
|
||||
android:id="@+id/paper_list_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center" >
|
||||
android:layout_gravity="center"
|
||||
auto:baseLine="bottom">
|
||||
</com.hippo.ehviewer.widget.AutoWrapLayout>
|
||||
|
||||
<ProgressBar
|
||||
|
||||
@@ -1,71 +1,81 @@
|
||||
Version 0.3.2 (2014-03-23)
|
||||
* 添加启动界面
|
||||
* 添加自动更新功能
|
||||
* 添加检测登陆状态按钮
|
||||
* 添加漫画标签显示
|
||||
* 优化下拉控件
|
||||
* 优化侧边栏
|
||||
* 优化漫画列表
|
||||
* 优化预览列表,屏幕颠倒可重新布局
|
||||
* 列表标题显示内容
|
||||
* 后台检查登陆状态
|
||||
* 设置中添加移除所有应用通知项
|
||||
* 修正清除缓存错误
|
||||
* 修正 game 拼写为 gmae 错误
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.3.1 (2014-03-14)
|
||||
* 修正有时点击通知栏无法进入下载界面
|
||||
|
||||
Version 0.3.0 (2014-03-14)
|
||||
* 完成搜索标签功能
|
||||
* 初步完成下载功能
|
||||
* 修正由收藏进入漫画详情无封面显示
|
||||
* 修正漫画详情无标题显示
|
||||
* 修正匹配宽度 y 轴偏移错误
|
||||
* 加强列表显示稳定性
|
||||
* 优化列表流畅度
|
||||
* 微调界面
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.2.2 (2014-03-06)
|
||||
* 放弃 4.0 以下系统
|
||||
* 修复多个关键字搜索错误
|
||||
* 修复列表跳转功能
|
||||
* 添加状态栏简易搜索
|
||||
* 微调界面
|
||||
* 更改筛选为搜索
|
||||
* 漫画详情页标题改为该漫画的 gid
|
||||
* 漫画详情页添加收藏按钮
|
||||
* 修正页面默认缩放错误
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.2.1 (2014-03-02)
|
||||
* 漫画详情页添加类型与上传者信息
|
||||
|
||||
Version 0.2 (2014-03-02)
|
||||
* 优化网络连接
|
||||
* 添加网络状态检查
|
||||
* 添加是否能连接到主机检查
|
||||
* 添加屏幕方向设置
|
||||
* 添加警告提示
|
||||
* 添加作者联系入口
|
||||
* 添加感谢信息
|
||||
* 添加双击返回键退出功能
|
||||
* 添加 exhentai 选项
|
||||
* 添加漫画详情页面缓存
|
||||
* 移除容易大量产生的 Toast
|
||||
* 改善列表显示
|
||||
* 完善列表跳页功能
|
||||
* 替换未授权资源
|
||||
* 更改过滤为筛选
|
||||
* 修正预览导航栏
|
||||
* 修正平均得分显示错误
|
||||
* 修正中文搜索失败
|
||||
* 修正屏幕重新亮起后页面纯白问题
|
||||
* 修正从中间读取页面无法查看上一页问题
|
||||
* 修正页面无限重试问题
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.1 (2014-02-24)
|
||||
* 公开
|
||||
Version 0.3.4 (2014-03-28)
|
||||
* 完善用于显示预览图的控件
|
||||
* 显示漫画标签组名
|
||||
* 自动更新改为每日检查
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.3.3 (2014-03-23)
|
||||
* 测试自动更新
|
||||
* 修正没有时更新显示主机错误问题
|
||||
|
||||
Version 0.3.2 (2014-03-23)
|
||||
* 添加启动界面
|
||||
* 添加自动更新功能
|
||||
* 添加检测登陆状态按钮
|
||||
* 添加漫画标签显示
|
||||
* 优化下拉控件
|
||||
* 优化侧边栏
|
||||
* 优化漫画列表
|
||||
* 优化预览列表,屏幕颠倒可重新布局
|
||||
* 列表标题显示内容
|
||||
* 后台检查登陆状态
|
||||
* 设置中添加移除所有应用通知项
|
||||
* 修正清除缓存错误
|
||||
* 修正 game 拼写为 gmae 错误
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.3.1 (2014-03-14)
|
||||
* 修正有时点击通知栏无法进入下载界面
|
||||
|
||||
Version 0.3.0 (2014-03-14)
|
||||
* 完成搜索标签功能
|
||||
* 初步完成下载功能
|
||||
* 修正由收藏进入漫画详情无封面显示
|
||||
* 修正漫画详情无标题显示
|
||||
* 修正匹配宽度 y 轴偏移错误
|
||||
* 加强列表显示稳定性
|
||||
* 优化列表流畅度
|
||||
* 微调界面
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.2.2 (2014-03-06)
|
||||
* 放弃 4.0 以下系统
|
||||
* 修复多个关键字搜索错误
|
||||
* 修复列表跳转功能
|
||||
* 添加状态栏简易搜索
|
||||
* 微调界面
|
||||
* 更改筛选为搜索
|
||||
* 漫画详情页标题改为该漫画的 gid
|
||||
* 漫画详情页添加收藏按钮
|
||||
* 修正页面默认缩放错误
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.2.1 (2014-03-02)
|
||||
* 漫画详情页添加类型与上传者信息
|
||||
|
||||
Version 0.2 (2014-03-02)
|
||||
* 优化网络连接
|
||||
* 添加网络状态检查
|
||||
* 添加是否能连接到主机检查
|
||||
* 添加屏幕方向设置
|
||||
* 添加警告提示
|
||||
* 添加作者联系入口
|
||||
* 添加感谢信息
|
||||
* 添加双击返回键退出功能
|
||||
* 添加 exhentai 选项
|
||||
* 添加漫画详情页面缓存
|
||||
* 移除容易大量产生的 Toast
|
||||
* 改善列表显示
|
||||
* 完善列表跳页功能
|
||||
* 替换未授权资源
|
||||
* 更改过滤为筛选
|
||||
* 修正预览导航栏
|
||||
* 修正平均得分显示错误
|
||||
* 修正中文搜索失败
|
||||
* 修正屏幕重新亮起后页面纯白问题
|
||||
* 修正从中间读取页面无法查看上一页问题
|
||||
* 修正页面无限重试问题
|
||||
* 修正其他问题
|
||||
|
||||
Version 0.1 (2014-02-24)
|
||||
* 公开
|
||||
@@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<declare-styleable name="SuperImageView">
|
||||
<declare-styleable name="SuperImageView">
|
||||
<!-- Sets a drawable as the content of this ImageView. -->
|
||||
<attr name="src" format="reference|color" />
|
||||
<!-- Controls how the image should be resized or moved to match the size
|
||||
of this ImageView. -->
|
||||
<attr name="scaleType">
|
||||
<enum name="matrix" value="0" />
|
||||
<enum name="fitXY" value="1" /> <!-- error -->
|
||||
<enum name="fitXY" value="1" />
|
||||
<enum name="fitStart" value="2" />
|
||||
<enum name="fitCenter" value="3" />
|
||||
<enum name="fitEnd" value="4" />
|
||||
@@ -44,6 +44,12 @@
|
||||
<attr name="mask" format="reference" />
|
||||
</declare-styleable>
|
||||
|
||||
|
||||
<declare-styleable name="AutoWrapLayout">
|
||||
<attr name="baseLine">
|
||||
<enum name="top" value="0" />
|
||||
<enum name="center" value="1" />
|
||||
<enum name="bottom" value="2" />
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
|
||||
</resources>
|
||||
@@ -17,6 +17,7 @@ import com.hippo.ehviewer.dialog.DialogBuilder;
|
||||
import com.hippo.ehviewer.network.Downloader;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.EhClient;
|
||||
import com.hippo.ehviewer.util.Util;
|
||||
import com.hippo.ehviewer.view.AlertButton;
|
||||
|
||||
public class UpdateHelper {
|
||||
@@ -29,10 +30,16 @@ public class UpdateHelper {
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
public void autoCheckUpdate() {
|
||||
if (Config.getUpdateDate() < Util.getDate())
|
||||
checkUpdate();
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
EhClient.checkUpdate(new EhClient.OnCheckUpdateListener() {
|
||||
@Override
|
||||
public void onSuccess(String pageContext) {
|
||||
Config.setUpdateDate();
|
||||
String[] items = pageContext.split("\n");
|
||||
if (items.length > 3) {
|
||||
|
||||
@@ -69,15 +76,17 @@ public class UpdateHelper {
|
||||
}).create();
|
||||
if (!mActivity.isFinishing())
|
||||
dialog.show();
|
||||
} else if(pageContext.equals("none")) {
|
||||
if (listener != null)
|
||||
listener.onNoUpdate();
|
||||
} else if(pageContext.equals("error")){
|
||||
if (listener != null)
|
||||
listener.onFailure(R.string.em_request_error);
|
||||
} else {
|
||||
if (listener != null)
|
||||
listener.onFailure(R.string.em_host_error);
|
||||
if(pageContext.equals("none")) {
|
||||
if (listener != null)
|
||||
listener.onNoUpdate();
|
||||
} else if(pageContext.equals("error")){
|
||||
if (listener != null)
|
||||
listener.onFailure(R.string.em_request_error);
|
||||
} else {
|
||||
if (listener != null)
|
||||
listener.onFailure(R.string.em_host_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,388 +1,389 @@
|
||||
package com.hippo.ehviewer.activity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.hippo.ehviewer.BeautifyScreen;
|
||||
import com.hippo.ehviewer.DownloadInfo;
|
||||
import com.hippo.ehviewer.ListMangaDetail;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.dialog.DialogBuilder;
|
||||
import com.hippo.ehviewer.service.DownloadService;
|
||||
import com.hippo.ehviewer.service.DownloadServiceConnection;
|
||||
import com.hippo.ehviewer.util.Cache;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Download;
|
||||
import com.hippo.ehviewer.util.EhClient;
|
||||
import com.hippo.ehviewer.util.Favourite;
|
||||
import com.hippo.ehviewer.util.Util;
|
||||
import com.hippo.ehviewer.view.AlertButton;
|
||||
import com.hippo.ehviewer.view.DownloadItemLayout;
|
||||
import com.hippo.ehviewer.view.OlImageView;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
|
||||
public class DownloadActivity extends Activity {
|
||||
|
||||
private static final String TAG = "DownloadActivity";
|
||||
private static final String ACTION_UPDATE = "com.hippo.ehviewer.service.UPDATE";
|
||||
|
||||
private DownloadServiceConnection mServiceConn = new DownloadServiceConnection();
|
||||
|
||||
private List<DownloadInfo> mDownloadInfos;
|
||||
private DlAdapter mDlAdapter;
|
||||
private int longClickItemIndex;
|
||||
|
||||
private AlertDialog longClickDialog;
|
||||
|
||||
private AlertDialog setLongClickDialog() {
|
||||
return new DialogBuilder(this).setTitle(R.string.what_to_do)
|
||||
.setItems(R.array.download_item_long_click, new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1,
|
||||
int position, long arg3) {
|
||||
switch (position) {
|
||||
case 0: // Remove info item
|
||||
mServiceConn.getService().cancel(Download.getKey(longClickItemIndex));
|
||||
Download.remove(longClickItemIndex);
|
||||
mDlAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
case 1: // Remove info item
|
||||
mServiceConn.getService().cancel(Download.getKey(longClickItemIndex));
|
||||
mDlAdapter.notifyDataSetChanged();
|
||||
File dir = new File(Config.getDownloadPath(), Download.get(longClickItemIndex).title);
|
||||
try {
|
||||
Util.deleteContents(dir);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dir.delete();
|
||||
Download.remove(longClickItemIndex);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
longClickDialog.cancel();
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((AlertButton)v).dialog.dismiss();
|
||||
}
|
||||
}).create();
|
||||
}
|
||||
|
||||
private class DlAdapter extends BaseAdapter {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
public DlAdapter() {
|
||||
mInflater = LayoutInflater.from(DownloadActivity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mDownloadInfos.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int arg0) {
|
||||
return mDownloadInfos.get(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
DownloadInfo di= mDownloadInfos.get(position);
|
||||
if (convertView != null) {
|
||||
DownloadItemLayout view = (DownloadItemLayout)convertView;
|
||||
if (!view.gid.equals(di.gid)) {
|
||||
view.gid = di.gid;
|
||||
view.status = di.status;
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
view.isWait = false;
|
||||
|
||||
OlImageView thumb = (OlImageView)view
|
||||
.findViewById(R.id.thumb);
|
||||
thumb.setUrl(di.thumb);
|
||||
thumb.setKey(String.valueOf(di.gid));
|
||||
thumb.setCache(Cache.memoryCache, Cache.cpCache);
|
||||
thumb.loadImage(true);
|
||||
|
||||
TextView title = (TextView)view.findViewById(R.id.title);
|
||||
title.setText(di.title);
|
||||
|
||||
setDownloadInfo(view, di);
|
||||
} else if (view.status != di.status || view.isWait) {
|
||||
view.status = di.status;
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
view.isWait = false;
|
||||
|
||||
setDownloadInfo(view, di);
|
||||
} else if (view.status == DownloadInfo.DOWNLOADING &&
|
||||
(view.type != di.type
|
||||
|| view.lastStartIndex != di.lastStartIndex
|
||||
|| view.downloadSize != di.downloadSize)) {
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
|
||||
ProgressBar pb = (ProgressBar)view.findViewById(R.id.progressBar);
|
||||
TextView info = (TextView)view.findViewById(R.id.info);
|
||||
|
||||
if (di.type == DownloadInfo.DETAIL_URL) {
|
||||
pb.setIndeterminate(true);
|
||||
info.setText(R.string.downloading);
|
||||
} else {
|
||||
pb.setIndeterminate(false);
|
||||
pb.setMax(di.pageSum);
|
||||
pb.setProgress(di.lastStartIndex-1);
|
||||
StringBuilder sb = new StringBuilder(getString(R.string.downloading));
|
||||
sb.append(" ").append(di.lastStartIndex-1).append(" / ").append(di.pageSum).append("\n");
|
||||
if (di.totalSize != 0)
|
||||
sb.append(String.format("%.2f", di.downloadSize))
|
||||
.append(" / ").append(String.format("%.2f", di.totalSize)).append(" KB");
|
||||
info.setText(sb.toString());
|
||||
}
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
DownloadItemLayout view = (DownloadItemLayout)mInflater.inflate(R.layout.download_item, null);
|
||||
view.gid = di.gid;
|
||||
view.status = di.status;
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
view.isWait = false;
|
||||
|
||||
OlImageView thumb = (OlImageView)view
|
||||
.findViewById(R.id.thumb);
|
||||
thumb.setUrl(di.thumb);
|
||||
thumb.setKey(String.valueOf(di.gid));
|
||||
thumb.setCache(Cache.memoryCache, Cache.cpCache);
|
||||
thumb.loadImage(true);
|
||||
|
||||
TextView title = (TextView)view.findViewById(R.id.title);
|
||||
title.setText(di.title);
|
||||
|
||||
setDownloadInfo(view, di);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* For clickable button, when click change message to "Please wait", then when action over change message
|
||||
*
|
||||
* @param view
|
||||
* @param di
|
||||
* @param position
|
||||
*/
|
||||
private void setDownloadInfo(final DownloadItemLayout view, final DownloadInfo di) {
|
||||
final ProgressBar pb = (ProgressBar)view.findViewById(R.id.progressBar);
|
||||
final TextView info = (TextView)view.findViewById(R.id.info);
|
||||
final ImageView action = (ImageView)view.findViewById(R.id.action);
|
||||
|
||||
if (di.status == DownloadInfo.STOP) {
|
||||
pb.setVisibility(View.GONE);
|
||||
String meg = getString(R.string.not_started) + (di.type == DownloadInfo.DETAIL_URL ? ""
|
||||
: (" " + (di.lastStartIndex-1) + " / " + di.pageSum));
|
||||
info.setText(meg);
|
||||
action.setImageResource(R.drawable.ic_action_start);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
Intent it = new Intent(DownloadActivity.this, DownloadService.class);
|
||||
startService(it);
|
||||
mServiceConn.getService().add(di);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.DOWNLOADING) {
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
if (di.type == DownloadInfo.DETAIL_URL) {
|
||||
pb.setIndeterminate(true);
|
||||
info.setText(R.string.downloading);
|
||||
} else {
|
||||
pb.setIndeterminate(false);
|
||||
pb.setMax(di.pageSum);
|
||||
pb.setProgress(di.lastStartIndex-1);
|
||||
StringBuilder sb = new StringBuilder(getString(R.string.downloading));
|
||||
sb.append(" ").append(di.lastStartIndex-1).append(" / ").append(di.pageSum).append("\n");
|
||||
if (di.totalSize != 0)
|
||||
sb.append(String.format("%.2f", di.downloadSize))
|
||||
.append(" / ").append(String.format("%.2f", di.totalSize)).append(" KB");
|
||||
info.setText(sb.toString());
|
||||
}
|
||||
action.setImageResource(R.drawable.ic_action_pause);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
mServiceConn.getService().cancel(di.gid);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.WAITING) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.waiting);
|
||||
action.setImageResource(R.drawable.ic_action_pause);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
mServiceConn.getService().cancel(di.gid);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.COMPLETED) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.download_successfully);
|
||||
action.setImageResource(R.drawable.ic_action_completed);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(DownloadActivity.this,
|
||||
MangaDownloadActivity.class);
|
||||
intent.putExtra("title", di.title);
|
||||
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.FAILED) {
|
||||
pb.setVisibility(View.GONE);
|
||||
String meg = getString(R.string.download_unsuccessfully) + (di.type == DownloadInfo.DETAIL_URL ? ""
|
||||
: (" " + (di.lastStartIndex-1) + " / " + di.pageSum));
|
||||
info.setText(meg);
|
||||
action.setImageResource(R.drawable.ic_action_start);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
Intent it = new Intent(DownloadActivity.this, DownloadService.class);
|
||||
startService(it);
|
||||
mServiceConn.getService().add(di);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
BeautifyScreen.fixColour(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
int screenOri = Config.getScreenOriMode();
|
||||
if (screenOri != getRequestedOrientation())
|
||||
setRequestedOrientation(screenOri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
unbindService(mServiceConn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.download);
|
||||
|
||||
int screenOri = Config.getScreenOriMode();
|
||||
if (screenOri != getRequestedOrientation())
|
||||
setRequestedOrientation(screenOri);
|
||||
|
||||
// Download service
|
||||
Intent it = new Intent(this, DownloadService.class);
|
||||
bindService(it, mServiceConn, BIND_AUTO_CREATE);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_UPDATE);
|
||||
registerReceiver(mReceiver, filter);
|
||||
|
||||
longClickDialog = setLongClickDialog();
|
||||
|
||||
// For colourfy the activity
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
BeautifyScreen.ColourfyScreen(this);
|
||||
}
|
||||
|
||||
mDownloadInfos = Download.getDownloadInfoList();
|
||||
|
||||
ListView listView = (ListView)findViewById(R.id.download);
|
||||
mDlAdapter = new DlAdapter();
|
||||
listView.setAdapter(mDlAdapter);
|
||||
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
|
||||
int position, long arg3) {
|
||||
longClickItemIndex = position;
|
||||
longClickDialog.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver(){
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(intent.getAction().equals(ACTION_UPDATE))
|
||||
mDlAdapter.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
package com.hippo.ehviewer.activity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.hippo.ehviewer.BeautifyScreen;
|
||||
import com.hippo.ehviewer.DownloadInfo;
|
||||
import com.hippo.ehviewer.ListMangaDetail;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.dialog.DialogBuilder;
|
||||
import com.hippo.ehviewer.service.DownloadService;
|
||||
import com.hippo.ehviewer.service.DownloadServiceConnection;
|
||||
import com.hippo.ehviewer.util.Cache;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Download;
|
||||
import com.hippo.ehviewer.util.EhClient;
|
||||
import com.hippo.ehviewer.util.Favourite;
|
||||
import com.hippo.ehviewer.util.Util;
|
||||
import com.hippo.ehviewer.view.AlertButton;
|
||||
import com.hippo.ehviewer.view.DownloadItemLayout;
|
||||
import com.hippo.ehviewer.view.OlImageView;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
|
||||
public class DownloadActivity extends Activity {
|
||||
|
||||
private static final String TAG = "DownloadActivity";
|
||||
private static final String ACTION_UPDATE = "com.hippo.ehviewer.service.UPDATE";
|
||||
|
||||
private DownloadServiceConnection mServiceConn = new DownloadServiceConnection();
|
||||
|
||||
private List<DownloadInfo> mDownloadInfos;
|
||||
private DlAdapter mDlAdapter;
|
||||
private int longClickItemIndex;
|
||||
|
||||
private AlertDialog longClickDialog;
|
||||
|
||||
private AlertDialog setLongClickDialog() {
|
||||
return new DialogBuilder(this).setTitle(R.string.what_to_do)
|
||||
.setItems(R.array.download_item_long_click, new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1,
|
||||
int position, long arg3) {
|
||||
switch (position) {
|
||||
case 0: // Remove info item
|
||||
mServiceConn.getService().cancel(Download.getKey(longClickItemIndex));
|
||||
Download.remove(longClickItemIndex);
|
||||
mDlAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
case 1: // Remove info item
|
||||
mServiceConn.getService().cancel(Download.getKey(longClickItemIndex));
|
||||
mDlAdapter.notifyDataSetChanged();
|
||||
// TODO 有人反馈 Download.get(longClickItemIndex).title 为空,看来很有必要在正则抓取时检查是否为空
|
||||
File dir = new File(Config.getDownloadPath(), Download.get(longClickItemIndex).title);
|
||||
try {
|
||||
Util.deleteContents(dir);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dir.delete();
|
||||
Download.remove(longClickItemIndex);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
longClickDialog.cancel();
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((AlertButton)v).dialog.dismiss();
|
||||
}
|
||||
}).create();
|
||||
}
|
||||
|
||||
private class DlAdapter extends BaseAdapter {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
public DlAdapter() {
|
||||
mInflater = LayoutInflater.from(DownloadActivity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mDownloadInfos.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int arg0) {
|
||||
return mDownloadInfos.get(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
DownloadInfo di= mDownloadInfos.get(position);
|
||||
if (convertView != null) {
|
||||
DownloadItemLayout view = (DownloadItemLayout)convertView;
|
||||
if (!view.gid.equals(di.gid)) {
|
||||
view.gid = di.gid;
|
||||
view.status = di.status;
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
view.isWait = false;
|
||||
|
||||
OlImageView thumb = (OlImageView)view
|
||||
.findViewById(R.id.thumb);
|
||||
thumb.setUrl(di.thumb);
|
||||
thumb.setKey(String.valueOf(di.gid));
|
||||
thumb.setCache(Cache.memoryCache, Cache.cpCache);
|
||||
thumb.loadImage(true);
|
||||
|
||||
TextView title = (TextView)view.findViewById(R.id.title);
|
||||
title.setText(di.title);
|
||||
|
||||
setDownloadInfo(view, di);
|
||||
} else if (view.status != di.status || view.isWait) {
|
||||
view.status = di.status;
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
view.isWait = false;
|
||||
|
||||
setDownloadInfo(view, di);
|
||||
} else if (view.status == DownloadInfo.DOWNLOADING &&
|
||||
(view.type != di.type
|
||||
|| view.lastStartIndex != di.lastStartIndex
|
||||
|| view.downloadSize != di.downloadSize)) {
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
|
||||
ProgressBar pb = (ProgressBar)view.findViewById(R.id.progressBar);
|
||||
TextView info = (TextView)view.findViewById(R.id.info);
|
||||
|
||||
if (di.type == DownloadInfo.DETAIL_URL) {
|
||||
pb.setIndeterminate(true);
|
||||
info.setText(R.string.downloading);
|
||||
} else {
|
||||
pb.setIndeterminate(false);
|
||||
pb.setMax(di.pageSum);
|
||||
pb.setProgress(di.lastStartIndex-1);
|
||||
StringBuilder sb = new StringBuilder(getString(R.string.downloading));
|
||||
sb.append(" ").append(di.lastStartIndex-1).append(" / ").append(di.pageSum).append("\n");
|
||||
if (di.totalSize != 0)
|
||||
sb.append(String.format("%.2f", di.downloadSize))
|
||||
.append(" / ").append(String.format("%.2f", di.totalSize)).append(" KB");
|
||||
info.setText(sb.toString());
|
||||
}
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
DownloadItemLayout view = (DownloadItemLayout)mInflater.inflate(R.layout.download_item, null);
|
||||
view.gid = di.gid;
|
||||
view.status = di.status;
|
||||
view.type = di.type;
|
||||
view.lastStartIndex = di.lastStartIndex;
|
||||
view.downloadSize = di.downloadSize;
|
||||
view.isWait = false;
|
||||
|
||||
OlImageView thumb = (OlImageView)view
|
||||
.findViewById(R.id.thumb);
|
||||
thumb.setUrl(di.thumb);
|
||||
thumb.setKey(String.valueOf(di.gid));
|
||||
thumb.setCache(Cache.memoryCache, Cache.cpCache);
|
||||
thumb.loadImage(true);
|
||||
|
||||
TextView title = (TextView)view.findViewById(R.id.title);
|
||||
title.setText(di.title);
|
||||
|
||||
setDownloadInfo(view, di);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* For clickable button, when click change message to "Please wait", then when action over change message
|
||||
*
|
||||
* @param view
|
||||
* @param di
|
||||
* @param position
|
||||
*/
|
||||
private void setDownloadInfo(final DownloadItemLayout view, final DownloadInfo di) {
|
||||
final ProgressBar pb = (ProgressBar)view.findViewById(R.id.progressBar);
|
||||
final TextView info = (TextView)view.findViewById(R.id.info);
|
||||
final ImageView action = (ImageView)view.findViewById(R.id.action);
|
||||
|
||||
if (di.status == DownloadInfo.STOP) {
|
||||
pb.setVisibility(View.GONE);
|
||||
String meg = getString(R.string.not_started) + (di.type == DownloadInfo.DETAIL_URL ? ""
|
||||
: (" " + (di.lastStartIndex-1) + " / " + di.pageSum));
|
||||
info.setText(meg);
|
||||
action.setImageResource(R.drawable.ic_action_start);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
Intent it = new Intent(DownloadActivity.this, DownloadService.class);
|
||||
startService(it);
|
||||
mServiceConn.getService().add(di);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.DOWNLOADING) {
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
if (di.type == DownloadInfo.DETAIL_URL) {
|
||||
pb.setIndeterminate(true);
|
||||
info.setText(R.string.downloading);
|
||||
} else {
|
||||
pb.setIndeterminate(false);
|
||||
pb.setMax(di.pageSum);
|
||||
pb.setProgress(di.lastStartIndex-1);
|
||||
StringBuilder sb = new StringBuilder(getString(R.string.downloading));
|
||||
sb.append(" ").append(di.lastStartIndex-1).append(" / ").append(di.pageSum).append("\n");
|
||||
if (di.totalSize != 0)
|
||||
sb.append(String.format("%.2f", di.downloadSize))
|
||||
.append(" / ").append(String.format("%.2f", di.totalSize)).append(" KB");
|
||||
info.setText(sb.toString());
|
||||
}
|
||||
action.setImageResource(R.drawable.ic_action_pause);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
mServiceConn.getService().cancel(di.gid);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.WAITING) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.waiting);
|
||||
action.setImageResource(R.drawable.ic_action_pause);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
mServiceConn.getService().cancel(di.gid);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.COMPLETED) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.download_successfully);
|
||||
action.setImageResource(R.drawable.ic_action_completed);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(DownloadActivity.this,
|
||||
MangaDownloadActivity.class);
|
||||
intent.putExtra("title", di.title);
|
||||
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else if (di.status == DownloadInfo.FAILED) {
|
||||
pb.setVisibility(View.GONE);
|
||||
String meg = getString(R.string.download_unsuccessfully) + (di.type == DownloadInfo.DETAIL_URL ? ""
|
||||
: (" " + (di.lastStartIndex-1) + " / " + di.pageSum));
|
||||
info.setText(meg);
|
||||
action.setImageResource(R.drawable.ic_action_start);
|
||||
action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pb.setVisibility(View.GONE);
|
||||
info.setText(R.string.wait);
|
||||
action.setClickable(false);
|
||||
view.isWait = true;
|
||||
|
||||
Intent it = new Intent(DownloadActivity.this, DownloadService.class);
|
||||
startService(it);
|
||||
mServiceConn.getService().add(di);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
BeautifyScreen.fixColour(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
int screenOri = Config.getScreenOriMode();
|
||||
if (screenOri != getRequestedOrientation())
|
||||
setRequestedOrientation(screenOri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
unbindService(mServiceConn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.download);
|
||||
|
||||
int screenOri = Config.getScreenOriMode();
|
||||
if (screenOri != getRequestedOrientation())
|
||||
setRequestedOrientation(screenOri);
|
||||
|
||||
// Download service
|
||||
Intent it = new Intent(this, DownloadService.class);
|
||||
bindService(it, mServiceConn, BIND_AUTO_CREATE);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_UPDATE);
|
||||
registerReceiver(mReceiver, filter);
|
||||
|
||||
longClickDialog = setLongClickDialog();
|
||||
|
||||
// For colourfy the activity
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
BeautifyScreen.ColourfyScreen(this);
|
||||
}
|
||||
|
||||
mDownloadInfos = Download.getDownloadInfoList();
|
||||
|
||||
ListView listView = (ListView)findViewById(R.id.download);
|
||||
mDlAdapter = new DlAdapter();
|
||||
listView.setAdapter(mDlAdapter);
|
||||
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
|
||||
int position, long arg3) {
|
||||
longClickItemIndex = position;
|
||||
longClickDialog.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver(){
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(intent.getAction().equals(ACTION_UPDATE))
|
||||
mDlAdapter.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -63,21 +63,31 @@ public class DownloadService extends Service {
|
||||
|
||||
@Override
|
||||
public void onDownloadMangaStart(String id) {
|
||||
mBuilder.setContentTitle(getString(R.string.downloading)
|
||||
+ " " + Download.get(id).title)
|
||||
DownloadInfo di = Download.get(id);
|
||||
if (di == null)
|
||||
mNotifyManager.cancel(DOWNLOAD_NOTIFY_ID);
|
||||
else {
|
||||
mBuilder.setContentTitle(getString(R.string.downloading)
|
||||
+ " " + di.title)
|
||||
.setContentText(null)
|
||||
.setProgress(0, 0, true).setOngoing(true).setAutoCancel(false);;
|
||||
mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadMangaStart(String id, int pageSum, int startIndex) {
|
||||
mBuilder.setContentTitle(getString(R.string.downloading)
|
||||
+ " " + Download.get(id).title)
|
||||
.setContentText(startIndex + " / " + pageSum)
|
||||
.setProgress(pageSum, startIndex, false).setOngoing(true)
|
||||
.setAutoCancel(false);
|
||||
mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build());
|
||||
DownloadInfo di = Download.get(id);
|
||||
if (di == null)
|
||||
mNotifyManager.cancel(DOWNLOAD_NOTIFY_ID);
|
||||
else {
|
||||
mBuilder.setContentTitle(getString(R.string.downloading)
|
||||
+ " " + di.title)
|
||||
.setContentText(startIndex + " / " + pageSum)
|
||||
.setProgress(pageSum, startIndex, false).setOngoing(true)
|
||||
.setAutoCancel(false);
|
||||
mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,16 +62,16 @@ public class Cache {
|
||||
}
|
||||
}
|
||||
|
||||
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
||||
final int cacheSize = maxMemory / 24;
|
||||
//final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
||||
final int cacheSize = 8 * 1024 * 1024; // 8MB, can store 80 thumb
|
||||
memoryCache = new LruCache<String, Bitmap>(cacheSize) {
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected int sizeOf(String key, Bitmap bitmap) {
|
||||
if (Build.VERSION.SDK_INT < 19)
|
||||
return bitmap.getByteCount() / 1024;
|
||||
return bitmap.getByteCount();
|
||||
else
|
||||
return bitmap.getAllocationByteCount() / 1024;
|
||||
return bitmap.getAllocationByteCount();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,218 +1,228 @@
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.hippo.ehviewer.view.MangaImage;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class Config {
|
||||
private static final String TAG = "Config";
|
||||
|
||||
private static final String KEY_ALLOWED = "allowed";
|
||||
private static final String KEY_FIRST = "first_time";
|
||||
private static final String KEY_LOGIN = "login";
|
||||
private static final String KEY_IS_EXHENTAI = "is_exhentai";
|
||||
|
||||
private static final String CP_CACHE = "preference_cp_cache";
|
||||
private static final String CP_CACHE_DEFAULT = "25";
|
||||
private static final String PAGE_CACHE = "preference_page_cache";
|
||||
private static final String PAGE_CACHE_DEFAULT = "256";
|
||||
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 SCREEN_ORI = "preference_screen_ori";
|
||||
private static final String SCREEN_ORI_DEFAULT = "0";
|
||||
private static final String DOWNLOAD_PATH = "preference_download_path";
|
||||
private static final String DOWNLOAD_PATH_DEFAULT = Environment.getExternalStorageDirectory() + "/EhViewer/download/";
|
||||
|
||||
private static boolean mInit = false;
|
||||
|
||||
private static Context mContext;
|
||||
private static SharedPreferences mConfigPre;
|
||||
|
||||
private static final String EMSG = "Please init Config first.";
|
||||
|
||||
/**
|
||||
* Init Config
|
||||
*
|
||||
* @param context Application context
|
||||
*/
|
||||
public static void init(Context context) {
|
||||
if (mInit)
|
||||
return;
|
||||
mInit = true;
|
||||
|
||||
mContext = context;
|
||||
mConfigPre = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
|
||||
// Init what in config
|
||||
MangaImage.setMode(getPageScalingMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is init
|
||||
* @return True if init
|
||||
*/
|
||||
public static boolean isInit() {
|
||||
return mInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get is it allowed to launch
|
||||
*
|
||||
* @return True if allowed
|
||||
*/
|
||||
public static boolean isAllowed() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException(EMSG);
|
||||
}
|
||||
return mConfigPre.getBoolean(KEY_ALLOWED, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowed the appliation to launch
|
||||
*/
|
||||
public static void allowed() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException(EMSG);
|
||||
}
|
||||
mConfigPre.edit().putBoolean(KEY_ALLOWED, true).apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is it first time to launch the application
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFirstTime() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return mConfigPre.getBoolean(KEY_FIRST, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* It is first time to launch the application
|
||||
*/
|
||||
public static void firstTime() {
|
||||
mConfigPre.edit().putBoolean(KEY_FIRST, false).apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is login last time ?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isLogin() {
|
||||
return mConfigPre.getBoolean(KEY_LOGIN, false);
|
||||
}
|
||||
|
||||
public static void loginNow() {
|
||||
mConfigPre.edit().putBoolean(KEY_LOGIN, true).apply();
|
||||
}
|
||||
|
||||
public static void logoutNow() {
|
||||
mConfigPre.edit().putBoolean(KEY_LOGIN, false).apply();
|
||||
}
|
||||
|
||||
public static String getDownloadPath() {
|
||||
return mConfigPre.getString(DOWNLOAD_PATH, DOWNLOAD_PATH_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cover cache size in MB
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getCoverDiskCacheSize() {
|
||||
try {
|
||||
return Integer.parseInt(mConfigPre.getString(CP_CACHE, CP_CACHE_DEFAULT));
|
||||
} catch (Exception e) {
|
||||
mConfigPre.edit().putString(CP_CACHE, CP_CACHE_DEFAULT).apply();
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page cache size in MB
|
||||
*
|
||||
* @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) {
|
||||
mConfigPre.edit().putString(PAGE_CACHE, PAGE_CACHE_DEFAULT).apply();
|
||||
return 256;
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
PAGE_SCALING, PAGE_SCALING_DEFAULT));
|
||||
} catch (Exception e) {
|
||||
mConfigPre.edit().putString(PAGE_SCALING, PAGE_SCALING_DEFAULT)
|
||||
.apply();
|
||||
}
|
||||
return pageScalingMode;
|
||||
}
|
||||
|
||||
public static int getScreenOriMode() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException(EMSG);
|
||||
}
|
||||
int screenOriMode = 0;
|
||||
try {
|
||||
screenOriMode = Integer.parseInt(mConfigPre.getString(
|
||||
SCREEN_ORI, SCREEN_ORI_DEFAULT));
|
||||
} catch (Exception e) {
|
||||
mConfigPre.edit().putString(SCREEN_ORI, SCREEN_ORI_DEFAULT)
|
||||
.apply();
|
||||
}
|
||||
return screenOriPre2Value(screenOriMode);
|
||||
}
|
||||
|
||||
public static int screenOriPre2Value(int screenOriModePre) {
|
||||
switch (screenOriModePre) {
|
||||
case 0:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
case 1:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
case 2:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
default:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isExhentai() {
|
||||
return mConfigPre.getBoolean(KEY_IS_EXHENTAI, false);
|
||||
}
|
||||
|
||||
public static void exhentai(boolean isExhentai) {
|
||||
mConfigPre.edit().putBoolean(KEY_IS_EXHENTAI, isExhentai).apply();
|
||||
}
|
||||
}
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import com.hippo.ehviewer.view.MangaImage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class Config {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = "Config";
|
||||
|
||||
private static final String KEY_ALLOWED = "allowed";
|
||||
private static final String KEY_FIRST = "first_time";
|
||||
private static final String KEY_LOGIN = "login";
|
||||
private static final String KEY_IS_EXHENTAI = "is_exhentai";
|
||||
private static final String KEY_UPDATE_DATE = "update_date";
|
||||
|
||||
private static final String CP_CACHE = "preference_cp_cache";
|
||||
private static final String CP_CACHE_DEFAULT = "25";
|
||||
private static final String PAGE_CACHE = "preference_page_cache";
|
||||
private static final String PAGE_CACHE_DEFAULT = "256";
|
||||
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 SCREEN_ORI = "preference_screen_ori";
|
||||
private static final String SCREEN_ORI_DEFAULT = "0";
|
||||
private static final String DOWNLOAD_PATH = "preference_download_path";
|
||||
private static final String DOWNLOAD_PATH_DEFAULT = Environment.getExternalStorageDirectory() + "/EhViewer/download/";
|
||||
|
||||
private static boolean mInit = false;
|
||||
|
||||
private static Context mContext;
|
||||
private static SharedPreferences mConfigPre;
|
||||
|
||||
private static final String EMSG = "Please init Config first.";
|
||||
|
||||
/**
|
||||
* Init Config
|
||||
*
|
||||
* @param context Application context
|
||||
*/
|
||||
public static void init(Context context) {
|
||||
if (mInit)
|
||||
return;
|
||||
mInit = true;
|
||||
|
||||
mContext = context;
|
||||
mConfigPre = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
|
||||
// Init what in config
|
||||
MangaImage.setMode(getPageScalingMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is init
|
||||
* @return True if init
|
||||
*/
|
||||
public static boolean isInit() {
|
||||
return mInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get is it allowed to launch
|
||||
*
|
||||
* @return True if allowed
|
||||
*/
|
||||
public static boolean isAllowed() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException(EMSG);
|
||||
}
|
||||
return mConfigPre.getBoolean(KEY_ALLOWED, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowed the appliation to launch
|
||||
*/
|
||||
public static void allowed() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException(EMSG);
|
||||
}
|
||||
mConfigPre.edit().putBoolean(KEY_ALLOWED, true).apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is it first time to launch the application
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFirstTime() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return mConfigPre.getBoolean(KEY_FIRST, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* It is first time to launch the application
|
||||
*/
|
||||
public static void firstTime() {
|
||||
mConfigPre.edit().putBoolean(KEY_FIRST, false).apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is login last time ?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isLogin() {
|
||||
return mConfigPre.getBoolean(KEY_LOGIN, false);
|
||||
}
|
||||
|
||||
public static void loginNow() {
|
||||
mConfigPre.edit().putBoolean(KEY_LOGIN, true).apply();
|
||||
}
|
||||
|
||||
public static void logoutNow() {
|
||||
mConfigPre.edit().putBoolean(KEY_LOGIN, false).apply();
|
||||
}
|
||||
|
||||
public static String getDownloadPath() {
|
||||
return mConfigPre.getString(DOWNLOAD_PATH, DOWNLOAD_PATH_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cover cache size in MB
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getCoverDiskCacheSize() {
|
||||
try {
|
||||
return Integer.parseInt(mConfigPre.getString(CP_CACHE, CP_CACHE_DEFAULT));
|
||||
} catch (Exception e) {
|
||||
mConfigPre.edit().putString(CP_CACHE, CP_CACHE_DEFAULT).apply();
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page cache size in MB
|
||||
*
|
||||
* @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) {
|
||||
mConfigPre.edit().putString(PAGE_CACHE, PAGE_CACHE_DEFAULT).apply();
|
||||
return 256;
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
PAGE_SCALING, PAGE_SCALING_DEFAULT));
|
||||
} catch (Exception e) {
|
||||
mConfigPre.edit().putString(PAGE_SCALING, PAGE_SCALING_DEFAULT)
|
||||
.apply();
|
||||
}
|
||||
return pageScalingMode;
|
||||
}
|
||||
|
||||
public static int getScreenOriMode() {
|
||||
if (!mInit) {
|
||||
throw new IllegalStateException(EMSG);
|
||||
}
|
||||
int screenOriMode = 0;
|
||||
try {
|
||||
screenOriMode = Integer.parseInt(mConfigPre.getString(
|
||||
SCREEN_ORI, SCREEN_ORI_DEFAULT));
|
||||
} catch (Exception e) {
|
||||
mConfigPre.edit().putString(SCREEN_ORI, SCREEN_ORI_DEFAULT)
|
||||
.apply();
|
||||
}
|
||||
return screenOriPre2Value(screenOriMode);
|
||||
}
|
||||
|
||||
public static int screenOriPre2Value(int screenOriModePre) {
|
||||
switch (screenOriModePre) {
|
||||
case 0:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
case 1:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
case 2:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
default:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isExhentai() {
|
||||
return mConfigPre.getBoolean(KEY_IS_EXHENTAI, false);
|
||||
}
|
||||
|
||||
public static void exhentai(boolean isExhentai) {
|
||||
mConfigPre.edit().putBoolean(KEY_IS_EXHENTAI, isExhentai).apply();
|
||||
}
|
||||
|
||||
public static int getUpdateDate() {
|
||||
return mConfigPre.getInt(KEY_UPDATE_DATE, 0);
|
||||
}
|
||||
|
||||
public static void setUpdateDate() {
|
||||
setUpdateDate(Util.getDate());
|
||||
}
|
||||
|
||||
public static void setUpdateDate(int date) {
|
||||
mConfigPre.edit().putInt(KEY_UPDATE_DATE, date).apply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,187 +1,199 @@
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
import com.hippo.ehviewer.DiskCache;
|
||||
import com.hippo.ehviewer.ListUrls;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.view.OlImageView;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Movie;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class Util {
|
||||
private static String TAG = "Util";
|
||||
|
||||
/**
|
||||
* Put InputStream to File, default bufferSize is 512 * 1024
|
||||
*
|
||||
* @param is
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void inputStream2File(InputStream is, File file) throws IOException {
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
copy(is, os);
|
||||
}
|
||||
|
||||
public static void copy(InputStream is, OutputStream os) throws IOException {
|
||||
copy(is, os, 512 * 1024);
|
||||
}
|
||||
|
||||
public static void copy(InputStream is, OutputStream os, int size) throws IOException {
|
||||
byte[] buffer = new byte[512 * 1024];
|
||||
int bytesRead;
|
||||
while((bytesRead = is.read(buffer)) !=-1)
|
||||
os.write(buffer, 0, bytesRead);
|
||||
is.close();
|
||||
os.flush();
|
||||
os.close();
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
public static final int BITMAP = 0x0;
|
||||
public static final int MOVIE = 0x1;
|
||||
|
||||
public static int getResourcesType(String url) {
|
||||
int type = BITMAP;
|
||||
int index = url.lastIndexOf('.');
|
||||
if (index != -1 && getExtension(url).equals("gif"))
|
||||
type = MOVIE;
|
||||
return type;
|
||||
}
|
||||
|
||||
public static String getExtension(String url) {
|
||||
int index = url.lastIndexOf('.');
|
||||
if (index != -1)
|
||||
return url.substring(index + 1).toLowerCase();
|
||||
else
|
||||
return "png";
|
||||
}
|
||||
|
||||
public static String getName(String fileName) {
|
||||
int index = fileName.lastIndexOf('.');
|
||||
if (index != -1)
|
||||
return fileName.substring(0, index).toLowerCase();
|
||||
else
|
||||
return "png";
|
||||
}
|
||||
|
||||
public static boolean isNumber(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (ch < '0' || ch > '9')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String byteArrayToHexString(byte[] b) {
|
||||
StringBuilder sb = new StringBuilder(b.length * 2);
|
||||
for (byte element : b) {
|
||||
int v = element & 0xFF;
|
||||
if (v < 16) {
|
||||
sb.append('0');
|
||||
}
|
||||
sb.append(Integer.toHexString(v));
|
||||
}
|
||||
return sb.toString().toUpperCase();
|
||||
}
|
||||
|
||||
public static byte[] hexStringToByteArray(String s) {
|
||||
int len = s.length()/2*2;
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[(i / 2)] = ((byte) ((Character.digit(s.charAt(i), 16) << 4) + Character
|
||||
.digit(s.charAt(i + 1), 16)));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String InputStream2String(InputStream is) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is,
|
||||
"UTF-8"));
|
||||
String inputLine;
|
||||
while ((inputLine = br.readLine()) != null)
|
||||
sb.append(inputLine + "\n");
|
||||
br.close();
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int length = sb.length();
|
||||
if (length != 0)
|
||||
sb.delete(length - 1, length);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String[] getStrings(SharedPreferences shaper, String key) {
|
||||
String str = shaper.getString(key, null);
|
||||
if (str == null || str.length() == 0)
|
||||
return null;
|
||||
return new String(Util.hexStringToByteArray(str)).split("\n");
|
||||
}
|
||||
|
||||
public static void putStrings(SharedPreferences shaper, String key, List<String> strs) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String item : strs) {
|
||||
sb.append(item);
|
||||
sb.append('\n');
|
||||
}
|
||||
int length = sb.length();
|
||||
if (length != 0)
|
||||
sb.delete(length - 1, length);
|
||||
shaper.edit().putString(key, byteArrayToHexString(sb.toString().getBytes())).apply();
|
||||
}
|
||||
|
||||
public static void closeStreamQuietly (Closeable is) {
|
||||
try {
|
||||
if (is != null)
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteContents(File dir) throws IOException {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
throw new IOException("not a readable directory: " + dir);
|
||||
}
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteContents(file);
|
||||
}
|
||||
if (!file.delete()) {
|
||||
throw new IOException("failed to delete file: " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
import com.hippo.ehviewer.DiskCache;
|
||||
import com.hippo.ehviewer.ListUrls;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.view.OlImageView;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Movie;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class Util {
|
||||
private static String TAG = "Util";
|
||||
|
||||
/**
|
||||
* Put InputStream to File, default bufferSize is 512 * 1024
|
||||
*
|
||||
* @param is
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void inputStream2File(InputStream is, File file) throws IOException {
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
copy(is, os);
|
||||
}
|
||||
|
||||
public static void copy(InputStream is, OutputStream os) throws IOException {
|
||||
copy(is, os, 512 * 1024);
|
||||
}
|
||||
|
||||
public static void copy(InputStream is, OutputStream os, int size) throws IOException {
|
||||
byte[] buffer = new byte[size];
|
||||
int bytesRead;
|
||||
while((bytesRead = is.read(buffer)) !=-1)
|
||||
os.write(buffer, 0, bytesRead);
|
||||
is.close();
|
||||
os.flush();
|
||||
os.close();
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
public static final int BITMAP = 0x0;
|
||||
public static final int MOVIE = 0x1;
|
||||
|
||||
public static int getResourcesType(String url) {
|
||||
int type = BITMAP;
|
||||
int index = url.lastIndexOf('.');
|
||||
if (index != -1 && getExtension(url).equals("gif"))
|
||||
type = MOVIE;
|
||||
return type;
|
||||
}
|
||||
|
||||
public static String getExtension(String url) {
|
||||
int index = url.lastIndexOf('.');
|
||||
if (index != -1)
|
||||
return url.substring(index + 1).toLowerCase();
|
||||
else
|
||||
return "png";
|
||||
}
|
||||
|
||||
public static String getName(String fileName) {
|
||||
int index = fileName.lastIndexOf('.');
|
||||
if (index != -1)
|
||||
return fileName.substring(0, index).toLowerCase();
|
||||
else
|
||||
return "png";
|
||||
}
|
||||
|
||||
public static boolean isNumber(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (ch < '0' || ch > '9')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String byteArrayToHexString(byte[] b) {
|
||||
StringBuilder sb = new StringBuilder(b.length * 2);
|
||||
for (byte element : b) {
|
||||
int v = element & 0xFF;
|
||||
if (v < 16) {
|
||||
sb.append('0');
|
||||
}
|
||||
sb.append(Integer.toHexString(v));
|
||||
}
|
||||
return sb.toString().toUpperCase(Locale.getDefault());
|
||||
}
|
||||
|
||||
public static byte[] hexStringToByteArray(String s) {
|
||||
int len = s.length()/2*2;
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[(i / 2)] = ((byte) ((Character.digit(s.charAt(i), 16) << 4) + Character
|
||||
.digit(s.charAt(i + 1), 16)));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String InputStream2String(InputStream is) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is,
|
||||
"UTF-8"));
|
||||
String inputLine;
|
||||
while ((inputLine = br.readLine()) != null)
|
||||
sb.append(inputLine + "\n");
|
||||
br.close();
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int length = sb.length();
|
||||
if (length != 0)
|
||||
sb.delete(length - 1, length);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String[] getStrings(SharedPreferences shaper, String key) {
|
||||
String str = shaper.getString(key, null);
|
||||
if (str == null || str.length() == 0)
|
||||
return null;
|
||||
return new String(Util.hexStringToByteArray(str)).split("\n");
|
||||
}
|
||||
|
||||
public static void putStrings(SharedPreferences shaper, String key, List<String> strs) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String item : strs) {
|
||||
sb.append(item);
|
||||
sb.append('\n');
|
||||
}
|
||||
int length = sb.length();
|
||||
if (length != 0)
|
||||
sb.delete(length - 1, length);
|
||||
shaper.edit().putString(key, byteArrayToHexString(sb.toString().getBytes())).apply();
|
||||
}
|
||||
|
||||
public static void closeStreamQuietly (Closeable is) {
|
||||
try {
|
||||
if (is != null)
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteContents(File dir) throws IOException {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
throw new IOException("not a readable directory: " + dir);
|
||||
}
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteContents(file);
|
||||
}
|
||||
if (!file.delete()) {
|
||||
throw new IOException("failed to delete file: " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public static int getDate() {
|
||||
int time = 0;
|
||||
try {
|
||||
time = Integer.parseInt(new SimpleDateFormat("yyyyMMdd").format(new Date()));
|
||||
} catch (NumberFormatException e) {}
|
||||
return time;
|
||||
}
|
||||
}
|
||||
@@ -3,82 +3,184 @@ package com.hippo.ehviewer.widget;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
|
||||
/**
|
||||
* A ViewGroup that can layout views in line and auto wrap
|
||||
*
|
||||
* @author Hippo
|
||||
*
|
||||
*/
|
||||
public class AutoWrapLayout extends ViewGroup {
|
||||
@SuppressWarnings("unused")
|
||||
private final static String TAG = "AutoWrapLayout";
|
||||
|
||||
private List<Rect> rectList = new ArrayList<Rect>();
|
||||
|
||||
private BaseLine mBaseLine;
|
||||
|
||||
private static final BaseLine[] sBaseLineArray = { BaseLine.TOP,
|
||||
BaseLine.CENTER, BaseLine.BOTTOM };
|
||||
|
||||
|
||||
public enum BaseLine {
|
||||
TOP(0),
|
||||
CENTER(1),
|
||||
BOTTOM(2);
|
||||
|
||||
BaseLine(int ni) {
|
||||
nativeInt = ni;
|
||||
}
|
||||
|
||||
final int nativeInt;
|
||||
}
|
||||
|
||||
public AutoWrapLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public AutoWrapLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
public AutoWrapLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
static int adjust(int measureSpec, int delta) {
|
||||
return MeasureSpec.makeMeasureSpec(
|
||||
MeasureSpec.getSize(measureSpec + delta), MeasureSpec.getMode(measureSpec));
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.AutoWrapLayout, defStyle, 0);
|
||||
|
||||
int index = a.getInt(R.styleable.AutoWrapLayout_baseLine, -1);
|
||||
if (index >= 0)
|
||||
setBaseLine(sBaseLineArray[index]);
|
||||
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setBaseLine(BaseLine baseLine) {
|
||||
if (baseLine == null)
|
||||
return;
|
||||
|
||||
if (mBaseLine != baseLine) {
|
||||
mBaseLine = baseLine;
|
||||
|
||||
requestLayout();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public BaseLine getScaleType() {
|
||||
return mBaseLine;
|
||||
}
|
||||
|
||||
private void adjustBaseLine(int lineHeight, int startIndex, int endIndex) {
|
||||
if (mBaseLine == BaseLine.TOP)
|
||||
return;
|
||||
|
||||
for (int index = startIndex; index < endIndex; index++) {
|
||||
final View child = getChildAt(index);
|
||||
final AutoWrapLayout.LayoutParams lp =
|
||||
(AutoWrapLayout.LayoutParams)child.getLayoutParams();
|
||||
Rect rect = rectList.get(index);
|
||||
int offsetRaw = lineHeight - rect.height() - lp.topMargin - lp.bottomMargin;
|
||||
if (mBaseLine == BaseLine.CENTER)
|
||||
rect.offset(0, offsetRaw/2);
|
||||
else if (mBaseLine == BaseLine.BOTTOM)
|
||||
rect.offset(0, offsetRaw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO Take vertical mode
|
||||
/**
|
||||
* each row or line at least show one child
|
||||
*
|
||||
* horizontal only show child can show or partly show in parent
|
||||
*/
|
||||
@SuppressLint("DrawAllocation")
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightSpec) {
|
||||
final int mWidth = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight();
|
||||
final int childCount = getChildCount();
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
|
||||
int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
if (widthMode == MeasureSpec.UNSPECIFIED)
|
||||
maxWidth = Integer.MAX_VALUE;
|
||||
if (heightMode == MeasureSpec.UNSPECIFIED)
|
||||
maxHeight = Integer.MAX_VALUE;
|
||||
|
||||
int paddingLeft = getPaddingLeft();
|
||||
int paddingTop = getPaddingTop();
|
||||
int paddingRight = getPaddingRight();
|
||||
int paddingBottom = getPaddingBottom();
|
||||
|
||||
int maxRightBound = maxWidth - paddingRight;
|
||||
int maxBottomBound = maxHeight - paddingBottom;
|
||||
|
||||
int left;
|
||||
int top;
|
||||
int right;
|
||||
int bottom;
|
||||
int rightBound = 0;
|
||||
int rightBound = paddingLeft;
|
||||
int maxRightNoPadding = rightBound;
|
||||
int bottomBound;
|
||||
int lastMaxBottom = 0;
|
||||
int maxBottom = lastMaxBottom;
|
||||
int width;
|
||||
int height;
|
||||
int lastMaxBottom = paddingTop;
|
||||
int maxBottom = lastMaxBottom; // maxBottom is maxBottomNoPadding
|
||||
//int maxBottomNoPadding = maxBottom;
|
||||
int childWidth;
|
||||
int childHeight;
|
||||
|
||||
int lineStartIndex = 0;
|
||||
int lineEndIndex = 0; // endIndex + 1
|
||||
|
||||
rectList.clear();
|
||||
|
||||
for(int i = 0; i < childCount; i++){
|
||||
final View child = this.getChildAt(i);
|
||||
int childCount = getChildCount();
|
||||
for (int index = 0; index < childCount; index++) {
|
||||
final View child = getChildAt(index);
|
||||
child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
|
||||
if (child.getVisibility() == View.GONE)
|
||||
continue;
|
||||
final AutoWrapLayout.LayoutParams lp =
|
||||
(AutoWrapLayout.LayoutParams)child.getLayoutParams();
|
||||
width = child.getMeasuredWidth();
|
||||
height = child.getMeasuredHeight();
|
||||
childWidth = child.getMeasuredWidth();
|
||||
childHeight = child.getMeasuredHeight();
|
||||
|
||||
left = rightBound + lp.leftMargin;
|
||||
right = left + width;
|
||||
right = left + childWidth;
|
||||
rightBound = right + lp.rightMargin;
|
||||
//if it can't drawing on a same line , skip to next line
|
||||
if(rightBound > mWidth) {
|
||||
left = 0 + lp.leftMargin;
|
||||
right = left + width;
|
||||
if (rightBound > maxRightBound) { // Go to next row
|
||||
lineEndIndex = index;
|
||||
// Adjust child position base on baseline
|
||||
adjustBaseLine(maxBottom - lastMaxBottom, lineStartIndex, lineEndIndex);
|
||||
|
||||
// If child can't show in parent begin this line
|
||||
if (maxBottom >= maxBottomBound)
|
||||
break;
|
||||
left = paddingLeft + lp.leftMargin;
|
||||
right = left + childWidth;
|
||||
rightBound = right + lp.rightMargin;
|
||||
|
||||
lastMaxBottom = maxBottom;
|
||||
|
||||
top = lastMaxBottom + lp.topMargin;
|
||||
bottom = top + height;
|
||||
bottom = top + childHeight;
|
||||
bottomBound = bottom + lp.bottomMargin;
|
||||
|
||||
maxBottom = bottomBound;
|
||||
lineStartIndex = index;
|
||||
} else {
|
||||
top = lastMaxBottom + lp.topMargin;
|
||||
bottom = top + height;
|
||||
bottom = top + childHeight;
|
||||
bottomBound = bottom + lp.bottomMargin;
|
||||
}
|
||||
// Update max bottom
|
||||
// Update max
|
||||
if (rightBound > maxRightNoPadding)
|
||||
maxRightNoPadding = rightBound;
|
||||
if (bottomBound > maxBottom)
|
||||
maxBottom = bottomBound;
|
||||
Rect rect = new Rect();
|
||||
@@ -88,15 +190,35 @@ public class AutoWrapLayout extends ViewGroup {
|
||||
rect.bottom = bottom;
|
||||
rectList.add(rect);
|
||||
}
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), maxBottom + getPaddingTop() + getPaddingBottom());
|
||||
|
||||
// Handle last line baseline
|
||||
adjustBaseLine(maxBottom - lastMaxBottom, lineStartIndex, rectList.size());
|
||||
|
||||
int measuredWidth;
|
||||
int measuredHeight;
|
||||
|
||||
if (widthMode == MeasureSpec.EXACTLY)
|
||||
measuredWidth = maxWidth;
|
||||
else
|
||||
measuredWidth = maxRightNoPadding + paddingRight;
|
||||
if (heightMode == MeasureSpec.EXACTLY)
|
||||
measuredHeight = maxHeight;
|
||||
else {
|
||||
measuredHeight = maxBottom + paddingBottom;
|
||||
if (heightMode == MeasureSpec.AT_MOST)
|
||||
measuredHeight = measuredHeight > maxHeight ? maxHeight : measuredHeight;
|
||||
}
|
||||
|
||||
setMeasuredDimension(measuredWidth, measuredHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
final int count = getChildCount() > rectList.size() ? rectList.size() : getChildCount();
|
||||
|
||||
final int count = rectList.size();
|
||||
for(int i = 0; i < count; i++){
|
||||
final View child = this.getChildAt(i);
|
||||
if (child.getVisibility() == View.GONE)
|
||||
continue;
|
||||
Rect rect = rectList.get(i);
|
||||
child.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||