SampleCode.java
public class ListActivity extends AppCompatActivity {
Toolbar toolbar;
Functions function;
SharedPreferences Pref;
ArrayList<myModel> CArrayList = new ArrayList<myModel>();
RecyclerView recyclerViewCar;
StringEntity entity = null;
AsyncHttpClient client;
JSONObject objSend;
Intent i;
String customer_id;
RelativeLayout ivBack;
TextView txtTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.car_list);
function = new Functions(ListActivity.this);
Pref = getSharedPreferences(getResources().getString(R.string.app_name), MODE_PRIVATE);
// Drawer.displayDrawer(CustomerDetailsActivity.this);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getResources().getString(R.string.act));
ivBack = (RelativeLayout) findViewById(R.id.imgback);
txtTitle = (TextView) findViewById(R.id.txttitle);
txtTitle.setText(getResources().getString(R.string.car));
//toolbar.setNavigationIcon(R.mipmap.drawer);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
recyclerViewCar = (RecyclerView) findViewById(R.id.rc_car);
recyclerViewCar.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerViewCar.setLayoutManager(layoutManager);
i = getIntent();
if (i.getExtras() != null) {
customer_id = i.getStringExtra(Constr.Tag_customer_id);
}
if (function.isOnline(toolbar, R.string.internet_not_available)) {
getSelldata(customer_id);
}
ivBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
}
public void getdata(final String customerid) {
function.show();
JSONObject get_JSONObject = function.request_json();
try {
objSend = new JSONObject(get_JSONObject.toString());
objSend.put("txtuserid", customerid);
objSend.put("user_type", "SPA");
objSend.put("txt_id", function.getUserId());
Log.e("paramSellistCustomerid", objSend.toString().trim());
} catch (JSONException e) {
e.printStackTrace();
}
try {
entity = new StringEntity(objSend.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
client = new AsyncHttpClient();
client.setTimeout(30 * 1000);
client.setMaxConnections(6);
client.post(getApplicationContext(), Constr.GETLIST, entity, "application/json", new TextHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
if (responseString != null) {
Toast.makeText(getApplicationContext(), "Fail to load data", Toast.LENGTH_LONG).show();
}
function.dismiss();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
if (statusCode == 200 && responseString != null) {
Log.e("onSuccess", responseString);
try {
JSONObject json = new JSONObject(responseString);
int success = json.getInt(Constr.TAG_SUCCESS);
if (success == 1) {
JSONArray arrList = json.getJSONArray("allnewdata");
for (int i = 0; i < arrList.length(); i++) {
JSONObject c = arrList.getJSONObject(i);
myModel obj = new myModel();
obj.set_no(c.getString(Constr.Tag_no).trim());
obj.set_pic(c.getString(Constr.Tag_act_pic).trim());
if (c != null) {
JSONArray all_jsondata = c.getJSONArray(Constr.Tag_jsonarrayname);
if (all_jsondata != null) {
for (int j = 0; j < all_jsondata.length(); j++) {
JSONObject objData = all_jsondata.getJSONObject(j);
obj.setCl_id(objData.getString(Constr.Tag_cl_id).trim());
obj.setCl_id(objData.getString(Constr.Tag_cl_details_pid).trim());
obj.setCl_name(objData.getString(Constr.Tag_cl_pname).trim());
obj.setCl_desc(objData.getString(Constr.Tag_cl_pdesc).trim());
obj.setClperson_id(objData.getString(Constr.Tag_cl_sid).trim());
obj.setCl_customer_id(objData.getString(Constr.Tag_cl_custid).trim());
obj.setCl_customer_name(objData.getString(Constr.Tag_cl_custname).trim());
obj.setCl_customer_email(objData.getString(Constr.Tag_cl_custemail).trim());
//get JSONArray in response
obj.setSellplanpkgdata(objData.getJSONArray(Constr.Tag_jsonArrayData));
/*if (objData != null) {
JSONArray all_Sdata = objData.getJSONArray(Constr.Tag_jsonArrayData);
if (all_sellobjSjData != null) {
for (int k = 0; k < all_Sdata.length(); k++) {
JSONObject objSjData = all_sellobjSjData.getJSONObject(k);
obj.setCssellsdetails_id(objSjData.getString(Constr.Tag_cldetails_id).trim());
obj.setCl_id(objSjData.getString(Constr.Tag_cl_id).trim());
obj.setClsdetails_prod_qty(objSjData.getString(Constr.Tag_cs_ssdetails_total_qty).trim());
obj.setClsdetails_pused_qty(objSjData.getString(Constr.Tag_cs_sdetails_used_qty).trim());
}
}
}*/
CArrayList.add(obj);
}
}
}
}
}
if (CArrayList.size() > 0) {
CAdapter adapter = new CarAdapter(ListActivity.this, CArrayList);
recyclerViewCar.setAdapter(adapter);
}
function.dismiss();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (Drawer.mDrawerLayout.isDrawerOpen(Drawer.flDrawerRl)) {
Drawer.mDrawerLayout.closeDrawers();
} else {
Drawer.mDrawerLayout.openDrawer(Drawer.flDrawerRl);
}
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.andy"
minSdkVersion 11
targetSdkVersion 20
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
testCompile 'junit:junit:4.12'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile files('libs/httpmime-4.0.3.jar')
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile files('libs/apache-mime4j-0.6.jar')
compile 'com.nineoldandroids:library:2.4.0+'
compile 'com.android.support:cardview-v7:25+'
//compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
//compile 'com.android.support:cardview-v7:26.0.0-alpha1'
}
public class ListActivity extends AppCompatActivity {
Toolbar toolbar;
Functions function;
SharedPreferences Pref;
ArrayList<myModel> CArrayList = new ArrayList<myModel>();
RecyclerView recyclerViewCar;
StringEntity entity = null;
AsyncHttpClient client;
JSONObject objSend;
Intent i;
String customer_id;
RelativeLayout ivBack;
TextView txtTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.car_list);
function = new Functions(ListActivity.this);
Pref = getSharedPreferences(getResources().getString(R.string.app_name), MODE_PRIVATE);
// Drawer.displayDrawer(CustomerDetailsActivity.this);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getResources().getString(R.string.act));
ivBack = (RelativeLayout) findViewById(R.id.imgback);
txtTitle = (TextView) findViewById(R.id.txttitle);
txtTitle.setText(getResources().getString(R.string.car));
//toolbar.setNavigationIcon(R.mipmap.drawer);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
recyclerViewCar = (RecyclerView) findViewById(R.id.rc_car);
recyclerViewCar.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerViewCar.setLayoutManager(layoutManager);
i = getIntent();
if (i.getExtras() != null) {
customer_id = i.getStringExtra(Constr.Tag_customer_id);
}
if (function.isOnline(toolbar, R.string.internet_not_available)) {
getSelldata(customer_id);
}
ivBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
}
public void getdata(final String customerid) {
function.show();
JSONObject get_JSONObject = function.request_json();
try {
objSend = new JSONObject(get_JSONObject.toString());
objSend.put("txtuserid", customerid);
objSend.put("user_type", "SPA");
objSend.put("txt_id", function.getUserId());
Log.e("paramSellistCustomerid", objSend.toString().trim());
} catch (JSONException e) {
e.printStackTrace();
}
try {
entity = new StringEntity(objSend.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
client = new AsyncHttpClient();
client.setTimeout(30 * 1000);
client.setMaxConnections(6);
client.post(getApplicationContext(), Constr.GETLIST, entity, "application/json", new TextHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
if (responseString != null) {
Toast.makeText(getApplicationContext(), "Fail to load data", Toast.LENGTH_LONG).show();
}
function.dismiss();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
if (statusCode == 200 && responseString != null) {
Log.e("onSuccess", responseString);
try {
JSONObject json = new JSONObject(responseString);
int success = json.getInt(Constr.TAG_SUCCESS);
if (success == 1) {
JSONArray arrList = json.getJSONArray("allnewdata");
for (int i = 0; i < arrList.length(); i++) {
JSONObject c = arrList.getJSONObject(i);
myModel obj = new myModel();
obj.set_no(c.getString(Constr.Tag_no).trim());
obj.set_pic(c.getString(Constr.Tag_act_pic).trim());
if (c != null) {
JSONArray all_jsondata = c.getJSONArray(Constr.Tag_jsonarrayname);
if (all_jsondata != null) {
for (int j = 0; j < all_jsondata.length(); j++) {
JSONObject objData = all_jsondata.getJSONObject(j);
obj.setCl_id(objData.getString(Constr.Tag_cl_id).trim());
obj.setCl_id(objData.getString(Constr.Tag_cl_details_pid).trim());
obj.setCl_name(objData.getString(Constr.Tag_cl_pname).trim());
obj.setCl_desc(objData.getString(Constr.Tag_cl_pdesc).trim());
obj.setClperson_id(objData.getString(Constr.Tag_cl_sid).trim());
obj.setCl_customer_id(objData.getString(Constr.Tag_cl_custid).trim());
obj.setCl_customer_name(objData.getString(Constr.Tag_cl_custname).trim());
obj.setCl_customer_email(objData.getString(Constr.Tag_cl_custemail).trim());
//get JSONArray in response
obj.setSellplanpkgdata(objData.getJSONArray(Constr.Tag_jsonArrayData));
/*if (objData != null) {
JSONArray all_Sdata = objData.getJSONArray(Constr.Tag_jsonArrayData);
if (all_sellobjSjData != null) {
for (int k = 0; k < all_Sdata.length(); k++) {
JSONObject objSjData = all_sellobjSjData.getJSONObject(k);
obj.setCssellsdetails_id(objSjData.getString(Constr.Tag_cldetails_id).trim());
obj.setCl_id(objSjData.getString(Constr.Tag_cl_id).trim());
obj.setClsdetails_prod_qty(objSjData.getString(Constr.Tag_cs_ssdetails_total_qty).trim());
obj.setClsdetails_pused_qty(objSjData.getString(Constr.Tag_cs_sdetails_used_qty).trim());
}
}
}*/
CArrayList.add(obj);
}
}
}
}
}
if (CArrayList.size() > 0) {
CAdapter adapter = new CarAdapter(ListActivity.this, CArrayList);
recyclerViewCar.setAdapter(adapter);
}
function.dismiss();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (Drawer.mDrawerLayout.isDrawerOpen(Drawer.flDrawerRl)) {
Drawer.mDrawerLayout.closeDrawers();
} else {
Drawer.mDrawerLayout.openDrawer(Drawer.flDrawerRl);
}
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.andy"
minSdkVersion 11
targetSdkVersion 20
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
testCompile 'junit:junit:4.12'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile files('libs/httpmime-4.0.3.jar')
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile files('libs/apache-mime4j-0.6.jar')
compile 'com.nineoldandroids:library:2.4.0+'
compile 'com.android.support:cardview-v7:25+'
//compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
//compile 'com.android.support:cardview-v7:26.0.0-alpha1'
}
No comments :
Post a Comment