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.launcher3.accessibility;
     18 
     19 import android.content.Context;
     20 import android.os.Bundle;
     21 import android.view.View;
     22 import android.view.View.AccessibilityDelegate;
     23 import android.view.accessibility.AccessibilityNodeInfo;
     24 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
     25 
     26 import com.android.launcher3.Launcher;
     27 import com.android.launcher3.R;
     28 import com.android.launcher3.Utilities;
     29 
     30 /**
     31  * Accessibility delegate with actions pointing to various Overview entry points.
     32  */
     33 public class OverviewAccessibilityDelegate extends AccessibilityDelegate {
     34 
     35     private static final int OVERVIEW = R.string.accessibility_action_overview;
     36     private static final int WALLPAPERS = R.string.wallpaper_button_text;
     37     private static final int WIDGETS = R.string.widget_button_text;
     38     private static final int SETTINGS = R.string.settings_button_text;
     39 
     40     @Override
     41     public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
     42         super.onInitializeAccessibilityNodeInfo(host, info);
     43 
     44         Context context = host.getContext();
     45         info.addAction(new AccessibilityAction(OVERVIEW, context.getText(OVERVIEW)));
     46 
     47         if (Utilities.isWallapaperAllowed(context)) {
     48             info.addAction(new AccessibilityAction(WALLPAPERS, context.getText(WALLPAPERS)));
     49         }
     50         info.addAction(new AccessibilityAction(WIDGETS, context.getText(WIDGETS)));
     51         info.addAction(new AccessibilityAction(SETTINGS, context.getText(SETTINGS)));
     52     }
     53 
     54     @Override
     55     public boolean performAccessibilityAction(View host, int action, Bundle args) {
     56         Launcher launcher = Launcher.getLauncher(host.getContext());
     57         if (action == OVERVIEW) {
     58             launcher.showOverviewMode(true);
     59             return true;
     60         } else if (action == WALLPAPERS) {
     61             launcher.onClickWallpaperPicker(host);
     62             return true;
     63         } else if (action == WIDGETS) {
     64             launcher.onClickAddWidgetButton(host);
     65             return true;
     66         } else if (action == SETTINGS) {
     67             launcher.onClickSettingsButton(host);
     68             return true;
     69         }
     70         return super.performAccessibilityAction(host, action, args);
     71     }
     72 }
     73