fix bottom navigation view height on android 15
This commit is contained in:
12
.idea/caches/deviceStreaming.xml
generated
12
.idea/caches/deviceStreaming.xml
generated
@@ -51,6 +51,18 @@
|
|||||||
<option name="screenX" value="1080" />
|
<option name="screenX" value="1080" />
|
||||||
<option name="screenY" value="2412" />
|
<option name="screenY" value="2412" />
|
||||||
</PersistentDeviceSelectionData>
|
</PersistentDeviceSelectionData>
|
||||||
|
<PersistentDeviceSelectionData>
|
||||||
|
<option name="api" value="35" />
|
||||||
|
<option name="brand" value="OnePlus" />
|
||||||
|
<option name="codename" value="OP5552L1" />
|
||||||
|
<option name="id" value="OP5552L1" />
|
||||||
|
<option name="labId" value="google" />
|
||||||
|
<option name="manufacturer" value="OnePlus" />
|
||||||
|
<option name="name" value="CPH2415" />
|
||||||
|
<option name="screenDensity" value="480" />
|
||||||
|
<option name="screenX" value="1080" />
|
||||||
|
<option name="screenY" value="2412" />
|
||||||
|
</PersistentDeviceSelectionData>
|
||||||
<PersistentDeviceSelectionData>
|
<PersistentDeviceSelectionData>
|
||||||
<option name="api" value="34" />
|
<option name="api" value="34" />
|
||||||
<option name="brand" value="OPPO" />
|
<option name="brand" value="OPPO" />
|
||||||
|
|||||||
7
.idea/misc.xml
generated
7
.idea/misc.xml
generated
@@ -14,4 +14,11 @@
|
|||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
<option name="id" value="Android" />
|
<option name="id" value="Android" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="VisualizationToolProject">
|
||||||
|
<option name="state">
|
||||||
|
<ProjectState>
|
||||||
|
<option name="scale" value="0.22487304687499998" />
|
||||||
|
</ProjectState>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -3,11 +3,17 @@ package ch.pizzalemon.android.activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.graphics.Insets;
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
|
import ch.pizzalemon.android.R;
|
||||||
import ch.pizzalemon.android.helper.DisplayHelper;
|
import ch.pizzalemon.android.helper.DisplayHelper;
|
||||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
|
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
|
||||||
|
|
||||||
@@ -23,8 +29,14 @@ public class BaseActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setCurrentActivity(this);
|
setCurrentActivity(this);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
|
}
|
||||||
DisplayHelper.changeStatusColor();
|
|
||||||
|
@Override
|
||||||
|
public void setContentView(int layoutResID) {
|
||||||
|
super.setContentView(layoutResID);
|
||||||
|
applyToInsentForStatusBar();
|
||||||
|
if (layoutResID != R.layout.activity_main){
|
||||||
|
applyToInsentForNavigationBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,4 +76,37 @@ public class BaseActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
return pInfo.versionName;
|
return pInfo.versionName;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void applyToInsentForNavigationBar() {
|
||||||
|
if (DisplayHelper.getNavMode() != NavMode.THREE_BUTTON){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ViewGroup content = findViewById(android.R.id.content);
|
||||||
|
if (content.getChildCount() > 0) {
|
||||||
|
View rootView = content.getChildAt(0);
|
||||||
|
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(rootView, (v, insets) -> {
|
||||||
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||||
|
v.setPadding(0, systemBars.top, 0, systemBars.bottom);
|
||||||
|
return insets;
|
||||||
|
});
|
||||||
|
|
||||||
|
ViewCompat.requestApplyInsets(rootView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyToInsentForStatusBar() {
|
||||||
|
ViewGroup content = findViewById(android.R.id.content);
|
||||||
|
if (content.getChildCount() > 0) {
|
||||||
|
View rootView = content.getChildAt(0);
|
||||||
|
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(rootView, (v, insets) -> {
|
||||||
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||||
|
v.setPadding(0, systemBars.top, 0, 0);
|
||||||
|
return insets;
|
||||||
|
});
|
||||||
|
|
||||||
|
ViewCompat.requestApplyInsets(rootView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import android.content.Intent;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
|
|
||||||
|
import androidx.core.view.WindowCompat;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.core.view.GravityCompat;
|
import androidx.core.view.GravityCompat;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
@@ -13,9 +15,11 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -34,6 +38,7 @@ import ch.pizzalemon.android.fragment.MenuFragment;
|
|||||||
import ch.pizzalemon.android.fragment.ProductFragment;
|
import ch.pizzalemon.android.fragment.ProductFragment;
|
||||||
import ch.pizzalemon.android.fragment.ProfileFragment;
|
import ch.pizzalemon.android.fragment.ProfileFragment;
|
||||||
import ch.pizzalemon.android.helper.DialogHelper;
|
import ch.pizzalemon.android.helper.DialogHelper;
|
||||||
|
import ch.pizzalemon.android.helper.DisplayHelper;
|
||||||
import ch.pizzalemon.android.helper.PriceHelper;
|
import ch.pizzalemon.android.helper.PriceHelper;
|
||||||
import ch.pizzalemon.android.helper.SessionHelper;
|
import ch.pizzalemon.android.helper.SessionHelper;
|
||||||
import ch.pizzalemon.android.helper.SharedPrefsHelper;
|
import ch.pizzalemon.android.helper.SharedPrefsHelper;
|
||||||
@@ -56,6 +61,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
@BindView(R.id.badgeLayout) RelativeLayout badgeLayout;
|
@BindView(R.id.badgeLayout) RelativeLayout badgeLayout;
|
||||||
@BindView(R.id.badgeTextView) TextView badgeTextView;
|
@BindView(R.id.badgeTextView) TextView badgeTextView;
|
||||||
|
|
||||||
|
@BindView(R.id.shoppingCartLayout) LinearLayout shoppingCartLayout;
|
||||||
@BindView(R.id.shoppingCartButtonLayout) RelativeLayout shoppingCartButtonLayout;
|
@BindView(R.id.shoppingCartButtonLayout) RelativeLayout shoppingCartButtonLayout;
|
||||||
@BindView(R.id.shoppingCartImageView) ImageView shoppingCartImageView;
|
@BindView(R.id.shoppingCartImageView) ImageView shoppingCartImageView;
|
||||||
@BindView(R.id.shoppingCartTextView) TextView shoppingCartTextView;
|
@BindView(R.id.shoppingCartTextView) TextView shoppingCartTextView;
|
||||||
@@ -114,6 +120,14 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void initShoppingCartButton(){
|
private void initShoppingCartButton(){
|
||||||
|
|
||||||
|
int shoppingCartLayoutBottomMarginPx = DisplayHelper.dpToPx(20);
|
||||||
|
if (DisplayHelper.getNavMode() == NavMode.THREE_BUTTON){
|
||||||
|
shoppingCartLayoutBottomMarginPx = DisplayHelper.dpToPx(40);
|
||||||
|
}
|
||||||
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) shoppingCartLayout.getLayoutParams();
|
||||||
|
params.bottomMargin = shoppingCartLayoutBottomMarginPx; // px cinsinden
|
||||||
|
|
||||||
|
|
||||||
animDown = AnimationUtils.loadAnimation(this, R.anim.anim_scale_down);
|
animDown = AnimationUtils.loadAnimation(this, R.anim.anim_scale_down);
|
||||||
animUp = AnimationUtils.loadAnimation(this, R.anim.anim_scale_up);
|
animUp = AnimationUtils.loadAnimation(this, R.anim.anim_scale_up);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ch.pizzalemon.android.activity;
|
||||||
|
|
||||||
|
public enum NavMode {
|
||||||
|
THREE_BUTTON,
|
||||||
|
GESTURE,
|
||||||
|
UNKNOWN
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package ch.pizzalemon.android.helper;
|
package ch.pizzalemon.android.helper;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.os.Build;
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.core.graphics.Insets;
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import ch.pizzalemon.android.R;
|
import ch.pizzalemon.android.R;
|
||||||
import ch.pizzalemon.android.activity.BaseActivity;
|
import ch.pizzalemon.android.activity.BaseActivity;
|
||||||
|
import ch.pizzalemon.android.activity.NavMode;
|
||||||
|
|
||||||
public class DisplayHelper {
|
public class DisplayHelper {
|
||||||
|
|
||||||
@@ -32,10 +35,41 @@ public class DisplayHelper {
|
|||||||
return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
public static NavMode getNavMode() {
|
||||||
|
// 1) Settings.Secure (Android 10+ çoğu OEM’de doğru)
|
||||||
|
try {
|
||||||
|
int s = android.provider.Settings.Secure.getInt(
|
||||||
|
BaseActivity.currentActivity.getContentResolver(), "navigation_mode");
|
||||||
|
if (s == 0) return NavMode.THREE_BUTTON;
|
||||||
|
if (s == 2) return NavMode.GESTURE;
|
||||||
|
} catch (android.provider.Settings.SettingNotFoundException ignore) { }
|
||||||
|
|
||||||
|
// 2) Framework config (cihaz resource üzerinden dene)
|
||||||
|
int id = BaseActivity.currentActivity.getResources()
|
||||||
|
.getIdentifier("config_navBarInteractionMode", "integer", "android");
|
||||||
|
if (id != 0) {
|
||||||
|
int mode = BaseActivity.currentActivity.getResources().getInteger(id);
|
||||||
|
if (mode == 0) return NavMode.THREE_BUTTON;
|
||||||
|
if (mode == 2) return NavMode.GESTURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) Fallback: WindowInsets (bunu view attached olduktan sonra çağır)
|
||||||
|
View root = BaseActivity.currentActivity.getWindow().getDecorView();
|
||||||
|
WindowInsetsCompat wi = ViewCompat.getRootWindowInsets(root);
|
||||||
|
if (wi == null) return NavMode.UNKNOWN;
|
||||||
|
|
||||||
|
Insets nav = wi.getInsets(WindowInsetsCompat.Type.navigationBars());
|
||||||
|
Insets gest = wi.getInsets(WindowInsetsCompat.Type.systemGestures());
|
||||||
|
// Heuristik: gesture'da nav bar yok ya da çok küçük; systemGestures > 0 olur
|
||||||
|
if (nav.bottom > 0 && gest.bottom == 0) return NavMode.THREE_BUTTON;
|
||||||
|
if (nav.bottom == 0 && gest.bottom > 0) return NavMode.GESTURE;
|
||||||
|
if (nav.bottom > 0 && gest.bottom > 0) {
|
||||||
|
// Bazı OEM'lerde küçük nav + gesture birlikte gelebilir
|
||||||
|
return (nav.bottom >= gest.bottom) ? NavMode.THREE_BUTTON : NavMode.GESTURE;
|
||||||
|
}
|
||||||
|
return NavMode.UNKNOWN;
|
||||||
|
}
|
||||||
public static void changeStatusColor() {
|
public static void changeStatusColor() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
return;
|
|
||||||
Window window = BaseActivity.currentActivity.getWindow();
|
Window window = BaseActivity.currentActivity.getWindow();
|
||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||||
|
|||||||
@@ -118,7 +118,7 @@
|
|||||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
android:id="@+id/bottomNavigationView"
|
android:id="@+id/bottomNavigationView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="72dp"
|
android:layout_height="wrap_content"
|
||||||
app:itemIconTint="@drawable/selector_bottom_navigation_item"
|
app:itemIconTint="@drawable/selector_bottom_navigation_item"
|
||||||
app:itemTextColor="@drawable/selector_bottom_navigation_item"
|
app:itemTextColor="@drawable/selector_bottom_navigation_item"
|
||||||
android:background="@color/pizzalemon_dark_green"
|
android:background="@color/pizzalemon_dark_green"
|
||||||
@@ -128,11 +128,11 @@
|
|||||||
android:layout_alignParentBottom="true"/>
|
android:layout_alignParentBottom="true"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/shoppingCartLayout"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:elevation="9dp"
|
android:elevation="9dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
@@ -191,16 +191,4 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageButton
|
|
||||||
android:id="@+id/shoppingCartButton"
|
|
||||||
android:layout_width="64dp"
|
|
||||||
android:layout_height="64dp"
|
|
||||||
android:background="@drawable/background_button_cart"
|
|
||||||
android:gravity="center"
|
|
||||||
android:src="@drawable/ic_bottom_nav_item_cart_white"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:elevation="9dp"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
Reference in New Issue
Block a user