タイポをところどころ修正しました。

This commit is contained in:
磯野 2024-02-01 15:30:39 +09:00
parent aef4ba4bea
commit 895732b1b3
15 changed files with 77 additions and 79 deletions

View File

@ -1,6 +1,6 @@
<project version="4">
<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" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

BIN
app/release/app-release.apk Normal file

Binary file not shown.

View File

@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.example.childguard",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}

View File

@ -1,22 +0,0 @@
package com.example.childguard;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import androidx.appcompat.app.AppCompatActivity;
public class Bluetooth_device_save {
SharedPreferences pref;
// public void device_save(String deviceAddress){
// pref = PreferenceManager.getDefaultSharedPreferencesName()
// SharedPreferences.Editor e=pref.edit();
// e.putString("bluetooth_device1",deviceAddress);
// e.apply();
// }
public String device_info(){
return pref.getString("bluetooth_device1","not_device");
}
}

View File

@ -1,14 +1,18 @@
package com.example.childguard;
import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class First_Start extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_start);
}
}

View File

@ -23,6 +23,7 @@ public class GenerateQrFragment extends Fragment {
public GenerateQrFragment() {
// Required empty public constructor
}
public static GenerateQrFragment newInstance(String key) {
GenerateQrFragment fragment = new GenerateQrFragment();
Bundle args = new Bundle();
@ -54,7 +55,7 @@ public class GenerateQrFragment extends Fragment {
ImageView imageView = view.findViewById(R.id.result_bitmap_image_view);
imageView.setImageBitmap(result);
view.findViewById(R.id.button_print).setOnClickListener( v -> {
view.findViewById(R.id.button_print).setOnClickListener(v -> {
PrintHelper photoPrinter = new PrintHelper(requireContext());
photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
photoPrinter.printBitmap("placeholder", result, () -> {
@ -62,7 +63,7 @@ public class GenerateQrFragment extends Fragment {
});
});
view.findViewById(R.id.button_cancel).setOnClickListener( v -> {
view.findViewById(R.id.button_cancel).setOnClickListener(v -> {
getParentFragmentManager().popBackStack();
});
}

View File

@ -20,7 +20,7 @@ import androidx.fragment.app.FragmentTransaction;
* Use the {@link HomeFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class HomeFragment extends Fragment implements OnEventListener{
public class HomeFragment extends Fragment implements OnEventListener {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@ -133,26 +133,26 @@ public class HomeFragment extends Fragment implements OnEventListener{
return true;
}
private boolean updateBluetoothSituation(Boolean Bluetoothconnect){
private boolean updateBluetoothSituation(Boolean BluetoothConnect) {
FrameLayout frameLayout;
TextView textView;
ImageView imageView;
try {
frameLayout=requireView().findViewById(R.id.situation_bg2);
textView=requireView().findViewById(R.id.Bluetoothsituation);
imageView=requireView().findViewById(R.id.Bluetoothsituationimage);
}catch (NullPointerException e) {
frameLayout = requireView().findViewById(R.id.situation_bg2);
textView = requireView().findViewById(R.id.Bluetoothsituation);
imageView = requireView().findViewById(R.id.Bluetoothsituationimage);
} catch (NullPointerException e) {
Log.d("HomeFragment", "updateUiState: view is null");
return false;
} catch (IllegalStateException e) {
Log.d("HomeFragment", "updateUiState: view is not attached");
getParentFragmentManager().beginTransaction().replace(R.id.fragmentContainerView, HomeFragment.newInstance("test", "test")).commit();
updateBluetoothSituation(Bluetoothconnect);
updateBluetoothSituation(BluetoothConnect);
return false;
}
String connect="接続中";
String disconnect="切断中";
if (Bluetoothconnect) {
String connect = "接続中";
String disconnect = "切断中";
if (BluetoothConnect) {
//接続状態にする
frameLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null));
textView.setText(connect);
@ -177,13 +177,13 @@ public class HomeFragment extends Fragment implements OnEventListener{
@Override
public void onEvent2(boolean BluetoothConnect) {
return ;
return;
}
@Override
public boolean onEvent2(Boolean Bluetoothconnect) {//Bluetoothの接続切断を受け取ってupdateBluetoothSituation()に渡す
updateBluetoothSituation(Bluetoothconnect);
public boolean onEvent2(Boolean BluetoothConnect) {//Bluetoothの接続切断を受け取ってupdateBluetoothSituation()に渡す
updateBluetoothSituation(BluetoothConnect);
return false;
}
}

View File

@ -12,7 +12,6 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -25,7 +24,6 @@ import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.fragment.app.Fragment;
@ -65,7 +63,7 @@ public class MainActivity extends AppCompatActivity {
if (!contents.contains("https://practicefirestore1-8808c.web.app/")) {
Toast.makeText(this, "Child Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show();
} else {
changeisInCar();
changeIsInCar();
}
}
}
@ -101,7 +99,7 @@ public class MainActivity extends AppCompatActivity {
.replace(findViewById(R.id.fragmentContainerView).getId(), this.homeFragment)
.addToBackStack(null)
.commit();
firebaselink();
firebaseLink();
} else if (v.getItemId() == findViewById(R.id.navigation_settings).getId()) {
findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.GONE);
@ -110,7 +108,7 @@ public class MainActivity extends AppCompatActivity {
.addToBackStack(null)
.commit();
}
firebaselink();
firebaseLink();
Bluetooth_status();
return true;
});
@ -146,7 +144,7 @@ public class MainActivity extends AppCompatActivity {
super.onResume();
Log.d("onResume", "called");
Log.d("onResume", "mDocRef is null");
firebaselink();
firebaseLink();
}
private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理
@ -168,7 +166,7 @@ public class MainActivity extends AppCompatActivity {
//FireBaseで更新された情報の判定
if (!documentSnapshot.getBoolean("isReported")) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき
if (fragment instanceof HomeFragment) {//fragmentがHomeFragmentのインスタンスかの判定
// changessituation();// changessituation()メソッドを処理アプリ側の乗降状態を変化
// changes-situation();// changes-situation()メソッドを処理アプリ側の乗降状態を変化
((HomeFragment) fragment).onEvent(!isInCar);
}
} else if (isInCar) {//第三者ボタンが押されたときにisInCarがtrueのとき乗車状態のときいたずら防止
@ -231,7 +229,7 @@ public class MainActivity extends AppCompatActivity {
public void firebaselink() {//Firebaseのドキュメントの取得
public void firebaseLink() {//Firebaseのドキュメントの取得
//共有プリファレンス全体の準備
SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
String IdPref = sharedPreferences.getString("ID", null);////アプリに記録されているIDの取得
@ -255,7 +253,7 @@ public class MainActivity extends AppCompatActivity {
isReported.update("isReported", false).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e));
}
public void changeisInCar() {
public void changeIsInCar() {
//共有プリファレンス全体の準備
SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("app_situation", MODE_PRIVATE);
//共有プリファレンス 書き込みの準備
@ -418,7 +416,6 @@ public class MainActivity extends AppCompatActivity {
String action = intent.getAction(); // may need to chain this to a recognizing function
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Boolean isInCar = pref.getBoolean("isInCarPref", false);
Boolean Bluetoothconnect = pref.getBoolean("change", false);
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
Log.d("BT", "No permission to connect bluetooth devices");
return;
@ -477,9 +474,9 @@ public class MainActivity extends AppCompatActivity {
public void changeBluetooth(){
SharedPreferences pref=getSharedPreferences("Bluetooth_situation",MODE_PRIVATE);
SharedPreferences.Editor e=pref.edit();
Boolean Bluetoothconnect = pref.getBoolean("change", false);
Boolean BluetoothConnect = pref.getBoolean("change", false);
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
((HomeFragment) fragment).onEvent2(Bluetoothconnect);
((HomeFragment) fragment).onEvent2(BluetoothConnect);
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
public class NotificationReceiver extends BroadcastReceiver {//通知をタップしたときにアプリを起動する処理
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals("OPEN_ACTIVITY")) {// 通知がタップされたときの処理

View File

@ -6,5 +6,5 @@ public interface OnEventListener {
void onEvent2(boolean BluetoothConnect);
boolean onEvent2(Boolean Bluetoothconnect);
boolean onEvent2(Boolean BluetoothConnect);
}

View File

@ -1,19 +1,14 @@
package com.example.childguard;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.util.AndroidRuntimeException;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.widget.ImageView;
import androidx.print.PrintHelper;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
@ -30,20 +25,20 @@ public class QrUtils {
public Bitmap getBitmap(String key) {
Log.d("getBitmap", "getBitmap: " + key);
String KoteiURL = "https://practicefirestore1-8808c.web.app/?id=";
String fixationURL = "https://practicefirestore1-8808c.web.app/?id=";
//すべてのドメイン
String AllURL;
//IdPrefにの値が初期値の場合
AllURL=KoteiURL+key;
AllURL = fixationURL + key;
int qrCodeSize = calculateQRCodeSize(); // 画面密度に応じてサイズを計算
Bitmap QRGazou;
Bitmap bitmapqr;
Bitmap QRImage;
Bitmap bitmapQR;
try {
//QRコード生成
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
bitmapqr = barcodeEncoder.encodeBitmap(AllURL, BarcodeFormat.QR_CODE, qrCodeSize, qrCodeSize);
bitmapQR = barcodeEncoder.encodeBitmap(AllURL, BarcodeFormat.QR_CODE, qrCodeSize, qrCodeSize);
} catch (WriterException e) {
throw new AndroidRuntimeException("Barcode Error.", e);
}
@ -51,19 +46,20 @@ public class QrUtils {
Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.a_group_qr_sos_2);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
QRGazou = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
QRImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// Canvasの準備
Canvas canvas = new Canvas(QRGazou);
Canvas canvas = new Canvas(QRImage);
// 画像のサイズの調整
int disWidth = (width - bitmapqr.getWidth()) / 2;
int disHeight = (int) ((height - bitmapqr.getHeight()) / 1.5);
int disWidth = (width - bitmapQR.getWidth()) / 2;
int disHeight = (int) ((height - bitmapQR.getHeight()) / 1.5);
canvas.drawBitmap(bitmap, 0, 0, (Paint) null);
canvas.drawBitmap(bitmapqr, disWidth, disHeight, (Paint) null); // 画像合成
canvas.drawBitmap(bitmapQR, disWidth, disHeight, (Paint) null); // 画像合成
//Androidからプリンターへ印刷指示を出すサポートライブラリ
return QRGazou;
return QRImage;
}
private int calculateQRCodeSize() {
// 画面解像度を取得
DisplayMetrics metrics = new DisplayMetrics();

View File

@ -23,6 +23,7 @@ public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ItemVi
Context applicationContext;
View parentView;
// Constructor
public RecyclerAdapter(ArrayList<String[]> deviceList, Context applicationContext, View parentView) {
// Init
@ -30,6 +31,7 @@ public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ItemVi
this.deviceList = deviceList;
this.applicationContext = applicationContext;
this.parentView = parentView;
}
@NonNull
@ -43,7 +45,7 @@ public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ItemVi
@Override
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
holder.textView.setText(deviceList.get(position)[0]);
holder.textView.setOnClickListener( v -> {
holder.textView.setOnClickListener(v -> {
// アラートダイアログを表示
new AlertDialog.Builder(v.getContext())
@ -53,14 +55,13 @@ public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ItemVi
// OK button pressed
Toast.makeText(v.getContext(), "OK button clicked", Toast.LENGTH_SHORT).show();
//共有プリファレンスに保存
SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(this.applicationContext);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.applicationContext);
sharedPreferences.edit().putString("bluetooth_device_id", deviceList.get(position)[1]).apply();
sharedPreferences.edit().putString("bluetooth_device_name",deviceList.get(position)[0]).apply();
Toast.makeText(v.getContext(),PreferenceManager.getDefaultSharedPreferences(this.applicationContext).getString("bluetooth_device_id","none"), Toast.LENGTH_SHORT).show();
sharedPreferences.edit().putString("bluetooth_device_name", deviceList.get(position)[0]).apply();
Toast.makeText(v.getContext(), PreferenceManager.getDefaultSharedPreferences(this.applicationContext).getString("bluetooth_device_id", "none"), Toast.LENGTH_SHORT).show();
TextView textView = this.parentView.findViewById(R.id.registered_device);
textView.setText(PreferenceManager.getDefaultSharedPreferences(this.applicationContext).getString("bluetooth_device_name","none"));
textView.setText(PreferenceManager.getDefaultSharedPreferences(this.applicationContext).getString("bluetooth_device_name", "none"));
})

View File

@ -26,6 +26,7 @@ import java.util.Map;
public class SettingFragment extends Fragment {
FirebaseFirestore db;
public SettingFragment() {
// Required empty public constructor
}
@ -55,11 +56,11 @@ public class SettingFragment extends Fragment {
db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
view.findViewById(R.id.button_bluetooth_setting).setOnClickListener( v -> {
view.findViewById(R.id.button_bluetooth_setting).setOnClickListener(v -> {
getParentFragmentManager().beginTransaction().replace(R.id.fragmentContainerView, bluetooth_setupFragment.newInstance("test", "test")).addToBackStack(null).commit();
});
view.findViewById(R.id.button_print_qr).setOnClickListener( v -> {
view.findViewById(R.id.button_print_qr).setOnClickListener(v -> {
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("app_situation", MODE_PRIVATE);
boolean alreadySaved = sharedPreferences.getBoolean("alreadySaved", false);
//falseのときにFirebaseへの登録

View File

@ -77,6 +77,7 @@ public class TestService extends Service {
Log.d("nt", "レスポンスを検知しました1");
if (isInCar) {//isReportedがtrue=サイト上で乗車状態のとき
if (documentSnapshot.getBoolean("isReported")) {
//ここスタートリサイクル
ResetReported();// ResetReported();を処理FireBaseのisReportedをfalseにする
NotificationSetting();//通知に関する設定のメソッド
Notification(getApplicationContext());//通知を行うメソッド

View File

@ -126,7 +126,6 @@ public class bluetooth_setupFragment extends Fragment {
for (BluetoothDevice device : pairedDevices) {
String[] deviceInfo = new String[2];
deviceInfo[0] = device.getName();
deviceInfo[1] = device.getAddress(); // MAC address
@ -143,9 +142,8 @@ public class bluetooth_setupFragment extends Fragment {
//RecyclerViewとAdapterの結び付け
recyclerView1.setAdapter(adapter);
TextView textView=view.findViewById(R.id.registered_device);
textView.setText(PreferenceManager.getDefaultSharedPreferences(requireActivity().getApplicationContext()).getString("bluetooth_device_name","none"));
TextView textView = view.findViewById(R.id.registered_device);
textView.setText(PreferenceManager.getDefaultSharedPreferences(requireActivity().getApplicationContext()).getString("bluetooth_device_name", "none"));
}