-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce add local actor and object (#5022)
- Loading branch information
Showing
14 changed files
with
460 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
catroid/src/main/java/org/catrobat/catroid/ui/controller/ActorsAndObjectsManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Catroid: An on-device visual programming system for Android devices | ||
* Copyright (C) 2010-2023 The Catrobat Team | ||
* (<http://developer.catrobat.org/credits>) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* An additional term exception under section 7 of the GNU Affero | ||
* General Public License, version 3, is available at | ||
* http://developer.catrobat.org/license_additional_term | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.catrobat.catroid.ui.controller; | ||
|
||
import org.catrobat.catroid.ProjectManager; | ||
import org.catrobat.catroid.R; | ||
import org.catrobat.catroid.common.FlavoredConstants; | ||
import org.catrobat.catroid.common.LookData; | ||
import org.catrobat.catroid.content.Script; | ||
import org.catrobat.catroid.content.Sprite; | ||
import org.catrobat.catroid.content.StartScript; | ||
import org.catrobat.catroid.content.bricks.MoveNStepsBrick; | ||
import org.catrobat.catroid.content.bricks.PenDownBrick; | ||
import org.catrobat.catroid.content.bricks.PlaceAtBrick; | ||
import org.catrobat.catroid.content.bricks.RepeatBrick; | ||
import org.catrobat.catroid.content.bricks.RepeatUntilBrick; | ||
import org.catrobat.catroid.content.bricks.SetTransparencyBrick; | ||
import org.catrobat.catroid.content.bricks.TurnRightBrick; | ||
import org.catrobat.catroid.io.ResourceImporter; | ||
import org.catrobat.catroid.ui.settingsfragments.SettingsFragment; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import static org.catrobat.catroid.common.Constants.DEFAULT_IMAGE_EXTENSION; | ||
import static org.catrobat.catroid.common.Constants.IMAGE_DIRECTORY_NAME; | ||
|
||
public final class ActorsAndObjectsManager { | ||
|
||
private static ActorsAndObjectsManager instance = null; | ||
public static ActorsAndObjectsManager getInstance() { | ||
if (instance == null) { | ||
instance = new ActorsAndObjectsManager(); | ||
} | ||
return instance; | ||
} | ||
|
||
private ActorsAndObjectsManager() { | ||
} | ||
|
||
private Sprite generateSprite(String name, int imgId, double scale) throws IOException { | ||
var sprite = new Sprite(name); | ||
var folder = new File(FlavoredConstants.DEFAULT_ROOT_DIRECTORY, IMAGE_DIRECTORY_NAME); | ||
if(!folder.exists()) | ||
folder.mkdirs(); | ||
var path = | ||
ResourceImporter.createImageFileFromResourcesInDirectory(ProjectManager.getInstance().getApplicationContext().getResources(), | ||
imgId, | ||
folder, | ||
"img" + DEFAULT_IMAGE_EXTENSION, | ||
scale); | ||
var lookData = new LookData(name, path); | ||
sprite.getLookList().add(lookData); | ||
|
||
return sprite; | ||
} | ||
|
||
public List<Sprite> getSprites() { | ||
var sprites = new ArrayList<Sprite>(); | ||
|
||
try { | ||
if(SettingsFragment.isEmroiderySharedPreferenceEnabled(ProjectManager.getInstance().getApplicationContext())){ | ||
var frame = generateSprite("10x10", R.drawable.frame, 1.0); | ||
var script = new StartScript(); | ||
script.addBrick(new SetTransparencyBrick(100.0)); | ||
script.addBrick(new PlaceAtBrick(-250, 250)); | ||
script.addBrick(new PenDownBrick()); | ||
for (int i = 0; i < 4; i++) { | ||
script.addBrick(new MoveNStepsBrick(500)); | ||
script.addBrick(new TurnRightBrick(90)); | ||
} | ||
frame.addScript(script); | ||
sprites.add(frame); | ||
|
||
sprites.add(generateSprite("Needle", R.drawable.plotter, 0.2)); | ||
} else { | ||
sprites.add(generateSprite("Plotter", R.drawable.plotter, 0.2)); | ||
sprites.add(generateSprite("PandaA", R.drawable.panda_a, 1.0)); | ||
sprites.add(generateSprite("PandaB", R.drawable.panda_b, 1.0)); | ||
sprites.add(generateSprite("Apple", R.drawable.apple, 1.0)); | ||
sprites.add(generateSprite("LynxA", R.drawable.lynx_a, 1.0)); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return sprites; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...d/src/main/java/org/catrobat/catroid/ui/recyclerview/backpack/ActorAndObjectActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Catroid: An on-device visual programming system for Android devices | ||
* Copyright (C) 2010-2022 The Catrobat Team | ||
* (<http://developer.catrobat.org/credits>) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* An additional term exception under section 7 of the GNU Affero | ||
* General Public License, version 3, is available at | ||
* http://developer.catrobat.org/license_additional_term | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.catrobat.catroid.ui.recyclerview.backpack; | ||
|
||
import android.graphics.Color; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.os.Bundle; | ||
import android.view.Menu; | ||
|
||
import org.catrobat.catroid.R; | ||
import org.catrobat.catroid.ui.BaseActivity; | ||
|
||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.fragment.app.FragmentTransaction; | ||
|
||
public class ActorAndObjectActivity extends BaseActivity { | ||
|
||
public static final String TAG = ActorAndObjectActivity.class.getSimpleName(); | ||
|
||
public static final String EXTRA_FRAGMENT_POSITION = "fragmentPosition"; | ||
public static final int FRAGMENT_SPRITES = 0; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
setContentView(R.layout.activity_recycler_backpack); | ||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); | ||
getSupportActionBar().setTitle(R.string.actor_object_title); | ||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#83B3C7"))); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
switchToFragment(); | ||
} | ||
|
||
private void switchToFragment() { | ||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | ||
fragmentTransaction.replace(R.id.fragment_container, new ActorAndObjectSpriteFragment(), ActorAndObjectSpriteFragment.TAG); | ||
fragmentTransaction.commit(); | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
...ava/org/catrobat/catroid/ui/recyclerview/backpack/ActorAndObjectRecyclerViewFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Catroid: An on-device visual programming system for Android devices | ||
* Copyright (C) 2010-2022 The Catrobat Team | ||
* (<http://developer.catrobat.org/credits>) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* An additional term exception under section 7 of the GNU Affero | ||
* General Public License, version 3, is available at | ||
* http://developer.catrobat.org/license_additional_term | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.catrobat.catroid.ui.recyclerview.backpack; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import org.catrobat.catroid.R; | ||
import org.catrobat.catroid.ui.recyclerview.adapter.ExtendedRVAdapter; | ||
import org.catrobat.catroid.ui.recyclerview.adapter.RVAdapter; | ||
import org.catrobat.catroid.ui.recyclerview.adapter.draganddrop.TouchHelperCallback; | ||
import org.catrobat.catroid.ui.recyclerview.adapter.multiselection.MultiSelectionManager; | ||
import org.catrobat.catroid.ui.recyclerview.viewholder.CheckableViewHolder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import androidx.annotation.PluralsRes; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.recyclerview.widget.ItemTouchHelper; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
public abstract class ActorAndObjectRecyclerViewFragment<T> extends Fragment implements | ||
RVAdapter.OnItemClickListener<T> { | ||
|
||
protected View parentView; | ||
protected RecyclerView recyclerView; | ||
|
||
protected ExtendedRVAdapter<T> adapter; | ||
|
||
protected String sharedPreferenceDetailsKey = ""; | ||
public boolean hasDetails = false; | ||
|
||
protected ItemTouchHelper touchHelper; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
parentView = inflater.inflate(R.layout.fragment_list_view, container, false); | ||
recyclerView = parentView.findViewById(R.id.recycler_view); | ||
setHasOptionsMenu(false); | ||
|
||
return parentView; | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(Bundle savedInstance) { | ||
super.onActivityCreated(savedInstance); | ||
initializeAdapter(); | ||
} | ||
|
||
public void onAdapterReady() { | ||
recyclerView.setAdapter(adapter); | ||
|
||
adapter.setOnItemClickListener(this); | ||
adapter.showRipples = false; | ||
adapter.showSettings = false; | ||
adapter.showDetails = false; | ||
setHasOptionsMenu(false); | ||
adapter.notifyDataSetChanged(); | ||
|
||
ItemTouchHelper.Callback callback = new TouchHelperCallback(adapter); | ||
touchHelper = new ItemTouchHelper(callback); | ||
touchHelper.attachToRecyclerView(recyclerView); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
adapter.notifyDataSetChanged(); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
super.onStop(); | ||
finishActionMode(); | ||
} | ||
|
||
@Override | ||
public void onPrepareOptionsMenu(Menu menu) { | ||
super.onPrepareOptionsMenu(menu); | ||
} | ||
|
||
protected void finishActionMode() { | ||
adapter.clearSelection(); | ||
setShowProgressBar(false); | ||
} | ||
|
||
@Override | ||
public void onItemClick(final T item, MultiSelectionManager selectionManager) { | ||
unpackItems(new ArrayList<>(Collections.singletonList(item))); | ||
|
||
} | ||
|
||
public void setShowProgressBar(boolean show) { | ||
parentView.findViewById(R.id.progress_bar).setVisibility(show ? View.VISIBLE : View.GONE); | ||
recyclerView.setVisibility(show ? View.GONE : View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void onItemLongClick(T item, CheckableViewHolder holder) { | ||
onItemClick(item, null); | ||
} | ||
|
||
@Override | ||
public void onSettingsClick(T item, View view) { | ||
|
||
} | ||
|
||
protected abstract void initializeAdapter(); | ||
|
||
protected abstract void unpackItems(List<T> selectedItems); | ||
|
||
@PluralsRes | ||
protected abstract int getDeleteAlertTitleId(); | ||
protected abstract void deleteItems(List<T> selectedItems); | ||
} |
Oops, something went wrong.