1 /*
2  * Copyright (C) 2020 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.systemui.qs;
18 
19 import android.content.ClipData;
20 import android.content.ClipboardManager;
21 import android.text.TextUtils;
22 import android.view.View;
23 import android.widget.TextView;
24 import android.widget.Toast;
25 
26 import com.android.systemui.plugins.ActivityStarter;
27 import com.android.systemui.plugins.FalsingManager;
28 import com.android.systemui.qs.dagger.QSScope;
29 import com.android.systemui.res.R;
30 import com.android.systemui.retail.domain.interactor.RetailModeInteractor;
31 import com.android.systemui.settings.UserTracker;
32 import com.android.systemui.util.ViewController;
33 
34 import javax.inject.Inject;
35 
36 /**
37  * Controller for {@link QSFooterView}.
38  */
39 @QSScope
40 public class QSFooterViewController extends ViewController<QSFooterView> implements QSFooter {
41 
42     private final UserTracker mUserTracker;
43     private final QSPanelController mQsPanelController;
44     private final TextView mBuildText;
45     private final PageIndicator mPageIndicator;
46     private final View mEditButton;
47     private final FalsingManager mFalsingManager;
48     private final ActivityStarter mActivityStarter;
49     private final RetailModeInteractor mRetailModeInteractor;
50 
51     @Inject
QSFooterViewController(QSFooterView view, UserTracker userTracker, FalsingManager falsingManager, ActivityStarter activityStarter, QSPanelController qsPanelController, RetailModeInteractor retailModeInteractor )52     QSFooterViewController(QSFooterView view,
53             UserTracker userTracker,
54             FalsingManager falsingManager,
55             ActivityStarter activityStarter,
56             QSPanelController qsPanelController,
57             RetailModeInteractor retailModeInteractor
58     ) {
59         super(view);
60         mUserTracker = userTracker;
61         mQsPanelController = qsPanelController;
62         mFalsingManager = falsingManager;
63         mActivityStarter = activityStarter;
64         mRetailModeInteractor = retailModeInteractor;
65 
66         mBuildText = mView.findViewById(R.id.build);
67         mPageIndicator = mView.findViewById(R.id.footer_page_indicator);
68         mEditButton = mView.findViewById(android.R.id.edit);
69     }
70 
71     @Override
onViewAttached()72     protected void onViewAttached() {
73         mBuildText.setOnLongClickListener(view -> {
74             CharSequence buildText = mBuildText.getText();
75             if (!TextUtils.isEmpty(buildText)) {
76                 ClipboardManager service =
77                         mUserTracker.getUserContext().getSystemService(ClipboardManager.class);
78                 String label = getResources().getString(R.string.build_number_clip_data_label);
79                 service.setPrimaryClip(ClipData.newPlainText(label, buildText));
80                 Toast.makeText(getContext(), R.string.build_number_copy_toast, Toast.LENGTH_SHORT)
81                         .show();
82                 return true;
83             }
84             return false;
85         });
86 
87         mEditButton.setOnClickListener(view -> {
88             if (mFalsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
89                 return;
90             }
91             mActivityStarter
92                     .postQSRunnableDismissingKeyguard(() -> mQsPanelController.showEdit(view));
93         });
94         mQsPanelController.setFooterPageIndicator(mPageIndicator);
95         mView.updateEverything();
96     }
97 
98     @Override
onViewDetached()99     protected void onViewDetached() {}
100 
101     @Override
setVisibility(int visibility)102     public void setVisibility(int visibility) {
103         mView.setVisibility(visibility);
104         mEditButton
105                 .setVisibility(mRetailModeInteractor.isInRetailMode() ? View.GONE : View.VISIBLE);
106         mEditButton.setClickable(visibility == View.VISIBLE);
107     }
108 
109     @Override
setExpanded(boolean expanded)110     public void setExpanded(boolean expanded) {
111         mView.setExpanded(expanded);
112     }
113 
114     @Override
setExpansion(float expansion)115     public void setExpansion(float expansion) {
116         mView.setExpansion(expansion);
117     }
118 
119     @Override
setKeyguardShowing(boolean keyguardShowing)120     public void setKeyguardShowing(boolean keyguardShowing) {
121         mView.setKeyguardShowing();
122     }
123 
124     @Override
disable(int state1, int state2, boolean animate)125     public void disable(int state1, int state2, boolean animate) {
126         mView.disable(state2);
127     }
128 }
129