Skip to content

Commit

Permalink
🔨 All tile-related names are all changed to block
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyge committed Oct 24, 2017
1 parent a37cffb commit 2c880ee
Show file tree
Hide file tree
Showing 37 changed files with 602 additions and 604 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ sketchImageView.displayImage("http://t.cn/RShdS1f");
* [使用 Options 配置图片][options]
* [播放 GIF 图片][play_gif_image]
* [手势缩放、旋转图片][zoom]
* [分块显示超大图片][huge_image]
* [分块显示超大图片][block_display]
* [使用 ShapeSize 在绘制时改变图片的尺寸][shape_size]
* [使用 ImageShaper 在绘制时改变图片的形状][image_shaper]
* [使用 ImageProcessor 在解码后改变图片][image_processor]
Expand Down Expand Up @@ -221,7 +221,7 @@ sketchImageView.displayImage("http://t.cn/RShdS1f");
[load_and_download]: docs/wiki/load_and_download.md
[play_gif_image]: docs/wiki/play_gif_image.md
[zoom]: docs/wiki/zoom.md
[huge_image]: docs/wiki/huge_image.md
[block_display]: docs/wiki/block_display.md
[shape_size]: docs/wiki/shape_size.md
[image_shaper]: docs/wiki/image_shaper.md
[image_processor]: docs/wiki/image_processor.md
Expand Down
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Basic functions:
* [Use Options to configure the image][options]
* [Play GIF image][play_gif_image]
* [Gesture zoom, rotate the picture][zoom]
* [Blocked display of huge image][huge_image]
* [Blocked display of huge image][block_display]
* [Use ShapeSize to change the size of the image when drawing][shape_size]
* [Use ImageShaper to change the shape of a picture when drawing][image_shaper]
* [Use ImageProcessor to change the picture after decoding][image_processor]
Expand Down Expand Up @@ -221,7 +221,7 @@ More:
[load_and_download]: docs/wiki/load_and_download.md
[play_gif_image]: docs/wiki/play_gif_image.md
[zoom]: docs/wiki/zoom.md
[huge_image]: docs/wiki/huge_image.md
[block_display]: docs/wiki/block_display.md
[shape_size]: docs/wiki/shape_size.md
[image_shaper]: docs/wiki/image_shaper.md
[image_processor]: docs/wiki/image_processor.md
Expand Down
2 changes: 1 addition & 1 deletion docs/logs/log_2.3.0-beta1.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
新功能:
>* ``Decode``. [缩略图模式](../wiki/thumbnail_mode.md),通过缩略图模式你可以在列表中更加清晰的显示那些宽高相差特别大的图片
>* ``Gesture Zoom``. [手势缩放功能](../wiki/zoom.md),参照PhotoVie,SketchImageView内置了手势缩放功能,比PhotoView功能更强大,体验更好,新增了定位、阅读模式等特色功能
>* ``Super Large Image``. [分块显示超大图功能](../wiki/huge_image.md),SketchImageVie内置了分块显示超大图功能,长微博、高清妹子图什么的不再是问题
>* ``Super Large Image``. [分块显示超大图功能](../wiki/block_display.md),SketchImageVie内置了分块显示超大图功能,长微博、高清妹子图什么的不再是问题
>* ``ModeImage``. 新增ModeImage替代ImageHolder,现在可以用任意类型的drawable或者内存缓存中的图片来作为loading占位图了
优化:
Expand Down
2 changes: 1 addition & 1 deletion docs/logs/log_2.3.0-stable.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#### 全新功能
>* :sparkles: `Gesture Zoom`. 新增[手势缩放](../wiki/zoom.md)功能,参照PhotoVie,SketchImageView内置了手势缩放功能,比PhotoView功能更强大,体验更好,新增了定位、阅读模式等特色功能
>* :sparkles: `Super Large Image`. 新增[分块显示超大图](../wiki/huge_image.md)功能,SketchImageVie内置了分块显示超大图功能,长微博、高清妹子图什么的不再是问题
>* :sparkles: `Super Large Image`. 新增[分块显示超大图](../wiki/block_display.md)功能,SketchImageVie内置了分块显示超大图功能,长微博、高清妹子图什么的不再是问题
>* :sparkles: `ImageShaper` 新增[ImageShaper](../wiki/image_shaper.md),可以在绘制时修改图片的形状,避免同一张图片有不同的形状需求时通过ImageProcessor实现会产生多张图片,从而浪费内存缓存的情况
#### 相对于2.3.0-beta10:
Expand Down
6 changes: 6 additions & 0 deletions docs/logs/log_2.6.0_p1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
* :hammer: SketchImageView.getImageZoomer() 重命名为 getZoomer()
* :hammer: HugeImageViewer 重命名为 BlockDisplayer
* :fire: SketchImageView.getHugeImageViewer() 移除,请用 getZoomer().getBlockDisplayer() 代替
* :hammer: Tile 重命名为 Block
* :hammer: ErrorTracker.onTileSortError() 重命名为 onBlockSortError
* :hammer: 所有 tile 相关的名字 全部改成了 block

sample app:
* :bug: 修复 UNSPLASH 页面没有加载完数据就切换到别的页面时崩溃的 BUG

待办:
* 重写 block_display.md ,然后在 zoom.md 中引用
35 changes: 16 additions & 19 deletions docs/wiki/huge_image.md → docs/wiki/block_display.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

纵观其它几款流行的图片加载器 [Fresco][Glide][Picasso] 都没有提供超大图片支持,而单独支持超大图片的 View 倒是有几款,例如 [Subsampling Scale Image View][WorldMap][LargeImage] , 但都做的不够好或者没法跟现有的图片加载框架集成,做的不好还好说,不能跟现有图片加载框架集成用起来就很恶心了

下面用 [Glide] 代指现有的图片框架,用 [Subsampling Scale Image View] 代指单独的分块显示超大图控件来举例说明两者不能集成时的恶心之处
下面用 [Glide] 代指现有的图片框架,用 [Subsampling Scale Image View] 代指单独的分块显示超大图控件来举例说明两者不能集成时的不便之处

1. 图片详情页必须准备两个 ImageView,一个 [Glide] 是用的,一个是 [Subsampling Scale Image View]。先用 [Glide] 加载完图片,然后根据结果(如果返回了原始图片尺寸的话,没有的话你还要自己去解析并判断)判断这张图片需不需要用 [Subsampling Scale Image View],如果需要的话再将 [Subsampling Scale Image View] 显示出来遮盖住 [Glide] 用的 ImageView,并初始化 [Subsampling Scale Image View]
2. [Subsampling Scale Image View] 要继续优化的话,还会涉及到内存缓存和 bitmap 复用池,如果 [Subsampling Scale Image View][Glide] 分别单独维护一套的话,APP 的可用内存就剩不了多少了,因此这两者必须能共用一套内存缓存和 bitmap 复用池
3. [Glide] 支持的 uri,[Subsampling Scale Image View] 未必支持

### 使用

Sketch 是目前唯一提供了超大图片支持的图片加载器,核心类是 [HugeImageViewer]
Sketch 是目前唯一提供了超大图片支持的图片加载器,核心类是 [BlockDisplayer],依赖于[手势缩放][zoom]功能,是[手势缩放][zoom]能的一部分

#### 支持的图片类型和系统版本
* jpeg、png:API 10(2.3.3)及其以上
Expand All @@ -26,22 +26,17 @@ Sketch 是目前唯一提供了超大图片支持的图片加载器,核心类

#### 开启

```java
SketchImageView sketchImageView = ...;
sketchImageView.setHugeImageEnabled(true);
```
注意:
* [HugeImageViewer] 需要依赖手势缩放功能,因此当手势缩放功能未开启时 [HugeImageViewer] 会自动开启,同理在关闭 [HugeImageViewer] 的时候如果检测到手势缩放功能是被 [HugeImageViewer] 开启的也会一并关闭手势缩放功能
只要开启[手势缩放][zoom]就自动开启了分块显示功能

#### 旋转

[HugeImageViewer] 支持跟随手势缩放功旋转,但只支持 90°、180°、270° 旋转
[BlockDisplayer] 支持跟随[手势缩放][zoom]功旋转,但只支持 90°、180°、270° 旋转

#### 在 ViewPager 中使用

由于 ViewPager 会至少缓存三个页面,所以至少会有三个 [HugeImageViewer] 同时工作,这样对内存的消耗是非常大的
由于 ViewPager 会至少缓存三个页面,所以至少会有三个 [BlockDisplayer] 同时工作,这样对内存的消耗是非常大的

因此 [HugeImageViewer] 特地提供了 setPause(boolean) 方法来减少在 ViewPager 中的内存消耗,如下:
因此 [BlockDisplayer] 特地提供了 setPause(boolean) 方法来减少在 ViewPager 中的内存消耗,如下:

```java
public class MyFragment extends Fragment {
Expand All @@ -52,8 +47,9 @@ public class MyFragment extends Fragment {
View view = ...;
sketchImageView = ...;

sketchImageView.setZoomEnabled(true);
// 初始化超大图查看器的暂停状态,这一步很重要
sketchImageView.getHugeImageViewer().setPause(!isVisibleToUser());
sketchImageView.getZoomer().getBlockDisplayer().setPause(!isVisibleToUser());

return view;
}
Expand Down Expand Up @@ -88,8 +84,8 @@ public class MyFragment extends Fragment {

protected void onUserVisibleChanged(boolean isVisibleToUser) {
// 不可见的时候暂停超大图查看器,节省内存,可见的时候恢复
if (sketchImageView != null && sketchImageView.isHugeImageEnabled()) {
sketchImageView.getHugeImageViewer().setPause(!isVisibleToUser);
if (sketchImageView != null && sketchImageView.isZoomEnabled()) {
sketchImageView.getZoomer().getBlockDisplayer().setPause(!isVisibleToUser);
}
}
}
Expand All @@ -99,16 +95,16 @@ public class MyFragment extends Fragment {

```java
// 显示碎片范围
hugeImageViewer.setShowTileRect(true);
sketchImageView.getZoomer().getBlockDisplayer().setShowBlockRect(true);

// 获取当前碎片数量
int tiles = hugeImageViewer.getTiles();
int blockSize = sketchImageView.getZoomer().getBlockDisplayer().getBlockSize();

// 获取当前所有碎片占用的字节数
long tilesByteCount = hugeImageViewer.getTilesAllocationByteCount();
long allocationByteCount = sketchImageView.getZoomer().getBlockDisplayer().getAllocationByteCount();

// 设置碎片变化监听器
hugeImageViewer.setOnTileChangedListener(HugeImageViewer.OnTileChangedListener)
sketchImageView.getZoomer().getBlockDisplayer().setOnBlockChangedListener(BlockDisplayer.OnBlockChangedListener)
```

[BitmapRegionDecoder]: https://developer.android.google.cn/reference/android/graphics/BitmapRegionDecoder.html
Expand All @@ -118,4 +114,5 @@ hugeImageViewer.setOnTileChangedListener(HugeImageViewer.OnTileChangedListener)
[WorldMap]: https://github.com/johnnylambada/WorldMap
[Subsampling Scale Image View]: https://github.com/davemorrissey/subsampling-scale-image-view
[LargeImage]: https://github.com/LuckyJayce/LargeImage
[HugeImageViewer]: ../../sketch/src/main/java/me/xiaopan/sketch/viewfun/huge/HugeImageViewer.java
[BlockDisplayer]: ../../sketch/src/main/java/me/xiaopan/sketch/zoom/BlockDisplayer.java
[zoom]: zoom.md
6 changes: 3 additions & 3 deletions docs/wiki/error_tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class MyErrorTracker extends ErrorTracker {
}

@Override
public void onTileSortError(IllegalArgumentException e, List<Tile> tileList, boolean useLegacyMergeSort) {
super.onTileSortError(e, tileList, useLegacyMergeSort);
String message = (useLegacyMergeSort ? "useLegacyMergeSort. " : "") + SketchUtils.tileListToString(tileList);
public void onBlockSortError(IllegalArgumentException e, List<Block> blockList, boolean useLegacyMergeSort) {
super.onBlockSortError(e, blockList, useLegacyMergeSort);
String message = (useLegacyMergeSort ? "useLegacyMergeSort. " : "") + SketchUtils.blockListToString(blockList);
CrashReport.postCatchedException(new Exception(message, e));
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SLog.getLevel();
* TYPE_CACHE: 内存缓存、bitmap pool、磁盘缓存相关日志
* TYPE_TIME: commit()和解码耗时相关日志
* TYPE_ZOOM: 手势缩放相关日志
* TYPE_HUGE_IMAGE: 分块显示超大图相关日志
* TYPE_ZOOM_BLOCK_DISPLAY: 分块显示超大图相关日志

注意:
* 日志分类默认全部关闭
Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/sketch_image_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ sketchImageView.setOptions(displayOptions)

参考 [手势缩放、旋转图片][zoom]

参考 [分块显示超大图片][huge_image]
参考 [分块显示超大图片][block_display]

### 监听显示过程和下载进度

Expand Down Expand Up @@ -149,7 +149,7 @@ sketchImageView.setClickRetryOnDisplayErrorEnabled(true);
[pause_download]: pause_download.md
[play_gif]: play_gif.md
[zoom]: zoom.md
[huge_image]: huge_image.md
[block_display]: block_display.md
[uri]: uri.md
[options]: options.md
[listener]: listener.md
Expand Down
8 changes: 4 additions & 4 deletions sample/src/main/java/me/xiaopan/sketchsample/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import me.xiaopan.sketchsample.util.DataTransferStation

open class BaseFragment : Fragment() {
val dataTransferHelper = DataTransferStation.PageHelper(this)
var isViewCreated = false;
var isViewCreated = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -18,10 +18,10 @@ open class BaseFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val bindContentView = javaClass.getAnnotation(BindContentView::class.java)
if (bindContentView != null && bindContentView.value > 0) {
return inflater!!.inflate(bindContentView.value, container, false)
return if (bindContentView != null && bindContentView.value > 0) {
inflater!!.inflate(bindContentView.value, container, false)
} else {
return super.onCreateView(inflater, container, savedInstanceState)
super.onCreateView(inflater, container, savedInstanceState)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import me.xiaopan.sketch.uri.UriModel
import me.xiaopan.sketch.util.SketchUtils
import me.xiaopan.sketch.util.UnableCreateDirException
import me.xiaopan.sketch.util.UnableCreateFileException
import me.xiaopan.sketch.zoom.block.Tile
import me.xiaopan.sketch.zoom.block.Block
import java.io.File
import java.util.*

Expand Down Expand Up @@ -203,15 +203,15 @@ internal class SampleErrorTracker(context: Context) : ErrorTracker(context) {
), throwable))
}

override fun onTileSortError(e: IllegalArgumentException, tileList: List<Tile>, useLegacyMergeSort: Boolean) {
super.onTileSortError(e, tileList, useLegacyMergeSort)
override fun onBlockSortError(e: IllegalArgumentException, blockList: List<Block>, useLegacyMergeSort: Boolean) {
super.onBlockSortError(e, blockList, useLegacyMergeSort)

CrashReport.postCatchedException(Exception(String.format(
"Sketch - TileSortError - " +
"Sketch - BlockSortError - " +
"%s " +
"\ntiles: %s",
"\nblocks: %s",
if (useLegacyMergeSort) "useLegacyMergeSort. " else "",
SketchUtils.tileListToString(tileList)
SketchUtils.blockListToString(blockList)
), e))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SampleSketchInitializer : Initializer {
onEvent(AppConfigChangedEvent(AppConfig.Key.LOG_REQUEST))
onEvent(AppConfigChangedEvent(AppConfig.Key.LOG_CACHE))
onEvent(AppConfigChangedEvent(AppConfig.Key.LOG_ZOOM))
onEvent(AppConfigChangedEvent(AppConfig.Key.LOG_HUGE_IMAGE))
onEvent(AppConfigChangedEvent(AppConfig.Key.LOG_ZOOM_BLOCK_DISPLAY))

onEvent(AppConfigChangedEvent(AppConfig.Key.MOBILE_NETWORK_PAUSE_DOWNLOAD))
onEvent(AppConfigChangedEvent(AppConfig.Key.GLOBAL_LOW_QUALITY_IMAGE))
Expand Down Expand Up @@ -86,10 +86,10 @@ class SampleSketchInitializer : Initializer {
} else {
SLog.closeType(SLog.TYPE_ZOOM)
}
AppConfig.Key.LOG_HUGE_IMAGE == event.key -> if (AppConfig.getBoolean(context!!, AppConfig.Key.LOG_HUGE_IMAGE)) {
SLog.openType(SLog.TYPE_HUGE_IMAGE)
AppConfig.Key.LOG_ZOOM_BLOCK_DISPLAY == event.key -> if (AppConfig.getBoolean(context!!, AppConfig.Key.LOG_ZOOM_BLOCK_DISPLAY)) {
SLog.openType(SLog.TYPE_ZOOM_BLOCK_DISPLAY)
} else {
SLog.closeType(SLog.TYPE_HUGE_IMAGE)
SLog.closeType(SLog.TYPE_ZOOM_BLOCK_DISPLAY)
}
AppConfig.Key.MOBILE_NETWORK_PAUSE_DOWNLOAD == event.key -> configuration!!.isMobileDataPauseDownloadEnabled = AppConfig.getBoolean(context!!, AppConfig.Key.MOBILE_NETWORK_PAUSE_DOWNLOAD)
AppConfig.Key.GLOBAL_LOW_QUALITY_IMAGE == event.key -> configuration!!.isLowQualityImageEnabled = AppConfig.getBoolean(context!!, AppConfig.Key.GLOBAL_LOW_QUALITY_IMAGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class MainActivity : BaseActivity(), AppListFragment.GetAppListTagStripListener,
menuList.add(CheckMenu(this, "Enabled Gesture Zoom In Detail Page", AppConfig.Key.SUPPORT_ZOOM, null, menuClickListener))
menuList.add(CheckMenu(this, "Enabled Read Mode In Detail Page", AppConfig.Key.READ_MODE, null, menuClickListener))
menuList.add(CheckMenu(this, "Enabled Location Animation In Detail Page", AppConfig.Key.LOCATION_ANIMATE, null, menuClickListener))
menuList.add(CheckMenu(this, "Visible To User Decode Huge Image In Detail Page", AppConfig.Key.PAGE_VISIBLE_TO_USER_DECODE_HUGE_IMAGE, null, menuClickListener))
menuList.add(CheckMenu(this, "Pause Block Display When Page Not Visible In Detail Page", AppConfig.Key.PAUSE_BLOCK_DISPLAY_WHEN_PAGE_NOT_VISIBLE, null, menuClickListener))

menuList.add("GIF Menu")
menuList.add(CheckMenu(this, "Auto Play GIF In List", AppConfig.Key.PLAY_GIF_ON_LIST, null, menuClickListener))
Expand Down Expand Up @@ -239,7 +239,7 @@ class MainActivity : BaseActivity(), AppListFragment.GetAppListTagStripListener,
menuList.add(CheckMenu(this, "Output Flow Log", AppConfig.Key.LOG_REQUEST, null, menuClickListener))
menuList.add(CheckMenu(this, "Output Cache Log", AppConfig.Key.LOG_CACHE, null, menuClickListener))
menuList.add(CheckMenu(this, "Output Zoom Log", AppConfig.Key.LOG_ZOOM, null, menuClickListener))
menuList.add(CheckMenu(this, "Output Block Display Huge Image Log", AppConfig.Key.LOG_HUGE_IMAGE, null, menuClickListener))
menuList.add(CheckMenu(this, "Output Zoom Block Display Log", AppConfig.Key.LOG_ZOOM_BLOCK_DISPLAY, null, menuClickListener))
menuList.add(CheckMenu(this, "Output Used Time Log", AppConfig.Key.LOG_TIME, null, menuClickListener))
menuList.add(CheckMenu(this, "Sync Output Log To Disk (cache/sketch_log)", AppConfig.Key.OUT_LOG_2_SDCARD, null, menuClickListener))

Expand Down Expand Up @@ -358,25 +358,25 @@ class MainActivity : BaseActivity(), AppListFragment.GetAppListTagStripListener,
APP_LIST("My Apps", AppListFragment::class.java, false, false),
ABOUT("About Sketch", AboutFragment::class.java, false, false),

LARGE_IMAGE("Block Display Huge Image", HugeImageTestFragment::class.java, true, false),
BLOCK_DISPLAY_TEST("Block Display Huge Image", BlockDisplayTestFragment::class.java, true, false),
IMAGE_PROCESSOR_TEST("Image Processor Test", ImageProcessorTestFragment::class.java, true, false),
IMAGE_SHAPER_TESt("Image Shaper Test", ImageShaperTestFragment::class.java, true, false),
IMAGE_SHAPER_TEST("Image Shaper Test", ImageShaperTestFragment::class.java, true, false),
REPEAT_LOAD_OR_DOWNLOAD_TEST("Repeat Load Or Download Test", RepeatLoadOrDownloadTestFragment::class.java, true, false),
IN_BITMAP_TESt("inBitmap Test", InBitmapTestFragment::class.java, true, false),
IN_BITMAP_TEST("inBitmap Test", InBitmapTestFragment::class.java, true, false),
IMAGE_ORIENTATION_TEST("Image Orientation Test", ImageOrientationTestHomeFragment::class.java, true, false),
BASE64_IMAGE_TESt("Base64 Image Test", Base64ImageTestFragment::class.java, true, false),
BASE64_IMAGE_TEST("Base64 Image Test", Base64ImageTestFragment::class.java, true, false),
OTHER_TEST("Other Test", OtherTestFragment::class.java, true, !BuildConfig.DEBUG);

val fragment: Fragment?
get() {
try {
return fragmentClass.newInstance()
return try {
fragmentClass.newInstance()
} catch (e: InstantiationException) {
e.printStackTrace()
return null
null
} catch (e: IllegalAccessException) {
e.printStackTrace()
return null
null
}
}

Expand Down
Loading

0 comments on commit 2c880ee

Please sign in to comment.