Java Code Examples for android.support.v4.widget.DrawerLayout#setStatusBarBackgroundColor()

The following examples show how to use android.support.v4.widget.DrawerLayout#setStatusBarBackgroundColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemBarHelper.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
/**
 * Android4.4以上的状态栏着色(针对于DrawerLayout)
 * 注:
 * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
 * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
 *
 * @param activity Activity对象
 * @param drawerLayout DrawerLayout对象
 * @param statusBarColor 状态栏颜色
 * @param alpha 透明栏透明度[0.0-1.0]
 */
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout,
                                          @ColorInt int statusBarColor,
                                          @FloatRange(from = 0.0, to = 1.0) float alpha) {

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    return;
  }

  Window window = activity.getWindow();
  ViewGroup decorView = (ViewGroup) window.getDecorView();
  ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
    drawerLayout.setStatusBarBackgroundColor(statusBarColor);

    int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    window.getDecorView().setSystemUiVisibility(systemUiVisibility);
  } else {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  }

  setStatusBar(decorView, statusBarColor, true, true);
  setTranslucentView(decorView, alpha);

  drawerLayout.setFitsSystemWindows(false);
  drawContent.setFitsSystemWindows(true);
  ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
  drawer.setFitsSystemWindows(false);
}
 
Example 2
Source File: SystemBarHelper.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
/**
 * Android4.4以上的状态栏着色(针对于DrawerLayout)
 * 注:
 * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
 * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
 *
 * @param activity Activity对象
 * @param drawerLayout DrawerLayout对象
 * @param statusBarColor 状态栏颜色
 * @param alpha 透明栏透明度[0.0-1.0]
 */
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout,
                                          @ColorInt int statusBarColor,
                                          @FloatRange(from = 0.0, to = 1.0) float alpha) {

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    return;
  }

  Window window = activity.getWindow();
  ViewGroup decorView = (ViewGroup) window.getDecorView();
  ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
    drawerLayout.setStatusBarBackgroundColor(statusBarColor);

    int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    window.getDecorView().setSystemUiVisibility(systemUiVisibility);
  } else {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  }

  setStatusBar(decorView, statusBarColor, true, true);
  setTranslucentView(decorView, alpha);

  drawerLayout.setFitsSystemWindows(false);
  drawContent.setFitsSystemWindows(true);
  ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
  drawer.setFitsSystemWindows(false);
}
 
Example 3
Source File: SystemBarHelper.java    From FlycoSystemBar with MIT License 5 votes vote down vote up
/**
 * Android4.4以上的状态栏着色(针对于DrawerLayout)
 * 注:
 * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
 * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
 *
 * @param activity       Activity对象
 * @param drawerLayout   DrawerLayout对象
 * @param statusBarColor 状态栏颜色
 * @param alpha          透明栏透明度[0.0-1.0]
 */
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout, @ColorInt int statusBarColor,
                                          @FloatRange(from = 0.0, to = 1.0) float alpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }

    Window window = activity.getWindow();
    ViewGroup decorView = (ViewGroup) window.getDecorView();
    ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        drawerLayout.setStatusBarBackgroundColor(statusBarColor);

        int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
        systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        window.getDecorView().setSystemUiVisibility(systemUiVisibility);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    setStatusBar(decorView, statusBarColor, true, true);
    setTranslucentView(decorView, alpha);

    drawerLayout.setFitsSystemWindows(false);
    drawContent.setFitsSystemWindows(true);
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawer.setFitsSystemWindows(false);
}
 
Example 4
Source File: SystemBarUtils.java    From MarkdownEditors with Apache License 2.0 5 votes vote down vote up
/**
 * Android4.4以上的状态栏着色(针对于DrawerLayout)
 * 注:
 * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
 * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
 *
 * @param activity       Activity对象
 * @param drawerLayout   DrawerLayout对象
 * @param statusBarColor 状态栏颜色
 * @param alpha          透明栏透明度[0.0-1.0]
 */
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout, @ColorInt int statusBarColor,
                                          @FloatRange(from = 0.0, to = 1.0) float alpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }

    Window window = activity.getWindow();
    ViewGroup decorView = (ViewGroup) window.getDecorView();
    ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        drawerLayout.setStatusBarBackgroundColor(statusBarColor);

        int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
        systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        window.getDecorView().setSystemUiVisibility(systemUiVisibility);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    setStatusBar(decorView, statusBarColor, true, true);
    setTranslucentView(decorView, alpha);

    drawerLayout.setFitsSystemWindows(false);
    drawContent.setFitsSystemWindows(true);
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawer.setFitsSystemWindows(false);
}
 
Example 5
Source File: MainActivity.java    From KA27 with Apache License 2.0 5 votes vote down vote up
/**
 * Define all views
 */
private void setView() {
    mScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.scrimInsetsFrameLayout);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (mDrawerLayout != null) {
        mDrawerLayout.setStatusBarBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.statusbar_color));
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    }
    mDrawerList = (RecyclerView) findViewById(R.id.drawer_list);
    mSplashView = (SplashView) findViewById(R.id.splash_view);

    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mLayoutManager.setSmoothScrollbarEnabled(true);
    mDrawerList.setLayoutManager(mLayoutManager);
    mDrawerList.setHasFixedSize(true);
    mDrawerList.setAdapter(new RecyclerView.Adapter() {
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return null;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {}

        @Override
        public int getItemCount() {
            return 0;
        }
    });
}
 
Example 6
Source File: MainActivity.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
/**
 * Define all views
 */
private void setView() {
    mScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.scrimInsetsFrameLayout);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (mDrawerLayout != null) {
        mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.statusbar_color));
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    }
    mDrawerList = (RecyclerView) findViewById(R.id.drawer_list);
    mSplashView = (SplashView) findViewById(R.id.splash_view);

    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mLayoutManager.setSmoothScrollbarEnabled(true);
    mDrawerList.setLayoutManager(mLayoutManager);
    mDrawerList.setHasFixedSize(true);
    mDrawerList.setAdapter(new RecyclerView.Adapter() {
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return null;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        }

        @Override
        public int getItemCount() {
            return 0;
        }
    });
}
 
Example 7
Source File: SystemBarHelper.java    From LeisureRead with Apache License 2.0 5 votes vote down vote up
/**
 * Android4.4以上的状态栏着色(针对于DrawerLayout)
 * 注:
 * 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
 * 2.可以版本判断在5.0以上不调用该方法,使用系统自带
 *
 * @param activity Activity对象
 * @param drawerLayout DrawerLayout对象
 * @param statusBarColor 状态栏颜色
 * @param alpha 透明栏透明度[0.0-1.0]
 */
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout,
                                          @ColorInt int statusBarColor,
                                          @FloatRange(from = 0.0, to = 1.0) float alpha) {

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    return;
  }

  Window window = activity.getWindow();
  ViewGroup decorView = (ViewGroup) window.getDecorView();
  ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
    drawerLayout.setStatusBarBackgroundColor(statusBarColor);

    int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    window.getDecorView().setSystemUiVisibility(systemUiVisibility);
  } else {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  }

  setStatusBar(decorView, statusBarColor, true, true);
  setTranslucentView(decorView, alpha);

  drawerLayout.setFitsSystemWindows(false);
  drawContent.setFitsSystemWindows(true);
  ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
  drawer.setFitsSystemWindows(false);
}
 
Example 8
Source File: MainActivity.java    From MaterialRohling with MIT License 5 votes vote down vote up
public void initLayout() {
    //--------------------------------------------------------------------------
    // create the material toolbar
    //--------------------------------------------------------------------------
    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(mToolbar);

    //--------------------------------------------------------------------------
    // create the material navdrawer
    //--------------------------------------------------------------------------
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.colorMainDark));

    //--------------------------------------------------------------------------
    // create the material navdrawer toggle and bind it to the navigation_drawer
    //--------------------------------------------------------------------------
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.app_name, R.string.app_name);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    //--------------------------------------------------------------------------
    // create the viewpager which holds the tab contents
    // tell the viewpager which tabs he have to listen to
    //--------------------------------------------------------------------------
    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setOffscreenPageLimit(5); // tabcachesize (=tabcount for better performance)
    mViewPager.setAdapter(new SlidingTabAdapter());

    //--------------------------------------------------------------------------
    // create sliding tabs and bind them to the viewpager
    //--------------------------------------------------------------------------
    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);

    // use own style rules for tab layout
    mSlidingTabLayout.setCustomTabView(R.layout.toolbar_tab, R.id.toolbar_tab_txtCaption);
    mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.tab_indicator_color));

    mSlidingTabLayout.setDistributeEvenly(true); // each tab has the same size
    mSlidingTabLayout.setViewPager(mViewPager);

}
 
Example 9
Source File: ActionBarCastActivity.java    From LyricHere with Apache License 2.0 5 votes vote down vote up
protected void initializeToolbar() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    if (mToolbar == null) {
        throw new IllegalStateException("Layout is required to include a Toolbar with id " +
                "'toolbar'");
    }
    mToolbar.inflateMenu(R.menu.main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    if (mDrawerLayout != null) {
        mDrawerList = (ListView) findViewById(R.id.drawer_list);
        if (mDrawerList == null) {
            throw new IllegalStateException("A layout with a drawerLayout is required to" +
                    "include a ListView with id 'drawerList'");
        }

        // Create an ActionBarDrawerToggle that will handle opening/closing of the drawer:
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                mToolbar, R.string.open_content_drawer, R.string.close_content_drawer);
        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setStatusBarBackgroundColor(
                ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.black));
        populateDrawerItems();
        setSupportActionBar(mToolbar);
        updateDrawerToggle();
    } else {
        setSupportActionBar(mToolbar);
    }

    mToolbarInitialized = true;
}
 
Example 10
Source File: SilentActivity.java    From KUAS-AP-Material with MIT License 4 votes vote down vote up
public void setUpMenuDrawer(int selectItem) {
	drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	navigationView = (NavigationView) findViewById(R.id.nav_view);
	headerView = navigationView.getHeaderView(0);
	if (headerView.findViewById(R.id.layout_user) != null) {
		final boolean isLogin = Memory.getBoolean(this, Constant.PREF_IS_LOGIN, false);
		headerView.findViewById(R.id.layout_user)
				.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						drawer.closeDrawers();
						if (mLayoutID == R.layout.activity_messages ||
								mLayoutID == R.layout.activity_about) {
							if (isLogin) {
								showUserInfo();
							} else {
								startActivity(
										new Intent(SilentActivity.this, LoginActivity.class));
							}
						} else if (mLayoutID == R.layout.activity_login) {
							Toast.makeText(SilentActivity.this, R.string.login_first,
									Toast.LENGTH_SHORT).show();
						} else {
							showUserInfo();
						}
					}
				});
	}

	drawer.setDrawerShadow(R.drawable.shadow_right, GravityCompat.START);
	drawer.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.main_theme_dark));

	mDrawerToggle = new AnimationActionBarDrawerToggle(this, drawer, R.string.open_drawer,
			R.string.close_drawer) {

		@Override
		public void onDrawerSlide(View drawerView, float slideOffset) {
			if (drawerView == navigationView) {
				super.onDrawerSlide(drawerView, slideOffset);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}

		/** Called when a drawer has settled in a completely closed state. */
		public void onDrawerClosed(View drawerView) {
			if (drawerView == navigationView) {
				super.onDrawerClosed(drawerView);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}

		/** Called when a drawer has settled in a completely open state. */
		public void onDrawerOpened(View drawerView) {
			if (drawerView == navigationView) {
				super.onDrawerOpened(drawerView);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}
	};

	// Set the drawer toggle as the DrawerListener
	drawer.setDrawerListener(mDrawerToggle);
	navigationView.setNavigationItemSelectedListener(this);

	mSelectedItem = -1;
	if (-1 < selectItem && selectItem < navigationView.getMenu().size()) {
		selectedMenuItem = navigationView.getMenu().getItem(selectItem);
		selectedMenuItem.setChecked(true);
		mSelectedItem = selectItem;
	}
}
 
Example 11
Source File: SilentActivity.java    From KUAS-AP-Material with MIT License 4 votes vote down vote up
public void setUpMenuDrawer(int selectItem) {
	drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	navigationView = (NavigationView) findViewById(R.id.nav_view);
	headerView = navigationView.getHeaderView(0);
	if (headerView.findViewById(R.id.layout_user) != null) {
		final boolean isLogin = Memory.getBoolean(this, Constant.PREF_IS_LOGIN, false);
		headerView.findViewById(R.id.layout_user)
				.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						drawer.closeDrawers();
						if (mLayoutID == R.layout.activity_messages ||
								mLayoutID == R.layout.activity_about) {
							if (isLogin) {
								showUserInfo();
							} else {
								startActivity(
										new Intent(SilentActivity.this, LoginActivity.class));
							}
						} else if (mLayoutID == R.layout.activity_login) {
							Toast.makeText(SilentActivity.this, R.string.login_first,
									Toast.LENGTH_SHORT).show();
						} else {
							showUserInfo();
						}
					}
				});
	}

	drawer.setDrawerShadow(R.drawable.shadow_right, GravityCompat.START);
	drawer.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.main_theme_dark));

	mDrawerToggle = new AnimationActionBarDrawerToggle(this, drawer, R.string.open_drawer,
			R.string.close_drawer) {

		@Override
		public void onDrawerSlide(View drawerView, float slideOffset) {
			if (drawerView == navigationView) {
				super.onDrawerSlide(drawerView, slideOffset);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}

		/** Called when a drawer has settled in a completely closed state. */
		public void onDrawerClosed(View drawerView) {
			if (drawerView == navigationView) {
				super.onDrawerClosed(drawerView);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}

		/** Called when a drawer has settled in a completely open state. */
		public void onDrawerOpened(View drawerView) {
			if (drawerView == navigationView) {
				super.onDrawerOpened(drawerView);
				InputMethodManager inputMethodManager =
						(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(drawerView.getWindowToken(), 0);
			}
		}
	};

	// Set the drawer toggle as the DrawerListener
	drawer.setDrawerListener(mDrawerToggle);
	navigationView.setNavigationItemSelectedListener(this);

	mSelectedItem = -1;
	if (-1 < selectItem && selectItem < navigationView.getMenu().size()) {
		selectedMenuItem = navigationView.getMenu().getItem(selectItem);
		selectedMenuItem.setChecked(true);
		mSelectedItem = selectItem;
	}
}
 
Example 12
Source File: NavDrawer.java    From smartcard-reader with GNU General Public License v3.0 4 votes vote down vote up
public NavDrawer(Activity activity, Bundle inState,
                 int resId, DrawerLayout drawerLayout, Toolbar toolbar) {
    mActivity = activity;
    mResId = resId;
    mDrawerLayout = drawerLayout;

    // this only takes effect on Lollipop, or when using translucentStatusBar on Kitkat
    drawerLayout.setStatusBarBackgroundColor(activity.getResources().getColor(R.color.primary));
    mParentItem = drawerLayout.findViewById(resId);
    mParentItem.setActivated(true);

    mDrawerToggle = new ActionBarDrawerToggle(activity, drawerLayout,
            toolbar, R.string.app_name, R.string.app_name) {

        /** called when a drawer has settled in a completely closed state */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            // force call to onPrepareOptionsMenu()
            mActivity.invalidateOptionsMenu();
        }

        /** called when a drawer has settled in a completely open state */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // force call to onPrepareOptionsMenu()
            mActivity.invalidateOptionsMenu();
        }
    };
    drawerLayout.setDrawerListener(mDrawerToggle);

    View appSelect = drawerLayout.findViewById(R.id.app_select);
    View batchSelect = drawerLayout.findViewById(R.id.batch_select);
    View emvRead = drawerLayout.findViewById(R.id.emv_read);
    View apps = drawerLayout.findViewById(R.id.apps);
    View settings = drawerLayout.findViewById(R.id.settings);

    appSelect.setOnClickListener(mClickListener);
    batchSelect.setOnClickListener(mClickListener);
    emvRead.setOnClickListener(mClickListener);
    apps.setOnClickListener(mClickListener);
    settings.setOnClickListener(mClickListener);

    if (inState != null) {
        if (inState.getBoolean("drawer_open")) {
            drawerLayout.openDrawer(Gravity.START|Gravity.LEFT);
        }
    }
}
 
Example 13
Source File: Main.java    From Mizuu with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Mizuu_Theme_Overview);

    super.onCreate(savedInstanceState);

    mPicasso = MizuuApplication.getPicasso(getApplicationContext());

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    mStartup = Integer.valueOf(settings.getString(STARTUP_SELECTION, "1"));

    mDbHelper = MizuuApplication.getMovieAdapter();
    mDbHelperTv = MizuuApplication.getTvDbAdapter();

    mTfMedium = TypefaceUtils.getRobotoMedium(getApplicationContext());
    mTfRegular = TypefaceUtils.getRoboto(getApplicationContext());

    setupMenuItems();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.color_primary_dark));
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_list_shadow, GravityCompat.START);

    mDrawerList = (ListView) findViewById(R.id.listView1);
    mDrawerList.setLayoutParams(new FrameLayout.LayoutParams(ViewUtils.getNavigationDrawerWidth(this), FrameLayout.LayoutParams.MATCH_PARENT));
    mDrawerList.setAdapter(new MenuAdapter());
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            switch (mMenuItems.get(arg2).getType()) {
                case MenuItem.HEADER:

                    Intent intent = new Intent(getApplicationContext(), Preferences.class);
                    intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, AccountsFragment.class.getName());
                    intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
                    intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_TITLE, getString(R.string.social));
                    intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_SHORT_TITLE, getString(R.string.social));

                    startActivity(intent);
                    break;

                case MenuItem.SECTION:
                    loadFragment(mMenuItems.get(arg2).getFragment());
                    break;
                case MenuItem.SETTINGS_AREA:

                    Intent smallIntent = new Intent(getApplicationContext(), Preferences.class);
                    startActivity(smallIntent);

                    mDrawerLayout.closeDrawers();

                    break;
            }
        }
    });

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState != null && savedInstanceState.containsKey("selectedIndex")) {
        selectedIndex = savedInstanceState.getInt("selectedIndex");
        loadFragment(selectedIndex);
    } else if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("startup")) {
        loadFragment(Integer.parseInt(getIntent().getExtras().getString("startup")));
    } else {
        loadFragment(mStartup);
    }

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(LocalBroadcastUtils.UPDATE_MOVIE_LIBRARY));
    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(LocalBroadcastUtils.UPDATE_TV_SHOW_LIBRARY));
}