List of usage examples for android.widget ListView invalidateViews
public void invalidateViews()
From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java
@SuppressLint("NewApi") public static void handleSubtask(final Context ctx, final Task task, final OnTaskChangedListner taskChanged, final boolean asSubtask) { final List<Pair<Long, String>> names = Task.getTaskNames(); final CharSequence[] values = new String[names.size()]; for (int i = 0; i < names.size(); i++) { values[i] = names.get(i).second; }//from w w w. j a v a 2s .com final View v = ((Activity) ctx).getLayoutInflater().inflate(R.layout.select_subtask, null, false); final ListView lv = (ListView) v.findViewById(R.id.subtask_listview); final List<Task> tasks = Task.cursorToTaskList( ctx.getContentResolver().query(MirakelInternalContentProvider.TASK_URI, Task.allColumns, ModelBase.ID + "=" + task.getId() + " AND " + Task.BASIC_FILTER_DISPLAY_TASKS, null, null)); subtaskAdapter = new SubtaskAdapter(ctx, 0, tasks, task, asSubtask); lv.post(new Runnable() { @Override public void run() { lv.setAdapter(subtaskAdapter); } }); searchString = ""; done = false; content = false; reminder = false; optionEnabled = false; newTask = true; listId = SpecialList.firstSpecialSafe().getId(); final EditText search = (EditText) v.findViewById(R.id.subtask_searchbox); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Drawable left = ctx.getResources().getDrawable(android.R.drawable.ic_menu_search); Drawable right = null; left.setBounds(0, 0, 42, 42); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && ctx.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { right = ctx.getResources().getDrawable(android.R.drawable.ic_menu_search); right.setBounds(0, 0, 42, 42); left = null; } search.setCompoundDrawables(left, null, right, null); } search.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(final Editable s) { // Nothing } @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { // Nothing } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { searchString = s.toString(); updateListView(subtaskAdapter, task, lv, ctx); } }); final Button options = (Button) v.findViewById(R.id.subtasks_options); final LinearLayout wrapper = (LinearLayout) v.findViewById(R.id.subtask_option_wrapper); wrapper.setVisibility(View.GONE); options.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (optionEnabled) { wrapper.setVisibility(View.GONE); } else { wrapper.setVisibility(View.VISIBLE); final InputMethodManager imm = (InputMethodManager) ctx .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(search.getWindowToken(), 0); } optionEnabled = !optionEnabled; } }); final ViewSwitcher switcher = (ViewSwitcher) v.findViewById(R.id.subtask_switcher); final Button subtaskNewtask = (Button) v.findViewById(R.id.subtask_newtask); final Button subtaskSelectOld = (Button) v.findViewById(R.id.subtask_select_old); final boolean darkTheme = MirakelCommonPreferences.isDark(); if (asSubtask) { v.findViewById(R.id.subtask_header).setVisibility(View.GONE); switcher.showNext(); newTask = false; } else { subtaskNewtask.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (newTask) { return; } switcher.showPrevious(); subtaskNewtask .setTextColor(ctx.getResources().getColor(darkTheme ? R.color.White : R.color.Black)); subtaskSelectOld.setTextColor(ctx.getResources().getColor(R.color.Grey)); newTask = true; } }); subtaskSelectOld.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (!newTask) { return; } switcher.showNext(); subtaskNewtask.setTextColor(ctx.getResources().getColor(R.color.Grey)); subtaskSelectOld .setTextColor(ctx.getResources().getColor(darkTheme ? R.color.White : R.color.Black)); if (subtaskAdapter != null) { subtaskAdapter.notifyDataSetChanged(); } newTask = false; lv.invalidateViews(); updateListView(subtaskAdapter, task, lv, ctx); } }); } final CheckBox doneBox = (CheckBox) v.findViewById(R.id.subtask_done); doneBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { done = isChecked; updateListView(subtaskAdapter, task, lv, ctx); } }); final CheckBox reminderBox = (CheckBox) v.findViewById(R.id.subtask_reminder); reminderBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { reminder = isChecked; updateListView(subtaskAdapter, task, lv, ctx); } }); final Button list = (Button) v.findViewById(R.id.subtask_list); list.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { final List<ListMirakel> lists = ListMirakel.all(true); final CharSequence[] names = new String[lists.size()]; for (int i = 0; i < names.length; i++) { names[i] = lists.get(i).getName(); } new AlertDialog.Builder(ctx).setSingleChoiceItems(names, -1, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { listId = lists.get(which).getId(); updateListView(subtaskAdapter, task, lv, ctx); list.setText(lists.get(which).getName()); dialog.dismiss(); } }).show(); } }); final CheckBox contentBox = (CheckBox) v.findViewById(R.id.subtask_content); contentBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { content = isChecked; updateListView(subtaskAdapter, task, lv, ctx); } }); final EditText newTaskEdit = (EditText) v.findViewById(R.id.subtask_add_task_edit); final AlertDialog dialog = new AlertDialog.Builder(ctx).setTitle(ctx.getString(R.string.add_subtask)) .setView(v).setPositiveButton(R.string.add, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { if (newTask && newTaskEdit.getText().length() > 0) { newSubtask(newTaskEdit.getText().toString(), task, ctx); } else if (!newTask) { final List<Task> checked = subtaskAdapter.getSelected(); for (final Task t : checked) { if (!asSubtask) { if (!t.hasSubtasksLoop(task)) { task.addSubtask(t); } else { ErrorReporter.report(ErrorType.TASKS_CANNOT_FORM_LOOP); } } else { if (!task.hasSubtasksLoop(t)) { t.addSubtask(task); } else { ErrorReporter.report(ErrorType.TASKS_CANNOT_FORM_LOOP); } } } } if (taskChanged != null) { taskChanged.onTaskChanged(task); } ((Activity) ctx).getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, dialogDoNothing).show(); newTaskEdit.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { newSubtask(v.getText().toString(), task, ctx); v.setText(null); if (taskChanged != null) { taskChanged.onTaskChanged(task); } dialog.dismiss(); } return false; } }); }