public SandboxView(Context context, Bitmap bitmap, MatrixConfig matrixConfig) : base(context) { this.bitmap = bitmap; this.width = bitmap.Width; this.height = bitmap.Height; this.matrixConfig = matrixConfig; if (matrixConfig.transform == null) { matrixConfig.transform = new Matrix(); } SetOnTouchListener(this); }
internal void AfterScroll() { int lastVisisble = layoutManager.FindLastCompletelyVisibleItemPosition(); int firstVisible = layoutManager.FindFirstCompletelyVisibleItemPosition(); if ((lastVisisble - firstVisible) / 2 + firstVisible > ExtraItem - 1) { int e = (lastVisisble - firstVisible) / 2 + firstVisible; for (int i = 0; i < mPhotoAlbum.numPhoto; i++) { if (mPhotoAlbum[i].SelectedId != 0) { mPhotoAlbum[i].SelectedId = 0; mAdapter.NotifyItemChanged(i); } } mPhotoAlbum[e].SelectedId = e; linearButton.SetBackgroundResource(Resource.Drawable.solid_circle_background_trophy); mAdapter.NotifyItemChanged(e); context.LastSelectedIndex = e - ExtraItem; bitmap = mPhotoAlbum[e].bitmap; containerImg.RemoveAllViews(); if (matrixConfig == null) { matrixConfig = new MatrixConfig(); } containerImg.AddView(new SandboxView(Context, bitmap, matrixConfig)); } else { for (int i = 0; i < mPhotoAlbum.numPhoto; i++) { if (mPhotoAlbum[i].SelectedId != 0) { mPhotoAlbum[i].SelectedId = 0; mAdapter.NotifyItemChanged(i); } } linearButton.SetBackgroundResource(Resource.Drawable.trophy_center_selection_circle); containerImg.RemoveAllViews(); context.LastSelectedIndex = -1; if (bitmap != null && !bitmap.IsRecycled) { bitmap = null; GC.Collect(); } } }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); mHandler = new Handler(); progressBarLL = view.FindViewById <LinearLayout>(Resource.Id.LLPleaseWait); progressBarLL.Visibility = ViewStates.Gone; ActionLayout = view.FindViewById <FrameLayout>(Resource.Id.ActionLayout); ActionLayout.Visibility = ViewStates.Gone; mRecycleView = view.FindViewById <RecyclerView>(Resource.Id.recyclerView); linearButton = view.FindViewById <LinearLayout>(Resource.Id.linearButton); linearButton.Enabled = true; mLayoutManager = new CenterLayoutManager(context, LinearLayoutManager.Horizontal, false); mRecycleView.SetLayoutManager(mLayoutManager); mRecycleView.AddOnScrollListener(new CustomScrollListener(this)); buttonFlipcamera = view.FindViewById <Button>(Resource.Id.buttonFlipcamera); BackLobby = view.FindViewById <Button>(Resource.Id.buttonGoLobby); buttonRetake = view.FindViewById <Button>(Resource.Id.buttonRetake); SnapHelper helper = new LinearSnapHelpers(); helper.AttachToRecyclerView(mRecycleView); //logoImageView = (ImageView)view.FindViewById(Resource.Id.logoImageView); //logoImageView.SetOnTouchListener(this); //ViewImage = (View)view.FindViewById(Resource.Id.logoImageView); takenImage = (ImageView)view.FindViewById(Resource.Id.ImageViewtaken); imageLayout = (RelativeLayout)view.FindViewById(Resource.Id.containerTaken); containerImg = (RelativeLayout)view.FindViewById(Resource.Id.containerImg); imageLayout.Visibility = ViewStates.Gone; back = (Button)view.FindViewById(Resource.Id.buttonBack); save = (Button)view.FindViewById(Resource.Id.buttonSave); layoutManager = ((CenterLayoutManager)mRecycleView.GetLayoutManager()); linearButton.Click += delegate { if (bitmap != null) { progressBarLL.Visibility = ViewStates.Visible; context.matrix.Set(matrixConfig.transform); OnCAptureClick(bitmap, linearButton); } }; buttonFlipcamera.Click += (object sender, EventArgs e) => { ChangeCameraFace(true); }; BackLobby.Click += (object sender, EventArgs e) => { BackPressEvent(true); }; buttonRetake.Click += (object sender, EventArgs e) => { imageLayout.Visibility = ViewStates.Gone; ActionLayout.Visibility = ViewStates.Visible; ResetAcitivity(true); containerImg.RemoveAllViews(); if (matrixConfig == null) { matrixConfig = new MatrixConfig(); } containerImg.AddView(new SandboxView(context, bitmap, matrixConfig)); }; back.Click += delegate { BackPressEvent(true); }; save.Click += delegate { if (bitmapToSave == null) { return; } try { MediaStore.Images.Media.InsertImage(context.ContentResolver, bitmapToSave, Long.ToString(JavaSystem.CurrentTimeMillis()) + ".jpg", "Adda52"); } catch (System.Exception e) { Log.Debug("In Saving File", e + ""); } bitmapToSave.Recycle(); bitmapToSave.Dispose(); bitmapToSave = null; System.GC.Collect(); }; Dialog dialog = Dialog; if (dialog != null) { int ScreenHeight = (int)(Resources.DisplayMetrics.HeightPixels); int ScreenWidth = (int)(Resources.DisplayMetrics.WidthPixels); screenWidth = ScreenWidth; screenHeight = ScreenHeight; Window window = Dialog.Window; WindowManagerLayoutParams windowParams = window.Attributes; windowParams.DimAmount = 0.0f; window.Attributes = (windowParams); int actual = Resources.GetDimensionPixelSize(Resource.Dimension.dimen90); int numberofImages = ScreenWidth / actual; int increase = 0; if (numberofImages % 2 == 0) { increase = (numberofImages / 2) + 1; } else { increase = (numberofImages / 2) + 2; } ExtraItem = increase; mPhotoAlbum = new PhotoAlbum(increase, context.BaseContext, TrophyName); mAdapter = new HorizontalTrouphyAdaptor(mPhotoAlbum); ActionLayout.Visibility = ViewStates.Visible; mRecycleView.SetAdapter(mAdapter); mAdapter.ItemClick += (sender, e) => { if (e > ExtraItem - 1 && e - 1 < mPhotoAlbum.numPhoto - ExtraItem) { mRecycleView.SmoothScrollToPosition(e); for (int i = 0; i < mPhotoAlbum.numPhoto; i++) { if (mPhotoAlbum[i].SelectedId != 0) { mPhotoAlbum[i].SelectedId = 0; mAdapter.NotifyItemChanged(i); } } mPhotoAlbum[e].SelectedId = e; linearButton.SetBackgroundResource(Resource.Drawable.solid_circle_background_trophy); mAdapter.NotifyItemChanged(e); context.LastSelectedIndex = e - ExtraItem; bitmap = mPhotoAlbum[e].bitmap; containerImg.RemoveAllViews(); if (matrixConfig == null) { matrixConfig = new MatrixConfig(); } sandboxView = new SandboxView(context, bitmap, matrixConfig); containerImg.AddView(sandboxView); } }; } }
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(); } } } }