Search in sources :

Example 1 with FilterQueryProvider

use of android.widget.FilterQueryProvider in project XposedInstaller by rovo89.

the class DownloadFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPref = XposedApp.getPreferences();
    mRepoLoader = RepoLoader.getInstance();
    mModuleUtil = ModuleUtil.getInstance();
    mAdapter = new DownloadsAdapter(getActivity());
    mAdapter.setFilterQueryProvider(new FilterQueryProvider() {

        @Override
        public Cursor runQuery(CharSequence constraint) {
            return RepoDb.queryModuleOverview(mSortingOrder, constraint);
        }
    });
    mSortingOrder = mPref.getInt("download_sorting_order", RepoDb.SORT_STATUS);
    setHasOptionsMenu(true);
}
Also used : Cursor(android.database.Cursor) FilterQueryProvider(android.widget.FilterQueryProvider)

Example 2 with FilterQueryProvider

use of android.widget.FilterQueryProvider in project Open-Weather-App by ardovic.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    cityCountryName = sharedPreferences.getString(CITY_COUNTRY_NAME, "");
    actvCityCountryName.setText(cityCountryName);
    mFetchThreadData = new FetchThreadData<>(mHandler);
    mFetchThreadData.start();
    mFetchThreadData.getLooper();
    initServerResponse();
    if (database.isOpen()) {
        checkDatabaseState();
    } else {
        database = databaseHelper.getReadableDatabase();
        checkDatabaseState();
    }
    // Create a SimpleCursorAdapter for the State Name field.
    mAdapter = new SimpleCursorAdapter(this, R.layout.dropdown_text, null, new String[] { CITY_COUNTRY_NAME }, new int[] { R.id.text }, 0);
    mAdapter.setFilterQueryProvider(new FilterQueryProvider() {

        @Override
        public Cursor runQuery(CharSequence constraint) {
            if (constraint != null) {
                if (constraint.length() >= 3 && !TextUtils.isEmpty(constraint)) {
                    Bundle bundle = new Bundle();
                    String query = charArrayUpperCaser(constraint);
                    bundle.putString(CITY_ARGS, query);
                    getLoaderManager().restartLoader(0, bundle, MainActivity.this).forceLoad();
                }
            }
            return null;
        }
    });
    // Set an OnItemClickListener, to update dependent fields when
    // a choice is made in the AutoCompleteTextView.
    actvCityCountryName.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            // Get the cursor, positioned to the corresponding row in the
            // result set
            Cursor cursor = (Cursor) listView.getItemAtPosition(position);
            // Get the state's capital from this row in the database.
            cityCountryName = cursor.getString(cursor.getColumnIndexOrThrow(CITY_COUNTRY_NAME));
            // Update the parent class's TextView
            actvCityCountryName.setText(cityCountryName);
            mFetchThreadData.queueResponce(position, cityCountryName);
            // JSONWeatherTask task = new JSONWeatherTask();
            // task.execute(new String[]{cityCountryName});
            hideKeyboard();
        }
    });
    actvCityCountryName.setAdapter(mAdapter);
}
Also used : Bundle(android.os.Bundle) Cursor(android.database.Cursor) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) FilterQueryProvider(android.widget.FilterQueryProvider) SimpleCursorAdapter(android.widget.SimpleCursorAdapter) AdapterView(android.widget.AdapterView)

Example 3 with FilterQueryProvider

use of android.widget.FilterQueryProvider in project NetGuard by M66B.

the class ActivityLog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.logging);
    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;
                        case R.id.menu_copy:
                            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("netguard", dname == null ? daddr : dname);
                            clipboard.setPrimaryClip(clip);
                            return true;
                        default:
                            return false;
                    }
                }
            });
            // Show
            popup.show();
        }
    });
    live = true;
}
Also used : Cursor(android.database.Cursor) FilterQueryProvider(android.widget.FilterQueryProvider) PackageManager(android.content.pm.PackageManager) TextView(android.widget.TextView) ClipboardManager(android.content.ClipboardManager) UnknownHostException(java.net.UnknownHostException) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) MenuItem(android.view.MenuItem) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) InetAddress(java.net.InetAddress) ClipData(android.content.ClipData) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat) PopupMenu(android.widget.PopupMenu)

Aggregations

Cursor (android.database.Cursor)3 FilterQueryProvider (android.widget.FilterQueryProvider)3 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Bundle (android.os.Bundle)1 SearchView (android.support.v7.widget.SearchView)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 MenuItem (android.view.MenuItem)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 PopupMenu (android.widget.PopupMenu)1 SimpleCursorAdapter (android.widget.SimpleCursorAdapter)1