当前位置:  编程技术>移动开发
本页文章导读:
    ▪gzip资料的解压缩        gzip文件的解压缩 to allow zlib compression/decompression of NSData. But a couple months ago I went looking for similar code to allow gzip compression/decompression. At the time I didn't find any, and found myself wading through the zlib docu.........
    ▪ 动态设立GridView宽,高        动态设置GridView宽,高 这里假设实例Id为mGrid: RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) mGrid.getLayoutParams(); // 取控件mGrid当前的布局参数 linearParams.height = 150; // 当控.........
    ▪ 汇集各大视频网站内容的网络视频播放器“天下视频&quot       汇集各大视频网站内容的网络视频播放器“天下视频" 天下视频集合了目前所有主流网络视频大站的资源,包括优酷、土豆、酷六、6间房、新浪视频等等,让您可以方便的欣赏各大站点的各.........

[1]gzip资料的解压缩
    来源: 互联网  发布时间: 2014-02-18
gzip文件的解压缩
to allow zlib compression/decompression of NSData. But a couple months ago I went looking for similar code to allow gzip compression/decompression. At the time I didn't find any, and found myself wading through the zlib documentation and header files until I came up with a solution. I've recently noticed that someone else on CocoaDev has also mentioned the solution, but it looks like they didn't fully implement a deflate version of it. So, without further ado, here is an NSData category that adds support for gzip compression and decompression:




@interface NSData (DDData)

// gzip compression utilities
- (NSData *)gzipInflate;
- (NSData *)gzipDeflate;

@end

-----------------------------------------


#include

@implementation NSData (DDData)

- (NSData *)gzipInflate
{
if ([self length] == 0) return self;

unsigned full_length = [self length];
unsigned half_length = [self length] / 2;

NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
BOOL done = NO;
int status;

z_stream strm;
strm.next_in = (Bytef *)[self bytes];
strm.avail_in = [self length];
strm.total_out = 0;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;

if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;
while (!done)
{
  // Make sure we have enough room and reset the lengths.
  if (strm.total_out >= [decompressed length])
   [decompressed increaseLengthBy: half_length];
  strm.next_out = [decompressed mutableBytes] + strm.total_out;
  strm.avail_out = [decompressed length] - strm.total_out;
 
  // Inflate another chunk.
  status = inflate (&strm, Z_SYNC_FLUSH);
  if (status == Z_STREAM_END) done = YES;
  else if (status != Z_OK) break;
}
if (inflateEnd (&strm) != Z_OK) return nil;

// Set real length.
if (done)
{
  [decompressed setLength: strm.total_out];
  return [NSData dataWithData: decompressed];
}
else return nil;
}

- (NSData *)gzipDeflate
{
if ([self length] == 0) return self;

z_stream strm;

strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.total_out = 0;
strm.next_in=(Bytef *)[self bytes];
strm.avail_in = [self length];

// Compresssion Levels:
//   Z_NO_COMPRESSION
//   Z_BEST_SPEED
//   Z_BEST_COMPRESSION
//   Z_DEFAULT_COMPRESSION

if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil;

NSMutableData *compressed = [NSMutableData dataWithLength:16384];  // 16K chunks for expansion

do {
 
  if (strm.total_out >= [compressed length])
   [compressed increaseLengthBy: 16384];
 
  strm.next_out = [compressed mutableBytes] + strm.total_out;
  strm.avail_out = [compressed length] - strm.total_out;
 
  deflate(&strm, Z_FINISH); 
 
} while (strm.avail_out == 0);

deflateEnd(&strm);

[compressed setLength: strm.total_out];
return [NSData dataWithData:compressed];
}

@end

转自 http://hi.baidu.com/leonqgl/blog/item/abe7eec7f9ac4dc6d10060b1.html

    
[2] 动态设立GridView宽,高
    来源: 互联网  发布时间: 2014-02-18
动态设置GridView宽,高
这里假设实例Id为mGrid:
 RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) mGrid.getLayoutParams();
    // 取控件mGrid当前的布局参数
     linearParams.height = 150;
    // 当控件的高强制设成75象素
     mGrid.setLayoutParams(linearParams);
    使设置好的布局参数应用到控件mGrid2


这里要说的是GridView的父View要是RelativeLayout的View类型,不然就会报错,本来这个尺寸设置都是相对父View来进行设置的.
    现在写在这里供自己以后参考.

    
[3] 汇集各大视频网站内容的网络视频播放器“天下视频&quot
    来源: 互联网  发布时间: 2014-02-18
汇集各大视频网站内容的网络视频播放器“天下视频"

天下视频集合了目前所有主流网络视频大站的资源,包括优酷、土豆、酷六、6间房、新浪视频等等,让您可以方便的欣赏各大站点的各类视频,同时可以将您喜欢的视频分享到sina微博。


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3