您好,登錄后才能下訂單哦!
- public class tween extends Activity {
- // 聲明ImageView對象
- ImageView p_w_picpathView;
- // 聲明TextView
- TextView textView;
- // ImageView的alpha值
- int p_w_picpath_alpha = 0;
- // Handler對象用來給UI_Thread的MessageQueue發送消息
- Handler mHandler;
- // 線程是否運行判斷變量
- 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的對象
- p_w_picpathView = (ImageView) this.findViewById(R.id.img);
- textView = (TextView) this.findViewById(R.id.tvgc);
- // 設置p_w_picpathView的Alpha值
- p_w_picpathView.setAlpha(p_w_picpath_alpha);
- textView.setAlpha(p_w_picpath_alpha);
- // 開啟一個線程來讓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);
- // 設置textview顯示當前的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; }
- // 發送需要更新p_w_picpathview視圖的消息-->這里是發給主線程
- 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, "提示:當前處于運營商網絡", Toast.LENGTH_SHORT).show(); }
- Intent it = new Intent();
- it.setClass(tween.this,tabhost.class);
- startActivity(it);
- }
- else{
- Toast.makeText(tween.this, "當前網絡連接不可用!", Toast.LENGTH_SHORT).show();
- }}
- }
- }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。