Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-217 Resize and rotate object when when placing in stage #5054

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class BrickValues {
//constants Motions
public static final int X_POSITION = 100;
public static final int Y_POSITION = 200;
public static final float ROTATION = 0.0f;
public static final int CHANGE_X_BY = 10;
public static final int CHANGE_Y_BY = 10;
public static final double MOVE_STEPS = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import androidx.fragment.app.Fragment;

import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_BRICK_HASH;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_ROTATION;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_X_TRANSFORM;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_Y_TRANSFORM;
import static org.catrobat.catroid.ui.SpriteActivity.REQUEST_CODE_VISUAL_PLACEMENT;
Expand Down Expand Up @@ -116,6 +117,7 @@ public Intent generateIntentForVisualPlacement(BrickField brickFieldX, BrickFiel
}
intent.putExtra(EXTRA_X_TRANSFORM, xValue);
intent.putExtra(EXTRA_Y_TRANSFORM, yValue);
// intent.putExtra(EXTRA_ROTATION, rotationAngle);

return intent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public class SpriteActivity extends BaseActivity {

public static final String EXTRA_X_TRANSFORM = "X";
public static final String EXTRA_Y_TRANSFORM = "Y";

public static final String EXTRA_ROTATION = "ROTATION";

public static final String EXTRA_TEXT = "TEXT";
public static final String EXTRA_TEXT_COLOR = "TEXT_COLOR";
public static final String EXTRA_TEXT_SIZE = "TEXT_SIZE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import org.catrobat.catroid.io.StorageOperations
import org.catrobat.catroid.merge.ImportProjectHelper
import org.catrobat.catroid.ui.SpriteActivity.EXTRA_X_TRANSFORM
import org.catrobat.catroid.ui.SpriteActivity.EXTRA_Y_TRANSFORM
import org.catrobat.catroid.ui.SpriteActivity.EXTRA_ROTATION
import org.catrobat.catroid.ui.SpriteActivity.REQUEST_CODE_VISUAL_PLACEMENT
import org.catrobat.catroid.ui.recyclerview.dialog.textwatcher.DuplicateInputTextWatcher
import org.catrobat.catroid.ui.recyclerview.fragment.SpriteListFragment
Expand Down Expand Up @@ -214,6 +215,7 @@ class NewSpriteDialogFragment(
val intent = Intent(requireContext(), VisualPlacementActivity()::class.java)
intent.putExtra(EXTRA_X_TRANSFORM, BrickValues.X_POSITION)
intent.putExtra(EXTRA_Y_TRANSFORM, BrickValues.Y_POSITION)
intent.putExtra(EXTRA_ROTATION, BrickValues.ROTATION)
activity?.startActivityForResult(intent, REQUEST_CODE_VISUAL_PLACEMENT)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -75,6 +76,7 @@
import static org.catrobat.catroid.content.Look.ROTATION_STYLE_LEFT_RIGHT_ONLY;
import static org.catrobat.catroid.content.Look.ROTATION_STYLE_NONE;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_BRICK_HASH;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_ROTATION;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_TEXT;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_TEXT_ALIGNMENT;
import static org.catrobat.catroid.ui.SpriteActivity.EXTRA_TEXT_COLOR;
Expand All @@ -100,10 +102,13 @@ public class VisualPlacementActivity extends BaseCastActivity implements View.On
public static final String Y_COORDINATE_BUNDLE_ARGUMENT = "yCoordinate";
public static final String CHANGED_COORDINATES = "changedCoordinates";

public static final String ROTATION_ANGLE_BUNDLE_ARGUMENT = "rotationAngle";

private ProjectManager projectManager;
private FrameLayout frameLayout;
private BitmapFactory.Options bitmapOptions;
private ImageView imageView;
private float rotationAngle = 0.0f;

private float xCoord;
private float yCoord;
Expand Down Expand Up @@ -163,6 +168,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
translateX = extras.getInt(EXTRA_X_TRANSFORM);
translateY = extras.getInt(EXTRA_Y_TRANSFORM);
rotationAngle = extras.getFloat(EXTRA_ROTATION);

if (extras.containsKey(EXTRA_TEXT)) {
isText = true;
text = extras.getString(EXTRA_TEXT);
Expand Down Expand Up @@ -215,10 +222,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
Button rotateLeftButton = findViewById(R.id.rotate_left_button);
Button rotateRightButton = findViewById(R.id.rotate_right_button);

setBackground();
showMovableImageView();

rotateLeftButton.setOnClickListener(v -> {
rotateImage(-90);
});

rotateRightButton.setOnClickListener(v -> {
rotateImage(90);
});


toolbar.bringToFront();
frameLayout.setOnTouchListener(this);
}
Expand Down Expand Up @@ -301,6 +319,7 @@ public void showMovableImageView() {
} else {
imageView.setTranslationX(translateX);
imageView.setTranslationY(-translateY);
imageView.setRotation(rotationAngle);
}
xCoord = translateX * layoutWidthRatio;
yCoord = translateY * layoutHeightRatio;
Expand All @@ -315,6 +334,11 @@ public void showMovableImageView() {
frameLayout.addView(imageView);
}

private void rotateImage(float degrees) {
rotationAngle += degrees;
imageView.setRotation(rotationAngle);
}

private Bitmap convertTextToBitmap() {
Bitmap visualPlacementBitmap;

Expand Down Expand Up @@ -404,6 +428,7 @@ private void finishWithResult() {
extras.putInt(X_COORDINATE_BUNDLE_ARGUMENT, xCoordinate);
extras.putInt(Y_COORDINATE_BUNDLE_ARGUMENT, yCoordinate);
extras.putBoolean(CHANGED_COORDINATES, translateX != xCoordinate || translateY != yCoordinate);
extras.putFloat(ROTATION_ANGLE_BUNDLE_ARGUMENT, rotationAngle);

returnIntent.putExtras(extras);
setResult(Activity.RESULT_OK, returnIntent);
Expand Down
17 changes: 16 additions & 1 deletion catroid/src/main/res/layout/visual_placement_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@
android:layout_height="wrap_content"
android:background="#60002B3B"
app:titleTextAppearance="@color/solid_white" />


<Button
android:id="@+id/rotate_left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:text="Rotate Left" />

<!-- Add Rotate Right Button -->
<Button
android:id="@+id/rotate_right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="Rotate Right" />

</FrameLayout>

</LinearLayout>
Expand Down