version:3.2
fix: update:增加拨号,添加联系人,通话记录
This commit is contained in:
@@ -21,7 +21,7 @@ import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.disklrucache.CacheHelper;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
import com.uiuios.aios.receiver.BootReceiver;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class EmergencyActivity extends AppCompatActivity {
|
||||
// return;
|
||||
// }
|
||||
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_MAIL_LIST);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_MAIL_LIST);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
package com.uiuios.aios.activity.contact;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.luck.picture.lib.basic.PictureSelector;
|
||||
import com.luck.picture.lib.config.SelectMimeType;
|
||||
import com.luck.picture.lib.entity.LocalMedia;
|
||||
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.base.BaseLightActivity;
|
||||
import com.uiuios.aios.base.GlideEngine;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.GlideLoadUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.uiuios.aios.view.ToggleButton;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class AddContactActivity extends BaseLightActivity {
|
||||
private static final String TAG = AddContactActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.iv_cancel)
|
||||
ImageView iv_cancel;
|
||||
@BindView(R.id.iv_confirm)
|
||||
ImageView iv_confirm;
|
||||
@BindView(R.id.nv_avatar)
|
||||
NiceImageView nv_avatar;
|
||||
@BindView(R.id.et_name)
|
||||
EditText et_name;
|
||||
@BindView(R.id.et_phone)
|
||||
EditText et_phone;
|
||||
@BindView(R.id.toggleButton)
|
||||
ToggleButton toggleButton;
|
||||
|
||||
|
||||
private String avatarFilePath;
|
||||
private boolean urgent = false;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_add_contact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
nv_avatar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
selectPicture();
|
||||
}
|
||||
});
|
||||
iv_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
iv_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkContact();
|
||||
}
|
||||
});
|
||||
iv_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
checkContact();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void selectPicture() {
|
||||
PictureSelector.create(this)
|
||||
.openGallery(SelectMimeType.ofImage())
|
||||
.setSelectionMode(1)
|
||||
.setImageEngine(GlideEngine.createGlideEngine())
|
||||
.forResult(new OnResultCallbackListener<LocalMedia>() {
|
||||
@Override
|
||||
public void onResult(ArrayList<LocalMedia> result) {
|
||||
avatarFilePath = result.get(0).getPath();
|
||||
Log.e("selectPicture", "onResult: " + avatarFilePath);
|
||||
GlideLoadUtils.getInstance().glideLoad(AddContactActivity.this, avatarFilePath, nv_avatar, R.drawable.default_avatar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void checkContact() {
|
||||
String name = et_name.getText().toString();
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
ToastUtil.show("请输入联系人姓名");
|
||||
return;
|
||||
}
|
||||
String phone = et_phone.getText().toString();
|
||||
if (TextUtils.isEmpty(phone)) {
|
||||
ToastUtil.show("请输入手机号码");
|
||||
return;
|
||||
}
|
||||
File avatarFile;
|
||||
Log.e("checkContact", "avatarFilePath: " + avatarFilePath);
|
||||
if (TextUtils.isEmpty(avatarFilePath)) {
|
||||
avatarFile = drawableToFile(R.drawable.default_avatar, "avatar");
|
||||
} else {
|
||||
Uri uri = Uri.parse(avatarFilePath);
|
||||
avatarFile = uriToFile(uri, AddContactActivity.this);
|
||||
}
|
||||
MediaType mediaType = MediaType.Companion.parse("image/png");
|
||||
RequestBody requestBody = RequestBody.Companion.create(avatarFile, mediaType);
|
||||
MultipartBody.Part body = MultipartBody.Part.createFormData("avatar", avatarFile.getName(), requestBody);
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", Utils.getSerial());
|
||||
params.put("name", name);
|
||||
params.put("mobile", phone);
|
||||
params.put("is_urgent", String.valueOf(toggleButton.isToggleOn()));
|
||||
NetInterfaceManager.getInstance()
|
||||
.getMailListAddObservable(params, body)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkContact", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("checkContact", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
ToastUtil.show("已添加");
|
||||
finish();
|
||||
} else {
|
||||
ToastUtil.show(baseResponse.msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkContact", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkContact", "onComplete: ");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* drawable转为file
|
||||
*
|
||||
* @param drawableId drawable的ID
|
||||
* @param fileName 转换后的文件名
|
||||
* @return
|
||||
*/
|
||||
public File drawableToFile(int drawableId, String fileName) {
|
||||
// InputStream is = view.getContext().getResources().openRawResource(R.drawable.logo);
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), drawableId);
|
||||
// Bitmap bitmap = BitmapFactory.decodeStream(is);
|
||||
String defaultPath = getFilesDir().getAbsolutePath() + "/defaultGoodInfo";
|
||||
File file = new File(defaultPath);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
String defaultImgPath = defaultPath + "/" + fileName;
|
||||
file = new File(defaultImgPath);
|
||||
try {
|
||||
file.createNewFile();
|
||||
FileOutputStream fOut = new FileOutputStream(file);
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 20, fOut);
|
||||
// is.close();
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
public static File uriToFile(Uri uri, Context context) {
|
||||
String path = null;
|
||||
if ("file".equals(uri.getScheme())) {
|
||||
path = uri.getEncodedPath();
|
||||
if (path != null) {
|
||||
path = Uri.decode(path);
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("(").append(MediaStore.Images.ImageColumns.DATA).append("=").append("'" + path + "'").append(")");
|
||||
Cursor cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA}, buff.toString(), null, null);
|
||||
int index = 0;
|
||||
int dataIdx = 0;
|
||||
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||
index = cur.getColumnIndex(MediaStore.Images.ImageColumns._ID);
|
||||
index = cur.getInt(index);
|
||||
dataIdx = cur.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
|
||||
path = cur.getString(dataIdx);
|
||||
}
|
||||
cur.close();
|
||||
if (index == 0) {
|
||||
} else {
|
||||
Uri u = Uri.parse("content://media/external/images/media/" + index);
|
||||
System.out.println("temp uri is :" + u);
|
||||
}
|
||||
}
|
||||
if (path != null) {
|
||||
return new File(path);
|
||||
}
|
||||
} else if ("content".equals(uri.getScheme())) {
|
||||
// 4.2.2以后
|
||||
String[] proj = {MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||
path = cursor.getString(columnIndex);
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
return new File(path);
|
||||
} else {
|
||||
//Log.i(TAG, "Uri Scheme:" + uri.getScheme());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.uiuios.aios.activity.contact;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -26,6 +27,8 @@ public class ContactActivity extends BaseActivity implements ContactContact.Cont
|
||||
TextView tv_people;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.tv_add)
|
||||
TextView tv_add;
|
||||
|
||||
@OnClick({R.id.iv_back})
|
||||
public void onClick(View view) {
|
||||
@@ -58,10 +61,23 @@ public class ContactActivity extends BaseActivity implements ContactContact.Cont
|
||||
rv_contact.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
}
|
||||
rv_contact.setAdapter(mContactAdapter);
|
||||
tv_add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(ContactActivity.this, AddContactActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mContactPresenter.getContact();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
import com.uiuios.aios.utils.GsonUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@@ -68,10 +68,10 @@ public class ContactPresenter implements ContactContact.Presenter {
|
||||
public void onNext(@NonNull BaseResponse<List<Contact>> listBaseResponse) {
|
||||
Log.e("getContactList", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
mMMKV.putString(URLAddress.GET_MAIL_LIST, GsonUtils.toJsonString(listBaseResponse.data));
|
||||
mMMKV.putString(UrlAddress.GET_MAIL_LIST, GsonUtils.toJsonString(listBaseResponse.data));
|
||||
mView.setContact(listBaseResponse.data);
|
||||
} else {
|
||||
mMMKV.putString(URLAddress.GET_MAIL_LIST, "");
|
||||
mMMKV.putString(UrlAddress.GET_MAIL_LIST, "");
|
||||
mView.setContact(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class ContactPresenter implements ContactContact.Presenter {
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getContactList", "onError: " + e.getMessage());
|
||||
String jsonString = mMMKV.getString(URLAddress.GET_MAIL_LIST, null);
|
||||
String jsonString = mMMKV.getString(UrlAddress.GET_MAIL_LIST, null);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<Contact>>() {
|
||||
}.getType();
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
package com.uiuios.aios.activity.dialer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.SoundPool;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.contact.ContactActivity;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class DialerActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.et_phone)
|
||||
EditText et_phone;
|
||||
@BindView(R.id.iv_delete)
|
||||
ImageView iv_delete;
|
||||
@BindView(R.id.nv_dialer)
|
||||
NiceImageView nv_dialer;
|
||||
@BindView(R.id.iv_contact)
|
||||
ImageView iv_contact;
|
||||
@BindView(R.id.tv_contact)
|
||||
TextView tv_contact;
|
||||
@BindView(R.id.cl_0)
|
||||
ConstraintLayout cl_0;
|
||||
@BindView(R.id.cl_1)
|
||||
ConstraintLayout cl_1;
|
||||
@BindView(R.id.cl_2)
|
||||
ConstraintLayout cl_2;
|
||||
@BindView(R.id.cl_3)
|
||||
ConstraintLayout cl_3;
|
||||
@BindView(R.id.cl_4)
|
||||
ConstraintLayout cl_4;
|
||||
@BindView(R.id.cl_5)
|
||||
ConstraintLayout cl_5;
|
||||
@BindView(R.id.cl_6)
|
||||
ConstraintLayout cl_6;
|
||||
@BindView(R.id.cl_7)
|
||||
ConstraintLayout cl_7;
|
||||
@BindView(R.id.cl_8)
|
||||
ConstraintLayout cl_8;
|
||||
@BindView(R.id.cl_9)
|
||||
ConstraintLayout cl_9;
|
||||
@BindView(R.id.cl_11)
|
||||
ConstraintLayout cl_11;
|
||||
@BindView(R.id.cl_12)
|
||||
ConstraintLayout cl_12;
|
||||
|
||||
private SoundPool soundPool;
|
||||
private HashMap<Integer, Integer> soundMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_dialer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
ButterKnife.bind(this);
|
||||
AudioAttributes attr = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME) // 设置音效使用场景
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build(); // 设置音效的类型
|
||||
soundPool = new SoundPool.Builder().setAudioAttributes(attr) // 设置音效池的属性
|
||||
.setMaxStreams(12) // 设置最多可容纳10个音频流
|
||||
.build(); // ①
|
||||
// load方法加载指定音频文件,并返回所加载的音效ID
|
||||
// 此处使用HashMap来管理这些音频流
|
||||
soundMap.put(0, soundPool.load(this, R.raw.s_0, 1));
|
||||
soundMap.put(1, soundPool.load(this, R.raw.s_1, 1));
|
||||
soundMap.put(2, soundPool.load(this, R.raw.s_2, 1));
|
||||
soundMap.put(3, soundPool.load(this, R.raw.s_3, 1));
|
||||
soundMap.put(4, soundPool.load(this, R.raw.s_4, 1));
|
||||
soundMap.put(5, soundPool.load(this, R.raw.s_5, 1));
|
||||
soundMap.put(6, soundPool.load(this, R.raw.s_6, 1));
|
||||
soundMap.put(7, soundPool.load(this, R.raw.s_7, 1));
|
||||
soundMap.put(8, soundPool.load(this, R.raw.s_8, 1));
|
||||
soundMap.put(9, soundPool.load(this, R.raw.s_9, 1));
|
||||
soundMap.put(10, soundPool.load(this, R.raw.s_x, 1));
|
||||
soundMap.put(11, soundPool.load(this, R.raw.s_j, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
cl_0.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("0", 0);
|
||||
}
|
||||
});
|
||||
cl_1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("1", 1);
|
||||
}
|
||||
});
|
||||
cl_2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("2", 2);
|
||||
}
|
||||
});
|
||||
cl_3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("3", 3);
|
||||
}
|
||||
});
|
||||
cl_4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("4", 4);
|
||||
}
|
||||
});
|
||||
cl_5.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("5", 5);
|
||||
}
|
||||
});
|
||||
cl_6.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("6", 6);
|
||||
}
|
||||
});
|
||||
cl_7.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("7", 7);
|
||||
}
|
||||
});
|
||||
cl_8.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("8", 8);
|
||||
}
|
||||
});
|
||||
cl_9.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("9", 9);
|
||||
}
|
||||
});
|
||||
cl_11.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("*", 10);
|
||||
}
|
||||
});
|
||||
cl_12.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addNumber("#", 11);
|
||||
}
|
||||
});
|
||||
nv_dialer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String phone = et_phone.getText().toString();
|
||||
Intent dialIntent = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + phone);
|
||||
dialIntent.setData(data);
|
||||
startActivity(dialIntent);
|
||||
}
|
||||
});
|
||||
iv_delete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String tmp = et_phone.getText().toString();
|
||||
if (TextUtils.isEmpty(tmp)) {
|
||||
et_phone.setText("");
|
||||
} else {
|
||||
et_phone.setText(tmp.substring(0, tmp.length() - 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
iv_contact.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(DialerActivity.this, ContactActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
tv_contact.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(DialerActivity.this, ContactActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void addNumber(String number, int position) {
|
||||
String tmp = et_phone.getText().toString();
|
||||
if (TextUtils.isEmpty(tmp)) {
|
||||
et_phone.setText(number);
|
||||
} else {
|
||||
et_phone.setText(tmp + number);
|
||||
}
|
||||
soundPool.play(soundMap.get(position), 1, 1, 0, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package com.uiuios.aios.activity.records;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.CallLog;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.dialer.DialerActivity;
|
||||
import com.uiuios.aios.adapter.CallRecordAdapter;
|
||||
import com.uiuios.aios.bean.RecordsInfo;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class RecordsActivity extends AppCompatActivity {
|
||||
private static final String TAG = RecordsActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.iv_cancel)
|
||||
ImageView iv_cancel;
|
||||
@BindView(R.id.iv_clear)
|
||||
ImageView iv_clear;
|
||||
@BindView(R.id.nv_dialer)
|
||||
NiceImageView nv_dialer;
|
||||
@BindView(R.id.tv_nodata)
|
||||
TextView tv_nodata;
|
||||
|
||||
private CallRecordAdapter mCallRecordAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_records);
|
||||
UltimateBarX.statusBarOnly(this)
|
||||
.colorRes(R.color.default_blue)
|
||||
.fitWindow(true)
|
||||
.apply();
|
||||
ButterKnife.bind(this);
|
||||
Log.e(TAG, "initData: " + dataList);
|
||||
mCallRecordAdapter = new CallRecordAdapter();
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(RecordsActivity.this);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
recyclerView.setAdapter(mCallRecordAdapter);
|
||||
|
||||
iv_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
nv_dialer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(RecordsActivity.this, DialerActivity.class));
|
||||
}
|
||||
});
|
||||
iv_clear.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
for (RecordsInfo recordsInfo : dataList) {
|
||||
String queryString = "NUMBER=" + recordsInfo.getNumber();
|
||||
getContentResolver().delete(CallLog.Calls.CONTENT_URI, queryString, null);
|
||||
}
|
||||
getData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
getData();
|
||||
}
|
||||
|
||||
private void getData() {
|
||||
dataList = getDataList();
|
||||
if (dataList.size() == 0) {
|
||||
tv_nodata.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
} else {
|
||||
tv_nodata.setVisibility(View.GONE);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mCallRecordAdapter.setRecordsInfoList(dataList);
|
||||
}
|
||||
|
||||
private List<RecordsInfo> dataList;
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
*
|
||||
* @return 读取到的数据
|
||||
*/
|
||||
private List<RecordsInfo> getDataList() {
|
||||
// 1.获得ContentResolver
|
||||
ContentResolver resolver = getContentResolver();
|
||||
// 2.利用ContentResolver的query方法查询通话记录数据库
|
||||
/**
|
||||
* @param uri 需要查询的URI,(这个URI是ContentProvider提供的)
|
||||
* @param projection 需要查询的字段
|
||||
* @param selection sql语句where之后的语句
|
||||
* @param selectionArgs ?占位符代表的数据
|
||||
* @param sortOrder 排序方式
|
||||
*
|
||||
*/
|
||||
Cursor cursor = resolver.query(CallLog.Calls.CONTENT_URI, // 查询通话记录的URI
|
||||
new String[]{CallLog.Calls.CACHED_NAME// 通话记录的联系人
|
||||
, CallLog.Calls.NUMBER// 通话记录的电话号码
|
||||
, CallLog.Calls.DATE// 通话记录的日期
|
||||
, CallLog.Calls.DURATION// 通话时长
|
||||
, CallLog.Calls.TYPE}// 通话类型
|
||||
, null, null, CallLog.Calls.DEFAULT_SORT_ORDER// 按照时间逆序排列,最近打的最先显示
|
||||
);
|
||||
// 3.通过Cursor获得数据
|
||||
List<RecordsInfo> list = new ArrayList<>();
|
||||
while (cursor.moveToNext()) {
|
||||
String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
|
||||
String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
|
||||
long dateLong = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
|
||||
// String date = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date(dateLong));
|
||||
int duration = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION));
|
||||
int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
|
||||
|
||||
RecordsInfo recordsInfo = new RecordsInfo();
|
||||
recordsInfo.setName(name);
|
||||
recordsInfo.setNumber(number);
|
||||
recordsInfo.setDate(dateLong);
|
||||
recordsInfo.setDuration(duration);
|
||||
recordsInfo.setType(type);
|
||||
list.add(recordsInfo);
|
||||
|
||||
String typeString = "";
|
||||
switch (type) {
|
||||
case CallLog.Calls.INCOMING_TYPE:
|
||||
typeString = "打入";
|
||||
break;
|
||||
case CallLog.Calls.OUTGOING_TYPE:
|
||||
typeString = "打出";
|
||||
break;
|
||||
case CallLog.Calls.MISSED_TYPE:
|
||||
typeString = "未接";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.uiuios.aios.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.RecordsInfo;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class CallRecordAdapter extends RecyclerView.Adapter<CallRecordAdapter.Holder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<RecordsInfo> mRecordsInfoList;
|
||||
private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("HH:mm");
|
||||
|
||||
public void setRecordsInfoList(List<RecordsInfo> recordsInfoList) {
|
||||
this.mRecordsInfoList = recordsInfoList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_call_record, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
||||
RecordsInfo recordsInfo = mRecordsInfoList.get(position);
|
||||
String phone = recordsInfo.getNumber();
|
||||
holder.tv_phone.setText(phone);
|
||||
holder.tv_time.setText(mSimpleDateFormat.format(new Date(recordsInfo.getDate())));
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent dialIntent = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + phone);
|
||||
dialIntent.setData(data);
|
||||
mContext.startActivity(dialIntent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mRecordsInfoList == null ? 0 : mRecordsInfoList.size();
|
||||
}
|
||||
|
||||
class Holder extends RecyclerView.ViewHolder {
|
||||
ConstraintLayout root;
|
||||
ImageView iv_avatar;
|
||||
TextView tv_phone;
|
||||
TextView tv_time;
|
||||
|
||||
public Holder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
iv_avatar = itemView.findViewById(R.id.iv_avatar);
|
||||
tv_phone = itemView.findViewById(R.id.tv_phone);
|
||||
tv_time = itemView.findViewById(R.id.tv_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.uiuios.aios.adapter;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -17,6 +16,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.contact.AddContactActivity;
|
||||
import com.uiuios.aios.activity.records.RecordsActivity;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
@@ -27,6 +28,7 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactH
|
||||
private Context mContext;
|
||||
|
||||
public static final String DIALER_PACKAGE = "com.android.dialer";
|
||||
public static final String DIALER_ADD_CONTACT = "com.uiui.aios.contact.add";
|
||||
|
||||
public void setContactList(List<Contact> contactList) {
|
||||
this.mContactList = contactList;
|
||||
@@ -46,45 +48,59 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactH
|
||||
contactHolder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// int aole_call_forbid = Settings.System.getInt(mContext.getContentResolver(), "aole_call_forbid", 0);
|
||||
// if (aole_call_forbid == 1) {
|
||||
// int qch_call_forbid = Settings.System.getInt(mContext.getContentResolver(), "qch_call_forbid", 0);
|
||||
// if (qch_call_forbid == 1) {
|
||||
// ToastUtil.show("电话功能被禁用");
|
||||
// return;
|
||||
// icon_return;
|
||||
// }
|
||||
Intent intent1 = new Intent(Intent.ACTION_CALL);
|
||||
Intent dialIntent = new Intent(Intent.ACTION_CALL);
|
||||
String phone = contact.getMobile();
|
||||
if (DIALER_PACKAGE.equals(phone)) {
|
||||
mContext.startActivity(new Intent(Intent.ACTION_DIAL));
|
||||
try {
|
||||
// mContext.startActivity(new Intent(Intent.ACTION_DIAL));
|
||||
// mContext.startActivity(new Intent(mContext, DialerActivity.class));
|
||||
mContext.startActivity(new Intent(mContext, RecordsActivity.class));
|
||||
} catch (Exception e) {
|
||||
ToastUtil.show("无法打开电话功能");
|
||||
}
|
||||
} else if (DIALER_ADD_CONTACT.equals(contact.getMobile())) {
|
||||
Intent intent = new Intent(mContext, AddContactActivity.class);
|
||||
mContext.startActivity(intent);
|
||||
} else if (!TextUtils.isEmpty(phone)) {
|
||||
Uri data = Uri.parse("tel:" + phone);
|
||||
intent1.setData(data);
|
||||
mContext.startActivity(intent1);
|
||||
dialIntent.setData(data);
|
||||
mContext.startActivity(dialIntent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
contactHolder.tv_name.setText(contact.getName());
|
||||
if (DIALER_PACKAGE.equals(contact.getMobile())) {
|
||||
contactHolder.cl_contact.setVisibility(View.GONE);
|
||||
contactHolder.iv_head2.setVisibility(View.VISIBLE);
|
||||
contactHolder.tv_phone.setText("");
|
||||
Glide.with(contactHolder.iv_head).load(R.drawable.icon_dialer).error(R.drawable.icon_dialer).into(contactHolder.iv_head);
|
||||
Glide.with(contactHolder.iv_head).load(R.drawable.home_dialer_cion_circle).error(R.drawable.home_dialer_cion_circle).into(contactHolder.iv_head);
|
||||
} else if (DIALER_ADD_CONTACT.equals(contact.getMobile())) {
|
||||
Glide.with(contactHolder.iv_head).load(R.drawable.icon_contact_add).error(R.drawable.icon_contact_add).into(contactHolder.iv_head);
|
||||
} else {
|
||||
contactHolder.cl_contact.setVisibility(View.VISIBLE);
|
||||
contactHolder.iv_head2.setVisibility(View.GONE);
|
||||
contactHolder.tv_phone.setText(contact.getMobile());
|
||||
Glide.with(contactHolder.iv_head).load(contact.getAvatar()).error(R.drawable.default_head).into(contactHolder.iv_head);
|
||||
}
|
||||
int index = position % 3;
|
||||
switch (index) {
|
||||
case 0:
|
||||
contactHolder.root.setBackground(mContext.getDrawable(R.drawable.contact_bg1));
|
||||
break;
|
||||
case 1:
|
||||
contactHolder.root.setBackground(mContext.getDrawable(R.drawable.contact_bg2));
|
||||
break;
|
||||
case 2:
|
||||
contactHolder.root.setBackground(mContext.getDrawable(R.drawable.contact_bg3));
|
||||
break;
|
||||
default:
|
||||
contactHolder.root.setBackground(mContext.getDrawable(R.drawable.contact_bg1));
|
||||
Glide.with(contactHolder.iv_head).load(contact.getAvatar()).error(R.drawable.default_avatar).into(contactHolder.iv_head);
|
||||
}
|
||||
// int index = position % 3;
|
||||
// switch (index) {
|
||||
// case 0:
|
||||
// contactHolder.root.setBackground(mContext.getDrawable(R.drawable.background_weather_rain));
|
||||
// break;
|
||||
// case 1:
|
||||
// contactHolder.root.setBackground(mContext.getDrawable(R.drawable.background_weather_sun));
|
||||
// break;
|
||||
// case 2:
|
||||
// contactHolder.root.setBackground(mContext.getDrawable(R.drawable.background_weather_sunny));
|
||||
// break;
|
||||
// default:
|
||||
// contactHolder.root.setBackground(mContext.getDrawable(R.drawable.background_weather_rain));
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,14 +110,18 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactH
|
||||
|
||||
static class ContactHolder extends RecyclerView.ViewHolder {
|
||||
ConstraintLayout root;
|
||||
ConstraintLayout cl_contact;
|
||||
NiceImageView iv_head;
|
||||
NiceImageView iv_head2;
|
||||
TextView tv_name;
|
||||
TextView tv_phone;
|
||||
|
||||
public ContactHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
cl_contact = itemView.findViewById(R.id.cl_contact);
|
||||
iv_head = itemView.findViewById(R.id.iv_head);
|
||||
iv_head2 = itemView.findViewById(R.id.iv_head2);
|
||||
tv_name = itemView.findViewById(R.id.tv_name);
|
||||
tv_phone = itemView.findViewById(R.id.tv_phone);
|
||||
}
|
||||
|
||||
129
app/src/main/java/com/uiuios/aios/base/BaseLightActivity.java
Normal file
129
app/src/main/java/com/uiuios/aios/base/BaseLightActivity.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package com.uiuios.aios.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ContentView;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.trello.rxlifecycle4.LifecycleProvider;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
import com.uiuios.aios.R;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
|
||||
public abstract class BaseLightActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseLightActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseLightActivity(@LayoutRes int contentLayoutId) {
|
||||
super(contentLayoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
// StatusBarUtil.init(this);
|
||||
UltimateBarX.statusBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
.light(true)
|
||||
.apply();
|
||||
UltimateBarX.navigationBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
.light(true)
|
||||
.apply();
|
||||
setContentView(this.getLayoutId());
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
public abstract void initView();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
public abstract void initData();
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
lifecycleSubject.onNext(ActivityEvent.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
lifecycleSubject.onNext(ActivityEvent.RESUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onPause() {
|
||||
lifecycleSubject.onNext(ActivityEvent.PAUSE);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStop() {
|
||||
lifecycleSubject.onNext(ActivityEvent.STOP);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onDestroy() {
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
118
app/src/main/java/com/uiuios/aios/base/GlideEngine.java
Normal file
118
app/src/main/java/com/uiuios/aios/base/GlideEngine.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package com.uiuios.aios.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.luck.picture.lib.engine.ImageEngine;
|
||||
import com.luck.picture.lib.utils.ActivityCompatHelper;
|
||||
import com.uiuios.aios.R;
|
||||
|
||||
/**
|
||||
* @author:luck
|
||||
* @date:2019-11-13 17:02
|
||||
* @describe:Glide加载引擎
|
||||
*/
|
||||
public class GlideEngine implements ImageEngine {
|
||||
|
||||
/**
|
||||
* 加载图片
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 资源url
|
||||
* @param imageView 图片承载控件
|
||||
*/
|
||||
@Override
|
||||
public void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(Context context, ImageView imageView, String url, int maxWidth, int maxHeight) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.override(maxWidth, maxHeight)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载相册目录封面
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadAlbumCover(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.override(180, 180)
|
||||
.sizeMultiplier(0.5f)
|
||||
.transform(new CenterCrop(), new RoundedCorners(8))
|
||||
.placeholder(R.drawable.ps_image_placeholder)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载图片列表图片
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadGridImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.override(200, 200)
|
||||
.centerCrop()
|
||||
.placeholder(R.drawable.ps_image_placeholder)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseRequests(Context context) {
|
||||
Glide.with(context).pauseRequests();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeRequests(Context context) {
|
||||
Glide.with(context).resumeRequests();
|
||||
}
|
||||
|
||||
private GlideEngine() {
|
||||
}
|
||||
|
||||
private static GlideEngine instance;
|
||||
|
||||
public static GlideEngine createGlideEngine() {
|
||||
if (null == instance) {
|
||||
synchronized (GlideEngine.class) {
|
||||
if (null == instance) {
|
||||
instance = new GlideEngine();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
64
app/src/main/java/com/uiuios/aios/bean/RecordsInfo.java
Normal file
64
app/src/main/java/com/uiuios/aios/bean/RecordsInfo.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.uiuios.aios.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class RecordsInfo implements Serializable {
|
||||
private static final long serialVersionUID = -8677336093725878416L;
|
||||
|
||||
String name;
|
||||
String number;
|
||||
long date;
|
||||
int duration;
|
||||
int type;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public long getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(long date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,8 @@ import com.uiuios.aios.dialog.SingleDialog;
|
||||
import com.uiuios.aios.disklrucache.CacheHelper;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
import com.uiuios.aios.push.PushManager;
|
||||
import com.uiuios.aios.push.tpush.MessageReceiver;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.AppUtil;
|
||||
import com.uiuios.aios.utils.BitmapUtils;
|
||||
@@ -793,7 +792,7 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
}
|
||||
|
||||
public void setSosNumber() {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_SETTINGS);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_SETTINGS);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
// rv_sos.setVisibility(View.GONE);
|
||||
@@ -854,7 +853,7 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
}
|
||||
|
||||
private void getAlarmCache() {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_ALARM_CLOCK);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ALARM_CLOCK);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
}.getType();
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.uiuios.aios.network.api.GetMailList;
|
||||
import com.uiuios.aios.network.api.GetUserIDApi;
|
||||
import com.uiuios.aios.network.api.GoodsListApi;
|
||||
import com.uiuios.aios.network.api.HealthCodeApi;
|
||||
import com.uiuios.aios.network.api.MailListAddApi;
|
||||
import com.uiuios.aios.network.api.RunNewApp;
|
||||
import com.uiuios.aios.network.api.SNInfoApi;
|
||||
import com.uiuios.aios.network.api.SOSRecordApi;
|
||||
@@ -55,6 +56,7 @@ import com.uiuios.aios.utils.Utils;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -68,6 +70,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import retrofit2.Retrofit;
|
||||
@@ -116,7 +119,7 @@ public class NetInterfaceManager {
|
||||
if (mRetrofit == null) {
|
||||
mRetrofit = new Retrofit.Builder()
|
||||
.client(okHttpClient)
|
||||
.baseUrl(URLAddress.ROOT_URL)
|
||||
.baseUrl(UrlAddress.ROOT_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
|
||||
.build();
|
||||
@@ -264,6 +267,12 @@ public class NetInterfaceManager {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse> getMailListAddObservable(Map<String, String> params, MultipartBody.Part body) {
|
||||
return mRetrofit.create(MailListAddApi.class)
|
||||
.addMailList(params, body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public interface onCompleteCallback {
|
||||
void onComplete();
|
||||
@@ -312,10 +321,10 @@ public class NetInterfaceManager {
|
||||
Log.e("getUserID", "onNext: " + userIdBaseResponse);
|
||||
if (userIdBaseResponse.code == 200) {
|
||||
UserId userId = userIdBaseResponse.data;
|
||||
mCacheHelper.put(URLAddress.GET_USER_ID, GsonUtils.toJsonString(userId));
|
||||
mCacheHelper.put(UrlAddress.GET_USER_ID, GsonUtils.toJsonString(userId));
|
||||
mMMKV.encode("USER_ID", userId.getUser_id());
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_USER_ID, -1);
|
||||
mCacheHelper.put(UrlAddress.GET_USER_ID, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,10 +367,10 @@ public class NetInterfaceManager {
|
||||
if (refresh) {
|
||||
connectMode = ConnectMode.ONE_MINUTE;
|
||||
}
|
||||
if (ConnectManager.getInstance().isNeedConnect(URLAddress.GET_ACTIVITY_LIST, connectMode)) {
|
||||
if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_ACTIVITY_LIST, connectMode)) {
|
||||
getActivityList(lifecycle, callback);
|
||||
} else {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_ACTIVITY_LIST);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ACTIVITY_LIST);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getActivityList(lifecycle, callback);
|
||||
@@ -409,14 +418,14 @@ public class NetInterfaceManager {
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<ActivityBean> activityBeans = listBaseResponse.data;
|
||||
if (activityBeans == null || activityBeans.size() == 0) {
|
||||
mCacheHelper.put(URLAddress.GET_ACTIVITY_LIST, "");
|
||||
mCacheHelper.put(UrlAddress.GET_ACTIVITY_LIST, "");
|
||||
if (callback != null) callback.noData();
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_ACTIVITY_LIST, GsonUtils.toJsonString(activityBeans));
|
||||
mCacheHelper.put(UrlAddress.GET_ACTIVITY_LIST, GsonUtils.toJsonString(activityBeans));
|
||||
if (callback != null) callback.setActivitiesList(activityBeans);
|
||||
}
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_ACTIVITY_LIST, "");
|
||||
mCacheHelper.put(UrlAddress.GET_ACTIVITY_LIST, "");
|
||||
if (callback != null) callback.noData();
|
||||
}
|
||||
}
|
||||
@@ -424,7 +433,7 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getActivityListObserver", "onError: " + e.getMessage());
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_ACTIVITY_LIST);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ACTIVITY_LIST);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<ActivityBean>>() {
|
||||
}.getType();
|
||||
@@ -468,10 +477,10 @@ public class NetInterfaceManager {
|
||||
if (refresh) {
|
||||
connectMode = ConnectMode.ONE_MINUTE;
|
||||
}
|
||||
if (ConnectManager.getInstance().isNeedConnect(URLAddress.GET_DEMAND_LIST, connectMode)) {
|
||||
if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_DEMAND_LIST, connectMode)) {
|
||||
getDemandList(lifecycle, callback);
|
||||
} else {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_DEMAND_LIST);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_DEMAND_LIST);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getDemandList(lifecycle, callback);
|
||||
@@ -520,14 +529,14 @@ public class NetInterfaceManager {
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<DemandBean> demandBeans = listBaseResponse.data;
|
||||
if (demandBeans == null || demandBeans.size() == 0) {
|
||||
mCacheHelper.put(URLAddress.GET_DEMAND_LIST, "");
|
||||
mCacheHelper.put(UrlAddress.GET_DEMAND_LIST, "");
|
||||
if (callback != null) callback.noData();
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_DEMAND_LIST, GsonUtils.toJsonString(demandBeans));
|
||||
mCacheHelper.put(UrlAddress.GET_DEMAND_LIST, GsonUtils.toJsonString(demandBeans));
|
||||
if (callback != null) callback.setDemandList(demandBeans);
|
||||
}
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_DEMAND_LIST, "");
|
||||
mCacheHelper.put(UrlAddress.GET_DEMAND_LIST, "");
|
||||
if (callback != null) callback.noData();
|
||||
}
|
||||
}
|
||||
@@ -535,7 +544,7 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getDemandListObserver", "onError: " + e.getMessage());
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_DEMAND_LIST);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_DEMAND_LIST);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<DemandBean>>() {
|
||||
}.getType();
|
||||
@@ -586,10 +595,10 @@ public class NetInterfaceManager {
|
||||
if (refresh) {
|
||||
connectMode = ConnectMode.ONE_MINUTE;
|
||||
}
|
||||
if (ConnectManager.getInstance().isNeedConnect(URLAddress.GET_HEALTH_CODE, connectMode)) {
|
||||
if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_HEALTH_CODE, connectMode)) {
|
||||
getHealthCode(lifecycle, callback);
|
||||
} else {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_HEALTH_CODE);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_HEALTH_CODE);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getHealthCode(lifecycle, callback);
|
||||
@@ -641,10 +650,10 @@ public class NetInterfaceManager {
|
||||
Log.e("getHealthCode", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<HealthCode> healthCodeList = listBaseResponse.data;
|
||||
mCacheHelper.put(URLAddress.GET_HEALTH_CODE, GsonUtils.toJsonString(healthCodeList));
|
||||
mCacheHelper.put(UrlAddress.GET_HEALTH_CODE, GsonUtils.toJsonString(healthCodeList));
|
||||
callback.setHealthCode(healthCodeList);
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_HEALTH_CODE, "");
|
||||
mCacheHelper.put(UrlAddress.GET_HEALTH_CODE, "");
|
||||
callback.noData();
|
||||
}
|
||||
}
|
||||
@@ -652,7 +661,7 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getHealthCode", "onError: ");
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_HEALTH_CODE);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_HEALTH_CODE);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<HealthCode>>() {
|
||||
}.getType();
|
||||
@@ -687,7 +696,7 @@ public class NetInterfaceManager {
|
||||
// if (refresh) {
|
||||
// connectMode = ConnectMode.DEFAULT;
|
||||
// }
|
||||
// if (ConnectManager.getInstance().isNeedConnect(URLAddress.GET_ALARM_CLOCK, connectMode)) {
|
||||
// if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_ALARM_CLOCK, connectMode)) {
|
||||
getAlarmClock(lifecycle, callback);
|
||||
// } else {
|
||||
// getAlarmClockCache(lifecycle, callback);
|
||||
@@ -695,7 +704,7 @@ public class NetInterfaceManager {
|
||||
}
|
||||
|
||||
public void getAlarmClockCache(BehaviorSubject<ActivityEvent> lifecycle, AlarmClockCallback callback) {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_ALARM_CLOCK);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ALARM_CLOCK);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getAlarmClock(lifecycle, callback);
|
||||
@@ -748,11 +757,11 @@ public class NetInterfaceManager {
|
||||
AlarmUtils.getInstance().setAlarmClockData(null);
|
||||
if (callback != null) callback.setAlarmClockEmpty();
|
||||
}
|
||||
mCacheHelper.put(URLAddress.GET_ALARM_CLOCK, GsonUtils.toJsonString(alarmClockData));
|
||||
mCacheHelper.put(UrlAddress.GET_ALARM_CLOCK, GsonUtils.toJsonString(alarmClockData));
|
||||
} else {
|
||||
AlarmUtils.getInstance().deleteAllAlarmClock();
|
||||
AlarmUtils.getInstance().setAlarmClockData(null);
|
||||
mCacheHelper.put(URLAddress.GET_ALARM_CLOCK, "");
|
||||
mCacheHelper.put(UrlAddress.GET_ALARM_CLOCK, "");
|
||||
if (callback != null) callback.setAlarmClockEmpty();
|
||||
}
|
||||
}
|
||||
@@ -760,7 +769,7 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClockObserver", "onError: " + e.getMessage());
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_ALARM_CLOCK);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ALARM_CLOCK);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
}.getType();
|
||||
@@ -828,10 +837,10 @@ public class NetInterfaceManager {
|
||||
if (refresh) {
|
||||
connectMode = ConnectMode.DEFAULT;
|
||||
}
|
||||
if (ConnectManager.getInstance().isNeedConnect(URLAddress.GET_SETTINGS, connectMode)) {
|
||||
if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_SETTINGS, connectMode)) {
|
||||
getSystemSettings(lifecycle, callback);
|
||||
} else {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_SETTINGS);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_SETTINGS);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getSystemSettings(lifecycle, callback);
|
||||
@@ -883,18 +892,18 @@ public class NetInterfaceManager {
|
||||
mMMKV.encode("is_info", systemSettings.getIs_info());
|
||||
List<Contact> setting_sos = systemSettings.getSetting_sos();
|
||||
if (setting_sos == null || setting_sos.size() == 0) {
|
||||
mCacheHelper.put(URLAddress.GET_SETTINGS, "");
|
||||
mCacheHelper.put(UrlAddress.GET_SETTINGS, "");
|
||||
if (callback != null) callback.setEmpty();
|
||||
} else {
|
||||
List<Contact> emergencyContact = setting_sos.stream().filter(contact -> contact.getIs_urgent() == 1).collect(Collectors.toList());
|
||||
mCacheHelper.put(URLAddress.GET_SETTINGS, GsonUtils.toJsonString(setting_sos));
|
||||
mCacheHelper.put(UrlAddress.GET_SETTINGS, GsonUtils.toJsonString(setting_sos));
|
||||
if (callback != null) {
|
||||
callback.setContact(setting_sos);
|
||||
callback.setEmergencyContact(emergencyContact);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_SETTINGS, "");
|
||||
mCacheHelper.put(UrlAddress.GET_SETTINGS, "");
|
||||
if (callback != null) callback.setEmpty();
|
||||
}
|
||||
}
|
||||
@@ -902,7 +911,7 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getSystemSettings", "onError: " + e.getMessage());
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_SETTINGS);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_SETTINGS);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
if (callback != null) callback.setEmpty();
|
||||
@@ -935,10 +944,10 @@ public class NetInterfaceManager {
|
||||
if (refresh) {
|
||||
connectMode = ConnectMode.DEFAULT;
|
||||
}
|
||||
if (ConnectManager.getInstance().isNeedConnect(URLAddress.GET_MAIL_LIST, connectMode)) {
|
||||
if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_MAIL_LIST, connectMode)) {
|
||||
getContactList(lifecycle, callback);
|
||||
} else {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_MAIL_LIST);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_MAIL_LIST);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getContactList(lifecycle, callback);
|
||||
@@ -986,10 +995,10 @@ public class NetInterfaceManager {
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<Contact> contactList = listBaseResponse.data;
|
||||
if (contactList == null || contactList.size() == 0) {
|
||||
mCacheHelper.put(URLAddress.GET_MAIL_LIST, "");
|
||||
mCacheHelper.put(UrlAddress.GET_MAIL_LIST, "");
|
||||
if (callback != null) callback.setEmpty();
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_MAIL_LIST, GsonUtils.toJsonString(contactList));
|
||||
mCacheHelper.put(UrlAddress.GET_MAIL_LIST, GsonUtils.toJsonString(contactList));
|
||||
List<Contact> emergencyContact = contactList.stream().filter(contact -> contact.getIs_urgent() == 1).collect(Collectors.toList());
|
||||
if (callback != null) {
|
||||
callback.setContact(contactList);
|
||||
@@ -997,7 +1006,7 @@ public class NetInterfaceManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mCacheHelper.put(URLAddress.GET_MAIL_LIST, "");
|
||||
mCacheHelper.put(UrlAddress.GET_MAIL_LIST, "");
|
||||
if (callback != null) callback.setEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1022,10 +1031,10 @@ public class NetInterfaceManager {
|
||||
if (refresh) {
|
||||
connectMode = ConnectMode.DEFAULT;
|
||||
}
|
||||
if (ConnectManager.getInstance().isNeedConnect(URLAddress.GET_ADMIN_SN_SETTING, connectMode)) {
|
||||
if (ConnectManager.getInstance().isNeedConnect(UrlAddress.GET_ADMIN_SN_SETTING, connectMode)) {
|
||||
getAdminSnSetting(lifecycle, callback);
|
||||
} else {
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_ADMIN_SN_SETTING);
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ADMIN_SN_SETTING);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getAdminSnSetting(lifecycle, callback);
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.uiuios.aios.network;
|
||||
|
||||
public class URLAddress {
|
||||
public class UrlAddress {
|
||||
public static final String ROOT_URL = "https://led.zuoyepad.com/android/";
|
||||
/*设备信息接口*/
|
||||
public static final String SNINFO = "sn/getSnInfo";
|
||||
/*获取用户头像和信息*/
|
||||
public static final String GET_USER_AVATAR_INFO = "sn/getUserAvatarInfo";
|
||||
/*获取闹钟*/
|
||||
public static final String GET_ALARM_CLOCK = "getAlarmClock";
|
||||
/*应用使用记录*/
|
||||
public static final String APP_USAGE_RECORD = "appUsageRecord";
|
||||
/*正在运行的应用*/
|
||||
@@ -38,13 +36,32 @@ public class URLAddress {
|
||||
public static final String GET_DEMAND_LIST = "demandList";
|
||||
/*获取健康吗*/
|
||||
public static final String GET_HEALTH_CODE = "getHealthCode";
|
||||
/*获取联系人*/
|
||||
public static final String GET_MAIL_LIST = "Control/getMailList";
|
||||
/*获取负二屏开关*/
|
||||
public static final String GET_ADMIN_SN_SETTING = "getAdminSnSetting";
|
||||
/*更新app隐藏或者显示状态*/
|
||||
public static final String APP_ICON_UPDATE = "Control/appIconUpdate";
|
||||
|
||||
/*获取联系人*/
|
||||
public static final String GET_MAIL_LIST = "Control/getMailList";
|
||||
/*添加联系人*/
|
||||
public static final String MAIL_LIST_ADD = "MailList/mailListAdd";
|
||||
/*编辑联系人*/
|
||||
public static final String MAIL_LIST_EDIT = "MailList/mailListEdit";
|
||||
/*删除联系人*/
|
||||
public static final String MAIL_LIST_DELETE = "MailList/mailListDelete";
|
||||
/*编号查询联系人*/
|
||||
public static final String MAIL_LIST_BY_ID = "MailList/mailListById";
|
||||
|
||||
/*获取闹钟*/
|
||||
public static final String GET_ALARM_CLOCK = "getAlarmClock";
|
||||
/*添加闹钟*/
|
||||
public static final String ALARM_CLOCK_ADD = "AlarmClock/alarmClockAdd";
|
||||
/*编辑闹钟*/
|
||||
public static final String ALARM_CLOCK_EDIT = "AlarmClock/alarmClockEdit";
|
||||
/*编号查询闹钟*/
|
||||
public static final String ALARM_CLOCK_BY_ID = "AlarmClock/alarmClockById";
|
||||
/*删除闹钟*/
|
||||
public static final String ALARM_CLOCK_DELETE = "AlarmClock/alarmClockDelete";
|
||||
|
||||
public static final String GET_USER_ID = "getUserId";
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.ActivityBean;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface ActivityListApi {
|
||||
@GET(URLAddress.GET_ACTIVITY_LIST)
|
||||
@GET(UrlAddress.GET_ACTIVITY_LIST)
|
||||
Observable<BaseResponse<List<ActivityBean>>> getActivityList(
|
||||
@Query("sn") String sn,
|
||||
@Query("startSize") int startSize,
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface AlarmClockApi {
|
||||
@GET(URLAddress.GET_ALARM_CLOCK)
|
||||
@GET(UrlAddress.GET_ALARM_CLOCK)
|
||||
Observable<BaseResponse<List<AlarmClockData>>> getAlarmClockApiApi(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
@@ -10,7 +10,7 @@ import retrofit2.http.POST;
|
||||
|
||||
public interface AppUsageRecordApi {
|
||||
@FormUrlEncoded
|
||||
@POST(URLAddress.APP_USAGE_RECORD)
|
||||
@POST(UrlAddress.APP_USAGE_RECORD)
|
||||
Observable<BaseResponse> sendappUsageRecord(
|
||||
@Field("sn") String sn,
|
||||
@Field("app_name") String app_name,
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.ArticleDetails;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface ArticleDetailsApi {
|
||||
@GET(URLAddress.GET_ARTICLE_DETAILS)
|
||||
@GET(UrlAddress.GET_ARTICLE_DETAILS)
|
||||
Observable<BaseResponse<ArticleDetails>> getArticleDetails(
|
||||
@Query("id") int id
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.ArticleInfo;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface ArticleListApi {
|
||||
@GET(URLAddress.GET_ARTICLE_LIST)
|
||||
@GET(UrlAddress.GET_ARTICLE_LIST)
|
||||
Observable<BaseResponse<List<ArticleInfo>>> getArticleList(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.DemandBean;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface DemandListApi {
|
||||
@GET(URLAddress.GET_DEMAND_LIST)
|
||||
@GET(UrlAddress.GET_DEMAND_LIST)
|
||||
Observable<BaseResponse<List<DemandBean>>> getDemandList(
|
||||
@Query("sn") String sn,
|
||||
@Query("startSize") int startSize,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface GetAdminSnSettingApi {
|
||||
@GET(URLAddress.GET_ADMIN_SN_SETTING)
|
||||
@GET(UrlAddress.GET_ADMIN_SN_SETTING)
|
||||
Observable<BaseResponse> getAdminSnSetting(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.NetDesktopIcon;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface GetDesktopApi {
|
||||
@GET(URLAddress.GET_DESKTOP_LAYOUT)
|
||||
@GET(UrlAddress.GET_DESKTOP_LAYOUT)
|
||||
Observable<BaseResponse<List<NetDesktopIcon>>> getDesktopLayout(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface GetMailList {
|
||||
@GET(URLAddress.GET_MAIL_LIST)
|
||||
@GET(UrlAddress.GET_MAIL_LIST)
|
||||
Observable<BaseResponse<List<Contact>>> getContact(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.UserId;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface GetUserIDApi {
|
||||
@GET(URLAddress.GET_USER_ID)
|
||||
@GET(UrlAddress.GET_USER_ID)
|
||||
Observable<BaseResponse<UserId>> getUserID(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.GoodsDetails;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface GoodsDetailsApi {
|
||||
@GET(URLAddress.GET_GOODS_DETAILS)
|
||||
@GET(UrlAddress.GET_GOODS_DETAILS)
|
||||
Observable<BaseResponse<GoodsDetails>> getGoodsDetails(
|
||||
@Query("id") int id
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.GoodsInfo;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface GoodsListApi {
|
||||
@GET(URLAddress.GET_GOODS_LIST)
|
||||
@GET(UrlAddress.GET_GOODS_LIST)
|
||||
Observable<BaseResponse<List<GoodsInfo>>> getGoodsList(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.HealthCode;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface HealthCodeApi {
|
||||
@GET(URLAddress.GET_HEALTH_CODE)
|
||||
@GET(UrlAddress.GET_HEALTH_CODE)
|
||||
Observable<BaseResponse<List<HealthCode>>> getArticleDetails(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.QueryMap;
|
||||
|
||||
public interface MailListAddApi {
|
||||
@Multipart
|
||||
@POST(UrlAddress.MAIL_LIST_ADD)
|
||||
Observable<BaseResponse> addMailList(
|
||||
@QueryMap Map<String, String> params,
|
||||
@Part MultipartBody.Part body
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
@@ -10,7 +10,7 @@ import retrofit2.http.POST;
|
||||
|
||||
public interface RunNewApp {
|
||||
@FormUrlEncoded
|
||||
@POST(URLAddress.RUN_NEW_APP)
|
||||
@POST(UrlAddress.RUN_NEW_APP)
|
||||
Observable<BaseResponse> sendRunningInfo(
|
||||
@Field("sn") String sn,
|
||||
@Field("app") String app
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.SnInfo;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface SNInfoApi {
|
||||
@GET(URLAddress.SNINFO)
|
||||
@GET(UrlAddress.SNINFO)
|
||||
Observable<BaseResponse<SnInfo>> getsninfo(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
@@ -10,7 +10,7 @@ import retrofit2.http.POST;
|
||||
|
||||
public interface SOSRecordApi {
|
||||
@FormUrlEncoded
|
||||
@POST(URLAddress.SOS_RECORD)
|
||||
@POST(UrlAddress.SOS_RECORD)
|
||||
Observable<BaseResponse> sendSOSRecord(
|
||||
@Field("sn") String sn,
|
||||
@Field("longitude") String longitude,
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import okhttp3.MultipartBody;
|
||||
@@ -13,7 +13,7 @@ import retrofit2.http.Query;
|
||||
|
||||
public interface SendScreenshotApi {
|
||||
@Multipart
|
||||
@POST(URLAddress.SEND_SCREENSHOT)
|
||||
@POST(UrlAddress.SEND_SCREENSHOT)
|
||||
Observable<BaseResponse> sendScreenshot(
|
||||
@Query("sn") String sn,
|
||||
@Part MultipartBody.Part file
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.SystemSettings;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface Setting {
|
||||
@GET(URLAddress.GET_SETTINGS)
|
||||
@GET(UrlAddress.GET_SETTINGS)
|
||||
Observable<BaseResponse<SystemSettings>> getSetting(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
@@ -10,7 +10,7 @@ import retrofit2.http.POST;
|
||||
|
||||
public interface UpdateAlarmClockApi {
|
||||
@FormUrlEncoded
|
||||
@POST(URLAddress.UPDATE_ALARM_CLOCK)
|
||||
@POST(UrlAddress.UPDATE_ALARM_CLOCK)
|
||||
Observable<BaseResponse> updateAlarm(
|
||||
@Field("sn") String sn,
|
||||
@Field("id") int id
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
@@ -10,7 +10,7 @@ import retrofit2.http.POST;
|
||||
|
||||
public interface UpdateAppIconApi {
|
||||
@FormUrlEncoded
|
||||
@POST(URLAddress.APP_ICON_UPDATE)
|
||||
@POST(UrlAddress.APP_ICON_UPDATE)
|
||||
Observable<BaseResponse> appIconUpdate(
|
||||
@Field("sn") String sn,
|
||||
@Field("app_package") String app_package,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
@@ -10,7 +10,7 @@ import retrofit2.http.POST;
|
||||
|
||||
public interface UpdateDesktopApi {
|
||||
@FormUrlEncoded
|
||||
@POST(URLAddress.UPDATE_DESKTOP_LAYOUT)
|
||||
@POST(UrlAddress.UPDATE_DESKTOP_LAYOUT)
|
||||
Observable<BaseResponse> updateLayout(
|
||||
@Field("sn") String sn,
|
||||
@Field("app") String app
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.UserAvatarInfo;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
@@ -12,7 +12,7 @@ import retrofit2.http.POST;
|
||||
|
||||
public interface UserInfoControl {
|
||||
@FormUrlEncoded
|
||||
@POST(URLAddress.GET_USER_AVATAR_INFO)
|
||||
@POST(UrlAddress.GET_USER_AVATAR_INFO)
|
||||
Observable<BaseResponse<UserAvatarInfo>> getUserAvatarInfo(
|
||||
@Field("sn") String sn
|
||||
);
|
||||
|
||||
347
app/src/main/java/com/uiuios/aios/view/ToggleButton.java
Normal file
347
app/src/main/java/com/uiuios/aios/view/ToggleButton.java
Normal file
@@ -0,0 +1,347 @@
|
||||
package com.uiuios.aios.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.rebound.SimpleSpringListener;
|
||||
import com.facebook.rebound.Spring;
|
||||
import com.facebook.rebound.SpringConfig;
|
||||
import com.facebook.rebound.SpringSystem;
|
||||
import com.facebook.rebound.SpringUtil;
|
||||
import com.uiuios.aios.R;
|
||||
|
||||
public class ToggleButton extends View {
|
||||
private SpringSystem springSystem;
|
||||
private Spring spring;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private float radius;
|
||||
/**
|
||||
* 开启颜色
|
||||
*/
|
||||
private int onColor = Color.parseColor("#f62626");
|
||||
/**
|
||||
* 关闭颜色
|
||||
*/
|
||||
private int offBorderColor = Color.parseColor("#e7e4e4");
|
||||
/**
|
||||
* 灰色带颜色
|
||||
*/
|
||||
private int offColor = Color.parseColor("#ffffff");
|
||||
/**
|
||||
* 手柄颜色
|
||||
*/
|
||||
private int spotColor = Color.parseColor("#ffffff");
|
||||
/**
|
||||
* 边框颜色
|
||||
*/
|
||||
private int borderColor = offBorderColor;
|
||||
/**
|
||||
* 画笔
|
||||
*/
|
||||
private Paint paint;
|
||||
/**
|
||||
* 开关状态
|
||||
*/
|
||||
private boolean toggleOn = false;
|
||||
/**
|
||||
* 边框大小
|
||||
*/
|
||||
private int borderWidth = 2;
|
||||
/**
|
||||
* 垂直中心
|
||||
*/
|
||||
private float centerY;
|
||||
/**
|
||||
* 按钮的开始和结束位置
|
||||
*/
|
||||
private float startX, endX;
|
||||
/**
|
||||
* 手柄X位置的最小和最大值
|
||||
*/
|
||||
private float spotMinX, spotMaxX;
|
||||
/**
|
||||
* 手柄大小
|
||||
*/
|
||||
private int spotSize;
|
||||
/**
|
||||
* 手柄X位置
|
||||
*/
|
||||
private float spotX;
|
||||
/**
|
||||
* 关闭时内部灰色带高度
|
||||
*/
|
||||
private float offLineWidth;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private RectF rect = new RectF();
|
||||
/**
|
||||
* 默认使用动画
|
||||
*/
|
||||
private boolean defaultAnimate = true;
|
||||
/**
|
||||
* 是否默认处于打开状态
|
||||
*/
|
||||
private boolean isDefaultOn = false;
|
||||
/**
|
||||
* 禁止点击
|
||||
*/
|
||||
private boolean disable = false;
|
||||
|
||||
private OnToggleChanged listener;
|
||||
|
||||
public void setDisable(boolean dis) {
|
||||
this.disable = dis;
|
||||
}
|
||||
|
||||
private ToggleButton(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ToggleButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
setup(attrs);
|
||||
}
|
||||
|
||||
public ToggleButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setup(attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
spring.removeListener(springListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
spring.addListener(springListener);
|
||||
}
|
||||
|
||||
public void setup(AttributeSet attrs) {
|
||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
springSystem = SpringSystem.create();
|
||||
spring = springSystem.createSpring();
|
||||
spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7));
|
||||
this.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
if (disable) {
|
||||
|
||||
} else {
|
||||
toggle(defaultAnimate);
|
||||
}
|
||||
}
|
||||
});
|
||||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton);
|
||||
offBorderColor = typedArray.getColor(R.styleable.ToggleButton_tbOffBorderColor, offBorderColor);
|
||||
onColor = typedArray.getColor(R.styleable.ToggleButton_tbOnColor, onColor);
|
||||
spotColor = typedArray.getColor(R.styleable.ToggleButton_tbSpotColor, spotColor);
|
||||
offColor = typedArray.getColor(R.styleable.ToggleButton_tbOffColor, offColor);
|
||||
borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_tbBorderWidth, borderWidth);
|
||||
defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_tbAnimate, defaultAnimate);
|
||||
isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_tbAsDefaultOn, isDefaultOn);
|
||||
typedArray.recycle();
|
||||
borderColor = offBorderColor;
|
||||
if (isDefaultOn) {
|
||||
toggleOn();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
toggle(true);
|
||||
}
|
||||
|
||||
public void toggle(boolean animate) {
|
||||
toggleOn = !toggleOn;
|
||||
takeEffect(animate);
|
||||
if (listener != null) {
|
||||
listener.onToggle(toggleOn);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleOn() {
|
||||
setToggleOn();
|
||||
if (listener != null) {
|
||||
listener.onToggle(toggleOn);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleOff() {
|
||||
setToggleOff();
|
||||
if (listener != null) {
|
||||
listener.onToggle(toggleOn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示成打开样式,不会触发toggle事件
|
||||
*/
|
||||
public void setToggleOn() {
|
||||
setToggleOn(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param animate asd
|
||||
*/
|
||||
public void setToggleOn(boolean animate) {
|
||||
toggleOn = true;
|
||||
takeEffect(animate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示成关闭样式,不会触发toggle事件
|
||||
*/
|
||||
public void setToggleOff() {
|
||||
setToggleOff(true);
|
||||
}
|
||||
|
||||
public void setToggleOff(boolean animate) {
|
||||
toggleOn = false;
|
||||
takeEffect(animate);
|
||||
}
|
||||
|
||||
public int isToggleOn() {
|
||||
return toggleOn ? 1 : 0;
|
||||
}
|
||||
|
||||
private void takeEffect(boolean animate) {
|
||||
if (animate) {
|
||||
spring.setEndValue(toggleOn ? 1 : 0);
|
||||
} else {
|
||||
//这里没有调用spring,所以spring里的当前值没有变更,这里要设置一下,同步两边的当前值
|
||||
spring.setCurrentValue(toggleOn ? 1 : 0);
|
||||
calculateEffect(toggleOn ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
Resources r = Resources.getSystem();
|
||||
if (widthMode == MeasureSpec.UNSPECIFIED || widthMode == MeasureSpec.AT_MOST) {
|
||||
widthSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, r.getDisplayMetrics());
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
|
||||
}
|
||||
if (heightMode == MeasureSpec.UNSPECIFIED || heightSize == MeasureSpec.AT_MOST) {
|
||||
heightSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, r.getDisplayMetrics());
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right,
|
||||
int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
final int width = getWidth();
|
||||
final int height = getHeight();
|
||||
radius = Math.min(width, height) * 0.5f;
|
||||
centerY = radius;
|
||||
startX = radius;
|
||||
endX = width - radius;
|
||||
spotMinX = startX + borderWidth;
|
||||
spotMaxX = endX - borderWidth;
|
||||
spotSize = height - 4 * borderWidth;
|
||||
spotX = toggleOn ? spotMaxX : spotMinX;
|
||||
offLineWidth = 0;
|
||||
}
|
||||
|
||||
SimpleSpringListener springListener = new SimpleSpringListener() {
|
||||
@Override
|
||||
public void onSpringUpdate(Spring spring) {
|
||||
final double value = spring.getCurrentValue();
|
||||
calculateEffect(value);
|
||||
}
|
||||
};
|
||||
|
||||
private int clamp(int value, int low, int high) {
|
||||
return Math.min(Math.max(value, low), high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
//
|
||||
super.draw(canvas);
|
||||
rect.set(0, 0, getWidth(), getHeight());
|
||||
paint.setColor(borderColor);
|
||||
canvas.drawRoundRect(rect, radius, radius, paint);
|
||||
if (offLineWidth > 0) {
|
||||
final float cy = offLineWidth * 0.5f;
|
||||
rect.set(spotX - cy, centerY - cy, endX + cy, centerY + cy);
|
||||
// paint.setColor(offColor);
|
||||
canvas.drawRoundRect(rect, cy, cy, paint);
|
||||
}
|
||||
rect.set(spotX - 1 - radius, centerY - radius, spotX + 1.1f + radius, centerY + radius);
|
||||
paint.setColor(borderColor);
|
||||
canvas.drawRoundRect(rect, radius, radius, paint);
|
||||
final float spotR = spotSize * 0.5f;
|
||||
rect.set(spotX - spotR, centerY - spotR, spotX + spotR, centerY + spotR);
|
||||
paint.setColor(spotColor);
|
||||
canvas.drawRoundRect(rect, spotR, spotR, paint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
private void calculateEffect(final double value) {
|
||||
final float mapToggleX = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, spotMinX, spotMaxX);
|
||||
spotX = mapToggleX;
|
||||
float mapOffLineWidth = (float) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, 10, spotSize);
|
||||
offLineWidth = mapOffLineWidth;
|
||||
final int fb = Color.blue(onColor);
|
||||
final int fr = Color.red(onColor);
|
||||
final int fg = Color.green(onColor);
|
||||
final int tb = Color.blue(offBorderColor);
|
||||
final int tr = Color.red(offBorderColor);
|
||||
final int tg = Color.green(offBorderColor);
|
||||
int sb = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fb, tb);
|
||||
int sr = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fr, tr);
|
||||
int sg = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fg, tg);
|
||||
sb = clamp(sb, 0, 255);
|
||||
sr = clamp(sr, 0, 255);
|
||||
sg = clamp(sg, 0, 255);
|
||||
borderColor = Color.rgb(sr, sg, sb);
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @author ThinkPad
|
||||
*/
|
||||
public interface OnToggleChanged {
|
||||
/**
|
||||
* @param on = =
|
||||
*/
|
||||
public void onToggle(boolean on);
|
||||
}
|
||||
|
||||
public void setOnToggleChanged(OnToggleChanged onToggleChanged) {
|
||||
listener = onToggleChanged;
|
||||
}
|
||||
|
||||
public boolean isAnimate() {
|
||||
return defaultAnimate;
|
||||
}
|
||||
|
||||
public void setAnimate(boolean animate) {
|
||||
this.defaultAnimate = animate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user