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:com.gmail.emerssso.srbase.ListDailiesActivity.java
/** * Fill data from the database into the ListView. *///from w ww . j av a2s . c o m private void fillData() { // Fields from the database (projection) // Must include the _id column for the adapter to work String[] from = new String[] { DailyTable.COLUMN_DAY, DailyTable.COLUMN_MONTH, DailyTable.COLUMN_YEAR, DailyTable.COLUMN_COMMENT, DailyTable.COLUMN_ID }; // Fields on the UI to which we map int[] to = new int[] { R.id.day, R.id.month, R.id.year, R.id.comment_body }; //create cursor so that we only list relevant comments Cursor cursor = getContentResolver().query(SRContentProvider.DAILY_CONTENT_URI, from, DailyTable.COLUMN_SR_ID + " = ? ", new String[] { srId }, null); adapter = new SimpleCursorAdapter(this, R.layout.list_comment_row, cursor, from, to, 0); setListAdapter(adapter); getLoaderManager().initLoader(0, null, this); }
From source file:net.olejon.mdapp.AtcActivity.java
private void getAnatomicalGroups() { mToolbar.setTitle(getString(R.string.atc_title)); mGroup = "anatomical_groups"; mSqLiteDatabase = new SlDataSQLiteHelper(mContext).getReadableDatabase(); mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_ATC_ANATOMICAL_GROUPS, null, null, null, null, null, SlDataSQLiteHelper.ATC_ANATOMICAL_GROUPS_COLUMN_CODE); String[] fromColumns = new String[] { SlDataSQLiteHelper.ATC_ANATOMICAL_GROUPS_COLUMN_CODE, SlDataSQLiteHelper.ATC_ANATOMICAL_GROUPS_COLUMN_NAME }; int[] toViews = new int[] { R.id.atc_anatomical_groups_list_item_code, R.id.atc_anatomical_groups_list_item_name }; SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(mContext, R.layout.activity_atc_anatomical_groups_list_item, mCursor, fromColumns, toViews, 0); mListView.setAdapter(simpleCursorAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//w w w . j ava 2 s . c o m public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mCursor.moveToPosition(i)) { mAnatomicalGroupsCode = mCursor.getString( mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_ANATOMICAL_GROUPS_COLUMN_CODE)); mPharmacologicGroupsTitle = mCursor.getString( mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.ATC_ANATOMICAL_GROUPS_COLUMN_NAME)); getPharmacologicGroups(); } } }); }
From source file:nu.firetech.android.pactrack.frontend.ParcelDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.parcel_view, container, false); mExtended = (LinearLayout) view.findViewById(R.id.extended); mToggleButton = (Button) view.findViewById(R.id.extended_toggle); mToggleButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { mExtendedShowing = !mExtendedShowing; if (mExtendedShowing) { mExtended.setVisibility(View.VISIBLE); mToggleButton.setText(R.string.hide_extended); } else { mExtended.setVisibility(View.GONE); mToggleButton.setText(R.string.show_extended); }//from ww w. j av a 2s .c om } }); if (mExtendedShowing) { mExtended.setVisibility(View.VISIBLE); mToggleButton.setText(R.string.hide_extended); } String[] from = new String[] { ParcelDbAdapter.KEY_CUSTOM, ParcelDbAdapter.KEY_DESC }; int[] to = new int[] { android.R.id.title, android.R.id.text1 }; mEventsAdapter = new SimpleCursorAdapter(view.getContext(), R.layout.event_row, null, from, to, 0); setListAdapter(mEventsAdapter); Bundle extras = getArguments(); if (extras != null) { if (mRowId == null && extras.containsKey(ParcelDbAdapter.KEY_ROWID)) { mRowId = extras.getLong(ParcelDbAdapter.KEY_ROWID); } if (extras.containsKey(FORCE_REFRESH)) { doRefresh(); } } setRetainInstance(true); setHasOptionsMenu(true); return view; }
From source file:uk.org.freeflight.wifefinder.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Create cursor adaptor for the spinner control Cursor cursor = db.makeCursor(); String[] from = { WifeFinderDb.DbContract.AircraftTable.COLUMN_NAME_AIRCRAFT_REG }; int[] to = { android.R.id.text1 }; aircraftCursorAdapter = new SimpleCursorAdapter(this, R.layout.spinner_item, cursor, from, to, 0); aircraftCursorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Spinner setup getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem item = menu.findItem(R.id.aircraft_spinner); Spinner spinner = (Spinner) MenuItemCompat.getActionView(item); spinner.setAdapter(aircraftCursorAdapter); setSpinnerItemById(spinner, id);// ww w . j av a 2s. c o m spinner.setOnItemSelectedListener(this); return true; }
From source file:de.baumann.browser.popups.Popup_pass.java
private void setFilesList() { //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[] { "pass_title", "pass_content", "pass_creation" }; final Cursor row = db.fetchAllData(this); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0); listView.setAdapter(adapter);/*from www . j a v a 2 s . c om*/ //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 pass_content = row2.getString(row2.getColumnIndexOrThrow("pass_content")); final String pass_icon = row2.getString(row2.getColumnIndexOrThrow("pass_icon")); final String pass_attachment = row2.getString(row2.getColumnIndexOrThrow("pass_attachment")); try { String decrypted_userName = mahEncryptor.decode(pass_icon); String decrypted_userPW = mahEncryptor.decode(pass_attachment); sharedPref.edit().putString("copyPW", decrypted_userPW).apply(); sharedPref.edit().putString("copyUN", decrypted_userName).apply(); sharedPref.edit().putString("openURL", "openLogin" + pass_content).apply(); finishAffinity(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(listView, R.string.toast_error, Snackbar.LENGTH_SHORT).show(); } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String pass_title = row2.getString(row2.getColumnIndexOrThrow("pass_title")); final String pass_content = row2.getString(row2.getColumnIndexOrThrow("pass_content")); final String pass_icon = row2.getString(row2.getColumnIndexOrThrow("pass_icon")); final String pass_attachment = row2.getString(row2.getColumnIndexOrThrow("pass_attachment")); final CharSequence[] options = { getString(R.string.pass_copy), getString(R.string.pass_edit), getString(R.string.bookmark_remove_bookmark) }; new AlertDialog.Builder(Popup_pass.this) .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.pass_edit))) { try { AlertDialog.Builder builder = new AlertDialog.Builder(Popup_pass.this); View dialogView = View.inflate(Popup_pass.this, R.layout.dialog_login, null); final EditText pass_titleET = (EditText) dialogView .findViewById(R.id.pass_title); final EditText pass_userNameET = (EditText) dialogView .findViewById(R.id.pass_userName); final EditText pass_userPWET = (EditText) dialogView .findViewById(R.id.pass_userPW); final String decrypted_userName = mahEncryptor.decode(pass_icon); final String decrypted_userPW = mahEncryptor.decode(pass_attachment); pass_titleET.setText(pass_title); pass_userNameET.setText(decrypted_userName); pass_userPWET.setText(decrypted_userPW); builder.setView(dialogView); builder.setTitle(R.string.pass_edit); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { String input_pass_title = pass_titleET.getText() .toString().trim(); String encrypted_userName = mahEncryptor.encode( pass_userNameET.getText().toString().trim()); String encrypted_userPW = mahEncryptor.encode( pass_userPWET.getText().toString().trim()); db.update(Integer.parseInt(_id), input_pass_title, pass_content, encrypted_userName, encrypted_userPW, helper_main.createDate()); setFilesList(); Snackbar.make(listView, R.string.pass_success, Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(listView, R.string.toast_error, 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_editText.showKeyboard(Popup_pass.this, pass_titleET, 0, pass_title, getString(R.string.app_search_hint_bookmark)); } catch (Exception e) { e.printStackTrace(); Snackbar.make(listView, R.string.toast_error, Snackbar.LENGTH_SHORT).show(); } } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { 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) { db.delete(Integer.parseInt(_id)); setFilesList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.pass_copy))) { try { String decrypted_userName = mahEncryptor.decode(pass_icon); String decrypted_userPW = mahEncryptor.decode(pass_attachment); sharedPref.edit().putString("copyPW", decrypted_userPW).apply(); sharedPref.edit().putString("copyUN", decrypted_userName).apply(); sharedPref.edit().putString("openURL", "copyLogin").apply(); finishAffinity(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(listView, R.string.toast_error, Snackbar.LENGTH_SHORT).show(); } } } }).show(); return true; } }); }
From source file:com.mstoyanov.music_lessons.StudentsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);/*from w ww .j a va2 s . c o m*/ String[] fromColumns = new String[] { "firstName", "lastName" }; int[] toViews = new int[] { R.id.firstName, R.id.lastName }; studentsAdapter = new SimpleCursorAdapter(getActivity(), R.layout.student_list_item, // layout null, // no cursor is created yet fromColumns, // columns toViews, // UI controls 0 // flags ); studentsList = (ListView) getActivity().findViewById(R.id.students_list); studentsList.setOnItemClickListener(this); studentsList.setAdapter(studentsAdapter); // determine the current layout: View studentDetailsView = getActivity().findViewById(R.id.student_details_pane); dualPane = studentDetailsView != null && studentDetailsView.getVisibility() == View.VISIBLE; if (dualPane) { if (savedInstanceState != null) { selectedStudent = savedInstanceState.getInt("SELECTED_STUDENT", 0); } else if (getActivity().getIntent() != null) { selectedStudent = getActivity().getIntent().getIntExtra("SELECTED_STUDENT", selectedStudent); } firstNameLabel = ((TextView) getActivity().findViewById(R.id.label_fname_students)); firstNameTextView = ((TextView) getActivity().findViewById(R.id.fname_students)); lastNameLabel = ((TextView) getActivity().findViewById(R.id.label_lname_students)); lastNameTextView = ((TextView) getActivity().findViewById(R.id.lname_students)); studentDetailsList = (ListView) getActivity().findViewById(R.id.student_details_list); studentDetailsList.setOnItemClickListener(this); actions = new ArrayList<Actions>(); studentDetailsAdapter = new ActionsAdapter(getActivity(), actions); studentDetailsList.setAdapter(studentDetailsAdapter); } }
From source file:com.github.notizklotz.derbunddownloader.issuesgrid.DownloadedIssuesActivity.java
@AfterViews void setupIssuesGrid() { gridView.setEmptyView(emptyGridView); gridView.setOnItemClickListener(new IssuesGridOnItemClickListener()); final SimpleCursorAdapter issueListAdapter = new SimpleCursorAdapter(this, R.layout.include_issue, null, new String[] { DownloadManager.COLUMN_DESCRIPTION, DownloadManager.COLUMN_STATUS }, new int[] { R.id.dateTextView, R.id.stateTextView }, 0) { @Override/*from w w w. ja va 2 s . c om*/ public View getView(final int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); View deleteButton = view.findViewById(R.id.issueDeleteButton); deleteButton.setOnClickListener(new IssueDeleteButtonOnClickListener(position)); // Load the thumbnail image ImageView image = (ImageView) view.findViewById(R.id.issueImageView); Uri uri = Uri.parse(getCursor().getString(getCursor().getColumnIndex(DownloadManager.COLUMN_URI))); Picasso.with(image.getContext()).load(IssueDownloadService_.getThumbnailUriForPDFUri(uri)) .placeholder(R.drawable.issue_placeholder).into(image); return view; } }; issueListAdapter.setViewBinder(new IssuesGridViewBinder(this)); gridView.setAdapter(issueListAdapter); getLoaderManager().initLoader(1, null, new IssuesGridLoaderCallbacks(this, issueListAdapter)); }
From source file:de.baumann.browser.popups.Popup_history.java
private void setHistoryList() { //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[] { "history_title", "history_content", "history_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0); //display data by filter final String note_search = sharedPref.getString("filter_historyBY", "history_title"); sharedPref.edit().putString("filter_historyBY", "history_title").apply(); editText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { }// ww w .j av a 2 s . c om 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 row = (Cursor) listView.getItemAtPosition(position); final String history_content = row.getString(row.getColumnIndexOrThrow("history_content")); sharedPref.edit().putString("openURL", history_content).apply(); finish(); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String history_title = row2.getString(row2.getColumnIndexOrThrow("history_title")); final String history_content = row2.getString(row2.getColumnIndexOrThrow("history_content")); final String history_icon = row2.getString(row2.getColumnIndexOrThrow("history_icon")); final String history_attachment = row2.getString(row2.getColumnIndexOrThrow("history_attachment")); final String history_creation = row2.getString(row2.getColumnIndexOrThrow("history_creation")); final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save), getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) }; new AlertDialog.Builder(Popup_history.this) .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.bookmark_edit_title))) { sharedPref.edit().putString("edit_id", _id).apply(); sharedPref.edit().putString("edit_content", history_content).apply(); sharedPref.edit().putString("edit_icon", history_icon).apply(); sharedPref.edit().putString("edit_attachment", history_attachment).apply(); sharedPref.edit().putString("edit_creation", history_creation).apply(); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Popup_history.this, editText, 2, history_title, getString(R.string.bookmark_edit_title)); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { 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) { db.delete(Integer.parseInt(_id)); setHistoryList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.menu_share))) { final CharSequence[] options = { getString(R.string.menu_share_link), getString(R.string.menu_share_link_copy) }; new AlertDialog.Builder(Popup_history.this) .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.menu_share_link))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, history_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, history_content); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (options[item] .equals(getString(R.string.menu_share_link_copy))) { ClipboardManager clipboard = (ClipboardManager) Popup_history.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip( ClipData.newPlainText("text", history_content)); Snackbar.make(listView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } } }).show(); } if (options[item].equals(getString(R.string.menu_save))) { final CharSequence[] options = { getString(R.string.menu_save_bookmark), getString(R.string.menu_save_readLater), getString(R.string.menu_save_pass), getString(R.string.menu_createShortcut) }; new AlertDialog.Builder(Popup_history.this) .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.menu_save_pass))) { helper_editText.editText_savePass(Popup_history.this, listView, history_title, history_content); } if (options[item] .equals(getString(R.string.menu_save_bookmark))) { DbAdapter_Bookmarks db = new DbAdapter_Bookmarks( Popup_history.this); db.open(); if (db.isExist(history_content)) { Snackbar.make(listView, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(history_title, history_content, "", "", helper_main.createDate()); Snackbar.make(listView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (options[item] .equals(getString(R.string.menu_save_readLater))) { DbAdapter_ReadLater db = new DbAdapter_ReadLater( Popup_history.this); db.open(); if (db.isExist(history_content)) { Snackbar.make(listView, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(history_title, history_content, "", "", helper_main.createDate()); Snackbar.make(listView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (options[item] .equals(getString(R.string.menu_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Popup_history.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(history_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, history_title); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext( Popup_history.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction( "com.android.launcher.action.INSTALL_SHORTCUT"); Popup_history.this.sendBroadcast(shortcut); Snackbar.make(listView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } } }).show(); } } }).show(); return true; } }); listView.post(new Runnable() { public void run() { listView.setSelection(listView.getCount() - 1); } }); }
From source file:de.baumann.browser.popups.Popup_bookmarks.java
private void setBookmarksList() { //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[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) { @Override/*w w w . jav a 2 s .com*/ public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) listView.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")); View v = super.getView(position, convertView, parent); final ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes); 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(listView, 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("startURL", bookmarks_content).apply(); Snackbar.make(listView, 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(); } } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title"); sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_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 row = (Cursor) listView.getItemAtPosition(position); final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content")); sharedPref.edit().putString("openURL", bookmarks_content).apply(); finish(); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.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.menu_share), getString(R.string.menu_save), getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) }; new AlertDialog.Builder(Popup_bookmarks.this) .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.bookmark_edit_title))) { sharedPref.edit().putString("edit_id", _id).apply(); sharedPref.edit().putString("edit_content", bookmarks_content).apply(); sharedPref.edit().putString("edit_icon", bookmarks_icon).apply(); sharedPref.edit().putString("edit_attachment", bookmarks_attachment).apply(); sharedPref.edit().putString("edit_creation", bookmarks_creation).apply(); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Popup_bookmarks.this, editText, 2, bookmarks_title, getString(R.string.bookmark_edit_title)); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { 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) { db.delete(Integer.parseInt(_id)); setBookmarksList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.menu_share))) { final CharSequence[] options = { getString(R.string.menu_share_link), getString(R.string.menu_share_link_copy) }; new AlertDialog.Builder(Popup_bookmarks.this) .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.menu_share_link))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, bookmarks_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, bookmarks_content); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (options[item] .equals(getString(R.string.menu_share_link_copy))) { ClipboardManager clipboard = (ClipboardManager) Popup_bookmarks.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip( ClipData.newPlainText("text", bookmarks_content)); Snackbar.make(listView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } } }).show(); } if (options[item].equals(getString(R.string.menu_save))) { final CharSequence[] options = { getString(R.string.menu_save_readLater), getString(R.string.menu_save_pass), getString(R.string.menu_createShortcut) }; new AlertDialog.Builder(Popup_bookmarks.this) .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.menu_save_pass))) { helper_editText.editText_savePass(Popup_bookmarks.this, listView, bookmarks_title, bookmarks_content); } if (options[item] .equals(getString(R.string.menu_save_readLater))) { DbAdapter_ReadLater db = new DbAdapter_ReadLater( Popup_bookmarks.this); db.open(); if (db.isExist(bookmarks_content)) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(bookmarks_title, bookmarks_content, "", "", helper_main.createDate()); Snackbar.make(listView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (options[item] .equals(getString(R.string.menu_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Popup_bookmarks.this, "de.baumann.browser.Browser_left"); 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( Popup_bookmarks.this .getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction( "com.android.launcher.action.INSTALL_SHORTCUT"); Popup_bookmarks.this.sendBroadcast(shortcut); Snackbar.make(listView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } } }).show(); } } }).show(); return true; } }); }
From source file:nu.firetech.android.pactrack.frontend.ParcelListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.parcel_list, container, false); Context context = view.getContext(); if (sAboutMessage == null) { String spacer = "\n\n"; String versionName = "Huh?"; try {//from w w w . j av a 2 s . co m versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { } sAboutMessage = new StringBuilder(getString(R.string.app_name)).append(" - ").append(versionName) .append(spacer).append("Copyright (C) 2014 Joakim Andersson").append("\n") .append("Copyright (C) 2014 blunden").append(spacer) .append("This program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, licensed under the GNU General Public License; version 2.") .toString(); } mAboutDialog = new AlertDialog.Builder(context).setTitle(R.string.menu_about).setMessage(sAboutMessage) .setPositiveButton(R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setNegativeButton(R.string.go_homepage, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.home_page))) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } }).create(); String[] from = new String[] { ParcelDbAdapter.KEY_CUSTOM, ParcelDbAdapter.KEY_CUSTOMER, ParcelDbAdapter.KEY_STATUSCODE }; int[] to = new int[] { android.R.id.text1, android.R.id.text2, android.R.id.icon }; final Preferences prefs = Preferences.getPreferences(context); mAdapter = new SimpleCursorAdapter(context, R.layout.parcel_row, null, from, to, 0); mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view instanceof ImageView && view.getId() == android.R.id.icon) { ((ImageView) view).setImageResource(UICommon.getStatusImage(cursor, columnIndex)); if (prefs.getCheckInterval() == 0 || cursor.getInt(cursor.getColumnIndexOrThrow(ParcelDbAdapter.KEY_AUTO)) == 1) { ((ImageView) view).getDrawable().mutate().setAlpha(255); } else { ((ImageView) view).getDrawable().mutate().setAlpha(70); } return true; } else { return false; } } }); setListAdapter(mAdapter); setRetainInstance(true); setHasOptionsMenu(true); return view; }