Пример #1
0
 public void setHomeButtonEnabled(boolean enable) {
   mHomeLayout.setEnabled(enable);
   mHomeLayout.setFocusable(enable);
   // Make sure the home button has an accurate content description for accessibility.
   if (!enable) {
     mHomeLayout.setContentDescription(null);
   } else if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
     mHomeLayout.setContentDescription(
         mContext.getResources().getText(R.string.abs__action_bar_up_description));
   } else {
     mHomeLayout.setContentDescription(
         mContext.getResources().getText(R.string.abs__action_bar_home_description));
   }
 }
Пример #2
0
  public void setDisplayOptions(int options) {
    final int flagsChanged = mDisplayOptions == -1 ? -1 : options ^ mDisplayOptions;
    mDisplayOptions = options;

    if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) {
      final boolean showHome = (options & ActionBar.DISPLAY_SHOW_HOME) != 0;
      final int vis = showHome && mExpandedActionView == null ? VISIBLE : GONE;
      mHomeLayout.setVisibility(vis);

      if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
        final boolean setUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0;
        mHomeLayout.setUp(setUp);

        // Showing home as up implicitly enables interaction with it.
        // In honeycomb it was always enabled, so make this transition
        // a bit easier for developers in the common case.
        // (It would be silly to show it as up without responding to it.)
        if (setUp) {
          setHomeButtonEnabled(true);
        }
      }

      if ((flagsChanged & ActionBar.DISPLAY_USE_LOGO) != 0) {
        final boolean logoVis = mLogo != null && (options & ActionBar.DISPLAY_USE_LOGO) != 0;
        mHomeLayout.setIcon(logoVis ? mLogo : mIcon);
      }

      if ((flagsChanged & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
        if ((options & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
          initTitle();
        } else {
          removeView(mTitleLayout);
        }
      }

      if (mTitleLayout != null
          && (flagsChanged & (ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME)) != 0) {
        final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
        mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
        mTitleLayout.setEnabled(!showHome && homeAsUp);
      }

      if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
        if ((options & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
          addView(mCustomNavView);
        } else {
          removeView(mCustomNavView);
        }
      }

      requestLayout();
    } else {
      invalidate();
    }

    // Make sure the home button has an accurate content description for accessibility.
    if (!mHomeLayout.isEnabled()) {
      mHomeLayout.setContentDescription(null);
    } else if ((options & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
      mHomeLayout.setContentDescription(
          mContext.getResources().getText(R.string.abs__action_bar_up_description));
    } else {
      mHomeLayout.setContentDescription(
          mContext.getResources().getText(R.string.abs__action_bar_home_description));
    }
  }
Пример #3
0
  public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Background is always provided by the container.
    setBackgroundResource(0);

    TypedArray a =
        context.obtainStyledAttributes(
            attrs, R.styleable.SherlockActionBar, R.attr.actionBarStyleABS, 0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode =
        a.getInt(
            R.styleable.SherlockActionBar_navigationModeABS, ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.SherlockActionBar_titleABS);
    mSubtitle = a.getText(R.styleable.SherlockActionBar_subtitleABS);

    mLogo = a.getDrawable(R.styleable.SherlockActionBar_logoABS);
    if (mLogo == null) {
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        if (context instanceof Activity) {
          // Even though native methods existed in API 9 and 10 they don't work
          // so just parse the manifest to look for the logo pre-Honeycomb
          final int resId = ResourcesCompat.loadLogoFromManifest((Activity) context);
          if (resId != 0) {
            mLogo = context.getResources().getDrawable(resId);
          }
        }
      } else {
        if (context instanceof Activity) {
          try {
            mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
          } catch (NameNotFoundException e) {
            Log.e(TAG, "Activity component name not found!", e);
          }
        }
        if (mLogo == null) {
          mLogo = appInfo.loadLogo(pm);
        }
      }
    }

    mIcon = a.getDrawable(R.styleable.SherlockActionBar_iconABS);
    if (mIcon == null) {
      if (context instanceof Activity) {
        try {
          mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
        } catch (NameNotFoundException e) {
          Log.e(TAG, "Activity component name not found!", e);
        }
      }
      if (mIcon == null) {
        mIcon = appInfo.loadIcon(pm);
      }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId =
        a.getResourceId(R.styleable.SherlockActionBar_homeLayoutABS, R.layout.abs__action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(
        getResources().getText(R.string.abs__action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_titleTextStyleABS, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_subtitleTextStyleABS, 0);
    mProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_progressBarStyleABS, 0);
    mIndeterminateProgressStyle =
        a.getResourceId(R.styleable.SherlockActionBar_indeterminateProgressStyleABS, 0);

    mProgressBarPadding =
        a.getDimensionPixelOffset(R.styleable.SherlockActionBar_progressBarPaddingABS, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_itemPaddingABS, 0);

    setDisplayOptions(a.getInt(R.styleable.SherlockActionBar_displayOptionsABS, DISPLAY_DEFAULT));

    final int customNavId =
        a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayoutABS, 0);
    if (customNavId != 0) {
      mCustomNavView = inflater.inflate(customNavId, this, false);
      mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
      setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionBar_heightABS, 0);

    a.recycle();

    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);
  }