Ejemplo n.º 1
0
  // Na odabir stavke menija.
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.addItemToList:
        Intent intent = new Intent(this, AddItem.class);
        intent.putExtra("listName", listName);
        startActivity(intent);
        finish();
        break;
      case R.id.refreshItems:
        Intent intent2 = new Intent(this, EditListItems.class);
        intent2.putExtra("listName", listName);
        startActivity(intent2);
        finish();
        break;

      case R.id.cleanItems:
        ArrayList<Item> items = list.getItems();
        int n = items.size();
        for (int i = 0; i < n; i++) {
          if (list.getItems().get(i).isDone()) {
            list.removeItem(i);
            i--;
            n--;
          }
        }

        String string = list.toXMLplist();
        FileOutputStream fos;
        try {
          fos = openFileOutput(listName, Context.MODE_PRIVATE);
          fos.write(string.getBytes());
          fos.close();
          Util.listChanged(listName, getApplicationContext());
        } catch (Exception e) {
          e.printStackTrace();
        }

        Intent intent3 = new Intent(getApplicationContext(), EditListItems.class);
        intent3.putExtra("listName", listName);
        startActivity(intent3);
        finish();
        break;
    }
    return true;
  }
Ejemplo n.º 2
0
 // Popunjavanje floating context menija.
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
   int index3 = info.position;
   String name1 = array_sort.get(index3);
   String[] name = name1.split(",");
   int broj = list.idByNameInArray(name[0]);
   switch (item.getItemId()) {
       // Editiranje Itema sa liste.
     case R.id.editItem:
       Intent intent2 = new Intent(this, EditItem.class);
       intent2.putExtra("listName", listName);
       intent2.putExtra("itemIndex", broj);
       startActivity(intent2);
       finish();
       break;
       // Brisanje Itema sa liste.
     case R.id.deleteItem:
       int index4 = info.position;
       String name3 = array_sort.get(index4);
       String[] name2 = name3.split(",");
       int num = list.idByNameInArray(name2[0]);
       list.removeItem(num);
       String string = list.toXMLplist();
       FileOutputStream fos;
       try {
         fos = openFileOutput(listName, Context.MODE_PRIVATE);
         fos.write(string.getBytes());
         fos.close();
         Util.listChanged(listName, getApplicationContext());
       } catch (Exception e) {
         e.printStackTrace();
       }
       Intent intent3 = new Intent(getApplicationContext(), EditListItems.class);
       intent3.putExtra("listName", listName);
       startActivity(intent3);
       finish();
       break;
     default:
       return super.onContextItemSelected(item);
   }
   return true;
 }
Ejemplo n.º 3
0
 // Popunjavanje ListView-a Itemima.
 private String[] populateList() {
   ArrayList<Item> items = list.getItems();
   String[] item_row = new String[items.size()];
   for (int i = 0; i < items.size(); ++i) {
     Item item = items.get(i);
     String status = item.isDone() ? "  " + Html.fromHtml("&#10004;") : "";
     item_row[i] = item.getName() + ", " + item.getCount() + status;
   }
   return item_row;
 }
Ejemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_list_items_activity);
    Log.i(TAG, "Activity started!");

    listNameTextView = (TextView) this.findViewById(R.id.editListName);
    itemRow = (TextView) this.findViewById(R.id.itemRow);
    empty = (TextView) this.findViewById(android.R.id.empty);
    relLayout = (RelativeLayout) this.findViewById(R.id.editListBg);

    // Pronaði i postavi ime liste. Ime liste se prenosi kao parametar u Intentu.
    Intent intent = getIntent();
    listName = intent.getStringExtra("listName");
    listNameTextView.setText(listName);

    // Otvori listu iz interne memorije.
    File file = getBaseContext().getFileStreamPath(listName);
    list = new List(file);

    // Postavi boju pozadine.
    int bgColor = list.getColor();
    relLayout.setBackgroundColor(bgColor);

    // Postavi boju teksa suprotnu boji pozadine.
    textColor = Util.getOppositeColor(bgColor);
    listNameTextView.setTextColor(textColor);
    empty.setTextColor(textColor);

    registerForContextMenu(getListView());

    listview_names = populateList();

    et = (EditText) findViewById(R.id.EditText02);
    et.setTextColor(textColor);
    array_sort = new ArrayList<String>(Arrays.asList(listview_names));
    setListAdapter(new bsAdapter(this));

    lv = (ListView) findViewById(android.R.id.list);

    et.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void afterTextChanged(Editable s) {
            // Abstract Method of TextWatcher Interface.
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Abstract Method of TextWatcher Interface.
          }

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            textlength = et.getText().length();
            array_sort.clear();
            for (int i = 0; i < listview_names.length; i++) {
              if (textlength <= listview_names[i].length()) {
                if (listview_names[i]
                    .toLowerCase()
                    .contains(et.getText().toString().toLowerCase().trim())) {
                  array_sort.add(listview_names[i]);
                }
              }
            }
            AppendList(array_sort);
          }
        });

    lv.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            String name1 = array_sort.get(position);
            String[] name = name1.split(",");
            int broj = list.idByNameInArray(name[0]);
            if (list.getItems().get(broj).isDone()) {
              list.getItems().get(broj).setDone(false);
            } else {
              list.setItemDone(broj);
            }
            String str = list.toXMLplist();
            FileOutputStream fostream;
            try {
              fostream = openFileOutput(listName, Context.MODE_PRIVATE);
              fostream.write(str.getBytes());
              fostream.close();
              Util.listChanged(listName, getApplicationContext());
            } catch (Exception e) {
              e.printStackTrace();
            }
            Intent intent = new Intent(getApplicationContext(), EditListItems.class);
            intent.putExtra("listName", listName);
            startActivity(intent);
            finish();
          }
        });
  }