apk更新触发界面
package com.xxx.update;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.xxx.base.SczwApplication;
import com.xxx.sczwdemo.R;
import com.xxx.update.DownloadService.DownloadBinder;
import com.xxx.utils.DimensUtils;
public class UpdateNotifiActivity extends Activity {
private Button btn_cancel;
private TextView tv_progress;
private DownloadBinder binder;
private boolean isBinded;
private ProgressBar mProgressBar;
// 获取到下载url后,直接复制给MapApp,里面的全局变量
private String downloadUrl;
//
private boolean isDestroy = true;
private SczwApplication sczwApp;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.update_activity);
sczwApp = SczwApplication.getInstance();
btn_cancel = (Button) findViewById(R.id.cancel);
tv_progress = (TextView) findViewById(R.id.currentPro);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
btn_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
binder.cancel();
binder.cancelNotification();
finish();
}
});
}
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
isBinded = false;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
binder = (DownloadBinder) service;
Log.i("yzh","服务启动!!!");
// 开始下载
isBinded = true;
binder.addCallback(callback);
binder.start();
}
};
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (isDestroy && sczwApp.isDownload()) {
Intent it = new Intent(UpdateNotifiActivity.this, DownloadService.class);
startService(it);
bindService(it, conn, Context.BIND_AUTO_CREATE);
}
Log.i("yzh"," notification onresume");
}
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
super.onNewIntent(intent);
if (isDestroy && sczwApp.isDownload()) {
Intent it = new Intent(UpdateNotifiActivity.this, DownloadService.class);
startService(it);
bindService(it, conn, Context.BIND_AUTO_CREATE);
}
Log.i("yzh"," notification onNewIntent");
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("yzh"," notification onPause");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
isDestroy = false;
Log.i("yzh"," notification onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
if (isBinded) {
Log.i("yzh"," onDestroy unbindservice");
unbindService(conn);
}
if (binder != null && binder.isCanceled()) {
Log.i("yzh"," onDestroy stopservice");
Intent it = new Intent(this, DownloadService.class);
stopService(it);
}
}
private ICallbackResult callback = new ICallbackResult() {
@Override
public void OnBackResult(Object result) {
// TODO Auto-generated method stub
if ("finish".equals(result)) {
finish();
return;
}
int i = (Integer) result;
mProgressBar.setProgress(i);
mHandler.sendEmptyMessage(i);
}
};
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
tv_progress.setText("下载进度 : " + msg.what + "%");
if(msg.what==1){
ObjectAnimator.ofFloat(tv_progress, "translationY", DimensUtils.dip2px(20f) ,0.0f).setDuration(500).start();
ObjectAnimator.ofFloat(tv_progress, "alpha", 0.0f , 1.0f).setDuration(500).start();
tv_progress.setVisibility(View.VISIBLE);
ObjectAnimator.ofFloat(btn_cancel, "alpha", 0.0f , 1.0f).setDuration(500).start();
btn_cancel.setVisibility(View.VISIBLE);
}
};
};
public interface ICallbackResult {
public void OnBackResult(Object result);
}
}
应用更新相关文章:
应用更新之_DownloadService
应用更新之_update_activity.xml
应用更新之_update_notif_ly.xml
应用更新之_permission