/** * Last but not least, try to pull the Font Path from the Theme, which is defined. * * @param context Activity Context * @param styleAttrId Theme style id * @param subStyleAttrId the sub style from the theme to look up after the first style * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme( Context context, int styleAttrId, int subStyleAttrId, int attributeId) { if (styleAttrId == -1 || attributeId == -1) return null; final Resources.Theme theme = context.getTheme(); final TypedValue value = new TypedValue(); theme.resolveAttribute(styleAttrId, value, true); int subStyleResId = -1; final TypedArray parentTypedArray = theme.obtainStyledAttributes(value.resourceId, new int[] {subStyleAttrId}); try { subStyleResId = parentTypedArray.getResourceId(0, -1); } catch (Exception ignore) { // Failed for some reason. return null; } finally { parentTypedArray.recycle(); } if (subStyleResId == -1) return null; final TypedArray subTypedArray = context.obtainStyledAttributes(subStyleResId, new int[] {attributeId}); if (subTypedArray != null) { try { return subTypedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { subTypedArray.recycle(); } } return null; }
/** * Constructor that is called when inflating SwipeRefreshLayout from XML. * * @param context * @param attrs */ public NoisySwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime); setWillNotDraw(false); final DisplayMetrics metrics = getResources().getDisplayMetrics(); mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR); mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR); final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS); setEnabled(a.getBoolean(0, true)); a.recycle(); final TypedArray va = context.obtainStyledAttributes(attrs, R.styleable.SuperSwipeRefreshLayout); mProgressBarOffsetTop = a.getDimensionPixelSize(R.styleable.SuperSwipeRefreshLayout_topOffset, 0); mProgressBarHeight = a.getDimensionPixelSize( R.styleable.SuperSwipeRefreshLayout_progressBarHeight, (int) (metrics.density * PROGRESS_BAR_HEIGHT)); va.recycle(); }
public VDVideoSoundSeekButton(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub mContext = context; // 支持自定义背景 TypedArray typedArr = context.obtainStyledAttributes(attrs, new int[] {android.R.attr.background}); mResID = R.drawable.play_ctrl_volume; if (typedArr != null) { mResID = typedArr.getResourceId(0, -1); if (mResID == -1) { mResID = R.drawable.play_ctrl_volume; } typedArr.recycle(); } setBackgroundResource(mResID); // 指定相应的音量控制容器类 typedArr = context.obtainStyledAttributes(attrs, R.styleable.VDVideoSoundSeekButton); mSilentResID = R.drawable.ad_silent_selcetor; if (typedArr != null) { for (int i = 0; i < typedArr.getIndexCount(); i++) { if (typedArr.getIndex(i) == R.styleable.VDVideoSoundSeekButton_soundSeekContainer) { mContainerID = typedArr.getResourceId(i, -1); } else if (typedArr.getIndex(i) == R.styleable.VDVideoSoundSeekButton_soundSeekSilent) { // 自定义背景的时候,换静音按钮 mSilentResID = typedArr.getResourceId(i, -1); } } typedArr.recycle(); } registerListeners(); }
public ListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes); mEntries = TypedArrayUtils.getTextArray( a, R.styleable.ListPreference_entries, R.styleable.ListPreference_android_entries); mEntryValues = TypedArrayUtils.getTextArray( a, R.styleable.ListPreference_entryValues, R.styleable.ListPreference_android_entryValues); a.recycle(); /* Retrieve the Preference summary attribute since it's private * in the Preference class. */ a = context.obtainStyledAttributes(attrs, R.styleable.Preference, defStyleAttr, defStyleRes); mSummary = TypedArrayUtils.getString( a, R.styleable.Preference_summary, R.styleable.Preference_android_summary); a.recycle(); }
public BatteryMeterView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mHandler = new Handler(); final Resources res = context.getResources(); TypedArray levels = res.obtainTypedArray(R.array.batterymeter_color_levels); TypedArray colors = res.obtainTypedArray(R.array.batterymeter_color_values); final int N = levels.length(); mColors = new int[2 * N]; for (int i = 0; i < N; i++) { mColors[2 * i] = levels.getInt(i, 0); mColors[2 * i + 1] = colors.getColor(i, 0); } levels.recycle(); colors.recycle(); mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt( context.getContentResolver(), "status_bar_show_battery_percent", 0); mChargeColor = getResources().getColor(R.color.batterymeter_charge_color); mWarningString = context.getString(R.string.battery_meter_very_low_overlay_symbol); mMeterMode = BatteryMeterMode.BATTERY_METER_ICON_PORTRAIT; mBatteryMeterDrawable = createBatteryMeterDrawable(mMeterMode); setLayerType(View.LAYER_TYPE_SOFTWARE, null); }
private void init(AttributeSet attrs) { if (attrs != null) { TypedArray a = getContext() .getTheme() .obtainStyledAttributes(attrs, R.styleable.DexCrossFadeImageView, 0, 0); setTransitionDurationMillis( a.getInt( R.styleable.DexCrossFadeImageView_transition_duration_millis, transitionDurationMillis)); setStillImageDurationMillis( a.getInt( R.styleable.DexCrossFadeImageView_still_image_duration_millis, stillImageDurationMillis)); setLoop(a.getBoolean(R.styleable.DexCrossFadeImageView_loop, loop)); int intArrayRes = a.getResourceId(R.styleable.DexCrossFadeImageView_images_array, 0); if (intArrayRes != 0) { TypedArray images = getResources().obtainTypedArray(intArrayRes); drawables = new Drawable[images.length()]; for (int i = 0; i < images.length(); i++) drawables[i] = images.getDrawable(i); images.recycle(); start(); } a.recycle(); } }
/** * Tries to pull the Font Path from the Text Appearance. * * @param context Activity Context * @param attrs View Attributes * @param attributeId if -1 returns null. * @return returns null if attribute is not defined or if no TextAppearance is found. */ static String pullFontPathFromTextAppearance( final Context context, AttributeSet attrs, int attributeId) { if (attributeId == -1 || attrs == null) { return null; } int textAppearanceId = -1; final TypedArray typedArrayAttr = context.obtainStyledAttributes(attrs, new int[] {android.R.attr.textAppearance}); if (typedArrayAttr != null) { try { textAppearanceId = typedArrayAttr.getResourceId(0, -1); } catch (Exception ignored) { // Failed for some reason return null; } finally { typedArrayAttr.recycle(); } } final TypedArray textAppearanceAttrs = context.obtainStyledAttributes(textAppearanceId, new int[] {attributeId}); if (textAppearanceAttrs != null) { try { return textAppearanceAttrs.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { textAppearanceAttrs.recycle(); } } return null; }
public ChartGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setWillNotDraw(false); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ChartGridView, defStyle, 0); mPrimary = a.getDrawable(R.styleable.ChartGridView_primaryDrawable); mSecondary = a.getDrawable(R.styleable.ChartGridView_secondaryDrawable); mBorder = a.getDrawable(R.styleable.ChartGridView_borderDrawable); final int taId = a.getResourceId(R.styleable.ChartGridView_android_textAppearance, -1); final TypedArray ta = context.obtainStyledAttributes(taId, com.android.internal.R.styleable.TextAppearance); mLabelSize = ta.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0); ta.recycle(); final ColorStateList labelColor = a.getColorStateList(R.styleable.ChartGridView_android_textColor); mLabelColor = labelColor.getDefaultColor(); a.recycle(); }
private void parseKeyStyle(final XmlPullParser parser, final boolean skip) throws XmlPullParserException, IOException { final AttributeSet attr = Xml.asAttributeSet(parser); final TypedArray keyStyleAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_KeyStyle); final TypedArray keyAttrs = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key); try { if (!keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_styleName)) { throw new XmlParseUtils.ParseException( "<" + TAG_KEY_STYLE + "/> needs styleName attribute", parser); } if (DEBUG) { startEndTag( "<%s styleName=%s />%s", TAG_KEY_STYLE, keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName), skip ? " skipped" : ""); } if (!skip) { mParams.mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser); } } finally { keyStyleAttr.recycle(); keyAttrs.recycle(); } XmlParseUtils.checkEndTag(TAG_KEY_STYLE, parser); }
public VDVideoResolutionListButton(Context context, AttributeSet attrs) { super(context, attrs); // 自定义背景 TypedArray typedArr = context.obtainStyledAttributes(attrs, new int[] {android.R.attr.background}); int background = R.drawable.quality_bg; if (typedArr != null) { int res = typedArr.getResourceId(0, -1); if (res != -1) { background = res; } typedArr.recycle(); } setBackgroundResource(background); // 自定义属性部分 typedArr = context.obtainStyledAttributes(attrs, R.styleable.VDVideoResolutionListButton); if (typedArr != null) { for (int i = 0; i < typedArr.getIndexCount(); i++) { if (typedArr.getIndex(i) == R.styleable.VDVideoResolutionListButton_resolutionTag) { mResolutionIndex = typedArr.getInt(i, -1); } } typedArr.recycle(); } init(context); }
/** * Create a key with the given top-left coordinate and extract its attributes from the XML * parser. * * @param res resources associated with the caller's context * @param parent the row that this key belongs to. The row must already be attached to a {@link * Keyboard}. * @param x the x coordinate of the top-left * @param y the y coordinate of the top-left * @param parser the XML parser containing the attributes for this key */ public Key( Context askContext, Resources res, Row parent, KeyboardDimens keyboardDimens, int x, int y, XmlResourceParser parser) { this(parent, keyboardDimens); final Resources askResources = askContext.getResources(); SparseIntArray attributeIdMap = parent.parent.attributeIdMap; this.x = x; this.y = y; // setting up some defaults width = Math.min(keyboardDimens.getKeyMaxWidth(), parent.defaultWidth); height = KeyboardSupport.getKeyHeightFromHeightCode( keyboardDimens, parent.defaultHeightCode, askResources.getConfiguration().orientation); gap = parent.defaultHorizontalGap; codes = null; iconPreview = null; popupCharacters = null; popupResId = 0; repeatable = false; showPreview = true; dynamicEmblem = KEY_EMBLEM_NONE; modifier = false; sticky = false; // loading data from XML int[] remoteKeyboardLayoutStyleable = parent.parent.remoteKeyboardLayoutStyleable; TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]); setDataFromTypedArray(parent, keyboardDimens, askResources, a, remoteIndex, localAttrId); } a.recycle(); this.x += gap; int[] remoteKeyboardKeyLayoutStyleable = parent.parent.remoteKeyboardKeyLayoutStyleable; a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardKeyLayoutStyleable); n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardKeyLayoutStyleable[remoteIndex]); setDataFromTypedArray(parent, keyboardDimens, askResources, a, remoteIndex, localAttrId); } externalResourcePopupLayout = popupResId != 0; if (codes == null && !TextUtils.isEmpty(label)) { codes = new int[] {label.charAt(0)}; } a.recycle(); }
public Row(Context askContext, Resources res, Keyboard parent, XmlResourceParser parser) { this.parent = parent; // some defaults defaultWidth = parent.mDefaultWidth; defaultHeightCode = parent.mDefaultHeightCode; defaultHorizontalGap = parent.mDefaultHorizontalGap; verticalGap = parent.getVerticalGap(); // now reading from the XML SparseIntArray attributeIdMap = parent.attributeIdMap; int[] remoteKeyboardLayoutStyleable = parent.remoteKeyboardLayoutStyleable; TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]); try { switch (localAttrId) { case android.R.attr.keyWidth: defaultWidth = getDimensionOrFraction( a, remoteIndex, parent.mDisplayWidth, parent.mDefaultWidth); break; case android.R.attr.keyHeight: defaultHeightCode = getKeyHeightCode(a, remoteIndex, parent.mDefaultHeightCode); break; case android.R.attr.horizontalGap: defaultHorizontalGap = getDimensionOrFraction( a, remoteIndex, parent.mDisplayWidth, parent.mDefaultHorizontalGap); break; } } catch (Exception e) { Log.w(TAG, "Failed to set data from XML!", e); } } a.recycle(); int[] remoteKeyboardRowLayoutStyleable = parent.remoteKeyboardRowLayoutStyleable; a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardRowLayoutStyleable); n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardRowLayoutStyleable[remoteIndex]); try { switch (localAttrId) { case android.R.attr.rowEdgeFlags: rowEdgeFlags = a.getInt(remoteIndex, 0); break; case android.R.attr.keyboardMode: mode = a.getResourceId(remoteIndex, 0); break; } } catch (Exception e) { Log.w(TAG, "Failed to set data from XML!", e); } } a.recycle(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment Resources res = getResources(); TypedArray ta = res.obtainTypedArray(R.array.movies); int n = ta.length(); for (int i = 0; i < n; i++) { TypedArray movieData = res.obtainTypedArray(ta.getResourceId(i, 0)); Movie movie = new Movie( movieData.getString(0), movieData.getString(1), movieData.getString(2), movieData.getResourceId(4, 0), movieData.getResourceId(3, 0)); mMovieList.add(movie); movieData.recycle(); } ta.recycle(); View v = inflater.inflate(R.layout.fragment_master, container, false); GridView gridview = (GridView) v.findViewById(R.id.gridview); gridview.setAdapter(new GridAdapter(v.getContext(), mMovieList)); gridview.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // Create new fragment and bundle DetailFragment newFragment = new DetailFragment(); Bundle bundle = new Bundle(); Movie movie = mMovieList.get(position); if (movie != null) { bundle.putSerializable(FRAGMENT_BUNDLE_KEY, movie); newFragment.setArguments(bundle); } else { Log.e("Movie", "Is null"); } // Set transaction. android.support.v4.app.FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); } }); return v; }
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(); }
private AccountManager() { this.application = Application.getInstance(); accountItems = new HashMap<String, AccountItem>(); enabledAccounts = new HashSet<String>(); savedStatuses = new ArrayList<SavedStatus>(); authorizationErrorProvider = new BaseAccountNotificationProvider<AccountAuthorizationError>( R.drawable.ic_stat_auth_failed); passwordRequestProvider = new BaseAccountNotificationProvider<PasswordRequest>(R.drawable.ic_stat_request); TypedArray accountAvatars = application.getResources().obtainTypedArray(R.array.account_avatars); colors = accountAvatars.length(); accountAvatars.recycle(); TypedArray types = application.getResources().obtainTypedArray(R.array.account_types); accountTypes = new ArrayList<AccountType>(); for (int index = 0; index < types.length(); index++) { int id = types.getResourceId(index, 0); TypedArray values = application.getResources().obtainTypedArray(id); AccountProtocol protocol = AccountProtocol.valueOf(values.getString(0)); if (Application.SDK_INT < 8 && protocol == AccountProtocol.wlm) { values.recycle(); continue; } ArrayList<String> servers = new ArrayList<String>(); servers.add(values.getString(9)); for (int i = 10; i < values.length(); i++) servers.add(values.getString(i)); accountTypes.add( new AccountType( id, protocol, values.getString(1), values.getString(2), values.getString(3), values.getDrawable(4), values.getBoolean(5, false), values.getString(6), values.getInt(7, 5222), values.getBoolean(8, false), servers)); values.recycle(); } types.recycle(); away = false; xa = false; }
public static BeveledTileAttributeSet extractAttributes(Context context, AttributeSet attrs) { BeveledTileAttributeSet beveledTileAttributeSet = null; TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.BeveledTileView); try { int[] colorList = new int[BeveledTileDrawable.REQUIRED_COLOR_COUNT]; colorList[INNER_RECT_COLOR_INDICE] = attributesArray.getColor(R.styleable.BeveledTileView_innerRectColor, -1); colorList[LEFT_BEVEL_COLOR_INDICE] = attributesArray.getColor(R.styleable.BeveledTileView_leftBevelColor, -1); colorList[TOP_BEVEL_COLOR_INDICE] = attributesArray.getColor(R.styleable.BeveledTileView_topBevelColor, -1); colorList[RIGHT_BEVEL_COLOR_INDICE] = attributesArray.getColor(R.styleable.BeveledTileView_rightBevelColor, -1); colorList[BOTTOM_BEVEL_COLOR_INDICE] = attributesArray.getColor(R.styleable.BeveledTileView_bottomBevelColor, -1); float fillPercent = attributesArray.getFloat(R.styleable.BeveledTileView_fillPercentage, -1); beveledTileAttributeSet = new BeveledTileAttributeSet(colorList, fillPercent); } finally { attributesArray.recycle(); return beveledTileAttributeSet; } }
private void initWithContext(Context context, AttributeSet attrs) { mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); // 根据属性设置参数 if (attrs != null) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.XRefreshView, 0, 0); try { isHeightMatchParent = a.getBoolean(R.styleable.XRefreshView_isHeightMatchParent, true); isWidthMatchParent = a.getBoolean(R.styleable.XRefreshView_isHeightMatchParent, true); autoRefresh = a.getBoolean(R.styleable.XRefreshView_autoRefresh, false); autoLoadMore = a.getBoolean(R.styleable.XRefreshView_autoLoadMore, true); } catch (Exception e) { e.printStackTrace(); } finally { a.recycle(); } } mHeaderView = new XRefreshViewHeader(getContext()); mFooterView = new XRefreshViewFooter(context); this.getViewTreeObserver() .addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { addHeaderView(); addFooterView(this); } }); }
/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse */ private void parseAttributes(TypedArray a) { barWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwBarWidth, barWidth); rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwRimWidth, rimWidth); spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_pwSpinSpeed, spinSpeed); barLength = (int) a.getDimension(R.styleable.ProgressWheel_pwBarLength, barLength); delayMillis = a.getInteger(R.styleable.ProgressWheel_pwDelayMillis, delayMillis); if (delayMillis < 0) { delayMillis = 10; } // Only set the text if it is explicitly defined if (a.hasValue(R.styleable.ProgressWheel_pwText)) { setText(a.getString(R.styleable.ProgressWheel_pwText)); } barColor = a.getColor(R.styleable.ProgressWheel_pwBarColor, barColor); textColor = a.getColor(R.styleable.ProgressWheel_pwTextColor, textColor); rimColor = a.getColor(R.styleable.ProgressWheel_pwRimColor, rimColor); circleColor = a.getColor(R.styleable.ProgressWheel_pwCircleColor, circleColor); contourColor = a.getColor(R.styleable.ProgressWheel_pwContourColor, contourColor); textSize = (int) a.getDimension(R.styleable.ProgressWheel_pwTextSize, textSize); contourSize = a.getDimension(R.styleable.ProgressWheel_pwContourSize, contourSize); a.recycle(); }
public void init(Context context, AttributeSet attrs, int defStyle) { mActiveMediaPlayer = new MediaPlayer(); if (attrs != null) { TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.OnemomentPlayerView, 0, 0); try { mShowPlayBtn = ta.getBoolean(R.styleable.OnemomentPlayerView_showPlayButton, true); mAutoplay = ta.getBoolean(R.styleable.OnemomentPlayerView_autoplay, false); mShowTags = ta.getBoolean(R.styleable.OnemomentPlayerView_showTags, true); } finally { ta.recycle(); } } LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (inflater != null) { inflater.inflate(R.layout.onemoment_player_view, this); } // get views mVideo = (SurfaceView) findViewById(R.id.om_video_surface); mPlayBtn = (ImageView) findViewById(R.id.om_play_btn); mTagsContainer = (VideoTagsContainer) findViewById(R.id.om_tags_container); mHeadsContainer = (LinearLayout) findViewById(R.id.om_heads_container); // add listeners mVideoSurfaceHolder = mVideo.getHolder(); mVideoSurfaceHolder.addCallback(this); mActiveMediaPlayer.setOnCompletionListener(this); }
/** * 获取自定义属性 * * @param attrs */ private void obtainStyledAttributes(AttributeSet attrs) { metrics = getContext().getResources().getDisplayMetrics(); framePadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_FRAME_PADDING, metrics); frameWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_FRAME_WIDTH, metrics); TypedArray mTypedArray = getContext().obtainStyledAttributes(attrs, R.styleable.WaterMarkView); Drawable srcDrawble = mTypedArray.getDrawable(R.styleable.WaterMarkView_src); if (srcDrawble instanceof BitmapDrawable) { BitmapDrawable bd = (BitmapDrawable) srcDrawble; this.mWaterMarkBitmap = bd.getBitmap(); } framePadding = mTypedArray.getDimensionPixelSize(R.styleable.WaterMarkView_framePadding, framePadding); frameWidth = mTypedArray.getDimensionPixelSize(R.styleable.WaterMarkView_frameWidth, frameWidth); frameColor = mTypedArray.getColor(R.styleable.WaterMarkView_frameColor, DEFAULT_FRAME_COLOR); mScale = mTypedArray.getFloat(R.styleable.WaterMarkView_scale, DEFAULT_SCALE); mDegree = mTypedArray.getFloat(R.styleable.WaterMarkView_degree, DEFAULT_DEGREE); controlDrawable = mTypedArray.getDrawable(R.styleable.WaterMarkView_controlDrawable); controlLocation = mTypedArray.getInt(R.styleable.WaterMarkView_controlLocation, DEFAULT_CONTROL_LOCATION); isEditable = mTypedArray.getBoolean(R.styleable.WaterMarkView_editable, DEFAULT_EDITABLE); mTypedArray.recycle(); }
public DashboardViewAttr(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DashboardView, defStyleAttr, 0); mTikeCount = ta.getInt(R.styleable.DashboardView_tikeCount, 48); mTextSize = ta.getDimensionPixelSize( PxUtils.spToPx(R.styleable.DashboardView_android_textSize, context), 24); mText = ta.getString(R.styleable.DashboardView_android_text); // progressHeight = // ta.getInt(PxUtils.dpToPx(R.styleable.DashboardView_progressHeight,context), 20); unit = ta.getString(R.styleable.DashboardView_Unit); textColor = ta.getColor( R.styleable.DashboardView_textColor, context.getResources().getColor(R.color.textColor)); background = ta.getColor(R.styleable.DashboardView_backgroundColor, 0); startColor = ta.getColor(R.styleable.DashboardView_startProgressColor, 0); endColor = ta.getColor(R.styleable.DashboardView_endProgressColor, 0); startNum = ta.getInt(R.styleable.DashboardView_startNumber, 0); maxNum = ta.getInt(R.styleable.DashboardView_maxNumber, 120); padding = ta.getInt(PxUtils.dpToPx(R.styleable.DashboardView_padding, context), 0); progressColor = ta.getColor( R.styleable.DashboardView_progressColor, context.getResources().getColor(R.color.skyblue)); ta.recycle(); }
private void init(AttributeSet attrs, int defStyle) { if (isInEditMode()) return; TypedArray a = getContext() .getTheme() .obtainStyledAttributes(attrs, R.styleable.SVGImageView, defStyle, 0); try { int resourceId = a.getResourceId(R.styleable.SVGImageView_svg, -1); if (resourceId != -1) { setImageResource(resourceId); return; } String url = a.getString(R.styleable.SVGImageView_svg); if (url != null) { Uri uri = Uri.parse(url); if (internalSetImageURI(uri, false)) return; // Last chance, try loading it as an asset filename setImageAsset(url); } } finally { a.recycle(); } }
public MButton(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MTextView, 0, 0); try { txtFont = a.getInteger(R.styleable.MTextView_txtFont, -1); txtTouch = a.getInteger(R.styleable.MTextView_txtTouch, -1); if (txtFont != -1) { Fonts.getIntance(getContext()).setFont(this, txtFont); } if (txtTouch != -1) { CommonAndroid.setAnimationOnClick(this); } } finally { a.recycle(); } try { // ((SkypeApplication) // getContext().getApplicationContext()).setFonts(txtFont, this); } catch (Exception x) { } }
/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse */ private void parseAttributes(TypedArray a) { // We transform the default values from DIP to pixels DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); barWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, barWidth, metrics); rimWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rimWidth, metrics); circleRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, circleRadius, metrics); circleRadius = (int) a.getDimension(R.styleable.ProgressWheel_matProg_circleRadius, circleRadius); fillRadius = a.getBoolean(R.styleable.ProgressWheel_matProg_fillRadius, false); barWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_barWidth, barWidth); rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_rimWidth, rimWidth); float baseSpinSpeed = a.getFloat(R.styleable.ProgressWheel_matProg_spinSpeed, spinSpeed / 360.0f); spinSpeed = baseSpinSpeed * 360; barSpinCycleTime = a.getInt(R.styleable.ProgressWheel_matProg_barSpinCycleTime, (int) barSpinCycleTime); barColor = a.getColor(R.styleable.ProgressWheel_matProg_barColor, barColor); rimColor = a.getColor(R.styleable.ProgressWheel_matProg_rimColor, rimColor); linearProgress = a.getBoolean(R.styleable.ProgressWheel_matProg_linearProgress, false); if (a.getBoolean(R.styleable.ProgressWheel_matProg_progressIndeterminate, false)) { spin(); } // Recycle a.recycle(); }
public WeightProgressBar(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.a = null; this.b = 0.0f; this.c = 0; this.d = 0; this.e = 0; this.f = 0; this.g = 150.0f; this.h = 0.0f; this.i = 0.0f; TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, t.WeightProgressBar); this.b = obtainStyledAttributes.getDimension(0, BitmapDescriptorFactory.HUE_ORANGE); this.c = obtainStyledAttributes.getColor(1, -1); this.e = obtainStyledAttributes.getColor(3, -10919831); this.d = obtainStyledAttributes.getColor(2, -12827569); this.f = obtainStyledAttributes.getColor(4, -8476672); this.g = (float) obtainStyledAttributes.getInteger(5, a.ap); this.h = obtainStyledAttributes.getFloat(6, 0.0f); this.i = obtainStyledAttributes.getFloat(6, 0.0f); obtainStyledAttributes.recycle(); this.a = new Paint(); this.a.setColor(this.e); this.a.setStyle(Style.STROKE); this.a.setStrokeWidth(this.b); this.a.setAntiAlias(true); }
public VerticalCardView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context .getTheme() .obtainStyledAttributes(attrs, R.styleable.com_gabm_fancyplaces_VerticalCardView, 0, 0); try { title = a.getString(R.styleable.com_gabm_fancyplaces_VerticalCardView_card_title); } finally { a.recycle(); } // own settings this.setOrientation(VERTICAL); this.setPadding(30, 30, 30, 30); // text view as title TextView textView = new TextView(context); textView.setText(title); textView.setTextAppearance(context, R.style.TextAppearance_AppCompat_Large); textView.setTypeface(null, Typeface.BOLD); textView.setPadding(0, 20, 0, 10); this.addView(textView); }
public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mDragHelper = ViewDragHelper.create(this, new ViewDragCallback()); TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SwipeBackLayout, defStyle, R.style.SwipeBackLayout); int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1); if (edgeSize > 0) setEdgeSize(edgeSize); int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)]; setEdgeTrackingEnabled(mode); int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, R.drawable.shadow_left); int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, R.drawable.shadow_right); int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, R.drawable.shadow_bottom); setShadow(shadowLeft, EDGE_LEFT); setShadow(shadowRight, EDGE_RIGHT); setShadow(shadowBottom, EDGE_BOTTOM); a.recycle(); final float density = getResources().getDisplayMetrics().density; final float minVel = MIN_FLING_VELOCITY * density; mDragHelper.setMinVelocity(minVel); mDragHelper.setMaxVelocity(minVel * 2f); }
public static Drawable getDrawableFromAttribute(Context ctx, @AttrRes int attr) { int[] attrs = new int[] {attr}; TypedArray ta = ctx.obtainStyledAttributes(attrs); Drawable d = ta.getDrawable(0); ta.recycle(); return d; }
public FloatingMenuLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.CustomFloatingActionMenu, 0, 0); mLabelStyle = attr.getResourceId(R.styleable.CustomFloatingActionMenu_menu_label_style, 0); attr.recycle(); }
public CustomPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomPicker, 0, 0); try { min = typedArray.getInteger(R.styleable.CustomPicker_minValue, 0); max = typedArray.getInteger(R.styleable.CustomPicker_maxValue, 0); digitsNumber = typedArray.getInteger(R.styleable.CustomPicker_digitNumber, 1); incrementValue = typedArray.getInteger(R.styleable.CustomPicker_incrementValue, 1); visibility = typedArray.getInteger(R.styleable.CustomPicker_editTextVisibility, VISIBILITY_VISIBLE); orientation = typedArray.getInteger(R.styleable.CustomPicker_orientation, ORIENTATION_VERTICAL); } finally { typedArray.recycle(); } LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (orientation) { case ORIENTATION_VERTICAL: myPickerView = inflator.inflate(R.layout.picker_control, null); break; case ORIENTATION_HORIZONTAL: myPickerView = inflator.inflate(R.layout.picker_control_horizontal, null); break; } this.addView(myPickerView); initializeReference(); }