Merge "QS Tweaks" into nyc-dev
This commit is contained in:
@@ -22,47 +22,13 @@
|
||||
android:background="@drawable/qs_customizer_background"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<LinearLayout
|
||||
<Toolbar
|
||||
android:id="@*android:id/action_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="28dp"
|
||||
android:paddingEnd="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/close"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:padding="16dp"
|
||||
android:src="@drawable/ic_close_white" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/save"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Widget.Button.Inverse"
|
||||
android:textColor="?android:attr/colorAccent"
|
||||
android:text="@string/save" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/reset"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Widget.Button.Inverse"
|
||||
android:textColor="?android:attr/colorAccent"
|
||||
android:text="@*android:string/reset" />
|
||||
|
||||
</LinearLayout>
|
||||
android:layout_marginTop="28dp"
|
||||
android:navigationContentDescription="@*android:string/action_bar_up_description"
|
||||
style="?android:attr/toolbarStyle" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@android:id/list"
|
||||
|
||||
@@ -203,6 +203,7 @@
|
||||
<dimen name="qs_data_usage_text_size">14sp</dimen>
|
||||
<dimen name="qs_data_usage_usage_text_size">36sp</dimen>
|
||||
<dimen name="qs_expand_margin">0dp</dimen>
|
||||
<dimen name="qs_battery_padding">2dp</dimen>
|
||||
|
||||
<dimen name="segmented_button_spacing">0dp</dimen>
|
||||
<dimen name="borderless_button_radius">2dp</dimen>
|
||||
|
||||
@@ -70,11 +70,13 @@ public class QSIconView extends ViewGroup {
|
||||
protected void setIcon(ImageView iv, QSTile.State state) {
|
||||
if (!Objects.equals(state.icon, iv.getTag(R.id.qs_icon_tag))) {
|
||||
Drawable d = state.icon != null ? state.icon.getDrawable(mContext) : null;
|
||||
int padding = state.icon != null ? state.icon.getPadding() : null;
|
||||
if (d != null && state.autoMirrorDrawable) {
|
||||
d.setAutoMirrored(true);
|
||||
}
|
||||
iv.setImageDrawable(d);
|
||||
iv.setTag(R.id.qs_icon_tag, state.icon);
|
||||
iv.setPadding(0, padding, 0, padding);
|
||||
if (d instanceof Animatable) {
|
||||
Animatable a = (Animatable) d;
|
||||
a.start();
|
||||
|
||||
@@ -420,6 +420,10 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
public int hashCode() {
|
||||
return Icon.class.hashCode();
|
||||
}
|
||||
|
||||
public int getPadding() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DrawableIcon extends Icon {
|
||||
|
||||
@@ -22,12 +22,15 @@ import android.content.Context;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toolbar;
|
||||
import android.widget.Toolbar.OnMenuItemClickListener;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.qs.QSDetailClipper;
|
||||
import com.android.systemui.qs.QSTile;
|
||||
@@ -43,7 +46,9 @@ import java.util.List;
|
||||
* This adds itself to the status bar window, so it can appear on top of quick settings and
|
||||
* *someday* do fancy animations to get into/out of it.
|
||||
*/
|
||||
public class QSCustomizer extends LinearLayout implements OnClickListener {
|
||||
public class QSCustomizer extends LinearLayout implements OnMenuItemClickListener {
|
||||
|
||||
private static final int MENU_RESET = Menu.FIRST;
|
||||
|
||||
private final QSDetailClipper mClipper;
|
||||
|
||||
@@ -53,9 +58,7 @@ public class QSCustomizer extends LinearLayout implements OnClickListener {
|
||||
private QSTileHost mHost;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TileAdapter mTileAdapter;
|
||||
private View mClose;
|
||||
private View mSave;
|
||||
private View mReset;
|
||||
private Toolbar mToolbar;
|
||||
|
||||
public QSCustomizer(Context context, AttributeSet attrs) {
|
||||
super(new ContextThemeWrapper(context, android.R.style.Theme_Material), attrs);
|
||||
@@ -70,17 +73,26 @@ public class QSCustomizer extends LinearLayout implements OnClickListener {
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mClose = findViewById(R.id.close);
|
||||
mSave = findViewById(R.id.save);
|
||||
mReset = findViewById(R.id.reset);
|
||||
mClose.setOnClickListener(this);
|
||||
mSave.setOnClickListener(this);
|
||||
mReset.setOnClickListener(this);
|
||||
mToolbar = (Toolbar) findViewById(com.android.internal.R.id.action_bar);
|
||||
TypedValue value = new TypedValue();
|
||||
mContext.getTheme().resolveAttribute(android.R.attr.homeAsUpIndicator, value, true);
|
||||
mToolbar.setNavigationIcon(
|
||||
getResources().getDrawable(R.drawable.ic_close_white, mContext.getTheme()));
|
||||
mToolbar.setNavigationOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
save();
|
||||
hide((int) v.getX() + v.getWidth() / 2, (int) v.getY() + v.getHeight() / 2);
|
||||
}
|
||||
});
|
||||
mToolbar.setOnMenuItemClickListener(this);
|
||||
mToolbar.getMenu().add(Menu.NONE, MENU_RESET, 0,
|
||||
mContext.getString(com.android.internal.R.string.reset));
|
||||
|
||||
mRecyclerView = (RecyclerView) findViewById(android.R.id.list);
|
||||
mTileAdapter = new TileAdapter(getContext());
|
||||
mRecyclerView.setAdapter(mTileAdapter);
|
||||
new ItemTouchHelper(mTileAdapter.getCallback()).attachToRecyclerView(mRecyclerView);
|
||||
mTileAdapter.getItemTouchHelper().attachToRecyclerView(mRecyclerView);
|
||||
GridLayoutManager layout = new GridLayoutManager(getContext(), 3);
|
||||
layout.setSpanSizeLookup(mTileAdapter.getSizeLookup());
|
||||
mRecyclerView.setLayoutManager(layout);
|
||||
@@ -111,6 +123,16 @@ public class QSCustomizer extends LinearLayout implements OnClickListener {
|
||||
return isShown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_RESET:
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
ArrayList<String> tiles = new ArrayList<>();
|
||||
String defTiles = mContext.getString(R.string.quick_settings_tiles_default);
|
||||
@@ -130,19 +152,6 @@ public class QSCustomizer extends LinearLayout implements OnClickListener {
|
||||
|
||||
private void save() {
|
||||
mTileAdapter.saveSpecs(mHost);
|
||||
hide((int) mSave.getX() + mSave.getWidth() / 2, (int) mSave.getY() + mSave.getHeight() / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mClose) {
|
||||
hide((int) mClose.getX() + mClose.getWidth() / 2,
|
||||
(int) mClose.getY() + mClose.getHeight() / 2);
|
||||
} else if (v == mSave) {
|
||||
save();
|
||||
} else if (v == mReset) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
private final AnimatorListener mCollapseAnimationListener = new AnimatorListenerAdapter() {
|
||||
|
||||
@@ -24,9 +24,10 @@ import android.support.v7.widget.RecyclerView.ItemDecoration;
|
||||
import android.support.v7.widget.RecyclerView.State;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper.Callback;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import com.android.systemui.R;
|
||||
@@ -52,6 +53,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
private final Context mContext;
|
||||
|
||||
private final List<TileInfo> mTiles = new ArrayList<>();
|
||||
private final ItemTouchHelper mItemTouchHelper;
|
||||
private int mDividerIndex;
|
||||
private List<String> mCurrentSpecs;
|
||||
private List<TileInfo> mOtherTiles;
|
||||
@@ -61,6 +63,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
|
||||
public TileAdapter(Context context) {
|
||||
mContext = context;
|
||||
mItemTouchHelper = new ItemTouchHelper(mCallbacks);
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
@@ -69,8 +72,8 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
return mTiles.get(position) != null ? mAllTiles.indexOf(mTiles.get(position)) : -1;
|
||||
}
|
||||
|
||||
public Callback getCallback() {
|
||||
return mCallbacks;
|
||||
public ItemTouchHelper getItemTouchHelper() {
|
||||
return mItemTouchHelper;
|
||||
}
|
||||
|
||||
public ItemDecoration getItemDecoration() {
|
||||
@@ -148,11 +151,18 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(Holder holder, int position) {
|
||||
public void onBindViewHolder(final Holder holder, int position) {
|
||||
if (holder.getItemViewType() == TYPE_EDIT) return;
|
||||
|
||||
TileInfo info = mTiles.get(position);
|
||||
holder.mTileView.onStateChanged(info.state);
|
||||
holder.mTileView.setOnTouchListener(new OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
mItemTouchHelper.startDrag(holder);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public SpanSizeLookup getSizeLookup() {
|
||||
@@ -266,9 +276,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
||||
int from = viewHolder.getAdapterPosition();
|
||||
int to = target.getAdapterPosition();
|
||||
if (to > mDividerIndex) {
|
||||
if (from < mDividerIndex) {
|
||||
to = mDividerIndex;
|
||||
} else {
|
||||
if (from >= mDividerIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.systemui.qs.customize;
|
||||
|
||||
import android.Manifest.permission;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -132,6 +133,9 @@ public class TileQueryHelper {
|
||||
ComponentName componentName = new ComponentName(packageName, info.serviceInfo.name);
|
||||
String spec = CustomTile.toSpec(componentName);
|
||||
Drawable icon = info.serviceInfo.loadIcon(pm);
|
||||
if (!permission.BIND_QUICK_SETTINGS_TILE.equals(info.serviceInfo.permission)) {
|
||||
continue;
|
||||
}
|
||||
if (icon != null) {
|
||||
icon.mutate();
|
||||
icon.setTint(mContext.getColor(android.R.color.white));
|
||||
|
||||
@@ -115,6 +115,12 @@ public class BatteryTile extends QSTile<QSTile.State> implements BatteryControll
|
||||
public Drawable getDrawable(Context context) {
|
||||
return mDrawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPadding() {
|
||||
return mHost.getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.qs_battery_padding);
|
||||
}
|
||||
};
|
||||
state.label = percentage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user