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; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 23 | import android.support.v7.widget.DefaultItemAnimator; |
| 24 | import android.support.v7.widget.GridLayoutManager; |
| 25 | import android.support.v7.widget.RecyclerView; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 26 | import android.util.AttributeSet; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 27 | import android.util.TypedValue; |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 28 | import android.view.ContextThemeWrapper; |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 29 | import android.view.LayoutInflater; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 30 | import android.view.Menu; |
| 31 | import android.view.MenuItem; |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 32 | import android.view.View; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 33 | import android.widget.LinearLayout; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 34 | import android.widget.Toolbar; |
| 35 | import android.widget.Toolbar.OnMenuItemClickListener; |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 36 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 37 | import com.android.internal.logging.nano.MetricsProto; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 38 | import com.android.systemui.R; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 39 | import com.android.systemui.qs.QSContainer; |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 40 | import com.android.systemui.qs.QSDetailClipper; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 41 | import com.android.systemui.qs.QSTile; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 43 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
| 44 | import com.android.systemui.statusbar.phone.QSTileHost; |
Jason Monk | 181d3fe | 2016-06-06 16:18:50 -0400 | [diff] [blame] | 45 | import com.android.systemui.statusbar.policy.KeyguardMonitor.Callback; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 46 | |
| 47 | import java.util.ArrayList; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 48 | import java.util.List; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Allows full-screen customization of QS, through show() and hide(). |
| 52 | * |
| 53 | * This adds itself to the status bar window, so it can appear on top of quick settings and |
| 54 | * *someday* do fancy animations to get into/out of it. |
| 55 | */ |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 56 | public class QSCustomizer extends LinearLayout implements OnMenuItemClickListener { |
| 57 | |
| 58 | private static final int MENU_RESET = Menu.FIRST; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 59 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 60 | private final QSDetailClipper mClipper; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 61 | |
| 62 | private PhoneStatusBar mPhoneStatusBar; |
| 63 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 64 | private boolean isShown; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 65 | private QSTileHost mHost; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 66 | private RecyclerView mRecyclerView; |
| 67 | private TileAdapter mTileAdapter; |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 68 | private Toolbar mToolbar; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 69 | private boolean mCustomizing; |
| 70 | private NotificationsQuickSettingsContainer mNotifQsContainer; |
| 71 | private QSContainer mQsContainer; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 72 | |
| 73 | public QSCustomizer(Context context, AttributeSet attrs) { |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 74 | super(new ContextThemeWrapper(context, R.style.edit_theme), attrs); |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 75 | mClipper = new QSDetailClipper(this); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 76 | |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 77 | LayoutInflater.from(getContext()).inflate(R.layout.qs_customize_panel_content, this); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 78 | |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 79 | mToolbar = (Toolbar) findViewById(com.android.internal.R.id.action_bar); |
| 80 | TypedValue value = new TypedValue(); |
| 81 | mContext.getTheme().resolveAttribute(android.R.attr.homeAsUpIndicator, value, true); |
| 82 | mToolbar.setNavigationIcon( |
Jason Monk | 04fd249 | 2016-02-29 14:29:26 -0500 | [diff] [blame] | 83 | getResources().getDrawable(value.resourceId, mContext.getTheme())); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 84 | mToolbar.setNavigationOnClickListener(new OnClickListener() { |
| 85 | @Override |
| 86 | public void onClick(View v) { |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 87 | hide((int) v.getX() + v.getWidth() / 2, (int) v.getY() + v.getHeight() / 2); |
| 88 | } |
| 89 | }); |
| 90 | mToolbar.setOnMenuItemClickListener(this); |
| 91 | mToolbar.getMenu().add(Menu.NONE, MENU_RESET, 0, |
| 92 | mContext.getString(com.android.internal.R.string.reset)); |
Jason Monk | f923db5 | 2016-03-02 14:11:14 -0500 | [diff] [blame] | 93 | mToolbar.setTitle(R.string.qs_edit); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 94 | |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 95 | mRecyclerView = (RecyclerView) findViewById(android.R.id.list); |
| 96 | mTileAdapter = new TileAdapter(getContext()); |
| 97 | mRecyclerView.setAdapter(mTileAdapter); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 98 | mTileAdapter.getItemTouchHelper().attachToRecyclerView(mRecyclerView); |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 99 | GridLayoutManager layout = new GridLayoutManager(getContext(), 3); |
| 100 | layout.setSpanSizeLookup(mTileAdapter.getSizeLookup()); |
| 101 | mRecyclerView.setLayoutManager(layout); |
| 102 | mRecyclerView.addItemDecoration(mTileAdapter.getItemDecoration()); |
| 103 | DefaultItemAnimator animator = new DefaultItemAnimator(); |
| 104 | animator.setMoveDuration(TileAdapter.MOVE_DURATION); |
| 105 | mRecyclerView.setItemAnimator(animator); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Jason Monk | 931f546 | 2016-05-25 11:19:04 -0400 | [diff] [blame] | 108 | @Override |
| 109 | protected void onConfigurationChanged(Configuration newConfig) { |
| 110 | super.onConfigurationChanged(newConfig); |
| 111 | View navBackdrop = findViewById(R.id.nav_bar_background); |
| 112 | if (navBackdrop != null) { |
| 113 | boolean shouldShow = newConfig.smallestScreenWidthDp >= 600 |
| 114 | || newConfig.orientation != Configuration.ORIENTATION_LANDSCAPE; |
| 115 | navBackdrop.setVisibility(shouldShow ? View.VISIBLE : View.GONE); |
| 116 | } |
| 117 | } |
| 118 | |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 119 | public void setHost(QSTileHost host) { |
| 120 | mHost = host; |
| 121 | mPhoneStatusBar = host.getPhoneStatusBar(); |
Jason Monk | 63554ed | 2016-04-29 14:58:29 -0400 | [diff] [blame] | 122 | mTileAdapter.setHost(host); |
Jason Monk | a8321e6 | 2016-03-11 08:56:25 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | public void setContainer(NotificationsQuickSettingsContainer notificationsQsContainer) { |
| 126 | mNotifQsContainer = notificationsQsContainer; |
| 127 | } |
| 128 | |
| 129 | public void setQsContainer(QSContainer qsContainer) { |
| 130 | mQsContainer = qsContainer; |
| 131 | } |
| 132 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 133 | public void show(int x, int y) { |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 134 | if (!isShown) { |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 135 | MetricsLogger.visible(getContext(), MetricsProto.MetricsEvent.QS_EDIT); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 136 | isShown = true; |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 137 | setTileSpecs(); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 138 | setVisibility(View.VISIBLE); |
| 139 | mClipper.animateCircularClip(x, y, true, mExpandAnimationListener); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 140 | new TileQueryHelper(mContext, mHost).setListener(mTileAdapter); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 141 | mNotifQsContainer.setCustomizerAnimating(true); |
Jason Monk | 428914d | 2016-03-30 09:35:36 -0400 | [diff] [blame] | 142 | mNotifQsContainer.setCustomizerShowing(true); |
Jason Monk | 0121369 | 2016-05-04 14:44:02 -0400 | [diff] [blame] | 143 | announceForAccessibility(mContext.getString( |
| 144 | R.string.accessibility_desc_quick_settings_edit)); |
Jason Monk | 181d3fe | 2016-06-06 16:18:50 -0400 | [diff] [blame] | 145 | mHost.getKeyguardMonitor().addCallback(mKeyguardCallback); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 146 | } |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 149 | public void hide(int x, int y) { |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 150 | if (isShown) { |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 151 | MetricsLogger.hidden(getContext(), MetricsProto.MetricsEvent.QS_EDIT); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 152 | isShown = false; |
Jason Monk | df8cbc3 | 2016-03-16 16:10:56 -0400 | [diff] [blame] | 153 | mToolbar.dismissPopupMenus(); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 154 | setCustomizing(false); |
Jason Monk | 04fd249 | 2016-02-29 14:29:26 -0500 | [diff] [blame] | 155 | save(); |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 156 | mClipper.animateCircularClip(x, y, false, mCollapseAnimationListener); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 157 | mNotifQsContainer.setCustomizerAnimating(true); |
Jason Monk | 428914d | 2016-03-30 09:35:36 -0400 | [diff] [blame] | 158 | mNotifQsContainer.setCustomizerShowing(false); |
Jason Monk | 0121369 | 2016-05-04 14:44:02 -0400 | [diff] [blame] | 159 | announceForAccessibility(mContext.getString( |
| 160 | R.string.accessibility_desc_quick_settings)); |
Jason Monk | 181d3fe | 2016-06-06 16:18:50 -0400 | [diff] [blame] | 161 | mHost.getKeyguardMonitor().removeCallback(mKeyguardCallback); |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 162 | } |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 163 | } |
| 164 | |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 165 | public boolean isShown() { |
| 166 | return isShown; |
| 167 | } |
| 168 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 169 | private void setCustomizing(boolean customizing) { |
| 170 | mCustomizing = customizing; |
| 171 | mQsContainer.notifyCustomizeChanged(); |
| 172 | } |
| 173 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 174 | public boolean isCustomizing() { |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 175 | return mCustomizing; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 178 | @Override |
| 179 | public boolean onMenuItemClick(MenuItem item) { |
| 180 | switch (item.getItemId()) { |
| 181 | case MENU_RESET: |
Jason Monk | 96defbe | 2016-03-29 16:51:03 -0400 | [diff] [blame] | 182 | MetricsLogger.action(getContext(), MetricsProto.MetricsEvent.ACTION_QS_EDIT_RESET); |
Jason Monk | b53b6c5 | 2016-02-24 17:25:49 -0500 | [diff] [blame] | 183 | reset(); |
| 184 | break; |
| 185 | } |
| 186 | return false; |
| 187 | } |
| 188 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 189 | private void reset() { |
| 190 | ArrayList<String> tiles = new ArrayList<>(); |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 191 | String defTiles = mContext.getString(R.string.quick_settings_tiles_default); |
| 192 | for (String tile : defTiles.split(",")) { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 193 | tiles.add(tile); |
| 194 | } |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 195 | mTileAdapter.setTileSpecs(tiles); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 198 | private void setTileSpecs() { |
| 199 | List<String> specs = new ArrayList<>(); |
| 200 | for (QSTile tile : mHost.getTiles()) { |
| 201 | specs.add(tile.getTileSpec()); |
| 202 | } |
| 203 | mTileAdapter.setTileSpecs(specs); |
Jason Monk | 4efc924 | 2016-03-31 14:10:37 -0400 | [diff] [blame] | 204 | mRecyclerView.setAdapter(mTileAdapter); |
Jason Monk | f7fe83f | 2015-09-09 13:03:20 -0400 | [diff] [blame] | 205 | } |
| 206 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 207 | private void save() { |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 208 | mTileAdapter.saveSpecs(mHost); |
Jason Monk | 2681dcb | 2015-09-09 13:50:34 -0400 | [diff] [blame] | 209 | } |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 210 | |
Jason Monk | 181d3fe | 2016-06-06 16:18:50 -0400 | [diff] [blame] | 211 | private final Callback mKeyguardCallback = new Callback() { |
| 212 | @Override |
| 213 | public void onKeyguardChanged() { |
| 214 | if (mHost.getKeyguardMonitor().isShowing()) { |
| 215 | hide(0, 0); |
| 216 | } |
| 217 | } |
| 218 | }; |
| 219 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 220 | private final AnimatorListener mExpandAnimationListener = new AnimatorListenerAdapter() { |
| 221 | @Override |
| 222 | public void onAnimationEnd(Animator animation) { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 223 | if (isShown) { |
| 224 | setCustomizing(true); |
| 225 | } |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 226 | mNotifQsContainer.setCustomizerAnimating(false); |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public void onAnimationCancel(Animator animation) { |
| 231 | mNotifQsContainer.setCustomizerAnimating(false); |
| 232 | } |
| 233 | }; |
| 234 | |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 235 | private final AnimatorListener mCollapseAnimationListener = new AnimatorListenerAdapter() { |
| 236 | @Override |
| 237 | public void onAnimationEnd(Animator animation) { |
| 238 | if (!isShown) { |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 239 | setVisibility(View.GONE); |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 240 | } |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 241 | mNotifQsContainer.setCustomizerAnimating(false); |
Jason Monk | b213ac4 | 2016-06-20 10:27:27 -0400 | [diff] [blame] | 242 | mRecyclerView.setAdapter(mTileAdapter); |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 243 | } |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 244 | |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 245 | @Override |
| 246 | public void onAnimationCancel(Animator animation) { |
| 247 | if (!isShown) { |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 248 | setVisibility(View.GONE); |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 249 | } |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 250 | mNotifQsContainer.setCustomizerAnimating(false); |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 251 | } |
Jason Monk | 77a2c5f | 2016-02-22 15:18:36 -0500 | [diff] [blame] | 252 | }; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 253 | } |