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