Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2014 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.example.android.visualgamecontroller.util;
     18 
     19 import android.app.Activity;
     20 import android.view.View;
     21 import android.view.WindowManager;
     22 
     23 /**
     24  * A base implementation of {@link SystemUiHider}. Uses APIs available in all
     25  * API levels to show and hide the status bar.
     26  */
     27 public class SystemUiHiderBase extends SystemUiHider {
     28     /**
     29      * Whether or not the system UI is currently visible. This is a cached value
     30      * from calls to {@link #hide()} and {@link #show()}.
     31      */
     32     private boolean mVisible = true;
     33 
     34     /**
     35      * Constructor not intended to be called by clients. Use
     36      * {@link SystemUiHider#getInstance} to obtain an instance.
     37      */
     38     protected SystemUiHiderBase(Activity activity, View anchorView, int flags) {
     39         super(activity, anchorView, flags);
     40     }
     41 
     42     @Override
     43     public void setup() {
     44         if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) {
     45             mActivity.getWindow().setFlags(
     46                     WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
     47                             | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
     48                     WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
     49                             | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
     50         }
     51     }
     52 
     53     @Override
     54     public boolean isVisible() {
     55         return mVisible;
     56     }
     57 
     58     @Override
     59     public void hide() {
     60         if ((mFlags & FLAG_FULLSCREEN) != 0) {
     61             mActivity.getWindow().setFlags(
     62                     WindowManager.LayoutParams.FLAG_FULLSCREEN,
     63                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
     64         }
     65         mOnVisibilityChangeListener.onVisibilityChange(false);
     66         mVisible = false;
     67     }
     68 
     69     @Override
     70     public void show() {
     71         if ((mFlags & FLAG_FULLSCREEN) != 0) {
     72             mActivity.getWindow().setFlags(
     73                     0,
     74                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
     75         }
     76         mOnVisibilityChangeListener.onVisibilityChange(true);
     77         mVisible = true;
     78     }
     79 }
     80