Compare commits

...

3 Commits

Author SHA1 Message Date
11ea004d30 菊池
地図に名前と、緯度経度を入れて実行できるようにしました。
良ければ確認お願いします。
2024-07-03 14:13:06 +09:00
9dec1476e1 菊池
名前の追加(scrollView)に成功。今度は名前と緯度経度別々にして、問題なくマップが見れるようにする
2024-07-02 20:56:34 +09:00
7e9b9eb751 菊池
名前を入れる前に、マップにちゃんと経路案内がされるかテストをしてほしいです。名前の機能を入れる前にそこで間違いがあったら危ないので、それで何かありましたら言ってください
2024-07-02 16:39:53 +09:00
5 changed files with 88 additions and 24 deletions

View File

@ -5,8 +5,9 @@
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="GRADLE" /> <option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> <option name="gradleJvm" value="JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -1,6 +1,6 @@
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" 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">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -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が選ばれました");
} }
}); });

View File

@ -1,20 +1,27 @@
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;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity; 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;
private LinearLayout locationsName;
ImageView backMain; ImageView backMain;
private MapsBinding binding; private MapsBinding binding;
@ -29,19 +36,20 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
backMain.setOnClickListener(this); backMain.setOnClickListener(this);
webView = findViewById(R.id.webView); webView = findViewById(R.id.webView);
locationsName = findViewById(R.id.locationsName);
WebSettings webSettings = webView.getSettings(); WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient()); webView.setWebViewClient(new WebViewClient());
// ここにデータを入れておいてください処理は[/]で区切っています // 初期の緯度経度と名前のセットをロード
loadMapInWebView("35.09050879999539,136.87845379325216/35.09284820618655,136.88165119390393/35.09364708442631,136.88171563326418"); 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("/");
// 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) {
@ -62,7 +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) {
runOnUiThread(() -> {
try {
TextView textView = new TextView(this);
textView.setText(locationName);
textView.setTextSize(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(underline);
} catch (Exception e) {
Log.e("Maps", "Error adding location to ScrollView", e);
}
});
} }
@Override @Override

View File

@ -31,7 +31,6 @@
android:textSize="40dp" /> android:textSize="40dp" />
</LinearLayout> </LinearLayout>
<!-- Webの処理 -->
<WebView <WebView
android:id="@+id/webView" android:id="@+id/webView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -42,6 +41,11 @@
android:id="@+id/scrollable" android:id="@+id/scrollable"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="3" /> android:layout_weight="3">
<LinearLayout
android:id="@+id/locationsName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
</LinearLayout> </LinearLayout>