示例#1
0
  public ShSwitchView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShSwitchView);

    tintColor = ta.getColor(R.styleable.ShSwitchView_tintColor, 0xFF9CE949);
    tempTintColor = tintColor;

    int defaultOuterStrokeWidth =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1.5F, context.getResources().getDisplayMetrics());
    int defaultShadowSpace =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 5, context.getResources().getDisplayMetrics());

    outerStrokeWidth =
        ta.getDimensionPixelOffset(
            R.styleable.ShSwitchView_outerStrokeWidth, defaultOuterStrokeWidth);
    shadowSpace =
        ta.getDimensionPixelOffset(R.styleable.ShSwitchView_shadowSpace, defaultShadowSpace);

    ta.recycle();

    knobBound = new RectF();
    innerContentBound = new RectF();
    ovalForPath = new RectF();

    tempForRoundRect = new RectF();

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    roundRectPath = new Path();

    gestureDetector = new GestureDetector(context, gestureListener);
    gestureDetector.setIsLongpressEnabled(false);

    if (Build.VERSION.SDK_INT >= 11) {
      setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    innerContentAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, innerContentProperty, innerContentRate, 1.0F);
    innerContentAnimator.setDuration(commonDuration);
    innerContentAnimator.setInterpolator(new DecelerateInterpolator());

    knobExpandAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, knobExpandProperty, knobExpandRate, 1.0F);
    knobExpandAnimator.setDuration(commonDuration);
    knobExpandAnimator.setInterpolator(new DecelerateInterpolator());

    knobMoveAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, knobMoveProperty, knobMoveRate, 1.0F);
    knobMoveAnimator.setDuration(commonDuration);
    knobMoveAnimator.setInterpolator(new DecelerateInterpolator());

    shadowDrawable = context.getResources().getDrawable(R.drawable.shadow);
  }
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);

    int type;

    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }

      if (depth > innerDepth || !parser.getName().equals("item")) {
        continue;
      }

      TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawableItem);

      int left =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_left, 0);
      int top =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_top, 0);
      int right =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_right, 0);
      int bottom =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_bottom, 0);
      int drawableRes =
          a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_drawable, 0);
      int id = a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_id, View.NO_ID);

      a.recycle();

      Drawable dr;
      if (drawableRes != 0) {
        dr = r.getDrawable(drawableRes);
      } else {
        while ((type = parser.next()) == XmlPullParser.TEXT) {}
        if (type != XmlPullParser.START_TAG) {
          throw new XmlPullParserException(
              parser.getPositionDescription()
                  + ": <item> tag requires a 'drawable' attribute or "
                  + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs);
      }

      addLayer(dr, id, left, top, right, bottom);
    }

    ensurePadding();
    onStateChange(getState());
  }
  private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a =
        context.obtainStyledAttributes(
            attrs, R.styleable.GoogleCircleProgressView, defStyleAttr, 0);
    final float density = getContext().getResources().getDisplayMetrics().density;

    mBackGroundColor =
        a.getColor(
            R.styleable.GoogleCircleProgressView_gcp_background_color, DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor =
        a.getColor(
            R.styleable.GoogleCircleProgressView_gcp_progress_color, DEFAULT_CIRCLE_BG_LIGHT);
    mColors = new int[] {mProgressColor};

    mInnerRadius =
        a.getDimensionPixelOffset(R.styleable.GoogleCircleProgressView_gcp_inner_radius, -1);

    mProgressStokeWidth =
        a.getDimensionPixelOffset(
            R.styleable.GoogleCircleProgressView_gcp_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth =
        a.getDimensionPixelOffset(R.styleable.GoogleCircleProgressView_gcp_arrow_width, -1);
    mArrowHeight =
        a.getDimensionPixelOffset(R.styleable.GoogleCircleProgressView_gcp_arrow_height, -1);
    mTextSize =
        a.getDimensionPixelOffset(
            R.styleable.GoogleCircleProgressView_gcp_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor =
        a.getColor(R.styleable.GoogleCircleProgressView_gcp_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.GoogleCircleProgressView_gcp_show_arrow, true);
    mCircleBackgroundEnabled =
        a.getBoolean(R.styleable.GoogleCircleProgressView_gcp_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.GoogleCircleProgressView_gcp_progress, 0);
    mMax = a.getInt(R.styleable.GoogleCircleProgressView_gcp_max, 100);
    int textVisible =
        a.getInt(R.styleable.GoogleCircleProgressView_gcp_progress_text_visibility, 1);
    if (textVisible != 1) {
      mIfDrawText = true;
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
    super.setImageDrawable(mProgressDrawable);
  }
示例#4
0
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {
    int type;

    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.InsetDrawable);

    super.inflateWithAttributes(
        r, parser, a, com.android.internal.R.styleable.InsetDrawable_visible);

    int drawableRes = a.getResourceId(com.android.internal.R.styleable.InsetDrawable_drawable, 0);

    int inLeft =
        a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetLeft, 0);
    int inTop =
        a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetTop, 0);
    int inRight =
        a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetRight, 0);
    int inBottom =
        a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetBottom, 0);

    a.recycle();

    Drawable dr;
    if (drawableRes != 0) {
      dr = r.getDrawable(drawableRes);
    } else {
      while ((type = parser.next()) == XmlPullParser.TEXT) {}
      if (type != XmlPullParser.START_TAG) {
        throw new XmlPullParserException(
            parser.getPositionDescription()
                + ": <inset> tag requires a 'drawable' attribute or "
                + "child tag defining a drawable");
      }
      dr = Drawable.createFromXmlInner(r, parser, attrs);
    }

    if (dr == null) {
      Log.w("drawable", "No drawable specified for <inset>");
    }

    mInsetState.mDrawable = dr;
    mInsetState.mInsetLeft = inLeft;
    mInsetState.mInsetRight = inRight;
    mInsetState.mInsetTop = inTop;
    mInsetState.mInsetBottom = inBottom;

    if (dr != null) {
      dr.setCallback(this);
    }
  }
 private void init(Context context, AttributeSet attrs) {
   TypedArray typedArray =
       context.obtainStyledAttributes(attrs, R.styleable.iphoneContactEditText);
   mbg = typedArray.getDrawable(R.styleable.iphoneContactEditText_contactEdtBg);
   mEdtTextSize =
       typedArray.getDimensionPixelOffset(
           R.styleable.iphoneContactEditText_contactEdtTextSize, 14);
   mEdtTextColor = typedArray.getColor(R.styleable.iphoneContactEditText_contactEdtTextColor, 0);
   mEdtHint = typedArray.getString(R.styleable.iphoneContactEditText_contactEdtHint);
   mEdtTextPaddingLeft =
       typedArray.getDimensionPixelOffset(
           R.styleable.iphoneContactEditText_contactEdtTextpaddingLeft, 0);
   mEdiTextWidth =
       typedArray.getDimensionPixelOffset(R.styleable.iphoneContactEditText_contactWidth, 0);
 }
 /**
  * Creates a new set of layout parameters. The values are extracted from the supplied attributes
  * set and context. The XML attributes mapped to this set of layout parameters are:
  *
  * <ul>
  *   <li><code>layout_x</code>: the X location of the child
  *   <li><code>layout_y</code>: the Y location of the child
  *   <li>All the XML attributes from {@link android.view.ViewGroup.LayoutParams}
  * </ul>
  *
  * @param c the application environment
  * @param attrs the set of attributes fom which to extract the layout parameters values
  */
 public LayoutParams(Context c, AttributeSet attrs) {
   super(c, attrs);
   TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.DynamicAbsoluteLayout_Layout);
   x = a.getDimensionPixelOffset(R.styleable.DynamicAbsoluteLayout_Layout_layout_x, 0);
   y = a.getDimensionPixelOffset(R.styleable.DynamicAbsoluteLayout_Layout_layout_y, 0);
   a.recycle();
 }
示例#7
0
  public SoundLevels(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    // Safe source, replaced with system one when attached.
    mLevelSource = new AudioLevelSource();
    mLevelSource.setSpeechLevel(0);

    final TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.SoundLevels, defStyle, 0);

    mMaximumLevelSize = a.getDimensionPixelOffset(R.styleable.SoundLevels_maxLevelRadius, 0);
    mMinimumLevelSize = a.getDimensionPixelOffset(R.styleable.SoundLevels_minLevelRadius, 0);
    mMinimumLevel = mMinimumLevelSize / mMaximumLevelSize;

    mPrimaryLevelPaint = new Paint();
    mPrimaryLevelPaint.setColor(a.getColor(R.styleable.SoundLevels_primaryColor, Color.BLACK));
    mPrimaryLevelPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    a.recycle();

    // This animator generates ticks that invalidate the
    // view so that the animation is synced with the global animation loop.
    // TODO: We could probably remove this in favor of using postInvalidateOnAnimation
    // which might improve things further.
    mSpeechLevelsAnimator = new TimeAnimator();
    mSpeechLevelsAnimator.setRepeatCount(ObjectAnimator.INFINITE);
    mSpeechLevelsAnimator.setTimeListener(
        new TimeListener() {
          @Override
          public void onTimeUpdate(
              final TimeAnimator animation, final long totalTime, final long deltaTime) {
            invalidate();
          }
        });
  }
  private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray attr =
        context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0);
    mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336);
    mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043);
    mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA);
    mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple, 0x99FFFFFF);
    mShowShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_showShadow, true);
    mShadowColor = attr.getColor(R.styleable.FloatingActionButton_fab_shadowColor, 0x66000000);
    mShadowRadius =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowRadius, mShadowRadius);
    mShadowXOffset =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowXOffset, mShadowXOffset);
    mShadowYOffset =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowYOffset, mShadowYOffset);
    mFabSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);
    mLabelText = attr.getString(R.styleable.FloatingActionButton_fab_label);
    mShouldProgressIndeterminate =
        attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_indeterminate, false);
    mProgressColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_color, 0xFF009688);
    mProgressBackgroundColor =
        attr.getColor(R.styleable.FloatingActionButton_fab_progress_backgroundColor, 0x4D000000);
    mProgressMax = attr.getInt(R.styleable.FloatingActionButton_fab_progress_max, mProgressMax);
    mShowProgressBackground =
        attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_showBackground, true);

    if (attr.hasValue(R.styleable.FloatingActionButton_fab_progress)) {
      mProgress = attr.getInt(R.styleable.FloatingActionButton_fab_progress, 0);
      mShouldSetProgress = true;
    }

    if (attr.hasValue(R.styleable.FloatingActionButton_fab_elevationCompat)) {
      float elevation =
          attr.getDimensionPixelOffset(R.styleable.FloatingActionButton_fab_elevationCompat, 0);
      if (isInEditMode()) {
        setElevation(elevation);
      } else {
        setElevationCompat(elevation);
      }
    }

    initShowAnimation(attr);
    initHideAnimation(attr);
    attr.recycle();

    if (isInEditMode()) {
      if (mShouldProgressIndeterminate) {
        setIndeterminate(true);
      } else if (mShouldSetProgress) {
        saveButtonOriginalPosition();
        setProgress(mProgress, false);
      }
    }

    //        updateBackground();
    setClickable(true);
  }
  /**
   * Constructor for the sliding layer.<br>
   * By default this panel will
   *
   * <ol>
   *   <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}
   *   <li>Use no shadow drawable. (i.e. with width of 0)
   *   <li>Close when the panel is tapped
   *   <li>Open when the offset is tapped, but will have an offset of 0
   * </ol>
   *
   * @param context a reference to an existing context
   * @param attrs attribute set constructed from attributes set in android .xml file
   * @param defStyle style res id
   */
  public SlidingLayer(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Style
    final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer);

    // Set the side of the screen
    setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO));

    // Sets the shadow drawable
    int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1);
    if (shadowRes != -1) {
      setShadowDrawable(shadowRes);
    }

    // Sets the shadow width
    setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0));

    // Sets the ability to close the layer by tapping in any empty space
    closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true);
    // Sets the ability to open the layout by tapping on any of the exposed closed layer
    openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true);

    // How much of the view sticks out when closed
    setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0));

    ta.recycle();

    init();
  }
示例#10
0
  /**
   * Subclasses override this to parse custom subelements. If you handle it, return true, else
   * return <em>super.inflateTag(...)</em>.
   */
  protected boolean inflateTag(String name, Resources r, XmlPullParser parser, AttributeSet attrs) {

    if ("padding".equals(name)) {
      TypedArray a =
          r.obtainAttributes(attrs, com.android.internal.R.styleable.ShapeDrawablePadding);
      setPadding(
          a.getDimensionPixelOffset(com.android.internal.R.styleable.ShapeDrawablePadding_left, 0),
          a.getDimensionPixelOffset(com.android.internal.R.styleable.ShapeDrawablePadding_top, 0),
          a.getDimensionPixelOffset(com.android.internal.R.styleable.ShapeDrawablePadding_right, 0),
          a.getDimensionPixelOffset(
              com.android.internal.R.styleable.ShapeDrawablePadding_bottom, 0));
      a.recycle();
      return true;
    }

    return false;
  }
示例#11
0
  /**
   * Initializes paint objects and sets desired attributes.
   *
   * @param context
   * @param attrs
   * @param defStyle
   */
  private void init(Context context, AttributeSet attrs, int defStyle) {
    // Initialize paint objects
    paint = new Paint();
    paint.setAntiAlias(true);
    paintBorder = new Paint();
    paintBorder.setAntiAlias(true);
    paintSelectorBorder = new Paint();
    paintSelectorBorder.setAntiAlias(true);

    // load the styled attributes and set their properties
    TypedArray attributes =
        context.obtainStyledAttributes(attrs, R.styleable.CircularImageView, defStyle, 0);

    // Check if border and/or border is enabled
    hasBorder = attributes.getBoolean(R.styleable.CircularImageView_border, false);
    hasSelector = attributes.getBoolean(R.styleable.CircularImageView_selector, false);

    // Set border properties if enabled
    if (hasBorder) {
      int defaultBorderSize = (int) (2 * context.getResources().getDisplayMetrics().density + 0.5f);
      setBorderWidth(
          attributes.getDimensionPixelOffset(
              R.styleable.CircularImageView_border_width, defaultBorderSize));
      setBorderColor(attributes.getColor(R.styleable.CircularImageView_border_color, Color.WHITE));
    }

    // Set selector properties if enabled
    if (hasSelector) {
      int defaultSelectorSize =
          (int) (2 * context.getResources().getDisplayMetrics().density + 0.5f);
      setSelectorColor(
          attributes.getColor(R.styleable.CircularImageView_selector_color, Color.TRANSPARENT));
      setSelectorStrokeWidth(
          attributes.getDimensionPixelOffset(
              R.styleable.CircularImageView_selector_stroke_width, defaultSelectorSize));
      setSelectorStrokeColor(
          attributes.getColor(R.styleable.CircularImageView_selector_stroke_color, Color.BLUE));
    }

    // Add shadow if enabled
    if (attributes.getBoolean(R.styleable.CircularImageView_shadow, false)) addShadow();

    // We no longer need our attributes TypedArray, give it back to cache
    attributes.recycle();
  }
  public ContactListPinnedHeaderView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ContactListItemView);

    mHeaderTextIndent =
        a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_header_text_indent, 0);
    mHeaderTextColor =
        a.getColor(R.styleable.ContactListItemView_list_item_header_text_color, Color.BLACK);
    mHeaderTextSize =
        a.getDimensionPixelSize(R.styleable.ContactListItemView_list_item_header_text_size, 12);
    mHeaderUnderlineHeight =
        a.getDimensionPixelSize(
            R.styleable.ContactListItemView_list_item_header_underline_height, 1);
    mHeaderUnderlineColor =
        a.getColor(R.styleable.ContactListItemView_list_item_header_underline_color, 0);
    mHeaderBackgroundHeight =
        a.getDimensionPixelSize(R.styleable.ContactListItemView_list_item_header_height, 30);
    mPaddingLeft =
        a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_left, 0);
    mPaddingRight =
        a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_right, 0);
    mContactsCountTextColor =
        a.getColor(
            R.styleable.ContactListItemView_list_item_contacts_count_text_color, Color.BLACK);
    mCountViewTextSize =
        (int)
            a.getDimensionPixelSize(
                R.styleable.ContactListItemView_list_item_contacts_count_text_size, 12);

    a.recycle();

    mHeaderTextView = new TextView(mContext);
    mHeaderTextView.setTextColor(mHeaderTextColor);
    mHeaderTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mHeaderTextSize);
    mHeaderTextView.setTypeface(mHeaderTextView.getTypeface(), Typeface.BOLD);
    mHeaderTextView.setGravity(Gravity.CENTER_VERTICAL);

    mHeaderTextView.setAllCaps(true);
    addView(mHeaderTextView);
    mHeaderDivider = new View(mContext);
    mHeaderDivider.setBackgroundColor(mHeaderUnderlineColor);
    addView(mHeaderDivider);
  }
 private void initPadding(TypedArray typedArray) {
   int padding =
       typedArray.getDimensionPixelOffset(
           R.styleable.ImageTextButton_itb_padding,
           getResources().getDimensionPixelOffset(R.dimen.default_padding));
   if (padding > 0) {
     setPadding(padding, padding, padding, padding);
   }
 }
示例#14
0
    /**
     * Creates a new set of layout parameters. The values are extracted from the supplied attributes
     * set and context. The XML attributes mapped to this set of layout parameters are:
     *
     * <ul>
     *   <li><code>scroll_direction</code>: the scroll direction, forward | backward
     *   <li><code>scroll_speed</code>: the scroll speed of the view
     * </ul>
     *
     * @param c The application environment
     * @param attrs The set of attributes fom which to extract the layout parameters values
     */
    public LayoutParams(Context c, AttributeSet attrs) {
      super(c, attrs);

      TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.XUIParallexView_Layout);

      scroll_direction =
          a.getInt(R.styleable.XUIParallexView_Layout_scroll_direction, SCROLL_DIRECTION_FORWARD);
      scroll_speed = a.getDimensionPixelOffset(R.styleable.XUIParallexView_Layout_scroll_speed, 0);

      a.recycle();
    }
示例#15
0
 static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
   TypedValue value = a.peekValue(index);
   if (value == null) return defValue;
   if (value.type == TypedValue.TYPE_DIMENSION) {
     return a.getDimensionPixelOffset(index, defValue);
   } else if (value.type == TypedValue.TYPE_FRACTION) {
     // Round it to avoid values like 47.9999 from getting truncated
     return Math.round(a.getFraction(index, base, base, defValue));
   }
   return defValue;
 }
示例#16
0
  /**
   * Constructor for XML inflation.
   *
   * @param context the context to inflate with
   * @param attrs the XML attrs
   * @param defStyle the default style resource id
   */
  public LeftGallery(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    mGestureDetector = new GestureDetector(context, this);
    mGestureDetector.setIsLongpressEnabled(true);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LeftGallery, defStyle, 0);
    int spacing = a.getDimensionPixelOffset(R.styleable.LeftGallery_spacing, 0);
    setSpacing(spacing);

    a.recycle();
  }
示例#17
0
  public RoundedButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RoundedButton, defStyle, 0);

    mRadius = ta.getDimensionPixelOffset(R.styleable.RoundedButton_radius, 0);
    mColorStateList = ta.getColorStateList(R.styleable.RoundedButton_background);

    mBackgroundPaint.setAntiAlias(true);
    mBackgroundPaint.setDither(true);

    if (mColorStateList != null) {
      mBackgroundPaint.setColor(mColorStateList.getColorForState(getDrawableState(), 0));
    }
  }
  private void initBackground(TypedArray typedArray) {
    int radius =
        typedArray.getDimensionPixelOffset(
            R.styleable.ImageTextButton_itb_radius,
            getResources().getDimensionPixelOffset(R.dimen.default_radius));
    int btnNormalBgColor =
        typedArray.getColor(
            R.styleable.ImageTextButton_itb_bg, getResources().getColor(R.color.default_bg));
    int btnPressedBgColor = typedArray.getColor(R.styleable.ImageTextButton_itb_bg_pressed, -1);
    if (btnPressedBgColor == -1) {
      int alpha = Color.alpha(btnNormalBgColor);
      int red = Color.red(btnNormalBgColor);
      int green = Color.green(btnNormalBgColor);
      int blue = Color.blue(btnNormalBgColor);
      if (alpha < 0xFF) {
        btnPressedBgColor = Color.argb(0xFF, red, green, blue);
      } else {
        btnPressedBgColor = Color.argb(0x90, red, green, blue);
      }
    }

    int btnDisabledBgColor =
        typedArray.getColor(
            R.styleable.ImageTextButton_itb_bg_disabled,
            getResources().getColor(R.color.default_bg_disabled));

    GradientDrawable normalShape = new GradientDrawable();
    normalShape.setColor(btnNormalBgColor);
    if (radius > 0) {
      normalShape.setCornerRadius(radius);
    }

    GradientDrawable pressedShape = new GradientDrawable();
    pressedShape.setColor(btnPressedBgColor);
    if (radius > 0) {
      pressedShape.setCornerRadius(radius);
    }

    GradientDrawable disabledShape = new GradientDrawable();
    disabledShape.setColor(btnDisabledBgColor);
    if (radius > 0) {
      disabledShape.setCornerRadius(radius);
    }

    StateListDrawable bg = new StateListDrawable();
    bg.addState(new int[] {android.R.attr.state_pressed}, pressedShape);
    bg.addState(new int[] {android.R.attr.state_enabled}, normalShape);
    setBackground(bg);
    setClickable(true);
  }
示例#19
0
  public SpacingTextView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray typedArray =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.TuZhaospacingtextview, 0, 0);
    oneMarginLeft = typedArray.getDimension(R.styleable.TuZhaospacingtextview_zMarginLeft, 0);
    lineSpace = typedArray.getDimensionPixelOffset(R.styleable.TuZhaospacingtextview_zLineSpace, 0);
    bottomSpace = typedArray.getDimension(R.styleable.TuZhaospacingtextview_zBottomSpace, 10);
    isGravityCenter =
        typedArray.getBoolean(R.styleable.TuZhaospacingtextview_zIsGravityCenter, false);

    Log.i("TAG", "oneMarginLeft--" + oneMarginLeft);
    Log.i("TAG", "lineSpace--" + lineSpace);
  }
  public AbsVerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekBar, defStyle, 0);
    Drawable thumb = a.getDrawable(R.styleable.SeekBar_android_thumb);
    setThumb(thumb); // will guess mThumbOffset if thumb != null...
    // ...but allow layout to override this
    int thumbOffset =
        a.getDimensionPixelOffset(R.styleable.SeekBar_android_thumbOffset, getThumbOffset());
    setThumbOffset(thumbOffset);
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.Theme, 0, 0);
    mDisabledAlpha = a.getFloat(R.styleable.Theme_android_disabledAlpha, 0.5f);
    a.recycle();
  }
示例#21
0
  private void handlerAttrs(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TabsIndicator);

    mTabPaddingTop = ta.getDimensionPixelOffset(R.styleable.TabsIndicator_tabPaddingTop, 0);
    mTabPaddingBottom = ta.getDimensionPixelOffset(R.styleable.TabsIndicator_tabPaddingTop, 0);

    // indicator line
    mIndicatorColor = ta.getColor(R.styleable.TabsIndicator_indicatorColor, mIndicatorColor);
    mIndicatorMarginTab =
        ta.getDimensionPixelOffset(
            R.styleable.TabsIndicator_indicatorMarginTab, mIndicatorMarginTab);
    mIndicatorHeight =
        ta.getDimensionPixelOffset(R.styleable.TabsIndicator_indicatorHeight, mIndicatorHeight);
    mIndicatorPos = ta.getInt(R.styleable.TabsIndicator_indicatorPosition, 1);

    // tabs text
    mTextColor = ta.getColorStateList(R.styleable.TabsIndicator_textColor);
    mTextSizeNormal =
        ta.getDimensionPixelOffset(R.styleable.TabsIndicator_textSizeNormal, mTextSizeNormal);
    int sizeSelected =
        ta.getDimensionPixelOffset(R.styleable.TabsIndicator_textSizeSelected, mTextSizeSelected);
    mTextSizeSelected = sizeSelected > 0 ? sizeSelected : mTextSizeNormal;

    // divider between tabs
    mHasDivider = ta.getBoolean(R.styleable.TabsIndicator_hasDivider, mHasDivider);
    mDividerColor = ta.getColor(R.styleable.TabsIndicator_dividerColor, mDividerColor);
    mDividerWidth =
        ta.getDimensionPixelOffset(R.styleable.TabsIndicator_dividerWidth, mDividerWidth);
    mDividerVerticalMargin =
        ta.getDimensionPixelOffset(
            R.styleable.TabsIndicator_dividerVerticalMargin, mDividerVerticalMargin);

    // under Line
    mUnderLineColor = ta.getColor(R.styleable.TabsIndicator_underLineColor, mUnderLineColor);
    mUnderLineHeight =
        ta.getDimensionPixelOffset(
            R.styleable.TabsIndicator_underLineHeight, (int) mUnderLineHeight);

    ta.recycle();
  }
 private void applyAttributeSet(Context context, AttributeSet attrs) {
   TypedArray typedArray =
       context.obtainStyledAttributes(attrs, R.styleable.MaterialCompoundButton);
   mChecked = typedArray.getBoolean(R.styleable.MaterialCompoundButton_mcChecked, mChecked);
   setAnimator(typedArray.getBoolean(R.styleable.MaterialCompoundButton_mcAnimator, isAnimator()));
   mButtonRes = typedArray.getResourceId(R.styleable.MaterialCompoundButton_mcButton, 0);
   if (mButtonRes != 0) {
     setButtonRes(mButtonRes);
   }
   setButtonPadding(
       typedArray.getDimensionPixelOffset(R.styleable.MaterialCompoundButton_mcPadding, 0));
   setText(typedArray.getText(R.styleable.MaterialCompoundButton_mcText));
   setTextSize(
       typedArray.getDimensionPixelSize(R.styleable.MaterialCompoundButton_mcTextSize, 15));
   setTextColor(typedArray.getColorStateList(R.styleable.MaterialCompoundButton_mcTextColor));
   typedArray.recycle();
 }
示例#23
0
 public WheelView(Context context, AttributeSet attrs) {
   super(context, attrs);
   textColorOut = getResources().getColor(R.color.pickerview_wheelview_textcolor_out);
   textColorCenter = getResources().getColor(R.color.pickerview_wheelview_textcolor_center);
   dividerColor = getResources().getColor(R.color.pickerview_wheelview_textcolor_divider);
   // 配合customTextSize使用,customTextSize为true才会发挥效果
   textSize = getResources().getDimensionPixelSize(R.dimen.pickerview_textsize);
   customTextSize = getResources().getBoolean(R.bool.pickerview_customTextSize);
   if (attrs != null) {
     TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.wheelview, 0, 0);
     mGravity = a.getInt(R.styleable.wheelview_gravity, Gravity.CENTER);
     textColorOut = a.getColor(R.styleable.wheelview_textColorOut, textColorOut);
     textColorCenter = a.getColor(R.styleable.wheelview_textColorCenter, textColorCenter);
     dividerColor = a.getColor(R.styleable.wheelview_dividerColor, dividerColor);
     textSize = a.getDimensionPixelOffset(R.styleable.wheelview_textSize, textSize);
   }
   initLoopView(context);
 }
示例#24
0
 private void init(AttributeSet attrs, int defStyleAttr) {
   setOrientation(VERTICAL);
   setGravity(Gravity.CENTER_HORIZONTAL);
   TypedArray array =
       this.getContext()
           .obtainStyledAttributes(attrs, R.styleable.ExpandTextView, defStyleAttr, 0);
   textColor = array.getColor(R.styleable.ExpandTextView_textcolor, DEFAULT_TEXT_COLOR);
   textSize =
       array.getDimensionPixelOffset(
           R.styleable.ExpandTextView_textsize, dp2px(DEFAULT_TEXT_SIZE));
   maxLine = array.getInt(R.styleable.ExpandTextView_lines, DEFAULT_LINE_NUM);
   mIcon = array.getDrawable(R.styleable.ExpandTextView_icon);
   text = array.getString(R.styleable.ExpandTextView_text);
   if (mIcon == null) {
     mIcon = this.getContext().getResources().getDrawable(R.drawable.text_expand);
   }
   array.recycle();
   initViewAttribute();
 }
示例#25
0
  private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes);
    mBackgroundColor =
        a.getColor(
            R.styleable.TimePicker_tp_backgroundColor,
            ColorUtil.getColor(ThemeUtil.colorPrimary(context, 0xFF000000), 0.25f));
    mSelectionColor =
        a.getColor(
            R.styleable.TimePicker_tp_selectionColor, ThemeUtil.colorPrimary(context, 0xFF000000));
    mSelectionRadius =
        a.getDimensionPixelOffset(
            R.styleable.TimePicker_tp_selectionRadius, ThemeUtil.dpToPx(context, 8));
    mTickSize =
        a.getDimensionPixelSize(R.styleable.TimePicker_tp_tickSize, ThemeUtil.dpToPx(context, 1));
    mTextSize =
        a.getDimensionPixelSize(
            R.styleable.TimePicker_tp_textSize,
            context.getResources().getDimensionPixelOffset(R.dimen.abc_text_size_caption_material));
    mTextColor = a.getColor(R.styleable.TimePicker_tp_textColor, 0xFF000000);
    mTextHighlightColor = a.getColor(R.styleable.TimePicker_tp_textHighlightColor, 0xFFFFFFFF);
    mAnimDuration =
        a.getInteger(
            R.styleable.TimePicker_tp_animDuration,
            context.getResources().getInteger(android.R.integer.config_mediumAnimTime));
    int resId = a.getResourceId(R.styleable.TimePicker_tp_inInterpolator, 0);
    mInInterpolator =
        resId == 0 ? new DecelerateInterpolator() : AnimationUtils.loadInterpolator(context, resId);
    resId = a.getResourceId(R.styleable.TimePicker_tp_outInterpolator, 0);
    mOutInterpolator =
        resId == 0 ? new DecelerateInterpolator() : AnimationUtils.loadInterpolator(context, resId);
    setMode(a.getInteger(R.styleable.TimePicker_tp_mode, mMode), false);
    set24Hour(a.getBoolean(R.styleable.TimePicker_tp_24Hour, m24Hour));
    setHour(a.getInteger(R.styleable.TimePicker_tp_hour, mHour));
    setMinute(a.getInteger(R.styleable.TimePicker_tp_minute, mMinute));

    String familyName = a.getString(R.styleable.TimePicker_tp_fontFamily);
    int style = a.getInteger(R.styleable.TimePicker_tp_textStyle, Typeface.NORMAL);

    mTypeface = TypefaceUtil.load(context, familyName, style);

    a.recycle();
  }
 private void initTextView(TypedArray typedArray, TextView textView) {
   String btnText = typedArray.getString(R.styleable.ImageTextButton_itb_text);
   int btnTextSize =
       typedArray.getDimensionPixelSize(
           R.styleable.ImageTextButton_itb_text_size,
           getResources().getDimensionPixelSize(R.dimen.default_text_size));
   if (TextUtils.isEmpty(btnText)) {
     textView.setVisibility(GONE);
   } else {
     int btnTextColor =
         typedArray.getColor(
             R.styleable.ImageTextButton_itb_text_color,
             getResources().getColor(R.color.default_text_color));
     textView.setTextColor(btnTextColor);
     textView.setTextSize(px2dip(btnTextSize));
     int marggin =
         typedArray.getDimensionPixelOffset(
             R.styleable.ImageTextButton_itb_icon_text_marggin,
             getResources().getDimensionPixelOffset(R.dimen.default_text_margin));
     ViewGroup.MarginLayoutParams params = (MarginLayoutParams) textView.getLayoutParams();
     switch (mIconPositon) {
       case ICON_POSITION_LEFT:
         params.setMargins(marggin, 0, 0, 0);
         break;
       case ICON_POSITION_TOP:
         params.setMargins(0, marggin, 0, 0);
         break;
       case ICON_POSITION_RIGHT:
         params.setMargins(0, 0, marggin, 0);
         break;
       case ICON_POSITION_BOTTOM:
         params.setMargins(0, 0, 0, marggin);
         break;
       default:
         params.setMargins(marggin, 0, 0, 0);
         break;
     }
     textView.setLayoutParams(params);
     textView.setText(btnText);
   }
 }
示例#27
0
  public ImageTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // setTag(this);
    mViewId = getId();
    Log.i(TAG, "ImageTextView is called2 ,,,,");
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ImageTextView);
    // mContentColor = ta.getColorStateList(R.styleable.ImageTextView_content_color);
    mContentVisible = ta.getBoolean(R.styleable.ImageTextView_content_visible, true);

    mIconVisible = ta.getBoolean(R.styleable.ImageTextView_icon_visible, true);
    mContentColor = ta.getColor(R.styleable.ImageTextView_content_color, Color.WHITE);

    mContentSize =
        ta.getDimensionPixelSize(
            R.styleable.ImageTextView_content_size, getDefaultTextSize(context));
    mContent = ta.getString(R.styleable.ImageTextView_content);
    mIcon = drawableToBitamp(ta.getDrawable(R.styleable.ImageTextView_view_icon));
    mDistance =
        ta.getDimensionPixelOffset(R.styleable.ImageTextView_view_dis, getDefaultDistance(context));
    mDire = ta.getInt(R.styleable.ImageTextView_dire, 1);

    Log.i(TAG, "mDistance = " + mDistance);
    /** 获得绘制文本的宽和高 */
    mPaint = new Paint();
    mPaint.setAlpha(120);
    mPaint.setAntiAlias(true);
    if (mContentVisible) {
      mPaint.setTextSize(mContentSize);
      mPaint.setColor(mContentColor);
      mBound = new Rect();
      mPaint.getTextBounds(mContent, 0, mContent.length(), mBound);
      Log.i(TAG, "mContent = " + mContent + " and bound's size = " + mBound.height());
    }

    setEnabled(false);
    setOnTouchListener(this);
  }
  /**
   * 介绍TypedArray使用方法 获取 attr中formate 十种类型属性值
   * float,integer,boolean,fraction,string,dimension,color,reference,enum,flag
   *
   * <p>
   *
   * @param context 上下文环境
   * @param attrs 属性集合
   */
  private void printAttributes(Context context, AttributeSet attrs) {
    TypedArray typedArray =
        context.obtainStyledAttributes(attrs, R.styleable.CustomTextViewStyle, 0, 0);
    System.out.println(
        "typedArray.getChangingConfigurations() = "
            + Integer.toHexString(typedArray.getChangingConfigurations()));
    float float_value = typedArray.getFloat(R.styleable.CustomTextViewStyle_float_value, 0f);
    int integer_value = typedArray.getInteger(R.styleable.CustomTextViewStyle_integer_value, 0);
    boolean boolean_value =
        typedArray.getBoolean(R.styleable.CustomTextViewStyle_boolean_value, false);

    // public float getFraction (int index, int base, int pbase, float defValue)
    // 如果值为10% 则 fraction_value=10%*base
    // 如果值格式为10%p,则fraction_value=10%*pbase
    float fraction_value =
        typedArray.getFraction(R.styleable.CustomTextViewStyle_fraction_value, 1, 1, 0);
    String string_value = typedArray.getString(R.styleable.CustomTextViewStyle_string_value);

    // 获取像素值,浮点数  eg:27.5625
    float dimension_value_float =
        typedArray.getDimension(R.styleable.CustomTextViewStyle_dimension_value, 0f);
    // 将取得浮点像素值四舍五入 eg:28
    int dimension_value =
        typedArray.getDimensionPixelSize(R.styleable.CustomTextViewStyle_dimension_value, 0);
    // 将取得浮点像素值直接截取整数部分 eg:27
    int dimension_value_offset_ =
        typedArray.getDimensionPixelOffset(R.styleable.CustomTextViewStyle_dimension_value, 0);

    int color_value = typedArray.getColor(R.styleable.CustomTextViewStyle_color_value, 0);
    int reference_drawable_value =
        typedArray.getResourceId(R.styleable.CustomTextViewStyle_reference_drawable_value, 0);
    int reference_array_value =
        typedArray.getResourceId(R.styleable.CustomTextViewStyle_reference_array_value, 0);
    int enum_value = typedArray.getInt(R.styleable.CustomTextViewStyle_enum_value, -1);
    int flag_value = typedArray.getInt(R.styleable.CustomTextViewStyle_flag_value, -1);

    System.out.println(
        "float_value = ["
            + float_value
            + "], integer_value = ["
            + integer_value
            + "], "
            + "boolean_value = ["
            + boolean_value
            + "], fraction_value = ["
            + fraction_value
            + "], string_value = ["
            + string_value
            + "], dimension_value = ["
            + dimension_value
            + "], color_value = ["
            + color_value
            + "], "
            + "reference_drawable_value ="
            + " [0x"
            + Integer.toHexString(reference_drawable_value)
            + "], enum_value = ["
            + enum_value
            + "], "
            + "flag_value1 = ["
            + flag_value
            + "]");

    // 后期数据处理,设置左边图片
    Drawable drawable;
    drawable = typedArray.getDrawable(R.styleable.CustomTextViewStyle_reference_drawable_value);
    // or
    drawable = context.getDrawable(reference_drawable_value);
    drawable.setBounds(new Rect(0, 0, 50, 50));
    setCompoundDrawables(drawable, null, null, null);
    // 设置文字是否大写,斜体
    if (flag_value >= 0) {
      Typeface typeface = getTypeface();
      setTypeface(Typeface.defaultFromStyle(flag_value));
    }

    // 其他方法getTextArray
    CharSequence[] arrays;
    arrays = typedArray.getTextArray(R.styleable.CustomTextViewStyle_reference_array_value);
    // or
    arrays = context.getResources().getTextArray(reference_array_value);
    for (int i = 0; i < arrays.length; i++) {
      System.out.println("arrays[" + i + "] = " + arrays[i]);
    }

    // 遍历TypedArray
    for (int i = 0, m = typedArray.getIndexCount(); i < m; i++) {
      System.out.println(
          "typedArray"
              + i
              + " type= "
              + typedArray.getType(i)
              + " value="
              + typedArray.getString(i));
    }

    int textsize = typedArray.getDimensionPixelSize(R.styleable.CustomTextViewStyle_text_size, 10);
    int textcolor = typedArray.getColor(R.styleable.CustomTextViewStyle_text_color, Color.BLACK);
    String text = typedArray.getString(R.styleable.CustomTextViewStyle_text_content);
    int padding = typedArray.getDimensionPixelSize(R.styleable.CustomTextViewStyle_padding, 0);

    setTextColor(textcolor);
    setTextSize(textsize);
    setText(text);
    setPadding(padding, padding, padding, padding);

    typedArray.recycle();
  }
示例#29
0
  private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    setWillNotDraw(false);

    mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);

    TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.ContactView, defStyleAttr, defStyleRes);

    mAvatarSize =
        a.getDimensionPixelSize(
            R.styleable.ContactView_cv_avatarSize, ThemeUtil.dpToPx(context, 40));
    mSpacing =
        a.getDimensionPixelOffset(R.styleable.ContactView_cv_spacing, ThemeUtil.dpToPx(context, 8));
    mMinHeight = a.getDimensionPixelOffset(R.styleable.ContactView_android_minHeight, 0);
    int avatarSrc = a.getResourceId(R.styleable.ContactView_cv_avatarSrc, 0);

    mNameView = new TextView(context);
    mNameView.setGravity(GravityCompat.START);
    mNameView.setSingleLine(true);
    mNameView.setEllipsize(TextUtils.TruncateAt.END);
    int nameTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_nameTextSize, 0);
    ColorStateList nameTextColor = a.getColorStateList(R.styleable.ContactView_cv_nameTextColor);
    int nameTextAppearance = a.getResourceId(R.styleable.ContactView_cv_nameTextAppearance, 0);
    if (nameTextAppearance > 0) mNameView.setTextAppearance(context, nameTextAppearance);
    if (nameTextSize > 0) mNameView.setTextSize(TypedValue.COMPLEX_UNIT_PX, nameTextSize);
    if (nameTextColor != null) mNameView.setTextColor(nameTextColor);
    setNameText(a.getString(R.styleable.ContactView_cv_name));

    mAddressView = new TextView(context);
    mAddressView.setGravity(GravityCompat.START);
    mAddressView.setSingleLine(true);
    mAddressView.setEllipsize(TextUtils.TruncateAt.END);
    int addressTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_addressTextSize, 0);
    ColorStateList addressTextColor =
        a.getColorStateList(R.styleable.ContactView_cv_addressTextColor);
    int addressTextAppearance =
        a.getResourceId(R.styleable.ContactView_cv_addressTextAppearance, 0);
    if (addressTextAppearance > 0) mAddressView.setTextAppearance(context, addressTextAppearance);
    if (addressTextSize > 0) mAddressView.setTextSize(TypedValue.COMPLEX_UNIT_PX, addressTextSize);
    if (addressTextColor != null) mAddressView.setTextColor(addressTextColor);
    setAddressText(a.getString(R.styleable.ContactView_cv_address));

    mButtonSize = a.getDimensionPixelOffset(R.styleable.ContactView_cv_buttonSize, 0);

    if (mButtonSize > 0) {
      mButton = new ImageButton(context);
      int resId = a.getResourceId(R.styleable.ContactView_cv_buttonSrc, 0);
      if (resId != 0) mButton.setImageResource(resId);
      ViewUtil.setBackground(mButton, BlankDrawable.getInstance());
      mButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
      mButton.setFocusableInTouchMode(false);
      mButton.setFocusable(false);
      mButton.setClickable(false);
    }

    a.recycle();

    addView(mNameView);
    addView(mAddressView);
    if (mButton != null) addView(mButton);

    mAvatarDrawable = new AvatarDrawable();
    if (avatarSrc != 0) setAvatarResource(avatarSrc);
  }
示例#30
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);
  }