Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 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 | package com.android.systemui.qs.customize; |
| 17 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 18 | import android.animation.Animator; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 19 | import android.animation.Animator.AnimatorListener; |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 20 | import android.animation.AnimatorListenerAdapter; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 21 | import android.content.Context; |
Jason Monk | 931f546 | 2016-05-25 11:19:04 -0400 | [diff] [blame] | 22 | import android.content.res.Configuration; |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 23 | import android.os.Bundle; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 24 | import android.util.AttributeSet; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 25 | import android.util.TypedValue; |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 26 | import android.view.ContextThemeWrapper; |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 27 | import android.view.LayoutInflater; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 28 | import android.view.Menu; |
| 29 | import android.view.MenuItem; |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 30 | import android.view.View; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 31 | import android.widget.LinearLayout; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 32 | import android.widget.Toolbar; |
| 33 | import android.widget.Toolbar.OnMenuItemClickListener; |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 34 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 35 | import androidx.recyclerview.widget.DefaultItemAnimator; |
| 36 | import androidx.recyclerview.widget.GridLayoutManager; |
| 37 | import androidx.recyclerview.widget.RecyclerView; |
| 38 | |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 39 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 40 | import com.android.internal.logging.nano.MetricsProto; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 41 | import com.android.systemui.Dependency; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 42 | import com.android.systemui.R; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 43 | import com.android.systemui.plugins.qs.QS; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 44 | import com.android.systemui.plugins.qs.QSTile; |
Jason Monk | 78a3d60 | 2017-03-16 12:12:57 -0400 | [diff] [blame] | 45 | import com.android.systemui.qs.QSDetailClipper; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 46 | import com.android.systemui.qs.QSTileHost; |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 47 | import com.android.systemui.statusbar.phone.LightBarController; |
Jason Monk | 78a3d60 | 2017-03-16 12:12:57 -0400 | [diff] [blame] | 48 | import com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
Jason Monk | 181d3fe | 2016-06-06 16:18:50 -0400 | [diff] [blame] | 50 | import com.android.systemui.statusbar.policy.KeyguardMonitor.Callback; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 51 | |
| 52 | import java.util.ArrayList; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 53 | import java.util.List; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Allows full-screen customization of QS, through show() and hide(). |
| 57 | * |
| 58 | * This adds itself to the status bar window, so it can appear on top of quick settings and |
| 59 | * *someday* do fancy animations to get into/out of it. |
| 60 | */ |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 61 | public class QSCustomizer extends LinearLayout implements OnMenuItemClickListener { |
| 62 | |
| 63 | private static final int MENU_RESET = Menu.FIRST; |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 64 | private static final String EXTRA_QS_CUSTOMIZING = "qs_customizing"; |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 65 | private static final String TAG = "QSCustomizer"; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 66 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 67 | private final QSDetailClipper mClipper; |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 68 | private final LightBarController mLightBarController; |
Amin Shaikh | c5b1bc8 | 2018-03-21 08:13:47 -0400 | [diff] [blame] | 69 | private final TileQueryHelper mTileQueryHelper; |
Fabian Kozynski | 5d5deeb | 2018-09-18 14:49:37 -0400 | [diff] [blame] | 70 | private final View mTransparentView; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 71 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 72 | private boolean isShown; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 73 | private QSTileHost mHost; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 74 | private RecyclerView mRecyclerView; |
| 75 | private TileAdapter mTileAdapter; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 76 | private Toolbar mToolbar; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 77 | private boolean mCustomizing; |
| 78 | private NotificationsQuickSettingsContainer mNotifQsContainer; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 79 | private QS mQs; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 80 | private int mX; |
| 81 | private int mY; |
Jason Monk | 78a3d60 | 2017-03-16 12:12:57 -0400 | [diff] [blame] | 82 | private boolean mOpening; |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 83 | private boolean mIsShowingNavBackdrop; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 84 | |
| 85 | public QSCustomizer(Context context, AttributeSet attrs) { |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 86 | super(new ContextThemeWrapper(context, R.style.edit_theme), attrs); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 87 | |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 88 | LayoutInflater.from(getContext()).inflate(R.layout.qs_customize_panel_content, this); |
Amin Shaikh | 9a6fa08 | 2018-03-29 17:27:26 -0400 | [diff] [blame] | 89 | mClipper = new QSDetailClipper(findViewById(R.id.customize_container)); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 90 | mToolbar = findViewById(com.android.internal.R.id.action_bar); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 91 | TypedValue value = new TypedValue(); |
| 92 | mContext.getTheme().resolveAttribute(android.R.attr.homeAsUpIndicator, value, true); |
| 93 | mToolbar.setNavigationIcon( |
Jason Monk | 04fd249 | 2016-02-29 14:29:26 -0500 | [diff] [blame] | 94 | getResources().getDrawable(value.resourceId, mContext.getTheme())); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 95 | mToolbar.setNavigationOnClickListener(new OnClickListener() { |
| 96 | @Override |
| 97 | public void onClick(View v) { |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 98 | hide(); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 99 | } |
| 100 | }); |
| 101 | mToolbar.setOnMenuItemClickListener(this); |
| 102 | mToolbar.getMenu().add(Menu.NONE, MENU_RESET, 0, |
| 103 | mContext.getString(com.android.internal.R.string.reset)); |
Jason Monk | f923db5 | 2016-03-02 14:11:14 -0500 | [diff] [blame] | 104 | mToolbar.setTitle(R.string.qs_edit); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 105 | mRecyclerView = findViewById(android.R.id.list); |
Fabian Kozynski | 5d5deeb | 2018-09-18 14:49:37 -0400 | [diff] [blame] | 106 | mTransparentView = findViewById(R.id.customizer_transparent_view); |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 107 | mTileAdapter = new TileAdapter(getContext()); |
Amin Shaikh | c5b1bc8 | 2018-03-21 08:13:47 -0400 | [diff] [blame] | 108 | mTileQueryHelper = new TileQueryHelper(context, mTileAdapter); |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 109 | mRecyclerView.setAdapter(mTileAdapter); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 110 | mTileAdapter.getItemTouchHelper().attachToRecyclerView(mRecyclerView); |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 111 | GridLayoutManager layout = new GridLayoutManager(getContext(), 3); |
| 112 | layout.setSpanSizeLookup(mTileAdapter.getSizeLookup()); |
| 113 | mRecyclerView.setLayoutManager(layout); |
| 114 | mRecyclerView.addItemDecoration(mTileAdapter.getItemDecoration()); |
| 115 | DefaultItemAnimator animator = new DefaultItemAnimator(); |
| 116 | animator.setMoveDuration(TileAdapter.MOVE_DURATION); |
| 117 | mRecyclerView.setItemAnimator(animator); |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 118 | mLightBarController = Dependency.get(LightBarController.class); |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 119 | updateNavBackDrop(getResources().getConfiguration()); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Jason Monk | 931f546 | 2016-05-25 11:19:04 -0400 | [diff] [blame] | 122 | @Override |
| 123 | protected void onConfigurationChanged(Configuration newConfig) { |
| 124 | super.onConfigurationChanged(newConfig); |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 125 | updateNavBackDrop(newConfig); |
Fabian Kozynski | 5d5deeb | 2018-09-18 14:49:37 -0400 | [diff] [blame] | 126 | updateResources(); |
| 127 | } |
| 128 | |
| 129 | private void updateResources() { |
| 130 | LayoutParams lp = (LayoutParams) mTransparentView.getLayoutParams(); |
| 131 | lp.height = mContext.getResources().getDimensionPixelSize( |
| 132 | com.android.internal.R.dimen.quick_qs_offset_height); |
| 133 | mTransparentView.setLayoutParams(lp); |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | private void updateNavBackDrop(Configuration newConfig) { |
Jason Monk | 931f546 | 2016-05-25 11:19:04 -0400 | [diff] [blame] | 137 | View navBackdrop = findViewById(R.id.nav_bar_background); |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 138 | mIsShowingNavBackdrop = newConfig.smallestScreenWidthDp >= 600 |
| 139 | || newConfig.orientation != Configuration.ORIENTATION_LANDSCAPE; |
Jason Monk | 931f546 | 2016-05-25 11:19:04 -0400 | [diff] [blame] | 140 | if (navBackdrop != null) { |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 141 | navBackdrop.setVisibility(mIsShowingNavBackdrop ? View.VISIBLE : View.GONE); |
Jason Monk | 931f546 | 2016-05-25 11:19:04 -0400 | [diff] [blame] | 142 | } |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 143 | updateNavColors(); |
| 144 | } |
| 145 | |
| 146 | private void updateNavColors() { |
| 147 | mLightBarController.setQsCustomizing(mIsShowingNavBackdrop && isShown); |
Jason Monk | 931f546 | 2016-05-25 11:19:04 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 150 | public void setHost(QSTileHost host) { |
| 151 | mHost = host; |
Jason Monk | 63554ed | 2016-04-29 14:58:29 -0400 | [diff] [blame] | 152 | mTileAdapter.setHost(host); |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | public void setContainer(NotificationsQuickSettingsContainer notificationsQsContainer) { |
| 156 | mNotifQsContainer = notificationsQsContainer; |
| 157 | } |
| 158 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 159 | public void setQs(QS qs) { |
| 160 | mQs = qs; |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 161 | } |
| 162 | |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 163 | /** Animate and show QSCustomizer panel. |
| 164 | * @param x,y Location on screen of {@code edit} button to determine center of animation. |
| 165 | */ |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 166 | public void show(int x, int y) { |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 167 | if (!isShown) { |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 168 | int containerLocation[] = findViewById(R.id.customize_container).getLocationOnScreen(); |
| 169 | mX = x - containerLocation[0]; |
| 170 | mY = y - containerLocation[1]; |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 171 | MetricsLogger.visible(getContext(), MetricsProto.MetricsEvent.QS_EDIT); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 172 | isShown = true; |
Jason Monk | 78a3d60 | 2017-03-16 12:12:57 -0400 | [diff] [blame] | 173 | mOpening = true; |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 174 | setTileSpecs(); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 175 | setVisibility(View.VISIBLE); |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 176 | mClipper.animateCircularClip(mX, mY, true, mExpandAnimationListener); |
Evan Laird | 6b28473 | 2017-02-28 17:27:04 -0500 | [diff] [blame] | 177 | queryTiles(); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 178 | mNotifQsContainer.setCustomizerAnimating(true); |
Jason Monk | 428914d | 2016-03-30 09:35:36 -0400 | [diff] [blame] | 179 | mNotifQsContainer.setCustomizerShowing(true); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 180 | Dependency.get(KeyguardMonitor.class).addCallback(mKeyguardCallback); |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 181 | updateNavColors(); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 182 | } |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 183 | } |
| 184 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 185 | |
| 186 | public void showImmediately() { |
| 187 | if (!isShown) { |
| 188 | setVisibility(VISIBLE); |
| 189 | mClipper.showBackground(); |
| 190 | isShown = true; |
| 191 | setTileSpecs(); |
| 192 | setCustomizing(true); |
| 193 | queryTiles(); |
| 194 | mNotifQsContainer.setCustomizerAnimating(false); |
| 195 | mNotifQsContainer.setCustomizerShowing(true); |
| 196 | Dependency.get(KeyguardMonitor.class).addCallback(mKeyguardCallback); |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 197 | updateNavColors(); |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
Evan Laird | 6b28473 | 2017-02-28 17:27:04 -0500 | [diff] [blame] | 201 | private void queryTiles() { |
Amin Shaikh | c5b1bc8 | 2018-03-21 08:13:47 -0400 | [diff] [blame] | 202 | mTileQueryHelper.queryTiles(mHost); |
Evan Laird | 6b28473 | 2017-02-28 17:27:04 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 205 | public void hide() { |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 206 | if (isShown) { |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 207 | MetricsLogger.hidden(getContext(), MetricsProto.MetricsEvent.QS_EDIT); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 208 | isShown = false; |
Jason Monk | df8cbc3 | 2016-03-16 16:10:56 -0400 | [diff] [blame] | 209 | mToolbar.dismissPopupMenus(); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 210 | setCustomizing(false); |
Jason Monk | 04fd249 | 2016-02-29 14:29:26 -0500 | [diff] [blame] | 211 | save(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 212 | mClipper.animateCircularClip(mX, mY, false, mCollapseAnimationListener); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 213 | mNotifQsContainer.setCustomizerAnimating(true); |
Jason Monk | 428914d | 2016-03-30 09:35:36 -0400 | [diff] [blame] | 214 | mNotifQsContainer.setCustomizerShowing(false); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 215 | Dependency.get(KeyguardMonitor.class).removeCallback(mKeyguardCallback); |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 216 | updateNavColors(); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 217 | } |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 220 | public boolean isShown() { |
| 221 | return isShown; |
| 222 | } |
| 223 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 224 | private void setCustomizing(boolean customizing) { |
| 225 | mCustomizing = customizing; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 226 | mQs.notifyCustomizeChanged(); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 229 | public boolean isCustomizing() { |
Amin Shaikh | 1420e7e | 2018-04-11 11:12:33 -0400 | [diff] [blame] | 230 | return mCustomizing || mOpening; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 233 | @Override |
| 234 | public boolean onMenuItemClick(MenuItem item) { |
| 235 | switch (item.getItemId()) { |
| 236 | case MENU_RESET: |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 237 | MetricsLogger.action(getContext(), MetricsProto.MetricsEvent.ACTION_QS_EDIT_RESET); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 238 | reset(); |
| 239 | break; |
| 240 | } |
| 241 | return false; |
| 242 | } |
| 243 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 244 | private void reset() { |
| 245 | ArrayList<String> tiles = new ArrayList<>(); |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 246 | String defTiles = mContext.getString(R.string.quick_settings_tiles_default); |
| 247 | for (String tile : defTiles.split(",")) { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 248 | tiles.add(tile); |
| 249 | } |
Jason Monk | 903556b | 2017-03-29 13:13:51 -0400 | [diff] [blame] | 250 | mTileAdapter.resetTileSpecs(mHost, tiles); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 253 | private void setTileSpecs() { |
| 254 | List<String> specs = new ArrayList<>(); |
| 255 | for (QSTile tile : mHost.getTiles()) { |
| 256 | specs.add(tile.getTileSpec()); |
| 257 | } |
| 258 | mTileAdapter.setTileSpecs(specs); |
Jason Monk | 4efc924 | 2016-03-31 14:10:37 -0400 | [diff] [blame] | 259 | mRecyclerView.setAdapter(mTileAdapter); |
Jason Monk | f7fe83f | 2015-09-09 13:03:20 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 262 | private void save() { |
Amin Shaikh | c5b1bc8 | 2018-03-21 08:13:47 -0400 | [diff] [blame] | 263 | if (mTileQueryHelper.isFinished()) { |
Evan Laird | 6b28473 | 2017-02-28 17:27:04 -0500 | [diff] [blame] | 264 | mTileAdapter.saveSpecs(mHost); |
| 265 | } |
Jason Monk | 2681dcb | 2015-09-09 13:50:34 -0400 | [diff] [blame] | 266 | } |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 267 | |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 268 | |
| 269 | public void saveInstanceState(Bundle outState) { |
| 270 | if (isShown) { |
| 271 | Dependency.get(KeyguardMonitor.class).removeCallback(mKeyguardCallback); |
| 272 | } |
| 273 | outState.putBoolean(EXTRA_QS_CUSTOMIZING, mCustomizing); |
| 274 | } |
| 275 | |
| 276 | public void restoreInstanceState(Bundle savedInstanceState) { |
| 277 | boolean customizing = savedInstanceState.getBoolean(EXTRA_QS_CUSTOMIZING); |
| 278 | if (customizing) { |
| 279 | setVisibility(VISIBLE); |
| 280 | addOnLayoutChangeListener(new OnLayoutChangeListener() { |
| 281 | @Override |
| 282 | public void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 283 | int oldLeft, |
| 284 | int oldTop, int oldRight, int oldBottom) { |
| 285 | removeOnLayoutChangeListener(this); |
| 286 | showImmediately(); |
| 287 | } |
| 288 | }); |
| 289 | } |
| 290 | } |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 291 | /** @param x,y Location on screen of animation center. |
| 292 | */ |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 293 | public void setEditLocation(int x, int y) { |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 294 | int containerLocation[] = findViewById(R.id.customize_container).getLocationOnScreen(); |
| 295 | mX = x - containerLocation[0]; |
| 296 | mY = y - containerLocation[1]; |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Selim Cinek | 72cd9a7 | 2019-08-09 17:19:57 -0700 | [diff] [blame] | 299 | private final Callback mKeyguardCallback = new Callback() { |
| 300 | @Override |
| 301 | public void onKeyguardShowingChanged() { |
| 302 | if (!isAttachedToWindow()) return; |
| 303 | if (Dependency.get(KeyguardMonitor.class).isShowing() && !mOpening) { |
| 304 | hide(); |
| 305 | } |
Jason Monk | 181d3fe | 2016-06-06 16:18:50 -0400 | [diff] [blame] | 306 | } |
| 307 | }; |
| 308 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 309 | private final AnimatorListener mExpandAnimationListener = new AnimatorListenerAdapter() { |
| 310 | @Override |
| 311 | public void onAnimationEnd(Animator animation) { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 312 | if (isShown) { |
| 313 | setCustomizing(true); |
| 314 | } |
Jason Monk | 78a3d60 | 2017-03-16 12:12:57 -0400 | [diff] [blame] | 315 | mOpening = false; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 316 | mNotifQsContainer.setCustomizerAnimating(false); |
| 317 | } |
| 318 | |
| 319 | @Override |
| 320 | public void onAnimationCancel(Animator animation) { |
Jason Monk | 78a3d60 | 2017-03-16 12:12:57 -0400 | [diff] [blame] | 321 | mOpening = false; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 322 | mNotifQsContainer.setCustomizerAnimating(false); |
| 323 | } |
| 324 | }; |
| 325 | |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 326 | private final AnimatorListener mCollapseAnimationListener = new AnimatorListenerAdapter() { |
| 327 | @Override |
| 328 | public void onAnimationEnd(Animator animation) { |
| 329 | if (!isShown) { |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 330 | setVisibility(View.GONE); |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 331 | } |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 332 | mNotifQsContainer.setCustomizerAnimating(false); |
Jason Monk | b213ac4 | 2016-06-20 10:27:27 -0400 | [diff] [blame] | 333 | mRecyclerView.setAdapter(mTileAdapter); |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 334 | } |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 335 | |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 336 | @Override |
| 337 | public void onAnimationCancel(Animator animation) { |
| 338 | if (!isShown) { |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 339 | setVisibility(View.GONE); |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 340 | } |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 341 | mNotifQsContainer.setCustomizerAnimating(false); |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 342 | } |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 343 | }; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 344 | } |