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
17package com.android.gallery3d.ui;
18
19import android.content.Context;
20import android.view.View;
21import android.view.View.OnClickListener;
22import android.widget.Button;
23
24import com.android.gallery3d.R;
25import com.android.gallery3d.ui.PopupList.OnPopupItemClickListener;
26
27public 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
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
46    public void onClick(View v) {
47        mPopupList.show();
48    }
49
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
58    public void setTitle(CharSequence title) {
59        mButton.setText(title);
60    }
61}
62