rexseeCallLog對象,實現自定義數量的最近通話記錄,自定義查詢最近通話,讀取記錄數據庫表的URI地址。。html
【函數】 JsonObjectArray get(int number)java
【說明】 獲取指定數量的最近通話。android
【返回】 Json對象數組,使用eval('('+json+')')轉換爲JavaScript對象數組。數據庫
【參數】 number:要獲取的最近通話的數量。express
【示例】 json
alert(rexseeCallLog.get(10));
【函數】 JsonObjectArray get(String type, int number)數組
【說明】 獲取值類型、指定數量的最近通話。app
【返回】 Json對象數組,使用eval('('+json+')')轉換爲JavaScript對象數組。less
【參數】 type:類型,"INCOMING"(數據庫中爲1)、"OUTGOING"(數據庫中爲2)或"MISSED"(數據庫中爲3)。ide
number:要獲取的最近通話的數量。
【示例】
alert(rexseeCallLog.get('INCOMING',10)); alert(rexseeCallLog.get('OUTGOING',10)); alert(rexseeCallLog.get('MISSED',10));
【函數】 JsonArray getColumns()
【說明】 獲取通話記錄數據表全部字段。
【返回】 Json數組,使用eval('('+json+')')轉換爲JavaScript數組,注意,爲了提升效率,調用get()或getData()時並不會返回其中全部字段。
【參數】 無
【示例】
alert(rexseeCallLog.getColumns());
【函數】 JsonObjectArray getData(String selection, int number)
【說明】 獲取自定義查詢條件的最近通話。
【返回】 Json對象數組,使用eval('('+json+')')轉換爲JavaScript對象數組。
【參數】 selection:自定義查詢條件,至關於SQL語句中的WHERE字句(不含單詞WHERE)。
number:要獲取的最近通話的數量。
【示例】
alert(rexseeCallLog.getData('duration<10',10));
RexseeCallLog.java源碼:
/* * Copyright (C) 2011 The Rexsee Open Source Project * * Licensed under the Rexsee License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.rexsee.com/CN/legal/license.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package rexsee.content; import rexsee.core.browser.JavascriptInterface; import rexsee.core.browser.RexseeBrowser; import rexsee.core.browser.UrlListener; import rexsee.core.lang.RexseeLanguage; import rexsee.core.utilities.RexseeUtilities; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.provider.CallLog.Calls; public class RexseeCallLog implements JavascriptInterface { private static final String INTERFACE_NAME = "CallLog"; @Override public String getInterfaceName() { return mBrowser.application.resources.prefix + INTERFACE_NAME; } @Override public JavascriptInterface getInheritInterface(RexseeBrowser childBrowser) { return this; } @Override public JavascriptInterface getNewInterface(RexseeBrowser childBrowser) { return new RexseeCallLog(childBrowser); } private static final String[] CALLS_COLUMNS = new String[]{ Calls.NUMBER, //0 Calls.TYPE, //1 Calls.DATE, //2 Calls.DURATION //3 }; private final Context mContext; private final RexseeBrowser mBrowser; public RexseeCallLog(RexseeBrowser browser) { mBrowser = browser; mContext = browser.getContext(); browser.urlListeners.add(new UrlListener(mBrowser.application.resources.prefix + ":callLog") { @Override public void run(final Context context, final RexseeBrowser browser, String url) { new Thread() { @Override public void run() { browser.progressDialog.show(RexseeLanguage.PROGRESS_ONGOING); String html = "<HTML><HEAD><TITLE>" + Calls.CONTENT_URI.toString() + "</TITLE></HEAD>"; html += "<BODY style='margin:0px;background-color:black;color:white;'>"; html += "<table width=100% cellspacing=0 style='color:white;font-size:14px;'>"; try { ContentResolver contentResolver = context.getContentResolver(); String[] columns = new String[]{ Calls.NUMBER, //0 Calls.TYPE, //1 Calls.DATE, //2 Calls.DURATION //3 }; Cursor cursor = contentResolver.query(Calls.CONTENT_URI, columns, null, null, Calls.DATE + " DESC limit 100"); if (cursor == null || cursor.getCount() == 0) { html += "<tr><td style='padding:10px;'>No recent call found.</td></tr>"; } else { for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); html += "<tr><td style='border-bottom:1px solid #222222; padding:10 5 10 5;'>"; html += "<div style='font-size:16px;font-weight:bold;'>" + cursor.getString(0) + "</div>"; html += "<div>" + getType(cursor.getInt(1)) + "</div>"; html += "<div>" + RexseeUtilities.timeStamp2dateString(cursor.getLong(2)) + "</div>"; html += "<div>" + cursor.getString(3) + " seconds</div>"; html += "</td></tr>"; } } cursor.close(); } catch (Exception e) { html += "<tr><td style='padding:10px;'>Exception: " + e.getLocalizedMessage() + "</td></tr>"; } html += "</table>"; html += "</BODY>"; html += "</HTML>"; browser.function.loadHTMLWithoutHistory(html); } }.start(); } @Override public boolean shouldAddToHistory(Context context, RexseeBrowser browser, String url) { return true; } }); } private static String getType(int type) { switch (type) { case Calls.MISSED_TYPE : return "MISSED"; case Calls.INCOMING_TYPE : return "INCOMING"; case Calls.OUTGOING_TYPE : return "OUTGOING"; default : return "unknown"; } } private static int getType(String type) { if (type == null) return -1; else if (type.equalsIgnoreCase("MISSED")) return Calls.MISSED_TYPE; else if (type.equalsIgnoreCase("INCOMING")) return Calls.INCOMING_TYPE; else if (type.equalsIgnoreCase("OUTGOING")) return Calls.OUTGOING_TYPE; else return -1; } //JavaScript Interface public String getContentUri() { return Calls.CONTENT_URI.toString(); } public String get(int number) { return get(null, number); } public String get(String type, int number) { int t = getType(type); String selection = (t > 0) ? Calls.TYPE + "=" + t : null; return getData(selection, number); } public String getData(String selection, int number) { ContentResolver contentResolver = mContext.getContentResolver(); Cursor cursor; if (number > 0) { cursor = contentResolver.query(Calls.CONTENT_URI, CALLS_COLUMNS, selection, null, Calls.DATE + " DESC limit " + number); } else { cursor = contentResolver.query(Calls.CONTENT_URI, CALLS_COLUMNS, selection, null, Calls.DATE + " DESC"); } if (cursor == null) return "[]"; String rtn = ""; for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); if (i > 0) rtn += ","; rtn += "{"; rtn += "\"number\":\"" + cursor.getString(0) + "\""; rtn += ",\"type\":\"" + getType(cursor.getInt(1)) + "\""; rtn += ",\"date\":" + cursor.getString(2); rtn += ",\"duration\":" + cursor.getString(3); rtn += "}"; } cursor.close(); return "[" + rtn + "]"; } public String getColumns() { return RexseeContent.getContentColumns_(mContext, Calls.CONTENT_URI); } }
僅對Rexsee的源碼和函數事件作了整理,相關的demo或源碼解析能夠在Rexsee社區瞭解,目前Rexsee已提供了近2000個擴展,覆蓋Android原生功能超過90%,且所有開放:http://www.rexsee.com/