Navigation Drawer and Custom listview
Userpanel.java
package com.alexatechno.;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class Userpanel extends AppCompatActivity {
DrawerLayout mDrawerLayout;
NavigationView mNavigationView;
ArrayList<Pojo> Productlist;
ActorAdapter adapter;
Pojo actor;
String cat="",subcat="",child="",tname="",tid123="";
JsonParser jsonParser = new JsonParser();
private static final String url_check_login = "";
private static final String TAG_SUCCESS = "success";
private static final String TAG_PERSON = "person";
private static final String TAG_MESSAGE = "message";
private ProgressDialog pDialog;
String designation="",pid="";
private DatabaseAdapter dbHelper;
SQLiteDatabase sampleDB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userpanel);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mNavigationView = (NavigationView) findViewById(R.id.shitstuff);
tname= getIntent().getStringExtra("tid");
dbHelper = new DatabaseAdapter(this);
try {
dbHelper.open();
} catch (SQLException e) {
e.printStackTrace();
}
sampleDB = this.openOrCreateDatabase("rkgroup",MODE_PRIVATE, null);
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();
if (menuItem.getItemId() == R.id.cust_list) {
Intent intent = new Intent(Userpanel.this, Customerlist.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.add_team) {
Intent intent = new Intent(Userpanel.this, Addsalesteam.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.registration) {
Intent intent = new Intent(Userpanel.this, Registartrion.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.team_group) {
Intent intent = new Intent(Userpanel.this, Addteamgroup.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.team_assign) {
Intent intent = new Intent(Userpanel.this, Addteamassign.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.list_assign) {
Intent intent = new Intent(Userpanel.this, Teamassign.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.team_list) {
Intent intent = new Intent(Userpanel.this, Salesteam.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.list_group) {
Intent intent = new Intent(Userpanel.this, Teamgroup.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.add_cust) {
Intent intent = new Intent(Userpanel.this, Addcustomer.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.logout) {
Cursor cc= dbHelper.Deletelogin();
Intent intent = new Intent(Userpanel.this, Mains.class);
intent.putExtra("finish", true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finishAffinity();
finish();
}
return false;
}
});
android.support.v7.widget.Toolbar toolbar1 = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar1);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar1, R.string.app_name,
R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
try {
Cursor mCursor = dbHelper.getlogin();
if (mCursor != null) {
mCursor.moveToFirst();
for (int i = 0; i < mCursor.getCount(); i++) {
pid=mCursor.getString(2);
designation=mCursor.getString(6);
tid123=mCursor.getString(7);
System.out.println("designation"+designation);
mNavigationView.getMenu().findItem(R.id.user).setVisible(true);
mNavigationView.getMenu().findItem(R.id.user).setTitle("HI-"+ mCursor.getString(1));
if(designation.equals("Sales Executive"))
{
mNavigationView.getMenu().findItem(R.id.team_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.add_team).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_list).setVisible(false);
mNavigationView.getMenu().findItem(R.id.registration).setVisible(false);
}
if(designation.equals("Assistant Manager"))
{
mNavigationView.getMenu().findItem(R.id.team_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.add_team).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_list).setVisible(false);
mNavigationView.getMenu().findItem(R.id.registration).setVisible(false);
}
// System.out.println("designation"+designation);
mCursor.moveToNext();
}
}
} catch(Exception e){}
// new CreateLogin().execute();
Productlist = new ArrayList<Pojo>();
new JSONAsyncTask().execute("");
ListView listview = (ListView)findViewById(R.id.listView);
adapter = new ActorAdapter(getApplicationContext(), R.layout.row, Productlist,cat,designation,tname);
listview.setAdapter(adapter);
listview.setDivider(null);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView text = (TextView)view.findViewById(R.id.value1);
String tid= text.getText().toString();
TextView text1 = (TextView)view.findViewById(R.id.value2);
String tid1= text1.getText().toString();
TextView text2 = (TextView)view.findViewById(R.id.value1);
String tid2= text2.getText().toString();
// Toast.makeText(getApplication(), tid1, Toast.LENGTH_LONG).show();
if(designation.equals("M D")) {
Intent intent = new Intent(Userpanel.this, Details.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
if(designation.equals("Sales Head")) {
Intent intent = new Intent(Userpanel.this, Details.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
if(designation.equals("Sales manager")) {
Intent intent = new Intent(Userpanel.this, Details.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
if(designation.equals("Sales Executive")) {
// Toast.makeText(Userpanel.this,""+tid1+""+tid123,Toast.LENGTH_LONG).show();
if(tid1.equals(tid123)) {
Intent intent = new Intent(Userpanel.this, Salesexecustlist.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
}
if(designation.equals("Assistant Manager")) {
if(tid1.equals(tid123)) {
Intent intent = new Intent(Userpanel.this, Salesexecustlist.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
}
if(tid2.equals(tname))
{
}
}
});
}
class CreateLogin extends AsyncTask<String, String, String> {
JSONArray productObj;
/**
* Before starting background thread Show Progress Dialog
* */
boolean failure = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Userpanel.this);
pDialog.setMessage("Logged In...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("designation", designation));
params.add(new BasicNameValuePair("pid", pid));
Log.d("request!", "starting");
//Posting user data to script
JSONObject json = jsonParser.makeHttpRequest(
url_check_login, "POST", params);
// full json response
Log.d("Login attempt", json.toString());
// json success element
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Attempt!", json.toString());
productObj = json
.getJSONArray(TAG_PERSON);
// Intent intent = new Intent(Login.this, MainActivity.class);
//startActivity(intent);
// finish();
return json.getString(TAG_MESSAGE);
}
else{
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null){
//System.out.print("file_url"+file_url);
Toast.makeText(Userpanel.this, file_url + "" + productObj, Toast.LENGTH_LONG).show();
}
if (productObj != null) {
try {
// get first product object from JSON Array
JSONObject person = productObj.getJSONObject(0);
System.out.println("person"+person);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(Userpanel.this);
dialog.setMessage("Loading");
dialog.setTitle("Wait");
dialog.show();
dialog.setCancelable(false);
}
@Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
HttpPost httppost = new HttpPost(urls[0]);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("designation", designation));
params.add(new BasicNameValuePair("pid", pid));
try{ //encode login data and Hands the entity to the request.
httppost.setEntity(new UrlEncodedFormEntity(params));
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
Log.e("UnsupportedEncoding", "unable to encode some characters", e1);
return null;
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
// JSONObject jsono = new JSONObject(data);
// JSONArray jarray = jsono.getJSONArray("");
System.out.println("Data is"+data);
JSONArray jarray = new JSONArray(data);
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
actor = new Pojo();
System.out.println("Image" +object.getString("deal_close_price"));
if(object.getString("sum_deal_close_price") == "null") {
actor.setDeal_close_price(""+0);
actor.setSum_deal_close_price("0.00");
}
else if(object.getString("sum_deal_close_price").equals("null")) {
actor.setDeal_close_price(""+0);
actor.setSum_deal_close_price("0.00");
}
else
{
actor.setDeal_close_price(object.getString("sum_deal_close_price"));
actor.setSum_deal_close_price(""+object.getString("sum_deal_close_price"));
}
//actor.setDescription(object.getString("description"));
actor.setGroup_name(""+object.getString("group_name"));
actor.setTeam_id(""+object.getString("team_id"));
Productlist.add(actor);
}
return true;
}
//------------------>>
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
}
}
package com.alexatechno.;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class Userpanel extends AppCompatActivity {
DrawerLayout mDrawerLayout;
NavigationView mNavigationView;
ArrayList<Pojo> Productlist;
ActorAdapter adapter;
Pojo actor;
String cat="",subcat="",child="",tname="",tid123="";
JsonParser jsonParser = new JsonParser();
private static final String url_check_login = "";
private static final String TAG_SUCCESS = "success";
private static final String TAG_PERSON = "person";
private static final String TAG_MESSAGE = "message";
private ProgressDialog pDialog;
String designation="",pid="";
private DatabaseAdapter dbHelper;
SQLiteDatabase sampleDB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userpanel);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mNavigationView = (NavigationView) findViewById(R.id.shitstuff);
tname= getIntent().getStringExtra("tid");
dbHelper = new DatabaseAdapter(this);
try {
dbHelper.open();
} catch (SQLException e) {
e.printStackTrace();
}
sampleDB = this.openOrCreateDatabase("rkgroup",MODE_PRIVATE, null);
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();
if (menuItem.getItemId() == R.id.cust_list) {
Intent intent = new Intent(Userpanel.this, Customerlist.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.add_team) {
Intent intent = new Intent(Userpanel.this, Addsalesteam.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.registration) {
Intent intent = new Intent(Userpanel.this, Registartrion.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.team_group) {
Intent intent = new Intent(Userpanel.this, Addteamgroup.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.team_assign) {
Intent intent = new Intent(Userpanel.this, Addteamassign.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.list_assign) {
Intent intent = new Intent(Userpanel.this, Teamassign.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.team_list) {
Intent intent = new Intent(Userpanel.this, Salesteam.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.list_group) {
Intent intent = new Intent(Userpanel.this, Teamgroup.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.add_cust) {
Intent intent = new Intent(Userpanel.this, Addcustomer.class);
startActivity(intent);
}
if (menuItem.getItemId() == R.id.logout) {
Cursor cc= dbHelper.Deletelogin();
Intent intent = new Intent(Userpanel.this, Mains.class);
intent.putExtra("finish", true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finishAffinity();
finish();
}
return false;
}
});
android.support.v7.widget.Toolbar toolbar1 = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar1);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar1, R.string.app_name,
R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
try {
Cursor mCursor = dbHelper.getlogin();
if (mCursor != null) {
mCursor.moveToFirst();
for (int i = 0; i < mCursor.getCount(); i++) {
pid=mCursor.getString(2);
designation=mCursor.getString(6);
tid123=mCursor.getString(7);
System.out.println("designation"+designation);
mNavigationView.getMenu().findItem(R.id.user).setVisible(true);
mNavigationView.getMenu().findItem(R.id.user).setTitle("HI-"+ mCursor.getString(1));
if(designation.equals("Sales Executive"))
{
mNavigationView.getMenu().findItem(R.id.team_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.add_team).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_list).setVisible(false);
mNavigationView.getMenu().findItem(R.id.registration).setVisible(false);
}
if(designation.equals("Assistant Manager"))
{
mNavigationView.getMenu().findItem(R.id.team_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_group).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.list_assign).setVisible(false);
mNavigationView.getMenu().findItem(R.id.add_team).setVisible(false);
mNavigationView.getMenu().findItem(R.id.team_list).setVisible(false);
mNavigationView.getMenu().findItem(R.id.registration).setVisible(false);
}
// System.out.println("designation"+designation);
mCursor.moveToNext();
}
}
} catch(Exception e){}
// new CreateLogin().execute();
Productlist = new ArrayList<Pojo>();
new JSONAsyncTask().execute("");
ListView listview = (ListView)findViewById(R.id.listView);
adapter = new ActorAdapter(getApplicationContext(), R.layout.row, Productlist,cat,designation,tname);
listview.setAdapter(adapter);
listview.setDivider(null);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView text = (TextView)view.findViewById(R.id.value1);
String tid= text.getText().toString();
TextView text1 = (TextView)view.findViewById(R.id.value2);
String tid1= text1.getText().toString();
TextView text2 = (TextView)view.findViewById(R.id.value1);
String tid2= text2.getText().toString();
// Toast.makeText(getApplication(), tid1, Toast.LENGTH_LONG).show();
if(designation.equals("M D")) {
Intent intent = new Intent(Userpanel.this, Details.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
if(designation.equals("Sales Head")) {
Intent intent = new Intent(Userpanel.this, Details.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
if(designation.equals("Sales manager")) {
Intent intent = new Intent(Userpanel.this, Details.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
if(designation.equals("Sales Executive")) {
// Toast.makeText(Userpanel.this,""+tid1+""+tid123,Toast.LENGTH_LONG).show();
if(tid1.equals(tid123)) {
Intent intent = new Intent(Userpanel.this, Salesexecustlist.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
}
if(designation.equals("Assistant Manager")) {
if(tid1.equals(tid123)) {
Intent intent = new Intent(Userpanel.this, Salesexecustlist.class);
intent.putExtra("tid", tid1);
startActivity(intent);
}
}
if(tid2.equals(tname))
{
}
}
});
}
class CreateLogin extends AsyncTask<String, String, String> {
JSONArray productObj;
/**
* Before starting background thread Show Progress Dialog
* */
boolean failure = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Userpanel.this);
pDialog.setMessage("Logged In...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("designation", designation));
params.add(new BasicNameValuePair("pid", pid));
Log.d("request!", "starting");
//Posting user data to script
JSONObject json = jsonParser.makeHttpRequest(
url_check_login, "POST", params);
// full json response
Log.d("Login attempt", json.toString());
// json success element
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Attempt!", json.toString());
productObj = json
.getJSONArray(TAG_PERSON);
// Intent intent = new Intent(Login.this, MainActivity.class);
//startActivity(intent);
// finish();
return json.getString(TAG_MESSAGE);
}
else{
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null){
//System.out.print("file_url"+file_url);
Toast.makeText(Userpanel.this, file_url + "" + productObj, Toast.LENGTH_LONG).show();
}
if (productObj != null) {
try {
// get first product object from JSON Array
JSONObject person = productObj.getJSONObject(0);
System.out.println("person"+person);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(Userpanel.this);
dialog.setMessage("Loading");
dialog.setTitle("Wait");
dialog.show();
dialog.setCancelable(false);
}
@Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
HttpPost httppost = new HttpPost(urls[0]);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("designation", designation));
params.add(new BasicNameValuePair("pid", pid));
try{ //encode login data and Hands the entity to the request.
httppost.setEntity(new UrlEncodedFormEntity(params));
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
Log.e("UnsupportedEncoding", "unable to encode some characters", e1);
return null;
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
// JSONObject jsono = new JSONObject(data);
// JSONArray jarray = jsono.getJSONArray("");
System.out.println("Data is"+data);
JSONArray jarray = new JSONArray(data);
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
actor = new Pojo();
System.out.println("Image" +object.getString("deal_close_price"));
if(object.getString("sum_deal_close_price") == "null") {
actor.setDeal_close_price(""+0);
actor.setSum_deal_close_price("0.00");
}
else if(object.getString("sum_deal_close_price").equals("null")) {
actor.setDeal_close_price(""+0);
actor.setSum_deal_close_price("0.00");
}
else
{
actor.setDeal_close_price(object.getString("sum_deal_close_price"));
actor.setSum_deal_close_price(""+object.getString("sum_deal_close_price"));
}
//actor.setDescription(object.getString("description"));
actor.setGroup_name(""+object.getString("group_name"));
actor.setTeam_id(""+object.getString("team_id"));
Productlist.add(actor);
}
return true;
}
//------------------>>
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
}
}
package com.alexatechno.; /** * Created by Naveen&jyoti on 8/9/2016. */ public class Pojo { private String deal_close_price; private String sum_deal_close_price; private String group_name; private String team_id; public Pojo() { } public Pojo(String deal_close_price, String sum_deal_close_price, String group_name, String team_id) { this.deal_close_price = deal_close_price; this.sum_deal_close_price = sum_deal_close_price; this.group_name = group_name; this.team_id = team_id; } public String getDeal_close_price() { return deal_close_price; } public void setDeal_close_price(String deal_close_price) { this.deal_close_price = deal_close_price; } public String getSum_deal_close_price() { return sum_deal_close_price; } public void setSum_deal_close_price(String sum_deal_close_price) { this.sum_deal_close_price = sum_deal_close_price; } public String getGroup_name() { return group_name; } public void setGroup_name(String group_name) { this.group_name = group_name; } public String getTeam_id() { return team_id; } public void setTeam_id(String team_id) { this.team_id = team_id; } }
Adapter class
package com.alexatechno.;
/**
 * Created by Naveen&jyoti on 8/9/2016.
 */
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
    @SuppressWarnings("ALL")
    public class ActorAdapter extends ArrayAdapter<Pojo> {
        String size11="",size22="",size33="",size44="",q11="",q22="",q33="",q44="",sizeofpro="",tid="";
        //ImageLoader imageLoader;
        ArrayList<Pojo> productlist;
        LayoutInflater vi;
        int Resource;
        ViewHolder holder;
        String cat="",subcat="",child="";
        // public ImageLoader imageLoader;
        private  DatabaseAdapter dbHelper;
        String pid1="";
        SQLiteDatabase sampleDB;
        static Button notifCount;
        static int mNotifCount = 5;
        private String[] arraySpinner;
        private Context mContext;
        View v;
        private Activity activity;
        public ActorAdapter(Context context, int resource, ArrayList<Pojo> objects,String cat,String subcat,String child) {
            super(context, resource, objects);
            mContext = context;
            vi = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            Resource = resource;
            productlist = objects;
            this.cat=cat;
            this.subcat=subcat;
            this.child=child;
            dbHelper = new DatabaseAdapter(context);
            try {
                dbHelper.open();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            sampleDB = context.openOrCreateDatabase("databasename",mContext.MODE_PRIVATE, null);
            try {
                Cursor mCursor = dbHelper.getlogin();
                if (mCursor != null) {
                    mCursor.moveToFirst();
                    for (int i = 0; i < mCursor.getCount(); i++) {
                        tid=mCursor.getString(7);
                    }
                }
            } catch(Exception e){}
        }
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            // convert view = design
            v = convertView;
            LayoutInflater inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         //   final  View rowView = inflater.inflate(R.layout.feed_update_count, parent, false);
            if (v == null) {
                holder = new ViewHolder();
                v = vi.inflate(Resource, null);
                holder.teamname =(TextView) v.findViewById(R.id.teamname);
                holder.price = (TextView) v.findViewById(R.id.price);
                //  holder.tvDescription = (TextView) v.findViewById(R.id.tvDescriptionn);
                holder.value1 = (TextView) v.findViewById(R.id.value1);
                holder.value2 = (TextView) v.findViewById(R.id.value2);
                v.setTag(holder);
            } else {
                holder = (ViewHolder) v.getTag();
            }
            //  new DownloadImageTask(holder.imageview).execute(productlist.get(position).getImage());
       /* try {
            holder.imageview = (ImageView)v.findViewById(ivImage);
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(productlist.get(position).getImage()).getContent());
            holder.imageview.setImageBitmap(bitmap);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }*/
            holder.teamname.setText(""+productlist.get(position).getGroup_name());
            if(productlist.get(position).getSum_deal_close_price().equals(null)) {
                holder.price.setText("INR. "+0);
            }
            else
            {
                holder.price.setText("INR. " + productlist.get(position).getSum_deal_close_price());
            }
            // holder.tvDescription.setText(productlist.get(position).getDescription());
            holder.value1.setText(" " + productlist.get(position).getDeal_close_price());
            holder.value2.setText(""+productlist.get(position).getTeam_id());
            //View popupButton = rowView.findViewById(R.id.badge);
            //v.setOnCreateContextMenuListener(new Product());
            //v.setOnCreateContextMenuListener();
           // System.out.println("tid"+productlist.get(position).getTeam_id());
            if(productlist.get(position).getTeam_id().contains(tid))
            {
                System.out.println("tid"+productlist.get(position).getTeam_id());
            }
            return v;
        }
        /* public static void setMenuItem(String title){
              Menu menu = (Menu) mContext.getMenu();
              MenuItem quantity = (MenuItem) menu.findItem(R.id.notif_count);
              quantity.setTitle(title);
          }*/
        static class ViewHolder {
            public TextView teamname;
            public TextView price;
            // public TextView tvDescription;
            public TextView value1;
            public TextView value2;
        }
}
content_userpanel.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.alexatechno.rkgroup.Userpanel"
    tools:showIn="@layout/activity_userpanel">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="vertical"
        android:layout_marginTop="30dp"
        android:background="@drawable/line1"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:id="@+id/textView2"
            android:layout_gravity="center_horizontal"
            android:gravity="center"
            android:textStyle="bold"
            android:textSize="20dp"
            android:textColor="#660000" />
    </LinearLayout>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sales Reporting"
        android:id="@+id/textView4"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="5dp"
        android:textSize="20dp"
        android:textStyle="bold" />
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        tools:listitem="@layout/row"
        android:layout_marginTop="10dp" />
</LinearLayout>
</RelativeLayout>
activity_userpanel.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/drawerLayout"
    >
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.alexatechno.rkgroup.Userpanel">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>
    <include layout="@layout/content_userpanel" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/shitstuff"
app:itemTextColor="#000"
app:menu="@menu/drawermenu"
android:layout_marginTop="10dp"
    />
