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
;
39 * Fragment for Searching users and groups
41 * A simple {@link Fragment} subclass.
42 * Activities that contain this fragment must implement the
43 * {@link SearchFragment.OnSearchFragmentInteractionListener} interface
44 * to handle interaction events.
45 * Use the {@link SearchFragment#newInstance} factory method to
46 * create an instance of this fragment.
48 public class SearchFragment
extends Fragment
{
49 private static final String TAG
= SearchFragment
.class.getSimpleName();
51 // the fragment initialization parameters
52 private static final String ARG_FILE
= "FILE";
53 private static final String ARG_ACCOUNT
= "ACCOUNT";
57 private Account mAccount
;
59 private OnSearchFragmentInteractionListener mListener
;
62 * Public factory method to create new SearchFragment instances.
64 * @param fileToShare An {@link OCFile} to show in the fragment
65 * @param account An ownCloud account
66 * @return A new instance of fragment SearchFragment.
68 // TODO: Rename and change types and number of parameters
69 public static SearchFragment
newInstance(OCFile fileToShare
, Account account
) {
70 SearchFragment fragment
= new SearchFragment();
71 Bundle args
= new Bundle();
72 args
.putParcelable(ARG_FILE
, fileToShare
);
73 args
.putParcelable(ARG_ACCOUNT
, account
);
74 fragment
.setArguments(args
);
78 public SearchFragment() {
79 // Required empty public constructor
83 public void onCreate(Bundle savedInstanceState
) {
84 super.onCreate(savedInstanceState
);
85 if (getArguments() != null
) {
86 mFile
= getArguments().getParcelable(ARG_FILE
);
87 mAccount
= getArguments().getParcelable(ARG_ACCOUNT
);
93 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
94 Bundle savedInstanceState
) {
95 // Inflate the layout for this fragment
96 View view
= inflater
.inflate(R
.layout
.search_users_groups_layout
, container
, false
);
98 // Get the SearchView and set the searchable configuration
99 SearchView searchView
= (SearchView
) view
.findViewById(R
.id
.searchView
);
100 SearchManager searchManager
= (SearchManager
) getActivity().getSystemService(Context
.SEARCH_SERVICE
);
101 searchView
.setSearchableInfo(searchManager
.getSearchableInfo(
102 getActivity().getComponentName()) // assumes parent activity is the searchable activity
104 searchView
.setIconifiedByDefault(false
); // do not iconify the widget; expand it by default
109 // TODO: Rename method, update argument and hook method into UI event
110 public void onButtonPressed(Uri uri
) {
111 if (mListener
!= null
) {
112 mListener
.onSearchFragmentInteraction(uri
);
117 public void onAttach(Activity activity
) {
118 super.onAttach(activity
);
120 mListener
= (OnSearchFragmentInteractionListener
) activity
;
121 } catch (ClassCastException e
) {
122 throw new ClassCastException(activity
.toString()
123 + " must implement OnFragmentInteractionListener");
128 public void onDetach() {
133 // TODO: review if it is necessary
135 * This interface must be implemented by activities that contain this
136 * fragment to allow an interaction in this fragment to be communicated
137 * to the activity and potentially other fragments contained in that
140 * See the Android Training lesson <a href=
141 * "http://developer.android.com/training/basics/fragments/communicating.html"
142 * >Communicating with Other Fragments</a> for more information.
144 public interface OnSearchFragmentInteractionListener
{
145 // TODO: Update argument type and name
146 public void onSearchFragmentInteraction(Uri uri
);