Android Open Source - Simple-Dilbert Action Bar Utility






From Project

Back to project page Simple-Dilbert.

License

The source code is released under:

Apache License

If you think the Android project Simple-Dilbert 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 com.mareksebera.simpledilbert.utilities;
//w  ww  .ja  v a2s  . c o m
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.util.TypedValue;
import android.widget.FrameLayout;

public final class ActionBarUtility {

    public static int getActionBarHeightDip(Context c) {
        float scale = c.getResources().getDisplayMetrics().density;
        return (int) ((48 * scale) + 0.5);
    }

    public static void toggleActionBar(ActionBarActivity actionBarActivity,
                                       ViewPager viewPager) {
        try {
            if (actionBarActivity == null || actionBarActivity.getSupportActionBar() == null)
                return;
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) viewPager
                    .getLayoutParams();
            if (lp == null)
                return;
            if (actionBarActivity.getSupportActionBar().isShowing()) {
                actionBarActivity.getSupportActionBar().hide();
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    lp.topMargin = 0;
                    viewPager.setLayoutParams(lp);
                } else {
                    viewPager.setPadding(0, 0, 0, 0);
                }
            } else {
                actionBarActivity.getSupportActionBar().show();
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    lp.topMargin = getActionBarHeightCompat(actionBarActivity);
                    viewPager.setLayoutParams(lp);
                } else {
                    viewPager.setPadding(0, getActionBarHeightDip(actionBarActivity), 0, 0);
                }
            }
        } catch (Throwable t) {
            Log.e("DilbertFragmentActivity", "Toggle ActionBar failed", t);
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private static int getActionBarHeightCompat(ActionBarActivity actionBarActivity) {
        TypedValue tv = new TypedValue();
        Resources.Theme activityTheme = actionBarActivity.getTheme();
        boolean resolved = false;
        if (activityTheme != null) {
            resolved = activityTheme.resolveAttribute(
                    android.R.attr.actionBarSize, tv, true);
        }
        return resolved ? actionBarActivity.getResources()
                .getDimensionPixelSize(tv.resourceId) : 40;

    }

}




Java Source Code List

com.mareksebera.simpledilbert.AppController.java
com.mareksebera.simpledilbert.core.DilbertFragmentActivity.java
com.mareksebera.simpledilbert.core.DilbertFragmentAdapter.java
com.mareksebera.simpledilbert.core.DilbertFragmentInterface.java
com.mareksebera.simpledilbert.core.DilbertFragment.java
com.mareksebera.simpledilbert.favorites.DilbertFavoritedActivity.java
com.mareksebera.simpledilbert.favorites.DilbertFavoritedFragmentAdapter.java
com.mareksebera.simpledilbert.favorites.FavoritedItem.java
com.mareksebera.simpledilbert.picker.FolderPickerActivity.java
com.mareksebera.simpledilbert.picker.FolderPickerAdapter.java
com.mareksebera.simpledilbert.picker.FolderPickerFragment.java
com.mareksebera.simpledilbert.preferences.DilbertPreferencesActivity.java
com.mareksebera.simpledilbert.preferences.DilbertPreferences.java
com.mareksebera.simpledilbert.utilities.ActionBarUtility.java
com.mareksebera.simpledilbert.utilities.DownloadManagerBroadcastReceiver.java
com.mareksebera.simpledilbert.utilities.FailSafeBitmapDisplayer.java
com.mareksebera.simpledilbert.utilities.FindUrls.java
com.mareksebera.simpledilbert.utilities.FixedViewPager.java
com.mareksebera.simpledilbert.utilities.GetStripUrlInterface.java
com.mareksebera.simpledilbert.utilities.GetStripUrl.java
com.mareksebera.simpledilbert.widget.WidgetProvider.java