Home | History | Annotate | Download | only in accessibility
      1 /*
      2  * Copyright (C) 2016 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.settings.accessibility;
     18 
     19 import android.app.Fragment;
     20 import android.app.FragmentTransaction;
     21 import android.os.Bundle;
     22 import android.text.TextUtils;
     23 import android.view.accessibility.AccessibilityEvent;
     24 import android.view.LayoutInflater;
     25 import android.view.Menu;
     26 import android.view.View;
     27 import android.view.WindowInsets;
     28 import android.widget.FrameLayout;
     29 import android.widget.LinearLayout;
     30 
     31 import com.android.settings.R;
     32 import com.android.settings.SettingsActivity;
     33 import com.android.settings.SettingsPreferenceFragment;
     34 import com.android.setupwizardlib.util.SystemBarHelper;
     35 import com.android.setupwizardlib.view.NavigationBar;
     36 
     37 public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivity {
     38 
     39     private static final String SAVE_KEY_TITLE = "activity_title";
     40 
     41     private boolean mSendExtraWindowStateChanged;
     42 
     43     @Override
     44     protected void onCreate(Bundle savedState) {
     45         // Main content frame id should be set before calling super as that is where the first
     46         // Fragment is inflated.
     47         setMainContentId(R.id.suw_main_content);
     48         super.onCreate(savedState);
     49 
     50         // Finish configuring the content view.
     51         FrameLayout parentLayout = (FrameLayout) findViewById(R.id.main_content);
     52         LayoutInflater.from(this)
     53                 .inflate(R.layout.accessibility_settings_for_suw, parentLayout);
     54 
     55         getActionBar().setDisplayHomeAsUpEnabled(true);
     56         setIsDrawerPresent(false);
     57 
     58         // Hide System Nav Bar.
     59         SystemBarHelper.hideSystemBars(getWindow());
     60         LinearLayout parentView = (LinearLayout) findViewById(R.id.content_parent);
     61         parentView.setFitsSystemWindows(false);
     62         // Adjust for the Status Bar.
     63         parentView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
     64                 @Override
     65                 public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
     66                     parentView.setPadding(0, insets.getSystemWindowInsetTop(), 0, 0);
     67                     return insets;
     68                 }
     69             });
     70 
     71         // Show SUW Nav Bar.
     72         NavigationBar navigationBar = (NavigationBar) findViewById(R.id.suw_navigation_bar);
     73         navigationBar.getNextButton().setVisibility(View.GONE);
     74         navigationBar.setNavigationBarListener(new NavigationBar.NavigationBarListener() {
     75             @Override
     76             public void onNavigateBack() {
     77                 onNavigateUp();
     78             }
     79 
     80             @Override
     81             public void onNavigateNext() {
     82                 // Do nothing. We don't show this button.
     83             }
     84         });
     85     }
     86 
     87     @Override
     88     protected void onSaveInstanceState(Bundle savedState) {
     89         savedState.putCharSequence(SAVE_KEY_TITLE, getTitle());
     90         super.onSaveInstanceState(savedState);
     91     }
     92 
     93     @Override
     94     protected void onRestoreInstanceState(Bundle savedState) {
     95         super.onRestoreInstanceState(savedState);
     96         setTitle(savedState.getCharSequence(SAVE_KEY_TITLE));
     97     }
     98 
     99     @Override
    100     public void onResume() {
    101         super.onResume();
    102         mSendExtraWindowStateChanged = false;
    103     }
    104 
    105     @Override
    106     public boolean onCreateOptionsMenu(Menu menu) {
    107         // Return true, so we get notified when items in the menu are clicked.
    108         return true;
    109     }
    110 
    111     @Override
    112     public boolean onNavigateUp() {
    113         onBackPressed();
    114 
    115         // Clear accessibility focus and let the screen reader announce the new title.
    116         getWindow().getDecorView()
    117                 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    118 
    119         return true;
    120     }
    121 
    122     @Override
    123     public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
    124             CharSequence titleText, Fragment resultTo, int resultRequestCode) {
    125         // Set the title.
    126         if (!TextUtils.isEmpty(titleText)) {
    127             setTitle(titleText);
    128         } else if (titleRes > 0) {
    129             setTitle(getString(titleRes));
    130         }
    131 
    132         // Start the new Fragment.
    133         args.putInt(SettingsPreferenceFragment.HELP_URI_RESOURCE_KEY, 0);
    134         startPreferenceFragment(Fragment.instantiate(this, fragmentClass, args), true);
    135         mSendExtraWindowStateChanged = true;
    136     }
    137 
    138     @Override
    139     public void onAttachFragment(Fragment fragment) {
    140         if (mSendExtraWindowStateChanged) {
    141             // Clear accessibility focus and let the screen reader announce the new title.
    142             getWindow().getDecorView()
    143                     .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    144         }
    145     }
    146 }
    147