1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.gallery3d.ui;
18 
19 import android.content.Context;
20 import android.view.View;
21 import android.view.View.OnClickListener;
22 import android.widget.Button;
23 
24 import com.android.gallery3d.R;
25 import com.android.gallery3d.ui.PopupList.OnPopupItemClickListener;
26 
27 public class SelectionMenu implements OnClickListener {
28     @SuppressWarnings("unused")
29     private static final String TAG = "SelectionMenu";
30 
31     private final Context mContext;
32     private final Button mButton;
33     private final PopupList mPopupList;
34 
SelectionMenu(Context context, Button button, OnPopupItemClickListener listener)35     public SelectionMenu(Context context, Button button, OnPopupItemClickListener listener) {
36         mContext = context;
37         mButton = button;
38         mPopupList = new PopupList(context, mButton);
39         mPopupList.addItem(R.id.action_select_all,
40                 context.getString(R.string.select_all));
41         mPopupList.setOnPopupItemClickListener(listener);
42         mButton.setOnClickListener(this);
43     }
44 
45     @Override
onClick(View v)46     public void onClick(View v) {
47         mPopupList.show();
48     }
49 
updateSelectAllMode(boolean inSelectAllMode)50     public void updateSelectAllMode(boolean inSelectAllMode) {
51         PopupList.Item item = mPopupList.findItem(R.id.action_select_all);
52         if (item != null) {
53             item.setTitle(mContext.getString(
54                     inSelectAllMode ? R.string.deselect_all : R.string.select_all));
55         }
56     }
57 
setTitle(CharSequence title)58     public void setTitle(CharSequence title) {
59         mButton.setText(title);
60     }
61 }
62