package cn.yinuo.picture;
import java.io.File;
import cn.yinuo.picture.R;
import cn.yinuo.search.Search;
import cn.yinuo.service.ImageServiceBean;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ImageListActivity extends Activity {
private ImageSwitcher imageSwitcher;
private Gallery gallery;
private int index = 0;//记录当前浏览的图片索引
private ImageServiceBean imageService;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button search = (Button) findViewById(R.id.search);
search.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
Intent intent=new Intent(ImageListActivity.this,Search.class);
startActivity(intent);
}
});
imageService = new ImageServiceBean(this);
imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
imageSwitcher.setFactory(new ImageSwitcher.ViewFactory() {
public View makeView() {
ImageView i = new ImageView(ImageListActivity.this);
i.setImageURI(imageService.getBigBitmap(index));//默认显示第一张图
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return i;
}
});
imageSwitcher.setOnClickListener(new View.OnClickListener() {//点击全屏显示图片
public void onClick(View v) {
showPicture();
}
});
gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));//绑定数据
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
imageSwitcher.setImageURI(imageService.getBigBitmap(position));
index = position;
}
});
gallery.setSelection(index);
Button quit = (Button) findViewById(R.id.quit);
quit.setOnClickListener(new View.OnClickListener() {//退出应用
public void onClick(View v) {
finish();
}
});
}
//打开全屏显示图片
private void showPicture() {
Intent intent = new Intent(ImageListActivity.this, ShowActivity.class);
intent.putExtra("imageuri", imageService.getBigBitmap(index).toString());
startActivity(intent);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) { //处理按键事件,注:Gallery已经处理了左右键移动图片,我们只需处理确认键打开全图
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER://确认键
index = gallery.getSelectedItemPosition();//获取当前图片的索引
imageSwitcher.setImageURI(imageService.getBigBitmap(index));//显示对应索引图片
showPicture();
break;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onDestroy() {
super.onDestroy();
if(this.getCacheDir().exists()){//清除缓存图片
for(File file : this.getCacheDir().listFiles()){
file.delete();
}
}
android.os.Process.killProcess(android.os.Process.myPid());//杀死进程,关闭应用
}
private final class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
mGalleryItemBackground = a.getResourceId(R.styleable.Gallery_android_galleryItemBackground, 0);
a.recycle();
}
/*返回图片数目 */
public int getCount() {
return imageService.getLength();
}
public long getItemId(int position) {
return position;
}
/* 覆盖的方法getView,返回一View对象 */
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
/* 设置图片给imageView对象 */
i.setImageURI(imageService.getSmallBitmap(position));
/* 重新设置图片的宽高 */
i.setScaleType(ImageView.ScaleType.FIT_XY);
/* 重新设置Layout的宽高 */
i.setLayoutParams(new Gallery.LayoutParams(70, 60));
/* 设置Gallery背景图 */
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
public Object getItem(int position) {
return imageService.getSmallBitmap(position);
}
}
}
分享到:
相关推荐
本文实例为大家分享了android网络图片查看器的具体代码,供大家参考,具体内容如下 效果图: 1.输入一个图片url 2.转换成bitmap位图 3.展示到ImageView上 xml: <?xml version=1.0 encoding=utf-8?> <...
本篇文章主要介绍了Android 网络图片查看器与网页源码查看器的相关知识。具有很好的参考价值。下面跟着小编一起来看下吧
网络图片查看器,主要有httpclient联网操作,子线程处理耗时操作,handler机制消息
Android网络通信之网络图片查看器事例代码,解决出现异常:android.os.NetworkOnMainThreadException方案
根据黑马视频跟学,再加上自己的注释,希望对想学Android的people有所帮助,能运行
viewpager+photoview自带圆点支持放大缩小,仿微信朋友圈图片查看器,自定义dialog [注意:本资源来自网络,如有侵权,请联系我删除,谢谢。]
安卓源码包android图片缓存&展示Android 异步加载图片等24个合集: ‘360全景查看demo.rar afinal框架实现图片的简单异步缓存加载.rar andengine中直接加载多张小图片合成一张大图片...自己在用的网络图片加载代码.zip
Android开发笔记 数据交互--网络图片查看器
主要描述了从android端查看web端的图片。这时主要用到了网络之间的通信。
主要介绍了Android编程实现网络图片查看器和网页源码查看器,结合实例形式分析了Android针对网络图片及网页的相关操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下
1.添加权限(访问网络权限) 2.创建异步请求对象 3.执行post请求(指定url路径,新建AsyncHttpResponseHandler方法) a)如果成功创建工厂对象 b)工厂对象的decodeByteArray把字节转换成Bitmap对象 c)设置图片
注意:支持网络图片、本地图片。 更新日志 v0.0.5新增:可设置缩放比例、缩放动画时间。 v1.2.0新增:可设置多种加载策略(仅普清、仅原图、手动模式、网络自适应) v1.2.1修复可能与app冲突的部分 v1.2.2新增:长...
RTSP Player是一个非常简单的IP摄像机查看器。 快速应用从IP摄像机,视频服务器和监视系统回放网络流。 主要特征: 支持的流传输类型:RTSP,RTP,UDP(支持多播流),HTTP-HLS,RTMP,MMS 从实时摄像机录制 数码...
Android-YRichEditor an android richedtor with ...详细使用请查看示例,有关原理可以查看Android原生简易图文编辑器 Thanks: XRichText: https://github.com/sendtion/XRichText cwac-richedit: https://github.c
信录中的联系人和添加联系人,23_网络通信之网络图片查看器,24_网络通信之网页源码查看器,25_网络通信之资讯客户 端,26_采用JSON格式返回数据给资讯客户端,27_网络通信之通过GET和POST方式提交参数给web应用,...
FinalBitmap可以自定义下载器,用来扩展其他协议显示网络图片,比如ftp等。同时可以自定义bitmap显示器, 在imageview显示图片的时候播放动画等(默认是渐变动画显示)。 4、xUtils框架 项目地址:...
图像浏览器ImageViewer是用于LAN / WAN的samba共享照片的开源图像查看器。 它仍在开发中。贡献准则编写测试代码审查其他指引我要和谁说话? 谢谢 :一个开源客户端库,以100%Java实现CIFS / SMB网络协议 :可缩放的...
信录中的联系人和添加联系人,23_网络通信之网络图片查看器,24_网络通信之网页源码查看器,25_网络通信之资讯客户 端,26_采用JSON格式返回数据给资讯客户端,27_网络通信之通过GET和POST方式提交参数给web应用,...