Esempio n. 1
0
        /// <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;
        }
Esempio n. 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;
			}
		}