Эх сурвалжийг харах

Complete search widget to send search requests to parent activity

David A. Velasco 9 жил өмнө
parent
commit
e3d509a451

+ 7 - 1
AndroidManifest.xml

@@ -189,7 +189,13 @@
         <activity
             android:name=".ui.activity.ShareActivity"
             android:label="@string/share_dialog_title"
-            android:theme="@style/Theme.ownCloud.Dialog" >
+            android:theme="@style/Theme.ownCloud.Dialog"
+            android:launchMode="singleTop" >
+            <intent-filter>
+                <action android:name="android.intent.action.SEARCH" />
+            </intent-filter>
+            <meta-data android:name="android.app.searchable"
+                       android:resource="@xml/searchable"/>
         </activity>
     </application>
 

+ 1 - 2
res/values/strings.xml

@@ -373,7 +373,6 @@
     <string name="share_add_user_or_group">Add User or Group</string>
     <string name="share_search">Search</string>
 
-<!-- TODO: Remove or change this placeholder text -->
-    <string name="hello_blank_fragment">Hello blank fragment</string>
+    <string name="search_users_and_groups_hint">Search users and groups</string>
 
 </resources>

+ 25 - 0
res/xml/searchable.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+
+  @author David A. Velasco
+  Copyright (C) 2015 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<!-- Searchable configuration to search users & groups in an OC server -->
+<searchable xmlns:android="http://schemas.android.com/apk/res/android"
+    android:label="@string/app_name"
+    android:hint="@string/search_users_and_groups_hint" >
+</searchable>

+ 26 - 1
src/com/owncloud/android/ui/activity/ShareActivity.java

@@ -2,6 +2,7 @@
  *   ownCloud Android client application
  *
  *   @author masensio
+ *   @author David A. Velasco
  *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
@@ -21,13 +22,15 @@
 package com.owncloud.android.ui.activity;
 
 import android.accounts.Account;
+import android.app.SearchManager;
+import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
+import android.widget.Toast;
 
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
@@ -94,6 +97,28 @@ public class ShareActivity extends AppCompatActivity
             mSearchFragment = null;
         }
 
+        handleIntent(getIntent());
+    }
+
+
+    @Override
+    protected void onNewIntent(Intent intent) {
+        setIntent(intent);
+        handleIntent(intent);
+    }
+
+
+    private void handleIntent(Intent intent) {
+        // Verify the action and get the query
+        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+            String query = intent.getStringExtra(SearchManager.QUERY);
+            doMySearch(query);
+        }
+    }
+
+    private void doMySearch(String query) {
+        // TODO implement
+        Toast.makeText(this, "You want to search for [" + query + "]", Toast.LENGTH_SHORT).show();
     }
 
     @Override

+ 12 - 1
src/com/owncloud/android/ui/fragment/SearchFragment.java

@@ -22,12 +22,15 @@ package com.owncloud.android.ui.fragment;
 
 import android.accounts.Account;
 import android.app.Activity;
+import android.app.SearchManager;
+import android.content.Context;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.SearchView;
 
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
@@ -43,7 +46,7 @@ import com.owncloud.android.datamodel.OCFile;
  * create an instance of this fragment.
  */
 public class SearchFragment extends Fragment {
-    private static final String TAG = ShareFileFragment.class.getSimpleName();
+    private static final String TAG = SearchFragment.class.getSimpleName();
 
     // the fragment initialization parameters
     private static final String ARG_FILE = "FILE";
@@ -92,6 +95,14 @@ public class SearchFragment extends Fragment {
         // Inflate the layout for this fragment
         View view = inflater.inflate(R.layout.search_users_groups_layout, container, false);
 
+        // Get the SearchView and set the searchable configuration
+        SearchView searchView = (SearchView) view.findViewById(R.id.searchView);
+        SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
+        searchView.setSearchableInfo(searchManager.getSearchableInfo(
+                getActivity().getComponentName())   // assumes parent activity is the searchable activity
+        );
+        searchView.setIconifiedByDefault(false);    // do not iconify the widget; expand it by default
+
         return view;
     }