OSDN Git Service

Import translations. DO NOT MERGE
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / ui / CustomMenu.java
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.Menu;
21 import android.view.MenuItem;
22 import android.view.View;
23 import android.view.View.OnClickListener;
24 import android.widget.Button;
25 import android.widget.PopupMenu;
26 import android.widget.PopupMenu.OnMenuItemClickListener;
27
28 import com.android.gallery3d.R;
29
30 import java.util.ArrayList;
31
32 public class CustomMenu implements OnMenuItemClickListener {
33     @SuppressWarnings("unused")
34     private static final String TAG = "FilterMenu";
35
36     public static class DropDownMenu {
37         private Button mButton;
38         private PopupMenu mPopupMenu;
39         private Menu mMenu;
40
41         public DropDownMenu(Context context, Button button, int menuId,
42                 OnMenuItemClickListener listener) {
43             mButton = button;
44             mPopupMenu = new PopupMenu(context, mButton);
45             mMenu = mPopupMenu.getMenu();
46             mPopupMenu.getMenuInflater().inflate(menuId, mMenu);
47             mPopupMenu.setOnMenuItemClickListener(listener);
48             mButton.setOnClickListener(new OnClickListener() {
49                 public void onClick(View v) {
50                     mPopupMenu.show();
51                 }
52             });
53         }
54
55         public MenuItem findItem(int id) {
56             return mMenu.findItem(id);
57         }
58
59         public void setTitle(CharSequence title) {
60             mButton.setText(title);
61         }
62     }
63
64
65
66     private Context mContext;
67     private ArrayList<DropDownMenu> mMenus;
68     private OnMenuItemClickListener mListener;
69
70     public CustomMenu(Context context) {
71         mContext = context;
72         mMenus = new ArrayList<DropDownMenu>();
73     }
74
75     public DropDownMenu addDropDownMenu(Button button, int menuId) {
76         DropDownMenu menu = new DropDownMenu(mContext, button, menuId, this);
77         mMenus.add(menu);
78         return menu;
79     }
80
81     public void setOnMenuItemClickListener(OnMenuItemClickListener listener) {
82         mListener = listener;
83     }
84
85     public boolean onMenuItemClick(MenuItem item) {
86         if (mListener != null) {
87             return mListener.onMenuItemClick(item);
88         }
89         return false;
90     }
91 }