Android Open Source - cellar-communicator Category List






From Project

Back to project page cellar-communicator.

License

The source code is released under:

GNU General Public License

If you think the Android project cellar-communicator 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.vinit.orderplacer;
//from  www .  ja va 2 s  .  c  om
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class CategoryList extends Activity {

  ListView l;
  IPGetter get_ip;
  Intent i;
  Bundle b;
  String shared_data;

  /*
   * TODO: separate this class into another file
   */

  class FetchList extends AsyncTask<Void, Void, String> {
    ArrayList<String> arr;
    Context context;
    ListView l;
    String shared_data, salesman, party;
    ProgressDialog dialog;

    public FetchList(Context context, ListView l, String shared_data, String salesman, String party) {
      this.context = context;
      this.l = l;
      this.shared_data = shared_data;
      this.salesman = salesman;
      this.party = party;
      dialog = new ProgressDialog(context);
    }

    @Override
    protected void onPreExecute()  {
      dialog.setMessage("Loading");
      dialog.show();
    }
    
    @Override
    protected String doInBackground(Void... arg0) {
      get_ip = new IPGetter();
      HttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
      HttpGet httpGet = new HttpGet(get_ip.getIP() + "categories.php");
      try {
        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity entity = httpResponse.getEntity();
        String response = EntityUtils.toString(entity);
        return response;
      } catch (Exception e) {
        e.printStackTrace();
        return " ";
      }
    }

    @Override
    protected void onPostExecute(String s) {
      if(dialog.isShowing()) {
        dialog.dismiss();
      }
      
      JSONArray jArr;
      arr = new ArrayList<String>();

      try {
        jArr = new JSONArray(s);
        JSONObject jObj;
        for (int i = 0; i < jArr.length(); i++) {
          jObj = jArr.getJSONObject(i);
          arr.add(jObj.getString("category").toString());
        }
      } catch (JSONException e) {
        e.printStackTrace();
      }

      ArrayAdapter<String> ad = new ArrayAdapter<>(context,
          android.R.layout.simple_list_item_1, arr);
      l.setAdapter(ad);
      
      l.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v,
            int position, long id) {
          // TODO Auto-generated method stub
          Intent i = new Intent(context, SalesApp.class);
          i.putExtra("category", l.getItemAtPosition(position).toString());
          i.putExtra("data", shared_data);
          i.putExtra("salesman", salesman);
          i.putExtra("party", party);
          startActivity(i);
          
        }
        
      });
    }
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category_list);
    i = getIntent();
    b = i.getExtras();
    shared_data = new String();
    shared_data = "";
    if(b != null)
    {
      shared_data = b.getString("data");
    }
    
    l = (ListView) findViewById(R.id.categ_list);
    FetchList f = new FetchList(this, l, shared_data, b.getString("salesman"), b.getString("party"));
    f.execute();
  }
}




Java Source Code List

com.vinit.orderplacer.CategoryList.java
com.vinit.orderplacer.CheckPin.java
com.vinit.orderplacer.CommentBox.java
com.vinit.orderplacer.CounterOnClickListener.java
com.vinit.orderplacer.DumpJSON.java
com.vinit.orderplacer.IPGetter.java
com.vinit.orderplacer.RetrieveJSON.java
com.vinit.orderplacer.RetrieveSalesmen.java
com.vinit.orderplacer.SalesApp.java
com.vinit.orderplacer.SalesHistory.java
com.vinit.orderplacer.Salesman.java
com.vinit.orderplacer.SecurityPIN.java
com.vinit.orderplacer.SummaryActivity.java