Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.05 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:id="@+id/activity_main"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:stretchColumns="*"
  9. tools:context="com.example.jay.jobfinder.MainActivity">
  10.  
  11. <TableRow
  12. android:layout_width="match_parent"
  13. android:layout_height="match_parent"
  14. android:layout_marginTop="20dp">
  15.  
  16. <ImageView
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. app:srcCompat="@drawable/logo"
  20. android:id="@+id/ivLogo"
  21. android:layout_span="2"
  22. android:layout_alignParentTop="true"
  23. android:layout_centerHorizontal="true" />
  24. </TableRow>
  25.  
  26. <TableRow
  27. android:layout_width="match_parent"
  28. android:layout_height="match_parent"
  29. android:layout_marginTop="20dp">
  30.  
  31. <TextView
  32. android:layout_width="match_parent"
  33. android:layout_height="wrap_content"
  34. android:id="@+id/tvState"
  35. android:text="@string/tvState"
  36. android:layout_span="2"
  37. android:textColor="#000000"
  38. android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
  39. android:textStyle="normal|bold" />
  40. </TableRow>
  41.  
  42. <TableRow
  43. android:layout_width="match_parent"
  44. android:layout_height="match_parent"
  45. android:layout_marginTop="20dp">
  46. <Spinner
  47. android:layout_width="match_parent"
  48. android:layout_height="wrap_content"
  49. android:layout_centerHorizontal="true"
  50. android:layout_span="2"
  51. android:id="@+id/spinner_state" />
  52. </TableRow>
  53.  
  54. <TableRow
  55. android:layout_width="match_parent"
  56. android:layout_height="match_parent"
  57. android:layout_marginTop="20dp">
  58. <TextView
  59. android:layout_width="match_parent"
  60. android:layout_height="wrap_content"
  61. android:id="@+id/tvJob"
  62. android:text="@string/tvJob"
  63. android:textColor="#000000"
  64. android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
  65. android:textStyle="normal|bold" />
  66. </TableRow>
  67.  
  68. <TableRow
  69. android:layout_width="match_parent"
  70. android:layout_height="match_parent"
  71. android:layout_marginTop="20dp">
  72. <RadioGroup
  73. android:layout_width="wrap_content"
  74. android:layout_height="wrap_content"
  75. android:id="@+id/rgJob">
  76.  
  77. <RadioButton
  78. android:text="Goverment"
  79. android:layout_width="wrap_content"
  80. android:layout_height="wrap_content"
  81. android:id="@+id/radioButton2" />
  82.  
  83. <RadioButton
  84. android:text="Private"
  85. android:layout_width="wrap_content"
  86. android:layout_height="wrap_content"
  87. android:id="@+id/radioButton" />
  88. </RadioGroup>
  89. </TableRow>
  90.  
  91. <TableRow
  92. android:layout_width="match_parent"
  93. android:layout_height="match_parent"
  94. android:layout_marginTop="20dp">
  95. <Button
  96. android:text="@string/btn_search"
  97. android:layout_width="match_parent"
  98. android:layout_height="wrap_content"
  99. android:id="@+id/btnSearch"
  100. android:layout_span="2"/>
  101. </TableRow>
  102.  
  103. <TableRow
  104. android:layout_width="match_parent"
  105. android:layout_height="match_parent"
  106. android:layout_marginTop="20dp">
  107.  
  108. <TextView
  109. android:layout_width="wrap_content"
  110. android:layout_height="wrap_content"
  111. android:id="@+id/tvTag"
  112. android:layout_span="2"
  113. android:gravity="center_horizontal" />
  114.  
  115. </TableRow>
  116. </TableLayout>
  117.  
  118. package com.example.jay.jobfinder;
  119.  
  120. import android.app.Activity;
  121. import android.app.ProgressDialog;
  122. import android.content.Intent;
  123. import android.content.pm.PackageInstaller;
  124. import android.os.AsyncTask;
  125. import android.os.Bundle;
  126. import android.provider.MediaStore;
  127. import android.support.v7.app.AppCompatActivity;
  128. import android.util.Log;
  129. import android.view.View;
  130. import android.widget.AdapterView;
  131. import android.widget.ArrayAdapter;
  132. import android.widget.Button;
  133. import android.widget.ListView;
  134. import android.widget.RadioButton;
  135. import android.widget.RadioGroup;
  136. import android.widget.Spinner;
  137. import android.widget.TextView;
  138. import android.widget.Toast;
  139.  
  140. import org.apache.http.HttpEntity;
  141. import org.apache.http.HttpResponse;
  142. import org.apache.http.client.HttpClient;
  143. import org.apache.http.client.methods.HttpPost;
  144. import org.apache.http.impl.client.DefaultHttpClient;
  145. import org.json.JSONArray;
  146. import org.json.JSONObject;
  147.  
  148. import java.io.BufferedReader;
  149. import java.io.InputStream;
  150. import java.io.InputStreamReader;
  151. import java.util.ArrayList;
  152. import java.util.List;
  153.  
  154. public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener
  155. {
  156. Spinner spinner_state;
  157. Button button;
  158. String city,job;
  159. TextView textView;
  160. RadioGroup rg;
  161. RadioButton rb;
  162. private session session;
  163. int rbId;
  164.  
  165. @Override
  166. public void onCreate(Bundle savedInstanceState)
  167. {
  168. super.onCreate(savedInstanceState);
  169. setContentView(R.layout.activity_main);
  170. session = new session(getApplicationContext());
  171. button=(Button)findViewById(R.id.btnSearch);
  172. textView=(TextView)findViewById(R.id.tvTag);
  173. textView.setText(city);
  174. rg=(RadioGroup)findViewById(R.id.rgJob);
  175. spinner_state=(Spinner)findViewById(R.id.spinner_state);
  176. spinner_state.setOnItemSelectedListener(this);
  177. final List<String> state = new ArrayList<String>();
  178. state.add("Andhra Pradesh");
  179. state.add("Arunachal Pradesh");
  180. state.add("Assam");
  181. state.add("Bihar");
  182. state.add("Chandigath");
  183. state.add("Chhattisgath");
  184. state.add("Delhi");
  185. state.add("Goa");
  186. state.add("Gujarat");
  187. state.add("Haryana");
  188. state.add("Himachal Pradesh");
  189. state.add("Jharkhand");
  190. state.add("Jammu and Kashmir");
  191. state.add("Karnataka");
  192. state.add("Kerala");
  193. state.add("Madhya Pradesh");
  194. state.add("Maharashtra");
  195. state.add("Manipur");
  196. state.add("Meghalaya");
  197. state.add("Mizoram");
  198. state.add("Nagaland");
  199. state.add("Odisha");
  200. state.add("Puducherry");
  201. state.add("Punjab");
  202. state.add("Rajashtan");
  203. state.add("Sikkim");
  204. state.add("Tamil Nadu");
  205. state.add("Telangana");
  206. state.add("Tripura");
  207. state.add("Uttar Pradesh");
  208. state.add("Uttarkhand");
  209. state.add("West Bengal");
  210. ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,state);
  211. dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  212. spinner_state.setAdapter(dataAdapter);
  213. button.setOnClickListener(new View.OnClickListener() {
  214. @Override
  215. public void onClick(View v)
  216. {
  217. city=spinner_state.getSelectedItem().toString();
  218. session.setState(city);
  219.  
  220. rbId=rg.getCheckedRadioButtonId();
  221. rb=(RadioButton)findViewById(rbId);
  222. Toast.makeText(getApplicationContext(),"True",Toast.LENGTH_LONG).show();
  223. /*Intent i = new Intent(MainActivity.this, JobActivity.class);
  224. i.putExtra("data", rb.getText());
  225. startActivity(i);*/
  226. }
  227. });
  228. }
  229.  
  230. @Override
  231. public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
  232. {
  233. //city = parent.getItemAtPosition(position).toString();
  234. }
  235.  
  236. @Override
  237. public void onNothingSelected(AdapterView<?> parent)
  238. {
  239.  
  240. }
  241. }
  242.  
  243. package com.example.jay.jobfinder;
  244.  
  245. import android.app.Activity;
  246. import android.app.ProgressDialog;
  247. import android.content.Intent;
  248. import android.content.pm.PackageInstaller;
  249. import android.os.AsyncTask;
  250. import android.support.v7.app.AppCompatActivity;
  251. import android.os.Bundle;
  252. import android.text.Editable;
  253. import android.text.TextWatcher;
  254. import android.util.Log;
  255. import android.view.Menu;
  256. import android.view.MenuItem;
  257. import android.widget.EditText;
  258. import android.widget.ListView;
  259. import android.widget.Toast;
  260.  
  261. import org.apache.http.HttpEntity;
  262. import org.apache.http.HttpResponse;
  263. import org.apache.http.client.HttpClient;
  264. import org.apache.http.client.methods.HttpPost;
  265. import org.apache.http.impl.client.DefaultHttpClient;
  266. import org.json.JSONArray;
  267. import org.json.JSONObject;
  268. import java.io.BufferedReader;
  269. import java.io.InputStream;
  270. import java.io.InputStreamReader;
  271. import java.util.ArrayList;
  272. import java.util.Locale;
  273.  
  274. public class JobActivity extends AppCompatActivity
  275. {
  276. Activity context;
  277.  
  278. HttpPost httppost;
  279.  
  280. StringBuffer buffer;
  281.  
  282. HttpResponse response;
  283.  
  284. HttpClient httpclient;
  285.  
  286. ProgressDialog pd;
  287.  
  288. jobAdapter adapter;
  289.  
  290. ListView listJob;
  291. ArrayList<job> records;
  292. private session session;
  293. String s,states;
  294.  
  295. @Override
  296. protected void onCreate(Bundle savedInstanceState)
  297. {
  298. super.onCreate(savedInstanceState);
  299. setContentView(R.layout.activity_job);
  300. session = new session(getApplicationContext());
  301. states=session.getState();
  302. Intent i = getIntent();
  303. i.getExtras();
  304. s = i.getStringExtra("data");
  305. Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
  306. context=this;
  307. records=new ArrayList<job>();
  308. listJob=(ListView)findViewById(R.id.lvJob);
  309. adapter=new jobAdapter(context,R.layout.list_job,R.id.tvState1,records);
  310. listJob.setAdapter(adapter);
  311. BackTask bt=new BackTask();
  312. bt.execute();
  313. }
  314. public void onStart(){
  315. super.onStart();
  316.  
  317. //execute background task
  318. BackTask bt=new BackTask();
  319. bt.execute();
  320. }
  321. private class BackTask extends AsyncTask<Void,Void,Void>
  322. {
  323. protected void onPreExecute()
  324. {
  325. super.onPreExecute();
  326. pd = new ProgressDialog(context);
  327. //pd.setTitle("Retrieving data");
  328. //pd.setMessage("Please wait.");
  329. pd.setCancelable(true);
  330. pd.setIndeterminate(true);
  331. //pd.show();
  332. }
  333. protected Void doInBackground(Void...params)
  334. {
  335. InputStream is=null;
  336. String result="";
  337. try
  338. {
  339. httpclient=new DefaultHttpClient();
  340. httppost= new HttpPost("http://10.0.2.2/JobFinder/Android/FetchJob2.php");
  341. response=httpclient.execute(httppost);
  342. HttpEntity entity = response.getEntity();
  343. // Get our response as a String.
  344. is = entity.getContent();
  345. }
  346. catch(Exception e)
  347. {
  348. if(pd!=null)
  349. pd.dismiss(); //close the dialog if error occurs
  350. Log.e("ERROR", e.getMessage());
  351. }
  352. //convert response to string
  353. try
  354. {
  355. BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"),8);
  356. StringBuilder sb = new StringBuilder();
  357. String line = null;
  358. while ((line = reader.readLine()) != null)
  359. {
  360. sb.append(line+"n");
  361. }
  362. is.close();
  363. result=sb.toString();
  364. }
  365. catch(Exception e)
  366. {
  367. Log.e("ERROR", "Error converting result "+e.toString());
  368. }
  369. //parse json data
  370.  
  371. try{
  372.  
  373. // Remove unexpected characters that might be added to beginning of the string
  374. result=result.substring(result.indexOf("["));
  375. JSONArray jArray =new JSONArray(result);
  376. for(int i=0;i<jArray.length();i++)
  377. {
  378. JSONObject json_data =jArray.getJSONObject(i);
  379.  
  380. job p=new job();
  381.  
  382. p.setState(json_data.getString("state"));
  383.  
  384. p.setCat(json_data.getString("category"));
  385.  
  386. p.setPost(json_data.getString("post"));
  387.  
  388. p.setVacancy(json_data.getInt("vacancy"));
  389.  
  390. records.add(p);
  391. }
  392. }
  393. catch(Exception e)
  394. {
  395.  
  396. Log.e("ERROR", "Error pasting data "+e.toString());
  397. }
  398. return null;
  399. }
  400. protected void onPostExecute(Void result)
  401. {
  402. session.setState(s);
  403. if(pd!=null) pd.dismiss(); //close dialog
  404.  
  405. Log.e("size", records.size() + "");
  406.  
  407. adapter.notifyDataSetChanged(); //notify the ListView to get new records
  408. }
  409. }
  410. @Override
  411. public boolean onCreateOptionsMenu(Menu menu) {
  412. // Inflate the menu; this adds items to the action bar if it is present.
  413. return true;
  414. }
  415.  
  416. @Override
  417. public boolean onOptionsItemSelected(MenuItem item) {
  418. // Handle action bar item clicks here. The action bar will
  419. // automatically handle clicks on the Home/Up button, so long
  420. // as you specify a parent activity in AndroidManifest.xml.
  421. int id = item.getItemId();
  422.  
  423. //noinspection SimplifiableIfStatement
  424. return super.onOptionsItemSelected(item);
  425. }
  426. }
  427.  
  428. package com.example.jay.jobfinder;
  429.  
  430. /**
  431. * Created by Jay on 7/13/2017.
  432. */
  433. import android.content.Context;
  434. import android.content.SharedPreferences;
  435. import android.preference.PreferenceManager;
  436.  
  437. public class session
  438. {
  439.  
  440. private SharedPreferences prefs;
  441.  
  442. public session(Context cntx)
  443. {
  444. // TODO Auto-generated constructor stub
  445. prefs = PreferenceManager.getDefaultSharedPreferences(cntx);
  446. }
  447.  
  448. public void setState(String state)
  449. {
  450. prefs.edit().putString("state", state).commit();
  451. // prefsCommit();
  452. }
  453.  
  454. public String getState()
  455. {
  456. String state = prefs.getString("state","");
  457. return state;
  458. }
  459. }
  460.  
  461. package com.example.jay.jobfinder;
  462. /**
  463. * Created by Jay on 7/13/2017.
  464. */
  465. import java.util.ArrayList;
  466. import android.content.Context;
  467. import android.view.LayoutInflater;
  468. import android.view.View;
  469. import android.view.ViewGroup;
  470. import android.widget.ArrayAdapter;
  471. import android.widget.Filter;
  472. import android.widget.TextView;
  473.  
  474. public class jobAdapter extends ArrayAdapter<job>
  475. {
  476. int groupid;
  477.  
  478. private ArrayList<job> originalList;
  479. private ArrayList<job> countryList;
  480. private JobFilter filter;
  481. Context context;
  482.  
  483. public jobAdapter(Context context, int vg, int id, ArrayList<job> countryList)
  484. {
  485. super(context, vg, id, countryList);
  486. this.context = context;
  487. groupid = vg;
  488. this.countryList = countryList;
  489. this.countryList.addAll(countryList);
  490. this.originalList = countryList;
  491. this.originalList.addAll(countryList);
  492. }
  493. @Override
  494. public Filter getFilter()
  495. {
  496. if (filter == null)
  497. {
  498. filter = new JobFilter();
  499. }
  500. return filter;
  501. }
  502.  
  503. public View getView(int position, View convertView, ViewGroup parent) {
  504.  
  505. LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  506.  
  507. View itemView = inflater.inflate(groupid, parent, false);
  508.  
  509. TextView State = (TextView) itemView.findViewById(R.id.tvState1);
  510. State.setText(countryList.get(position).getState());
  511.  
  512. TextView Category = (TextView) itemView.findViewById(R.id.tvCat1);
  513. Category.setText(countryList.get(position).getCat() + "");
  514.  
  515. TextView Post = (TextView) itemView.findViewById(R.id.tvPost1);
  516. Post.setText(countryList.get(position).getPost() + "");
  517.  
  518. TextView Vacancy = (TextView) itemView.findViewById(R.id.tvVac1);
  519. Vacancy.setText(countryList.get(position).getVacancy() + "");
  520.  
  521. return itemView;
  522.  
  523. }
  524. private class JobFilter extends Filter
  525. {
  526. @Override
  527. protected Filter.FilterResults performFiltering(CharSequence constraint)
  528. {
  529. constraint = constraint.toString().toLowerCase();
  530. FilterResults result = new FilterResults();
  531. if(constraint != null && constraint.toString().length() > 0)
  532. {
  533. ArrayList<job> filteredItems = new ArrayList<job>();
  534. for(int i = 0, l = originalList.size(); i < l; i++)
  535. {
  536. job area = originalList.get(i);
  537. if(area.toString().toLowerCase().contains(constraint))
  538. filteredItems.add(area);
  539. }
  540. result.count = filteredItems.size();
  541. result.values = filteredItems;
  542. }
  543. else
  544. {
  545. synchronized(this)
  546. {
  547. result.values = originalList;
  548. result.count = originalList.size();
  549. }
  550. }
  551. return result;
  552. }
  553.  
  554. @SuppressWarnings("unchecked")
  555. @Override
  556. protected void publishResults(CharSequence constraint,FilterResults results)
  557. {
  558.  
  559. countryList = (ArrayList<job>)results.values;
  560. notifyDataSetChanged();
  561. clear();
  562. for(int i = 0, l = countryList.size(); i < l; i++)
  563. add(countryList.get(i));
  564. notifyDataSetInvalidated();
  565. }
  566. }
  567. }
  568.  
  569. package com.example.jay.jobfinder;
  570.  
  571. /**
  572. * Created by Jay on 7/13/2017.
  573. */
  574.  
  575. public class job
  576. {
  577. String state,cat,post;
  578. int vacancy;
  579. public String getState()
  580. {
  581. return state;
  582. }
  583.  
  584. public void setState(String state) {
  585. this.state = state;
  586. }
  587.  
  588. public String getCat()
  589. {
  590. return cat;
  591. }
  592.  
  593. public void setCat(String cat) {
  594. this.cat = cat;
  595. }
  596.  
  597. public String getPost()
  598. {
  599. return post;
  600. }
  601.  
  602. public void setPost(String post) {
  603. this.post = post;
  604. }
  605.  
  606. public int getVacancy()
  607. {
  608. return vacancy;
  609. }
  610.  
  611. public void setVacancy(int vacancy)
  612. {
  613. this.vacancy=vacancy;
  614. }
  615.  
  616. public String toString()
  617. {
  618. return state + "," + cat + ","+ post+","+vacancy;
  619. }
  620. }
  621.  
  622. <?php
  623. session_start();
  624. $city=$_POST['states'];
  625. $con = mysql_connect("localhost","root");
  626. mysql_select_db("jobs", $con);
  627. $sql = "select state,category,post,vacancy from main_tbl where state='".$city."'";
  628. // Execute query
  629. $result = mysql_query($sql,$con);
  630. // Loop through each records
  631. while($row = mysql_fetch_assoc($result))
  632. {
  633. $output[]=$row;
  634. }
  635. print(json_encode($output));
  636. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement