Java Code Examples for android.support.design.widget.NavigationView#setNavigationItemSelectedListener()

The following examples show how to use android.support.design.widget.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: NotesActivity.java    From androidtestdebug with MIT License 6 votes vote down vote up
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    switch (menuItem.getItemId()) {
                        case R.id.statistics_navigation_menu_item:
                            startActivity(new Intent(NotesActivity.this, StatisticsActivity.class));
                            break;
                        default:
                            break;
                    }
                    // Close the navigation drawer when an item is selected.
                    menuItem.setChecked(true);
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
}
 
Example 2
Source File: MainActivity.java    From android-samples 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);

    database=new DataBase(this);


    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);

    fragment=new InsertFragment();
    FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.content_main,fragment);
    ft.commit();
}
 
Example 3
Source File: BaseActivity.java    From privacy-friendly-dame with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if(getSupportActionBar() == null) {
        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();

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

    selectNavigationItem(getNavigationDrawerID());

    View mainContent = findViewById(R.id.main_content);
    if (mainContent != null) {
        mainContent.setAlpha(0);
        mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEIN_DURATION);
    }
}
 
Example 4
Source File: BreadcrumbActivity.java    From BreadcrumbToolbar with Apache License 2.0 6 votes vote down vote up
private void bindViews() {
    // Bind toolbar
    toolbar = (BreadcrumbToolbar) findViewById(R.id.toolbar);
    // We can't use setSupportActionBar()
    toolbar.setBreadcrumbToolbarListener(this);
    toolbar.setTitle(R.string.app_name);
    // Set animated drawer icon to toolbar
    DrawerArrowDrawable drawerArrow = new DrawerArrowDrawable(this);
    drawerArrow.setColor(ContextCompat.getColor(this, android.R.color.white));
    toolbar.setNavigationIcon(drawerArrow);
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    // Bind drawer and toggle button
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    bindDrawerToggle();
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_home);

    // Bind FAB
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(this::openBreadCrumbFragment);
}
 
Example 5
Source File: MainActivity.java    From Modularity 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 = getToolbar();
    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);
    toggle.syncState();

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

    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.content_main,
                    FragmentRouter.getFragment(RouterList.MEMORY_FRAG_MAIN))
            .commit();
}
 
Example 6
Source File: HNewsNavigationDrawerActivity.java    From yahnac with Apache License 2.0 5 votes vote down vote up
@Override
public void setContentView(int layoutResID) {
    super.setContentView(layoutResID);

    drawer = Views.findById(this, R.id.navigation_drawer);
    drawerListener = new ActionBarDrawerListener(this, drawer);
    drawer.setDrawerListener(drawerListener);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        navigationView.setNavigationItemSelectedListener(drawerListener);
    }

}
 
Example 7
Source File: BaseActivity.java    From privacy-friendly-shopping-list with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostCreate(Bundle savedInstanceState)
{
    super.onPostCreate(savedInstanceState);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if ( getSupportActionBar() == null )
    {
        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();


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

    selectNavigationItem(getNavigationDrawerID());

    View mainContent = findViewById(R.id.main_content);
    if ( mainContent != null )
    {
        mainContent.setAlpha(0);
        mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEIN_DURATION);
    }
}
 
Example 8
Source File: MainActivity.java    From EvilsLive with MIT License 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        setSupportActionBar(mToolbar);

        mPermissionsChecker = new PermissionsChecker(this);

        streamer = new EvilsLiveStreamer(this);

//        ViewGroup.LayoutParams layoutParams = mPreviewView.getLayoutParams();
//        layoutParams.width = 640;
//        layoutParams.height = 480;
//        mPreviewView.setLayoutParams(layoutParams);
        SurfaceHolder holder = mPreviewView.getHolder();
        holder.addCallback(this);

        audioCapture = new AudioCapture();
        audioPlay = new AudioPlayer();

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, mToolbar, 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);
        ActivityComponent activityComponent = DaggerActivityComponent.builder()
                .activityModule(new ActivityModule(this)).build();
        activityComponent.getActivity();

//        CameraComponent cameraComponent = DaggerCameraComponent.builder().activityComponent(activityComponent).
//                cameraModule(new com.thinkkeep.videolib.di.modules.CameraModule(this)).build();
//        cameraComponent.inject(this);
    }
 
Example 9
Source File: MainActivity.java    From Varis-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up navigation drawer layout
 */
private void setupDrawerLayout() {
    mDrawerLayout = findViewById(R.id.drawer_layout);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    final NavigationView view = findViewById(R.id.navigation_view);
    view.setNavigationItemSelectedListener(menuItem -> {

        switch (menuItem.getItemId()) {
            case R.id.drawer_login:
                Intent loginIntent = new Intent(MainActivity.this, AuthActivity.class);
                startActivityForResult(loginIntent, AUTH_ACTIVITY_CODE);
                break;
            case R.id.drawer_logout:
                getPresenter().userLogout();

                finish();
                startActivity(getIntent());
                break;
            case R.id.drawer_licenses:
                LicensesDialogFragment dialog = LicensesDialogFragment.newInstance();
                dialog.show(getSupportFragmentManager(), "LicensesDialog");
                break;
            case R.id.drawer_about:
                Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class);
                startActivity(aboutIntent);
                break;
        }
        menuItem.setChecked(false);
        mDrawerLayout.closeDrawers();
        return true;
    });

}
 
Example 10
Source File: NavigationViewActivity.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(SettingsActivity.ThemePreferenceFragment.getTheme(this,
            SettingsActivity
                    .ThemePreferenceFragment.THEME_TYPE.NO_ACTION_BAR));
    setContentView(R.layout.activity_navigation_view);
    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_view_open, R.string.navigation_view_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
    mNavigationView.setNavigationItemSelectedListener(this);

    if (savedInstanceState == null) {
        showDashboard();
        SyncAdapter.initializeSyncAdapter(this);
    } else {
        mCurrentFragment = savedInstanceState.getString(EXTRA_CURRENT_FRAGMENT);
        if (mCurrentFragment.equals(DashboardFragment.class.getSimpleName())) {
            showDashboard();
        } else if (mCurrentFragment.equals(PublicRepositoryFragment.class.getSimpleName())) {
            showRepositories();
        } else {
            showTrendingRepositories();
        }
    }

    mLoaderProvider = new LoaderProvider(this);
    getSupportLoaderManager().initLoader(USER_LOADER, null, this);
}
 
Example 11
Source File: SampleActivity.java    From AndroidStarterKit with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

  if (savedInstanceState == null) {
    getSupportFragmentManager()
        .beginTransaction()
        .add(R.id.container, new SampleFragment())
        .commit();
  }

  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, "Welcome to AndroidStarterKit!", Snackbar.LENGTH_LONG)
          .setAction("Action", null).show();
    }
  });

  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 12
Source File: MainActivity.java    From QuickNote with Apache License 2.0 5 votes vote down vote up
private void initBaseLayout() {
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        initFabMenu();

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, mToolbar, 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);
//        initNavigationHeadView(navigationView);
    }
 
Example 13
Source File: MainActivity.java    From CineLog with GNU General Public License v3.0 5 votes vote down vote up
private void configureDrawer() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setCheckedItem(R.id.nav_reviews);

    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                    // close drawer when item is tapped
                    drawerLayout.closeDrawers();

                    switch (menuItem.getItemId()) {
                        case R.id.nav_wishlist:
                            Intent intent = new Intent(getApplicationContext(), WishlistActivity.class);
                            startActivity(intent);
                            break;
                    }

                    setViewPager(viewPager);

                    fab.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            setReviewFragment();
                        }
                    });

                    return true;
                }
            }
    );
}
 
Example 14
Source File: MainActivity.java    From floatingsearchview with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

    showFragment(new SlidingSearchResultsExampleFragment());
}
 
Example 15
Source File: MainActivity.java    From jus with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MyJus.init(this);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    //Listen for changes in the back stack
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(view ->
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
            .setAction("Action", null).show());

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

    toggle.syncState();
    shouldDisplayHomeUp();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example 16
Source File: MainActivity.java    From cashuwallet with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

    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);
    navigationView.getMenu().performIdentifierAction(R.id.nav_wallet, 0);

    sync = MainApplication.app().getSync();
    List<Multiwallet> multiwallets = sync.findMultiwallets(0);
    Collections.sort(multiwallets, (Multiwallet m1, Multiwallet m2) -> m1.getCoin().getName().compareTo(m2.getCoin().getName()));
    adapter = new Adapter(multiwallets);

    RecyclerView recyclerView = findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL));
    recyclerView.setAdapter(adapter);

    SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(() -> {
        if (!MainApplication.app().networkAvailable()) {
            Snackbar.make(recyclerView, R.string.network_not_available, Snackbar.LENGTH_LONG).show();
            swipeRefreshLayout.setRefreshing(false);
            return;
        }
        adapter.refresh();
        swipeRefreshLayout.setRefreshing(false);
    });
    swipeRefreshLayout.post(() -> adapter.refresh());

    if (MainApplication.app().requiresReconnect()) {
        new AlertDialog.Builder(this)
                .setTitle(R.string.new_version_installed)
                .setCancelable(true)
                .setMessage(R.string.info_newcoins_reset)
                .setPositiveButton(R.string.ok, null)
                .show();
    }
}
 
Example 17
Source File: NavigationViewActivity.java    From twoh-android-material-design with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_nav_view);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    setupToolbar();
    navView = (NavigationView) findViewById(R.id.navigation);
    navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if(menuItem.isChecked())
                menuItem.setChecked(false);
            else
                menuItem.setChecked(true);

            drawerLayout.closeDrawers();

            switch (menuItem.getItemId()){

                case R.id.nav_home:
                    decideToDisplay();
                    Toast.makeText(NavigationViewActivity.this, "Home clicked", Toast.LENGTH_SHORT).show();
                    return true;
                case R.id.nav_my_profile:
                    decideToDisplay();
                    Toast.makeText(NavigationViewActivity.this, "My profile clicked", Toast.LENGTH_SHORT).show();
                    return true;
                case R.id.nav_settings:
                    decideToDisplay();
                    Toast.makeText(NavigationViewActivity.this, "Settings clicked", Toast.LENGTH_SHORT).show();
                    return true;

            }
            return true;
        }
    });
    super.onCreate(savedInstanceState);

    Button btTutorial = (Button) findViewById(R.id.bt_tutorial);
    btTutorial.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            decideToDisplay();
            readTheTutorial(Const.TUTORIAL_NAV);
        }
    });
}
 
Example 18
Source File: MainActivity.java    From YoutubeDown with MIT License 4 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);
    myWebView = (YouTuBeWebView) findViewById(R.id.webview);
    fab = (FloatingActionButton) findViewById(R.id.fab);
    mLoadingProgressBar = (ProgressBar) findViewById(R.id.progress);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showWaitDialog();
            //调用解析
            RxYoutube.fetchYoutube(mVideoId, new Subscriber<List<FmtStreamMap>>() {
                @Override
                public void onCompleted() {
                    dismissWaitDialog();
                }

                @Override
                public void onError(Throwable e) {
                    dismissWaitDialog();
                }

                @Override
                public void onNext(List<FmtStreamMap> fmtStreamMaps) {
                    dismissWaitDialog();
                    showDialog(fmtStreamMaps);
                }
            });
        }
    });
    downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    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);

    initWebView();
}
 
Example 19
Source File: NavigationActivity.java    From AvI with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Intent intent = getIntent();
    if (intent != null) {
        handleIntentExtras(intent);
    }


    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();
        }
    });

    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);

    //instantiate the fragmentManager and set the default view to profile
    fragmentManager = getFragmentManager();
    if(fragmentManager.findFragmentByTag(fragmentTag) == null) {
        currentFragment = new ProfileFragment();
        fragmentManager.beginTransaction()
                .replace(R.id.content_frame, (Fragment) currentFragment, fragmentTag)
                .commit();
    }else{
        currentFragment = (INavigationFragment) fragmentManager.findFragmentByTag(fragmentTag);
    }


    //initialize the default application settings
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Create an instance of GoogleAPIClient.
    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
    }
}
 
Example 20
Source File: MainActivity.java    From find-client-android with MIT License 4 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);

    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);

    //Check for Android M runtime permissions
    if(Build.VERSION.SDK_INT >= 23) {
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.ACCESS_FINE_LOCATION)) {
            } else {
                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                        REQUEST_CODE_ASK_PERMISSIONS);
            }
        }
    }

    // Calling function to set some default values if its our first run
    sharedPreferences = getSharedPreferences(Constants.PREFS_NAME, 0);
    setDefaultPrefs();

    // Set the Learn Fragment as default
    Fragment fragment = new LearnFragment();
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.content, fragment)
            .commit();
}