Java Code Examples for android.app.Activity#getActionBar()

The following examples show how to use android.app.Activity#getActionBar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SensorsDataPrivate.java    From AutoTrackAppViewScreen with Apache License 2.0 6 votes vote down vote up
@TargetApi(11)
private static String getToolbarTitle(Activity activity) {
    try {
        ActionBar actionBar = activity.getActionBar();
        if (actionBar != null) {
            if (!TextUtils.isEmpty(actionBar.getTitle())) {
                return actionBar.getTitle().toString();
            }
        } else {
            if (activity instanceof AppCompatActivity) {
                AppCompatActivity appCompatActivity = (AppCompatActivity) activity;
                android.support.v7.app.ActionBar supportActionBar = appCompatActivity.getSupportActionBar();
                if (supportActionBar != null) {
                    if (!TextUtils.isEmpty(supportActionBar.getTitle())) {
                        return supportActionBar.getTitle().toString();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 2
Source File: MenuProcessor.java    From droidtestrec with Apache License 2.0 6 votes vote down vote up
public void processActivity(Activity activity) {
    ActionBar actionBar = activity.getActionBar();
    if (actionBar != null) {
        processActionBar(actionBar);
    } else if (activity instanceof AppCompatActivity) {
        android.support.v7.app.ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
        if (supportActionBar != null) {
            processSupportActionBar(supportActionBar);
        }
    }

    ViewGroup menuView = findActionBar(activity);
    if (menuView != null) {
        processMenuView(menuView);
    }
}
 
Example 3
Source File: ActionBarDrawerToggleHoneycomb.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public static Object setActionBarDescription(Object info, Activity activity,
        int contentDescRes) {
    if (info == null) {
        info = new SetIndicatorInfo(activity);
    }
    final SetIndicatorInfo sii = (SetIndicatorInfo) info;
    if (sii.setHomeAsUpIndicator != null) {
        try {
            final ActionBar actionBar = activity.getActionBar();
            sii.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
        } catch (Exception e) {
            Log.w(TAG, "Couldn't set content description via JB-MR2 API", e);
        }
    }
    return info;
}
 
Example 4
Source File: ActionBarDrawerToggleHoneycomb.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
public static SetIndicatorInfo setActionBarDescription(SetIndicatorInfo info, Activity activity,
        int contentDescRes) {
    if (info == null) {
        info = new SetIndicatorInfo(activity);
    }
    if (info.setHomeAsUpIndicator != null) {
        try {
            final ActionBar actionBar = activity.getActionBar();
            info.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
            if (Build.VERSION.SDK_INT <= 19) {
                // For API 19 and earlier, we need to manually force the
                // action bar to generate a new content description.
                actionBar.setSubtitle(actionBar.getSubtitle());
            }
        } catch (Exception e) {
            Log.w(TAG, "Couldn't set content description via JB-MR2 API", e);
        }
    }
    return info;
}
 
Example 5
Source File: ScreenShot.java    From weex with Apache License 2.0 6 votes vote down vote up
public static  int getActionBarHeight(Activity activity) {
    int actionBarHeight = 0;
    if(activity.getActionBar()!= null){
        actionBarHeight = activity.getActionBar().getHeight();
    }

    if (actionBarHeight != 0)
        return actionBarHeight;

    final TypedValue tv = new TypedValue();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (activity.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true)){
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
            Log.e("actionBarHeight==",actionBarHeight +  "android.support.v7.appcompat.R.attr.actionBarSize");

        }

        else if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)){
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
            Log.e("actionBarHeight==",actionBarHeight +  "actionBarHeight is android.R.attr.actionBarSize");

        }
    }

    return actionBarHeight;
}
 
Example 6
Source File: PullToRefreshAttacher.java    From Bitocle with Apache License 2.0 6 votes vote down vote up
protected EnvironmentDelegate createDefaultEnvironmentDelegate() {
    return new EnvironmentDelegate() {
        @Override
        public Context getContextForInflater(Activity activity) {
            Context context = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                ActionBar ab = activity.getActionBar();
                if (ab != null) {
                    context = ab.getThemedContext();
                }
            }
            if (context == null) {
                context = activity;
            }
            return context;
        }
    };
}
 
Example 7
Source File: AppUtils.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static void initActionBar(final Activity activity) {
    if (activity == null) {
        return;
    }

    ActionBar bar = activity.getActionBar();
    if (bar == null) {
        return;
    }

    if (activity instanceof MainActivity) {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM
                | ActionBar.DISPLAY_SHOW_HOME);
    } else {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP
                | ActionBar.DISPLAY_SHOW_CUSTOM);
    }
}
 
Example 8
Source File: ActionBarDrawerToggleHoneycomb.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
public static Object setActionBarUpIndicator(Object info, Activity activity,
        Drawable drawable, int contentDescRes) {
    if (info == null) {
        info = new SetIndicatorInfo(activity);
    }
    final SetIndicatorInfo sii = (SetIndicatorInfo) info;
    if (sii.setHomeAsUpIndicator != null) {
        try {
            final ActionBar actionBar = activity.getActionBar();
            sii.setHomeAsUpIndicator.invoke(actionBar, drawable);
            sii.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
        } catch (Exception e) {
            Log.w(TAG, "Couldn't set home-as-up indicator via JB-MR2 API", e);
        }
    } else if (sii.upIndicatorView != null) {
        sii.upIndicatorView.setImageDrawable(drawable);
    } else {
        Log.w(TAG, "Couldn't set home-as-up indicator");
    }
    return info;
}
 
Example 9
Source File: ActionBarWrapper.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
public ActionBarWrapper(Activity activity) {
    mActivity = activity;
    mActionBar = activity.getActionBar();
    if (mActionBar != null) {
        mActionBar.addOnMenuVisibilityListener(this);

        // Fixes issue #746
        int displayOptions = mActionBar.getDisplayOptions();
        mActionBar.setHomeButtonEnabled((displayOptions & DISPLAY_HOME_AS_UP) != 0);
    }
}
 
Example 10
Source File: ConfigurationActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public static void setupActionBar(Activity activity) {

        // Tint the status bar, if available.
        SystemBarTintManager tintManager = new SystemBarTintManager(activity);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setTintColor(activity.getResources().getColor(R.color.action_bar_dark));

        ActionBar actionBar = activity.getActionBar();
        if (null != actionBar) {
            actionBar.setIcon(DateUtils.AppIcon());
            actionBar.setDisplayHomeAsUpEnabled(!activity.isTaskRoot());
            actionBar.setDisplayShowTitleEnabled(true);
        }
    }
 
Example 11
Source File: CameraFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Add an up arrow to the "home" button, indicating that the button will go "up"
    // one activity in the app's Activity heirarchy.
    // Calls to getActionBar() aren't guaranteed to return the ActionBar when called
    // from within the Fragment's onCreate method, because the Window's decor hasn't been
    // initialized yet.  Either call for the ActionBar reference in Activity.onCreate()
    // (after the setContentView(...) call), or in the Fragment's onActivityCreated method.
    Activity activity = this.getActivity();
    ActionBar actionBar = activity.getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}
 
Example 12
Source File: ActionBarWrapper.java    From zen4android with MIT License 5 votes vote down vote up
public ActionBarWrapper(Activity activity) {
    mActivity = activity;
    mActionBar = activity.getActionBar();
    if (mActionBar != null) {
        mActionBar.addOnMenuVisibilityListener(this);

        // Fixes issue #746
        int displayOptions = mActionBar.getDisplayOptions();
        mActionBar.setHomeButtonEnabled((displayOptions & DISPLAY_HOME_AS_UP) != 0);
    }
}
 
Example 13
Source File: ActionBarDrawerToggleJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public static Object setActionBarUpIndicator(Object info, Activity activity,
        Drawable drawable, int contentDescRes) {
    final ActionBar actionBar = activity.getActionBar();
    if (actionBar != null) {
        actionBar.setHomeAsUpIndicator(drawable);
        actionBar.setHomeActionContentDescription(contentDescRes);
    }
    return info;
}
 
Example 14
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static boolean showActionBar(Activity activity) {
    ActionBar actionBar = activity.getActionBar();
    if (actionBar == null || actionBar.isShowing()) return false;
    actionBar.show();
    return true;
}
 
Example 15
Source File: ActionBarWrapper.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
public ActionBarWrapper(Activity activity) {
    mActivity = activity;
    mActionBar = activity.getActionBar();
    if (mActionBar != null) {
        mActionBar.addOnMenuVisibilityListener(this);

        // Fixes issue #746
        int displayOptions = mActionBar.getDisplayOptions();
        mActionBar.setHomeButtonEnabled((displayOptions & DISPLAY_HOME_AS_UP) != 0);
    }
}
 
Example 16
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static boolean hideActionBar(Activity activity) {
    ActionBar actionBar = activity.getActionBar();
    if (actionBar == null || !actionBar.isShowing()) return false;
    actionBar.hide();
    return true;
}
 
Example 17
Source File: Api14Adapter.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@Override
public void configureActionBarHomeAsUp(Activity activity) {
  ActionBar actionBar = activity.getActionBar();
  if (actionBar != null) {
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
  }
}
 
Example 18
Source File: CameraFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Add an up arrow to the "home" button, indicating that the button will go "up"
    // one activity in the app's Activity heirarchy.
    // Calls to getActionBar() aren't guaranteed to return the ActionBar when called
    // from within the Fragment's onCreate method, because the Window's decor hasn't been
    // initialized yet.  Either call for the ActionBar reference in Activity.onCreate()
    // (after the setContentView(...) call), or in the Fragment's onActivityCreated method.
    Activity activity = this.getActivity();
    ActionBar actionBar = activity.getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}
 
Example 19
Source File: API11Wrapper.java    From PictureChooser with Apache License 2.0 4 votes vote down vote up
public static boolean hasActionBar(final Activity a) {
    return a.getActionBar() != null;
}
 
Example 20
Source File: Api11Adapter.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
public void setTitleAndSubtitle(Activity activity, String title, String subtitle) {
  ActionBar actionBar = activity.getActionBar();
  actionBar.setTitle(title);
  actionBar.setSubtitle(subtitle);
}