public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.primaryDarkColor)); mActionBarDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) return; getActivity().invalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) return; getActivity().invalidateOptionsMenu(); } }; mDrawerLayout.post( new Runnable() { @Override public void run() { mActionBarDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mActionBarDrawerToggle); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, R.drawable.ic_drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); if (mCallbacks != null) { mCallbacks.onDrawerclose(); } } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } if (mCallbacks != null) { mCallbacks.onDraweropen(); } } }; if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
public void setUp(DrawerLayout drawerLayout, Toolbar toolbar, int headerImageRes) { this.headerImageRes = headerImageRes; this.drawerToggle = new ActionBarDrawerToggle( getMicroActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getMicroActivity().supportInvalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getMicroActivity().supportInvalidateOptionsMenu(); } }; drawerLayout.setDrawerListener(drawerToggle); drawerLayout.post( new Runnable() { @Override public void run() { drawerToggle.syncState(); } }); }
public void setUp(int fragmentId, final DrawerLayout drawerLayout) { fragmentContainerView = baseActivity.findViewById(fragmentId); this.drawerLayout = drawerLayout; drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ActionBar actionBar = baseActivity.getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); drawerToggle = new QMActionBarDrawerToggle( baseActivity, drawerLayout, R.drawable.ic_drawer, R.string.nvd_open, R.string.nvd_close); if (!userLearnedDrawer && !fromSavedInstanceState) { drawerLayout.openDrawer(fragmentContainerView); } drawerLayout.post( new Runnable() { @Override public void run() { drawerToggle.syncState(); } }); drawerLayout.setDrawerListener(drawerToggle); }
public void setUp(DrawerLayout drawerLayout, final Toolbar toolbar, int id) { viewContainer = getActivity().findViewById(id); this.toolbar = toolbar; this.drawerLayout = drawerLayout; actionBarDrawerToggle = new ActionBarDrawerToggle( getActivity(), this.drawerLayout, toolbar, R.string.open, R.string.close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) {} }; drawerLayout.post( new Runnable() { @Override public void run() { actionBarDrawerToggle.syncState(); } }); drawerLayout.setDrawerListener(actionBarDrawerToggle); }
public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) { containerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; mDrawerToggle = new ActionBarDrawerToggle( getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); toolbar.setAlpha(1 - slideOffset / 2); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); }
public void setUp(int fragmentid, DrawerLayout layout, Toolbar tool) { containerview = getActivity().findViewById(fragmentid); mDralayout = layout; mtoggle = new ActionBarDrawerToggle( getActivity(), layout, tool, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!muserlearned) { muserlearned = true; savetoprefrence(getActivity(), keyuser, muserlearned + ""); // saved to pref method } getActivity().invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActivity().invalidateOptionsMenu(); } }; if (!muserlearned && !mfromsaved) { mDralayout.openDrawer(containerview); } mDralayout.setDrawerListener(mtoggle); mDralayout.post( new Runnable() { @Override public void run() { mtoggle.syncState(); } }); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer // opens // 给DrawerLayout设置阴影 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); // 设置返回按钮可以显示 (向左的小箭头)// 默认不显示 actionBar.setDisplayHomeAsUpEnabled(true); // 设置返回按钮可以点击 actionBar.setHomeButtonEnabled(true); // 创建自定义返回按钮内容 drawerArrow = new DrawerArrowDrawable(getActivity()) { @Override public boolean isLayoutRtl() { return false; } }; // 创建v7包下的返回按钮ActionBarDrawerToggle, (封装DrawerArrowDrawable) mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, drawerArrow, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); getActivity().invalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActivity().invalidateOptionsMenu(); } }; mDrawerLayout.post( new Runnable() { @Override public void run() { // 同步开关状态 mDrawerToggle.syncState(); } }); // 设置按钮监听, 点击之后, 或者拖拽过程中返回按钮可以实时更新其动画位置. mDrawerLayout.setDrawerListener(mDrawerToggle); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; ActionBar ab = getSupportActivity().getSupportActionBar(); if (ab != null) { mDrawerListView.setAdapter( new ArrayAdapter<>( ab.getThemedContext(), R.layout.drawer_list_item, android.R.id.text1, new String[] { getString(R.string.flasher), getString(R.string.recovery_script_manager), getString(R.string.donate), getString(R.string.settings) })); // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ getSupportActivity().getToolbar(), R.string.app_name, /* "open drawer" description for accessibility */ R.string.app_name /* "close drawer" description for accessibility */) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getSupportActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } getSupportActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); } }
/** * Called by the implementing activity to initialise the navigation drawer * * @param navigationContainer * @param drawerLayout */ public void initialise(ViewGroup navigationContainer, DrawerLayout drawerLayout) { mNavigationDrawerContainer = navigationContainer; mDrawerLayout = drawerLayout; // ensure the mToolbar displays the home icon (will be overriden with the burger icon) ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) return; if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; PrefUtils.save(getActivity(), Prefs.DRAWER_LEARNED, true); } } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, 0); } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mNavigationDrawerContainer); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout, String[] titles, int position) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // ActionBar actionBar = getActionBar(); // actionBar.setDisplayHomeAsUpEnabled(true); // actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, mUserLearnedDrawer).apply(); } } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(mDrawerToggle::syncState); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerListView.setAdapter( new ArrayAdapter<>( getActivity(), R.layout.item_navigation_drawer, android.R.id.text1, titles)); mCurrentPosition = position; }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. * @param toolbar The Toolbar of the activity. */ public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.myPrimaryDarkColor)); mActionBarDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) return; getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) return; if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mActionBarDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mActionBarDrawerToggle); }
public void setup(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) { mDrawerLayout = drawerLayout; containerView = getActivity().findViewById(fragmentId); mDrawerToggle = new ActionBarDrawerToggle( getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; saveToPreferences(getActivity(), KEY_USER_LEARNED_DRAWER, mUserLearnedDrawer + ""); } getActivity().invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { if (slideOffset < 0.6) { toolbar.setAlpha(1 - slideOffset); } } }; if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(containerView); } mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); }
public void setUp(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, toolbar, R.string.app_name, R.string.app_name) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().supportInvalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; PreferencesEditor.savePreference( Dribbble.getContext(), PREF_USER_LEARNED_DRAWER, true); } getActivity().supportInvalidateOptionsMenu(); } }; mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) { containerView = getActivity().findViewById(fragmentId); this.mDrawerLayout = drawerLayout; mDrawerToggle = new ActionBarDrawerToggle( getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; savePreferences(getActivity(), Key_User_Learned_Drawer, mUserLearnedDrawer); } getActivity().invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { // toolbar.setAlpha(1 - (float) (slideOffset * 0.7)); } }; Log.v("dkholt", "NavigationDrawerFragment-SetUp"); if (!mUserLearnedDrawer && !mFromSavedInstance) { mDrawerLayout.openDrawer(containerView); } mDrawerLayout.setDrawerListener(mDrawerToggle); Log.v("dkholt", "NavigationDrawerFragment-SetUpAfter"); mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); }
public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) { containerView = getActivity().findViewById(fragmentId); ViewGroup.LayoutParams layoutParams = containerView.getLayoutParams(); Display display = ((Activity) containerView.getContext()).getWindowManager().getDefaultDisplay(); int width = display.getWidth(); width = width - Util.dpToPx(containerView.getContext(), 56); int maxWidth = Util.dpToPx(containerView.getContext(), 320); layoutParams.width = width > maxWidth ? maxWidth : width; mDrawerLayout = drawerLayout; mDrawerToggle = new ActionBarDrawerToggle( getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close); mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); ((MenuActivity) getActivity()).hideKeyBoard(); } }; // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { containerview = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; mDrawerToggle = new ActionBarDrawerToggle( getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); Log.d("userlearned ", "" + mUserLearnedDrawer); Log.d("fromsaved ", "" + mFromSavedInstanceState); // if(!mUserLearnedDrawer) { // mUserLearnedDrawer = true; saveToPreferences(getActivity(), KEY_USER_LEARNED_DRAWER, mUserLearnedDrawer + ""); // } getActivity().invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActivity().invalidateOptionsMenu(); } }; // if(!mUserLearnedDrawer && mFromSavedInstanceState) { // mDrawerLayout.openDrawer(containerview); // } mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mUserName = (String) sharedpreferences.getParam( getActivity(), getString(R.string.pref_file), getString(R.string.pref_user_name), ""); if (mUserName == null) mUserName = getString(R.string.pref_user_name_default); mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // Toast.makeText(getActivity(), "onDrawerOpened", Toast.LENGTH_SHORT).show(); // dynamically get the user name from the local storage and refresh the list view, added // by Lin mUserName = (String) sharedpreferences.getParam( getActivity(), getString(R.string.pref_file), getString(R.string.pref_user_name), ""); if (mUserName == null) mUserName = getString(R.string.pref_user_name_default); mDrawerListView.setAdapter( new ArrayAdapter<String>( getActionBar().getThemedContext(), android.R.layout.simple_list_item_activated_1, android.R.id.text1, new String[] { mUserName, // getString(R.string.title_section2), getString(R.string.title_section2), getString(R.string.title_section3), getString(R.string.title_section4), getString(R.string.title_section5), getString(R.string.title_section6), })); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } if (lazyIntent != null) { getActivity().sendBroadcast(lazyIntent); lazyIntent = null; } else { getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); if (currentSubItem != null) { lazyIntent = new Intent(); lazyIntent.setAction(Consts.Action_Open_Content_Fragment); lazyIntent.putExtra(Consts.Extra_SubItem, currentSubItem); getActivity().sendBroadcast(lazyIntent); } }
@Override protected void onCreate(Bundle savedInstanceState) { final SharedPreferences sharedpreferences = getSharedPreferences("myPref", Context.MODE_PRIVATE); id = sharedpreferences.getInt("id", 0); Log.e("manual id", String.valueOf(id)); super.onCreate(savedInstanceState); setContentView(R.layout.activity_manual_entry); tb1 = (Toolbar) findViewById(R.id.app_bar_manual); setSupportActionBar(tb1); date = (TextView) findViewById(R.id.date_manual); start1 = (EditText) findViewById(R.id.entry_time); exit1 = (EditText) findViewById(R.id.exit_time); break1_start1 = (EditText) findViewById(R.id.b1_start); break2_start1 = (EditText) findViewById(R.id.b2_start); break3_start1 = (EditText) findViewById(R.id.b3_start); break1_stop1 = (EditText) findViewById(R.id.b1_stop); break2_stop1 = (EditText) findViewById(R.id.b2_stop); break3_stop1 = (EditText) findViewById(R.id.b3_stop); edit = (Button) findViewById(R.id.edit); dbHelper = new DbHelper(getApplicationContext()); try { dbHelper.openDataBase(); } catch (SQLException e) { e.printStackTrace(); } details = new String[8]; final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); mHour = c.get(Calendar.HOUR_OF_DAY); mMinute = c.get(Calendar.MINUTE); DatePickerDialog dpd = new DatePickerDialog( this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { flag = 1; yearSelected = year; monthSelected = monthOfYear + 1; daySelected = dayOfMonth; if (daySelected >= mDay) { Toast.makeText( getApplication(), getString(R.string.manual_today), Toast.LENGTH_SHORT) .show(); Intent intent = new Intent(getApplicationContext(), userHome.class); finish(); startActivity(intent); } if (daySelected < 10 && monthSelected > 9) { dates = "0" + daySelected + "-" + monthSelected + "-" + yearSelected; } else if (daySelected > 9 && monthSelected < 10) { dates = daySelected + "-0" + monthSelected + "-" + yearSelected; } else if (daySelected < 10 && monthSelected < 10) { dates = "0" + daySelected + "-0" + monthSelected + "-" + yearSelected; } else { dates = daySelected + "-" + monthSelected + "-" + yearSelected; } date.setText(dates); details = dbHelper.getManualEntryDetails(id, dates); start1.setText(details[0]); break1_start1.setText(details[1]); break1_stop1.setText(details[2]); break2_start1.setText(details[3]); break2_stop1.setText(details[4]); break3_start1.setText(details[5]); break3_stop1.setText(details[6]); exit1.setText(details[7]); } }, mYear, mMonth, mDay); dpd.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { flag = 0; Intent intent = new Intent(getApplicationContext(), userHome.class); finish(); startActivity(intent); } }); dpd.show(); start1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { entryhourSelected = hourOfDay; entryminuteSelected = minute; if (entryhourSelected < 10 && entryminuteSelected > 9) { start1.setText("0" + entryhourSelected + ":" + entryminuteSelected); } else if (entryhourSelected > 9 && entryminuteSelected < 10) { start1.setText(entryhourSelected + ":0" + entryminuteSelected); } else if (entryhourSelected < 10 && entryminuteSelected < 10) { start1.setText("0" + entryhourSelected + ":0" + entryminuteSelected); } else { start1.setText(entryhourSelected + ":" + entryminuteSelected); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Enter Entry Time"); timePickerDialog.show(); } }); break1_start1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { break1_hrs_start = hourOfDay; break1_min_start = minute; if (break1_hrs_start < 10 && break1_min_start > 9) { break1_start1.setText("0" + break1_hrs_start + ":" + break1_min_start); } else if (break1_hrs_start > 9 && break1_min_start < 10) { break1_start1.setText(break1_hrs_start + ":0" + break1_min_start); } else if (break1_hrs_start < 10 && break1_min_start < 10) { break1_start1.setText("0" + break1_hrs_start + ":0" + break1_min_start); } else { break1_start1.setText(break1_hrs_start + ":" + break1_min_start); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Break1 Start"); timePickerDialog.show(); } }); break1_stop1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { break1_hrs_stop = hourOfDay; break1_min_stop = minute; if (break1_hrs_stop < 10 && break1_min_stop > 9) { break1_stop1.setText("0" + break1_hrs_stop + ":" + break1_min_stop); } else if (break1_hrs_stop > 9 && break1_min_stop < 10) { break1_stop1.setText(break1_hrs_stop + ":0" + break1_min_stop); } else if (break1_hrs_stop < 10 && break1_min_stop < 10) { break1_stop1.setText("0" + break1_hrs_stop + ":0" + break1_min_stop); } else { break1_stop1.setText(break1_hrs_stop + ":" + break1_min_stop); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Break1 Stop"); timePickerDialog.show(); } }); break2_start1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { break2_hrs_start = hourOfDay; break2_min_start = minute; if (break2_hrs_start < 10 && break2_min_start > 9) { break2_start1.setText("0" + break2_hrs_start + ":" + break2_min_start); } else if (break2_hrs_start > 9 && break2_min_start < 10) { break2_start1.setText(break2_hrs_start + ":0" + break2_min_start); } else if (break2_hrs_start < 10 && break2_min_start < 10) { break2_start1.setText("0" + break2_hrs_start + ":0" + break2_min_start); } else { break2_start1.setText(break2_hrs_start + ":" + break2_min_start); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Break2 Start"); timePickerDialog.show(); } }); break2_stop1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { break2_hrs_stop = hourOfDay; break2_min_stop = minute; if (break2_hrs_stop < 10 && break2_min_stop > 9) { break2_stop1.setText("0" + break2_hrs_stop + ":" + break2_min_stop); } else if (break2_hrs_stop > 9 && break2_min_stop < 10) { break2_stop1.setText(break2_hrs_stop + ":0" + break2_min_stop); } else if (break2_hrs_stop < 10 && break2_min_start < 10) { break2_stop1.setText("0" + break2_hrs_stop + ":0" + break2_min_stop); } else { break2_stop1.setText(break2_hrs_stop + ":" + break2_min_stop); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Break2 Stop"); timePickerDialog.show(); } }); break3_start1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { break3_hrs_start = hourOfDay; break3_min_start = minute; if (break3_hrs_start < 10 && break3_min_start > 9) { break3_start1.setText("0" + break3_hrs_start + ":" + break3_min_start); } else if (break3_hrs_start > 9 && break3_min_start < 10) { break3_start1.setText(break3_hrs_start + ":0" + break3_min_start); } else if (break3_hrs_start < 10 && break3_min_start < 10) { break3_start1.setText("0" + break3_hrs_start + ":0" + break3_min_start); } else { break3_start1.setText(break3_hrs_start + ":" + break3_min_start); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Break3 Start"); timePickerDialog.show(); } }); break3_stop1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { break3_hrs_stop = hourOfDay; break3_min_stop = minute; if (break3_hrs_stop < 10 && break3_min_stop > 9) { break3_stop1.setText("0" + break3_hrs_stop + ":" + break3_min_stop); } else if (break3_hrs_stop > 9 && break3_min_stop < 10) { break3_stop1.setText(break3_hrs_stop + ":0" + break3_min_stop); } else if (break3_hrs_stop < 10 && break3_min_stop < 10) { break3_stop1.setText("0" + break3_hrs_stop + ":0" + break3_min_stop); } else { break3_stop1.setText(break3_hrs_stop + ":" + break3_min_stop); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Break3 Stop"); timePickerDialog.show(); } }); exit1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { TimePickerDialog timePickerDialog; timePickerDialog = new TimePickerDialog( manualEntry.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { exithourSelected = hourOfDay; exitminSelected = minute; Log.e("Just to check", String.valueOf(exithourSelected)); if (exithourSelected < 10 && exitminSelected > 9) { exit1.setText("0" + exithourSelected + ":" + exitminSelected); } else if (exithourSelected > 9 && exitminSelected < 10) { exit1.setText(exithourSelected + ":0" + exitminSelected); } else if (exithourSelected < 10 && exitminSelected < 10) { exit1.setText("0" + exithourSelected + ":0" + exitminSelected); } else { exit1.setText(exithourSelected + ":" + exitminSelected); } } }, mHour, mMinute, true); timePickerDialog.setTitle("Enter Exit Time"); timePickerDialog.show(); } }); edit.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { break3_stop = break3_stop1.getText().toString(); break3_start = break3_start1.getText().toString(); break1_start = break1_start1.getText().toString(); break1_stop = break1_stop1.getText().toString(); break2_stop = break2_stop1.getText().toString(); break2_start = break2_start1.getText().toString(); entry = start1.getText().toString(); exit = exit1.getText().toString(); if (entry.equals("")) { Toast.makeText(getApplicationContext(), "Entry Time not provided", Toast.LENGTH_SHORT) .show(); } else if ((!break2_start.equals("") && break2_stop.equals("")) || (!break1_start.equals("") && break1_stop.equals("")) || (!break3_start.equals("") && break3_stop.equals(""))) { Toast.makeText( getApplicationContext(), "Exit Time for break not Provided", Toast.LENGTH_SHORT) .show(); } else if (exit.equals("")) { Toast.makeText(getApplicationContext(), "Exit Time not Provided", Toast.LENGTH_SHORT) .show(); } else { dbHelper.updateManualEntry( id, entry, exit, break1_start, break2_start, break3_start, break1_stop, break2_stop, break3_stop, dates); start1.setText(""); exit1.setText(""); break1_start1.setText(""); break1_stop1.setText(""); break2_start1.setText(""); break2_stop1.setText(""); break3_start1.setText(""); break3_stop1.setText(""); Toast.makeText(getApplication(), "UPDATE DONE", Toast.LENGTH_SHORT).show(); edit.setEnabled(false); edit.setVisibility(View.INVISIBLE); } } }); drawerLayout = (DrawerLayout) findViewById(R.id.drawlay_manual); /*Drawer*/ nv1 = (NavigationView) findViewById(R.id.draw_manual); abdt = new ActionBarDrawerToggle( this, drawerLayout, tb1, R.string.drawer_open, R.string.drawer_close); drawerLayout.setDrawerListener(abdt); abdt.syncState(); drawerLayout.post( new Runnable() { @Override public void run() { abdt.syncState(); } }); nv1.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.home: { Intent home = new Intent(getApplicationContext(), userHome.class); finish(); startActivity(home); break; } case R.id.month: { Intent month = new Intent(getApplicationContext(), MonthReport.class); finish(); startActivity(month); break; } case R.id.day: Intent intent1 = new Intent(getApplicationContext(), DayReport.class); finish(); startActivity(intent1); break; case R.id.manual: Toast.makeText(getApplicationContext(), "This is Manual Entry", Toast.LENGTH_SHORT) .show(); break; case R.id.logout: final SharedPreferences sharedpreferences1 = getSharedPreferences("Login", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences1.edit(); editor.remove("uname"); editor.remove("pass"); editor.commit(); Intent logout = new Intent(getApplicationContext(), MainActivity.class); finish(); startActivity(logout); break; } drawerLayout.closeDrawers(); return true; } }); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.navigation_drawer_hamburger, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */) { @Override public void onDrawerSlide(View drawerView, float slideOffset) { bgTransitionHandler.updateTransition(slideOffset); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } if (mCallbacks != null) { mCallbacks.onNavigationDrawerClosed(); } } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (mCallbacks != null) { mCallbacks.onNavigationDrawerOpened(); } } }; // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
/** * 设置导航drawer * * @param fragmentId fragmentent的id * @param drawerLayout fragment的容器 */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setHomeButtonEnabled(true); // actionBar.setIcon(R.drawable.ic_action_menu); actionBar.setLogo(getResources().getDrawable(R.drawable.ic_action_menu)); // actionBar.setBackgroundDrawable(); // 隐藏Action bar上的app icon actionBar.setDisplayShowHomeEnabled(true); mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* 宿主 */ mDrawerLayout, /* DrawerLayout 对象 */ R.drawable.ic_action_menu, /* 替换actionbar上的'Up'图标 */ R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().supportInvalidateOptionsMenu(); // 调用 // onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit(); } getActivity().supportInvalidateOptionsMenu(); // 调用 // onPrepareOptionsMenu() } }; // 如果是第一次进入应用,显示抽屉 if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().setTitle(mTitle); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } mTitle = getActivity().getTitle(); getActivity().setTitle(R.string.app_name); if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. Toast.makeText(getActivity(), R.string.drawer_longpress_hint, Toast.LENGTH_LONG) .show(); mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().invalidateOptionsMenu(); } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerLinearLayout = (LinearLayout) getActivity().findViewById(R.id.left_drawer_view); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); mDrawerListView = (ExpandableListView) getActivity().findViewById(R.id.left_drawer); mDrawerListView.setAdapter(new NavigationDrawerExpandableListAdapter(getActivity())); mDrawerListView.setOnGroupClickListener(new DrawerOnGroupClickListener()); mDrawerListView.setOnChildClickListener(new DrawerOnChildClickListener()); mDrawerListView.setGroupIndicator(null); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.app_name, /* "open drawer" description for accessibility */ R.string.app_name /* "close drawer" description for accessibility */) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } for (int i = 0; i < mDrawerListView.getExpandableListAdapter().getGroupCount(); i++) { if (mDrawerListView.isGroupExpanded(i)) { mDrawerListView.collapseGroup(i); TextView textView = (TextView) mDrawerListView.getChildAt(i); textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_bullet, 0, 0, 0); } } getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // this code opens drawer at startup // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. // if (!mUserLearnedDrawer && !mFromSavedInstanceState) { // mDrawerLayout.openDrawer(mFragmentContainerView); // } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
public void setUp( int fragmentId, DrawerLayout drawerLayout, NavigationDrawerAdapter adapter, AvatarLoader avatar, Organization user) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); int drawerWidth = checkTabletOrLandscape() ? R.dimen.navigation_drawer_width : materializedWidth(); mDrawerListView.getLayoutParams().width = drawerWidth; View header = getActivity().getLayoutInflater().inflate(R.layout.drawer_header, mDrawerListView, false); userImage = (ImageView) header.findViewById(R.id.user_picture); userRealName = (TextView) header.findViewById(R.id.user_real_name); userName = (TextView) header.findViewById(R.id.user_name); avatar.bind(userImage, user); userName.setText(user.login); String name = user.name; if (name != null) { userRealName.setText(user.name); } else { userRealName.setVisibility(View.GONE); } mDrawerListView.addHeaderView(header, null, false); mDrawerListView.setAdapter(adapter); mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().supportInvalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().supportInvalidateOptionsMenu(); } }; if (!mUserLearnedDrawer && !mFromSavedInstanceState) mDrawerLayout.openDrawer(mFragmentContainerView); mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }