commit
b10f3409a6
|
@ -1,5 +1,8 @@
|
|||
plugins {
|
||||
id 'com.android.application'
|
||||
|
||||
id 'com.google.gms.google-services'
|
||||
|
||||
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
|
||||
}
|
||||
|
||||
|
@ -37,6 +40,7 @@ dependencies {
|
|||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'com.google.firebase:firebase-firestore:24.4.1'
|
||||
implementation 'com.google.android.gms:play-services-maps:18.2.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
|
|
|
@ -1,16 +1,41 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import androidd.os.Bunle;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.gms.tasks.OnFailureListener;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.google.firebase.firestore.DocumentReference;
|
||||
import com.google.firebase.firestore.DocumentSnapshot;
|
||||
import com.google.firebase.firestore.FirebaseFirestore;
|
||||
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private TextView textView;
|
||||
private Button btnShow;
|
||||
private Button btnAdd;
|
||||
private EditText number;
|
||||
private EditText address;
|
||||
private EditText date;
|
||||
private EditText time;
|
||||
private FirebaseFirestore db = FirebaseFirestore.getInstance();
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
|
||||
Button button;
|
||||
// TextView textView;
|
||||
EditText editText;
|
||||
|
@ -21,6 +46,54 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
||||
textView=findViewById(R.id.showText);
|
||||
btnShow=findViewById(R.id.btnShow);
|
||||
btnAdd=findViewById(R.id.btnAdd);
|
||||
|
||||
number=findViewById(R.id.editNumber);
|
||||
address=findViewById(R.id.editAddress);
|
||||
date=findViewById(R.id.editDate);
|
||||
time=findViewById(R.id.editTime);
|
||||
|
||||
|
||||
//データの追加(適当なデータを追加しています。実際にはデータベースに保存したいデータを追加してください。)
|
||||
|
||||
findViewById(R.id.btnAdd).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
User user = new User(number.getText().toString(), address.getText().toString(),date.getText().toString(),time.getText().toString());
|
||||
|
||||
|
||||
db.collection("users")
|
||||
.add(user)
|
||||
.addOnSuccessListener(documentReference -> Log.d("@FB1", "DocumentSnapshot added with ID: " + documentReference.getId()))
|
||||
.addOnFailureListener(e -> Log.w("@FB1", "Error adding document", e));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
btnShow.setOnClickListener(v -> {
|
||||
// ⑤Read Data
|
||||
// Firestoreのコレクション「users」のドキュメント一覧を取得する
|
||||
// 非同期で取得処理が動作する。結果を受け取るために処理完了時のリスナーをセットする
|
||||
db.collection("users").get().addOnCompleteListener(task -> {
|
||||
String data = "";
|
||||
if (task.isSuccessful()) {
|
||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||
Log.d("@FB1", document.getId() + "=>" + document.getData());
|
||||
User user = document.toObject(User.class);
|
||||
data += user + "\n";
|
||||
}
|
||||
} else {
|
||||
data = "Error getting documents." + task.getException().getMessage();
|
||||
}
|
||||
textView.setText(data);//編集したデータを画面下部に表示
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
findViewById(R.id.mapmapcreate).setOnClickListener(
|
||||
view->{
|
||||
|
@ -33,5 +106,48 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
class User {
|
||||
private String number;
|
||||
private String address;
|
||||
private String date;
|
||||
private String time;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String number, String address, String data, String time) {
|
||||
this.number = number;
|
||||
this.address = address;
|
||||
this.date = data;
|
||||
this.time = time;
|
||||
}
|
||||
//getterとsetter
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,47 @@
|
|||
tools:context=".MainActivity"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editNumber"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="番号" />
|
||||
<EditText
|
||||
android:id="@+id/editAddress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="住所" />
|
||||
<EditText
|
||||
android:id="@+id/editDate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="日付" />
|
||||
<EditText
|
||||
android:id="@+id/editTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="時間" />
|
||||
<Button
|
||||
android:id="@+id/btnAdd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="追加"/>
|
||||
<Button
|
||||
android:id="@+id/btnShow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="表示" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/showText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
|
||||
|
||||
=======
|
||||
<Button
|
||||
android:id="@+id/mapmapcreate"
|
||||
android:text="マップ生成"
|
||||
|
@ -24,4 +65,5 @@
|
|||
android:text=""
|
||||
/>
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -1,4 +1,8 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath 'com.google.gms:google-services:4.3.14'
|
||||
}
|
||||
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.0.2' apply false
|
||||
id 'com.android.library' version '8.0.2' apply false
|
||||
|
|
Loading…
Reference in New Issue
Block a user