use of android.support.v4.app.ActionBarDrawerToggle in project MaterialDrawer by mikepenz.
the class DrawerBuilder method handleDrawerNavigation.
/**
* handles the different logics for the Drawer Navigation Listeners / Indications (ActionBarDrawertoggle)
*/
protected void handleDrawerNavigation(Activity activity, boolean recreateActionBarDrawerToggle) {
//set the navigationOnClickListener
final View.OnClickListener toolbarNavigationListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean handled = false;
if (mOnDrawerNavigationListener != null && (mActionBarDrawerToggle != null && !mActionBarDrawerToggle.isDrawerIndicatorEnabled())) {
handled = mOnDrawerNavigationListener.onNavigationClickListener(v);
}
if (!handled) {
if (mDrawerLayout.isDrawerOpen(mDrawerGravity)) {
mDrawerLayout.closeDrawer(mDrawerGravity);
} else {
mDrawerLayout.openDrawer(mDrawerGravity);
}
}
}
};
if (recreateActionBarDrawerToggle) {
mActionBarDrawerToggle = null;
}
// create the ActionBarDrawerToggle if not set and enabled and if we have a toolbar
if (mActionBarDrawerToggleEnabled && mActionBarDrawerToggle == null && mToolbar != null) {
this.mActionBarDrawerToggle = new ActionBarDrawerToggle(activity, mDrawerLayout, mToolbar, R.string.material_drawer_open, R.string.material_drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
if (mOnDrawerListener != null) {
mOnDrawerListener.onDrawerOpened(drawerView);
}
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
if (mOnDrawerListener != null) {
mOnDrawerListener.onDrawerClosed(drawerView);
}
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
if (mOnDrawerListener != null) {
mOnDrawerListener.onDrawerSlide(drawerView, slideOffset);
}
if (!mAnimateActionBarDrawerToggle) {
super.onDrawerSlide(drawerView, 0);
} else {
super.onDrawerSlide(drawerView, slideOffset);
}
}
};
this.mActionBarDrawerToggle.syncState();
}
//we also have to do this after setting the ActionBarDrawerToggle as this will overwrite this
if (mToolbar != null) {
this.mToolbar.setNavigationOnClickListener(toolbarNavigationListener);
}
//handle the ActionBarDrawerToggle
if (mActionBarDrawerToggle != null) {
mActionBarDrawerToggle.setToolbarNavigationClickListener(toolbarNavigationListener);
mDrawerLayout.addDrawerListener(mActionBarDrawerToggle);
} else {
mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
if (mOnDrawerListener != null) {
mOnDrawerListener.onDrawerSlide(drawerView, slideOffset);
}
}
@Override
public void onDrawerOpened(View drawerView) {
if (mOnDrawerListener != null) {
mOnDrawerListener.onDrawerOpened(drawerView);
}
}
@Override
public void onDrawerClosed(View drawerView) {
if (mOnDrawerListener != null) {
mOnDrawerListener.onDrawerClosed(drawerView);
}
}
@Override
public void onDrawerStateChanged(int newState) {
}
});
}
}
use of android.support.v4.app.ActionBarDrawerToggle in project platform_frameworks_base by android.
the class DrawerController method create.
/**
* Returns a controller suitable for {@code Layout}.
*/
static DrawerController create(Activity activity) {
DrawerLayout layout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
if (layout == null) {
return new DummyDrawerController();
}
View drawer = activity.findViewById(R.id.drawer_roots);
Toolbar toolbar = (Toolbar) activity.findViewById(R.id.roots_toolbar);
drawer.getLayoutParams().width = calculateDrawerWidth(activity);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(activity, layout, R.drawable.ic_hamburger, R.string.drawer_open, R.string.drawer_close);
return new RuntimeDrawerController(layout, drawer, toggle, toolbar);
}
use of android.support.v4.app.ActionBarDrawerToggle in project SimpleNews by liuling07.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
mDrawerToggle.syncState();
mDrawerLayout.setDrawerListener(mDrawerToggle);
mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
setupDrawerContent(mNavigationView);
mMainPresenter = new MainPresenterImpl(this);
switch2News();
}
use of android.support.v4.app.ActionBarDrawerToggle in project FloatingActionButton by Clans.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerLayout.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(navigationItemSelectedListener);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.fragment, new HomeFragment()).commit();
}
navigationView.setCheckedItem(R.id.home);
}
use of android.support.v4.app.ActionBarDrawerToggle in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
deviceFragment = new DeviceFragment();
cellInfoFragment = new CellInfoFragment();
atCommandFragment = new AtCommandFragment();
dbViewerFragment = new DbViewerFragment();
mapFragment = new MapFragment();
mNavConf = new DrawerMenuActivityConfiguration.Builder(this).build();
mDrawerLayout = (DrawerLayout) findViewById(mNavConf.getDrawerLayoutId());
mDrawerList = (ListView) findViewById(mNavConf.getLeftDrawerId());
mActionBar = getSupportActionBar();
mTitle = getTitle();
mDrawerTitle = getTitle();
mDrawerList.setAdapter(mNavConf.getBaseAdapter());
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close) {
/* "close drawer" description */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
mActionBar.setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
mActionBar.setTitle(mDrawerTitle);
invalidateOptionsMenu();
}
};
// Set the drawer toggle as the DrawerListener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerLayout.setDrawerListener(mDrawerToggle);
mActionBar.setDisplayHomeAsUpEnabled(true);
mActionBar.setHomeButtonEnabled(true);
prefs = getSharedPreferences(AimsicdService.SHARED_PREFERENCES_BASENAME, 0);
/* Pref listener to enable sms detection on pref change */
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (key.equals(getString(R.string.adv_user_root_pref_key))) {
SmsDetection();
}
}
};
prefs.registerOnSharedPreferenceChangeListener(prefListener);
mDisclaimerAccepted = getResources().getString(R.string.disclaimer_accepted);
if (!prefs.getBoolean(mDisclaimerAccepted, false)) {
final AlertDialog.Builder disclaimer = new AlertDialog.Builder(this).setTitle(R.string.disclaimer_title).setMessage(R.string.disclaimer).setPositiveButton(R.string.text_agree, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
prefsEditor = prefs.edit();
prefsEditor.putBoolean(mDisclaimerAccepted, true);
prefsEditor.apply();
startService();
}
}).setNegativeButton(R.string.text_disagree, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
prefsEditor = prefs.edit();
prefsEditor.putBoolean(mDisclaimerAccepted, false);
prefsEditor.apply();
Uri packageUri = Uri.parse("package:com.SecUpwN.AIMSICD");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
startActivity(uninstallIntent);
finish();
if (mAimsicdService != null) {
mAimsicdService.onDestroy();
}
}
});
AlertDialog disclaimerAlert = disclaimer.create();
disclaimerAlert.show();
} else {
startService();
}
}
Aggregations