监听列表 显式逻辑
This commit is contained in:
@@ -102,12 +102,7 @@ public class NotificationActivity extends MiracleGardenActivity<ActivityNotifica
|
|||||||
startActivity(intent_s);
|
startActivity(intent_s);
|
||||||
});
|
});
|
||||||
binding.button.setOnClickListener(v -> {
|
binding.button.setOnClickListener(v -> {
|
||||||
AppInfo appInfo = AppListUtil.getAppByPackageName(NotificationActivity.this,"com.miraclegarden.smsmessage");
|
|
||||||
appInfo.setCode("111");
|
|
||||||
appInfo.setName("测试");
|
|
||||||
appInfo.setRemark("测试备注");
|
|
||||||
MessageInfo messageInfo = MessageInfo.AppInfoToMessageInfo(appInfo);
|
|
||||||
Submit(messageInfo,"我是标题","我是正文");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
binding.button1.setOnClickListener(view -> {
|
binding.button1.setOnClickListener(view -> {
|
||||||
@@ -121,6 +116,14 @@ public class NotificationActivity extends MiracleGardenActivity<ActivityNotifica
|
|||||||
startActivity(new Intent(NotificationActivity.this,SettingActivity.class));
|
startActivity(new Intent(NotificationActivity.this,SettingActivity.class));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
binding.jiantingList.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Intent intent = new Intent(NotificationActivity.this,SettingActivity.class);
|
||||||
|
intent.putExtra("is_list",true);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPermission() {
|
private void initPermission() {
|
||||||
@@ -160,48 +163,4 @@ public class NotificationActivity extends MiracleGardenActivity<ActivityNotifica
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
||||||
|
|
||||||
public void Submit(MessageInfo messageInfo, String title, String context) {
|
|
||||||
OkHttpClient client = new OkHttpClient();
|
|
||||||
SharedPreferences sharedPreferences = getSharedPreferences("server", MODE_PRIVATE);
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
jsonObject.put("name", messageInfo.getName());
|
|
||||||
jsonObject.put("code", messageInfo.getCode());
|
|
||||||
jsonObject.put("remark", messageInfo.getRemark());
|
|
||||||
jsonObject.put("appName", messageInfo.getAppName());
|
|
||||||
jsonObject.put("packageName", messageInfo.getPackageName());
|
|
||||||
JSONObject jsonObject1 = new JSONObject();
|
|
||||||
jsonObject1.put("title", title);
|
|
||||||
jsonObject1.put("context", context);
|
|
||||||
jsonObject.put("data", jsonObject1);
|
|
||||||
String json = jsonObject.toString();
|
|
||||||
RequestBody body = RequestBody.create(json, JSON);
|
|
||||||
// 构建请求
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(sharedPreferences.getString("host", ""))
|
|
||||||
.post(body)
|
|
||||||
.build();
|
|
||||||
client.newCall(request).enqueue(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
||||||
NotificationActivity.sendMessage("提交失败:" + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
String str = response.body().string();
|
|
||||||
NotificationActivity.sendMessage(title + "提交成功:" + str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NotificationActivity.sendMessage("提交失败:");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (JSONException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
package com.miraclegarden.smsmessage.Activity;
|
package com.miraclegarden.smsmessage.Activity;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PermissionInfo;
|
import android.content.pm.PermissionInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ScrollView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -32,20 +37,43 @@ import com.miraclegarden.smsmessage.comm.ViewHolder;
|
|||||||
import com.miraclegarden.smsmessage.databinding.ActivityMainBinding;
|
import com.miraclegarden.smsmessage.databinding.ActivityMainBinding;
|
||||||
import com.miraclegarden.smsmessage.databinding.ActivitySettingBinding;
|
import com.miraclegarden.smsmessage.databinding.ActivitySettingBinding;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class SettingActivity extends MiracleGardenActivity<ActivitySettingBinding> {
|
public class SettingActivity extends MiracleGardenActivity<ActivitySettingBinding> {
|
||||||
public static SharedPreferences sp;
|
public static SharedPreferences sp;
|
||||||
private static final String TAG = "SettingActivity";
|
private static final String TAG = "SettingActivity";
|
||||||
private ArrayList<MessageInfo> appList = new ArrayList<>();
|
private ArrayList<MessageInfo> appList = new ArrayList<>();
|
||||||
CommonAdapter userAdapter;
|
CommonAdapter userAdapter;
|
||||||
|
boolean is_list = false;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
sp = getSharedPreferences("server", MODE_PRIVATE);
|
sp = getSharedPreferences("server", MODE_PRIVATE);
|
||||||
initData();
|
initData();
|
||||||
initList();
|
initList();
|
||||||
|
|
||||||
|
is_list = getIntent().getBooleanExtra("is_list",false);
|
||||||
|
if(!is_list){
|
||||||
|
binding.setPostLy.setVisibility(View.VISIBLE);
|
||||||
|
binding.titleTv.setText("设置");
|
||||||
|
}else{
|
||||||
|
binding.titleTv.setText("监听App列表");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,16 +117,106 @@ public class SettingActivity extends MiracleGardenActivity<ActivitySettingBindin
|
|||||||
Toast.makeText(this, "服务器地址错误", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "服务器地址错误", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedPreferences.Editor edit = sp.edit();
|
hideKeyboard();
|
||||||
edit.putString("host", binding.host.getText().toString());
|
AppInfo appInfo = AppListUtil.getAppByPackageName(SettingActivity.this,"com.miraclegarden.smsmessage");
|
||||||
edit.apply();
|
appInfo.setCode("111");
|
||||||
Toast.makeText(this, "服务器地址修改成功", Toast.LENGTH_SHORT).show();
|
appInfo.setName("测试");
|
||||||
|
appInfo.setRemark("测试更换接口");
|
||||||
|
MessageInfo messageInfo = MessageInfo.AppInfoToMessageInfo(appInfo);
|
||||||
|
Submit(messageInfo,"测试更换接口","测试更换接口");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||||
|
|
||||||
|
public void Submit(MessageInfo messageInfo, String title, String context) {
|
||||||
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("name", messageInfo.getName());
|
||||||
|
jsonObject.put("code", messageInfo.getCode());
|
||||||
|
jsonObject.put("remark", messageInfo.getRemark());
|
||||||
|
jsonObject.put("appName", messageInfo.getAppName());
|
||||||
|
jsonObject.put("packageName", messageInfo.getPackageName());
|
||||||
|
JSONObject jsonObject1 = new JSONObject();
|
||||||
|
jsonObject1.put("title", title);
|
||||||
|
jsonObject1.put("context", context);
|
||||||
|
jsonObject.put("data", jsonObject1);
|
||||||
|
String json = jsonObject.toString();
|
||||||
|
RequestBody body = RequestBody.create(json, JSON);
|
||||||
|
// 构建请求
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(binding.host.getText().toString())
|
||||||
|
.post(body)
|
||||||
|
.build();
|
||||||
|
Log.i("地址是啥","地址是啥1111:"+binding.host.getText().toString());
|
||||||
|
Log.i("地址是啥","地址是啥2222:"+json);
|
||||||
|
|
||||||
|
client.newCall(request).enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||||
|
// NotificationActivity.sendMessage("提交失败:" + e);
|
||||||
|
// Toast.makeText(SettingActivity.this,"接口地址访问异常",Toast.LENGTH_SHORT).show();
|
||||||
|
sendMessage("接口地址访问异常");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||||
|
String str = response.body().string();
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
Log.i("地址是啥","地址是啥:"+str);
|
||||||
|
// {"ok":true,"received":true}
|
||||||
|
toSaveAddress();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.i("地址是啥","地址是啥11:"+str);
|
||||||
|
sendMessage("接口地址访问异常");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (JSONException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void hideKeyboard() {
|
||||||
|
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||||
|
if (imm != null && binding.host.getWindowToken() != null) {
|
||||||
|
imm.hideSoftInputFromWindow(binding.host.getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Handler handler = new Handler(Looper.myLooper()) {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(@NonNull Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
String str = (String) msg.obj;
|
||||||
|
if (str != null) {
|
||||||
|
Toast.makeText(SettingActivity.this,str,Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public void sendMessage(String str) {
|
||||||
|
Message message = new Message();
|
||||||
|
message.obj = str;
|
||||||
|
handler.sendMessage(message);
|
||||||
|
}
|
||||||
|
private void toSaveAddress() {
|
||||||
|
|
||||||
|
SharedPreferences.Editor edit = sp.edit();
|
||||||
|
edit.putString("host", binding.host.getText().toString());
|
||||||
|
edit.apply();
|
||||||
|
sendMessage( "服务器地址修改成功:" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initList() {
|
private void initList() {
|
||||||
binding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
|
binding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
|
||||||
userAdapter = new CommonAdapter<>(SettingActivity.this, R.layout.item_user, appList) {
|
userAdapter = new CommonAdapter<>(SettingActivity.this, R.layout.item_user, appList) {
|
||||||
|
|||||||
11
app/src/main/res/drawable-anydpi/ic_action_next.xml
Normal file
11
app/src/main/res/drawable-anydpi/ic_action_next.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#FFFFFF"
|
||||||
|
android:alpha="0.8">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
|
||||||
|
</vector>
|
||||||
BIN
app/src/main/res/drawable-hdpi/ic_action_next.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_next.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 240 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_next.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_next.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 161 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_next.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_next.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 191 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_next.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_next.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 369 B |
@@ -24,6 +24,20 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="5dp">
|
android:padding="5dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:text="监听App列表"
|
||||||
|
android:paddingStart="5dp"
|
||||||
|
android:drawableTint="@color/black"
|
||||||
|
android:drawableEnd="@drawable/ic_action_next"
|
||||||
|
android:id="@+id/jianting_list"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1px"
|
||||||
|
android:background="#DDDDDD" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -35,8 +49,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:textColor="@color/white"
|
|
||||||
android:text="开启监听"
|
android:text="开启监听"
|
||||||
|
android:textColor="@color/white"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -45,9 +59,11 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:visibility="gone"
|
||||||
android:text="测试接口"
|
android:text="测试接口"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button1"
|
android:id="@+id/button1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="设置"
|
android:text="设置"
|
||||||
|
android:id="@+id/title_tv"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textColor="@color/white"/>
|
android:textColor="@color/white"/>
|
||||||
</androidx.appcompat.widget.Toolbar>
|
</androidx.appcompat.widget.Toolbar>
|
||||||
@@ -38,7 +39,12 @@
|
|||||||
android:layout_below="@id/top_ab"
|
android:layout_below="@id/top_ab"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="10dp">
|
android:padding="10dp">
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/set_post_ly"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:orientation="vertical">
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -58,6 +64,8 @@
|
|||||||
android:text="保存"
|
android:text="保存"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user