First pass at drawer to Settings
Change-Id: I94c3bc69ff773e48c33f59f37bfc0d91139c187a
This commit is contained in:
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DashboardCategory implements Parcelable {
|
||||
|
||||
/**
|
||||
* Default value for {@link com.android.settings.dashboard.DashboardCategory#id DashboardCategory.id}
|
||||
* indicating that no identifier value is set. All other values (including those below -1)
|
||||
* are valid.
|
||||
*/
|
||||
public static final long CAT_ID_UNDEFINED = -1;
|
||||
|
||||
/**
|
||||
* Identifier for this tile, to correlate with a new list when
|
||||
* it is updated. The default value is
|
||||
* {@link com.android.settings.dashboard.DashboardTile#TILE_ID_UNDEFINED}, meaning no id.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_id
|
||||
*/
|
||||
public long id = CAT_ID_UNDEFINED;
|
||||
|
||||
/**
|
||||
* Resource ID of title of the category that is shown to the user.
|
||||
*/
|
||||
public int titleRes;
|
||||
|
||||
/**
|
||||
* Title of the category that is shown to the user.
|
||||
*/
|
||||
public CharSequence title;
|
||||
|
||||
/**
|
||||
* Key used for placing external tiles.
|
||||
*/
|
||||
public String key;
|
||||
|
||||
/**
|
||||
* Optional index of where to place tiles specified by system apps.
|
||||
*/
|
||||
public int externalIndex = -1;
|
||||
|
||||
/**
|
||||
* List of the category's children
|
||||
*/
|
||||
public List<DashboardTile> tiles = new ArrayList<DashboardTile>();
|
||||
|
||||
|
||||
public DashboardCategory() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public void addTile(DashboardTile tile) {
|
||||
tiles.add(tile);
|
||||
}
|
||||
|
||||
public void addTile(int n, DashboardTile tile) {
|
||||
tiles.add(n, tile);
|
||||
}
|
||||
|
||||
public void removeTile(DashboardTile tile) {
|
||||
tiles.remove(tile);
|
||||
}
|
||||
|
||||
public void removeTile(int n) {
|
||||
tiles.remove(n);
|
||||
}
|
||||
|
||||
public int getTilesCount() {
|
||||
return tiles.size();
|
||||
}
|
||||
|
||||
public DashboardTile getTile(int n) {
|
||||
return tiles.get(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently set title. If {@link #titleRes} is set,
|
||||
* this resource is loaded from <var>res</var> and returned. Otherwise
|
||||
* {@link #title} is returned.
|
||||
*/
|
||||
public CharSequence getTitle(Resources res) {
|
||||
if (titleRes != 0) {
|
||||
return res.getText(titleRes);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(titleRes);
|
||||
dest.writeInt(externalIndex);
|
||||
TextUtils.writeToParcel(title, dest, flags);
|
||||
dest.writeString(key);
|
||||
|
||||
final int count = tiles.size();
|
||||
dest.writeInt(count);
|
||||
|
||||
for (int n = 0; n < count; n++) {
|
||||
DashboardTile tile = tiles.get(n);
|
||||
tile.writeToParcel(dest, flags);
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel in) {
|
||||
titleRes = in.readInt();
|
||||
externalIndex = in.readInt();
|
||||
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
|
||||
key = in.readString();
|
||||
|
||||
final int count = in.readInt();
|
||||
|
||||
for (int n = 0; n < count; n++) {
|
||||
DashboardTile tile = DashboardTile.CREATOR.createFromParcel(in);
|
||||
tiles.add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
DashboardCategory(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<DashboardCategory> CREATOR = new Creator<DashboardCategory>() {
|
||||
public DashboardCategory createFromParcel(Parcel source) {
|
||||
return new DashboardCategory(source);
|
||||
}
|
||||
|
||||
public DashboardCategory[] newArray(int size) {
|
||||
return new DashboardCategory[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
@@ -42,6 +41,8 @@ import com.android.settings.HelpUtils;
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.DashboardTile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -147,7 +148,7 @@ public class DashboardSummary extends InstrumentedFragment {
|
||||
false);
|
||||
|
||||
TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title);
|
||||
categoryLabel.setText(category.getTitle(res));
|
||||
categoryLabel.setText(category.title);
|
||||
|
||||
ViewGroup categoryContent =
|
||||
(ViewGroup) categoryView.findViewById(R.id.category_content);
|
||||
@@ -175,11 +176,11 @@ public class DashboardSummary extends InstrumentedFragment {
|
||||
private void updateTileView(Context context, Resources res, DashboardTile tile,
|
||||
ImageView tileIcon, TextView tileTextView, TextView statusTextView) {
|
||||
|
||||
if (!TextUtils.isEmpty(tile.iconPkg)) {
|
||||
try {
|
||||
Drawable drawable = context.getPackageManager()
|
||||
.getResourcesForApplication(tile.iconPkg).getDrawable(tile.iconRes, null);
|
||||
if (!tile.iconPkg.equals(context.getPackageName()) && drawable != null) {
|
||||
if (tile.icon != null) {
|
||||
if (!TextUtils.isEmpty(tile.icon.getResPackage())) {
|
||||
Drawable drawable = tile.icon.loadDrawable(context);
|
||||
if (!tile.icon.getResPackage().equals(context.getPackageName())
|
||||
&& drawable != null) {
|
||||
// If this drawable is coming from outside Settings, tint it to match the color.
|
||||
TypedValue tintColor = new TypedValue();
|
||||
context.getTheme().resolveAttribute(com.android.internal.R.attr.colorAccent,
|
||||
@@ -187,20 +188,17 @@ public class DashboardSummary extends InstrumentedFragment {
|
||||
drawable.setTint(tintColor.data);
|
||||
}
|
||||
tileIcon.setImageDrawable(drawable);
|
||||
} catch (NameNotFoundException | Resources.NotFoundException e) {
|
||||
tileIcon.setImageDrawable(null);
|
||||
tileIcon.setBackground(null);
|
||||
} else {
|
||||
tileIcon.setImageIcon(tile.icon);
|
||||
}
|
||||
} else if (tile.iconRes > 0) {
|
||||
tileIcon.setImageResource(tile.iconRes);
|
||||
} else {
|
||||
tileIcon.setImageDrawable(null);
|
||||
tileIcon.setBackground(null);
|
||||
}
|
||||
|
||||
tileTextView.setText(tile.getTitle(res));
|
||||
tileTextView.setText(tile.title);
|
||||
|
||||
CharSequence summary = tile.getSummary(res);
|
||||
CharSequence summary = tile.summary;
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
statusTextView.setVisibility(View.VISIBLE);
|
||||
statusTextView.setText(summary);
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Description of a single dashboard tile that the user can select.
|
||||
*/
|
||||
public class DashboardTile implements Parcelable {
|
||||
/**
|
||||
* Default value for {@link com.android.settings.dashboard.DashboardTile#id DashboardTile.id}
|
||||
* indicating that no identifier value is set. All other values (including those below -1)
|
||||
* are valid.
|
||||
*/
|
||||
public static final long TILE_ID_UNDEFINED = -1;
|
||||
|
||||
/**
|
||||
* Identifier for this tile, to correlate with a new list when
|
||||
* it is updated. The default value is
|
||||
* {@link com.android.settings.dashboard.DashboardTile#TILE_ID_UNDEFINED}, meaning no id.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_id
|
||||
*/
|
||||
public long id = TILE_ID_UNDEFINED;
|
||||
|
||||
/**
|
||||
* Resource ID of title of the tile that is shown to the user.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_title
|
||||
*/
|
||||
public int titleRes;
|
||||
|
||||
/**
|
||||
* Title of the tile that is shown to the user.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_title
|
||||
*/
|
||||
public CharSequence title;
|
||||
|
||||
/**
|
||||
* Resource ID of optional summary describing what this tile controls.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_summary
|
||||
*/
|
||||
public int summaryRes;
|
||||
|
||||
/**
|
||||
* Optional summary describing what this tile controls.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_summary
|
||||
*/
|
||||
public CharSequence summary;
|
||||
|
||||
/**
|
||||
* Optional icon resource to show for this tile.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_icon
|
||||
*/
|
||||
public int iconRes;
|
||||
|
||||
/**
|
||||
* Optional package to pull the icon resource from.
|
||||
*/
|
||||
public String iconPkg;
|
||||
|
||||
/**
|
||||
* Full class name of the fragment to display when this tile is
|
||||
* selected.
|
||||
* @attr ref android.R.styleable#PreferenceHeader_fragment
|
||||
*/
|
||||
public String fragment;
|
||||
|
||||
/**
|
||||
* Optional arguments to supply to the fragment when it is
|
||||
* instantiated.
|
||||
*/
|
||||
public Bundle fragmentArguments;
|
||||
|
||||
/**
|
||||
* Intent to launch when the preference is selected.
|
||||
*/
|
||||
public Intent intent;
|
||||
|
||||
/**
|
||||
* Optional list of user handles which the intent should be launched on.
|
||||
*/
|
||||
public ArrayList<UserHandle> userHandle = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Optional additional data for use by subclasses of the activity
|
||||
*/
|
||||
public Bundle extras;
|
||||
|
||||
public DashboardTile() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently set title. If {@link #titleRes} is set,
|
||||
* this resource is loaded from <var>res</var> and returned. Otherwise
|
||||
* {@link #title} is returned.
|
||||
*/
|
||||
public CharSequence getTitle(Resources res) {
|
||||
if (titleRes != 0) {
|
||||
return res.getText(titleRes);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently set summary. If {@link #summaryRes} is set,
|
||||
* this resource is loaded from <var>res</var> and returned. Otherwise
|
||||
* {@link #summary} is returned.
|
||||
*/
|
||||
public CharSequence getSummary(Resources res) {
|
||||
if (summaryRes != 0) {
|
||||
return res.getText(summaryRes);
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(id);
|
||||
dest.writeInt(titleRes);
|
||||
TextUtils.writeToParcel(title, dest, flags);
|
||||
dest.writeInt(summaryRes);
|
||||
TextUtils.writeToParcel(summary, dest, flags);
|
||||
dest.writeInt(iconRes);
|
||||
dest.writeString(iconPkg);
|
||||
dest.writeString(fragment);
|
||||
dest.writeBundle(fragmentArguments);
|
||||
if (intent != null) {
|
||||
dest.writeInt(1);
|
||||
intent.writeToParcel(dest, flags);
|
||||
} else {
|
||||
dest.writeInt(0);
|
||||
}
|
||||
final int N = userHandle.size();
|
||||
dest.writeInt(N);
|
||||
for (int i = 0; i < N; i++) {
|
||||
userHandle.get(i).writeToParcel(dest, flags);
|
||||
}
|
||||
dest.writeBundle(extras);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel in) {
|
||||
id = in.readLong();
|
||||
titleRes = in.readInt();
|
||||
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
|
||||
summaryRes = in.readInt();
|
||||
summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
|
||||
iconRes = in.readInt();
|
||||
iconPkg = in.readString();
|
||||
fragment = in.readString();
|
||||
fragmentArguments = in.readBundle();
|
||||
if (in.readInt() != 0) {
|
||||
intent = Intent.CREATOR.createFromParcel(in);
|
||||
}
|
||||
final int N = in.readInt();
|
||||
for (int i = 0; i < N; i++) {
|
||||
userHandle.add(UserHandle.CREATOR.createFromParcel(in));
|
||||
}
|
||||
extras = in.readBundle();
|
||||
}
|
||||
|
||||
DashboardTile(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<DashboardTile> CREATOR = new Creator<DashboardTile>() {
|
||||
public DashboardTile createFromParcel(Parcel source) {
|
||||
return new DashboardTile(source);
|
||||
}
|
||||
public DashboardTile[] newArray(int size) {
|
||||
return new DashboardTile[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import android.widget.TextView;
|
||||
import com.android.settings.ProfileSelectDialog;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.drawer.DashboardTile;
|
||||
|
||||
public class DashboardTileView extends FrameLayout implements View.OnClickListener {
|
||||
|
||||
@@ -91,17 +92,21 @@ public class DashboardTileView extends FrameLayout implements View.OnClickListen
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mTile.fragment != null) {
|
||||
Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,
|
||||
mTile.titleRes, mTile.getTitle(getResources()));
|
||||
} else if (mTile.intent != null) {
|
||||
int numUserHandles = mTile.userHandle.size();
|
||||
clickTile(getContext(), mTile);
|
||||
}
|
||||
|
||||
public static void clickTile(Context context, DashboardTile tile) {
|
||||
if (tile.fragment != null) {
|
||||
Utils.startWithFragment(context, tile.fragment, tile.fragmentArguments, null, 0,
|
||||
0, tile.title);
|
||||
} else if (tile.intent != null) {
|
||||
int numUserHandles = tile.userHandle.size();
|
||||
if (numUserHandles > 1) {
|
||||
ProfileSelectDialog.show(((Activity) getContext()).getFragmentManager(), mTile);
|
||||
ProfileSelectDialog.show(((Activity) context).getFragmentManager(), tile);
|
||||
} else if (numUserHandles == 1) {
|
||||
getContext().startActivityAsUser(mTile.intent, mTile.userHandle.get(0));
|
||||
context.startActivityAsUser(tile.intent, tile.userHandle.get(0));
|
||||
} else {
|
||||
getContext().startActivity(mTile.intent);
|
||||
context.startActivity(tile.intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user