use of android.support.v7.widget.Toolbar in project flexbox-layout by google.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeStringResources();
mFlexboxLayout = (FlexboxLayout) findViewById(R.id.flexbox_layout);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
if (drawer != null) {
drawer.addDrawerListener(toggle);
}
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) {
navigationView.setNavigationItemSelectedListener(this);
Menu navigationMenu = navigationView.getMenu();
initializeFlexDirectionSpinner(navigationMenu);
initializeFlexWrapSpinner(navigationMenu);
initializeJustifyContentSpinner(navigationMenu);
initializeAlignItemsSpinner(navigationMenu);
initializeAlignContentSpinner(navigationMenu);
}
if (savedInstanceState != null) {
ArrayList<FlexItem> flexItems = savedInstanceState.getParcelableArrayList(FLEX_ITEMS_KEY);
assert flexItems != null;
mFlexboxLayout.removeAllViews();
for (int i = 0; i < flexItems.size(); i++) {
FlexItem flexItem = flexItems.get(i);
FlexboxLayout.LayoutParams lp = flexItem.toLayoutParams(this);
TextView textView = createBaseFlexItemTextView(i);
ViewCompat.setPaddingRelative(textView, flexItem.paddingStart, flexItem.paddingTop, flexItem.paddingEnd, flexItem.paddingBottom);
textView.setLayoutParams(lp);
mFlexboxLayout.addView(textView);
}
}
for (int i = 0; i < mFlexboxLayout.getChildCount(); i++) {
mFlexboxLayout.getChildAt(i).setOnClickListener(new FlexItemClickListener(i));
}
FloatingActionButton addFab = (FloatingActionButton) findViewById(R.id.add_fab);
if (addFab != null) {
addFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int viewIndex = mFlexboxLayout.getChildCount();
// index starts from 0. New View's index is N if N views ([0, 1, 2, ... N-1])
// exist.
TextView textView = createBaseFlexItemTextView(viewIndex);
textView.setLayoutParams(createDefaultLayoutParams());
textView.setOnClickListener(new FlexItemClickListener(viewIndex));
mFlexboxLayout.addView(textView);
}
});
}
FloatingActionButton removeFab = (FloatingActionButton) findViewById(R.id.remove_fab);
if (removeFab != null) {
removeFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mFlexboxLayout.getChildCount() == 0) {
return;
}
mFlexboxLayout.removeViewAt(mFlexboxLayout.getChildCount() - 1);
}
});
}
}
use of android.support.v7.widget.Toolbar in project material-components-android by material-components.
the class AppBarLayoutBaseTest method configureContent.
@CallSuper
protected void configureContent(@LayoutRes final int layoutResId, @StringRes final int titleResId) throws Throwable {
onView(withId(R.id.coordinator_stub)).perform(inflateViewStub(layoutResId));
mAppBar = (AppBarLayout) mCoordinatorLayout.findViewById(R.id.app_bar);
mCollapsingToolbar = (CollapsingToolbarLayout) mAppBar.findViewById(R.id.collapsing_app_bar);
mToolbar = (Toolbar) mAppBar.findViewById(R.id.toolbar);
final AppCompatActivity activity = activityTestRule.getActivity();
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setSupportActionBar(mToolbar);
}
});
final CharSequence activityTitle = activity.getString(titleResId);
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setTitle(activityTitle);
}
});
getInstrumentation().waitForIdleSync();
if (mCollapsingToolbar != null) {
onView(withId(R.id.collapsing_app_bar)).perform(setTitle(activityTitle)).perform(setContentScrimColor(Color.MAGENTA));
}
TextView dialog = (TextView) mCoordinatorLayout.findViewById(R.id.textview_dialogue);
if (dialog != null) {
onView(withId(R.id.textview_dialogue)).perform(setText(TextUtils.concat(Shakespeare.DIALOGUE)));
}
mDefaultElevationValue = mAppBar.getResources().getDimension(R.dimen.design_appbar_elevation);
}
use of android.support.v7.widget.Toolbar in project material-components-android by material-components.
the class AppBarLayoutCollapsePinActivity method onContentViewSet.
@Override
protected void onContentViewSet() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
use of android.support.v7.widget.Toolbar in project AdvancedMaterialDrawer by madcyph3r.
the class HeadItemTypesFragment method createAdapter.
private void createAdapter(RecyclerView recyclerView) {
final List<ExampleData> content = new ArrayList<>();
content.add(new ExampleData("One Item Example", HeadItemOneActivity.class));
content.add(new ExampleData("(One Item) Below Toolbar", HeadItemOneBelowToolbarActivity.class));
content.add(new ExampleData("(One Item) Black Theme", HeadItemOneBlackThemeActivity.class));
content.add(new ExampleData("(Three Item)", HeadItemThreeActivity.class));
content.add(new ExampleData("(Five Item)", HeadItemFiveActivity.class));
content.add(new ExampleData("(Five Item) With Extra Menu", HeadItemFiveExtraMenuActivity.class));
content.add(new ExampleData("(Two Items) With Extra Menu", HeadItemTwoExtraMenuActivity.class));
content.add(new ExampleData("(Three Items) Don't Close Drawer On Change", HeadItemThreeDontCloseOnChangeActivity.class));
content.add(new ExampleData("(Five Items) Don't Close Drawer On Change", HeadItemFiveDontCloseOnChangeActivity.class));
content.add(new ExampleData("Add And Remove Menu Items At Runtime", AddRemoveMenuItemsActivity.class));
content.add(new ExampleData("(Two Items) Only First Item Has a Menu", HeadItemTwoOnlyOneHasMenuActivity.class));
content.add(new ExampleData("(Two Items) Fragment Doesn't Change On HeadItem Change", HeadItemTwoNoFragmentLoadOnChangeActivity.class));
content.add(new ExampleData("100 Head Items With Static Background", HeadItem100StaticBackgroundActivity.class));
final ParallaxRecyclerAdapter<ExampleData> adapter = new ParallaxRecyclerAdapter<>(content);
View header = getActivity().getLayoutInflater().inflate(R.layout.recycleview_header, recyclerView, false);
ImageView headerImage = (ImageView) header.findViewById(R.id.imageViewHeader);
headerImage.setImageResource(R.drawable.l_5);
adapter.setParallaxHeader(header, recyclerView);
adapter.setData(content);
adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
((ViewHolder) viewHolder).textView.setText(adapter.getData().get(i).getTitle());
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) {
final ViewHolder holder = new ViewHolder(getActivity().getLayoutInflater().inflate(R.layout.recycleview_row, viewGroup, false));
return holder;
}
@Override
public int getItemCount() {
return content.size();
}
});
adapter.setOnParallaxScroll(new ParallaxRecyclerAdapter.OnParallaxScroll() {
@Override
public void onParallaxScroll(float percentage, float offset, View view) {
((MainActivity) getActivity()).setActionBarAlpha(percentage);
}
});
adapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() {
@Override
public void onClick(View view, int i) {
if (i >= 0) {
Intent intent = new Intent(getActivity(), adapter.getData().get(i).getClazz());
startActivity(intent);
}
}
});
recyclerView.setAdapter(adapter);
}
use of android.support.v7.widget.Toolbar in project AdvancedMaterialDrawer by madcyph3r.
the class ThemeFragment method createAdapter.
private void createAdapter(RecyclerView recyclerView) {
final List<ExampleData> content = new ArrayList<>();
content.add(new ExampleData("Dark Theme", DarkThemeActivity.class));
content.add(new ExampleData("Light Theme", LightThemeActivity.class));
content.add(new ExampleData("My Theme", MyThemeActivity.class));
content.add(new ExampleData("Unique Toolbar Color", UniqueToolbarColorActivity.class));
content.add(new ExampleData("Actionbar Overlay", ActionBarOverlayActivity.class));
content.add(new ExampleData("KitKat Translucent Statusbar", KitKatTranslucentStatusBarActivity.class));
content.add(new ExampleData("Actionbar Own Font", ActionBarOwnFontActivity.class));
content.add(new ExampleData("Own Drawer Width", OwnDrawerWidthActivity.class));
content.add(new ExampleData("Only Icons Menu", OnlyIconsActivity.class));
final ParallaxRecyclerAdapter<ExampleData> adapter = new ParallaxRecyclerAdapter<>(content);
View header = getActivity().getLayoutInflater().inflate(R.layout.recycleview_header, recyclerView, false);
ImageView headerImage = (ImageView) header.findViewById(R.id.imageViewHeader);
headerImage.setImageResource(R.drawable.l_8);
adapter.setParallaxHeader(header, recyclerView);
adapter.setData(content);
adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
((ViewHolder) viewHolder).textView.setText(adapter.getData().get(i).getTitle());
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) {
final ViewHolder holder = new ViewHolder(getActivity().getLayoutInflater().inflate(R.layout.recycleview_row, viewGroup, false));
return holder;
}
@Override
public int getItemCount() {
return content.size();
}
});
adapter.setOnParallaxScroll(new ParallaxRecyclerAdapter.OnParallaxScroll() {
@Override
public void onParallaxScroll(float percentage, float offset, View view) {
((MainActivity) getActivity()).setActionBarAlpha(percentage);
}
});
adapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() {
@Override
public void onClick(View view, int i) {
if (i >= 0) {
Intent intent = new Intent(getActivity(), adapter.getData().get(i).getClazz());
startActivity(intent);
}
}
});
recyclerView.setAdapter(adapter);
}
Aggregations