Search in sources :

Example 51 with NavigationView

use of android.support.design.widget.NavigationView in project iosched by google.

the class AppNavigationViewAsDrawerImpl method setUpView.

@Override
public void setUpView() {
    mHandler = new Handler();
    mDrawerLayout = (DrawerLayout) mActivity.findViewById(R.id.drawer_layout);
    if (mDrawerLayout == null) {
        return;
    }
    // setup the status bar color to be colorPrimaryDark from the theme
    mDrawerLayout.setStatusBarBackgroundColor(UIUtils.getThemeColor(mActivity, R.attr.colorPrimaryDark, R.color.theme_primary_dark));
    mNavigationView = (NavigationView) mActivity.findViewById(R.id.nav_view);
    if (mSelfItem == NavigationModel.NavigationItemEnum.INVALID) {
        // do not show a nav drawer
        mDrawerLayout = null;
        return;
    }
    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerClosed(View drawerView) {
            // run deferred action, if we have one
            if (mDeferredOnDrawerClosedRunnable != null) {
                mDeferredOnDrawerClosedRunnable.run();
                mDeferredOnDrawerClosedRunnable = null;
            }
            mNavigationDrawerStateListener.onNavDrawerStateChanged(false, false);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            mNavigationDrawerStateListener.onNavDrawerStateChanged(true, false);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            mNavigationDrawerStateListener.onNavDrawerStateChanged(isNavDrawerOpen(), newState != DrawerLayout.STATE_IDLE);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            mNavigationDrawerStateListener.onNavDrawerSlide(slideOffset);
        }
    });
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // navigation drawer open. But just the first time.
    if (!SettingsUtils.isFirstRunProcessComplete(mActivity)) {
        // first run of the app starts with the nav drawer open
        SettingsUtils.markFirstRunProcessesDone(mActivity, true);
        mDrawerLayout.openDrawer(GravityCompat.START);
    }
    setupAccountBox();
}
Also used : Handler(android.os.Handler) DrawerLayout(android.support.v4.widget.DrawerLayout) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View)

Example 52 with NavigationView

use of android.support.design.widget.NavigationView in project flexbox-layout by google.

the class MainActivityTest method testFlexWrapSpinner.

@Test
@SuppressWarnings("unchecked")
@FlakyTest
public void testFlexWrapSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_flex_wrap));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int wrapReversePosition = spinnerAdapter.getPosition(activity.getString(R.string.wrap_reverse));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(wrapReversePosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    final int noWrapPosition = spinnerAdapter.getPosition(activity.getString(R.string.nowrap));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(noWrapPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) NavigationView(android.support.design.widget.NavigationView) Spinner(android.widget.Spinner) MainActivity(com.google.android.apps.flexbox.MainActivity) Menu(android.view.Menu) ArrayAdapter(android.widget.ArrayAdapter) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 53 with NavigationView

use of android.support.design.widget.NavigationView in project flexbox-layout by google.

the class MainActivityTest method testJustifyContentSpinner.

@Test
@SuppressWarnings("unchecked")
@FlakyTest
public void testJustifyContentSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_justify_content));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int spaceBetweenPosition = spinnerAdapter.getPosition(activity.getString(R.string.space_between));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(spaceBetweenPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN));
    final int centerPosition = spinnerAdapter.getPosition(activity.getString(R.string.center));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(centerPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) NavigationView(android.support.design.widget.NavigationView) Spinner(android.widget.Spinner) MainActivity(com.google.android.apps.flexbox.MainActivity) Menu(android.view.Menu) ArrayAdapter(android.widget.ArrayAdapter) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 54 with NavigationView

use of android.support.design.widget.NavigationView in project flexbox-layout by google.

the class MainActivityTest method testAlignItemsSpinner.

@Test
@SuppressWarnings("unchecked")
@FlakyTest
public void testAlignItemsSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_align_items));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int baselinePosition = spinnerAdapter.getPosition(activity.getString(R.string.baseline));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(baselinePosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_BASELINE));
    final int flexEndPosition = spinnerAdapter.getPosition(activity.getString(R.string.flex_end));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(flexEndPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) NavigationView(android.support.design.widget.NavigationView) Spinner(android.widget.Spinner) MainActivity(com.google.android.apps.flexbox.MainActivity) Menu(android.view.Menu) ArrayAdapter(android.widget.ArrayAdapter) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 55 with NavigationView

use of android.support.design.widget.NavigationView in project material-design-data by Luosunce.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.mipmap.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpage);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Snackbar.make(v, "Here's a Snackbar", Snackbar.LENGTH_LONG).setAction("Action", new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this, "Toast comes out", Toast.LENGTH_SHORT).show();
                }
            }).show();
        }
    });
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
}
Also used : NavigationView(android.support.design.widget.NavigationView) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) ViewPager(android.support.v4.view.ViewPager) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

NavigationView (android.support.design.widget.NavigationView)70 View (android.view.View)42 Toolbar (android.support.v7.widget.Toolbar)25 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)24 TextView (android.widget.TextView)21 DrawerLayout (android.support.v4.widget.DrawerLayout)17 ImageView (android.widget.ImageView)16 UiController (android.support.test.espresso.UiController)13 ViewAction (android.support.test.espresso.ViewAction)13 Menu (android.view.Menu)10 ActionBar (android.support.v7.app.ActionBar)8 Intent (android.content.Intent)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)7 MenuItem (android.view.MenuItem)7 Handler (android.os.Handler)6 SearchView (android.support.v7.widget.SearchView)6 BindView (butterknife.BindView)6 FlexboxLayout (com.google.android.flexbox.FlexboxLayout)6 TabLayout (android.support.design.widget.TabLayout)5 FlakyTest (android.support.test.filters.FlakyTest)5