Rexsee API紹介:Android画面ロック、Keyguard関数と拡張ソースコード


Androidは画面をロックするときにonPause()を呼び出します.ロック解除時にonResumeを呼び出し、保存したアプリケーションのリソースを読み込みます.プログラムの実行中に画面がロックされている場合、アプリケーションはonCreate()を呼び出し、onResume()を呼び出し、onPause()を呼び出します.
スクリーンのロック解除:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
KeyguardManager mKeyGuardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("  Activity  ");
mLock.disableKeyguard();

かなり簡単ですが、RexseeベースのAPIは、一言で済ませられます.
1.スクリーンロック解除:window.setTimeout('rexseeKeyguard.disable();alert('自動ロック解除!');',10000);
alert('電源キーを押して画面を閉じてから画面を開けてロック画面を見てください.10秒後に自動的にロックを解除します')
2.起動ロック画面:rexseeKeyguard.reEnable();
以下はrexseeKeyguard.JAvaソース:
/* 
* Copyright (C) 2011 The Rexsee Open Source Project 
* 
* Licensed under the Rexsee License, Version 1.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*      http://www.rexsee.com/CN/legal/license.html 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 
 
package rexsee.core.alarm;  
 
import rexsee.core.browser.JavascriptInterface;  
import rexsee.core.browser.RexseeBrowser;  
import android.app.KeyguardManager;  
import android.app.KeyguardManager.KeyguardLock;  
import android.content.Context;  
 
public class RexseeKeyguard implements JavascriptInterface {  
 
       private static final String INTERFACE_NAME = "Keyguard";  
       @Override  
       public String getInterfaceName() {  
               return mBrowser.application.resources.prefix + INTERFACE_NAME;  
       }  
       @Override  
       public JavascriptInterface getInheritInterface(RexseeBrowser childBrowser) {  
               return this;  
       }  
       @Override  
       public JavascriptInterface getNewInterface(RexseeBrowser childBrowser) {  
               return new RexseeKeyguard(childBrowser);  
       }  
 
       private final Context mContext;  
       private final RexseeBrowser mBrowser;  
       private KeyguardLock mKeyguardLock = null;  
 
       public RexseeKeyguard(RexseeBrowser browser) {  
               mBrowser = browser;  
               mContext = browser.getContext();  
       }  
       public RexseeKeyguard(Context context) {  
               mBrowser = null;  
               mContext = context;  
       }  
 
       //JavaScript Interface  
 
       public void enable() {  
               /*  
               try {  
                       DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);  
                       dpm.lockNow();  
               } catch (Exception e) {  
                       mBrowser.exception(getInterfaceName(), e);  
               }  
               */  
       }  
       public void reEnable() {  
               if (mKeyguardLock != null) {  
                       mKeyguardLock.reenableKeyguard();  
                       mKeyguardLock = null;  
               }  
       }  
       public void disable() {  
               KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);  
               mKeyguardLock = keyguardManager.newKeyguardLock("");  
               mKeyguardLock.disableKeyguard();  
       }  
 
}

Rexseeのソースコードと関数イベントのみを整理し、関連するdemoまたはソースコード解析はRexseeコミュニティで理解できます.現在、Rexseeは2000近くの拡張を提供しており、Androidのオリジナル機能を90%以上カバーし、すべてオープンしています.http://www.rexsee.com/