@@ -0,0 +1,2766 @@
+/*%0A * Copyright 2014 Kevin Quan (kevin.quan@gmail.com)%0A * %0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.kevinquan.android.ui;%0A%0Aimport android.app.Activity;%0Aimport android.util.Log;%0Aimport android.view.View;%0A%0A/**%0A * Helper class to maintain system UI visibility across activity lifecycle%0A * @author Kevin Quan (kevin.quan@gmail.com)%0A *%0A */%0Apublic class SystemUiVisibilityController %7B%0A%0A    private static final String TAG = SystemUiVisibilityController.class.getSimpleName();%0A    %0A    protected int mVisibility;%0A    %0A    public SystemUiVisibilityController(int visibility) %7B%0A        mVisibility = visibility;%0A    %7D%0A    %0A    /**%0A     * Apply the desired system UI visibility.  The desired system UI visibility will be restored if a change is detected%0A     * @param activity The activity to apply the settings to%0A     * @return%0A     */%0A    public SystemUiVisibilityController apply(Activity activity) %7B%0A        if (activity == null) %7B%0A            Log.w(TAG, %22No activity available to apply system visibility to.%22);%0A            return this;%0A        %7D%0A        final View decorView = activity.getWindow().getDecorView();%0A        decorView.setSystemUiVisibility(mVisibility);%0A        registerListener(activity);%0A        return this;%0A    %7D%0A    %0A    /**%0A     * Register a listener to restore the desired system UI visibility if/when it is changed%0A     * @param activity The activity to apply the settings to%0A     * @return%0A     */%0A    public SystemUiVisibilityController registerListener(Activity activity) %7B%0A        if (activity == null) %7B%0A            Log.w(TAG, %22No activity available to register system UI visibility listener to.%22);%0A            return this;%0A        %7D%0A        final View decorView = activity.getWindow().getDecorView();%0A        // Based on http://stackoverflow.com/questions/21164836/immersive-mode-navigation-becomes-sticky-after-volume-press-or-minimise-restore%0A        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() %7B%0A            @Override public void onSystemUiVisibilityChange(int visibility) %7B%0A                //Log.d(TAG, %22Re-applying system UI visibility%22);%0A                decorView.setSystemUiVisibility(mVisibility);%0A            %7D%0A        %7D);%0A        return this;%0A    %7D%0A%0A%7D%0A

Add helper to restore immersive modes