Home | History | Annotate | Download | only in ui
      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.packageinstaller.permission.ui;
     18 
     19 import android.graphics.drawable.Icon;
     20 import android.os.Bundle;
     21 import android.view.View;
     22 import android.view.WindowManager;
     23 
     24 /**
     25  * Class for managing the presentation and user interaction of the "grant
     26  * permissions" user interface.
     27  */
     28 public interface GrantPermissionsViewHandler {
     29 
     30     /**
     31      * Listener interface for getting notified when the user responds to a
     32      * permissions grant request.
     33      */
     34     interface ResultListener {
     35         void onPermissionGrantResult(String groupName, boolean granted, boolean doNotAskAgain);
     36     }
     37 
     38     /**
     39      * Creates and returns the view hierarchy that is managed by this view
     40      * handler. This must be called before {@link #updateUi}.
     41      */
     42     View createView();
     43 
     44     /**
     45      * Updates the layout attributes of the current window. This is an optional
     46      * operation; implementations only need to do work in this method if they
     47      * need to alter the default styles provided by the activity's theme.
     48      */
     49     void updateWindowAttributes(WindowManager.LayoutParams outLayoutParams);
     50 
     51     /**
     52      * Updates the view hierarchy to reflect the specified state.
     53      * <p>
     54      * Note that this must be called at least once before showing the UI to
     55      * the user to properly initialize the UI.
     56      *
     57      * @param groupName the name of the permission group
     58      * @param groupCount the total number of groups that are being requested
     59      * @param groupIndex the index of the current group being requested
     60      * @param icon the icon representation of the current group
     61      * @param message the message to display the user
     62      * @param showDoNotAsk whether to show the "do not ask again" option
     63      */
     64     void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
     65             CharSequence message, boolean showDoNotAsk);
     66 
     67     /**
     68      * Sets the result listener that will be notified when the user responds
     69      * to a permissions grant request.
     70      */
     71     GrantPermissionsViewHandler setResultListener(ResultListener listener);
     72 
     73     /**
     74      * Called by {@link GrantPermissionsActivity} to save the state of this
     75      * view handler to the specified bundle.
     76      */
     77     void saveInstanceState(Bundle outState);
     78 
     79     /**
     80      * Called by {@link GrantPermissionsActivity} to load the state of this
     81      * view handler from the specified bundle.
     82      */
     83     void loadInstanceState(Bundle savedInstanceState);
     84 
     85     /**
     86      * Gives a chance for handling the back key.
     87      */
     88     void onBackPressed();
     89 }
     90