Skip to content

Commit

Permalink
CATROID-1163 Add Icons to Menus
Browse files Browse the repository at this point in the history
Created new ArrayAdapter for AlertDialogs to view Icons
and added Icons to all options menus
  • Loading branch information
mseiser committed Aug 30, 2021
1 parent d8b583d commit a39ae1b
Show file tree
Hide file tree
Showing 36 changed files with 687 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.catrobat.catroid.ui;

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
Expand Down Expand Up @@ -64,6 +65,7 @@
import java.io.InputStream;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.menu.MenuBuilder;
import kotlin.Lazy;

import static org.catrobat.catroid.common.FlavoredConstants.CATROBAT_HELP_URL;
Expand Down Expand Up @@ -244,6 +246,7 @@ public void onPause() {
}
}

@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main_menu, menu);
Expand All @@ -257,6 +260,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
scratchConverter.length(), scratchConverterBeta.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
menu.findItem(R.id.menu_scratch_converter).setTitle(scratchConverterBeta);

if (menu instanceof MenuBuilder) {
MenuBuilder m = (MenuBuilder) menu;
m.setOptionalIconsVisible(true);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

package org.catrobat.catroid.ui

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import androidx.appcompat.view.menu.MenuBuilder
import org.catrobat.catroid.R
import org.catrobat.catroid.ui.recyclerview.fragment.NfcTagListFragment

Expand All @@ -50,8 +52,12 @@ class NfcTagsActivity : BaseActivity() {
}
}

@SuppressLint("RestrictedApi")
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_script_activity, menu)
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)
}
return super.onCreateOptionsMenu(menu)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.catrobat.catroid.ui;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
Expand Down Expand Up @@ -63,6 +64,7 @@
import java.io.File;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.menu.MenuBuilder;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
Expand Down Expand Up @@ -148,9 +150,14 @@ public void setShowProgressBar(boolean show) {
findViewById(R.id.fragment_container).setVisibility(show ? View.GONE : View.VISIBLE);
}

@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_project_activity, menu);
if (menu instanceof MenuBuilder) {
MenuBuilder m = (MenuBuilder) menu;
m.setOptionalIconsVisible(true);
}
return super.onCreateOptionsMenu(menu);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.catrobat.catroid.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -33,6 +34,7 @@
import org.catrobat.catroid.ui.recyclerview.dialog.NewProjectDialogFragment;
import org.catrobat.catroid.ui.recyclerview.fragment.ProjectListFragment;

import androidx.appcompat.view.menu.MenuBuilder;
import androidx.fragment.app.Fragment;

public class ProjectListActivity extends BaseCastActivity {
Expand Down Expand Up @@ -71,10 +73,15 @@ private void loadFragment(Fragment fragment) {
.commit();
}

@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_projects_activity, menu);
menu.findItem(R.id.merge).setVisible(BuildConfig.FEATURE_MERGE_ENABLED);
if (menu instanceof MenuBuilder) {
MenuBuilder m = (MenuBuilder) menu;
m.setOptionalIconsVisible(true);
}
return super.onCreateOptionsMenu(menu);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.catrobat.catroid.ui;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
Expand Down Expand Up @@ -80,6 +81,7 @@

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.menu.MenuBuilder;
import androidx.fragment.app.Fragment;

import static org.catrobat.catroid.common.Constants.DEFAULT_IMAGE_EXTENSION;
Expand Down Expand Up @@ -202,10 +204,16 @@ Fragment getCurrentFragment() {
return getSupportFragmentManager().findFragmentById(R.id.fragment_container);
}

@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_script_activity, menu);
currentMenu = menu;

if (menu instanceof MenuBuilder) {
MenuBuilder m = (MenuBuilder) menu;
m.setOptionalIconsVisible(true);
}
return super.onCreateOptionsMenu(menu);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package org.catrobat.catroid.ui.recyclerview.fragment

import android.annotation.SuppressLint
import android.content.DialogInterface
import android.os.Bundle
import android.view.ActionMode
Expand All @@ -36,6 +37,7 @@ import android.widget.TextView
import androidx.annotation.IntDef
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuBuilder
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
Expand Down Expand Up @@ -76,6 +78,7 @@ class DataListFragment : Fragment(),
this.formulaEditorDataInterface = formulaEditorDataInterface
}

@SuppressLint("RestrictedApi")
override fun onCreateActionMode(
mode: ActionMode,
menu: Menu
Expand All @@ -86,6 +89,9 @@ class DataListFragment : Fragment(),
}
val inflater = mode.menuInflater
inflater.inflate(R.menu.context_menu, menu)
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)
}
adapter?.showCheckBoxes(true)
adapter?.updateDataSet()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package org.catrobat.catroid.ui.recyclerview.fragment

import android.content.Context
import android.content.DialogInterface
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
Expand All @@ -47,11 +48,11 @@ import org.catrobat.catroid.ui.UiUtils
import org.catrobat.catroid.ui.recyclerview.adapter.DataListAdapter
import org.catrobat.catroid.ui.recyclerview.adapter.RVAdapter
import org.catrobat.catroid.ui.recyclerview.dialog.TextInputDialog
import org.catrobat.catroid.ui.recyclerview.dialog.textwatcher.DuplicateInputTextWatcher
import org.catrobat.catroid.ui.recyclerview.viewholder.CheckableVH
import org.catrobat.catroid.utils.ToastUtil
import java.util.ArrayList
import org.catrobat.catroid.ui.recyclerview.dialog.textwatcher.DuplicateInputTextWatcher
import org.catrobat.catroid.utils.UserDataUtil
import java.util.ArrayList

class ListSelectorFragment : Fragment(), RVAdapter.SelectionListener,
RVAdapter.OnItemClickListener<UserData<*>> {
Expand Down Expand Up @@ -270,20 +271,27 @@ class ListSelectorFragment : Fragment(), RVAdapter.SelectionListener,
}

override fun onSettingsClick(item: UserData<*>, view: View?) {
val elementList = arrayOf<CharSequence>(getString(R.string.delete), getString(R.string.rename))
val popupMenu = PopupMenu(context, view)
for (element: CharSequence in elementList) popupMenu.menu.add(element)
val itemList: MutableList<UserData<*>> = ArrayList()
itemList.add(item)

popupMenu.menuInflater.inflate(R.menu.menu_project_activity, popupMenu.menu)
popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.title) {
getString(R.string.rename) -> showRenameDialog(
listOf(item)
)
getString(R.string.delete) -> showDeleteAlert(
listOf(item)
)
when (menuItem.itemId) {
R.id.rename -> showRenameDialog(listOf(item))
R.id.delete -> showDeleteAlert(listOf(item))
}
true
}
popupMenu.menu.findItem(R.id.backpack).isVisible = false
popupMenu.menu.findItem(R.id.copy).isVisible = false
popupMenu.menu.findItem(R.id.new_group).isVisible = false
popupMenu.menu.findItem(R.id.new_scene).isVisible = false
popupMenu.menu.findItem(R.id.show_details).isVisible = false
popupMenu.menu.findItem(R.id.project_options).isVisible = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
popupMenu.setForceShowIcon(true)
}
popupMenu.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ public boolean onMenuItemClick(MenuItem menuItem) {
popupMenu.getMenu().findItem(R.id.new_scene).setVisible(false);
popupMenu.getMenu().findItem(R.id.show_details).setVisible(false);
popupMenu.getMenu().findItem(R.id.project_options).setVisible(false);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
popupMenu.setForceShowIcon(true);
}
popupMenu.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ public boolean onMenuItemClick(MenuItem menuItem) {
popupMenu.getMenu().findItem(R.id.new_scene).setVisible(false);
popupMenu.getMenu().findItem(R.id.show_details).setVisible(false);
popupMenu.getMenu().findItem(R.id.project_options).setVisible(false);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
popupMenu.setForceShowIcon(true);
}
popupMenu.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ public boolean onMenuItemClick(MenuItem menuItem) {
popupMenu.getMenu().findItem(R.id.new_group).setVisible(false);
popupMenu.getMenu().findItem(R.id.new_scene).setVisible(false);
popupMenu.getMenu().findItem(R.id.show_details).setVisible(false);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
popupMenu.setForceShowIcon(true);
}
popupMenu.show();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.catrobat.catroid.ui.recyclerview.fragment;

import android.content.Intent;
import android.os.Build;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -49,6 +50,7 @@
import java.util.List;

import androidx.annotation.PluralsRes;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import static org.catrobat.catroid.common.Constants.Z_INDEX_BACKGROUND;
Expand Down Expand Up @@ -248,6 +250,7 @@ public void onItemClick(Scene item) {
}
}

@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public void onSettingsClick(Scene item, View view) {
PopupMenu popupMenu = new PopupMenu(getContext(), view);
Expand Down Expand Up @@ -283,6 +286,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
popupMenu.getMenu().findItem(R.id.new_scene).setVisible(false);
popupMenu.getMenu().findItem(R.id.show_details).setVisible(false);
popupMenu.getMenu().findItem(R.id.project_options).setVisible(false);
popupMenu.setForceShowIcon(true);
popupMenu.show();
}

Expand Down
Loading

0 comments on commit a39ae1b

Please sign in to comment.