Guest User

Untitled

a guest
Dec 9th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.17 KB | None | 0 0
  1. package com.android.fibreoptic;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import org.apache.http.util.ByteArrayBuffer;
  6. import org.json.JSONObject;
  7. import android.app.Activity;
  8. import android.app.ProgressDialog;
  9. import android.content.Context;
  10. import android.content.Intent;
  11. import android.database.Cursor;
  12. import android.os.AsyncTask;
  13. import android.os.Bundle;
  14. import android.text.Editable;
  15. import android.text.Html;
  16. import android.text.TextWatcher;
  17. import android.util.Log;
  18. import android.view.LayoutInflater;
  19. import android.view.View;
  20. import android.view.ViewGroup;
  21. import android.view.View.OnClickListener;
  22. import android.view.inputmethod.InputMethodManager;
  23. import android.widget.AdapterView;
  24. import android.widget.AdapterView.OnItemClickListener;
  25. import android.widget.ArrayAdapter;
  26. import android.widget.BaseAdapter;
  27. import android.widget.EditText;
  28. import android.widget.ListView;
  29. import android.widget.SimpleCursorAdapter;
  30. import android.widget.TextView;
  31.  
  32. public class TermActivity extends Activity implements OnItemClickListener{
  33.  
  34. //Initializations
  35.  
  36. ByteArrayBuffer baf ;
  37. ListView list_view;
  38. private EditText ed;
  39. private Cursor mNotesCursor;
  40. private NotesDbAdapter mDbHelper;
  41. ArrayList<String> title_list = new ArrayList<String>();
  42. ArrayList<String> desc_list = new ArrayList<String>();
  43. ArrayList<String> image_list = new ArrayList<String>();
  44. ArrayList<String> link_list = new ArrayList<String>();
  45. ArrayList<String> cat_list = new ArrayList<String>();
  46. public static String[] VALUE1,VALUE2,VALUE3,VALUE4 ,VALUE5;
  47. private ArrayList<String> arr_sort= new ArrayList<String>();
  48. int textlength = 0;
  49. String var="";
  50. String link="",title_value;
  51. ListView list;
  52. //End
  53.  
  54. int position;
  55. MultiLine dealAdapter;
  56. static ViewHolder holder;
  57. @Override
  58. public void onCreate(Bundle savedInstanceState) {
  59.  
  60. super.onCreate(savedInstanceState);
  61. setContentView(R.layout.terms);
  62. list=(ListView) findViewById(R.id.list);
  63. ed=(EditText) findViewById(R.id.EditText01);
  64. InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  65. mgr.hideSoftInputFromWindow(ed.getWindowToken(), 0);
  66. mDbHelper = new NotesDbAdapter(this);
  67. mDbHelper.open();
  68.  
  69. // mDbHelper.deleteNote(0);
  70.  
  71. try{
  72. mNotesCursor = mDbHelper.fetchAllNotes();
  73. startManagingCursor(mNotesCursor);
  74. long details;
  75. if (mNotesCursor.moveToFirst()) {
  76.  
  77. int rowid = mNotesCursor.getColumnIndex(NotesDbAdapter.KEY_ROWID);
  78. do {
  79. // Get the field values
  80. details =mNotesCursor.getLong(rowid);
  81. Log.v("expense", ""+details);
  82. mDbHelper.deleteNote(details);
  83.  
  84. } while (mNotesCursor.moveToNext());
  85. }
  86. }catch(Exception e){
  87. Log.v("Excep", ""+e);
  88. }
  89.  
  90.  
  91.  
  92. list_view=(ListView)findViewById(R.id.list);
  93. list_view.setOnItemClickListener(this);
  94.  
  95. final String[] title_Array = getResources().getStringArray(R.array.title);
  96.  
  97. for(String cad : title_Array) {
  98. String categoryAndDesc = cad;
  99. Log.v("Title", categoryAndDesc);
  100. title_list.add(categoryAndDesc);
  101. }
  102.  
  103.  
  104. String[] description_Array = getResources().getStringArray(R.array.description);
  105.  
  106. for(String cad : description_Array) {
  107. String categoryAndDesc = cad;
  108. Log.v("Desc", categoryAndDesc);
  109. if(categoryAndDesc.contains("*")){
  110.  
  111. Log.v("summe", ""+categoryAndDesc.indexOf("*"));
  112. Log.v("summe", ""+categoryAndDesc.indexOf("%"));
  113. Log.v("summe", ""+categoryAndDesc.lastIndexOf("*"));
  114.  
  115. Log.v("summe", ""+categoryAndDesc.substring(categoryAndDesc.indexOf("*")+1, categoryAndDesc.indexOf("%")-1));
  116. var=categoryAndDesc.substring(categoryAndDesc.indexOf("*")+1, categoryAndDesc.indexOf("%")-1);
  117. Log.v("summe", ""+categoryAndDesc.substring(categoryAndDesc.indexOf("%")+1, categoryAndDesc.lastIndexOf("*")));
  118. link=categoryAndDesc.substring(categoryAndDesc.indexOf("%")+1, categoryAndDesc.lastIndexOf("*"));
  119. }
  120. desc_list.add(categoryAndDesc);
  121. }
  122.  
  123.  
  124. final String[] link_Array = getResources().getStringArray(R.array.linkify);
  125.  
  126. for(String cad : link_Array) {
  127. String categoryAndDesc = cad;
  128. Log.v("Title", categoryAndDesc);
  129. link_list.add(categoryAndDesc);
  130. }
  131.  
  132. // String[] image_name_Array = {"im1", "im2","im3","im4","im5","im6","im7","im8",};
  133.  
  134. String[] image_name_Array = {"im1", "im2","im3","im4","im5","im6","im7","im8","im9", "im10", "im11","im12","im13","im14","im15", "im16", "im17", "im18", "im19", "im20", "im21", "im22",
  135. "im23", "im24", "im25","im26", "im27", "im28", "im29", "im30", "im31", "im32", "im33",
  136. "im34", "im35","im36","im37", "im38","im39","im40", "im41","im42","im43","im44","im45",
  137. "im46", "im47", "im48", "im49", "im50", "im51", "im52", "im53", "im54", "im55", "im56",
  138. "im57","im58", "im59","im60","im61", "im62", "im63", "im64", "im65", "im66", "im67", "im68",
  139. "im69","im70", "im71", "im72", "im73", "im74", "im75", "im76", "im77", "im78", "im79", "im80",
  140. "im81", "im82","im83","im84","im85","im86", "im87", "im88","im89","im90", "im91", "im92", "im93",
  141. "im94","im95","im96","im97","im98", "im99","im100","im101","im102","im103","im104","im105","im106",
  142. "im107","im108","im109","im110","im111","im112","im113","im114","im115", "im116","im117","im118",
  143. "im119","im120","im121","im122","im123","im124","im125","im126","im127","im128","im129","im130",
  144. "im131","im132","im133","im134","im135","im136","im137","im138","im139","im140","im141"};
  145. // String[] image_name_Array = getResources().getStringArray(images);
  146. for(String cad : image_name_Array) {
  147. String categoryAndDesc = cad;
  148. Log.v("Image", categoryAndDesc);
  149. image_list.add(categoryAndDesc);
  150. }
  151.  
  152. String[] cat_Array = getResources().getStringArray(R.array.category);
  153. for(String cad : cat_Array){
  154. String categoryAndDesc = cad;
  155. Log.v("Category", categoryAndDesc);
  156. cat_list.add(categoryAndDesc);
  157. }
  158.  
  159.  
  160. int l1=-1;
  161. int m1=-1;
  162. int m2=-1;
  163. int m3=-1;
  164. int ll=-1;
  165. VALUE1 = new String[title_list.size()];
  166. Iterator<String> itc = title_list.iterator();
  167. while (itc.hasNext()) {
  168. l1++;
  169. VALUE1[l1] = itc.next().toString();
  170. }
  171. VALUE2 = new String[desc_list.size()];
  172. Iterator<String> it2 = desc_list.iterator();
  173. while (it2.hasNext()) {
  174. m1++;
  175. VALUE2[m1] = it2.next().toString();
  176. }
  177.  
  178. VALUE3 = new String[image_list.size()];
  179. Iterator<String> it3 = image_list.iterator();
  180. while (it3.hasNext()) {
  181. m2++;
  182. VALUE3[m2] = it3.next().toString();
  183. }
  184.  
  185. VALUE4 = new String[cat_list.size()];
  186. Iterator<String> it4 = cat_list.iterator();
  187. while (it4.hasNext()) {
  188. m3++;
  189. VALUE4[m3] = it4.next().toString();
  190. }
  191.  
  192. VALUE5 = new String[link_list.size()];
  193. Iterator<String> it5 = link_list.iterator();
  194. while (it5.hasNext()) {
  195. ll++;
  196. VALUE5[ll] = it5.next().toString();
  197. }
  198.  
  199. dealAdapter = new MultiLine(this,VALUE1);
  200. // dealAdapter = new MultiLine(this,VALUE1,VALUE2);
  201. list.setAdapter(dealAdapter);
  202. // for(int i=0;i<VALUE4.length;i++){
  203. // new Task_like_flag().execute(VALUE1[i],VALUE2[i],VALUE3[i], VALUE4[i]);
  204. // }
  205.  
  206. ed.addTextChangedListener(new TextWatcher() {
  207. @Override
  208. public void beforeTextChanged(CharSequence s, int start, int count,
  209. int after){
  210.  
  211. }
  212.  
  213. @Override
  214. public void afterTextChanged(Editable s) {
  215.  
  216.  
  217. }
  218. @Override
  219. public void onTextChanged(CharSequence s, int start, int before, int count) {
  220. textlength = ed.getText().length();
  221. arr_sort.clear();
  222. for(int i=0;i<title_Array.length;i++)
  223. {
  224. if(textlength<=title_Array[i].length())
  225. {
  226. if(ed.getText().toString().equalsIgnoreCase((String) title_Array[i].subSequence(0, textlength)))
  227. {
  228. arr_sort.add(title_Array[i]);
  229. Log.v("title_Array[i]",title_Array[i]);
  230. }
  231.  
  232. }
  233. }
  234. list_view.setAdapter(new ArrayAdapter<String>(TermActivity.this, android.R.layout.simple_list_item_1, arr_sort));
  235.  
  236. list_view.setOnItemClickListener(new OnItemClickListener(){
  237.  
  238. @Override
  239. public void onItemClick(AdapterView<?> arg0, View arg1,
  240. int arg2, long arg3) {
  241. // TODO Auto-generated method stub
  242.  
  243. Log.v("fff", arr_sort.get(arg2).toString());
  244.  
  245. for(int i=0;i<title_Array.length;i++){
  246. if(arr_sort.get(arg2).toString().equalsIgnoreCase(title_Array[i])){
  247. Log.v("i",""+i);
  248. position=i;
  249. }
  250. }
  251.  
  252.  
  253. Intent obj_intent = new Intent(TermActivity.this, WordDisplay.class);
  254. Bundle b = new Bundle();
  255. // position=arg2;
  256. b.putString("TITLE", VALUE1[position]);
  257. b.putString("DESCRIPTION", VALUE2[position]);
  258. b.putInt("IMAGE_URL",position);
  259. // b.putString("LINK_URL",VALUE5[arg2]);
  260.  
  261. // b.putString("values",var);
  262.  
  263. // b.putString("link",link);
  264.  
  265. b.putStringArray("TITLEARRAY", VALUE1);
  266. b.putStringArray("DESCARRAY", VALUE2);
  267. b.putStringArray("IMAGEARRAY", VALUE3);
  268.  
  269.  
  270. // fillData();
  271.  
  272. mDbHelper.createNote1(VALUE1[position]);
  273. fillData1();
  274. obj_intent.putExtras(b);
  275. startActivity(obj_intent);
  276.  
  277. }
  278.  
  279.  
  280.  
  281. });
  282. }
  283. });
  284. }
  285.  
  286.  
  287.  
  288.  
  289.  
  290. // public class Task_like_flag extends AsyncTask<String, Void, Void> {
  291. // private final ProgressDialog dialog = new ProgressDialog(TermActivity.this);
  292. // JSONObject object_feed;
  293. // // can use UI thread here
  294. // protected void onPreExecute() {
  295. // this.dialog.setMessage("Loading...");
  296. // this.dialog.setCancelable(false);
  297. // this.dialog.show();
  298. // }
  299. ////
  300. // @Override
  301. // protected Void doInBackground(String... params) {
  302. //
  303. // String async_tit=params[0];
  304. // String async_desc=params[1];
  305. // String async_img=params[2];
  306. // String async_cat=params[3];
  307. // mDbHelper.createNote(async_tit,async_desc,async_img,async_cat);
  308. //
  309. // return null;
  310. // }
  311. //
  312. // @Override
  313. // protected void onPostExecute(Void result) {
  314. //
  315. // fillData();
  316. // if (this.dialog.isShowing()) {
  317. // this.dialog.dismiss();
  318. // }
  319. //
  320. // }
  321. // }
  322.  
  323.  
  324. // private void fillData() {
  325. // // Get all of the rows from the database and create the item list
  326. // mNotesCursor = mDbHelper.fetchAllNotes();
  327. // startManagingCursor(mNotesCursor);
  328. //
  329. // // Create an array to specify the fields we want to display in the list (only TITLE)
  330. // String[] from = new String[]{NotesDbAdapter.KEY_TITLE,NotesDbAdapter.KEY_DESC};
  331. // // and an array of the fields we want to bind those fields to (in this case just text1)
  332. // int[] to = new int[]{R.id.text1,R.id.text2};
  333. //
  334. // // Now create a simple cursor adapter and set it to display
  335. // SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
  336. // Log.v("length", ""+notes.getCount());
  337. // list_view.setAdapter(notes);
  338. // // mDbHelper.close();
  339. //
  340. // }
  341.  
  342.  
  343. private void fillData1() {
  344.  
  345. try{
  346. mNotesCursor = mDbHelper.fetchAllNotes();
  347. startManagingCursor(mNotesCursor);
  348. if (mNotesCursor.moveToFirst()) {
  349.  
  350. int rowid = mNotesCursor.getColumnIndex(NotesDbAdapter.KEY_TITLE);
  351. do {
  352. // Get the field values
  353. title_value =mNotesCursor.getString(rowid);
  354. Log.v("expense", ""+title_value);
  355. // mDbHelper.deleteNote(details);
  356.  
  357. } while (mNotesCursor.moveToNext());
  358. }
  359. }catch(Exception e){
  360. Log.v("Excep", ""+e);
  361. }
  362. }
  363. @Override
  364. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
  365. long arg3) {
  366. // TODO Auto-generated method stub
  367. Intent obj_intent = new Intent(this, WordDisplay.class);
  368. Bundle b = new Bundle();
  369. position=arg2;
  370. b.putString("TITLE", VALUE1[position]);
  371. b.putString("DESCRIPTION", VALUE2[position]);
  372. b.putInt("IMAGE_URL",position);
  373. // b.putString("LINK_URL",VALUE5[arg2]);
  374.  
  375. // b.putString("values",var);
  376.  
  377. // b.putString("link",link);
  378.  
  379. b.putStringArray("TITLEARRAY", VALUE1);
  380. b.putStringArray("DESCARRAY", VALUE2);
  381. b.putStringArray("IMAGEARRAY", VALUE3);
  382.  
  383.  
  384. // fillData();
  385.  
  386. mDbHelper.createNote1(VALUE1[position]);
  387. fillData1();
  388. obj_intent.putExtras(b);
  389. startActivity(obj_intent);
  390. }
  391. class MultiLine extends BaseAdapter {
  392.  
  393. LayoutInflater mInflater;
  394. String name;
  395. String TAG = "MultiLine";
  396. int i = -1;
  397. int j = -1;
  398. int k = -1;
  399. String[] VAL1,VAL2,VAL3,VAL4;
  400.  
  401. public MultiLine(Context context, String[] value1) {
  402. try {
  403.  
  404. mInflater = LayoutInflater.from(context);
  405. VAL1 = value1;
  406. } catch (Exception e) {
  407. Log.v(TAG, "dom" + e);
  408. }
  409.  
  410. }
  411.  
  412. public int getCount() {
  413.  
  414. return VAL1.length;
  415. }
  416.  
  417. public Object getItem(int arg0) {
  418. return arg0;
  419. }
  420.  
  421. public long getItemId(int arg0) {
  422. return arg0;
  423. }
  424.  
  425. public View getView(int position, View convertView, ViewGroup arg2) {
  426.  
  427. if (convertView == null) {
  428. convertView = mInflater.inflate(R.layout.notes_row, null);
  429.  
  430. holder = new ViewHolder();
  431. holder.text1 = (TextView) convertView
  432. .findViewById(R.id.text1);
  433.  
  434.  
  435. convertView.setTag(holder);
  436. } else {
  437. holder.text1 = (TextView) convertView
  438. .findViewById(R.id.text1);
  439.  
  440.  
  441. }
  442.  
  443. holder.text1.setText(Html.fromHtml(VAL1[position]));
  444.  
  445.  
  446. return convertView;
  447. }
  448.  
  449. }
  450.  
  451. static class ViewHolder {
  452. TextView text1, text2, text3;
  453. }
  454. }
Add Comment
Please, Sign In to add comment