package com.duoduo.nasadailyimage;
import java.io.IOException;
import android.app.Activity;
import android.app.ProgressDialog;
import android.app.WallpaperManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class NasaDailyImageActivity extends Activity {
private ProgressDialog dialog;
private Handler handler;
private Bitmap bitmap;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler = new Handler();
}
public void onRefresh(View view) {
dialog = ProgressDialog.show(this, "Loading", "Loading");
Thread thread = new Thread() {
public void run() {
handler.post(new Runnable() {
public void run() {
TextView imageDescriptionView = (TextView) findViewById(R.id.imageDescription);
imageDescriptionView
.setText(getString(R.string.image_description2));
dialog.dismiss();
}
});
}
};
thread.start();
}
public void setWallPaper(View view) {
Thread thread = new Thread() {
public void run() {
handler.post(new Runnable() {
public void run() {
WallpaperManager wallpaperManager = WallpaperManager
.getInstance(NasaDailyImageActivity.this);
// Resources res = getResources();
// bitmap = BitmapFactory.decodeResource(res,
// R.drawable.test);
try {
wallpaperManager.setResource(R.drawable.test);
// wallpaperManager.setBitmap(bitmap);
handler.post(new Runnable() {
public void run() {
Toast.makeText(NasaDailyImageActivity.this,
"壁纸设置成功", Toast.LENGTH_SHORT)
.show();
}
});
} catch (IOException e) {
handler.post(new Runnable() {
public void run() {
Toast.makeText(NasaDailyImageActivity.this,
"壁纸设置失败", Toast.LENGTH_SHORT)
.show();
}
});
e.printStackTrace();
}
}
});
}
};
thread.start();
}
}