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.wanderingcan.floatingactionmenu.FloatingActionButton.java

private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0);
    mLabelText = attr.getString(R.styleable.FloatingActionButton_label);

    mShowAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.fab_in);
    mShowAnimation.setInterpolator(new FastOutSlowInInterpolator());
    mShowAnimation.setDuration(FloatingActionMenu.ANIMATION_DURATION);

    mHideAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.fab_out);
    mHideAnimation.setInterpolator(new FastOutSlowInInterpolator());
    mHideAnimation.setDuration(FloatingActionMenu.ANIMATION_DURATION);

    attr.recycle();//from  w  w  w.  ja va  2s  .  c om
}

From source file:ru.tlrs.vincent.VincentView.java

public VincentView(Context context, AttributeSet attrs, int src) {
    super(context, attrs, src);
    mContext = context;//from   www .  ja va 2s.  c om
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.VincentView, 0, 0);
    TypedArray b = context.getTheme().obtainStyledAttributes(attrs, new int[] { src }, 0, 0);
    try {
        mImgUri = a.getString(R.styleable.VincentView_imageUri);
        mOverlayMode = a.getBoolean(R.styleable.VincentView_overlayMode, false);
        mPinch2Zoom = !mOverlayMode && a.getBoolean(R.styleable.VincentView_pinch2zoomEnable, true);
        mGroupId = a.getInt(R.styleable.VincentView_groupId, 0);
        mSrc = b.getString(0);
    } finally {
        a.recycle();
        b.recycle();
    }
    setOnClickListener(this);
}

From source file:pt.hugofernandes.ExtendedRecyclerView.java

protected void initAttrs(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.awesomerecyclerview);
    try {/*from   w  ww.  java  2  s  . c om*/
        emptyMessage = a.getString(R.styleable.awesomerecyclerview_empty_message);
        if (TextUtils.isEmpty(emptyMessage)) {
            emptyMessage = getContext().getString(R.string.empty_data);
        }
    } finally {
        a.recycle();
    }
}

From source file:com.todev.rabbitmqmanagement.ui.overview.widget.MessagesIndicator.java

protected void initializeAttributes(Context context, AttributeSet attrs) {
    TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MessagesIndicator, 0, 0);

    try {//from w w  w.ja v  a  2 s.co m
        title = array.getString(R.styleable.MessagesIndicator_title);

        defaultColor = ContextCompat.getColor(context, android.R.color.black);

        valuesVisible = array.getBoolean(R.styleable.MessagesIndicator_values_visible,
                getResources().getBoolean(R.bool.queued_messages_indicator_default_values_visible));

        idleText = array.getString(R.styleable.MessagesIndicator_idle_text);

        int range = array.getInteger(R.styleable.MessagesIndicator_visible_range, 0);

        visibleRange = VisibleRange.fromRange(range);
    } finally {
        array.recycle();
    }
}

From source file:com.vinexs.eeb.receiver.BaseReceiverGCM.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public void onMessageTypeReceive(Context context, Intent intent) {
    notifyMgr = NotificationManagerCompat.from(context);
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(context);
    int notifyId = setting.getInt("notifyId", new Random().nextInt(65535));
    Bundle receIntent = intent.getExtras();
    try {//from  www .  j  a  v a  2 s  .c om
        if (!receIntent.containsKey("contentTitle") || !receIntent.containsKey("contentText")) {
            throw new Exception("Message don't contain necessary data.");
        }

        if (builder == null) {
            builder = new NotificationCompat.Builder(context);
            contentTitle = receIntent.getCharSequence("contentTitle");
            contentText = receIntent.getCharSequence("contentText");

            builder.setDefaults(Notification.DEFAULT_ALL).setContentTitle(contentTitle)
                    .setContentText(contentText).setSmallIcon(getMonoColorIcon())
                    .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true);
            try {
                if (Build.VERSION.SDK_INT < 14 || !receIntent.containsKey("largeIcon")) {
                    throw new Exception("Message don't contain [largeIcon] or device SDK lower than 14.");
                }
                String bigIconUrl = receIntent.getString("largeIcon");
                if (bigIconUrl == null || bigIconUrl.isEmpty()) {
                    throw new Exception("Message [largeIcon] is empty.");
                }
                HttpURLConnection connection = (HttpURLConnection) new URL(bigIconUrl).openConnection();
                connection.setDoInput(true);
                connection.connect();
                Bitmap bigIcon = BitmapFactory.decodeStream(connection.getInputStream());
                builder.setLargeIcon(bigIcon);
                // Add backgroud to wearable
                NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
                wearableExtender.setBackground(bigIcon);
                builder.extend(wearableExtender);
                // Set accent color
                int[] attrs = new int[] { R.attr.colorAccent };
                TypedArray ta = context.obtainStyledAttributes(attrs);
                String colorAccent = ta.getString(0);
                ta.recycle();
                builder.setColor(Color.parseColor(colorAccent));
            } catch (Exception e) {
                builder.setLargeIcon(
                        BitmapFactory.decodeResource(context.getResources(), getApplicationIcon()));
            }
            try {
                if (!receIntent.containsKey("ticker")) {
                    throw new Exception("Message don't contain [ticker].");
                }
                builder.setTicker(receIntent.getCharSequence("ticker"));
            } catch (Exception e) {
                builder.setTicker(receIntent.getCharSequence("contentText"));
            }
            if (Build.VERSION.SDK_INT >= 16) {
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
            }
        } else {
            contentText = contentText + "\n" + receIntent.getCharSequence("contentText");
            messageNum++;
            builder.setContentTitle(Utility.getAppName(context)).setContentText(contentText)
                    .setTicker(receIntent.getCharSequence("contentText")).setNumber(messageNum);
        }

        if (Build.VERSION.SDK_INT >= 16) {
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
        }

        Intent actionIntent = new Intent(context, getLauncherClass());
        if (receIntent.containsKey("intentAction")) {
            actionIntent.putExtra("onNewIntentAction", receIntent.getCharSequence("intentAction"));
        }
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, actionIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(contentIntent);

        notifyMgr.notify(notifyId, builder.build());
    } catch (Exception e) {
        Log.d("GoogleCloudMessaging",
                "Exception occurred while show message as notification -> " + e.toString());
        e.printStackTrace();
    }
}

From source file:com.astir_trotter.atcustom.ui.iconics.core.view.IconicsImageView.java

public IconicsImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (!isInEditMode()) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconicsImageView, defStyle, 0);
        String icon = a.getString(R.styleable.IconicsImageView_iiv_icon);

        //set the color even if we had no image yet
        mColor = a.getColor(R.styleable.IconicsImageView_iiv_color, 0);
        mSize = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_size, -1);
        mPadding = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_padding, -1);
        mContourColor = a.getColor(R.styleable.IconicsImageView_iiv_contour_color, 0);
        mContourWidth = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_contour_width, -1);
        mBackgroundColor = a.getColor(R.styleable.IconicsImageView_iiv_background_color, 0);
        mCornerRadius = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_corner_radius, -1);

        //recycle the typedArray
        a.recycle();/*from   w  w w  .  j av  a  2s .  c  o m*/

        //set the scale type for this view
        setScaleType(ScaleType.CENTER_INSIDE);

        //if we have no icon return now
        if (icon == null) {
            return;
        }

        //get the drawable
        mIcon = new IconicsDrawable(context, icon);

        //set attributes
        setAttributes();

        //set our values for this view
        setImageDrawable(mIcon);
    }
}

From source file:android.support.v7.app.AppCompatViewInflater.java

/**
 * android:onClick doesn't handle views with a ContextWrapper context. This method
 * backports new framework functionality to traverse the Context wrappers to find a
 * suitable target.//from   w  w w . j  a va2 s  .  c o m
 */
private void checkOnClickListener(View view, AttributeSet attrs) {
    final Context context = view.getContext();

    if (!(context instanceof ContextWrapper)
            || (Build.VERSION.SDK_INT >= 15 && !ViewCompat.hasOnClickListeners(view))) {
        // Skip our compat functionality if: the Context isn't a ContextWrapper, or
        // the view doesn't have an OnClickListener (we can only rely on this on API 15+ so
        // always use our compat code on older devices)
        return;
    }

    final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs);
    final String handlerName = a.getString(0);
    if (handlerName != null) {
        view.setOnClickListener(new DeclaredOnClickListener(view, handlerName));
    }
    a.recycle();
}

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

@Override
protected TypedArray parseAttrs(Context context, AttributeSet attrs) {
    final TypedArray a = super.parseAttrs(context, attrs);

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

    mDefaultValue = a.getString(R.styleable.MaterialPreference_prefDefaultValue);
    mValue = mDefaultValue;
    mPrefTextColor = a.getResourceId(R.styleable.MaterialPreference_prefTextColor, -1);
    mPrefTextSize = a.getInt(R.styleable.MaterialPreference_prefTextSize, -1);
    mPrefTextMaxLength = a.getInt(R.styleable.MaterialPreference_prefTextMaxLength, 25);

    return a;
}

From source file:com.markupartist.android.widget.ActionBar.java

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

    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mBarView = (RelativeLayout) mInflater.inflate(R.layout.actionbar, null);
    addView(mBarView);/*www .j a  v  a  2  s .c om*/

    mLogoView = (ImageView) mBarView.findViewById(R.id.actionbar_home_logo);
    mHomeLayout = (RelativeLayout) mBarView.findViewById(R.id.actionbar_home_bg);
    mHomeBtn = (ImageButton) mBarView.findViewById(R.id.actionbar_home_btn);
    mBackIndicator = mBarView.findViewById(R.id.actionbar_home_is_back);

    mTitleView = (TextView) mBarView.findViewById(R.id.actionbar_title);
    mActionsView = (LinearLayout) mBarView.findViewById(R.id.actionbar_actions);

    mProgress = (ProgressBar) mBarView.findViewById(R.id.actionbar_progress);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar);
    CharSequence title = a.getString(R.styleable.ActionBar_title);
    if (title != null) {
        setTitle(title);
    }
    a.recycle();
}

From source file:com.waz.zclient.ui.calling.CallControlButtonView.java

private void init(AttributeSet attrs) {
    setOrientation(VERTICAL);/*  www .j  a  v  a  2s.com*/
    setGravity(Gravity.CENTER);
    setBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));

    int circleIconDimension = 0;
    String circleIconGlyph = "";
    int circleIconStyle = 0;
    String labelText = "";
    int buttonLabelWidth = 0;
    int labelTextSize = 0;
    String labelFont = "";

    if (attrs != null) {
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.CallControlButtonView,
                0, 0);
        circleIconDimension = a.getDimensionPixelSize(R.styleable.CallControlButtonView_circleIconDimension, 0);
        circleIconGlyph = a.getString(R.styleable.CallControlButtonView_circleIconGlyph);
        circleIconStyle = attrs.getStyleAttribute();
        labelText = a.getString(R.styleable.CallControlButtonView_labelText);
        buttonLabelWidth = a.getDimensionPixelSize(R.styleable.CallControlButtonView_labelWidth, 0);
        labelTextSize = a.getDimensionPixelSize(R.styleable.CallControlButtonView_labelTextSize, 0);
        labelFont = a.getString(R.styleable.CallControlButtonView_labelFont);
        a.recycle();
    }

    buttonView = new GlyphTextView(getContext(), null, circleIconStyle);
    buttonView.setLayoutParams(new LayoutParams(circleIconDimension, circleIconDimension));
    buttonView.setText(circleIconGlyph);
    buttonView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimensionPixelSize(R.dimen.wire__icon_button__text_size));
    buttonView.setGravity(Gravity.CENTER);
    if (circleIconStyle == 0) {
        buttonView.setTextColor(new OptionsDarkTheme(getContext()).getTextColorPrimarySelector());
        buttonView.setBackground(
                ContextCompat.getDrawable(getContext(), R.drawable.selector__icon_button__background__calling));
    }
    addView(buttonView);

    buttonLabelView = new TypefaceTextView(getContext(), null, R.attr.callingControlButtonLabel);
    buttonLabelView.setText(labelText);
    buttonLabelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, labelTextSize);
    buttonLabelView.setTypeface(labelFont);
    buttonLabelView.setGravity(Gravity.CENTER);
    if (buttonLabelWidth > 0) {
        addView(buttonLabelView,
                new LinearLayout.LayoutParams(buttonLabelWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
    } else {
        addView(buttonLabelView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    ViewUtils.setMarginTop(buttonLabelView, getContext().getResources()
            .getDimensionPixelSize(R.dimen.calling__controls__button__label__margin_top));
}