Android锁屏(四)

ScreenActivity被锁屏服务调用后显示指定的锁屏界面,相当于一个控制不同解锁界面的Controller。该类处理显示不同的解锁界面。同样这个类也处理一些细节的东西,隐藏状态栏等

[java]  view plain copy print ?
  1. import java.util.Timer;  
  2. import java.util.TimerTask;  
  3. import android.app.Activity;  
  4. import android.content.BroadcastReceiver;  
  5. import android.content.Context;  
  6. import android.content.Intent;  
  7. import android.content.IntentFilter;  
  8. import android.graphics.PixelFormat;  
  9. import android.os.Bundle;  
  10. import android.view.WindowManager;  
  11. /** 
  12.  * the controller of display interface 
  13.  * @author liao 
  14.  * 
  15.  */  
  16. public class ScreenActivity extends Activity {  
  17.   
  18.     private Timer timer;  
  19.   
  20.     @Override  
  21.     protected void onCreate(Bundle savedInstanceState) {  
  22.         super.onCreate(savedInstanceState);  
  23.         setContentView(R.layout.saf_fullscreen);  
  24.           
  25.         //Configuration parameters for this activity  
  26.         getWindow().setFormat(PixelFormat.TRANSLUCENT);  
  27.         getWindow().setBackgroundDrawable(null);  
  28.         hideStatusBar(true);  
  29.           
  30.         //Registered  receive close close activiys  
  31.         IntentFilter localIntentFilter = new IntentFilter();  
  32.         localIntentFilter.addAction(SAFLockConstants.INTENT_UNLOCK);  
  33.         registerReceiver(mReceiver, localIntentFilter);  
  34.     }  
  35.   
  36.     @Override  
  37.     protected void onResume() {  
  38.         super.onResume();  
  39.         //Set a timer, executing a timing task  
  40.         timer = new Timer();  
  41.         timer.schedule(new TimerTask() {  
  42.             @Override  
  43.             public void run() {  
  44.                 //Start the specified activity  
  45.                 Intent mLockScreenIntent = new Intent(  
  46.                         SAFLockConstants.LOCK_INTENT);  
  47.                 mLockScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  48.                 mLockScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);  
  49.                 startActivity(mLockScreenIntent);  
  50.             }  
  51.         }, 300);  
  52.     }  
  53.   
  54.     @Override  
  55.     protected void onDestroy() {  
  56.         super.onDestroy();  
  57.         //unregister this receiver  
  58.         unregisterReceiver(mReceiver);  
  59.     }  
  60.     /** 
  61.      * finish this activiy 
  62.      */  
  63.     private void close() {  
  64.         this.finish();  
  65.     }  
  66.   
  67.     /** 
  68.      * Receive the broadcast to finish activity 
  69.      */  
  70.     BroadcastReceiver mReceiver = new BroadcastReceiver() {  
  71.         @Override  
  72.         public void onReceive(Context context, Intent intent) {  
  73.             close();  
  74.         }  
  75.     };  
  76.   
  77.     /** 
  78.      * hide the statusBar of this activity 
  79.      * @param flag 
  80.      */  
  81.     public void hideStatusBar(boolean flag) {  
  82.   
  83.         if (!flag) {  
  84.             this.getWindow().clearFlags(  
  85.                     WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  86.             this.getWindow().addFlags(  
  87.                     WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);  
  88.         } else {  
  89.             this.getWindow().addFlags(  
  90.                     WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  91.             this.getWindow().clearFlags(  
  92.                     WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);  
  93.         }  
  94.     }  
  95. }  


 待续....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值