2 * ownCloud Android client application
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.ui
.fragment
;
24 import android
.accounts
.Account
;
25 import android
.app
.Activity
;
26 import android
.app
.SearchManager
;
27 import android
.content
.Context
;
28 import android
.net
.Uri
;
29 import android
.os
.Bundle
;
30 import android
.support
.v4
.app
.Fragment
;
31 import android
.view
.LayoutInflater
;
32 import android
.view
.View
;
33 import android
.view
.ViewGroup
;
34 import android
.widget
.SearchView
;
36 import com
.owncloud
.android
.R
;
37 import com
.owncloud
.android
.datamodel
.OCFile
;
38 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
41 * Fragment for Searching users and groups
43 * A simple {@link Fragment} subclass.
44 * Activities that contain this fragment must implement the
45 * {@link SearchFragment.OnSearchFragmentInteractionListener} interface
46 * to handle interaction events.
47 * Use the {@link SearchFragment#newInstance} factory method to
48 * create an instance of this fragment.
50 public class SearchFragment
extends Fragment
{
51 private static final String TAG
= SearchFragment
.class.getSimpleName();
53 // the fragment initialization parameters
54 private static final String ARG_FILE
= "FILE";
55 private static final String ARG_ACCOUNT
= "ACCOUNT";
59 private Account mAccount
;
61 private OnSearchFragmentInteractionListener mListener
;
64 * Public factory method to create new SearchFragment instances.
66 * @param fileToShare An {@link OCFile} to show in the fragment
67 * @param account An ownCloud account
68 * @return A new instance of fragment SearchFragment.
70 // TODO: Rename and change types and number of parameters
71 public static SearchFragment
newInstance(OCFile fileToShare
, Account account
) {
72 SearchFragment fragment
= new SearchFragment();
73 Bundle args
= new Bundle();
74 args
.putParcelable(ARG_FILE
, fileToShare
);
75 args
.putParcelable(ARG_ACCOUNT
, account
);
76 fragment
.setArguments(args
);
80 public SearchFragment() {
81 // Required empty public constructor
85 public void onCreate(Bundle savedInstanceState
) {
86 super.onCreate(savedInstanceState
);
87 if (getArguments() != null
) {
88 mFile
= getArguments().getParcelable(ARG_FILE
);
89 mAccount
= getArguments().getParcelable(ARG_ACCOUNT
);
95 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
96 Bundle savedInstanceState
) {
97 // Inflate the layout for this fragment
98 View view
= inflater
.inflate(R
.layout
.search_users_groups_layout
, container
, false
);
100 // Get the SearchView and set the searchable configuration
101 SearchView searchView
= (SearchView
) view
.findViewById(R
.id
.searchView
);
102 SearchManager searchManager
= (SearchManager
) getActivity().getSystemService(Context
.SEARCH_SERVICE
);
103 searchView
.setSearchableInfo(searchManager
.getSearchableInfo(
104 getActivity().getComponentName()) // assumes parent activity is the searchable activity
106 searchView
.setIconifiedByDefault(false
); // do not iconify the widget; expand it by default
108 //searchView.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_FULLSCREEN);
110 searchView
.setOnQueryTextListener(new SearchView
.OnQueryTextListener() {
112 public boolean onQueryTextSubmit(String query
) {
113 Log_OC
.v(TAG
, "onQueryTextSubmit intercepted, query: " + query
);
114 return true
; // return true to prevent the query is processed to be queried;
115 // a user / group will be picked only if selected in the list of suggestions
119 public boolean onQueryTextChange(String newText
) {
120 return false
; // let it for the parent listener in the hierarchy / default behaviour
127 // TODO: Rename method, update argument and hook method into UI event
128 public void onButtonPressed(Uri uri
) {
129 if (mListener
!= null
) {
130 mListener
.onSearchFragmentInteraction(uri
);
135 public void onAttach(Activity activity
) {
136 super.onAttach(activity
);
138 mListener
= (OnSearchFragmentInteractionListener
) activity
;
139 } catch (ClassCastException e
) {
140 throw new ClassCastException(activity
.toString()
141 + " must implement OnFragmentInteractionListener");
146 public void onDetach() {
151 // TODO: review if it is necessary
153 * This interface must be implemented by activities that contain this
154 * fragment to allow an interaction in this fragment to be communicated
155 * to the activity and potentially other fragments contained in that
158 * See the Android Training lesson <a href=
159 * "http://developer.android.com/training/basics/fragments/communicating.html"
160 * >Communicating with Other Fragments</a> for more information.
162 public interface OnSearchFragmentInteractionListener
{
163 // TODO: Update argument type and name
164 public void onSearchFragmentInteraction(Uri uri
);