Settings new dashboard - part 2
Introduce the new Dashboard (a grid like presentation of Settings top categories) per UX specification. - the Dashboard is composed of "categories" and in each of them you have "tiles" - implement a new layout for showing top categories (DashboardContainerView). This layout basically acts like a grid - depending on the device configuration make the grid with 1 column in portrait / 2 colums in landscape (phones) OR 2 columns in portrait and 3 in landscape (tablets) - take care of Accounts adding and removing (as it changes the number of tiles to show) Also remove all the old code related to Headers Change-Id: Ie29944132c1b4c3f7b073d5a7d4453b8f5ec19a7
This commit is contained in:
134
src/com/android/settings/dashboard/DashboardContainerView.java
Normal file
134
src/com/android/settings/dashboard/DashboardContainerView.java
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class DashboardContainerView extends ViewGroup {
|
||||
|
||||
private int mNumColumns;
|
||||
private float mCellGap;
|
||||
|
||||
public DashboardContainerView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
final Resources res = context.getResources();
|
||||
mCellGap = res.getDimension(R.dimen.dashboard_cell_gap);
|
||||
mNumColumns = res.getInteger(R.integer.dashboard_num_columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int availableWidth = (int) (width - getPaddingLeft() - getPaddingRight() -
|
||||
(mNumColumns - 1) * mCellGap);
|
||||
float cellWidth = (float) Math.ceil(((float) availableWidth) / mNumColumns);
|
||||
final int N = getChildCount();
|
||||
|
||||
int cellHeight = 0;
|
||||
int cursor = 0;
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
DashboardTileView v = (DashboardTileView) getChildAt(i);
|
||||
if (v.getVisibility() == View.GONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ViewGroup.LayoutParams lp = v.getLayoutParams();
|
||||
int colSpan = v.getColumnSpan();
|
||||
lp.width = (int) ((colSpan * cellWidth) + (colSpan - 1) * mCellGap);
|
||||
|
||||
// Measure the child
|
||||
int newWidthSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
|
||||
int newHeightSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);
|
||||
v.measure(newWidthSpec, newHeightSpec);
|
||||
|
||||
// Save the cell height
|
||||
if (cellHeight <= 0) {
|
||||
cellHeight = v.getMeasuredHeight();
|
||||
}
|
||||
|
||||
lp.height = cellHeight;
|
||||
|
||||
cursor += colSpan;
|
||||
}
|
||||
|
||||
final int numRows = (int) Math.ceil((float) cursor / mNumColumns);
|
||||
final int newHeight = (int) ((numRows * cellHeight) + ((numRows - 1) * mCellGap)) +
|
||||
getPaddingTop() + getPaddingBottom();
|
||||
|
||||
setMeasuredDimension(width, newHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
final int N = getChildCount();
|
||||
final boolean isLayoutRtl = isLayoutRtl();
|
||||
final int width = getWidth();
|
||||
|
||||
int x = getPaddingStart();
|
||||
int y = getPaddingTop();
|
||||
int cursor = 0;
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
final DashboardTileView child = (DashboardTileView) getChildAt(i);
|
||||
final ViewGroup.LayoutParams lp = child.getLayoutParams();
|
||||
if (child.getVisibility() == GONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int col = cursor % mNumColumns;
|
||||
final int colSpan = child.getColumnSpan();
|
||||
|
||||
final int childWidth = lp.width;
|
||||
final int childHeight = lp.height;
|
||||
|
||||
int row = cursor / mNumColumns;
|
||||
|
||||
// Push the item to the next row if it can't fit on this one
|
||||
if ((col + colSpan) > mNumColumns) {
|
||||
x = getPaddingStart();
|
||||
y += childHeight + mCellGap;
|
||||
row++;
|
||||
}
|
||||
|
||||
final int childLeft = (isLayoutRtl) ? width - x - childWidth : x;
|
||||
final int childRight = childLeft + childWidth;
|
||||
|
||||
final int childTop = y;
|
||||
final int childBottom = childTop + childHeight;
|
||||
|
||||
// Layout the container
|
||||
child.layout(childLeft, childTop, childRight, childBottom);
|
||||
|
||||
// Offset the position by the cell gap or reset the position and cursor when we
|
||||
// reach the end of the row
|
||||
cursor += child.getColumnSpan();
|
||||
if (cursor < (((row + 1) * mNumColumns))) {
|
||||
x += childWidth + mCellGap;
|
||||
} else {
|
||||
x = getPaddingStart();
|
||||
y += childHeight + mCellGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,35 +16,166 @@
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.app.ListFragment;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.OnAccountsUpdateListener;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.accounts.AuthenticatorHelper;
|
||||
import com.android.settings.accounts.ManageAccountsSettings;
|
||||
|
||||
public class DashboardSummary extends ListFragment {
|
||||
import java.util.List;
|
||||
|
||||
public class DashboardSummary extends Fragment implements OnAccountsUpdateListener {
|
||||
private static final String LOG_TAG = "DashboardSummary";
|
||||
|
||||
private LayoutInflater mLayoutInflater;
|
||||
private ViewGroup mContainer;
|
||||
private ViewGroup mDashboard;
|
||||
private AuthenticatorHelper mAuthHelper;
|
||||
|
||||
private static final int MSG_BUILD_CATEGORIES = 1;
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_BUILD_CATEGORIES: {
|
||||
final Context context = getActivity();
|
||||
rebuildUI(context);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
final View view = inflater.inflate(R.layout.dashboard, container, false);
|
||||
final Context context = getActivity();
|
||||
|
||||
ListView listView = (ListView) view.findViewById(android.R.id.list);
|
||||
mLayoutInflater = inflater;
|
||||
mContainer = container;
|
||||
|
||||
ListAdapter adapter = ((SettingsActivity) getActivity()).getHeaderAdapter();
|
||||
listView.setAdapter(adapter);
|
||||
final View rootView = inflater.inflate(R.layout.dashboard, container, false);
|
||||
mDashboard = (ViewGroup) rootView.findViewById(R.id.dashboard_container);
|
||||
|
||||
return view;
|
||||
mAuthHelper = ((SettingsActivity) context).getAuthenticatorHelper();
|
||||
|
||||
rebuildUI(getActivity());
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void rebuildUI(Context context) {
|
||||
final Resources res = getResources();
|
||||
|
||||
mDashboard.removeAllViews();
|
||||
|
||||
List<DashboardCategory> categories =
|
||||
((SettingsActivity) context).getDashboardCategories();
|
||||
|
||||
final int count = categories.size();
|
||||
|
||||
for (int n = 0; n < count; n++) {
|
||||
DashboardCategory category = categories.get(n);
|
||||
|
||||
View categoryView = mLayoutInflater.inflate(R.layout.dashboard_category, mContainer,
|
||||
false);
|
||||
|
||||
TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title);
|
||||
categoryLabel.setText(category.getTitle(res));
|
||||
|
||||
ViewGroup categoryContent =
|
||||
(ViewGroup) categoryView.findViewById(R.id.category_content);
|
||||
|
||||
final int tilesCount = category.getTilesCount();
|
||||
for (int i = 0; i < tilesCount; i++) {
|
||||
DashboardTile tile = category.getTile(i);
|
||||
|
||||
DashboardTileView tileView = new DashboardTileView(context);
|
||||
updateTileView(context, res, tile, tileView.getImageView(),
|
||||
tileView.getTitleTextView(), tileView.getStatusTextView());
|
||||
|
||||
tileView.setTile(tile);
|
||||
|
||||
categoryContent.addView(tileView);
|
||||
}
|
||||
|
||||
// Add the category
|
||||
mDashboard.addView(categoryView);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
((SettingsActivity) getActivity()).onListItemClick(l, v, position, id);
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
AccountManager.get(getActivity()).addOnAccountsUpdatedListener(this, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
AccountManager.get(getActivity()).removeOnAccountsUpdatedListener(this);
|
||||
}
|
||||
|
||||
private void updateTileView(Context context, Resources res, DashboardTile tile,
|
||||
ImageView tileIcon, TextView tileTextView, TextView statusTextView) {
|
||||
|
||||
if (tile.extras != null
|
||||
&& tile.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
|
||||
String accType = tile.extras.getString(ManageAccountsSettings.KEY_ACCOUNT_TYPE);
|
||||
Drawable drawable = mAuthHelper.getDrawableForType(context, accType);
|
||||
tileIcon.setImageDrawable(drawable);
|
||||
} else {
|
||||
if (tile.iconRes > 0) {
|
||||
tileIcon.setImageResource(tile.iconRes);
|
||||
} else {
|
||||
tileIcon.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
if (tileIcon != null) {
|
||||
if (tile.iconRes > 0) {
|
||||
tileIcon.setBackgroundResource(R.color.temporary_background_icon);
|
||||
} else {
|
||||
tileIcon.setBackground(null);
|
||||
}
|
||||
}
|
||||
tileTextView.setText(tile.getTitle(res));
|
||||
|
||||
CharSequence summary = tile.getSummary(res);
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
statusTextView.setVisibility(View.VISIBLE);
|
||||
statusTextView.setText(summary);
|
||||
} else {
|
||||
statusTextView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildCategories() {
|
||||
if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
|
||||
mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountsUpdated(Account[] accounts) {
|
||||
final SettingsActivity sa = (SettingsActivity) getActivity();
|
||||
sa.setNeedToRebuildCategories(true);
|
||||
rebuildCategories();
|
||||
}
|
||||
}
|
||||
|
||||
91
src/com/android/settings/dashboard/DashboardTileView.java
Normal file
91
src/com/android/settings/dashboard/DashboardTileView.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class DashboardTileView extends FrameLayout implements View.OnClickListener {
|
||||
|
||||
private static final int DEFAULT_COL_SPAN = 1;
|
||||
|
||||
private ImageView mImageView;
|
||||
private TextView mTitleTextView;
|
||||
private TextView mStatusTextView;
|
||||
|
||||
private int mColSpan = DEFAULT_COL_SPAN;
|
||||
|
||||
private DashboardTile mTile;
|
||||
|
||||
public DashboardTileView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public DashboardTileView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, this);
|
||||
|
||||
mImageView = (ImageView) view.findViewById(R.id.icon);
|
||||
mTitleTextView = (TextView) view.findViewById(R.id.title);
|
||||
mStatusTextView = (TextView) view.findViewById(R.id.status);
|
||||
|
||||
setOnClickListener(this);
|
||||
}
|
||||
|
||||
public TextView getTitleTextView() {
|
||||
return mTitleTextView;
|
||||
}
|
||||
|
||||
public TextView getStatusTextView() {
|
||||
return mStatusTextView;
|
||||
}
|
||||
|
||||
public ImageView getImageView() {
|
||||
return mImageView;
|
||||
}
|
||||
|
||||
public void setTile(DashboardTile tile) {
|
||||
mTile = tile;
|
||||
}
|
||||
|
||||
void setColumnSpan(int span) {
|
||||
mColSpan = span;
|
||||
}
|
||||
|
||||
int getColumnSpan() {
|
||||
return mColSpan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mTile.fragment != null) {
|
||||
Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,
|
||||
mTile.getTitle(getResources()));
|
||||
} else if (mTile.intent != null) {
|
||||
getContext().startActivity(mTile.intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,265 +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.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accounts.AuthenticatorHelper;
|
||||
import com.android.settings.accounts.ManageAccountsSettings;
|
||||
import com.android.settings.bluetooth.BluetoothEnabler;
|
||||
import com.android.settings.wifi.WifiEnabler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A basic ArrayAdapter for dealing with the Headers
|
||||
*/
|
||||
public class HeaderAdapter extends ArrayAdapter<Header> {
|
||||
public static final int HEADER_TYPE_CATEGORY = 0;
|
||||
public static final int HEADER_TYPE_NORMAL = 1;
|
||||
public static final int HEADER_TYPE_SWITCH = 2;
|
||||
public static final int HEADER_TYPE_BUTTON = 3;
|
||||
|
||||
private static final int HEADER_TYPE_COUNT = HEADER_TYPE_BUTTON + 1;
|
||||
|
||||
private final WifiEnabler mWifiEnabler;
|
||||
private final BluetoothEnabler mBluetoothEnabler;
|
||||
private AuthenticatorHelper mAuthHelper;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
|
||||
private static class HeaderViewHolder {
|
||||
ImageView mIcon;
|
||||
TextView mTitle;
|
||||
TextView mSummary;
|
||||
Switch mSwitch;
|
||||
ImageButton mButton;
|
||||
View mDivider;
|
||||
}
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
public static int getHeaderType(Header header) {
|
||||
if (header.fragment == null && header.intent == null) {
|
||||
return HEADER_TYPE_CATEGORY;
|
||||
} else if (header.id == R.id.security_settings) {
|
||||
return HEADER_TYPE_BUTTON;
|
||||
} else {
|
||||
return HEADER_TYPE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Header header = getItem(position);
|
||||
return getHeaderType(header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return false; // because of categories
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return getItemViewType(position) != HEADER_TYPE_CATEGORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return HEADER_TYPE_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableIds() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public HeaderAdapter(Context context, List<Header> objects,
|
||||
AuthenticatorHelper authenticatorHelper, DevicePolicyManager dpm) {
|
||||
super(context, 0, objects);
|
||||
|
||||
mAuthHelper = authenticatorHelper;
|
||||
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
// Temp Switches provided as placeholder until the adapter replaces these with actual
|
||||
// Switches inflated from their layouts. Must be done before adapter is set in super
|
||||
mWifiEnabler = new WifiEnabler(context, new Switch(context));
|
||||
mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context));
|
||||
mDevicePolicyManager = dpm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
HeaderViewHolder holder;
|
||||
Header header = getItem(position);
|
||||
int headerType = getHeaderType(header);
|
||||
View view = null;
|
||||
|
||||
if (convertView == null) {
|
||||
holder = new HeaderViewHolder();
|
||||
switch (headerType) {
|
||||
case HEADER_TYPE_CATEGORY:
|
||||
view = new TextView(getContext(), null,
|
||||
android.R.attr.listSeparatorTextViewStyle);
|
||||
holder.mTitle = (TextView) view;
|
||||
break;
|
||||
|
||||
case HEADER_TYPE_SWITCH:
|
||||
view = mInflater.inflate(R.layout.preference_header_switch_item, parent,
|
||||
false);
|
||||
holder.mIcon = (ImageView) view.findViewById(R.id.icon);
|
||||
holder.mTitle = (TextView)
|
||||
view.findViewById(com.android.internal.R.id.title);
|
||||
holder.mSummary = (TextView)
|
||||
view.findViewById(com.android.internal.R.id.summary);
|
||||
holder.mSwitch = (Switch) view.findViewById(R.id.switchWidget);
|
||||
break;
|
||||
|
||||
case HEADER_TYPE_BUTTON:
|
||||
view = mInflater.inflate(R.layout.preference_header_button_item, parent,
|
||||
false);
|
||||
holder.mIcon = (ImageView) view.findViewById(R.id.icon);
|
||||
holder.mTitle = (TextView)
|
||||
view.findViewById(com.android.internal.R.id.title);
|
||||
holder.mSummary = (TextView)
|
||||
view.findViewById(com.android.internal.R.id.summary);
|
||||
holder.mButton = (ImageButton) view.findViewById(R.id.buttonWidget);
|
||||
holder.mDivider = view.findViewById(R.id.divider);
|
||||
break;
|
||||
|
||||
case HEADER_TYPE_NORMAL:
|
||||
view = mInflater.inflate(
|
||||
R.layout.preference_header_item, parent,
|
||||
false);
|
||||
holder.mIcon = (ImageView) view.findViewById(R.id.icon);
|
||||
holder.mTitle = (TextView)
|
||||
view.findViewById(com.android.internal.R.id.title);
|
||||
holder.mSummary = (TextView)
|
||||
view.findViewById(com.android.internal.R.id.summary);
|
||||
break;
|
||||
}
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
view = convertView;
|
||||
holder = (HeaderViewHolder) view.getTag();
|
||||
}
|
||||
|
||||
// All view fields must be updated every time, because the view may be recycled
|
||||
switch (headerType) {
|
||||
case HEADER_TYPE_CATEGORY:
|
||||
holder.mTitle.setText(header.getTitle(getContext().getResources()));
|
||||
break;
|
||||
|
||||
case HEADER_TYPE_SWITCH:
|
||||
// Would need a different treatment if the main menu had more switches
|
||||
if (header.id == R.id.wifi_settings) {
|
||||
mWifiEnabler.setSwitch(holder.mSwitch);
|
||||
} else {
|
||||
mBluetoothEnabler.setSwitch(holder.mSwitch);
|
||||
}
|
||||
updateCommonHeaderView(header, holder);
|
||||
break;
|
||||
|
||||
case HEADER_TYPE_BUTTON:
|
||||
if (header.id == R.id.security_settings) {
|
||||
boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled();
|
||||
if (hasCert) {
|
||||
holder.mButton.setVisibility(View.VISIBLE);
|
||||
holder.mDivider.setVisibility(View.VISIBLE);
|
||||
boolean isManaged = mDevicePolicyManager.getDeviceOwner() != null;
|
||||
if (isManaged) {
|
||||
holder.mButton.setImageResource(R.drawable.ic_settings_about);
|
||||
} else {
|
||||
holder.mButton.setImageResource(
|
||||
android.R.drawable.stat_notify_error);
|
||||
}
|
||||
holder.mButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(
|
||||
android.provider.Settings.ACTION_MONITORING_CERT_INFO);
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
holder.mButton.setVisibility(View.GONE);
|
||||
holder.mDivider.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
updateCommonHeaderView(header, holder);
|
||||
break;
|
||||
|
||||
case HEADER_TYPE_NORMAL:
|
||||
updateCommonHeaderView(header, holder);
|
||||
break;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void updateCommonHeaderView(Header header, HeaderViewHolder holder) {
|
||||
if (header.extras != null
|
||||
&& header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
|
||||
String accType = header.extras.getString(
|
||||
ManageAccountsSettings.KEY_ACCOUNT_TYPE);
|
||||
Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
|
||||
setHeaderIcon(holder, icon);
|
||||
} else {
|
||||
if (header.iconRes > 0) {
|
||||
holder.mIcon.setImageResource(header.iconRes);
|
||||
} else {
|
||||
holder.mIcon.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
if (holder.mIcon != null) {
|
||||
if (header.iconRes > 0) {
|
||||
holder.mIcon.setBackgroundResource(R.color.background_drawer_icon);
|
||||
} else {
|
||||
holder.mIcon.setBackground(null);
|
||||
}
|
||||
}
|
||||
holder.mTitle.setText(header.getTitle(getContext().getResources()));
|
||||
CharSequence summary = header.getSummary(getContext().getResources());
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
holder.mSummary.setVisibility(View.VISIBLE);
|
||||
holder.mSummary.setText(summary);
|
||||
} else {
|
||||
holder.mSummary.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void setHeaderIcon(HeaderViewHolder holder, Drawable icon) {
|
||||
ViewGroup.LayoutParams lp = holder.mIcon.getLayoutParams();
|
||||
lp.width = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.header_icon_width);
|
||||
lp.height = lp.width;
|
||||
holder.mIcon.setLayoutParams(lp);
|
||||
holder.mIcon.setImageDrawable(icon);
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,11 @@ package com.android.settings.dashboard;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -41,15 +39,11 @@ import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.search.IndexDatabaseHelper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.android.settings.search.IndexDatabaseHelper.SavedQueriesColums;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.Tables;
|
||||
|
||||
public class SearchResultsSummary extends Fragment {
|
||||
|
||||
private static final String LOG_TAG = "SearchResultsSummary";
|
||||
@@ -164,14 +158,13 @@ public class SearchResultsSummary extends Fragment {
|
||||
final String key = cursor.getString(Index.COLUMN_INDEX_KEY);
|
||||
|
||||
final SettingsActivity sa = (SettingsActivity) getActivity();
|
||||
|
||||
sa.needToRevertToInitialFragment();
|
||||
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||
|
||||
sa.startWithFragment(className, args, null, 0, screenTitle);
|
||||
Utils.startWithFragment(sa, className, args, null, 0, screenTitle);
|
||||
} else {
|
||||
final Intent intent = new Intent(action);
|
||||
|
||||
@@ -588,7 +581,7 @@ public class SearchResultsSummary extends Fragment {
|
||||
// Not much we can do except logging
|
||||
Log.e(LOG_TAG, "Cannot load Drawable for " + result.title);
|
||||
}
|
||||
imageView.setBackgroundResource(R.color.background_search_result_icon);
|
||||
imageView.setBackgroundResource(R.color.temporary_background_icon);
|
||||
} else {
|
||||
imageView.setImageDrawable(null);
|
||||
imageView.setBackgroundResource(R.drawable.empty_icon);
|
||||
|
||||
Reference in New Issue
Block a user