1package com.google.android.test.shared_library;
2
3import android.content.Context;
4import android.content.res.TypedArray;
5import android.util.AttributeSet;
6import android.view.LayoutInflater;
7import android.view.View;
8import android.widget.LinearLayout;
9import android.widget.TextView;
10
11public class AddressView extends LinearLayout {
12    private TextView mNameView;
13    private TextView mStreetView;
14    private TextView mCityStateZipView;
15    private TextView mCountryView;
16
17    public AddressView(Context context, AttributeSet attrs) {
18        super(context, attrs);
19        setOrientation(VERTICAL);
20
21        View view = LayoutInflater.from(context).inflate(R.layout.address, this);
22        mNameView = (TextView) view.findViewById(R.id.name);
23        mStreetView = (TextView) view.findViewById(R.id.street);
24        mCityStateZipView = (TextView) view.findViewById(R.id.cityStateZip);
25        mCountryView = (TextView) view.findViewById(R.id.country);
26
27        TypedArray a = context.getTheme().obtainStyledAttributes(
28                attrs,
29                R.styleable.AddressView,
30                0, 0);
31        try {
32            mNameView.setText(a.getString(R.styleable.AddressView_name));
33            int streetNumber = a.getInteger(R.styleable.AddressView_streetNumber, -1);
34            mStreetView.setText((streetNumber <= 0 ? "" : Integer.toString(streetNumber)) +
35                    " " + a.getString(R.styleable.AddressView_streetName));
36            mCityStateZipView.setText(a.getString(R.styleable.AddressView_city) + ", " +
37                    a.getString(R.styleable.AddressView_state) + " " +
38                    a.getString(R.styleable.AddressView_zip));
39            mCountryView.setText(a.getString(R.styleable.AddressView_country));
40        } finally {
41            a.recycle();
42        }
43    }
44}
45