Android Open Source - welcome-android Data Browser 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  v  a 2 s  .c o  m
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.EditText;
import android.widget.TextView;

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

public class DataBrowserFragment extends Fragment implements OnClickListener {

  
  private View rootView;
  private EditText et;
  private TextView success, fail;
  private ProgressDialog dialog;

  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_data_browser, 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 dataBrowserButton = (Button) rootView
        .findViewById(R.id.data_browser_btn);
    dataBrowserButton.setTypeface(font);
    dataBrowserButton.setOnClickListener(this);

    et = (EditText) rootView.findViewById(R.id.user_name);
    
    success = (TextView) rootView.findViewById(R.id.data_browser_success);
    success.setVisibility(View.GONE);
    fail = (TextView) rootView.findViewById(R.id.data_browser_fail);
    fail.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) {
    if (view.getId() == R.id.data_browser_btn) {
      if (validateFields()) {
        setDialog();
        dataBrowser();
      }
    }
  }

  
  private void dataBrowser() {
    // Use FH Agent to store value in cloud DB
    FHAgent fhAgent = new FHAgent();
        fhAgent.dataBrowser(et.getText().toString(), new FHActCallback() {
            @Override
            public void success(FHResponse fhResponse) {
            success.setVisibility(View.VISIBLE);
            dialog.dismiss();
            Log.i("FEEDHENRY", "Data Browser Success!");
            }

            @Override
            public void fail(FHResponse fhResponse) {
            fail.setVisibility(View.VISIBLE);
            dialog.dismiss();
            Log.i("FEEDHENRY", "Data Browser Failed!");
            }
        });
        // Utility method to hide the keyboard
        KeyboardToggle.hideTheKeyboard(getActivity(), et);
  }


  // Set Edit Text validation rules
  private boolean validateFields() {
    if (et.getText().toString().length() == 0) {
      et.setError("Name is required!");
      et.requestFocus();
      return false;
    } else {
      return true;
    }
  }
}




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