您好,登錄后才能下訂單哦!
- public class tween extends Activity {
- // 聲明ImageView對(duì)象
- ImageView p_w_picpathView;
- // 聲明TextView
- TextView textView;
- // ImageView的alpha值
- int p_w_picpath_alpha = 0;
- // Handler對(duì)象用來(lái)給UI_Thread的MessageQueue發(fā)送消息
- Handler mHandler;
- // 線程是否運(yùn)行判斷變量
- boolean isrung = false;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.tween);
- SysApplication.getInstance().addActivity(this);
- final Context con=this.getApplicationContext();
- isrung = true;
- // 獲得ImageView的對(duì)象
- p_w_picpathView = (ImageView) this.findViewById(R.id.img);
- textView = (TextView) this.findViewById(R.id.tvgc);
- // 設(shè)置p_w_picpathView的Alpha值
- p_w_picpathView.setAlpha(p_w_picpath_alpha);
- textView.setAlpha(p_w_picpath_alpha);
- // 開(kāi)啟一個(gè)線程來(lái)讓Alpha值遞減
- new Thread(new Runnable() {
- @Override
- public void run() {
- while (isrung) {
- try {
- Thread.sleep(200);
- // 更新Alpha值
- updateAlpha();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }} }
- }).start();
- // 接受消息之后更新p_w_picpathview視圖
- mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- p_w_picpathView.setAlpha(p_w_picpath_alpha);
- // 設(shè)置textview顯示當(dāng)前的Alpha值
- textView.setAlpha(p_w_picpath_alpha);
- // 刷新視圖
- p_w_picpathView.invalidate();
- try{
- if(p_w_picpath_alpha==255)
- {
- isNetworkConnected(con);
- }
- }
- catch(Exception e){}
- } };}
- // 更新Alpha
- public void updateAlpha() {
- if (p_w_picpath_alpha +7<= 255) {
- p_w_picpath_alpha += 7;
- }
- else {
- p_w_picpath_alpha = 255;
- isrung = false; }
- // 發(fā)送需要更新p_w_picpathview視圖的消息-->這里是發(fā)給主線程
- mHandler.sendMessage(mHandler.obtainMessage());
- }
- public void isNetworkConnected(Context context) {
- if (context != null) {
- ConnectivityManager mConnectivityManager = (ConnectivityManager)context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
- if (mNetworkInfo != null) {
- NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- if(!mWiFiNetworkInfo.isConnected()){
- Toast.makeText(tween.this, "提示:當(dāng)前處于運(yùn)營(yíng)商網(wǎng)絡(luò)", Toast.LENGTH_SHORT).show(); }
- Intent it = new Intent();
- it.setClass(tween.this,tabhost.class);
- startActivity(it);
- }
- else{
- Toast.makeText(tween.this, "當(dāng)前網(wǎng)絡(luò)連接不可用!", Toast.LENGTH_SHORT).show();
- }}
- }
- }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。