Beispiel #1
0
            public SimulationView(AccelerometerPlayActivity context)
                : base(context)
            {
                activity        = context;
                mParticleSystem = new ParticleSystem(this);
                mAccelerometer  = activity.mSensorManager.GetDefaultSensor(Sensor.TYPE_ACCELEROMETER);

                var metrics = new DisplayMetrics();

                activity.WindowManager.DefaultDisplay.GetMetrics(metrics);
                mXDpi            = metrics.Xdpi;
                mYDpi            = metrics.Ydpi;
                mMetersToPixelsX = mXDpi / 0.0254f;
                mMetersToPixelsY = mYDpi / 0.0254f;

                // rescale the ball so it's about 0.5 cm on screen
                var ball      = BitmapFactory.DecodeResource(Resources, R.Drawable.ball);
                var dstWidth  = (int)(sBallDiameter * mMetersToPixelsX + 0.5f);
                var dstHeight = (int)(sBallDiameter * mMetersToPixelsY + 0.5f);

                mBitmap = Bitmap.CreateScaledBitmap(ball, dstWidth, dstHeight, true);

                var opts = new BitmapFactory.Options();

                opts.InDither          = true;
                opts.InPreferredConfig = Bitmap.Config.RGB_565;
                mWood = BitmapFactory.DecodeResource(Resources, R.Drawable.wood, opts);
            }
            public SimulationView(AccelerometerPlayActivity context)
                : base(context)
            {
                activity = context;
                mParticleSystem = new ParticleSystem(this);
                mAccelerometer = activity.mSensorManager.GetDefaultSensor(Sensor.TYPE_ACCELEROMETER);

                var metrics = new DisplayMetrics();
                activity.WindowManager.GetDefaultDisplay().GetMetrics(metrics);
                mXDpi = metrics.Xdpi;
                mYDpi = metrics.Ydpi;
                mMetersToPixelsX = mXDpi / 0.0254f;
                mMetersToPixelsY = mYDpi / 0.0254f;

                // rescale the ball so it's about 0.5 cm on screen
                var ball = BitmapFactory.DecodeResource(Resources, R.Drawables.ball);
                var dstWidth = (int)(sBallDiameter * mMetersToPixelsX + 0.5f);
                var dstHeight = (int)(sBallDiameter * mMetersToPixelsY + 0.5f);
                mBitmap = Bitmap.CreateScaledBitmap(ball, dstWidth, dstHeight, true);

                var opts = new BitmapFactory.Options();
                opts.InDither = true;
                opts.InPreferredConfig = Bitmap.Config.RGB_565;
                mWood = BitmapFactory.DecodeResource(Resources, R.Drawables.wood, opts);
            }