示例#1
0
        /// <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());
        }
示例#2
0
		/// <summary>Creates the top level Resources for applications with the given compatibility info.
		/// 	</summary>
		/// <remarks>Creates the top level Resources for applications with the given compatibility info.
		/// 	</remarks>
		/// <param name="resDir">the resource directory.</param>
		/// <param name="compInfo">
		/// the compability info. It will use the default compatibility info when it's
		/// null.
		/// </param>
		internal android.content.res.Resources getTopLevelResources(string resDir, android.content.res.CompatibilityInfo
			 compInfo)
		{
			android.app.ActivityThread.ResourcesKey key = new android.app.ActivityThread.ResourcesKey
				(resDir, compInfo.applicationScale);
			android.content.res.Resources r;
			lock (mPackages)
			{
				// Resources is app scale dependent.
				if (false)
				{
					android.util.Slog.w(TAG, "getTopLevelResources: " + resDir + " / " + compInfo.applicationScale
						);
				}
				[email protected]<android.content.res.Resources> wr = mActiveResources
					.get(key);
				r = wr != null ? wr.get() : null;
				//if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate());
				if (r != null && r.getAssets().isUpToDate())
				{
					if (false)
					{
						android.util.Slog.w(TAG, "Returning cached resources " + r + " " + resDir + ": appScale="
							 + r.getCompatibilityInfo().applicationScale);
					}
					return r;
				}
			}
			//if (r != null) {
			//    Slog.w(TAG, "Throwing away out-of-date resources!!!! "
			//            + r + " " + resDir);
			//}
			android.content.res.AssetManager assets = new android.content.res.AssetManager();
			if (assets.addAssetPath(resDir) == 0)
			{
				return null;
			}
			//Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
			android.util.DisplayMetrics metrics = getDisplayMetricsLocked(null, false);
			r = new android.content.res.Resources(assets, metrics, getConfiguration(), compInfo
				);
			if (false)
			{
				android.util.Slog.i(TAG, "Created app resources " + resDir + " " + r + ": " + r.getConfiguration
					() + " appScale=" + r.getCompatibilityInfo().applicationScale);
			}
			lock (mPackages)
			{
				[email protected]<android.content.res.Resources> wr = mActiveResources
					.get(key);
				android.content.res.Resources existing = wr != null ? wr.get() : null;
				if (existing != null && existing.getAssets().isUpToDate())
				{
					// Someone else already created the resources while we were
					// unlocked; go ahead and use theirs.
					r.getAssets().close();
					return existing;
				}
				// XXX need to remove entries when weak references go away
				mActiveResources.put(key, new [email protected]<android.content.res.Resources
					>(r));
				return r;
			}
		}
示例#3
0
		internal void init(android.app.LoadedApk packageInfo, android.os.IBinder activityToken
			, android.app.ActivityThread mainThread, android.content.res.Resources container
			, string basePackageName)
		{
			mPackageInfo = packageInfo;
			mBasePackageName = basePackageName != null ? basePackageName : packageInfo.mPackageName;
			mResources = mPackageInfo.getResources(mainThread);
			if (mResources != null && container != null && container.getCompatibilityInfo().applicationScale
				 != mResources.getCompatibilityInfo().applicationScale)
			{
				mResources = mainThread.getTopLevelResources(mPackageInfo.getResDir(), container.
					getCompatibilityInfo());
			}
			mMainThread = mainThread;
			mContentResolver = new android.app.ContextImpl.ApplicationContentResolver(this, mainThread
				);
			setActivityToken(activityToken);
		}