/// <summary>Creates a new configuration for the specified context.</summary> /// <remarks> /// Creates a new configuration for the specified context. The configuration depends on /// various parameters of the context, like the dimension of the display or the density /// of the display. /// </remarks> /// <param name="context">The application context used to initialize this view configuration. /// </param> /// <seealso cref="get(android.content.Context)"></seealso> /// <seealso cref="android.util.DisplayMetrics">android.util.DisplayMetrics</seealso> private ViewConfiguration(android.content.Context context) { android.content.res.Resources res = context.getResources(); android.util.DisplayMetrics metrics = res.getDisplayMetrics(); android.content.res.Configuration config = res.getConfiguration(); float density = metrics.density; float sizeAndDensity; if (config.isLayoutSizeAtLeast(android.content.res.Configuration.SCREENLAYOUT_SIZE_XLARGE)) { sizeAndDensity = density * 1.5f; } else { sizeAndDensity = density; } mEdgeSlop = (int)(sizeAndDensity * EDGE_SLOP + 0.5f); mFadingEdgeLength = (int)(sizeAndDensity * FADING_EDGE_LENGTH + 0.5f); mMinimumFlingVelocity = (int)(density * MINIMUM_FLING_VELOCITY + 0.5f); mMaximumFlingVelocity = (int)(density * MAXIMUM_FLING_VELOCITY + 0.5f); mScrollbarSize = (int)(density * SCROLL_BAR_SIZE + 0.5f); mTouchSlop = (int)(sizeAndDensity * TOUCH_SLOP + 0.5f); mPagingTouchSlop = (int)(sizeAndDensity * PAGING_TOUCH_SLOP + 0.5f); mDoubleTapSlop = (int)(sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f); mScaledTouchExplorationTapSlop = (int)(density * TOUCH_EXPLORATION_TAP_SLOP + 0.5f ); mWindowTouchSlop = (int)(sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f); // Size of the screen in bytes, in ARGB_8888 format mMaximumDrawingCacheSize = 4 * metrics.widthPixels * metrics.heightPixels; mOverscrollDistance = (int)(sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f); mOverflingDistance = (int)(sizeAndDensity * OVERFLING_DISTANCE + 0.5f); mFadingMarqueeEnabled = false; }
// do nothing here /// <summary>Decode a new Bitmap from an InputStream.</summary> /// <remarks> /// Decode a new Bitmap from an InputStream. This InputStream was obtained from /// resources, which we pass to be able to scale the bitmap accordingly. /// </remarks> public static android.graphics.Bitmap decodeResourceStream(android.content.res.Resources res, android.util.TypedValue value, java.io.InputStream @is, android.graphics.Rect pad, android.graphics.BitmapFactory.Options opts) { if (opts == null) { opts = new android.graphics.BitmapFactory.Options(); } if (opts.inDensity == 0 && value != null) { int density = value.density; if (density == android.util.TypedValue.DENSITY_DEFAULT) { opts.inDensity = android.util.DisplayMetrics.DENSITY_DEFAULT; } else { if (density != android.util.TypedValue.DENSITY_NONE) { opts.inDensity = density; } } } if (opts.inTargetDensity == 0 && res != null) { opts.inTargetDensity = res.getDisplayMetrics().densityDpi; } return(decodeStream(@is, pad, opts)); }
internal virtual float resolveScale(float scale, int type, int data, int size, int psize) { float targetSize; if (type == android.util.TypedValue.TYPE_FRACTION) { targetSize = android.util.TypedValue.complexToFraction(data, size, psize); } else { if (type == android.util.TypedValue.TYPE_DIMENSION) { targetSize = android.util.TypedValue.complexToDimension(data, mResources.getDisplayMetrics ()); } else { return(scale); } } if (size == 0) { return(1); } return(targetSize / (float)size); }
public MenuPopupHelper(android.content.Context context, [email protected] menu, android.view.View anchorView, bool overflowOnly) { mContext = context; mInflater = android.view.LayoutInflater.from(context); mMenu = menu; mOverflowOnly = overflowOnly; android.content.res.Resources res = context.getResources(); mPopupMaxWidth = System.Math.Max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize ([email protected]_prefDialogWidth)); mAnchorView = anchorView; menu.addMenuPresenter(this); }
internal BitmapDrawable(android.graphics.drawable.BitmapDrawable.BitmapState state , android.content.res.Resources res) { mBitmapState = state; if (res != null) { mTargetDensity = res.getDisplayMetrics().densityDpi; } else { mTargetDensity = state.mTargetDensity; } setBitmap(state != null ? state.mBitmap : null); }
public override void initForMenu(android.content.Context context, [email protected] menu) { base.initForMenu(context, menu); android.content.res.Resources res = context.getResources(); if (!mReserveOverflowSet) { mReserveOverflow = !android.view.ViewConfiguration.get(context).hasPermanentMenuKey (); } if (!mWidthLimitSet) { mWidthLimit = res.getDisplayMetrics().widthPixels / 2; } // Measure for initial configuration if (!mMaxItemsSet) { mMaxItems = res.getInteger([email protected]_action_buttons); } int width = mWidthLimit; if (mReserveOverflow) { if (mOverflowButton == null) { mOverflowButton = new android.view.@internal.menu.ActionMenuPresenter.OverflowMenuButton (this, mSystemContext); int spec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View.MeasureSpec .UNSPECIFIED); mOverflowButton.measure(spec, spec); } width -= mOverflowButton.getMeasuredWidth(); } else { mOverflowButton = null; } mActionItemWidthLimit = width; mMinCellSize = (int)([email protected]_CELL_SIZE * res .getDisplayMetrics().density); // Drop a scrap view as it may no longer reflect the proper context/config. mScrapActionButtonView = null; }
internal void setNinePatchState(android.graphics.drawable.NinePatchDrawable.NinePatchState state, android.content.res.Resources res) { mNinePatchState = state; mNinePatch = state.mNinePatch; mPadding = state.mPadding; mTargetDensity = res != null?res.getDisplayMetrics().densityDpi : state.mTargetDensity; //noinspection PointlessBooleanExpression if (state.mDither != DEFAULT_DITHER) { // avoid calling the setter unless we need to, since it does a // lazy allocation of a paint setDither(state.mDither); } if (mNinePatch != null) { computeBitmapSize(); } }
/// <summary>Create a new instance.</summary> /// <remarks>Create a new instance.</remarks> /// <param name="context">The application environment.</param> /// <param name="attrs">A collection of attributes.</param> /// <param name="defStyle">The default style to apply to this view.</param> public ActivityChooserView(android.content.Context context, android.util.AttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { mModelDataSetOberver = new _DataSetObserver_118(this); mOnGlobalLayoutListener = new _OnGlobalLayoutListener_132(this); android.content.res.TypedArray attributesArray = context.obtainStyledAttributes(attrs , [email protected], defStyle, 0); mInitialActivityCount = attributesArray.getInt([email protected]_initialActivityCount , android.widget.ActivityChooserView.ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT ); android.graphics.drawable.Drawable expandActivityOverflowButtonDrawable = attributesArray .getDrawable([email protected]_expandActivityOverflowButtonDrawable ); attributesArray.recycle(); android.view.LayoutInflater inflater = android.view.LayoutInflater.from(mContext); inflater.inflate([email protected]_chooser_view, this, true); mCallbacks = new android.widget.ActivityChooserView.Callbacks(this); mActivityChooserContent = (android.widget.LinearLayout)findViewById([email protected] .id.activity_chooser_view_content); mActivityChooserContentBackground = mActivityChooserContent.getBackground(); mDefaultActivityButton = (android.widget.FrameLayout)findViewById([email protected] .id.default_activity_button); mDefaultActivityButton.setOnClickListener(mCallbacks); mDefaultActivityButton.setOnLongClickListener(mCallbacks); mDefaultActivityButtonImage = (android.widget.ImageView)mDefaultActivityButton.findViewById ([email protected]); mExpandActivityOverflowButton = (android.widget.FrameLayout)findViewById([email protected] .id.expand_activities_button); mExpandActivityOverflowButton.setOnClickListener(mCallbacks); mExpandActivityOverflowButtonImage = (android.widget.ImageView)mExpandActivityOverflowButton .findViewById([email protected]); mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable ); mAdapter = new android.widget.ActivityChooserView.ActivityChooserViewAdapter(this ); mAdapter.registerDataSetObserver(new _DataSetObserver_239(this)); android.content.res.Resources resources = context.getResources(); mListPopupMaxWidth = System.Math.Max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize([email protected]_prefDialogWidth )); }
/// <summary> /// Construct a new Switch with a default style determined by the given theme attribute, /// overriding specific style attributes as requested. /// </summary> /// <remarks> /// Construct a new Switch with a default style determined by the given theme attribute, /// overriding specific style attributes as requested. /// </remarks> /// <param name="context">The Context that will determine this widget's theming.</param> /// <param name="attrs">Specification of attributes that should deviate from the default styling. /// </param> /// <param name="defStyle"> /// An attribute ID within the active theme containing a reference to the /// default style for this widget. e.g. android.R.attr.switchStyle. /// </param> public Switch(android.content.Context context, android.util.AttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { // Enum for the "typeface" XML parameter. // Does not include padding mTextPaint = new android.text.TextPaint(android.graphics.Paint.ANTI_ALIAS_FLAG); android.content.res.Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; mTextPaint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale); android.content.res.TypedArray a = context.obtainStyledAttributes(attrs, [email protected] .styleable.Switch, defStyle, 0); mThumbDrawable = a.getDrawable([email protected]_thumb); mTrackDrawable = a.getDrawable([email protected]_track); mTextOn = a.getText([email protected]_textOn); mTextOff = a.getText([email protected]_textOff); mThumbTextPadding = a.getDimensionPixelSize([email protected]_thumbTextPadding , 0); mSwitchMinWidth = a.getDimensionPixelSize([email protected]_switchMinWidth , 0); mSwitchPadding = a.getDimensionPixelSize([email protected]_switchPadding , 0); int appearance = a.getResourceId([email protected]_switchTextAppearance , 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } a.recycle(); android.view.ViewConfiguration config = android.view.ViewConfiguration.get(context ); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
public override void inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs) { base.inflate(r, parser, attrs); android.content.res.TypedArray a = r.obtainAttributes(attrs, [email protected]. styleable.BitmapDrawable); int id = a.getResourceId([email protected]_src, 0); if (id == 0) { throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() + ": <bitmap> requires a valid src attribute"); } android.graphics.Bitmap bitmap = android.graphics.BitmapFactory.decodeResource(r, id); if (bitmap == null) { throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() + ": <bitmap> requires a valid src attribute"); } mBitmapState.mBitmap = bitmap; setBitmap(bitmap); setTargetDensity(r.getDisplayMetrics()); android.graphics.Paint paint = mBitmapState.mPaint; paint.setAntiAlias(a.getBoolean([email protected]_antialias , paint.isAntiAlias())); paint.setFilterBitmap(a.getBoolean([email protected]_filter , paint.isFilterBitmap())); paint.setDither(a.getBoolean([email protected]_dither, paint.isDither())); setGravity(a.getInt([email protected]_gravity, android.view.Gravity .FILL)); int tileMode = a.getInt([email protected]_tileMode, -1 ); if (tileMode != -1) { switch (tileMode) { case 0: { setTileModeXY(android.graphics.Shader.TileMode.CLAMP, android.graphics.Shader.TileMode .CLAMP); break; } case 1: { setTileModeXY(android.graphics.Shader.TileMode.REPEAT, android.graphics.Shader.TileMode .REPEAT); break; } case 2: { setTileModeXY(android.graphics.Shader.TileMode.MIRROR, android.graphics.Shader.TileMode .MIRROR); break; } } } a.recycle(); }