Search in sources :

Example 1 with ActionBarDrawerToggle

use of androidx.appcompat.app.ActionBarDrawerToggle 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 ActionBarDrawerToggle

use of androidx.appcompat.app.ActionBarDrawerToggle in project kdeconnect-android by KDE.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Workaround: If the activity starts in landscape orientation and we call this before super.onCreate, the PluginItem entries appears with white on white background
    ThemeUtil.setUserPreferredTheme(this);
    final ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    mNavigationView = binding.navigationDrawer;
    mDrawerLayout = binding.drawerLayout;
    View mDrawerHeader = mNavigationView.getHeaderView(0);
    mNavViewDeviceName = mDrawerHeader.findViewById(R.id.device_name);
    ImageView mNavViewDeviceType = mDrawerHeader.findViewById(R.id.device_type);
    setSupportActionBar(binding.toolbarLayout.toolbar);
    ActionBar actionBar = getSupportActionBar();
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.string.open, /* "open drawer" description */
    R.string.close);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerToggle.syncState();
    preferences = getSharedPreferences("stored_menu_selection", Context.MODE_PRIVATE);
    // Note: The preference changed listener should be registered before getting the name, because getting
    // it can trigger a background fetch from the internet that will eventually update the preference
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
    String deviceName = DeviceHelper.getDeviceName(this);
    mNavViewDeviceType.setImageDrawable(DeviceHelper.getDeviceType(this).getIcon(this));
    mNavViewDeviceName.setText(deviceName);
    mNavigationView.setNavigationItemSelectedListener(menuItem -> {
        mCurrentMenuEntry = menuItem.getItemId();
        switch(mCurrentMenuEntry) {
            case MENU_ENTRY_ADD_DEVICE:
                mCurrentDevice = null;
                preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply();
                setContentFragment(new PairingFragment());
                break;
            case MENU_ENTRY_SETTINGS:
                mCurrentDevice = null;
                preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply();
                setContentFragment(new SettingsFragment());
                break;
            case MENU_ENTRY_ABOUT:
                mCurrentDevice = null;
                preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply();
                setContentFragment(AboutFragment.newInstance(Objects.requireNonNull(ApplicationAboutDataKt.getApplicationAboutData(this))));
                break;
            default:
                String deviceId = mMapMenuToDeviceId.get(menuItem);
                onDeviceSelected(deviceId);
                break;
        }
        mDrawerLayout.closeDrawer(mNavigationView);
        return true;
    });
    // Decide which menu entry should be selected at start
    String savedDevice;
    int savedMenuEntry;
    if (getIntent().hasExtra("forceOverview")) {
        Log.i("MainActivity", "Requested to start main overview");
        savedDevice = null;
        savedMenuEntry = MENU_ENTRY_ADD_DEVICE;
    } else if (getIntent().hasExtra(EXTRA_DEVICE_ID)) {
        Log.i("MainActivity", "Loading selected device from parameter");
        savedDevice = getIntent().getStringExtra(EXTRA_DEVICE_ID);
        savedMenuEntry = MENU_ENTRY_DEVICE_UNKNOWN;
        // If pairStatus is not empty, then the user has accepted/reject the pairing from the notification
        String pairStatus = getIntent().getStringExtra(PAIR_REQUEST_STATUS);
        if (pairStatus != null) {
            Log.i("MainActivity", "pair status is " + pairStatus);
            savedDevice = onPairResultFromNotification(savedDevice, pairStatus);
            if (savedDevice == null) {
                savedMenuEntry = MENU_ENTRY_ADD_DEVICE;
            }
        }
    } else if (savedInstanceState != null) {
        Log.i("MainActivity", "Loading selected device from saved activity state");
        savedDevice = savedInstanceState.getString(STATE_SELECTED_DEVICE);
        savedMenuEntry = savedInstanceState.getInt(STATE_SELECTED_MENU_ENTRY, MENU_ENTRY_ADD_DEVICE);
    } else {
        Log.i("MainActivity", "Loading selected device from persistent storage");
        savedDevice = preferences.getString(STATE_SELECTED_DEVICE, null);
        savedMenuEntry = (savedDevice != null) ? MENU_ENTRY_DEVICE_UNKNOWN : MENU_ENTRY_ADD_DEVICE;
    }
    mCurrentMenuEntry = savedMenuEntry;
    mCurrentDevice = savedDevice;
    mNavigationView.setCheckedItem(savedMenuEntry);
    // FragmentManager will restore whatever fragment was there
    if (savedInstanceState != null) {
        Fragment frag = getSupportFragmentManager().findFragmentById(R.id.container);
        if (!(frag instanceof DeviceFragment) || ((DeviceFragment) frag).getDeviceId().equals(savedDevice)) {
            return;
        }
    }
    // Activate the chosen fragment and select the entry in the menu
    if (savedMenuEntry >= MENU_ENTRY_DEVICE_FIRST_ID && savedDevice != null) {
        onDeviceSelected(savedDevice);
    } else {
        if (mCurrentMenuEntry == MENU_ENTRY_SETTINGS) {
            setContentFragment(new SettingsFragment());
        } else if (mCurrentMenuEntry == MENU_ENTRY_ABOUT) {
            setContentFragment(AboutFragment.newInstance(Objects.requireNonNull(ApplicationAboutDataKt.getApplicationAboutData(this))));
        } else {
            setContentFragment(new PairingFragment());
        }
    }
}
Also used : ShareSettingsFragment(org.kde.kdeconnect.Plugins.SharePlugin.ShareSettingsFragment) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) ImageView(android.widget.ImageView) ActivityMainBinding(org.kde.kdeconnect_tp.databinding.ActivityMainBinding) NavigationView(com.google.android.material.navigation.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Fragment(androidx.fragment.app.Fragment) ShareSettingsFragment(org.kde.kdeconnect.Plugins.SharePlugin.ShareSettingsFragment) AboutFragment(org.kde.kdeconnect.UserInterface.About.AboutFragment) ActionBar(androidx.appcompat.app.ActionBar)

Example 3 with ActionBarDrawerToggle

use of androidx.appcompat.app.ActionBarDrawerToggle in project materialistic by hidroh.

the class DrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.activity_drawer);
    mDrawer = findViewById(R.id.drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerAccount = (TextView) findViewById(R.id.drawer_account);
    mDrawerLogout = findViewById(R.id.drawer_logout);
    mDrawerUser = findViewById(R.id.drawer_user);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open_drawer, R.string.close_drawer) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (drawerView.equals(mDrawer) && mPendingNavigation != null) {
                final Intent intent = new Intent(DrawerActivity.this, mPendingNavigation);
                if (mPendingNavigationExtras != null) {
                    intent.putExtras(mPendingNavigationExtras);
                    mPendingNavigationExtras = null;
                }
                // TODO M bug https://code.google.com/p/android/issues/detail?id=193822
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent);
                mPendingNavigation = null;
            }
        }
    };
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(mLoginListener);
    setUpDrawer();
    setUsername();
}
Also used : ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View)

Example 4 with ActionBarDrawerToggle

use of androidx.appcompat.app.ActionBarDrawerToggle in project RSAndroidApp by RailwayStations.

the class MainActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    setSupportActionBar(binding.appBarMain.toolbar);
    baseApplication = (BaseApplication) getApplication();
    dbAdapter = baseApplication.getDbAdapter();
    rsapiClient = baseApplication.getRsapiClient();
    final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, binding.drawerLayout, binding.appBarMain.toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    binding.drawerLayout.addDrawerListener(toggle);
    toggle.syncState();
    binding.navView.setNavigationItemSelectedListener(this);
    final View header = binding.navView.getHeaderView(0);
    final TextView tvUpdate = header.findViewById(R.id.tvUpdate);
    if (!baseApplication.getFirstAppStart()) {
        startActivity(new Intent(this, IntroSliderActivity.class));
        finish();
    }
    final long lastUpdateDate = baseApplication.getLastUpdate();
    if (lastUpdateDate > 0) {
        tvUpdate.setText(getString(R.string.last_update_at, SimpleDateFormat.getDateTimeInstance().format(lastUpdateDate)));
    } else {
        tvUpdate.setText(R.string.no_stations_in_database);
    }
    final Intent searchIntent = getIntent();
    if (Intent.ACTION_SEARCH.equals(searchIntent.getAction())) {
        searchString = searchIntent.getStringExtra(SearchManager.QUERY);
    }
    myPos = baseApplication.getLastLocation();
    bindToStatus();
}
Also used : ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) TextView(android.widget.TextView) Intent(android.content.Intent) NavigationView(com.google.android.material.navigation.NavigationView) View(android.view.View) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView)

Example 5 with ActionBarDrawerToggle

use of androidx.appcompat.app.ActionBarDrawerToggle in project Android-Image-Cropper by ArthurHub.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.main_drawer_open, R.string.main_drawer_close);
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
        setMainFragmentByPreset(CropDemoPreset.RECT);
    }
}
Also used : ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle)

Aggregations

ActionBarDrawerToggle (androidx.appcompat.app.ActionBarDrawerToggle)18 View (android.view.View)10 Intent (android.content.Intent)8 TextView (android.widget.TextView)7 NavigationView (com.google.android.material.navigation.NavigationView)7 DrawerLayout (androidx.drawerlayout.widget.DrawerLayout)6 Toolbar (androidx.appcompat.widget.Toolbar)5 Handler (android.os.Handler)4 ImageView (android.widget.ImageView)4 Fragment (androidx.fragment.app.Fragment)4 SharedPreferences (android.content.SharedPreferences)3 Build (android.os.Build)3 Bundle (android.os.Bundle)3 ArgbEvaluator (android.animation.ArgbEvaluator)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 Configuration (android.content.res.Configuration)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Uri (android.net.Uri)2 KeyEvent (android.view.KeyEvent)2