[android] Add switch to enable 3D mode from layers bottomsheet

Signed-off-by: Jean-Baptiste <jeanbaptiste.charron@outlook.fr>
This commit is contained in:
Jean-Baptiste
2026-01-10 14:44:55 +01:00
parent d67803fc61
commit a0d563db02
2 changed files with 34 additions and 1 deletions

View File

@@ -1,24 +1,31 @@
package app.organicmaps.maplayer;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.sdk.Framework;
import app.organicmaps.sdk.maplayer.Mode;
import app.organicmaps.sdk.util.PowerManagment;
import app.organicmaps.sdk.util.SharedPropertiesUtils;
import app.organicmaps.util.ThemeSwitcher;
import app.organicmaps.util.Utils;
import app.organicmaps.util.bottomsheet.MenuBottomSheetFragment;
import app.organicmaps.widget.recycler.SpanningLinearLayoutManager;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.materialswitch.MaterialSwitch;
import java.util.ArrayList;
import java.util.List;
@@ -36,6 +43,20 @@ public class ToggleMapLayerFragment extends Fragment
{
View mRoot = inflater.inflate(R.layout.fragment_toggle_map_layer, container, false);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
final int powerManagementValue = sharedPreferences.getInt(ContextCompat.getString(requireContext(), R.string.power_management), PowerManagment.HIGH);
final boolean _3DEnabled = sharedPreferences.getBoolean(ContextCompat.getString(requireContext(), R.string.pref_3d_buildings),true);
MaterialSwitch m3DSwitch = mRoot.findViewById(R.id._3d_button);
m3DSwitch.setChecked(_3DEnabled);
if (powerManagementValue != PowerManagment.HIGH)
{
m3DSwitch.setEnabled(true);
m3DSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> Framework.nativeSet3dMode(true, isChecked));
}
else
{
m3DSwitch.setEnabled(false);
}
mMapButtonsController =
(MapButtonsController) requireActivity().getSupportFragmentManager().findFragmentById(R.id.map_buttons);
MaterialButton mCloseButton = mRoot.findViewById(R.id.close_button);

View File

@@ -42,8 +42,20 @@
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:minHeight="@dimen/toggle_map_layer_frame_height"
android:paddingStart="@dimen/margin_base"
android:paddingEnd="@dimen/margin_base" />
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/_3d_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|end"
android:text="@string/pref_map_3d_buildings_title"
android:layout_marginStart="@dimen/margin_half"
android:layout_marginEnd="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"/>
</LinearLayout>