Skip to content

Commit

Permalink
Updating Menus catalog demo
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 249279193
  • Loading branch information
leticiarossi committed May 24, 2019
1 parent 53abdff commit cc63b86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion catalog/java/io/material/catalog/menu/MenuFragment.java
Expand Up @@ -18,6 +18,7 @@

import io.material.catalog.R;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import dagger.Provides;
Expand All @@ -42,13 +43,21 @@ public int getDescriptionResId() {
return R.string.cat_menus_description;
}


@LayoutRes
public int getAdapterItemLayout() {
return R.layout.cat_popup_item;
}

@Override
public Demo getMainDemo() {
return new Demo() {
@Nullable
@Override
public Fragment createFragment() {
return new MenuMainDemoFragment();
MenuMainDemoFragment menuMainDemoFragment = new MenuMainDemoFragment();
menuMainDemoFragment.setPopupItemLayoutRes(getAdapterItemLayout());
return menuMainDemoFragment;
}
};
}
Expand Down
Expand Up @@ -26,6 +26,7 @@
import android.content.Context;
import android.graphics.drawable.InsetDrawable;
import android.os.Bundle;
import androidx.annotation.LayoutRes;
import androidx.annotation.MenuRes;
import androidx.annotation.Nullable;
import com.google.android.material.snackbar.Snackbar;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class MenuMainDemoFragment extends DemoFragment {

private static final int ICON_MARGIN = 8;
private static final String CLIP_DATA_LABEL = "Sample text to copy";
@LayoutRes private int popupItemLayout;

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
Expand Down Expand Up @@ -167,13 +169,17 @@ public boolean onMenuItemClick(MenuItem item) {
});
}

public void setPopupItemLayoutRes(@LayoutRes int popupItemRes) {
popupItemLayout = popupItemRes;
}

private ListPopupWindow initializeListPopupMenu(View v) {
ListPopupWindow listPopupWindow =
new ListPopupWindow(getContext(), null, R.attr.listPopupWindowStyle);
ArrayAdapter<CharSequence> adapter =
new ArrayAdapter<>(
getContext(),
R.layout.cat_popup_item,
popupItemLayout,
getResources().getStringArray(R.array.cat_list_popup_window_content));
listPopupWindow.setAdapter(adapter);
listPopupWindow.setAnchorView(v);
Expand Down

0 comments on commit cc63b86

Please sign in to comment.