خرید بک لینک

Vote count: 0

I am having a problem filtering a list (more specifically, a list built with Aphid FlipView, but using a normal ListView gave the exact same problem), when the list is filtered via the Search in App intent in Google's System Voice Actions.

The exact problem encountered is listed below:

  1. The app is initially not ruing at all (the search works perfectly if the app is ruing or in the background).

  2. Fire the intent via adb:

cd C:...android-sdkplatform-tools
adb shell am start -a "com.google.android.gms.actions.SEARCH_ACTION" --es query "[query keyword]" -n "com.testapp/.MainActivity"

  1. The correct app opens but the list is empty, i.e. no results filtered.

  2. The app then crashes.

Below is the stacktrace:

02-05 11:27:39.551: D/AndroidRuntime(12972): Shutting down VM
02-05 11:27:39.561: E/AndroidRuntime(12972): FATAL EXCEPTION: main
02-05 11:27:39.561: E/AndroidRuntime(12972): Process: com.testapp, PID: 12972
02-05 11:27:39.561: E/AndroidRuntime(12972): junit.framework.AssertionFailedError: Invalid selection position
02-05 11:27:39.561: E/AndroidRuntime(12972):    at junit.framework.Assert.fail(Assert.java:50)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at junit.framework.Assert.assertTrue(Assert.java:20)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.aphidmobile.flip.FlipViewController.setSelection(FlipViewController.java:314)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.aphidmobile.flip.FlipViewController.onDataChanged(FlipViewController.java:627)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.aphidmobile.flip.FlipViewController.access$2(FlipViewController.java:617)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.aphidmobile.flip.FlipViewController$MyDataSetObserver.onChanged(FlipViewController.java:634)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.testapp.MainActivity$1.onResponse(MainActivity.java:150)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.testapp.MainActivity$1.onResponse(MainActivity.java:1)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.android.volley.ExecutorDelivery$ResponseDeliveryRuable.run(ExecutorDelivery.java:99)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at android.os.Handler.handleCallback(Handler.java:739)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at android.os.Handler.dispatchMessage(Handler.java:95)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at android.os.Looper.loop(Looper.java:145)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at android.app.ActivityThread.main(ActivityThread.java:6843)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at java.lang.reflect.Method.invoke(Native Method)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at java.lang.reflect.Method.invoke(Method.java:372)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.android.inteal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
02-05 11:27:39.561: E/AndroidRuntime(12972):    at com.android.inteal.os.ZygoteInit.main(ZygoteInit.java:1199)
02-05 11:27:45.761: I/Process(12972): Sending signal. PID: 12972 SIG: 9

My app includes a MainActivity which is the searchable activity that displays the list, a model class, an adapter class, and a controller class for the list items (similar to existing Android ListView tutorials).

Below is the code (some code omitted):

MainActivity

//[…]
public class MainActivity extends AppCompatActivity {
    //[…]
    private List<Item> itemList = new ArrayList<Item>();
    public static FlipViewController listView;
    private CustomListAdapter adapter;
    private static final String GMS_SEARCH_ACTION = "com.google.android.gms.actions.SEARCH_ACTION";
    private String qq;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //[…]
        onNewIntent(getIntent());
    }
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        String action = intent.getAction();
        if (action!= null && (action.equals(Intent.ACTION_SEARCH)||action.equals(GMS_SEARCH_ACTION))) {
            qq = intent.getStringExtra(SearchManager.QUERY);
            doSearch(qq);
        }
    }
    /* FIXME - Current problem: From adb command, FlipView can only be filtered successfully only if app is still ruing in background (i.e. onPause()). FlipView filtering works ok if searching within the app. If app is not ruing, sending the search command causes the app to open but nothing is filtered, and then crashes shortly after.*/
    private void doSearch(String qq) {
        CharSequence query = qq.toUpperCase(Locale.getDefault());
        MainActivity.this.adapter.getFilter().filter(query);
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        // […]
        MenuItem searchItem = menu.findItem(R.id.menu_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
        searchView.setSearchableInfo(searchableInfo);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String qq) {
                doSearch(qq);
                retu false;
            }
            @Override
            public boolean onQueryTextChange(String qq) {
                doSearch(qq);
                retu false;
            }
        });
        retu super.onCreateOptionsMenu(menu);
    }
}

Adapter class

// […]
public class CustomListAdapter extends BaseAdapter {
    private Activity activity;
    private LayoutInflater inflater;
    private List<Item> items, default_items;
    private Filter myFilter;
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();
    public CustomListAdapter(Activity activity, List<Item> items) {
        this.activity = activity;
        this.items = items;
        this.default_items = items;
    }
    //[…]
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//…
    }
    public Filter getFilter() {
        if (myFilter == null) { myFilter = new MYFilter();}
        retu myFilter;
    }
    private class MYFilter extends Filter {
        @Override
        protected FilterResults performFiltering(CharSequence query) {
            FilterResults results = new FilterResults();
            // If no filter implemented, retu the whole list
            if (query == null || query.length() == 0) {
                results.values = default_ items;
                results.count = default_ items.size();
            }
            else {
                List<Item> nitems = new ArrayList<Item>();
                items = default_nitems;
                for (Item t : items) {
                    // Filter logic implemented here, items are added to nitems if it meets conditions
}
                results.values = nitems;
                results.count = nitems.size();
            }
            retu results;
        }
        @Override
        protected void publishResults(CharSequence query, FilterResults results) {
            if (results.count == 0){
                items = (List<Item>) results.values;
                MainActivity.emptyView.setVisibility(View.VISIBLE);
                MainActivity.listView.setVisibility(View.GONE);
            }
            else {
                items = (List< Item >) results.values;
                MainActivity.listView.setVisibility(View.VISIBLE);
                MainActivity.emptyView.setVisibility(View.GONE);
                notifyDataSetChanged();
            }
        }
    }
}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >

    <application
        android:name=".app.AppController"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:allowTaskReparenting="true">

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:exported="true"
            android:launchMode="singleTop" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />

            <intent-filter>
                <action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>

            <meta-data
                android:name="android.app.default_searchable"
                android:value=".MainActivity" />

        </activity>
<!-- ... -->
</application>
</manifest>

Any assistance to fix this problem is appreciated.

asked 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 21 بهمن 1394 ساعت: 15:15

صفحه بندی