Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.android.fibreoptic;
- import java.util.ArrayList;
- import java.util.Iterator;
- import org.apache.http.util.ByteArrayBuffer;
- import org.json.JSONObject;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.database.Cursor;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.text.Editable;
- import android.text.Html;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.View.OnClickListener;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.BaseAdapter;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.SimpleCursorAdapter;
- import android.widget.TextView;
- public class TermActivity extends Activity implements OnItemClickListener{
- //Initializations
- ByteArrayBuffer baf ;
- ListView list_view;
- private EditText ed;
- private Cursor mNotesCursor;
- private NotesDbAdapter mDbHelper;
- ArrayList<String> title_list = new ArrayList<String>();
- ArrayList<String> desc_list = new ArrayList<String>();
- ArrayList<String> image_list = new ArrayList<String>();
- ArrayList<String> link_list = new ArrayList<String>();
- ArrayList<String> cat_list = new ArrayList<String>();
- public static String[] VALUE1,VALUE2,VALUE3,VALUE4 ,VALUE5;
- private ArrayList<String> arr_sort= new ArrayList<String>();
- int textlength = 0;
- String var="";
- String link="",title_value;
- ListView list;
- //End
- int position;
- MultiLine dealAdapter;
- static ViewHolder holder;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.terms);
- list=(ListView) findViewById(R.id.list);
- ed=(EditText) findViewById(R.id.EditText01);
- InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- mgr.hideSoftInputFromWindow(ed.getWindowToken(), 0);
- mDbHelper = new NotesDbAdapter(this);
- mDbHelper.open();
- // mDbHelper.deleteNote(0);
- try{
- mNotesCursor = mDbHelper.fetchAllNotes();
- startManagingCursor(mNotesCursor);
- long details;
- if (mNotesCursor.moveToFirst()) {
- int rowid = mNotesCursor.getColumnIndex(NotesDbAdapter.KEY_ROWID);
- do {
- // Get the field values
- details =mNotesCursor.getLong(rowid);
- Log.v("expense", ""+details);
- mDbHelper.deleteNote(details);
- } while (mNotesCursor.moveToNext());
- }
- }catch(Exception e){
- Log.v("Excep", ""+e);
- }
- list_view=(ListView)findViewById(R.id.list);
- list_view.setOnItemClickListener(this);
- final String[] title_Array = getResources().getStringArray(R.array.title);
- for(String cad : title_Array) {
- String categoryAndDesc = cad;
- Log.v("Title", categoryAndDesc);
- title_list.add(categoryAndDesc);
- }
- String[] description_Array = getResources().getStringArray(R.array.description);
- for(String cad : description_Array) {
- String categoryAndDesc = cad;
- Log.v("Desc", categoryAndDesc);
- if(categoryAndDesc.contains("*")){
- Log.v("summe", ""+categoryAndDesc.indexOf("*"));
- Log.v("summe", ""+categoryAndDesc.indexOf("%"));
- Log.v("summe", ""+categoryAndDesc.lastIndexOf("*"));
- Log.v("summe", ""+categoryAndDesc.substring(categoryAndDesc.indexOf("*")+1, categoryAndDesc.indexOf("%")-1));
- var=categoryAndDesc.substring(categoryAndDesc.indexOf("*")+1, categoryAndDesc.indexOf("%")-1);
- Log.v("summe", ""+categoryAndDesc.substring(categoryAndDesc.indexOf("%")+1, categoryAndDesc.lastIndexOf("*")));
- link=categoryAndDesc.substring(categoryAndDesc.indexOf("%")+1, categoryAndDesc.lastIndexOf("*"));
- }
- desc_list.add(categoryAndDesc);
- }
- final String[] link_Array = getResources().getStringArray(R.array.linkify);
- for(String cad : link_Array) {
- String categoryAndDesc = cad;
- Log.v("Title", categoryAndDesc);
- link_list.add(categoryAndDesc);
- }
- // String[] image_name_Array = {"im1", "im2","im3","im4","im5","im6","im7","im8",};
- 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",
- "im23", "im24", "im25","im26", "im27", "im28", "im29", "im30", "im31", "im32", "im33",
- "im34", "im35","im36","im37", "im38","im39","im40", "im41","im42","im43","im44","im45",
- "im46", "im47", "im48", "im49", "im50", "im51", "im52", "im53", "im54", "im55", "im56",
- "im57","im58", "im59","im60","im61", "im62", "im63", "im64", "im65", "im66", "im67", "im68",
- "im69","im70", "im71", "im72", "im73", "im74", "im75", "im76", "im77", "im78", "im79", "im80",
- "im81", "im82","im83","im84","im85","im86", "im87", "im88","im89","im90", "im91", "im92", "im93",
- "im94","im95","im96","im97","im98", "im99","im100","im101","im102","im103","im104","im105","im106",
- "im107","im108","im109","im110","im111","im112","im113","im114","im115", "im116","im117","im118",
- "im119","im120","im121","im122","im123","im124","im125","im126","im127","im128","im129","im130",
- "im131","im132","im133","im134","im135","im136","im137","im138","im139","im140","im141"};
- // String[] image_name_Array = getResources().getStringArray(images);
- for(String cad : image_name_Array) {
- String categoryAndDesc = cad;
- Log.v("Image", categoryAndDesc);
- image_list.add(categoryAndDesc);
- }
- String[] cat_Array = getResources().getStringArray(R.array.category);
- for(String cad : cat_Array){
- String categoryAndDesc = cad;
- Log.v("Category", categoryAndDesc);
- cat_list.add(categoryAndDesc);
- }
- int l1=-1;
- int m1=-1;
- int m2=-1;
- int m3=-1;
- int ll=-1;
- VALUE1 = new String[title_list.size()];
- Iterator<String> itc = title_list.iterator();
- while (itc.hasNext()) {
- l1++;
- VALUE1[l1] = itc.next().toString();
- }
- VALUE2 = new String[desc_list.size()];
- Iterator<String> it2 = desc_list.iterator();
- while (it2.hasNext()) {
- m1++;
- VALUE2[m1] = it2.next().toString();
- }
- VALUE3 = new String[image_list.size()];
- Iterator<String> it3 = image_list.iterator();
- while (it3.hasNext()) {
- m2++;
- VALUE3[m2] = it3.next().toString();
- }
- VALUE4 = new String[cat_list.size()];
- Iterator<String> it4 = cat_list.iterator();
- while (it4.hasNext()) {
- m3++;
- VALUE4[m3] = it4.next().toString();
- }
- VALUE5 = new String[link_list.size()];
- Iterator<String> it5 = link_list.iterator();
- while (it5.hasNext()) {
- ll++;
- VALUE5[ll] = it5.next().toString();
- }
- dealAdapter = new MultiLine(this,VALUE1);
- // dealAdapter = new MultiLine(this,VALUE1,VALUE2);
- list.setAdapter(dealAdapter);
- // for(int i=0;i<VALUE4.length;i++){
- // new Task_like_flag().execute(VALUE1[i],VALUE2[i],VALUE3[i], VALUE4[i]);
- // }
- ed.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after){
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- textlength = ed.getText().length();
- arr_sort.clear();
- for(int i=0;i<title_Array.length;i++)
- {
- if(textlength<=title_Array[i].length())
- {
- if(ed.getText().toString().equalsIgnoreCase((String) title_Array[i].subSequence(0, textlength)))
- {
- arr_sort.add(title_Array[i]);
- Log.v("title_Array[i]",title_Array[i]);
- }
- }
- }
- list_view.setAdapter(new ArrayAdapter<String>(TermActivity.this, android.R.layout.simple_list_item_1, arr_sort));
- list_view.setOnItemClickListener(new OnItemClickListener(){
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1,
- int arg2, long arg3) {
- // TODO Auto-generated method stub
- Log.v("fff", arr_sort.get(arg2).toString());
- for(int i=0;i<title_Array.length;i++){
- if(arr_sort.get(arg2).toString().equalsIgnoreCase(title_Array[i])){
- Log.v("i",""+i);
- position=i;
- }
- }
- Intent obj_intent = new Intent(TermActivity.this, WordDisplay.class);
- Bundle b = new Bundle();
- // position=arg2;
- b.putString("TITLE", VALUE1[position]);
- b.putString("DESCRIPTION", VALUE2[position]);
- b.putInt("IMAGE_URL",position);
- // b.putString("LINK_URL",VALUE5[arg2]);
- // b.putString("values",var);
- // b.putString("link",link);
- b.putStringArray("TITLEARRAY", VALUE1);
- b.putStringArray("DESCARRAY", VALUE2);
- b.putStringArray("IMAGEARRAY", VALUE3);
- // fillData();
- mDbHelper.createNote1(VALUE1[position]);
- fillData1();
- obj_intent.putExtras(b);
- startActivity(obj_intent);
- }
- });
- }
- });
- }
- // public class Task_like_flag extends AsyncTask<String, Void, Void> {
- // private final ProgressDialog dialog = new ProgressDialog(TermActivity.this);
- // JSONObject object_feed;
- // // can use UI thread here
- // protected void onPreExecute() {
- // this.dialog.setMessage("Loading...");
- // this.dialog.setCancelable(false);
- // this.dialog.show();
- // }
- ////
- // @Override
- // protected Void doInBackground(String... params) {
- //
- // String async_tit=params[0];
- // String async_desc=params[1];
- // String async_img=params[2];
- // String async_cat=params[3];
- // mDbHelper.createNote(async_tit,async_desc,async_img,async_cat);
- //
- // return null;
- // }
- //
- // @Override
- // protected void onPostExecute(Void result) {
- //
- // fillData();
- // if (this.dialog.isShowing()) {
- // this.dialog.dismiss();
- // }
- //
- // }
- // }
- // private void fillData() {
- // // Get all of the rows from the database and create the item list
- // mNotesCursor = mDbHelper.fetchAllNotes();
- // startManagingCursor(mNotesCursor);
- //
- // // Create an array to specify the fields we want to display in the list (only TITLE)
- // String[] from = new String[]{NotesDbAdapter.KEY_TITLE,NotesDbAdapter.KEY_DESC};
- // // and an array of the fields we want to bind those fields to (in this case just text1)
- // int[] to = new int[]{R.id.text1,R.id.text2};
- //
- // // Now create a simple cursor adapter and set it to display
- // SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
- // Log.v("length", ""+notes.getCount());
- // list_view.setAdapter(notes);
- // // mDbHelper.close();
- //
- // }
- private void fillData1() {
- try{
- mNotesCursor = mDbHelper.fetchAllNotes();
- startManagingCursor(mNotesCursor);
- if (mNotesCursor.moveToFirst()) {
- int rowid = mNotesCursor.getColumnIndex(NotesDbAdapter.KEY_TITLE);
- do {
- // Get the field values
- title_value =mNotesCursor.getString(rowid);
- Log.v("expense", ""+title_value);
- // mDbHelper.deleteNote(details);
- } while (mNotesCursor.moveToNext());
- }
- }catch(Exception e){
- Log.v("Excep", ""+e);
- }
- }
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- // TODO Auto-generated method stub
- Intent obj_intent = new Intent(this, WordDisplay.class);
- Bundle b = new Bundle();
- position=arg2;
- b.putString("TITLE", VALUE1[position]);
- b.putString("DESCRIPTION", VALUE2[position]);
- b.putInt("IMAGE_URL",position);
- // b.putString("LINK_URL",VALUE5[arg2]);
- // b.putString("values",var);
- // b.putString("link",link);
- b.putStringArray("TITLEARRAY", VALUE1);
- b.putStringArray("DESCARRAY", VALUE2);
- b.putStringArray("IMAGEARRAY", VALUE3);
- // fillData();
- mDbHelper.createNote1(VALUE1[position]);
- fillData1();
- obj_intent.putExtras(b);
- startActivity(obj_intent);
- }
- class MultiLine extends BaseAdapter {
- LayoutInflater mInflater;
- String name;
- String TAG = "MultiLine";
- int i = -1;
- int j = -1;
- int k = -1;
- String[] VAL1,VAL2,VAL3,VAL4;
- public MultiLine(Context context, String[] value1) {
- try {
- mInflater = LayoutInflater.from(context);
- VAL1 = value1;
- } catch (Exception e) {
- Log.v(TAG, "dom" + e);
- }
- }
- public int getCount() {
- return VAL1.length;
- }
- public Object getItem(int arg0) {
- return arg0;
- }
- public long getItemId(int arg0) {
- return arg0;
- }
- public View getView(int position, View convertView, ViewGroup arg2) {
- if (convertView == null) {
- convertView = mInflater.inflate(R.layout.notes_row, null);
- holder = new ViewHolder();
- holder.text1 = (TextView) convertView
- .findViewById(R.id.text1);
- convertView.setTag(holder);
- } else {
- holder.text1 = (TextView) convertView
- .findViewById(R.id.text1);
- }
- holder.text1.setText(Html.fromHtml(VAL1[position]));
- return convertView;
- }
- }
- static class ViewHolder {
- TextView text1, text2, text3;
- }
- }
Add Comment
Please, Sign In to add comment