Java Code Examples for android.content.res.TypedArray#hasValue()

The following examples show how to use android.content.res.TypedArray#hasValue() . 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: ActivityInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Determines whether the {@link Activity} is considered translucent or floating.
 * @hide
 */
@TestApi
public static boolean isTranslucentOrFloating(TypedArray attributes) {
    final boolean isTranslucent =
            attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsTranslucent,
                    false);
    final boolean isSwipeToDismiss = !attributes.hasValue(
            com.android.internal.R.styleable.Window_windowIsTranslucent)
            && attributes.getBoolean(
                    com.android.internal.R.styleable.Window_windowSwipeToDismiss, false);
    final boolean isFloating =
            attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsFloating,
                    false);

    return isFloating || isTranslucent || isSwipeToDismiss;
}
 
Example 2
Source File: ParallaxScrimageView.java    From ShrinkingImageLayout with Apache License 2.0 6 votes vote down vote up
public ParallaxScrimageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if(attrs != null) {
        final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ParallaxScrimageView);
        if (a.hasValue(R.styleable.ParallaxScrimageView_scrimColor)) {
            scrimColor = a.getColor(R.styleable.ParallaxScrimageView_scrimColor, scrimColor);
        }
        if (a.hasValue(R.styleable.ParallaxScrimageView_scrimAlpha)) {
            scrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_scrimAlpha, scrimAlpha);
        }
        if (a.hasValue(R.styleable.ParallaxScrimageView_maxScrimAlpha)) {
            maxScrimAlpha = a.getFloat(R.styleable.ParallaxScrimageView_maxScrimAlpha,
                    maxScrimAlpha);
        }
        if (a.hasValue(R.styleable.ParallaxScrimageView_parallaxFactor)) {
            parallaxFactor = a.getFloat(R.styleable.ParallaxScrimageView_parallaxFactor,
                    parallaxFactor);
        }
        a.recycle();
    }


    scrimPaint = new Paint();
    scrimPaint.setColor(ColorUtils.modifyAlpha(scrimColor, scrimAlpha));
}
 
Example 3
Source File: CircleImageView.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

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

    mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH);
    mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR);
    mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);

    // Look for deprecated civ_fill_color if civ_circle_background_color is not set
    if (a.hasValue(R.styleable.CircleImageView_civ_circle_background_color)) {
        mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_circle_background_color,
                DEFAULT_CIRCLE_BACKGROUND_COLOR);
    } else if (a.hasValue(R.styleable.CircleImageView_civ_fill_color)) {
        mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_fill_color,
                DEFAULT_CIRCLE_BACKGROUND_COLOR);
    }

    a.recycle();

    init();
}
 
Example 4
Source File: AppCompatBackgroundHelper.java    From timecat with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ResourceType")
@Override
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    initPadding();
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mBackgroundTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportBackgroundTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportBackgroundTint(mBackgroundTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mBackgroundResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setBackgroundDrawable(drawable);
        }
    }
    array.recycle();
}
 
Example 5
Source File: PlacePickerFragment.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);
    TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_place_picker_fragment);

    setRadiusInMeters(a.getInt(R.styleable.com_facebook_place_picker_fragment_radius_in_meters, radiusInMeters));
    setResultsLimit(a.getInt(R.styleable.com_facebook_place_picker_fragment_results_limit, resultsLimit));
    if (a.hasValue(R.styleable.com_facebook_place_picker_fragment_results_limit)) {
        setSearchText(a.getString(R.styleable.com_facebook_place_picker_fragment_search_text));
    }
    showSearchBox = a.getBoolean(R.styleable.com_facebook_place_picker_fragment_show_search_box, showSearchBox);

    a.recycle();
}
 
Example 6
Source File: MaterialResources.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the drawable object from the given attributes.
 *
 * <p>This method supports inflation of {@code <vector>} and {@code <animated-vector>} resources
 * on devices where platform support is not available.
 */
@Nullable
public static Drawable getDrawable(
    @NonNull Context context, @NonNull TypedArray attributes, @StyleableRes int index) {
  if (attributes.hasValue(index)) {
    int resourceId = attributes.getResourceId(index, 0);
    if (resourceId != 0) {
      Drawable value = AppCompatResources.getDrawable(context, resourceId);
      if (value != null) {
        return value;
      }
    }
  }
  return attributes.getDrawable(index);
}
 
Example 7
Source File: RoundedLetterView.java    From RoundedLetterView with Apache License 2.0 5 votes vote down vote up
private void init(AttributeSet attrs, int defStyle) {
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.RoundedLetterView, defStyle, 0);

    if(a.hasValue(R.styleable.RoundedLetterView_rlv_titleText)){
        mTitleText = a.getString(R.styleable.RoundedLetterView_rlv_titleText);
    }

    mTitleColor = a.getColor(R.styleable.RoundedLetterView_rlv_titleColor,DEFAULT_TITLE_COLOR);
    mBackgroundColor = a.getColor(R.styleable.RoundedLetterView_rlv_backgroundColorValue,DEFAULT_BACKGROUND_COLOR);

    mTitleSize = a.getDimension(R.styleable.RoundedLetterView_rlv_titleSize,DEFAULT_TITLE_SIZE);
    a.recycle();

    //Title TextPaint
    mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(mFont);
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(mTitleColor);
    mTitleTextPaint.setTextSize(mTitleSize);

    //Background Paint
    mBackgroundPaint = new Paint();
    mBackgroundPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setStyle(Paint.Style.FILL);
    mBackgroundPaint.setColor(mBackgroundColor);

    mInnerRectF = new RectF();
}
 
Example 8
Source File: ParallaxImageView.java    From motion with Apache License 2.0 5 votes vote down vote up
public ParallaxImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Instantiate future objects
    mTranslationMatrix = new Matrix();
    mSensorInterpreter = new SensorInterpreter();

    // Sets scale type
    setScaleType(ScaleType.MATRIX);

    // Set available attributes
    if (attrs != null) {
        final TypedArray customAttrs = context.obtainStyledAttributes(attrs, R.styleable.ParallaxImageView);

        if (customAttrs != null) {
            if (customAttrs.hasValue(R.styleable.ParallaxImageView_motionIntensity)) {
                setParallaxIntensity(customAttrs.getFloat(R.styleable.ParallaxImageView_motionIntensity, mParallaxIntensity));
            }

            if (customAttrs.hasValue(R.styleable.ParallaxImageView_motionScaledIntensity)) {
                setScaledIntensities(customAttrs.getBoolean(R.styleable.ParallaxImageView_motionScaledIntensity, mScaledIntensities));
            }

            if (customAttrs.hasValue(R.styleable.ParallaxImageView_motionTiltSensitivity)) {
                setTiltSensitivity(customAttrs.getFloat(R.styleable.ParallaxImageView_motionTiltSensitivity,
                        mSensorInterpreter.getTiltSensitivity()));
            }

            customAttrs.recycle();
        }
    }

    // Configure matrix as early as possible by posting to MessageQueue
    post(new Runnable() {
        @Override
        public void run() {
            configureMatrix();
        }
    });
}
 
Example 9
Source File: FrameLayout.java    From Carbon with Apache License 2.0 5 votes vote down vote up
public LayoutParams(Context c, AttributeSet attrs) {
    super(c, attrs);
    if (gravity <= 0)
        gravity = GravityCompat.START | Gravity.TOP;

    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.FrameLayout_Layout);
    anchorView = a.getResourceId(R.styleable.FrameLayout_Layout_carbon_layout_anchor, -1);
    anchorGravity = a.getInt(R.styleable.FrameLayout_Layout_carbon_layout_anchorGravity, -1);
    if (a.hasValue(R.styleable.FrameLayout_Layout_carbon_layout_marginHorizontal))
        leftMargin = rightMargin = a.getDimensionPixelSize(R.styleable.FrameLayout_Layout_carbon_layout_marginHorizontal, 0);
    if (a.hasValue(R.styleable.FrameLayout_Layout_carbon_layout_marginVertical))
        topMargin = bottomMargin = a.getDimensionPixelSize(R.styleable.FrameLayout_Layout_carbon_layout_marginVertical, 0);
    a.recycle();
}
 
Example 10
Source File: PlacePickerFragment.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);
    TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_place_picker_fragment);

    setRadiusInMeters(a.getInt(R.styleable.com_facebook_place_picker_fragment_radius_in_meters, radiusInMeters));
    setResultsLimit(a.getInt(R.styleable.com_facebook_place_picker_fragment_results_limit, resultsLimit));
    if (a.hasValue(R.styleable.com_facebook_place_picker_fragment_results_limit)) {
        setSearchText(a.getString(R.styleable.com_facebook_place_picker_fragment_search_text));
    }
    showSearchBox = a.getBoolean(R.styleable.com_facebook_place_picker_fragment_show_search_box, showSearchBox);

    a.recycle();
}
 
Example 11
Source File: KeyStylesSet.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public String[] getStringArray(final TypedArray a, final int index) {
    if (a.hasValue(index)) {
        return parseStringArray(a, index);
    }
    final Object value = mStyleAttributes.get(index);
    if (value != null) {
        final String[] array = (String[])value;
        return Arrays.copyOf(array, array.length);
    }
    final KeyStyle parentStyle = mStyles.get(mParentStyleName);
    return parentStyle.getStringArray(a, index);
}
 
Example 12
Source File: ShimmerFrameLayout.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public ShimmerFrameLayout(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);

  setWillNotDraw(false);

  mMask = new Mask();
  mAlphaPaint = new Paint();
  mMaskPaint = new Paint();
  mMaskPaint.setAntiAlias(true);
  mMaskPaint.setDither(true);
  mMaskPaint.setFilterBitmap(true);
  mMaskPaint.setXfermode(DST_IN_PORTER_DUFF_XFERMODE);

  useDefaults();

  if (attrs != null) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShimmerFrameLayout, 0, 0);
    try {
      if (a.hasValue(R.styleable.ShimmerFrameLayout_auto_start)) {
        setAutoStart(a.getBoolean(R.styleable.ShimmerFrameLayout_auto_start, false));
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_base_alpha)) {
        setBaseAlpha(a.getFloat(R.styleable.ShimmerFrameLayout_base_alpha, 0));
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_shimmerduration)) {
        setDuration(a.getInt(R.styleable.ShimmerFrameLayout_shimmerduration, 0));
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_repeat_count)) {
        setRepeatCount(a.getInt(R.styleable.ShimmerFrameLayout_repeat_count, 0));
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_repeat_delay)) {
        setRepeatDelay(a.getInt(R.styleable.ShimmerFrameLayout_repeat_delay, 0));
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_repeat_mode)) {
        setRepeatMode(a.getInt(R.styleable.ShimmerFrameLayout_repeat_mode, 0));
      }

      if (a.hasValue(R.styleable.ShimmerFrameLayout_shimmerangle)) {
        int angle = a.getInt(R.styleable.ShimmerFrameLayout_shimmerangle, 0);
        switch (angle) {
          default:
          case 0:
            mMask.angle = MaskAngle.CW_0;
            break;
          case 90:
            mMask.angle = MaskAngle.CW_90;
            break;
          case 180:
            mMask.angle = MaskAngle.CW_180;
            break;
          case 270:
            mMask.angle = MaskAngle.CW_270;
            break;
        }
      }

      if (a.hasValue(R.styleable.ShimmerFrameLayout_shimmershape)) {
        int shape = a.getInt(R.styleable.ShimmerFrameLayout_shimmerangle, 0);
        switch (shape) {
          default:
          case 0:
            mMask.shape = MaskShape.LINEAR;
            break;
          case 1:
            mMask.shape = MaskShape.RADIAL;
            break;
        }
      }

      if (a.hasValue(R.styleable.ShimmerFrameLayout_shimmerdropoff)) {
        mMask.dropoff = a.getFloat(R.styleable.ShimmerFrameLayout_shimmerdropoff, 0);
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_fixed_width)) {
        mMask.fixedWidth = a.getDimensionPixelSize(R.styleable.ShimmerFrameLayout_fixed_width, 0);
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_fixed_height)) {
        mMask.fixedHeight = a.getDimensionPixelSize(R.styleable.ShimmerFrameLayout_fixed_height, 0);
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_shimmerintensity)) {
        mMask.intensity = a.getFloat(R.styleable.ShimmerFrameLayout_shimmerintensity, 0);
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_relative_width)) {
        mMask.relativeWidth = a.getFloat(R.styleable.ShimmerFrameLayout_relative_width, 0);
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_relative_height)) {
        mMask.relativeHeight = a.getFloat(R.styleable.ShimmerFrameLayout_relative_height, 0);
      }
      if (a.hasValue(R.styleable.ShimmerFrameLayout_tilt)) {
        mMask.tilt = a.getFloat(R.styleable.ShimmerFrameLayout_tilt, 0);
      }
    } finally {
      a.recycle();
    }
  }
}
 
Example 13
Source File: RangeSeekBar.java    From RangeSeekBar with MIT License 4 votes vote down vote up
public RangeSeekBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr);

    mInitialProgressDone = false;

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

    Drawable thumb;
    Drawable thumb2;

    if (a.hasValue(R.styleable.RangeSeekBar_range_seekbar_leftThumb)) {
        thumb = a.getDrawable(R.styleable.RangeSeekBar_range_seekbar_leftThumb);
    } else {
        thumb = a.getDrawable(R.styleable.RangeSeekBar_android_thumb);
    }

    if (a.hasValue(R.styleable.RangeSeekBar_range_seekbar_rightThumb)) {
        thumb2 = a.getDrawable(R.styleable.RangeSeekBar_range_seekbar_rightThumb);
    } else {
        thumb2 = a.getDrawable(R.styleable.RangeSeekBar_android_thumb);
    }

    setThumb(thumb, WhichThumb.Start);
    setThumb(thumb2, WhichThumb.End);

    if (a.hasValue(R.styleable.RangeSeekBar_android_thumbTintMode)) {
        mThumbTintMode = DrawableUtils.parseTintMode(a.getInt(
            R.styleable.RangeSeekBar_android_thumbTintMode, -1), mThumbTintMode);
        mHasThumbTintMode = true;
    }

    if (a.hasValue(R.styleable.RangeSeekBar_android_thumbTint)) {
        mThumbTintList = a.getColorStateList(R.styleable.RangeSeekBar_android_thumbTint);
        mHasThumbTint = true;
    }

    if (Build.VERSION.SDK_INT >= 24) {
        final Drawable tickMark = a.getDrawable(R.styleable.RangeSeekBar_android_tickMark);
        logger.verbose("tickMark = %s", tickMark);

        setTickMark(tickMark);

        if (a.hasValue(R.styleable.RangeSeekBar_android_tickMarkTintMode)) {
            mTickMarkTintMode = DrawableUtils.parseTintMode(a.getInt(
                R.styleable.RangeSeekBar_android_tickMarkTintMode, -1), mTickMarkTintMode);
            mHasTickMarkTintMode = true;
        }

        if (a.hasValue(R.styleable.RangeSeekBar_android_tickMarkTint)) {
            mTickMarkTintList = a.getColorStateList(R.styleable.RangeSeekBar_android_tickMarkTint);
            mHasTickMarkTint = true;
        }
    }

    mSplitTrack = a.getBoolean(R.styleable.RangeSeekBar_android_splitTrack, false);

    if (a.hasValue(R.styleable.RangeSeekBar_range_seekbar_stepSize)) {
        mStepSize = a.getInt(R.styleable.RangeSeekBar_range_seekbar_stepSize, 1);
    }

    setMinMaxStepSize(getMinMapStepSize());

    mThumbClipInset = a.getDimensionPixelSize(R.styleable.RangeSeekBar_range_seekbar_thumbInset, mThumbClipInset);

    final int thumbOffset = a.getDimensionPixelOffset(
        R.styleable.RangeSeekBar_android_thumbOffset, getThumbOffset());
    setThumbOffset(thumbOffset);

    final boolean useDisabledAlpha = a.getBoolean(R.styleable.RangeSeekBar_range_seekbar_useDisabledAlpha, true);
    a.recycle();

    if (useDisabledAlpha) {
        //            final TypedArray ta = context.obtainStyledAttributes(attrs, android.R.styleable.Theme, 0, 0);
        //            mDisabledAlpha = ta.getFloat(R.styleable.Theme_disabledAlpha, 0.5f);
        //            ta.recycle();

        // TODO: find out
        mDisabledAlpha = 0.5f;
    } else {
        mDisabledAlpha = 1.0f;
    }

    applyTickMarkTint();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    setInitialProgress(mInitialStartValue, mInitialEndValue);

    setProgress(mInitialStartValue, mInitialEndValue);

    mInitialProgressDone = true;
}
 
Example 14
Source File: PagerTitleStripV22.java    From Dividers with Apache License 2.0 4 votes vote down vote up
public PagerTitleStripV22(Context context, AttributeSet attrs) {
  super(context, attrs);

  addView(mPrevText = new TextView(context));
  addView(mCurrText = new TextView(context));
  addView(mNextText = new TextView(context));

  final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
  final int textAppearance = a.getResourceId(0, 0);
  if (textAppearance != 0) {
    mPrevText.setTextAppearance(context, textAppearance);
    mCurrText.setTextAppearance(context, textAppearance);
    mNextText.setTextAppearance(context, textAppearance);
  }
  final int textSize = a.getDimensionPixelSize(1, 0);
  if (textSize != 0) {
    setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
  }
  if (a.hasValue(2)) {
    final int textColor = a.getColor(2, 0);
    mPrevText.setTextColor(textColor);
    mCurrText.setTextColor(textColor);
    mNextText.setTextColor(textColor);
  }
  mGravity = a.getInteger(3, Gravity.BOTTOM);
  a.recycle();

  mTextColor = mCurrText.getTextColors().getDefaultColor();
  setNonPrimaryAlpha(SIDE_ALPHA);

  mPrevText.setEllipsize(TruncateAt.END);
  mCurrText.setEllipsize(TruncateAt.END);
  mNextText.setEllipsize(TruncateAt.END);

  boolean allCaps = false;
  if (textAppearance != 0) {
    final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS);
    allCaps = ta.getBoolean(0, false);
    ta.recycle();
  }

  if (allCaps) {
    setSingleLineAllCaps(mPrevText);
    setSingleLineAllCaps(mCurrText);
    setSingleLineAllCaps(mNextText);
  } else {
    mPrevText.setSingleLine();
    mCurrText.setSingleLine();
    mNextText.setSingleLine();
  }

  final float density = context.getResources().getDisplayMetrics().density;
  mScaledTextSpacing = (int) (TEXT_SPACING * density);
}
 
Example 15
Source File: SimpleSearchView.java    From SimpleSearchView with Apache License 2.0 4 votes vote down vote up
private void initStyle(AttributeSet attrs, int defStyleAttr) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SimpleSearchView, defStyleAttr, 0);
    if (typedArray == null) {
        setCardStyle(style);
        return;
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_type)) {
        setCardStyle(typedArray.getInt(R.styleable.SimpleSearchView_type, style));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_backIconAlpha)) {
        setBackIconAlpha(typedArray.getFloat(R.styleable.SimpleSearchView_backIconAlpha, BACK_ICON_ALPHA_DEFAULT));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_iconsAlpha)) {
        setIconsAlpha(typedArray.getFloat(R.styleable.SimpleSearchView_iconsAlpha, ICONS_ALPHA_DEFAULT));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_backIconTint)) {
        setBackIconColor(typedArray.getColor(R.styleable.SimpleSearchView_backIconTint, ContextUtils.getPrimaryColor(context)));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_iconsTint)) {
        setIconsColor(typedArray.getColor(R.styleable.SimpleSearchView_iconsTint, Color.BLACK));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_cursorColor)) {
        setCursorColor(typedArray.getColor(R.styleable.SimpleSearchView_cursorColor, ContextUtils.getAccentColor(context)));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_hintColor)) {
        setHintTextColor(typedArray.getColor(R.styleable.SimpleSearchView_hintColor, getResources().getColor(R.color.default_textColorHint)));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_searchBackground)) {
        setSearchBackground(typedArray.getDrawable(R.styleable.SimpleSearchView_searchBackground));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_searchBackIcon)) {
        setBackIconDrawable(typedArray.getDrawable(R.styleable.SimpleSearchView_searchBackIcon));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_searchClearIcon)) {
        setClearIconDrawable(typedArray.getDrawable(R.styleable.SimpleSearchView_searchClearIcon));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_searchVoiceIcon)) {
        setVoiceIconDrawable(typedArray.getDrawable(R.styleable.SimpleSearchView_searchVoiceIcon));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_voiceSearch)) {
        enableVoiceSearch(typedArray.getBoolean(R.styleable.SimpleSearchView_voiceSearch, allowVoiceSearch));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_voiceSearchPrompt)) {
        setVoiceSearchPrompt(typedArray.getString(R.styleable.SimpleSearchView_voiceSearchPrompt));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_android_hint)) {
        setHint(typedArray.getString(R.styleable.SimpleSearchView_android_hint));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_android_inputType)) {
        setInputType(typedArray.getInt(R.styleable.SimpleSearchView_android_inputType, EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS));
    }

    if (typedArray.hasValue(R.styleable.SimpleSearchView_android_textColor)) {
        setTextColor(typedArray.getColor(R.styleable.SimpleSearchView_android_textColor, getResources().getColor(R.color.default_textColor)));
    }

    typedArray.recycle();
}
 
Example 16
Source File: RulerValuePicker.java    From android-ruler-picker with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the view and parse the {@link AttributeSet}.
 *
 * @param attributeSet {@link AttributeSet} to parse or null if no attribute parameters set.
 */
private void init(@Nullable AttributeSet attributeSet) {

    //Add all the children
    addChildViews();

    if (attributeSet != null) {
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attributeSet,
                R.styleable.RulerValuePicker,
                0,
                0);

        try { //Parse params
            if (a.hasValue(R.styleable.RulerValuePicker_notch_color)) {
                mNotchColor = a.getColor(R.styleable.RulerValuePicker_notch_color, Color.WHITE);
            }

            if (a.hasValue(R.styleable.RulerValuePicker_ruler_text_color)) {
                setTextColor(a.getColor(R.styleable.RulerValuePicker_ruler_text_color, Color.WHITE));
            }

            if (a.hasValue(R.styleable.RulerValuePicker_ruler_text_size)) {
                setTextSize((int) a.getDimension(R.styleable.RulerValuePicker_ruler_text_size, 14));
            }

            if (a.hasValue(R.styleable.RulerValuePicker_indicator_color)) {
                setIndicatorColor(a.getColor(R.styleable.RulerValuePicker_indicator_color, Color.WHITE));
            }

            if (a.hasValue(R.styleable.RulerValuePicker_indicator_width)) {
                setIndicatorWidth(a.getDimensionPixelSize(R.styleable.RulerValuePicker_indicator_width,
                        4));
            }

            if (a.hasValue(R.styleable.RulerValuePicker_indicator_interval)) {
                setIndicatorIntervalDistance(a.getDimensionPixelSize(R.styleable.RulerValuePicker_indicator_interval,
                        4));
            }

            if (a.hasValue(R.styleable.RulerValuePicker_long_height_height_ratio)
                    || a.hasValue(R.styleable.RulerValuePicker_short_height_height_ratio)) {

                setIndicatorHeight(a.getFraction(R.styleable.RulerValuePicker_long_height_height_ratio,
                        1, 1, 0.6f),
                        a.getFraction(R.styleable.RulerValuePicker_short_height_height_ratio,
                                1, 1, 0.4f));
            }

            if (a.hasValue(R.styleable.RulerValuePicker_min_value) ||
                    a.hasValue(R.styleable.RulerValuePicker_max_value)) {
                setMinMaxValue(a.getInteger(R.styleable.RulerValuePicker_min_value, 0),
                        a.getInteger(R.styleable.RulerValuePicker_max_value, 100));
            }
        } finally {
            a.recycle();
        }
    }

    //Prepare the notch color.
    mNotchPaint = new Paint();
    prepareNotchPaint();

    mNotchPath = new Path();
}
 
Example 17
Source File: YcCardView.java    From CardViewShadowColor with Apache License 2.0 4 votes vote down vote up
private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.YcCardView, defStyleAttr,
            R.style.YcCardView);
    int backgroundColor;
    if (a.hasValue(R.styleable.YcCardView_ycCardBackgroundColor)) {
        backgroundColor = a.getColor(R.styleable.YcCardView_ycCardBackgroundColor, 0);
    } else {
        // There isn't one set, so we'll compute one based on the theme
        final TypedArray aa = getContext().obtainStyledAttributes(COLOR_BACKGROUND_ATTR);
        final int themeColorBackground = aa.getColor(0, 0);
        aa.recycle();

        // If the theme colorBackground is light, use our own light color, otherwise dark
        final float[] hsv = new float[3];
        Color.colorToHSV(themeColorBackground, hsv);
        backgroundColor = hsv[2] > 0.5f
                ? getResources().getColor(R.color.yc_cardview_light_background)
                : getResources().getColor(R.color.yc_cardview_dark_background);
    }
    startShadowColor = a.getColor(R.styleable.YcCardView_ycStartShadowColor, 0);
    endShadowColor = a.getColor(R.styleable.YcCardView_ycEndShadowColor, 0);
    float radius = a.getDimension(R.styleable.YcCardView_ycCardCornerRadius, 0);
    float elevation = a.getDimension(R.styleable.YcCardView_ycCardElevation, 0);
    float maxElevation = a.getDimension(R.styleable.YcCardView_ycCardMaxElevation, 0);
    mCompatPadding = a.getBoolean(R.styleable.YcCardView_ycCardUseCompatPadding, false);
    mPreventCornerOverlap = a.getBoolean(R.styleable.YcCardView_ycCardPreventCornerOverlap, true);
    int defaultPadding = a.getDimensionPixelSize(R.styleable.YcCardView_ycContentPadding, 0);
    mContentPadding.left = a.getDimensionPixelSize(R.styleable.YcCardView_ycContentPaddingLeft,
            defaultPadding);
    mContentPadding.top = a.getDimensionPixelSize(R.styleable.YcCardView_ycContentPaddingTop,
            defaultPadding);
    mContentPadding.right = a.getDimensionPixelSize(R.styleable.YcCardView_ycContentPaddingRight,
            defaultPadding);
    mContentPadding.bottom = a.getDimensionPixelSize(R.styleable.YcCardView_contentPaddingBottom,
            defaultPadding);
    if (elevation > maxElevation) {
        maxElevation = elevation;
    }
    mUserSetMinWidth = a.getDimensionPixelSize(R.styleable.YcCardView_android_minWidth, 0);
    mUserSetMinHeight = a.getDimensionPixelSize(R.styleable.YcCardView_android_minHeight, 0);
    a.recycle();

    IMPL.initialize(mCardViewDelegate, context, backgroundColor, radius,
            elevation, maxElevation, startShadowColor, endShadowColor);
}
 
Example 18
Source File: StateAwareTextView.java    From SublimeNavigationView with Apache License 2.0 4 votes vote down vote up
public StateAwareTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = getContext().obtainStyledAttributes(attrs,
            R.styleable.StateAwareTextView, defStyleAttr,
            0);

    try {

        // If user has provided a valid value
        // for @android:attr/textAppearance, it has already been
        // applied in our parent - TextView. Else, resolve & use the value
        // of @attr/saTextAppearance.
        if (a.hasValue(R.styleable.StateAwareTextView_android_textAppearance)) {
            int textAppearance = a.getResourceId(
                    R.styleable.StateAwareTextView_android_textAppearance, -1);

            if (textAppearance == -1) {
                if (Config.DEBUG) {
                    Log.i(TAG, "textAppearance is -1");
                }

                int saTextAppearance = a.getResourceId(
                        R.styleable.StateAwareTextView_saTextAppearance,
                        R.style.SnvDefaultTextAppearance);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    setTextAppearance(saTextAppearance);
                } else {
                    setTextAppearance(getContext(), saTextAppearance);
                }
            } else {
                if (Config.DEBUG) {
                    Log.i(TAG, "textAppearance is AVAILABLE");
                }
            }
        }
    } finally {
        a.recycle();
    }
}
 
Example 19
Source File: KeyboardBuilder.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
private static boolean matchString(final TypedArray a, final int index, final String value) {
    // If <case> does not have "index" attribute, that means this <case> is wild-card for
    // the attribute.
    return !a.hasValue(index)
            || StringUtils.containsInArray(value, a.getString(index).split("\\|"));
}
 
Example 20
Source File: StateAwareTextView.java    From SublimeNavigationView with Apache License 2.0 4 votes vote down vote up
public StateAwareTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = getContext().obtainStyledAttributes(attrs,
            R.styleable.StateAwareTextView, defStyleAttr,
            0);

    try {

        // If user has provided a valid value
        // for @android:attr/textAppearance, it has already been
        // applied in our parent - TextView. Else, resolve & use the value
        // of @attr/saTextAppearance.
        if (a.hasValue(R.styleable.StateAwareTextView_android_textAppearance)) {
            int textAppearance = a.getResourceId(
                    R.styleable.StateAwareTextView_android_textAppearance, -1);

            if (textAppearance == -1) {
                if (Config.DEBUG) {
                    Log.i(TAG, "textAppearance is -1");
                }

                int saTextAppearance = a.getResourceId(
                        R.styleable.StateAwareTextView_saTextAppearance,
                        R.style.SnvDefaultTextAppearance);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    setTextAppearance(saTextAppearance);
                } else {
                    setTextAppearance(getContext(), saTextAppearance);
                }
            } else {
                if (Config.DEBUG) {
                    Log.i(TAG, "textAppearance is AVAILABLE");
                }
            }
        }
    } finally {
        a.recycle();
    }
}