Merge remote-tracking branch 'origin/main'

This commit is contained in:
ろむねこ 2024-01-11 16:41:07 +09:00
commit b4d85f9011
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 25 additions and 10 deletions

View File

@ -26,7 +26,8 @@ import com.journeyapps.barcodescanner.ScanOptions;
* create an instance of this fragment. * create an instance of this fragment.
*/ */
public class QRFragment extends Fragment { public class QRFragment extends Fragment {
//QRコードから受け取ったURLの受け渡しの宣言
OnDataPass dataPass;
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM1 = "param1";
@ -69,25 +70,23 @@ public class QRFragment extends Fragment {
} }
//FragmentからActivityへデータの受け渡しをするためのInterface
public interface OnDataPass{
void onDataPass(String urlPass);
}
private final ActivityResultLauncher<ScanOptions> fragmentLauncher = registerForActivityResult(new ScanContract(), private final ActivityResultLauncher<ScanOptions> fragmentLauncher = registerForActivityResult(new ScanContract(),
result -> { result -> {
//QRコードからデータを読み取れたかの確認 //QRコードからデータを読み取れたかの確認
if(result.getContents() == null) { if(result.getContents() == null) {
Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show();
} else { } else {
//共有プリファレンス全体の準備 dataPass.onDataPass(result.getContents());
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0); //画面遷移
//共有プリファレンス書き込みの準備
SharedPreferences.Editor editor = sharedPreferences.edit();
//共有プリファレンスにURLの書き込み
editor.putString(result.getContents(),"");
//確定処理
editor.apply();
Intent intent=new Intent(getActivity(),UrlPageActivity.class); Intent intent=new Intent(getActivity(),UrlPageActivity.class);
startActivity(intent); startActivity(intent);
} }
});
});
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,

View File

@ -0,0 +1,16 @@
package com.example.childguard;
import androidx.appcompat.app.AppCompatActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.webkit.WebView;
public class UrlPageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_url_page);
}
}