From 97850c066b3eccdabecdd5f424735883661c12ed Mon Sep 17 00:00:00 2001 From: Mick Lin Date: Thu, 11 Sep 2014 16:36:08 +0800 Subject: [PATCH] [DS] DSDS support for widget view Change-Id: If8b8410eb3cc471933f0b109973ea1f43fe5e791 --- .../internal/widget/AccountItemView.java | 102 ++++++++++++++ .../internal/widget/AccountViewAdapter.java | 127 ++++++++++++++++++ core/res/res/layout/simple_account_item.xml | 55 ++++++++ core/res/res/values/symbols.xml | 3 + 4 files changed, 287 insertions(+) create mode 100644 core/java/com/android/internal/widget/AccountItemView.java create mode 100644 core/java/com/android/internal/widget/AccountViewAdapter.java create mode 100644 core/res/res/layout/simple_account_item.xml diff --git a/core/java/com/android/internal/widget/AccountItemView.java b/core/java/com/android/internal/widget/AccountItemView.java new file mode 100644 index 0000000000000..a5214288a7c35 --- /dev/null +++ b/core/java/com/android/internal/widget/AccountItemView.java @@ -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); + } + } +} diff --git a/core/java/com/android/internal/widget/AccountViewAdapter.java b/core/java/com/android/internal/widget/AccountViewAdapter.java new file mode 100644 index 0000000000000..8a7a9a67bfc49 --- /dev/null +++ b/core/java/com/android/internal/widget/AccountViewAdapter.java @@ -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 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 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 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; + } + } +} diff --git a/core/res/res/layout/simple_account_item.xml b/core/res/res/layout/simple_account_item.xml new file mode 100644 index 0000000000000..e7b746cec2b40 --- /dev/null +++ b/core/res/res/layout/simple_account_item.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index ff6f1f8b6e0e6..64699cfd73652 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2071,4 +2071,7 @@ + + +