有setimage()
和setWeather()
方法來改變圖片。 我想成爲一個補間動畫,在服務上調用setweather
和setimage
。 我需要你的幫助。我想做一個動畫的時候改變服務的圖片視圖
@Override
public void onCreate() {
super.onCreate();
mIv = new ImageView(this);
mIv.setImageResource(R.drawable.ic_launcher);
mContentResolver = getContentResolver();
mProviderObserver = new ContentObserver(new Handler()){
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
if(uri.compareTo(mUri) == 0){
String weather =mContentResolver.getType(uri);
setWeather(weather);
}
}
};
mContentResolver.registerContentObserver(mUri, true, mProviderObserver);
rnsmc= new ReadNewSmsMissedCall(mContentResolver);
rnsmc.setChangeTelephonyListener(new ChangeTelephonyListener() {
public void onChange() {
setImage();
}
});
rnsmc.registerObserver();
setImage();
mHandler = new Handler();
mRunnable = new Runnable(){
@Override
public void run() {
if(count == 1){
setImage();
count = 2;
}
else if(count == 2){
weather = mContentResolver.getType(mUri);
setWeather(weather);
ount = 1;
}
mHandler.postDelayed(mRunnable, 1000);
}
};
mRunnable.run();
mTask = new TimerTask(){
@Override
public void run() {
new DoTask().execute(url);
setWeather(weather);
}
};
mTimer = new Timer();
mTimer.schedule(mTask, 500, 100000);
new DoTask().execute(url);
}
public class DoTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
for (String urlVal : params) {
mPullParser = new PullParser(urlVal);
}
mData = mPullParser.parse();
ContentValues value = new ContentValues();
value.put("weather", mData);
mContentResolver.insert(mUri,value);
return mData;
}
}
private void setImage(){ //
int smsCount = rnsmc.getCountNewSms();
int callCount = rnsmc.getCountMissedCall();
if(smsCount > 0 && callCount >0){
mIv.setImageResource(R.drawable.bump);
count = 1;
}
}
private void setWeather(String weather){///
}
你在使用AsyncTask嗎? –
@哈迪是!嗯.. setweather,它通過解析天氣來轉換圖像。 解析是在asyctask上。 –