FIreBaseへの登録とFireBaseによって生成されたIDを用いたQRコードの生成、登録済みの場合は重複の登録は行わないようにする処理を追加しました
This commit is contained in:
parent
f7566d9df0
commit
98578291ea
|
@ -3,6 +3,7 @@ package com.example.childguard;
|
|||
import static android.content.ContentValues.TAG;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
@ -11,6 +12,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -34,7 +36,6 @@ import java.util.Map;
|
|||
* create an instance of this fragment.
|
||||
*/
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
FirebaseFirestore db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
|
@ -43,7 +44,7 @@ public class HomeFragment extends Fragment {
|
|||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String str_key;
|
||||
private String mParam2;
|
||||
|
||||
public HomeFragment() {
|
||||
|
@ -72,7 +73,7 @@ public class HomeFragment extends Fragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
// mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
@ -92,13 +93,17 @@ public class HomeFragment extends Fragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
//初回起動かを保存する変数
|
||||
// int i = Integer.parseInt(preferences.getString("kidoukaisuu", "1"));
|
||||
boolean alreadySaved = preferences.getBoolean("alreadySaved", false);
|
||||
//ボタン変数の宣言
|
||||
Button parent = view.findViewById(R.id.QRprinting);
|
||||
Button born = view.findViewById(R.id.QRprinting);
|
||||
if (alreadySaved) {
|
||||
//falseのときにFirebaseへの登録
|
||||
if (!alreadySaved) {
|
||||
Log.d("HomeFragment", "already printed");
|
||||
//画面遷移&ID受け渡し
|
||||
Toast.makeText(getActivity(),"再印刷",Toast.LENGTH_SHORT).show();
|
||||
QrPrintFragment qrPrintFragment = new QrPrintFragment();
|
||||
replaceFragment(qrPrintFragment);
|
||||
return;
|
||||
} else Log.d("HomeFragment", "not printed yet"); // debug
|
||||
|
||||
|
@ -118,12 +123,23 @@ public class HomeFragment extends Fragment {
|
|||
@Override
|
||||
public void onSuccess(DocumentReference documentReference) {
|
||||
//成功したら
|
||||
//documentReference.getId()でID取得
|
||||
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());
|
||||
SharedPreferences.Editor e = preferences.edit();
|
||||
e.putBoolean("alreadySaved", true);
|
||||
// キー"alreadySaved"の値をtrueにする
|
||||
e.putBoolean("alreadySaved", false);
|
||||
//確定処理
|
||||
e.apply();
|
||||
//画面遷移
|
||||
replaceFragment(new QrPrintFragment());
|
||||
//画面遷移&ID受け渡し
|
||||
str_key = "" + documentReference.getId();
|
||||
Toast.makeText(getActivity(),"初回登録",Toast.LENGTH_SHORT).show();
|
||||
QrPrintFragment qrPrintFragment = new QrPrintFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("STR_KEY",str_key);
|
||||
//値を書き込む
|
||||
qrPrintFragment.setArguments(bundle);
|
||||
replaceFragment(qrPrintFragment);
|
||||
|
||||
}
|
||||
})
|
||||
.addOnFailureListener(new OnFailureListener() {
|
||||
|
@ -134,11 +150,7 @@ public class HomeFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
//
|
||||
// SharedPreferences.Editor e = preferences.edit();
|
||||
// e.putString("kidoukiroku", "2");
|
||||
// e.apply();
|
||||
replaceFragment(new QrPrintFragment());
|
||||
|
||||
}
|
||||
});
|
||||
//bluetooth設定ボタンの処理
|
||||
|
@ -160,7 +172,6 @@ public class HomeFragment extends Fragment {
|
|||
FrameLayout situation_bg = getView().findViewById(R.id.situation_bg);
|
||||
updateInCarStatus(situationTextView, situation_bg);
|
||||
}
|
||||
|
||||
public void updateInCarStatus(TextView situationTextView, FrameLayout situation_bg) {
|
||||
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0);
|
||||
|
||||
|
|
|
@ -15,19 +15,19 @@ public class QR extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fragment_qr);
|
||||
|
||||
findViewById(R.id.camera).setOnClickListener(
|
||||
v -> {
|
||||
if(get_on.equals(tv.getText().toString())){
|
||||
tv.setText(get_off);
|
||||
findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#dcdcdc"));
|
||||
}
|
||||
else {
|
||||
tv.setText(get_on);
|
||||
findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#ff4500"));
|
||||
}
|
||||
}
|
||||
);
|
||||
//多分いらないコード
|
||||
// findViewById(R.id.camera).setOnClickListener(
|
||||
// v -> {
|
||||
// if(get_on.equals(tv.getText().toString())){
|
||||
// tv.setText(get_off);
|
||||
// findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#dcdcdc"));
|
||||
// }
|
||||
// else {
|
||||
// tv.setText(get_on);
|
||||
// findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#ff4500"));
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -97,13 +97,10 @@ public class QRFragment extends Fragment {
|
|||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_qr, container, false);
|
||||
|
||||
Button cameraButton = view.findViewById(R.id.camera);
|
||||
|
||||
cameraButton.setOnClickListener(v -> {
|
||||
Log.d("QRFragment", "onClick: called");
|
||||
//QRリーダ起動
|
||||
fragmentLauncher.launch(new ScanOptions());
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.example.childguard;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
|
@ -10,6 +11,7 @@ import android.os.Bundle;
|
|||
import androidx.fragment.app.Fragment;
|
||||
import androidx.print.PrintHelper;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -59,7 +61,7 @@ public class QrPrintFragment extends Fragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate (Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
|
@ -68,18 +70,34 @@ public class QrPrintFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
//共有プリファレンス 全体の準備
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
//User毎のドメインを保存する
|
||||
String IdPref=preferences.getString("ID",null);
|
||||
// Inflate the layout for this fragment
|
||||
View view=inflater.inflate(R.layout.fragment_qr_print, container, false);
|
||||
|
||||
View view=inflater.inflate(R.layout.fragment_qr_print, container, false);;
|
||||
//固定のドメイン
|
||||
String KoteiURL = "https://practicefirestore1-8808c.web.app/?id=";
|
||||
//すべてのドメイン
|
||||
String AllURL;
|
||||
//IdPrefにの値が初期値の場合
|
||||
if(IdPref==null) {
|
||||
//User毎のドメイン
|
||||
String userURL="YKjFsZgJBlZmcyvdZ3Ap";
|
||||
String userURL = getArguments().getString("STR_KEY");
|
||||
//キー"ID"の値をuserURLの値にする
|
||||
SharedPreferences.Editor e = preferences.edit();
|
||||
e.putString("ID", userURL);
|
||||
//確定処理
|
||||
e.apply();
|
||||
//二つのドメインを合成する
|
||||
String AllURL=KoteiURL+userURL;
|
||||
AllURL=KoteiURL+userURL;
|
||||
}else{
|
||||
//二つのドメインを合成する
|
||||
AllURL=KoteiURL+IdPref;
|
||||
}
|
||||
|
||||
int size = 2500;
|
||||
ImageView imageViewQrCode;
|
||||
|
@ -96,6 +114,7 @@ public class QrPrintFragment extends Fragment {
|
|||
throw new AndroidRuntimeException("Barcode Error.", e);
|
||||
}
|
||||
// 画像合成の準備
|
||||
// ここのエラーは直すと何故か動かなくなる。このままで動くので放置
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a_group_qr_sos);
|
||||
Bitmap bitmap1 = ((BitmapDrawable) imageViewQrCode.getDrawable()).getBitmap();
|
||||
int width = bitmap.getWidth(); // 元ファイルの幅取得
|
||||
|
|
|
@ -5,13 +5,6 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".QRFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<Button
|
||||
android:id="@+id/camera"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue
Block a user