Java Code Examples for android.content.res.TypedArray#getIndexCount()

The following examples show how to use android.content.res.TypedArray#getIndexCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbsRefreshLayout.java    From NestRefreshLayout with MIT License 6 votes vote down vote up
/**
 * @param context
 * @param attrs
 * @param defStyleAttr
 */
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
    mScroller = new Scroller(context, new DecelerateInterpolator());
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.AbsRefreshLayout, defStyleAttr, 0);
    final int N = a.getIndexCount();
    int resFooter = R.layout.layout_loadmore;
    for (int i = 0; i < N; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.AbsRefreshLayout_footerNestLayout) {
            resFooter = a.getResourceId(attr, resFooter);
            break;
        }
    }
    a.recycle();
    /**
     * Convert values in dp to values in px;
     */
    setFooterView(inflate(context, resFooter, null));
}
 
Example 2
Source File: RoundedImageView.java    From Melophile with Apache License 2.0 6 votes vote down vote up
public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  if (attrs != null) {
    TypedArray array = getContext().obtainStyledAttributes(attrs,
            R.styleable.RoundedImageView);
    final int N = array.getIndexCount();
    for (int i = 0; i < N; ++i) {
      int attr = array.getIndex(i);
      if (attr == R.styleable.RoundedImageView_radius) {
        radius = array.getFloat(R.styleable.RoundedImageView_radius, 18.f);
      }
    }
    array.recycle();
  }
  init();
}
 
Example 3
Source File: TextMarker.java    From Carbon with Apache License 2.0 6 votes vote down vote up
private void init(AttributeSet attrs, @AttrRes int defStyleAttr) {
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TextMarker, defStyleAttr, 0);

        for (int i = 0; i < a.getIndexCount(); i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.TextMarker_carbon_text) {
                setText(a.getText(attr).toString());
            } else if (attr == R.styleable.TextMarker_carbon_textView) {
                id = a.getResourceId(attr, 0);
            }
        }

        a.recycle();
    }
}
 
Example 4
Source File: WaypointItem.java    From msdkui-android with Apache License 2.0 6 votes vote down vote up
/**
 * Initialization of attributes.
 */
private void attrsInit(final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
    if (attrs == null) {
        return;
    }
    final TypedArray typedArray = this.getContext()
            .obtainStyledAttributes(attrs, R.styleable.WaypointItem, defStyleAttr, defStyleRes);
    final int indexCount = typedArray.getIndexCount();
    for (int i = 0; i < indexCount; ++i) {
        final int attr = typedArray.getIndex(i);
        if (attr == R.styleable.WaypointItem_removingEnabled) {
            setRemoveEnabled(typedArray.getBoolean(attr, false));
        } else if (attr == R.styleable.WaypointItem_draggingEnabled) {
            setDragEnabled(typedArray.getBoolean(attr, false));
        } else if (attr == R.styleable.WaypointItem_removingEnabledIcon || attr == R.styleable.WaypointItem_draggingEnabledIcon) {
            setIcon(typedArray, attr);
        }
    }
    typedArray.recycle();
}
 
Example 5
Source File: CreditsRollView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void init(AttributeSet attrs, int defStyle, Context context) {
    // Load attributes
    final TypedArray a = context.obtainStyledAttributes(
        attrs, R.styleable.CreditsRollView, defStyle, 0);

    if (a != null) {
        final int N = a.getIndexCount();

        for (int i = 0; i < N; ++i) {
            int attr = a.getIndex(i);

            if (attr == R.styleable.CreditsRollView_crv_angle) {
                float angle = a.getFloat(attr, mAngle);
                setAngle(angle);
            }
            else if (attr == R.styleable.CreditsRollView_crv_scrollPosition) {
                float scrollPercent = a.getFloat(attr, 0f);
                setScrollPosition(scrollPercent);
            }
            else if (attr == R.styleable.CreditsRollView_crv_endScrollMultiplier) {
                float scrollMult = a.getFloat(attr, 0f);
                setEndScrollMult(scrollMult);
            }
            else if (attr == R.styleable.CreditsRollView_crv_distanceFromText) {
                float distance = a.getFloat(attr, 0f);
                setDistanceFromText(distance);
            }
        }

        a.recycle();
    }

    initTextPaint();
}
 
Example 6
Source File: SwipeMenuView.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    mScaleTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mMaxVelocity = ViewConfiguration.get(context).getScaledMaximumFlingVelocity();
    //初始化滑动帮助类对象
    //mScroller = new Scroller(context);

    //右滑删除功能的开关,默认开
    isSwipeEnable = true;
    //IOS、QQ式交互,默认开
    isIos = true;
    //左滑右滑的开关,默认左滑打开菜单
    isLeftSwipe = true;
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeMenuView, defStyleAttr, 0);
    int count = ta.getIndexCount();
    for (int i = 0; i < count; i++) {
        int attr = ta.getIndex(i);
        //如果引用成AndroidLib 资源都不是常量,无法使用switch case
        if (attr == R.styleable.SwipeMenuView_swipeEnable) {
            isSwipeEnable = ta.getBoolean(attr, true);
        } else if (attr == R.styleable.SwipeMenuView_ios) {
            isIos = ta.getBoolean(attr, true);
        } else if (attr == R.styleable.SwipeMenuView_leftSwipe) {
            isLeftSwipe = ta.getBoolean(attr, true);
        }
    }
    ta.recycle();


}
 
Example 7
Source File: CommonPtrLayout.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
public CommonPtrLayout(Context context, AttributeSet attrs, int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.obtainStyledAttributes(attrs, com.lib.ptrview.R.styleable.CommonPtrLayout, defStyleAttr, 0);

    try
    {
        final int N = a.getIndexCount();
        for (int i = 0; i < N; i++)
        {
            int attr = a.getIndex(i);
            if (attr == com.lib.ptrview.R.styleable.CommonPtrLayout_ptr_enable_refresh)
                setRefreshEnabled(a.getBoolean(attr, true));
            else if (attr == com.lib.ptrview.R.styleable.CommonPtrLayout_ptr_enable_loadmore)
                setLoadMoreEnabled(a.getBoolean(attr, true));
            else if (attr == com.lib.ptrview.R.styleable.CommonPtrLayout_ptr_friction)
                setFriction(a.getFloat(attr, DEFAULT_FRICTION));
            else if (attr == com.lib.ptrview.R.styleable.CommonPtrLayout_ptr_delay_duration)
                mDurationOfDelay = a.getInt(attr, DEFAULT_DURATION_DELAY);
            else if (attr == R.styleable.CommonPtrLayout_ptr_bg_refresh)
                mRefreshBgResId = a.getResourceId(attr, R.color.black_ptr_view_bg);
            else if (attr == R.styleable.CommonPtrLayout_ptr_bg_loadmore)
                mLoadMoreBgResId = a.getResourceId(attr, R.color.black_ptr_view_bg);
            else if (attr == com.lib.ptrview.R.styleable.CommonPtrLayout_ptr_is_coordinatorLayout)
                mIsCoo = a.getBoolean(attr, false);
        }
    } finally
    {
        a.recycle();
    }
}
 
Example 8
Source File: ExpandableButtonView.java    From Expandable-Action-Button with MIT License 5 votes vote down vote up
private void initAttrs(@Nullable AttributeSet attrs) {
    if (attrs == null)
        return;

    float density = getResources().getDisplayMetrics().density;
    TypedArray array = getContext().obtainStyledAttributes(attrs,
            R.styleable.ExpandableButtonView);

    for(int index=0;index<array.getIndexCount();index++) {
        int attr=array.getIndex(index);
        if(attr==R.styleable.ExpandableButtonView_button_width) {
            setButtonWidth(array.getDimensionPixelSize(attr, (int) (56 * density)));
        }else if(attr==R.styleable.ExpandableButtonView_button_height) {
            setButtonHeight(array.getDimensionPixelSize(attr, (int) (56 * density)));
        }else if(attr==R.styleable.ExpandableButtonView_button_color) {
            setButtonColor(array.getColor(attr, 0));
        }else if(attr==R.styleable.ExpandableButtonView_button_icon) {
            setButtonIcon(array.getResourceId(attr, -1));
        }else if(attr==R.styleable.ExpandableButtonView_toolbar_color) {
            setToolbarColor(array.getColor(attr, -1));
        }else if(attr==R.styleable.ExpandableButtonView_duration) {
            setDuration(array.getInteger(attr, 150));
        }else if(attr==R.styleable.ExpandableButtonView_reverse_duration){
            setReverseDuration(array.getInteger(attr,150));
        }
    }
    array.recycle();
}
 
Example 9
Source File: ChangeColorIconWithText.java    From HHComicViewer with Apache License 2.0 5 votes vote down vote up
/**
 * 获取自定义属性的值
 *
 * @param context
 * @param attrs
 * @param defStyleAttr
 */
public ChangeColorIconWithText(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ChangeColorIconWithText);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
            case R.styleable.ChangeColorIconWithText_icon:
                BitmapDrawable drawable = (BitmapDrawable) a.getDrawable(attr);
                if (drawable != null) {
                    mIconBitmap = drawable.getBitmap();
                }
                break;
            case R.styleable.ChangeColorIconWithText_color:
                mColor = a.getColor(attr, 0xFF45C01A);
                break;
            case R.styleable.ChangeColorIconWithText_text:
                mText = a.getString(attr);
                break;
            case R.styleable.ChangeColorIconWithText_text_size:
                mTextSize = (int) a.getDimension(attr,
                        TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12,
                                getResources().getDisplayMetrics()));
                break;
        }
    }
    a.recycle();

    //初始化成员变量
    mTextBound = new Rect();
    mTextPaint = new Paint();
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(0xff555555);
    mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
    mTextPaint.setAntiAlias(true); //抗锯齿
}
 
Example 10
Source File: ScanBoxView.java    From qrcode_android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void initCustomAttrs(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.QRCodeView);
    final int count = typedArray.getIndexCount();
    for (int i = 0; i < count; i++) {
        initCustomAttr(typedArray.getIndex(i), typedArray);
    }
    typedArray.recycle();

    afterInitCustomAttrs();
}
 
Example 11
Source File: CalendarView.java    From CalendarView with Apache License 2.0 5 votes vote down vote up
private void initAttr(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CalendarView);
    for (int i = 0; i < ta.getIndexCount(); i++) {
        int attr = ta.getIndex(i);
        if (attr == R.styleable.CalendarView_show_last_next) {
            mAttrsBean.setShowLastNext(ta.getBoolean(attr, true));
        } else if (attr == R.styleable.CalendarView_show_lunar) {
            mAttrsBean.setShowLunar(ta.getBoolean(attr, true));
        } else if (attr == R.styleable.CalendarView_show_holiday) {
            mAttrsBean.setShowHoliday(ta.getBoolean(attr, true));
        } else if (attr == R.styleable.CalendarView_show_term) {
            mAttrsBean.setShowTerm(ta.getBoolean(attr, true));
        } else if (attr == R.styleable.CalendarView_switch_choose) {
            mAttrsBean.setSwitchChoose(ta.getBoolean(attr, true));
        } else if (attr == R.styleable.CalendarView_solar_color) {
            mAttrsBean.setColorSolar(ta.getColor(attr, mAttrsBean.getColorSolar()));
        } else if (attr == R.styleable.CalendarView_solar_size) {
            mAttrsBean.setSizeSolar(CalendarUtil.getTextSize(context, ta.getInteger(attr, mAttrsBean.getSizeSolar())));
        } else if (attr == R.styleable.CalendarView_lunar_color) {
            mAttrsBean.setColorLunar(ta.getColor(attr, mAttrsBean.getColorLunar()));
        } else if (attr == R.styleable.CalendarView_lunar_size) {
            mAttrsBean.setSizeLunar(CalendarUtil.getTextSize(context, ta.getInt(attr, mAttrsBean.getSizeLunar())));
        } else if (attr == R.styleable.CalendarView_holiday_color) {
            mAttrsBean.setColorHoliday(ta.getColor(attr, mAttrsBean.getColorHoliday()));
        } else if (attr == R.styleable.CalendarView_choose_color) {
            mAttrsBean.setColorChoose(ta.getColor(attr, mAttrsBean.getColorChoose()));
        } else if (attr == R.styleable.CalendarView_day_bg) {
            mAttrsBean.setDayBg(ta.getResourceId(attr, mAttrsBean.getDayBg()));
        } else if (attr == R.styleable.CalendarView_choose_type) {
            mAttrsBean.setChooseType(ta.getInt(attr, 0));
        }
    }

    ta.recycle();

    startDate = new int[]{1900, 1};
    endDate = new int[]{2049, 12};
    mAttrsBean.setStartDate(startDate);
    mAttrsBean.setEndDate(endDate);
}
 
Example 12
Source File: DSListView.java    From direct-select-android with MIT License 5 votes vote down vote up
public DSListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.DSListView);
    final int count = styledAttrs.getIndexCount();
    for (int i = 0; i < count; ++i) {
        int attr = styledAttrs.getIndex(i);
        if (attr == R.styleable.DSListView_cell_font_size) {
            this.cellTextSize = styledAttrs.getDimensionPixelSize(attr, 0);
        } else if (attr == R.styleable.DSListView_data_array) {
            String[] arr = getResources().getStringArray(styledAttrs.getResourceId(attr, 0));
            this.dataFromAttributes = new ArrayList<>(Arrays.asList(arr));
        } else if (attr == R.styleable.DSListView_scale_animations) {
            this.selectorAnimationsEnabled = styledAttrs.getBoolean(attr, true);
        } else if (attr == R.styleable.DSListView_selected_index) {
            this.selectedItem = styledAttrs.getInt(attr, 0);
        } else if (attr == R.styleable.DSListView_picker_box_view) {
            this.pickerBoxResId = styledAttrs.getResourceId(attr, 0);
        } else if (attr == R.styleable.DSListView_scale_animations_factor) {
            this.scaleFactorDelta = styledAttrs.getFloat(attr, 1.3f) - 1f;
        } else if (attr == R.styleable.DSListView_scale_animations_pivot_center) {
            this.selectorAnimationCenterPivot = styledAttrs.getBoolean(attr, false);
        } else if (attr == R.styleable.DSListView_selector_background) {
            try {
                this.selectorBgColor = styledAttrs.getColor(attr, Color.parseColor("#116b2b66"));
            } catch (Exception e) {
                this.selectorBgDrawable = styledAttrs.getResourceId(attr, 0);
            }
        }
    }
    styledAttrs.recycle();
    initPicker(context);
}
 
Example 13
Source File: VDVideoRelatedButton.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
public VDVideoRelatedButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    // mContext = context;

    // 如果有自定义属性,加载
    TypedArray typedArr = context.obtainStyledAttributes(attrs, R.styleable.VDVideoRelatedButton);
    if (typedArr != null) {
        for (int i = 0; i < typedArr.getIndexCount(); i++) {
            int i1 = typedArr.getIndex(i);
            if (i1 == R.styleable.VDVideoRelatedButton_listContainer) {
                mListContainerID = typedArr.getResourceId(R.styleable.VDVideoRelatedButton_listContainer, -1);

            } else if (i1 == R.styleable.VDVideoRelatedButton_uiControl) {
                mUIControl = typedArr.getInteger(R.styleable.VDVideoRelatedButton_uiControl, -1);

            }
        }
        typedArr.recycle();
    } else {
        VDLog.e(TAG, "listContainer属性必须设置");
        return;
    }

    // 如果没有自定义图片,则默认为新浪视频的素材
    typedArr = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.background});
    if (typedArr != null) {
        int resouceID = typedArr.getResourceId(0, -1);
        if (resouceID == -1) {
            setBackgroundResource(R.drawable.play_ctrl_video_list);
        }
        typedArr.recycle();
    } else {
        setBackgroundResource(R.drawable.play_ctrl_video_list);
    }

    registerListeners();
}
 
Example 14
Source File: VDVideoView.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
/**
 * 从TypedArray里面抽取需要的resourceID
 * 
 * @param typedArr
 */
private void initLayer(TypedArray typedArr) {
	removeAllViews();
	for (int i = 0; i < typedArr.getIndexCount(); i++) {
		if (typedArr.getIndex(i) == R.styleable.VDVideoView_layerAttrs) {
			int resID = -1;
			// 1.layerAttrs中格式一般为@array/sv_videoview_layers之类的格式
			// 先读出其resourceID来,准备加载TypedArray
			resID = typedArr.getResourceId(
					R.styleable.VDVideoView_layerAttrs, -1);
			if (resID == -1) {
				if (typedArr != null)
					typedArr.recycle();
				throw new IllegalArgumentException("resID=-1");
			}

			readLayerAttrs(resID);
		} else if (typedArr.getIndex(i) == R.styleable.VDVideoView_canPopupWindow) {
			int popWindowType = typedArr.getInt(
					R.styleable.VDVideoView_canPopupWindow, -1);
			if (popWindowType != -1) {
				mIsCanPopupWindow = true;
				mPopupWindowType = popWindowType;
			}
		} else if (typedArr.getIndex(i) == R.styleable.VDVideoView_popWindowWidth) {
			float width = typedArr.getDimension(
					R.styleable.VDVideoView_popWindowWidth, -1);
			if (width != -1) {
				mPopupWindowWidth = (int) width;
			}
		} else if (typedArr.getIndex(i) == R.styleable.VDVideoView_popWindowHeight) {
			float height = typedArr.getDimension(
					R.styleable.VDVideoView_popWindowHeight, -1);
			if (height != -1) {
				mPopupWindowHeight = (int) height;
			}
		}
	}
}
 
Example 15
Source File: Preference.java    From ticdesign with Apache License 2.0 4 votes vote down vote up
/**
 * Perform inflation from XML and apply a class-specific base style. This
 * constructor of Preference allows subclasses to use their own base style
 * when they are inflating. For example, a {@link CheckBoxPreference}
 * constructor calls this version of the super class constructor and
 * supplies {@code android.R.attr.checkBoxPreferenceStyle} for
 * <var>defStyleAttr</var>. This allows the theme's checkbox preference
 * style to modify all of the base preference attributes as well as the
 * {@link CheckBoxPreference} class's attributes.
 *
 * @param context The Context this is associated with, through which it can
 *            access the current theme, resources,
 *            {@link SharedPreferences}, etc.
 * @param attrs The attributes of the XML tag that is inflating the
 *            preference.
 * @param defStyleAttr An attribute in the current theme that contains a
 *            reference to a style resource that supplies default values for
 *            the view. Can be 0 to not look for defaults.
 * @param defStyleRes A resource identifier of a style resource that
 *            supplies default values for the view, used only if
 *            defStyleAttr is 0 or can not be found in the theme. Can be 0
 *            to not look for defaults.
 * @see #Preference(Context, AttributeSet)
 */
public Preference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.Preference, defStyleAttr, defStyleRes);
    for (int i = a.getIndexCount() - 1; i >= 0; i--) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.Preference_android_icon) {
            mIconResId = a.getResourceId(attr, 0);

        } else if (attr == R.styleable.Preference_android_key) {
            mKey = a.getString(attr);

        } else if (attr == R.styleable.Preference_android_title) {
            mTitleRes = a.getResourceId(attr, 0);
            mTitle = a.getString(attr);

        } else if (attr == R.styleable.Preference_android_summary) {
            mSummary = a.getString(attr);

        } else if (attr == R.styleable.Preference_android_order) {
            mOrder = a.getInt(attr, mOrder);

        } else if (attr == R.styleable.Preference_android_fragment) {
            mFragment = a.getString(attr);

        } else if (attr == R.styleable.Preference_android_layout) {
            mLayoutResId = a.getResourceId(attr, mLayoutResId);

        } else if (attr == R.styleable.Preference_android_widgetLayout) {
            mWidgetLayoutResId = a.getResourceId(attr, mWidgetLayoutResId);

        } else if (attr == R.styleable.Preference_android_enabled) {
            mEnabled = a.getBoolean(attr, true);

        } else if (attr == R.styleable.Preference_android_selectable) {
            mSelectable = a.getBoolean(attr, true);

        } else if (attr == R.styleable.Preference_android_persistent) {
            mPersistent = a.getBoolean(attr, mPersistent);

        } else if (attr == R.styleable.Preference_android_dependency) {
            mDependencyKey = a.getString(attr);

        } else if (attr == R.styleable.Preference_android_defaultValue) {
            mDefaultValue = onGetDefaultValue(a, attr);

        } else if (attr == R.styleable.Preference_android_shouldDisableView) {
            mShouldDisableView = a.getBoolean(attr, mShouldDisableView);

        }
    }
    a.recycle();

}
 
Example 16
Source File: PullButton.java    From AnkiDroid-Wear with GNU General Public License v2.0 4 votes vote down vote up
public PullButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr);
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.pull_button, this);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    display.getSize(displaySize);


    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullButton);
    final int N = a.getIndexCount();

    icon = (ImageButton) findViewById(R.id.icon);
    textView = (TextView) findViewById(R.id.textView);
    easeTextView = (TextView) findViewById(R.id.ease_text);



    for (int i = 0; i < N; ++i) {
        int attr = a.getIndex(i);
        switch (attr) {
            case R.styleable.PullButton_icon:
                imageResId = a.getResourceId(attr, R.drawable.close_button);
                break;
            case R.styleable.PullButton_text:
                String text = a.getString(attr);
                textView.setText(text);
                break;
            case R.styleable.PullButton_upsideDown:
                upsideDown = a.getBoolean(attr, false);

                break;
            case R.styleable.PullButton_ease_text:
                easeTextView.setText(a.getString(attr));
                break;
        }
    }
    a.recycle();



    ViewTreeObserver vto = getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (upsideDown) {
                textView.setY(0);
                icon.setY(textView.getHeight());
                icon.setRotation(180);
                easeTextView.setY(easeTextView.getY() + textView.getHeight());
            }


            if (upsideDown) {
                homePosition = 0 - textView.getHeight();
                extendedPosition = 0;
                exitY = displaySize.y + 10;
            } else {
                homePosition = displaySize.y - icon.getHeight();
                extendedPosition = displaySize.y - getHeight();
                exitY = -getHeight() - 10;
            }

            setY(homePosition);

            ViewTreeObserver obs = getViewTreeObserver();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                obs.removeOnGlobalLayoutListener(this);
            } else {
                obs.removeGlobalOnLayoutListener(this);
            }
        }
    });


    if (imageResId != -1) {
        icon.setImageResource(imageResId);
    }



    minMovementDistance = displaySize.y / 2;


    setAlpha(homeAlpha);


    this.animate().setInterpolator(new LinearInterpolator());
    this.setOnTouchListener(new SwipeTouchListener());

}
 
Example 17
Source File: ArcMenu.java    From zone-sdk with MIT License 4 votes vote down vote up
/**
 * 初始化属性
 * 
 * @param context
 * @param attrs
 * @param defStyle
 */
public ArcMenu(Context context, AttributeSet attrs, int defStyle)
{

	super(context, attrs, defStyle);
	// dp fillData to px
	mRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
			mRadius, getResources().getDisplayMetrics());
	TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
			R.styleable.ArcMenu, defStyle, 0);

	int n = a.getIndexCount();
	for (int i = 0; i < n; i++)
	{
		int attr = a.getIndex(i);
		switch (attr)
		{
		case R.styleable.ArcMenu_position:
			int val = a.getInt(attr, 0);
			switch (val)
			{
			case 0:
				mPosition = Position.LEFT_TOP;
				break;
			case 1:
				mPosition = Position.RIGHT_TOP;
				break;
			case 2:
				mPosition = Position.RIGHT_BOTTOM;
				break;
			case 3:
				mPosition = Position.LEFT_BOTTOM;
				break;
			}
			break;
		case R.styleable.ArcMenu_radius:
			// dp fillData to px
			mRadius = a.getDimensionPixelSize(attr, (int) TypedValue
					.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100f,
							getResources().getDisplayMetrics()));
			break;

		}
	}
	a.recycle();
}
 
Example 18
Source File: Spinner.java    From AndroidMaterialValidation with Apache License 2.0 4 votes vote down vote up
/**
 * Obtains all attributes, which are defined by an {@link android.widget.Spinner} widget, from a
 * specific typed array.
 *
 * @param typedArray
 *         The typed array, the attributes should be obtained from, as an instance of the class
 *         {@link TypedArray}. The typed array may not be null
 */
private void obtainSpinnerStyledAttributes(@NonNull final TypedArray typedArray) {
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
        int index = typedArray.getIndex(i);

        if (index == R.styleable.Spinner_android_dropDownHorizontalOffset) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                setDropDownHorizontalOffset(
                        typedArray.getDimensionPixelSize(index, getDropDownHorizontalOffset()));
            }
        } else if (index == R.styleable.Spinner_android_dropDownVerticalOffset) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                setDropDownVerticalOffset(
                        typedArray.getDimensionPixelSize(index, getDropDownVerticalOffset()));
            }
        } else if (index == R.styleable.Spinner_dropDownWidth) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                setDropDownWidth(typedArray.getLayoutDimension(index, getDropDownWidth()));
            }
        } else if (index == R.styleable.Spinner_popupBackground) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                Drawable popupBackground = typedArray.getDrawable(index);

                if (popupBackground != null) {
                    setPopupBackgroundDrawable(popupBackground);
                }
            }
        } else if (index == R.styleable.Spinner_prompt) {
            String prompt = typedArray.getString(index);

            if (prompt != null) {
                setPrompt(prompt);
            }
        } else if (index == R.styleable.Spinner_android_entries) {
            CharSequence[] entries = typedArray.getTextArray(index);

            if (entries != null) {
                ArrayAdapter<CharSequence> adapter =
                        new ArrayAdapter<>(getContext(), R.layout.spinner_item, entries);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                setAdapter(adapter);
            }
        }
    }
}
 
Example 19
Source File: SceneConfigurator.java    From ParticlesDrawable with Apache License 2.0 4 votes vote down vote up
public void configureSceneFromAttributes(
        @NonNull final SceneConfiguration scene,
        @NonNull final Resources r,
        @NonNull final AttributeSet attrs) {
    final TypedArray a = r.obtainAttributes(attrs, R.styleable.ParticlesView);
    try {
        final int count = a.getIndexCount();
        float particleRadiusMax = Defaults.PARTICLE_RADIUS_MAX;
        float particleRadiusMin = Defaults.PARTICLE_RADIUS_MIN;
        for (int i = 0; i < count; i++) {
            final int attr = a.getIndex(i);
            if (attr == R.styleable.ParticlesView_density) {
                scene.setDensity(a.getInteger(attr, Defaults.DENSITY));

            } else if (attr == R.styleable.ParticlesView_frameDelayMillis) {
                scene.setFrameDelay(a.getInteger(attr, Defaults.FRAME_DELAY));

            } else if (attr == R.styleable.ParticlesView_lineColor) {
                scene.setLineColor(a.getColor(attr, Defaults.LINE_COLOR));

            } else if (attr == R.styleable.ParticlesView_lineLength) {
                scene.setLineLength(a.getDimension(attr, Defaults.LINE_LENGTH));

            } else if (attr == R.styleable.ParticlesView_lineThickness) {
                scene.setLineThickness(a.getDimension(attr, Defaults.LINE_THICKNESS));

            } else if (attr == R.styleable.ParticlesView_particleColor) {
                scene.setParticleColor(a.getColor(attr, Defaults.PARTICLE_COLOR));

            } else if (attr == R.styleable.ParticlesView_particleRadiusMax) {
                particleRadiusMax = a.getDimension(attr, Defaults.PARTICLE_RADIUS_MAX);

            } else if (attr == R.styleable.ParticlesView_particleRadiusMin) {
                particleRadiusMin = a.getDimension(attr, Defaults.PARTICLE_RADIUS_MIN);

            } else if (attr == R.styleable.ParticlesView_speedFactor) {
                scene.setSpeedFactor(a.getFloat(attr, Defaults.SPEED_FACTOR));
            }
        }
        scene.setParticleRadiusRange(particleRadiusMin, particleRadiusMax);
    } finally {
        a.recycle();
    }
}
 
Example 20
Source File: FButton.java    From Trivia-Knowledge with Apache License 2.0 4 votes vote down vote up
private void parseAttrs(Context context, AttributeSet attrs) {
    //Load from custom attributes
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FButton);
    if (typedArray == null) return;
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
        int attr = typedArray.getIndex(i);
        if (attr == R.styleable.FButton_shadowEnabled) {
            isShadowEnabled = typedArray.getBoolean(attr, true); //Default is true
        } else if (attr == R.styleable.FButton_buttonColor) {
            mButtonColor = typedArray.getColor(attr, getResources().getColor(R.color.fbutton_default_color));
        } else if (attr == R.styleable.FButton_shadowColor) {
            mShadowColor = typedArray.getColor(attr, getResources().getColor(R.color.fbutton_default_shadow_color));
            isShadowColorDefined = true;
        } else if (attr == R.styleable.FButton_shadowHeight) {
            mShadowHeight = typedArray.getDimensionPixelSize(attr, R.dimen.fbutton_default_shadow_height);
        } else if (attr == R.styleable.FButton_cornerRadius) {
            mCornerRadius = typedArray.getDimensionPixelSize(attr, R.dimen.fbutton_default_conner_radius);
        }
    }
    typedArray.recycle();

    //Get paddingLeft, paddingRight
    int[] attrsArray = new int[]{
            android.R.attr.paddingLeft,  // 0
            android.R.attr.paddingRight, // 1
    };
    TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
    if (ta == null) return;
    mPaddingLeft = ta.getDimensionPixelSize(0, 0);
    mPaddingRight = ta.getDimensionPixelSize(1, 0);
    ta.recycle();

    //Get paddingTop, paddingBottom
    int[] attrsArray2 = new int[]{
            android.R.attr.paddingTop,   // 0
            android.R.attr.paddingBottom,// 1
    };
    TypedArray ta1 = context.obtainStyledAttributes(attrs, attrsArray2);
    if (ta1 == null) return;
    mPaddingTop = ta1.getDimensionPixelSize(0, 0);
    mPaddingBottom = ta1.getDimensionPixelSize(1, 0);
    ta1.recycle();
}