Android Open Source - welcome-android Call Cloud Fragment






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.fragments;
//from  ww w.  ja  va2s  .c om
import android.app.Fragment;
import android.app.ProgressDialog;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.feedhenry.android.R;
import com.feedhenry.android.server.FHAgent;
import com.feedhenry.android.utilities.MyToast;
import com.feedhenry.sdk.FHActCallback;
import com.feedhenry.sdk.FHResponse;

public class CallCloudFragment extends Fragment implements OnClickListener {

  private View rootView;
  private LinearLayout ll;
  private ProgressDialog dialog;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_call_cloud, container,
        false);
    initUI();
    return rootView;
  }

  public void initUI() {
    // TODO Possible Memory Issues Here creating new instances of font
    Typeface font = Typeface.createFromAsset(getActivity()
        .getApplicationContext().getAssets(),
        "fonts/fontawesome-webfont.ttf");

    Button cloudButton = (Button) rootView
        .findViewById(R.id.call_cloud_btn);
    cloudButton.setTypeface(font);
    cloudButton.setOnClickListener(this);

    ll = (LinearLayout) rootView.findViewById(R.id.cloud_toggle);
    ll.setVisibility(View.GONE);
  }

  private void setDialog() {
    dialog = new ProgressDialog(this.getActivity());
    dialog.setIndeterminate(true);
    dialog.setCancelable(false);
    dialog.setMessage("Loading...");
    dialog.show();
  }

  @Override
  public void onClick(View view) {
    setDialog();
    callCloud();
  }

  private void callCloud() {
    // Use FH Agent to call the FH Cloud
    FHAgent fhAgent = new FHAgent();
    fhAgent.cloudCall(new FHActCallback() {
      @Override
      public void success(FHResponse fhResponse) {
        ll.setVisibility(View.VISIBLE);
        TextView tv = (TextView) rootView
            .findViewById(R.id.cloud_action_response_title);
        tv.setText("Response: "
            + fhResponse.getJson().getString("text"));
        dialog.dismiss();
        Log.i("FEEDHENRY", "Cloud Call Success! "
            + fhResponse.getJson().getString("text"));
      }

      @Override
      public void fail(FHResponse fhResponse) {
        dialog.dismiss();
        MyToast.showToast("Could not reach cloud");
        Log.i("FEEDHENRY", fhResponse.getRawResponse());
        Log.i("FEEDHENRY", "Cloud Call Failed!");
      }
    });
  }
}




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