diff --git a/app/src/main/java/org/ntlab/amaryllis/client/MyDialogFragment.java b/app/src/main/java/org/ntlab/amaryllis/client/MyDialogFragment.java new file mode 100644 index 0000000..75b3b25 --- /dev/null +++ b/app/src/main/java/org/ntlab/amaryllis/client/MyDialogFragment.java @@ -0,0 +1,328 @@ +package org.ntlab.amaryllis.client; + +//import android.app.Activity; +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import android.view.View; + +import android.app.Dialog; +import android.content.DialogInterface; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; + + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.RadioGroup; +import android.widget.TextView; + +import org.ntlab.amaryllis.client.fragment.ListFragment; + + +public class MyDialogFragment extends DialogFragment { + + + + public interface DialogFragmentListener{ + void onDialogPositiveButtonClicked(); + public void onOkClicked(Bundle args); + } + + public interface OnOkClickListener { + //public void onOkClicked(Bundle args); + } + + private DialogFragmentListener dialogFragmentListener; + + public MyDialogFragment newInstance(DialogFragmentListener dialogFragmentListener){ + this.dialogFragmentListener = dialogFragmentListener; + return new MyDialogFragment(); + } + + + + public static MyDialogFragment newInstance(Bundle bundle,Fragment fragment){ + MyDialogFragment instance = new MyDialogFragment(); + instance.setArguments(bundle); + instance.setTargetFragment(fragment, 0); + return instance; + } + + + + @Override + public void onAttach(Context context) { + super.onAttach(context); + + //public void onAttach(Activity activity) { + //super.onAttach(activity); + + + //System.out.printf("aaaaaaaaaaa"); + Fragment targetFragment = this.getTargetFragment(); + try{ + if(targetFragment != null){ + dialogFragmentListener = (DialogFragmentListener)targetFragment; + } + }catch (ClassCastException e){ + throw new ClassCastException("DialogFragmentListenerをimplementしていません"); + } + } + +///* + + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState){ + final EditText editTextTitle = new EditText(getActivity()); + final EditText editTextOverview = new EditText(getActivity()); + + Context context = getContext(); + LinearLayout layout = new LinearLayout(context); + layout.setOrientation(LinearLayout.VERTICAL); + editTextTitle.setHint("タイトル"); + editTextOverview.setHint("概要"); + + layout.addView(editTextTitle); + layout.addView(editTextOverview); + + + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()) + //Dialog dialog = new AlertDialog.Builder(getActivity()) + .setTitle("ボイスメモ") + .setMessage("タイトル、概要を入力してください。") + .setView(layout) + //.setView(editTextTitle) + //.setView(editTextOverview) + .setPositiveButton("決定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialogFragmentListener.onDialogPositiveButtonClicked(); + TextView Title = (TextView)getActivity().findViewById(R.id.VoiceTitle); + Title.setText(editTextTitle.getText()); + + TextView Overview = (TextView)getActivity().findViewById(R.id.VoiceOverview); + Overview.setText(editTextOverview.getText()); + //Title.setText("aaa"); + } + }) + .setNegativeButton("やめる", null); + //.create(); + + return dialogBuilder.create(); + //return dialog; + } + + +//*/ + + + + + + + + int mCheckedId; + + /* + + public static MyDialogFragment newInstance() { + + return new MyDialogFragment(); + } + + + private OnOkClickListener mListener; + public interface OnOkClickListener { + void onOkClicked(Bundle args); + } + + @Override + public void onAttach(Context Context) { + super.onAttach(Context); + mListener = (OnOkClickListener) getTargetFragment(); + if (mListener instanceof OnOkClickListener == false) { + throw new ClassCastException("実装エラー"); + } + } + + */ + + /* + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + LayoutInflater inflater = getActivity().getLayoutInflater(); + View v = inflater.inflate(R.layout.activity_my_dialog_fragment, null, false); + //RadioGroup radioGroup = (RadioGroup) v.findViewById(R.id.radioGroupOptions); + + //radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + //public void onCheckedChanged(RadioGroup group, int checkedId) { + //mCheckedId = checkedId; + //} + //}); + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle("MY DIALOG"); + builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // 呼び出し元フラグメントのビューを更新 + Bundle arg = new Bundle(); + arg.putInt("KEY_MYDIALOG", mCheckedId); + + // MyFragmentのonOkClickedをコール + //DialogFragmentListener.onOkClicked(arg); + } + }); + builder.setNegativeButton("Cancel", null); + builder.setView(v); + return builder.create(); + } + +//*/ + + /* + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + LayoutInflater inflater = requireActivity().getLayoutInflater(); + View v = inflater.inflate(R.layout.activity_my_dialog_fragment, null, false); + //RadioGroup radioGroup = (RadioGroup) v.findViewById(R.id.radioGroupOptions); + + + builder.setView(inflater.inflate(R.layout.activity_my_dialog_fragment, null)); + //radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + //public void onCheckedChanged(RadioGroup group, int checkedId) { + //mCheckedId = checkedId; + //} + //}); + + + //builder.setTitle("MY DIALOG"); + builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + // 呼び出し元フラグメントのビューを更新 + //Bundle arg = new Bundle(); + //arg.putInt("KEY_MYDIALOG", mCheckedId); + + // MyFragmentのonOkClickedをコール + //DialogFragmentListener.onOkClicked(arg); + } + }); + builder.setNegativeButton("Cancel", null); + //builder.setView(editText); + builder.setView(v); + return builder.create(); + } + +*/ + + + //@Override + //public void onCreate(Bundle savedInstanceState) { + //super.onCreate(savedInstanceState); + //if (getArguments() != null) { + //mParam1 = getArguments().getString(ARG_PARAM1); + //mParam2 = getArguments().getString(ARG_PARAM2); + //} + //} + + //@Override + //public View onCreateView(LayoutInflater inflater, ViewGroup container, + //Bundle savedInstanceState) { + // Inflate the layout for this fragment + //return inflater.inflate(R.layout.fragment_dialog, container, false); + //} + + //public void show(FragmentManager manager, String dialogFragment) { + //} + + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +//public class MyDialogFragment extends AppCompatActivity { + +//@Override +//protected void onCreate(Bundle savedInstanceState) { +//super.onCreate(savedInstanceState); +//setContentView(R.layout.activity_my_dialog_fragment); +//Toolbar toolbar = findViewById(R.id.toolbar); +//setSupportActionBar(toolbar); + +//FloatingActionButton fab = findViewById(R.id.fab); +//fab.setOnClickListener(new View.OnClickListener() { +//@Override +//public void onClick(View view) { +//Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) +//.setAction("Action", null).show(); +//} +//}); +//} +//} \ No newline at end of file