Example usage for org.apache.cordova PluginResult PluginResult

List of usage examples for org.apache.cordova PluginResult PluginResult

Introduction

In this page you can find the example usage for org.apache.cordova PluginResult PluginResult.

Prototype

public PluginResult(Status status, List<PluginResult> multipartMessages) 

Source Link

Usage

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void queryStartingAtValue(JSONArray data) {
    String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName;
    Object objStartValue;/*ww  w.j  a v  a 2s . c  om*/

    if (data.length() >= 2) {
        try {
            strURL = data.getString(0);
            objStartValue = data.get(1);
        } catch (JSONException e) {
            PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
            e.printStackTrace();
            return;
        }
    } else {
        PluginResult pluginResult = new PluginResult(Status.ERROR, "queryStartingAtValue : Parameter Error");
        mCallbackContext.sendPluginResult(pluginResult);
        return;
    }

    Firebase urlRef = new Firebase(strURL);

    if (isUsed != true)
        isUsed = true;
    ValueEventListener listener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            JSONObject resultObj;
            try {
                HashMap result = snapshot.getValue(HashMap.class);
                if (result == null)
                    resultObj = new JSONObject();
                else
                    resultObj = new JSONObject(result);
                PluginResult pluginResult = new PluginResult(Status.OK, resultObj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (Exception e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println("queryStartingAtValue().addListenerForSingleValueEvent failed: "
                    + firebaseError.getMessage());
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "queryStartingAtValue failded: " + firebaseError.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }
    };
    // Read data and react to changes
    if (objStartValue.getClass() == Double.class)
        urlRef.startAt(((Double) objStartValue).doubleValue()).addListenerForSingleValueEvent(listener);
    else if (objStartValue.getClass() == Boolean.class)
        urlRef.startAt(((Boolean) objStartValue).booleanValue()).addListenerForSingleValueEvent(listener);
    else if (objStartValue.getClass() == String.class)
        urlRef.startAt((String) objStartValue).addListenerForSingleValueEvent(listener);
    else
        urlRef.startAt(objStartValue.toString()).addListenerForSingleValueEvent(listener);

}

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void queryStartingAtValueChildKey(JSONArray data) {
    String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName;
    String strChildKey;//from www.j a v  a 2s.com
    Object objStartValue;

    if (data.length() >= 3) {
        try {
            strURL = data.getString(0);
            objStartValue = data.get(1);
            strChildKey = data.getString(2);
        } catch (JSONException e) {
            PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
            e.printStackTrace();
            return;
        }
    } else {
        PluginResult pluginResult = new PluginResult(Status.ERROR,
                "queryStartingAtValueChildKey : Parameter Error");
        mCallbackContext.sendPluginResult(pluginResult);
        return;
    }

    Firebase urlRef = new Firebase(strURL);

    if (isUsed != true)
        isUsed = true;
    ValueEventListener listener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            JSONObject resultObj;
            try {
                HashMap result = snapshot.getValue(HashMap.class);
                if (result == null)
                    resultObj = new JSONObject();
                else
                    resultObj = new JSONObject(result);
                PluginResult pluginResult = new PluginResult(Status.OK, resultObj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (Exception e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println("queryStartingAtValueChildKey().addListenerForSingleValueEvent failed: "
                    + firebaseError.getMessage());
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "queryStartingAtValueChildKey failded: " + firebaseError.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }
    };

    // Read data and react to changes
    if (objStartValue.getClass() == Double.class)
        urlRef.startAt(((Double) objStartValue).doubleValue(), strChildKey)
                .addListenerForSingleValueEvent(listener);
    else if (objStartValue.getClass() == Boolean.class)
        urlRef.startAt(((Boolean) objStartValue).booleanValue(), strChildKey)
                .addListenerForSingleValueEvent(listener);
    else if (objStartValue.getClass() == String.class)
        urlRef.startAt((String) objStartValue, strChildKey).addListenerForSingleValueEvent(listener);
    else
        urlRef.startAt(objStartValue.toString(), strChildKey).addListenerForSingleValueEvent(listener);
}

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void queryEndingAtValue(JSONArray data) {
    String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName;
    Object objEndValue;/*from w ww. ja  v  a 2  s .c o m*/

    if (data.length() >= 2) {
        try {
            strURL = data.getString(0);
            objEndValue = data.get(1);
        } catch (JSONException e) {
            PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
            e.printStackTrace();
            return;
        }
    } else {
        PluginResult pluginResult = new PluginResult(Status.ERROR, "queryEndingAtValue : Parameter Error");
        mCallbackContext.sendPluginResult(pluginResult);
        return;
    }

    Firebase urlRef = new Firebase(strURL);

    if (isUsed != true)
        isUsed = true;
    ValueEventListener listener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            JSONObject resultObj;
            try {
                HashMap result = snapshot.getValue(HashMap.class);
                if (result == null)
                    resultObj = new JSONObject();
                else
                    resultObj = new JSONObject(result);
                PluginResult pluginResult = new PluginResult(Status.OK, resultObj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (Exception e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println("queryEndingAtValue().addListenerForSingleValueEvent failed: "
                    + firebaseError.getMessage());
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "queryEndingAtValue failded: " + firebaseError.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }
    };

    if (objEndValue.getClass() == Double.class)
        urlRef.endAt(((Double) objEndValue).doubleValue()).addListenerForSingleValueEvent(listener);
    else if (objEndValue.getClass() == Boolean.class)
        urlRef.endAt(((Boolean) objEndValue).booleanValue()).addListenerForSingleValueEvent(listener);
    else if (objEndValue.getClass() == String.class)
        urlRef.endAt((String) objEndValue).addListenerForSingleValueEvent(listener);
    else
        urlRef.endAt(objEndValue.toString()).addListenerForSingleValueEvent(listener);
}

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void queryEndingAtValueChildKey(JSONArray data) {
    String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName;
    String strChildKey;/*from   w  w  w.j  a  v a 2 s  . c o  m*/
    Object objEndValue;

    if (data.length() >= 3) {
        try {
            strURL = data.getString(0);
            objEndValue = data.get(1);
            strChildKey = data.getString(2);
        } catch (JSONException e) {
            PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
            e.printStackTrace();
            return;
        }
    } else {
        PluginResult pluginResult = new PluginResult(Status.ERROR,
                "queryEndingAtValueChildKey : Parameter Error");
        mCallbackContext.sendPluginResult(pluginResult);
        return;
    }

    Firebase urlRef = new Firebase(strURL);

    if (isUsed != true)
        isUsed = true;
    ValueEventListener listener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            JSONObject resultObj;
            try {
                HashMap result = snapshot.getValue(HashMap.class);
                if (result == null)
                    resultObj = new JSONObject();
                else
                    resultObj = new JSONObject(result);
                PluginResult pluginResult = new PluginResult(Status.OK, resultObj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (Exception e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println("queryEndingAtValueChildKey().addListenerForSingleValueEvent failed: "
                    + firebaseError.getMessage());
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "queryEndingAtValueChildKey failded: " + firebaseError.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }
    };

    // Read data and react to changes
    if (objEndValue.getClass() == Double.class)
        urlRef.endAt(((Double) objEndValue).doubleValue(), strChildKey)
                .addListenerForSingleValueEvent(listener);
    else if (objEndValue.getClass() == Boolean.class)
        urlRef.endAt(((Boolean) objEndValue).booleanValue(), strChildKey)
                .addListenerForSingleValueEvent(listener);
    else if (objEndValue.getClass() == String.class)
        urlRef.endAt((String) objEndValue, strChildKey).addListenerForSingleValueEvent(listener);
    else
        urlRef.endAt(objEndValue.toString(), strChildKey).addListenerForSingleValueEvent(listener);
}

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void queryEqualToValue(JSONArray data) {
    String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName;
    Object objValue;/*from  w w  w .  j av  a 2 s.  c  om*/

    if (data.length() >= 2) {
        try {
            strURL = data.getString(0);
            objValue = data.get(1);
        } catch (JSONException e) {
            PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
            e.printStackTrace();
            return;
        }
    } else {
        PluginResult pluginResult = new PluginResult(Status.ERROR, "queryEqualToValue : Parameter Error");
        mCallbackContext.sendPluginResult(pluginResult);
        return;
    }

    Firebase urlRef = new Firebase(strURL);

    if (isUsed != true)
        isUsed = true;
    ValueEventListener listener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            JSONObject resultObj;
            try {
                HashMap result = snapshot.getValue(HashMap.class);
                if (result == null)
                    resultObj = new JSONObject();
                else
                    resultObj = new JSONObject(result);
                PluginResult pluginResult = new PluginResult(Status.OK, resultObj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (Exception e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println(
                    "queryEqualToValue().addListenerForSingleValueEvent failed: " + firebaseError.getMessage());
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "queryEqualToValue failded: " + firebaseError.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }
    };
    // Read data and react to changes
    if (objValue.getClass() == Double.class)
        urlRef.equalTo(((Double) objValue).doubleValue()).addListenerForSingleValueEvent(listener);
    else if (objValue.getClass() == Boolean.class)
        urlRef.equalTo(((Boolean) objValue).booleanValue()).addListenerForSingleValueEvent(listener);
    else if (objValue.getClass() == String.class)
        urlRef.equalTo((String) objValue).addListenerForSingleValueEvent(listener);
    else
        urlRef.equalTo(objValue.toString()).addListenerForSingleValueEvent(listener);
}

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void queryEqualToValueChildKey(JSONArray data) {
    String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName;
    String strChildKey;/*from   w  w  w. j a  v  a  2  s. co  m*/
    Object objValue;

    if (data.length() >= 3) {
        try {
            strURL = data.getString(0);
            objValue = data.get(1);
            strChildKey = data.getString(2);
        } catch (JSONException e) {
            PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
            e.printStackTrace();
            return;
        }
    } else {
        PluginResult pluginResult = new PluginResult(Status.ERROR,
                "queryEqualToValueChildKey : Parameter Error");
        mCallbackContext.sendPluginResult(pluginResult);
        return;
    }

    Firebase urlRef = new Firebase(strURL);

    if (isUsed != true)
        isUsed = true;
    ValueEventListener listener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            JSONObject resultObj;
            try {
                HashMap result = snapshot.getValue(HashMap.class);
                if (result == null)
                    resultObj = new JSONObject();
                else
                    resultObj = new JSONObject(result);
                PluginResult pluginResult = new PluginResult(Status.OK, resultObj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (Exception e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println("queryEqualToValueChildKey().addListenerForSingleValueEvent failed: "
                    + firebaseError.getMessage());
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "queryEqualToValueChildKey failded: " + firebaseError.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }
    };

    // Read data and react to changes
    if (objValue.getClass() == Double.class)
        urlRef.equalTo(((Double) objValue).doubleValue(), strChildKey).addListenerForSingleValueEvent(listener);
    else if (objValue.getClass() == Boolean.class)
        urlRef.equalTo(((Boolean) objValue).booleanValue(), strChildKey)
                .addListenerForSingleValueEvent(listener);
    else if (objValue.getClass() == String.class)
        urlRef.equalTo((String) objValue, strChildKey).addListenerForSingleValueEvent(listener);
    else
        urlRef.equalTo(objValue.toString(), strChildKey).addListenerForSingleValueEvent(listener);
}

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void querySearch(JSONArray data) throws JSONException {
    ///*from w ww .java2 s. com*/
    String strURL = String.format("https://%s.firebaseio.com", appName);
    JSONObject queryInfo;

    QSearchType typeofSearch = QSearchType.QSearchAt_EQUAL;
    Object searchValue = null;
    String strSearchKey = "";
    QOrderType typeofOrder = QOrderType.QOrderBy_NOT;
    String strOrderValue = "";
    QLimitType typeofLimit = QLimitType.QLimitedTo_NOT;
    Integer numLimited = 0;

    // String temp;
    if (data.length() >= 2) {
        strURL = data.getString(0);
        queryInfo = data.getJSONObject(1);
        {
            if (!queryInfo.has("search")) {
                //                    typeofSearch = QSearchType.QSearchAt_STARTING;
                //                    searchValue = "";
                //                    strSearchKey = "";
            } else {
                if (queryInfo.getJSONObject("search").getString("type").compareTo("starting") == 0)
                    typeofSearch = QSearchType.QSearchAt_STARTING;
                else if (queryInfo.getJSONObject("search").getString("type").compareTo("ending") == 0)
                    typeofSearch = QSearchType.QSearchAt_ENDING;
                else //"equal" or nil
                    typeofSearch = QSearchType.QSearchAt_EQUAL;
                searchValue = queryInfo.getJSONObject("search").get("value");
                if (searchValue == null)
                    searchValue = "";

                strSearchKey = queryInfo.getJSONObject("search").getString("child");
                if (strSearchKey == null)
                    strSearchKey = "";
            }

            if (!queryInfo.has("order")) {
                //                    typeofOrder = QOrderType.QOrderBy_NOT;
                //                    strOrderValue = "";
            } else {
                if (queryInfo.getJSONObject("order").getString("by").compareTo("key") == 0)
                    typeofOrder = QOrderType.QOrderBy_CHILDKEY;
                else if (queryInfo.getJSONObject("order").getString("by").compareTo("value") == 0)
                    typeofOrder = QOrderType.QOrderBy_CHILDVALUE;
                else
                    typeofOrder = QOrderType.QOrderBy_NOT;

                strOrderValue = queryInfo.getJSONObject("order").getString("field");
                if (strOrderValue == null)
                    strOrderValue = "";
            }

            if (!queryInfo.has("limit")) {
                //                    typeofLimit = QLimitType.QLimitedTo_NOT;
                //                    numLimited = 0;
            } else {
                if (queryInfo.getJSONObject("limit").getString("at").compareTo("first") == 0)
                    typeofLimit = QLimitType.QLimitedTo_FIRST;
                else if (queryInfo.getJSONObject("limit").getString("at").compareTo("last") == 0)
                    typeofLimit = QLimitType.QLimitedTo_LAST;
                else
                    typeofLimit = QLimitType.QLimitedTo_NOT;

                if (queryInfo.getJSONObject("limit").isNull("num"))
                    numLimited = 0;
                else
                    numLimited = queryInfo.getJSONObject("limit").getInt("num");
            }
        }
    }

    Firebase urlRef = new Firebase(strURL);
    Query queryOrder = null;

    switch (typeofOrder) {
    case QOrderBy_NOT:
    default:
    case QOrderBy_CHILDKEY:
        queryOrder = urlRef.orderByKey();
        break;

    case QOrderBy_CHILDVALUE:
        queryOrder = urlRef.orderByChild(strOrderValue);
        break;
    }

    Query queryObj = null;

    switch (typeofSearch) {
    case QSearchAt_EQUAL:
        if (strSearchKey == null | strSearchKey.length() == 0) {
            if (searchValue.getClass() == Double.class)
                queryObj = queryOrder.equalTo(((Double) searchValue).doubleValue());
            else if (searchValue.getClass() == Boolean.class)
                queryObj = queryOrder.equalTo(((Boolean) searchValue).booleanValue());
            else if (searchValue.getClass() == String.class)
                queryObj = queryOrder.equalTo((String) searchValue);
            else
                queryObj = queryOrder.equalTo(searchValue.toString());
        } else {
            if (searchValue.getClass() == Double.class)
                queryObj = queryOrder.equalTo(((Double) searchValue).doubleValue(), strSearchKey);
            else if (searchValue.getClass() == Boolean.class)
                queryObj = queryOrder.equalTo(((Boolean) searchValue).booleanValue(), strSearchKey);
            else if (searchValue.getClass() == String.class)
                queryObj = queryOrder.equalTo((String) searchValue, strSearchKey);
            else
                queryObj = queryOrder.equalTo(searchValue.toString(), strSearchKey);
        }
        break;

    case QSearchAt_STARTING:
        if (strSearchKey == null | strSearchKey.length() == 0) {
            if (searchValue.getClass() == Double.class)
                queryObj = queryOrder.startAt(((Double) searchValue).doubleValue());
            else if (searchValue.getClass() == Boolean.class)
                queryObj = queryOrder.startAt(((Boolean) searchValue).booleanValue());
            else if (searchValue.getClass() == String.class)
                queryObj = queryOrder.startAt((String) searchValue);
            else
                queryObj = queryOrder.startAt(searchValue.toString());
        } else {
            if (searchValue.getClass() == Double.class)
                queryObj = queryOrder.startAt(((Double) searchValue).doubleValue(), strSearchKey);
            else if (searchValue.getClass() == Boolean.class)
                queryObj = queryOrder.startAt(((Boolean) searchValue).booleanValue(), strSearchKey);
            else if (searchValue.getClass() == String.class)
                queryObj = queryOrder.startAt((String) searchValue, strSearchKey);
            else
                queryObj = queryOrder.startAt(searchValue.toString(), strSearchKey);
        }
        break;

    case QSearchAt_ENDING:
        if (strSearchKey == null | strSearchKey.length() == 0) {
            if (searchValue.getClass() == Double.class)
                queryObj = queryOrder.endAt(((Double) searchValue).doubleValue());
            else if (searchValue.getClass() == Boolean.class)
                queryObj = queryOrder.endAt(((Boolean) searchValue).booleanValue());
            else if (searchValue.getClass() == String.class)
                queryObj = queryOrder.endAt((String) searchValue);
            else
                queryObj = queryOrder.endAt(searchValue.toString());
        } else {
            if (searchValue.getClass() == Double.class)
                queryObj = queryOrder.endAt(((Double) searchValue).doubleValue(), strSearchKey);
            else if (searchValue.getClass() == Boolean.class)
                queryObj = queryOrder.endAt(((Boolean) searchValue).booleanValue(), strSearchKey);
            else if (searchValue.getClass() == String.class)
                queryObj = queryOrder.endAt((String) searchValue, strSearchKey);
            else
                queryObj = queryOrder.endAt(searchValue.toString(), strSearchKey);
        }
        break;

    default:
        queryObj = queryOrder.startAt();//queryObj = [queryOrder queryStartingAtValue:nil];
        break;
    }
    Query queryLimit = null;
    switch (typeofLimit) {
    case QLimitedTo_NOT:
    default:
        queryLimit = queryObj;
        break;
    case QLimitedTo_FIRST:
        queryLimit = queryObj.limitToFirst(numLimited);
        break;
    case QLimitedTo_LAST:
        queryLimit = queryObj.limitToLast(numLimited);
        break;
    }

    queryLimit.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            JSONObject resultObj;
            try {
                HashMap result = snapshot.getValue(HashMap.class);
                if (result == null)
                    resultObj = new JSONObject();
                else
                    resultObj = new JSONObject(result);
                PluginResult pluginResult = new PluginResult(Status.OK, resultObj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (Exception e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println(
                    "The querySearch(addListenerForSingleValueEvent) failed: " + firebaseError.getMessage());
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "The querySearch failded: " + firebaseError.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }
    });
}

From source file:com.phonegap.plugins.Firebase.CDVFirebase.java

License:Apache License

private void userLogin(JSONArray data) {
    String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName;
    String userName;//from   ww  w .j a v a2 s  .c o  m
    String password;

    if (data.length() >= 2) {
        try {
            userName = data.getString(0);
            password = data.getString(1);
        } catch (JSONException e) {
            PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
            e.printStackTrace();
            return;
        }
    } else {
        PluginResult pluginResult = new PluginResult(Status.ERROR, "queryEqualToValue : Parameter Error");
        mCallbackContext.sendPluginResult(pluginResult);
        return;
    }

    Firebase rootRef = new Firebase(strURL);
    rootRef.authWithPassword(userName, password, new Firebase.AuthResultHandler() {

        @Override
        public void onAuthenticationError(FirebaseError arg0) {
            PluginResult pluginResult = new PluginResult(Status.ERROR,
                    "authWithPassword failded: " + arg0.getMessage());
            mCallbackContext.sendPluginResult(pluginResult);
        }

        @Override
        public void onAuthenticated(AuthData arg0) {
            JSONObject obj;
            try {
                obj = new JSONObject(arg0.getAuth().toString());
                PluginResult pluginResult = new PluginResult(Status.OK, obj);
                //pluginResult.setKeepCallback(true);
                mCallbackContext.sendPluginResult(pluginResult);
            } catch (JSONException e) {
                PluginResult pluginResult = new PluginResult(Status.ERROR,
                        "AuthData failded: " + e.getMessage());
                mCallbackContext.sendPluginResult(pluginResult);
                e.printStackTrace();
            }
        }
    });
}

From source file:com.phonegap.plugins.nativesettings.NativeSettings.java

License:BSD License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    //Information on settings can be found here:
    //http://developer.android.com/reference/android/provider/Settings.html

    if (action.equals("open")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
    } else if (action.equals("accessibility")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS));
    } else if (action.equals("add_account")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT));
    } else if (action.equals("airplane_mode")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS));
    } else if (action.equals("apn")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_APN_SETTINGS));
    } else if (action.equals("application_details")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS));
    } else if (action.equals("application_development")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
    } else if (action.equals("application")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS));
    }/* w  w  w.ja  v  a2  s  .  c o  m*/
    //else if (action.equals("battery_saver")) {
    //    this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_BATTERY_SAVER_SETTINGS));
    //}
    else if (action.equals("bluetooth")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS));
    } else if (action.equals("captioning")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_CAPTIONING_SETTINGS));
    } else if (action.equals("cast")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_CAST_SETTINGS));
    } else if (action.equals("data_roaming")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS));
    } else if (action.equals("date")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));
    } else if (action.equals("device_info")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS));
    } else if (action.equals("display")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_DISPLAY_SETTINGS));
    } else if (action.equals("dream")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_DREAM_SETTINGS));
    } else if (action.equals("home")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_HOME_SETTINGS));
    } else if (action.equals("input_method")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS));
    } else if (action.equals("input_method_subtype")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS));
    } else if (action.equals("internal_storage")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS));
    } else if (action.equals("locale")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_LOCALE_SETTINGS));
    } else if (action.equals("location_source")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
    } else if (action.equals("manage_all_applications")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
    } else if (action.equals("manage_applications")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS));
    } else if (action.equals("memory_card")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS));
    } else if (action.equals("network_operator")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS));
    } else if (action.equals("nfcsharing")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_NFCSHARING_SETTINGS));
    } else if (action.equals("nfc_payment")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_NFC_PAYMENT_SETTINGS));
    } else if (action.equals("nfc_settings")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_NFC_SETTINGS));
    }
    //else if (action.equals("notification_listner")) {
    //    this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
    //}
    else if (action.equals("print")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS));
    } else if (action.equals("privacy")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_PRIVACY_SETTINGS));
    } else if (action.equals("quick_launch")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_QUICK_LAUNCH_SETTINGS));
    } else if (action.equals("search")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_SEARCH_SETTINGS));
    } else if (action.equals("security")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));
    } else if (action.equals("settings")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
    } else if (action.equals("show_regulatory_info")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_SHOW_REGULATORY_INFO));
    } else if (action.equals("sound")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS));
    } else if (action.equals("sync")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_SYNC_SETTINGS));
    } else if (action.equals("usage_access")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS));
    } else if (action.equals("user_dictionary")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_USER_DICTIONARY_SETTINGS));
    } else if (action.equals("voice_input")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_VOICE_INPUT_SETTINGS));
    } else if (action.equals("wifi_ip")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_WIFI_IP_SETTINGS));
    } else if (action.equals("wifi")) {
        this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
    } else if (action.equals("wireless")) {
        this.cordova.getActivity()
                .startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
    } else {
        status = PluginResult.Status.INVALID_ACTION;
    }

    callbackContext.sendPluginResult(new PluginResult(status, result));

    return true;

}

From source file:com.phonegap.plugins.nativesettings.NativeSettings.java

License:BSD License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    if (action.equals("checkSD")) {
        Boolean isSDPresent = android.os.Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED);
        return isSDPresent;
    } else {/*from   ww w. ja  v a 2 s  . c o m*/
        status = PluginResult.Status.INVALID_ACTION;
    }

    callbackContext.sendPluginResult(new PluginResult(status, result));

    return true;

}