Search in sources :

Example 1 with NavigationView

use of com.google.android.material.navigation.NavigationView in project orgzly-android by orgzly.

the class MainActivity method setupDrawer.

private void setupDrawer() {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG);
    mDrawerLayout = findViewById(R.id.drawer_layout);
    NavigationView navigationView = mDrawerLayout.findViewById(R.id.drawer_navigation_view);
    navigationView.setNavigationItemSelectedListener(item -> {
        Intent intent = item.getIntent();
        if (intent != null) {
            mDrawerLayout.closeDrawer(GravityCompat.START);
            // Avoid jerky drawer close by displaying new fragment with a delay
            new Handler().postDelayed(() -> broadcastManager.sendBroadcast(intent), 200);
        }
        if (BuildConfig.LOG_DEBUG)
            LogUtils.d(TAG, item, intent);
        return true;
    });
    drawerNavigationView = new DrawerNavigationView(this, viewModel, navigationView);
    if (mDrawerLayout != null) {
        // Set the drawer toggle as the DrawerListener
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {

            private int state = -1;

            /*
                 * onDrawerOpened and onDrawerClosed are not called fast enough.
                 * So state is determined using onDrawerSlide callback and checking the slide offset.
                 */
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);
                switch(state) {
                    case // Unknown
                    -1:
                        if (slideOffset == 0) {
                            state = 0;
                            drawerClosed();
                        } else if (slideOffset > 0) {
                            state = 1;
                            drawerOpened();
                        }
                        break;
                    case // Starting to open the drawer
                    0:
                        if (slideOffset > 0) {
                            state = 1;
                            drawerOpened();
                        }
                        break;
                    case // Starting to close the drawer
                    1:
                        if (slideOffset == 0) {
                            state = 0;
                            drawerClosed();
                        }
                        break;
                }
            }
        };
        // No flipping burgers
        mDrawerToggle.setDrawerSlideAnimationEnabled(false);
        mDrawerLayout.addDrawerListener(mDrawerToggle);
    }
    mSyncFragment = addSyncFragment();
}
Also used : DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) NavigationView(com.google.android.material.navigation.NavigationView) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Handler(android.os.Handler) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) NavigationView(com.google.android.material.navigation.NavigationView) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView)

Example 2 with NavigationView

use of com.google.android.material.navigation.NavigationView in project Timber by naman14.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    action = getIntent().getAction();
    isDarkTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    navigationMap.put(Constants.NAVIGATE_LIBRARY, navigateLibrary);
    navigationMap.put(Constants.NAVIGATE_PLAYLIST, navigatePlaylist);
    navigationMap.put(Constants.NAVIGATE_QUEUE, navigateQueue);
    navigationMap.put(Constants.NAVIGATE_NOWPLAYING, navigateNowplaying);
    navigationMap.put(Constants.NAVIGATE_ALBUM, navigateAlbum);
    navigationMap.put(Constants.NAVIGATE_ARTIST, navigateArtist);
    navigationMap.put(Constants.NAVIGATE_LYRICS, navigateLyrics);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    panelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    View header = navigationView.inflateHeaderView(R.layout.nav_header);
    albumart = (ImageView) header.findViewById(R.id.album_art);
    songtitle = (TextView) header.findViewById(R.id.song_title);
    songartist = (TextView) header.findViewById(R.id.song_artist);
    setPanelSlideListeners(panelLayout);
    navDrawerRunnable.postDelayed(new Runnable() {

        @Override
        public void run() {
            setupDrawerContent(navigationView);
            setupNavigationIcons(navigationView);
        }
    }, 700);
    if (TimberUtils.isMarshmallow()) {
        checkPermissionAndThenLoad();
    // checkWritePermissions();
    } else {
        loadEverything();
    }
    addBackstackListener();
    if (Intent.ACTION_VIEW.equals(action)) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                MusicPlayer.clearQueue();
                MusicPlayer.openFile(getIntent().getData().getPath());
                MusicPlayer.playOrPause();
                navigateNowplaying.run();
            }
        }, 350);
    }
    if (!panelLayout.isPanelHidden() && MusicPlayer.getTrackName() == null) {
        panelLayout.hidePanel();
    }
    if (playServicesAvailable) {
        final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.BOTTOM;
        FrameLayout contentRoot = findViewById(R.id.content_root);
        contentRoot.addView(LayoutInflater.from(this).inflate(R.layout.fragment_cast_mini_controller, null), params);
        findViewById(R.id.castMiniController).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, ExpandedControllerActivity.class));
            }
        });
    }
}
Also used : FrameLayout(android.widget.FrameLayout) Handler(android.os.Handler) Intent(android.content.Intent) NavigationView(com.google.android.material.navigation.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 3 with NavigationView

use of com.google.android.material.navigation.NavigationView in project Gadgetbridge by Freeyourgadget.

the class ControlCenterv2 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    AbstractGBActivity.init(this, AbstractGBActivity.NO_ACTIONBAR);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_controlcenterv2);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.controlcenter_navigation_drawer_open, R.string.controlcenter_navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    // end of material design boilerplate
    deviceManager = ((GBApplication) getApplication()).getDeviceManager();
    deviceListView = findViewById(R.id.deviceListView);
    deviceListView.setHasFixedSize(true);
    deviceListView.setLayoutManager(new LinearLayoutManager(this));
    deviceList = deviceManager.getDevices();
    mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList, deviceActivityHashMap);
    // get activity data asynchronously, this fills the deviceActivityHashMap
    // and calls refreshPairedDevices() → notifyDataSetChanged
    createRefreshTask("get activity data", getApplication()).execute();
    deviceListView.setAdapter(this.mGBDeviceAdapter);
    fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            launchDiscoveryActivity();
        }
    });
    showFabIfNeccessary();
    /* uncomment to enable fixed-swipe to reveal more actions

        ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
                ItemTouchHelper.LEFT , ItemTouchHelper.RIGHT) {
            @Override
            public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
                if(dX>50)
                    dX = 50;
                super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

            }

            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                GB.toast(getBaseContext(), "onMove", Toast.LENGTH_LONG, GB.ERROR);

                return false;
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                GB.toast(getBaseContext(), "onSwiped", Toast.LENGTH_LONG, GB.ERROR);

            }

            @Override
            public void onChildDrawOver(Canvas c, RecyclerView recyclerView,
                                        RecyclerView.ViewHolder viewHolder, float dX, float dY,
                                        int actionState, boolean isCurrentlyActive) {
            }
        });

        swipeToDismissTouchHelper.attachToRecyclerView(deviceListView);
        */
    registerForContextMenu(deviceListView);
    IntentFilter filterLocal = new IntentFilter();
    filterLocal.addAction(GBApplication.ACTION_LANGUAGE_CHANGE);
    filterLocal.addAction(GBApplication.ACTION_QUIT);
    filterLocal.addAction(GBApplication.ACTION_NEW_DATA);
    filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
    filterLocal.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
    refreshPairedDevices();
    /*
         * Ask for permission to intercept notifications on first run.
         */
    Prefs prefs = GBApplication.getPrefs();
    pesterWithPermissions = prefs.getBoolean("permission_pestering", true);
    Set<String> set = NotificationManagerCompat.getEnabledListenerPackages(this);
    if (pesterWithPermissions) {
        if (!set.contains(this.getPackageName())) {
            // If notification listener access hasn't been granted
            Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
            startActivity(enableIntent);
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkAndRequestPermissions();
    }
    ChangeLog cl = createChangeLog();
    if (cl.isFirstRun()) {
        try {
            cl.getLogDialog().show();
        } catch (Exception ignored) {
            GB.toast(getBaseContext(), "Error showing Changelog", Toast.LENGTH_LONG, GB.ERROR);
        }
    }
    GBApplication.deviceService().start();
    if (GB.isBluetoothEnabled() && deviceList.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        startActivity(new Intent(this, DiscoveryActivity.class));
    } else {
        GBApplication.deviceService().requestDeviceInfo();
    }
}
Also used : IntentFilter(android.content.IntentFilter) NavigationView(com.google.android.material.navigation.NavigationView) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) GBDeviceAdapterv2(nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavigationView(com.google.android.material.navigation.NavigationView) ChangeLog(de.cketti.library.changelog.ChangeLog) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) Toolbar(androidx.appcompat.widget.Toolbar)

Example 4 with NavigationView

use of com.google.android.material.navigation.NavigationView in project IITB-App by wncc.

the class MainActivity method initNavigationView.

private void initNavigationView() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
Also used : NavigationView(com.google.android.material.navigation.NavigationView)

Example 5 with NavigationView

use of com.google.android.material.navigation.NavigationView in project EhViewer by seven332.

the class MainActivity method onCreate2.

@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);
}
Also used : EhApplication(com.hippo.ehviewer.EhApplication) View(android.view.View) LoadImageView(com.hippo.widget.LoadImageView) TextView(android.widget.TextView) NavigationView(com.google.android.material.navigation.NavigationView)

Aggregations

NavigationView (com.google.android.material.navigation.NavigationView)11 View (android.view.View)6 Intent (android.content.Intent)4 TextView (android.widget.TextView)4 ActionBarDrawerToggle (androidx.appcompat.app.ActionBarDrawerToggle)4 ImageView (android.widget.ImageView)3 DrawerLayout (androidx.drawerlayout.widget.DrawerLayout)3 Handler (android.os.Handler)2 Toolbar (androidx.appcompat.widget.Toolbar)2 FragmentManager (androidx.fragment.app.FragmentManager)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 IntentFilter (android.content.IntentFilter)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Pair (android.util.Pair)1 KeyEvent (android.view.KeyEvent)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 ViewGroup (android.view.ViewGroup)1