温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

首屏动画及验证网络状态跳转

发布时间:2020-08-03 00:29:08 来源:网络 阅读:448 作者:王村桥 栏目:开发技术
  1. public class tween extends Activity {   
  2.     // 声明ImageView对象   
  3.     ImageView p_w_picpathView;   
  4.     // 声明TextView   
  5.     TextView textView;   
  6.     // ImageView的alpha值   
  7.     int p_w_picpath_alpha = 0;   
  8.     // Handler对象用来给UI_Thread的MessageQueue发送消息   
  9.     Handler mHandler;   
  10.     // 线程是否运行判断变量   
  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的对象   
  22.         p_w_picpathView = (ImageView) this.findViewById(R.id.img);   
  23.         textView = (TextView) this.findViewById(R.id.tvgc);   
  24.        // 设置p_w_picpathView的Alpha值   
  25.         p_w_picpathView.setAlpha(p_w_picpath_alpha);   
  26.         textView.setAlpha(p_w_picpath_alpha);   
  27.         // 开启一个线程来让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.                 // 设置textview显示当前的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.         // 发送需要更新p_w_picpathview视图的消息-->这里是发给主线程   
  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"提示:当前处于运营商网络", 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"当前网络连接不可用!", Toast.LENGTH_SHORT).show();        
  88.             }} 
  89.           }   

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI