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.calllog;
     18 
     19 import android.content.res.Resources;
     20 import android.provider.CallLog.Calls;
     21 
     22 import com.android.dialer.R;
     23 
     24 /**
     25  * Helper class to perform operations related to call types.
     26  */
     27 public class CallTypeHelper {
     28     /** Name used to identify incoming calls. */
     29     private final CharSequence mIncomingName;
     30     /** Name used to identify outgoing calls. */
     31     private final CharSequence mOutgoingName;
     32     /** Name used to identify missed calls. */
     33     private final CharSequence mMissedName;
     34     /** Name used to identify voicemail calls. */
     35     private final CharSequence mVoicemailName;
     36     /** Color used to identify new missed calls. */
     37     private final int mNewMissedColor;
     38     /** Color used to identify new voicemail calls. */
     39     private final int mNewVoicemailColor;
     40 
     41     public CallTypeHelper(Resources resources) {
     42         // Cache these values so that we do not need to look them up each time.
     43         mIncomingName = resources.getString(R.string.type_incoming);
     44         mOutgoingName = resources.getString(R.string.type_outgoing);
     45         mMissedName = resources.getString(R.string.type_missed);
     46         mVoicemailName = resources.getString(R.string.type_voicemail);
     47         mNewMissedColor = resources.getColor(R.color.call_log_missed_call_highlight_color);
     48         mNewVoicemailColor = resources.getColor(R.color.call_log_voicemail_highlight_color);
     49     }
     50 
     51     /** Returns the text used to represent the given call type. */
     52     public CharSequence getCallTypeText(int callType) {
     53         switch (callType) {
     54             case Calls.INCOMING_TYPE:
     55                 return mIncomingName;
     56 
     57             case Calls.OUTGOING_TYPE:
     58                 return mOutgoingName;
     59 
     60             case Calls.MISSED_TYPE:
     61                 return mMissedName;
     62 
     63             case Calls.VOICEMAIL_TYPE:
     64                 return mVoicemailName;
     65 
     66             default:
     67                 return mMissedName;
     68         }
     69     }
     70 
     71     /** Returns the color used to highlight the given call type, null if not highlight is needed. */
     72     public Integer getHighlightedColor(int callType) {
     73         switch (callType) {
     74             case Calls.INCOMING_TYPE:
     75                 // New incoming calls are not highlighted.
     76                 return null;
     77 
     78             case Calls.OUTGOING_TYPE:
     79                 // New outgoing calls are not highlighted.
     80                 return null;
     81 
     82             case Calls.MISSED_TYPE:
     83                 return mNewMissedColor;
     84 
     85             case Calls.VOICEMAIL_TYPE:
     86                 return mNewVoicemailColor;
     87 
     88             default:
     89                 // Don't highlight calls of unknown types. They are treated as missed calls by
     90                 // the rest of the UI, but since they will never be marked as read by
     91                 // {@link CallLogQueryHandler}, just don't ever highlight them anyway.
     92                 return null;
     93         }
     94     }
     95 
     96     public static boolean isMissedCallType(int callType) {
     97         return (callType != Calls.INCOMING_TYPE && callType != Calls.OUTGOING_TYPE &&
     98                 callType != Calls.VOICEMAIL_TYPE);
     99     }
    100 }
    101