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