コード例 #1
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            PhotoViewHolder vh = holder as PhotoViewHolder;

            if (mPhotoAlbum[position].mPhotoID == 0)
            {
                vh.imageView.SetImageResource(mPhotoAlbum[position].mPhotoID);
            }
            else
            {
                vh.imageView.SetImageBitmap(mPhotoAlbum[position].bitmap);
            }
            if (mPhotoAlbum[position].mPhotoID != 0)
            {
                vh.imageView.SetBackgroundResource(Resource.Drawable.circle_background_trophy);
            }
            else
            {
                vh.imageView.SetBackgroundResource(Resource.Drawable.circle_background_trophy_clear);
            }
            if (mPhotoAlbum[position].SelectedId != 0)
            {
                vh.imageView.SetBackgroundResource(Resource.Drawable.circle_background_trophy_clear);
            }
            switch (TrophyCameraActivity.tempOrientRounded)
            {
            case 1:
                vh.imageView.Rotation = 0;
                break;

            case 2:
                vh.imageView.Rotation = -90;
                break;

            case 3:
                vh.imageView.Rotation = -180;
                break;

            case 4:
                vh.imageView.Rotation = 90;
                break;
            }
        }
コード例 #2
0
        public void OnSensorChanged(SensorEvent e)
        {
            Log.Debug("TROPHY", "Sensor Changed");
            neglectCount++;
            if (neglectCount < 7)
            {
                return;
            }
            neglectCount = 0;
            var   values      = e.Values;
            int   orientation = ORIENTATION_UNKNOWN;
            float X           = -values[_DATA_X];
            float Y           = -values[_DATA_Y];
            float Z           = -values[_DATA_Z];
            float magnitude   = X * X + Y * Y;

            // Don't trust the angle if the magnitude is small compared to the y value
            if (magnitude * 4 >= Z * Z)
            {
                float OneEightyOverPi = 57.29577957855f;
                float angle           = (float)Java.Lang.Math.Atan2(-Y, X) * OneEightyOverPi;
                orientation = 90 - (int)Java.Lang.Math.Round(angle);
                // normalize to 0 - 359 range
                while (orientation >= 360)
                {
                    orientation -= 360;
                }
                while (orientation < 0)
                {
                    orientation += 360;
                }
            }
            //^^ thanks to google for that code
            //now we must figure out which orientation based on the degrees
            Log.Debug("Oreination", "" + orientation);
            if (orientation != mOrientationDeg)
            {
                mOrientationDeg = orientation;
                //figure out actual orientation
                if (orientation == -1)
                {    //basically flat
                }
                else if (orientation <= 45 || orientation > 315)
                {                          //round to 0
                    tempOrientRounded = 1; //portrait
                }
                else if (orientation > 45 && orientation <= 135)
                {                          //round to 90
                    tempOrientRounded = 2; //lsleft
                }
                else if (orientation > 135 && orientation <= 225)
                {                          //round to 180
                    tempOrientRounded = 3; //upside down
                }
                else if (orientation > 225 && orientation <= 315)
                {                          //round to 270
                    tempOrientRounded = 4; //lsright
                }
            }

            if (mOrientationRounded != tempOrientRounded)
            {
                mOrientationRounded = tempOrientRounded;
                int viewsIds = TrophyFragment.layoutManager.FindLastCompletelyVisibleItemPosition();
                int angle    = 0;
                switch (TrophyCameraActivity.tempOrientRounded)
                {
                case 1:
                    trophyFragment.back.Rotation = trophyFragment.save.Rotation = trophyFragment.buttonFlipcamera.Rotation = trophyFragment.BackLobby.Rotation = trophyFragment.buttonRetake.Rotation = trophyFragment.BackLobby.Rotation = 0;
                    angle = 0;
                    break;

                case 2:
                    trophyFragment.back.Rotation = trophyFragment.save.Rotation = trophyFragment.buttonFlipcamera.Rotation = trophyFragment.BackLobby.Rotation = trophyFragment.buttonRetake.Rotation = trophyFragment.BackLobby.Rotation = -90;
                    angle = -90;
                    break;

                case 3:
                    trophyFragment.back.Rotation = trophyFragment.save.Rotation = trophyFragment.buttonFlipcamera.Rotation = trophyFragment.BackLobby.Rotation = trophyFragment.buttonRetake.Rotation = trophyFragment.BackLobby.Rotation = -180;
                    angle = -180;
                    break;

                case 4:
                    trophyFragment.back.Rotation = trophyFragment.save.Rotation = trophyFragment.buttonFlipcamera.Rotation = trophyFragment.BackLobby.Rotation = trophyFragment.buttonRetake.Rotation = trophyFragment.BackLobby.Rotation = 90;
                    angle = 90;
                    break;
                }
                for (int i = 0; i <= viewsIds + 1; i++)
                {
                    PhotoViewHolder firstViewHolder = (PhotoViewHolder)trophyFragment.mRecycleView.FindViewHolderForLayoutPosition(i);
                    if (firstViewHolder != null)
                    {
                        firstViewHolder.imageView.Rotation = angle;
                    }
                }
                if (TrophyFragment.sandboxView != null)
                {
                    MatrixConfig matrixConfig = TrophyFragment.sandboxView.matrixConfig;
                    System.Console.WriteLine("matrixConfig.angle:" + matrixConfig.angle + " angle:" + angle);
                    if (System.Math.Abs(matrixConfig.angle - (float)angle) > 0)
                    {
                        matrixConfig.angle = (float)(angle * (System.Math.PI / 180));
                        TrophyFragment.sandboxView.Invalidate();
                    }
                }
            }
        }