Android Open Source - GroupSmart-Android Find Group






From Project

Back to project page GroupSmart-Android.

License

The source code is released under:

Copyright (C) <2014> <Derek Argueta - Hunter Kehoe> 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 GroupSmart-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.dargueta.groupsmart;
/*from  ww w  .j  av a  2  s .c om*/
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.google.analytics.tracking.android.EasyTracker;

/**
 * 
 * @author Hunter Kehoe
 * 
 * This class presents the activity where the user can browse or search for groups
 *
 */
public class FindGroup extends Activity {
  
  // search bar to enable user to search through groups for a specific group
  EditText etSearch;
  
  // list to display all groups available to the user
  ListView lvGroups;
  
  // navigation buttons
  Button btnHome, btnProfile, btnNewGroup, btnSettings;
  
  // list to hold all the groups
  ArrayList<HashMap<String,String>> groupList = new ArrayList<HashMap<String,String>>();
  
  // JSON return result from an HTTP request
  JSONArray groups = null;
  
  // progress indicator
  ProgressDialog pDialog;
  
  public void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.find_group);
    
    etSearch = (EditText) findViewById(R.id.etSearch);
    lvGroups = (ListView) findViewById(R.id.lvGroups);

    // Navigation Tabs
    btnProfile = (Button) findViewById(R.id.btnProfile);
    btnSettings = (Button) findViewById(R.id.btnSettings);
    btnHome = (Button) findViewById(R.id.btnHome);
    btnNewGroup = (Button) findViewById(R.id.btnNewGroup);
    
    btnProfile.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        Intent i = new Intent(getApplicationContext(), Profile.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
        overridePendingTransition(0, 0);
      }
    });
    
    btnSettings.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        Intent i = new Intent(getApplicationContext(), Settings.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
        overridePendingTransition(0, 0);
      }
    });
    
    btnHome.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        Intent i = new Intent(getApplicationContext(), Main.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
        overridePendingTransition(0, 0);
      }
    });
    
    btnNewGroup.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        Intent i = new Intent(getApplicationContext(), CreateGroup.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
        overridePendingTransition(0, 0);
      }
    });
    
    // Search Bar
    etSearch.addTextChangedListener(new TextWatcher() {
      
      public void onTextChanged(CharSequence cs, int ar1, int arg2, int arg3) {
        
        ((SimpleAdapter) lvGroups.getAdapter()).getFilter().filter(cs);
      }
      
      public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        
      }
      
      public void afterTextChanged(Editable arg0) {
        
      }
    });
    
    lvGroups.setOnItemClickListener(new OnItemClickListener() {
      
      public void onItemClick(AdapterView<?> parent, final View v, int position, long id) {
        Intent i = new Intent(getApplicationContext(), GroupInfo.class);
        i.putExtra(Constants.ID_KEY, ((TextView) v.findViewById(R.id.id)).getText().toString());
        startActivity(i);
      }
    });
    
    new GetGroups().execute();
  }
  
  public void onBackPressed() {
    
    super.onBackPressed();
    this.overridePendingTransition(0, 0);
  }
  
  /**
   * 
   * @author Hunter Kehoe
   * 
   * This class provides a way to asynchronously grab the groups from the remote database.
   *
   */
  private class GetGroups extends AsyncTask<Void, Void, Void> {
    
    String url = Constants.BASE_URL+"mode=ggl";
    
    protected void onPreExecute() {
      
      super.onPreExecute();
      pDialog = new ProgressDialog(FindGroup.this);
      pDialog.setMessage(getString(R.string.pleaseWait));
      pDialog.setCancelable(false);
      pDialog.show();
    }
    
    protected Void doInBackground(Void... arg0) {
      
      ServiceHandler sh = new ServiceHandler();
      String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
      //Log.d("Response: ", "> " + jsonStr);
      if (jsonStr != null) {
        
        try {
          
          JSONObject jsonObj = new JSONObject(jsonStr);
          
          groups = jsonObj.getJSONArray(Constants.GROUPS_KEY);
          
          for(int i = 0; i < groups.length(); i++) {
            
            JSONObject u = groups.getJSONObject(i);
            int id = u.getInt(Constants.ID_KEY);
            String name = u.getString(Constants.NAME_KEY);
            String className = u.getString(Constants.CLASS_KEY);
            String teacher = u.getString(Constants.TEACHER_KEY);
            
            HashMap<String,String> group = new HashMap<String,String>();
            group.put(Constants.ID_KEY, String.valueOf(id));
            group.put(Constants.NAME_KEY, name.replaceAll("\\\\", Constants.EMPTY_STRING));
            group.put("className", className);
            group.put(Constants.TEACHER_KEY, teacher);
            
            groupList.add(group);
          }
          
        } catch (JSONException e) {
          
          //Log.d("Error: ", "catch in JSON");
          e.printStackTrace();
        }
        
      } else {
        //Log.e("ServiceHandler", "Couldn't get any data from url");
      }
      
      return null;
    }
    
    protected void onPostExecute(Void result) {
      
      super.onPostExecute(result);
      
      if(pDialog.isShowing()) {
        
        pDialog.dismiss();
      }
      
      ListAdapter adapter = new SimpleAdapter(FindGroup.this,
                          groupList,
                          R.layout.group_list_item,
                          new String[] {Constants.ID_KEY, Constants.NAME_KEY, "className", Constants.TEACHER_KEY},
                          new int[] {R.id.id,R.id.name,R.id.className,R.id.teacher});
      
      lvGroups.setAdapter(adapter);
    }
  }
  
  /*private class Group {
    private String name, className, teacher, time, day;
    
    public Group() {
      name = "";
      className = "";
      teacher = "";
      time = "";
      day = "";
    }
    
    public Group(String n,String cn,String t,String ti, String d) {
      name = n;
      className = cn;
      teacher = t;
      time = ti;
      day = d;
    }
    
    public String getName() {
      return name;
    }
    
    public String getClassName() {
      return className;
    }
    
    public String getTeacher() {
      return teacher;
    }
    
    public String getTime() {
      return time;
    }
    
    public String getDay() {
      return day;
    }
    
    public String toString() {
      return getName();
    }
  }*/

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }
  
  // Google Analytics
  public void onStart() {
    
    super.onStart();
    EasyTracker.getInstance(this).activityStart(this);
  }
  
  public void onStop() {
    
    super.onStop();
    EasyTracker.getInstance(this).activityStop(this);
  }
}




Java Source Code List

com.dargueta.groupsmart.ChangePassword.java
com.dargueta.groupsmart.Constants.java
com.dargueta.groupsmart.CourseSelect.java
com.dargueta.groupsmart.CreateGroup.java
com.dargueta.groupsmart.Feedback.java
com.dargueta.groupsmart.FindGroup.java
com.dargueta.groupsmart.GroupInfo.java
com.dargueta.groupsmart.Login.java
com.dargueta.groupsmart.Main.java
com.dargueta.groupsmart.MajorSelect.java
com.dargueta.groupsmart.Profile.java
com.dargueta.groupsmart.Register.java
com.dargueta.groupsmart.ServiceHandler.java
com.dargueta.groupsmart.Settings.java
com.dargueta.groupsmart.UpdateGroup.java
com.dargueta.groupsmart.UpdateProfile.java