Home | History | Annotate | Download | only in calllog
      1 /*
      2  * Copyright (C) 2011 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 
     17 package com.android.dialer.app.calllog;
     18 
     19 import android.content.Context;
     20 import android.view.View;
     21 import android.widget.TextView;
     22 import com.android.dialer.app.R;
     23 import com.android.dialer.calllogutils.CallTypeIconsView;
     24 
     25 /** Encapsulates the views that are used to display the details of a phone call in the call log. */
     26 public final class PhoneCallDetailsViews {
     27 
     28   public final TextView nameView;
     29   public final View callTypeView;
     30   public final CallTypeIconsView callTypeIcons;
     31   public final TextView callLocationAndDate;
     32   public final View transcriptionView;
     33   public final TextView voicemailTranscriptionView;
     34   public final TextView voicemailTranscriptionBrandingView;
     35   public final View voicemailTranscriptionRatingView;
     36   public final TextView callAccountLabel;
     37 
     38   private PhoneCallDetailsViews(
     39       TextView nameView,
     40       View callTypeView,
     41       CallTypeIconsView callTypeIcons,
     42       TextView callLocationAndDate,
     43       View transcriptionView,
     44       TextView voicemailTranscriptionView,
     45       TextView voicemailTranscriptionBrandingView,
     46       View voicemailTranscriptionRatingView,
     47       TextView callAccountLabel) {
     48     this.nameView = nameView;
     49     this.callTypeView = callTypeView;
     50     this.callTypeIcons = callTypeIcons;
     51     this.callLocationAndDate = callLocationAndDate;
     52     this.transcriptionView = transcriptionView;
     53     this.voicemailTranscriptionView = voicemailTranscriptionView;
     54     this.voicemailTranscriptionBrandingView = voicemailTranscriptionBrandingView;
     55     this.voicemailTranscriptionRatingView = voicemailTranscriptionRatingView;
     56     this.callAccountLabel = callAccountLabel;
     57   }
     58 
     59   /**
     60    * Create a new instance by extracting the elements from the given view.
     61    *
     62    * <p>The view should contain three text views with identifiers {@code R.id.name}, {@code
     63    * R.id.date}, and {@code R.id.number}, and a linear layout with identifier {@code
     64    * R.id.call_types}.
     65    */
     66   public static PhoneCallDetailsViews fromView(View view) {
     67     return new PhoneCallDetailsViews(
     68         (TextView) view.findViewById(R.id.name),
     69         view.findViewById(R.id.call_type),
     70         (CallTypeIconsView) view.findViewById(R.id.call_type_icons),
     71         (TextView) view.findViewById(R.id.call_location_and_date),
     72         view.findViewById(R.id.transcription),
     73         (TextView) view.findViewById(R.id.voicemail_transcription),
     74         (TextView) view.findViewById(R.id.voicemail_transcription_branding),
     75         view.findViewById(R.id.voicemail_transcription_rating),
     76         (TextView) view.findViewById(R.id.call_account_label));
     77   }
     78 
     79   public static PhoneCallDetailsViews createForTest(Context context) {
     80     return new PhoneCallDetailsViews(
     81         new TextView(context),
     82         new View(context),
     83         new CallTypeIconsView(context),
     84         new TextView(context),
     85         new View(context),
     86         new TextView(context),
     87         new TextView(context),
     88         new View(context),
     89         new TextView(context));
     90   }
     91 }
     92