Task - MessageOnTap/MessageOnTap_API GitHub Wiki

For every action to show on the phone, such as popping up UI or auto-send some messages, developers need to send PluginManagerService with a task that contains type and content in it.

Things that you can do with a task.

  • UIService
  • UIAction
  • PersonalGraph

Usage

The following example shows how to use a task to call MessageOnTap-core's UIService to show bubble.

int sid = SESSION_ID;          //You always need to initialize a task with a session id
HashMap<String, Object> = params;         //All of the parameters of the related task type
createTask(sid, MethodConstants.UI_TYPE,
                        MethodConstants.UI_METHOD_SHOW_BUBBLE, params);

The following example shows how to use a task to call MessageOnTap-core's PersonalGraph to retrieve personal data.

int sid = SESSION_ID;          //You always need to initialize a task with a session id
HashMap<String, Object> = params;         //All of the parameters of the related task type
createTask(sid, MethodConstants.GRAPH_TYPE,
                        MethodConstants.GRAPH_METHOD_RETRIEVE, params);

The following example shows how to use a task to call MessageOnTap-core's UIActionThread to retrieve personal data.

int sid = SESSION_ID;          //You always need to initialize a task with a session id
HashMap<String, Object> = params;         //All of the parameters of the related task type
createTask(sid, MethodConstants.ACTION_TYPE,
        MethodConstants.ACTION_METHOD_SETTEXT, params);
@Override
protected void newTaskResponsed(long sid, long tid, HashMap<String, Object> params) throws Exception {
    Log.e(TAG, "Got task response!");
    Log.e(TAG, JSONUtils.hashMapToString(params));

    ArrayList<Doc> DocList = new ArrayList<>();
    if (tid == tidFindAllDocName.get(sid)) {
        //getCardMessage and put it into params
        try {
            ArrayList<HashMap<String, Object>> cardList =
                    (ArrayList<HashMap<String, Object>>) params.get(EntityAttributes.Graph.CARD_LIST);
            for (HashMap<String, Object> card : cardList) {                 
            for (int i = 0; i < tree1.get(sid).getNodeList().size(); i++) {
                    ParseTree.Node node = tree1.get(sid).getNodeList().get(i);
                    if (node.getWord().equals((String) card.get(EntityAttributes.Graph.Document.TITLE))) {
                        Doc doc = new Doc();
                        doc.setDocName((String) card.get(EntityAttributes.Graph.Document.TITLE));
                        doc.setCreatedTime((Long) card.get(EntityAttributes.Graph.Document.CREATED_TIME));
                        //doc.setDocUrl((String)card.get(Graph.Document.URL));
                        DocList.add(doc);
                    }
                }
            }
            if (!DocList.isEmpty()) {
                tree1.put(sid, AddUrlRoot(tree1.get(sid), ALL_URL_ROOT_ID, DocTime1.get(sid), tag_time));
                params.remove(EntityAttributes.Graph.SYNTAX_TREE);
                params.put(EntityAttributes.Graph.SYNTAX_TREE, tree1);
                tidFindUrl1.put(sid, createTask(sid, MethodConstants.GRAPH_TYPE,
                        MethodConstants.GRAPH_METHOD_RETRIEVE, params));
            }
        } catch (Exception e) {
            e.printStackTrace();
            endSession(sid);
        }
    } else if (tid == tidFindDocName.get(sid)) {
        try {
            ArrayList<HashMap<String, Object>> cardList =
                    (ArrayList<HashMap<String, Object>>) params.get(EntityAttributes.Graph.CARD_LIST);
            for (HashMap<String, Object> card : cardList) {
                Doc doc = new Doc();
                doc.setDocName((String) card.get(EntityAttributes.Graph.Document.TITLE));
                doc.setCreatedTime((Long) card.get(EntityAttributes.Graph.Document.CREATED_TIME));
                //doc.setDocUrl((String)card.get(Graph.Document.URL));
                DocList.add(doc);
            }
            if (!DocList.isEmpty()) {
                tree2.put(sid, AddUrlRoot(tree2.get(sid), FILTERED_URL_ROOT_ID, DocTime2.get(sid), tag_time));
                params.remove(EntityAttributes.Graph.SYNTAX_TREE);
                params.put(EntityAttributes.Graph.SYNTAX_TREE, tree2);
                tidFindUrl2.put(sid, createTask(sid, MethodConstants.GRAPH_TYPE,
                        MethodConstants.GRAPH_METHOD_RETRIEVE, params));
            }
       } catch (Exception e) {
            e.printStackTrace();
            endSession(sid);
       }
   }


    if ((tid == tidFindUrl1.get(sid))||(tid == tidFindUrl2.get(sid))){
        try{
            ArrayList<HashMap<String, Object>> cardList =
                    (ArrayList<HashMap<String, Object>>) params.get(EntityAttributes.Graph.CARD_LIST);
            for (HashMap<String, Object> card : cardList) {
                for (Doc doc : DocList){
                    if (doc.getCreatedTime().equals(card.get(EntityAttributes.Graph.Document.CREATED_TIME))){
                       doc.setDocUrl((String)card.get(EntityAttributes.Graph.Document.TITLE));           //Todo:change to URL
                    }
                }
            }
            if (!DocList.isEmpty()) {
                //params.put(BUBBLE_FIRST_LINE, "Show GoogleDocs name");
                tidBubble.put(sid, createTask(sid, MethodConstants.UI_TYPE,
                        MethodConstants.UI_METHOD_SHOW_BUBBLE, params));
            }
        } catch (Exception e) {
            e.printStackTrace();
            endSession(sid);
        }
    }



/*
    if (tid == tidBubble.get(sid)) {
        if (params.get(BUBBLE_STATUS) == 1) {
            try {
                params.put("HTML Details", getHtml(DocList));
                tidDetails.put(sid, createTask(sid, MethodConstants.UI_TYPE,
                MethodConstants.UI_METHOD_LOAD_WEBVIEW, params));
            } catch (Exception e) {
                e.printStackTrace();
                endSession(sid);
            }
        } else {
            endSession(sid);
        }
    } else if (tid == tidDetails.get(sid)){
        //get selected URL
        for (Doc doc:DocList){
        String status = (String) params.get(doc.getDocName());
            if (status.equals("on")){
                selectedDocUrl.get(sid).append(doc.getDocUrl());
            }
        }
        params.put("Action SetText", selectedDocUrl.toString());                      //send URL
        tidDocSend.put(sid, createTask(sid, MethodConstants.ACTION_TYPE,
        MethodConstants.ACTION_METHOD_SETTEXT, params));
    } else if (tid == tidDocSend.get(sid)) {
        Log.e(TAG, "Ending session (triggerListShow)");
        endSession(sid);
        Log.e(TAG, "Session ended");
    }
    */
}
    HashMap<Long, Long> tidFindAllDocName = new HashMap<>();

    tidFindAllDocName.put(sid, createTask(sid, MethodConstants.GRAPH_TYPE,
                    MethodConstants.GRAPH_METHOD_RETRIEVE, params));

Summary

Fields

DataType Name
TaskData data
int status
long[] timestamp

Public Constructors

Function
Task(TaskData)

Public Methods

Return Type Function
TaskData getTaskData()
void setTaskData(TaskData)
int getStatus()
long getTimeStamp(int)
void updateStatus(int)
void prepareSendResponse(HashMap<String,Pobject>)
void prepareSendResponse(String)
⚠️ **GitHub.com Fallback** ⚠️