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