Merge pull request '背景色消して○で表現できるようにした。すごい' (#58) from murakumo_Mapに○を into master

Reviewed-on: #58
This commit is contained in:
murakumo 2024-07-17 05:30:25 +00:00
commit 2c0bb36c68

View File

@ -2,6 +2,8 @@ package com.example.oplogy;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -413,6 +415,8 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
} }
} }
// スクロールビューに位置情報を追加するメソッド
// スクロールビューに位置情報を追加するメソッド
// スクロールビューに位置情報を追加するメソッド // スクロールビューに位置情報を追加するメソッド
private void addLocationToScrollView(String locationName, int color) { private void addLocationToScrollView(String locationName, int color) {
runOnUiThread(() -> { runOnUiThread(() -> {
@ -422,35 +426,52 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback, View.O
textView.setText(locationName); textView.setText(locationName);
textView.setTextSize(20); textView.setTextSize(20);
textView.setPadding(16, 16, 16, 16); textView.setPadding(16, 16, 16, 16);
textView.setBackgroundColor(color); textView.setTextColor(Color.BLACK); // 文字色を黒に設定
textView.setBackgroundColor(Color.WHITE); // 背景色を白に設定
// 円を作成
ShapeDrawable circle = new ShapeDrawable(new OvalShape());
circle.setIntrinsicWidth(30);
circle.setIntrinsicHeight(30);
circle.getPaint().setColor(color);
// 左側に円を表示するためにDrawableを設定
textView.setCompoundDrawablesWithIntrinsicBounds(circle, null, null, null);
textView.setCompoundDrawablePadding(16);
// テキストビューにクリックリスナーを追加 // テキストビューにクリックリスナーを追加
textView.setOnClickListener(v -> { textView.setOnClickListener(v -> {
// 名前リストから位置情報を取得 for (int j = 0; j < nameList.size(); j++) {
int index = nameList.indexOf(locationName); if (nameList.get(j).equals(locationName)) {
if (index != -1) { mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLngList.get(j), 17));
LatLng position = latLngList.get(index); break;
// カメラを該当ピンの位置に移動 }
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, 17));
} }
}); });
// 下線のビューの作成 // ボーダーラインの作成
View underline = new View(this); View border = new View(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 3); border.setLayoutParams(new LinearLayout.LayoutParams(
params.setMargins(0, 0, 0, 16); LinearLayout.LayoutParams.MATCH_PARENT, // 横幅は親と同じ
underline.setLayoutParams(params); 2 // 高さは2dp
underline.setBackgroundColor(Color.BLACK); ));
border.setBackgroundColor(Color.GRAY); // ボーダーラインの色を設定
// テキストビューと下線のビューをスクロールビューに追加 // レイアウトの作成
locationsName.addView(textView); LinearLayout layout = new LinearLayout(this);
locationsName.addView(underline); layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(textView);
layout.addView(border);
// スクロールビューにレイアウトを追加
locationsName.addView(layout);
} catch (Exception e) { } catch (Exception e) {
Log.e("Maps", "Error adding location to scroll view", e); Log.e("Maps", "エラーが発生しました。原因は以下", e);
} }
}); });
} }
private int getNextColor() { private int getNextColor() {
int color = COLORS[colorIndex]; int color = COLORS[colorIndex];
colorIndex = (colorIndex + 1) % COLORS.length; colorIndex = (colorIndex + 1) % COLORS.length;