Search in sources :

Example 1 with AppBarConfiguration

use of androidx.navigation.ui.AppBarConfiguration in project firebase-android-sdk by firebase.

the class FragmentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Listening on FragmentManager's FragmentLifeCycleCallbacks
    registerListeners();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);
    Toolbar toolbar = findViewById(R.id.toolbar_fragment_activity);
    setSupportActionBar(toolbar);
    BottomNavigationView navView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications).build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_fragment);
    // Listening on navigation events using NavController
    navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
        Log.d("Navigation", destination.getLabel().toString() + "Fragment");
    });
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    NavigationUI.setupWithNavController((BottomNavigationView) findViewById(R.id.nav_view), navController);
    model = new ViewModelProvider(this).get(SharedViewModel.class);
}
Also used : BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NavController(androidx.navigation.NavController) Toolbar(androidx.appcompat.widget.Toolbar) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 2 with AppBarConfiguration

use of androidx.navigation.ui.AppBarConfiguration in project OpenBot by isl-org.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    viewModel = new ViewModelProvider(this).get(MainViewModel.class);
    vehicle = OpenBotApplication.vehicle;
    // if (vehicle == null) {
    // SharedPreferences sharedPreferences =
    // PreferenceManager.getDefaultSharedPreferences(this);
    // int baudRate = Integer.parseInt(sharedPreferences.getString("baud_rate", "115200"));
    // vehicle = new Vehicle(this, baudRate);
    // vehicle.connectUsb();
    viewModel.setVehicle(vehicle);
    // }
    localBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action != null) {
                switch(action) {
                    case UsbManager.ACTION_USB_DEVICE_ATTACHED:
                        if (!vehicle.isUsbConnected()) {
                            vehicle.connectUsb();
                            viewModel.setUsbStatus(vehicle.isUsbConnected());
                        }
                        Timber.i("USB device attached");
                        break;
                    // Case activated when app is not set to open default when usb is connected
                    case UsbConnection.ACTION_USB_PERMISSION:
                        synchronized (this) {
                            UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
                            if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                                if (usbDevice != null) {
                                    // call method to set up device communication
                                    if (!vehicle.isUsbConnected()) {
                                        vehicle.connectUsb();
                                    }
                                    viewModel.setUsbStatus(vehicle.isUsbConnected());
                                    Timber.i("USB device attached");
                                }
                            }
                        }
                        break;
                    case UsbManager.ACTION_USB_DEVICE_DETACHED:
                        vehicle.disconnectUsb();
                        viewModel.setUsbStatus(vehicle.isUsbConnected());
                        Timber.i("USB device detached");
                        break;
                    case USB_ACTION_DATA_RECEIVED:
                        viewModel.setUsbData(intent.getStringExtra("data"));
                        break;
                }
            }
        }
    };
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction(USB_ACTION_DATA_RECEIVED);
    localIntentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    localIntentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    localIntentFilter.addAction(UsbConnection.ACTION_USB_PERMISSION);
    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localBroadcastManager.registerReceiver(localBroadcastReceiver, localIntentFilter);
    registerReceiver(localBroadcastReceiver, localIntentFilter);
    NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    NavController navController = navHostFragment.getNavController();
    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration);
    navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
        if (destination.getId() == R.id.mainFragment || destination.getId() == R.id.settingsFragment)
            toolbar.setVisibility(View.VISIBLE);
        else
            toolbar.setVisibility(View.GONE);
    });
// if (savedInstanceState == null) {
// // Default to open this when app opens
// Intent intent = new Intent(this, DefaultActivity.class);
// startActivity(intent);
// }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) UsbDevice(android.hardware.usb.UsbDevice) NavController(androidx.navigation.NavController) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) NavHostFragment(androidx.navigation.fragment.NavHostFragment) ViewModelProvider(androidx.lifecycle.ViewModelProvider) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration) Toolbar(androidx.appcompat.widget.Toolbar)

Example 3 with AppBarConfiguration

use of androidx.navigation.ui.AppBarConfiguration in project firebase-android-sdk by firebase.

the class FragmentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);
    BottomNavigationView navView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_home, R.id.navigation_fast, R.id.navigation_slow).build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    NavigationUI.setupWithNavController(navView, navController);
}
Also used : BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NavController(androidx.navigation.NavController) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration)

Example 4 with AppBarConfiguration

use of androidx.navigation.ui.AppBarConfiguration in project AudioVideo by JimSeker.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    BottomNavigationView navView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications).build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    NavigationUI.setupWithNavController(navView, navController);
    myViewModel = new ViewModelProvider(this).get(videoViewModel.class);
}
Also used : BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NavController(androidx.navigation.NavController) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

NavController (androidx.navigation.NavController)4 AppBarConfiguration (androidx.navigation.ui.AppBarConfiguration)4 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3 BottomNavigationView (com.google.android.material.bottomnavigation.BottomNavigationView)3 Toolbar (androidx.appcompat.widget.Toolbar)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 UsbDevice (android.hardware.usb.UsbDevice)1 NavHostFragment (androidx.navigation.fragment.NavHostFragment)1