溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

首屏動(dòng)畫及驗(yàn)證網(wǎng)絡(luò)狀態(tài)跳轉(zhuǎn)

發(fā)布時(shí)間:2020-08-03 00:29:08 來(lái)源:網(wǎng)絡(luò) 閱讀:445 作者:王村橋 欄目:開(kāi)發(fā)技術(shù)
  1. public class tween extends Activity {   
  2.     // 聲明ImageView對(duì)象   
  3.     ImageView p_w_picpathView;   
  4.     // 聲明TextView   
  5.     TextView textView;   
  6.     // ImageView的alpha值   
  7.     int p_w_picpath_alpha = 0;   
  8.     // Handler對(duì)象用來(lái)給UI_Thread的MessageQueue發(fā)送消息   
  9.     Handler mHandler;   
  10.     // 線程是否運(yùn)行判斷變量   
  11.     boolean isrung = false;   
  12.    
  13.     @Override   
  14.     public void onCreate(Bundle savedInstanceState) {   
  15.         super.onCreate(savedInstanceState);         
  16.         requestWindowFeature(Window.FEATURE_NO_TITLE);   
  17.         setContentView(R.layout.tween); 
  18.         SysApplication.getInstance().addActivity(this);  
  19.         final Context con=this.getApplicationContext(); 
  20.         isrung = true;   
  21.         // 獲得ImageView的對(duì)象   
  22.         p_w_picpathView = (ImageView) this.findViewById(R.id.img);   
  23.         textView = (TextView) this.findViewById(R.id.tvgc);   
  24.        // 設(shè)置p_w_picpathView的Alpha值   
  25.         p_w_picpathView.setAlpha(p_w_picpath_alpha);   
  26.         textView.setAlpha(p_w_picpath_alpha);   
  27.         // 開(kāi)啟一個(gè)線程來(lái)讓Alpha值遞減   
  28.         new Thread(new Runnable() {   
  29.             @Override   
  30.             public  void run() {   
  31.                 while (isrung) {   
  32.                     try {   
  33.                         Thread.sleep(200);   
  34.                         // 更新Alpha值   
  35.                         updateAlpha();   
  36.                     } catch (InterruptedException e) {   
  37.                         e.printStackTrace();   
  38.                     }} }   
  39.         }).start();   
  40.         // 接受消息之后更新p_w_picpathview視圖   
  41.         mHandler = new Handler() {   
  42.             @Override   
  43.             public void handleMessage(Message msg) {   
  44.                 super.handleMessage(msg);   
  45.                 p_w_picpathView.setAlpha(p_w_picpath_alpha);   
  46.                 // 設(shè)置textview顯示當(dāng)前的Alpha值   
  47.                 textView.setAlpha(p_w_picpath_alpha);  
  48.                 // 刷新視圖   
  49.                 p_w_picpathView.invalidate();  
  50.               try
  51.                   if(p_w_picpath_alpha==255
  52.                   { 
  53.                 isNetworkConnected(con); 
  54.                 } 
  55.                   } 
  56.               catch(Exception e){} 
  57.                
  58.             } };}   
  59.     // 更新Alpha   
  60.     public void updateAlpha() {   
  61.         if (p_w_picpath_alpha +7<= 255) {   
  62.             p_w_picpath_alpha += 7;   
  63.         }  
  64.         else { 
  65.                p_w_picpath_alpha = 255
  66.                isrung = false;  }   
  67.         // 發(fā)送需要更新p_w_picpathview視圖的消息-->這里是發(fā)給主線程   
  68.         mHandler.sendMessage(mHandler.obtainMessage());   
  69.          
  70. }   
  71.     public void isNetworkConnected(Context context)  {   
  72.         if (context != null) {   
  73.              ConnectivityManager mConnectivityManager = (ConnectivityManager)context   
  74.                 .getSystemService(Context.CONNECTIVITY_SERVICE);   
  75.              NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();   
  76.            if (mNetworkInfo != null) {   
  77.                NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 
  78.                NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);  
  79.               if(!mWiFiNetworkInfo.isConnected()){ 
  80.                Toast.makeText(tween.this"提示:當(dāng)前處于運(yùn)營(yíng)商網(wǎng)絡(luò)", Toast.LENGTH_SHORT).show(); } 
  81.               Intent it = new Intent(); 
  82.               it.setClass(tween.this,tabhost.class); 
  83.               startActivity(it); 
  84.             
  85.            } 
  86.            else
  87.                Toast.makeText(tween.this"當(dāng)前網(wǎng)絡(luò)連接不可用!", Toast.LENGTH_SHORT).show();        
  88.             }} 
  89.           }   

 

向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI