Added primitive about dialog to all main windows. Added 'donate' button to main.
[debian/openrocket] / android / src / net / sf / openrocket / android / actionbarcompat / ActionBarHelperHoneycomb.java
1 /*
2  * Copyright 2011 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 net.sf.openrocket.android.actionbarcompat;
18
19 import net.sf.openrocket.R;
20 import android.app.Activity;
21 import android.content.Context;
22 import android.view.LayoutInflater;
23 import android.view.Menu;
24 import android.view.MenuItem;
25 import android.view.View;
26
27 /**
28  * An extension of {@link ActionBarHelper} that provides Android 3.0-specific functionality for
29  * Honeycomb tablets. It thus requires API level 11.
30  */
31 public class ActionBarHelperHoneycomb extends ActionBarHelper {
32     private Menu mOptionsMenu;
33     private View mRefreshIndeterminateProgressView = null;
34
35     protected ActionBarHelperHoneycomb(Activity activity) {
36         super(activity);
37     }
38
39     @Override
40     public boolean onCreateOptionsMenu(Menu menu) {
41         mOptionsMenu = menu;
42         return super.onCreateOptionsMenu(menu);
43     }
44
45     @Override
46     public void setRefreshActionItemState(boolean refreshing) {
47         // On Honeycomb, we can set the state of the refresh button by giving it a custom
48         // action view.
49         if (mOptionsMenu == null) {
50             return;
51         }
52
53         final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
54         if (refreshItem != null) {
55             if (refreshing) {
56                 if (mRefreshIndeterminateProgressView == null) {
57                     LayoutInflater inflater = (LayoutInflater)
58                             getActionBarThemedContext().getSystemService(
59                                     Context.LAYOUT_INFLATER_SERVICE);
60                     mRefreshIndeterminateProgressView = inflater.inflate(
61                             R.layout.actionbar_indeterminate_progress, null);
62                 }
63
64                 refreshItem.setActionView(mRefreshIndeterminateProgressView);
65             } else {
66                 refreshItem.setActionView(null);
67             }
68         }
69     }
70
71     /**
72      * Returns a {@link Context} suitable for inflating layouts for the action bar. The
73      * implementation for this method in {@link ActionBarHelperICS} asks the action bar for a
74      * themed context.
75      */
76     protected Context getActionBarThemedContext() {
77         return mActivity;
78     }
79
80         @Override
81         public void setDisplayHomeAsUpEnabled(boolean enabled) {
82                 mActivity.getActionBar().setDisplayHomeAsUpEnabled(enabled);
83         }
84     
85         @Override
86         public void hide() {
87                 mActivity.getActionBar().hide();
88         }
89     
90 }