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