List of usage examples for android.widget TextView setCompoundDrawablesWithIntrinsicBounds
@android.view.RemotableViewMethod public void setCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom)
From source file:de.baumann.quitsmoking.fragments.FragmentNotes.java
private void setNotesList() { ArrayList<HashMap<String, String>> mapList = new ArrayList<>(); try {/*w w w . ja v a 2s .co m*/ Database_Notes db = new Database_Notes(getActivity()); ArrayList<String[]> bookmarkList = new ArrayList<>(); db.getBookmarks(bookmarkList, getActivity()); if (bookmarkList.size() == 0) { db.loadInitialData(); db.getBookmarks(bookmarkList, getActivity()); } db.close(); for (String[] strAry : bookmarkList) { HashMap<String, String> map = new HashMap<>(); map.put("seqno", strAry[0]); map.put("title", strAry[1]); map.put("cont", strAry[2]); map.put("icon", strAry[3]); map.put("attachment", strAry[4]); map.put("createDate", strAry[5]); mapList.add(map); } SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), mapList, R.layout.list_item_notes, new String[] { "title", "cont", "createDate" }, new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }) { @Override public View getView(final int position, View convertView, ViewGroup parent) { @SuppressWarnings("unchecked") HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position); final String title = map.get("title"); final String cont = map.get("cont"); final String seqnoStr = map.get("seqno"); final String icon = map.get("icon"); final String attachment = map.get("attachment"); final String create = map.get("createDate"); View v = super.getView(position, convertView, parent); ImageView i = (ImageView) v.findViewById(R.id.icon_notes); ImageView i2 = (ImageView) v.findViewById(R.id.att_notes); switch (icon) { case "1": i.setImageResource(R.drawable.emoticon_neutral); break; case "2": i.setImageResource(R.drawable.emoticon_happy); break; case "3": i.setImageResource(R.drawable.emoticon_sad); break; case "4": i.setImageResource(R.drawable.emoticon); break; case "5": i.setImageResource(R.drawable.emoticon_cool); break; case "6": i.setImageResource(R.drawable.emoticon_dead); break; case "7": i.setImageResource(R.drawable.emoticon_excited); break; case "8": i.setImageResource(R.drawable.emoticon_tongue); break; case "9": i.setImageResource(R.drawable.emoticon_devil); break; } switch (attachment) { case "": i2.setVisibility(View.GONE); break; default: i2.setVisibility(View.VISIBLE); break; } File file = new File(attachment); if (!file.exists()) { i2.setVisibility(View.GONE); } i.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final FragmentNotes.Item[] items = { new FragmentNotes.Item(getString(R.string.text_tit_1), R.drawable.emoticon_neutral), new FragmentNotes.Item(getString(R.string.text_tit_2), R.drawable.emoticon_happy), new FragmentNotes.Item(getString(R.string.text_tit_3), R.drawable.emoticon_sad), new FragmentNotes.Item(getString(R.string.text_tit_4), R.drawable.emoticon), new FragmentNotes.Item(getString(R.string.text_tit_5), R.drawable.emoticon_cool), new FragmentNotes.Item(getString(R.string.text_tit_6), R.drawable.emoticon_dead), new FragmentNotes.Item(getString(R.string.text_tit_7), R.drawable.emoticon_excited), new FragmentNotes.Item(getString(R.string.text_tit_8), R.drawable.emoticon_tongue), new FragmentNotes.Item(getString(R.string.text_tit_9), R.drawable.emoticon_devil) }; ListAdapter adapter = new ArrayAdapter<FragmentNotes.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.goal_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { changeIcon(seqnoStr, title, cont, "1", attachment, create); } else if (item == 1) { changeIcon(seqnoStr, title, cont, "2", attachment, create); } else if (item == 2) { changeIcon(seqnoStr, title, cont, "3", attachment, create); } else if (item == 3) { changeIcon(seqnoStr, title, cont, "4", attachment, create); } else if (item == 4) { changeIcon(seqnoStr, title, cont, "5", attachment, create); } else if (item == 5) { changeIcon(seqnoStr, title, cont, "6", attachment, create); } else if (item == 6) { changeIcon(seqnoStr, title, cont, "7", attachment, create); } else if (item == 7) { changeIcon(seqnoStr, title, cont, "8", attachment, create); } else if (item == 8) { changeIcon(seqnoStr, title, cont, "9", attachment, create); } else if (item == 9) { changeIcon(seqnoStr, title, cont, "10", attachment, create); } } }).show(); } }); i2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { openAtt(attachment); } }); return v; } }; listView.setAdapter(simpleAdapter); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:de.baumann.hhsmoodle.data_bookmarks.Bookmarks_Fragment.java
public void setBookmarksList() { //display data final int layoutstyle = R.layout.list_item_notes; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" }; final Cursor row = db.fetchAllData(getActivity()); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override/*from ww w. j av a 2 s . co m*/ public View getView(final int position, View convertView, ViewGroup parent) { Cursor row = (Cursor) lv.getItemAtPosition(position); final String _id = row.getString(row.getColumnIndexOrThrow("_id")); final String bookmarks_title = row.getString(row.getColumnIndexOrThrow("bookmarks_title")); final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content")); final String bookmarks_icon = row.getString(row.getColumnIndexOrThrow("bookmarks_icon")); final String bookmarks_attachment = row .getString(row.getColumnIndexOrThrow("bookmarks_attachment")); final String bookmarks_creation = row.getString(row.getColumnIndexOrThrow("bookmarks_creation")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); final ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes); switch (bookmarks_icon) { case "01": iv_icon.setImageResource(R.drawable.circle_red); break; case "02": iv_icon.setImageResource(R.drawable.circle_yellow); break; case "03": iv_icon.setImageResource(R.drawable.circle_green); break; case "04": iv_icon.setImageResource(R.drawable.ic_school_grey600_48dp); break; case "05": iv_icon.setImageResource(R.drawable.ic_view_dashboard_grey600_48dp); break; case "06": iv_icon.setImageResource(R.drawable.ic_face_profile_grey600_48dp); break; case "07": iv_icon.setImageResource(R.drawable.ic_calendar_grey600_48dp); break; case "08": iv_icon.setImageResource(R.drawable.ic_chart_areaspline_grey600_48dp); break; case "09": iv_icon.setImageResource(R.drawable.ic_bell_grey600_48dp); break; case "10": iv_icon.setImageResource(R.drawable.ic_settings_grey600_48dp); break; case "11": iv_icon.setImageResource(R.drawable.ic_web_grey600_48dp); break; case "12": iv_icon.setImageResource(R.drawable.ic_magnify_grey600_48dp); break; case "13": iv_icon.setImageResource(R.drawable.ic_pencil_grey600_48dp); break; case "14": iv_icon.setImageResource(R.drawable.ic_check_grey600_48dp); break; case "15": iv_icon.setImageResource(R.drawable.ic_clock_grey600_48dp); break; case "16": iv_icon.setImageResource(R.drawable.ic_bookmark_grey600_48dp); break; } switch (bookmarks_attachment) { case "": iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.star_outline); break; default: iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.star_grey); break; } iv_attachment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (bookmarks_attachment.equals("")) { if (db.isExistFav("true")) { Snackbar.make(lv, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show(); } else { iv_attachment.setImageResource(R.drawable.star_grey); db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "true", bookmarks_creation); setBookmarksList(); sharedPref.edit().putString("favoriteURL", bookmarks_content) .putString("favoriteTitle", bookmarks_title).apply(); Snackbar.make(lv, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show(); } } else { iv_attachment.setImageResource(R.drawable.star_outline); db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "", bookmarks_creation); setBookmarksList(); } } }); iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green), new helper_main.Item(getString(R.string.text_tit_11), R.drawable.ic_school_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_1), R.drawable.ic_view_dashboard_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_2), R.drawable.ic_face_profile_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_8), R.drawable.ic_calendar_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_3), R.drawable.ic_chart_areaspline_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_4), R.drawable.ic_bell_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_5), R.drawable.ic_settings_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_6), R.drawable.ic_web_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_7), R.drawable.ic_magnify_grey600_48dp), new helper_main.Item(getString(R.string.title_notes), R.drawable.ic_pencil_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_9), R.drawable.ic_check_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_10), R.drawable.ic_clock_grey600_48dp), new helper_main.Item(getString(R.string.title_bookmarks), R.drawable.ic_bookmark_grey600_48dp), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "01", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 1) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "02", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 2) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "03", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 3) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "04", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 4) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "05", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 5) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "06", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 6) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "07", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 7) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "08", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 8) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "09", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 9) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "10", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 10) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "11", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 11) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "12", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 12) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "13", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 13) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "14", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 14) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "15", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 15) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "16", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } } }).show(); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title"); sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content")); sharedPref.edit().putString("load_next", "true").apply(); sharedPref.edit().putString("loadURL", bookmarks_content).apply(); ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager); viewPager.setCurrentItem(0); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title")); final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content")); final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon")); final String bookmarks_attachment = row2 .getString(row2.getColumnIndexOrThrow("bookmarks_attachment")); final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu), getString(R.string.bookmark_createNote), getString(R.string.count_create), getString(R.string.bookmark_createShortcut), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ConstantConditions") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setHint(R.string.bookmark_edit_title); edit_title.setText(bookmarks_title); builder.setView(dialogView); builder.setTitle(R.string.bookmark_edit_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); db.update(Integer.parseInt(_id), inputTag, bookmarks_content, bookmarks_icon, bookmarks_attachment, bookmarks_creation); setBookmarksList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } if (options[item].equals(getString(R.string.todo_menu))) { Todo_helper.newTodo(getActivity(), bookmarks_title, "", ""); } if (options[item].equals(getString(R.string.count_create))) { Count_helper.newCount(getActivity(), bookmarks_title, bookmarks_content, getActivity().getString(R.string.note_content), false); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), bookmarks_title, bookmarks_content); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setBookmarksList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.bookmark_createNote))) { Notes_helper.newNote(getActivity(), bookmarks_title, bookmarks_content, "", "", "", ""); } if (options[item].equals(getString(R.string.bookmark_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.parse(bookmarks_content)); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, bookmarks_title); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext( getActivity().getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); getActivity().sendBroadcast(shortcut); Snackbar.make(lv, R.string.toast_shortcut, Snackbar.LENGTH_LONG).show(); } } }).show(); return true; } }); }
From source file:com.yyjlr.tickets.viewutils.snakebar.TSnackbar.java
/** * @param resource_id/*from ww w.ja v a 2 s. com*/ * @return */ public TSnackbar addIcon(int resource_id) { final TextView tv = mView.getMessageView(); if (resource_id != -1) { tv.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().getDrawable(resource_id), null, null, null); } return this; }
From source file:com.box.myview.MyTopSnackBar.TSnackbar.java
/** * @param resource_id image id//from ww w . j av a2s.co m * @param width image width * @param height image height * @return */ public TSnackbar addIcon(int resource_id, int width, int height) { final TextView tv = mView.getMessageView(); if (width > 0 || height > 0) { tv.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(Bitmap.createScaledBitmap( ((BitmapDrawable) (mContext.getResources().getDrawable(resource_id))).getBitmap(), width, height, true)), null, null, null); } else { addIcon(resource_id); } return this; }
From source file:org.telegram.ui.MessagesActivity.java
@Override public void applySelfActionBar() { if (parentActivity == null) { return;/*from w ww. j a v a 2s. c om*/ } final ActionBar actionBar = parentActivity.getSupportActionBar(); if (onlySelect) { actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowCustomEnabled(false); actionBar.setSubtitle(null); actionBar.setCustomView(null); actionBar.setTitle(getStringEntry(R.string.SelectChat)); ((ApplicationActivity) parentActivity).fixBackButton(); } else { ImageView view = (ImageView) parentActivity.findViewById(16908332); if (view == null) { view = (ImageView) parentActivity.findViewById(R.id.home); } if (view != null) { view.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0); } actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayUseLogoEnabled(true); actionBar.setDisplayShowCustomEnabled(false); actionBar.setCustomView(null); actionBar.setSubtitle(null); actionBar.setTitle(getStringEntry(R.string.AppName)); } TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title); if (title == null) { final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); title = (TextView) parentActivity.findViewById(subtitleId); } if (title != null) { title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); title.setCompoundDrawablePadding(0); } }
From source file:de.baumann.hhsmoodle.data_subjects.Subjects_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false); PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header); helper_main.setImageHeader(getActivity(), imgHeader); RelativeLayout filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout); filter_layout.setVisibility(View.GONE); lv = (ListView) rootView.findViewById(R.id.listNotes); viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override//ww w .ja v a 2 s .c om public void onClick(View view) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent); titleInput = (EditText) dialogView.findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(""); teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher); teacherInput.setText(""); roomInput = (EditText) dialogView.findViewById(R.id.subject_room); roomInput.setText(""); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView.findViewById(R.id.imageButtonPri); assert be != null; be.setImageResource(R.drawable.circle_grey); sharedPref.edit().putString("subject_color", "11").apply(); be.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getActivity().getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { be.setImageResource(R.drawable.circle_red); sharedPref.edit().putString("subject_color", "1").apply(); } else if (item == 1) { be.setImageResource(R.drawable.circle_pink); sharedPref.edit().putString("subject_color", "2").apply(); } else if (item == 2) { be.setImageResource(R.drawable.circle_purple); sharedPref.edit().putString("subject_color", "3").apply(); } else if (item == 3) { be.setImageResource(R.drawable.circle_blue); sharedPref.edit().putString("subject_color", "4").apply(); } else if (item == 4) { be.setImageResource(R.drawable.circle_teal); sharedPref.edit().putString("subject_color", "5").apply(); } else if (item == 5) { be.setImageResource(R.drawable.circle_green); sharedPref.edit().putString("subject_color", "6").apply(); } else if (item == 6) { be.setImageResource(R.drawable.circle_lime); sharedPref.edit().putString("subject_color", "7").apply(); } else if (item == 7) { be.setImageResource(R.drawable.circle_yellow); sharedPref.edit().putString("subject_color", "8").apply(); } else if (item == 8) { be.setImageResource(R.drawable.circle_orange); sharedPref.edit().putString("subject_color", "9").apply(); } else if (item == 9) { be.setImageResource(R.drawable.circle_brown); sharedPref.edit().putString("subject_color", "10").apply(); } else if (item == 10) { be.setImageResource(R.drawable.circle_grey); sharedPref.edit().putString("subject_color", "11").apply(); } } }).show(); } }); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.subjects_edit); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Subject_DbAdapter db = new Subject_DbAdapter(getActivity()); db.open(); String inputTitle = titleInput.getText().toString().trim(); String inputTeacher = teacherInput.getText().toString().trim(); String inputRoom = roomInput.getText().toString().trim(); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd_HH-mm-ss", Locale.getDefault()); String creation = dateFormat.format(date); if (db.isExist(creation)) { Snackbar.make(titleInput, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG) .show(); } else { db.insert(inputTitle, inputTeacher, sharedPref.getString("subject_color", ""), inputRoom, creation); dialog.dismiss(); setSubjectsList(); } } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.support.v7.app.AlertDialog dialog2 = builder.create(); dialog2.show(); } }); //calling Notes_DbAdapter db = new Subject_DbAdapter(getActivity()); db.open(); setSubjectsList(); setHasOptionsMenu(true); return rootView; }
From source file:de.baumann.hhsmoodle.data_courses.Courses_Fragment.java
private void setCoursesList() { if (isFABOpen) { closeFABMenu();/* w ww.jav a2s .c o m*/ } //display data final int layoutstyle = R.layout.list_item_notes; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "courses_title", "courses_content", "courses_creation" }; final Cursor row = db.fetchAllData(); SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); iv_icon.setVisibility(View.GONE); return v; } }; lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { if (isFABOpen) { closeFABMenu(); } Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String courses_title = row2.getString(row2.getColumnIndexOrThrow("courses_title")); final String courses_content = row2.getString(row2.getColumnIndexOrThrow("courses_content")); final CharSequence[] options = { getString(R.string.courseList_todo), getString(R.string.courseList_note), getString(R.string.courseList_random), getString(R.string.courseList_subject), getString(R.string.bookmark_createEvent) }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.courseList_random))) { android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder( getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null); final EditText edit_title = (EditText) dialogView .findViewById(R.id.note_title_input); edit_title.setHint(R.string.title_hint); edit_title.setText(courses_title); final EditText edit_cont = (EditText) dialogView .findViewById(R.id.note_text_input); edit_cont.setHint(R.string.text_hint); edit_cont.setText(courses_content); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.app.AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Do stuff, possibly set wantToCloseDialog to true then... Random_DbAdapter db = new Random_DbAdapter(getActivity()); db.open(); String inputTitle = edit_title.getText().toString().trim(); String inputCont = edit_cont.getText().toString().trim(); if (db.isExist(inputTitle)) { Snackbar.make(edit_title, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(inputTitle, inputCont, "", "", helper_main.createDate()); dialog2.dismiss(); } } }); helper_main.showKeyboard(getActivity(), edit_title); } if (options[item].equals(getString(R.string.courseList_note))) { Notes_helper.newNote(getActivity(), courses_title, "", "", "", "", ""); } if (options[item].equals(getString(R.string.courseList_todo))) { Todo_helper.newTodo(getActivity(), courses_title, courses_content, getActivity().getString(R.string.note_content)); } if (options[item].equals(getString(R.string.courseList_subject))) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent); titleInput = (EditText) dialogView.findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(""); teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher); teacherInput.setText(courses_title); roomInput = (EditText) dialogView.findViewById(R.id.subject_room); roomInput.setText(""); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView .findViewById(R.id.imageButtonPri); assert be != null; be.setImageResource(R.drawable.circle_grey); sharedPref.edit().putString("subject_color", "11").apply(); be.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getActivity().getResources() .getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { be.setImageResource(R.drawable.circle_red); sharedPref.edit().putString("subject_color", "1") .apply(); } else if (item == 1) { be.setImageResource(R.drawable.circle_pink); sharedPref.edit().putString("subject_color", "2") .apply(); } else if (item == 2) { be.setImageResource(R.drawable.circle_purple); sharedPref.edit().putString("subject_color", "3") .apply(); } else if (item == 3) { be.setImageResource(R.drawable.circle_blue); sharedPref.edit().putString("subject_color", "4") .apply(); } else if (item == 4) { be.setImageResource(R.drawable.circle_teal); sharedPref.edit().putString("subject_color", "5") .apply(); } else if (item == 5) { be.setImageResource(R.drawable.circle_green); sharedPref.edit().putString("subject_color", "6") .apply(); } else if (item == 6) { be.setImageResource(R.drawable.circle_lime); sharedPref.edit().putString("subject_color", "7") .apply(); } else if (item == 7) { be.setImageResource(R.drawable.circle_yellow); sharedPref.edit().putString("subject_color", "8") .apply(); } else if (item == 8) { be.setImageResource(R.drawable.circle_orange); sharedPref.edit().putString("subject_color", "9") .apply(); } else if (item == 9) { be.setImageResource(R.drawable.circle_brown); sharedPref.edit().putString("subject_color", "10") .apply(); } else if (item == 10) { be.setImageResource(R.drawable.circle_grey); sharedPref.edit().putString("subject_color", "11") .apply(); } } }).show(); } }); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.subjects_edit); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Subject_DbAdapter db = new Subject_DbAdapter(getActivity()); db.open(); String inputTitle = titleInput.getText().toString().trim(); String inputTeacher = teacherInput.getText().toString().trim(); String inputRoom = roomInput.getText().toString().trim(); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat( "yy-MM-dd_HH-mm-ss", Locale.getDefault()); String creation = dateFormat.format(date); if (db.isExist(inputTitle)) { Snackbar.make(titleInput, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(inputTitle, inputTeacher, sharedPref.getString("subject_color", ""), inputRoom, creation); dialog.dismiss(); } } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.support.v7.app.AlertDialog dialog2 = builder.create(); dialog2.show(); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), courses_title, courses_content); } } }).show(); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (isFABOpen) { closeFABMenu(); } Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String courses_title = row2.getString(row2.getColumnIndexOrThrow("courses_title")); final String courses_content = row2.getString(row2.getColumnIndexOrThrow("courses_content")); final String courses_icon = row2.getString(row2.getColumnIndexOrThrow("courses_icon")); final String courses_attachment = row2.getString(row2.getColumnIndexOrThrow("courses_attachment")); final String courses_creation = row2.getString(row2.getColumnIndexOrThrow("courses_creation")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark) }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder( getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null); final EditText edit_title = (EditText) dialogView .findViewById(R.id.note_title_input); edit_title.setHint(R.string.title_hint); edit_title.setText(courses_title); final EditText edit_cont = (EditText) dialogView .findViewById(R.id.note_text_input); edit_cont.setHint(R.string.text_hint); edit_cont.setText(courses_content); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTitle = edit_title.getText().toString().trim(); String inputCont = edit_cont.getText().toString().trim(); db.update(Integer.parseInt(_id), inputTitle, inputCont, courses_icon, courses_attachment, courses_creation); setCoursesList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.app.AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setCoursesList(); } }); snackbar.show(); } } }).show(); return true; } }); }
From source file:com.nttec.everychan.ui.NewTabFragment.java
private void openLocal() { if (!CompatibilityUtils.hasAccessStorage(activity)) return;// ww w .j a v a 2s . c o m final ListAdapter savedThreadsAdapter = new ArrayAdapter<Object>(activity, 0) { private static final int HEAD_ITEM = 0; private static final int NORMAL_ITEM = 1; private LayoutInflater inflater = LayoutInflater.from(activity); private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); { add(new Object()); for (Database.SavedThreadEntry entity : MainApplication.getInstance().database.getSavedThreads()) { File file = new File(entity.filepath); if (file.exists()) add(entity); } } @Override public View getView(int position, View convertView, ViewGroup parent) { View v; if (position == 0) { v = convertView == null ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false) : convertView; TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setText(R.string.newtab_select_local_file); } else { Database.SavedThreadEntry item = (Database.SavedThreadEntry) getItem(position); v = convertView == null ? inflater.inflate(android.R.layout.simple_list_item_2, parent, false) : convertView; TextView t1 = (TextView) v.findViewById(android.R.id.text1); TextView t2 = (TextView) v.findViewById(android.R.id.text2); t1.setSingleLine(); t2.setSingleLine(); t1.setEllipsize(TextUtils.TruncateAt.END); t2.setEllipsize(TextUtils.TruncateAt.START); t1.setText(item.title); t2.setText(item.filepath); ChanModule chan = MainApplication.getInstance().getChanModule(item.chan); if (chan != null) { t1.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null); t1.setCompoundDrawablePadding(drawablePadding); } } return v; } @Override public int getViewTypeCount() { return 2; } @Override public int getItemViewType(int position) { return position == 0 ? HEAD_ITEM : NORMAL_ITEM; } }; if (savedThreadsAdapter.getCount() == 1) { selectFile(); return; } DialogInterface.OnClickListener listListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { selectFile(); } else { Database.SavedThreadEntry item = (Database.SavedThreadEntry) savedThreadsAdapter.getItem(which); LocalHandler.open(item.filepath, activity); } } }; new AlertDialog.Builder(activity).setTitle(R.string.newtab_saved_threads_title) .setAdapter(savedThreadsAdapter, listListener).setNegativeButton(android.R.string.cancel, null) .show(); }
From source file:dylan.com.adoptapet.SlidingTabLayout.java
private void populateTabStrip() { final HomePagerAdapter adapter = (HomePagerAdapter) mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//from www . j a v a2 s .co m TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i)); tabTitleView.setCompoundDrawablesWithIntrinsicBounds(0, adapter.getTabDrawable(i), 0, 0); tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
From source file:com.openerp.addons.messages.MessageDetail.java
/** * Sets the up list view.// w w w . j a v a 2 s . c o m * * @param list * the new up list view */ private boolean setupListView(final List<OEListViewRows> list) { // Handling List View controls and keys String[] from = new String[] { "image", "email_from|name", "email_from|email", "body", "date", "partners", "starred", "vote_nb" }; int[] to = new int[] { R.id.imgUserPicture, R.id.txvMessageAuthor, R.id.txvAuthorEmail, R.id.webViewMessageBody, R.id.txvTime, R.id.txvTo, R.id.imgBtnStar, R.id.txvmessageVotenb }; // Creating instance for listAdapter listAdapter = new OEListViewAdapter(scope.context(), R.layout.message_detail_listview_items, list, from, to, db); listAdapter.toHTML("body", true); listAdapter.addImageColumn("image"); // listAdapter.layoutBackgroundColor("parent_id", // Color.parseColor("#aaaaaa"), Color.parseColor("#0099cc")); listAdapter.cleanDate("date", scope.User().getTimezone(), "MMM dd, yyyy, hh:mm a"); listAdapter.addViewListener(new OEListViewOnCreateListener() { @Override public View listViewOnCreateListener(final int position, View row_view, OEListViewRows row_data) { final int message_id = row_data.getRow_id(); final HashMap<String, Object> row_values = row_data.getRow_data(); /* handling vote control */ final TextView txvVote = (TextView) row_view.findViewById(R.id.txvmessageVotenb); final int vote_nb = Integer.parseInt(row_data.getRow_data().get("vote_nb").toString()); if (vote_nb == 0) { txvVote.setText(""); } final boolean hasVoted = Boolean.parseBoolean(row_data.getRow_data().get("has_voted").toString()); if (!hasVoted) { txvVote.setCompoundDrawablesWithIntrinsicBounds( getResources().getDrawable(R.drawable.ic_thumbs_up_unselected_dark_tablet), null, null, null); // txvVote.setBackgroundResource(R.drawable.vote_background_selector_gray); } else { // txvVote.setBackgroundResource(R.drawable.vote_background_selector_blue); txvVote.setCompoundDrawablesWithIntrinsicBounds( getResources().getDrawable(R.drawable.ic_thumbs_up_selected_dark_tablet), null, null, null); } txvVote.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { MessageVoteToggle voteToggle = new MessageVoteToggle(message_id, vote_nb, hasVoted); String newVote = ""; boolean btnvoted = false; if (hasVoted) { newVote = (vote_nb - 1) + ""; row_values.put("has_voted", "false"); } else { btnvoted = true; newVote = (vote_nb + 1) + ""; row_values.put("has_voted", "true"); } row_values.put("vote_nb", newVote); listAdapter.updateRow(position, new OEListViewRows(message_id, row_values)); voteToggle.execute((Void) null); txvVote.setText(newVote); if (!btnvoted) { txvVote.setCompoundDrawablesWithIntrinsicBounds( getResources().getDrawable(R.drawable.ic_thumbs_up_unselected_dark_tablet), null, null, null); // txvVote.setBackgroundResource(R.drawable.vote_background_selector_gray); } else { // txvVote.setBackgroundResource(R.drawable.vote_background_selector_blue); txvVote.setCompoundDrawablesWithIntrinsicBounds( getResources().getDrawable(R.drawable.ic_thumbs_up_selected_dark_tablet), null, null, null); } } }); /* handling attachments */ List<OEListViewRows> attachments = getAttachmentsOfMessage(row_data.getRow_id() + ""); int index = 0; if (attachments.size() > 0) { LayoutInflater vi = (LayoutInflater) scope.context().getApplicationContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View insertPoint = row_view.findViewById(R.id.gridAttachments); ((ViewGroup) insertPoint).removeAllViews(); for (OEListViewRows row : attachments) { View v = vi.inflate(R.layout.fragment_message_detail_attachment_grid_item, null, true); TextView txvAttachmentName = (TextView) v.findViewById(R.id.txvFileName); txvAttachmentName.setText(row.getRow_data().get("name").toString()); TextView txvAttachmentSize = (TextView) v.findViewById(R.id.txvFileSize); long fileSize = Long.parseLong(row.getRow_data().get("file_size").toString()); String file_size = OEFileSizeHelper.readableFileSize(fileSize); txvAttachmentSize.setText((file_size.equals("0")) ? " " : file_size); TextView txvAttachmentId = (TextView) v.findViewById(R.id.txvAttachmentId); txvAttachmentId.setText(String.valueOf(row.getRow_id())); ((ViewGroup) insertPoint).addView(v, index, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); v.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int attachment_id = Integer.parseInt( ((TextView) v.findViewById(R.id.txvAttachmentId)).getText().toString()); OEBinaryDownloadHelper binaryDownload = new OEBinaryDownloadHelper(); binaryDownload.downloadBinary(attachment_id, db); } }); index++; } } else { row_view.findViewById(R.id.layoutMessageAttachments).setVisibility(View.GONE); } OEContactView oe_contactView = (OEContactView) row_view.findViewById(R.id.imgUserPicture); int partner_id = Integer.parseInt(row_data.getRow_data().get("partner_id").toString()); oe_contactView.assignPartnerId(partner_id); return row_view; } }); listAdapter.setItemClickListener(R.id.imgBtnReply, new ControlClickEventListener() { @Override public OEListViewRows controlClicked(int position, OEListViewRows row, View view) { Intent composeIntent = new Intent(scope.context(), MessageComposeActivty.class); composeIntent.putExtra("message_id", message_id); composeIntent.putExtra("send_reply", true); startActivityForResult(composeIntent, MESSAGE_REPLY); return null; } }); // Setting callback handler for boolean field value change. listAdapter.setBooleanEventOperation("starred", R.drawable.ic_action_starred, R.drawable.ic_action_unstarred, updateStarred); GridView lstview = (GridView) rootView.findViewById(R.id.lstMessageDetail); // Providing adapter to listview lstview.setAdapter(listAdapter); return true; }