菊池
地図に名前と、緯度経度を入れて実行できるようにしました。 良ければ確認お願いします。
This commit is contained in:
parent
9dec1476e1
commit
11ea004d30
|
@ -1,4 +1,3 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
|
|
|
@ -168,12 +168,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
classId = CreateUUID.generateUUID(classIdList);
|
classId = CreateUUID.generateUUID(classIdList);
|
||||||
|
imageUuid.setImageResource(R.drawable.checked_image);
|
||||||
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
|
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
imageUuid.setImageResource(R.drawable.checked_image);
|
||||||
Log.d("DialogNO", "DialogでNoが選ばれました");
|
Log.d("DialogNO", "DialogでNoが選ばれました");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
@ -14,6 +16,8 @@ import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.example.oplogy.databinding.MapsBinding;
|
import com.example.oplogy.databinding.MapsBinding;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class Maps extends FragmentActivity implements View.OnClickListener {
|
public class Maps extends FragmentActivity implements View.OnClickListener {
|
||||||
|
|
||||||
private WebView webView;
|
private WebView webView;
|
||||||
|
@ -37,24 +41,15 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
|
||||||
webSettings.setJavaScriptEnabled(true);
|
webSettings.setJavaScriptEnabled(true);
|
||||||
webView.setWebViewClient(new WebViewClient());
|
webView.setWebViewClient(new WebViewClient());
|
||||||
|
|
||||||
// ここにデータを入れておいてください、処理は[/]で区切っています(緯度と経度で入れているので、そこで一度試してください)
|
// 初期の緯度経度と名前のセットをロード
|
||||||
loadMapInWebView("35.09050879999539,136.87845379325216,名古屋港水族館/35.091950716938875,136.8826598363985,2番目/35.09273643623442,136.88154941341296,3番目");
|
loadMapInWebView("35.09050879999539,136.87845379325216/35.091950716938875,136.8826598363985/35.09273643623442,136.88154941341296");
|
||||||
|
loadName("名古屋港水族館/2番目/3番目");
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebViewの処理です(Mapの中の処理をやっています)
|
// WebViewの処理です(Mapの中の処理をやっています)
|
||||||
private void loadMapInWebView(String locations) {
|
private void loadMapInWebView(String locations) {
|
||||||
// 区切ることで、追加の地点を入れて、最終地点にピンを打ってある状態です
|
try {
|
||||||
String[] locArray = locations.split("/");
|
String[] locArray = locations.split("/");
|
||||||
|
|
||||||
// 各地点の名前をScrollViewに表示
|
|
||||||
for (String loc : locArray) {
|
|
||||||
String[] parts = loc.split(",");
|
|
||||||
if (parts.length == 3) {
|
|
||||||
addLocationToScrollView(parts[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// URLで経路案内(車)での表示をしています
|
|
||||||
StringBuilder urlBuilder = new StringBuilder("https://www.google.com/maps/dir/?api=1&travelmode=driving");
|
StringBuilder urlBuilder = new StringBuilder("https://www.google.com/maps/dir/?api=1&travelmode=driving");
|
||||||
|
|
||||||
if (locArray.length > 0) {
|
if (locArray.length > 0) {
|
||||||
|
@ -75,15 +70,56 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webView.loadUrl(urlBuilder.toString());
|
runOnUiThread(() -> webView.loadUrl(urlBuilder.toString()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("Maps", "Error loading map in WebView", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新しい名前を追加するメソッドです
|
||||||
|
private void loadName(String locNames) {
|
||||||
|
try {
|
||||||
|
String[] locArray = locNames.split("/");
|
||||||
|
|
||||||
|
for (String loc : locArray) {
|
||||||
|
runOnUiThread(() -> addLocationToScrollView(loc));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("Maps", "Error loading names", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScrollViewに新しい場所の名前を追加するメソッドです
|
||||||
private void addLocationToScrollView(String locationName) {
|
private void addLocationToScrollView(String locationName) {
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
try {
|
||||||
TextView textView = new TextView(this);
|
TextView textView = new TextView(this);
|
||||||
textView.setText(locationName);
|
textView.setText(locationName);
|
||||||
textView.setTextSize(16);
|
textView.setTextSize(16);
|
||||||
textView.setPadding(16, 16, 16, 16);
|
textView.setPadding(16, 16, 16, 16);
|
||||||
|
|
||||||
|
// ランダムな背景色を設定
|
||||||
|
Random random = new Random();
|
||||||
|
int color = Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||||
|
textView.setBackgroundColor(color);
|
||||||
|
|
||||||
|
// 下線のViewを追加
|
||||||
|
View underline = new View(this);
|
||||||
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
2 // 下線の高さをピクセル単位で設定
|
||||||
|
);
|
||||||
|
params.setMargins(0, 0, 0, 16); // 下線の上下のマージンを設定
|
||||||
|
underline.setLayoutParams(params);
|
||||||
|
underline.setBackgroundColor(Color.BLACK); // 下線の色を設定
|
||||||
|
|
||||||
|
// TextViewと下線のViewを追加
|
||||||
locationsName.addView(textView);
|
locationsName.addView(textView);
|
||||||
|
locationsName.addView(underline);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("Maps", "Error adding location to ScrollView", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user