Search in sources :

Example 1 with FlexboxLayout

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));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) MainActivity(com.google.android.apps.flexbox.MainActivity) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 2 with FlexboxLayout

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));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) TextView(android.widget.TextView) MainActivity(com.google.android.apps.flexbox.MainActivity) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 3 with FlexboxLayout

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()));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) TextView(android.widget.TextView) MainActivity(com.google.android.apps.flexbox.MainActivity) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 4 with FlexboxLayout

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));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) MainActivity(com.google.android.apps.flexbox.MainActivity) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 5 with FlexboxLayout

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);
            }
        });
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) NavigationView(android.support.design.widget.NavigationView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) FlexboxLayout(com.google.android.flexbox.FlexboxLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) Menu(android.view.Menu) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

FlexboxLayout (com.google.android.flexbox.FlexboxLayout)141 FlakyTest (android.support.test.filters.FlakyTest)140 MediumTest (android.support.test.filters.MediumTest)140 Test (org.junit.Test)140 TextView (android.widget.TextView)112 Drawable (android.graphics.drawable.Drawable)19 MainActivity (com.google.android.apps.flexbox.MainActivity)12 NavigationView (android.support.design.widget.NavigationView)6 Menu (android.view.Menu)6 ArrayAdapter (android.widget.ArrayAdapter)5 Spinner (android.widget.Spinner)5 View (android.view.View)3 Espresso.onView (android.support.test.espresso.Espresso.onView)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1 AdapterView (android.widget.AdapterView)1