Home | History | Annotate | Download | only in policy
      1 /*
      2  * Copyright (C) 2015 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 android.content.Context;
     20 import android.content.res.AssetManager;
     21 import android.content.res.Resources;
     22 import android.view.ContextThemeWrapper;
     23 import android.view.WindowManager;
     24 import android.view.WindowManagerImpl;
     25 
     26 /**
     27  * Context for decor views which can be seeded with pure application context and not depend on the
     28  * activity, but still provide some of the facilities that Activity has,
     29  * e.g. themes, activity-based resources, etc.
     30  *
     31  * @hide
     32  */
     33 class DecorContext extends ContextThemeWrapper {
     34     private PhoneWindow mPhoneWindow;
     35     private WindowManager mWindowManager;
     36     private Resources mActivityResources;
     37 
     38     public DecorContext(Context context, Resources activityResources) {
     39         super(context, null);
     40         mActivityResources = activityResources;
     41     }
     42 
     43     void setPhoneWindow(PhoneWindow phoneWindow) {
     44         mPhoneWindow = phoneWindow;
     45         mWindowManager = null;
     46     }
     47 
     48     @Override
     49     public Object getSystemService(String name) {
     50         if (Context.WINDOW_SERVICE.equals(name)) {
     51             if (mWindowManager == null) {
     52                 WindowManagerImpl wm =
     53                         (WindowManagerImpl) super.getSystemService(Context.WINDOW_SERVICE);
     54                 mWindowManager = wm.createLocalWindowManager(mPhoneWindow);
     55             }
     56             return mWindowManager;
     57         }
     58         return super.getSystemService(name);
     59     }
     60 
     61     @Override
     62     public Resources getResources() {
     63         return mActivityResources;
     64     }
     65 
     66     @Override
     67     public AssetManager getAssets() {
     68         return mActivityResources.getAssets();
     69     }
     70 }
     71