Remove unshare with users/groups option from the menu
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / SearchFragment.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * Copyright (C) 2015 ownCloud Inc.
6 *
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.
10 *
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.
15 *
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/>.
18 *
19 */
20
21 package com.owncloud.android.ui.fragment;
22
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;
34
35 import com.owncloud.android.R;
36 import com.owncloud.android.datamodel.OCFile;
37 import com.owncloud.android.lib.common.utils.Log_OC;
38
39 /**
40 * Fragment for Searching users and groups
41 *
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.
48 */
49 public class SearchFragment extends Fragment {
50 private static final String TAG = SearchFragment.class.getSimpleName();
51
52 // the fragment initialization parameters
53 private static final String ARG_FILE = "FILE";
54 private static final String ARG_ACCOUNT = "ACCOUNT";
55
56 // Parameters
57 private OCFile mFile;
58 private Account mAccount;
59
60 private OnSearchFragmentInteractionListener mListener;
61
62 /**
63 * Public factory method to create new SearchFragment instances.
64 *
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.
68 */
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);
76 return fragment;
77 }
78
79 public SearchFragment() {
80 // Required empty public constructor
81 }
82
83 @Override
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);
89 }
90
91 }
92
93 @Override
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);
98
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
104 );
105 searchView.setIconifiedByDefault(false); // do not iconify the widget; expand it by default
106
107 //searchView.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_FULLSCREEN);
108
109 searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
110 @Override
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
115 }
116
117 @Override
118 public boolean onQueryTextChange(String newText) {
119 return false; // let it for the parent listener in the hierarchy / default behaviour
120 }
121 });
122
123 return view;
124 }
125
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);
130 }
131 }
132
133 @Override
134 public void onAttach(Activity activity) {
135 super.onAttach(activity);
136 try {
137 mListener = (OnSearchFragmentInteractionListener) activity;
138 } catch (ClassCastException e) {
139 throw new ClassCastException(activity.toString()
140 + " must implement OnFragmentInteractionListener");
141 }
142 }
143
144 @Override
145 public void onDetach() {
146 super.onDetach();
147 mListener = null;
148 }
149
150 // TODO: review if it is necessary
151 /**
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
155 * activity.
156 * <p/>
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.
160 */
161 public interface OnSearchFragmentInteractionListener {
162 // TODO: Update argument type and name
163 public void onSearchFragmentInteraction(Uri uri);
164 }
165
166 }