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();
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ImageSwither.rar (63个子文件)
ImageSwither
.project 848B
project.properties 361B
proguard.cfg 1KB
src
com
drocode
swithcer
GuideGallery.java 2KB
ImageAdapter.java 6KB
ImageActivity.java 6KB
AndroidManifest.xml 758B
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
feature_point.png 2KB
feature_point_cur.png 42KB
icon.png 4KB
one.png 114KB
grayicon.png 3KB
loading.gif 5KB
greenicon.png 3KB
Thumbs.db 17KB
three.png 65KB
four.png 65KB
two.png 60KB
drawable-mdpi
icon.png 3KB
layout
url_connection_image.xml 1KB
item.xml 888B
anim
push_up_in.xml 279B
push_up_out.xml 280B
values
strings.xml 170B
.settings
org.eclipse.jdt.core.prefs 629B
org.eclipse.core.resources.prefs 122B
assets
gen
com
drocode
swithcer
R.java 2KB
default.properties 35B
.classpath 288B
bin
resources.ap_ 326KB
classes
resources.ap_ 326KB
com
drocode
swithcer
R$layout.class 444B
R$drawable.class 691B
R$attr.class 346B
GuideGallery.class 3KB
R$id.class 523B
ImageAdapter$1.class 967B
R$anim.class 435B
ImageActivity$ImageTimerTask.class 2KB
R.class 593B
R$string.class 433B
ImageActivity$1.class 1KB
GuideGallery$1.class 872B
ImageActivity.class 4KB
ImageAdapter.class 3KB
ImageActivity$2.class 1KB
ImageActivity$3.class 1KB
classes.dex 12KB
ImageSwither.apk 334KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
feature_point.png 307B
feature_point_cur.png 586B
icon.png 4KB
one.png 114KB
grayicon.png 657B
greenicon.png 673B
three.png 64KB
four.png 65KB
two.png 60KB
drawable-mdpi
icon.png 2KB
classes.dex 12KB
ImageSwither.apk 334KB
共 63 条
- 1
资源评论
- zkf892248532015-07-31可以运行,但不是我需要的
- 六爷是我2014-10-09还不错,可以运行
- qijinling2014-11-10可以运行,但效果不太好
- oqzuser0sunxiaoye2015-04-21简单明了 给初学者很大的帮助 希望今后会有更多的示例代码发布分享
- lvhongping20122015-08-27很好很强大,非常感谢
sunny_rn
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功