6 package com.google.appinventor.components.runtime.view;
8 import android.content.res.ColorStateList;
9 import android.graphics.Color;
10 import android.graphics.drawable.Drawable;
11 import android.graphics.drawable.ShapeDrawable;
12 import android.graphics.drawable.shapes.RoundRectShape;
13 import android.view.Gravity;
14 import android.view.View;
15 import android.widget.Button;
16 import android.widget.LinearLayout;
18 import org.osmdroid.views.MapView;
22 private final MapView parent;
23 private final Button zoomIn;
24 private final Button zoomOut;
26 private float density;
29 super(parent.getContext());
31 density = parent.getContext().getResources().getDisplayMetrics().density;
34 this.setOrientation(LinearLayout.VERTICAL);
35 zoomIn =
new Button(parent.getContext());
36 zoomOut =
new Button(parent.getContext());
37 initButton(zoomIn,
"+");
38 initButton(zoomOut,
"−");
39 zoomIn.setOnClickListener(
new OnClickListener() {
41 public void onClick(View view) {
45 zoomOut.setOnClickListener(
new OnClickListener() {
47 public void onClick(View view) {
55 int[][] states =
new int[][] {
56 new int[] {-android.R.attr.state_enabled },
57 new int[] { android.R.attr.state_enabled }
59 int[] colors =
new int[] {
63 zoomIn.setTextColor(
new ColorStateList(states, colors));
64 zoomOut.setTextColor(
new ColorStateList(states, colors));
69 this.setPadding((
int)(12 * density), (
int)(12 * density), 0, 0);
76 @SuppressWarnings(
"WeakerAccess")
78 zoomIn.setEnabled(parent.canZoomIn());
79 zoomOut.setEnabled(parent.canZoomOut());
82 private void initButton(Button button, String text) {
84 button.setTextSize(22);
85 button.setPadding(0, 0, 0, 0);
86 button.setWidth((
int)(30 * density));
87 button.setHeight((
int)(30 * density));
88 button.setSingleLine();
89 button.setGravity(Gravity.CENTER);
92 private static Drawable getZoomInDrawable(
float density) {
93 final int R = (int)(4 * density);
94 ShapeDrawable drawable =
new ShapeDrawable(
new RoundRectShape(
new float[] { R, R, R, R, 0, 0, 0, 0 },
null,
null));
95 drawable.getPaint().setColor(Color.WHITE);
99 private static Drawable getZoomOutDrawable(
float density) {
100 final int R = (int)(4 * density);
101 ShapeDrawable drawable =
new ShapeDrawable(
new RoundRectShape(
new float[] { 0, 0, 0, 0, R, R, R, R },
null,
null));
102 drawable.getPaint().setColor(Color.WHITE);