Java Code Examples for android.support.v4.widget.DrawerLayout

The following examples show how to use android.support.v4.widget.DrawerLayout. These examples are extracted from open source projects. 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 Project: ByWebView   Source File: StatusBarUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color        状态栏颜色值
 */
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 生成一个状态栏大小的矩形
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
            contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
        } else {
            // 添加 statusBarView 到布局中
            StatusBarView statusBarView = createStatusBarView(activity, color);
            contentLayout.addView(statusBarView, 0);
        }
        // 内容布局不是 LinearLayout 时,设置padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 设置属性
        ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
        drawerLayout.setFitsSystemWindows(false);
        contentLayout.setFitsSystemWindows(false);
        contentLayout.setClipToPadding(true);
        drawer.setFitsSystemWindows(false);
    }
}
 
Example 2
Source Project: kute   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.landing);

    // Set a Toolbar to replace the ActionBar.
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Find our drawer view
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Find our drawer view
    nvDrawer = (NavigationView) findViewById(R.id.nvView);
    // Setup drawer view
    setupDrawerContent(nvDrawer);



}
 
Example 3
Source Project: Cybernet-VPN   Source File: BrowserActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        // Handle the camera action
    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 4
Source Project: funcodetuts   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    // Code here will be triggered once the drawer closes as we don't want anything to happen so we leave this blank
    mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    //calling sync state is necessary or else your hamburger icon wont show up
    mActionBarDrawerToggle.syncState();

    if (savedInstanceState == null) {
        // update the main content by replacing fragments
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        FragmentTransaction transaction = fragmentManager.beginTransaction();

        transaction.replace(R.id.container, new ContainerFragment());
        transaction.commit();
    }
}
 
Example 5
Source Project: FimiX8-RE   Source File: StatusBarUtil.java    License: MIT License 6 votes vote down vote up
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (VERSION.SDK_INT >= 19) {
        if (VERSION.SDK_INT >= 21) {
            activity.getWindow().addFlags(Integer.MIN_VALUE);
            activity.getWindow().clearFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
            activity.getWindow().setStatusBarColor(0);
        } else {
            activity.getWindow().addFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
        }
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (!((contentLayout instanceof LinearLayout) || contentLayout.getChildAt(1) == null)) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        setDrawerLayoutProperty(drawerLayout, contentLayout);
    }
}
 
Example 6
Source Project: XFrame   Source File: XStatusBar.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
}
 
Example 7
Source Project: blade-player   Source File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBackPressed()
{
    // Handle drawer close
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START))
    {
        drawer.closeDrawer(GravityCompat.START);
    }
    else if(backBundles.size() != 0)
    {
        restoreInstanceState(backBundles.get(backBundles.size()-1), backObjects.get(backObjects.size()-1));
        backBundles.remove(backBundles.size()-1);
        backObjects.remove(backObjects.size()-1);
    }
    else
    {
        super.onBackPressed();
    }
}
 
Example 8
Source Project: Puff-Android   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {

    Category category = CategoryHelper.getInstance(getApplicationContext())
            .getCategoryByName(String.valueOf(item.getTitle()));
    loadAccountByCategory(category);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (headerImageView != null)
        Picasso.with(this).load(ResUtil.getInstance(null).getBmpUri(category.getIcon()))
                .config(Bitmap.Config.RGB_565)
                .fit()
                .into(headerImageView);
    if (headerTextView != null)
        headerTextView.setText(category.getName());
    drawer.closeDrawer(GravityCompat.START);
    if (lastChecked != null)
        lastChecked.setChecked(false);
    item.setChecked(true);
    lastChecked = item;
    return true;
}
 
Example 9
Source Project: SensorsAndAi   Source File: HomeActivity.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId ();

    if (id == R.id.nav_camera) {
        // Handle the camera action
    } else if (id == R.id.nav_gallery) {
        startActivity ( new Intent ( HomeActivity.this,About_us.class ) );

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById ( R.id.drawer_layout );
    drawer.closeDrawer ( GravityCompat.START );
    return true;
}
 
Example 10
Source Project: wshell   Source File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
	switch (item.getItemId()) {
		case R.id.nav_settings:
			Intent intent_settings = new Intent(this, SettingsActivity.class);
			startActivity(intent_settings);
			break;
		case R.id.nav_about:
			Intent intent_about = new Intent(this, AboutActivity.class);
			startActivity(intent_about);
			break;
		case R.id.nav_exit:
			finish();
			break;
	}
	DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	drawer.closeDrawer(GravityCompat.START);
	return true;
}
 
Example 11
Source Project: ZZShow   Source File: HomeActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initViews() {
    mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if(isSwitchNight && ismIsAddedView()){
                setIsAddedView(false);
                getWindow().setWindowAnimations(R.style.WindowAnimationFadeInOut);
                KLog.d("NightMode"," - recreate - ");
                recreate();
            }
        }
    });

    mNavigationView.setNavigationItemSelectedListener(this);
    initNightModeSwitch();
    childFragmentType = childFragmentType == null ? CHILD_FRAGMENT_TAG_NEWS : childFragmentType;
    setDefaultChildFragment(childFragmentType);
}
 
Example 12
Source Project: FileManager   Source File: StatusBarUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity 需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color 状态栏颜色值
 */
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout,
    int color) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    // 生成一个状态栏大小的矩形
    View statusBarView = createStatusBarView(activity, color);
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    contentLayout.addView(statusBarView, 0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
      contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }
    // 设置属性
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);
  }
}
 
Example 13
Source Project: MNImageBrowser   Source File: ImmersionBar.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 检查布局根节点是否使用了android:fitsSystemWindows="true"属性
 * Check fits system windows boolean.
 *
 * @param view the view
 * @return the boolean
 */
public static boolean checkFitsSystemWindows(View view) {
    if (view == null) {
        return false;
    }
    if (view.getFitsSystemWindows()) {
        return true;
    }
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
            View childView = viewGroup.getChildAt(i);
            if (childView instanceof DrawerLayout) {
                if (checkFitsSystemWindows(childView)) {
                    return true;
                }
            }
            if (childView.getFitsSystemWindows()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 14
Source Project: MaoWanAndoidClient   Source File: StatusBarUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
}
 
Example 15
Source Project: TLint   Source File: StatusBarUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);
}
 
Example 16
Source Project: SeeWeather   Source File: RxDrawer.java    License: Apache License 2.0 6 votes vote down vote up
public static Observable<Irrelevant> close(final DrawerLayout drawer) {
    return Observable.create(emitter -> {
        drawer.closeDrawer(GravityCompat.START);
        DrawerListener listener = new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                if (slideOffset < OFFSET_THRESHOLD) {
                    emitter.onNext(Irrelevant.INSTANCE);
                    emitter.onComplete();
                    drawer.removeDrawerListener(this);
                }
            }
        };
        drawer.addDrawerListener(listener);
    });
}
 
Example 17
Source Project: miappstore   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void initToolBar() {
    super.initToolBar();
    view = View.inflate(this, R.layout.activity_main, null);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
    toolbar.setBackgroundColor(getResources().getColor(R.color.light_toolbar));
    toolbar.setTitle("应用商店");
    toolbar.setLogo(R.mipmap.logo);//设置Logo
    setSupportActionBar(toolbar);
    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.app_name, R.string.app_name
    );
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();
}
 
Example 18
Source Project: FoodOrdering   Source File: Activity_Main.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 先加载不需要动态获取数据的静态布局,有利于用户体验
 */
private void initStaticView() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    navView = (NavigationView) findViewById(R.id.nav_view);
    bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    toolbar.setTitle("");
    toolbarText = (TextView) findViewById(R.id.toolbar_text);
    toolbarText.setText("首页");

    setSupportActionBar(toolbar);//使用toolbar,外观功能和ActionBar一致
    final ActionBar actionBar = getSupportActionBar();//得到ActionBar实例
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);//让导航按钮显示出来
        actionBar.setHomeAsUpIndicator(R.mipmap.ic_menu);//设置导航按钮图标
    }
    //加载底部导航栏及选中事件
    loadBottomNavigationBar();
}
 
Example 19
@Override
protected void onResume(){
    super.onResume();
    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), menu_name, this);
    getData();
}
 
Example 20
Source Project: Weather-Lite   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example 21
Source Project: MaterialDesignSupport   Source File: DrawerOnClickListener.java    License: MIT License 5 votes vote down vote up
public DrawerOnClickListener(CoreMaterialActivity activity, LinearLayout drawer, DrawerLayout drawerLayout, int resId, int position,
        boolean isParent) {
    mActivity = activity;
    mDrawer = drawer;
    mDrawerLayout = drawerLayout;
    mClasses = ResourceHelper.getStringArray(resId);
    mPosition = position;
    mIsParent = isParent;
}
 
Example 22
Source Project: 10000sentences   Source File: BaseActivity.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_collections) {
        CollectionsActivity.start(this);
    } else if (id == R.id.nav_annotations) {
        AnnotationsActivity.start(this);
    } else if (id == R.id.nav_reload) {
        reloadLanguages();
    } else if (id == R.id.nav_stats) {
        StatsActivity.start(this);
    } else if (id == R.id.nav_settings) {
        SettingsActivity.start(this);
    } else if (id == R.id.nav_tts_settings) {
        Intent intent = new Intent()
                .setAction("com.android.settings.TTS_SETTINGS")
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } else if (id == R.id.nav_about) {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(this.getPackageName(), 0);
            HtmlActivity.start(this, getString(R.string.about), getString(R.string.info_contents, info.versionName, String.valueOf(info.versionCode)), false);
        } catch (Exception e) {
            Toast.makeText(this, R.string.unexpected_error, Toast.LENGTH_SHORT).show();
            Log.e(TAG, e.getMessage(), e);
        }
    } else if (id == R.id.nav_help) {
        HtmlActivity.start(this, getString(R.string.help), getString(R.string.help_contents), true);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 23
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drawer_activity_emv_read);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.emv_drawer_layout);
    mNavDrawer = new NavDrawer(this, savedInstanceState, R.id.emv_read, drawerLayout, toolbar);

    ListView listView = (ListView) findViewById(R.id.msg_list);
    ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.switcher);
    mConsole = new Console(this, savedInstanceState, TEST_MODE_EMV_READ, listView, switcher);
    mNfcManager = new NfcManager(this, this);

    ApduParser.init(this);
    EMVTerminal.loadProperties(getResources());

    // persistent "shared preferences"
    SharedPreferences ss = getSharedPreferences("prefs", Context.MODE_PRIVATE);
    mEditor = ss.edit();

    // persistent settings and settings listener
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(this);

    mAutoClear = prefs.getBoolean("pref_auto_clear", true);
    mShowMsgSeparators = prefs.getBoolean("pref_show_separators", true);
    String tapFeedback = prefs.getString("pref_tap_feedback", "1");
    mTapFeedback = Integer.valueOf(tapFeedback);

    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
}
 
Example 24
Source Project: firebase-android-client   Source File: PlayActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);

    switchChannel(item.toString());

    return true;
}
 
Example 25
Source Project: arcgis-runtime-demos-android   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  mMapView = (MapView) findViewById(R.id.mapView);
  ArcGISMap map = new ArcGISMap(Basemap.Type.IMAGERY_WITH_LABELS, 0, 0, 1);
  mMapView.setMap(map);

  navCompletedListener = new LogCenterAndScale();
  mMapView.addNavigationChangedListener(navCompletedListener);

  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      mMapView.setViewpointAsync(mWorldViewpoint, 2);
    }
  });

  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.setDrawerListener(toggle);
  toggle.syncState();

  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
}
 
Example 26
Source Project: jus   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment frag;

    if (id == R.id.nav_camera) {
        frag = ImageListFragment.newInstance();
    } else if (id == R.id.nav_gallery) {
        MyJus.intructablesApi().list(20, 0, Instructables.SORT_RECENT, "id");
        frag = InstructablesListFragment.newInstance();
    } else if (id == R.id.nav_slideshow) {
        frag = BlankFragment.newInstance();
    } else if (id == R.id.nav_manage) {
        frag = BlankFragment.newInstance();
    } else if (id == R.id.nav_share) {
        frag = BlankFragment.newInstance();
    } else if (id == R.id.nav_send) {
        frag = BlankFragment.newInstance();
    } else {
        frag = BlankFragment.newInstance();
    }

    fragmentManager.beginTransaction()
            .replace(R.id.container, frag)
            .commit();

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 27
Source Project: candybar-library   Source File: CandyBarMainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onSearchExpanded(boolean expand) {
    Toolbar toolbar = findViewById(R.id.toolbar);
    mIsMenuVisible = !expand;

    if (expand) {
        int color = ColorHelper.getAttributeColor(this, R.attr.toolbar_icon);
        toolbar.setNavigationIcon(DrawableHelper.getTintedDrawable(
                this, R.drawable.ic_toolbar_back, color));
        toolbar.setNavigationOnClickListener(view -> onBackPressed());
    } else {
        SoftKeyboardHelper.closeKeyboard(this);
        ColorHelper.setStatusBarColor(this, Color.TRANSPARENT, true);
        if (CandyBarApplication.getConfiguration().getNavigationIcon() == CandyBarApplication.NavigationIcon.DEFAULT) {
            mDrawerToggle.setDrawerArrowDrawable(new DrawerArrowDrawable(this));
        } else {
            toolbar.setNavigationIcon(ConfigurationHelper.getNavigationIcon(this,
                    CandyBarApplication.getConfiguration().getNavigationIcon()));
        }

        toolbar.setNavigationOnClickListener(view ->
                mDrawerLayout.openDrawer(GravityCompat.START));
    }

    mDrawerLayout.setDrawerLockMode(expand ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED :
            DrawerLayout.LOCK_MODE_UNLOCKED);
    supportInvalidateOptionsMenu();
}
 
Example 28
Source Project: browser   Source File: BrowserActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onDrawerOpened(View v) {

	if (v == mDrawerRight) {
		mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerLeft);
	} else {
		mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerRight);
	}

}
 
Example 29
Source Project: LyricHere   Source File: ActionBarCastActivity.java    License: 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 30
Source Project: SystemUITuner2   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id != R.id.nav_exit) {
        setThings.editor.putInt("navpage", id);
        setThings.editor.apply();

        fragment = chooseFrag(id);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                fragmentManager.beginTransaction().replace(R.id.content_main, fragment).commit();
                setTitle(title);
                setThings.editor.putString("currentTitle", title.toString()).apply();
            }
        }, 350);

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }

    if (id == R.id.nav_exit) { //if exit button pressed, quit app (needs to be at end of method to avoid exceptions)
        Intent intent = new Intent("finish_systemuituner_activity");
        sendBroadcast(intent);
        super.onBackPressed();
    }
    return true;
}