use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class MainActivityTest method testAddFlexItem.
@Test
@FlakyTest
public void testAddFlexItem() {
MainActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
assertNotNull(flexboxLayout);
int beforeCount = flexboxLayout.getChildCount();
onView(withId(R.id.add_fab)).perform(click());
assertThat(flexboxLayout.getChildCount(), is(beforeCount + 1));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class MainActivityTest method testEditFragment_changeFlexBasisPercent.
@Test
@FlakyTest
public void testEditFragment_changeFlexBasisPercent() {
MainActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
assertNotNull(flexboxLayout);
onView(withId(R.id.textview1)).perform(click());
onView(withId(R.id.edit_text_flex_basis_percent)).perform(replaceText("50"), closeSoftKeyboard());
onView(withId(R.id.button_ok)).perform(click());
TextView first = (TextView) activity.findViewById(R.id.textview1);
TextView second = (TextView) activity.findViewById(R.id.textview2);
TextView third = (TextView) activity.findViewById(R.id.textview3);
assertNotNull(first);
assertNotNull(second);
assertNotNull(third);
assertThat(first.getWidth(), is(flexboxLayout.getWidth() / 2));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class MainActivityTest method testEditFragment_changeFlexGrowFloat.
@Test
@FlakyTest
public void testEditFragment_changeFlexGrowFloat() {
MainActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
assertNotNull(flexboxLayout);
onView(withId(R.id.textview1)).perform(click());
onView(withId(R.id.edit_text_flex_grow)).perform(replaceText("1.0"), closeSoftKeyboard());
onView(withId(R.id.button_ok)).perform(click());
TextView first = (TextView) activity.findViewById(R.id.textview1);
TextView second = (TextView) activity.findViewById(R.id.textview2);
TextView third = (TextView) activity.findViewById(R.id.textview3);
assertNotNull(first);
assertNotNull(second);
assertNotNull(third);
assertThat(first.getWidth(), is(flexboxLayout.getWidth() - second.getWidth() - third.getWidth()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class MainActivityTest method testConfigurationChange.
@Test
@FlakyTest
public void testConfigurationChange() {
MainActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
assertNotNull(flexboxLayout);
onView(withId(R.id.add_fab)).perform(click());
onView(withId(R.id.add_fab)).perform(click());
int beforeCount = flexboxLayout.getChildCount();
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// Verify the flex items are restored across the configuration change.
assertThat(flexboxLayout.getChildCount(), is(beforeCount));
}
use of com.google.android.flexbox.FlexboxLayout 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);
}
});
}
}
Aggregations