List of usage examples for android.content.res TypedArray getString
@Nullable public String getString(@StyleableRes int index)
From source file:android.support.graphics.drawable.AnimatedVectorDrawableCompat.java
@Override public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { if (mDelegateDrawable != null) { DrawableCompat.inflate(mDelegateDrawable, res, parser, attrs, theme); return;/* w ww . jav a2 s . c o m*/ } int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); if (DBG_ANIMATION_VECTOR_DRAWABLE) { Log.v(LOGTAG, "tagName is " + tagName); } if (ANIMATED_VECTOR.equals(tagName)) { final TypedArray a = obtainAttributes(res, theme, attrs, AndroidResources.styleable_AnimatedVectorDrawable); int drawableRes = a.getResourceId(AndroidResources.styleable_AnimatedVectorDrawable_drawable, 0); if (DBG_ANIMATION_VECTOR_DRAWABLE) { Log.v(LOGTAG, "drawableRes is " + drawableRes); } if (drawableRes != 0) { VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(res, drawableRes, theme); vectorDrawable.setAllowCaching(false); vectorDrawable.setCallback(mCallback); if (mAnimatedVectorState.mVectorDrawable != null) { mAnimatedVectorState.mVectorDrawable.setCallback(null); } mAnimatedVectorState.mVectorDrawable = vectorDrawable; } a.recycle(); } else if (TARGET.equals(tagName)) { final TypedArray a = res.obtainAttributes(attrs, AndroidResources.styleable_AnimatedVectorDrawableTarget); final String target = a.getString(AndroidResources.styleable_AnimatedVectorDrawableTarget_name); int id = a.getResourceId(AndroidResources.styleable_AnimatedVectorDrawableTarget_animation, 0); if (id != 0) { if (mContext != null) { Animator objectAnimator = AnimatorInflater.loadAnimator(mContext, id); setupAnimatorsForTarget(target, objectAnimator); } else { throw new IllegalStateException("Context can't be null when inflating" + " animators"); } } a.recycle(); } } eventType = parser.next(); } }
From source file:com.bvhloc.numpicker.widget.NumberPicker.java
public NumberPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mStart = DEFAULT_START;/*from w ww .j a v a2 s. c om*/ mEnd = DEFAULT_END; mCurrent = mStart; boolean vertical = true; int displayedValues = 0; if (attrs != null && !isInEditMode()) { // this crashes in edit mode (?!) TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NumberPicker); mStart = a.getInt(R.styleable.NumberPicker_rangeStart, DEFAULT_START); mEnd = a.getInt(R.styleable.NumberPicker_rangeEnd, DEFAULT_END); mSpeed = a.getInt(R.styleable.NumberPicker_speed, (int) mSpeed); mSpeedUp = mSpeed; mCurrent = a.getInt(R.styleable.NumberPicker_current, mCurrent); mNumColor = a.getColor(R.styleable.NumberPicker_numColor, ContextCompat.getColor(context, android.R.color.primary_text_light)); mNumBackground = a.getDrawable(R.styleable.NumberPicker_numBackground); mNumSize = a.getDimension(R.styleable.NumberPicker_numSize, mNumSize); mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numHorizontalPadding, mNumSize); mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numVeticalPadding, mNumSize); mIncrementDrawable = a.getDrawable(R.styleable.NumberPicker_incrementDrawable); mDecrementDrawable = a.getDrawable(R.styleable.NumberPicker_decrementDrawable); mKeyboardInput = a.getBoolean(R.styleable.NumberPicker_keyboardInput, mKeyboardInput); String orientation = a.getString(R.styleable.NumberPicker_android_orientation); displayedValues = a.getResourceId(R.styleable.NumberPicker_displayedValues, 0); if (orientation != null) { vertical = !"0".equals(orientation); } a.recycle(); } else if (attrs != null && isInEditMode()) { // fix orientation attribute for editor String orientation = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "orientation"); if (orientation != null) { vertical = !"horizontal".equals(orientation); } } // set a wrong orientation so our own orientation method will perform changes super.setOrientation(!vertical ? VERTICAL : HORIZONTAL); setOrientation(vertical ? VERTICAL : HORIZONTAL); mChangeHandler = new Handler(); InputFilter inputFilter = new NumberPickerInputFilter(); mNumberInputFilter = new NumberRangeKeyListener(); mIncrementButton = (NumberPickerButton) findViewById(R.id.increment); mIncrementButton.setOnClickListener(this); mIncrementButton.setOnLongClickListener(this); mIncrementButton.setNumberPicker(this); mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement); mDecrementButton.setOnClickListener(this); mDecrementButton.setOnLongClickListener(this); mDecrementButton.setNumberPicker(this); mIncrementButton.setBackground(null); mDecrementButton.setBackground(null); mIncrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER); mDecrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER); if (mIncrementDrawable != null) { mIncrementButton.setImageDrawable(mIncrementDrawable); } if (mDecrementDrawable != null) { mDecrementButton.setImageDrawable(mDecrementDrawable); } mText = (EditText) findViewById(R.id.timepicker_input); mText.setOnFocusChangeListener(this); mText.setFilters(new InputFilter[] { inputFilter }); mText.setRawInputType(InputType.TYPE_CLASS_NUMBER); LayoutParams params = (LayoutParams) mText.getLayoutParams(); params.weight = 1; mText.setLayoutParams(params); mText.setPadding(mNumHorizontalPadding, mNumVerticalPadding, mNumHorizontalPadding, mNumVerticalPadding); mText.setTextSize(mNumSize); if (mNumBackground != null) { mText.setBackground(mNumBackground); } else { mText.setBackground(ContextCompat.getDrawable(context, android.R.drawable.edit_text)); } if (!mKeyboardInput) { mText.setEnabled(false); } mText.setTextColor(mNumColor); if (!isEnabled()) { setEnabled(false); } if (displayedValues != 0) { setDisplayedRange(mStart, displayedValues); } else { setRange(mStart, mEnd); } }
From source file:com.fuzz.indicator.CutoutViewIndicator.java
@SuppressWarnings("ResourceType") protected void init(Context context, AttributeSet attrs, int defStyleAttr) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CutoutViewIndicator); setIndicatorDrawableId(a.getResourceId(R.styleable.CutoutViewIndicator_rcv_drawable, 0)); setInternalSpacing(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_internal_margin, 0)); // The superclass will have resolved orientation by now. if (getOrientation() == HORIZONTAL) { setPerpendicularLength(//from w w w.ja va 2 s .co m a.getDimensionPixelSize(R.styleable.CutoutViewIndicator_rcv_height, WRAP_CONTENT)); setCellLength(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_width, WRAP_CONTENT)); } else { setPerpendicularLength( a.getDimensionPixelSize(R.styleable.CutoutViewIndicator_rcv_width, WRAP_CONTENT)); setCellLength(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_height, WRAP_CONTENT)); } if (isInEditMode()) { editModePageCount = a.getInteger(R.styleable.CutoutViewIndicator_rcv_tools_indicator_count, 2); } String generatorName = a.getString(R.styleable.CutoutViewIndicator_rcv_generator_class_name); if (generatorName != null) { CCGFactory.constructGeneratorFrom(context, attrs, defStyleAttr, generatorName, new ConstructorCallback() { @Override public void onGenerated(@NonNull CutoutCellGenerator generated) { CutoutViewIndicator.this.generator = generated; } @Override public void onFailed(@NonNull String message) { if (!message.isEmpty()) { Log.e(TAG, message); if (isInEditMode()) { String tag = "resources.invalid"; logger.logToLayoutLib(tag, message); } } } }); } setCellBackgroundId(a.getResourceId(R.styleable.CutoutViewIndicator_rcv_drawable_unselected, 0)); a.recycle(); } if (isInEditMode()) { setStateProxy(EDIT_MODE_PROXY); } }
From source file:com.community.yuequ.bottombar.BottomBar.java
private void populateAttributes(Context context, AttributeSet attrs) { primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary); screenWidth = MiscUtils.getScreenWidth(getContext()); tenDp = MiscUtils.dpToPixel(getContext(), 10); maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0); try {/*from w w w . jav a 2s . c o m*/ tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0); isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false); behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE); inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha, isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1); activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1); @ColorInt int defaultInActiveColor = isShiftingMode() ? Color.WHITE : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor); int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor; inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor); activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor); badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED); titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0); titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace)); showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true); } finally { ta.recycle(); } }
From source file:com.gigamole.library.NavigationTabBar.java
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB// www .ja v a2 s . c o m // Always draw setWillNotDraw(false); // More speed! setLayerType(LAYER_TYPE_HARDWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false)); setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false)); setIsBadgeUseTypeface( typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false)); setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, ALL_INDEX)); setBadgePosition(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, RIGHT_INDEX)); setBadgeGravity(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, TOP_INDEX)); setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0f)); // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); // Set preview models if (isInEditMode()) { // Get preview colors String[] previewColors = null; try { final int previewColorsId = typedArray .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0); previewColors = previewColorsId == 0 ? null : typedArray.getResources().getStringArray(previewColorsId); } catch (Exception exception) { previewColors = null; exception.printStackTrace(); } finally { if (previewColors == null) previewColors = typedArray.getResources().getStringArray(R.array.default_preview); for (String previewColor : previewColors) mModels.add(new Model(null, Color.parseColor(previewColor))); requestLayout(); } } } finally { typedArray.recycle(); } }
From source file:com.waz.zclient.views.images.CircularSeekBar.java
/** * Initialize the CircularSeekBar with the attributes from the XML style. * Uses the defaults defined at the top of this file when an attribute is not specified by the user. * * @param attrArray TypedArray containing the attributes. *//*from w w w. j av a 2s.c om*/ protected void initAttributes(TypedArray attrArray) { circleXRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_x_radius, DEFAULT_CIRCLE_X_RADIUS * dpToPxScale); circleYRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_y_radius, DEFAULT_CIRCLE_Y_RADIUS * dpToPxScale); pointerRadius = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_radius, DEFAULT_POINTER_RADIUS * dpToPxScale); pointerHaloWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_width, DEFAULT_POINTER_HALO_WIDTH * dpToPxScale); pointerHaloBorderWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_border_width, DEFAULT_POINTER_HALO_BORDER_WIDTH * dpToPxScale); circleStrokeWidth = attrArray.getDimension(R.styleable.CircularSeekBar_circle_stroke_width, DEFAULT_CIRCLE_STROKE_WIDTH * dpToPxScale); String tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_color); if (tempColor != null) { try { pointerColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { pointerColor = DEFAULT_POINTER_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color); if (tempColor != null) { try { pointerHaloColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { pointerHaloColor = DEFAULT_POINTER_HALO_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color_ontouch); if (tempColor != null) { try { pointerHaloColorOnTouch = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { pointerHaloColorOnTouch = DEFAULT_POINTER_HALO_COLOR_ONTOUCH; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_color); if (tempColor != null) { try { circleColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { circleColor = DEFAULT_CIRCLE_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_progress_color); if (tempColor != null) { try { circleProgressColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { circleProgressColor = DEFAULT_CIRCLE_PROGRESS_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_fill); if (tempColor != null) { try { circleFillColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { circleFillColor = DEFAULT_CIRCLE_FILL_COLOR; } } pointerAlpha = Color.alpha(pointerHaloColor); pointerAlphaOnTouch = attrArray.getInt(R.styleable.CircularSeekBar_pointer_alpha_ontouch, DEFAULT_POINTER_ALPHA_ONTOUCH); if (pointerAlphaOnTouch > 255 || pointerAlphaOnTouch < 0) { pointerAlphaOnTouch = DEFAULT_POINTER_ALPHA_ONTOUCH; } max = attrArray.getInt(R.styleable.CircularSeekBar_max, DEFAULT_MAX); progress = attrArray.getInt(R.styleable.CircularSeekBar_progress, DEFAULT_PROGRESS); customRadii = attrArray.getBoolean(R.styleable.CircularSeekBar_use_custom_radii, DEFAULT_USE_CUSTOM_RADII); maintainEqualCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_maintain_equal_circle, DEFAULT_MAINTAIN_EQUAL_CIRCLE); moveOutsideCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_move_outside_circle, DEFAULT_MOVE_OUTSIDE_CIRCLE); // Modulo 360 right now to avoid constant conversion startAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_start_angle), DEFAULT_START_ANGLE) % 360f)) % 360f); endAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_end_angle), DEFAULT_END_ANGLE) % 360f)) % 360f); if (MathUtils.floatEqual(startAngle, endAngle)) { //startAngle = startAngle + 1f; endAngle = endAngle - .1f; } final GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (onArtClickListener != null) { onArtClickListener.onSingleClick(); return true; } return false; } @Override public boolean onDoubleTap(MotionEvent e) { if (onArtClickListener != null) { onArtClickListener.onDoubleClick(); } return super.onDoubleTap(e); } @Override public void onLongPress(MotionEvent e) { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); if (onArtLongClickListener != null) { onArtLongClickListener.onLongClick(CircularSeekBar.this); } } }; gestureDetector = new GestureDetectorCompat(getContext(), gestureListener); gestureDetector.setOnDoubleTapListener(gestureListener); }
From source file:talex.zsw.baselibrary.widget.NavigationTabBar.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB//from w w w . jav a 2 s. co m // Always draw setWillNotDraw(false); // More speed! setLayerType(LAYER_TYPE_HARDWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, false)); setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false)); setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false)); setIsBadgeUseTypeface( typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false)); setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, ALL_INDEX)); setBadgePosition(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, RIGHT_INDEX)); setBadgeGravity(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, TOP_INDEX)); setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0f)); // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); // Set preview models if (isInEditMode()) { // Get preview colors String[] previewColors = null; try { final int previewColorsId = typedArray .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0); previewColors = previewColorsId == 0 ? null : typedArray.getResources().getStringArray(previewColorsId); } catch (Exception exception) { previewColors = null; exception.printStackTrace(); } finally { if (previewColors == null) { previewColors = typedArray.getResources().getStringArray(R.array.default_preview); } for (String previewColor : previewColors) { mModels.add(new Model(null, Color.parseColor(previewColor))); } requestLayout(); } } } finally { typedArray.recycle(); } }
From source file:bottombar.BottomBar.java
private void populateAttributes(Context context, AttributeSet attrs) { primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary); screenWidth = MiscUtils.getScreenWidth(getContext()); tenDp = MiscUtils.dpToPixel(getContext(), 10); maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0); try {//from w w w . j av a 2 s . c o m tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0); isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false); behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE); inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha, isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1); activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1); @ColorInt int defaultInActiveColor = isShiftingMode() ? Color.WHITE : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor); int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor; inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor); activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor); badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED); hideBadgeWhenActive = ta.getBoolean(R.styleable.BottomBar_bb_badgesHideWhenActive, true); titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0); titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace)); showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true); } finally { ta.recycle(); } }
From source file:android.app.FragmentManager.java
@Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { if (!"fragment".equals(name)) { return null; }/*from w ww . j a v a2 s . c o m*/ String fname = attrs.getAttributeValue(null, "class"); TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment); if (fname == null) { fname = a.getString(com.android.internal.R.styleable.Fragment_name); } int id = a.getResourceId(com.android.internal.R.styleable.Fragment_id, View.NO_ID); String tag = a.getString(com.android.internal.R.styleable.Fragment_tag); a.recycle(); int containerId = parent != null ? parent.getId() : 0; if (containerId == View.NO_ID && id == View.NO_ID && tag == null) { throw new IllegalArgumentException(attrs.getPositionDescription() + ": Must specify unique android:id, android:tag, or have a parent with" + " an id for " + fname); } // If we restored from a previous state, we may already have // instantiated this fragment from the state and should use // that instance instead of making a new one. Fragment fragment = id != View.NO_ID ? findFragmentById(id) : null; if (fragment == null && tag != null) { fragment = findFragmentByTag(tag); } if (fragment == null && containerId != View.NO_ID) { fragment = findFragmentById(containerId); } if (FragmentManagerImpl.DEBUG) Log.v(TAG, "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment); if (fragment == null) { fragment = Fragment.instantiate(context, fname); fragment.mFromLayout = true; fragment.mFragmentId = id != 0 ? id : containerId; fragment.mContainerId = containerId; fragment.mTag = tag; fragment.mInLayout = true; fragment.mFragmentManager = this; fragment.onInflate(mActivity, attrs, fragment.mSavedFragmentState); addFragment(fragment, true); } else if (fragment.mInLayout) { // A fragment already exists and it is not one we restored from // previous state. throw new IllegalArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x" + Integer.toHexString(id) + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId) + " with another fragment for " + fname); } else { // This fragment was retained from a previous instance; get it // going now. fragment.mInLayout = true; // If this fragment is newly instantiated (either right now, or // from last saved state), then give it the attributes to // initialize itself. if (!fragment.mRetaining) { fragment.onInflate(mActivity, attrs, fragment.mSavedFragmentState); } } // If we haven't finished entering the CREATED state ourselves yet, // push the inflated child fragment along. if (mCurState < Fragment.CREATED && fragment.mFromLayout) { moveToState(fragment, Fragment.CREATED, 0, 0, false); } else { moveToState(fragment); } if (fragment.mView == null) { throw new IllegalStateException("Fragment " + fname + " did not create a view."); } if (id != 0) { fragment.mView.setId(id); } if (fragment.mView.getTag() == null) { fragment.mView.setTag(tag); } return fragment.mView; }
From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java
public SubsamplingScaleImageView(Context context, AttributeSet attr) { super(context, attr); setMinimumDpi(160);/* ww w . j ava 2 s . c o m*/ setDoubleTapZoomDpi(160); setGestureDetector(context); this.handler = new Handler(new Handler.Callback() { public boolean handleMessage(Message message) { if (message.what == MESSAGE_LONG_CLICK && onLongClickListener != null) { maxTouchCount = 0; SubsamplingScaleImageView.super.setOnLongClickListener(onLongClickListener); performLongClick(); SubsamplingScaleImageView.super.setOnLongClickListener(null); } return true; } }); // Handle XML attributes if (attr != null) { TypedArray typedAttr = getContext().obtainStyledAttributes(attr, R.styleable.SubsamplingScaleImageView); if (typedAttr.hasValue(R.styleable.SubsamplingScaleImageView_assetName)) { String assetName = typedAttr.getString(R.styleable.SubsamplingScaleImageView_assetName); if (assetName != null && assetName.length() > 0) { setImageAsset(assetName); } } if (typedAttr.hasValue(R.styleable.SubsamplingScaleImageView_panEnabled)) { setPanEnabled(typedAttr.getBoolean(R.styleable.SubsamplingScaleImageView_panEnabled, true)); } if (typedAttr.hasValue(R.styleable.SubsamplingScaleImageView_zoomEnabled)) { setZoomEnabled(typedAttr.getBoolean(R.styleable.SubsamplingScaleImageView_zoomEnabled, true)); } } }