Example usage for android.content.res TypedArray getString

List of usage examples for android.content.res TypedArray getString

Introduction

In this page you can find the example usage for android.content.res TypedArray getString.

Prototype

@Nullable
public String getString(@StyleableRes int index) 

Source Link

Document

Retrieves the string value for the attribute at index.

Usage

From source file:com.github.andrewlord1990.materialandroid.component.grid.GridItemView.java

private void loadText(TypedArray typedAttrs) {
    String primaryText = typedAttrs.getString(R.styleable.MDGridItemView_md_grid_text_primary);
    setPrimaryText(primaryText);/*  w  w  w . j  a  v  a  2s.  c  o m*/

    String secondaryText = typedAttrs.getString(R.styleable.MDGridItemView_md_grid_text_secondary);
    setSecondaryText(secondaryText);
}

From source file:ca.hoogit.garagepi.Controls.DoorView.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.door_view, this);
    ButterKnife.bind(this);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DoorView, defStyle, 0);
    mOpenedColor = a.getColor(R.styleable.DoorView_openedColor,
            ContextCompat.getColor(context, R.color.colorAccent));
    mClosedColor = a.getColor(R.styleable.DoorView_closedColor,
            ContextCompat.getColor(context, R.color.colorPrimary));
    mDoorName = a.getString(R.styleable.DoorView_doorName);
    a.recycle();/*from  w w  w .  j a  v  a 2 s.  c  om*/

    mContext = context;

    mToggleContainer.setOnClickListener(OnSingleClickListener.wrap(v -> {
        if (mOnToggle != null) {
            mOnToggle.onToggle(mDoorName);
        }
    }));

    mToggleContainer.setOnTouchListener((v, event) -> {
        int origColor = mDoorValue ? mOpenedColor : mClosedColor;
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mToggleContainer.setBackgroundColor(ColorUtil.darken(origColor));
        } else if (event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_CANCEL) {
            mToggleContainer.setBackgroundColor(origColor);
        }
        return false;
    });

    setupViews();
}

From source file:com.hippo.preference.DialogPreference.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr,
            defStyleRes);//from   w w  w . ja v  a  2s . c  o m
    mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle);
    if (mDialogTitle == null) {
        // Fallback on the regular title of the preference
        // (the one that is seen in the list)
        mDialogTitle = getTitle();
    }
    mDialogIcon = a.getDrawable(R.styleable.DialogPreference_dialogIcon);
    mPositiveButtonText = a.getString(R.styleable.DialogPreference_positiveButtonText);
    mNegativeButtonText = a.getString(R.styleable.DialogPreference_negativeButtonText);
    mDialogLayoutResId = a.getResourceId(R.styleable.DialogPreference_dialogLayout, mDialogLayoutResId);
    a.recycle();
}

From source file:de.grobox.transportr.locations.LocationView.java

public LocationView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LocationView, 0, 0);
    boolean showIcon = a.getBoolean(R.styleable.LocationView_showIcon, true);
    hint = a.getString(R.styleable.LocationView_hint);
    a.recycle();//from ww w.j  ava  2 s  .c  om

    setOrientation(LinearLayout.HORIZONTAL);

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.location_view, this, true);
    ui = new LocationViewHolder(this);

    ui.location.setHint(hint);
    if (!isInEditMode()) {
        adapter = new LocationAdapter(getContext());
        ui.location.setAdapter(adapter);
    }
    ui.location.setOnItemClickListener((parent, view, position, rowId) -> {
        WrapLocation loc = getAdapter().getItem(position);
        if (loc != null)
            onLocationItemClick(loc);
    });
    ui.location.setOnFocusChangeListener(LocationView.this::onFocusChange);
    ui.location.setOnClickListener(view -> LocationView.this.onClick());

    if (showIcon) {
        ui.status.setOnClickListener(v -> {
            getAdapter().resetDropDownLocations();
            LocationView.this.post(this::onClick);
        });
    } else {
        ui.status.setVisibility(GONE);
    }

    // clear text button
    ui.clear.setOnClickListener(v -> clearLocationAndShowDropDown());

    // From text input changed
    ui.location.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if ((count == 1 && before == 0) || (count == 0 && before == 1))
                handleTextChanged(s);
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
}

From source file:com.frostwire.android.gui.views.KeywordTagView.java

private KeywordTagView(Context context, AttributeSet attrs, KeywordFilter keywordFilter) {
    super(context, attrs);

    if (keywordFilter == null) {
        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.KeywordTagView, 0, 0);
        count = attributes.getInteger(R.styleable.KeywordTagView_keyword_tag_count, 0);
        dismissible = attributes.getBoolean(R.styleable.KeywordTagView_keyword_tag_dismissable, true);
        boolean inclusive = attributes.getBoolean(R.styleable.KeywordTagView_keyword_tag_inclusive, true);
        String keyword = attributes.getString(R.styleable.KeywordTagView_keyword_tag_keyword);
        keywordFilter = new KeywordFilter(inclusive, keyword != null ? keyword : "[Text]",
                KeywordDetector.Feature.MANUAL_ENTRY);
        attributes.recycle();/*w  w  w  . j  a v a 2 s . c om*/
    }

    this.keywordFilter = keywordFilter;

    keywordSpan = new TextAppearanceSpan(getContext(), R.style.keywordTagText);
    countSpan = new TextAppearanceSpan(getContext(), R.style.keywordTagCount);

    layoutParams = new FlexboxLayout.LayoutParams(FlexboxLayout.LayoutParams.WRAP_CONTENT, toPx(34));
    layoutParams.setMargins(0, 0, toPx(6), toPx(8));

    setPadding(toPx(12), toPx(4), toPx(12), toPx(4));
    setMinHeight(toPx(34));
    setGravity(Gravity.CENTER_VERTICAL);
    setCompoundDrawablePadding(toPx(6));
}

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

void init(Context context, AttributeSet attributeSet) {
    TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.GFFloatingActionButton, 0, 0);
    mColorNormal = attr.getColor(R.styleable.GFFloatingActionButton_fabColorNormal, Color.BLACK);
    mColorPressed = attr.getColor(R.styleable.GFFloatingActionButton_fabColorPressed, Color.BLACK);
    mIcon = attr.getResourceId(R.styleable.GFFloatingActionButton_fabIcon, 0);
    mTitle = attr.getString(R.styleable.GFFloatingActionButton_fabTitle);
    attr.recycle();/*from w  ww .  j  a  v  a  2  s.c  o m*/

    updateCircleSize();
    mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
    mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
    updateDrawableSize();

    updateBackground();
}

From source file:com.ahao.preferencelibrary.preference.DialogPreference.java

@Override
protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    super.init(context, attrs, defStyleAttr, defStyleRes);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr,
            defStyleRes);/*  ww  w .  jav  a2 s.c o  m*/
    mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle);
    if (mDialogTitle == null) {
        // Fallback on the regular title of the preference
        // (the one that is seen in the list)
        mDialogTitle = getTitle();
    }

    mDialogMessage = a.getString(R.styleable.DialogPreference_dialogMessage);
    mDialogIcon = a.getDrawable(R.styleable.DialogPreference_dialogIcon);
    mPositiveButtonText = a.getString(R.styleable.DialogPreference_positiveButtonText);
    mNegativeButtonText = a.getString(R.styleable.DialogPreference_negativeButtonText);
    mDialogLayoutResId = a.getResourceId(R.styleable.DialogPreference_dialogLayout, mDialogLayoutResId);
    a.recycle();
}

From source file:uk.co.brightec.ratetheapp.RateTheApp.java

private void loadAttributes(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RateTheApp, defStyleAttr,
            defStyleRes);//from   w ww .  j a v  a 2 s  . c om

    // Instance name for this rating bar
    mInstanceName = PREF_RATETHEAPP_PREFIX;
    String instanceName = a.getString(R.styleable.RateTheApp_rateTheAppName);
    if (instanceName != null) {
        mInstanceName += "_" + instanceName;
    }

    // Title Text Appearance
    mTitleTextAppearanceResId = a.getResourceId(R.styleable.RateTheApp_rateTheAppTitleTextAppearance,
            R.style.RateTheAppTitleTextAppearance);
    mTitleStr = a.getString(R.styleable.RateTheApp_rateTheAppTitleText);

    // Message Text Appearance
    mMessageTextAppearanceResId = a.getResourceId(R.styleable.RateTheApp_rateTheAppMessageTextAppearance,
            R.style.RateTheAppMessageTextAppearance);
    mMessageStr = a.getString(R.styleable.RateTheApp_rateTheAppMessageText);

    // Stars & Rating
    mNumberOfStars = a.getInt(R.styleable.RateTheApp_rateTheAppNumberOfStars, DEFAULT_NUMBER_OF_STARS);
    mStepSize = a.getFloat(R.styleable.RateTheApp_rateTheAppStepSize, DEFAULT_STEP_SIZE);
    mDefaultRating = a.getFloat(R.styleable.RateTheApp_rateTheAppDefaultRating, DEFAULT_RATING);
    mSelectedStarColour = a.getColor(R.styleable.RateTheApp_rateTheAppSelectedStarColor,
            ContextCompat.getColor(getContext(), R.color.RateTheApp_SelectedStarColor));
    mUnselectedStarColour = a.getColor(R.styleable.RateTheApp_rateTheAppUnselectedStarColor,
            ContextCompat.getColor(getContext(), R.color.RateTheApp_UnselectedStarColor));
    mDrawableResUnSelected = a.getResourceId(R.styleable.RateTheApp_rateTheAppStarUnSelectedDrawable,
            R.drawable.ic_rating_star_border_grey_36dp);
    mDrawableResSelected = a.getResourceId(R.styleable.RateTheApp_rateTheAppStarSelectedDrawable,
            R.drawable.ic_rating_star_green_36dp);

    mSaveRating = a.getBoolean(R.styleable.RateTheApp_rateTheAppSaveRating, true);

    a.recycle();
}

From source file:alexander.martinz.libs.materialpreferences.MaterialPreference.java

protected TypedArray parseAttrs(Context context, AttributeSet attrs) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialPreference);

    if (a == null) {
        Log.e(this.getClass().getSimpleName(), "Could not obtain typed array!");
        return null;
    }//w ww  .j  a v  a  2 s.c om

    mPrefKey = a.getString(R.styleable.MaterialPreference_prefKey);
    mPrefAsCard = a.getBoolean(R.styleable.MaterialPreference_prefAsCard, false);
    mResIdIcon = a.getResourceId(R.styleable.MaterialPreference_prefIcon, -1);
    mIconTintColor = a.getColor(R.styleable.MaterialPreference_prefIconTint, Integer.MIN_VALUE);
    mResIdTitle = a.getResourceId(R.styleable.MaterialPreference_prefTitle, -1);
    mResIdSummary = a.getResourceId(R.styleable.MaterialPreference_prefSummary, -1);

    mCardBackgroundColor = a.getColor(R.styleable.MaterialPreference_prefCardBackgroundColor,
            Integer.MIN_VALUE);

    return a;
}

From source file:util.android.viewpagerindicator.FontableTabPageIndicator.java

private void init(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FontableTabPageIndicator);
    final int n = a.getIndexCount();
    for (int i = 0; i < n; ++i) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.FontableTabPageIndicator_fontFamilyNormal) {
            normalText = setATypeface(a.getString(attr));
        } else if (attr == R.styleable.FontableTabPageIndicator_fontFamilySelected) {
            selectedText = setATypeface(a.getString(attr));
        }/*from   ww  w .j  a va2  s  . c o m*/

    }
    a.recycle();
}