Example usage for android.util AttributeSet getAttributeIntValue

List of usage examples for android.util AttributeSet getAttributeIntValue

Introduction

In this page you can find the example usage for android.util AttributeSet getAttributeIntValue.

Prototype

public int getAttributeIntValue(String namespace, String attribute, int defaultValue);

Source Link

Document

Return the integer value of 'attribute'.

Usage

From source file:de.andacaydin.bidirectionalviewpagerlibrary.BiDirectionalViewPager.java

public BiDirectionalViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    initViewPager();// ww  w . j a v  a  2  s.  c  o m

    // We default to horizontal, only change if a value is explicitly
    // specified
    int orientation = attrs.getAttributeIntValue(XML_NS, "orientation", -1);
    if (orientation != -1) {
        setOrientation(orientation);
    }
}

From source file:com.alimuzaffar.lib.widgets.PinEntryEditText.java

private void init(Context context, AttributeSet attrs) {
    float multi = context.getResources().getDisplayMetrics().density;
    mLineStroke = multi * mLineStroke;//ww  w . j  a  v  a  2s  .c o  m
    mLineStrokeSelected = multi * mLineStrokeSelected;
    mSpace = multi * mSpace; //convert to pixels for our density
    mTextBottomPadding = multi * mTextBottomPadding; //convert to pixels for our density

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PinEntryEditText, 0, 0);
    try {
        TypedValue outValue = new TypedValue();
        ta.getValue(R.styleable.PinEntryEditText_pinAnimationType, outValue);
        mAnimatedType = outValue.data;
        mMask = ta.getString(R.styleable.PinEntryEditText_pinCharacterMask);
        mLineStroke = ta.getDimension(R.styleable.PinEntryEditText_pinLineStroke, mLineStroke);
        mLineStrokeSelected = ta.getDimension(R.styleable.PinEntryEditText_pinLineStrokeSelected,
                mLineStrokeSelected);
        mSpace = ta.getDimension(R.styleable.PinEntryEditText_pinCharacterSpacing, mSpace);
        mTextBottomPadding = ta.getDimension(R.styleable.PinEntryEditText_pinTextBottomPadding,
                mTextBottomPadding);
        mIsDigitSquare = ta.getBoolean(R.styleable.PinEntryEditText_pinBackgroundIsSquare, mIsDigitSquare);
        mPinBackground = ta.getDrawable(R.styleable.PinEntryEditText_pinBackgroundDrawable);
        ColorStateList colors = ta.getColorStateList(R.styleable.PinEntryEditText_pinLineColors);
        if (colors != null) {
            mColorStates = colors;
        }
    } finally {
        ta.recycle();
    }

    mCharPaint = new Paint(getPaint());
    mLastCharPaint = new Paint(getPaint());
    mLinesPaint = new Paint(getPaint());
    mLinesPaint.setStrokeWidth(mLineStroke);

    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorControlActivated, outValue, true);
    int colorSelected = outValue.data;
    mColors[0] = colorSelected;

    int colorFocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[1] = colorFocused;

    int colorUnfocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[2] = colorUnfocused;

    setBackgroundResource(0);

    mMaxLength = attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4);
    mNumChars = mMaxLength;

    //Disable copy paste
    super.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    // When tapped, move cursor to end of text.
    super.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelection(getText().length());
            if (mClickListener != null) {
                mClickListener.onClick(v);
            }
        }
    });

    super.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            setSelection(getText().length());
            return true;
        }
    });

    //If input type is password and no mask is set, use a default mask
    if ((getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    } else if ((getInputType()
            & InputType.TYPE_NUMBER_VARIATION_PASSWORD) == InputType.TYPE_NUMBER_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    }

    if (!TextUtils.isEmpty(mMask)) {
        mMaskChars = getMaskChars();
    }

    //Height of the characters, used if there is a background drawable
    getPaint().getTextBounds("|", 0, 1, mTextHeight);
}

From source file:com.alimuzaffar.lib.pin.PinEntryEditText.java

private void init(Context context, AttributeSet attrs) {
    float multi = context.getResources().getDisplayMetrics().density;
    mLineStroke = multi * mLineStroke;/*from w  ww  .j  a  v a  2  s . c o m*/
    mLineStrokeSelected = multi * mLineStrokeSelected;
    mSpace = multi * mSpace; //convert to pixels for our density
    mTextBottomPadding = multi * mTextBottomPadding; //convert to pixels for our density

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PinEntryEditText, 0, 0);
    try {
        TypedValue outValue = new TypedValue();
        ta.getValue(R.styleable.PinEntryEditText_pinAnimationType, outValue);
        mAnimatedType = outValue.data;
        mMask = ta.getString(R.styleable.PinEntryEditText_pinCharacterMask);
        mSingleCharHint = ta.getString(R.styleable.PinEntryEditText_pinRepeatedHint);
        mLineStroke = ta.getDimension(R.styleable.PinEntryEditText_pinLineStroke, mLineStroke);
        mLineStrokeSelected = ta.getDimension(R.styleable.PinEntryEditText_pinLineStrokeSelected,
                mLineStrokeSelected);
        mSpace = ta.getDimension(R.styleable.PinEntryEditText_pinCharacterSpacing, mSpace);
        mTextBottomPadding = ta.getDimension(R.styleable.PinEntryEditText_pinTextBottomPadding,
                mTextBottomPadding);
        mIsDigitSquare = ta.getBoolean(R.styleable.PinEntryEditText_pinBackgroundIsSquare, mIsDigitSquare);
        mPinBackground = ta.getDrawable(R.styleable.PinEntryEditText_pinBackgroundDrawable);
        ColorStateList colors = ta.getColorStateList(R.styleable.PinEntryEditText_pinLineColors);
        if (colors != null) {
            mColorStates = colors;
        }
    } finally {
        ta.recycle();
    }

    mCharPaint = new Paint(getPaint());
    mLastCharPaint = new Paint(getPaint());
    mSingleCharPaint = new Paint(getPaint());
    mLinesPaint = new Paint(getPaint());
    mLinesPaint.setStrokeWidth(mLineStroke);

    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorControlActivated, outValue, true);
    int colorSelected = outValue.data;
    mColors[0] = colorSelected;

    int colorFocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[1] = colorFocused;

    int colorUnfocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[2] = colorUnfocused;

    setBackgroundResource(0);

    mMaxLength = attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4);
    mNumChars = mMaxLength;

    //Disable copy paste
    super.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    // When tapped, move cursor to end of text.
    super.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelection(getText().length());
            if (mClickListener != null) {
                mClickListener.onClick(v);
            }
        }
    });

    super.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            setSelection(getText().length());
            return true;
        }
    });

    //If input type is password and no mask is set, use a default mask
    if ((getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    } else if ((getInputType()
            & InputType.TYPE_NUMBER_VARIATION_PASSWORD) == InputType.TYPE_NUMBER_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    }

    if (!TextUtils.isEmpty(mMask)) {
        mMaskChars = getMaskChars();
    }

    //Height of the characters, used if there is a background drawable
    getPaint().getTextBounds("|", 0, 1, mTextHeight);

    mAnimate = mAnimatedType > -1;
}

From source file:dev.dworks.libs.widget.ViewPager.java

public ViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    initViewPager();// w  ww  .  j  av a2  s  .  c om

    //We default to horizontal, only change if a value is explicitly specified
    int orientation = attrs.getAttributeIntValue(XML_NS, "orientation", -1);
    if (orientation != -1) {
        setOrientation(orientation);
    }
}

From source file:androidx.media.widget.VideoView2.java

public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mVideoWidth = 0;// w w  w .ja v  a 2  s .  c  om
    mVideoHeight = 0;
    mSpeed = 1.0f;
    mFallbackSpeed = mSpeed;
    mSelectedSubtitleTrackIndex = INVALID_TRACK_INDEX;
    // TODO: add attributes to get this value.
    mShowControllerIntervalMs = DEFAULT_SHOW_CONTROLLER_INTERVAL_MS;

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    mAudioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build();
    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();

    // TODO: try to keep a single child at a time rather than always having both.
    mTextureView = new VideoTextureView(getContext());
    mSurfaceView = new VideoSurfaceView(getContext());
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mTextureView.setLayoutParams(params);
    mSurfaceView.setLayoutParams(params);
    mTextureView.setSurfaceListener(this);
    mSurfaceView.setSurfaceListener(this);

    addView(mTextureView);
    addView(mSurfaceView);

    // mSubtitleView = new SubtitleView(getContext());
    // mSubtitleView.setLayoutParams(params);
    // mSubtitleView.setBackgroundColor(0);
    // addView(mSubtitleView);

    boolean enableControlView = (attrs == null) || attrs
            .getAttributeBooleanValue("http://schemas.android.com/apk/res/android", "enableControlView", true);
    if (enableControlView) {
        mMediaControlView = new MediaControlView2(getContext());
    }

    mSubtitleEnabled = (attrs == null) || attrs
            .getAttributeBooleanValue("http://schemas.android.com/apk/res/android", "enableSubtitle", false);

    // TODO: Choose TextureView when SurfaceView cannot be created.
    // Choose surface view by default
    int viewType = (attrs == null) ? VideoView2.VIEW_TYPE_SURFACEVIEW
            : attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "viewType",
                    VideoView2.VIEW_TYPE_SURFACEVIEW);
    if (viewType == VideoView2.VIEW_TYPE_SURFACEVIEW) {
        Log.d(TAG, "viewType attribute is surfaceView.");
        mTextureView.setVisibility(View.GONE);
        mSurfaceView.setVisibility(View.VISIBLE);
        mCurrentView = mSurfaceView;
    } else if (viewType == VideoView2.VIEW_TYPE_TEXTUREVIEW) {
        Log.d(TAG, "viewType attribute is textureView.");
        mTextureView.setVisibility(View.VISIBLE);
        mSurfaceView.setVisibility(View.GONE);
        mCurrentView = mTextureView;
    }

    // TODO (b/77158231)
    /*
    MediaRouteSelector.Builder builder = new MediaRouteSelector.Builder();
    builder.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
    builder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO);
    builder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO);
    mRouteSelector = builder.build();
    */
}