List of usage examples for android.widget SimpleCursorAdapter SimpleCursorAdapter
public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)
From source file:blackman.matt.infinitebrowser.NavigationDrawerFragment.java
/** * Sets up the list adapter for the list of boards the user is following. *//*from www . j a va 2 s . c o m*/ private void setUpListAdapter() { BoardListDatabase boardListDB; Cursor cursor; boardListDB = new BoardListDatabase(getActivity()); cursor = boardListDB.getFavoritedBoards(); String[] from = new String[] { "boardlink" }; int[] to = new int[] { R.id.text }; SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(mDrawerListView.getContext(), R.layout.drawer_item, cursor, from, to, 0) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); if (position % 2 == 1) { view.setBackgroundColor(getActivity().getResources().getColor(R.color.row_color_2)); } return view; } }; mDrawerListView.setAdapter(cursorAdapter); boardListDB.close(); }
From source file:de.baumann.hhsmoodle.data_schedule.Schedule_Fragment.java
private void setScheduleList() { final int line = sharedPref.getInt("getLine", 1); //display data final int layoutstyle = R.layout.list_item_schedule; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes, R.id.textView_create_notes }; String[] column = new String[] { "schedule_title", "schedule_content", "schedule_attachment", "schedule_creation" }; final Cursor row = db.fetchAllData(); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override/*from w w w . j a va 2 s . c o m*/ public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); if (position == line) { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent_trans)); } else { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.color_trans)); } if (schedule_title.equals(getActivity().getString(R.string.schedule_weekend)) || schedule_title.equals(getActivity().getString(R.string.schedule_def_title))) { sharedPref.edit().putString("hour_" + schedule_id, "false").apply(); } else { sharedPref.edit().putString("hour_" + schedule_id, "true").apply(); } Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", iv_icon); iv_icon.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 * 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), schedule_title, schedule_content, "1", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 1) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "2", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 2) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "3", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 3) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "4", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 4) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "5", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 5) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "6", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 6) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "7", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 7) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "8", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 8) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "9", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 9) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "10", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 10) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "11", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } } }).show(); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_scheduleBY", "schedule_title"); sharedPref.edit().putString("filter_scheduleBY", "schedule_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 schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final CharSequence[] options = { getString(R.string.schedule_todo), getString(R.string.schedule_notes) }; 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() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.schedule_todo))) { sharedPref.edit().putString("filter_todo_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_todo.class, false); } }, 200); } if (options[item].equals(getString(R.string.schedule_notes))) { sharedPref.edit().putString("filter_note_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_note.class, false); } }, 200); } } }).show(); } }); 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 schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); 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_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))) { final CharSequence[] options = { getString(R.string.schedule_fromSubjectList), getString(R.string.todo_from_new) }; 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() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item] .equals(getString(R.string.schedule_fromSubjectList))) { sharedPref.edit().putString("edit_yes", "true") .putInt("scroll", Integer.parseInt(schedule_id)) .putString("handleSubjectCreation", schedule_creation) .putString("handleSubject_id", schedule_id) .putString("handle_id", _id).apply(); helper_main.switchToActivity(getActivity(), Popup_subjects.class, false); } if (options[item].equals(getString(R.string.todo_from_new))) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater .inflate(R.layout.dialog_edit_subject, nullParent); final EditText titleInput = (EditText) dialogView .findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(schedule_title); final EditText teacherInput = (EditText) dialogView .findViewById(R.id.subject_teacher); teacherInput.setText(schedule_content); final EditText roomInput = (EditText) dialogView .findViewById(R.id.subject_room); roomInput.setText(schedule_attachment); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView .findViewById(R.id.imageButtonPri); assert be != null; Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", be); 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( "schedule_color", "1") .apply(); } else if (item == 1) { be.setImageResource( R.drawable.circle_pink); sharedPref.edit() .putString( "schedule_color", "2") .apply(); } else if (item == 2) { be.setImageResource( R.drawable.circle_purple); sharedPref.edit() .putString( "schedule_color", "3") .apply(); } else if (item == 3) { be.setImageResource( R.drawable.circle_blue); sharedPref.edit() .putString( "schedule_color", "4") .apply(); } else if (item == 4) { be.setImageResource( R.drawable.circle_teal); sharedPref.edit() .putString( "schedule_color", "5") .apply(); } else if (item == 5) { be.setImageResource( R.drawable.circle_green); sharedPref.edit() .putString( "schedule_color", "6") .apply(); } else if (item == 6) { be.setImageResource( R.drawable.circle_lime); sharedPref.edit() .putString( "schedule_color", "7") .apply(); } else if (item == 7) { be.setImageResource( R.drawable.circle_yellow); sharedPref.edit() .putString( "schedule_color", "8") .apply(); } else if (item == 8) { be.setImageResource( R.drawable.circle_orange); sharedPref.edit() .putString( "schedule_color", "9") .apply(); } else if (item == 9) { be.setImageResource( R.drawable.circle_brown); sharedPref.edit() .putString( "schedule_color", "10") .apply(); } else if (item == 10) { be.setImageResource( R.drawable.circle_grey); sharedPref.edit() .putString( "schedule_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) { String inputTitle = titleInput.getText() .toString().trim(); String inputTeacher = teacherInput.getText() .toString().trim(); String inputRoom = roomInput.getText() .toString().trim(); db.update(Integer.parseInt(_id), inputTitle, inputTeacher, sharedPref.getString( "schedule_color", ""), inputRoom, schedule_creation, schedule_id); dialog.dismiss(); setScheduleList(); lv.setSelection( Integer.parseInt(schedule_id) - 1); 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.support.v7.app.AlertDialog dialog2 = builder .create(); dialog2.show(); } } }).show(); } 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.update(Integer.parseInt(_id), getString(R.string.schedule_def_teacher), getString(R.string.schedule_def_teacher), "11", getString(R.string.schedule_def_teacher), schedule_creation, schedule_id); setScheduleList(); lv.setSelection(Integer.parseInt(schedule_id) - 1); } }); snackbar.show(); } if (options[item].equals(getString(R.string.todo_menu))) { Todo_helper.newTodo(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content)); } if (options[item].equals(getString(R.string.count_create))) { Count_helper.newCount(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content), false); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), schedule_title, schedule_content); } if (options[item].equals(getString(R.string.bookmark_createNote))) { Notes_helper.newNote(getActivity(), schedule_title, schedule_content, "", "", "", ""); } } }).show(); return true; } }); scrollToNow(); }
From source file:net.olejon.mdapp.AtcActivity.java
private void getTherapeuticGroups() { mToolbar.setTitle(mTherapeuticGroupsTitle); mGroup = "therapeutic_groups"; mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_ATC_THERAPEUTIC_GROUPS, null, SlDataSQLiteHelper.ATC_THERAPEUTIC_GROUPS_COLUMN_CODE + " LIKE " + mTools.sqe(mPharmacologicGroupsCode + "%"), null, null, null, SlDataSQLiteHelper.ATC_THERAPEUTIC_GROUPS_COLUMN_CODE); String[] fromColumns = new String[] { SlDataSQLiteHelper.ATC_THERAPEUTIC_GROUPS_COLUMN_CODE, SlDataSQLiteHelper.ATC_THERAPEUTIC_GROUPS_COLUMN_NAME }; int[] toViews = new int[] { R.id.atc_therapeutic_groups_list_item_code, R.id.atc_therapeutic_groups_list_item_name }; SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(mContext, R.layout.activity_atc_therapeutic_groups_list_item, mCursor, fromColumns, toViews, 0); mListView.setAdapter(simpleCursorAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w ww . j a v a 2s . c om public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mCursor.moveToPosition(i)) { mTherapeuticGroupsCode = mCursor.getString( mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_THERAPEUTIC_GROUPS_COLUMN_CODE)); mSubstancesGroupsTitle = mCursor.getString( mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_THERAPEUTIC_GROUPS_COLUMN_NAME)); getSubstancesGroups(); } } }); }
From source file:de.baumann.browser.popups.Popup_files.java
private void setFilesList() { deleteDatabase("files_DB_v01.db"); File f = new File(sharedPref.getString("files_startFolder", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())); final File[] files = f.listFiles(); Arrays.sort(files, new Comparator<File>() { @Override//from w w w. ja v a2s. co m public int compare(File file1, File file2) { if (file1.isDirectory()) { if (file2.isDirectory()) { return String.valueOf(file1.getName().toLowerCase()) .compareTo(file2.getName().toLowerCase()); } else { return -1; } } else { if (file2.isDirectory()) { return 1; } else { return String.valueOf(file1.getName().toLowerCase()) .compareTo(file2.getName().toLowerCase()); } } } }); // looping through all items <item> if (files.length == 0) { Snackbar.make(listView, R.string.toast_files, Snackbar.LENGTH_LONG).show(); } for (File file : files) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String file_Name = file.getName().substring(0, 1).toUpperCase() + file.getName().substring(1); String file_Size = getReadableFileSize(file.length()); String file_date = formatter.format(new Date(file.lastModified())); String file_path = file.getAbsolutePath(); String file_ext; if (file.isDirectory()) { file_ext = "."; } else { file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".")); } db.open(); if (db.isExist(file_Name)) { Log.i(TAG, "Entry exists" + file_Name); } else { db.insert(file_Name, file_Size, file_ext, file_path, file_date); } } try { db.insert("...", "", "", "", ""); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } //display data final int layoutstyle = R.layout.list_item; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "files_title", "files_content", "files_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); View v = super.getView(position, convertView, parent); final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes); iv.setVisibility(View.VISIBLE); if (pathFile.isDirectory()) { iv.setImageResource(R.drawable.folder); } else { switch (files_icon) { case "": iv.setImageResource(R.drawable.arrow_up_dark); break; case ".m3u8": case ".mp3": case ".wma": case ".midi": case ".wav": case ".aac": case ".aif": case ".amp3": case ".weba": case ".ogg": iv.setImageResource(R.drawable.file_music); break; case ".mpeg": case ".mp4": case ".webm": case ".qt": case ".3gp": case ".3g2": case ".avi": case ".f4v": case ".flv": case ".h261": case ".h263": case ".h264": case ".asf": case ".wmv": try { Glide.with(Popup_files.this).load(files_attachment) // or URI/path .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_video); } break; case ".vcs": case ".vcf": case ".css": case ".ics": case ".conf": case ".config": case ".java": case ".html": iv.setImageResource(R.drawable.file_xml); break; case ".apk": iv.setImageResource(R.drawable.android); break; case ".pdf": iv.setImageResource(R.drawable.file_pdf); break; case ".rtf": case ".csv": case ".txt": case ".doc": case ".xls": case ".ppt": case ".docx": case ".pptx": case ".xlsx": case ".odt": case ".ods": case ".odp": iv.setImageResource(R.drawable.file_document); break; case ".zip": case ".rar": iv.setImageResource(R.drawable.zip_box); break; case ".gif": case ".bmp": case ".tiff": case ".svg": case ".png": case ".jpg": case ".JPG": case ".jpeg": try { Glide.with(Popup_files.this).load(files_attachment) // or URI/path .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true) .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_image); } break; default: iv.setImageResource(R.drawable.file); break; } } if (files_attachment.isEmpty()) { new Handler().postDelayed(new Runnable() { public void run() { iv.setImageResource(R.drawable.arrow_up_dark); } }, 350); } return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_filesBY", "files_title"); sharedPref.edit().putString("filter_filesBY", "files_title").apply(); editText.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); } }); listView.setAdapter(adapter); //onClick function listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { try { sharedPref.edit().putString("files_startFolder", files_attachment).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_attachment.equals("")) { try { final File pathActual = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath())); sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else { helper_main.open(files_icon, Popup_files.this, pathFile, listView); } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { Snackbar snackbar = Snackbar .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { sharedPref.edit().putString("files_startFolder", pathFile.getParent()).apply(); deleteRecursive(pathFile); setFilesList(); } }); snackbar.show(); } else { final CharSequence[] options = { getString(R.string.choose_menu_2), getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) }; final AlertDialog.Builder dialog = new AlertDialog.Builder(Popup_files.this); dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); dialog.setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.choose_menu_2))) { if (pathFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title); Uri bmpUri = Uri.fromFile(pathFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_file)))); } } if (options[item].equals(getString(R.string.choose_menu_4))) { Snackbar snackbar = Snackbar .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { pathFile.delete(); setFilesList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.choose_menu_3))) { sharedPref.edit().putString("pathFile", files_attachment).apply(); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Popup_files.this, editText, 2, files_title, getString(R.string.bookmark_edit_title)); } } }); dialog.show(); } return true; } }); }
From source file:com.nononsenseapps.notepad.MainActivity.java
private void leftOrTabletCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { // currentListId = savedInstanceState.getLong(CURRENT_LIST_ID); listIdToSelect = savedInstanceState.getLong(CURRENT_LIST_ID); // currentListPos = savedInstanceState.getInt(CURRENT_LIST_POS); }//from w w w.ja v a 2s . c o m // Set up dropdown navigation final ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); // Will set cursor in Loader // mSpinnerAdapter = new ExtrasCursorAdapter(this, // R.layout.actionbar_dropdown_item, null, // new String[] { NotePad.Lists.COLUMN_NAME_TITLE }, // new int[] { android.R.id.text1 }, new int[] { -9, -8 }, // new int[] { R.string.show_from_all_lists, R.string.error_title }); mSpinnerAdapter = new SimpleCursorAdapter(this, R.layout.actionbar_dropdown_item, null, new String[] { NotePad.Lists.COLUMN_NAME_TITLE }, new int[] { android.R.id.text1 }, 0); mSpinnerAdapter.setDropDownViewResource(R.layout.actionbar_dropdown_item); // This will listen for navigation callbacks actionBar.setListNavigationCallbacks(mSpinnerAdapter, this); // setContentView(R.layout.fragment_layout); // setUpList(); mSectionAdapter = new SimpleCursorAdapter(this, R.layout.actionbar_dropdown_item, null, new String[] { NotePad.Lists.COLUMN_NAME_TITLE }, new int[] { android.R.id.text1 }, 0); mSectionsPagerAdapter = new ListPagerAdapter(this, getFragmentManager(), mSectionAdapter); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.leftFragment); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int pos) { currentListId = mSectionsPagerAdapter.getItemId(pos); currentListPos = pos; actionBar.setSelectedNavigationItem(pos); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); // Set up navigation list // Set a default list to open if one is set if (listIdToSelect < 0) { listIdToSelect = getAList(this, -1); // Select the first note in that list to open also noteIdToSelect = getANote(this, listIdToSelect); } // Handle the intent first, so we know what to possibly select once // the // loader is finished beforeBoot = true; if (!resuming) { onNewIntent(getIntent()); } getLoaderManager().initLoader(0, null, this); }
From source file:de.baumann.hhsmoodle.data_files.Files_Fragment.java
public void setFilesList() { getActivity().deleteDatabase("files_DB_v01.db"); File f = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath() + "/HHS_Moodle/")); final File[] files = f.listFiles(); // looping through all items <item> if (files.length == 0) { Snackbar.make(lv, R.string.toast_files, Snackbar.LENGTH_LONG).show(); }/*from w ww . j a v a2 s. c om*/ for (File file : files) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String file_Name = file.getName(); String file_Size = getReadableFileSize(file.length()); String file_date = formatter.format(new Date(file.lastModified())); String file_path = file.getAbsolutePath(); String file_ext; if (file.isDirectory()) { file_ext = "."; } else { file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".")); } db.open(); if (db.isExist(file_Name)) { Log.i(TAG, "Entry exists" + file_Name); } else { db.insert(file_Name, file_Size, file_ext, file_path, file_date); } } try { db.insert("...", "", "", "", ""); } catch (Exception e) { Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } //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[] { "files_title", "files_content", "files_creation" }; final Cursor row = db.fetchAllData(getActivity()); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); View v = super.getView(position, convertView, parent); final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes); iv.setVisibility(View.VISIBLE); if (pathFile.isDirectory()) { iv.setImageResource(R.drawable.folder); } else { switch (files_icon) { case "": new Handler().postDelayed(new Runnable() { public void run() { iv.setImageResource(R.drawable.arrow_up); } }, 200); break; case ".gif": case ".bmp": case ".tiff": case ".svg": case ".png": case ".jpg": case ".JPG": case ".jpeg": try { Glide.with(getActivity()).load(files_attachment) // or URI/path .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_image); } break; case ".m3u8": case ".mp3": case ".wma": case ".midi": case ".wav": case ".aac": case ".aif": case ".amp3": case ".weba": case ".ogg": iv.setImageResource(R.drawable.file_music); break; case ".mpeg": case ".mp4": case ".webm": case ".qt": case ".3gp": case ".3g2": case ".avi": case ".f4v": case ".flv": case ".h261": case ".h263": case ".h264": case ".asf": case ".wmv": try { Glide.with(getActivity()).load(files_attachment) // or URI/path .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to } catch (Exception e) { Log.w("HHS_Moodle", "Error load thumbnail", e); iv.setImageResource(R.drawable.file_video); } break; case ".vcs": case ".vcf": case ".css": case ".ics": case ".conf": case ".config": case ".java": case ".html": iv.setImageResource(R.drawable.file_xml); break; case ".apk": iv.setImageResource(R.drawable.android); break; case ".pdf": iv.setImageResource(R.drawable.file_pdf); break; case ".rtf": case ".csv": case ".txt": case ".doc": case ".xls": case ".ppt": case ".docx": case ".pptx": case ".xlsx": case ".odt": case ".ods": case ".odp": iv.setImageResource(R.drawable.file_document); break; case ".zip": case ".rar": iv.setImageResource(R.drawable.zip_box); break; default: iv.setImageResource(R.drawable.file); break; } } return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_filesBY", "files_title"); sharedPref.edit().putString("filter_filesBY", "files_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 files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { try { sharedPref.edit().putString("files_startFolder", files_attachment).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_attachment.equals("")) { try { final File pathActual = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath())); sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else { helper_main.openAtt(getActivity(), lv, files_attachment); } } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { 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) { sharedPref.edit().putString("files_startFolder", pathFile.getParent()).apply(); deleteRecursive(pathFile); setFilesList(); } }); snackbar.show(); } else { final CharSequence[] options = { getString(R.string.choose_menu_2), getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) }; final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); dialog.setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.choose_menu_2))) { if (pathFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title); Uri bmpUri = Uri.fromFile(pathFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_file)))); } } if (options[item].equals(getString(R.string.choose_menu_4))) { 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) { pathFile.delete(); setFilesList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.choose_menu_3))) { android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder( getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_file, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setText(files_title); builder.setView(dialogView); builder.setTitle(R.string.choose_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); File dir = pathFile.getParentFile(); File to = new File(dir, inputTag); pathFile.renameTo(to); pathFile.delete(); setFilesList(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } } }); dialog.show(); } return true; } }); }
From source file:file_manager.Activity_files.java
private void setFilesList() { deleteDatabase("files_DB_v01.db"); String folder = sharedPref.getString("folder", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()); File f = new File(sharedPref.getString("files_startFolder", folder)); final File[] files = f.listFiles(); if (files == null || files.length == 0) { Snackbar.make(listView, R.string.toast_files, Snackbar.LENGTH_LONG).show(); } else {/* w ww.ja va 2 s. c o m*/ // looping through all items <item> for (File file : files) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String file_Name = file.getName(); String file_Size = getReadableFileSize(file.length()); String file_date = formatter.format(new Date(file.lastModified())); String file_path = file.getAbsolutePath(); String file_ext; if (file.isDirectory()) { file_ext = "."; } else { file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".")); } db.open(); if (file_ext.equals(".") || file_ext.equals(".pdf") || file_ext.equals(".") || file_ext.equals(".jpg") || file_ext.equals(".JPG") || file_ext.equals(".jpeg") || file_ext.equals(".png")) { if (db.isExist(file_Name)) { Log.i(TAG, "Entry exists" + file_Name); } else { db.insert(file_Name, file_Size, file_ext, file_path, file_date); } } } } try { db.insert("...", "", "", "", ""); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } //display data final int layoutstyle = R.layout.list_item; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "files_title", "files_content", "files_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final File pathFile = new File(files_attachment); View v = super.getView(position, convertView, parent); final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes); iv.setVisibility(View.VISIBLE); if (pathFile.isDirectory()) { iv.setImageResource(R.drawable.folder); } else { switch (files_icon) { case ".gif": case ".bmp": case ".tiff": case ".svg": case ".png": case ".jpg": case ".JPG": case ".jpeg": try { Uri uri = Uri.fromFile(pathFile); Picasso.with(Activity_files.this).load(uri).resize(76, 76).centerCrop().into(iv); } catch (Exception e) { Log.w("HHS_Moodle", "Error Load image", e); } break; case ".pdf": iv.setImageResource(R.drawable.file_pdf); break; default: iv.setImageResource(R.drawable.arrow_up_dark); break; } } if (files_title.equals("...")) { new Handler().postDelayed(new Runnable() { public void run() { iv.setImageResource(R.drawable.arrow_up_dark); } }, 200); } return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_filesBY", "files_title"); sharedPref.edit().putString("filter_filesBY", "files_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); } }); listView.setAdapter(adapter); //onClick function listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { try { sharedPref.edit().putString("files_startFolder", files_attachment).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_attachment.equals("")) { try { final File pathActual = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath())); sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_icon.equals(".pdf")) { Uri uri = Uri.fromFile(pathFile); Intent intent = new Intent(Activity_files.this, MuPDFActivity.class); intent.setAction(Intent.ACTION_VIEW); intent.setData(uri); startActivity(intent); } else { helper_main.open(files_icon, Activity_files.this, pathFile, listView); } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { Snackbar snackbar = Snackbar .make(listView, R.string.toast_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { deleteRecursive(pathFile); setFilesList(); } }); snackbar.show(); } else { final CharSequence[] options = { getString(R.string.choose_menu_2), getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) }; final AlertDialog.Builder dialog = new AlertDialog.Builder(Activity_files.this); dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); dialog.setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.choose_menu_2))) { if (pathFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title); Uri bmpUri = Uri.fromFile(pathFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_file)))); } } if (options[item].equals(getString(R.string.choose_menu_4))) { Snackbar snackbar = Snackbar .make(listView, R.string.toast_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { pathFile.delete(); setFilesList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.choose_menu_3))) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity_files.this); View dialogView = View.inflate(Activity_files.this, R.layout.dialog_edit_file, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setText(files_title); builder.setView(dialogView); builder.setTitle(R.string.choose_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); File dir = pathFile.getParentFile(); File to = new File(dir, inputTag); pathFile.renameTo(to); pathFile.delete(); setFilesList(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(Activity_files.this, edit_title); } } }); dialog.show(); } return true; } }); }
From source file:course1778.mobileapp.safeMedicare.Main.FamMemFrag.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); //ListView listView = (ListView) view.findViewById(R.id.list_view); SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.fam_mem_frag, current, new String[] { DatabaseHelper.TITLE, //String.format(format, DatabaseHelper.TIME_H), DatabaseHelper.TIME_H, //String.format(format, DatabaseHelper.TIME_M)}, DatabaseHelper.TIME_M }, new int[] { R.id.title, R.id.time_h, R.id.time_m }, 0); setListAdapter(adapter);/*from w w w .j ava 2 s . com*/ //listView.setAdapter(adapter); // if (current == null) { db = new DatabaseHelper(getActivity()); dbInteraction = new DatabaseInteractionHelper(getActivity()); task = new LoadCursorTask().execute(); // } view.setFocusableInTouchMode(true); view.requestFocus(); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Intent intent = new Intent(getActivity().getApplicationContext(), WelcomePage.class); startActivity(intent); return true; } else { return false; } } }); }
From source file:net.olejon.mdapp.AtcActivity.java
private void getSubstancesGroups() { mToolbar.setTitle(mSubstancesGroupsTitle); mGroup = "substances_groups"; mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_ATC_SUBSTANCES_GROUPS, null, SlDataSQLiteHelper.ATC_SUBSTANCES_GROUPS_COLUMN_CODE + " LIKE " + mTools.sqe(mTherapeuticGroupsCode + "%"), null, null, null, SlDataSQLiteHelper.ATC_SUBSTANCES_GROUPS_COLUMN_CODE); String[] fromColumns = new String[] { SlDataSQLiteHelper.ATC_SUBSTANCES_GROUPS_COLUMN_CODE, SlDataSQLiteHelper.ATC_SUBSTANCES_GROUPS_COLUMN_NAME }; int[] toViews = new int[] { R.id.atc_substances_groups_list_item_code, R.id.atc_substances_groups_list_item_name }; SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(mContext, R.layout.activity_atc_substances_groups_list_item, mCursor, fromColumns, toViews, 0); mListView.setAdapter(simpleCursorAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// w w w. j ava 2 s. co m public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mCursor.moveToPosition(i)) { String code = mCursor.getString( mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_SUBSTANCES_GROUPS_COLUMN_CODE)); Intent intent = new Intent(mContext, AtcCodesActivity.class); intent.putExtra("code", code); startActivity(intent); } } }); }
From source file:org.sensapp.android.sensappdroid.fragments.CompositeListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);/*from w w w . j ava 2s . com*/ newCompositedialog = new NewCompositeDialogFragment(); adapter = new SimpleCursorAdapter(getActivity(), R.layout.composite_row, null, new String[] { SensAppContract.Composite.NAME }, new int[] { R.id.name }, 0); getLoaderManager().initLoader(0, null, this); setListAdapter(adapter); registerForContextMenu(getListView()); }