zoukankan      html  css  js  c++  java
  • Android系统应用Mms之短信会话列表加载流程一

    1. ConversationList短息会话列表界面
    1. 开始进行加载
    ConversationList: 
    protected void onStart(){
        ...
        // 进行异步查询
        startAsyncQuery();
    }
    
    private void startAsyncQuery() {
        ...
        // 加载消息
        mLoaderFragment.reLoadMessage(THREAD_LIST_QUERY_TOKEN, // token: 1701
                                      Conversation.sAllThreadsUri,// 查询的Uri: content://mms-sms/conversations&simple=true
                                      Conversation.ALL_THREADS_PROJECTION,// 查询的字段
                                      null, null, 
                                      Conversations.DEFAULT_SORT_ORDER);
        ...
    }
    
    2. 进入到MessageLoaderFragment, 进行加载
    MessageLoaderFragment:
    public void reLoadMessage(int loadId, Uri uri, String[] projection,
                String selection, String[] selectionArgs, String orderBy) {
        ...
        // 进行异步加载
        getLoaderManager().restartLoader(loadId, null, mMessageLoaderListener);        
    }
    
    3. 进入到MmsSmsProvider中执行查询流程
    MmsSmsProvider:
    public Cursor query(Uri uri, String[] projection,
                String selection, String[] selectionArgs, String sortOrder) {
        ...
        switch(URI_MATCHER.match(uri)) {
            ...
            case URI_CONVERSATIONS:
                String simple = uri.getQueryParameter("simple");
                if ((simple != null) && simple.equals("true")) {
                    String threadType = uri.getQueryParameter("thread_type"); // 获取会话类型
                    if (!TextUtils.isEmpty(threadType)) {
                        selection = concatSelections(selection, Threads.TYPE + "=" + threadType);
                    }
                    // 获取简单会话
                    cursor = getSimpleConversations(projection, selection, selectionArgs, sortOrder);
                } else {
                    cursor = getConversations(projection, selection, sortOrder);
                }
                break;        
            ...
        }
        ...
        return cursor;    
    }
    
    private Cursor getSimpleConversations(String[] projection, String selection,
                String[] selectionArgs, String sortOrder) {
        // 到此处已完成会话的查询, 接下来看数据的填充
        return mOpenHelper.getReadableDatabase().query(TABLE_THREADS, // threads数据库 
                                                       projection, selection, 
                                                       selectionArgs, null, null,
                                                       " date DESC");        
    }
    
    4. 数据加载完成后回调到MessageLoaderFragment$LoaderManager.LoaderCallbacks<Cursor>中
    MessageLoaderFragment$LoaderManager.LoaderCallbacks<Cursor>:
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        ...
        // 数据加载完成回调到ConversationList中
        mListener.onMessageLoaded(data, loader);
    }
    
    5. 数据回调到ConversationList$MessageLoaderFragmentListener中
    ConversationList$MessageLoaderFragmentListener:
    public void onMessageLoaded(Cursor cursor, Loader<Cursor> loader) {
        // 更新UI
        mListAdapter.changeCursor(cursor);
        ... 
    }
    
    短信会话列表加载涉及到的数据库:
    MmsSmsDatabaseHelper: 
    数据库名: MmsSmsProvider:
    static final String TABLE_THREADS = "threads"
    数据库的创建:
    private void createCommonTables(SQLiteDatabase db) {
        ...
        db.execSQL("CREATE TABLE threads (" +
                   Threads._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +// id
                   Threads.DATE + " INTEGER DEFAULT 0," + // 时间
                   Threads.MESSAGE_COUNT + " INTEGER DEFAULT 0," + // 消息数量
                   Threads.RECIPIENT_IDS + " TEXT," + // 接受者ID
                   Threads.SNIPPET + " TEXT," + // 片段
                   Threads.SNIPPET_CHARSET + " INTEGER DEFAULT 0," + // 片段编码
                   Threads.READ + " INTEGER DEFAULT 1," + // 是否已读
                   Threads.TYPE + " INTEGER DEFAULT 0," + // 类型
                   Threads.ERROR + " INTEGER DEFAULT 0," + // 是否有错
                   Threads.HAS_ATTACHMENT + " INTEGER DEFAULT 0," + // 是否有附件
                   Threads.RECIPIENT_ADDRESSES + " TEXT, " + // 接受者地址
                   Threads.RECIPIENT_NAMES + " TEXT ); "); // 接受者姓名    
    }

  • 相关阅读:
    【JSP】上传图片到数据库中
    【MySQL】ERROR 1005: Can't create table (errno: 150)的错误解决办法
    【汇编】16进制转换成10进制(三种方法)
    书单
    C实现一个NTP客户端,可以从指定IP的NTP服务器获取时间戳
    crosss compile VLC with OpenMAX on ARM board(RockChip RK3399),in order to use Hard Acceleration when decode video
    win7结束进程 时,提示“拒绝访问”、“没有此任务的实例运行”怎么办?
    驱动文件中只有cat/inf/dll文件,怎么安装
    MFC开发中添加自定义消息和消息响应函数
    MFC中开发ocx控件,html容器收不到ocx的事件Event
  • 原文地址:https://www.cnblogs.com/firmly-believe/p/10719261.html
Copyright © 2011-2022 走看看