Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking Navigation bar is exist on device #100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
Expand All @@ -23,7 +24,10 @@
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
Expand Down Expand Up @@ -363,7 +367,13 @@ && isStatusBarTranslucent()) {
// evaluate bottom or right offset due to navigation bar.
int bottomOffset = 0;
int rightOffset = 0;
final int navBarSize = getNavigationBarOffset();
int navBarSize = 0;

if (hasNavigationBar(mHoldingActivity)) {
navBarSize = getNavigationBarOffset();
} else {
navBarSize = 0;
}

if (mHoldingActivity.getResources().getBoolean(R.bool.blur_dialog_has_bottom_navigation_bar)) {
bottomOffset = navBarSize;
Expand Down Expand Up @@ -516,6 +526,23 @@ private int getNavigationBarOffset() {
return result;
}

/**
* Check the device has navigation bar
* @param context
* @return boolean has navigation bar
*/
boolean hasNavigationBar(Context context) {
Resources resources = context.getResources();
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
return resources.getBoolean(id);
} else { // Check for keys
boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
return !hasMenuKey && !hasBackKey;
}
}

/**
* Used to check if the status bar is translucent.
*
Expand Down Expand Up @@ -544,6 +571,18 @@ private void removeBlurredView() {
}
}

/**
* Removed the duplicated blurred view from the view hierarchy.
*/
private void removedDuplicateBlurredView() {
if (mBlurredBackgroundView != null) {
ViewGroup parent = (ViewGroup) mBlurredBackgroundView.getParent();
if (parent != null) {
parent.removeView(mBlurredBackgroundView);
}
}
}

/**
* Async task used to process blur out of ui thread
*/
Expand Down Expand Up @@ -606,7 +645,7 @@ protected void onPostExecute(Void aVoid) {

mBackgroundView.destroyDrawingCache();
mBackgroundView.setDrawingCacheEnabled(false);

removedDuplicateBlurredView();
mHoldingActivity.getWindow().addContentView(
mBlurredBackgroundView,
mBlurredBackgroundLayoutParams
Expand Down