如何像其他应用一样更快地加载呼叫日志并显示为附件图像 [英] How to load call logs faster like other apps and display like attached image

查看:137
本文介绍了如何像其他应用一样更快地加载呼叫日志并显示为附件图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下查询加载的通话记录为从设备上获得的当前月份,对我来说,加载完成并存储到 sq-lite 中需要花费 2.5到3.5 秒数据库

The Following query load call logs of current month from the device, for me, it's taking 2.5 to 3.5 seconds to load complete and store into sq-lite database


CallLogHelper类

CallLogHelper Class



      public static Cursor getAllCallLogs(ContentResolver cr) {
          String[] PROJECTION = new String[]{
            CallLog.Calls.NUMBER,
            CallLog.Calls._ID,
            CallLog.Calls.CACHED_NAME,
            CallLog.Calls.DATE,
            CallLog.Calls.TYPE,
            CallLog.Calls.DURATION};
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -1);
    Date weekBefore = calendar.getTime();
    String strClause = CallLog.Calls.DATE + " >= ?";
    String[] strValues = {String.valueOf(weekBefore.getTime())};
    String strOrder = CallLog.Calls.DATE + " DESC limit 500";
    Cursor curCalls = cr.query(CallLog.Calls.CONTENT_URI, PROJECTION, strClause,
            strValues, strOrder);
    return curCalls;  }




CallLogLoaderServicel类
在这里,我在进行一些数据库操作使用调用日志,执行代码需要花费7 s的时间,其中<​​code> PHOTO_URI 是从另一个游标加载的,而没有 PHOTO_URI 花费2/3秒,但仍然花费2/3秒及更多。

CallLogLoaderServicel class Here I am making some database operations with call logs, for the execution of code it's taking 7 s with PHOTO_URI which is loading from another cursor and without PHOTO_URI taking 2/3 seconds but still it taking 2/3 seconds and its more.

club_id 是常见的 id 用于在 club_id 的帮助下针对特定号码进行的连续通话正在使用分组日志及其 ID DB 中删除以及设备

club_id is a common id for the sequential call made for particular number with the help of club_id I am making count while deleting on long-press I am taking grouped logs and its ID to delete from DB as well as from device.



private void setCallLogs(Cursor curLog) {
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE);
    logsqLiteDatabase.beginTransaction();
    for (curLog.moveToLast(); !curLog.isBeforeFirst(); curLog.moveToPrevious()) {
        String callNumber = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls.NUMBER));
        callNumber = Utilities.correctNumber(callNumber);
        String ids = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls._ID));

        String name = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls.CACHED_NAME));

        String callname = "Unknown";
        try {
            if (name != null)
                callname = name;

        } catch (Exception e) {
            e.printStackTrace();
        }


        String callType = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls.TYPE));

        String duration = "";

        ***//with pic 7 second
        //withought pic uri 5/6 second***

        String photoUri = "";
      /*  if (callNumber != null) {
            photoUri = Utilities_dialer.getContactPhoto(this, callNumber);
        }*/

        String dateString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
                .format(new Date(Long
                        .parseLong(curLog.getString(curLog.getColumnIndex(CallLog.Calls.DATE)))));

        if (log_db_Handler.getLogCount() == 0) {
            log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
                    , duration, String.valueOf(count), todayis, "1");

        } else {
            Cursor readContact = log_db_Handler.readLastCallLogs();
         //   if (readContact.moveToLast()) {
                String phone = readContact.getString(readContact.getColumnIndex(DatabaseHandler.KEY_PH_NO));

                if (phone.equals(callNumber.replace(" ", ""))) {
                    String type = readContact.getString(readContact.getColumnIndex(DatabaseHandler.KEY_TYPE));

                    club_id = readContact.getString(readContact.getColumnIndex(DialerDatabaseHandler.KEY_CLUB_ID));
                    int c_id = Integer.parseInt(club_id);
                    if (type.equals(callType)) {

                        log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
                                , duration, String.valueOf(count), todayis, String.valueOf(c_id));

                    } else {

                        if (type.equals("3") && (callType.equals("10") || callType.equals("2") || callType.equals("1"))) {

                            c_id = c_id + 1;

                            log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
                                    , duration, String.valueOf(count), todayis, String.valueOf(c_id));

                        } else if ((type.equals("10") || type.equals("2") || type.equals("1")) && callType.equals("3")) {

                            c_id = c_id + 1;

                            log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
                                    , duration, String.valueOf(count), todayis, String.valueOf(c_id));

                        } else {


                            log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
                                    , duration, String.valueOf(count), todayis, String.valueOf(c_id));

                        }
                    }

                } else {
                    club_id = readContact.getString(readContact.getColumnIndex(DialerDatabaseHandler.KEY_CLUB_ID));
                    int c_id = Integer.parseInt(club_id);
                    c_id = c_id + 1;
                    log_db_Handler.addDialerLog(callname, callNumber, callType, ids, photoUri, dateString
                            , duration, String.valueOf(count), todayis, String.valueOf(c_id));

                }
           // }
            readContact.close();

        }
    }
    logsqLiteDatabase.setTransactionSuccessful();
    logsqLiteDatabase.endTransaction();
    curLog.close();
    endTime = System.currentTimeMillis();
    long MethodeDuration = (endTime - startTime);
    Log.e("MethodeDuration", "-log-" + MethodeDuration);

    Intent intent = new Intent("log_updated");
    sendBroadcast(intent);
    smartCallPreference.setLogFirstTime("1");
}


推荐答案

我尝试过不使用数据


但它在呼叫日志的名称和照片uri上存在问题因为更改任何联系人后,缓存的数据可能不可用或无法更新。是他们的任何其他处理方式。

But I have issue with Name and photo uri of call log because Cached data may not be available or may not be updated after any contact changed. Is their any Other way to deal with it.



 private void setCallLogs(Cursor curLog) {
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE);
    int sr_id = 0;
    while (curLog.moveToNext()) {
        String callNumber = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls.NUMBER));
        callNumber = Utilities.correctNumber(callNumber);
        String ids = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls._ID));

        String name = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls.CACHED_NAME));

        String callname = "Unknown";
        String photoUri = "";
        if (name != null)
            callname = name;


        String callType = curLog.getString(curLog
                .getColumnIndex(CallLog.Calls.TYPE));

        String dateString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
                .format(new Date(Long
                        .parseLong(curLog.getString(curLog.getColumnIndex(CallLog.Calls.DATE)))));
        //dateString = CallHistoryFragment.setdateToLog(dateString);

        sr_id = sr_id + 1;
        if (mainDialerhistory.size() == 0) {

            club_id = 1;
            count = 1;

            mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
                    callType, "", "", count, photoUri, String.valueOf(club_id)));

        } else {
            count = 0;
            int mainArraySize = mainDialerhistory.size() - 1;
            if (mainDialerhistory.get(mainArraySize).getPhone().equals(callNumber.replace(" ", ""))) {

                if (mainDialerhistory.get(mainArraySize).getcallType().equals(callType)) {
                    count = mainDialerhistory.get(mainArraySize).getCount() + 1;
                    club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id());

                    mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
                            callType, "", "", count, photoUri, String.valueOf(club_id)));

                } else {
                    String lastType = mainDialerhistory.get(mainArraySize).getcallType();

                    if (lastType.equals("3") && (callType.equals("10") || callType.equals("2") || callType.equals("1"))) {
                        count = 0;
                        club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id()) + 1;

                        mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
                                callType, "", "", 1, photoUri, String.valueOf(club_id)));

                    } else if ((lastType.equals("10") || lastType.equals("2") || lastType.equals("1")) && callType.equals("3")) {
                        club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id()) + 1;

                        mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
                                callType, "", "", count + 1, photoUri, String.valueOf(club_id)));

                    } else {
                        count = 0;
                        count = mainDialerhistory.get(mainArraySize).getCount() + 1;
                        club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id());

                        mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
                                callType, "", "", count, photoUri, String.valueOf(club_id)));

                    }
                }
            } else {
                club_id = Integer.parseInt(mainDialerhistory.get(mainArraySize).getGr_id()) + 1;
                mainDialerhistory.add(new HistoryController(ids, String.valueOf(sr_id), callname, callNumber.replace(" ", ""), dateString,
                        callType, "", "", 1, photoUri, String.valueOf(club_id)));

            }
        }

    }
    curLog.close();
    endTime = System.currentTimeMillis();
    long MethodeDuration = (endTime - startTime);
    Log.e("MethodeDuration", "-count-" + mainDialerhistory.size());
    Log.e("MethodeDuration", "-log-" + MethodeDuration);
    AccountController.getInstance().mAccountHistory.addAll(mainDialerhistory);

    sendBroadcast(new Intent("log_updated"));


    stopService(new Intent(this, CallLogIntentService.class));
}

这篇关于如何像其他应用一样更快地加载呼叫日志并显示为附件图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆