AGRIMATE PROJECT FINAL REVIEW PHY1999 – INTRODUCTION TO INNOVATIVE PROJECTS PRESENTED BY: Keshav (18BCE1041) Apoorv Anupam (18BCE1154)
Udayan Chaudhary (18BCE1218) Mehul Malik (18BCE1097) Slot: TG1 Faculty: Dr. Bornali Sarma (SCHOOL OF ADVANCED SCIENCES)
CERTIFICATE This is to certify that the project work entitled Agrimate that is being submitted by our group for the project component of Introduction to Innovative Projects i.e. PHY1999, is record of bona fide work under my supervision. The contents of this project, in full or in parts, have neither been taken from any other source nor have been submitted for any other PHY course.
Place: Chennai Date: 14/03/2019
Signature of faculty: (Dr. Bornali Sarma)
Acknowledgement
We would like to express our special thanks of gratitude to our Physics faculty, Dr. Bornali Sarma, who gave us the golden opportunity to do this wonderful project named AGRIMATE, which also helped us in doing a lot of Research and we came to know about a lot of new things and explored different fields of computer science. We are really thankful to you. Secondly, we would also like to thank our group members for making this a reality and giving life to this project within the limited time frame. Also, we would like to thank our parents because whatever we have with us, is because of them. We would also like to thank the farmers who work day and night so that we can sleep with our stomach satisfied.
Abstract Agriculture is the prime sector of employment in our country with 50% of the Indian work force. Yet, it contributes only 17-18% to the total GDP of India. One of the main causes for the continuing degradation in agricultural trends is cultivation of crops that are not feasible for soil conditions. There is a gap between the cultivators and the data of agricultural experts. We can use this project's architecture to fill the gap between farmers and the experts. The common issue existing among the Indian farmers is that they don’t choose the right crop based on their soil requirements. Due to this they face a serious setback in productivity. This problem of the farmers has been addressed through precision agriculture. Precision agriculture is a modern farming technique that uses research data of soil characteristics, soil types, crop yield data collection and suggests the farmers the right crop based on their sitespecific parameters. In this Project, we are proposing a semantic web-based architecture which is linked with a database and a machine learning based recommender to generate agricultural recommendations, using spatial data and agricultural knowledge base and datasets provided by the government under Digital India program.
This method is actually characterized by a highly detailed soil, crop database collected from the farm, crop provided by agricultural experts, govt. Of India datasets and achievement of parameters such as soil through soil testing lab dataset. The data from soil testing lab given to recommendation system it will use the collect data and do ensemble model with majority voting technique using support vector machine (SVM) and ANN as learners to recommend a crop for site specific parameter with high accuracy and efficiency. It will also provide the complete diagnosis of soil quality for future reference and it will also compare the soil quality of different regions which are similar to a certain degree in the database and recommend the attribute that are being used in the other sites with the user's attributes.
WHAT IS AGRIMATE? 1) IT IS AN ANDROID BASED APPLICATION, MADE USING JAVA, SQL LITE, AND JSON. 2) FOCUSED ON SOLVING THE PROBLEMS FACED BY INDIAN FARMERS, BY PROVIDING A “ONE STOP DESTINATION” FOR ALL THEIR INFORMATION NEEDS. 3) APP IS BASED IN HINDI
FEATURES OF AGRIMATE (INNOVATION) 1) MADE IN ANDROID STUDIO, WITH LOW QUALITY GRAPHIC MODULES, IN ORDER TO OPERATE WITH LOW SPEED DATA CONNECTIVITY. 2) DEVELOPED IN THREE BASIC STAGES: - A) BASIC APP DESIGN, B) MODULAR DATABASE, C) WEB BASED RECOMMENDATION SYSTEM. 3) IT CONNECTS VARIOUS RESOURCES PROVIDED BY GOVT. OF INDIA AT A SINGLE PLACE. 4) RESOURCES INCLUDE KISAN PORTAL,KISAN HELPLINE, http://agmarknet.gov.in (MARKETPLACE FOR COMMODITIES).
CODE INVOLVED ACTIVITIES
BAZAAR ACTIVITY import android.content.Intent; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.util.Log;
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.ViewPagerAdapter;
/** * Created by sukhbir on 15/8/16. */ public class BazaarActivity2 extends AppCompatActivity {
private TabLayout tabLayout; private ViewPager viewPager; private ViewPagerAdapter viewPagerAdapter; String state,district;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bazaar_information2);
Intent i = getIntent();
if(i!=null){ state=i.getStringExtra(SurveyActivity.STATE); district=i.getStringExtra(SurveyActivity.DISTRICT); }
tabLayout = (TabLayout) findViewById(R.id.tabs); viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(),state,district); viewPager.setAdapter(viewPagerAdapter); viewPager.setOffscreenPageLimit(3);
final TabLayout.Tab home = tabLayout.newTab(); final TabLayout.Tab inbox = tabLayout.newTab(); final TabLayout.Tab star = tabLayout.newTab();
tabLayout.addTab(home, 0); tabLayout.addTab(inbox, 1); tabLayout.addTab(star, 2);
tabLayout.setupWithViewPager(viewPager);
Calendar cal2 = Calendar.getInstance();
String date = new SimpleDateFormat("dd/MM/yyyy").format(new Date(cal2.getTimeInMillis()));
cal2.add(Calendar.DATE, -1); Date dt2 = new Date(cal2.getTimeInMillis());
String date_pre = new SimpleDateFormat("dd/MM/yyyy").format(dt2);
cal2.add(Calendar.DATE,-1); Date dt3 = new Date(cal2.getTimeInMillis()); String date_pre_pre = new SimpleDateFormat("dd/MM/yyyy").format(dt3);
tabLayout.getTabAt(0).setText(date_pre_pre); tabLayout.getTabAt(1).setText(date); tabLayout.getTabAt(2).setText(date_pre);
tabLayout.getTabAt(1).select();
tabLayout.setTabTextColors(ContextCompat.getColorStateList(this, R.drawable.selector_colors)); tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(this, R.color.indicator));
}
}
BAZAAR INFO
import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.NavUtils; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast;
import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest;
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject;
import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Map;
import akssmk.com.agriculturalapp.modals.ItemBazaar; import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.BazaarAdapter; import akssmk.com.agriculturalapp.application.MyApplication; import akssmk.com.agriculturalapp.application.MySingleton; import akssmk.com.agriculturalapp.utilities.Connection;
/** * Created by sukhbir on 14/8/16. */ public class BazaarInformation extends AppCompatActivity {
RecyclerView recyclerView; BazaarAdapter adapter; String state,district,day; TextView state_view,district_view,day_view; FloatingActionButton btn; ProgressBar p; String day_string; private ArrayList
items;
private String URL_FINAL = "http://kharita.freevar.com/agriculture_market.php"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bazaar_information); Intent i = getIntent(); items = new ArrayList<>(); state_view=(TextView)findViewById(R.id.state); district_view=(TextView)findViewById(R.id.district); day_view=(TextView)findViewById(R.id.arrival_date); p = (ProgressBar) findViewById(R.id.progress); p.setVisibility(View.VISIBLE);
recyclerView=(RecyclerView)findViewById(R.id.crop_recycler); if(i!=null){ state=i.getStringExtra(SurveyActivity.STATE);
district=i.getStringExtra(SurveyActivity.DISTRICT); day=i.getStringExtra(SurveyActivity.CROP);
state_view.setText(state); district_view.setText(district); if(day!=null){ Date d=new Date();
if(day_view.equals("Today")){ day_string=new SimpleDateFormat("dd/MM/yyyy").format(d); }else if(day_view.equals("Yesterday")){ Date d1=new Date(); d1.setDate(d.getDate()- 1); day_string=new SimpleDateFormat("dd/MM/yyyy").format(d1); }else{ Date d2=new Date(); d2.setDate(d.getDate()-2); day_string=new SimpleDateFormat("dd/MM/yyyy").format(d2); }
day_view.setText(day_string);
Log.v("formatted date",day_string); }
sendRequest(URL_FINAL,state,district,"13/08/2016"); }
}
private void sendRequest(String url, final String State, final String District, final String Day)
{ StringRequest s = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { try { Log.v("RESPONSE", response);
JSONObject result = new JSONObject(response); JSONArray a=result.getJSONArray("result"); for(int i=0;i
JSONObject w=a.getJSONObject(i); ItemBazaar item = new ItemBazaar(); market = w.getString("Market"); commodity = w.getString("Commodity"); variety = w.getString("Variety"); min = w.getString("Min"); max = w.getString("Max"); avg = w.getString("Modal");
item.setMarket(market); item.setCommodity(commodity); item.setMin(min); item.setMax(max); item.setAvg(avg); item.setVariety(variety);
items.add(item);
} adapter=new BazaarAdapter(BazaarInformation.this,items); recyclerView.setLayoutManager(new LinearLayoutManager(BazaarInformation.this)); recyclerView.setAdapter(adapter); p.setVisibility(View.GONE);
} catch (JSONException e) { e.printStackTrace(); }
} }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { if(!new Connection(BazaarInformation.this).isInternet()){ Toast.makeText(BazaarInformation.this, "No Internet Connection", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(BazaarInformation.this, "Some error occured", Toast.LENGTH_SHORT).show(); } } }){ @Override protected Map<String, String rel="nofollow"> getParams() throws AuthFailureError { Map<String,String> map = new HashMap<>(); map.put("State",State); map.put("District",District); map.put("Date",Day); return map; } };
MySingleton.getInstance(MyApplication.getAppContext()).addToRequestQueue(s);
} @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) {
finish();
} return true; default: return super.onOptionsItemSelected(item); } } }
CROP DETAIL ACTIVITY import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ProgressBar;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.CropActivityAdapter; import akssmk.com.agriculturalapp.modals.CropDetailItem;
public class CropDetailActivity extends AppCompatActivity {
RecyclerView mRecyclerView; private CropActivityAdapter adapter; ProgressBar bar;
ArrayList items;
Integer[] headings={R.string.wheat_h1,R.string.wheat_h2,R.string.wheat_h3,R.string.wheat_h4,R.string.whea t_h5, R.string.wheat_h6,R.string.wheat_h7,R.string.wheat_h8,R.string.wheat_h9,R.string.wheat_h10, R.string.wheat_h11,R.string.wheat_h12,R.string.wheat_h13,R.string.wheat_h14};
Integer[] data1={R.string.wh1,R.string.wh2,R.string.wh3,R.string.wh4,R.string.wh5,R.string.wh6,R.string.wh7, R.string.wh8,R.string.wh9,R.string.wh10,R.string.wh11,R.string.wh12,R.string.wh13,R.string.wh14};
Integer[] data2={R.string.ph1,R.string.ph2,R.string.ph3,R.string.ph4,R.string.ph5,R.string.ph6,R.string.ph7, R.string.ph8,R.string.ph9,R.string.ph10,R.string.ph11,R.string.ph12,R.string.ph13,R.string.ph14};
Integer[] data3={R.string.ad1,R.string.ad2,R.string.ad3,R.string.ad4,R.string.ad5,R.string.ad6,R.string.ad7,
R.string.ad8,R.string.ad9,R.string.ad10,R.string.ad11};
Integer[] headings_a={ R.string.ah1,R.string.ah2,R.string.ah3,R.string.ah4,R.string.ah5,R.string.ah6,R.string.ah7, R.string.ah8,R.string.ah9,R.string.ah10,R.string.ah11};
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_recycler);
Integer[] temp1=null; Integer[] temp2=null;
int num=(int)getIntent().getIntExtra("number",1); if(num==1){ temp1=data1; }else if(num==2){ temp1=data2; }else if(num==3){ temp2=data3; }
mRecyclerView=(RecyclerView)findViewById(R.id.recycler); bar=(ProgressBar)findViewById(R.id.progress); bar.setVisibility(View.GONE); items=new ArrayList<>();
int l; if(num==3)
l=headings_a.length; else l=headings.length;
for(int i=0;i
items.add(item); }
adapter=new CropActivityAdapter(this,items); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(adapter);
} } CROP PRODUCTION ACTIVITY package akssmk.com.agriculturalapp.activities;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ProgressBar;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.CropActivityAdapter; import akssmk.com.agriculturalapp.modals.CropDetailItem;
public class CropDetailActivity extends AppCompatActivity {
RecyclerView mRecyclerView; private CropActivityAdapter adapter; ProgressBar bar;
ArrayList items;
Integer[] headings={R.string.wheat_h1,R.string.wheat_h2,R.string.wheat_h3,R.string.wheat_h4,R.string.whea t_h5, R.string.wheat_h6,R.string.wheat_h7,R.string.wheat_h8,R.string.wheat_h9,R.string.wheat_h10, R.string.wheat_h11,R.string.wheat_h12,R.string.wheat_h13,R.string.wheat_h14};
Integer[] data1={R.string.wh1,R.string.wh2,R.string.wh3,R.string.wh4,R.string.wh5,R.string.wh6,R.string.wh7, R.string.wh8,R.string.wh9,R.string.wh10,R.string.wh11,R.string.wh12,R.string.wh13,R.string.wh14};
Integer[] data2={R.string.ph1,R.string.ph2,R.string.ph3,R.string.ph4,R.string.ph5,R.string.ph6,R.string.ph7,
R.string.ph8,R.string.ph9,R.string.ph10,R.string.ph11,R.string.ph12,R.string.ph13,R.string.ph14};
Integer[] data3={R.string.ad1,R.string.ad2,R.string.ad3,R.string.ad4,R.string.ad5,R.string.ad6,R.string.ad7, R.string.ad8,R.string.ad9,R.string.ad10,R.string.ad11};
Integer[] headings_a={ R.string.ah1,R.string.ah2,R.string.ah3,R.string.ah4,R.string.ah5,R.string.ah6,R.string.ah7, R.string.ah8,R.string.ah9,R.string.ah10,R.string.ah11};
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_recycler);
Integer[] temp1=null; Integer[] temp2=null;
int num=(int)getIntent().getIntExtra("number",1); if(num==1){ temp1=data1; }else if(num==2){ temp1=data2; }else if(num==3){ temp2=data3; }
mRecyclerView=(RecyclerView)findViewById(R.id.recycler); bar=(ProgressBar)findViewById(R.id.progress); bar.setVisibility(View.GONE);
items=new ArrayList<>();
int l; if(num==3) l=headings_a.length; else l=headings.length;
for(int i=0;i
items.add(item); }
adapter=new CropActivityAdapter(this,items); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(adapter);
} } GRAPH ACTIVITY
package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.MenuItem; import android.widget.TextView; import android.widget.Toast;
import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.ValueDependentColor; import com.jjoe64.graphview.series.BarGraphSeries; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.DataPointInterface; import com.jjoe64.graphview.series.OnDataPointTapListener; import com.jjoe64.graphview.series.Series;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.modals.ItemSurvey;
public class GraphActivity extends AppCompatActivity { GraphView graphView; TextView text; private ArrayList items;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_graph);
text = (TextView) findViewById(R.id.graph_des);
Intent in = getIntent(); text.setText("Year vs Production(Tonnes/Hectare)");
Log.v("hi", "111");
if(in != null){ Bundle extra=getIntent().getBundleExtra("extra"); items = (ArrayList) extra.getSerializable("All"); //Log.v("data123",items.get(0).getYear()); }
ArrayList<String> year = new ArrayList<>(); ArrayList<String> area = new ArrayList<>(); ArrayList<String> production = new ArrayList<>();
double total = 0;
DataPoint[] ar = new DataPoint[items.size()];
for(int i=0;i
Log.v("value", items.get(i).getProduction() + " " + items.get(i).getArea());
total=Double.valueOf(Double.parseDouble(items.get(i).getProduction())/Double.parseDouble(items. get(i).getArea())); Log.v("check",""+items.get(i).getYear().substring(2,4)); DataPoint temp = new DataPoint(Double.parseDouble((items.get(i).getYear())),total ); ar[i] = temp; }
/* graphView = (GraphView) findViewById(R.id.indi_graph); BarGraphSeries series = new BarGraphSeries<>(ar);
/* graphView.getViewport().setXAxisBoundsManual(true); graphView.getViewport().setYAxisBoundsManual(true); graphView.getViewport().setMaxX(items.size() + 1); graphView.getViewport().setMaxY(10); graphView.getViewport().setMinX(0); graphView.getViewport().setMinY(0);
graphView.addSeries(series); graphView.getViewport().setScrollable(true);
series.setColor(Color.parseColor("#b2b2ff"));*/ GraphView graph = (GraphView) findViewById(R.id.indi_graph); BarGraphSeries series = new BarGraphSeries(ar);
graph.addSeries(series); series.setValueDependentColor(new ValueDependentColor() { @Override
public int get(DataPoint data) { return Color.rgb((int) data.getX() * 255 / 4, (int) Math.abs(data.getY() * 255 / 6), 100); } }); series.setDrawValuesOnTop(true); series.setValuesOnTopColor(Color.RED);
series.setSpacing(40); /* StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph); staticLabelsFormatter.setHorizontalLabels(new String[]{"", "Year", ""}); staticLabelsFormatter.setVerticalLabels(new String[]{"", "", "Production"}); graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter); */ series.setOnDataPointTapListener(new OnDataPointTapListener() { @Override public void onTap(Series series, DataPointInterface dataPoint) { Toast.makeText(GraphActivity.this, "" + dataPoint, Toast.LENGTH_LONG).show(); } });
// draw values on top Log.v("Datapoint", ar[0].getX() + ""); Double start = Double.parseDouble(ar[0].getX()+""); Double end = Double.parseDouble(ar[items.size()-1].getX()+""); Log.v("Start", start + ""); Log.v("End",end+""); graph.setTitleTextSize(5); graph.getGridLabelRenderer().setTextSize(18f); graph.getGridLabelRenderer().reloadStyles(); graph.getViewport().setXAxisBoundsManual(true); graph.getViewport().setMinX(start - 1);
graph.getViewport().setMaxX(end + 1); graph.getViewport().setScrollable(true); graph.getViewport().setScalable(true);
}
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) {
finish();
} return true; default: return super.onOptionsItemSelected(item); } } }
HORTICULTURE ACTIVITY
package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView;
import android.view.View;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.adapters.HorticultureAdapter; import akssmk.com.agriculturalapp.adapters.MainAdapter; import akssmk.com.agriculturalapp.modals.MainListItem; import akssmk.com.agriculturalapp.R;
public class HorticultureActivity extends AppCompatActivity {
RecyclerView mRecyclerView; ArrayList<MainListItem> list; HorticultureAdapter adapter;
Integer[] imageUrls={R.drawable.mango_main,R.drawable.banana_main,R.drawable.guava_main};
Integer[] englishTexts={R.string.horticulture_item1_en,R.string.horticulture_item2_en, R.string.horticulture_item3_en};
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_recycler);
if(getSupportActionBar()!=null){ getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
list=new ArrayList<>();
Intent[] links=getIntents();
for (int i=0;i
item.setImageUrl(imageUrls[i]); item.setIntent(links[i]); list.add(item); }
adapter=new HorticultureAdapter(this,list);
mRecyclerView=(RecyclerView)findViewById(R.id.recycler);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(adapter);
findViewById(R.id.progress).setVisibility(View.GONE); }
public Intent[] getIntents(){ Intent i1=new Intent(this, HorticultureDetailActivity.class); Intent i2=new Intent(this, HorticultureDetailActivity.class); Intent i3=new Intent(this, HorticultureDetailActivity.class); i1.putExtra("number",1); i2.putExtra("number",2); i3.putExtra("number",3);
Intent[] links={ i1, i2, i3 };
return links; }
}
Hhorticulture detail activity package akssmk.com.agriculturalapp.activities;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ProgressBar;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.HorticultureDetailAdapter; import akssmk.com.agriculturalapp.modals.HorticultureDetailItem;
public class HorticultureDetailActivity extends AppCompatActivity {
RecyclerView mRecyclerView; private HorticultureDetailAdapter adapter; ProgressBar bar;
ArrayList items;
String[] heading_m_b;
String[] heading_g;
Integer[] images_m={R.drawable.h1,R.drawable.h2,R.drawable.h3,R.drawable.h4,R.drawable.h5,R.drawable.h 6,R.drawable.h7,R.drawable.h8,R.drawable.h9,R.drawable.h10,R.drawable.h11,R.drawable.h12};
Integer[] images_b={R.drawable.bh1,R.drawable.h2,R.drawable.bh3,R.drawable.h4,R.drawable.h5,R.drawable .h6,R.drawable.h7,R.drawable.h8,R.drawable.h9,R.drawable.h10,R.drawable.h11,R.drawable.bh12};
Integer[] images_g={R.drawable.gh1,R.drawable.h2,R.drawable.gh3,R.drawable.h4,R.drawable.h5,R.drawable .h6,R.drawable.h7,R.drawable.h8,R.drawable.h9,R.drawable.h10,R.drawable.h11,R.drawable.gh12};
Integer[] data1={R.string.md1,R.string.md2,R.string.md3,R.string.md4,R.string.md5,R.string.md6,R.string.md7 , R.string.md8,R.string.md9,R.string.md10,R.string.md11,R.string.md12};
Integer[] data2={R.string.bd1,R.string.bd2,R.string.bd3,R.string.bd4,R.string.bd5,R.string.bd6,R.string.bd7, R.string.bd8,R.string.bd9,R.string.bd10,R.string.bd11,R.string.bd12};
Integer[] data3={R.string.gd1,R.string.gd2,R.string.gd3,R.string.gd4,R.string.gd5,R.string.gd6,R.string.gd7, R.string.gd8,R.string.gd9, R.string.gd10, R.string.gd11, R.string.gd12};
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_recycler);
Integer[] temp1=null; Integer[] temp2=null; Integer[] temp3=null;
heading_m_b=getResources().getStringArray(R.array.headings_m_b);
heading_g=getResources().getStringArray(R.array.headings_g);
int num=(int)getIntent().getIntExtra("number",1); String title="Horticulture Crops"; if(num==1){ temp1=data1; temp2=images_m; title="Mango Crop Details"; }else if(num==2){ temp1=data2; temp2=images_b; title="Banana Crop Details"; }else if(num==3){ temp1=data3; temp2=images_g; title="Guava Crop Details"; }
getSupportActionBar().setTitle(title);
mRecyclerView=(RecyclerView)findViewById(R.id.recycler); bar=(ProgressBar)findViewById(R.id.progress); bar.setVisibility(View.GONE); items=new ArrayList<>(); for(int i=0;i
adapter=new HorticultureDetailAdapter(this,items); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(adapter);
} }
MAIN ACTIVITY package akssmk.com.agriculturalapp.activities;
import android.Manifest; import android.annotation.TargetApi;
import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.text.method.LinkMovementMethod; import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.TextView; import android.widget.Toast;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.modals.MainListItem; import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.MainAdapter;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private ArrayList<MainListItem> list; private RecyclerView recyclerView; private MainAdapter adapter;
private Integer[] imageUrls={R.raw.crop_production_opt,R.raw.treat,R.raw.shc2,R.drawable.production_main,R.draw able.horticulture_main,R.raw.govp};
private Integer[] hindiTexts={R.string.crop_production_card_title_hi,R.string.treatment_card_title_hi, R.string.storage_card_title_hi,R.string.survey_card_title_hi, R.string.horticulture_card_title_hi,R.string.policy_card_title_hi};
private Integer[] englishTexts={R.string.crop_production_card_title_en,R.string.treatment_card_title_en, R.string.storage_card_title_en,R.string.survey_card_title_en, R.string.horticulture_card_title_en,R.string.policy_card_title_en};
private String[] backgroundColors={"#35e372","#a4f075","#ffff4d","#70dbdb","#cef63c","#ff9f80"};
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);
Intent[] links={ new Intent(MainActivity.this, CropProductionActivity.class), new Intent(MainActivity.this, SelectProblem.class), new Intent(MainActivity.this, SoilHealthActivity.class), new Intent(MainActivity.this, SurveyActivity.class),
new Intent(MainActivity.this, HorticultureActivity.class), new Intent(MainActivity.this, Select_Policy.class) };
list = new ArrayList<>(); for(int i=0;i
item.setImageUrl(imageUrls[i]); item.setHindiText(hindiTexts[i]); item.setEnglishText(englishTexts[i]); item.setBackgroundColor(backgroundColors[i]); item.setIntent(links[i]);
list.add(item); }
adapter = new MainAdapter(this,list);
recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter);
Log.v("version", Build.VERSION.SDK_INT + "");
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this);
findViewById(R.id.progress).setVisibility(View.GONE); }
@Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } }
@TargetApi(Build.VERSION_CODES.M) @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId();
if (id == R.id.bazar_rates_nav) { Log.v("###","hello"); startActivity(new Intent(MainActivity.this, Select_State_Bazaar.class));
}else if(id == R.id.state_agricultural_nav){ startActivity(new Intent(MainActivity.this,StateDepartment.class));
}else if(id == R.id.about_nav){
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(String.format("%1$s", getString(R.string.about))); builder.setMessage(getResources().getText(R.string.about_text)); builder.setPositiveButton("OK", null); builder.setIcon(R.mipmap.ic_launcher); AlertDialog welcomeAlert = builder.create(); welcomeAlert.show(); ((TextView) welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.g etInstance());
}else if(id == R.id.contactus_nav){ Intent intent = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("[email protected]") + "?subject=" + Uri.encode("Feedback") + "&body=" + Uri.encode("");
Uri uri = Uri.parse(uriText); intent.setData(uri); startActivity(Intent.createChooser(intent, "Send Email"));
}else if(id == R.id.call_link){ if(Build.VERSION.SDK_INT<23){ Intent in=new Intent(Intent.ACTION_CALL, Uri.parse("tel:+91" + "18001801551"));
try{ startActivity(in); }catch (android.content.ActivityNotFoundException ex){ Toast.makeText(getApplicationContext(), "yourActivity is not founded", Toast.LENGTH_SHORT).show(); }
}else{ int REQUEST_CODE_ASK_PERMISSIONS = 123;
int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.CALL_PHONE); if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] {Manifest.permission.CALL_PHONE}, REQUEST_CODE_ASK_PERMISSIONS);
}
Intent in=new Intent(Intent.ACTION_CALL, Uri.parse("tel:+91" + "18001801551"));
try{ startActivity(in); }catch (Exception ex){ Toast.makeText(getApplicationContext(), "Permissions required", Toast.LENGTH_SHORT).show(); }
}
return true;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } } SELECT POLICY
package akssmk.com.agriculturalapp.activities;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.PolicyAdapter;
public class Select_Policy extends AppCompatActivity {
private PolicyAdapter adapter; private ArrayList list; private RecyclerView recyclerView;
private String[] links;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_recycler);
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar); //setSupportActionBar(toolbar);
links=getResources().getStringArray(R.array.policies_link);
list = new ArrayList<>();
list=new ArrayList();
String[] array=getResources().getStringArray(R.array.policies);
for(int i=0;i<array.length;i++){ list.add(array[i]); }
adapter = new PolicyAdapter(this,list,links);
recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter);
findViewById(R.id.progress).setVisibility(View.GONE); } } SELECT STATE BAZAAR
package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; 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.ArrayAdapter; import android.widget.Button; import android.widget.ProgressBar; import android.widget.Spinner; import android.widget.Toast;
import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest;
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject;
import java.util.ArrayList; import java.util.HashMap; import java.util.Map;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.application.MyApplication; import akssmk.com.agriculturalapp.application.MySingleton; import akssmk.com.agriculturalapp.utilities.Connection;
public class Select_State_Bazaar extends AppCompatActivity {
public static final String STATE ="state" ;
public static final String DISTRICT = "district"; public static final String CROP ="crop" ; private Spinner spinner1, spinner2, spinner3; private Button btnSubmit; private static final String URL_DISTRICT = "http://kharita.freevar.com/district_market.php"; private static final String URL_CROP = "http://kharita.freevar.com/crop.php"; ArrayAdapter<String> arrayAdapter,arrayAdapter1,arrayAdapter2; ArrayList<String> list11,list2; ProgressBar p;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_survey); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); spinner1= (Spinner) findViewById(R.id.spinner1); spinner2= (Spinner) findViewById(R.id.spinner2); btnSubmit= (Button) findViewById(R.id.btnSubmit); p = (ProgressBar) findViewById(R.id.progress); list11=new ArrayList<>(); list11.add("Select District"); list2=new ArrayList<>();
arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,getResources().getStrin gArray(R.array.State_market)); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter(arrayAdapter); spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView> parent, View view, int position, long id) { String k = arrayAdapter.getItem(parent.getSelectedItemPosition());
if (k != null && spinner1.getSelectedItemPosition() != 0) { list11 = new ArrayList<>(); list11.add("Select District"); sendRequest(URL_DISTRICT, "State", k); } else if(spinner1.getSelectedItemPosition()==0) { list11 = new ArrayList<>(); list11.add("Select District"); arrayAdapter1 = new ArrayAdapter<String>(Select_State_Bazaar.this, android.R.layout.simple_spinner_dropdown_item, list11); arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(arrayAdapter1); } }
@Override public void onNothingSelected(AdapterView> parent) {
} });
arrayAdapter1=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,list11); arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(arrayAdapter1);
arrayAdapter2=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,getResources().getStrin gArray(R.array.Days)); arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
btnSubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
String State = arrayAdapter.getItem(spinner1.getSelectedItemPosition()); String District = arrayAdapter1.getItem(spinner2.getSelectedItemPosition());
if (spinner1.getSelectedItemPosition() != 0&& !District.equals("Select District")) {
Intent intent = new Intent(Select_State_Bazaar.this, BazaarActivity2.class); intent.putExtra(STATE, State); intent.putExtra(DISTRICT, District); startActivity(intent); }
} });
p.setVisibility(View.GONE);
}
private void sendRequest(final String url, final String key, final String value){ Log.v("K", value + ""); p.setVisibility(View.VISIBLE);
StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) {
Log.v("RESPONSE",response);
if(url==URL_DISTRICT){ arrayAdapter1.clear(); list11.add("Select District"); list11=parseJson(response,"result","District"); arrayAdapter1.addAll(list11); arrayAdapter1.notifyDataSetChanged(); } else if (url==URL_CROP){ arrayAdapter2.clear(); list2.add("Select Crop"); list2=parseJson(response,"result","Crop"); arrayAdapter2.addAll(list2); arrayAdapter2.notifyDataSetChanged(); } Log.d("data",response); p.setVisibility(View.GONE); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { p.setVisibility(View.GONE); if(!new Connection(Select_State_Bazaar.this).isInternet()){ Toast.makeText(Select_State_Bazaar.this, "No Internet Connection", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(Select_State_Bazaar.this, "Some error occured", Toast.LENGTH_SHORT).show(); } } }){
@Override protected Map<String, String> getParams() throws AuthFailureError { Map<String,String> map=new HashMap<>(); map.put(key,value); return map; } };
MySingleton.getInstance(MyApplication.getAppContext()).addToRequestQueue(stringRequest); }
private ArrayList<String> parseJson(String key,String array_name,String object_name){ ArrayList<String> list=new ArrayList<>(); try { JSONObject j=new JSONObject(key); JSONArray a=j.getJSONArray(array_name); for(int i=0;i
} } catch (JSONException e) { e.printStackTrace(); } return list; }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home:
if (NavUtils.getParentActivityName(this) != null) {
finish();
} return true; default: return super.onOptionsItemSelected(item); } } } Select problem package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.ProblemShowAdapter;
public class SelectProblem extends AppCompatActivity {
private ProblemShowAdapter adapter; private RecyclerView recyclerView;
private String[] links;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_recycler);
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar); //setSupportActionBar(toolbar);
Intent[] links=getIntents();
String[] array=getResources().getStringArray(R.array.problems);
adapter = new ProblemShowAdapter(this,array,links);
recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter);
findViewById(R.id.progress).setVisibility(View.GONE); }
public Intent[] getIntents(){ Intent i1=new Intent(this, TreatmentDetail.class); Intent i2=new Intent(this, TreatmentDetail.class); Intent i3=new Intent(this, TreatmentDetail.class); Intent i4=new Intent(this, TreatmentDetail.class); i1.putExtra("image",R.drawable.t1); i2.putExtra("image",R.drawable.t2);
i3.putExtra("image",R.drawable.t3); i4.putExtra("image",R.drawable.t4);
i1.putExtra("info",R.string.prob1); i2.putExtra("info",R.string.prob2); i3.putExtra("info",R.string.prob3); i4.putExtra("info",R.string.prob4);
Intent[] links={ i1, i2, i3 , i4};
return links; } }
SOIL HEALTH ACTIVITY package akssmk.com.agriculturalapp.activities;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Spinner; import android.widget.Toast;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.SoilHealthCardAdapter; import akssmk.com.agriculturalapp.modals.ItemHealthCard; import akssmk.com.agriculturalapp.utilities.SqliteHelper;
public class SoilHealthActivity extends AppCompatActivity {
private SqliteHelper helper; private Spinner spinner1,spinner2; private Button btnSubmit; ArrayList<String rel="nofollow"> list1,list2; ArrayList card_list; SoilHealthCardAdapter adapter;
ArrayAdapter<String> arrayAdapter1,arrayAdapter2; RecyclerView recyclerView;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_soil_health);
spinner1= (Spinner) findViewById(R.id.spinner1); spinner2= (Spinner) findViewById(R.id.spinner2); btnSubmit= (Button) findViewById(R.id.btnSubmit); list1=new ArrayList<>(); list2=new ArrayList<>();
helper=new SqliteHelper(this);
list1=helper.getDistinctStates();
Toast.makeText(SoilHealthActivity.this,"Find Nearest Soil Test Laboratory",Toast.LENGTH_LONG).show();
arrayAdapter1=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,list1); arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter(arrayAdapter1);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView> parent, View view, int position, long id) { Log.v("positon1", "" + position); list2 = helper.getDistricts((String) spinner1.getItemAtPosition(position)); arrayAdapter2 = new ArrayAdapter<String>(SoilHealthActivity.this, android.R.layout.simple_spinner_dropdown_item, list2); arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(arrayAdapter2); }
@Override public void onNothingSelected(AdapterView> parent) {
} });
list2.add("Select District");
arrayAdapter2=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,list2); arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(arrayAdapter2);
btnSubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (spinner1.getSelectedItemPosition()!=0 && spinner2.getSelectedItemPosition() != 0) { card_list= helper.getHealthCard(spinner1.getSelectedItem()+"",spinner2.getSelectedItem()+""); adapter=new SoilHealthCardAdapter(SoilHealthActivity.this,card_list);
recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(SoilHealthActivity.this)); recyclerView.setAdapter(adapter); } } }); }
}
SPLASH ACTIVITY
package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.AppCompatActivity;
import akssmk.com.agriculturalapp.R;
/**
* Created by sukhbir on 3/7/16. */ public class SplashActivity extends AppCompatActivity {
private int SPLASH_LENGTH=800;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(SplashActivity.this, MainActivity.class); startActivity(i); finish(); } }, SPLASH_LENGTH); } } STATE DEPARTMENT
package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar;
import android.view.View;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.ProblemShowAdapter; import akssmk.com.agriculturalapp.adapters.StateDepartmentAdapter;
public class StateDepartment extends AppCompatActivity {
private StateDepartmentAdapter adapter; private RecyclerView recyclerView;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_recycler);
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar); //setSupportActionBar(toolbar);
String[] array=getResources().getStringArray(R.array.States); String[] links=getResources().getStringArray(R.array.state_links);
adapter = new StateDepartmentAdapter(this,array,links);
recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter);
findViewById(R.id.progress).setVisibility(View.GONE);
} }
SURVEY ACTIVITY
package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; 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.ArrayAdapter; import android.widget.Button; import android.widget.ProgressBar; import android.widget.Spinner; import android.widget.Toast;
import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest;
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject;
import java.util.ArrayList; import java.util.HashMap; import java.util.Map;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.application.MyApplication; import akssmk.com.agriculturalapp.application.MySingleton; import akssmk.com.agriculturalapp.utilities.Connection;
public class SurveyActivity extends AppCompatActivity{
public static final String STATE ="state" ; public static final String DISTRICT = "district"; public static final String CROP ="crop" ; private Spinner spinner1, spinner2, spinner3; private Button btnSubmit; private static final String URL_DISTRICT = "http://kharita.freevar.com/district.php"; private static final String URL_CROP = "http://kharita.freevar.com/crop.php"; ArrayAdapter<String> arrayAdapter,arrayAdapter1,arrayAdapter2; ArrayList<String> list11,list2; ProgressBar p;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_survey2); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); spinner1= (Spinner) findViewById(R.id.spinner1); spinner2= (Spinner) findViewById(R.id.spinner2); spinner3= (Spinner) findViewById(R.id.spinner3);
btnSubmit= (Button) findViewById(R.id.btnSubmit); p = (ProgressBar) findViewById(R.id.progress); list11=new ArrayList<>(); list11.add("Select District"); list2=new ArrayList<>(); list2.add("Select Crop"); p.setVisibility(View.VISIBLE);
arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,getResources().getStrin gArray(R.array.States)); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter(arrayAdapter); spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView> parent, View view, int position, long id) { String k = arrayAdapter.getItem(parent.getSelectedItemPosition()); if (k != null && spinner1.getSelectedItemPosition() != 0) {
sendRequest(URL_DISTRICT, "State", k); } else if (spinner1.getSelectedItemPosition() == 0) { list11 = new ArrayList<>(); list11.add("Select District"); arrayAdapter1 = new ArrayAdapter<String>(SurveyActivity.this, android.R.layout.simple_spinner_dropdown_item, list11); arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(arrayAdapter1);
list2 = new ArrayList<>(); list2.add("Select Crop"); arrayAdapter2 = new ArrayAdapter<String>(SurveyActivity.this, android.R.layout.simple_spinner_dropdown_item, list2);
arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner3.setAdapter(arrayAdapter2); } }
@Override public void onNothingSelected(AdapterView> parent) {
} });
arrayAdapter1=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,list11); arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(arrayAdapter1); spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView> parent, View view, int position, long id) {
String k = arrayAdapter1.getItem(parent.getSelectedItemPosition()); if (k != null && spinner2.getSelectedItemPosition() != 0) { Log.d("Key", k); sendRequest(URL_CROP, "District", k); } else if (spinner2.getSelectedItemPosition() == 0) {
list2 = new ArrayList<>(); list2.add("Select Crop"); arrayAdapter2 = new ArrayAdapter<String>(SurveyActivity.this, android.R.layout.simple_spinner_dropdown_item, list2); arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner3.setAdapter(arrayAdapter2); }
}
@Override public void onNothingSelected(AdapterView> parent) {
} });
arrayAdapter2=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,list2); arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner3.setAdapter(arrayAdapter2);
btnSubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
String State = arrayAdapter.getItem(spinner1.getSelectedItemPosition()); String District = arrayAdapter1.getItem(spinner2.getSelectedItemPosition()); String Crop = arrayAdapter2.getItem(spinner3.getSelectedItemPosition());
if (!State.isEmpty() && !District.isEmpty() && !Crop.isEmpty() && (!State.equals("Select State")) && (!District.equals("Select District")) && (!Crop.equals("Select Crop"))) {
Intent intent = new Intent(SurveyActivity.this, SurveyInformation.class); intent.putExtra(STATE, State); intent.putExtra(DISTRICT, District); intent.putExtra(CROP, Crop);
startActivity(intent); }
} });
p.setVisibility(View.GONE);
}
private void sendRequest(final String url, final String key, final String value){
p.setVisibility(View.VISIBLE);
StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { if(url==URL_DISTRICT){ arrayAdapter1.clear(); list11.add("Select District"); list11=parseJson(response,"result","District"); arrayAdapter1.addAll(list11); arrayAdapter1.notifyDataSetChanged(); } else if (url==URL_CROP){ arrayAdapter2.clear(); list2.add("Select Crop"); list2=parseJson(response,"result","Crop"); arrayAdapter2.addAll(list2); arrayAdapter2.notifyDataSetChanged();
} Log.d("data",response); p.setVisibility(View.GONE); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { p.setVisibility(View.GONE); if(!new Connection(SurveyActivity.this).isInternet()){ Toast.makeText(SurveyActivity.this, "No Internet Connection", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(SurveyActivity.this, "Some error occured", Toast.LENGTH_SHORT).show(); } } }){ @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String,String> map=new HashMap<>(); map.put(key,value); return map; } };
MySingleton.getInstance(MyApplication.getAppContext()).addToRequestQueue(stringRequest); }
private ArrayList<String> parseJson(String key,String array_name,String object_name){ ArrayList<String> list=new ArrayList<>(); try { JSONObject j=new JSONObject(key);
JSONArray a=j.getJSONArray(array_name); for(int i=0;i
} } catch (JSONException e) { e.printStackTrace(); } return list; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) {
finish();
} return true; default: return super.onOptionsItemSelected(item); } } }
SURVEY INFO
package akssmk.com.agriculturalapp.activities;
import android.content.Intent; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.NavUtils; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.MenuItem; import android.view.View; import android.widget.ProgressBar; import android.widget.TextView;
import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest;
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject;
import java.util.ArrayList; import java.util.HashMap; import java.util.Map;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.adapters.SurveyAdapter; import akssmk.com.agriculturalapp.application.MyApplication; import akssmk.com.agriculturalapp.application.MySingleton; import akssmk.com.agriculturalapp.modals.ItemSurvey;
public class SurveyInformation extends AppCompatActivity {
RecyclerView recyclerView; SurveyAdapter adapter; String state,district,crop; TextView state_view,district_view,crop_view; FloatingActionButton btn; ProgressBar p; private ArrayList items;
private String URL_FINAL = "http://kharita.freevar.com/agriculture.php"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_survey_information); Intent i = getIntent(); items = new ArrayList<>(); state_view=(TextView)findViewById(R.id.state); district_view=(TextView)findViewById(R.id.district); crop_view=(TextView)findViewById(R.id.crop); p = (ProgressBar) findViewById(R.id.progress); p.setVisibility(View.VISIBLE);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.graph); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(items.size()!=0) { Intent i = new Intent(SurveyInformation.this,GraphActivity.class);
Bundle extra=new Bundle(); extra.putSerializable("All",items); i.putExtra("extra",extra); startActivity(i); }
} });
recyclerView=(RecyclerView)findViewById(R.id.crop_recycler); if(i!=null){ state=i.getStringExtra(SurveyActivity.STATE); district=i.getStringExtra(SurveyActivity.DISTRICT); crop=i.getStringExtra(SurveyActivity.CROP);
state_view.setText(state); district_view.setText(district); crop_view.setText(crop); sendRequest(URL_FINAL,state,district,crop); }
}
private void sendRequest(String url, final String State, final String District, final String Crop) { StringRequest s = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject result = new JSONObject(response);
JSONArray a=result.getJSONArray("result"); for(int i=0;i
} adapter=new SurveyAdapter(SurveyInformation.this,items); recyclerView.setLayoutManager(new LinearLayoutManager(SurveyInformation.this)); recyclerView.setAdapter(adapter); p.setVisibility(View.GONE);
} catch (JSONException e) { e.printStackTrace(); }
} }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) {
} }){ @Override
protected Map<String, String rel="nofollow"> getParams() throws AuthFailureError { Map<String,String> map = new HashMap<>(); map.put("State",State); map.put("District",District); map.put("Crop",Crop); return map; } }; MySingleton.getInstance(MyApplication.getAppContext()).addToRequestQueue(s);
} @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) {
finish();
} return true; default: return super.onOptionsItemSelected(item); } } }
TREATMENT DETAIL
package akssmk.com.agriculturalapp.activities;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.widget.ImageView; import android.widget.TextView;
import akssmk.com.agriculturalapp.R;
public class TreatmentDetail extends AppCompatActivity {
ImageView imageView; TextView textView;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.treatment_coordinator);
int image=(Integer) getIntent().getIntExtra("image",R.drawable.t1); int text=(Integer)getIntent().getIntExtra("info",0);
Log.v("###",text+"");
imageView=(ImageView)findViewById(R.id.imageView); textView=(TextView)findViewById(R.id.detail);
imageView.setImageResource(image); textView.setText(text); }
}
WEB ACTIVITY
package akssmk.com.agriculturalapp.activities;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast;
import akssmk.com.agriculturalapp.R;
public class WebActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web);
String link=getIntent().getStringExtra("link"); String title_temp=getIntent().getStringExtra("title");
if(title_temp!=null){ getSupportActionBar().setTitle(title_temp); }
WebView webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient());
webView.getSettings().setBuiltInZoomControls(true);
Toast.makeText(WebActivity.this, "Please Wait...", Toast.LENGTH_SHORT).show();
if(link==null){ webView.loadUrl("http://www.google.com"); }else{ webView.loadUrl(link); } }
}
ADAPTERS BAZAAR ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.modals.ItemBazaar; import akssmk.com.agriculturalapp.R;
/** * Created by kharita on 7/8/16. */ public class BazaarAdapter extends RecyclerView.Adapter{ private ArrayList items; private Context context;
public BazaarAdapter(Context context, ArrayList items){ this.context=context; this.items=items; }
@Override public BazaarAdapter.viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_bazaar_recycler,parent,false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, int position) { holder.market_view.setText(items.get(position).getMarket()); holder.commodity_view.setText(items.get(position).getCommodity()); holder.variety_view.setText(items.get(position).getVariety()); holder.min_view.setText(items.get(position).getMin()); holder.max_view.setText(items.get(position).getMax()); holder.avg_view.setText(items.get(position).getAvg());
}
@Override public int getItemCount() { return items.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{ private TextView market_view,commodity_view,variety_view; private TextView min_view,max_view,avg_view;
public viewHolder(View itemView) { super(itemView); market_view=(TextView)itemView.findViewById(R.id.market); commodity_view=(TextView)itemView.findViewById(R.id.commodity); variety_view=(TextView)itemView.findViewById(R.id.variety); min_view=(TextView)itemView.findViewById(R.id.min); max_view=(TextView)itemView.findViewById(R.id.max); avg_view=(TextView)itemView.findViewById(R.id.avg); } } }
CROP ACTIVITY ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View;
import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.modals.CropDetailItem; import akssmk.com.agriculturalapp.R;
/** * Created by sukhbir on 6/8/16. */ public class CropActivityAdapter extends RecyclerView.Adapter { private ArrayList list=new ArrayList<>(); private Context context; private int layout= R.layout.crop_detail_item;
private boolean check[];
public CropActivityAdapter(Context context, ArrayList items) { this.context = context; this.list=items; check=new boolean[items.size()]; }
public CropActivityAdapter(Context context, ArrayList items, int layout) { this.context = context; this.list=items; this.layout=layout; }
@Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(layout,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(final viewHolder holder, final int position) { // holder.linear.setBackgroundColor(Color.parseColor(list.get(position).getBackgroundColor())); holder.heading.setText(list.get(position).getHeading()); holder.detail.setText(list.get(position).getDetail());
if(check[position]==false){ holder.detail.setVisibility(View.GONE);
}else{ holder.detail.setVisibility(View.VISIBLE); }
holder.linear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(holder.detail.getVisibility()==View.GONE){ holder.detail.setVisibility(View.VISIBLE); check[position]=true;
}else{ holder.detail.setVisibility(View.GONE); check[position]=false;
}
} }); }
@Override public int getItemCount() { return list.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{
TextView heading,detail; LinearLayout linear;
public viewHolder(View itemView) { super(itemView); linear=(LinearLayout)itemView.findViewById(R.id.linear);
heading= (TextView) itemView.findViewById(R.id.heading); detail= (TextView) itemView.findViewById(R.id.detail); } } }
HORTICULTURE ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.graphics.Color; import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.modals.MainListItem;
/** * Created by sukhbir on 6/8/16. */ public class HorticultureAdapter extends RecyclerView.Adapter { private ArrayList<MainListItem> list=new ArrayList<>(); private Context context; private int layout= R.layout.item_horticulture_card;
public HorticultureAdapter(Context context, ArrayList<MainListItem> items) { this.context = context; this.list=items; }
public HorticultureAdapter(Context context, ArrayList<MainListItem> items, int layout) { this.context = context; this.list=items; this.layout=layout;
}
@Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(layout,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, final int position) {
holder.englishText.setText(list.get(position).getEnglishText()); holder.imageView.setImageResource(list.get(position).getImageUrl());
holder.card.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(list.get(position).getIntent()!=null) context.startActivity(list.get(position).getIntent()); } }); }
@Override public int getItemCount() { return list.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{ ImageView imageView;
TextView englishText; CardView card;
public viewHolder(View itemView) { super(itemView); card=(CardView) itemView.findViewById(R.id.card); imageView= (ImageView) itemView.findViewById(R.id.imageView); englishText= (TextView) itemView.findViewById(R.id.english_title); } } } HORTICULTURE DETAIL ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.modals.HorticultureDetailItem;
/** * Created by sukhbir on 6/8/16.
*/ public class HorticultureDetailAdapter extends RecyclerView.Adapter { private ArrayList list=new ArrayList<>(); private Context context; private int layout= R.layout.horticulture_detail_item;
private boolean check[];
public HorticultureDetailAdapter(Context context, ArrayList items) { this.context = context; this.list=items; check=new boolean[items.size()]; }
public HorticultureDetailAdapter(Context context, ArrayList items, int layout) { this.context = context; this.list=items; this.layout=layout; }
@Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(layout,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(final viewHolder holder, final int position) { // holder.linear.setBackgroundColor(Color.parseColor(list.get(position).getBackgroundColor())); holder.heading.setText(list.get(position).getHeading());
holder.detail.setText(list.get(position).getDetail()); holder.image.setImageResource(list.get(position).getImage());
if(check[position]==false){ holder.detail.setVisibility(View.GONE);
}else{ holder.detail.setVisibility(View.VISIBLE); }
holder.linear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(holder.detail.getVisibility()==View.GONE){ holder.detail.setVisibility(View.VISIBLE); check[position]=true;
}else{ holder.detail.setVisibility(View.GONE); check[position]=false;
} } }); }
@Override public int getItemCount() { return list.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{
TextView heading,detail; ImageView image; LinearLayout linear;
public viewHolder(View itemView) { super(itemView); linear=(LinearLayout)itemView.findViewById(R.id.linear); image=(ImageView)itemView.findViewById(R.id.imageView); heading= (TextView) itemView.findViewById(R.id.heading); detail= (TextView) itemView.findViewById(R.id.detail); } } }
MAIN ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.modals.MainListItem; import akssmk.com.agriculturalapp.R;
/** * Created by sukhbir on 6/8/16. */ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.viewHolder> { private ArrayList<MainListItem> list=new ArrayList<>(); private Context context; private int layout= R.layout.item_main;
public MainAdapter(Context context,ArrayList<MainListItem> items) { this.context = context; this.list=items; }
public MainAdapter(Context context,ArrayList<MainListItem> items,int layout) { this.context = context; this.list=items; this.layout=layout; }
@Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(layout,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, final int position) { holder.linear.setBackgroundColor(Color.parseColor(list.get(position).getBackgroundColor())); holder.englishText.setText(list.get(position).getEnglishText()); holder.hindiText.setText(list.get(position).getHindiText()); holder.imageView.setImageResource(list.get(position).getImageUrl());
holder.linear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(list.get(position).getIntent()!=null) context.startActivity(list.get(position).getIntent()); } }); }
@Override public int getItemCount() { return list.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{ ImageView imageView; TextView hindiText,englishText; LinearLayout linear;
public viewHolder(View itemView) { super(itemView); linear=(LinearLayout)itemView.findViewById(R.id.linear); imageView= (ImageView) itemView.findViewById(R.id.imageView); hindiText= (TextView) itemView.findViewById(R.id.hindi_title);
englishText= (TextView) itemView.findViewById(R.id.english_title); } } } POLICY ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.content.Intent; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.activities.WebActivity;
public class PolicyAdapter extends RecyclerView.Adapter { private String[] links; private ArrayList<String> list=new ArrayList<>(); private Context context;
public PolicyAdapter(Context context,ArrayList<String> list,String[] links) { this.links=links; this.context = context;
this.list=list; }
public void refresh(ArrayList<String> list){ this.list=list; notifyItemRangeChanged(0,list.size()); } @Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_category,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, final int position) { holder.textView.setText(list.get(position));
holder.card.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent browser =new Intent(context, WebActivity.class); browser.putExtra("link",links[position]); context.startActivity(browser); } }); }
@Override public int getItemCount() {
return list.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{ TextView textView; CardView card; public viewHolder(View itemView) { super(itemView); textView= (TextView) itemView.findViewById(R.id.title); card= (CardView) itemView.findViewById(R.id.card); } } }
PROBLEM SHOW ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.modals.MainListItem;
/** * Created by sukhbir on 6/8/16. */ public class ProblemShowAdapter extends RecyclerView.Adapter { private String[] array; private Intent[] links; private Context context; private int layout= R.layout.item_category;
public ProblemShowAdapter(Context context, String[] array,Intent[] links) { this.context = context; this.array=array; this.links=links; }
@Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(layout,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, final int position) {
holder.textView.setText(array[position]);
holder.card.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { context.startActivity(links[position]); } }); }
@Override public int getItemCount() { return array.length; }
public static class viewHolder extends RecyclerView.ViewHolder{ TextView textView; CardView card;
public viewHolder(View itemView) { super(itemView); card=(CardView) itemView.findViewById(R.id.card); textView= (TextView) itemView.findViewById(R.id.title); } } }
SOIL HEALTH CARD ADAPTER package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater;
import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.modals.ItemHealthCard;
/** * Created by sukhbir on 6/8/16. */ public class SoilHealthCardAdapter extends RecyclerView.Adapter<SoilHealthCardAdapter.viewHolder> { private ArrayList list=new ArrayList<>(); private Context context; private int layout= R.layout.item_health_card;
public SoilHealthCardAdapter(Context context, ArrayList items) { this.context = context; this.list=items; }
public SoilHealthCardAdapter(Context context, ArrayList items, int layout) { this.context = context; this.list=items; this.layout=layout; }
@Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(layout,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, final int position) { //
holder.linear.setBackgroundColor(Color.parseColor(list.get(position).getBackground())); holder.id.setText("LAB ID: "+list.get(position).getId()); holder.name.setText(list.get(position).getName());
}
@Override public int getItemCount() { return list.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{ TextView id,name; LinearLayout linear;
public viewHolder(View itemView) { super(itemView); linear=(LinearLayout)itemView.findViewById(R.id.linear); id= (TextView) itemView.findViewById(R.id.lab_id); name= (TextView) itemView.findViewById(R.id.lab_name); } } }
STATE DEPARTMENT ADAPTER package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.content.Intent; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.activities.GraphActivity; import akssmk.com.agriculturalapp.activities.WebActivity;
/** * Created by sukhbir on 6/8/16. */ public class StateDepartmentAdapter extends RecyclerView.Adapter<StateDepartmentAdapter.viewHolder> { private String[] array; private String[] links; private Context context; private int layout= R.layout.item_category;
public StateDepartmentAdapter(Context context, String[] array, String[] links) { this.context = context; this.array=array; this.links=links; }
@Override public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(layout,parent, false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, final int position) {
holder.textView.setText(array[position+1]);
holder.card.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(context, WebActivity.class); intent.putExtra("link",links[position]); intent.putExtra("title","State Agriculture Department"); context.startActivity(intent); } }); }
@Override public int getItemCount() { return array.length-1; }
public static class viewHolder extends RecyclerView.ViewHolder{ TextView textView; CardView card;
public viewHolder(View itemView) { super(itemView); card=(CardView) itemView.findViewById(R.id.card); textView= (TextView) itemView.findViewById(R.id.title); } } } SURVEY ADAPTER package akssmk.com.agriculturalapp.adapters;
import android.content.Context; import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.modals.ItemSurvey;
/** * */ public class SurveyAdapter extends RecyclerView.Adapter<SurveyAdapter.viewHolder>{ private ArrayList items; private Context context;
public SurveyAdapter(Context context,ArrayList items){ this.context=context; this.items=items; }
@Override public SurveyAdapter.viewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_crop_recycler,parent,false); return new viewHolder(view); }
@Override public void onBindViewHolder(viewHolder holder, int position) { holder.year_view.setText(items.get(position).getYear()); holder.area_view.setText(items.get(position).getArea()); holder.production_view.setText(items.get(position).getProduction());
if(position%2==0){ holder.cardView.setBackgroundColor(Color.parseColor("#80cbc4")); }else{ holder.cardView.setBackgroundColor(Color.parseColor("#ef9a9a")); } }
@Override public int getItemCount() { return items.size(); }
public static class viewHolder extends RecyclerView.ViewHolder{ private TextView year_view,area_view,production_view; private LinearLayout cardView;
public viewHolder(View itemView) { super(itemView); year_view=(TextView)itemView.findViewById(R.id.year); area_view=(TextView)itemView.findViewById(R.id.area); production_view=(TextView)itemView.findViewById(R.id.production); cardView=(LinearLayout)itemView.findViewById(R.id.card); } } } TAB FRAGMENT
package akssmk.com.agriculturalapp.adapters;
import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest;
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject;
import java.util.ArrayList; import java.util.HashMap; import java.util.Map;
import akssmk.com.agriculturalapp.R; import akssmk.com.agriculturalapp.application.MyApplication; import akssmk.com.agriculturalapp.application.MySingleton; import akssmk.com.agriculturalapp.modals.ItemBazaar; import akssmk.com.agriculturalapp.utilities.Connection;
public class TabFragment extends Fragment {
private String date_string; RecyclerView recyclerView; BazaarAdapter adapter; String state,district,day; TextView state_view,district_view,day_view; FloatingActionButton btn; ProgressBar p; String day_string; private ArrayList items; View view;
private String URL_FINAL = "http://kharita.freevar.com/agriculture_market.php";
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { date_string = getArguments().getString("date"); state = getArguments().getString("state"); district = getArguments().getString("district");
Log.v("dateRecieved", date_string); view = inflater.inflate(R.layout.singletab, container, false);
items = new ArrayList<>(); state_view=(TextView)view.findViewById(R.id.state); district_view=(TextView)view.findViewById(R.id.district); day_view=(TextView)view.findViewById(R.id.arrival_date); p = (ProgressBar)view.findViewById(R.id.progress);
recyclerView=(RecyclerView)view.findViewById(R.id.crop_recycler);
day=day_string; day_view.setText(date_string); state_view.setText(state); district_view.setText(district);
sendRequest(URL_FINAL,state,district,date_string);
return view; }
private void sendRequest(String url, final String State, final String District, final String Day) { p.setVisibility(View.VISIBLE);
StringRequest s = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { try { Log.v("RESPONSE#", response);
JSONObject result = new JSONObject(response); JSONArray a=result.getJSONArray("result"); for(int i=0;i
JSONObject w=a.getJSONObject(i); ItemBazaar item = new ItemBazaar(); market = w.getString("Market"); commodity = w.getString("Commodity"); variety = w.getString("Variety"); min = w.getString("Min"); max = w.getString("Max"); avg = w.getString("Modal");
item.setMarket(market); item.setCommodity(commodity); item.setMin(min); item.setMax(max); item.setAvg(avg); item.setVariety(variety);
items.add(item);
}
if(items.size()==0){ TextView text=(TextView)view.findViewById(R.id.error_message); text.setVisibility(View.VISIBLE); }else{ TextView text=(TextView)view.findViewById(R.id.error_message); text.setVisibility(View.GONE); }
adapter=new BazaarAdapter(getActivity(),items); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setAdapter(adapter); p.setVisibility(View.GONE);
} catch (JSONException e) { e.printStackTrace(); }
p.setVisibility(View.GONE);
} }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { p.setVisibility(View.GONE); if(!new Connection(getContext()).isInternet()){ Toast.makeText(getContext(), "No Internet Connection", Toast.LENGTH_SHORT).show();
}else{ Toast.makeText(getContext(), "Some error occured", Toast.LENGTH_SHORT).show(); } } }){ @Override protected Map<String, String rel="nofollow"> getParams() throws AuthFailureError { Map<String,String> map = new HashMap<>(); map.put("State",State.trim()); map.put("District",District.trim()); map.put("Date",Day.trim()); return map; } }; MySingleton.getInstance(MyApplication.getAppContext()).addToRequestQueue(s);
}
} VIEW PAGE ADAPTER
package akssmk.com.agriculturalapp.adapters;
import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter;
import java.text.SimpleDateFormat; import java.util.Calendar;
import java.util.Date;
/** * */ public class ViewPagerAdapter extends FragmentStatePagerAdapter {
TabFragment tb1,tb2,tb3; String state,district;
public ViewPagerAdapter(FragmentManager fm,String state,String district) { super(fm); this.state=state; this.district=district; }
@Override public Fragment getItem(int position) { Calendar cal2 = Calendar.getInstance();
String date = new SimpleDateFormat("dd/MM/yyyy").format(new Date(cal2.getTimeInMillis()));
cal2.add(Calendar.DATE, -1); Date dt2 = new Date(cal2.getTimeInMillis()); String date_pre = new SimpleDateFormat("dd/MM/yyyy").format(dt2);
cal2.add(Calendar.DATE,-1); Date dt3 = new Date(cal2.getTimeInMillis()); String date_pre_pre = new SimpleDateFormat("dd/MM/yyyy").format(dt3);
TabFragment temp=null;
if(position==0){ if(tb1==null){ TabFragment tf=new TabFragment(); Bundle bundle = new Bundle(); bundle.putString("date", date_pre_pre); bundle.putString("state", state); bundle.putString("district", district); tf.setArguments(bundle); tb1=tf; }
temp=tb1; }else if(position==1){ if(tb2==null){ TabFragment tf=new TabFragment(); Bundle bundle = new Bundle(); bundle.putString("date", date); bundle.putString("state", state); bundle.putString("district", district); tf.setArguments(bundle); tb2=tf; }
temp=tb2; }else{ if(tb3==null){ TabFragment tf=new TabFragment(); Bundle bundle = new Bundle(); bundle.putString("date", date_pre); bundle.putString("state", state);
bundle.putString("district", district); tf.setArguments(bundle); tb3=tf; }
temp=tb3; }
return temp; }
@Override public int getCount() { return 3; }
}
APPLICATION MY APPLICATION package akssmk.com.agriculturalapp.application;
import android.app.Application; import android.content.Context;
public class MyApplication extends Application { private static MyApplication myApplication ; @Override public void onCreate() { super.onCreate(); myApplication=this; } public static synchronized MyApplication getInstance() { return myApplication; } public static Context getAppContext(){ return myApplication.getApplicationContext(); } } MY SINGLETON package akssmk.com.agriculturalapp.application;
import android.content.Context; import android.graphics.Bitmap; import android.support.v4.util.LruCache;
import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.toolbox.ImageLoader; import com.android.volley.toolbox.Volley;
/** * */ public class MySingleton { private static MySingleton mInstance;
private RequestQueue mRequestQueue; private ImageLoader mImageLoader; private static Context mCtx;
private MySingleton(Context context) { mCtx = context; mRequestQueue = getRequestQueue();
mImageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() { private final LruCache<String, Bitmap> cache = new LruCache<String, Bitmap>(20);
@Override public Bitmap getBitmap(String url) { return cache.get(url); }
@Override public void putBitmap(String url, Bitmap bitmap) { cache.put(url, bitmap); } }); }
public static synchronized MySingleton getInstance(Context context) { if (mInstance == null) { mInstance = new MySingleton(context); } return mInstance; }
public RequestQueue getRequestQueue() { if (mRequestQueue == null) { // getApplicationContext() is key, it keeps you from leaking the // Activity or BroadcastReceiver if someone passes one in. mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext()); } return mRequestQueue; }
public void addToRequestQueue(Request req) { getRequestQueue().add(req); }
public ImageLoader getImageLoader() { return mImageLoader; } }
MODALS CROP package akssmk.com.agriculturalapp.modals;
import java.util.ArrayList;
/** * */ public class CropDetailItem {
private Integer heading; private Integer detail; private Integer image;
public Integer getImage() { return image; }
public void setImage(Integer image) { this.image = image; }
public Integer getHeading() { return heading; }
public void setHeading(Integer heading) { this.heading = heading; }
public Integer getDetail() { return detail; }
public void setDetail(Integer data) { this.detail = data; } } HORTICULTURE package akssmk.com.agriculturalapp.modals;
/** */ public class HorticultureDetailItem { private String heading; private Integer detail; private Integer image;
public Integer getImage() { return image; }
public void setImage(Integer image) { this.image = image; }
public String getHeading() { return heading; }
public void setHeading(String heading) { this.heading = heading; }
public Integer getDetail() { return detail; }
public void setDetail(Integer data) { this.detail = data; } }
ITEM BAZAAR package akssmk.com.agriculturalapp.modals;
import android.os.Parcel; import android.os.Parcelable;
import java.io.Serializable;
/**
*/ public class ItemBazaar implements Parcelable,Serializable{ private String market,commodity,variety,min,max,avg;
protected ItemBazaar(Parcel in) { market = in.readString(); commodity = in.readString(); variety = in.readString(); min = in.readString(); max = in.readString(); avg = in.readString(); }
public ItemBazaar() { }
public String getMarket() { return market; }
public void setMarket(String market) {
this.market = market; }
public String getCommodity() { return commodity; }
public void setCommodity(String commodity) { this.commodity = commodity; }
public String getVariety() { return variety; }
public void setVariety(String variety) { this.variety = variety; }
public String getMin() { return min; }
public void setMin(String min) { this.min = min; }
public String getMax() { return max; }
public void setMax(String max) { this.max = max; }
public String getAvg() { return avg; }
public void setAvg(String avg) { this.avg = avg; }
public static final Creator CREATOR = new Creator() { @Override public ItemBazaar createFromParcel(Parcel in) { return new ItemBazaar(in); }
@Override public ItemBazaar[] newArray(int size) { return new ItemBazaar[size]; } };
@Override public int describeContents() { return 0; }
@Override
public void writeToParcel(Parcel dest, int flags) { dest.writeString(market); dest.writeString(commodity); dest.writeString(variety); dest.writeString(min); dest.writeString(max); dest.writeString(avg); } } ITEM HEALTH CARD package akssmk.com.agriculturalapp.modals;
/** * */ public class ItemHealthCard { private String id,name; private String background;
public String getBackground() { return background; }
public void setBackground(String background) { this.background = background; }
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; } } ITEM SURVEY package akssmk.com.agriculturalapp.modals;
import android.os.Parcel; import android.os.Parcelable;
import java.io.Serializable;
/** */ public class ItemSurvey implements Parcelable,Serializable{ private String year,area,production;
protected ItemSurvey(Parcel in) { year = in.readString(); area = in.readString(); production = in.readString(); }
public ItemSurvey() { }
public static final Creator CREATOR = new Creator() { @Override public ItemSurvey createFromParcel(Parcel in) { return new ItemSurvey(in); }
@Override public ItemSurvey[] newArray(int size) { return new ItemSurvey[size]; } };
public String getYear() { return year; }
public void setYear(String year) { this.year = year; }
public String getArea() { return area; }
public void setArea(String area) { this.area = area; }
public String getProduction() { return production; }
public void setProduction(String production) { this.production = production; }
@Override public int describeContents() { return 0; }
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(year); dest.writeString(area); dest.writeString(production); } } MAIN LIST ITEM package akssmk.com.agriculturalapp.modals;
import android.content.Intent;
/** */ public class MainListItem { private int imageUrl; private int hindiText,englishText;
private String backgroundColor; private Intent intent;
public Intent getIntent() { return intent; }
public void setIntent(Intent intent) { this.intent = intent; }
public int getImageUrl() { return imageUrl; }
public void setImageUrl(int imageUrl) { this.imageUrl = imageUrl; }
public int getHindiText() { return hindiText; }
public void setHindiText(int hindiText) { this.hindiText = hindiText; }
public int getEnglishText() { return englishText; }
public void setEnglishText(int englishText) { this.englishText = englishText; }
public String getBackgroundColor() { return backgroundColor; }
public void setBackgroundColor(String backgroundColor) { this.backgroundColor = backgroundColor; } }
UTILITIES CONNECTION package akssmk.com.agriculturalapp.utilities;
import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo;
public class Connection {
Context context;
public Connection(Context context) { this.context = context; }
public boolean isInternet(){ ConnectivityManager manager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if(manager!=null){ NetworkInfo[] info = manager.getAllNetworkInfo(); if (info != null) for (int i = 0; i < info.length; i++) if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } return false; } } SQLLITE HELPER
package akssmk.com.agriculturalapp.utilities;
import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.util.Log;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
import java.util.ArrayList;
import akssmk.com.agriculturalapp.modals.ItemHealthCard;
/**
* Created by sukhbir on 19/8/16. */ public class SqliteHelper extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "soil_lab"; private static final int DATABASE_VERSION = 1;
public SqliteHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); }
public ArrayList<String> getDistinctStates(){ ArrayList<String> list = new ArrayList<String>(); String selectQuery = "SELECT distinct Column3 FROM 'Table 1'";
SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null);
list.add("Select State");
if (cursor.move(3)) { do { list.add(cursor.getString(0)); } while (cursor.moveToNext()); }
return list; }
public ArrayList<String> getDistricts(String state){ ArrayList<String> list = new ArrayList<String>();
String selectQuery = "SELECT distinct Column4 FROM 'Table 1' where Column3='"+state+"'";
SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null);
list.add("Select District");
if (cursor.moveToFirst()) { do { Log.v("district",cursor.getString(0)); list.add(cursor.getString(0)); } while (cursor.moveToNext()); }
return list; }
public ArrayList getHealthCard(String state,String district){ ArrayList list = new ArrayList<>(); String selectQuery = "SELECT Column2,Column5 FROM 'Table 1' where Column3='"+state+"' and Column4='"+district+"'" ;
SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) { do { ItemHealthCard item=new ItemHealthCard(); item.setId(cursor.getString(0)); item.setName(cursor.getString(1));
list.add(item); } while (cursor.moveToNext()); }
return list; } }