java类android.provider.CallLog.Calls的实例源码

CallLogListFragment.java 文件源码 项目:CSipSimple 阅读 30 收藏 0 点赞 0 评论 0
private void actionModeDelete() {
    ListView lv = getListView();

    ArrayList<Long> checkedIds = new ArrayList<Long>();

    for(int i = 0; i < lv.getCount(); i++) {
        if(lv.isItemChecked(i)) {
            long[] selectedIds = mAdapter.getCallIdsAtPosition(i);

            for(long id : selectedIds) {
                checkedIds.add(id);
            }

        }
    }
    if(checkedIds.size() > 0) {
        String strCheckedIds = TextUtils.join(", ", checkedIds);
        Log.d(THIS_FILE, "Checked positions ("+ strCheckedIds +")");
        getActivity().getContentResolver().delete(SipManager.CALLLOG_URI, Calls._ID + " IN ("+strCheckedIds+")", null);
        mMode.finish();
    }
}
ContactSelectionRecentFragment.java 文件源码 项目:TextSecure 阅读 20 收藏 0 点赞 0 评论 0
public void set(long id, String name, String label, String number, int type, long date) {
  if( name == null ) {
    name = ContactAccessor.getInstance().getNameForNumber(getActivity(), number);
  }

  this.line1.setText((name == null || name.equals("")) ? number : name);
  this.number.setText((name == null || name.equals("")) ? "" : number);
  this.label.setText(label);
  this.date.setText(DateUtils.getRelativeDateTimeString(context, date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));

  if      (type == Calls.INCOMING_TYPE || type == RedPhoneCallTypes.INCOMING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call));
  else if (type == Calls.OUTGOING_TYPE || type == RedPhoneCallTypes.OUTGOING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call));
  else if (type == Calls.MISSED_TYPE   || type == RedPhoneCallTypes.MISSED)   callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_missed_call));

  this.contactData = new ContactData(id, name);
  this.contactData.numbers.add(new NumberData(null, number));

  if (selectedContacts.containsKey(id))
    this.line1.setChecked(true);
  else
    this.line1.setChecked(false);
}
CallLogAdapter.java 文件源码 项目:Android-2017 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void setViewImage(ImageView view, String value) {
    if (view.getId() == R.id.liCallIcon) {
        switch (Integer.parseInt (value)) {
            case Calls.INCOMING_TYPE :
                view.setImageResource(R.drawable.ic_recived);
                break;
            case Calls.OUTGOING_TYPE :
                view.setImageResource(R.drawable.ic_made);
                break;
            case Calls.MISSED_TYPE :
                view.setImageResource(R.drawable.ic_missed);
                break;
            case Calls.REJECTED_TYPE :
                view.setImageResource(R.drawable.ic_rejected);
                break;
        }
        Log.d("APPTEST", value);
    }
}
Sipdroid.java 文件源码 项目:cInterphone 阅读 17 收藏 0 点赞 0 评论 0
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
    if (getFilterQueryProvider() != null) {
        return new CallsCursor(getFilterQueryProvider().runQuery(constraint));
    }

    StringBuilder buffer;
    String[] args;
    buffer = new StringBuilder();
    buffer.append(Calls.NUMBER);
    buffer.append(" LIKE ? OR ");
    buffer.append(Calls.CACHED_NAME);
    buffer.append(" LIKE ?");
    String arg = "%" + (constraint != null && constraint.length() > 0?
                constraint.toString() : "@") + "%";
    args = new String[] { arg, arg};

    return new CallsCursor(mContent.query(Calls.CONTENT_URI, PROJECTION,
            buffer.toString(), args,
            Calls.NUMBER + " asc"));
}
CInterphone.java 文件源码 项目:cInterphone 阅读 22 收藏 0 点赞 0 评论 0
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
    if (getFilterQueryProvider() != null) {
        return new CallsCursor(getFilterQueryProvider().runQuery(
                constraint));
    }

    StringBuilder buffer;
    String[] args;
    buffer = new StringBuilder();
    buffer.append(Calls.NUMBER);
    buffer.append(" LIKE ? OR ");
    buffer.append(Calls.CACHED_NAME);
    buffer.append(" LIKE ?");
    String arg = "%"
            + (constraint != null && constraint.length() > 0 ? constraint
                    .toString() : "@") + "%";
    args = new String[] { arg, arg };

    return new CallsCursor(mContent.query(Calls.CONTENT_URI,
            PROJECTION, buffer.toString(), args, Calls.NUMBER + " asc"));
}
ContactSelectionRecentFragment.java 文件源码 项目:Securecom-Messaging 阅读 20 收藏 0 点赞 0 评论 0
public void set(long id, String name, String label, String number, int type, long date) {
  if( name == null ) {
    name = ContactAccessor.getInstance().getNameForNumber(getActivity(), number);
  }

  this.line1.setText((name == null || name.equals("")) ? number : name);
  this.number.setText((name == null || name.equals("")) ? "" : number);
  this.label.setText(label);
  this.date.setText(DateUtils.getRelativeDateTimeString(context, date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));

  if      (type == Calls.INCOMING_TYPE || type == RedPhoneCallTypes.INCOMING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call));
  else if (type == Calls.OUTGOING_TYPE || type == RedPhoneCallTypes.OUTGOING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call));
  else if (type == Calls.MISSED_TYPE   || type == RedPhoneCallTypes.MISSED)   callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_missed_call));

  this.contactData = new ContactData(id, name);
  this.contactData.numbers.add(new NumberData(null, number));

  if (selectedContacts.containsKey(id))
    this.line1.setChecked(true);
  else
    this.line1.setChecked(false);
}
ContactSelectionRecentFragment.java 文件源码 项目:Securecom-Text 阅读 22 收藏 0 点赞 0 评论 0
public void set(long id, String name, String label, String number, int type, long date) {
  if( name == null ) {
    name = ContactAccessor.getInstance().getNameForNumber(getActivity(), number);
  }

  this.line1.setText((name == null || name.equals("")) ? number : name);
  this.number.setText((name == null || name.equals("")) ? "" : number);
  this.label.setText(label);
  this.date.setText(DateUtils.getRelativeDateTimeString(context, date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));

  if      (type == Calls.INCOMING_TYPE || type == RedPhoneCallTypes.INCOMING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call));
  else if (type == Calls.OUTGOING_TYPE || type == RedPhoneCallTypes.OUTGOING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call));
  else if (type == Calls.MISSED_TYPE   || type == RedPhoneCallTypes.MISSED)   callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_missed_call));

  this.contactData = new ContactData(id, name);
  this.contactData.numbers.add(new NumberData(null, number));

  if (selectedContacts.containsKey(id))
    this.line1.setChecked(true);
  else
    this.line1.setChecked(false);
}
MissedCallObserver.java 文件源码 项目:DevilTools 阅读 19 收藏 0 点赞 0 评论 0
@Override
 public void onChange(boolean selfChange) {
     Cursor cursor = context.getContentResolver().query(
         Calls.CONTENT_URI, 
         null, 
         Calls.TYPE +  " = ? AND " + Calls.NEW + " = ?", 
         new String[] { Integer.toString(Calls.MISSED_TYPE), "1" }, 
         Calls.DATE + " DESC ");

     int c = cursor.getCount();
     if(c > 0) {
        Log.d(LOG_TAG, "missed call=" + c + " register screen off for activate bln");

         // initialize receiver
         IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         if(screenReceiver == null) {
            screenReceiver = new ScreenReceiver();
         }
         context.registerReceiver(screenReceiver, filter);
     }else {
        Log.d(LOG_TAG, "deactivate bln");
        //set BLN off
SysCommand.getInstance().writeSysfs("/sys/class/misc/backlightnotification/notification_led", "0");
     }
 }
Sipdroid.java 文件源码 项目:phonty 阅读 21 收藏 0 点赞 0 评论 0
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
    if (getFilterQueryProvider() != null) {
        return new CallsCursor(getFilterQueryProvider().runQuery(constraint));
    }

    StringBuilder buffer;
    String[] args;
    buffer = new StringBuilder();
    buffer.append(Calls.NUMBER);
    buffer.append(" LIKE ? OR ");
    buffer.append(Calls.CACHED_NAME);
    buffer.append(" LIKE ?");
    String arg = "%" + (constraint != null && constraint.length() > 0?
                constraint.toString() : "@") + "%";
    args = new String[] { arg, arg};

    return new CallsCursor(mContent.query(Calls.CONTENT_URI, PROJECTION,
            buffer.toString(), args,
            Calls.NUMBER + " asc"));
}
LauncherMonitor.java 文件源码 项目:fruit.launcher 阅读 18 收藏 0 点赞 0 评论 0
private static int queryMissCallCount(Context context) {
    int count = 0;

    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(Calls.CONTENT_URI,
                null, "type=3 and new=1", null, null);
    } catch (IllegalStateException e) {
        System.gc();
    }
    if (cursor != null) {
        count = cursor.getCount();
        cursor.close();
    }
    Log.d(TAG, "getMissCallCount count=" + count);
    return count;
}
LogRunnerService.java 文件源码 项目:callmeter 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Check, if there is dual sim support.
 */
public static boolean checkCallsSimIdColumn(final ContentResolver cr) {
    try {
        String where = BuildConfig.DEBUG_LOG ? null : "1=2";
        Cursor c = cr.query(Calls.CONTENT_URI, null, where, null, null);
        boolean check = false;
        if (c != null) {
            check = SimIdColumnFinder.getsInstance().getSimIdColumn(cr, Calls.CONTENT_URI, c) >= 0;
            c.close();
        }
        Log.i(TAG, "sim_id column found in calls database: " + check);
        return check;
    } catch (SQLiteException e) {
        Log.w(TAG, "sim_id check for calls failed", e);
        return false;
    }
}
CallLogListFragment.java 文件源码 项目:CSipSimple 阅读 28 收藏 0 点赞 0 评论 0
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

        return new CursorLoader(getActivity(), SipManager.CALLLOG_URI, new String[] {
                Calls._ID, Calls.CACHED_NAME, Calls.CACHED_NUMBER_LABEL,
                Calls.CACHED_NUMBER_TYPE, Calls.DURATION, Calls.DATE,
                Calls.NEW, Calls.NUMBER, Calls.TYPE,
                SipManager.CALLLOG_PROFILE_ID_FIELD
        },
                null, null,
                Calls.DEFAULT_SORT_ORDER);
    }
CallLogDetailsFragment.java 文件源码 项目:CSipSimple 阅读 19 收藏 0 点赞 0 评论 0
public void onMenuRemoveFromCallLog(MenuItem menuItem) {
    final StringBuilder callIds = new StringBuilder();
    for (Uri callUri : getCallLogEntryUris()) {
        if (callIds.length() != 0) {
            callIds.append(",");
        }
        callIds.append(ContentUris.parseId(callUri));
    }

    getActivity().getContentResolver().delete(SipManager.CALLLOG_URI,
            Calls._ID + " IN (" + callIds + ")", null);
    if (quitListener != null) {
        quitListener.onQuit();
    }
}
CallTypeIconsView.java 文件源码 项目:CSipSimple 阅读 19 收藏 0 点赞 0 评论 0
private Drawable getCallTypeDrawable(int callType) {
    switch (callType) {
        case Calls.INCOMING_TYPE:
            return mResources.incoming;
        case Calls.OUTGOING_TYPE:
            return mResources.outgoing;
        case Calls.MISSED_TYPE:
            return mResources.missed;
        default:
            throw new IllegalArgumentException("invalid call type: " + callType);
    }
}
CallDetailHistoryAdapter.java 文件源码 项目:CSipSimple 阅读 20 收藏 0 点赞 0 评论 0
private int getCallTypeText(int callType) {
    switch (callType) {
        case Calls.INCOMING_TYPE:
            return R.string.type_incoming;
        case Calls.OUTGOING_TYPE:
            return R.string.type_outgoing;
        case Calls.MISSED_TYPE:
            return R.string.type_missed;
        default:
            throw new IllegalArgumentException("invalid call type: " + callType);
    }
}
MainActivity.java 文件源码 项目:Android-2017 阅读 21 收藏 0 点赞 0 评论 0
private Cursor getCalls (int type) {
    Uri llamadasUri = CallLog.Calls.CONTENT_URI;
    ContentResolver contentResolver = getContentResolver();

    String [] projection = new String [] {Calls._ID, Calls.NUMBER, Calls.DURATION, Calls.TYPE};

    String selection = null;
    String [] selectionArgs = null;

    if (type == Calls.INCOMING_TYPE || type == Calls.OUTGOING_TYPE || type == Calls.MISSED_TYPE || type == Calls.REJECTED_TYPE ) {
        selection = Calls.TYPE + " = ? ";
        selectionArgs = new String [] {Integer.toString(type)};
    }

    String order = Calls.DATE + " DESC ";

    // verificar permisos de llamada
    int permissionCheck = ContextCompat.checkSelfPermission (this, Manifest.permission.READ_CALL_LOG);

    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        cursor = contentResolver.query(llamadasUri,   // URI del Content provider
                projection,    // Columnas a devolver
                selection,     // Condición a la query
                selectionArgs, // Argumentos variables de la condición
                order);         // Orden de los resultados
    }

    return cursor;

}
ContactsAccessHelper.java 文件源码 项目:BlackList 阅读 43 收藏 0 点赞 0 评论 0
private ContactFromCallsCursorWrapper(Cursor cursor) {
    super(cursor);
    cursor.moveToFirst();
    ID = cursor.getColumnIndex(Calls._ID);
    NUMBER = cursor.getColumnIndex(Calls.NUMBER);
    NAME = cursor.getColumnIndex(Calls.CACHED_NAME);
}
PhoneStateChangedReceiver.java 文件源码 项目:TaskApp 阅读 19 收藏 0 点赞 0 评论 0
private Cursor getMissedCalls(Context context) {
    if (permissionChecker.canAccessMissedCallPermissions()) {
        //noinspection MissingPermission
        return context.getContentResolver().query(
                Calls.CONTENT_URI,
                new String[]{Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME},
                Calls.TYPE + " = ? AND " + Calls.NEW + " = ?",
                new String[]{Integer.toString(Calls.MISSED_TYPE), "1"},
                Calls.DATE + " DESC"
        );
    }
    return null;
}
ContactSelectionRecentFragment.java 文件源码 项目:TextSecure 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void bindView(View view, Context context, Cursor cursor) {
  long id       = cursor.getLong(cursor.getColumnIndexOrThrow(Calls._ID));
  String name   = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NAME));
  String label  = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NUMBER_LABEL));
  String number = cursor.getString(cursor.getColumnIndexOrThrow(Calls.NUMBER));
  int type      = cursor.getInt(cursor.getColumnIndexOrThrow(Calls.TYPE));
  long date     = cursor.getLong(cursor.getColumnIndexOrThrow(Calls.DATE));

  ((CallItemView)view).set(id, name, label, number, type, date);
}
Sipdroid.java 文件源码 项目:cInterphone 阅读 19 收藏 0 点赞 0 评论 0
@Override
public void onStart() {
    super.onStart();
    Receiver.engine(this).registerMore();
    ContentResolver content = getContentResolver();
    Cursor cursor = content.query(Calls.CONTENT_URI,
            PROJECTION, Calls.NUMBER+" like ?", new String[] { "%@%" }, Calls.DEFAULT_SORT_ORDER);
    CallsAdapter adapter = new CallsAdapter(this, cursor);
    sip_uri_box.setAdapter(adapter);
    sip_uri_box2.setAdapter(adapter);
}
Connection.java 文件源码 项目:cInterphone 阅读 30 收藏 0 点赞 0 评论 0
public void log(long start)
{
    String number = getAddress();
       long duration = (start != 0 ? SystemClock.elapsedRealtime()-start : 0);
    boolean isPrivateNumber = false; // TODO: need API for isPrivate()

    // Set the "type" to be displayed in the call log (see constants in CallLog.Calls)
    int callLogType;
    if (isIncoming()) {
        callLogType = (duration == 0 ?
                       CallLog.Calls.MISSED_TYPE :
                       CallLog.Calls.INCOMING_TYPE);
    } else {
        callLogType = CallLog.Calls.OUTGOING_TYPE;
    }

    // get the callerinfo object and then log the call with it.
    {
        Object o = getUserData();
        CallerInfo ci;
        if ((o == null) || (o instanceof CallerInfo)){
            ci = (CallerInfo) o;
        } else {
            ci = ((PhoneUtils.CallerInfoToken) o).currentInfo;
        }
        if (callLogType == CallLog.Calls.MISSED_TYPE)
            Receiver.onText(Receiver.MISSED_CALL_NOTIFICATION, ci != null && ci.name != null?ci.name:number, android.R.drawable.stat_notify_missed_call, 0);
        addCall(ci, Receiver.mContext, number, isPrivateNumber,
                callLogType, date, (int) duration / 1000);
    }
}
ContactSelectionRecentFragment.java 文件源码 项目:Securecom-Messaging 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void bindView(View view, Context context, Cursor cursor) {
  long id       = cursor.getLong(cursor.getColumnIndexOrThrow(Calls._ID));
  String name   = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NAME));
  String label  = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NUMBER_LABEL));
  String number = cursor.getString(cursor.getColumnIndexOrThrow(Calls.NUMBER));
  int type      = cursor.getInt(cursor.getColumnIndexOrThrow(Calls.TYPE));
  long date     = cursor.getLong(cursor.getColumnIndexOrThrow(Calls.DATE));

  ((CallItemView)view).set(id, name, label, number, type, date);
}
ContactSelectionRecentFragment.java 文件源码 项目:Securecom-Text 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void bindView(View view, Context context, Cursor cursor) {
  long id       = cursor.getLong(cursor.getColumnIndexOrThrow(Calls._ID));
  String name   = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NAME));
  String label  = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NUMBER_LABEL));
  String number = cursor.getString(cursor.getColumnIndexOrThrow(Calls.NUMBER));
  int type      = cursor.getInt(cursor.getColumnIndexOrThrow(Calls.TYPE));
  long date     = cursor.getLong(cursor.getColumnIndexOrThrow(Calls.DATE));

  ((CallItemView)view).set(id, name, label, number, type, date);
}
CallTypeIconsView.java 文件源码 项目:silent-contacts-android 阅读 19 收藏 0 点赞 0 评论 0
private Drawable getCallTypeDrawable(int callType) {
    switch (callType) {
        case Calls.INCOMING_TYPE:
            return mResources.incoming;
        case Calls.OUTGOING_TYPE:
            return mResources.outgoing;
        case Calls.MISSED_TYPE:
            return mResources.missed;
        default:
            throw new IllegalArgumentException("invalid call type: " + callType);
    }
}
Sipdroid.java 文件源码 项目:phonty 阅读 20 收藏 0 点赞 0 评论 0
@Override
public void onStart() {
    super.onStart();
    Receiver.engine(this).registerMore();
    ContentResolver content = getContentResolver();
    Cursor cursor = content.query(Calls.CONTENT_URI,
            PROJECTION, Calls.NUMBER+" like ?", new String[] { "%@%" }, Calls.DEFAULT_SORT_ORDER);
    CallsAdapter adapter = new CallsAdapter(this, cursor);
    sip_uri_box.setAdapter(adapter);
    sip_uri_box2.setAdapter(adapter);
}
Connection.java 文件源码 项目:phonty 阅读 34 收藏 0 点赞 0 评论 0
public void log(long start)
{
    String number = getAddress();
       long duration = (start != 0 ? SystemClock.elapsedRealtime()-start : 0);
    boolean isPrivateNumber = false; // TODO: need API for isPrivate()

    // Set the "type" to be displayed in the call log (see constants in CallLog.Calls)
    int callLogType;
    if (isIncoming()) {
        callLogType = (duration == 0 ?
                       CallLog.Calls.MISSED_TYPE :
                       CallLog.Calls.INCOMING_TYPE);
    } else {
        callLogType = CallLog.Calls.OUTGOING_TYPE;
    }

    // get the callerinfo object and then log the call with it.
    {
        Object o = getUserData();
        CallerInfo ci;
        if ((o == null) || (o instanceof CallerInfo)){
            ci = (CallerInfo) o;
        } else {
            ci = ((PhoneUtils.CallerInfoToken) o).currentInfo;
        }
        if (callLogType == CallLog.Calls.MISSED_TYPE)
            Receiver.onText(Receiver.MISSED_CALL_NOTIFICATION, ci != null && ci.name != null?ci.name:number, android.R.drawable.stat_notify_missed_call, 0);
        addCall(ci, Receiver.mContext, number, isPrivateNumber,
                callLogType, date, (int) duration / 1000);
    }
}
LauncherMonitor.java 文件源码 项目:fruit.launcher 阅读 19 收藏 0 点赞 0 评论 0
private Uri getMoinitorUri(int type) {
    switch (type) {
    case MONITOR_PHONE:
        return Calls.CONTENT_URI;
    case MONITOR_MESSAGE:
        return Telephony.MmsSms.CONTENT_URI;
    case MONITOR_UPDATE:
        return null; // update uri
    default:
        break;
    }

    return null;
}
CallLogProbe.java 文件源码 项目:funf-v4 阅读 19 收藏 0 点赞 0 评论 0
@Override
protected Map<String,CursorCell<?>> getProjectionMap() {
    Map<String,CursorCell<?>> projectionKeyToType = new HashMap<String, CursorCell<?>>();
    projectionKeyToType.put(Calls._ID, intCell());
    projectionKeyToType.put(Calls.NUMBER, new SensitiveCell(new PhoneNumberCell()));
    projectionKeyToType.put(Calls.DATE, longCell());
    projectionKeyToType.put(Calls.TYPE, intCell());
    projectionKeyToType.put(Calls.DURATION, longCell());
    projectionKeyToType.put(Calls.CACHED_NAME, sensitiveStringCell());
    projectionKeyToType.put(Calls.CACHED_NUMBER_LABEL, sensitiveStringCell());
    projectionKeyToType.put(Calls.CACHED_NUMBER_TYPE, sensitiveStringCell());
    return projectionKeyToType;
}
CallLogGroupBuilder.java 文件源码 项目:CSipSimple 阅读 59 收藏 0 点赞 0 评论 0
/**
 * Finds all groups of adjacent entries in the call log which should be grouped together and
 * calls {@link CallLogListFragment.GroupCreator#addGroup(int, int, boolean)} on
 * {@link #mGroupCreator} for each of them.
 * <p>
 * For entries that are not grouped with others, we do not need to create a group of size one.
 * <p>
 * It assumes that the cursor will not change during its execution.
 *
 * @see GroupingListAdapter#addGroups(Cursor)
 */
public void addGroups(Cursor cursor) {
    final int count = cursor.getCount();
    if (count == 0) {
        return;
    }
    int numberColIndex = cursor.getColumnIndex(Calls.NUMBER);
    int typeColIndex = cursor.getColumnIndex(Calls.TYPE);

    int currentGroupSize = 1;
    cursor.moveToFirst();
    // The number of the first entry in the group.
    String firstNumber = cursor.getString(numberColIndex);
    // This is the type of the first call in the group.
    int firstCallType = cursor.getInt(typeColIndex);
    while (cursor.moveToNext()) {
        // The number of the current row in the cursor.
        final String currentNumber = cursor.getString(numberColIndex);
        final int callType = cursor.getInt(typeColIndex);
        final boolean sameNumber = equalNumbers(firstNumber, currentNumber);
        final boolean shouldGroup;

        if (!sameNumber) {
            // Should only group with calls from the same number.
            shouldGroup = false;
        } else if ( firstCallType == Calls.MISSED_TYPE) {
            // Voicemail and missed calls should only be grouped with subsequent missed calls.
            shouldGroup = callType == Calls.MISSED_TYPE;
        } else {
            // Incoming and outgoing calls group together.
            shouldGroup = callType == Calls.INCOMING_TYPE || callType == Calls.OUTGOING_TYPE;
        }

        if (shouldGroup) {
            // Increment the size of the group to include the current call, but do not create
            // the group until we find a call that does not match.
            currentGroupSize++;
        } else {
            // Create a group for the previous set of calls, excluding the current one, but do
            // not create a group for a single call.
            if (currentGroupSize > 1) {
                addGroup(cursor.getPosition() - currentGroupSize, currentGroupSize);
            }
            // Start a new group; it will include at least the current call.
            currentGroupSize = 1;
            // The current entry is now the first in the group.
            firstNumber = currentNumber;
            firstCallType = callType;
        }
    }
    // If the last set of calls at the end of the call log was itself a group, create it now.
    if (currentGroupSize > 1) {
        addGroup(count - currentGroupSize, currentGroupSize);
    }
}
CallDetailHistoryAdapter.java 文件源码 项目:CSipSimple 阅读 20 收藏 0 点赞 0 评论 0
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    // Make sure we have a valid convertView to start with
    final View result  = convertView == null
            ? mLayoutInflater.inflate(R.layout.call_detail_history_item, parent, false)
            : convertView;

    PhoneCallDetails details = (PhoneCallDetails) getItem(position);
    CallTypeIconsView callTypeIconView =
            (CallTypeIconsView) result.findViewById(R.id.call_type_icon);
    TextView callTypeTextView = (TextView) result.findViewById(R.id.call_type_text);
    TextView dateView = (TextView) result.findViewById(R.id.date);
    TextView durationView = (TextView) result.findViewById(R.id.duration);

    int callType = details.callTypes[0];
    callTypeIconView.clear();
    callTypeIconView.add(callType);

    StringBuilder typeSb = new StringBuilder();
    typeSb.append(mContext.getResources().getString(getCallTypeText(callType)));
    // If not 200, we add text for user feedback about what went wrong
    if(details.statusCode != 200) {
        typeSb.append(" - ");
        typeSb.append(details.statusCode);
        if(!TextUtils.isEmpty(details.statusText)) {
            typeSb.append(" / ");
            typeSb.append(details.statusText);
        }
    }
    callTypeTextView.setText(typeSb.toString());

    // Set the date.
    CharSequence dateValue = DateUtils.formatDateRange(mContext, details.date, details.date,
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE |
            DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR);
    dateView.setText(dateValue);
    // Set the duration
    if (callType == Calls.MISSED_TYPE) {
        durationView.setVisibility(View.GONE);
    } else {
        durationView.setVisibility(View.VISIBLE);
        durationView.setText(formatDuration(details.duration));
    }

    return result;
}


问题


面经


文章

微信
公众号

扫码关注公众号