Merge pull request #11167 from osmandapp/fix_class_cast_exc

Fix ClassCastException
This commit is contained in:
Vitaliy 2021-03-16 17:19:16 +02:00 committed by GitHub
commit 8020884d6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
@ -20,6 +19,18 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.github.ksoichiro.android.observablescrollview.ScrollUtils;
import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
@ -85,17 +96,6 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.IndexConstants.GPX_INDEX_DIR;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode;
@ -303,9 +303,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} else {
cardsContainer = mapActivity.findViewById(R.id.left_side_menu);
bottomMapControls = mapActivity.findViewById(R.id.bottom_controls_container);
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
ScrollUtils.addOnGlobalLayoutListener(mainView, new Runnable() {
@Override
public void onGlobalLayout() {
public void run() {
updateCardContainerSize();
}
});
@ -676,19 +676,36 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void updateCardContainerSize() {
if (portrait) {
return;
}
View measureModeControls = mainView.findViewById(R.id.measure_mode_controls);
int width = mainView.getWidth() - measureModeControls.getWidth();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, -1);
int bottomMargin = measureModeControls.getHeight();
bottomMargin = progressBarVisible ? bottomMargin + mainView.findViewById(R.id.snap_to_road_progress_bar).getHeight() : bottomMargin;
params.setMargins(0, 0, 0, bottomMargin);
cardsContainer.setLayoutParams(params);
if (mainView.getParent() instanceof FrameLayout) {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, -1);
params.setMargins(0, 0, 0, bottomMargin);
cardsContainer.setLayoutParams(params);
} else if (mainView.getParent() instanceof LinearLayout) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, -1);
params.setMargins(0, 0, 0, bottomMargin);
cardsContainer.setLayoutParams(params);
}
}
private void shiftBottomMapControls(boolean toInitialPosition) {
if (portrait) {
return;
}
int leftMargin = toInitialPosition ? 0 : cardsContainer.getWidth();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) bottomMapControls.getLayoutParams();
params.setMargins(leftMargin, 0, 0, 0);
if (bottomMapControls.getParent() instanceof LinearLayout) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) bottomMapControls.getLayoutParams();
params.setMargins(leftMargin, 0, 0, 0);
} else if (bottomMapControls.getParent() instanceof FrameLayout) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) bottomMapControls.getLayoutParams();
params.setMargins(leftMargin, 0, 0, 0);
}
}
public boolean isInEditMode() {