am c55a2547: am bebcde44: Merge "[DS] DSDS support for widget view" into lmp-sprout-dev

* commit 'c55a2547a1462a1bf9e1b3c4e102d4d61877d7fe':
  [DS] DSDS support for widget view
This commit is contained in:
Paul West
2014-10-02 15:34:09 +00:00
committed by Android Git Automerger
4 changed files with 287 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2011-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.internal.widget;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.internal.R;
import com.android.internal.widget.AccountViewAdapter.AccountElements;
/**
* An LinearLayout view, to show Accounts elements.
*/
public class AccountItemView extends LinearLayout {
private ImageView mAccountIcon;
private TextView mAccountName;
private TextView mAccountNumber;
/**
* Constructor.
*/
public AccountItemView(Context context) {
this(context, null);
}
/**
* Constructor.
*/
public AccountItemView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflator = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.simple_account_item, null);
addView(view);
initViewItem(view);
}
private void initViewItem(View view) {
mAccountIcon = (ImageView)view.findViewById(android.R.id.icon);
mAccountName = (TextView)view.findViewById(android.R.id.title);
mAccountNumber = (TextView)view.findViewById(android.R.id.summary);
}
public void setViewItem(AccountElements element) {
Drawable drawable = element.getDrawable();
if (drawable != null) {
setAccountIcon(drawable);
} else {
setAccountIcon(element.getIcon());
}
setAccountName(element.getName());
setAccountNumber(element.getNumber());
}
public void setAccountIcon(int resId) {
mAccountIcon.setImageResource(resId);
}
public void setAccountIcon(Drawable drawable) {
mAccountIcon.setBackgroundDrawable(drawable);
}
public void setAccountName(String name) {
setText(mAccountName, name);
}
public void setAccountNumber(String number) {
setText(mAccountNumber, number);
}
private void setText(TextView view, String text) {
if (TextUtils.isEmpty(text)) {
view.setVisibility(View.GONE);
} else {
view.setText(text);
view.setVisibility(View.VISIBLE);
}
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2011-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.internal.widget;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.List;
public class AccountViewAdapter extends BaseAdapter {
private List<AccountElements> mData;
private Context mContext;
/**
* Constructor
*
* @param context The context where the View associated with this Adapter is running
* @param data A list with AccountElements data type. The list contains the data of each
* account and the each member of AccountElements will correspond to one item view.
*/
public AccountViewAdapter(Context context, final List<AccountElements> data) {
mContext = context;
mData = data;
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int position) {
return mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public void updateData(final List<AccountElements> data) {
mData = data;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
AccountItemView view;
if (convertView == null) {
view = new AccountItemView(mContext);
} else {
view = (AccountItemView) convertView;
}
AccountElements elements = (AccountElements) getItem(position);
view.setViewItem(elements);
return view;
}
public static class AccountElements {
private int mIcon;
private Drawable mDrawable;
private String mName;
private String mNumber;
/**
* Constructor
* A structure with basic element of an Account, icon, name and number
*
* @param icon Account icon id
* @param name Account name
* @param num Account number
*/
public AccountElements(int icon, String name, String number) {
this(icon, null, name, number);
}
/**
* Constructor
* A structure with basic element of an Account, drawable, name and number
*
* @param drawable Account drawable
* @param name Account name
* @param num Account number
*/
public AccountElements(Drawable drawable, String name, String number) {
this(0, drawable, name, number);
}
private AccountElements(int icon, Drawable drawable, String name, String number) {
mIcon = icon;
mDrawable = drawable;
mName = name;
mNumber = number;
}
public int getIcon() {
return mIcon;
}
public String getName() {
return mName;
}
public String getNumber() {
return mNumber;
}
public Drawable getDrawable() {
return mDrawable;
}
}
}

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingStart="16dip"
android:paddingEnd="?android:attr/scrollbarSize">
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginStart="10dip"
android:layout_marginEnd="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="none"
android:textAppearance="?android:attr/textAppearanceListItem" />
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:singleLine="true"
android:ellipsize="none"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary"/>
</RelativeLayout>
</LinearLayout>

View File

@@ -2071,4 +2071,7 @@
<java-symbol type="array" name="networks_not_clear_data" />
<java-symbol type="bool" name="config_switch_phone_on_voice_reg_state_change" />
<java-symbol type="string" name="whichHomeApplicationNamed" />
<!-- From MSIM Account -->
<java-symbol type="layout" name="simple_account_item" />
</resources>