Android Open Source - welcome-android F H Agent






From Project

Back to project page welcome-android.

License

The source code is released under:

Copyright (c) 2014 FeedHenry Ltd, All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software")...

If you think the Android project welcome-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.feedhenry.android.server;
/*from w  w w  . ja  v a 2  s .  c om*/
import org.json.fh.JSONArray;
import org.json.fh.JSONObject;

import android.content.Context;
import android.net.ConnectivityManager;
import android.util.Log;

import com.feedhenry.android.MyApplication;
import com.feedhenry.sdk.FH;
import com.feedhenry.sdk.FHActCallback;
import com.feedhenry.sdk.FHResponse;
import com.feedhenry.sdk.api.FHCloudRequest;

public class FHAgent {
  
    public static boolean initialised = false;
    
    public void cloudCall(FHActCallback fhActCallback){
        JSONObject param = new JSONObject("{}");
        this.call("hello", param, fhActCallback);
    }
    

    public void dataBrowser(String userName, FHActCallback fhActCallback) {
      JSONObject param = new JSONObject("{'collection':'Users', 'document': {username: " + userName + "}}");
      this.call("saveData", param, fhActCallback);
  }
    
    
    public void getWeather(double lat, double lng, FHActCallback fhActCallback){
        JSONObject param = new JSONObject("{'lat':'" + lat + "', 'lon':'" + lng + "'}");
        this.call("getWeather", param, fhActCallback);
    }
    
    public void getFHVars(FHActCallback fhActCallback){
        JSONObject param = new JSONObject("{}");
        this.call("getFhVars", param, fhActCallback);
    }
        
    public static boolean isOnline(){
        ConnectivityManager cm = (ConnectivityManager) MyApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected() ? true : false;
    }
    
    
    private void call(final String path, final JSONObject params, final FHActCallback callback) {
        try {
            FHCloudRequest request = FH.buildCloudRequest(path, "POST", null, params);
            request.executeAsync(callback);
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("fh", "Init Failed!");
        }
    }
    
    
    protected FHResponse getFakedErrorResponse(String errMessage){
        FHResponse fakedErrorResponse=new FHResponse(new JSONObject(),new JSONArray(),new Throwable(errMessage),errMessage);
        return fakedErrorResponse;
    }


    public static void init(final FHActCallback callback) {
        if (initialised) {
            callback.success(null);
        } else {
            FH.init(MyApplication.getAppContext(), new FHActCallback() {
                @Override
                public void success(FHResponse fhResponse) {
                    initialised = true;
                    callback.success(fhResponse);
                }
                @Override
                public void fail(FHResponse fhResponse) {
                    initialised = false;
                    callback.fail(fhResponse);
                }
            });
        }
    }
}




Java Source Code List

com.feedhenry.android.MainActivity.java
com.feedhenry.android.MyApplication.java
com.feedhenry.android.drawer.adapter.NavDrawerListAdapter.java
com.feedhenry.android.drawer.model.NavDrawerItem.java
com.feedhenry.android.fragments.CallCloudFragment.java
com.feedhenry.android.fragments.CloudIntegrationsFragment.java
com.feedhenry.android.fragments.DataBrowserFragment.java
com.feedhenry.android.fragments.HomeFragment.java
com.feedhenry.android.fragments.LocationFragment.java
com.feedhenry.android.fragments.NativeAppInfoFragment.java
com.feedhenry.android.fragments.PushNotificationsFragment.java
com.feedhenry.android.fragments.StatsFragment.java
com.feedhenry.android.server.FHAgent.java
com.feedhenry.android.utilities.KeyboardToggle.java
com.feedhenry.android.utilities.MyLocation.java
com.feedhenry.android.utilities.MyToast.java