androidx.core.view.GravityCompat Java Examples

The following examples show how to use androidx.core.view.GravityCompat. 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: MainActivity.java    From simple-stack with Apache License 2.0 6 votes vote down vote up
public void setupViewsForKey(BaseKey key) {
    if(key.shouldShowUp()) {
        drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED, GravityCompat.START);
        drawerToggle.setDrawerIndicatorEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    } else {
        drawerLayout.setDrawerLockMode(LOCK_MODE_UNLOCKED, GravityCompat.START);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        drawerToggle.setDrawerIndicatorEnabled(true);
    }
    drawerToggle.syncState();
    setCheckedItem(key.navigationViewId());
    supportInvalidateOptionsMenu();
    if(key.isFabVisible()) {
        fab.show();
    } else {
        fab.hide();
    }
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(key.getFragmentTag());
    key.setupFab(fragment, fab);
}
 
Example #2
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
private void onDirectorySelected(final String dirPath, final boolean isRootDirectory, final boolean addToBackStack) {
    // Create fragment and give it an argument for the selected directory
    final FilesFragment newFragment = FilesFragment.newInstance(dirPath, isRootDirectory);

    final FragmentManager fragmentManager = getSupportFragmentManager();

    final FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (!isRootDirectory) {
        // no root directory so set a enter / exit transition
        final int layoutDirection = getResources().getConfiguration().getLayoutDirection();
        newFragment.setEnterTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.START, layoutDirection)));
        newFragment.setExitTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.END, layoutDirection)));
    }

    transaction.replace(R.id.fragment_container, newFragment);
    if (!isRootDirectory && addToBackStack) {
        // add fragment only to the backstack if it's not a root directory
        transaction.addToBackStack("FilesFragment");
    }

    // Commit the transaction
    transaction.commit();
}
 
Example #3
Source File: NavigationActivity.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (mDrawer != null && mDrawer.isDrawerOpen(GravityCompat.START)) {
        mDrawer.closeDrawer(GravityCompat.START);
    } else {
        Fragment currentFragment = getFragment(mSelection);
        if (!(currentFragment instanceof BaseFragment)
                || !((BaseFragment) currentFragment).onBackPressed()) {
            if (mExit) {
                mExit = false;
                super.onBackPressed();
            } else {
                Utils.toast(R.string.press_back_again_exit, this);
                mExit = true;
                mHandler.postDelayed(() -> mExit = false, 2000);
            }
        }
    }
}
 
Example #4
Source File: MainActivity.java    From busybox with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_settings:
            Intent intentSettings = new Intent(this, SettingsActivity.class);
            startActivity(intentSettings);
            break;
        case R.id.action_help:
            new ExecScript(this, "info").start();
            break;
        case R.id.action_zip:
            requestWritePermissions();
            break;
        case R.id.action_about:
            Intent intentAbout = new Intent(this, AboutActivity.class);
            startActivity(intentAbout);
            break;
    }
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #5
Source File: MainFragment.java    From AndroidFastScroll with Apache License 2.0 6 votes vote down vote up
private boolean onNavigationItemSelected(@NonNull MenuItem item) {
    int itemId = item.getItemId();
    switch (item.getItemId()) {
        case R.id.recycler_view_list:
        case R.id.recycler_view_list_classic:
        case R.id.recycler_view_list_stateful:
        case R.id.recycler_view_grid:
        case R.id.scroll_view:
        case R.id.nested_scroll_view:
        case R.id.web_view:
            setNavigationCheckedItem(itemId);
            mDrawerLayout.closeDrawer(GravityCompat.START);
            return true;
        default:
            return false;
    }
}
 
Example #6
Source File: MainActivity.java    From c3nav-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            mDrawerLayout.openDrawer(GravityCompat.START);
            return true;
        case R.id.share:
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
            i.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
            startActivity(Intent.createChooser(i, getString(R.string.share)));
            return true;
        case R.id.refresh:
            webView.loadUrl(instanceBaseUrl.toString());
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #7
Source File: MainActivity.java    From ArcNavigationView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_right_menu) {
        if (drawer.isDrawerOpen(GravityCompat.END)) {
            drawer.closeDrawer(GravityCompat.END);
        } else {
            drawer.openDrawer(GravityCompat.END);
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #8
Source File: NavigationDrawerFragment.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Users of this fragment must call this method to set up the navigation drawer interactions.
 *
 * @param fragmentId   The android:id of this fragment in its activity's layout.
 * @param drawerLayout The DrawerLayout containing this fragment's UI.
 */
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    final AppCompatActivity activity = (AppCompatActivity) getActivity();
    fragmentContainerView = activity.findViewById(fragmentId);
    this.drawerLayout = drawerLayout;
    // set a custom shadow that overlays the main content when the drawer opens
    this.drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    toolbar = this.drawerLayout.findViewById(R.id.toolbar);

    setupActionBar();
    setupEntries();
    setupActionBarDrawerToggle(activity);

    if (!userLearnedDrawer) {
        openNavigationDrawerForFirstTimeUsers();
    }

    // Defer code dependent on restoration of previous instance state.
    this.drawerLayout.post(() -> drawerToggle.syncState());
    this.drawerLayout.addDrawerListener(drawerToggle);
}
 
Example #9
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPlaylistSelected(String playlistTitle, long playlistID) {
    // Create fragment and give it an argument for the selected playlist
    PlaylistTracksFragment newFragment = PlaylistTracksFragment.newInstance(playlistTitle, playlistID);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    // set enter / exit animation
    final int layoutDirection = getResources().getConfiguration().getLayoutDirection();
    newFragment.setEnterTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.START, layoutDirection)));
    newFragment.setExitTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.END, layoutDirection)));

    // Replace whatever is in the fragment_container view with this
    // fragment,
    // and add the transaction to the back stack so the user can navigate
    // back
    transaction.replace(R.id.fragment_container, newFragment);
    transaction.addToBackStack("PlaylistTracksFragment");

    // Commit the transaction
    transaction.commit();
}
 
Example #10
Source File: Home.java    From UberClone with MIT License 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    switch (id){
        case R.id.nav_trip_history:
            showTripHistory();
            break;
        case R.id.nav_updateInformation:
            showDialogUpdateInfo();
            break;
        case R.id.nav_signOut:
            signOut();
            break;
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #11
Source File: MainActivity.java    From iBeacon-Android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    Fragment fragment = null;
    if (id == R.id.nav_time_atten) {
        fragment = TimeAttendantFastFragment.newInstance();
    } else if (id == R.id.nav_simulator) {
        fragment = BeaconSimulatorFragment.newInstance();
    }

    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.contentFrame, fragment).commit();

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #12
Source File: MainActivity.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("RtlHardcoded")
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Boolean mo = moDialogHUD.onKeyDown(keyCode, event);
    if (mo) {
        return true;
    } else if (mTlIndicator.getSelectedTabPosition() != 0) {
        Objects.requireNonNull(mTlIndicator.getTabAt(0)).select();
        return true;
    } else {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START, !MApplication.isEInkMode);
                return true;
            }
            exit();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
 
Example #13
Source File: MainActivity.java    From GooglePlayCloned with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #14
Source File: NavigationViewActivity.java    From sa-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #15
Source File: BasicActivity.java    From intra42 with Apache License 2.0 5 votes vote down vote up
/**
 * Called when an item in the navigation menu is selected.
 *
 * @param item The selected item
 * @return true to display the item as the selected item
 */
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Navigation.onNavigationItemSelected(this, item);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #16
Source File: MainActivity.java    From zapp with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
		case android.R.id.home:
			drawerLayout.openDrawer(GravityCompat.START);
			return true;
		default:
			return super.onOptionsItemSelected(item);
	}
}
 
Example #17
Source File: AdvanceDrawer1Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_right_drawer:
            drawer.openDrawer(GravityCompat.END);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #18
Source File: ToolbarManager.java    From material with Apache License 2.0 5 votes vote down vote up
/**
 * Handling onDrawerSlide event of DrawerLayout. It'll sync progress of drawer sliding animation with navigation state changing animation if needed.
 * If you also want to handle this event, make sure to call super method.
 */
protected void onDrawerSlide(View drawerView, float slideOffset){
    if(!shouldSyncDrawerSlidingProgress()){
        notifyStateInvalidated();
    }
    else {
        if (mDrawerLayout.isDrawerOpen(GravityCompat.START))
            notifyStateProgressChanged(false, 1f - slideOffset);
        else
            notifyStateProgressChanged(true, slideOffset);
    }
}
 
Example #19
Source File: MainActivity.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.ll_title_menu:
            // 开启菜单
            bindingView.drawerLayout.openDrawer(GravityCompat.START);
            break;
        case R.id.iv_title_two:
            // 不然cpu会有损耗
            if (vpContent.getCurrentItem() != 1) {
                setCurrentItem(1);
            }
            break;
        case R.id.iv_title_one:
            if (vpContent.getCurrentItem() != 0) {
                setCurrentItem(0);
            }
            break;
        case R.id.iv_title_three:
            if (vpContent.getCurrentItem() != 2) {
                setCurrentItem(2);
            }
            break;
        case R.id.iv_avatar:
            // 头像进入GitHub
            WebViewActivity.loadUrl(v.getContext(), CommonUtils.getString(R.string.string_url_cloudreader), "CloudReader");
            break;
        case R.id.ll_nav_exit:
            // 退出应用
            finish();
            break;
        default:
            break;
    }
}
 
Example #20
Source File: MainActivity.java    From Open-Source-Android-Weather-App with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    Log.d("start", ">>> Navigation Bar");
    if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
        drawerLayout.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #21
Source File: MainActivity.java    From DeAutherDroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    if (!mainRender.canGoBack()) {
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    } else {
        mainRender.goBack();
    }
}
 
Example #22
Source File: DynamicDrawerActivity.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the drawer is in the locked mode.
 *
 * @return {@code true} if the drawer is in the locked mode.
 */
public boolean isDrawerLocked() {
    return mDrawer.getDrawerLockMode(GravityCompat.START)
            == DrawerLayout.LOCK_MODE_LOCKED_OPEN
            || mDrawer.getDrawerLockMode(GravityCompat.END)
            == DrawerLayout.LOCK_MODE_LOCKED_OPEN;
}
 
Example #23
Source File: Home.java    From UberClone with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #24
Source File: LandingActivity.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            drawerLayout.openDrawer(GravityCompat.START);
            break;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #25
Source File: PreferenceCategoryCompat.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return;

    final TextView titleView = (TextView) holder.findViewById(android.R.id.title);

    if (titleView != null) {
        titleView.setGravity(GravityCompat.START | Gravity.CENTER_VERTICAL);
        final TypedArray typedArray = getContext().obtainStyledAttributes(COLOR_ACCENT_ID);

        try {
            if (typedArray.length() > 0) {
                final int accentColor = typedArray.getColor(0, 0xff4081); // defaults to pink
                titleView.setTextColor(accentColor);
            }
        } finally {
            typedArray.recycle();
        }

        float density = getContext().getResources().getDisplayMetrics().density;
        int paddingPx = (int) (density * PADDING_DP);

        // View already includes bottom margin. Add padding to all other sides for consistency
        // across Android versions.
        titleView.setPadding(paddingPx, paddingPx, paddingPx, 0);
    }
}
 
Example #26
Source File: MainActivity.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawer(GravityCompat.START);
    } else {
        boolean handled = false;
        try {
            List fragmentList = getSupportFragmentManager().getFragments();
            for (Object f : fragmentList) {
                if (f instanceof BaseFragment) {
                    handled = ((BaseFragment) f).onBackPressed();
                    if (handled)
                        break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (!handled) {
            if (!isHomeFragmentOpen())
                goToHomeScreen();
            else
                showLogoutDialog();
        }
    }
}
 
Example #27
Source File: Advance3DDrawer1Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #28
Source File: MainActivity.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Open the navigation drawer.
 *
 * @param id
 *   The menu item id to perform an action on.
 */
public void openDrawer(int id) {
    if (drawer != null) {
        drawer.openDrawer(GravityCompat.START);
    }

    if (id > 0) {
        navigationView.setCheckedItem(id);
        drawerMenu.performIdentifierAction(id, 0);
    }
}
 
Example #29
Source File: MainActivity.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Close drawer if open otherwise go to app home screen.
 */
@Override
public void onBackPressed()
{
	DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	if (drawer.isDrawerOpen(GravityCompat.START))
	{
		drawer.closeDrawer(GravityCompat.START);
	}
	else
	{
		moveTaskToBack(true);
	}
}
 
Example #30
Source File: StopwatchFragment.java    From Alarmio with Apache License 2.0 5 votes vote down vote up
@Override
public void onLap(int lapNum, long lapTime, long lastLapTime, long lapDiff) {
    if (lastLapTime == 0)
        time.setMaxProgress(lapDiff);
    else time.setReferenceProgress(lapDiff);

    LinearLayout layout = new LinearLayout(getContext());

    TextView number = new TextView(getContext());
    number.setText(getString(R.string.title_lap_number, lapNum));
    number.setTextColor(textColorPrimary);
    layout.addView(number);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.weight = 1;

    TextView lap = new TextView(getContext());
    lap.setLayoutParams(layoutParams);
    lap.setGravity(GravityCompat.END);
    lap.setText(getString(R.string.title_lap_time, FormatUtils.formatMillis(lapDiff)));
    lap.setTextColor(textColorPrimary);
    layout.addView(lap);

    TextView total = new TextView(getContext());
    total.setLayoutParams(layoutParams);
    total.setGravity(GravityCompat.END);
    total.setText(getString(R.string.title_total_time, FormatUtils.formatMillis(lapTime)));
    total.setTextColor(textColorPrimary);
    layout.addView(total);

    lapsLayout.addView(layout, 0);
}