转载请注明出处王亟亟的大牛之路

上周大多数时间都是依据兴起,想到什么做什么写了几个自己定义控件,把Soyi丢在那没怎么动,今天就把写的东西整合进来,顺便把SOyi”个人研发的结构理一下”。

先上一下今天整合之后的效果,以及新加进来的几个库:

依照惯例,贴一下Gradle的配置:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'com.apkfuns.logutils:library:1.0.6'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.squareup.okhttp:okhttp:2.7.0'
compile 'commons-io:commons-io:2.4'
compile 'com.ikimuhendis:ldrawer:0.1'
compile 'com.dodola:listviewext:1.0'
compile 'com.bm.photoview:library:1.3.6'
compile 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'
compile 'net.frakbot:jumpingbeans:1.3.0'
compile 'com.bigkoo:convenientbanner:1.1.4'
compile files('libs/universal-image-loader-1.9.4.jar')
compile 'com.google.code.gson:gson:2.5'
compile 'com.android.support:recyclerview-v7:23.1.+'
compile 'com.felipecsl:gifimageview:2.0.0'
compile 'com.android.support:support-annotations:23.1.1'
}

是不是加进来的东西越来越多了? 之后还会继续加入(当然,实际项目中不建议使用过多的第三方框架,毕竟大框架的个别功能你是用不到的,而自己却载入了那么多内容,easy加大apk无谓的容积)


这一篇我们加了什么,讲些什么??

GifImageView和简单的代码梳理。(有一定工作经历的小伙伴能够不看第二部分,源代码还是在最以下)

项目地址:https://github.com/felipecsl/GifImageView

作者:http://felipecsl.com

通常为我们的ImageView仅仅支持普通的静态图片的展现(png,jpg等),假设是动图什么的就须要我们自己写了。可是有人给我们写好了,为何不用呢?

楼主这边为大家简单的分析下这个库的实现。

public class GifImageView extends ImageView implements Runnable

↑ 继承于ImageView继承Runnable,也就是说我们的各种绘画的操作事实上是在多线程的环境下进行的。

 private final Runnable updateResults = new Runnable() {
@Override
public void run() {
if (tmpBitmap != null && !tmpBitmap.isRecycled()) {
setImageBitmap(tmpBitmap);
}
}
};

推断临时的tmpBitmap 不为空,而且没有被释放,然后给imageview设置这张图片,这种方法在handle中被多次传递。

 private final Runnable cleanupRunnable = new Runnable() {
@Override
public void run() {
if (tmpBitmap != null && !tmpBitmap.isRecycled()) {
tmpBitmap.recycle();
}
tmpBitmap = null;
gifDecoder = null;
animationThread = null;
shouldClear = false;
}
};

↑ 回收tmpBitmap 而且。清空一系列參数。

  @Override public void run() {
if (shouldClear) {
handler.post(cleanupRunnable);
return;
} final int n = gifDecoder.getFrameCount();
do {
for (int i = 0; i < n; i++) {
if (!animating) {
break;
}
//milliseconds spent on frame decode
long frameDecodeTime = 0;
try {
long before = System.nanoTime();
tmpBitmap = gifDecoder.getNextFrame();
frameDecodeTime = (System.nanoTime() - before) / 1000000;
if (frameCallback != null) {
tmpBitmap = frameCallback.onFrameAvailable(tmpBitmap);
} if (!animating) {
break;
}
handler.post(updateResults);
} catch (final ArrayIndexOutOfBoundsException | IllegalArgumentException e) {
Log.w(TAG, e);
}
if (!animating) {
break;
}
gifDecoder.advance();
try {
int delay = gifDecoder.getNextDelay();
// Sleep for frame duration minus time already spent on frame decode
// Actually we need next frame decode duration here,
// but I use previous frame time to make code more readable
delay -= frameDecodeTime;
if (delay > 0) {
Thread.sleep(framesDisplayDuration > 0 ? framesDisplayDuration : delay);
}
} catch (final Exception e) {
// suppress any exception
// it can be InterruptedException or IllegalArgumentException
}
}
} while (animating);
}

主要实现的run方法。先推断是否clear,默认false.(也就是animationThread 这条工作线程的行为)

然后获取从文件读取的帧的数目(这边仅仅解释下主实现类的内容,Gif事实上就是帧动画)

接下来循环,開始更替图片操作(理论上一帧一画面)

推断假设正在动画效果中。就不进行在此循环操作(由于可能出现手动调用startAnimation()的可能)

接下来就是一帧持续多久,然后替换,然后直到最后一帧的显示结束,再继续。

整个包大概 10来个类,大家能够自己有时间具体读取。

总结:现对于https://github.com/frapontillo/ImageViewEx的实现属于比較轻量级的了。毕竟简单有用是大家更喜欢的。实现大致就是依据传入的数组进行计算,把每一帧的动画进行迭代的呈如今UI界面上,然后在调用StopAnimation()或者clear()之前会形成一个环。

当然这种频繁刷UI界面还是会有一定的性能影响。看你怎么使用了。


接下来再说下“个人研发”模块。那这是什么东西呢?

非常显然看上去就是一个ListView套着一个ListView然后第一层的ListView的选择会让第二层的内容大不同样,像这样。

那么难道,我去写一大堆新的xml么?

No,找共同点,遵循OOP会发现共同点。

统一的item,统一的呈现页面(一个Title,1个展示图,一个文字描写叙述,一个超级链接)

那就是主要的MVC模式我们在 View。Controller层面的内容是大致同样的那么就仅仅要在Model层做出一些改变就好了。那么从头到尾 我 仅仅须要一个布局文件,像这样

<?

xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Activity.CodeActivityPro.CodeActivity"> <android.support.v7.widget.RecyclerView
android:id="@+id/codeListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:scrollbars="none"
android:layoutAnimation="@anim/code_item_anim" />
</RelativeLayout>

然后就是展示页面,像这样

<?xml version="1.0" encoding="utf-8"?

>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="soyi.pro.com.soyi.Activity.CodeActivityPro.ShowCodeViewActivity"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <com.felipecsl.gifimageview.library.GifImageView
android:id="@+id/showCodeViewImage"
android:layout_gravity="center"
android:layout_width="350dp"
android:layout_height="450dp"
android:src="@drawable/tempimage"/> <TextView
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="载入中..."
android:textSize="20dp"
android:id="@+id/jumpText"
android:layout_alignBottom="@id/showCodeViewImage"
android:layout_gravity="center"/>
</LinearLayout>
</ScrollView>

其它一系列就从arrays.xml里面获取内容就好了当然。传递通过intent.putExtra,或者假设要2层都做在一个页面里那就设置点静态变量什么的。记录用户的选择吧。

怎样让你的TextView能够变为链接?

 textView.setText(Html.fromHtml(getIntent().getStringExtra("CodeActivityToShowCodeActivityMSG")  +"<br><a href=\""+getIntent().getStringExtra("CodeActivityToShowCodeActivityGitUrl")+"\">点击链接可訪问项目地址</a>"));
textView.setMovementMethod(LinkMovementMethod.getInstance());

源代码地址:https://github.com/ddwhan0123/SoyiGit

记得点个赞哦!

整合大量开源库项目(八)能够载入Gif动画的GifImageView的更多相关文章

  1. 整合大量开源库项目(五)跳动的TextView JumpingBeans,良好体验的滚动条ConvenientBanner

    转载请注明出处:王亟亟的大牛之路 时间过得非常快,这一系列已经写了第五篇了(感觉还要写好久).今天又引入了2个非常好用的库JumpingBeans,ConvenientBanner.首先.先看一下效果 ...

  2. Android开源库项目集锦

    一.兼容类库 ActionBarSherlock : Action Bar是Android 3.0后才開始支持的,ActionBarSherlock是让Action Bar功能支持2.X后的全部平台. ...

  3. iOS项目中常用的第三方开源库

    1.项目使用的第三方开源库 项目使用了CocoaPods(类似java中的maven)管理常用的第三方库,一些特殊的单独引用,下面介绍下比较好用的几个. (1)AFNetworking 目前比较推荐的 ...

  4. 第三方开源库和jar包的区别

    jar包和第三方开源库的根本区别在于,开源库的功能比jar包功能更强大,通过引入库项目可以访问java文件以及该开源库项目下的资源文件,例如图片,layout等文件 jar包中只能放class文件 引 ...

  5. Android 使用开源库载入网络图片

    Android 使用开源库载入网络图片,使用开源库载入图片.单击listview弹出popupwindow弹出框详情查看: Android 单击listview弹出popupwindow弹出框 ,里面 ...

  6. iOS 项目中用到的一些开源库和第三方组件

    iOS 项目中用到的一些 iOS 开源库和第三方组件 分享一下我目前所在公司 iOS 项目中用到的一些 iOS 开源库和第三方组件, 感谢开源, 减少了我们的劳动力, 节约了我们大量的时间, 让我们有 ...

  7. Android 开源库和项目 3

    Android 开源库和项目 Android 开源库和项目 2 1.Matisse Android 图片选择器 -- 知乎开源 github 地址:https://github.com/zhihu/M ...

  8. 如何在Android Studio项目中导入开源库?

    前两天,谷歌发布了Android Studio 1.0的正式版,也有更多的人开始迁移到Android Studio进行开发.然而,网上很多的开源库,控件等还是以前的基于Eclipse进行开发,很多人不 ...

  9. AndroidStudio怎样导入library项目开源库

    AndroidStudio是一款非常强大的android程序开发软件,在里面集成了几乎所有android开发中需要使用的工具,编译.运行.打包.开发.调试等功能一应俱全,可以使用起来非常方便. 今天要 ...

随机推荐

  1. Android ListView 和 ***Adapter 从本地/网络获取歌曲列表

    本文内容 环境 项目结构 测试数据 演示 1:SimpleAdapter 演示 2:BaseAdapter 演示 3:CustomLazyList 演示 4:CustomLazyCompleteLis ...

  2. SQL还原后:目录名称无效

    使用Sql Server备份文件,还原数据库出现如下错误:目录名称无效 解决方法:在系统临时文件夹内,如C:\Users\Administrator\AppData\Local\Temp\ 下新建名称 ...

  3. SpringBoot 启动错误搜集

    Spring Boot:The Bean Validation API is on the classpath but no implementation could be found https:/ ...

  4. c数据库读写分离和负载均衡策略

    最近在学习数据库的读写分离和主从复制,采用的是一主多从策略,采用轮询的方式,读取从数据库的内容.但是,假如某一台从数据库宕机了,而客户端不知道,每次轮选到此从数据库,不都要报错?到网上查阅了资料,找到 ...

  5. 当Ruby的model名字出错时,在现实view时显示错误的提示

    app/controllers/courses_controller.rb:1:in `<top (required)>' app/controllers/courses_controll ...

  6. Jenkins 持续集成综合实战

    Jenkins 是一款流行的开源持续集成(Continuous Integration)工具,广泛用于项目开发,具有自动化构建.测试和部署等功能.本文以 CentOS7 环境为例,总结了 Jenkin ...

  7. WIP 002- Rating info page design

    Please design the screen When Permitted Subdivision selected Yes hide Flood Zone, otherwise show it.

  8. VB操作EXCEL文件大全

    Private Sub writeToExcel(strTmp1() As String, colTmp1 As Collection)'' Dim tmp1 Dim i1 As Integer, i ...

  9. Flash:利用Bitmapdata,ColorTransform,DrawPath,制造绚丽效果

    JamesLi的文章:http://www.adobe.com/cn/devnet/actionscript/articles/silkflash-as.html 总结一下绚丽效果的核心: 1.利用一 ...

  10. Multitenant Architecture---PDB与CDB

    一.多租户框架 多租户技术(英语:multi-tenancy technology)或称多重租赁技术,是一种软件架构技术,它是在探讨与实现如何于多用户的环境下共用相同的系统或程序组件,并且仍可确保各用 ...