Java Code Examples for com.google.android.material.navigation.NavigationView#setNavigationItemSelectedListener()

The following examples show how to use com.google.android.material.navigation.NavigationView#setNavigationItemSelectedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BottomNavigationDialogFragment.java    From ui with Apache License 2.0 7 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View myView = inflater.inflate(R.layout.fragment_bottomsheet, container, false);
    NavigationView nw = myView.findViewById(R.id.navigation_view);
    nw.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            mListener.onFragmentPicker(menuItem.getItemId());
            dismiss();
            return false;
        }
    });

    return myView;
}
 
Example 2
Source File: MainActivity.java    From ArcNavigationView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    NavigationView navigationView = findViewById(R.id.nav_view);
    NavigationView navigationViewRight = findViewById(R.id.nav_view_right);
    navigationViewRight.setNavigationItemSelectedListener(this);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example 3
Source File: MainActivity.java    From iBeacon-Android with 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);
    Log.i("TimeAttendantFast", "Main Activity Create");
    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 = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    TimeAttendantFastFragment fragment = TimeAttendantFastFragment.newInstance();
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.contentFrame, fragment, null).disallowAddToBackStack().commit();
}
 
Example 4
Source File: NavigationDrawer.java    From Open-Source-Android-Weather-App with MIT License 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Suspect 2
        setContentView(R.layout.activity_main);
        //Toolbar toolbar = findViewById(R.id.drawer_layout);
        //Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        //setSupportActionBar(toolbar);

        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);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        //NavigationView navigationView = findViewById(R.id.nav_view);
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }
 
Example 5
Source File: MainActivity.java    From VoIpUSSD with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
//        ((App)getApplicationContext()).getAppComponent().inject(this);
        getActivityComponent().inject(this);
        super.onCreate(savedInstanceState);
        if (savedInstanceState == null)
            splashy();
        setContentView(R.layout.activity_main_menu);

        appUpdateManager.registerListener(this);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(getString(R.string.title_activity_cp1));
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        FragmentTransaction fragment = getSupportFragmentManager().beginTransaction();
        fragment.replace(R.id.fragment_layout, new MainFragment())
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                .addToBackStack(null)
                .commit();

    }
 
Example 6
Source File: Home.java    From UberClone with MIT License 5 votes vote down vote up
public void initDrawer(){
    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.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View navigationHeaderView=navigationView.getHeaderView(0);
    TextView tvName=(TextView)navigationHeaderView.findViewById(R.id.tvRiderName);
    TextView tvStars=(TextView)findViewById(R.id.tvStars);
    CircleImageView imageAvatar=(CircleImageView) navigationHeaderView.findViewById(R.id.imgAvatar);

    tvName.setText(Common.currentUser.getName());
    if(Common.currentUser.getRates()!=null &&
            !TextUtils.isEmpty(Common.currentUser.getRates()))
        tvStars.setText(Common.currentUser.getRates());

    if(isLoggedInFacebook)
        Picasso.get().load("https://graph.facebook.com/" + Common.userID + "/picture?width=500&height=500").into(imageAvatar);
    else if(account!=null)
        Picasso.get().load(account.getPhotoUrl()).into(imageAvatar);
    if(Common.currentUser.getAvatarUrl()!=null &&
            !TextUtils.isEmpty(Common.currentUser.getAvatarUrl()))
        Picasso.get().load(Common.currentUser.getAvatarUrl()).into(imageAvatar);
}
 
Example 7
Source File: NavigationDrawerFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void initNavigationView(View rootView) {
    NavigationView navigationView = rootView.findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this::onOptionsItemSelected);
    MenuItem menuItem = navigationView.getMenu().findItem(R.id.menu_gun);
    NavigationMenuView menuView = (NavigationMenuView) navigationView.getChildAt(0);
    menuView.setVerticalScrollBarEnabled(false);
    View actionView = getLayoutInflater().inflate(R.layout.nav_menu_action_view_gun, null);
    menuItem.setActionView(actionView);
    menuItem.expandActionView();
    mReplyCountView = actionView.findViewById(R.id.reply_count);
    mHeaderView = navigationView.getHeaderView(0).findViewById(R.id.viewFlipper);
    updateHeaderView();
}
 
Example 8
Source File: MainActivity.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    localeDelegate.onCreate(this);

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

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

    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (savedInstanceState == null){
        navigationView.setCheckedItem(R.id.nav_outline);
        Fragment fragment = new OutlineFragment();
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_main, fragment, FRAGMENT_OUTLINE)
                .commit();
    }

    Info.INSTANCE.welcome(this);
    Version.INSTANCE.dataVersionChange(this);
    Version.INSTANCE.nearFutureChange(this);
}
 
Example 9
Source File: SampleActivity.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.openDrawer(GravityCompat.START);
    drawer.clearAnimation();
    drawer.setAnimation(null);
    drawer.setLayoutAnimation(null);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.clearAnimation();
    navigationView.setAnimation(null);
    navigationView.setLayoutAnimation(null);

    bitmapView = findViewById(R.id.iv_image);
    bitmapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            bitmapView.setVisibility(View.GONE);
        }
    });

    rvImage = (RecyclerView) findViewById(R.id.rv_image);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    adapter = new MainAdapter(this, selectedPhotoList);
    rvImage.setLayoutManager(linearLayoutManager);
    rvImage.setAdapter(adapter);
    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(rvImage);
}
 
Example 10
Source File: DefaultDrawerActivity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_default);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


}
 
Example 11
Source File: AdvanceDrawer6Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance6);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });


    drawer = (AdvanceDrawerLayout) findViewById(R.id.drawer_layout);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        ViewCompat.setLayoutDirection(drawer, View.LAYOUT_DIRECTION_RTL);
    }

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


    drawer.setViewScale(GravityCompat.START, 0.9f);
    drawer.setRadius(GravityCompat.START, 35);
    drawer.setViewElevation(GravityCompat.START, 20);


}
 
Example 12
Source File: AdvanceDrawer4Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance4);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    drawer.setViewScale(Gravity.END, 0.9f);
    drawer.setViewElevation(Gravity.END, 20);


}
 
Example 13
Source File: AdvanceDrawer1Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance1);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    drawer.useCustomBehavior(Gravity.START);
    drawer.useCustomBehavior(Gravity.END);

}
 
Example 14
Source File: AdvanceDrawer5Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance5);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    drawer.setViewScale(Gravity.START, 0.9f);
    drawer.setRadius(Gravity.START, 35);
    drawer.setViewElevation(Gravity.START, 20);


}
 
Example 15
Source File: AdvanceDrawer2Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance2);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    drawer.setViewScale(Gravity.START, 0.9f);
    drawer.setViewElevation(Gravity.START, 20);


}
 
Example 16
Source File: MainActivity.java    From Daedalus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Daedalus.isDarkTheme()) {
        setTheme(R.style.AppTheme_Dark_NoActionBar_TransparentStatusBar);
    }
    super.onCreate(savedInstanceState);

    instance = this;

    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar); //causes toolbar issues

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

    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    ((TextView) navigationView.getHeaderView(0).findViewById(R.id.textView_nav_version)).setText(getString(R.string.nav_version) + " " + BuildConfig.VERSION_NAME);
    ((TextView) navigationView.getHeaderView(0).findViewById(R.id.textView_nav_git_commit)).setText(getString(R.string.nav_git_commit) + " " + BuildConfig.GIT_COMMIT);

    updateUserInterface(getIntent());
}
 
Example 17
Source File: MainActivity.java    From proofmode with GNU General Public License v3.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("");

        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

        View rootView = findViewById(R.id.root);
        layoutOn = rootView.findViewById(R.id.layout_on);
        layoutOff = rootView.findViewById(R.id.layout_off);
/*        layoutOn.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                setProofModeOn(false);
                return true;
            }
        });
        layoutOff.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                setProofModeOn(true);
                return true;
            }
        });*/

        if (mPrefs.getBoolean("firsttime",true)) {
            startActivityForResult(new Intent(this, OnboardingActivity.class), REQUEST_CODE_INTRO);
        }

        //Setup drawer
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerToggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, 0, 0);
        drawer.addDrawerListener(drawerToggle);
        drawerToggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        ImageButton btnSettings = findViewById(R.id.btnSettings);
        btnSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openSettings();
            }
        });

        updateOnOffState(false);
    }
 
Example 18
Source File: MainActivity.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate2(@Nullable Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);

    mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
    mNavView = (NavigationView) ViewUtils.$$(this, R.id.nav_view);
    mRightDrawer = (FrameLayout) ViewUtils.$$(this, R.id.right_drawer);
    View headerLayout = mNavView.getHeaderView(0);
    mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
    mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
    mChangeTheme = (Button) ViewUtils.$$(this, R.id.change_theme);

    mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    // Pre-L need shadow drawable
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT);
    }

    updateProfile();

    if (mNavView != null) {
        mNavView.setNavigationItemSelectedListener(this);
    }

    mChangeTheme.setText(getThemeText());
    mChangeTheme.setOnClickListener(v -> {
        Settings.putTheme(getNextTheme());
        ((EhApplication) getApplication()).recreate();
    });

    if (savedInstanceState == null) {
        onInit();
        CommonOperations.checkUpdate(this, false);
        checkDownloadLocation();
        if (Settings.getCellularNetworkWarning()) {
            checkCellularNetwork();
        }
    } else {
        onRestore(savedInstanceState);
    }

    EhTagDatabase.update(this);
}
 
Example 19
Source File: MainActivity.java    From science-journal with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  savedItemId =
      (savedInstanceState == null)
          ? NO_SELECTED_ITEM
          : savedInstanceState.getInt(ARG_SELECTED_NAV_ITEM_ID, NO_SELECTED_ITEM);

  WhistlePunkApplication.getPerfTrackerProvider(this).onActivityInit();

  accountsProvider = WhistlePunkApplication.getAppServices(this).getAccountsProvider();

  setContentView(R.layout.activity_main);
  accountsProvider.installAccountSwitcher(this);

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

  boolean isTablet = getResources().getBoolean(R.bool.is_tablet);
  if (!isTablet) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }

  final ActionBar actionBar = getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
    actionBar.setHomeActionContentDescription(R.string.navigation_drawer_content_description);
    actionBar.setDisplayShowTitleEnabled(true);
  }

  drawerLayout = (MultiTouchDrawerLayout) findViewById(R.id.drawer_layout);
  drawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.color_primary_dark));
  navigationView = (NavigationView) findViewById(R.id.navigation);
  navigationView.setNavigationItemSelectedListener(this);

  // Only show dev testing options when requested.
  if (!Flags.showTestingOptions()) {
    navigationView.getMenu().removeItem(R.id.dev_testing_options);
  }

  feedbackProvider = WhistlePunkApplication.getAppServices(this).getFeedbackProvider();

  setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
 
Example 20
Source File: MainActivity.java    From NekoSMS with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mCoordinatorLayout = (CoordinatorLayout)findViewById(R.id.main_coordinator);
    mDrawerLayout = (DrawerLayout)findViewById(R.id.main_drawer);
    mNavigationView = (NavigationView)findViewById(R.id.main_navigation);
    mToolbar = (Toolbar)findViewById(R.id.toolbar);
    mFloatingActionButton = (FloatingActionButton)findViewById(R.id.main_fab);

    // Load preferences
    mInternalPrefs = getSharedPreferences(PreferenceConsts.FILE_INTERNAL, MODE_PRIVATE);
    mInternalPrefs.edit().putInt(PreferenceConsts.KEY_APP_VERSION, VERSION_CODE).apply();

    // Setup toolbar
    setSupportActionBar(mToolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Setup navigation drawer
    mNavigationView.setNavigationItemSelectedListener(this);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open_drawer, R.string.close_drawer);
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

    // This is used to cache displayed snackbars, so we can
    // dismiss them when switching between fragments.
    mSnackbars = Collections.newSetFromMap(new WeakHashMap<Snackbar, Boolean>());

    // Create the notification channel immediately so user can
    // configure them immediately without needing to receive
    // a notification first
    NotificationHelper.createNotificationChannel(this);

    // Don't do this if the activity is being re-created (e.g.
    // after a screen rotation), since it will cause the fragment
    // to be created twice (see http://stackoverflow.com/a/13306633/)
    if (savedInstanceState == null) {
        // Process intent. If an action was taken, don't do the rest.
        if (handleIntent(getIntent())) {
            return;
        }

        // Show info dialogs as necessary
        if (!XposedUtils.isModuleEnabled()) {
            if (XposedUtils.isXposedInstalled(this)) {
                showEnableModuleDialog();
            } else {
                // We should probably show a different dialog if the
                // user doesn't even have Xposed installed...
                showEnableModuleDialog();
            }
        } else if (XposedUtils.isModuleUpdated()) {
            showModuleUpdatedDialog();
        } else {
            showTaskKillerDialogIfNecessary();
        }

        // Set the section that was selected previously
        String section = mInternalPrefs.getString(PreferenceConsts.KEY_SELECTED_SECTION, EXTRA_SECTION_BLACKLIST_RULES);
        setContentSection(section);
    }
}