GrantPermissionsViewHandler.java revision 9f0bcd12aab977eec99d692de9206484e859a252
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
17package com.android.packageinstaller.permission.ui;
18
19import android.graphics.drawable.Icon;
20import android.os.Bundle;
21import android.view.View;
22
23/**
24 * Class for managing the presentation and user interaction of the "grant
25 * permissions" user interface.
26 */
27interface GrantPermissionsViewHandler {
28
29    /**
30     * Listener interface for getting notified when the user responds to a
31     * permissions grant request.
32     */
33    interface ResultListener {
34        void onPermissionGrantResult(String groupName, boolean granted, boolean doNotAskAgain);
35    }
36
37    /**
38     * Creates and returns the view hierarchy that is managed by this view
39     * handler. This must be called before {@link #updateUi}.
40     */
41    View createView();
42
43    /**
44     * Updates the view hierarchy to reflect the specified state.
45     * <p>
46     * Note that this must be called at least once before showing the UI to
47     * the user to properly initialize the UI.
48     *
49     * @param groupName the name of the permission group
50     * @param groupCount the total number of groups that are being requested
51     * @param groupIndex the index of the current group being requested
52     * @param icon the icon representation of the current group
53     * @param message the message to display the user
54     * @param showDoNotAsk whether to show the "do not ask again" option
55     */
56    void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
57            CharSequence message, boolean showDoNotAsk);
58
59    /**
60     * Sets the result listener that will be notified when the user responds
61     * to a permissions grant request.
62     */
63    GrantPermissionsViewHandler setResultListener(ResultListener listener);
64
65    /**
66     * Called by {@link GrantPermissionsActivity} to save the state of this
67     * view handler to the specified bundle.
68     */
69    void saveInstanceState(Bundle outState);
70
71    /**
72     * Called by {@link GrantPermissionsActivity} to load the state of this
73     * view handler from the specified bundle.
74     */
75    void loadInstanceState(Bundle savedInstanceState);
76}
77