use of android.support.v7.app.ActionBarDrawerToggle in project carat by amplab.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CaratApplication.setMain(this);
tracker = Tracker.getInstance();
// track user clicks (taps)
tracker.trackUser("caratstarted");
if (!CaratApplication.isInternetAvailable()) {
EnableInternetDialogFragment dialog = new EnableInternetDialogFragment();
dialog.show(getSupportFragmentManager(), "dialog");
}
/*
* Activity.getWindow.requestFeature() should get invoked only before
* setContentView(), otherwise it will cause an app crash The progress
* bar doesn't get displayed when there is no update in progress
*/
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
// Log.d(TAG, "about to set the layout");
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
setTitleNormal();
// read and load the preferences specified in our xml preference file
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
// Log.d(TAG, "about to initialize fragments");
preInittializeFragments();
// Log.d(TAG, "done with fragment initialization");
/*
* Before using the field "fullVersion", first invoke setTitleNormal()
* or setFullVersion() to set this field
*/
mDrawerItems = getResources().getStringArray(R.array.drawer_items);
List<Item> items = new ArrayList<Item>();
// items.add(new NavDrawerListHeader("Main"));
items.add(new ListItem(mDrawerItems[0]));
items.add(new ListItem(mDrawerItems[1]));
items.add(new ListItem(mDrawerItems[2]));
items.add(new ListItem(mDrawerItems[3]));
items.add(new ListItem(mDrawerItems[4]));
items.add(new NavDrawerListHeader(""));
items.add(new ListItem(mDrawerItems[5]));
items.add(new ListItem(mDrawerItems[6]));
TextArrayAdapter adapter = new TextArrayAdapter(this, items);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// 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
mDrawerList.setAdapter(adapter);
// mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerItems));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close) {
/* "close drawer" description for accessibility */
public void onDrawerClosed(View view) {
//getSupportActionBar().setTitle(mTitle);
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mTitle);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Enable ActionBar app icon to behave as action to toggle navigation drawer
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
if (savedInstanceState == null) {
selectItem(0);
}
setTitleNormal();
// Uncomment the following to enable listening on local port 8080:
/*
* try {
* HelloServer h = new HelloServer();
* } catch (IOException e) {
* e.printStackTrace();
* }
*/
}
use of android.support.v7.app.ActionBarDrawerToggle in project JamsMusicPlayer by psaravan.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
//Context and Common object(s).
mContext = getApplicationContext();
mApp = (Common) getApplicationContext();
//Set the theme and inflate the layout.
setTheme();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Init the UI elements.
mDrawerParentLayout = (FrameLayout) findViewById(R.id.main_activity_root);
mDrawerLayout = (DrawerLayout) findViewById(R.id.main_activity_drawer_root);
mNavDrawerLayout = (RelativeLayout) findViewById(R.id.nav_drawer_container);
mCurrentQueueDrawerLayout = (RelativeLayout) findViewById(R.id.current_queue_drawer_container);
//Load the drawer fragments.
loadDrawerFragments();
//KitKat specific translucency.
applyKitKatTranslucency();
//Load the fragment.
loadFragment(savedInstanceState);
/**
* Navigation drawer toggle.
*/
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer, 0, 0) {
@Override
public void onDrawerClosed(View view) {
if (mQueueDrawerFragment != null && view == mCurrentQueueDrawerLayout)
mQueueDrawerFragment.setIsDrawerOpen(false);
}
@Override
public void onDrawerOpened(View view) {
if (mQueueDrawerFragment != null && view == mCurrentQueueDrawerLayout)
mQueueDrawerFragment.setIsDrawerOpen(true);
}
};
//Apply the drawer toggle to the DrawerLayout.
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
//Check if this is the first time the app is being started.
if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {
showAlbumArtScanningDialog();
mApp.getSharedPreferences().edit().putBoolean(Common.FIRST_RUN, false).commit();
}
}
use of android.support.v7.app.ActionBarDrawerToggle in project android by owncloud.
the class DrawerActivity method setupDrawer.
/**
* Initializes the drawer and its content.
* This method needs to be called after the content view has been set.
*/
protected void setupDrawer() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
if (mNavigationView != null) {
mAccountChooserToggle = (ImageView) findNavigationViewChildById(R.id.drawer_account_chooser_toogle);
mAccountChooserToggle.setImageResource(R.drawable.ic_down);
mIsAccountChooserActive = false;
mAccountMiddleAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_middle);
mAccountEndAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_end);
// ruining the generic avatars, so tinting for icons is deactivated pre lollipop
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mNavigationView.setItemIconTintList(null);
}
setupDrawerContent(mNavigationView);
findNavigationViewChildById(R.id.drawer_active_user).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleAccountList();
}
});
}
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
// standard behavior of drawer is to switch to the standard menu on closing
if (mIsAccountChooserActive) {
toggleAccountList();
}
invalidateOptionsMenu();
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
mDrawerToggle.setDrawerIndicatorEnabled(true);
invalidateOptionsMenu();
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.addDrawerListener(mDrawerToggle);
mDrawerToggle.setDrawerIndicatorEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
use of android.support.v7.app.ActionBarDrawerToggle in project cw-omnibus by commonsguy.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (getFragmentManager().findFragmentById(R.id.content) == null) {
showLorem();
}
ListView drawer = (ListView) findViewById(R.id.drawer);
drawer.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_row, getResources().getStringArray(R.array.drawer_rows)));
drawer.setOnItemClickListener(this);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
drawerLayout.setDrawerListener(toggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
use of android.support.v7.app.ActionBarDrawerToggle in project GeekNews by codeestX.
the class MainActivity method initEventAndData.
@Override
protected void initEventAndData() {
setToolBar(mToolbar, "知乎日报");
mZhihuFragment = new ZhihuMainFragment();
mGankFragment = new GankMainFragment();
mWechatFragment = new WechatMainFragment();
mGoldFragment = new GoldMainFragment();
mVtexFragment = new VtexMainFragment();
mLikeFragment = new LikeFragment();
mSettingFragment = new SettingFragment();
mAboutFragment = new AboutFragment();
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
mDrawerToggle.syncState();
mDrawerLayout.addDrawerListener(mDrawerToggle);
mLastMenuItem = mNavigationView.getMenu().findItem(R.id.drawer_zhihu);
loadMultipleRootFragment(R.id.fl_main_content, 0, mZhihuFragment, mWechatFragment, mGankFragment, mGoldFragment, mVtexFragment, mLikeFragment, mSettingFragment, mAboutFragment);
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch(menuItem.getItemId()) {
case R.id.drawer_zhihu:
showFragment = Constants.TYPE_ZHIHU;
mSearchMenuItem.setVisible(false);
break;
case R.id.drawer_gank:
showFragment = Constants.TYPE_GANK;
mSearchMenuItem.setVisible(true);
break;
case R.id.drawer_wechat:
showFragment = Constants.TYPE_WECHAT;
mSearchMenuItem.setVisible(true);
break;
case R.id.drawer_gold:
showFragment = Constants.TYPE_GOLD;
mSearchMenuItem.setVisible(false);
break;
case R.id.drawer_vtex:
showFragment = Constants.TYPE_VTEX;
mSearchMenuItem.setVisible(false);
break;
case R.id.drawer_setting:
showFragment = Constants.TYPE_SETTING;
mSearchMenuItem.setVisible(false);
break;
case R.id.drawer_like:
showFragment = Constants.TYPE_LIKE;
mSearchMenuItem.setVisible(false);
break;
case R.id.drawer_about:
showFragment = Constants.TYPE_ABOUT;
mSearchMenuItem.setVisible(false);
break;
}
if (mLastMenuItem != null) {
mLastMenuItem.setChecked(false);
}
mLastMenuItem = menuItem;
SharedPreferenceUtil.setCurrentItem(showFragment);
menuItem.setChecked(true);
mToolbar.setTitle(menuItem.getTitle());
mDrawerLayout.closeDrawers();
showHideFragment(getTargetFragment(showFragment), getTargetFragment(hideFragment));
hideFragment = showFragment;
return true;
}
});
mSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (showFragment == Constants.TYPE_GANK) {
mGankFragment.doSearch(query);
} else if (showFragment == Constants.TYPE_WECHAT) {
RxBus.getDefault().post(new SearchEvent(query, Constants.TYPE_WECHAT));
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
if (!SharedPreferenceUtil.getVersionPoint() && SystemUtil.isWifiConnected()) {
SharedPreferenceUtil.setVersionPoint(true);
try {
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
String versionName = pi.versionName;
mPresenter.checkVersion(versionName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
}
Aggregations