Example usage for android.content.res TypedArray getResourceId

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

Introduction

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

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:com.github.ppamorim.SlapBar.java

private void mapGUI(TypedArray attributes) {
    if (getChildCount() > 1) {
        throw new IllegalStateException("FlapBar must contains only one direct child");
    }/*ww w .  ja  va  2 s .  c o  m*/
    if (attributes != null && dragView == null) {
        int dragViewId = attributes.getResourceId(R.styleable.dragger_layout_drag_view_id, 0);
        dragView = findViewById(dragViewId);
    }
}

From source file:com.facebook.FacebookButtonBase.java

private void parseBackgroundAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    // TODO, figure out why com_facebook_button_like_background.xml doesn't work in designers
    if (isInEditMode()) {
        return;/*from   w  ww .  j av a  2s . co m*/
    }

    final int attrsResources[] = { android.R.attr.background, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        if (a.hasValue(0)) {
            int backgroundResource = a.getResourceId(0, 0);
            if (backgroundResource != 0) {
                setBackgroundResource(backgroundResource);
            } else {
                setBackgroundColor(a.getColor(0, 0));
            }
        } else {
            // fallback, if no background specified, fill with Facebook blue
            setBackgroundColor(a.getColor(0, R.color.com_facebook_blue));
        }
    } finally {
        a.recycle();
    }
}

From source file:com.artemchep.horario.ui.fragments.AuthFragment.java

/**
 * Shows dialog that provides email input and then calls
 * {@link #sendPasswordResetEmail(String)} to reset password
 * of the user.//  w  w w .  j av  a 2  s  . co m
 */
private void showRestorePasswordDialog() {
    // Load icon
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.icon_lock_reset });
    int iconDrawableRes = a.getResourceId(0, 0);
    a.recycle();

    MaterialDialog.SingleButtonCallback positiveCallback = new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            View view = dialog.getCustomView();
            assert view != null;
            EmailInputLayout emailLayout = view.findViewById(R.id.input_layout_email);

            if (emailLayout.validateEmail()) {
                sendPasswordResetEmail(emailLayout.getEmailText());
                dialog.dismiss();
            } else
                emailLayout.showErrorLabel();
        }
    };
    MaterialDialog.SingleButtonCallback negativeCallback = new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            dialog.dismiss();
        }
    };
    new MaterialDialog.Builder(getContext()).customView(R.layout.dialog_auth_reset_password, true)
            .title(R.string.auth_reset_password).positiveText(R.string.auth_reset_password)
            .negativeText(android.R.string.cancel).iconRes(iconDrawableRes).autoDismiss(false)
            .onPositive(positiveCallback).onNegative(negativeCallback).show();
}

From source file:com.amazon.android.ui.widget.EllipsizedTextView.java

/**
 * Initializes the view's attributes./*w ww  .  j a  v a 2 s  .com*/
 *
 * @param attrs The attribute set.
 */
private void init(final AttributeSet attrs) {
    // Load the layout parameters from attrs.
    final TypedArray styledAttributes = getContext().obtainStyledAttributes(attrs,
            R.styleable.EllipsizedTextView);

    mGuillemetDrawableId = styledAttributes.getResourceId(R.styleable.EllipsizedTextView_guillemetDrawable,
            R.drawable.guillemet);

    mReadDialogWidth = (int) styledAttributes.getDimension(R.styleable.EllipsizedTextView_readDialogWidth, 0);

    mReadDialogHeight = (int) styledAttributes.getDimension(R.styleable.EllipsizedTextView_readDialogHeight, 0);

    styledAttributes.recycle();
}

From source file:com.jikexueyuan.jikecalculator.Calculator.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);

    // Disable IME for this application
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    setContentView(R.layout.main);//from  ww  w .java 2  s.c  o  m
    mPager = (ViewPager) findViewById(R.id.panelswitch);
    if (mPager != null) {
        mPager.setAdapter(new PageAdapter(mPager));
    } else {
        // Single page UI
        final TypedArray buttons = getResources().obtainTypedArray(R.array.buttons);
        for (int i = 0; i < buttons.length(); i++) {
            setOnClickListener(null, buttons.getResourceId(i, 0));
        }
        buttons.recycle();
    }

    if (mClearButton == null) {
        mClearButton = findViewById(R.id.clear);
        mClearButton.setOnClickListener(mListener);
        mClearButton.setOnLongClickListener(mListener);
    }
    if (mBackspaceButton == null) {
        mBackspaceButton = findViewById(R.id.del);
        mBackspaceButton.setOnClickListener(mListener);
        mBackspaceButton.setOnLongClickListener(mListener);
    }

    mPersist = new Persist(this);
    mPersist.load();

    mHistory = mPersist.history;

    mDisplay = (CalculatorDisplay) findViewById(R.id.display);

    mLogic = new Logic(this, mHistory, mDisplay);
    mLogic.setListener(this);

    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());

    HistoryAdapter historyAdapter = new HistoryAdapter(this, mHistory, mLogic);
    mHistory.setObserver(historyAdapter);

    if (mPager != null) {
        mPager.setCurrentItem(state == null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0));
    }

    mListener.setHandler(mLogic, mPager);
    mDisplay.setOnKeyListener(mListener);

    mLogic.resumeWithHistory();
    updateDeleteMode();
    SoundManager.getInstance().initSounds(this);
}

From source file:com.daiv.android.twitter.settings.SettingsActivityOld.java

public void setUpTheme() {

    AppSettings settings = AppSettings.getInstance(this);

    switch (settings.theme) {
    case AppSettings.THEME_LIGHT:
        setTheme(R.style.Theme_TestLight);
        break;//  w  w  w . j ava  2 s.  co m
    case AppSettings.THEME_DARK:
        setTheme(R.style.Theme_TestLight);
        break;
    case AppSettings.THEME_BLACK:
        setTheme(R.style.Theme_TestLight);
        break;
    }

    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.windowBackground });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    getWindow().getDecorView().setBackgroundResource(resource);
}

From source file:com.facebook.FacebookButtonBase.java

private void parseBackgroundAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    // TODO, figure out why com_facebook_button_like_background.xml doesn't work in designers
    if (isInEditMode()) {
        return;//from  www .j a  va 2s.com
    }

    final int attrsResources[] = { android.R.attr.background, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        if (a.hasValue(0)) {
            int backgroundResource = a.getResourceId(0, 0);
            if (backgroundResource != 0) {
                setBackgroundResource(backgroundResource);
            } else {
                setBackgroundColor(a.getColor(0, 0));
            }
        } else {
            // fallback, if no background specified, fill with Facebook blue
            setBackgroundColor(ContextCompat.getColor(context, R.color.com_facebook_blue));
        }
    } finally {
        a.recycle();
    }
}

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();/*w w  w  . j  a v a  2 s  . c om*/

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

    updateBackground();
}

From source file:com.aman.stockcalculator.Calculator.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);

    // Disable IME for this application
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    setContentView(R.layout.main);/*  w w w.j a va 2s. co m*/
    mPager = (ViewPager) findViewById(R.id.panelswitch);
    if (mPager != null) {
        mPager.setAdapter(new PageAdapter(mPager));
    } else {
        // Single page UI
        final TypedArray buttons = getResources().obtainTypedArray(R.array.buttons);
        for (int i = 0; i < buttons.length(); i++) {
            setOnClickListener(null, buttons.getResourceId(i, 0));
        }
        buttons.recycle();
    }

    if (mClearButton == null) {
        mClearButton = findViewById(R.id.clear);
        mClearButton.setOnClickListener(mListener);
        mClearButton.setOnLongClickListener(mListener);
    }
    if (mBackspaceButton == null) {
        mBackspaceButton = findViewById(R.id.del);
        mBackspaceButton.setOnClickListener(mListener);
        mBackspaceButton.setOnLongClickListener(mListener);
    }

    mPersist = new Persist(this);
    mPersist.load();

    mHistory = mPersist.history;

    mDisplay = (CalculatorDisplay) findViewById(R.id.display);

    mLogic = new Logic(this, mHistory, mDisplay);
    mLogic.setListener(this);

    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());

    HistoryAdapter historyAdapter = new HistoryAdapter(this, mHistory, mLogic);
    mHistory.setObserver(historyAdapter);

    if (mPager != null) {
        mPager.setCurrentItem(state == null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0));
    }

    mListener.setHandler(mLogic, mPager);
    mDisplay.setOnKeyListener(mListener);

    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        createFakeMenu();
    }

    mLogic.resumeWithHistory();
    updateDeleteMode();
}

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  va  2s .c o  m

    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;
}