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.contacts.calllog;
     18 
     19 import android.database.Cursor;
     20 import android.provider.CallLog.Calls;
     21 
     22 /**
     23  * The query for the call log table.
     24  */
     25 public final class CallLogQuery {
     26     // If you alter this, you must also alter the method that inserts a fake row to the headers
     27     // in the CallLogQueryHandler class called createHeaderCursorFor().
     28     public static final String[] _PROJECTION = new String[] {
     29             Calls._ID,                       // 0
     30             Calls.NUMBER,                    // 1
     31             Calls.DATE,                      // 2
     32             Calls.DURATION,                  // 3
     33             Calls.TYPE,                      // 4
     34             Calls.COUNTRY_ISO,               // 5
     35             Calls.VOICEMAIL_URI,             // 6
     36             Calls.GEOCODED_LOCATION,         // 7
     37             Calls.CACHED_NAME,               // 8
     38             Calls.CACHED_NUMBER_TYPE,        // 9
     39             Calls.CACHED_NUMBER_LABEL,       // 10
     40             Calls.CACHED_LOOKUP_URI,         // 11
     41             Calls.CACHED_MATCHED_NUMBER,     // 12
     42             Calls.CACHED_NORMALIZED_NUMBER,  // 13
     43             Calls.CACHED_PHOTO_ID,           // 14
     44             Calls.CACHED_FORMATTED_NUMBER,   // 15
     45             Calls.IS_READ,                   // 16
     46     };
     47 
     48     public static final int ID = 0;
     49     public static final int NUMBER = 1;
     50     public static final int DATE = 2;
     51     public static final int DURATION = 3;
     52     public static final int CALL_TYPE = 4;
     53     public static final int COUNTRY_ISO = 5;
     54     public static final int VOICEMAIL_URI = 6;
     55     public static final int GEOCODED_LOCATION = 7;
     56     public static final int CACHED_NAME = 8;
     57     public static final int CACHED_NUMBER_TYPE = 9;
     58     public static final int CACHED_NUMBER_LABEL = 10;
     59     public static final int CACHED_LOOKUP_URI = 11;
     60     public static final int CACHED_MATCHED_NUMBER = 12;
     61     public static final int CACHED_NORMALIZED_NUMBER = 13;
     62     public static final int CACHED_PHOTO_ID = 14;
     63     public static final int CACHED_FORMATTED_NUMBER = 15;
     64     public static final int IS_READ = 16;
     65     /** The index of the synthetic "section" column in the extended projection. */
     66     public static final int SECTION = 17;
     67 
     68     /**
     69      * The name of the synthetic "section" column.
     70      * <p>
     71      * This column identifies whether a row is a header or an actual item, and whether it is
     72      * part of the new or old calls.
     73      */
     74     public static final String SECTION_NAME = "section";
     75     /** The value of the "section" column for the header of the new section. */
     76     public static final int SECTION_NEW_HEADER = 0;
     77     /** The value of the "section" column for the items of the new section. */
     78     public static final int SECTION_NEW_ITEM = 1;
     79     /** The value of the "section" column for the header of the old section. */
     80     public static final int SECTION_OLD_HEADER = 2;
     81     /** The value of the "section" column for the items of the old section. */
     82     public static final int SECTION_OLD_ITEM = 3;
     83 
     84     /** The call log projection including the section name. */
     85     public static final String[] EXTENDED_PROJECTION;
     86     static {
     87         EXTENDED_PROJECTION = new String[_PROJECTION.length + 1];
     88         System.arraycopy(_PROJECTION, 0, EXTENDED_PROJECTION, 0, _PROJECTION.length);
     89         EXTENDED_PROJECTION[_PROJECTION.length] = SECTION_NAME;
     90     }
     91 
     92     public static boolean isSectionHeader(Cursor cursor) {
     93         int section = cursor.getInt(CallLogQuery.SECTION);
     94         return section == CallLogQuery.SECTION_NEW_HEADER
     95                 || section == CallLogQuery.SECTION_OLD_HEADER;
     96     }
     97 
     98     public static boolean isNewSection(Cursor cursor) {
     99         int section = cursor.getInt(CallLogQuery.SECTION);
    100         return section == CallLogQuery.SECTION_NEW_ITEM
    101                 || section == CallLogQuery.SECTION_NEW_HEADER;
    102     }
    103 }