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