Determine if the navigation bar will be on the bottom of the screen, based on logic in PhoneWindowManager. - Android User Interface

Android examples for User Interface:NavigationBar

Description

Determine if the navigation bar will be on the bottom of the screen, based on logic in PhoneWindowManager.

Demo Code

/*/* w  w w .j  av a2s  .  co  m*/
 * Copyright 2015 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;

public class Main {
  /**
   * Determine if the navigation bar will be on the bottom of the screen, based
   * on logic in PhoneWindowManager.
   */
  public static boolean isNavBarOnBottom(@NonNull Context context) {
    final Resources res = context.getResources();
    final Configuration cfg = context.getResources().getConfiguration();
    final DisplayMetrics dm = res.getDisplayMetrics();
    boolean canMove = (dm.widthPixels != dm.heightPixels && cfg.smallestScreenWidthDp < 600);
    return (!canMove || dm.widthPixels < dm.heightPixels);
  }
}

Related Tutorials