Home | History | Annotate | Download | only in calllogutils
      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.calllogutils;
     18 
     19 import android.content.res.Resources;
     20 import com.android.dialer.compat.AppCompatConstants;
     21 
     22 /** Helper class to perform operations related to call types. */
     23 public class CallTypeHelper {
     24 
     25   /** Name used to identify incoming calls. */
     26   private final CharSequence mIncomingName;
     27   /** Name used to identify incoming calls which were transferred to another device. */
     28   private final CharSequence mIncomingPulledName;
     29   /** Name used to identify outgoing calls. */
     30   private final CharSequence mOutgoingName;
     31   /** Name used to identify outgoing calls which were transferred to another device. */
     32   private final CharSequence mOutgoingPulledName;
     33   /** Name used to identify missed calls. */
     34   private final CharSequence mMissedName;
     35   /** Name used to identify incoming video calls. */
     36   private final CharSequence mIncomingVideoName;
     37   /** Name used to identify incoming video calls which were transferred to another device. */
     38   private final CharSequence mIncomingVideoPulledName;
     39   /** Name used to identify outgoing video calls. */
     40   private final CharSequence mOutgoingVideoName;
     41   /** Name used to identify outgoing video calls which were transferred to another device. */
     42   private final CharSequence mOutgoingVideoPulledName;
     43   /** Name used to identify missed video calls. */
     44   private final CharSequence mMissedVideoName;
     45   /** Name used to identify voicemail calls. */
     46   private final CharSequence mVoicemailName;
     47   /** Name used to identify rejected calls. */
     48   private final CharSequence mRejectedName;
     49   /** Name used to identify blocked calls. */
     50   private final CharSequence mBlockedName;
     51   /** Name used to identify calls which were answered on another device. */
     52   private final CharSequence mAnsweredElsewhereName;
     53 
     54   public CallTypeHelper(Resources resources) {
     55     // Cache these values so that we do not need to look them up each time.
     56     mIncomingName = resources.getString(R.string.type_incoming);
     57     mIncomingPulledName = resources.getString(R.string.type_incoming_pulled);
     58     mOutgoingName = resources.getString(R.string.type_outgoing);
     59     mOutgoingPulledName = resources.getString(R.string.type_outgoing_pulled);
     60     mMissedName = resources.getString(R.string.type_missed);
     61     mIncomingVideoName = resources.getString(R.string.type_incoming_video);
     62     mIncomingVideoPulledName = resources.getString(R.string.type_incoming_video_pulled);
     63     mOutgoingVideoName = resources.getString(R.string.type_outgoing_video);
     64     mOutgoingVideoPulledName = resources.getString(R.string.type_outgoing_video_pulled);
     65     mMissedVideoName = resources.getString(R.string.type_missed_video);
     66     mVoicemailName = resources.getString(R.string.type_voicemail);
     67     mRejectedName = resources.getString(R.string.type_rejected);
     68     mBlockedName = resources.getString(R.string.type_blocked);
     69     mAnsweredElsewhereName = resources.getString(R.string.type_answered_elsewhere);
     70   }
     71 
     72   public static boolean isMissedCallType(int callType) {
     73     return (callType != AppCompatConstants.CALLS_INCOMING_TYPE
     74         && callType != AppCompatConstants.CALLS_OUTGOING_TYPE
     75         && callType != AppCompatConstants.CALLS_VOICEMAIL_TYPE
     76         && callType != AppCompatConstants.CALLS_ANSWERED_EXTERNALLY_TYPE);
     77   }
     78 
     79   /** Returns the text used to represent the given call type. */
     80   public CharSequence getCallTypeText(int callType, boolean isVideoCall, boolean isPulledCall) {
     81     switch (callType) {
     82       case AppCompatConstants.CALLS_INCOMING_TYPE:
     83         if (isVideoCall) {
     84           if (isPulledCall) {
     85             return mIncomingVideoPulledName;
     86           } else {
     87             return mIncomingVideoName;
     88           }
     89         } else {
     90           if (isPulledCall) {
     91             return mIncomingPulledName;
     92           } else {
     93             return mIncomingName;
     94           }
     95         }
     96 
     97       case AppCompatConstants.CALLS_OUTGOING_TYPE:
     98         if (isVideoCall) {
     99           if (isPulledCall) {
    100             return mOutgoingVideoPulledName;
    101           } else {
    102             return mOutgoingVideoName;
    103           }
    104         } else {
    105           if (isPulledCall) {
    106             return mOutgoingPulledName;
    107           } else {
    108             return mOutgoingName;
    109           }
    110         }
    111 
    112       case AppCompatConstants.CALLS_MISSED_TYPE:
    113         if (isVideoCall) {
    114           return mMissedVideoName;
    115         } else {
    116           return mMissedName;
    117         }
    118 
    119       case AppCompatConstants.CALLS_VOICEMAIL_TYPE:
    120         return mVoicemailName;
    121 
    122       case AppCompatConstants.CALLS_REJECTED_TYPE:
    123         return mRejectedName;
    124 
    125       case AppCompatConstants.CALLS_BLOCKED_TYPE:
    126         return mBlockedName;
    127 
    128       case AppCompatConstants.CALLS_ANSWERED_EXTERNALLY_TYPE:
    129         return mAnsweredElsewhereName;
    130 
    131       default:
    132         return mMissedName;
    133     }
    134   }
    135 }
    136