Animate unshare button
[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
38 /**
39 * Fragment for Searching users and groups
40 *
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.
47 */
48 public class SearchFragment extends Fragment {
49 private static final String TAG = SearchFragment.class.getSimpleName();
50
51 // the fragment initialization parameters
52 private static final String ARG_FILE = "FILE";
53 private static final String ARG_ACCOUNT = "ACCOUNT";
54
55 // Parameters
56 private OCFile mFile;
57 private Account mAccount;
58
59 private OnSearchFragmentInteractionListener mListener;
60
61 /**
62 * Public factory method to create new SearchFragment instances.
63 *
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.
67 */
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);
75 return fragment;
76 }
77
78 public SearchFragment() {
79 // Required empty public constructor
80 }
81
82 @Override
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);
88 }
89
90 }
91
92 @Override
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);
97
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
103 );
104 searchView.setIconifiedByDefault(false); // do not iconify the widget; expand it by default
105
106 return view;
107 }
108
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);
113 }
114 }
115
116 @Override
117 public void onAttach(Activity activity) {
118 super.onAttach(activity);
119 try {
120 mListener = (OnSearchFragmentInteractionListener) activity;
121 } catch (ClassCastException e) {
122 throw new ClassCastException(activity.toString()
123 + " must implement OnFragmentInteractionListener");
124 }
125 }
126
127 @Override
128 public void onDetach() {
129 super.onDetach();
130 mListener = null;
131 }
132
133 // TODO: review if it is necessary
134 /**
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
138 * activity.
139 * <p/>
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.
143 */
144 public interface OnSearchFragmentInteractionListener {
145 // TODO: Update argument type and name
146 public void onSearchFragmentInteraction(Uri uri);
147 }
148
149 }