質問編集履歴
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,9 +88,111 @@
|
|
88
88
|
|
89
89
|
```AsyncTask
|
90
90
|
|
91
|
-
public AsyncHttpRequest(Activity activity) {
|
91
|
+
public AsyncHttpRequest(Activity activity) {
|
92
|
+
|
92
|
-
|
93
|
+
mActivity = activity;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
@Override
|
100
|
+
|
101
|
+
protected void onPreExecute() {
|
102
|
+
|
103
|
+
super.onPreExecute();
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
@Override
|
110
|
+
|
111
|
+
protected void onPreExecute() {
|
112
|
+
|
113
|
+
super.onPreExecute();
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
@Override
|
120
|
+
|
121
|
+
protected String doInBackground(String... params) {
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
HttpURLConnection connection = null;
|
126
|
+
|
127
|
+
StringBuilder sb = new StringBuilder();
|
128
|
+
|
129
|
+
try {
|
130
|
+
|
131
|
+
URL url = new URL(params[0]);
|
132
|
+
|
133
|
+
connection = (HttpURLConnection) url.openConnection();
|
134
|
+
|
135
|
+
InputStream is = connection.getInputStream();
|
136
|
+
|
137
|
+
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
138
|
+
|
139
|
+
String line = "";
|
140
|
+
|
141
|
+
while ((line = reader.readLine()) != null)
|
142
|
+
|
143
|
+
sb.append(line);
|
144
|
+
|
145
|
+
is.close();
|
146
|
+
|
147
|
+
} catch (IOException e) {
|
148
|
+
|
149
|
+
e.printStackTrace();
|
150
|
+
|
151
|
+
} finally {
|
152
|
+
|
153
|
+
connection.disconnect();
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
if (sb.toString() == "NO") {
|
158
|
+
|
159
|
+
return null;
|
160
|
+
|
161
|
+
} else {
|
162
|
+
|
163
|
+
return (sb.toString());
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
public void onPostExecute(String string) {
|
172
|
+
|
173
|
+
if (string == null) {
|
174
|
+
|
175
|
+
((TextView)mActivity.findViewById(R.id.textView9)).setText("通信に失敗しました。再度接続をお試しください。");
|
176
|
+
|
177
|
+
} else {
|
178
|
+
|
179
|
+
try {
|
180
|
+
|
181
|
+
int i = Integer.parseInt(string);
|
182
|
+
|
93
|
-
((TextView)
|
183
|
+
((TextView)mActivity.findViewById(R.id.textView5)).setText(String.valueOf(i));
|
184
|
+
|
185
|
+
} catch (NumberFormatException e) {
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
94
196
|
|
95
197
|
```
|
96
198
|
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,71 @@
|
|
16
16
|
|
17
17
|
```DiarogFragment
|
18
18
|
|
19
|
+
@Override
|
20
|
+
|
21
|
+
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
22
|
+
|
23
|
+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
24
|
+
|
25
|
+
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
26
|
+
|
27
|
+
View view = inflater.inflate (R.layout.custom_layout, null);
|
28
|
+
|
29
|
+
textView = (TextView)view.findViewById(R.id.textView5);
|
30
|
+
|
31
|
+
textView2 = (TextView)view.findViewById(R.id.textView6);
|
32
|
+
|
33
|
+
button = (Button)view.findViewById(R.id.button2);
|
34
|
+
|
35
|
+
button.setOnClickListener(new View.OnClickListener() {
|
36
|
+
|
37
|
+
@Override
|
38
|
+
|
39
|
+
public void onClick(View view) {
|
40
|
+
|
41
|
+
PW = rand.nextInt(100000);
|
42
|
+
|
43
|
+
if (new AsyncHttpRequest(getActivity())
|
44
|
+
|
19
|
-
|
45
|
+
.execute("https://xxxxxxxxxxxxxx.jp" + PW) != null) {
|
46
|
+
|
47
|
+
textView2.setText(String.valueOf(PW));
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
});
|
54
|
+
|
55
|
+
builder.setView(view)
|
56
|
+
|
57
|
+
.setTitle("Pairring")
|
58
|
+
|
59
|
+
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
60
|
+
|
61
|
+
public void onClick(DialogInterface dialog, int id) {
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
})
|
68
|
+
|
69
|
+
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
70
|
+
|
71
|
+
public void onClick(DialogInterface dialog, int id) {
|
72
|
+
|
73
|
+
// User cancelled the dialog
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
});
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
return builder.create();
|
82
|
+
|
83
|
+
}
|
20
84
|
|
21
85
|
```
|
22
86
|
|