package com.drocode.swithcer;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.AdapterView.OnItemClickListener;
public class ImageActivity extends Activity {
//public HashMap<String,Bitmap> imagesCache=new HashMap<String, Bitmap>();//图片缓存
public List<String> urls ;
public GuideGallery images_ga;
private int positon = 0;
private Thread timeThread = null;
public boolean timeFlag = true;
private boolean isExit = false;
public ImageTimerTask timeTaks = null;
Uri uri;
Intent intent;
int gallerypisition = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.url_connection_image);
timeTaks = new ImageTimerTask();
autoGallery.scheduleAtFixedRate(timeTaks, 5000, 5000);
timeThread = new Thread() {
public void run() {
while(!isExit) {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (timeTaks) {
if(!timeFlag){
timeTaks.timeCondition = true;
timeTaks.notifyAll();
}
}
timeFlag = true;
}
};
};
timeThread.start();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
init();
}
private void init(){
Bitmap image= BitmapFactory.decodeResource(getResources(),R.drawable.icon);
//imagesCache.put("background_non_load",image); //设置缓存中默认的图片
images_ga = (GuideGallery) findViewById(R.id.image_wall_gallery);
images_ga.setImageActivity(this);
ImageAdapter imageAdapter = new ImageAdapter(this);
images_ga.setAdapter(imageAdapter);
LinearLayout pointLinear = (LinearLayout) findViewById(R.id.gallery_point_linear);
pointLinear.setBackgroundColor(Color.argb(200, 135, 135, 152));
for (int i = 0; i < 4; i++) {
ImageView pointView = new ImageView(this);
if(i==0){
pointView.setBackgroundResource(R.drawable.feature_point_cur);
}else
pointView.setBackgroundResource(R.drawable.feature_point);
pointLinear.addView(pointView);
}
images_ga.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
System.out.println(arg2+"arg2");
/*switch (arg2) {
case 0:
uri = Uri.parse("http://www.36939.net/");
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
case 1:
uri = Uri.parse("http://www.jiqunejia.com/default.aspx");
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
case 2:
uri = Uri.parse("http://www.jiqunejia.tv/");
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
case 3:
uri = Uri.parse("http://city.4000100006.com/");
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
default:
break;
}*/
}
});
}
public void changePointView(int cur){
LinearLayout pointLinear = (LinearLayout) findViewById(R.id.gallery_point_linear);
View view = pointLinear.getChildAt(positon);
View curView = pointLinear.getChildAt(cur);
if(view!=null&& curView!=null){
ImageView pointView = (ImageView)view;
ImageView curPointView = (ImageView)curView;
pointView.setBackgroundResource(R.drawable.feature_point);
curPointView.setBackgroundResource(R.drawable.feature_point_cur);
positon = cur;
}
}
final Handler autoGalleryHandler = new Handler() {
public void handleMessage(Message message) {
super.handleMessage(message);
switch (message.what) {
case 1:
images_ga.setSelection(message.getData().getInt("pos"));
break;
}
}
};
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
timeFlag = false;
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
timeTaks.timeCondition = false;
}
class ImageTimerTask extends TimerTask{
public volatile boolean timeCondition = true;
// int gallerypisition = 0;
public void run() {
synchronized (this) {
while(!timeCondition) {
try {
Thread.sleep(100);
wait();
} catch (InterruptedException e) {
Thread.interrupted();
}
}
}
try {
gallerypisition = images_ga.getSelectedItemPosition() + 1;
System.out.println(gallerypisition+"");
Message msg = new Message();
Bundle date = new Bundle();// 存放数据
date.putInt("pos", gallerypisition);
msg.setData(date);
msg.what = 1;//消息标识
autoGalleryHandler.sendMessage(msg);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Timer autoGallery = new Timer();
}
android Gallery图片轮播
5星 · 超过95%的资源 需积分: 10 195 浏览量
2013-10-04
17:35:41
上传
评论 8
收藏 2.39MB RAR 举报
yuan465887375
- 粉丝: 8
- 资源: 6
最新资源
- 基于UC3842+LTS26Q1565A设计PC机充电器 硬件(原理图+PCB)工程文件.zip
- Hive SQL经典面试题,大数据SQL经典面试题
- Qt实现喷码器代码,实现二维码、条形码、图形的旋转、移动等
- 基于LM324芯片比较器传感器模块AD09设计硬件(原理图+PCB)工程文件.zip
- HTTP请求 - 记一笔-添加记账.jmx
- 2205040245凡永超硬间隔svm.ipynb
- Qt喷码器demo,演示软件,不是代码
- 目标跟踪-基于目标中心点同时进行目标检测+目标跟踪算法实现-项目源码-优质项目实战.zip
- Python《文本特征分析-全唐诗数据挖掘及分析 》+源代码
- Netron-Setup-4.5.0
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页