1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/*
2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project
3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License");
5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License.
6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at
7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *      http://www.apache.org/licenses/LICENSE-2.0
9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software
11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS,
12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and
14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License.
15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */
16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.ui.conversation;
17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context;
19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.text.TextUtils;
20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.util.AttributeSet;
21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.View;
22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.LinearLayout;
23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.TextView;
24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R;
26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.data.SubscriptionListData.SubscriptionListEntry;
27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.Assert;
28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/**
30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Shows a view for a SIM in the SIM selector.
31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */
32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class SimSelectorItemView extends LinearLayout {
33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public interface HostInterface {
34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        void onSimItemClicked(SubscriptionListEntry item);
35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private SubscriptionListEntry mData;
38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private TextView mNameTextView;
39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private TextView mDetailsTextView;
40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private SimIconView mSimIconView;
41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private HostInterface mHost;
42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public SimSelectorItemView(final Context context, final AttributeSet attrs) {
44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        super(context, attrs);
45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    @Override
48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    protected void onFinishInflate() {
49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mNameTextView = (TextView) findViewById(R.id.name);
50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mDetailsTextView = (TextView) findViewById(R.id.details);
51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mSimIconView = (SimIconView) findViewById(R.id.sim_icon);
52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        setOnClickListener(new OnClickListener() {
53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            @Override
54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            public void onClick(View v) {
55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd                mHost.onSimItemClicked(mData);
56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            }
57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        });
58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public void bind(final SubscriptionListEntry simEntry) {
61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        Assert.notNull(simEntry);
62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mData = simEntry;
63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        updateViewAppearance();
64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public void setHostInterface(final HostInterface host) {
67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mHost = host;
68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private void updateViewAppearance() {
71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        Assert.notNull(mData);
72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        final String displayName = mData.displayName;
73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        if (TextUtils.isEmpty(displayName)) {
74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            mNameTextView.setVisibility(GONE);
75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        } else {
76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            mNameTextView.setVisibility(VISIBLE);
77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            mNameTextView.setText(displayName);
78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        }
79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        final String details = mData.displayDestination;
81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        if (TextUtils.isEmpty(details)) {
82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            mDetailsTextView.setVisibility(GONE);
83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        } else {
84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            mDetailsTextView.setVisibility(VISIBLE);
85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            mDetailsTextView.setText(details);
86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        }
87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mSimIconView.setImageResourceUri(mData.iconUri);
89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd}
91