Home | History | Annotate | Download | only in policy
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.internal.policy;
     18 
     19 import com.android.ide.common.rendering.api.LayoutLog;
     20 import com.android.layoutlib.bridge.Bridge;
     21 import com.android.layoutlib.bridge.impl.RenderAction;
     22 
     23 import android.content.Context;
     24 import android.view.BridgeInflater;
     25 import android.view.FallbackEventHandler;
     26 import android.view.KeyEvent;
     27 import android.view.LayoutInflater;
     28 import android.view.View;
     29 import android.view.Window;
     30 import android.view.WindowManagerPolicy;
     31 
     32 /**
     33  * Custom implementation of PolicyManager that does nothing to run in LayoutLib.
     34  *
     35  */
     36 public class PolicyManager {
     37 
     38     public static Window makeNewWindow(Context context) {
     39         // this will likely crash somewhere beyond so we log it.
     40         Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
     41                 "Call to PolicyManager.makeNewWindow is not supported", null);
     42         return null;
     43     }
     44 
     45     public static LayoutInflater makeNewLayoutInflater(Context context) {
     46         return new BridgeInflater(context, RenderAction.getCurrentContext().getProjectCallback());
     47     }
     48 
     49     public static WindowManagerPolicy makeNewWindowManager() {
     50         // this will likely crash somewhere beyond so we log it.
     51         Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
     52                 "Call to PolicyManager.makeNewWindowManager is not supported", null);
     53         return null;
     54     }
     55 
     56     public static FallbackEventHandler makeNewFallbackEventHandler(Context context) {
     57         return new FallbackEventHandler() {
     58             @Override
     59             public void setView(View v) {
     60             }
     61 
     62             @Override
     63             public void preDispatchKeyEvent(KeyEvent event) {
     64             }
     65 
     66             @Override
     67             public boolean dispatchKeyEvent(KeyEvent event) {
     68                 return false;
     69             }
     70         };
     71     }
     72 }
     73