|
| 1 | +package com.josh.trackcovid19v2; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | +import android.app.AlertDialog; |
| 5 | +import android.content.DialogInterface; |
| 6 | +import android.content.Intent; |
| 7 | +import android.os.Build; |
| 8 | +import android.os.Bundle; |
| 9 | + |
| 10 | +import androidx.fragment.app.Fragment; |
| 11 | + |
| 12 | +import android.util.DisplayMetrics; |
| 13 | +import android.view.InflateException; |
| 14 | +import android.view.LayoutInflater; |
| 15 | +import android.view.View; |
| 16 | +import android.view.ViewGroup; |
| 17 | +import android.widget.Button; |
| 18 | +import android.widget.EditText; |
| 19 | +import android.widget.TextView; |
| 20 | +import android.widget.Toast; |
| 21 | + |
| 22 | + |
| 23 | +/** |
| 24 | + * A simple {@link Fragment} subclass. |
| 25 | + * Use the {@link SendFeedbackFragment#newInstance} factory method to |
| 26 | + * create an instance of this fragment. |
| 27 | + */ |
| 28 | +public class SendFeedbackFragment extends Fragment { |
| 29 | + // TODO: Rename parameter arguments, choose names that match |
| 30 | + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER |
| 31 | + private static final String ARG_PARAM1 = "param1"; |
| 32 | + private static final String ARG_PARAM2 = "param2"; |
| 33 | + |
| 34 | + // TODO: Rename and change types of parameters |
| 35 | + private String mParam1; |
| 36 | + private String mParam2; |
| 37 | + |
| 38 | + public SendFeedbackFragment() { |
| 39 | + // Required empty public constructor |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Use this factory method to create a new instance of |
| 44 | + * this fragment using the provided parameters. |
| 45 | + * |
| 46 | + * @param param1 Parameter 1. |
| 47 | + * @param param2 Parameter 2. |
| 48 | + * @return A new instance of fragment SendFeedbackFragment. |
| 49 | + */ |
| 50 | + // TODO: Rename and change types and number of parameters |
| 51 | + public static SendFeedbackFragment newInstance(String param1, String param2) { |
| 52 | + SendFeedbackFragment fragment = new SendFeedbackFragment(); |
| 53 | + Bundle args = new Bundle(); |
| 54 | + args.putString(ARG_PARAM1, param1); |
| 55 | + args.putString(ARG_PARAM2, param2); |
| 56 | + fragment.setArguments(args); |
| 57 | + return fragment; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public void onCreate(Bundle savedInstanceState) { |
| 62 | + super.onCreate(savedInstanceState); |
| 63 | + if (getArguments() != null) { |
| 64 | + mParam1 = getArguments().getString(ARG_PARAM1); |
| 65 | + mParam2 = getArguments().getString(ARG_PARAM2); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 71 | + Bundle savedInstanceState) { |
| 72 | + // Inflate the layout for this fragment |
| 73 | + View view = inflater.inflate(R.layout.fragment_send_feedback, container, false); |
| 74 | + final TextView to = (TextView) view.findViewById(R.id.sendTo); |
| 75 | + final EditText message = (EditText) view.findViewById(R.id.EmailText); |
| 76 | + final EditText subject = (EditText) view.findViewById(R.id.subject); |
| 77 | + |
| 78 | + Button sendE = (Button) view.findViewById(R.id.sendEmail); |
| 79 | + sendE.setOnClickListener(new View.OnClickListener() { |
| 80 | + @Override |
| 81 | + public void onClick(android.view.View v) { |
| 82 | + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
| 83 | + |
| 84 | + builder.setTitle("Data"); |
| 85 | + builder.setMessage("We will need to take some data from your device to fix the report. Is this okay with you?"); |
| 86 | + |
| 87 | + builder.setPositiveButton("YES", new DialogInterface.OnClickListener() { |
| 88 | + |
| 89 | + public void onClick(DialogInterface dialog, int which) { |
| 90 | + |
| 91 | + |
| 92 | + String subS = subject.getText().toString(); |
| 93 | + String mesS = message.getText().toString(); |
| 94 | + String system = System.getProperty("os.version"); |
| 95 | + Integer API = Build.VERSION.SDK_INT; |
| 96 | + String device = Build.DEVICE; |
| 97 | + String model = Build.MODEL; |
| 98 | + String product = Build.PRODUCT; |
| 99 | + String display = Build.DISPLAY; |
| 100 | + String type = Build.TYPE; |
| 101 | + String user = Build.USER; |
| 102 | + DisplayMetrics displayMetrics = new DisplayMetrics(); |
| 103 | + ((Activity) getContext()).getWindowManager() |
| 104 | + .getDefaultDisplay() |
| 105 | + .getMetrics(displayMetrics); |
| 106 | + int height = displayMetrics.heightPixels + getNavigationBarHeight(); |
| 107 | + int width = displayMetrics.widthPixels; |
| 108 | + Intent email = new Intent(Intent.ACTION_SEND); |
| 109 | + |
| 110 | + email.putExtra(Intent.EXTRA_EMAIL , new String [] {toS}); |
| 111 | + email.putExtra(Intent.EXTRA_SUBJECT , subS); |
| 112 | + email.putExtra(Intent.EXTRA_TEXT , mesS + "\n\n\n\n\n\n" + "\nAPI: " + API + "\nDevice: " |
| 113 | + + device + "\nModel: "+ model +"\nType:" + type +"\nUser:" + user + |
| 114 | + "\nDisplay height: " + height + "\nDisplay width: " + width); |
| 115 | + |
| 116 | + email.setType("message/rfc822"); |
| 117 | + startActivity(Intent.createChooser(email, "Choose an app to send the email with")); |
| 118 | + dialog.dismiss(); |
| 119 | + } |
| 120 | + }); |
| 121 | + |
| 122 | + builder.setNegativeButton("NO", new DialogInterface.OnClickListener() { |
| 123 | + |
| 124 | + @Override |
| 125 | + public void onClick(DialogInterface dialog, int which) { |
| 126 | + |
| 127 | + Toast.makeText(getActivity(), "Canceled", Toast.LENGTH_SHORT).show(); |
| 128 | + dialog.dismiss(); |
| 129 | + } |
| 130 | + }); |
| 131 | + |
| 132 | + AlertDialog alert = builder.create(); |
| 133 | + alert.show(); |
| 134 | + } |
| 135 | + }); |
| 136 | + return view; |
| 137 | + } |
| 138 | + private int getNavigationBarHeight() { |
| 139 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 140 | + DisplayMetrics metrics = new DisplayMetrics(); |
| 141 | + ((Activity) getContext()).getWindowManager() |
| 142 | + .getDefaultDisplay() |
| 143 | + .getMetrics(metrics); |
| 144 | + int usableHeight = metrics.heightPixels; |
| 145 | + ((Activity) getContext()).getWindowManager() |
| 146 | + .getDefaultDisplay() |
| 147 | + .getRealMetrics(metrics); |
| 148 | + int realHeight = metrics.heightPixels; |
| 149 | + if (realHeight > usableHeight) |
| 150 | + return realHeight - usableHeight; |
| 151 | + else |
| 152 | + return 0; |
| 153 | + } |
| 154 | + return 0; |
| 155 | + } |
| 156 | +} |
0 commit comments