Android Open Source - android Action Bar Wrapper






From Project

Back to project page android.

License

The source code is released under:

GNU General Public License

If you think the Android project android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.nico.ha_manager.helper;
//from   w  ww .j a  v  a  2s  .com
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceActivity;
import android.support.v4.app.FragmentActivity;

/**
 * From @link{http://bit.ly/1AFDKgt}
 * Fixes a nasty VerifyError crash with getActionBar()
 * on Android versions lower than 3.0.
 */

@TargetApi(11)
public class ActionBarWrapper {
    private ActionBar actionBar;

    /**
     * Check if android.app.ActionBar exists and throw an error if not
     */
    static {
        try {
            Class.forName("android.app.ActionBar");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Since the method uses the FragmentActivity class in a cast, we need
     * to manually switch for our PreferenceActivity until we can get
     * a PreferenceFragment working.
     *
     * @param context
     * @param prefActivity
     */

    public ActionBarWrapper(Context context, boolean prefActivity) {
        if (prefActivity) {
            // PreferenceActivity
            actionBar = ((PreferenceActivity) context).getActionBar();
        } else {
            // FragmentActivity
            actionBar = ((FragmentActivity) context).getActionBar();
        }
    }

    /**
     * A static function that can be called to force the static
     * initialization of this class
     */
    public static void isAvailable() {
    }

    /**
     * Basic core ActionBar functions
     */

    public void setBackgroundDrawable(Drawable background) {
        if (actionBar != null)
            actionBar.setBackgroundDrawable(background);
    }

    public void setDisplayShowTitleEnabled(boolean showTitle) {
        if (actionBar != null)
            actionBar.setDisplayShowTitleEnabled(showTitle);
    }

    public void setDisplayUseLogoEnabled(boolean useLogo) {
        if (actionBar != null)
            actionBar.setDisplayUseLogoEnabled(useLogo);
    }

    public void setDisplayHomeAsUpEnabled(boolean homeAsUpEnabled) {
        if (actionBar != null)
            actionBar.setDisplayHomeAsUpEnabled(homeAsUpEnabled);
    }
}




Java Source Code List

de.nico.ha_manager.HWManager.java
de.nico.ha_manager.activities.About.java
de.nico.ha_manager.activities.AddHomework.java
de.nico.ha_manager.activities.Main.java
de.nico.ha_manager.activities.Preferences.java
de.nico.ha_manager.activities.SubjectOffers.java
de.nico.ha_manager.activities.Subjects.java
de.nico.ha_manager.database.Helper.java
de.nico.ha_manager.database.Source.java
de.nico.ha_manager.helper.ActionBarWrapper.java
de.nico.ha_manager.helper.Homework.java
de.nico.ha_manager.helper.Subject.java
de.nico.ha_manager.helper.Utils.java