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 | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 20 | import android.content.Context; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 21 | import android.support.v7.widget.DefaultItemAnimator; |
| 22 | import android.support.v7.widget.GridLayoutManager; |
| 23 | import android.support.v7.widget.RecyclerView; |
| 24 | import android.support.v7.widget.helper.ItemTouchHelper; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 26 | import android.view.ContextThemeWrapper; |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 27 | import android.view.View; |
Jason Monk | 2681dcb | 2015-09-09 13:50:34 -0400 | [diff] [blame] | 28 | import android.view.View.OnClickListener; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 29 | import android.widget.LinearLayout; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 30 | import com.android.systemui.R; |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 31 | import com.android.systemui.qs.QSDetailClipper; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 32 | import com.android.systemui.qs.QSTile; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 33 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
| 34 | import com.android.systemui.statusbar.phone.QSTileHost; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 35 | |
| 36 | import java.util.ArrayList; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 37 | import java.util.List; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Allows full-screen customization of QS, through show() and hide(). |
| 41 | * |
| 42 | * This adds itself to the status bar window, so it can appear on top of quick settings and |
| 43 | * *someday* do fancy animations to get into/out of it. |
| 44 | */ |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 45 | public class QSCustomizer extends LinearLayout implements AnimatorListener, OnClickListener { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 46 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 47 | private final QSDetailClipper mClipper; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 48 | |
| 49 | private PhoneStatusBar mPhoneStatusBar; |
| 50 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 51 | private boolean isShown; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 52 | private QSTileHost mHost; |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 53 | private RecyclerView mRecyclerView; |
| 54 | private TileAdapter mTileAdapter; |
| 55 | private View mClose; |
| 56 | private View mSave; |
| 57 | private View mReset; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 58 | |
| 59 | public QSCustomizer(Context context, AttributeSet attrs) { |
| 60 | super(new ContextThemeWrapper(context, android.R.style.Theme_Material), attrs); |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 61 | mClipper = new QSDetailClipper(this); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | public void setHost(QSTileHost host) { |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 65 | mHost = host; |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 66 | mPhoneStatusBar = host.getPhoneStatusBar(); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
| 70 | protected void onFinishInflate() { |
| 71 | super.onFinishInflate(); |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 72 | mClose = findViewById(R.id.close); |
| 73 | mSave = findViewById(R.id.save); |
| 74 | mReset = findViewById(R.id.reset); |
| 75 | mClose.setOnClickListener(this); |
| 76 | mSave.setOnClickListener(this); |
| 77 | mReset.setOnClickListener(this); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 78 | |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 79 | mRecyclerView = (RecyclerView) findViewById(android.R.id.list); |
| 80 | mTileAdapter = new TileAdapter(getContext()); |
| 81 | mRecyclerView.setAdapter(mTileAdapter); |
| 82 | new ItemTouchHelper(mTileAdapter.getCallback()).attachToRecyclerView(mRecyclerView); |
| 83 | GridLayoutManager layout = new GridLayoutManager(getContext(), 3); |
| 84 | layout.setSpanSizeLookup(mTileAdapter.getSizeLookup()); |
| 85 | mRecyclerView.setLayoutManager(layout); |
| 86 | mRecyclerView.addItemDecoration(mTileAdapter.getItemDecoration()); |
| 87 | DefaultItemAnimator animator = new DefaultItemAnimator(); |
| 88 | animator.setMoveDuration(TileAdapter.MOVE_DURATION); |
| 89 | mRecyclerView.setItemAnimator(animator); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 92 | public void show(int x, int y) { |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 93 | if (!isShown) { |
| 94 | isShown = true; |
| 95 | mPhoneStatusBar.getStatusBarWindow().addView(this); |
| 96 | setTileSpecs(); |
| 97 | mClipper.animateCircularClip(x, y, true, this); |
| 98 | new TileQueryHelper(mContext, mHost).setListener(mTileAdapter); |
| 99 | } |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 102 | public void hide(int x, int y) { |
Jason Monk | 8c7e47f | 2016-02-17 10:39:31 -0500 | [diff] [blame] | 103 | if (isShown) { |
| 104 | isShown = false; |
| 105 | mClipper.animateCircularClip(x, y, false, this); |
| 106 | } |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | public boolean isCustomizing() { |
| 110 | return isShown; |
| 111 | } |
| 112 | |
| 113 | private void reset() { |
| 114 | ArrayList<String> tiles = new ArrayList<>(); |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 115 | String defTiles = mContext.getString(R.string.quick_settings_tiles_default); |
| 116 | for (String tile : defTiles.split(",")) { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 117 | tiles.add(tile); |
| 118 | } |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 119 | mTileAdapter.setTileSpecs(tiles); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 122 | private void setTileSpecs() { |
| 123 | List<String> specs = new ArrayList<>(); |
| 124 | for (QSTile tile : mHost.getTiles()) { |
| 125 | specs.add(tile.getTileSpec()); |
| 126 | } |
| 127 | mTileAdapter.setTileSpecs(specs); |
Jason Monk | f7fe83f | 2015-09-09 13:03:20 -0400 | [diff] [blame] | 128 | } |
| 129 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 130 | private void save() { |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 131 | mTileAdapter.saveSpecs(mHost); |
| 132 | hide((int) mSave.getX() + mSave.getWidth() / 2, (int) mSave.getY() + mSave.getHeight() / 2); |
Jason Monk | f7fe83f | 2015-09-09 13:03:20 -0400 | [diff] [blame] | 133 | } |
Jason Monk | 2681dcb | 2015-09-09 13:50:34 -0400 | [diff] [blame] | 134 | |
| 135 | @Override |
| 136 | public void onClick(View v) { |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 137 | if (v == mClose) { |
| 138 | hide((int) mClose.getX() + mClose.getWidth() / 2, |
| 139 | (int) mClose.getY() + mClose.getHeight() / 2); |
| 140 | } else if (v == mSave) { |
| 141 | save(); |
| 142 | } else if (v == mReset) { |
| 143 | reset(); |
Jason Monk | 2681dcb | 2015-09-09 13:50:34 -0400 | [diff] [blame] | 144 | } |
| 145 | } |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 146 | |
| 147 | @Override |
| 148 | public void onAnimationEnd(Animator animation) { |
| 149 | if (!isShown) { |
| 150 | mPhoneStatusBar.getStatusBarWindow().removeView(this); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void onAnimationCancel(Animator animation) { |
| 156 | if (!isShown) { |
| 157 | mPhoneStatusBar.getStatusBarWindow().removeView(this); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void onAnimationStart(Animator animation) { |
| 163 | // Don't care. |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void onAnimationRepeat(Animator animation) { |
| 168 | // Don't care. |
| 169 | } |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 170 | } |