List of usage examples for android.widget FilterQueryProvider FilterQueryProvider
FilterQueryProvider
From source file:sms.spam.NewSmsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.new_sms_layout); final AutoCompleteTextView autocompleteContact = (AutoCompleteTextView) findViewById( R.id.autocompleteContact);/*from w w w . j av a 2s .co m*/ contactsCursorAdapter = new SimpleCursorAdapter(this, R.layout.autocomplete, null, new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }, new int[] { R.id.autocompleteText, R.id.autocompleteNumber }, 0); final ContactsLoader loader = new ContactsLoader(this); getSupportLoaderManager().initLoader(ContactsLoader.CONTACTS, null, loader); getSupportLoaderManager().initLoader(ContactsLoader.NUMBERS, null, loader); contactsCursorAdapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(final CharSequence constraint) { if (getSupportLoaderManager().hasRunningLoaders()) { return null; } return new CursorWrapper(loader.getCursor(ContactsLoader.NUMBERS)) { int pos, count; int[] indexes; { this.pos = 0; if (!constraint.equals("")) { this.indexes = new int[super.getCount()]; this.count = 0; for (int i = 0, j = 0; i < super.getCount(); ++i) { super.moveToPosition(i); if (super.getString(0).contains(constraint) || super.getString(1).contains(constraint)) { this.indexes[j++] = i; this.count++; } } } else { this.count = super.getCount(); this.indexes = new int[this.count]; for (int i = 0; i < count; ++i) { this.indexes[i] = i; } } } @Override public boolean move(int offset) { return this.moveToPosition(this.pos + offset); } @Override public boolean moveToNext() { return this.moveToPosition(this.pos + 1); } @Override public boolean moveToPrevious() { return this.moveToPosition(this.pos - 1); } @Override public boolean moveToFirst() { return this.moveToPosition(0); } @Override public boolean moveToLast() { return this.moveToPosition(this.count - 1); } @Override public boolean moveToPosition(int position) { if (position < 0 || position >= count) { return false; } this.pos = indexes[position]; return super.moveToPosition(this.pos); } @Override public int getCount() { return this.count; } @Override public int getPosition() { return this.pos; } @Override public void close() { } }; } }); autocompleteContact.setAdapter(contactsCursorAdapter); autocompleteContact.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int index, long id) { Cursor cursor = (Cursor) adapter.getItemAtPosition(index); autocompleteContact.setText(cursor.getString(1)); } }); // autocompleteContact.setAdapter(new ArrayAdapter<String> // (this, R.layout.autocomplete, new String[] {"alfa", "beta", "gamma"})); }
From source file:com.google.android.apps.mytracks.fragments.AddEmailsDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { fragmentActivity = getActivity();// w w w . j a v a 2s. c o m View view = fragmentActivity.getLayoutInflater().inflate(R.layout.add_emails, null); multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(R.id.add_emails); multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity, R.layout.add_emails_item, getCursor(fragmentActivity, null), new String[] { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() { @Override public CharSequence convertToString(Cursor cursor) { int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA); return cursor.getString(index).trim(); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { return getCursor(fragmentActivity, constraint); } }); multiAutoCompleteTextView.setAdapter(adapter); return new AlertDialog.Builder(fragmentActivity).setNegativeButton(R.string.generic_cancel, null) .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String acl = multiAutoCompleteTextView.getText().toString(); caller.onAddEmailsDone(acl); } }).setTitle(R.string.share_track_add_emails_title).setView(view).create(); }
From source file:com.pindroid.fragment.AddBookmarkFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); firstRun = savedInstanceState == null; setHasOptionsMenu(true);//from w ww .j a v a 2s.com mEditUrl = ((FloatLabel) getView().findViewById(R.id.add_edit_url)).getEditText(); mEditDescription = ((FloatLabel) getView().findViewById(R.id.add_edit_description)).getEditText(); mDescriptionProgress = (ProgressBar) getView().findViewById(R.id.add_description_progress); mEditNotes = ((FloatLabel) getView().findViewById(R.id.add_edit_notes)).getEditText(); mEditTags = (MultiAutoCompleteTextView) ((FloatLabel) getView().findViewById(R.id.add_edit_tags)) .getEditText(); mRecommendedTags = (TextView) getView().findViewById(R.id.add_recommended_tags); mPopularTags = (TextView) getView().findViewById(R.id.add_popular_tags); mPrivate = (CompoundButton) getView().findViewById(R.id.add_edit_private); mToRead = (CompoundButton) getView().findViewById(R.id.add_edit_toread); mRecommendedTags.setMovementMethod(LinkMovementMethod.getInstance()); mPopularTags.setMovementMethod(LinkMovementMethod.getInstance()); if (username != null) { CursorAdapter autoCompleteAdapter = new TagAutoCompleteCursorAdapter(getActivity(), R.layout.autocomplete_view, null, new String[] { Tag.Name, Tag.Count }, new int[] { R.id.autocomplete_name, R.id.autocomplete_count }, 0); autoCompleteAdapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return TagManager.GetTagsAsCursor((constraint != null ? constraint.toString() : ""), username, Tag.Count + " DESC, " + Tag.Name + " ASC", getActivity()); } }); mEditTags.setAdapter(autoCompleteAdapter); mEditTags.setTokenizer(new SpaceTokenizer()); } mEditUrl.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { String url = mEditUrl.getText().toString().trim(); if (url != null && !url.equals("")) { if (mEditDescription.getText().toString().equals("")) { titleTask = new GetTitleTask().execute(url); } tagTask = new GetTagSuggestionsTask().execute(url); } } } }); }
From source file:eu.faircode.netguard.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { Util.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.logging);// w w w . j a v a 2 s . c o m running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); SwitchCompat swEnabled = actionView.findViewById(R.id.swEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); boolean log = prefs.getBoolean("log", false); // Show disabled message TextView tvDisabled = findViewById(R.id.tvDisabled); tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); // Set enabled switch swEnabled.setChecked(log); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { prefs.edit().putBoolean("log", isChecked).apply(); } }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this, false); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; case R.id.menu_block: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this, false); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
From source file:eu.faircode.adblocker.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { Util.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.logging);/*from w ww .ja v a2s . c o m*/ running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); boolean log = prefs.getBoolean("log", false); // Show disabled message TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); // Set enabled switch swEnabled.setChecked(log); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { prefs.edit().putBoolean("log", isChecked).apply(); } }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = (ListView) findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, dport)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; case R.id.menu_block: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
From source file:com.master.metehan.filtereagle.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { Util.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.logging);/*from ww w. jav a 2 s . c o m*/ running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); boolean log = prefs.getBoolean("log", false); // Show disabled message TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); // Set enabled switch swEnabled.setChecked(log); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { prefs.edit().putBoolean("log", isChecked).apply(); } }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = (ListView) findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; case R.id.menu_block: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
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) { }//from www . ja v a 2s .c o m 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:android_network.hetnet.vpn_service.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { Util.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.logging);//from ww w. j a v a2s . c o m running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); boolean log = prefs.getBoolean("log", false); // Show disabled message TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); // Set enabled switch swEnabled.setChecked(log); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { prefs.edit().putBoolean("log", isChecked).apply(); } }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = (ListView) findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); // -- the adapter holds rows of data entries -> AdapterLog class adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } // -- when clicking the log items lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, MainActivity.class); main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: if (true) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, MainActivity.class); main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } return true; case R.id.menu_block: if (true) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, MainActivity.class); main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
From source file:com.devgmail.mitroshin.totutu.controllers.ListFragment.java
@Nullable @Override/* w w w . j av a 2 s . c om*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_list, container, false); mListView = (ListView) view.findViewById(R.id.list_list_view); mListView.setOnItemClickListener(this); mSearchEditText = (EditText) view.findViewById(R.id.list_edit_search); // ?? ? , ?? // . ? ? ? ?? ? mDirectionType = (String) getActivity().getIntent().getSerializableExtra(EXTRA_DIRECTION_TYPE); // ? ? ? ? ? ?? // , ?? ? ? // ? ? Info. mCursor = mDatabaseHelper.database.rawQuery(generateDefaultQuery(mDirectionType), null); // ? ? ? . // ? ? , ? ??. stationsCursorAdapter = new StationCursorAdapter(getActivity().getApplicationContext(), mCursor); if (!mSearchEditText.getText().toString().isEmpty()) { stationsCursorAdapter.getFilter().filter(mSearchEditText.getText().toString()); } mSearchEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } // ? , ??? ? @Override public void onTextChanged(CharSequence s, int start, int before, int count) { System.out.println(" *** Text Change *** "); stationsCursorAdapter.getFilter().filter(s.toString()); } @Override public void afterTextChanged(Editable s) { } }); stationsCursorAdapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { System.out.println(" *** Run Query *** "); if (constraint == null || constraint.length() == 0) { System.out.println(" *** Constraint == null || or length == 0 *** "); return mDatabaseHelper.database.rawQuery(generateDefaultQuery(mDirectionType), null); } else { System.out.println(" *** Constraint != null *** "); return mDatabaseHelper.database.rawQuery(generateSearchQuery(mDirectionType), new String[] { "%" + constraint.toString() + "%" }); } } }); mListView.setAdapter(stationsCursorAdapter); return view; }
From source file:br.com.bioscada.apps.biotracks.fragments.ShareTrackDialogFragment.java
@Override protected Dialog createDialog() { FragmentActivity fragmentActivity = getActivity(); accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE); if (accounts.length == 0) { return new AlertDialog.Builder(fragmentActivity).setMessage(R.string.send_google_no_account_message) .setTitle(R.string.send_google_no_account_title).setPositiveButton(R.string.generic_ok, null) .create();/*from ww w .j a v a2 s . c om*/ } // Get all the views View view = fragmentActivity.getLayoutInflater().inflate(R.layout.share_track, null); publicCheckBox = (CheckBox) view.findViewById(R.id.share_track_public); inviteCheckBox = (CheckBox) view.findViewById(R.id.share_track_invite); multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(R.id.share_track_emails); accountSpinner = (Spinner) view.findViewById(R.id.share_track_account); // Setup publicCheckBox publicCheckBox.setChecked(PreferencesUtils.getBoolean(fragmentActivity, R.string.share_track_public_key, PreferencesUtils.SHARE_TRACK_PUBLIC_DEFAULT)); // Setup inviteCheckBox inviteCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { multiAutoCompleteTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); inviteCheckBox.setChecked(PreferencesUtils.getBoolean(fragmentActivity, R.string.share_track_invite_key, PreferencesUtils.SHARE_TRACK_INVITE_DEFAULT)); // Setup multiAutoCompleteTextView multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity, R.layout.add_emails_item, getAutoCompleteCursor(fragmentActivity, null), new String[] { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() { @Override public CharSequence convertToString(Cursor cursor) { int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA); return cursor.getString(index).trim(); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { return getAutoCompleteCursor(getActivity(), constraint); } }); multiAutoCompleteTextView.setAdapter(adapter); // Setup accountSpinner accountSpinner.setVisibility(accounts.length > 1 ? View.VISIBLE : View.GONE); AccountUtils.setupAccountSpinner(fragmentActivity, accountSpinner, accounts); return new AlertDialog.Builder(fragmentActivity).setNegativeButton(R.string.generic_cancel, null) .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { FragmentActivity context = getActivity(); if (!publicCheckBox.isChecked() && !inviteCheckBox.isChecked()) { Toast.makeText(context, R.string.share_track_no_selection, Toast.LENGTH_LONG).show(); return; } String acl = multiAutoCompleteTextView.getText().toString().trim(); if (!publicCheckBox.isChecked() && acl.equals("")) { Toast.makeText(context, R.string.share_track_no_emails, Toast.LENGTH_LONG).show(); return; } PreferencesUtils.setBoolean(context, R.string.share_track_public_key, publicCheckBox.isChecked()); PreferencesUtils.setBoolean(context, R.string.share_track_invite_key, inviteCheckBox.isChecked()); Account account = accounts.length > 1 ? accounts[accountSpinner.getSelectedItemPosition()] : accounts[0]; AccountUtils.updateShareTrackAccountPreference(context, account); caller.onShareTrackDone(getArguments().getLong(KEY_TRACK_ID), publicCheckBox.isChecked(), acl, account); } }).setTitle(R.string.share_track_title).setView(view).create(); }