Example usage for android.content.res TypedArray getBoolean

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

Introduction

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

Prototype

public boolean getBoolean(@StyleableRes int index, boolean defValue) 

Source Link

Document

Retrieve the boolean value for the attribute at index.

Usage

From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java

public StaggeredGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StaggeredGridView);
        mColCount = a.getInteger(R.styleable.StaggeredGridView_numColumnsStag, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StaggeredGridView_drawSelectorOnTopStag, false);
    } else {/*from  w  ww  . j av  a  2  s  .c  om*/
        mColCount = 2;
        mDrawSelectorOnTop = false;
    }

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);
    setClipToPadding(false);
    this.setFocusableInTouchMode(false);

    if (mSelector == null) {
        useDefaultSelector();
    }
}

From source file:android.support.v7.widget.GridLayout.java

/**
 * {@inheritDoc}/*from   www. ja v a  2  s . c  o m*/
 */
public GridLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mDefaultGap = context.getResources().getDimensionPixelOffset(R.dimen.default_gap);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridLayout);
    try {
        setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT));
        setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT));
        setOrientation(a.getInt(ORIENTATION, DEFAULT_ORIENTATION));
        setUseDefaultMargins(a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS));
        setAlignmentMode(a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE));
        setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
        setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
    } finally {
        a.recycle();
    }
}

From source file:com.android.backups.StaggeredGridViewByJaumo.java

public StaggeredGridViewByJaumo(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StaggeredGridView);
        mColCount = a.getInteger(R.styleable.StaggeredGridView_numColumns, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StaggeredGridView_drawSelectorOnTop, false);
    } else {//from   w w  w.  ja v a 2s.  c o m
        mColCount = 2;
        mDrawSelectorOnTop = false;
    }

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);
    setClipToPadding(false);
    this.setFocusableInTouchMode(false);

    if (mSelector == null) {
        useDefaultSelector();
    }
}

From source file:com.android.backups.BackupStaggeredGridView.java

public BackupStaggeredGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StaggeredGridView);
        mColCount = a.getInteger(R.styleable.StaggeredGridView_numColumns, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StaggeredGridView_drawSelectorOnTop, false);

    } else {/*from   w ww .  j ava 2 s  .co m*/
        mColCount = 2;
        mDrawSelectorOnTop = false;
    }

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);
    setClipToPadding(false);
    this.setFocusableInTouchMode(false);

    if (mSelector == null) {
        useDefaultSelector();
    }
}

From source file:com.dishes.views.stageredggridview.StaggeredGridView.java

public StaggeredGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StaggeredGridView);
        mColCount = a.getInteger(R.styleable.StaggeredGridView_numColumns, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StaggeredGridView_drawSelectorOnTop, false);
        a.recycle();/* ww w.jav a 2  s  .  c  o m*/
    } else {
        mColCount = 2;
        mDrawSelectorOnTop = false;
    }

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);
    setClipToPadding(false);
    this.setFocusableInTouchMode(false);

    if (mSelector == null) {
        useDefaultSelector();
    }
}

From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

private void init(Context context, AttributeSet attrs) {
    Resources resources = getResources();
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
    int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit);

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding,
            defaultPadding);// w w w  .  j  a  v a 2  s  .  c o  m
    setClickable(true);

    backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector,
            R.drawable.selector);
    setBackgroundResource(backgroundSelector);
    textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context));
    setTextColor(textColor);

    listView = new ListView(context);
    // Set the spinner's id into the listview to make it pretend to be the right parent in
    // onItemClick
    listView.setId(getId());
    listView.setDivider(new ColorDrawable(Color.GRAY));
    listView.setDividerHeight(1);
    listView.setItemsCanFocus(true);
    //hide vertical and horizontal scrollbars
    listView.setVerticalScrollBarEnabled(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setOverScrollMode(OVER_SCROLL_NEVER);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectedIndex = position;

            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(parent, view, position, id);
            }

            if (onItemSelectedListener != null) {
                onItemSelectedListener.onItemSelected(parent, view, position, id);
            }

            adapter.setSelectedIndex(position);
            setTextInternal(adapter.getItemInDataset(position).toString());
            dismissDropDown();
        }
    });

    popupWindow = new PopupWindow(context);
    popupWindow.setContentView(listView);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindow.setElevation(DEFAULT_ELEVATION);
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable));
    } else {
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow));
    }

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (!isArrowHidden) {
                animateArrow(false);
            }
        }
    });

    isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false);
    arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE);
    arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow);
    dropDownListPaddingBottom = typedArray
            .getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0);
    typedArray.recycle();

    measureDisplayHeight();
}

From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView3.java

public StaggeredGridView3(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StgStaggeredGridView);
        mColCount = a.getInteger(R.styleable.StgStaggeredGridView_stgNumColumns, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StgStaggeredGridView_stgDrawSelectorOnTop, false);
    } else {//ww w .j  ava 2  s .c o  m
        mColCount = 2;
        mDrawSelectorOnTop = false;
    }

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    //mScroller=ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);
    setClipToPadding(false);
    this.setFocusableInTouchMode(false);

    if (mSelector == null) {
        useDefaultSelector();
    }

    mMinimumVelocity = vc.getScaledMinimumFlingVelocity();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>//  w w  w .j a  v  a2  s  .  c o  m
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this view specific data from it that can be used to configure this new view instance. The
 * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data
 * from the current theme provided by the specified <var>context</var>.
 */
@SuppressWarnings("ConstantConditions")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    this.ensureRect();
    this.ensureDecorator();
    mDecorator.processAttributes(context, attrs, defStyleAttr, defStyleRes);
    this.mAnimations = Animations.get(this);

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SeekBar, defStyleAttr,
            defStyleRes);
    if (typedArray != null) {
        final Rect indicatorTextPadding = new Rect();
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_SeekBar_android_enabled) {
                setEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscrete) {
                setDiscrete(typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscretePreviewEnabled) {
                setDiscretePreviewEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalRatio) {
                setDiscreteIntervalRatio(typedArray.getFloat(index, mDiscreteIntervalRatio));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicator) {
                setDiscreteIndicator(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextAppearance) {
                setDiscreteIndicatorTextAppearance(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextGravity) {
                setDiscreteIndicatorTextGravity(
                        typedArray.getInteger(index, DISCRETE_INDICATOR_TEXT_INFO.gravity));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingStart) {
                indicatorTextPadding.left = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingTop) {
                indicatorTextPadding.top = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingEnd) {
                indicatorTextPadding.right = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingBottom) {
                indicatorTextPadding.bottom = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkColor) {
                setDiscreteIntervalTickMarkColor(typedArray.getColorStateList(index));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkRadius) {
                setDiscreteIntervalTickMarkRadius(typedArray.getDimensionPixelSize(index, 0));
            }
        }
        setDiscreteIndicatorTextPadding(indicatorTextPadding.left, indicatorTextPadding.top,
                indicatorTextPadding.right, indicatorTextPadding.bottom);
        typedArray.recycle();
    }
    this.applyProgressTints();
    this.applyThumbTint();
}

From source file:android.app.FragmentState.java

/**
 * Called when a fragment is being created as part of a view layout
 * inflation, typically from setting the content view of an activity.  This
 * may be called immediately after the fragment is created from a <fragment>
 * tag in a layout file.  Note this is <em>before</em> the fragment's
 * {@link #onAttach(Activity)} has been called; all you should do here is
 * parse the attributes and save them away.
 *
 * <p>This is called every time the fragment is inflated, even if it is
 * being inflated into a new instance with saved state.  It typically makes
 * sense to re-parse the parameters each time, to allow them to change with
 * different configurations.</p>//from   w w  w .  j av a2s .  c om
 *
 * <p>Here is a typical implementation of a fragment that can take parameters
 * both through attributes supplied here as well from {@link #getArguments()}:</p>
 *
 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
 *      fragment}
 *
 * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
 * declaration for the styleable used here is:</p>
 *
 * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
 * 
 * <p>The fragment can then be declared within its activity's content layout
 * through a tag like this:</p>
 *
 * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
 *
 * <p>This fragment can also be created dynamically from arguments given
 * at runtime in the arguments Bundle; here is an example of doing so at
 * creation of the containing activity:</p>
 *
 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
 *      create}
 *
 * @param activity The Activity that is inflating this fragment.
 * @param attrs The attributes at the tag where the fragment is
 * being created.
 * @param savedInstanceState If the fragment is being re-created from
 * a previous saved state, this is the state.
 */
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    onInflate(attrs, savedInstanceState);
    mCalled = true;

    TypedArray a = activity.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
    mEnterTransition = loadTransition(activity, a, mEnterTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentEnterTransition);
    mReturnTransition = loadTransition(activity, a, mReturnTransition, USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentReturnTransition);
    mExitTransition = loadTransition(activity, a, mExitTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentExitTransition);
    mReenterTransition = loadTransition(activity, a, mReenterTransition, USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentReenterTransition);
    mSharedElementEnterTransition = loadTransition(activity, a, mSharedElementEnterTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentSharedElementEnterTransition);
    mSharedElementReturnTransition = loadTransition(activity, a, mSharedElementReturnTransition,
            USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentSharedElementReturnTransition);
    if (mAllowEnterTransitionOverlap == null) {
        mAllowEnterTransitionOverlap = a.getBoolean(
                com.android.internal.R.styleable.Fragment_fragmentAllowEnterTransitionOverlap, true);
    }
    if (mAllowReturnTransitionOverlap == null) {
        mAllowReturnTransitionOverlap = a.getBoolean(
                com.android.internal.R.styleable.Fragment_fragmentAllowReturnTransitionOverlap, true);
    }
    a.recycle();
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

private void init(Context context, AttributeSet attrs) {
    detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override/*  w w  w.  j a v  a 2s  .  c  om*/
        public boolean onDown(MotionEvent event) {
            boolean isMarkerInChord = false;
            int fret = NO_FRET, string = -1;
            fret = getSelectedFret(event);
            string = getSelectedString(event);
            touchEventMarker = new ChordMarker(string, fret, NO_FINGER);
            return true;
        }

        @Override
        public void onLongPress(MotionEvent event) {
            if (editable && touchEventMarker != null && chord != null && chord.contains(touchEventMarker)) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(GuitarChordView.this, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });
    chord = new Chord();
    showFretNumbers = true;
    showFingerNumbers = true;
    editable = false;
    stringCount = 6;
    listeners = new ArrayList<>();
    fretNumberListeners = new ArrayList<>();
    stringListeners = new ArrayList<>();
    touchEventMarker = null;
    mutedText = MUTED_TEXT;
    openStringText = OPEN_STRING_TEXT;
    initPaint();
    if (attrs != null) {
        //TODO handle custom attribute values
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.GuitarChordView, 0, 0);
        try {
            bridgeNutColor = a.getColor(R.styleable.GuitarChordView_bridgeNutColor, DEFAULT_COLOR);
            bridgeNutPaint.setColor(bridgeNutColor);
            fretMarkerColor = a.getColor(R.styleable.GuitarChordView_fretMarkerColor, DEFAULT_COLOR);
            fretMarkerPaint.setColor(fretMarkerColor);
            stringColor = a.getColor(R.styleable.GuitarChordView_stringColor, DEFAULT_COLOR);
            stringPaint.setColor(stringColor);
            fretNumberColor = a.getColor(R.styleable.GuitarChordView_fretNumberColor, DEFAULT_COLOR);
            fretNumberPaint.setColor(fretNumberColor);
            stringMarkerColor = a.getColor(R.styleable.GuitarChordView_stringMarkerColor, DEFAULT_COLOR);
            stringMarkerPaint.setColor(stringMarkerColor);
            noteColor = a.getColor(R.styleable.GuitarChordView_noteColor, DEFAULT_COLOR);
            notePaint.setColor(noteColor);
            noteNumberColor = a.getColor(R.styleable.GuitarChordView_noteNumberColor, WHITE);
            noteNumberPaint.setColor(noteNumberColor);
            barLineColor = a.getColor(R.styleable.GuitarChordView_barLineColor, DEFAULT_COLOR);
            barLinePaint.setColor(barLineColor);
            mutedText = a.getString(R.styleable.GuitarChordView_mutedText);
            mutedText = (mutedText == null) ? MUTED_TEXT : mutedText;
            openStringText = a.getString(R.styleable.GuitarChordView_openStringText);
            openStringText = (openStringText == null) ? OPEN_STRING_TEXT : openStringText;
            stringCount = a.getInt(R.styleable.GuitarChordView_stringAmount, 6);
            editable = a.getBoolean(R.styleable.GuitarChordView_editable, false);
            showFingerNumbers = a.getBoolean(R.styleable.GuitarChordView_showFingerNumbers, true);
            showFretNumbers = a.getBoolean(R.styleable.GuitarChordView_showFretNumbers, true);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            a.recycle();
        }
    }
}