<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
<project version="4"> | <project version="4"> | ||||
<component name="CompilerConfiguration"> | <component name="CompilerConfiguration"> | ||||
<bytecodeTargetLevel target="1.8" /> | |||||
<bytecodeTargetLevel target="11" /> | |||||
</component> | </component> | ||||
</project> | </project> |
</set> | </set> | ||||
</option> | </option> | ||||
<option name="resolveModulePerSourceSet" value="false" /> | <option name="resolveModulePerSourceSet" value="false" /> | ||||
<option name="useQualifiedModuleNames" value="true" /> | |||||
</GradleProjectSettings> | </GradleProjectSettings> | ||||
</option> | </option> | ||||
</component> | </component> |
<option name="name" value="maven" /> | <option name="name" value="maven" /> | ||||
<option name="url" value="https://jitpack.io" /> | <option name="url" value="https://jitpack.io" /> | ||||
</remote-repository> | </remote-repository> | ||||
<remote-repository> | |||||
<option name="id" value="maven" /> | |||||
<option name="name" value="maven" /> | |||||
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" /> | |||||
</remote-repository> | |||||
</component> | </component> | ||||
</project> | </project> |
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
<project version="4"> | <project version="4"> | ||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||||
<output url="file://$PROJECT_DIR$/build/classes" /> | <output url="file://$PROJECT_DIR$/build/classes" /> | ||||
</component> | </component> | ||||
<component name="ProjectType"> | <component name="ProjectType"> |
android { | android { | ||||
compileSdkVersion 30 | compileSdkVersion 30 | ||||
buildToolsVersion "30.0.3" | buildToolsVersion "30.0.3" | ||||
defaultConfig { | defaultConfig { | ||||
applicationId "com.example.tidalairpeisong" | applicationId "com.example.tidalairpeisong" | ||||
minSdkVersion 16 | |||||
minSdkVersion 19 | |||||
targetSdkVersion 30 | targetSdkVersion 30 | ||||
versionCode 1 | versionCode 1 | ||||
versionName "1.0" | versionName "1.0" | ||||
targetCompatibility JavaVersion.VERSION_1_8 | targetCompatibility JavaVersion.VERSION_1_8 | ||||
} | } | ||||
signingConfigs { | |||||
debug { | |||||
keyAlias 'TidalAir' | |||||
keyPassword '123456' | |||||
storeFile file('configure/TidalAir.jks') | |||||
storePassword '123456' | |||||
} | |||||
release { | |||||
keyAlias 'TidalAir' | |||||
keyPassword '123456' | |||||
storeFile file('configure/TidalAir.jks') | |||||
storePassword '123456' | |||||
} | |||||
} | |||||
} | } | ||||
dependencies { | dependencies { | ||||
implementation 'androidx.appcompat:appcompat:1.2.0' | implementation 'androidx.appcompat:appcompat:1.2.0' | ||||
implementation 'com.google.android.material:material:1.2.1' | implementation 'com.google.android.material:material:1.2.1' | ||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1' | implementation 'androidx.constraintlayout:constraintlayout:2.0.1' | ||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0' | |||||
testImplementation 'junit:junit:4.+' | testImplementation 'junit:junit:4.+' | ||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0' | implementation 'com.squareup.retrofit2:retrofit:2.9.0' | ||||
//日志的拦截器 | //日志的拦截器 | ||||
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.2' | implementation 'com.squareup.okhttp3:logging-interceptor:4.9.2' | ||||
//SmartRefreshLayout | |||||
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3' //核心必须依赖 | |||||
implementation 'com.scwang.smart:refresh-header-classics:2.0.3' //经典刷新头 | |||||
implementation 'com.scwang.smart:refresh-footer-ball:2.0.3' //球脉冲加载 | |||||
//glide | |||||
implementation 'com.github.bumptech.glide:glide:4.12.0' | |||||
//butterknife | |||||
implementation 'com.jakewharton:butterknife:10.2.1' | |||||
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1' | |||||
//圆角图 | |||||
implementation 'com.makeramen:roundedimageview:2.3.0' | |||||
//圆形图 | |||||
implementation 'de.hdodenhof:circleimageview:3.1.0' | |||||
//BaseRecyclerViewAdapterHelper | |||||
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4' | |||||
//EasySwipeMenuLayout | |||||
implementation 'com.github.anzaizai:EasySwipeMenuLayout:1.1.4' | |||||
//定位 | |||||
implementation 'com.amap.api:location:4.9.0' | |||||
//搜索 | |||||
implementation 'com.amap.api:search:7.3.0' | |||||
//3D地图 | |||||
implementation 'com.amap.api:3dmap:7.4.0' | |||||
//权限 | |||||
implementation 'com.yanzhenjie:permission:2.0.3' | |||||
//tablaytout | |||||
implementation 'com.github.hackware1993:MagicIndicator:1.5.0' | |||||
implementation 'io.github.h07000223:flycoTabLayout:3.0.0' | |||||
//eventbus | |||||
implementation 'org.greenrobot:eventbus:3.2.0' | |||||
//pictureselector | |||||
implementation 'io.github.lucksiege:pictureselector:v2.7.3-rc08' | |||||
} | } |
package="com.example.tidalairpeisong"> | package="com.example.tidalairpeisong"> | ||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||||
<uses-permission android:name="android.permission.INTERNET" /> <!-- 获取网络信息状态,如当前的网络连接是否有效 --> | |||||
<uses-permission android:name="android.permission.INTERNET" /> | |||||
<uses-permission android:name="android.permission.CAMERA" /> | |||||
<!-- 允许绘制到小米刘海屏机型的刘海区域 --> | |||||
<!-- 允许获取精确位置,精准定位必选 --> | |||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 允许获取粗略位置,粗略定位必选 --> | |||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 允许获取设备和运营商信息,用于问题排查和网络定位(无gps情况下的定位),若需网络定位功能则必选 --> | |||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 允许获取网络状态,用于网络定位(无gps情况下的定位),若需网络定位功能则必选 --> | |||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 允许获取wifi网络信息,用于网络定位(无gps情况下的定位),若需网络定位功能则必选 --> | |||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 允许获取wifi状态改变,用于网络定位(无gps情况下的定位),若需网络定位功能则必选 --> | |||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 后台获取位置信息,若需后台定位则必选 --> | |||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <!-- 用于申请调用A-GPS模块,卫星定位加速 --> | |||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <!-- 允许写设备缓存,用于问题排查 --> | |||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <!-- 允许写入扩展存储,用于写入缓存定位数据 --> | |||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 允许读设备等信息,用于问题排查 --> | |||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |||||
<uses-permission android:name="android.permission.CALL_PHONE" /> | |||||
<application | <application | ||||
android:name="com.example.tidalairpeisong.App" | |||||
android:name=".App" | |||||
android:allowBackup="true" | android:allowBackup="true" | ||||
android:icon="@mipmap/ic_launcher" | android:icon="@mipmap/ic_launcher" | ||||
android:label="@string/app_name" | android:label="@string/app_name" | ||||
android:networkSecurityConfig="@xml/network_security_config" | |||||
android:roundIcon="@mipmap/ic_launcher_round" | android:roundIcon="@mipmap/ic_launcher_round" | ||||
android:supportsRtl="true" | android:supportsRtl="true" | ||||
android:networkSecurityConfig="@xml/network_security_config" | |||||
android:theme="@style/Theme.NewProject"> | |||||
<activity android:name="com.example.tidalairpeisong.user.ui.activity.MainActivity"> | |||||
android:theme="@style/AppTheme" | |||||
android:requestLegacyExternalStorage="true"> | |||||
<activity android:name=".user.ui.activity.login.RenZhengActivity" | |||||
android:screenOrientation="portrait"></activity> | |||||
<activity android:name=".user.ui.activity.mine.SettingActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.IdentityAuthenticationActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.RuleActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.SetPwdActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.ResetPwdActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.ForgetPwdActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.RegisterActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.CodeLoginActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity android:name=".user.ui.activity.login.LoginActivity" | |||||
android:screenOrientation="portrait"> | |||||
<intent-filter> | <intent-filter> | ||||
<action android:name="android.intent.action.MAIN" /> | <action android:name="android.intent.action.MAIN" /> | ||||
<category android:name="android.intent.category.LAUNCHER" /> | <category android:name="android.intent.category.LAUNCHER" /> | ||||
</intent-filter> | </intent-filter> | ||||
</activity> | </activity> | ||||
<activity android:name=".user.ui.activity.SplashActivity" | |||||
android:screenOrientation="portrait"/> | |||||
<activity | |||||
android:name=".user.ui.activity.MainActivity" | |||||
android:theme="@style/AppTheme" | |||||
android:screenOrientation="portrait"/> | |||||
<meta-data | |||||
android:name="notch.config" | |||||
android:value="portrait" /> <!-- 允许绘制到华为刘海屏机型的刘海区域 --> | |||||
<meta-data | |||||
android:name="android.notch_support" | |||||
android:value="true" /> <!-- 允许绘制到oppo、vivo刘海屏机型的刘海区域 --> | |||||
<meta-data | |||||
android:name="android.max_aspect" | |||||
android:value="2.2" /> <!-- 今日头条适配设计图尺寸 --> | |||||
<meta-data | |||||
android:name="design_width_in_dp" | |||||
android:value="360" /> | |||||
<meta-data | |||||
android:name="design_height_in_dp" | |||||
android:value="640" /> | |||||
</application> | </application> | ||||
</manifest> | </manifest> |
import androidx.multidex.MultiDex; | import androidx.multidex.MultiDex; | ||||
import com.example.tidalairpeisong.rxhttp.manager.RxHttpManager; | import com.example.tidalairpeisong.rxhttp.manager.RxHttpManager; | ||||
import com.example.tidalairpeisong.utils.GDLocationUtil; | |||||
public class App extends Application { | public class App extends Application { | ||||
super.onCreate(); | super.onCreate(); | ||||
instance = this; | instance = this; | ||||
RxHttpManager.init(this); | RxHttpManager.init(this); | ||||
//GDLocationUtil.getInstance().init(instance); | |||||
} | } | ||||
protected void attachBaseContext(Context base) { | protected void attachBaseContext(Context base) { |
package com.example.tidalairpeisong.base; | |||||
import android.content.BroadcastReceiver; | |||||
import android.content.Context; | |||||
import android.content.Intent; | |||||
import android.content.IntentFilter; | |||||
import android.graphics.Color; | |||||
import android.graphics.drawable.ColorDrawable; | |||||
import android.os.Bundle; | |||||
import android.view.LayoutInflater; | |||||
import android.view.View; | |||||
import android.widget.TextView; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AlertDialog; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import com.example.tidalairpeisong.App; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.user.ui.activity.login.LoginActivity; | |||||
import com.example.tidalairpeisong.utils.ActivityTaskManager; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.base | |||||
* @ClassName: BaseActivity | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/18 20:43 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class BaseActivity extends AppCompatActivity { | |||||
private ForceOfflineReceiver receiver; | |||||
private AlertDialog alertDialog; | |||||
@Override | |||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
ActivityTaskManager.getInstance().addActivity(this); | |||||
} | |||||
@Override | |||||
protected void onResume() { | |||||
super.onResume(); | |||||
IntentFilter intentFilter = new IntentFilter(); | |||||
intentFilter.addAction("OffLine"); | |||||
receiver = new ForceOfflineReceiver(); | |||||
registerReceiver(receiver,intentFilter); | |||||
} | |||||
class ForceOfflineReceiver extends BroadcastReceiver { | |||||
@Override | |||||
public void onReceive(final Context context, final Intent intent) { | |||||
loginDialog("登录失效,请重新登录!"); | |||||
} | |||||
} | |||||
private void loginDialog(String s) { | |||||
if (alertDialog != null && alertDialog.isShowing()){ | |||||
return; | |||||
} | |||||
alertDialog = new AlertDialog.Builder(BaseActivity.this).create(); | |||||
alertDialog.setView(LayoutInflater.from(BaseActivity.this).inflate(R.layout.offline_dialog, null)); | |||||
alertDialog.show(); | |||||
alertDialog.getWindow().setContentView(R.layout.offline_dialog); | |||||
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | |||||
alertDialog.setCancelable(false); | |||||
alertDialog.setCanceledOnTouchOutside(false); | |||||
TextView tvBack = (TextView) alertDialog.findViewById(R.id.tv_back); | |||||
TextView tvCreate = (TextView) alertDialog.findViewById(R.id.tv_create); | |||||
TextView tvMessage = (TextView) alertDialog.findViewById(R.id.tv_message); | |||||
tvMessage.setText(s); | |||||
tvCreate.setOnClickListener(new View.OnClickListener() { | |||||
@Override | |||||
public void onClick(View v) { | |||||
Intent intent1 = new Intent(BaseActivity.this, LoginActivity.class); | |||||
//intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||||
intent1.putExtra("activity", "BaseActivity"); | |||||
startActivity(intent1); | |||||
ActivityTaskManager.getInstance().finishAllActivity(); | |||||
PrefUtils.clear(App.getInstance()); | |||||
alertDialog.dismiss(); | |||||
} | |||||
}); | |||||
tvBack.setOnClickListener(new View.OnClickListener() { | |||||
@Override | |||||
public void onClick(View v) { | |||||
alertDialog.dismiss(); | |||||
//ActivityTaskManager.getInstance().finishAllActivity(); | |||||
} | |||||
}); | |||||
} | |||||
} |
package com.example.tidalairpeisong.base; | |||||
import android.os.Bundle; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.fragment.app.Fragment; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.base | |||||
* @ClassName: BaseFragment | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/19 22:49 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class BaseFragment extends Fragment{ | |||||
@Override | |||||
public void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
} | |||||
@Override | |||||
public void onDestroy() { | |||||
super.onDestroy(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.listener; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.GridLayoutManager; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager; | |||||
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener{ | |||||
//用来标记是否正在向上滑动 | |||||
private boolean isSlidingUpward = false; | |||||
@Override | |||||
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { | |||||
super.onScrollStateChanged(recyclerView, newState); | |||||
//当前RecyclerView显示出来的最后一个的item的position | |||||
int lastPosition = -1; | |||||
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); | |||||
//当前状态为停止滑动状态SCROLL_STATE_IDLE时 | |||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) { | |||||
if (manager instanceof LinearLayoutManager) { | |||||
//获取最后一个完全显示的itemposition | |||||
lastPosition = ((LinearLayoutManager) manager).findLastCompletelyVisibleItemPosition(); | |||||
} else if (manager instanceof GridLayoutManager) { | |||||
//获取最后一个完全显示的itemposition | |||||
lastPosition = ((GridLayoutManager) manager).findLastCompletelyVisibleItemPosition(); | |||||
} else if (manager instanceof StaggeredGridLayoutManager) { | |||||
int[] lastPositions = new int[((StaggeredGridLayoutManager) manager).getSpanCount()]; | |||||
//((StaggeredGridLayoutManager) manager).findLastVisibleItemPositions(lastPositions); | |||||
lastPosition = findMax(((StaggeredGridLayoutManager) manager).findLastVisibleItemPositions(lastPositions)); | |||||
} | |||||
int itemCount = manager.getItemCount(); | |||||
//判断是否滑动到最后一个item,并且是向上滑动 | |||||
if (lastPosition == (itemCount - 1) && isSlidingUpward) { | |||||
//加载更多 | |||||
onLoadMore(); | |||||
} | |||||
} | |||||
} | |||||
//找到数组中的最大值 | |||||
private int findMax(int[] lastPositions) { | |||||
int max = lastPositions[0]; | |||||
for (int value : lastPositions) { | |||||
if (value > max) { | |||||
max = value; | |||||
} | |||||
} | |||||
return max; | |||||
} | |||||
@Override | |||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { | |||||
super.onScrolled(recyclerView, dx, dy); | |||||
//大于0表示正在向上滑动,小于等于0表示停止或向下滑动 | |||||
isSlidingUpward = dy > 0; | |||||
} | |||||
/* | |||||
* 加载更多回调 | |||||
* | |||||
* */ | |||||
public abstract void onLoadMore(); | |||||
} |
package com.example.tidalairpeisong.rxhttp.error; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.rxhttp.error | |||||
* @ClassName: ErrorBean | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/18 23:07 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class ErrorBean<T> { | |||||
/** | |||||
* code : 422 | |||||
* message : 缺少 appId 参数 | |||||
* data : {"name":"Unprocessable entity","message":"缺少 appId 参数","code":0,"status":422} | |||||
* req_id : 7ef5d01ae4748a1e09344a2ae1163aa6 | |||||
*/ | |||||
private int code; | |||||
private String message; | |||||
private T data; | |||||
private String req_id; | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public String getMessage() { | |||||
return message; | |||||
} | |||||
public void setMessage(String message) { | |||||
this.message = message; | |||||
} | |||||
public T getData() { | |||||
return data; | |||||
} | |||||
public void setData(T data) { | |||||
this.data = data; | |||||
} | |||||
public String getReq_id() { | |||||
return req_id; | |||||
} | |||||
public void setReq_id(String req_id) { | |||||
this.req_id = req_id; | |||||
} | |||||
public static class DataBean { | |||||
/** | |||||
* name : Unprocessable entity | |||||
* message : 缺少 appId 参数 | |||||
* code : 0 | |||||
* status : 422 | |||||
*/ | |||||
private String name; | |||||
private String message; | |||||
private int code; | |||||
private int status; | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public void setName(String name) { | |||||
this.name = name; | |||||
} | |||||
public String getMessage() { | |||||
return message; | |||||
} | |||||
public void setMessage(String message) { | |||||
this.message = message; | |||||
} | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public int getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(int status) { | |||||
this.status = status; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.rxhttp.error; | package com.example.tidalairpeisong.rxhttp.error; | ||||
import android.text.TextUtils; | |||||
import android.util.Log; | |||||
import com.example.tidalairpeisong.App; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.utils.Tip; | |||||
import com.google.gson.Gson; | |||||
import com.google.gson.JsonSyntaxException; | |||||
import java.net.ConnectException; | |||||
import java.net.SocketTimeoutException; | |||||
import java.net.UnknownHostException; | |||||
import java.util.concurrent.TimeoutException; | |||||
import rxhttp.wrapper.exception.HttpStatusCodeException; | |||||
import rxhttp.wrapper.exception.ParseException; | |||||
public class ErrorInfo { | public class ErrorInfo { | ||||
private int errorCode;//仅指服务器返回的错误码 | |||||
private String errorMsg;//错误文案,网络错误、请求失败错误、服务器返回的错误等 | |||||
private Throwable throwable;//异常信息 | |||||
public ErrorInfo(Throwable throwable){ | |||||
private int errorCode; //仅指服务器返回的错误码 | |||||
private String errorMsg; //错误文案,网络错误、请求失败错误、服务器返回的错误等文案 | |||||
private Throwable throwable; //异常信息 | |||||
public ErrorInfo(Throwable throwable) { | |||||
this.throwable = throwable; | this.throwable = throwable; | ||||
ExceptionHelper.ResponseException exception = ExceptionHelper.handleException(throwable); | |||||
String errorMsg = exception.message;//网络异常 | |||||
Log.e("csd",errorCode+throwable.getMessage()+"---"+throwable.toString()+"---"+throwable.getLocalizedMessage()); | |||||
String errorMsg = null; | |||||
if (throwable instanceof UnknownHostException) { | |||||
if (!ExceptionHelper.isNetworkConnected(App.getInstance())) { | |||||
errorMsg = getString(R.string.network_error); | |||||
} else { | |||||
errorMsg = getString(R.string.notify_no_network); | |||||
} | |||||
} else if (throwable instanceof SocketTimeoutException || throwable instanceof TimeoutException) { | |||||
//前者是通过OkHttpClient设置的超时引发的异常,后者是对单个请求调用timeout方法引发的超时异常 | |||||
errorMsg = getString(R.string.time_out_please_try_again_later); | |||||
} else if (throwable instanceof ConnectException) { | |||||
errorMsg = getString(R.string.esky_service_exception); | |||||
} else if (throwable instanceof HttpStatusCodeException) { //请求失败异常 | |||||
String code = throwable.getLocalizedMessage(); | |||||
if ("416".equals(code)) { | |||||
errorMsg = "请求范围不符合要求"; | |||||
} else { | |||||
String result = ((HttpStatusCodeException) throwable).getResult(); | |||||
Gson gson = new Gson(); | |||||
ErrorBean response = gson.fromJson(result, ErrorBean.class); | |||||
if (response.getMessage().equals("Your request was made with invalid credentials.")){ | |||||
errorMsg = ""; | |||||
}else { | |||||
errorMsg = response.getMessage(); | |||||
} | |||||
} | |||||
} else if (throwable instanceof JsonSyntaxException) { //请求成功,但Json语法异常,导致解析失败 | |||||
errorMsg = "数据解析失败,请稍后再试"; | |||||
} else if (throwable instanceof ParseException) { // ParseException异常表明请求成功,但是数据不正确 | |||||
String errorCode = throwable.getLocalizedMessage(); | |||||
this.errorCode = Integer.parseInt(errorCode); | |||||
errorMsg = throwable.getMessage(); | |||||
if (TextUtils.isEmpty(errorMsg)) errorMsg = errorCode;//errorMsg为空,显示errorCode | |||||
} else { | |||||
errorMsg = throwable.getMessage(); | |||||
} | |||||
this.errorMsg = errorMsg; | this.errorMsg = errorMsg; | ||||
} | } | ||||
return errorCode; | return errorCode; | ||||
} | } | ||||
public void setErrorCode(int errorCode) { | |||||
this.errorCode = errorCode; | |||||
} | |||||
public String getErrorMsg() { | public String getErrorMsg() { | ||||
return errorMsg; | return errorMsg; | ||||
} | } | ||||
public void setErrorMsg(String errorMsg) { | |||||
this.errorMsg = errorMsg; | |||||
} | |||||
public Throwable getThrowable() { | public Throwable getThrowable() { | ||||
return throwable; | return throwable; | ||||
} | } | ||||
public void setThrowable(Throwable throwable) { | |||||
this.throwable = throwable; | |||||
public boolean show() { | |||||
Tip.show(TextUtils.isEmpty(errorMsg) ? throwable.getMessage() : errorMsg); | |||||
return true; | |||||
} | } | ||||
/** | |||||
* @param standbyMsg 备用的提示文案 | |||||
*/ | |||||
public boolean show(String standbyMsg) { | |||||
Tip.show(TextUtils.isEmpty(errorMsg) ? standbyMsg : errorMsg); | |||||
return true; | |||||
} | |||||
/** | |||||
* @param standbyMsg 备用的提示文案 | |||||
*/ | |||||
public boolean show(int standbyMsg) { | |||||
Tip.show(TextUtils.isEmpty(errorMsg) ? App.getInstance().getString(standbyMsg) : errorMsg); | |||||
return true; | |||||
} | |||||
public String getString(int resId) { | |||||
return App.getInstance().getString(resId); | |||||
} | |||||
// private int errorCode;//仅指服务器返回的错误码 | |||||
// private String errorMsg;//错误文案,网络错误、请求失败错误、服务器返回的错误等 | |||||
// private Throwable throwable;//异常信息 | |||||
// | |||||
// public ErrorInfo(Throwable throwable){ | |||||
// this.throwable = throwable; | |||||
// ExceptionHelper.ResponseException exception = ExceptionHelper.handleException(throwable); | |||||
// String errorMsg = exception.message;//网络异常 | |||||
// this.errorMsg = errorMsg; | |||||
// } | |||||
// | |||||
// public int getErrorCode() { | |||||
// return errorCode; | |||||
// } | |||||
// | |||||
// public void setErrorCode(int errorCode) { | |||||
// this.errorCode = errorCode; | |||||
// } | |||||
// | |||||
// public String getErrorMsg() { | |||||
// return errorMsg; | |||||
// } | |||||
// | |||||
// public void setErrorMsg(String errorMsg) { | |||||
// this.errorMsg = errorMsg; | |||||
// } | |||||
// | |||||
// public Throwable getThrowable() { | |||||
// return throwable; | |||||
// } | |||||
// | |||||
// public void setThrowable(Throwable throwable) { | |||||
// this.throwable = throwable; | |||||
// } | |||||
} | } |
package com.example.tidalairpeisong.rxhttp.error; | package com.example.tidalairpeisong.rxhttp.error; | ||||
import com.google.gson.JsonParseException; | |||||
import org.json.JSONException; | |||||
import java.net.ConnectException; | |||||
import retrofit2.HttpException; | |||||
import rxhttp.wrapper.exception.ParseException; | |||||
import android.content.Context; | |||||
import android.net.ConnectivityManager; | |||||
import android.net.NetworkInfo; | |||||
/** | /** | ||||
* @ClassName ExceptionHelper | * @ClassName ExceptionHelper | ||||
* @Version 1.0 | * @Version 1.0 | ||||
*/ | */ | ||||
public class ExceptionHelper { | public class ExceptionHelper { | ||||
private static final int UNAUTHORIZED = 401; | |||||
private static final int FORBIDDEN = 403; | |||||
private static final int NOT_FOUND = 404; | |||||
private static final int REQUEST_TIMEOUT = 408; | |||||
private static final int INTERNAL_SERVER_ERROR = 500; | |||||
private static final int BAD_GATEWAY = 502; | |||||
private static final int SERVICE_UNAVAILABLE = 503; | |||||
private static final int GATEWAY_TIMEOUT = 504; | |||||
public static ResponseException handleException(Throwable e){ | |||||
//转换成ResponseException,根据状态码判定错误信息 | |||||
ResponseException ex; | |||||
if(e instanceof HttpException){ | |||||
HttpException httpException=(HttpException)e; | |||||
/**0 | |||||
* 传入状态码,根据状态码判定错误信息 | |||||
*/ | |||||
ex=new ResponseException(e,ERROR.HTTP_ERROR); | |||||
switch (httpException.code()){ | |||||
case UNAUTHORIZED: | |||||
case FORBIDDEN: | |||||
case NOT_FOUND: | |||||
case REQUEST_TIMEOUT: | |||||
case GATEWAY_TIMEOUT: | |||||
case INTERNAL_SERVER_ERROR: | |||||
case BAD_GATEWAY: | |||||
case SERVICE_UNAVAILABLE: | |||||
default: | |||||
ex.message = "网络错误"; | |||||
break; | |||||
@SuppressWarnings("deprecation") | |||||
public static boolean isNetworkConnected(Context context) { | |||||
if (context != null) { | |||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |||||
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); | |||||
if (mNetworkInfo != null) { | |||||
return mNetworkInfo.isAvailable(); | |||||
} | } | ||||
return ex; | |||||
} else if (e instanceof ServerException) { | |||||
ServerException resultException = (ServerException) e; | |||||
ex = new ResponseException(resultException, resultException.code); | |||||
ex.message = resultException.message; | |||||
return ex; | |||||
} else if(e instanceof JsonParseException | |||||
|| e instanceof JSONException | |||||
|| e instanceof ParseException){ | |||||
ex=new ResponseException(e,ERROR.PARSE_ERROR); | |||||
ex.message="解析错误"; | |||||
return ex; | |||||
}else if(e instanceof ConnectException){ | |||||
ex=new ResponseException(e,ERROR.NETWORD_ERROR); | |||||
ex.message="连接失败"; | |||||
return ex; | |||||
}else if(e instanceof javax.net.ssl.SSLHandshakeException){ | |||||
ex=new ResponseException(e,ERROR.SSL_ERROR); | |||||
ex.message="证书验证失败"; | |||||
return ex; | |||||
}else { | |||||
ex=new ResponseException(e,ERROR.UNKNOWN); | |||||
ex.message="未知错误"; | |||||
return ex; | |||||
} | |||||
} | |||||
/** | |||||
* 约定异常 | |||||
*/ | |||||
public static class ERROR{ | |||||
/** | |||||
* 自定义异常 | |||||
*/ | |||||
private static final int UNAUTHORIZED = 401;//请求用户进行身份验证 | |||||
private static final int UNREQUEST=403;//服务器理解请求客户端的请求,但是拒绝执行此请求 | |||||
private static final int UNFINDSOURCE=404;//服务器无法根据客户端的请求找到资源 | |||||
private static final int SEVERERROR=500;//服务器内部错误,无法完成请求。 | |||||
/** | |||||
* 协议出错 | |||||
*/ | |||||
public static final int HTTP_ERROR = 1003; | |||||
/** | |||||
* 未知错误 | |||||
*/ | |||||
public static final int UNKNOWN = 1000; | |||||
/** | |||||
* 解析错误 | |||||
*/ | |||||
public static final int PARSE_ERROR = 1001; | |||||
/** | |||||
* 网络错误 | |||||
*/ | |||||
public static final int NETWORD_ERROR = 1002; | |||||
/** | |||||
* 证书出错 | |||||
*/ | |||||
public static final int SSL_ERROR = 1005; | |||||
} | |||||
/** | |||||
* 自定义Throwable | |||||
*/ | |||||
public static class ResponseThrowable extends Exception{ | |||||
public int code; | |||||
public String message; | |||||
public ResponseThrowable(Throwable throwable,int code){ | |||||
super(throwable); | |||||
this.code=code; | |||||
} | } | ||||
} | |||||
/** | |||||
* 服务器异常 | |||||
*/ | |||||
public class ServerException extends RuntimeException{ | |||||
public int code; | |||||
public String message; | |||||
} | |||||
/** | |||||
* 统一异常类,便于处理 | |||||
*/ | |||||
public static class ResponseException extends Exception{ | |||||
public int code; | |||||
public String message; | |||||
public ResponseException (Throwable throwable,int code){ | |||||
super(throwable); | |||||
this.code=code; | |||||
} | |||||
return false; | |||||
} | } | ||||
// private static final int UNAUTHORIZED = 401; | |||||
// private static final int FORBIDDEN = 403; | |||||
// private static final int NOT_FOUND = 404; | |||||
// private static final int REQUEST_TIMEOUT = 408; | |||||
// private static final int INTERNAL_SERVER_ERROR = 500; | |||||
// private static final int BAD_GATEWAY = 502; | |||||
// private static final int SERVICE_UNAVAILABLE = 503; | |||||
// private static final int GATEWAY_TIMEOUT = 504; | |||||
// | |||||
// public static ResponseException handleException(Throwable e){ | |||||
// //转换成ResponseException,根据状态码判定错误信息 | |||||
// ResponseException ex; | |||||
// if(e instanceof HttpException){ | |||||
// HttpException httpException=(HttpException)e; | |||||
// /**0 | |||||
// * 传入状态码,根据状态码判定错误信息 | |||||
// */ | |||||
// ex=new ResponseException(e,ERROR.HTTP_ERROR); | |||||
// switch (httpException.code()){ | |||||
// case UNAUTHORIZED: | |||||
// case FORBIDDEN: | |||||
// case NOT_FOUND: | |||||
// case REQUEST_TIMEOUT: | |||||
// case GATEWAY_TIMEOUT: | |||||
// case INTERNAL_SERVER_ERROR: | |||||
// case BAD_GATEWAY: | |||||
// case SERVICE_UNAVAILABLE: | |||||
// default: | |||||
// ex.message = "网络错误"; | |||||
// break; | |||||
// } | |||||
// return ex; | |||||
// } else if (e instanceof ServerException) { | |||||
// ServerException resultException = (ServerException) e; | |||||
// ex = new ResponseException(resultException, resultException.code); | |||||
// ex.message = resultException.message; | |||||
// return ex; | |||||
// } else if(e instanceof JsonParseException | |||||
// || e instanceof JSONException | |||||
// || e instanceof ParseException){ | |||||
// ex=new ResponseException(e,ERROR.PARSE_ERROR); | |||||
// ex.message="解析错误"; | |||||
// return ex; | |||||
// }else if(e instanceof ConnectException){ | |||||
// ex=new ResponseException(e,ERROR.NETWORD_ERROR); | |||||
// ex.message="连接失败"; | |||||
// return ex; | |||||
// }else if(e instanceof javax.net.ssl.SSLHandshakeException){ | |||||
// ex=new ResponseException(e,ERROR.SSL_ERROR); | |||||
// ex.message="证书验证失败"; | |||||
// return ex; | |||||
// }else { | |||||
// ex=new ResponseException(e,ERROR.UNKNOWN); | |||||
// ex.message="未知错误"; | |||||
// return ex; | |||||
// } | |||||
// } | |||||
// /** | |||||
// * 约定异常 | |||||
// */ | |||||
// public static class ERROR{ | |||||
// /** | |||||
// * 自定义异常 | |||||
// */ | |||||
// private static final int UNAUTHORIZED = 401;//请求用户进行身份验证 | |||||
// private static final int UNREQUEST=403;//服务器理解请求客户端的请求,但是拒绝执行此请求 | |||||
// private static final int UNFINDSOURCE=404;//服务器无法根据客户端的请求找到资源 | |||||
// private static final int SEVERERROR=500;//服务器内部错误,无法完成请求。 | |||||
// /** | |||||
// * 协议出错 | |||||
// */ | |||||
// public static final int HTTP_ERROR = 1003; | |||||
// /** | |||||
// * 未知错误 | |||||
// */ | |||||
// public static final int UNKNOWN = 1000; | |||||
// /** | |||||
// * 解析错误 | |||||
// */ | |||||
// public static final int PARSE_ERROR = 1001; | |||||
// /** | |||||
// * 网络错误 | |||||
// */ | |||||
// public static final int NETWORD_ERROR = 1002; | |||||
// /** | |||||
// * 证书出错 | |||||
// */ | |||||
// public static final int SSL_ERROR = 1005; | |||||
// } | |||||
// /** | |||||
// * 自定义Throwable | |||||
// */ | |||||
// public static class ResponseThrowable extends Exception{ | |||||
// public int code; | |||||
// public String message; | |||||
// public ResponseThrowable(Throwable throwable,int code){ | |||||
// super(throwable); | |||||
// this.code=code; | |||||
// } | |||||
// } | |||||
// /** | |||||
// * 服务器异常 | |||||
// */ | |||||
// public class ServerException extends RuntimeException{ | |||||
// public int code; | |||||
// public String message; | |||||
// } | |||||
// | |||||
// /** | |||||
// * 统一异常类,便于处理 | |||||
// */ | |||||
// public static class ResponseException extends Exception{ | |||||
// public int code; | |||||
// public String message; | |||||
// public ResponseException (Throwable throwable,int code){ | |||||
// super(throwable); | |||||
// this.code=code; | |||||
// } | |||||
// } | |||||
} | } |
package com.example.tidalairpeisong.rxhttp.error; | |||||
import android.content.Context; | |||||
import android.widget.Toast; | |||||
/** | |||||
* @ClassName ErrorInfo | |||||
* @Description TODO | |||||
* @Antuor Administrator | |||||
* @Date 2021/10/11 | |||||
* @Version 1.0 | |||||
*/ | |||||
public class NetWorkError { | |||||
public static void error(Context context,Throwable e){ | |||||
ExceptionHelper.ResponseException exception = ExceptionHelper.handleException(e); | |||||
switch (exception.code) { | |||||
case ExceptionHelper.ERROR.UNKNOWN: | |||||
case ExceptionHelper.ERROR.PARSE_ERROR: | |||||
case ExceptionHelper.ERROR.NETWORD_ERROR: | |||||
case ExceptionHelper.ERROR.HTTP_ERROR: | |||||
case ExceptionHelper.ERROR.SSL_ERROR: | |||||
Toast.makeText(context, exception.message, Toast.LENGTH_SHORT).show(); | |||||
break; | |||||
case -1: | |||||
// 跳转到登陆页面 | |||||
break; | |||||
default: | |||||
Toast.makeText(context, exception.message, Toast.LENGTH_SHORT).show(); | |||||
break; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.rxhttp.interceptor; | package com.example.tidalairpeisong.rxhttp.interceptor; | ||||
import android.content.Intent; | |||||
import android.util.Log; | |||||
import com.example.tidalairpeisong.App; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.user.bean.RefreshTokenBean; | |||||
import com.example.tidalairpeisong.utils.EmptyUtils; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import com.google.gson.Gson; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
//token刷新时间 | //token刷新时间 | ||||
private static volatile long SESSION_KEY_REFRESH_TIME = 0; | private static volatile long SESSION_KEY_REFRESH_TIME = 0; | ||||
private static final String TAG = "csdRxHttp"; | |||||
private boolean success = false; | |||||
@Override | @Override | ||||
public Response intercept(Chain chain) throws IOException { | public Response intercept(Chain chain) throws IOException { | ||||
Request request = chain.request(); | Request request = chain.request(); | ||||
Response originalResponse = chain.proceed(request); | Response originalResponse = chain.proceed(request); | ||||
String code = originalResponse.header("token_code"); | |||||
if ("-1".equals(code)) { //token 失效 1、这里根据自己的业务需求写判断条件 | |||||
return handleTokenInvalid(chain, request); | |||||
String code = String.valueOf(originalResponse.code()); | |||||
//Logger.e("csdRefresh","code = "+code); | |||||
if ("401".equals(code)){//token失效 | |||||
Log.e(TAG,"token失效"); | |||||
originalResponse.close(); | |||||
return handleTokenInvalid(chain,request); | |||||
} | |||||
if ("400".equals(code)){ | |||||
String is_refresh = PrefUtils.getString(App.getInstance(), "is_refresh", "false"); | |||||
Log.e(TAG,"400 刷新失败"+is_refresh); | |||||
if (is_refresh.equals("true")){ | |||||
//refreshToken2(); | |||||
}else { | |||||
PrefUtils.putString(App.getInstance(),"is_refresh","false"); | |||||
Intent intent = new Intent("OffLine"); | |||||
App.getInstance().sendBroadcast(intent); | |||||
} | |||||
} | } | ||||
return originalResponse; | return originalResponse; | ||||
} | } | ||||
private Response handleTokenInvalid(Chain chain, Request request) throws IOException { | private Response handleTokenInvalid(Chain chain, Request request) throws IOException { | ||||
HashMap<String, String> mapParam = new HashMap<>(); | HashMap<String, String> mapParam = new HashMap<>(); | ||||
RequestBody body = request.body(); | RequestBody body = request.body(); | ||||
if (body instanceof FormBody) { | |||||
String method = request.method(); | |||||
if (body instanceof FormBody){ | |||||
FormBody formBody = (FormBody) body; | FormBody formBody = (FormBody) body; | ||||
for (int i = 0; i < formBody.size(); i++) { | |||||
mapParam.put(formBody.name(i), formBody.value(i)); //2、保存参数 | |||||
for (int i = 0; i < formBody.size(); i++){ | |||||
Log.e(TAG,formBody.name(i)+"----"+formBody.value(i)); | |||||
mapParam.put(formBody.name(i),formBody.value(i)); | |||||
} | } | ||||
} | } | ||||
Request newRequest = null; | |||||
//同步刷新token | //同步刷新token | ||||
String requestTime = mapParam.get("request_time"); //3、发请求前需要add("request_time",System.currentTimeMillis()) | |||||
boolean success = refreshToken(requestTime); | |||||
Request newRequest; | |||||
if (success) { //刷新成功,重新签名 | |||||
//mapParam.put("token", User.get().getToken()); //4、拿到最新的token,重新发起请求 | |||||
newRequest = RxHttp.postForm(request.url().toString()) | |||||
.addAll(mapParam) //添加参数 | |||||
.buildRequest(); | |||||
} else { | |||||
success = refreshToken(); | |||||
if (success){//刷新成功,重新签名 | |||||
Log.e(TAG,"刷新成功,重新签名"); | |||||
PrefUtils.putString(App.getInstance(),"is_refresh","true"); | |||||
String access_token = PrefUtils.getString(App.getInstance(), "access_token", ""); | |||||
chain.proceed(request).close(); | |||||
if (method.equals("GET")) { | |||||
newRequest = RxHttp.get(request.url().toString()) | |||||
.addHeader("x-api-key",access_token) | |||||
.addAll(mapParam) | |||||
.buildRequest(); | |||||
}else if (method.equals("POST")){ | |||||
newRequest = RxHttp.postForm(request.url().toString()) | |||||
.addHeader("x-api-key",access_token) | |||||
.addAll(mapParam) | |||||
.buildRequest(); | |||||
} | |||||
}else { | |||||
// String is_refresh = PrefUtils.getString(App.getInstance(), "is_refresh", "false"); | |||||
// Log.e(TAG,"刷新失败"+is_refresh); | |||||
// if (is_refresh.equals("true")){ | |||||
// String access_token = PrefUtils.getString(App.getInstance(), "access_token", ""); | |||||
// if (method.equals("GET")) { | |||||
// newRequest = RxHttp.get(request.url().toString()) | |||||
// .addHeader("x-api-key",access_token) | |||||
// .addAll(mapParam) | |||||
// .buildRequest(); | |||||
// }else if (method.equals("POST")){ | |||||
// newRequest = RxHttp.postForm(request.url().toString()) | |||||
// .addHeader("x-api-key",access_token) | |||||
// .addAll(mapParam) | |||||
// .buildRequest(); | |||||
// } | |||||
// }else { | |||||
// PrefUtils.putString(App.getInstance(),"is_refresh","false"); | |||||
// Intent intent = new Intent("OffLine"); | |||||
// App.getInstance().sendBroadcast(intent); | |||||
// } | |||||
newRequest = request; | newRequest = request; | ||||
PrefUtils.putString(App.getInstance(),"is_refresh","false"); | |||||
Intent intent = new Intent("OffLine"); | |||||
App.getInstance().sendBroadcast(intent); | |||||
chain.proceed(newRequest).close(); | |||||
} | } | ||||
return chain.proceed(newRequest); | return chain.proceed(newRequest); | ||||
} | } | ||||
//刷新token | |||||
private boolean refreshToken(Object value) { | |||||
long requestTime = 0; | |||||
try { | |||||
requestTime = Integer.parseInt(value.toString()); | |||||
} catch (Exception ignore) { | |||||
} | |||||
//请求时间小于token刷新时间,说明token已经刷新,则无需再次刷新 | |||||
if (requestTime <= SESSION_KEY_REFRESH_TIME) return true; | |||||
synchronized (this) { | |||||
//再次判断是否已经刷新 | |||||
if (requestTime <= SESSION_KEY_REFRESH_TIME) return true; | |||||
try { | |||||
//获取到最新的token,这里需要同步请求token,千万不能异步 5、根据自己的业务修改 | |||||
String token = RxHttp.postForm("/refreshToken/...") | |||||
.execute(SimpleParser.get(String.class)); | |||||
private boolean refreshToken() { | |||||
String access_token = PrefUtils.getString(App.getInstance(), "access_token", ""); | |||||
String refresh_token = PrefUtils.getString(App.getInstance(), "refresh_token", ""); | |||||
String expiration_time = PrefUtils.getString(App.getInstance(), "expiration_time", ""); | |||||
String user_type = PrefUtils.getString(App.getInstance(), "user_type", ""); | |||||
if (EmptyUtils.isStringNotEmpty(access_token)){ | |||||
SESSION_KEY_REFRESH_TIME = System.currentTimeMillis() / 1000; | |||||
//User.get().setToken(token); //保存最新的token | |||||
return true; | |||||
} catch (IOException e) { | |||||
String[] split = access_token.split("_"); | |||||
//获取token时间 | |||||
long startTime = Long.valueOf(split[split.length - 1]); | |||||
//当前时间 | |||||
long currentTime = System.currentTimeMillis() / 1000; | |||||
Log.e("csdRefresh1","access_token = "+access_token+"---refresh_token ="+ refresh_token+"---expiration_time ="+ expiration_time+"---"+(currentTime - startTime)); | |||||
//请求时间小于token刷新时间,说明token已经刷新,则无需再次刷新 | |||||
/*if ((currentTime - startTime) > Long.valueOf(expiration_time)) { | |||||
Intent intent = new Intent("OffLine"); | |||||
MyApp.getInstance().sendBroadcast(intent); | |||||
return false; | return false; | ||||
}*/ | |||||
synchronized (this){ | |||||
try { | |||||
//获取到最新的token,这里需要同步请求token,千万不能异步 5、根据自己的业务修改 | |||||
String string = RxHttp.postForm(Api.refresh) | |||||
.add("refresh_token", refresh_token) | |||||
.add("group", "tinyShopApp") | |||||
.execute(SimpleParser.get(String.class)); | |||||
Gson gson = new Gson(); | |||||
RefreshTokenBean bean = gson.fromJson(string, RefreshTokenBean.class); | |||||
RefreshTokenBean.DataBean data = bean.getData(); | |||||
PrefUtils.putString(App.getInstance(),"refresh_token",data.getRefresh_token()); | |||||
PrefUtils.putString(App.getInstance(),"access_token",data.getAccess_token()); | |||||
PrefUtils.putString(App.getInstance(),"member_id",data.getMember().getId()+""); | |||||
PrefUtils.putString(App.getInstance(),"user_type","user"); | |||||
PrefUtils.putString(App.getInstance(),"phone",data.getMember().getMobile()); | |||||
PrefUtils.putString(App.getInstance(),"expiration_time",data.getExpiration_time()+""); | |||||
return true; | |||||
} catch (IOException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | } | ||||
}else { | |||||
Intent intent = new Intent("OffLine"); | |||||
App.getInstance().sendBroadcast(intent); | |||||
} | } | ||||
return false; | |||||
} | } | ||||
} | } |
import android.app.Application; | import android.app.Application; | ||||
import com.example.tidalairpeisong.App; | |||||
import com.example.tidalairpeisong.BuildConfig; | import com.example.tidalairpeisong.BuildConfig; | ||||
import com.example.tidalairpeisong.rxhttp.interceptor.InterceptorUtil; | import com.example.tidalairpeisong.rxhttp.interceptor.InterceptorUtil; | ||||
import com.example.tidalairpeisong.rxhttp.interceptor.TokenInterceptor; | import com.example.tidalairpeisong.rxhttp.interceptor.TokenInterceptor; | ||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import java.io.File; | import java.io.File; | ||||
import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||
.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) //添加信任证书 | .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) //添加信任证书 | ||||
.hostnameVerifier((hostname, session) -> true) //忽略host验证 | .hostnameVerifier((hostname, session) -> true) //忽略host验证 | ||||
// .followRedirects(false) //禁制OkHttp的重定向操作,我们自己处理重定向 | // .followRedirects(false) //禁制OkHttp的重定向操作,我们自己处理重定向 | ||||
.addInterceptor(InterceptorUtil.logInterceptor()) | |||||
.addInterceptor(new TokenInterceptor()) | |||||
.addInterceptor(InterceptorUtil.logInterceptor()) | |||||
.addInterceptor(new TokenInterceptor()) | |||||
.build(); | .build(); | ||||
//设置缓存策略,非必须 | //设置缓存策略,非必须 | ||||
} | } | ||||
return p.add("versionName", "1.0.0")//添加公共参数 | return p.add("versionName", "1.0.0")//添加公共参数 | ||||
.add("time", System.currentTimeMillis()) | .add("time", System.currentTimeMillis()) | ||||
.addHeader("deviceType", "android"); //添加公共请求头 | |||||
.addHeader("deviceType", "android") | |||||
.add("access-token", PrefUtils.getString(App.getInstance(),"access_token","")); //添加公共请求头 | |||||
}); | }); | ||||
} | } | ||||
} | } |
* @Version 1.0 | * @Version 1.0 | ||||
*/ | */ | ||||
public interface Api { | public interface Api { | ||||
/** | |||||
* 密码注册 | |||||
* */ | |||||
String register = "/tiny-shop/v1/site/register"; | |||||
/** | |||||
* 密码重置 | |||||
* */ | |||||
String up_pwd = "/tiny-shop/v1/site/up-pwd"; | |||||
/** | |||||
* 密码登录 | |||||
* */ | |||||
String login = "/tiny-shop/v1/site/login"; | |||||
/** | |||||
* 获取手机验证码 | |||||
* */ | |||||
String sms_dode = "/tiny-shop/v1/site/sms-code"; | |||||
/** | |||||
* 手机号码登录 | |||||
* */ | |||||
String mobile_login = "/tiny-shop/v1/site/mobile-login"; | |||||
/** | |||||
* 退出登录 | |||||
* */ | |||||
String login_out = "/tiny-shop/v1/site/logout"; | |||||
/** | |||||
* 重置令牌 | |||||
* */ | |||||
String refresh = "/tiny-shop/v1/site/refresh"; | |||||
/** | |||||
* 登录令牌有效性检测 | |||||
* */ | |||||
String verify_access_token = "/tiny-shop/v1/site/verify-access-token"; | |||||
/** | |||||
* 个人信息 | |||||
* */ | |||||
String member_info = "/tiny-shop/v1/member/member/index"; | |||||
/** | |||||
* 地址列表 | |||||
* */ | |||||
String address_list = "/tiny-shop/v1/member/address/index"; | |||||
/** | |||||
* 楼层列表 | |||||
* */ | |||||
String floor_list = "/tiny-shop/v1/common/floor/index"; | |||||
/** | /** | ||||
* 版本更新 | |||||
* 创建地址 | |||||
* */ | * */ | ||||
String version = "/app-versions/versions/index"; | |||||
String create_address = "/tiny-shop/v1/member/address/create"; | |||||
/** | /** | ||||
* 商城产品列表 | |||||
* 地址详情 | |||||
* */ | * */ | ||||
String mall_products = "/tiny-shop/v1/product/product/index"; | |||||
String address_detail = "/tiny-shop/v1/member/address/view"; | |||||
/** | |||||
* 删除地址 | |||||
* */ | |||||
String delete_address = "/tiny-shop/v1/member/address/delete"; | |||||
/** | |||||
* 修改地址 | |||||
* */ | |||||
String update_address = "/tiny-shop/v1/member/address/update"; | |||||
/** | |||||
* 商家列表 | |||||
* */ | |||||
String merchant_list = "/tiny-shop/v1/merchant/merchant/index"; | |||||
/** | |||||
* 商家详情 | |||||
* */ | |||||
String merchant_detail = "/tiny-shop/v1/merchant/merchant/view"; | |||||
/** | |||||
* 订气列表 | |||||
* */ | |||||
String gas_list = "/tiny-shop/v1/product/gas/index"; | |||||
/** | |||||
* 订单预览 | |||||
* */ | |||||
String order_preview = "/tiny-shop/v1/order/order/preview"; | |||||
/** | |||||
* 运费计算 | |||||
* */ | |||||
String freight_fee = "/tiny-shop/v1/order/order/freight-fee"; | |||||
/** | |||||
* 下单 | |||||
* */ | |||||
String create_order = "/tiny-shop/v1/order/order/create"; | |||||
/*** | |||||
* 首页 | |||||
* */ | |||||
String index = "/tiny-shop/v1/index/index"; | |||||
/** | |||||
* 删除订单 | |||||
* */ | |||||
String delete_order = "/tiny-shop/v1/member/order/delete"; | |||||
/**I | |||||
* 订单列表 | |||||
* */ | |||||
String order_list = "/tiny-shop/v1/member/order/index"; | |||||
/** | |||||
* 订单详情 | |||||
* */ | |||||
String order_detail = "/tiny-shop/v1/member/order/view"; | |||||
} | } |
import rxhttp.wrapper.annotation.DefaultDomain; | import rxhttp.wrapper.annotation.DefaultDomain; | ||||
public class BaseUrl { | public class BaseUrl { | ||||
//测试地址:http://dev.gas888.com/api/ | |||||
//测试地址:https://tidal-air.yllook.com/api | |||||
//正式地址:http://new.gas888.com/api/ | //正式地址:http://new.gas888.com/api/ | ||||
@DefaultDomain | @DefaultDomain | ||||
public static String baseUrl = "http://new.gas888.com/api"; | |||||
public static String baseUrl = "https://tidal-air.yllook.com/api"; | |||||
} | } |
package com.example.tidalairpeisong.user.adapter; | |||||
import android.view.View; | |||||
import com.chad.library.adapter.base.BaseQuickAdapter; | |||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder; | |||||
import org.jetbrains.annotations.NotNull; | |||||
import org.jetbrains.annotations.Nullable; | |||||
import java.util.List; | |||||
import butterknife.ButterKnife; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalairpeisong.user.adapter | |||||
* @ClassName: OrderAdapter | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/11/3 22:33 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class RvOrderAdapter extends BaseQuickAdapter<String,RvOrderAdapter.ViewHolder> { | |||||
private OnItemMoreListener onItemMoreListener; | |||||
public void setOnItemMoreListener(OnItemMoreListener onItemMoreListener) { | |||||
this.onItemMoreListener = onItemMoreListener; | |||||
} | |||||
public interface OnItemMoreListener { | |||||
} | |||||
public RvOrderAdapter(int layoutResId) { | |||||
super(layoutResId); | |||||
} | |||||
public RvOrderAdapter(int layoutResId, @Nullable List<String> data) { | |||||
super(layoutResId, data); | |||||
} | |||||
@Override | |||||
protected void convert(@NotNull ViewHolder viewHolder, String s) { | |||||
} | |||||
public class ViewHolder extends BaseViewHolder { | |||||
public ViewHolder(@NotNull View view) { | |||||
super(view); | |||||
ButterKnife.bind(this,view); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.adapter; | |||||
import androidx.fragment.app.Fragment; | |||||
import androidx.fragment.app.FragmentManager; | |||||
import androidx.fragment.app.FragmentPagerAdapter; | |||||
import com.example.tidalairpeisong.base.BaseFragment; | |||||
import java.util.List; | |||||
public class TabFragmentAdapter extends FragmentPagerAdapter { | |||||
private List<BaseFragment> list; | |||||
private String[] tabs; | |||||
public TabFragmentAdapter(FragmentManager fm) { | |||||
super(fm); | |||||
} | |||||
public TabFragmentAdapter(FragmentManager fm, List<BaseFragment> list, String[] tabs) { | |||||
super(fm); | |||||
this.list = list; | |||||
this.tabs = tabs; | |||||
} | |||||
@Override | |||||
public Fragment getItem(int position) { | |||||
return list.get(position); | |||||
} | |||||
@Override | |||||
public int getCount() { | |||||
return list.size(); | |||||
} | |||||
@Override | |||||
public CharSequence getPageTitle(int position) { | |||||
return tabs[position]; | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.bean; | |||||
/** | |||||
* @ClassName MallProductBean | |||||
* @Antuor Administrator | |||||
* @Date 2021/10/11 | |||||
* @Version 1.0 | |||||
*/ | |||||
public class MallProductBean { | |||||
private String id; | |||||
private String name; | |||||
private String sketch; | |||||
private String keywords; | |||||
private String picture; | |||||
private String view; | |||||
private String match_point; | |||||
private String price; | |||||
private String market_price; | |||||
private String cost_price; | |||||
private String stock; | |||||
private Integer sales; | |||||
private String merchant_id; | |||||
private String is_open_presell; | |||||
private String is_open_commission; | |||||
private String point_exchange_type; | |||||
private String point_exchange; | |||||
private String max_use_point; | |||||
private String integral_give_type; | |||||
private String give_point; | |||||
private Object merchant; | |||||
private Integer commissionRate; | |||||
public String getId() { | |||||
return id; | |||||
} | |||||
public void setId(String id) { | |||||
this.id = id; | |||||
} | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public void setName(String name) { | |||||
this.name = name; | |||||
} | |||||
public String getSketch() { | |||||
return sketch; | |||||
} | |||||
public void setSketch(String sketch) { | |||||
this.sketch = sketch; | |||||
} | |||||
public String getKeywords() { | |||||
return keywords; | |||||
} | |||||
public void setKeywords(String keywords) { | |||||
this.keywords = keywords; | |||||
} | |||||
public String getPicture() { | |||||
return picture; | |||||
} | |||||
public void setPicture(String picture) { | |||||
this.picture = picture; | |||||
} | |||||
public String getView() { | |||||
return view; | |||||
} | |||||
public void setView(String view) { | |||||
this.view = view; | |||||
} | |||||
public String getMatch_point() { | |||||
return match_point; | |||||
} | |||||
public void setMatch_point(String match_point) { | |||||
this.match_point = match_point; | |||||
} | |||||
public String getPrice() { | |||||
return price; | |||||
} | |||||
public void setPrice(String price) { | |||||
this.price = price; | |||||
} | |||||
public String getMarket_price() { | |||||
return market_price; | |||||
} | |||||
public void setMarket_price(String market_price) { | |||||
this.market_price = market_price; | |||||
} | |||||
public String getCost_price() { | |||||
return cost_price; | |||||
} | |||||
public void setCost_price(String cost_price) { | |||||
this.cost_price = cost_price; | |||||
} | |||||
public String getStock() { | |||||
return stock; | |||||
} | |||||
public void setStock(String stock) { | |||||
this.stock = stock; | |||||
} | |||||
public Integer getSales() { | |||||
return sales; | |||||
} | |||||
public void setSales(Integer sales) { | |||||
this.sales = sales; | |||||
} | |||||
public String getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(String merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getIs_open_presell() { | |||||
return is_open_presell; | |||||
} | |||||
public void setIs_open_presell(String is_open_presell) { | |||||
this.is_open_presell = is_open_presell; | |||||
} | |||||
public String getIs_open_commission() { | |||||
return is_open_commission; | |||||
} | |||||
public void setIs_open_commission(String is_open_commission) { | |||||
this.is_open_commission = is_open_commission; | |||||
} | |||||
public String getPoint_exchange_type() { | |||||
return point_exchange_type; | |||||
} | |||||
public void setPoint_exchange_type(String point_exchange_type) { | |||||
this.point_exchange_type = point_exchange_type; | |||||
} | |||||
public String getPoint_exchange() { | |||||
return point_exchange; | |||||
} | |||||
public void setPoint_exchange(String point_exchange) { | |||||
this.point_exchange = point_exchange; | |||||
} | |||||
public String getMax_use_point() { | |||||
return max_use_point; | |||||
} | |||||
public void setMax_use_point(String max_use_point) { | |||||
this.max_use_point = max_use_point; | |||||
} | |||||
public String getIntegral_give_type() { | |||||
return integral_give_type; | |||||
} | |||||
public void setIntegral_give_type(String integral_give_type) { | |||||
this.integral_give_type = integral_give_type; | |||||
} | |||||
public String getGive_point() { | |||||
return give_point; | |||||
} | |||||
public void setGive_point(String give_point) { | |||||
this.give_point = give_point; | |||||
} | |||||
public Object getMerchant() { | |||||
return merchant; | |||||
} | |||||
public void setMerchant(Object merchant) { | |||||
this.merchant = merchant; | |||||
} | |||||
public Integer getCommissionRate() { | |||||
return commissionRate; | |||||
} | |||||
public void setCommissionRate(Integer commissionRate) { | |||||
this.commissionRate = commissionRate; | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.bean; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.user.bean | |||||
* @ClassName: MemberBean | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/30 12:51 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class MemberBean { | |||||
private String id; | |||||
private String merchant_id; | |||||
private String username; | |||||
private String password_hash; | |||||
private String auth_key; | |||||
private String mobile_reset_token; | |||||
private String password_reset_token; | |||||
private String type; | |||||
private String nickname; | |||||
private String realname; | |||||
private String head_portrait; | |||||
private String current_level; | |||||
private String level_expiration_time; | |||||
private String level_buy_type; | |||||
private String gender; | |||||
private String qq; | |||||
private String email; | |||||
private Object birthday; | |||||
private String visit_count; | |||||
private String home_phone; | |||||
private String mobile; | |||||
private String role; | |||||
private String last_time; | |||||
private String last_ip; | |||||
private String province_id; | |||||
private String city_id; | |||||
private String area_id; | |||||
private String pid; | |||||
private String level; | |||||
private String promo_code; | |||||
private String tree; | |||||
private String status; | |||||
private String created_at; | |||||
private String updated_at; | |||||
private AccountBean account; | |||||
private Object memberLevel; | |||||
private String coupon_num; | |||||
private String cart_num; | |||||
private String promoter; | |||||
private String is_open_commission; | |||||
private MemberCardBean member_card; | |||||
public String getId() { | |||||
return id; | |||||
} | |||||
public void setId(String id) { | |||||
this.id = id; | |||||
} | |||||
public String getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(String merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getUsername() { | |||||
return username; | |||||
} | |||||
public void setUsername(String username) { | |||||
this.username = username; | |||||
} | |||||
public String getPassword_hash() { | |||||
return password_hash; | |||||
} | |||||
public void setPassword_hash(String password_hash) { | |||||
this.password_hash = password_hash; | |||||
} | |||||
public String getAuth_key() { | |||||
return auth_key; | |||||
} | |||||
public void setAuth_key(String auth_key) { | |||||
this.auth_key = auth_key; | |||||
} | |||||
public String getMobile_reset_token() { | |||||
return mobile_reset_token; | |||||
} | |||||
public void setMobile_reset_token(String mobile_reset_token) { | |||||
this.mobile_reset_token = mobile_reset_token; | |||||
} | |||||
public String getPassword_reset_token() { | |||||
return password_reset_token; | |||||
} | |||||
public void setPassword_reset_token(String password_reset_token) { | |||||
this.password_reset_token = password_reset_token; | |||||
} | |||||
public String getType() { | |||||
return type; | |||||
} | |||||
public void setType(String type) { | |||||
this.type = type; | |||||
} | |||||
public String getNickname() { | |||||
return nickname; | |||||
} | |||||
public void setNickname(String nickname) { | |||||
this.nickname = nickname; | |||||
} | |||||
public String getRealname() { | |||||
return realname; | |||||
} | |||||
public void setRealname(String realname) { | |||||
this.realname = realname; | |||||
} | |||||
public String getHead_portrait() { | |||||
return head_portrait; | |||||
} | |||||
public void setHead_portrait(String head_portrait) { | |||||
this.head_portrait = head_portrait; | |||||
} | |||||
public String getCurrent_level() { | |||||
return current_level; | |||||
} | |||||
public void setCurrent_level(String current_level) { | |||||
this.current_level = current_level; | |||||
} | |||||
public String getLevel_expiration_time() { | |||||
return level_expiration_time; | |||||
} | |||||
public void setLevel_expiration_time(String level_expiration_time) { | |||||
this.level_expiration_time = level_expiration_time; | |||||
} | |||||
public String getLevel_buy_type() { | |||||
return level_buy_type; | |||||
} | |||||
public void setLevel_buy_type(String level_buy_type) { | |||||
this.level_buy_type = level_buy_type; | |||||
} | |||||
public String getGender() { | |||||
return gender; | |||||
} | |||||
public void setGender(String gender) { | |||||
this.gender = gender; | |||||
} | |||||
public String getQq() { | |||||
return qq; | |||||
} | |||||
public void setQq(String qq) { | |||||
this.qq = qq; | |||||
} | |||||
public String getEmail() { | |||||
return email; | |||||
} | |||||
public void setEmail(String email) { | |||||
this.email = email; | |||||
} | |||||
public Object getBirthday() { | |||||
return birthday; | |||||
} | |||||
public void setBirthday(Object birthday) { | |||||
this.birthday = birthday; | |||||
} | |||||
public String getVisit_count() { | |||||
return visit_count; | |||||
} | |||||
public void setVisit_count(String visit_count) { | |||||
this.visit_count = visit_count; | |||||
} | |||||
public String getHome_phone() { | |||||
return home_phone; | |||||
} | |||||
public void setHome_phone(String home_phone) { | |||||
this.home_phone = home_phone; | |||||
} | |||||
public String getMobile() { | |||||
return mobile; | |||||
} | |||||
public void setMobile(String mobile) { | |||||
this.mobile = mobile; | |||||
} | |||||
public String getRole() { | |||||
return role; | |||||
} | |||||
public void setRole(String role) { | |||||
this.role = role; | |||||
} | |||||
public String getLast_time() { | |||||
return last_time; | |||||
} | |||||
public void setLast_time(String last_time) { | |||||
this.last_time = last_time; | |||||
} | |||||
public String getLast_ip() { | |||||
return last_ip; | |||||
} | |||||
public void setLast_ip(String last_ip) { | |||||
this.last_ip = last_ip; | |||||
} | |||||
public String getProvince_id() { | |||||
return province_id; | |||||
} | |||||
public void setProvince_id(String province_id) { | |||||
this.province_id = province_id; | |||||
} | |||||
public String getCity_id() { | |||||
return city_id; | |||||
} | |||||
public void setCity_id(String city_id) { | |||||
this.city_id = city_id; | |||||
} | |||||
public String getArea_id() { | |||||
return area_id; | |||||
} | |||||
public void setArea_id(String area_id) { | |||||
this.area_id = area_id; | |||||
} | |||||
public String getPid() { | |||||
return pid; | |||||
} | |||||
public void setPid(String pid) { | |||||
this.pid = pid; | |||||
} | |||||
public String getLevel() { | |||||
return level; | |||||
} | |||||
public void setLevel(String level) { | |||||
this.level = level; | |||||
} | |||||
public String getPromo_code() { | |||||
return promo_code; | |||||
} | |||||
public void setPromo_code(String promo_code) { | |||||
this.promo_code = promo_code; | |||||
} | |||||
public String getTree() { | |||||
return tree; | |||||
} | |||||
public void setTree(String tree) { | |||||
this.tree = tree; | |||||
} | |||||
public String getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(String status) { | |||||
this.status = status; | |||||
} | |||||
public String getCreated_at() { | |||||
return created_at; | |||||
} | |||||
public void setCreated_at(String created_at) { | |||||
this.created_at = created_at; | |||||
} | |||||
public String getUpdated_at() { | |||||
return updated_at; | |||||
} | |||||
public void setUpdated_at(String updated_at) { | |||||
this.updated_at = updated_at; | |||||
} | |||||
public AccountBean getAccount() { | |||||
return account; | |||||
} | |||||
public void setAccount(AccountBean account) { | |||||
this.account = account; | |||||
} | |||||
public Object getMemberLevel() { | |||||
return memberLevel; | |||||
} | |||||
public void setMemberLevel(Object memberLevel) { | |||||
this.memberLevel = memberLevel; | |||||
} | |||||
public String getCoupon_num() { | |||||
return coupon_num; | |||||
} | |||||
public void setCoupon_num(String coupon_num) { | |||||
this.coupon_num = coupon_num; | |||||
} | |||||
public String getCart_num() { | |||||
return cart_num; | |||||
} | |||||
public void setCart_num(String cart_num) { | |||||
this.cart_num = cart_num; | |||||
} | |||||
public String getPromoter() { | |||||
return promoter; | |||||
} | |||||
public void setPromoter(String promoter) { | |||||
this.promoter = promoter; | |||||
} | |||||
public String getIs_open_commission() { | |||||
return is_open_commission; | |||||
} | |||||
public void setIs_open_commission(String is_open_commission) { | |||||
this.is_open_commission = is_open_commission; | |||||
} | |||||
public MemberCardBean getMember_card() { | |||||
return member_card; | |||||
} | |||||
public void setMember_card(MemberCardBean member_card) { | |||||
this.member_card = member_card; | |||||
} | |||||
public static class AccountBean { | |||||
private String id; | |||||
private String merchant_id; | |||||
private String member_id; | |||||
private String level; | |||||
private String user_money; | |||||
private String accumulate_money; | |||||
private String give_money; | |||||
private String consume_money; | |||||
private String frozen_money; | |||||
private String user_integral; | |||||
private String accumulate_integral; | |||||
private String give_integral; | |||||
private String consume_integral; | |||||
private String frozen_integral; | |||||
private String user_growth; | |||||
private String accumulate_growth; | |||||
private String consume_growth; | |||||
private String frozen_growth; | |||||
private String economize_money; | |||||
private String status; | |||||
public String getId() { | |||||
return id; | |||||
} | |||||
public void setId(String id) { | |||||
this.id = id; | |||||
} | |||||
public String getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(String merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getMember_id() { | |||||
return member_id; | |||||
} | |||||
public void setMember_id(String member_id) { | |||||
this.member_id = member_id; | |||||
} | |||||
public String getLevel() { | |||||
return level; | |||||
} | |||||
public void setLevel(String level) { | |||||
this.level = level; | |||||
} | |||||
public String getUser_money() { | |||||
return user_money; | |||||
} | |||||
public void setUser_money(String user_money) { | |||||
this.user_money = user_money; | |||||
} | |||||
public String getAccumulate_money() { | |||||
return accumulate_money; | |||||
} | |||||
public void setAccumulate_money(String accumulate_money) { | |||||
this.accumulate_money = accumulate_money; | |||||
} | |||||
public String getGive_money() { | |||||
return give_money; | |||||
} | |||||
public void setGive_money(String give_money) { | |||||
this.give_money = give_money; | |||||
} | |||||
public String getConsume_money() { | |||||
return consume_money; | |||||
} | |||||
public void setConsume_money(String consume_money) { | |||||
this.consume_money = consume_money; | |||||
} | |||||
public String getFrozen_money() { | |||||
return frozen_money; | |||||
} | |||||
public void setFrozen_money(String frozen_money) { | |||||
this.frozen_money = frozen_money; | |||||
} | |||||
public String getUser_integral() { | |||||
return user_integral; | |||||
} | |||||
public void setUser_integral(String user_integral) { | |||||
this.user_integral = user_integral; | |||||
} | |||||
public String getAccumulate_integral() { | |||||
return accumulate_integral; | |||||
} | |||||
public void setAccumulate_integral(String accumulate_integral) { | |||||
this.accumulate_integral = accumulate_integral; | |||||
} | |||||
public String getGive_integral() { | |||||
return give_integral; | |||||
} | |||||
public void setGive_integral(String give_integral) { | |||||
this.give_integral = give_integral; | |||||
} | |||||
public String getConsume_integral() { | |||||
return consume_integral; | |||||
} | |||||
public void setConsume_integral(String consume_integral) { | |||||
this.consume_integral = consume_integral; | |||||
} | |||||
public String getFrozen_integral() { | |||||
return frozen_integral; | |||||
} | |||||
public void setFrozen_integral(String frozen_integral) { | |||||
this.frozen_integral = frozen_integral; | |||||
} | |||||
public String getUser_growth() { | |||||
return user_growth; | |||||
} | |||||
public void setUser_growth(String user_growth) { | |||||
this.user_growth = user_growth; | |||||
} | |||||
public String getAccumulate_growth() { | |||||
return accumulate_growth; | |||||
} | |||||
public void setAccumulate_growth(String accumulate_growth) { | |||||
this.accumulate_growth = accumulate_growth; | |||||
} | |||||
public String getConsume_growth() { | |||||
return consume_growth; | |||||
} | |||||
public void setConsume_growth(String consume_growth) { | |||||
this.consume_growth = consume_growth; | |||||
} | |||||
public String getFrozen_growth() { | |||||
return frozen_growth; | |||||
} | |||||
public void setFrozen_growth(String frozen_growth) { | |||||
this.frozen_growth = frozen_growth; | |||||
} | |||||
public String getEconomize_money() { | |||||
return economize_money; | |||||
} | |||||
public void setEconomize_money(String economize_money) { | |||||
this.economize_money = economize_money; | |||||
} | |||||
public String getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(String status) { | |||||
this.status = status; | |||||
} | |||||
} | |||||
public static class MemberCardBean { | |||||
private Integer merchant_id; | |||||
private String economize_money; | |||||
private Integer level; | |||||
private Integer free_shipping; | |||||
private Integer give_time_type; | |||||
private Integer start_time; | |||||
private Integer end_time; | |||||
private String color; | |||||
private Integer status; | |||||
private Integer pay_type; | |||||
private Integer created_at; | |||||
private Integer updated_at; | |||||
public Integer getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(Integer merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getEconomize_money() { | |||||
return economize_money; | |||||
} | |||||
public void setEconomize_money(String economize_money) { | |||||
this.economize_money = economize_money; | |||||
} | |||||
public Integer getLevel() { | |||||
return level; | |||||
} | |||||
public void setLevel(Integer level) { | |||||
this.level = level; | |||||
} | |||||
public Integer getFree_shipping() { | |||||
return free_shipping; | |||||
} | |||||
public void setFree_shipping(Integer free_shipping) { | |||||
this.free_shipping = free_shipping; | |||||
} | |||||
public Integer getGive_time_type() { | |||||
return give_time_type; | |||||
} | |||||
public void setGive_time_type(Integer give_time_type) { | |||||
this.give_time_type = give_time_type; | |||||
} | |||||
public Integer getStart_time() { | |||||
return start_time; | |||||
} | |||||
public void setStart_time(Integer start_time) { | |||||
this.start_time = start_time; | |||||
} | |||||
public Integer getEnd_time() { | |||||
return end_time; | |||||
} | |||||
public void setEnd_time(Integer end_time) { | |||||
this.end_time = end_time; | |||||
} | |||||
public String getColor() { | |||||
return color; | |||||
} | |||||
public void setColor(String color) { | |||||
this.color = color; | |||||
} | |||||
public Integer getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(Integer status) { | |||||
this.status = status; | |||||
} | |||||
public Integer getPay_type() { | |||||
return pay_type; | |||||
} | |||||
public void setPay_type(Integer pay_type) { | |||||
this.pay_type = pay_type; | |||||
} | |||||
public Integer getCreated_at() { | |||||
return created_at; | |||||
} | |||||
public void setCreated_at(Integer created_at) { | |||||
this.created_at = created_at; | |||||
} | |||||
public Integer getUpdated_at() { | |||||
return updated_at; | |||||
} | |||||
public void setUpdated_at(Integer updated_at) { | |||||
this.updated_at = updated_at; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.bean; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.user.bean | |||||
* @ClassName: RefreshBean | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/30 13:17 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class RefreshBean { | |||||
private String refresh_token; | |||||
private String access_token; | |||||
private Integer expiration_time; | |||||
private MemberBean member; | |||||
private String promoter; | |||||
public String getRefresh_token() { | |||||
return refresh_token; | |||||
} | |||||
public void setRefresh_token(String refresh_token) { | |||||
this.refresh_token = refresh_token; | |||||
} | |||||
public String getAccess_token() { | |||||
return access_token; | |||||
} | |||||
public void setAccess_token(String access_token) { | |||||
this.access_token = access_token; | |||||
} | |||||
public Integer getExpiration_time() { | |||||
return expiration_time; | |||||
} | |||||
public void setExpiration_time(Integer expiration_time) { | |||||
this.expiration_time = expiration_time; | |||||
} | |||||
public MemberBean getMember() { | |||||
return member; | |||||
} | |||||
public void setMember(MemberBean member) { | |||||
this.member = member; | |||||
} | |||||
public String getPromoter() { | |||||
return promoter; | |||||
} | |||||
public void setPromoter(String promoter) { | |||||
this.promoter = promoter; | |||||
} | |||||
public static class MemberBean { | |||||
private Integer id; | |||||
private Integer merchant_id; | |||||
private String username; | |||||
private String mobile_reset_token; | |||||
private Integer type; | |||||
private String nickname; | |||||
private Object realname; | |||||
private Object head_portrait; | |||||
private Integer current_level; | |||||
private Integer level_expiration_time; | |||||
private Integer level_buy_type; | |||||
private Integer gender; | |||||
private String qq; | |||||
private String email; | |||||
private Object birthday; | |||||
private Integer visit_count; | |||||
private String home_phone; | |||||
private String mobile; | |||||
private Integer role; | |||||
private Integer last_time; | |||||
private String last_ip; | |||||
private Integer province_id; | |||||
private Integer city_id; | |||||
private Integer area_id; | |||||
private Integer pid; | |||||
private Integer level; | |||||
private String promo_code; | |||||
private String tree; | |||||
private Integer status; | |||||
private Integer created_at; | |||||
private Integer updated_at; | |||||
private AccountBean account; | |||||
private String coupon_num; | |||||
private String cart_num; | |||||
public Integer getId() { | |||||
return id; | |||||
} | |||||
public void setId(Integer id) { | |||||
this.id = id; | |||||
} | |||||
public Integer getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(Integer merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getUsername() { | |||||
return username; | |||||
} | |||||
public void setUsername(String username) { | |||||
this.username = username; | |||||
} | |||||
public String getMobile_reset_token() { | |||||
return mobile_reset_token; | |||||
} | |||||
public void setMobile_reset_token(String mobile_reset_token) { | |||||
this.mobile_reset_token = mobile_reset_token; | |||||
} | |||||
public Integer getType() { | |||||
return type; | |||||
} | |||||
public void setType(Integer type) { | |||||
this.type = type; | |||||
} | |||||
public String getNickname() { | |||||
return nickname; | |||||
} | |||||
public void setNickname(String nickname) { | |||||
this.nickname = nickname; | |||||
} | |||||
public Object getRealname() { | |||||
return realname; | |||||
} | |||||
public void setRealname(Object realname) { | |||||
this.realname = realname; | |||||
} | |||||
public Object getHead_portrait() { | |||||
return head_portrait; | |||||
} | |||||
public void setHead_portrait(Object head_portrait) { | |||||
this.head_portrait = head_portrait; | |||||
} | |||||
public Integer getCurrent_level() { | |||||
return current_level; | |||||
} | |||||
public void setCurrent_level(Integer current_level) { | |||||
this.current_level = current_level; | |||||
} | |||||
public Integer getLevel_expiration_time() { | |||||
return level_expiration_time; | |||||
} | |||||
public void setLevel_expiration_time(Integer level_expiration_time) { | |||||
this.level_expiration_time = level_expiration_time; | |||||
} | |||||
public Integer getLevel_buy_type() { | |||||
return level_buy_type; | |||||
} | |||||
public void setLevel_buy_type(Integer level_buy_type) { | |||||
this.level_buy_type = level_buy_type; | |||||
} | |||||
public Integer getGender() { | |||||
return gender; | |||||
} | |||||
public void setGender(Integer gender) { | |||||
this.gender = gender; | |||||
} | |||||
public String getQq() { | |||||
return qq; | |||||
} | |||||
public void setQq(String qq) { | |||||
this.qq = qq; | |||||
} | |||||
public String getEmail() { | |||||
return email; | |||||
} | |||||
public void setEmail(String email) { | |||||
this.email = email; | |||||
} | |||||
public Object getBirthday() { | |||||
return birthday; | |||||
} | |||||
public void setBirthday(Object birthday) { | |||||
this.birthday = birthday; | |||||
} | |||||
public Integer getVisit_count() { | |||||
return visit_count; | |||||
} | |||||
public void setVisit_count(Integer visit_count) { | |||||
this.visit_count = visit_count; | |||||
} | |||||
public String getHome_phone() { | |||||
return home_phone; | |||||
} | |||||
public void setHome_phone(String home_phone) { | |||||
this.home_phone = home_phone; | |||||
} | |||||
public String getMobile() { | |||||
return mobile; | |||||
} | |||||
public void setMobile(String mobile) { | |||||
this.mobile = mobile; | |||||
} | |||||
public Integer getRole() { | |||||
return role; | |||||
} | |||||
public void setRole(Integer role) { | |||||
this.role = role; | |||||
} | |||||
public Integer getLast_time() { | |||||
return last_time; | |||||
} | |||||
public void setLast_time(Integer last_time) { | |||||
this.last_time = last_time; | |||||
} | |||||
public String getLast_ip() { | |||||
return last_ip; | |||||
} | |||||
public void setLast_ip(String last_ip) { | |||||
this.last_ip = last_ip; | |||||
} | |||||
public Integer getProvince_id() { | |||||
return province_id; | |||||
} | |||||
public void setProvince_id(Integer province_id) { | |||||
this.province_id = province_id; | |||||
} | |||||
public Integer getCity_id() { | |||||
return city_id; | |||||
} | |||||
public void setCity_id(Integer city_id) { | |||||
this.city_id = city_id; | |||||
} | |||||
public Integer getArea_id() { | |||||
return area_id; | |||||
} | |||||
public void setArea_id(Integer area_id) { | |||||
this.area_id = area_id; | |||||
} | |||||
public Integer getPid() { | |||||
return pid; | |||||
} | |||||
public void setPid(Integer pid) { | |||||
this.pid = pid; | |||||
} | |||||
public Integer getLevel() { | |||||
return level; | |||||
} | |||||
public void setLevel(Integer level) { | |||||
this.level = level; | |||||
} | |||||
public String getPromo_code() { | |||||
return promo_code; | |||||
} | |||||
public void setPromo_code(String promo_code) { | |||||
this.promo_code = promo_code; | |||||
} | |||||
public String getTree() { | |||||
return tree; | |||||
} | |||||
public void setTree(String tree) { | |||||
this.tree = tree; | |||||
} | |||||
public Integer getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(Integer status) { | |||||
this.status = status; | |||||
} | |||||
public Integer getCreated_at() { | |||||
return created_at; | |||||
} | |||||
public void setCreated_at(Integer created_at) { | |||||
this.created_at = created_at; | |||||
} | |||||
public Integer getUpdated_at() { | |||||
return updated_at; | |||||
} | |||||
public void setUpdated_at(Integer updated_at) { | |||||
this.updated_at = updated_at; | |||||
} | |||||
public AccountBean getAccount() { | |||||
return account; | |||||
} | |||||
public void setAccount(AccountBean account) { | |||||
this.account = account; | |||||
} | |||||
public String getCoupon_num() { | |||||
return coupon_num; | |||||
} | |||||
public void setCoupon_num(String coupon_num) { | |||||
this.coupon_num = coupon_num; | |||||
} | |||||
public String getCart_num() { | |||||
return cart_num; | |||||
} | |||||
public void setCart_num(String cart_num) { | |||||
this.cart_num = cart_num; | |||||
} | |||||
public static class AccountBean { | |||||
private Integer id; | |||||
private Integer merchant_id; | |||||
private Integer member_id; | |||||
private Integer level; | |||||
private String user_money; | |||||
private String accumulate_money; | |||||
private String give_money; | |||||
private String consume_money; | |||||
private String frozen_money; | |||||
private Integer user_integral; | |||||
private Integer accumulate_integral; | |||||
private Integer give_integral; | |||||
private String consume_integral; | |||||
private Integer frozen_integral; | |||||
private Integer user_growth; | |||||
private Integer accumulate_growth; | |||||
private String consume_growth; | |||||
private String frozen_growth; | |||||
private String economize_money; | |||||
private Integer status; | |||||
public Integer getId() { | |||||
return id; | |||||
} | |||||
public void setId(Integer id) { | |||||
this.id = id; | |||||
} | |||||
public Integer getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(Integer merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public Integer getMember_id() { | |||||
return member_id; | |||||
} | |||||
public void setMember_id(Integer member_id) { | |||||
this.member_id = member_id; | |||||
} | |||||
public Integer getLevel() { | |||||
return level; | |||||
} | |||||
public void setLevel(Integer level) { | |||||
this.level = level; | |||||
} | |||||
public String getUser_money() { | |||||
return user_money; | |||||
} | |||||
public void setUser_money(String user_money) { | |||||
this.user_money = user_money; | |||||
} | |||||
public String getAccumulate_money() { | |||||
return accumulate_money; | |||||
} | |||||
public void setAccumulate_money(String accumulate_money) { | |||||
this.accumulate_money = accumulate_money; | |||||
} | |||||
public String getGive_money() { | |||||
return give_money; | |||||
} | |||||
public void setGive_money(String give_money) { | |||||
this.give_money = give_money; | |||||
} | |||||
public String getConsume_money() { | |||||
return consume_money; | |||||
} | |||||
public void setConsume_money(String consume_money) { | |||||
this.consume_money = consume_money; | |||||
} | |||||
public String getFrozen_money() { | |||||
return frozen_money; | |||||
} | |||||
public void setFrozen_money(String frozen_money) { | |||||
this.frozen_money = frozen_money; | |||||
} | |||||
public Integer getUser_integral() { | |||||
return user_integral; | |||||
} | |||||
public void setUser_integral(Integer user_integral) { | |||||
this.user_integral = user_integral; | |||||
} | |||||
public Integer getAccumulate_integral() { | |||||
return accumulate_integral; | |||||
} | |||||
public void setAccumulate_integral(Integer accumulate_integral) { | |||||
this.accumulate_integral = accumulate_integral; | |||||
} | |||||
public Integer getGive_integral() { | |||||
return give_integral; | |||||
} | |||||
public void setGive_integral(Integer give_integral) { | |||||
this.give_integral = give_integral; | |||||
} | |||||
public String getConsume_integral() { | |||||
return consume_integral; | |||||
} | |||||
public void setConsume_integral(String consume_integral) { | |||||
this.consume_integral = consume_integral; | |||||
} | |||||
public Integer getFrozen_integral() { | |||||
return frozen_integral; | |||||
} | |||||
public void setFrozen_integral(Integer frozen_integral) { | |||||
this.frozen_integral = frozen_integral; | |||||
} | |||||
public Integer getUser_growth() { | |||||
return user_growth; | |||||
} | |||||
public void setUser_growth(Integer user_growth) { | |||||
this.user_growth = user_growth; | |||||
} | |||||
public Integer getAccumulate_growth() { | |||||
return accumulate_growth; | |||||
} | |||||
public void setAccumulate_growth(Integer accumulate_growth) { | |||||
this.accumulate_growth = accumulate_growth; | |||||
} | |||||
public String getConsume_growth() { | |||||
return consume_growth; | |||||
} | |||||
public void setConsume_growth(String consume_growth) { | |||||
this.consume_growth = consume_growth; | |||||
} | |||||
public String getFrozen_growth() { | |||||
return frozen_growth; | |||||
} | |||||
public void setFrozen_growth(String frozen_growth) { | |||||
this.frozen_growth = frozen_growth; | |||||
} | |||||
public String getEconomize_money() { | |||||
return economize_money; | |||||
} | |||||
public void setEconomize_money(String economize_money) { | |||||
this.economize_money = economize_money; | |||||
} | |||||
public Integer getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(Integer status) { | |||||
this.status = status; | |||||
} | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.bean; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.user.bean | |||||
* @ClassName: RefreshTokenBean | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/30 16:29 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class RefreshTokenBean { | |||||
private Integer code; | |||||
private String message; | |||||
private DataBean data; | |||||
private Integer timestamp; | |||||
public Integer getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(Integer code) { | |||||
this.code = code; | |||||
} | |||||
public String getMessage() { | |||||
return message; | |||||
} | |||||
public void setMessage(String message) { | |||||
this.message = message; | |||||
} | |||||
public DataBean getData() { | |||||
return data; | |||||
} | |||||
public void setData(DataBean data) { | |||||
this.data = data; | |||||
} | |||||
public Integer getTimestamp() { | |||||
return timestamp; | |||||
} | |||||
public void setTimestamp(Integer timestamp) { | |||||
this.timestamp = timestamp; | |||||
} | |||||
public static class DataBean { | |||||
private String refresh_token; | |||||
private String access_token; | |||||
private Integer expiration_time; | |||||
private MemberBean member; | |||||
private String promoter; | |||||
public String getRefresh_token() { | |||||
return refresh_token; | |||||
} | |||||
public void setRefresh_token(String refresh_token) { | |||||
this.refresh_token = refresh_token; | |||||
} | |||||
public String getAccess_token() { | |||||
return access_token; | |||||
} | |||||
public void setAccess_token(String access_token) { | |||||
this.access_token = access_token; | |||||
} | |||||
public Integer getExpiration_time() { | |||||
return expiration_time; | |||||
} | |||||
public void setExpiration_time(Integer expiration_time) { | |||||
this.expiration_time = expiration_time; | |||||
} | |||||
public MemberBean getMember() { | |||||
return member; | |||||
} | |||||
public void setMember(MemberBean member) { | |||||
this.member = member; | |||||
} | |||||
public String getPromoter() { | |||||
return promoter; | |||||
} | |||||
public void setPromoter(String promoter) { | |||||
this.promoter = promoter; | |||||
} | |||||
public static class MemberBean { | |||||
private Integer id; | |||||
private Integer merchant_id; | |||||
private String username; | |||||
private String mobile_reset_token; | |||||
private Integer type; | |||||
private String nickname; | |||||
private Object realname; | |||||
private Object head_portrait; | |||||
private Integer current_level; | |||||
private Integer level_expiration_time; | |||||
private Integer level_buy_type; | |||||
private Integer gender; | |||||
private String qq; | |||||
private String email; | |||||
private Object birthday; | |||||
private Integer visit_count; | |||||
private String home_phone; | |||||
private String mobile; | |||||
private Integer role; | |||||
private Integer last_time; | |||||
private String last_ip; | |||||
private Integer province_id; | |||||
private Integer city_id; | |||||
private Integer area_id; | |||||
private Integer pid; | |||||
private Integer level; | |||||
private String promo_code; | |||||
private String tree; | |||||
private Integer status; | |||||
private Integer created_at; | |||||
private Integer updated_at; | |||||
private AccountBean account; | |||||
private String coupon_num; | |||||
private String cart_num; | |||||
public Integer getId() { | |||||
return id; | |||||
} | |||||
public void setId(Integer id) { | |||||
this.id = id; | |||||
} | |||||
public Integer getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(Integer merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getUsername() { | |||||
return username; | |||||
} | |||||
public void setUsername(String username) { | |||||
this.username = username; | |||||
} | |||||
public String getMobile_reset_token() { | |||||
return mobile_reset_token; | |||||
} | |||||
public void setMobile_reset_token(String mobile_reset_token) { | |||||
this.mobile_reset_token = mobile_reset_token; | |||||
} | |||||
public Integer getType() { | |||||
return type; | |||||
} | |||||
public void setType(Integer type) { | |||||
this.type = type; | |||||
} | |||||
public String getNickname() { | |||||
return nickname; | |||||
} | |||||
public void setNickname(String nickname) { | |||||
this.nickname = nickname; | |||||
} | |||||
public Object getRealname() { | |||||
return realname; | |||||
} | |||||
public void setRealname(Object realname) { | |||||
this.realname = realname; | |||||
} | |||||
public Object getHead_portrait() { | |||||
return head_portrait; | |||||
} | |||||
public void setHead_portrait(Object head_portrait) { | |||||
this.head_portrait = head_portrait; | |||||
} | |||||
public Integer getCurrent_level() { | |||||
return current_level; | |||||
} | |||||
public void setCurrent_level(Integer current_level) { | |||||
this.current_level = current_level; | |||||
} | |||||
public Integer getLevel_expiration_time() { | |||||
return level_expiration_time; | |||||
} | |||||
public void setLevel_expiration_time(Integer level_expiration_time) { | |||||
this.level_expiration_time = level_expiration_time; | |||||
} | |||||
public Integer getLevel_buy_type() { | |||||
return level_buy_type; | |||||
} | |||||
public void setLevel_buy_type(Integer level_buy_type) { | |||||
this.level_buy_type = level_buy_type; | |||||
} | |||||
public Integer getGender() { | |||||
return gender; | |||||
} | |||||
public void setGender(Integer gender) { | |||||
this.gender = gender; | |||||
} | |||||
public String getQq() { | |||||
return qq; | |||||
} | |||||
public void setQq(String qq) { | |||||
this.qq = qq; | |||||
} | |||||
public String getEmail() { | |||||
return email; | |||||
} | |||||
public void setEmail(String email) { | |||||
this.email = email; | |||||
} | |||||
public Object getBirthday() { | |||||
return birthday; | |||||
} | |||||
public void setBirthday(Object birthday) { | |||||
this.birthday = birthday; | |||||
} | |||||
public Integer getVisit_count() { | |||||
return visit_count; | |||||
} | |||||
public void setVisit_count(Integer visit_count) { | |||||
this.visit_count = visit_count; | |||||
} | |||||
public String getHome_phone() { | |||||
return home_phone; | |||||
} | |||||
public void setHome_phone(String home_phone) { | |||||
this.home_phone = home_phone; | |||||
} | |||||
public String getMobile() { | |||||
return mobile; | |||||
} | |||||
public void setMobile(String mobile) { | |||||
this.mobile = mobile; | |||||
} | |||||
public Integer getRole() { | |||||
return role; | |||||
} | |||||
public void setRole(Integer role) { | |||||
this.role = role; | |||||
} | |||||
public Integer getLast_time() { | |||||
return last_time; | |||||
} | |||||
public void setLast_time(Integer last_time) { | |||||
this.last_time = last_time; | |||||
} | |||||
public String getLast_ip() { | |||||
return last_ip; | |||||
} | |||||
public void setLast_ip(String last_ip) { | |||||
this.last_ip = last_ip; | |||||
} | |||||
public Integer getProvince_id() { | |||||
return province_id; | |||||
} | |||||
public void setProvince_id(Integer province_id) { | |||||
this.province_id = province_id; | |||||
} | |||||
public Integer getCity_id() { | |||||
return city_id; | |||||
} | |||||
public void setCity_id(Integer city_id) { | |||||
this.city_id = city_id; | |||||
} | |||||
public Integer getArea_id() { | |||||
return area_id; | |||||
} | |||||
public void setArea_id(Integer area_id) { | |||||
this.area_id = area_id; | |||||
} | |||||
public Integer getPid() { | |||||
return pid; | |||||
} | |||||
public void setPid(Integer pid) { | |||||
this.pid = pid; | |||||
} | |||||
public Integer getLevel() { | |||||
return level; | |||||
} | |||||
public void setLevel(Integer level) { | |||||
this.level = level; | |||||
} | |||||
public String getPromo_code() { | |||||
return promo_code; | |||||
} | |||||
public void setPromo_code(String promo_code) { | |||||
this.promo_code = promo_code; | |||||
} | |||||
public String getTree() { | |||||
return tree; | |||||
} | |||||
public void setTree(String tree) { | |||||
this.tree = tree; | |||||
} | |||||
public Integer getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(Integer status) { | |||||
this.status = status; | |||||
} | |||||
public Integer getCreated_at() { | |||||
return created_at; | |||||
} | |||||
public void setCreated_at(Integer created_at) { | |||||
this.created_at = created_at; | |||||
} | |||||
public Integer getUpdated_at() { | |||||
return updated_at; | |||||
} | |||||
public void setUpdated_at(Integer updated_at) { | |||||
this.updated_at = updated_at; | |||||
} | |||||
public AccountBean getAccount() { | |||||
return account; | |||||
} | |||||
public void setAccount(AccountBean account) { | |||||
this.account = account; | |||||
} | |||||
public String getCoupon_num() { | |||||
return coupon_num; | |||||
} | |||||
public void setCoupon_num(String coupon_num) { | |||||
this.coupon_num = coupon_num; | |||||
} | |||||
public String getCart_num() { | |||||
return cart_num; | |||||
} | |||||
public void setCart_num(String cart_num) { | |||||
this.cart_num = cart_num; | |||||
} | |||||
public static class AccountBean { | |||||
private Integer id; | |||||
private Integer merchant_id; | |||||
private Integer member_id; | |||||
private Integer level; | |||||
private String user_money; | |||||
private String accumulate_money; | |||||
private String give_money; | |||||
private String consume_money; | |||||
private String frozen_money; | |||||
private Integer user_integral; | |||||
private Integer accumulate_integral; | |||||
private Integer give_integral; | |||||
private String consume_integral; | |||||
private Integer frozen_integral; | |||||
private Integer user_growth; | |||||
private Integer accumulate_growth; | |||||
private String consume_growth; | |||||
private String frozen_growth; | |||||
private String economize_money; | |||||
private Integer status; | |||||
public Integer getId() { | |||||
return id; | |||||
} | |||||
public void setId(Integer id) { | |||||
this.id = id; | |||||
} | |||||
public Integer getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(Integer merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public Integer getMember_id() { | |||||
return member_id; | |||||
} | |||||
public void setMember_id(Integer member_id) { | |||||
this.member_id = member_id; | |||||
} | |||||
public Integer getLevel() { | |||||
return level; | |||||
} | |||||
public void setLevel(Integer level) { | |||||
this.level = level; | |||||
} | |||||
public String getUser_money() { | |||||
return user_money; | |||||
} | |||||
public void setUser_money(String user_money) { | |||||
this.user_money = user_money; | |||||
} | |||||
public String getAccumulate_money() { | |||||
return accumulate_money; | |||||
} | |||||
public void setAccumulate_money(String accumulate_money) { | |||||
this.accumulate_money = accumulate_money; | |||||
} | |||||
public String getGive_money() { | |||||
return give_money; | |||||
} | |||||
public void setGive_money(String give_money) { | |||||
this.give_money = give_money; | |||||
} | |||||
public String getConsume_money() { | |||||
return consume_money; | |||||
} | |||||
public void setConsume_money(String consume_money) { | |||||
this.consume_money = consume_money; | |||||
} | |||||
public String getFrozen_money() { | |||||
return frozen_money; | |||||
} | |||||
public void setFrozen_money(String frozen_money) { | |||||
this.frozen_money = frozen_money; | |||||
} | |||||
public Integer getUser_integral() { | |||||
return user_integral; | |||||
} | |||||
public void setUser_integral(Integer user_integral) { | |||||
this.user_integral = user_integral; | |||||
} | |||||
public Integer getAccumulate_integral() { | |||||
return accumulate_integral; | |||||
} | |||||
public void setAccumulate_integral(Integer accumulate_integral) { | |||||
this.accumulate_integral = accumulate_integral; | |||||
} | |||||
public Integer getGive_integral() { | |||||
return give_integral; | |||||
} | |||||
public void setGive_integral(Integer give_integral) { | |||||
this.give_integral = give_integral; | |||||
} | |||||
public String getConsume_integral() { | |||||
return consume_integral; | |||||
} | |||||
public void setConsume_integral(String consume_integral) { | |||||
this.consume_integral = consume_integral; | |||||
} | |||||
public Integer getFrozen_integral() { | |||||
return frozen_integral; | |||||
} | |||||
public void setFrozen_integral(Integer frozen_integral) { | |||||
this.frozen_integral = frozen_integral; | |||||
} | |||||
public Integer getUser_growth() { | |||||
return user_growth; | |||||
} | |||||
public void setUser_growth(Integer user_growth) { | |||||
this.user_growth = user_growth; | |||||
} | |||||
public Integer getAccumulate_growth() { | |||||
return accumulate_growth; | |||||
} | |||||
public void setAccumulate_growth(Integer accumulate_growth) { | |||||
this.accumulate_growth = accumulate_growth; | |||||
} | |||||
public String getConsume_growth() { | |||||
return consume_growth; | |||||
} | |||||
public void setConsume_growth(String consume_growth) { | |||||
this.consume_growth = consume_growth; | |||||
} | |||||
public String getFrozen_growth() { | |||||
return frozen_growth; | |||||
} | |||||
public void setFrozen_growth(String frozen_growth) { | |||||
this.frozen_growth = frozen_growth; | |||||
} | |||||
public String getEconomize_money() { | |||||
return economize_money; | |||||
} | |||||
public void setEconomize_money(String economize_money) { | |||||
this.economize_money = economize_money; | |||||
} | |||||
public Integer getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(Integer status) { | |||||
this.status = status; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.bean; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.user.ui.activity.login.bean | |||||
* @ClassName: RegisterBean | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/18 22:53 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class RegisterBean { | |||||
private String refresh_token; | |||||
private String access_token; | |||||
private Integer expiration_time; | |||||
private MemberBean member; | |||||
public String getRefresh_token() { | |||||
return refresh_token; | |||||
} | |||||
public void setRefresh_token(String refresh_token) { | |||||
this.refresh_token = refresh_token; | |||||
} | |||||
public String getAccess_token() { | |||||
return access_token; | |||||
} | |||||
public void setAccess_token(String access_token) { | |||||
this.access_token = access_token; | |||||
} | |||||
public Integer getExpiration_time() { | |||||
return expiration_time; | |||||
} | |||||
public void setExpiration_time(Integer expiration_time) { | |||||
this.expiration_time = expiration_time; | |||||
} | |||||
public MemberBean getMember() { | |||||
return member; | |||||
} | |||||
public void setMember(MemberBean member) { | |||||
this.member = member; | |||||
} | |||||
public static class MemberBean { | |||||
private Integer id; | |||||
private String merchant_id; | |||||
private String username; | |||||
private Integer type; | |||||
private String nickname; | |||||
private Object realname; | |||||
private Object head_portrait; | |||||
private Integer gender; | |||||
private String qq; | |||||
private String email; | |||||
private Object birthday; | |||||
private Integer visit_count; | |||||
private String home_phone; | |||||
private String mobile; | |||||
private Integer role; | |||||
private Integer last_time; | |||||
private String last_ip; | |||||
private Integer province_id; | |||||
private Integer city_id; | |||||
private Integer area_id; | |||||
private String pid; | |||||
private Integer status; | |||||
private String created_at; | |||||
private Integer updated_at; | |||||
private AccountBean account; | |||||
public Integer getId() { | |||||
return id; | |||||
} | |||||
public void setId(Integer id) { | |||||
this.id = id; | |||||
} | |||||
public String getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(String merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getUsername() { | |||||
return username; | |||||
} | |||||
public void setUsername(String username) { | |||||
this.username = username; | |||||
} | |||||
public Integer getType() { | |||||
return type; | |||||
} | |||||
public void setType(Integer type) { | |||||
this.type = type; | |||||
} | |||||
public String getNickname() { | |||||
return nickname; | |||||
} | |||||
public void setNickname(String nickname) { | |||||
this.nickname = nickname; | |||||
} | |||||
public Object getRealname() { | |||||
return realname; | |||||
} | |||||
public void setRealname(Object realname) { | |||||
this.realname = realname; | |||||
} | |||||
public Object getHead_portrait() { | |||||
return head_portrait; | |||||
} | |||||
public void setHead_portrait(Object head_portrait) { | |||||
this.head_portrait = head_portrait; | |||||
} | |||||
public Integer getGender() { | |||||
return gender; | |||||
} | |||||
public void setGender(Integer gender) { | |||||
this.gender = gender; | |||||
} | |||||
public String getQq() { | |||||
return qq; | |||||
} | |||||
public void setQq(String qq) { | |||||
this.qq = qq; | |||||
} | |||||
public String getEmail() { | |||||
return email; | |||||
} | |||||
public void setEmail(String email) { | |||||
this.email = email; | |||||
} | |||||
public Object getBirthday() { | |||||
return birthday; | |||||
} | |||||
public void setBirthday(Object birthday) { | |||||
this.birthday = birthday; | |||||
} | |||||
public Integer getVisit_count() { | |||||
return visit_count; | |||||
} | |||||
public void setVisit_count(Integer visit_count) { | |||||
this.visit_count = visit_count; | |||||
} | |||||
public String getHome_phone() { | |||||
return home_phone; | |||||
} | |||||
public void setHome_phone(String home_phone) { | |||||
this.home_phone = home_phone; | |||||
} | |||||
public String getMobile() { | |||||
return mobile; | |||||
} | |||||
public void setMobile(String mobile) { | |||||
this.mobile = mobile; | |||||
} | |||||
public Integer getRole() { | |||||
return role; | |||||
} | |||||
public void setRole(Integer role) { | |||||
this.role = role; | |||||
} | |||||
public Integer getLast_time() { | |||||
return last_time; | |||||
} | |||||
public void setLast_time(Integer last_time) { | |||||
this.last_time = last_time; | |||||
} | |||||
public String getLast_ip() { | |||||
return last_ip; | |||||
} | |||||
public void setLast_ip(String last_ip) { | |||||
this.last_ip = last_ip; | |||||
} | |||||
public Integer getProvince_id() { | |||||
return province_id; | |||||
} | |||||
public void setProvince_id(Integer province_id) { | |||||
this.province_id = province_id; | |||||
} | |||||
public Integer getCity_id() { | |||||
return city_id; | |||||
} | |||||
public void setCity_id(Integer city_id) { | |||||
this.city_id = city_id; | |||||
} | |||||
public Integer getArea_id() { | |||||
return area_id; | |||||
} | |||||
public void setArea_id(Integer area_id) { | |||||
this.area_id = area_id; | |||||
} | |||||
public String getPid() { | |||||
return pid; | |||||
} | |||||
public void setPid(String pid) { | |||||
this.pid = pid; | |||||
} | |||||
public Integer getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(Integer status) { | |||||
this.status = status; | |||||
} | |||||
public String getCreated_at() { | |||||
return created_at; | |||||
} | |||||
public void setCreated_at(String created_at) { | |||||
this.created_at = created_at; | |||||
} | |||||
public Integer getUpdated_at() { | |||||
return updated_at; | |||||
} | |||||
public void setUpdated_at(Integer updated_at) { | |||||
this.updated_at = updated_at; | |||||
} | |||||
public AccountBean getAccount() { | |||||
return account; | |||||
} | |||||
public void setAccount(AccountBean account) { | |||||
this.account = account; | |||||
} | |||||
public static class AccountBean { | |||||
private String id; | |||||
private String merchant_id; | |||||
private String member_id; | |||||
private String user_money; | |||||
private String accumulate_money; | |||||
private String frozen_money; | |||||
private Integer user_integral; | |||||
private Integer accumulate_integral; | |||||
private Integer frozen_integral; | |||||
public String getId() { | |||||
return id; | |||||
} | |||||
public void setId(String id) { | |||||
this.id = id; | |||||
} | |||||
public String getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(String merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getMember_id() { | |||||
return member_id; | |||||
} | |||||
public void setMember_id(String member_id) { | |||||
this.member_id = member_id; | |||||
} | |||||
public String getUser_money() { | |||||
return user_money; | |||||
} | |||||
public void setUser_money(String user_money) { | |||||
this.user_money = user_money; | |||||
} | |||||
public String getAccumulate_money() { | |||||
return accumulate_money; | |||||
} | |||||
public void setAccumulate_money(String accumulate_money) { | |||||
this.accumulate_money = accumulate_money; | |||||
} | |||||
public String getFrozen_money() { | |||||
return frozen_money; | |||||
} | |||||
public void setFrozen_money(String frozen_money) { | |||||
this.frozen_money = frozen_money; | |||||
} | |||||
public Integer getUser_integral() { | |||||
return user_integral; | |||||
} | |||||
public void setUser_integral(Integer user_integral) { | |||||
this.user_integral = user_integral; | |||||
} | |||||
public Integer getAccumulate_integral() { | |||||
return accumulate_integral; | |||||
} | |||||
public void setAccumulate_integral(Integer accumulate_integral) { | |||||
this.accumulate_integral = accumulate_integral; | |||||
} | |||||
public Integer getFrozen_integral() { | |||||
return frozen_integral; | |||||
} | |||||
public void setFrozen_integral(Integer frozen_integral) { | |||||
this.frozen_integral = frozen_integral; | |||||
} | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.bean; | |||||
/** | |||||
* @ClassName VersionInfo | |||||
* @Antuor Administrator | |||||
* @Date 2021/10/11 | |||||
* @Version 1.0 | |||||
*/ | |||||
public class VersionInfo { | |||||
private Integer code; | |||||
private String message; | |||||
private DataDTO data; | |||||
private Integer timestamp; | |||||
public Integer getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(Integer code) { | |||||
this.code = code; | |||||
} | |||||
public String getMessage() { | |||||
return message; | |||||
} | |||||
public void setMessage(String message) { | |||||
this.message = message; | |||||
} | |||||
public DataDTO getData() { | |||||
return data; | |||||
} | |||||
public void setData(DataDTO data) { | |||||
this.data = data; | |||||
} | |||||
public Integer getTimestamp() { | |||||
return timestamp; | |||||
} | |||||
public void setTimestamp(Integer timestamp) { | |||||
this.timestamp = timestamp; | |||||
} | |||||
public static class DataDTO { | |||||
private String id; | |||||
private String merchant_id; | |||||
private String title; | |||||
private String version_id; | |||||
private String version; | |||||
private String package_size; | |||||
private String type; | |||||
private String content; | |||||
private String download_url; | |||||
private String is_enforce; | |||||
private String status; | |||||
private String download_num; | |||||
private String created_at; | |||||
private String updated_at; | |||||
private String cate_name; | |||||
public String getId() { | |||||
return id; | |||||
} | |||||
public void setId(String id) { | |||||
this.id = id; | |||||
} | |||||
public String getMerchant_id() { | |||||
return merchant_id; | |||||
} | |||||
public void setMerchant_id(String merchant_id) { | |||||
this.merchant_id = merchant_id; | |||||
} | |||||
public String getTitle() { | |||||
return title; | |||||
} | |||||
public void setTitle(String title) { | |||||
this.title = title; | |||||
} | |||||
public String getVersion_id() { | |||||
return version_id; | |||||
} | |||||
public void setVersion_id(String version_id) { | |||||
this.version_id = version_id; | |||||
} | |||||
public String getVersion() { | |||||
return version; | |||||
} | |||||
public void setVersion(String version) { | |||||
this.version = version; | |||||
} | |||||
public String getPackage_size() { | |||||
return package_size; | |||||
} | |||||
public void setPackage_size(String package_size) { | |||||
this.package_size = package_size; | |||||
} | |||||
public String getType() { | |||||
return type; | |||||
} | |||||
public void setType(String type) { | |||||
this.type = type; | |||||
} | |||||
public String getContent() { | |||||
return content; | |||||
} | |||||
public void setContent(String content) { | |||||
this.content = content; | |||||
} | |||||
public String getDownload_url() { | |||||
return download_url; | |||||
} | |||||
public void setDownload_url(String download_url) { | |||||
this.download_url = download_url; | |||||
} | |||||
public String getIs_enforce() { | |||||
return is_enforce; | |||||
} | |||||
public void setIs_enforce(String is_enforce) { | |||||
this.is_enforce = is_enforce; | |||||
} | |||||
public String getStatus() { | |||||
return status; | |||||
} | |||||
public void setStatus(String status) { | |||||
this.status = status; | |||||
} | |||||
public String getDownload_num() { | |||||
return download_num; | |||||
} | |||||
public void setDownload_num(String download_num) { | |||||
this.download_num = download_num; | |||||
} | |||||
public String getCreated_at() { | |||||
return created_at; | |||||
} | |||||
public void setCreated_at(String created_at) { | |||||
this.created_at = created_at; | |||||
} | |||||
public String getUpdated_at() { | |||||
return updated_at; | |||||
} | |||||
public void setUpdated_at(String updated_at) { | |||||
this.updated_at = updated_at; | |||||
} | |||||
public String getCate_name() { | |||||
return cate_name; | |||||
} | |||||
public void setCate_name(String cate_name) { | |||||
this.cate_name = cate_name; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.event; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.user.event | |||||
* @ClassName: CloseOrderEvent | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/11/1 20:53 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class CloseOrderEvent { | |||||
private int position; | |||||
public CloseOrderEvent(int position) { | |||||
this.position = position; | |||||
} | |||||
public int getPosition() { | |||||
return position; | |||||
} | |||||
public void setPosition(int position) { | |||||
this.position = position; | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity; | package com.example.tidalairpeisong.user.ui.activity; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.widget.RadioButton; | |||||
import android.widget.RadioGroup; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import androidx.fragment.app.FragmentManager; | |||||
import androidx.fragment.app.FragmentTransaction; | |||||
import com.example.tidalairpeisong.R; | import com.example.tidalairpeisong.R; | ||||
import com.example.tidalairpeisong.rxhttp.error.OnError; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.user.bean.MallProductBean; | |||||
import com.example.tidalairpeisong.user.bean.VersionInfo; | |||||
import com.rxjava.rxlife.RxLife; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.base.BaseFragment; | |||||
import com.example.tidalairpeisong.user.ui.fragment.main.MineFragment; | |||||
import com.example.tidalairpeisong.user.ui.fragment.main.OrderFragment; | |||||
import com.example.tidalairpeisong.user.ui.fragment.main.SaoMaFragment; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import rxhttp.wrapper.param.RxHttp; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
public class MainActivity extends AppCompatActivity { | |||||
public class MainActivity extends BaseActivity { | |||||
@BindView(R.id.radioGroup) | |||||
RadioGroup radioGroup; | |||||
@BindView(R.id.radio_order) | |||||
RadioButton radio_order; | |||||
@BindView(R.id.radio_mine) | |||||
RadioButton radio_mine; | |||||
private OrderFragment orderFragment; | |||||
private MineFragment mineFragment; | |||||
private List<BaseFragment> fragments; | |||||
private SaoMaFragment saoMaFragment; | |||||
@Override | @Override | ||||
protected void onCreate(Bundle savedInstanceState) { | protected void onCreate(Bundle savedInstanceState) { | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_main); | setContentView(R.layout.activity_main); | ||||
RxHttp.get(Api.version) | |||||
.add("type",1) | |||||
.add("version","2.2.2") | |||||
.asResponse(VersionInfo.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(s -> { | |||||
Log.e("csd",s.getData().getCate_name()+""); | |||||
}, (OnError) error -> { | |||||
Log.e("csd",error.getErrorMsg()); | |||||
}); | |||||
RxHttp.get(Api.mall_products) | |||||
.add("page",1) | |||||
.add("cate_id",1) | |||||
.asResponseList(MallProductBean.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(productBeans -> { | |||||
Log.e("csd",productBeans.size()+""); | |||||
},(OnError) error -> { | |||||
Log.e("csd",error.getErrorMsg()); | |||||
}); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
initView(); | |||||
} | |||||
private void initView() { | |||||
orderFragment = new OrderFragment(); | |||||
saoMaFragment = new SaoMaFragment(); | |||||
mineFragment = new MineFragment(); | |||||
fragments = new ArrayList<>(); | |||||
fragments.add(orderFragment); | |||||
fragments.add(saoMaFragment); | |||||
fragments.add(mineFragment); | |||||
//初始时想容器中添加第一个Fragment对象 | |||||
addFragment(orderFragment); | |||||
//设置RadioGroup开始时设置的按钮,设置第一个按钮为默认 | |||||
radioGroup.check(R.id.radio_order); | |||||
} | } | ||||
//向Activity中添加Fragment的方法 | |||||
private void addFragment(BaseFragment fragment) { | |||||
//获得Fragment管理器 | |||||
FragmentManager fragmentManager = getSupportFragmentManager(); | |||||
//使用管理器开启事务 | |||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); | |||||
//使用事务替换Fragment容器中Fragment对象 | |||||
fragmentTransaction.replace(R.id.activity_main_framelayout,fragment); | |||||
//提交事务 | |||||
fragmentTransaction.commit(); | |||||
} | |||||
@OnClick({R.id.radio_order,R.id.radio_mine,R.id.rl_saoma}) | |||||
public void onViewClicked(View view){ | |||||
switch (view.getId()){ | |||||
case R.id.radio_order: | |||||
addFragment(orderFragment); | |||||
break; | |||||
case R.id.rl_saoma: | |||||
addFragment(saoMaFragment); | |||||
radio_order.setChecked(false); | |||||
radio_mine.setChecked(false); | |||||
break; | |||||
case R.id.radio_mine: | |||||
addFragment(mineFragment); | |||||
break; | |||||
} | |||||
} | |||||
} | } |
package com.example.tidalairpeisong.user.ui.activity; | |||||
import android.os.Build; | |||||
import android.os.Bundle; | |||||
import android.view.WindowManager; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
public class SplashActivity extends AppCompatActivity { | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_splash); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.teal_200)); | |||||
// 适配刘海屏 | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | |||||
WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); | |||||
layoutParams.layoutInDisplayCutoutMode = | |||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; | |||||
getWindow().setAttributes(layoutParams); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.content.Intent; | |||||
import android.os.Bundle; | |||||
import android.os.CountDownTimer; | |||||
import android.view.View; | |||||
import android.widget.EditText; | |||||
import android.widget.ImageView; | |||||
import android.widget.TextView; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.rxhttp.error.OnError; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.user.ui.activity.MainActivity; | |||||
import com.example.tidalairpeisong.user.bean.RegisterBean; | |||||
import com.example.tidalairpeisong.utils.ActivityTaskManager; | |||||
import com.example.tidalairpeisong.utils.EditTextUtil; | |||||
import com.example.tidalairpeisong.utils.EmptyUtils; | |||||
import com.example.tidalairpeisong.utils.PhoneUtils; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import com.example.tidalairpeisong.utils.ToastUtil; | |||||
import com.rxjava.rxlife.RxLife; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
import rxhttp.wrapper.param.RxHttp; | |||||
public class CodeLoginActivity extends BaseActivity { | |||||
@BindView(R.id.tv_right) | |||||
TextView tv_right; | |||||
@BindView(R.id.edit_phone) | |||||
EditText edit_phone; | |||||
@BindView(R.id.edit_code) | |||||
EditText edit_code; | |||||
@BindView(R.id.tv_code_btn) | |||||
TextView tv_code_btn; | |||||
@BindView(R.id.tv_error) | |||||
TextView tv_error; | |||||
@BindView(R.id.tv_login) | |||||
TextView tv_login; | |||||
@BindView(R.id.pwd_login) | |||||
TextView pwd_login; | |||||
@BindView(R.id.forget_pwd) | |||||
TextView forget_pwd; | |||||
@BindView(R.id.iv_weixin) | |||||
ImageView iv_weixin; | |||||
private ActivityTaskManager instance; | |||||
private TimeCount timeCount; | |||||
private static final String TAG = "csdCodeLogin"; | |||||
private long lastClickTime = 0; | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_code_login); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
instance = ActivityTaskManager.getInstance(); | |||||
initView(); | |||||
} | |||||
private void initView() { | |||||
EditTextUtil.setMaxLength(edit_phone,11); | |||||
EditTextUtil.setEditTextInputSpace(edit_code); | |||||
EditTextUtil.setMaxLength(edit_code,4); | |||||
} | |||||
@OnClick({R.id.tv_right,R.id.tv_code_btn,R.id.tv_login,R.id.pwd_login,R.id.forget_pwd,R.id.iv_weixin}) | |||||
public void onClick(View v) { | |||||
Intent intent; | |||||
long now; | |||||
switch (v.getId()){ | |||||
case R.id.tv_right: | |||||
intent = new Intent(this,RegisterActivity.class); | |||||
startActivity(intent); | |||||
break; | |||||
case R.id.tv_code_btn: | |||||
getCode(); | |||||
break; | |||||
case R.id.tv_login: | |||||
now = System.currentTimeMillis(); | |||||
if (now - lastClickTime > 1000) { | |||||
login(); | |||||
}else { | |||||
ToastUtil.makeText(this,"请勿重复点击!"); | |||||
} | |||||
break; | |||||
case R.id.pwd_login: | |||||
break; | |||||
case R.id.forget_pwd: | |||||
break; | |||||
case R.id.iv_weixin: | |||||
break; | |||||
} | |||||
} | |||||
private void login() { | |||||
String editPhone = edit_phone.getText().toString().trim(); | |||||
if (!PhoneUtils.isPhone(editPhone)){ | |||||
ToastUtil.makeText(this,"手机号格式不正确"); | |||||
return; | |||||
} | |||||
String editCode = edit_code.getText().toString().trim(); | |||||
if (!EmptyUtils.isStringNotEmpty(editCode) || editPhone.length() < 6){ | |||||
ToastUtil.makeText(this,"验证码格式不正确"); | |||||
return; | |||||
} | |||||
RxHttp.postForm(Api.mobile_login) | |||||
.add("mobile",editPhone) | |||||
.add("code",editCode) | |||||
.add("group","tinyShopApp") | |||||
.asResponse(RegisterBean.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(registerBean -> { | |||||
initUi(registerBean); | |||||
tv_error.setVisibility(View.GONE); | |||||
},(OnError) error -> { | |||||
String errorMsg = error.getErrorMsg(); | |||||
if (EmptyUtils.isStringNotEmpty(errorMsg)){ | |||||
//ToastUtil.makeText(this,errorMsg); | |||||
tv_error.setVisibility(View.VISIBLE); | |||||
tv_error.setText(errorMsg); | |||||
} | |||||
}); | |||||
} | |||||
private void initUi(RegisterBean registerBean) { | |||||
PrefUtils.putString(this,"refresh_token",registerBean.getRefresh_token()); | |||||
PrefUtils.putString(this,"access_token",registerBean.getAccess_token()); | |||||
PrefUtils.putString(this,"member_id",registerBean.getMember().getId()+""); | |||||
PrefUtils.putString(this,"user_type","user"); | |||||
PrefUtils.putString(this,"phone",registerBean.getMember().getMobile()); | |||||
PrefUtils.putString(this,"expiration_time",registerBean.getExpiration_time()+""); | |||||
Intent intent = new Intent(this, MainActivity.class); | |||||
intent.putExtra("from","login"); | |||||
startActivity(intent); | |||||
finish(); | |||||
ActivityTaskManager.getInstance().finishActivity(this); | |||||
} | |||||
private void getCode() { | |||||
String editPhone = edit_phone.getText().toString().trim(); | |||||
if (!PhoneUtils.isPhone(editPhone)){ | |||||
ToastUtil.makeText(this,"手机号格式不正确"); | |||||
return; | |||||
} | |||||
if (!EmptyUtils.isStringNotEmpty(editPhone)){ | |||||
return; | |||||
} | |||||
RxHttp.postForm(Api.sms_dode) | |||||
.add("mobile",editPhone) | |||||
.add("usage","login") | |||||
.asResponse(Object.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(object -> { | |||||
ToastUtil.makeText(this,"发送成功"); | |||||
timeCount = new TimeCount(1000 * 60, 1000); | |||||
timeCount.start(); | |||||
if (object != null){ | |||||
edit_code.setText(object.toString().substring(0,object.toString().length()-2)); | |||||
} | |||||
tv_error.setVisibility(View.GONE); | |||||
},(OnError) error -> { | |||||
String errorMsg = error.getErrorMsg(); | |||||
if (EmptyUtils.isStringNotEmpty(errorMsg)){ | |||||
tv_error.setVisibility(View.VISIBLE); | |||||
tv_error.setText(errorMsg); | |||||
} | |||||
}); | |||||
} | |||||
/** | |||||
* 倒计时的内部类 | |||||
*/ | |||||
class TimeCount extends CountDownTimer { | |||||
/** | |||||
* @param millisInFuture The number of millis in the future from the call | |||||
* to {@link #start()} until the countdown is done and {@link #onFinish()} | |||||
* is called.总时长 | |||||
* @param countDownInterval The interval along the way to receive | |||||
* {@link #onTick(long)} callbacks. 计时的时间间隔 | |||||
*/ | |||||
public TimeCount(long millisInFuture, long countDownInterval) { | |||||
super(millisInFuture, countDownInterval); | |||||
} | |||||
@Override | |||||
public void onTick(long millisUntilFinished) {//计时过程显示 | |||||
tv_code_btn.setClickable(false); | |||||
tv_code_btn.setText((millisUntilFinished) / 1000 + "s"); | |||||
} | |||||
@Override | |||||
public void onFinish() {//计时完毕 | |||||
tv_code_btn.setClickable(true); | |||||
tv_code_btn.setText("获取验证码"); | |||||
} | |||||
} | |||||
@Override | |||||
protected void onDestroy() { | |||||
super.onDestroy(); | |||||
if (timeCount != null){ | |||||
timeCount.cancel(); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.content.Intent; | |||||
import android.os.Bundle; | |||||
import android.os.CountDownTimer; | |||||
import android.view.View; | |||||
import android.widget.EditText; | |||||
import android.widget.TextView; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.rxhttp.error.OnError; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.utils.ActivityTaskManager; | |||||
import com.example.tidalairpeisong.utils.EditTextUtil; | |||||
import com.example.tidalairpeisong.utils.EmptyUtils; | |||||
import com.example.tidalairpeisong.utils.PhoneUtils; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import com.example.tidalairpeisong.utils.ToastUtil; | |||||
import com.rxjava.rxlife.RxLife; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
import rxhttp.wrapper.param.RxHttp; | |||||
public class ForgetPwdActivity extends BaseActivity { | |||||
@BindView(R.id.edit_phone) | |||||
EditText edit_phone; | |||||
@BindView(R.id.edit_code) | |||||
EditText edit_code; | |||||
@BindView(R.id.tv_error) | |||||
TextView tv_error; | |||||
@BindView(R.id.tv_next) | |||||
TextView tv_next; | |||||
@BindView(R.id.tv_code_btn) | |||||
TextView tv_code_btn; | |||||
private ActivityTaskManager instance; | |||||
private TimeCount timeCount; | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_forget_pwd); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
instance = ActivityTaskManager.getInstance(); | |||||
initView(); | |||||
} | |||||
private void initView() { | |||||
EditTextUtil.setMaxLength(edit_phone,11); | |||||
EditTextUtil.setEditTextInputSpace(edit_code); | |||||
EditTextUtil.setMaxLength(edit_code,4); | |||||
} | |||||
@OnClick({R.id.tv_code_btn,R.id.tv_next}) | |||||
public void onClick(View v) { | |||||
Intent intent; | |||||
switch (v.getId()){ | |||||
case R.id.tv_code_btn: | |||||
getCode(); | |||||
break; | |||||
case R.id.tv_next: | |||||
String editPhone = edit_phone.getText().toString().trim(); | |||||
if (!PhoneUtils.isPhone(editPhone)){ | |||||
ToastUtil.makeText(this,"手机号格式不正确"); | |||||
return; | |||||
} | |||||
String editCode = edit_code.getText().toString().trim(); | |||||
if (!EmptyUtils.isStringNotEmpty(editCode) || editPhone.length() < 6){ | |||||
ToastUtil.makeText(this,"验证码格式不正确"); | |||||
return; | |||||
} | |||||
intent = new Intent(this,ResetPwdActivity.class); | |||||
intent.putExtra("mobile",editPhone); | |||||
intent.putExtra("code",editCode); | |||||
startActivity(intent); | |||||
break; | |||||
} | |||||
} | |||||
private void getCode() { | |||||
String editPhone = edit_phone.getText().toString().trim(); | |||||
if (!PhoneUtils.isPhone(editPhone)){ | |||||
ToastUtil.makeText(this,"手机号格式不正确"); | |||||
return; | |||||
} | |||||
if (!EmptyUtils.isStringNotEmpty(editPhone)){ | |||||
return; | |||||
} | |||||
RxHttp.postForm(Api.sms_dode) | |||||
.add("mobile",editPhone) | |||||
.add("usage","up-pwd") | |||||
.asResponse(Object.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(object -> { | |||||
ToastUtil.makeText(this,"发送成功"); | |||||
timeCount = new TimeCount(1000 * 60, 1000); | |||||
timeCount.start(); | |||||
if (object != null){ | |||||
edit_code.setText(object.toString().substring(0,object.toString().length()-2)); | |||||
} | |||||
tv_error.setVisibility(View.GONE); | |||||
},(OnError) error -> { | |||||
String errorMsg = error.getErrorMsg(); | |||||
if (EmptyUtils.isStringNotEmpty(errorMsg)){ | |||||
tv_error.setVisibility(View.VISIBLE); | |||||
tv_error.setText(errorMsg); | |||||
} | |||||
}); | |||||
} | |||||
/** | |||||
* 倒计时的内部类 | |||||
*/ | |||||
class TimeCount extends CountDownTimer { | |||||
/** | |||||
* @param millisInFuture The number of millis in the future from the call | |||||
* to {@link #start()} until the countdown is done and {@link #onFinish()} | |||||
* is called.总时长 | |||||
* @param countDownInterval The interval along the way to receive | |||||
* {@link #onTick(long)} callbacks. 计时的时间间隔 | |||||
*/ | |||||
public TimeCount(long millisInFuture, long countDownInterval) { | |||||
super(millisInFuture, countDownInterval); | |||||
} | |||||
@Override | |||||
public void onTick(long millisUntilFinished) {//计时过程显示 | |||||
tv_code_btn.setClickable(false); | |||||
tv_code_btn.setText((millisUntilFinished) / 1000 + "s"); | |||||
} | |||||
@Override | |||||
public void onFinish() {//计时完毕 | |||||
tv_code_btn.setClickable(true); | |||||
tv_code_btn.setText("获取验证码"); | |||||
} | |||||
} | |||||
@Override | |||||
protected void onDestroy() { | |||||
super.onDestroy(); | |||||
if (timeCount != null){ | |||||
timeCount.cancel(); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.os.Bundle; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import butterknife.ButterKnife; | |||||
/** | |||||
* 身份认证 | |||||
* */ | |||||
public class IdentityAuthenticationActivity extends BaseActivity { | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_identity_authentication); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.content.Intent; | |||||
import android.os.Bundle; | |||||
import android.text.Editable; | |||||
import android.text.InputType; | |||||
import android.text.TextWatcher; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.widget.EditText; | |||||
import android.widget.ImageView; | |||||
import android.widget.TextView; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.rxhttp.error.OnError; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.user.ui.activity.MainActivity; | |||||
import com.example.tidalairpeisong.user.bean.RegisterBean; | |||||
import com.example.tidalairpeisong.utils.ActivityTaskManager; | |||||
import com.example.tidalairpeisong.utils.EditTextUtil; | |||||
import com.example.tidalairpeisong.utils.EmptyUtils; | |||||
import com.example.tidalairpeisong.utils.PhoneUtils; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import com.example.tidalairpeisong.utils.ToastUtil; | |||||
import com.rxjava.rxlife.RxLife; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
import rxhttp.wrapper.param.RxHttp; | |||||
public class LoginActivity extends BaseActivity { | |||||
@BindView(R.id.tv_right) | |||||
TextView tv_right; | |||||
@BindView(R.id.edit_phone) | |||||
EditText edit_phone; | |||||
@BindView(R.id.edit_pwd) | |||||
EditText edit_pwd; | |||||
@BindView(R.id.eye) | |||||
ImageView eye; | |||||
@BindView(R.id.tv_login) | |||||
TextView tv_login; | |||||
@BindView(R.id.code_login) | |||||
TextView code_login; | |||||
@BindView(R.id.forget_pwd) | |||||
TextView forget_pwd; | |||||
@BindView(R.id.iv_weixin) | |||||
ImageView iv_weixin; | |||||
@BindView(R.id.tv_error) | |||||
TextView tv_error; | |||||
private ActivityTaskManager instance; | |||||
private long lastClickTime = 0; | |||||
private boolean eye_show = false; | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_login); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
instance = ActivityTaskManager.getInstance(); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
initView(); | |||||
} | |||||
private void initView() { | |||||
EditTextUtil.setMaxLength(edit_phone,11); | |||||
EditTextUtil.setEditTextInputSpace(edit_pwd); | |||||
EditTextUtil.setMaxLength(edit_pwd,15); | |||||
edit_pwd.addTextChangedListener(new TextWatcher() { | |||||
@Override | |||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |||||
} | |||||
@Override | |||||
public void onTextChanged(CharSequence s, int start, int before, int count) { | |||||
if (s.length() > 0){ | |||||
eye.setVisibility(View.VISIBLE); | |||||
eye.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye_show = true; | |||||
}else { | |||||
eye.setVisibility(View.GONE); | |||||
eye_show = false; | |||||
} | |||||
} | |||||
@Override | |||||
public void afterTextChanged(Editable s) { | |||||
} | |||||
}); | |||||
} | |||||
@OnClick({R.id.tv_right,R.id.eye,R.id.tv_login,R.id.code_login,R.id.forget_pwd,R.id.iv_weixin}) | |||||
public void onClick(View v) { | |||||
Intent intent = null; | |||||
long now; | |||||
switch (v.getId()){ | |||||
case R.id.tv_right: | |||||
intent = new Intent(this,RegisterActivity.class); | |||||
startActivity(intent); | |||||
finish(); | |||||
break; | |||||
case R.id.eye: | |||||
if (eye_show){ | |||||
edit_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | |||||
eye.setImageResource(R.mipmap.denglu_ic_eye_closed); | |||||
eye_show = false; | |||||
}else{ | |||||
edit_pwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); | |||||
eye.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye_show = true; | |||||
} | |||||
break; | |||||
case R.id.tv_login: | |||||
now = System.currentTimeMillis(); | |||||
if (now - lastClickTime > 1000) { | |||||
login(); | |||||
}else { | |||||
ToastUtil.makeText(this,"请勿重复点击!"); | |||||
} | |||||
break; | |||||
case R.id.code_login: | |||||
intent = new Intent(this,CodeLoginActivity.class); | |||||
startActivity(intent); | |||||
finish(); | |||||
break; | |||||
case R.id.forget_pwd: | |||||
intent = new Intent(this,ForgetPwdActivity.class); | |||||
startActivity(intent); | |||||
finish(); | |||||
break; | |||||
case R.id.iv_weixin: | |||||
break; | |||||
} | |||||
} | |||||
private void login() { | |||||
String editPhone = edit_phone.getText().toString().trim(); | |||||
if (!PhoneUtils.isPhone(editPhone)){ | |||||
ToastUtil.makeText(this,"手机号格式不正确"); | |||||
return; | |||||
} | |||||
String editPwd = edit_pwd.getText().toString().trim(); | |||||
if (!EmptyUtils.isStringNotEmpty(editPwd) || editPhone.length() < 6){ | |||||
ToastUtil.makeText(this,"密码格式不正确"); | |||||
return; | |||||
} | |||||
RxHttp.postForm(Api.login) | |||||
.add("mobile",editPhone) | |||||
.add("password",editPwd) | |||||
.add("group","tinyShopApp") | |||||
.asResponse(RegisterBean.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(registerBean -> { | |||||
initUi(registerBean); | |||||
tv_error.setVisibility(View.GONE); | |||||
},(OnError) error -> { | |||||
String errorMsg = error.getErrorMsg(); | |||||
if (EmptyUtils.isStringNotEmpty(errorMsg)){ | |||||
//ToastUtil.makeText(this,errorMsg); | |||||
tv_error.setVisibility(View.VISIBLE); | |||||
tv_error.setText(errorMsg); | |||||
} | |||||
}); | |||||
} | |||||
private void initUi(RegisterBean registerBean) { | |||||
Log.e("csd",registerBean.getAccess_token()+"---"+registerBean.getRefresh_token()); | |||||
PrefUtils.putString(this,"refresh_token",registerBean.getRefresh_token()); | |||||
PrefUtils.putString(this,"access_token",registerBean.getAccess_token()); | |||||
PrefUtils.putString(this,"member_id",registerBean.getMember().getId()+""); | |||||
PrefUtils.putString(this,"user_type","user"); | |||||
PrefUtils.putString(this,"phone",registerBean.getMember().getMobile()); | |||||
PrefUtils.putString(this,"expiration_time",registerBean.getExpiration_time()+""); | |||||
Intent intent = new Intent(this, MainActivity.class); | |||||
intent.putExtra("from","login"); | |||||
startActivity(intent); | |||||
finish(); | |||||
ActivityTaskManager.getInstance().finishActivity(this); | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.content.Intent; | |||||
import android.graphics.Paint; | |||||
import android.os.Bundle; | |||||
import android.os.CountDownTimer; | |||||
import android.text.Editable; | |||||
import android.text.InputType; | |||||
import android.text.TextWatcher; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.widget.CheckBox; | |||||
import android.widget.CompoundButton; | |||||
import android.widget.EditText; | |||||
import android.widget.ImageView; | |||||
import android.widget.TextView; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.rxhttp.error.OnError; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.user.ui.activity.MainActivity; | |||||
import com.example.tidalairpeisong.user.bean.RegisterBean; | |||||
import com.example.tidalairpeisong.utils.ActivityTaskManager; | |||||
import com.example.tidalairpeisong.utils.EditTextUtil; | |||||
import com.example.tidalairpeisong.utils.EmptyUtils; | |||||
import com.example.tidalairpeisong.utils.PhoneUtils; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import com.example.tidalairpeisong.utils.ToastUtil; | |||||
import com.rxjava.rxlife.RxLife; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
import rxhttp.wrapper.param.RxHttp; | |||||
public class RegisterActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener { | |||||
@BindView(R.id.tv_right) | |||||
TextView tv_right; | |||||
@BindView(R.id.tv_code_btn) | |||||
TextView tv_code_btn; | |||||
@BindView(R.id.eye1) | |||||
ImageView eye1; | |||||
@BindView(R.id.eye2) | |||||
ImageView eye2; | |||||
@BindView(R.id.tv_login) | |||||
TextView tv_login; | |||||
@BindView(R.id.tv_use_rule) | |||||
TextView tv_use_rule; | |||||
@BindView(R.id.tv_yinsi_rule) | |||||
TextView tv_yinsi_rule; | |||||
@BindView(R.id.edit_phone) | |||||
EditText edit_phone; | |||||
@BindView(R.id.edit_code) | |||||
EditText edit_code; | |||||
@BindView(R.id.edit_pwd1) | |||||
EditText edit_pwd1; | |||||
@BindView(R.id.edit_pwd2) | |||||
EditText edit_pwd2; | |||||
@BindView(R.id.checkbox) | |||||
CheckBox checkbox; | |||||
@BindView(R.id.tv_error) | |||||
TextView tv_error; | |||||
private static final String TAG = "csdRegister"; | |||||
private ActivityTaskManager instance; | |||||
private boolean checked = true; | |||||
private TimeCount timeCount; | |||||
private boolean eye1_show = false; | |||||
private boolean eye2_show = false; | |||||
private long lastClickTime = 0; | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_register); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
tv_use_rule.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); | |||||
tv_yinsi_rule.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); | |||||
instance = ActivityTaskManager.getInstance(); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
initView(); | |||||
} | |||||
private void initView() { | |||||
EditTextUtil.setMaxLength(edit_phone,11); | |||||
EditTextUtil.setEditTextInputSpace(edit_pwd1); | |||||
EditTextUtil.setMaxLength(edit_pwd1,15); | |||||
EditTextUtil.setEditTextInputSpace(edit_pwd2); | |||||
EditTextUtil. setMaxLength(edit_pwd2,15); | |||||
edit_pwd1.addTextChangedListener(new TextWatcher() { | |||||
@Override | |||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |||||
} | |||||
@Override | |||||
public void onTextChanged(CharSequence s, int start, int before, int count) { | |||||
if (s.length() > 0){ | |||||
eye1.setVisibility(View.VISIBLE); | |||||
eye1.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye1_show = true; | |||||
}else { | |||||
eye1.setVisibility(View.GONE); | |||||
eye1_show = false; | |||||
} | |||||
} | |||||
@Override | |||||
public void afterTextChanged(Editable s) { | |||||
} | |||||
}); | |||||
edit_pwd2.addTextChangedListener(new TextWatcher() { | |||||
@Override | |||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |||||
} | |||||
@Override | |||||
public void onTextChanged(CharSequence s, int start, int before, int count) { | |||||
if (s.length() > 0){ | |||||
eye2.setVisibility(View.VISIBLE); | |||||
eye2.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye2_show = true; | |||||
}else { | |||||
eye2.setVisibility(View.GONE); | |||||
eye2_show = false; | |||||
} | |||||
} | |||||
@Override | |||||
public void afterTextChanged(Editable s) { | |||||
} | |||||
}); | |||||
checkbox.setOnCheckedChangeListener(this); | |||||
} | |||||
@OnClick({R.id.tv_right,R.id.tv_code_btn,R.id.eye1,R.id.eye2,R.id.tv_login,R.id.tv_use_rule,R.id.tv_yinsi_rule}) | |||||
public void onClick(View view){ | |||||
Intent intent = null; | |||||
long now; | |||||
switch (view.getId()){ | |||||
case R.id.tv_right: | |||||
intent = new Intent(this,LoginActivity.class); | |||||
startActivity(intent); | |||||
finish(); | |||||
break; | |||||
case R.id.tv_code_btn: | |||||
getCode(); | |||||
break; | |||||
case R.id.eye1: | |||||
if (eye1_show){ | |||||
edit_pwd1.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | |||||
eye1.setImageResource(R.mipmap.denglu_ic_eye_closed); | |||||
eye1_show = false; | |||||
}else{ | |||||
edit_pwd1.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); | |||||
eye1.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye1_show = true; | |||||
} | |||||
break; | |||||
case R.id.eye2: | |||||
if (eye2_show){ | |||||
edit_pwd2.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | |||||
eye2.setImageResource(R.mipmap.denglu_ic_eye_closed); | |||||
eye2_show = false; | |||||
}else{ | |||||
edit_pwd2.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); | |||||
eye2.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye2_show = true; | |||||
} | |||||
break; | |||||
case R.id.tv_login: | |||||
now = System.currentTimeMillis(); | |||||
if (now - lastClickTime > 1000) { | |||||
register(); | |||||
}else { | |||||
ToastUtil.makeText(this,"请勿重复点击!"); | |||||
} | |||||
break; | |||||
case R.id.tv_use_rule: | |||||
intent = new Intent(this,RuleActivity.class); | |||||
startActivity(intent); | |||||
break; | |||||
case R.id.tv_yinsi_rule: | |||||
intent = new Intent(this,RuleActivity.class); | |||||
startActivity(intent); | |||||
break; | |||||
} | |||||
} | |||||
private void register() { | |||||
String editPhone = edit_phone.getText().toString().trim(); | |||||
if (!PhoneUtils.isPhone(editPhone)){ | |||||
ToastUtil.makeText(this,"手机号格式不正确"); | |||||
return; | |||||
} | |||||
String editCode = edit_code.getText().toString().trim(); | |||||
if (!EmptyUtils.isStringNotEmpty(editCode)){ | |||||
ToastUtil.makeText(this,"验证码不能为空"); | |||||
return; | |||||
} | |||||
String pwd1 = edit_pwd1.getText().toString().trim(); | |||||
String pwd2 = edit_pwd2.getText().toString().trim(); | |||||
if (pwd1.isEmpty() || pwd2.isEmpty()){ | |||||
ToastUtil.makeText(this,"密码不能为空"); | |||||
return; | |||||
} | |||||
if (pwd1.length() < 6 || pwd2.length() < 6){ | |||||
ToastUtil.makeText(this,"密码不能少于6位"); | |||||
return; | |||||
} | |||||
if (!pwd1.equals(pwd2)){ | |||||
ToastUtil.makeText(this,"两次密码不一致"); | |||||
return; | |||||
} | |||||
if (checked){ | |||||
RxHttp.postForm(Api.register) | |||||
.add("mobile",editPhone) | |||||
.add("code",editCode) | |||||
.add("password",pwd1) | |||||
.add("password_repetition",pwd2) | |||||
.add("group","tinyShopApp") | |||||
.asResponse(RegisterBean.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(registerBean -> { | |||||
initUi(registerBean); | |||||
tv_error.setVisibility(View.GONE); | |||||
},(OnError) error -> { | |||||
String errorMsg = error.getErrorMsg(); | |||||
if (EmptyUtils.isStringNotEmpty(errorMsg)){ | |||||
tv_error.setVisibility(View.VISIBLE); | |||||
tv_error.setText(errorMsg); | |||||
} | |||||
}); | |||||
}else { | |||||
ToastUtil.makeText(this,"请阅读并勾选使用协议"); | |||||
} | |||||
} | |||||
private void initUi(RegisterBean registerBean) { | |||||
timeCount.cancel(); | |||||
PrefUtils.putString(this,"refresh_token",registerBean.getRefresh_token()); | |||||
PrefUtils.putString(this,"access_token",registerBean.getAccess_token()); | |||||
PrefUtils.putString(this,"member_id",registerBean.getMember().getId()+""); | |||||
PrefUtils.putString(this,"user_type","user"); | |||||
PrefUtils.putString(this,"expiration_time",registerBean.getExpiration_time()+""); | |||||
PrefUtils.putString(this,"phone",registerBean.getMember().getMobile()); | |||||
ToastUtil.makeText(RegisterActivity.this,"注册成功"); | |||||
Intent intent = new Intent(RegisterActivity.this, MainActivity.class); | |||||
intent.putExtra("from","register"); | |||||
startActivity(intent); | |||||
finish(); | |||||
ActivityTaskManager.getInstance().finishAllActivity(); | |||||
} | |||||
private void getCode() { | |||||
String editPhone = edit_phone.getText().toString().trim(); | |||||
if (!PhoneUtils.isPhone(editPhone)){ | |||||
ToastUtil.makeText(this,"手机号格式不正确"); | |||||
return; | |||||
} | |||||
if (!EmptyUtils.isStringNotEmpty(editPhone)){ | |||||
return; | |||||
} | |||||
RxHttp.postForm(Api.sms_dode) | |||||
.add("mobile",editPhone) | |||||
.add("usage","register") | |||||
.asResponse(Object.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(object -> { | |||||
ToastUtil.makeText(this,"发送成功"); | |||||
timeCount = new TimeCount(1000 * 60, 1000); | |||||
timeCount.start(); | |||||
Log.e(TAG,"object = "+object.toString().substring(0,object.toString().length()-2)); | |||||
if (object != null){ | |||||
edit_code.setText(object.toString().substring(0,object.toString().length()-2)); | |||||
} | |||||
tv_error.setVisibility(View.GONE); | |||||
},(OnError) error -> { | |||||
String errorMsg = error.getErrorMsg(); | |||||
if (EmptyUtils.isStringNotEmpty(errorMsg)){ | |||||
tv_error.setVisibility(View.VISIBLE); | |||||
tv_error.setText(errorMsg); | |||||
} | |||||
}); | |||||
} | |||||
@Override | |||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||||
if (isChecked){ | |||||
checked = true; | |||||
}else { | |||||
checked = false; | |||||
} | |||||
} | |||||
/** | |||||
* 倒计时的内部类 | |||||
*/ | |||||
class TimeCount extends CountDownTimer { | |||||
/** | |||||
* @param millisInFuture The number of millis in the future from the call | |||||
* to {@link #start()} until the countdown is done and {@link #onFinish()} | |||||
* is called.总时长 | |||||
* @param countDownInterval The interval along the way to receive | |||||
* {@link #onTick(long)} callbacks. 计时的时间间隔 | |||||
*/ | |||||
public TimeCount(long millisInFuture, long countDownInterval) { | |||||
super(millisInFuture, countDownInterval); | |||||
} | |||||
@Override | |||||
public void onTick(long millisUntilFinished) {//计时过程显示 | |||||
tv_code_btn.setClickable(false); | |||||
tv_code_btn.setText((millisUntilFinished) / 1000 + "s"); | |||||
} | |||||
@Override | |||||
public void onFinish() {//计时完毕 | |||||
tv_code_btn.setClickable(true); | |||||
tv_code_btn.setText("获取验证码"); | |||||
} | |||||
} | |||||
@Override | |||||
protected void onDestroy() { | |||||
super.onDestroy(); | |||||
if (timeCount != null){ | |||||
timeCount.cancel(); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import androidx.annotation.BinderThread; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import android.content.Intent; | |||||
import android.media.Image; | |||||
import android.net.Uri; | |||||
import android.os.Bundle; | |||||
import android.os.Environment; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.widget.ImageView; | |||||
import com.bumptech.glide.Glide; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.utils.GlideEngine; | |||||
import com.example.tidalairpeisong.utils.RuntimeRationale; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import com.example.tidalairpeisong.view.InputEditText; | |||||
import com.luck.picture.lib.PictureSelector; | |||||
import com.luck.picture.lib.config.PictureConfig; | |||||
import com.luck.picture.lib.config.PictureMimeType; | |||||
import com.luck.picture.lib.entity.LocalMedia; | |||||
import com.luck.picture.lib.listener.OnResultCallbackListener; | |||||
import com.yanzhenjie.permission.Action; | |||||
import com.yanzhenjie.permission.AndPermission; | |||||
import com.yanzhenjie.permission.runtime.Permission; | |||||
import java.io.File; | |||||
import java.util.List; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
/** | |||||
* | |||||
* @ProjectName: tidalair | |||||
* @Package: com.example.tidalair | |||||
* @ClassName: 上传认证信息 | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class RenZhengActivity extends BaseActivity { | |||||
@BindView(R.id.et_name) | |||||
InputEditText et_name; | |||||
@BindView(R.id.et_shenfenzheng) | |||||
InputEditText et_shenfenzheng; | |||||
@BindView(R.id.img_zhengmian) | |||||
ImageView img_zhengmian; | |||||
@BindView(R.id.img_fanmian) | |||||
ImageView img_fanmian; | |||||
private boolean isZhengmian = true; | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_ren_zheng); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
} | |||||
@OnClick({R.id.rl_back,R.id.img_zhengmian,R.id.img_fanmian}) | |||||
public void onClick(View view){ | |||||
switch (view.getId()){ | |||||
case R.id.rl_back: | |||||
finish(); | |||||
break; | |||||
case R.id.img_zhengmian: | |||||
requestPermission(Permission.CAMERA); | |||||
isZhengmian = true; | |||||
takePhotot(); | |||||
break; | |||||
case R.id.img_fanmian: | |||||
requestPermission(Permission.CAMERA); | |||||
isZhengmian = false; | |||||
takePhotot(); | |||||
break; | |||||
} | |||||
} | |||||
private void requestPermission(String permissions) { | |||||
AndPermission.with(this) | |||||
.runtime() | |||||
.permission(permissions) | |||||
.rationale(new RuntimeRationale()) | |||||
.onGranted(new Action<List<String>>() { | |||||
@Override | |||||
public void onAction(List<String> permissions) { | |||||
Log.e("csd0","获取成功"); | |||||
} | |||||
}) | |||||
.onDenied(new Action<List<String>>() { | |||||
@Override | |||||
public void onAction(@NonNull List<String> permissions) { | |||||
Log.e("csd1","获取成功"); | |||||
} | |||||
}) | |||||
.start(); | |||||
} | |||||
private void takePhotot() { | |||||
PictureSelector.create(this) | |||||
.openCamera(PictureMimeType.ofImage()) | |||||
.imageEngine(GlideEngine.createGlideEngine()) | |||||
.forResult(new OnResultCallbackListener<LocalMedia>() { | |||||
@Override | |||||
public void onResult(List<LocalMedia> result) { | |||||
// onResult Callback | |||||
Log.e("csd",result.toString()); | |||||
String realPath = result.get(0).getRealPath(); | |||||
String fileName = result.get(0).getFileName(); | |||||
updateImg(realPath,fileName); | |||||
} | |||||
@Override | |||||
public void onCancel() { | |||||
// onCancel Callback | |||||
} | |||||
}); | |||||
} | |||||
private void updateImg(String realPath, String fileName) { | |||||
if (isZhengmian){ | |||||
Glide.with(this) | |||||
.load(Uri.fromFile(new File(realPath))) | |||||
.into(img_zhengmian); | |||||
}else { | |||||
Glide.with(this) | |||||
.load(Uri.fromFile(new File(realPath))) | |||||
.into(img_fanmian); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.content.Intent; | |||||
import android.os.Bundle; | |||||
import android.text.Editable; | |||||
import android.text.InputType; | |||||
import android.text.TextWatcher; | |||||
import android.view.View; | |||||
import android.widget.EditText; | |||||
import android.widget.ImageView; | |||||
import android.widget.TextView; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.rxhttp.error.OnError; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.user.ui.activity.MainActivity; | |||||
import com.example.tidalairpeisong.user.bean.RegisterBean; | |||||
import com.example.tidalairpeisong.utils.ActivityTaskManager; | |||||
import com.example.tidalairpeisong.utils.EditTextUtil; | |||||
import com.example.tidalairpeisong.utils.EmptyUtils; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import com.example.tidalairpeisong.utils.ToastUtil; | |||||
import com.rxjava.rxlife.RxLife; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
import rxhttp.wrapper.param.RxHttp; | |||||
public class ResetPwdActivity extends BaseActivity { | |||||
@BindView(R.id.edit_pwd1) | |||||
EditText edit_pwd1; | |||||
@BindView(R.id.edit_pwd2) | |||||
EditText edit_pwd2; | |||||
@BindView(R.id.tv_error) | |||||
TextView tv_error; | |||||
@BindView(R.id.eye1) | |||||
ImageView eye1; | |||||
@BindView(R.id.eye2) | |||||
ImageView eye2; | |||||
@BindView(R.id.tv_reset) | |||||
TextView tv_reset; | |||||
private boolean eye1_show = false; | |||||
private boolean eye2_show = false; | |||||
private String mobile; | |||||
private String code; | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_reset_pwd); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
initView(); | |||||
} | |||||
private void initView() { | |||||
Intent intent = getIntent(); | |||||
mobile = intent.getStringExtra("mobile"); | |||||
code = intent.getStringExtra("code"); | |||||
EditTextUtil.setEditTextInputSpace(edit_pwd1); | |||||
EditTextUtil.setMaxLength(edit_pwd1,15); | |||||
EditTextUtil.setEditTextInputSpace(edit_pwd2); | |||||
EditTextUtil. setMaxLength(edit_pwd2,15); | |||||
edit_pwd1.addTextChangedListener(new TextWatcher() { | |||||
@Override | |||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |||||
} | |||||
@Override | |||||
public void onTextChanged(CharSequence s, int start, int before, int count) { | |||||
if (s.length() > 0){ | |||||
eye1.setVisibility(View.VISIBLE); | |||||
eye1.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye1_show = true; | |||||
}else { | |||||
eye1.setVisibility(View.GONE); | |||||
eye1_show = false; | |||||
} | |||||
} | |||||
@Override | |||||
public void afterTextChanged(Editable s) { | |||||
} | |||||
}); | |||||
edit_pwd2.addTextChangedListener(new TextWatcher() { | |||||
@Override | |||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |||||
} | |||||
@Override | |||||
public void onTextChanged(CharSequence s, int start, int before, int count) { | |||||
if (s.length() > 0){ | |||||
eye2.setVisibility(View.VISIBLE); | |||||
eye2.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye2_show = true; | |||||
}else { | |||||
eye2.setVisibility(View.GONE); | |||||
eye2_show = false; | |||||
} | |||||
} | |||||
@Override | |||||
public void afterTextChanged(Editable s) { | |||||
} | |||||
}); | |||||
} | |||||
@OnClick({R.id.eye1,R.id.eye2,R.id.tv_reset}) | |||||
public void onClick(View view){ | |||||
switch (view.getId()){ | |||||
case R.id.eye1: | |||||
if (eye1_show){ | |||||
edit_pwd1.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | |||||
eye1.setImageResource(R.mipmap.denglu_ic_eye_closed); | |||||
eye1_show = false; | |||||
}else{ | |||||
edit_pwd1.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); | |||||
eye1.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye1_show = true; | |||||
} | |||||
break; | |||||
case R.id.eye2: | |||||
if (eye2_show){ | |||||
edit_pwd2.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | |||||
eye2.setImageResource(R.mipmap.denglu_ic_eye_closed); | |||||
eye2_show = false; | |||||
}else{ | |||||
edit_pwd2.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); | |||||
eye2.setImageResource(R.mipmap.denglu_ic_eye_opened); | |||||
eye2_show = true; | |||||
} | |||||
break; | |||||
case R.id.tv_reset: | |||||
resetPwd(); | |||||
break; | |||||
} | |||||
} | |||||
private void resetPwd() { | |||||
String pwd1 = edit_pwd1.getText().toString().trim(); | |||||
String pwd2 = edit_pwd2.getText().toString().trim(); | |||||
if (pwd1.isEmpty() || pwd2.isEmpty()){ | |||||
ToastUtil.makeText(this,"密码不能为空"); | |||||
return; | |||||
} | |||||
if (pwd1.length() < 6 || pwd2.length() < 6){ | |||||
ToastUtil.makeText(this,"密码不能少于6位"); | |||||
return; | |||||
} | |||||
if (!pwd1.equals(pwd2)){ | |||||
ToastUtil.makeText(this,"两次密码不一致"); | |||||
return; | |||||
} | |||||
RxHttp.postForm(Api.up_pwd) | |||||
.add("mobile",mobile) | |||||
.add("code",code) | |||||
.add("password",pwd1) | |||||
.add("password_repetition",pwd2) | |||||
.add("group","tinyShopApp") | |||||
.asResponse(RegisterBean.class) | |||||
.to(RxLife.asOnMain(this)) | |||||
.subscribe(registerBean -> { | |||||
initUi(registerBean); | |||||
tv_error.setVisibility(View.GONE); | |||||
},(OnError) error -> { | |||||
String errorMsg = error.getErrorMsg(); | |||||
if (EmptyUtils.isStringNotEmpty(errorMsg)){ | |||||
tv_error.setVisibility(View.VISIBLE); | |||||
tv_error.setText(errorMsg); | |||||
} | |||||
}); | |||||
} | |||||
private void initUi(RegisterBean registerBean) { | |||||
PrefUtils.putString(this,"refresh_token",registerBean.getRefresh_token()); | |||||
PrefUtils.putString(this,"access_token",registerBean.getAccess_token()); | |||||
PrefUtils.putString(this,"member_id",registerBean.getMember().getId()+""); | |||||
PrefUtils.putString(this,"user_type","user"); | |||||
PrefUtils.putString(this,"expiration_time",registerBean.getExpiration_time()+""); | |||||
PrefUtils.putString(this,"phone",registerBean.getMember().getMobile()); | |||||
ToastUtil.makeText(ResetPwdActivity.this,"注册成功"); | |||||
Intent intent = new Intent(ResetPwdActivity.this, MainActivity.class); | |||||
intent.putExtra("from","register"); | |||||
startActivity(intent); | |||||
finish(); | |||||
ActivityTaskManager.getInstance().finishAllActivity(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.os.Bundle; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
public class RuleActivity extends BaseActivity { | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_rule); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.login; | |||||
import android.os.Bundle; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
public class SetPwdActivity extends BaseActivity { | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_set_pwd); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.white)); | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.activity.mine; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import android.content.Intent; | |||||
import android.os.Bundle; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseActivity; | |||||
import com.example.tidalairpeisong.user.ui.activity.login.RenZhengActivity; | |||||
import com.example.tidalairpeisong.utils.RuntimeRationale; | |||||
import com.example.tidalairpeisong.utils.StatusBarUtils; | |||||
import com.yanzhenjie.permission.Action; | |||||
import com.yanzhenjie.permission.AndPermission; | |||||
import com.yanzhenjie.permission.runtime.Permission; | |||||
import java.util.List; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
public class SettingActivity extends BaseActivity { | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_setting); | |||||
ButterKnife.bind(this); | |||||
StatusBarUtils.setTransparent(this); | |||||
StatusBarUtils.setTextDark(this,true); | |||||
StatusBarUtils.setColor(this, getResources().getColor(R.color.clolo_F2F4F7)); | |||||
} | |||||
@OnClick({R.id.rl_back,R.id.rl_login_out}) | |||||
public void onClick(View view){ | |||||
Intent intent; | |||||
switch (view.getId()){ | |||||
case R.id.rl_back: | |||||
finish(); | |||||
break; | |||||
case R.id.rl_login_out: | |||||
intent = new Intent(this, RenZhengActivity.class); | |||||
startActivity(intent); | |||||
break; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.fragment.main; | |||||
import android.content.Intent; | |||||
import android.os.Bundle; | |||||
import androidx.fragment.app.Fragment; | |||||
import android.util.Log; | |||||
import android.view.LayoutInflater; | |||||
import android.view.View; | |||||
import android.view.ViewGroup; | |||||
import android.widget.ImageView; | |||||
import android.widget.RelativeLayout; | |||||
import android.widget.TextView; | |||||
import com.bumptech.glide.Glide; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseFragment; | |||||
import com.example.tidalairpeisong.rxhttp.error.OnError; | |||||
import com.example.tidalairpeisong.rxhttp.url.Api; | |||||
import com.example.tidalairpeisong.user.bean.MemberBean; | |||||
import com.example.tidalairpeisong.user.ui.activity.mine.SettingActivity; | |||||
import com.example.tidalairpeisong.utils.EmptyUtils; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import com.example.tidalairpeisong.utils.ToastUtil; | |||||
import com.rxjava.rxlife.RxLife; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
import butterknife.OnClick; | |||||
import de.hdodenhof.circleimageview.CircleImageView; | |||||
import rxhttp.wrapper.param.RxHttp; | |||||
/** | |||||
* A simple {@link Fragment} subclass. | |||||
* Use the {@link MineFragment#} factory method to | |||||
* create an instance of this fragment. | |||||
*/ | |||||
public class MineFragment extends BaseFragment { | |||||
private String access_token; | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |||||
Bundle savedInstanceState) { | |||||
// Inflate the layout for this fragment | |||||
View view = inflater.inflate(R.layout.fragment_mine, container, false); | |||||
ButterKnife.bind(this,view); | |||||
access_token = PrefUtils.getString(getContext(), "access_token", ""); | |||||
Log.e("csd", String.valueOf(access_token)); | |||||
initData(); | |||||
return view; | |||||
} | |||||
private void initData() { | |||||
} | |||||
@OnClick({R.id.rl_set}) | |||||
public void onClick(View view){ | |||||
Intent intent; | |||||
switch (view.getId()){ | |||||
case R.id.rl_set: | |||||
intent = new Intent(getContext(), SettingActivity.class); | |||||
startActivity(intent); | |||||
break; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.fragment.main; | |||||
import android.content.Context; | |||||
import android.graphics.Color; | |||||
import android.graphics.Typeface; | |||||
import android.os.Bundle; | |||||
import androidx.camera.core.Logger; | |||||
import androidx.fragment.app.Fragment; | |||||
import androidx.fragment.app.FragmentManager; | |||||
import androidx.fragment.app.FragmentTransaction; | |||||
import androidx.viewpager.widget.ViewPager; | |||||
import android.util.Log; | |||||
import android.view.LayoutInflater; | |||||
import android.view.View; | |||||
import android.view.ViewGroup; | |||||
import android.view.animation.AccelerateInterpolator; | |||||
import android.view.animation.DecelerateInterpolator; | |||||
import android.widget.RelativeLayout; | |||||
import android.widget.TextView; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseFragment; | |||||
import com.example.tidalairpeisong.user.adapter.TabFragmentAdapter; | |||||
import com.example.tidalairpeisong.user.ui.fragment.order.OrderChildFragment; | |||||
import com.example.tidalairpeisong.utils.PrefUtils; | |||||
import com.flyco.tablayout.SlidingTabLayout; | |||||
import com.google.android.material.tabs.TabLayout; | |||||
import net.lucode.hackware.magicindicator.FragmentContainerHelper; | |||||
import net.lucode.hackware.magicindicator.MagicIndicator; | |||||
import net.lucode.hackware.magicindicator.ViewPagerHelper; | |||||
import net.lucode.hackware.magicindicator.buildins.UIUtil; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgeAnchor; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView; | |||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgeRule; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
/** | |||||
* A simple {@link Fragment} subclass. | |||||
* Use the {@link OrderFragment#} factory method to | |||||
* create an instance of this fragment. | |||||
*/ | |||||
public class OrderFragment extends BaseFragment { | |||||
@BindView(R.id.tablayout) | |||||
TabLayout tablayout; | |||||
@BindView(R.id.vp_order) | |||||
ViewPager vp_order; | |||||
private static final String[] CHANNELS = new String[]{"待接单","待配送","已完成","订单池"}; | |||||
private List<String> mDataList = Arrays.asList(CHANNELS); | |||||
private ArrayList<BaseFragment> fragments; | |||||
private static final int[] nums = new int[]{0,1,2,2}; | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |||||
Bundle savedInstanceState) { | |||||
// Inflate the layout for this fragment | |||||
View view = inflater.inflate(R.layout.fragment_order, container, false); | |||||
ButterKnife.bind(this,view); | |||||
initViewPager(); | |||||
return view; | |||||
} | |||||
private void initViewPager() { | |||||
fragments = new ArrayList<>(); | |||||
for (int i = 0; i < CHANNELS.length; i++){ | |||||
OrderChildFragment orderChildFragment = new OrderChildFragment(); | |||||
Bundle bundle = new Bundle(); | |||||
bundle.putString("type",CHANNELS[i]); | |||||
orderChildFragment.setArguments(bundle); | |||||
fragments.add(orderChildFragment); | |||||
} | |||||
TabFragmentAdapter tabFragmentAdapter = new TabFragmentAdapter(getChildFragmentManager(),fragments, CHANNELS); | |||||
vp_order.setAdapter(tabFragmentAdapter); | |||||
tablayout.setupWithViewPager(vp_order);//让tablayout与viewpager建立关联关系 | |||||
for (int i =0;i<CHANNELS.length;i++){ | |||||
setTabItem(CHANNELS,i,nums); | |||||
} | |||||
//tablayout选中状态的一些UI更新 | |||||
tablayout.addOnTabSelectedListener(new TabLayout.BaseOnTabSelectedListener() { | |||||
@Override | |||||
public void onTabSelected(TabLayout.Tab tab) { | |||||
View view = tab.getCustomView(); | |||||
TextView textView = view.findViewById(R.id.tv); | |||||
textView.setTextColor(getResources().getColor(R.color.color_145ECC)); | |||||
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); | |||||
textView.setTextSize(15); | |||||
} | |||||
@Override | |||||
public void onTabUnselected(TabLayout.Tab tab) { | |||||
View view = tab.getCustomView(); | |||||
TextView textView = view.findViewById(R.id.tv); | |||||
textView.setTextColor(getResources().getColor(R.color.color_8390A3)); | |||||
textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); | |||||
textView.setTextSize(12); | |||||
} | |||||
@Override | |||||
public void onTabReselected(TabLayout.Tab tab) { | |||||
} | |||||
}); | |||||
chooseFirst(); | |||||
} | |||||
private void chooseFirst() { | |||||
TabLayout.Tab tabAt = tablayout.getTabAt(0); | |||||
View view = tabAt.getCustomView(); | |||||
TextView textView = view.findViewById(R.id.tv); | |||||
textView.setTextColor(getResources().getColor(R.color.color_145ECC)); | |||||
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); | |||||
textView.setTextSize(15); | |||||
} | |||||
private void setTabItem(String[] titleArry, int i, int[] nums) { | |||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.tablayout_item, null); | |||||
TextView textView = (TextView) view.findViewById(R.id.tv); | |||||
TextView tv_num = (TextView) view.findViewById(R.id.tv_num); | |||||
RelativeLayout rl_num = (RelativeLayout) view.findViewById(R.id.rl_num); | |||||
textView.setText(titleArry[i]); | |||||
tablayout.getTabAt(i).setCustomView(view); | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.fragment.main; | |||||
import android.os.Bundle; | |||||
import androidx.fragment.app.Fragment; | |||||
import android.view.LayoutInflater; | |||||
import android.view.View; | |||||
import android.view.ViewGroup; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseFragment; | |||||
/** | |||||
* A simple {@link Fragment} subclass. | |||||
* Use the {@link SaoMaFragment#} factory method to | |||||
* create an instance of this fragment. | |||||
*/ | |||||
public class SaoMaFragment extends BaseFragment { | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |||||
Bundle savedInstanceState) { | |||||
// Inflate the layout for this fragment | |||||
return inflater.inflate(R.layout.fragment_sao_ma, container, false); | |||||
} | |||||
} |
package com.example.tidalairpeisong.user.ui.fragment.order; | |||||
import android.os.Bundle; | |||||
import androidx.fragment.app.Fragment; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import android.view.LayoutInflater; | |||||
import android.view.View; | |||||
import android.view.ViewGroup; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.example.tidalairpeisong.base.BaseFragment; | |||||
import com.example.tidalairpeisong.user.adapter.RvOrderAdapter; | |||||
import com.example.tidalairpeisong.utils.SpacesItemDecoration; | |||||
import com.scwang.smart.refresh.layout.SmartRefreshLayout; | |||||
import java.util.ArrayList; | |||||
import butterknife.BindView; | |||||
import butterknife.ButterKnife; | |||||
/** | |||||
* A simple {@link Fragment} subclass. | |||||
* Use the {@link OrderChildFragment#} factory method to | |||||
* create an instance of this fragment. | |||||
*/ | |||||
public class OrderChildFragment extends BaseFragment { | |||||
@BindView(R.id.smartRefreshLayout) | |||||
SmartRefreshLayout smartRefreshLayout; | |||||
@BindView(R.id.rv_order) | |||||
RecyclerView rv_order; | |||||
private RvOrderAdapter adapter; | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |||||
Bundle savedInstanceState) { | |||||
// Inflate the layout for this fragment | |||||
View view = inflater.inflate(R.layout.fragment_order_child, container, false); | |||||
ButterKnife.bind(this,view); | |||||
Bundle arguments = getArguments(); | |||||
initRvOrder(); | |||||
return view; | |||||
} | |||||
private void initRvOrder() { | |||||
ArrayList<String> strings = new ArrayList<>(); | |||||
for (int i = 0; i < 5; i++){ | |||||
strings.add("item"+i); | |||||
} | |||||
adapter = new RvOrderAdapter(R.layout.item_rv_order, strings); | |||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); | |||||
linearLayoutManager.setOrientation(RecyclerView.VERTICAL); | |||||
rv_order.setLayoutManager(linearLayoutManager); | |||||
rv_order.setAdapter(adapter); | |||||
if (rv_order.getItemDecorationCount() == 0 ) { | |||||
rv_order.addItemDecoration(new SpacesItemDecoration(30)); | |||||
} | |||||
} | |||||
@Override | |||||
public void onResume() { | |||||
super.onResume(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.app.Activity; | |||||
import java.util.Iterator; | |||||
import java.util.Stack; | |||||
public class ActivityTaskManager { | |||||
public static Stack<Activity> getActivityStack() { | |||||
return activityStack; | |||||
} | |||||
private static Stack<Activity> activityStack; | |||||
private static ActivityTaskManager instance; | |||||
private ActivityTaskManager() { | |||||
} | |||||
/** | |||||
* 单一实例 | |||||
*/ | |||||
public static ActivityTaskManager getInstance() { | |||||
if (instance == null) { | |||||
instance = new ActivityTaskManager(); | |||||
} | |||||
return instance; | |||||
} | |||||
/** | |||||
* 添加Activity到堆栈 | |||||
*/ | |||||
public void addActivity(Activity activity) { | |||||
if (activityStack == null) { | |||||
activityStack = new Stack<>(); | |||||
} | |||||
activityStack.add(activity); | |||||
} | |||||
/** | |||||
* 获取栈顶Activity(堆栈中最后一个压入的) | |||||
*/ | |||||
public Activity getTopActivity() { | |||||
return activityStack.lastElement(); | |||||
} | |||||
/** | |||||
* 结束栈顶Activity(堆栈中最后一个压入的) | |||||
*/ | |||||
public void finishTopActivity() { | |||||
Activity activity = activityStack.lastElement(); | |||||
finishActivity(activity); | |||||
} | |||||
/** | |||||
* 结束指定类名的Activity | |||||
* | |||||
* @param cls | |||||
*/ | |||||
public void finishActivity(Class<?> cls) { | |||||
Iterator iterator = activityStack.iterator(); | |||||
while (iterator.hasNext()) { | |||||
Activity activity = (Activity) iterator.next(); | |||||
if (activity.getClass().equals(cls)) { | |||||
iterator.remove(); | |||||
activity.finish(); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 结束所有Activity | |||||
*/ | |||||
@SuppressWarnings("WeakerAccess") | |||||
public void finishAllActivity() { | |||||
for (int i = 0, size = activityStack.size(); i < size; i++) { | |||||
if (null != activityStack.get(i)) { | |||||
activityStack.get(i).finish(); | |||||
} | |||||
} | |||||
activityStack.clear(); | |||||
} | |||||
/** | |||||
* 除指定Activity,结束所有Activity | |||||
*/ | |||||
@SuppressWarnings("WeakerAccess") | |||||
public void finishAllActivityExcept(Class<?> cls) { | |||||
Iterator iterator = activityStack.iterator(); | |||||
while (iterator.hasNext()) { | |||||
Activity activity = (Activity) iterator.next(); | |||||
if (!activity.getClass().equals(cls)) { | |||||
iterator.remove(); | |||||
activity.finish(); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 退出应用程序 | |||||
*/ | |||||
public void appExit() { | |||||
try { | |||||
finishAllActivity(); | |||||
System.exit(0); | |||||
android.os.Process.killProcess(android.os.Process.myPid()); | |||||
} catch (Exception e) { | |||||
} | |||||
} | |||||
/** | |||||
* 结束指定的Activity | |||||
*/ | |||||
public void finishActivity(Activity activity) { | |||||
if (activity != null) { | |||||
activityStack.remove(activity); | |||||
activity.finish(); | |||||
activity = null; | |||||
} | |||||
} | |||||
/** | |||||
* 得到指定类名的Activity | |||||
*/ | |||||
public Activity getActivity(Class<?> cls) { | |||||
for (Activity activity : activityStack) { | |||||
if (activity.getClass().equals(cls)) { | |||||
return activity; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.app.Activity; | |||||
import android.app.ActivityManager; | |||||
import android.content.ComponentName; | |||||
import android.content.Context; | |||||
import androidx.fragment.app.Fragment; | |||||
import com.example.tidalairpeisong.user.ui.activity.SplashActivity; | |||||
import java.util.List; | |||||
import java.util.Stack; | |||||
/** | |||||
* activity堆栈式管理 | |||||
*/ | |||||
public class AppManager { | |||||
private static Stack<Activity> activityStack; | |||||
private static Stack<Fragment> fragmentStack; | |||||
private static AppManager instance; | |||||
private AppManager() { | |||||
} | |||||
/** | |||||
* 单例模式 | |||||
* | |||||
* @return AppManager | |||||
*/ | |||||
public static AppManager getAppManager() { | |||||
if (instance == null) { | |||||
instance = new AppManager(); | |||||
} | |||||
return instance; | |||||
} | |||||
public static Stack<Activity> getActivityStack() { | |||||
return activityStack; | |||||
} | |||||
public static Stack<Fragment> getFragmentStack() { | |||||
return fragmentStack; | |||||
} | |||||
public void finishLoginModelActivity() { | |||||
if (activityStack != null) { | |||||
finishActivity(SplashActivity.class); | |||||
} | |||||
} | |||||
public void finishForgetActivity() { | |||||
if (activityStack != null) { | |||||
} | |||||
} | |||||
public void finishSplashActivity() { | |||||
if (activityStack != null) { | |||||
finishActivity(SplashActivity.class); | |||||
} | |||||
} | |||||
public void finishBranchCertActivity() { | |||||
if (activityStack != null) { | |||||
} | |||||
} | |||||
public void finishBranchListActivity() { | |||||
if (activityStack != null) { | |||||
} | |||||
} | |||||
public void finishBranchActivity() { | |||||
if (activityStack != null) { | |||||
} | |||||
} | |||||
public void finishApplyShopMoveInActivity() { | |||||
if (activityStack != null) { | |||||
} | |||||
} | |||||
/** | |||||
* 添加Activity到堆栈 | |||||
*/ | |||||
public void addActivity(Activity activity) { | |||||
if (activityStack == null) { | |||||
activityStack = new Stack<Activity>(); | |||||
} | |||||
activityStack.add(activity); | |||||
} | |||||
/** | |||||
* 移除指定的Activity | |||||
*/ | |||||
public void removeActivity(Activity activity) { | |||||
if (activityStack != null && activity != null) { | |||||
activityStack.remove(activity); | |||||
} | |||||
} | |||||
/** | |||||
* 是否有activity | |||||
*/ | |||||
public boolean isActivity() { | |||||
if (activityStack != null) { | |||||
return activityStack.isEmpty(); | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* 获取当前Activity(堆栈中最后一个压入的) | |||||
*/ | |||||
public Activity currentActivity() { | |||||
Activity activity = null; | |||||
if (activityStack != null) { | |||||
activity = activityStack.lastElement(); | |||||
} | |||||
return activity; | |||||
} | |||||
/** | |||||
* 判断某activity是否处于栈顶 | |||||
* | |||||
* @return true在栈顶 false不在栈顶 | |||||
*/ | |||||
private boolean isActivityTop(Class cls, Context context) { | |||||
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |||||
String name = manager.getRunningTasks(1).get(0).topActivity.getClassName(); | |||||
return name.equals(cls.getName()); | |||||
} | |||||
/** | |||||
* 结束当前Activity(堆栈中最后一个压入的) | |||||
*/ | |||||
public void finishActivity() { | |||||
if (activityStack != null) { | |||||
Activity activity = activityStack.lastElement(); | |||||
finishActivity(activity); | |||||
} | |||||
} | |||||
/** | |||||
* 结束指定的Activity | |||||
*/ | |||||
public void finishActivity(Activity activity) { | |||||
if (activity != null) { | |||||
if (!activity.isFinishing()) { | |||||
activity.finish(); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 结束指定类名的Activity | |||||
*/ | |||||
public void finishActivity(Class<?> cls) { | |||||
if (activityStack != null) { | |||||
for (Activity activity : activityStack) { | |||||
if (activity.getClass().equals(cls)) { | |||||
finishActivity(activity); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 结束所有Activity | |||||
*/ | |||||
public void finishAllActivity() { | |||||
if (activityStack != null) { | |||||
for (int i = 0, size = activityStack.size(); i < size; i++) { | |||||
if (null != activityStack.get(i)) { | |||||
finishActivity(activityStack.get(i)); | |||||
} | |||||
} | |||||
activityStack.clear(); | |||||
} | |||||
} | |||||
/** | |||||
* 获取指定的Activity | |||||
* | |||||
* @author kymjs | |||||
*/ | |||||
public static Activity getActivity(Class<?> cls) { | |||||
if (activityStack != null) | |||||
for (Activity activity : activityStack) { | |||||
if (activity.getClass().equals(cls)) { | |||||
return activity; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
/** | |||||
* 添加Fragment到堆栈 | |||||
*/ | |||||
public void addFragment(Fragment fragment) { | |||||
if (fragmentStack == null) { | |||||
fragmentStack = new Stack<Fragment>(); | |||||
} | |||||
fragmentStack.add(fragment); | |||||
} | |||||
/** | |||||
* 移除指定的Fragment | |||||
*/ | |||||
public void removeFragment(Fragment fragment) { | |||||
if (fragment != null) { | |||||
fragmentStack.remove(fragment); | |||||
} | |||||
} | |||||
/** | |||||
* 是否有Fragment | |||||
*/ | |||||
public boolean isFragment() { | |||||
if (fragmentStack != null) { | |||||
return fragmentStack.isEmpty(); | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* 获取当前Activity(堆栈中最后一个压入的) | |||||
*/ | |||||
public Fragment currentFragment() { | |||||
if (fragmentStack != null) { | |||||
Fragment fragment = fragmentStack.lastElement(); | |||||
return fragment; | |||||
} | |||||
return null; | |||||
} | |||||
/** | |||||
* 退出应用程序 | |||||
*/ | |||||
public void AppExit() { | |||||
try { | |||||
finishAllActivity(); | |||||
// 杀死该应用进程 | |||||
// android.os.Process.killProcess(android.os.Process.myPid()); | |||||
// 调用 System.exit(n) 实际上等效于调用: | |||||
// Runtime.getRuntime().exit(n) | |||||
// finish()是Activity的类方法,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没有立即释放内存,活动的资源并没有被清理;当调用System.exit(0)时,退出当前Activity并释放资源(内存),但是该方法不可以结束整个App如有多个Activty或者有其他组件service等不会结束。 | |||||
// 其实android的机制决定了用户无法完全退出应用,当你的application最长时间没有被用过的时候,android自身会决定将application关闭了。 | |||||
//System.exit(0); | |||||
} catch (Exception e) { | |||||
if (activityStack != null) | |||||
activityStack.clear(); | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
/** | |||||
* *判断当前应用程序处于前台还是后台 | |||||
* | |||||
*/ | |||||
public static boolean isApplicationBroughtToBackground(final Context context) { | |||||
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |||||
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); | |||||
if (!tasks.isEmpty()) { | |||||
ComponentName topActivity = tasks.get(0).topActivity; | |||||
if (!topActivity.getPackageName().equals(context.getPackageName())) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public static String getRunningActivityName(Context context) { | |||||
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |||||
//完整类名 | |||||
String runningActivity = activityManager.getRunningTasks(1).get(0).topActivity.getClassName(); | |||||
String contextActivity = runningActivity.substring(runningActivity.lastIndexOf(".") + 1); | |||||
return contextActivity; | |||||
} | |||||
public static String getAppPackageName(Context context) { | |||||
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |||||
List<ActivityManager.RunningTaskInfo> taskInfo = activityManager.getRunningTasks(1); | |||||
ComponentName componentInfo = taskInfo.get(0).topActivity; | |||||
return componentInfo.getPackageName(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.annotation.TargetApi; | |||||
import android.content.ContentUris; | |||||
import android.content.Context; | |||||
import android.content.res.ColorStateList; | |||||
import android.content.res.Resources; | |||||
import android.database.Cursor; | |||||
import android.graphics.Bitmap; | |||||
import android.graphics.BitmapFactory; | |||||
import android.graphics.Canvas; | |||||
import android.graphics.Color; | |||||
import android.graphics.drawable.BitmapDrawable; | |||||
import android.graphics.drawable.ColorDrawable; | |||||
import android.graphics.drawable.Drawable; | |||||
import android.graphics.drawable.NinePatchDrawable; | |||||
import android.net.Uri; | |||||
import android.os.Build; | |||||
import android.os.Environment; | |||||
import android.provider.DocumentsContract; | |||||
import android.provider.MediaStore; | |||||
import androidx.annotation.ColorInt; | |||||
import androidx.annotation.FloatRange; | |||||
import android.text.TextUtils; | |||||
import android.util.TypedValue; | |||||
import android.view.View; | |||||
import android.widget.ListView; | |||||
import android.widget.ScrollView; | |||||
import java.io.BufferedReader; | |||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import java.io.InputStreamReader; | |||||
import java.io.UnsupportedEncodingException; | |||||
import java.nio.ByteBuffer; | |||||
import java.text.DecimalFormat; | |||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
/** | |||||
* 数据类型转换、单位转换 | |||||
* @author matt | |||||
* blog: addapp.cn | |||||
*/ | |||||
public class ConvertUtils { | |||||
public static final long GB = 1073741824; | |||||
public static final long MB = 1048576; | |||||
public static final long KB = 1024; | |||||
public static int toInt(Object obj) { | |||||
try { | |||||
return Integer.parseInt(obj.toString()); | |||||
} catch (NumberFormatException e) { | |||||
return -1; | |||||
} | |||||
} | |||||
public static int toInt(byte[] bytes) { | |||||
int result = 0; | |||||
byte abyte; | |||||
for (int i = 0; i < bytes.length; i++) { | |||||
abyte = bytes[i]; | |||||
result += (abyte & 0xFF) << (8 * i); | |||||
} | |||||
return result; | |||||
} | |||||
public static int toShort(byte first, byte second) { | |||||
return (first << 8) + (second & 0xFF); | |||||
} | |||||
public static long toLong(Object obj) { | |||||
try { | |||||
return Long.parseLong(obj.toString()); | |||||
} catch (NumberFormatException e) { | |||||
return -1L; | |||||
} | |||||
} | |||||
public static float toFloat(Object obj) { | |||||
try { | |||||
return Float.parseFloat(obj.toString()); | |||||
} catch (NumberFormatException e) { | |||||
return -1f; | |||||
} | |||||
} | |||||
/** | |||||
* int占4字节 | |||||
* | |||||
* @param i the | |||||
* @return byte [ ] | |||||
*/ | |||||
public static byte[] toByteArray(int i) { | |||||
// byte[] bytes = new byte[4]; | |||||
// bytes[0] = (byte) (0xff & i); | |||||
// bytes[1] = (byte) ((0xff00 & i) >> 8); | |||||
// bytes[2] = (byte) ((0xff0000 & i) >> 16); | |||||
// bytes[3] = (byte) ((0xff000000 & i) >> 24); | |||||
// return bytes; | |||||
return ByteBuffer.allocate(4).putInt(i).array(); | |||||
} | |||||
public static byte[] toByteArray(String hexData, boolean isHex) { | |||||
if (hexData == null || hexData.equals("")) { | |||||
return null; | |||||
} | |||||
if (!isHex) { | |||||
return hexData.getBytes(); | |||||
} | |||||
hexData = hexData.replaceAll("\\s+", ""); | |||||
String hexDigits = "0123456789ABCDEF"; | |||||
ByteArrayOutputStream baos = new ByteArrayOutputStream( | |||||
hexData.length() / 2); | |||||
// 将每2位16进制整数组装成一个字节 | |||||
for (int i = 0; i < hexData.length(); i += 2) { | |||||
baos.write((hexDigits.indexOf(hexData.charAt(i)) << 4 | hexDigits | |||||
.indexOf(hexData.charAt(i + 1)))); | |||||
} | |||||
byte[] bytes = baos.toByteArray(); | |||||
try { | |||||
baos.close(); | |||||
} catch (IOException e) { | |||||
} | |||||
return bytes; | |||||
} | |||||
public static String toHexString(String str) { | |||||
if (TextUtils.isEmpty(str)) | |||||
return ""; | |||||
StringBuilder builder = new StringBuilder(); | |||||
byte[] bytes = str.getBytes(); | |||||
for (byte aByte : bytes) { | |||||
builder.append(Integer.toHexString(0xFF & aByte)); | |||||
builder.append(" "); | |||||
} | |||||
return builder.toString(); | |||||
} | |||||
/** | |||||
* To hex string string. | |||||
* | |||||
* @param bytes the bytes | |||||
* @return the string | |||||
*/ | |||||
public static String toHexString(byte... bytes) { | |||||
char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', | |||||
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; | |||||
// 参见:http://www.oschina.net/code/snippet_116768_9019 | |||||
char[] buffer = new char[bytes.length * 2]; | |||||
for (int i = 0, j = 0; i < bytes.length; ++i) { | |||||
int u = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];//转无符号整型 | |||||
buffer[j++] = DIGITS[u >>> 4]; | |||||
buffer[j++] = DIGITS[u & 0xf]; | |||||
} | |||||
return new String(buffer); | |||||
} | |||||
/** | |||||
* To hex string string. | |||||
* | |||||
* @param num the num | |||||
* @return the string | |||||
*/ | |||||
public static String toHexString(int num) { | |||||
String hexString = Integer.toHexString(num); | |||||
return hexString; | |||||
} | |||||
/** | |||||
* To binary string string. | |||||
* | |||||
* @param bytes the bytes | |||||
* @return the string | |||||
*/ | |||||
public static String toBinaryString(byte... bytes) { | |||||
char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', | |||||
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; | |||||
// 参见:http://www.oschina.net/code/snippet_116768_9019 | |||||
char[] buffer = new char[bytes.length * 8]; | |||||
for (int i = 0, j = 0; i < bytes.length; ++i) { | |||||
int u = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];//转无符号整型 | |||||
buffer[j++] = DIGITS[(u >>> 7) & 0x1]; | |||||
buffer[j++] = DIGITS[(u >>> 6) & 0x1]; | |||||
buffer[j++] = DIGITS[(u >>> 5) & 0x1]; | |||||
buffer[j++] = DIGITS[(u >>> 4) & 0x1]; | |||||
buffer[j++] = DIGITS[(u >>> 3) & 0x1]; | |||||
buffer[j++] = DIGITS[(u >>> 2) & 0x1]; | |||||
buffer[j++] = DIGITS[(u >>> 1) & 0x1]; | |||||
buffer[j++] = DIGITS[u & 0x1]; | |||||
} | |||||
return new String(buffer); | |||||
} | |||||
/** | |||||
* To binary string string. | |||||
* | |||||
* @param num the num | |||||
* @return the string | |||||
*/ | |||||
public static String toBinaryString(int num) { | |||||
String binaryString = Integer.toBinaryString(num); | |||||
return binaryString; | |||||
} | |||||
public static String toSlashString(String str) { | |||||
String result = ""; | |||||
char[] chars = str.toCharArray(); | |||||
for (char chr : chars) { | |||||
if (chr == '"' || chr == '\'' || chr == '\\') { | |||||
result += "\\";//符合“"”“'”“\”这三个符号的前面加一个“\” | |||||
} | |||||
result += chr; | |||||
} | |||||
return result; | |||||
} | |||||
public static <T> T[] toArray(List<T> list) { | |||||
//noinspection unchecked | |||||
return (T[]) list.toArray(); | |||||
} | |||||
public static <T> List<T> toList(T[] array) { | |||||
return Arrays.asList(array); | |||||
} | |||||
public static String toString(Object[] objects) { | |||||
return Arrays.deepToString(objects); | |||||
} | |||||
public static String toString(Object[] objects, String tag) { | |||||
StringBuilder sb = new StringBuilder(); | |||||
for (Object object : objects) { | |||||
sb.append(object); | |||||
sb.append(tag); | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
public static byte[] toByteArray(InputStream is) { | |||||
if (is == null) { | |||||
return null; | |||||
} | |||||
try { | |||||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |||||
byte[] buff = new byte[100]; | |||||
while (true) { | |||||
int len = is.read(buff, 0, 100); | |||||
if (len == -1) { | |||||
break; | |||||
} else { | |||||
os.write(buff, 0, len); | |||||
} | |||||
} | |||||
byte[] bytes = os.toByteArray(); | |||||
os.close(); | |||||
is.close(); | |||||
return bytes; | |||||
} catch (IOException e) { | |||||
} | |||||
return null; | |||||
} | |||||
public static byte[] toByteArray(Bitmap bitmap) { | |||||
if (bitmap == null) { | |||||
return null; | |||||
} | |||||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |||||
// 将Bitmap压缩成PNG编码,质量为100%存储,除了PNG还有很多常见格式,如jpeg等。 | |||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); | |||||
byte[] bytes = os.toByteArray(); | |||||
try { | |||||
os.close(); | |||||
} catch (IOException e) { | |||||
} | |||||
return bytes; | |||||
} | |||||
public static Bitmap toBitmap(byte[] bytes, int width, int height) { | |||||
Bitmap bitmap = null; | |||||
if (bytes.length != 0) { | |||||
try { | |||||
BitmapFactory.Options options = new BitmapFactory.Options(); | |||||
// 不进行图片抖动处理 | |||||
options.inDither = false; | |||||
// 设置让解码器以最佳方式解码 | |||||
options.inPreferredConfig = null; | |||||
if (width > 0 && height > 0) { | |||||
options.outWidth = width; | |||||
options.outHeight = height; | |||||
} | |||||
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); | |||||
bitmap.setDensity(96);// 96 dpi | |||||
} catch (Exception e) { | |||||
} | |||||
} | |||||
return bitmap; | |||||
} | |||||
public static Bitmap toBitmap(byte[] bytes) { | |||||
return toBitmap(bytes, -1, -1); | |||||
} | |||||
/** | |||||
* 将Drawable转换为Bitmap | |||||
* 参考:http://kylines.iteye.com/blog/1660184 | |||||
*/ | |||||
public static Bitmap toBitmap(Drawable drawable) { | |||||
if (drawable instanceof BitmapDrawable) { | |||||
return ((BitmapDrawable) drawable).getBitmap(); | |||||
} else if (drawable instanceof ColorDrawable) { | |||||
//color | |||||
Bitmap bitmap = Bitmap.createBitmap(32, 32, Bitmap.Config.ARGB_8888); | |||||
Canvas canvas = new Canvas(bitmap); | |||||
canvas.drawColor(((ColorDrawable) drawable).getColor()); | |||||
return bitmap; | |||||
} else if (drawable instanceof NinePatchDrawable) { | |||||
//.9.png | |||||
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), | |||||
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); | |||||
Canvas canvas = new Canvas(bitmap); | |||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); | |||||
drawable.draw(canvas); | |||||
return bitmap; | |||||
} | |||||
return null; | |||||
} | |||||
/** | |||||
* 从第三方文件选择器获取路径。 | |||||
* 参见:http://blog.csdn.net/zbjdsbj/article/details/42387551 | |||||
*/ | |||||
@TargetApi(Build.VERSION_CODES.KITKAT) | |||||
public static String toPath(Context context, Uri uri) { | |||||
if (uri == null) { | |||||
return ""; | |||||
} | |||||
String path = uri.getPath(); | |||||
String scheme = uri.getScheme(); | |||||
String authority = uri.getAuthority(); | |||||
//是否是4.4及以上版本 | |||||
boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; | |||||
// DocumentProvider | |||||
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { | |||||
String docId = DocumentsContract.getDocumentId(uri); | |||||
String[] split = docId.split(":"); | |||||
String type = split[0]; | |||||
Uri contentUri = null; | |||||
switch (authority) { | |||||
// ExternalStorageProvider | |||||
case "com.android.externalstorage.documents": | |||||
if ("primary".equalsIgnoreCase(type)) { | |||||
return Environment.getExternalStorageDirectory() + "/" + split[1]; | |||||
} | |||||
break; | |||||
// DownloadsProvider | |||||
case "com.android.providers.downloads.documents": | |||||
contentUri = ContentUris.withAppendedId( | |||||
Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); | |||||
return _queryPathFromMediaStore(context, contentUri, null, null); | |||||
// MediaProvider | |||||
case "com.android.providers.media.documents": | |||||
if ("image".equals(type)) { | |||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; | |||||
} else if ("video".equals(type)) { | |||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; | |||||
} else if ("audio".equals(type)) { | |||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; | |||||
} | |||||
String selection = "_id=?"; | |||||
String[] selectionArgs = new String[]{split[1]}; | |||||
return _queryPathFromMediaStore(context, contentUri, selection, selectionArgs); | |||||
} | |||||
} | |||||
// MediaStore (and general) | |||||
else { | |||||
if ("content".equalsIgnoreCase(scheme)) { | |||||
// Return the remote address | |||||
if (authority.equals("com.google.android.apps.photos.content")) { | |||||
return uri.getLastPathSegment(); | |||||
} | |||||
return _queryPathFromMediaStore(context, uri, null, null); | |||||
} | |||||
// File | |||||
else if ("file".equalsIgnoreCase(scheme)) { | |||||
return uri.getPath(); | |||||
} | |||||
} | |||||
return path; | |||||
} | |||||
private static String _queryPathFromMediaStore(Context context, Uri uri, String selection, String[] selectionArgs) { | |||||
String filePath = null; | |||||
try { | |||||
String[] projection = {MediaStore.Images.Media.DATA}; | |||||
Cursor cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); | |||||
if (cursor != null) { | |||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); | |||||
cursor.moveToFirst(); | |||||
filePath = cursor.getString(column_index); | |||||
cursor.close(); | |||||
} | |||||
} catch (IllegalArgumentException e) { | |||||
} | |||||
return filePath; | |||||
} | |||||
/** | |||||
* 把view转化为bitmap(截图) | |||||
* 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html | |||||
*/ | |||||
public static Bitmap toBitmap(View view) { | |||||
int width = view.getWidth(); | |||||
int height = view.getHeight(); | |||||
if (view instanceof ListView) { | |||||
height = 0; | |||||
// 获取listView实际高度 | |||||
ListView listView = (ListView) view; | |||||
for (int i = 0; i < listView.getChildCount(); i++) { | |||||
height += listView.getChildAt(i).getHeight(); | |||||
} | |||||
} else if (view instanceof ScrollView) { | |||||
height = 0; | |||||
// 获取scrollView实际高度 | |||||
ScrollView scrollView = (ScrollView) view; | |||||
for (int i = 0; i < scrollView.getChildCount(); i++) { | |||||
height += scrollView.getChildAt(i).getHeight(); | |||||
} | |||||
} | |||||
view.setDrawingCacheEnabled(true); | |||||
view.clearFocus(); | |||||
view.setPressed(false); | |||||
boolean willNotCache = view.willNotCacheDrawing(); | |||||
view.setWillNotCacheDrawing(false); | |||||
// Reset the drawing cache background color to fully transparent for the duration of this operation | |||||
int color = view.getDrawingCacheBackgroundColor(); | |||||
view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) | |||||
if (color != Color.WHITE) { | |||||
view.destroyDrawingCache(); | |||||
} | |||||
view.buildDrawingCache(); | |||||
Bitmap cacheBitmap = view.getDrawingCache(); | |||||
if (cacheBitmap == null) { | |||||
return null; | |||||
} | |||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | |||||
Canvas canvas = new Canvas(bitmap); | |||||
canvas.drawBitmap(cacheBitmap, 0, 0, null); | |||||
//canvas.save(Canvas.ALL_SAVE_FLAG); | |||||
canvas.restore(); | |||||
if (!bitmap.isRecycled()) { | |||||
bitmap.recycle(); | |||||
} | |||||
// Restore the view | |||||
view.destroyDrawingCache(); | |||||
view.setWillNotCacheDrawing(willNotCache); | |||||
view.setDrawingCacheBackgroundColor(color); | |||||
return bitmap; | |||||
} | |||||
public static Drawable toDrawable(Bitmap bitmap) { | |||||
return bitmap == null ? null : new BitmapDrawable(Resources.getSystem(), bitmap); | |||||
} | |||||
public static byte[] toByteArray(Drawable drawable) { | |||||
return toByteArray(toBitmap(drawable)); | |||||
} | |||||
public static Drawable toDrawable(byte[] bytes) { | |||||
return toDrawable(toBitmap(bytes)); | |||||
} | |||||
/** | |||||
* dp转换为px | |||||
*/ | |||||
public static int toPx(Context context, float dpValue) { | |||||
final float scale = context.getResources().getDisplayMetrics().density; | |||||
int pxValue = (int) (dpValue * scale + 0.5f); | |||||
return pxValue; | |||||
} | |||||
public static int toPx(float dpValue) { | |||||
Resources resources = Resources.getSystem(); | |||||
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, resources.getDisplayMetrics()); | |||||
return (int) px; | |||||
} | |||||
/** | |||||
* px转换为dp | |||||
*/ | |||||
public static int toDp(Context context, float pxValue) { | |||||
final float scale = context.getResources().getDisplayMetrics().density; | |||||
int dpValue = (int) (pxValue / scale + 0.5f); | |||||
return dpValue; | |||||
} | |||||
/** | |||||
* px转换为sp | |||||
*/ | |||||
public static int toSp(Context context, float pxValue) { | |||||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; | |||||
int spValue = (int) (pxValue / fontScale + 0.5f); | |||||
return spValue; | |||||
} | |||||
public static String toGbk(String str) { | |||||
try { | |||||
return new String(str.getBytes("utf-8"), "gbk"); | |||||
} catch (UnsupportedEncodingException e) { | |||||
return str; | |||||
} | |||||
} | |||||
public static String toFileSizeString(long fileSize) { | |||||
DecimalFormat df = new DecimalFormat("0.00"); | |||||
String fileSizeString; | |||||
if (fileSize < KB) { | |||||
fileSizeString = fileSize + "B"; | |||||
} else if (fileSize < MB) { | |||||
fileSizeString = df.format((double) fileSize / KB) + "K"; | |||||
} else if (fileSize < GB) { | |||||
fileSizeString = df.format((double) fileSize / MB) + "M"; | |||||
} else { | |||||
fileSizeString = df.format((double) fileSize / GB) + "G"; | |||||
} | |||||
return fileSizeString; | |||||
} | |||||
public static String toString(InputStream is, String charset) { | |||||
StringBuilder sb = new StringBuilder(); | |||||
try { | |||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is, charset)); | |||||
while (true) { | |||||
String line = reader.readLine(); | |||||
if (line == null) { | |||||
break; | |||||
} else { | |||||
sb.append(line).append("\n"); | |||||
} | |||||
} | |||||
reader.close(); | |||||
is.close(); | |||||
} catch (IOException e) { | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
public static String toString(InputStream is) { | |||||
return toString(is, "utf-8"); | |||||
} | |||||
public static int toDarkenColor(@ColorInt int color) { | |||||
return toDarkenColor(color, 0.8f); | |||||
} | |||||
public static int toDarkenColor(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float value) { | |||||
float[] hsv = new float[3]; | |||||
Color.colorToHSV(color, hsv); | |||||
hsv[2] *= value;//HSV指Hue、Saturation、Value,即色调、饱和度和亮度,此处表示修改亮度 | |||||
return Color.HSVToColor(hsv); | |||||
} | |||||
/** | |||||
* 转换为6位十六进制颜色代码,不含“#” | |||||
*/ | |||||
public static String toColorString(@ColorInt int color) { | |||||
return toColorString(color, false); | |||||
} | |||||
/** | |||||
* 转换为6位十六进制颜色代码,不含“#” | |||||
*/ | |||||
public static String toColorString(@ColorInt int color, boolean includeAlpha) { | |||||
String alpha = Integer.toHexString(Color.alpha(color)); | |||||
String red = Integer.toHexString(Color.red(color)); | |||||
String green = Integer.toHexString(Color.green(color)); | |||||
String blue = Integer.toHexString(Color.blue(color)); | |||||
if (alpha.length() == 1) { | |||||
alpha = "0" + alpha; | |||||
} | |||||
if (red.length() == 1) { | |||||
red = "0" + red; | |||||
} | |||||
if (green.length() == 1) { | |||||
green = "0" + green; | |||||
} | |||||
if (blue.length() == 1) { | |||||
blue = "0" + blue; | |||||
} | |||||
String colorString; | |||||
if (includeAlpha) { | |||||
colorString = alpha + red + green + blue; | |||||
} else { | |||||
colorString = red + green + blue; | |||||
} | |||||
return colorString; | |||||
} | |||||
/** | |||||
* 对TextView、Button等设置不同状态时其文字颜色。 | |||||
* 参见:http://blog.csdn.net/sodino/article/details/6797821 | |||||
*/ | |||||
public static ColorStateList toColorStateList(@ColorInt int normalColor, @ColorInt int pressedColor, | |||||
@ColorInt int focusedColor, @ColorInt int unableColor) { | |||||
int[] colors = new int[]{pressedColor, focusedColor, normalColor, focusedColor, unableColor, normalColor}; | |||||
int[][] states = new int[6][]; | |||||
states[0] = new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled}; | |||||
states[1] = new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}; | |||||
states[2] = new int[]{android.R.attr.state_enabled}; | |||||
states[3] = new int[]{android.R.attr.state_focused}; | |||||
states[4] = new int[]{android.R.attr.state_window_focused}; | |||||
states[5] = new int[]{}; | |||||
return new ColorStateList(states, colors); | |||||
} | |||||
public static ColorStateList toColorStateList(@ColorInt int normalColor, @ColorInt int pressedColor) { | |||||
return toColorStateList(normalColor, pressedColor, pressedColor, normalColor); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.content.Context; | |||||
import android.util.AttributeSet; | |||||
import android.view.MotionEvent; | |||||
import android.view.View; | |||||
import android.widget.OverScroller; | |||||
import androidx.coordinatorlayout.widget.CoordinatorLayout; | |||||
import androidx.core.view.ViewCompat; | |||||
import com.google.android.material.appbar.AppBarLayout; | |||||
import java.lang.reflect.Field; | |||||
/** | |||||
* Created by 于德海 on 2018/4/27. | |||||
* package inter.baisong.widgets | |||||
* email : yudehai0204@163.com | |||||
* | |||||
* @describe 自定义behavior 以解决滑动抖动 | |||||
* | |||||
*/ | |||||
public class CustomBehavior extends AppBarLayout.Behavior { | |||||
private OverScroller mScroller; | |||||
public CustomBehavior() { | |||||
} | |||||
public CustomBehavior(Context context, AttributeSet attrs) { | |||||
super(context, attrs); | |||||
getParentScroller(context); | |||||
} | |||||
/** | |||||
* 反射获得滑动属性。 | |||||
* | |||||
* @param context | |||||
*/ | |||||
private void getParentScroller(Context context) { | |||||
if (mScroller != null) return; | |||||
mScroller = new OverScroller(context); | |||||
try { | |||||
Class<?> reflex_class = getClass().getSuperclass().getSuperclass();//父类AppBarLayout.Behavior 父类的父类 HeaderBehavior | |||||
Field fieldScroller = reflex_class.getDeclaredField("mScroller"); | |||||
fieldScroller.setAccessible(true); | |||||
fieldScroller.set(this, mScroller); | |||||
} catch (Exception e) {} | |||||
} | |||||
//fling上滑appbar然后迅速fling下滑recycler时, HeaderBehavior的mScroller并未停止, 会导致上下来回晃动 | |||||
@Override | |||||
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed, int type) { | |||||
if(mScroller!=null){ //当recyclerView 做好滑动准备的时候 直接干掉Appbar的滑动 | |||||
if (mScroller.computeScrollOffset()) { | |||||
mScroller.abortAnimation(); | |||||
} | |||||
} | |||||
if (type == ViewCompat.TYPE_NON_TOUCH&&getTopAndBottomOffset() == 0) { //recyclerview 鸡儿的 惯性比较大 会顶在头部一会儿 到头直接干掉它的滑动 | |||||
ViewCompat.stopNestedScroll(target, type); | |||||
} | |||||
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); | |||||
} | |||||
@Override | |||||
public boolean onTouchEvent(CoordinatorLayout parent, AppBarLayout child, MotionEvent e) { | |||||
switch (e.getActionMasked()) { | |||||
case MotionEvent.ACTION_DOWN: | |||||
break; | |||||
} | |||||
return super.onTouchEvent(parent,child,e); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import java.text.SimpleDateFormat; | |||||
import java.util.Calendar; | |||||
import java.util.Date; | |||||
import java.util.GregorianCalendar; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.utils | |||||
* @ClassName: DateUtils | |||||
* @Description: 时间utils | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/25 21:00 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class DateUtils { | |||||
/** | |||||
* | |||||
* @author 作者:孙磊 方法描述:获取某天,-1是昨天,0是今天,1是明天依次类推 | |||||
* | |||||
* @param参数描述 | |||||
* 格式M月dd日这样的话显示的就是3月12日,否则 MM月dd日格式会选择03月12日 | |||||
* @return 返回值描述 | |||||
* @throws <异常类型> {@inheritDoc} 异常描述 | |||||
*/ | |||||
public static String getmoutianMD(int i) { | |||||
Date date = new Date(); | |||||
SimpleDateFormat formatter = new SimpleDateFormat("M月dd日"); | |||||
Calendar calendar = new GregorianCalendar(); | |||||
calendar.setTime(date); | |||||
String dateString=""; | |||||
try { | |||||
calendar.add(calendar.DATE,i);//把日期往后增加一天.整数往后推,负数往前移动 | |||||
date=calendar.getTime(); //这个时间就是日期往后推一天的结果 | |||||
dateString = formatter.format(date); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
return dateString; | |||||
} | |||||
/** | |||||
* 计算待支付订单关闭时间 | |||||
* @param endtime 订单关闭时间 | |||||
* */ | |||||
public static String getCloseTime2(String endtime){ | |||||
//订单关闭时间 | |||||
long endTime = Long.valueOf(endtime) ; | |||||
//当前时间 | |||||
long millis = System.currentTimeMillis() / 1000; | |||||
//获取时间差 | |||||
long longExpend = endTime - millis; | |||||
//根据时间差来计算小时数 | |||||
long longHours = longExpend / (60 * 60); | |||||
//根据时间差来计算分钟数 | |||||
long longMinutes = longExpend / (60 ); | |||||
long longSecond = longExpend % 1000; | |||||
return String.valueOf(longSecond); | |||||
} | |||||
/** | |||||
* 调用此方法输入所要转换的时间戳输入例如(1402733340)输出("2014-06-14 16:09:00") | |||||
* | |||||
* @param time | |||||
* @return | |||||
*/ | |||||
public static String timeSecond(String time) { | |||||
SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||||
@SuppressWarnings("unused") | |||||
long lcc = Long.valueOf(time); | |||||
int i = Integer.parseInt(time); | |||||
String times = sdr.format(new Date(i * 1000L)); | |||||
return times; | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.text.Editable; | |||||
import android.text.InputFilter; | |||||
import android.text.Spanned; | |||||
import android.text.TextWatcher; | |||||
import android.widget.EditText; | |||||
public class EditTextUtil { | |||||
/** | |||||
* 禁止EditText输入空格和换行符 | |||||
* | |||||
* @param editText EditText输入框 | |||||
*/ | |||||
public static void setEditTextInputSpace(EditText editText) { | |||||
InputFilter filter = new InputFilter() { | |||||
@Override | |||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { | |||||
if (source.equals(" ") || source.toString().contentEquals("\n")) { | |||||
return ""; | |||||
} else { | |||||
return null; | |||||
} | |||||
} | |||||
}; | |||||
editText.setFilters(new InputFilter[]{filter}); | |||||
} | |||||
/** | |||||
* 设置edittext最大的输入限制 | |||||
* @param editText | |||||
* @param length | |||||
*/ | |||||
public static void setMaxLength(EditText editText , int length){ | |||||
editText.addTextChangedListener(new TextWatcher() { | |||||
@Override | |||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |||||
} | |||||
@Override | |||||
public void onTextChanged(CharSequence s, int start, int before, int count) { | |||||
String str = s.toString(); | |||||
if (str.length()>length){ | |||||
editText.setText(str.substring(0,length)); //截取前x位 | |||||
editText.requestFocus(); | |||||
editText.setSelection(editText.getText().length()); //光标移动到最后 | |||||
} | |||||
} | |||||
@Override | |||||
public void afterTextChanged(Editable s) { | |||||
} | |||||
}); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.text.TextUtils; | |||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
public class EmptyUtils { | |||||
/** | |||||
* 判断String是否为空值 | |||||
* | |||||
* | |||||
* */ | |||||
public static boolean isStringNotEmpty(String str){ | |||||
if (str != null && !TextUtils.isEmpty(str)){ | |||||
return true; | |||||
}else { | |||||
return false; | |||||
} | |||||
} | |||||
/*** | |||||
* 验证手机号 | |||||
* */ | |||||
public static boolean isPhone(String phone) { | |||||
String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$"; | |||||
if (phone.length() != 11) { | |||||
return false; | |||||
} else { | |||||
Pattern p = Pattern.compile(regex); | |||||
Matcher m = p.matcher(phone); | |||||
boolean isMatch = m.matches(); | |||||
return isMatch; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.content.Context; | |||||
import android.util.Log; | |||||
import com.amap.api.fence.PoiItem; | |||||
import com.amap.api.location.AMapLocation; | |||||
import com.amap.api.location.AMapLocationClient; | |||||
import com.amap.api.location.AMapLocationClientOption; | |||||
import com.amap.api.location.AMapLocationListener; | |||||
import com.amap.api.services.poisearch.PoiSearch; | |||||
import java.util.ArrayList; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.utils | |||||
* @ClassName: GDLocationUtil | |||||
* @Description: 地图工具类 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/27 20:04 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class GDLocationUtil { | |||||
private static GDLocationUtil sInstance; | |||||
private AMapLocationClient mlocationClient; | |||||
public AMapLocationClientOption mLocationOption = null; | |||||
public AMapLocation sLocation = null; | |||||
public static GDLocationUtil getInstance() { | |||||
if (sInstance == null) { | |||||
synchronized (GDLocationUtil.class) { | |||||
if (sInstance == null) { | |||||
sInstance = new GDLocationUtil(); | |||||
} | |||||
} | |||||
} | |||||
return sInstance; | |||||
} | |||||
/** | |||||
* 初始化 | |||||
*/ | |||||
public void init(Context context) { | |||||
// 声明mLocationOption对象 | |||||
mlocationClient = new AMapLocationClient(context); | |||||
// 初始化定位参数 | |||||
mLocationOption = new AMapLocationClientOption(); | |||||
// 设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式 | |||||
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); | |||||
// 设置定位间隔,单位毫秒,默认为2000ms | |||||
mLocationOption.setInterval(2000); | |||||
//单位是毫秒,默认30000毫秒,建议超时时间不要低于8000毫秒。 | |||||
mLocationOption.setHttpTimeOut(10000); | |||||
//获取一次定位结果: | |||||
//该方法默认为false。 | |||||
mLocationOption.setOnceLocation(true); | |||||
// 设置定位参数 | |||||
mlocationClient.setLocationOption(mLocationOption); | |||||
// 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗, | |||||
// 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求 | |||||
// 在定位结束后,在合适的生命周期调用onDestroy()方法 | |||||
// 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除 | |||||
} | |||||
/** | |||||
* 定位返回 | |||||
*/ | |||||
public interface MyLocationListener { | |||||
public void result(AMapLocation location); | |||||
} | |||||
public interface MyPoiListenerListener { | |||||
public void result2(ArrayList<PoiItem> poiItem); | |||||
} | |||||
public void getPoiList(PoiSearch.OnPoiSearchListener listener) { | |||||
} | |||||
/** | |||||
* 获取位置,如果之前获取过定位结果,则不会重复获取 | |||||
*/ | |||||
public void getLocation(MyLocationListener listener) { | |||||
getCurrentLocation(listener); | |||||
} | |||||
/** | |||||
* 获取位置,重新发起获取位置请求 | |||||
*/ | |||||
public void getCurrentLocation(final MyLocationListener listener) { | |||||
if (mlocationClient == null) { | |||||
return; | |||||
} | |||||
mlocationClient.setLocationListener(new AMapLocationListener() { | |||||
@Override | |||||
public void onLocationChanged(AMapLocation location) { | |||||
if (location != null) { | |||||
if (location.getErrorCode() == 0) { | |||||
//可在其中解析amapLocation获取相应内容。 | |||||
mlocationClient.stopLocation(); | |||||
sLocation = location; | |||||
listener.result(location); | |||||
} else { | |||||
//定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。 | |||||
Log.e("AmapError", "location Error, ErrCode:" | |||||
+ location.getErrorCode() + ", errInfo:" | |||||
+ location.getErrorInfo()); | |||||
} | |||||
} else { | |||||
} | |||||
} | |||||
}); | |||||
//设置场景模式后最好调用一次stop,再调用start以保证场景模式生效 | |||||
mlocationClient.stopLocation(); | |||||
// 启动定位 | |||||
mlocationClient.startLocation(); | |||||
} | |||||
/** | |||||
* @Title: destroy | |||||
* @Description: 销毁定位,必须在退出程序时调用,否则定位会发生异常 | |||||
*/ | |||||
public void destroy() { | |||||
mlocationClient.onDestroy(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.content.Context; | |||||
import android.graphics.Bitmap; | |||||
import android.graphics.PointF; | |||||
import android.graphics.drawable.Drawable; | |||||
import android.view.View; | |||||
import android.widget.ImageView; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable; | |||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory; | |||||
import com.bumptech.glide.Glide; | |||||
import com.bumptech.glide.request.target.BitmapImageViewTarget; | |||||
import com.bumptech.glide.request.target.ImageViewTarget; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.luck.picture.lib.engine.ImageEngine; | |||||
import com.luck.picture.lib.listener.OnImageCompleteCallback; | |||||
import com.luck.picture.lib.tools.MediaUtils; | |||||
import com.luck.picture.lib.widget.longimage.ImageSource; | |||||
import com.luck.picture.lib.widget.longimage.ImageViewState; | |||||
import com.luck.picture.lib.widget.longimage.SubsamplingScaleImageView; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalairpeisong.utils | |||||
* @ClassName: GlideEngine | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/11/3 20:52 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class GlideEngine implements ImageEngine { | |||||
/** | |||||
* 加载图片 | |||||
* | |||||
* @param context | |||||
* @param url | |||||
* @param imageView | |||||
*/ | |||||
@Override | |||||
public void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) { | |||||
if (!ImageLoaderUtils.assertValidRequest(context)) { | |||||
return; | |||||
} | |||||
Glide.with(context) | |||||
.load(url) | |||||
.into(imageView); | |||||
} | |||||
/** | |||||
* 加载网络图片适配长图方案 | |||||
* # 注意:此方法只有加载网络图片才会回调 | |||||
* | |||||
* @param context | |||||
* @param url | |||||
* @param imageView | |||||
* @param longImageView | |||||
* @param callback 网络图片加载回调监听 {link after version 2.5.1 Please use the #OnImageCompleteCallback#} | |||||
*/ | |||||
@Override | |||||
public void loadImage(@NonNull Context context, @NonNull String url, | |||||
@NonNull ImageView imageView, | |||||
SubsamplingScaleImageView longImageView, OnImageCompleteCallback callback) { | |||||
if (!ImageLoaderUtils.assertValidRequest(context)) { | |||||
return; | |||||
} | |||||
Glide.with(context) | |||||
.asBitmap() | |||||
.load(url) | |||||
.into(new ImageViewTarget<Bitmap>(imageView) { | |||||
@Override | |||||
public void onLoadStarted(@Nullable Drawable placeholder) { | |||||
super.onLoadStarted(placeholder); | |||||
if (callback != null) { | |||||
callback.onShowLoading(); | |||||
} | |||||
} | |||||
@Override | |||||
public void onLoadFailed(@Nullable Drawable errorDrawable) { | |||||
super.onLoadFailed(errorDrawable); | |||||
if (callback != null) { | |||||
callback.onHideLoading(); | |||||
} | |||||
} | |||||
@Override | |||||
protected void setResource(@Nullable Bitmap resource) { | |||||
if (callback != null) { | |||||
callback.onHideLoading(); | |||||
} | |||||
if (resource != null) { | |||||
boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(), | |||||
resource.getHeight()); | |||||
longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE); | |||||
imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE); | |||||
if (eqLongImage) { | |||||
// 加载长图 | |||||
longImageView.setQuickScaleEnabled(true); | |||||
longImageView.setZoomEnabled(true); | |||||
longImageView.setDoubleTapZoomDuration(100); | |||||
longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP); | |||||
longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER); | |||||
longImageView.setImage(ImageSource.cachedBitmap(resource), | |||||
new ImageViewState(0, new PointF(0, 0), 0)); | |||||
} else { | |||||
// 普通图片 | |||||
imageView.setImageBitmap(resource); | |||||
} | |||||
} | |||||
} | |||||
}); | |||||
} | |||||
/** | |||||
* 加载网络图片适配长图方案 | |||||
* # 注意:此方法只有加载网络图片才会回调 | |||||
* | |||||
* @param context | |||||
* @param url | |||||
* @param imageView | |||||
* @param longImageView | |||||
* @ 已废弃 | |||||
*/ | |||||
@Override | |||||
public void loadImage(@NonNull Context context, @NonNull String url, | |||||
@NonNull ImageView imageView, | |||||
SubsamplingScaleImageView longImageView) { | |||||
if (!ImageLoaderUtils.assertValidRequest(context)) { | |||||
return; | |||||
} | |||||
Glide.with(context) | |||||
.asBitmap() | |||||
.load(url) | |||||
.into(new ImageViewTarget<Bitmap>(imageView) { | |||||
@Override | |||||
protected void setResource(@Nullable Bitmap resource) { | |||||
if (resource != null) { | |||||
boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(), | |||||
resource.getHeight()); | |||||
longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE); | |||||
imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE); | |||||
if (eqLongImage) { | |||||
// 加载长图 | |||||
longImageView.setQuickScaleEnabled(true); | |||||
longImageView.setZoomEnabled(true); | |||||
longImageView.setDoubleTapZoomDuration(100); | |||||
longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP); | |||||
longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER); | |||||
longImageView.setImage(ImageSource.cachedBitmap(resource), | |||||
new ImageViewState(0, new PointF(0, 0), 0)); | |||||
} else { | |||||
// 普通图片 | |||||
imageView.setImageBitmap(resource); | |||||
} | |||||
} | |||||
} | |||||
}); | |||||
} | |||||
/** | |||||
* 加载相册目录 | |||||
* | |||||
* @param context 上下文 | |||||
* @param url 图片路径 | |||||
* @param imageView 承载图片ImageView | |||||
*/ | |||||
@Override | |||||
public void loadFolderImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) { | |||||
if (!ImageLoaderUtils.assertValidRequest(context)) { | |||||
return; | |||||
} | |||||
Glide.with(context) | |||||
.asBitmap() | |||||
.load(url) | |||||
.override(180, 180) | |||||
.centerCrop() | |||||
.sizeMultiplier(0.5f) | |||||
.placeholder(R.drawable.picture_image_placeholder) | |||||
.into(new BitmapImageViewTarget(imageView) { | |||||
@Override | |||||
protected void setResource(Bitmap resource) { | |||||
RoundedBitmapDrawable circularBitmapDrawable = | |||||
RoundedBitmapDrawableFactory. | |||||
create(context.getResources(), resource); | |||||
circularBitmapDrawable.setCornerRadius(8); | |||||
imageView.setImageDrawable(circularBitmapDrawable); | |||||
} | |||||
}); | |||||
} | |||||
/** | |||||
* 加载gif | |||||
* | |||||
* @param context 上下文 | |||||
* @param url 图片路径 | |||||
* @param imageView 承载图片ImageView | |||||
*/ | |||||
@Override | |||||
public void loadAsGifImage(@NonNull Context context, @NonNull String url, | |||||
@NonNull ImageView imageView) { | |||||
if (!ImageLoaderUtils.assertValidRequest(context)) { | |||||
return; | |||||
} | |||||
Glide.with(context) | |||||
.asGif() | |||||
.load(url) | |||||
.into(imageView); | |||||
} | |||||
/** | |||||
* 加载图片列表图片 | |||||
* | |||||
* @param context 上下文 | |||||
* @param url 图片路径 | |||||
* @param imageView 承载图片ImageView | |||||
*/ | |||||
@Override | |||||
public void loadGridImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) { | |||||
if (!ImageLoaderUtils.assertValidRequest(context)) { | |||||
return; | |||||
} | |||||
Glide.with(context) | |||||
.load(url) | |||||
.override(200, 200) | |||||
.centerCrop() | |||||
.placeholder(R.drawable.picture_image_placeholder) | |||||
.into(imageView); | |||||
} | |||||
private GlideEngine() { | |||||
} | |||||
private static GlideEngine instance; | |||||
public static GlideEngine createGlideEngine() { | |||||
if (null == instance) { | |||||
synchronized (GlideEngine.class) { | |||||
if (null == instance) { | |||||
instance = new GlideEngine(); | |||||
} | |||||
} | |||||
} | |||||
return instance; | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.app.PendingIntent; | |||||
import android.content.Context; | |||||
import android.content.Intent; | |||||
import android.location.LocationManager; | |||||
import android.net.Uri; | |||||
public class GpsUtils { | |||||
/** | |||||
* 判断GPS是否开启,GPS或者AGPS开启一个就认为是开启的 | |||||
* @param context | |||||
* @return true 表示开启 | |||||
*/ | |||||
public static final boolean isOPen(final Context context) { | |||||
LocationManager locationManager | |||||
= (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | |||||
// 通过GPS卫星定位,定位级别可以精确到街(通过24颗卫星定位,在室外和空旷的地方定位准确、速度快) | |||||
boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); | |||||
// 通过WLAN或移动网络(3G/2G)确定的位置(也称作AGPS,辅助GPS定位。主要用于在室内或遮盖物(建筑群或茂密的深林等)密集的地方定位) | |||||
boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); | |||||
if (gps || network) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* 强制帮用户打开GPS | |||||
* @param context | |||||
*/ | |||||
public static final void openGPS(Context context) { | |||||
Intent GPSIntent = new Intent(); | |||||
GPSIntent.setClassName("com.android.settings", | |||||
"com.android.settings.widget.SettingsAppWidgetProvider"); | |||||
GPSIntent.addCategory("android.intent.category.ALTERNATIVE"); | |||||
GPSIntent.setData(Uri.parse("custom:3")); | |||||
try { | |||||
PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send(); | |||||
} catch (PendingIntent.CanceledException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.app.Activity; | |||||
import android.content.Context; | |||||
import android.content.ContextWrapper; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalairpeisong.utils | |||||
* @ClassName: ImageLoaderUtils | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/11/3 20:53 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class ImageLoaderUtils { | |||||
public static boolean assertValidRequest(Context context) { | |||||
if (context instanceof Activity) { | |||||
Activity activity = (Activity) context; | |||||
return !isDestroy(activity); | |||||
} else if (context instanceof ContextWrapper){ | |||||
ContextWrapper contextWrapper = (ContextWrapper) context; | |||||
if (contextWrapper.getBaseContext() instanceof Activity){ | |||||
Activity activity = (Activity) contextWrapper.getBaseContext(); | |||||
return !isDestroy(activity); | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
private static boolean isDestroy(Activity activity) { | |||||
if (activity == null) { | |||||
return true; | |||||
} | |||||
return activity.isFinishing() || activity.isDestroyed(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import java.text.DecimalFormat; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.utils | |||||
* @ClassName: NumUtils | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/31 13:26 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class NumUtils { | |||||
public static double stringToDouble(String str){ | |||||
return Double.parseDouble(str); | |||||
} | |||||
public static String dfString(String str) { | |||||
DecimalFormat df = new DecimalFormat("#0.00"); | |||||
double parseDouble = Double.parseDouble(str); | |||||
return df.format(parseDouble); | |||||
} | |||||
public static String dfDouble(double num) { | |||||
DecimalFormat df = new DecimalFormat("#0.00"); | |||||
return df.format(num); | |||||
} | |||||
public static String int2chineseNum(int src) { | |||||
final String num[] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}; | |||||
final String unit[] = {"", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千"}; | |||||
String dst = ""; | |||||
int count = 0; | |||||
while(src > 0) { | |||||
dst = (num[src % 10] + unit[count]) + dst; | |||||
src = src / 10; | |||||
count++; | |||||
} | |||||
return dst.replaceAll("零[千百十]", "零").replaceAll("零+万", "万") | |||||
.replaceAll("零+亿", "亿").replaceAll("亿万", "亿零") | |||||
.replaceAll("零+", "零").replaceAll("零$", ""); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.os.Environment; | |||||
import android.text.TextUtils; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.util.Properties; | |||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
/** | |||||
* @ClassName OSUtils | |||||
* @Antuor Administrator | |||||
* @Date 2021/10/12 | |||||
* @Version 1.0 | |||||
* desc : 工具类: OS 系统相关 | |||||
* 简介 : 由于国内定制系统的泛滥, 不同定制系统的一些功能或实现方法会有所不同, 如果需要做到足够好的适配工作, 需要 | |||||
* 对不同的定制系统做一些专门的适配. | |||||
* API : 获取 ROM 类型等 | |||||
* | |||||
* Deprecated : | |||||
* 在工具类中对 ROM 类型进行判断,显得有些力不从心,所以单独创建了新的项目,用于判断 ROM,获取其版本号。 | |||||
*/ | |||||
public class OSUtils { | |||||
private static final String KEY_DISPLAY_ID = "ro.build.display.id"; | |||||
private static final String KEY_BASE_OS_VERSION = "ro.build.version.base_os"; | |||||
private static final String KEY_CLIENT_ID_BASE = "ro.com.google.clientidbase"; | |||||
// 小米 : MIUI | |||||
private static final String KEY_MIUI_VERSION = "ro.build.version.incremental"; // "7.6.15" | |||||
private static final String KEY_MIUI_VERSION_NANE = "ro.miui.ui.version.name"; // "V8" | |||||
private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code"; // "6" | |||||
private static final String VALUE_MIUI_CLIENT_ID_BASE = "android-xiaomi"; | |||||
// 华为 : EMUI | |||||
private static final String KEY_EMUI_VERSION = "ro.build.version.emui"; // "EmotionUI_3.0" | |||||
private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level"; // | |||||
private static final String KEY_EMUI_SYSTEM_VERSION = "ro.confg.hw_systemversion"; // | |||||
// "T1-A21wV100R001C233B008_SYSIMG" | |||||
// 魅族 : Flyme | |||||
private static final String KEY_FLYME_PUBLISHED = "ro.flyme.published"; // "true" | |||||
private static final String KEY_FLYME_SETUP = "ro.meizu.setupwizard.flyme"; // "true" | |||||
private static final String VALUE_FLYME_DISPLAY_ID_CONTAIN = "Flyme"; // "Flyme OS 4.5.4.2U" | |||||
// OPPO : ColorOS | |||||
private static final String KEY_COLOROS_VERSION = "ro.oppo.theme.version"; // "703" | |||||
private static final String KEY_COLOROS_THEME_VERSION = "ro.oppo.version"; // "" | |||||
private static final String KEY_COLOROS_ROM_VERSION = "ro.rom.different.version"; // | |||||
private static final String VALUE_COLOROS_BASE_OS_VERSION_CONTAIN = "OPPO"; // "OPPO/R7sm | |||||
// "ColorOS2.1" | |||||
// /R7sm:5.1.1/LMY47V/1440928800:user/release-keys" | |||||
private static final String VALUE_COLOROS_CLIENT_ID_BASE = "android-oppo"; | |||||
// vivo : FuntouchOS | |||||
private static final String KEY_FUNTOUCHOS_BOARD_VERSION = "ro.vivo.board.version"; // "MD" | |||||
private static final String KEY_FUNTOUCHOS_OS_NAME = "ro.vivo.os.name"; // "Funtouch" | |||||
private static final String KEY_FUNTOUCHOS_OS_VERSION = "ro.vivo.os.version"; // "3.0" | |||||
private static final String KEY_FUNTOUCHOS_DISPLAY_ID = "ro.vivo.os.build.display.id"; // | |||||
// "FuntouchOS_3.0" | |||||
private static final String KEY_FUNTOUCHOS_ROM_VERSION = "ro.vivo.rom.version"; // "rom_3.1" | |||||
private static final String VALUE_FUNTOUCHOS_CLIENT_ID_BASE = "android-vivo"; | |||||
// Samsung | |||||
private static final String VALUE_SAMSUNG_BASE_OS_VERSION_CONTAIN = "samsung"; // "samsung | |||||
// /zeroltezc/zeroltechn:6.0.1/MMB29K/G9250ZCU2DQD1:user/release-keys" | |||||
private static final String VALUE_SAMSUNG_CLIENT_ID_BASE = "android-samsung"; | |||||
// Sony | |||||
private static final String KEY_SONY_PROTOCOL_TYPE = "ro.sony.irremote.protocol_type"; // "2" | |||||
private static final String KEY_SONY_ENCRYPTED_DATA = "ro.sony.fota.encrypteddata"; // | |||||
private static final String VALUE_SONY_CLIENT_ID_BASE = "android-sonyericsson"; | |||||
// "supported" | |||||
// 乐视 : eui | |||||
private static final String KEY_EUI_VERSION = "ro.letv.release.version"; // "5.9.023S" | |||||
private static final String KEY_EUI_VERSION_DATE = "ro.letv.release.version_date"; // "5.9 | |||||
// .023S_03111" | |||||
private static final String KEY_EUI_NAME = "ro.product.letv_name"; // "乐1s" | |||||
private static final String KEY_EUI_MODEL = "ro.product.letv_model"; // "Letv X500" | |||||
// 金立 : amigo | |||||
private static final String KEY_AMIGO_ROM_VERSION = "ro.gn.gnromvernumber"; // "GIONEE ROM5.0 | |||||
// .16" | |||||
private static final String KEY_AMIGO_SYSTEM_UI_SUPPORT = "ro.gn.amigo.systemui.support"; // | |||||
private static final String VALUE_AMIGO_DISPLAY_ID_CONTAIN = "amigo"; // "amigo3.5.1" | |||||
// "yes" | |||||
private static final String VALUE_AMIGO_CLIENT_ID_BASE = "android-gionee"; | |||||
// 酷派 : yulong | |||||
private static final String KEY_YULONG_VERSION_RELEASE = "ro.yulong.version.release"; // "5.1 | |||||
// .046.P1.150921.8676_M01" | |||||
private static final String KEY_YULONG_VERSION_TAG = "ro.yulong.version.tag"; // "LC" | |||||
private static final String VALUE_YULONG_CLIENT_ID_BASE = "android-coolpad"; | |||||
// HTC : Sense | |||||
private static final String KEY_SENSE_BUILD_STAGE = "htc.build.stage"; // "2" | |||||
private static final String KEY_SENSE_BLUETOOTH_SAP = "ro.htc.bluetooth.sap"; // "true" | |||||
private static final String VALUE_SENSE_CLIENT_ID_BASE = "android-htc-rev"; | |||||
// LG : LG | |||||
private static final String KEY_LG_SW_VERSION = "ro.lge.swversion"; // "D85720b" | |||||
private static final String KEY_LG_SW_VERSION_SHORT = "ro.lge.swversion_short"; // "V20b" | |||||
private static final String KEY_LG_FACTORY_VERSION = "ro.lge.factoryversion"; // "LGD857AT-00 | |||||
// -V20b-CUO-CN-FEB-17-2015+0" | |||||
// 联想 | |||||
private static final String KEY_LENOVO_DEVICE = "ro.lenovo.device"; // "phone" | |||||
private static final String KEY_LENOVO_PLATFORM = "ro.lenovo.platform"; // "qualcomm" | |||||
private static final String KEY_LENOVO_ADB = "ro.lenovo.adb"; // "apkctl,speedup" | |||||
private static final String VALUE_LENOVO_CLIENT_ID_BASE = "android-lenovo"; | |||||
/** | |||||
* ROM 类型 | |||||
*/ | |||||
private static final ROM ROM_TYPE = initRomType(); | |||||
/** | |||||
* 获取 ROM 类型 | |||||
* | |||||
* @return ROM | |||||
*/ | |||||
public static ROM getRomType() { | |||||
return ROM_TYPE; | |||||
} | |||||
/** | |||||
* 初始化 ROM 类型 | |||||
*/ | |||||
private static ROM initRomType() { | |||||
ROM rom = ROM.Other; | |||||
FileInputStream is = null; | |||||
try { | |||||
Properties buildProperties = new Properties(); | |||||
is = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")); | |||||
buildProperties.load(is); | |||||
if (buildProperties.containsKey(KEY_MIUI_VERSION_NANE) || buildProperties.containsKey(KEY_MIUI_VERSION_CODE)) { | |||||
// MIUI | |||||
rom = ROM.MIUI; | |||||
if (buildProperties.containsKey(KEY_MIUI_VERSION_NANE)) { | |||||
String versionName = buildProperties.getProperty(KEY_MIUI_VERSION_NANE); | |||||
if (!TextUtils.isEmpty(versionName) && versionName.matches("[Vv]\\d+")) { // V8 | |||||
try { | |||||
rom.setBaseVersion(Integer.parseInt(versionName.split("[Vv]")[1])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
if (buildProperties.containsKey(KEY_MIUI_VERSION)) { | |||||
String versionStr = buildProperties.getProperty(KEY_MIUI_VERSION); | |||||
if (!TextUtils.isEmpty(versionStr) && versionStr.matches("[\\d.]+")) { | |||||
rom.setVersion(versionStr); | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_EMUI_VERSION) || buildProperties.containsKey(KEY_EMUI_API_LEVEL) | |||||
|| buildProperties.containsKey(KEY_EMUI_SYSTEM_VERSION)) { | |||||
// EMUI | |||||
rom = ROM.EMUI; | |||||
if (buildProperties.containsKey(KEY_EMUI_VERSION)) { | |||||
String versionStr = buildProperties.getProperty(KEY_EMUI_VERSION); | |||||
Matcher matcher = Pattern.compile("EmotionUI_([\\d.]+)").matcher(versionStr); // EmotionUI_3.0 | |||||
if (!TextUtils.isEmpty(versionStr) && matcher.find()) { | |||||
try { | |||||
String version = matcher.group(1); | |||||
rom.setVersion(version); | |||||
rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_FLYME_SETUP) || buildProperties.containsKey(KEY_FLYME_PUBLISHED)) { | |||||
// Flyme | |||||
rom = ROM.Flyme; | |||||
if (buildProperties.containsKey(KEY_DISPLAY_ID)) { | |||||
String versionStr = buildProperties.getProperty(KEY_DISPLAY_ID); | |||||
Matcher matcher = | |||||
Pattern.compile("Flyme[^\\d]*([\\d.]+)[^\\d]*").matcher(versionStr); | |||||
// Flyme OS 4.5.4.2U | |||||
if (!TextUtils.isEmpty(versionStr) && matcher.find()) { | |||||
try { | |||||
String version = matcher.group(1); | |||||
rom.setVersion(version); | |||||
rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_COLOROS_VERSION) || buildProperties.containsKey(KEY_COLOROS_THEME_VERSION) | |||||
|| buildProperties.containsKey(KEY_COLOROS_ROM_VERSION)) { | |||||
// ColorOS | |||||
rom = ROM.ColorOS; | |||||
if (buildProperties.containsKey(KEY_COLOROS_ROM_VERSION)) { | |||||
String versionStr = buildProperties.getProperty(KEY_COLOROS_ROM_VERSION); | |||||
Matcher matcher = Pattern.compile("ColorOS([\\d.]+)").matcher(versionStr); // | |||||
// ColorOS2.1 | |||||
if (!TextUtils.isEmpty(versionStr) && matcher.find()) { | |||||
try { | |||||
String version = matcher.group(1); | |||||
rom.setVersion(version); | |||||
rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_FUNTOUCHOS_OS_NAME) || buildProperties.containsKey(KEY_FUNTOUCHOS_OS_VERSION) | |||||
|| buildProperties.containsKey(KEY_FUNTOUCHOS_DISPLAY_ID)) { | |||||
// FuntouchOS | |||||
rom = ROM.FuntouchOS; | |||||
if (buildProperties.containsKey(KEY_FUNTOUCHOS_OS_VERSION)) { | |||||
String versionStr = buildProperties.getProperty(KEY_FUNTOUCHOS_OS_VERSION); | |||||
if (!TextUtils.isEmpty(versionStr) && versionStr.matches("[\\d.]+")) { // 3.0 | |||||
try { | |||||
rom.setVersion(versionStr); | |||||
rom.setBaseVersion(Integer.parseInt(versionStr.split("\\.")[0])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_EUI_VERSION) || buildProperties.containsKey(KEY_EUI_NAME) | |||||
|| buildProperties.containsKey(KEY_EUI_MODEL)) { | |||||
// EUI | |||||
rom = ROM.EUI; | |||||
if (buildProperties.containsKey(KEY_EUI_VERSION)) { | |||||
String versionStr = buildProperties.getProperty(KEY_EUI_VERSION); | |||||
Matcher matcher = Pattern.compile("([\\d.]+)[^\\d]*").matcher(versionStr); // | |||||
// 5.9.023S | |||||
if (!TextUtils.isEmpty(versionStr) && matcher.find()) { | |||||
try { | |||||
String version = matcher.group(1); | |||||
rom.setVersion(version); | |||||
rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_AMIGO_ROM_VERSION) || buildProperties.containsKey(KEY_AMIGO_SYSTEM_UI_SUPPORT)) { | |||||
// amigo | |||||
rom = ROM.AmigoOS; | |||||
if (buildProperties.containsKey(KEY_DISPLAY_ID)) { | |||||
String versionStr = buildProperties.getProperty(KEY_DISPLAY_ID); | |||||
Matcher matcher = | |||||
Pattern.compile("amigo([\\d.]+)[a-zA-Z]*").matcher(versionStr); // | |||||
// "amigo3.5.1" | |||||
if (!TextUtils.isEmpty(versionStr) && matcher.find()) { | |||||
try { | |||||
String version = matcher.group(1); | |||||
rom.setVersion(version); | |||||
rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_SONY_PROTOCOL_TYPE) || buildProperties.containsKey(KEY_SONY_ENCRYPTED_DATA)) { | |||||
// Sony | |||||
rom = ROM.Sony; | |||||
} else if (buildProperties.containsKey(KEY_YULONG_VERSION_RELEASE) || buildProperties.containsKey(KEY_YULONG_VERSION_TAG)) { | |||||
// YuLong | |||||
rom = ROM.YuLong; | |||||
} else if (buildProperties.containsKey(KEY_SENSE_BUILD_STAGE) || buildProperties.containsKey(KEY_SENSE_BLUETOOTH_SAP)) { | |||||
// Sense | |||||
rom = ROM.Sense; | |||||
} else if (buildProperties.containsKey(KEY_LG_SW_VERSION) || buildProperties.containsKey(KEY_LG_SW_VERSION_SHORT) | |||||
|| buildProperties.containsKey(KEY_LG_FACTORY_VERSION)) { | |||||
// LG | |||||
rom = ROM.LG; | |||||
} else if (buildProperties.containsKey(KEY_LENOVO_DEVICE) || buildProperties.containsKey(KEY_LENOVO_PLATFORM) | |||||
|| buildProperties.containsKey(KEY_LENOVO_ADB)) { | |||||
// Lenovo | |||||
rom = ROM.Lenovo; | |||||
} else if (buildProperties.containsKey(KEY_DISPLAY_ID)) { | |||||
String displayId = buildProperties.getProperty(KEY_DISPLAY_ID); | |||||
if (!TextUtils.isEmpty(displayId)) { | |||||
if (displayId.contains(VALUE_FLYME_DISPLAY_ID_CONTAIN)) { | |||||
return ROM.Flyme; | |||||
} else if (displayId.contains(VALUE_AMIGO_DISPLAY_ID_CONTAIN)) { | |||||
return ROM.AmigoOS; | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_BASE_OS_VERSION)) { | |||||
String baseOsVersion = buildProperties.getProperty(KEY_BASE_OS_VERSION); | |||||
if (!TextUtils.isEmpty(baseOsVersion)) { | |||||
if (baseOsVersion.contains(VALUE_COLOROS_BASE_OS_VERSION_CONTAIN)) { | |||||
return ROM.ColorOS; | |||||
} else if (baseOsVersion.contains(VALUE_SAMSUNG_BASE_OS_VERSION_CONTAIN)) { | |||||
return ROM.SamSung; | |||||
} | |||||
} | |||||
} else if (buildProperties.containsKey(KEY_CLIENT_ID_BASE)) { | |||||
String clientIdBase = buildProperties.getProperty(KEY_CLIENT_ID_BASE); | |||||
switch (clientIdBase) { | |||||
case VALUE_MIUI_CLIENT_ID_BASE: | |||||
return ROM.MIUI; | |||||
case VALUE_COLOROS_CLIENT_ID_BASE: | |||||
return ROM.ColorOS; | |||||
case VALUE_FUNTOUCHOS_CLIENT_ID_BASE: | |||||
return ROM.FuntouchOS; | |||||
case VALUE_SAMSUNG_CLIENT_ID_BASE: | |||||
return ROM.SamSung; | |||||
case VALUE_SONY_CLIENT_ID_BASE: | |||||
return ROM.Sony; | |||||
case VALUE_YULONG_CLIENT_ID_BASE: | |||||
return ROM.YuLong; | |||||
case VALUE_SENSE_CLIENT_ID_BASE: | |||||
return ROM.Sense; | |||||
case VALUE_LENOVO_CLIENT_ID_BASE: | |||||
return ROM.Lenovo; | |||||
case VALUE_AMIGO_CLIENT_ID_BASE: | |||||
return ROM.AmigoOS; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
} catch (IOException e) { | |||||
e.printStackTrace(); | |||||
} finally { | |||||
if (is != null) { | |||||
try { | |||||
is.close(); | |||||
} catch (IOException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
return rom; | |||||
} | |||||
public enum ROM { | |||||
MIUI, // 小米 | |||||
Flyme, // 魅族 | |||||
EMUI, // 华为 | |||||
ColorOS, // OPPO | |||||
FuntouchOS, // vivo | |||||
SmartisanOS, // 锤子 | |||||
EUI, // 乐视 | |||||
Sense, // HTC | |||||
AmigoOS, // 金立 | |||||
_360OS, // 奇酷360 | |||||
NubiaUI, // 努比亚 | |||||
H2OS, // 一加 | |||||
YunOS, // 阿里巴巴 | |||||
YuLong, // 酷派 | |||||
SamSung, // 三星 | |||||
Sony, // 索尼 | |||||
Lenovo, // 联想 | |||||
LG, // LG | |||||
Google, // 原生 | |||||
Other; // CyanogenMod, Lewa OS, 百度云OS, Tencent OS, 深度OS, IUNI OS, Tapas OS, Mokee | |||||
private int baseVersion = -1; | |||||
private String version; | |||||
public int getBaseVersion() { | |||||
return baseVersion; | |||||
} | |||||
void setBaseVersion(int baseVersion) { | |||||
this.baseVersion = baseVersion; | |||||
} | |||||
public String getVersion() { | |||||
return version; | |||||
} | |||||
void setVersion(String version) { | |||||
this.version = version; | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.content.Context; | |||||
import android.util.Log; | |||||
import androidx.annotation.NonNull; | |||||
import com.yanzhenjie.permission.Action; | |||||
import com.yanzhenjie.permission.AndPermission; | |||||
import java.util.List; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.utils | |||||
* @ClassName: PermissionUtils | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/30 18:21 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class PermissionUtils { | |||||
public static void requestPermission(Context context, String permissions) { | |||||
AndPermission.with(context) | |||||
.runtime() | |||||
.permission(permissions) | |||||
.rationale(new RuntimeRationale()) | |||||
.onGranted(new Action<List<String>>() { | |||||
@Override | |||||
public void onAction(List<String> permissions) { | |||||
Log.e("csd0","获取成功"); | |||||
} | |||||
}) | |||||
.onDenied(new Action<List<String>>() { | |||||
@Override | |||||
public void onAction(@NonNull List<String> permissions) { | |||||
Log.e("csd1","获取成功"); | |||||
} | |||||
}) | |||||
.start(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
public class PhoneUtils { | |||||
public static boolean isPhone(String phone) { | |||||
String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$"; | |||||
if (phone.length() != 11) { | |||||
return false; | |||||
} else { | |||||
Pattern p = Pattern.compile(regex); | |||||
Matcher m = p.matcher(phone); | |||||
boolean isMatch = m.matches(); | |||||
return isMatch; | |||||
} | |||||
} | |||||
public static String hidePhone(String phone){ | |||||
return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.content.Context; | |||||
import android.content.SharedPreferences; | |||||
import java.lang.reflect.InvocationTargetException; | |||||
import java.lang.reflect.Method; | |||||
import java.util.Map; | |||||
public class PrefUtils { | |||||
/** | |||||
* 保存在手机里的文件名 | |||||
* */ | |||||
private static final String FILE_NAME = "share_data"; | |||||
/** | |||||
* 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 | |||||
* | |||||
* @param context | |||||
* @param key | |||||
* @param object | |||||
* */ | |||||
public static void put(Context context,String key,Object object){ | |||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); | |||||
SharedPreferences.Editor editor = sp.edit(); | |||||
if (object instanceof String){ | |||||
editor.putString(key, (String) object); | |||||
}else if (object instanceof Integer){ | |||||
editor.putInt(key, (Integer) object); | |||||
}else if (object instanceof Boolean){ | |||||
editor.putBoolean(key, (Boolean) object); | |||||
}else if (object instanceof Float){ | |||||
editor.putFloat(key, (Float) object); | |||||
}else if (object instanceof Long){ | |||||
editor.putLong(key, (Long) object); | |||||
}else { | |||||
editor.putString(key,object.toString()); | |||||
} | |||||
SharedPreferencesCompat.apply(editor); | |||||
} | |||||
/** | |||||
* 得到保存数据的放法,我们根据默认值得到保存数据的具体类型,然后调用相对于的方法获取值 | |||||
* | |||||
* @param context | |||||
* @param key | |||||
* @param defaultObject | |||||
* @return | |||||
* */ | |||||
public static Object get(Context context,String key,Object defaultObject){ | |||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); | |||||
if (defaultObject instanceof String){ | |||||
return sp.getString(key, (String) defaultObject); | |||||
}else if (defaultObject instanceof Boolean){ | |||||
return sp.getBoolean(key, (Boolean) defaultObject); | |||||
}else if (defaultObject instanceof Float){ | |||||
return sp.getFloat(key, (Float) defaultObject); | |||||
}else if (defaultObject instanceof Long){ | |||||
return sp.getLong(key, (Long) defaultObject); | |||||
} | |||||
return null; | |||||
} | |||||
/** | |||||
* 移除某个key值对应的值 | |||||
* | |||||
* @param context | |||||
* @param key | |||||
* */ | |||||
public static void remove(Context context,String key){ | |||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); | |||||
SharedPreferences.Editor editor = sp.edit(); | |||||
editor.remove(key); | |||||
SharedPreferencesCompat.apply(editor); | |||||
} | |||||
/** | |||||
* 清除所有数据 | |||||
* | |||||
* @param context | |||||
* */ | |||||
public static void clear(Context context){ | |||||
SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); | |||||
SharedPreferences.Editor editor = sp.edit(); | |||||
editor.clear(); | |||||
editor.commit(); | |||||
} | |||||
/** | |||||
* 查询某个key是否已经存在 | |||||
* | |||||
* @param context | |||||
* @param key | |||||
* @return | |||||
* */ | |||||
public static boolean contains(Context context,String key){ | |||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); | |||||
return sp.contains(key); | |||||
} | |||||
/** | |||||
* 返回所有的键值对 | |||||
* | |||||
* @param context | |||||
* @return | |||||
* */ | |||||
public static Map getAll(Context context){ | |||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); | |||||
return sp.getAll(); | |||||
} | |||||
/** | |||||
* 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类 | |||||
* | |||||
* @author csd | |||||
* */ | |||||
private static class SharedPreferencesCompat{ | |||||
private static final Method sApplyMethod = findApplyMethod(); | |||||
/** | |||||
* 反射查找apply的方法 | |||||
* | |||||
* @return | |||||
* */ | |||||
private static Method findApplyMethod() { | |||||
Class<SharedPreferences.Editor> clz = SharedPreferences.Editor.class; | |||||
try { | |||||
return clz.getMethod("apply"); | |||||
} catch (NoSuchMethodException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
return null; | |||||
} | |||||
/** | |||||
* 如果找到则使用apply执行,否则使用commit | |||||
* | |||||
* @param editor | |||||
* */ | |||||
public static void apply(SharedPreferences.Editor editor){ | |||||
try { | |||||
if (sApplyMethod != null) { | |||||
sApplyMethod.invoke(editor); | |||||
return; | |||||
} | |||||
} catch (IllegalAccessException e) { | |||||
e.printStackTrace(); | |||||
} catch (InvocationTargetException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
editor.commit(); | |||||
} | |||||
} | |||||
private static SharedPreferences sharedPreferences; | |||||
/**写入Boolean变量至sharedPreferences中 | |||||
* @param context 上下文环境 | |||||
* @param key 存储节点名称 | |||||
* @param value 存储节点的值 | |||||
*/ | |||||
public static void putBoolean(Context context,String key,Boolean value){ | |||||
//(存储节点文件名称,读写方式) | |||||
if (sharedPreferences == null){ | |||||
sharedPreferences = context.getSharedPreferences("config",Context.MODE_PRIVATE); | |||||
} | |||||
sharedPreferences.edit().putBoolean(key,value).commit(); | |||||
} | |||||
/**读取boolean标识从sharedPreferences中 | |||||
* @param context 上下文环境 | |||||
* @param key 存储节点名称 | |||||
* @param value 没有此节点的默认值 | |||||
* @return 默认值或者此节点读取到的结果 | |||||
*/ | |||||
public static boolean getBoolean(Context context, String key, Boolean value){ | |||||
//(存储节点文件名称,读写方式) | |||||
if (sharedPreferences == null){ | |||||
sharedPreferences = context.getSharedPreferences("config",Context.MODE_PRIVATE); | |||||
} | |||||
return sharedPreferences.getBoolean(key,value); | |||||
} | |||||
/**写入String变量至sharedPreferences中 | |||||
* @param context 上下文环境 | |||||
* @param key 存储节点名称 | |||||
* @param value 存储节点的值String | |||||
*/ | |||||
public static void putString(Context context,String key,String value){ | |||||
//存储节点文件的名称,读写方式 | |||||
if(sharedPreferences == null){ | |||||
sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE); | |||||
} | |||||
sharedPreferences.edit().putString(key, value).commit(); | |||||
} | |||||
/**读取String标识从sharedPreferences中 | |||||
* @param context 上下文环境 | |||||
* @param key 存储节点名称 | |||||
* @param defValue 没有此节点的默认值 | |||||
* @return 返回默认值或者此节点读取到的结果 | |||||
*/ | |||||
public static String getString(Context context,String key,String defValue){ | |||||
//存储节点文件的名称,读写方式 | |||||
if(sharedPreferences == null){ | |||||
sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE); | |||||
} | |||||
return sharedPreferences.getString(key, defValue); | |||||
} | |||||
/**写入int变量至sharedPreferences中 | |||||
* @param context 上下文环境 | |||||
* @param key 存储节点名称 | |||||
* @param value 存储节点的值String | |||||
*/ | |||||
public static void putInt(Context context,String key,int value){ | |||||
//存储节点文件的名称,读写方式 | |||||
if(sharedPreferences == null){ | |||||
sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE); | |||||
} | |||||
sharedPreferences.edit().putInt(key, value).commit(); | |||||
} | |||||
/**读取int标识从sharedPreferences中 | |||||
* @param context 上下文环境 | |||||
* @param key 存储节点名称 | |||||
* @param defValue 没有此节点的默认值 | |||||
* @return 返回默认值或者此节点读取到的结果 | |||||
*/ | |||||
public static int getInt(Context context,String key,int defValue){ | |||||
//存储节点文件的名称,读写方式 | |||||
if(sharedPreferences == null){ | |||||
sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE); | |||||
} | |||||
return sharedPreferences.getInt(key, defValue); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.app.AlertDialog; | |||||
import android.content.Context; | |||||
import android.content.DialogInterface; | |||||
import android.text.TextUtils; | |||||
import com.example.tidalairpeisong.R; | |||||
import com.yanzhenjie.permission.Rationale; | |||||
import com.yanzhenjie.permission.RequestExecutor; | |||||
import com.yanzhenjie.permission.runtime.Permission; | |||||
import java.util.List; | |||||
/** | |||||
* @ClassName RuntimeRationale | |||||
* @Description TODO | |||||
* @Author csd | |||||
* @Date 2021/7/1 16:30 | |||||
*/ | |||||
public class RuntimeRationale implements Rationale<List<String>> { | |||||
@Override | |||||
public void showRationale(Context context, List<String> permissions, RequestExecutor executor) { | |||||
List<String> permissionNames = Permission.transformText(context, permissions); | |||||
String message = context.getString(R.string.message_permission_rationale, | |||||
TextUtils.join("\n", permissionNames)); | |||||
new AlertDialog.Builder(context).setCancelable(false) | |||||
.setTitle("") | |||||
.setMessage(message) | |||||
.setPositiveButton("允许", new DialogInterface.OnClickListener() { | |||||
@Override | |||||
public void onClick(DialogInterface dialog, int which) { | |||||
executor.execute(); | |||||
} | |||||
}) | |||||
.setNegativeButton("拒绝", new DialogInterface.OnClickListener() { | |||||
@Override | |||||
public void onClick(DialogInterface dialog, int which) { | |||||
executor.cancel(); | |||||
} | |||||
}) | |||||
.show(); | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.graphics.Rect; | |||||
import android.view.View; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
public class SpacesItemDecoration extends RecyclerView.ItemDecoration { | |||||
private int space; | |||||
public SpacesItemDecoration(int space) { | |||||
this.space = space; | |||||
} | |||||
@Override | |||||
public void getItemOffsets(Rect outRect, View view, | |||||
RecyclerView parent, RecyclerView.State state) { | |||||
outRect.left = space; | |||||
outRect.right = space; | |||||
outRect.bottom = space; | |||||
// Add top margin only for the first item to avoid double space between items | |||||
if (parent.getChildPosition(view) == 0) | |||||
outRect.top = space; | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.app.Activity; | |||||
import android.content.Context; | |||||
import android.graphics.Color; | |||||
import android.os.Build; | |||||
import android.view.View; | |||||
import android.view.ViewGroup; | |||||
import android.view.Window; | |||||
import android.view.WindowManager; | |||||
import android.widget.FrameLayout; | |||||
import androidx.annotation.ColorInt; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.RequiresApi; | |||||
import androidx.core.graphics.ColorUtils; | |||||
import com.example.tidalairpeisong.R; | |||||
import java.lang.reflect.Field; | |||||
import java.lang.reflect.Method; | |||||
/** | |||||
* @ClassName StatusBarUtils | |||||
* @Antuor Administrator | |||||
* @Date 2021/10/12 | |||||
* @Version 1.0 | |||||
*/ | |||||
public class StatusBarUtils { | |||||
private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.fake_status_bar_view; | |||||
/** | |||||
* 获得状态栏的高度 | |||||
* | |||||
* @param context 上下文 | |||||
* @return 状态栏高度 | |||||
*/ | |||||
public static int getHeight(Context context) { | |||||
int statusBarHeight = 0; | |||||
try { | |||||
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", | |||||
"android"); | |||||
if (resourceId > 0) { | |||||
statusBarHeight = context.getResources().getDimensionPixelSize(resourceId); | |||||
} | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
return statusBarHeight; | |||||
} | |||||
/** | |||||
* 设置状态栏颜色 | |||||
* | |||||
* @param context 上下文,尽量使用Activity | |||||
* @param color 状态栏颜色 | |||||
*/ | |||||
public static void setColor(Context context, @ColorInt int color) { | |||||
if (context instanceof Activity) { | |||||
setColor(((Activity) context).getWindow(), color); | |||||
} | |||||
} | |||||
/** | |||||
* 设置状态栏颜色 | |||||
* | |||||
* @param window 窗口,可用于Activity和Dialog等 | |||||
* @param color 状态栏颜色 | |||||
*/ | |||||
public static void setColor(@NonNull Window window, @ColorInt int color) { | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); | |||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); | |||||
window.setStatusBarColor(color); | |||||
setTextDark(window, !isDarkColor(color)); | |||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | |||||
setColor(window, ColorUtils.blendARGB(Color.TRANSPARENT, color, 0.5f), false); | |||||
} | |||||
} | |||||
/** | |||||
* Android 5.0 以下版本设置状态栏颜色 | |||||
* | |||||
* @param window 窗口 | |||||
* @param color 状态栏颜色值 | |||||
* @param isTransparent 是否透明 | |||||
*/ | |||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | |||||
public static void setColor(@NonNull Window window, @ColorInt int color, | |||||
boolean isTransparent) { | |||||
Context context = window.getContext(); | |||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); | |||||
ViewGroup decorView = (ViewGroup) window.getDecorView(); | |||||
View contentView = decorView.findViewById(android.R.id.content); | |||||
if (contentView != null) { | |||||
contentView.setPadding(0, isTransparent ? 0 : getHeight(context), 0, 0); | |||||
} | |||||
View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID); | |||||
if (fakeStatusBarView != null) { | |||||
fakeStatusBarView.setBackgroundColor(color); | |||||
if (fakeStatusBarView.getVisibility() == View.GONE) { | |||||
fakeStatusBarView.setVisibility(View.VISIBLE); | |||||
} | |||||
} else { | |||||
// 绘制一个和状态栏一样高的矩形 | |||||
View statusBarView = new View(context); | |||||
FrameLayout.LayoutParams layoutParams = | |||||
new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | |||||
getHeight(context)); | |||||
statusBarView.setLayoutParams(layoutParams); | |||||
statusBarView.setBackgroundColor(color); | |||||
statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID); | |||||
decorView.addView(statusBarView); | |||||
} | |||||
} | |||||
/** | |||||
* 设置状态栏透明 | |||||
* | |||||
* @param context 上下文,尽量使用Activity | |||||
*/ | |||||
public static void setTransparent(Context context) { | |||||
if (context instanceof Activity) { | |||||
setTransparent(((Activity) context).getWindow()); | |||||
} | |||||
} | |||||
/** | |||||
* 设置状态栏透明 | |||||
* | |||||
* @param window 窗口,可用于Activity和Dialog等 | |||||
*/ | |||||
public static void setTransparent(@NonNull Window window) { | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); | |||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | |||||
window.setStatusBarColor(Color.TRANSPARENT); | |||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | |||||
setColor(window, 0x80000000, true); | |||||
} | |||||
} | |||||
/** | |||||
* 设置状态栏是否为黑色文字 | |||||
* | |||||
* @param context 上下文,尽量使用Activity | |||||
* @param isDark 是否为黑色文字 | |||||
*/ | |||||
public static void setTextDark(Context context, boolean isDark) { | |||||
if (context instanceof Activity) { | |||||
setTextDark(((Activity) context).getWindow(), isDark); | |||||
} | |||||
} | |||||
/** | |||||
* 设置状态栏是否为黑色文字 | |||||
* | |||||
* @param window 窗口,可用于Activity和全屏Dialog | |||||
* @param isDark 是否为黑色文字 | |||||
*/ | |||||
private static void setTextDark(Window window, boolean isDark) { | |||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { | |||||
View decorView = window.getDecorView(); | |||||
int systemUiVisibility = decorView.getSystemUiVisibility(); | |||||
if (isDark) { | |||||
decorView.setSystemUiVisibility(systemUiVisibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | |||||
} else { | |||||
decorView.setSystemUiVisibility(systemUiVisibility & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | |||||
} | |||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |||||
switch (OSUtils.getRomType()) { | |||||
case MIUI: | |||||
setMIUIDark(window, isDark); | |||||
break; | |||||
case Flyme: | |||||
setFlymeDark(window, isDark); | |||||
break; | |||||
default: | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 设置MIUI系统状态栏是否为黑色文字 | |||||
* | |||||
* @param window 窗口,仅可用于Activity | |||||
* @param isDark 是否为黑色文字 | |||||
*/ | |||||
private static void setMIUIDark(Window window, boolean isDark) { | |||||
try { | |||||
Class<? extends Window> clazz = window.getClass(); | |||||
int darkModeFlag; | |||||
Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); | |||||
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); | |||||
darkModeFlag = field.getInt(layoutParams); | |||||
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); | |||||
extraFlagField.invoke(window, isDark ? darkModeFlag : 0, darkModeFlag); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
/** | |||||
* 设置Flyme系统状态栏是否为黑色文字 | |||||
* | |||||
* @param window 窗口 | |||||
* @param isDark 是否为黑色文字 | |||||
*/ | |||||
private static void setFlymeDark(Window window, boolean isDark) { | |||||
if (window != null) { | |||||
try { | |||||
WindowManager.LayoutParams lp = window.getAttributes(); | |||||
Field darkFlag = WindowManager.LayoutParams.class | |||||
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); | |||||
Field meizuFlags = WindowManager.LayoutParams.class | |||||
.getDeclaredField("meizuFlags"); | |||||
darkFlag.setAccessible(true); | |||||
meizuFlags.setAccessible(true); | |||||
int bit = darkFlag.getInt(null); | |||||
int value = meizuFlags.getInt(lp); | |||||
if (isDark) { | |||||
value |= bit; | |||||
} else { | |||||
value &= ~bit; | |||||
} | |||||
meizuFlags.setInt(lp, value); | |||||
window.setAttributes(lp); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 判断颜色是否为深色 | |||||
* | |||||
* @param color 要判断的颜色 | |||||
* @return 是否为深色 | |||||
*/ | |||||
public static boolean isDarkColor(@ColorInt int color) { | |||||
// double darkness = | |||||
// 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255; | |||||
// return darkness >= 0.5; | |||||
return ColorUtils.calculateLuminance(color) < 0.5; | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
/** | |||||
* @ClassName SystemUtil | |||||
* @Antuor Administrator | |||||
* @Date 2021/10/12 | |||||
* @Version 1.0 | |||||
*/ | |||||
public class SystemUtil { | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.os.Handler; | |||||
import android.os.Looper; | |||||
import android.widget.Toast; | |||||
import com.example.tidalairpeisong.App; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.utils | |||||
* @ClassName: Tip | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/19 21:35 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class Tip { | |||||
private static Handler mHandler = new Handler(Looper.getMainLooper()); | |||||
private static Toast mToast; | |||||
public static void show(int msgResId) { | |||||
show(msgResId, false); | |||||
} | |||||
public static void show(int msgResId, boolean timeLong) { | |||||
show(App.getInstance().getString(msgResId), timeLong); | |||||
} | |||||
public static void show(CharSequence msg) { | |||||
show(msg, false); | |||||
} | |||||
public static void show(final CharSequence msg, final boolean timeLong) { | |||||
runOnUiThread(() -> { | |||||
if (mToast != null) { | |||||
mToast.cancel(); | |||||
} | |||||
int duration = timeLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT; | |||||
mToast = Toast.makeText(App.getInstance(), msg, duration); | |||||
mToast.show(); | |||||
}); | |||||
} | |||||
private static void runOnUiThread(Runnable runnable) { | |||||
if (Looper.getMainLooper() == Looper.myLooper()) { | |||||
runnable.run(); | |||||
} else { | |||||
mHandler.post(runnable); | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.utils; | |||||
import android.content.Context; | |||||
import android.os.Handler; | |||||
import android.widget.Toast; | |||||
/** | |||||
* 下一个Toast覆盖上一个Toast | |||||
*/ | |||||
public class ToastUtil { | |||||
private static Toast mToast; | |||||
private static Handler mHandler = new Handler(); | |||||
private static Runnable r = new Runnable() { | |||||
public void run() { | |||||
mToast.cancel(); | |||||
} | |||||
}; | |||||
public static void makeText(Context mContext, String text) { | |||||
mHandler.removeCallbacks(r); | |||||
if (mToast != null) | |||||
mToast.setText(text); | |||||
else | |||||
mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT); | |||||
mHandler.postDelayed(r, 2000); | |||||
mToast.show(); | |||||
} | |||||
// public static void makeText(Context mContext, int resId, int duration) { | |||||
// makeText(mContext, mContext.getResources().getString(resId), duration); | |||||
// } | |||||
} |
package com.example.tidalairpeisong.view; | |||||
import android.annotation.SuppressLint; | |||||
import android.content.Context; | |||||
import android.graphics.Paint; | |||||
import android.util.AttributeSet; | |||||
import android.widget.TextView; | |||||
/** | |||||
* 添加横线的textview | |||||
* */ | |||||
@SuppressLint("AppCompatCustomView") | |||||
public class DrawLineTextView extends TextView { | |||||
public DrawLineTextView(Context context) { | |||||
this(context, null); | |||||
} | |||||
public DrawLineTextView(Context context, AttributeSet attrs) { | |||||
super(context, attrs); | |||||
getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); | |||||
} | |||||
} |
package com.example.tidalairpeisong.view; | |||||
import android.annotation.SuppressLint; | |||||
import android.content.Context; | |||||
import android.text.Editable; | |||||
import android.text.Selection; | |||||
import android.text.Spannable; | |||||
import android.text.TextWatcher; | |||||
import android.util.AttributeSet; | |||||
import android.widget.EditText; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.view | |||||
* @ClassName: InputEditText | |||||
* @Description: 禁止表情符输入框 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/27 19:32 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
@SuppressLint("AppCompatCustomView") | |||||
public class InputEditText extends EditText { | |||||
//输入表情前的光标位置 | |||||
private int cursorPos; | |||||
//输入表情前EditText中的文本 | |||||
private String inputAfterText; | |||||
//是否重置了EditText的内容 | |||||
private boolean resetText; | |||||
private Context mContext; | |||||
public boolean isVoice=false; | |||||
public int large_num=200; | |||||
public InputEditText(Context context) { | |||||
super(context); | |||||
this.mContext=context; | |||||
initView(); | |||||
} | |||||
public InputEditText(Context context, AttributeSet attrs) { | |||||
super(context, attrs); | |||||
this.mContext=context; | |||||
initView(); | |||||
} | |||||
public InputEditText(Context context, AttributeSet attrs, int defStyleAttr) { | |||||
super(context, attrs, defStyleAttr); | |||||
this.mContext=context; | |||||
initView(); | |||||
} | |||||
private void initView(){ | |||||
addTextChangedListener(new TextWatcher() { | |||||
@Override | |||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |||||
if (!resetText) { | |||||
cursorPos = getSelectionEnd(); | |||||
// 这里用s.toString()而不直接用s是因为如果用s, | |||||
// 那么,inputAfterText和s在内存中指向的是同一个地址,s改变了, | |||||
// inputAfterText也就改变了,那么表情过滤就失败了 | |||||
inputAfterText= s.toString(); | |||||
} | |||||
} | |||||
@Override | |||||
public void onTextChanged(CharSequence s, int start, int before, int count) { | |||||
if(s.length()>=large_num){ | |||||
s.subSequence(0,large_num); | |||||
} | |||||
if(!isVoice){ | |||||
try { | |||||
if (!resetText) { | |||||
if (count >= 2) {//表情符号的字符长度最小为2 | |||||
CharSequence input = s.subSequence(cursorPos, cursorPos + count); | |||||
if (containsEmoji(input.toString())) { | |||||
resetText = true; | |||||
//是表情符号就将文本还原为输入表情符号之前的内容 | |||||
setText(inputAfterText); | |||||
CharSequence text = getText(); | |||||
if (text instanceof Spannable) { | |||||
Spannable spanText = (Spannable) text; | |||||
Selection.setSelection(spanText, cursorPos); | |||||
} | |||||
} | |||||
} | |||||
} else { | |||||
resetText = false; | |||||
} | |||||
}catch (IndexOutOfBoundsException e){ | |||||
} | |||||
} | |||||
} | |||||
@Override | |||||
public void afterTextChanged(Editable s) { | |||||
if(null!=callBack){ | |||||
callBack.onCallBack(getText().toString().trim()); | |||||
isVoice=false; | |||||
} | |||||
} | |||||
}); | |||||
} | |||||
/** | |||||
* 检测是否有emoji表情 | |||||
* | |||||
* @param source | |||||
* @return | |||||
*/ | |||||
public static boolean containsEmoji(String source) { | |||||
int len = source.length(); | |||||
for (int i = 0; i < len; i++) { | |||||
char codePoint = source.charAt(i); | |||||
if (!isEmojiCharacter(codePoint)) { //如果不能匹配,则该字符是Emoji表情 | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* 判断是否是Emoji | |||||
* | |||||
* @param codePoint 比较的单个字符 | |||||
* @return | |||||
*/ | |||||
private static boolean isEmojiCharacter(char codePoint) { | |||||
return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || | |||||
(codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || | |||||
((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) | |||||
&& (codePoint <= 0x10FFFF)); | |||||
} | |||||
public interface CallBack{ | |||||
void onCallBack(String s); | |||||
} | |||||
public CallBack callBack; | |||||
public void setCallBack(CallBack callBack){ | |||||
this.callBack=callBack; | |||||
} | |||||
public void setIsVoice(boolean voice){ | |||||
isVoice=voice; | |||||
} | |||||
public void setLargeInt(int large){ | |||||
large_num=large; | |||||
} | |||||
} |
package com.example.tidalairpeisong.view; | |||||
import androidx.annotation.ColorInt; | |||||
import androidx.annotation.FloatRange; | |||||
import androidx.annotation.IntRange; | |||||
/** | |||||
* @author matt | |||||
* blog: addapp.cn | |||||
*/ | |||||
public class LineConfig { | |||||
public enum DividerType { // 分隔线类型 | |||||
FILL, WRAP | |||||
} | |||||
private static final int LINE_ALPHA = 220; | |||||
private static final int LINE_COLOR = 0X7F050041; | |||||
private static final float LINE_THICK = 1f;//px | |||||
private boolean visible = true; | |||||
private boolean shadowVisible = false; | |||||
private int color = LINE_COLOR; | |||||
private int alpha = LINE_ALPHA; | |||||
private float ratio = (float) (1.0 / 9.5); | |||||
private float thick = LINE_THICK;// px | |||||
private int width = 0; | |||||
private int height = 0; | |||||
private int itemHeight = 0; | |||||
private int wheelSize = 0; | |||||
public LineConfig() { | |||||
super(); | |||||
} | |||||
public LineConfig(@FloatRange(from = 0, to = 1) float ratio) { | |||||
this.ratio = ratio; | |||||
} | |||||
/** | |||||
* 线是否可见 | |||||
*/ | |||||
public void setVisible(boolean visible) { | |||||
this.visible = visible; | |||||
} | |||||
public boolean isVisible() { | |||||
return visible; | |||||
} | |||||
/** | |||||
* 阴影是否可见 | |||||
*/ | |||||
public void setShadowVisible(boolean shadowVisible) { | |||||
this.shadowVisible = shadowVisible; | |||||
} | |||||
public boolean isShadowVisible() { | |||||
return shadowVisible; | |||||
} | |||||
@ColorInt | |||||
public int getColor() { | |||||
return color; | |||||
} | |||||
/** | |||||
* 线颜色 | |||||
*/ | |||||
public void setColor(@ColorInt int color) { | |||||
this.color = color; | |||||
} | |||||
@IntRange(from = 1, to = 255) | |||||
public int getAlpha() { | |||||
return alpha; | |||||
} | |||||
/** | |||||
* 线透明度 | |||||
*/ | |||||
public void setAlpha(@IntRange(from = 1, to = 255) int alpha) { | |||||
this.alpha = alpha; | |||||
} | |||||
@FloatRange(from = 0, to = 1) | |||||
public float getRatio() { | |||||
return ratio; | |||||
} | |||||
/** | |||||
* 线比例,范围为0-1,0表示最长,1表示最短 | |||||
*/ | |||||
public void setRatio(@FloatRange(from = 0, to = 1) float ratio) { | |||||
this.ratio = ratio; | |||||
} | |||||
public float getThick() { | |||||
return thick; | |||||
} | |||||
/** | |||||
* 线粗 | |||||
*/ | |||||
public void setThick(float thick) { | |||||
this.thick = thick; | |||||
} | |||||
public int getWidth() { | |||||
return width; | |||||
} | |||||
public void setWidth(int width) { | |||||
this.width = width; | |||||
} | |||||
public int getHeight() { | |||||
return height; | |||||
} | |||||
public void setHeight(int height) { | |||||
this.height = height; | |||||
} | |||||
public int getItemHeight() { | |||||
return itemHeight; | |||||
} | |||||
public void setItemHeight(int itemHeight) { | |||||
this.itemHeight = itemHeight; | |||||
} | |||||
public int getWheelSize() { | |||||
return wheelSize; | |||||
} | |||||
public void setWheelSize(int wheelSize) { | |||||
this.wheelSize = wheelSize; | |||||
} | |||||
@Override | |||||
public String toString() { | |||||
return "visible=" + visible + "color=" + color + ", alpha=" + alpha | |||||
+ ", thick=" + thick + ", width=" + width; | |||||
} | |||||
} |
package com.example.tidalairpeisong.view; | |||||
import android.content.Context; | |||||
import android.content.res.Configuration; | |||||
import android.os.Build; | |||||
import android.util.AttributeSet; | |||||
import android.webkit.WebView; | |||||
public class MyWebView extends WebView { | |||||
public MyWebView(Context context) { | |||||
super(getFixedContext(context)); | |||||
} | |||||
public MyWebView(Context context, AttributeSet attrs) { | |||||
super(getFixedContext(context), attrs); | |||||
} | |||||
public MyWebView(Context context, AttributeSet attrs, int defStyleAttr) { | |||||
super(getFixedContext(context), attrs, defStyleAttr); | |||||
} | |||||
private static Context getFixedContext(Context context){ | |||||
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23){ | |||||
return context.createConfigurationContext(new Configuration()); | |||||
} | |||||
return context; | |||||
} | |||||
} |
package com.example.tidalairpeisong.view; | |||||
import android.content.Context; | |||||
import android.graphics.Canvas; | |||||
import android.graphics.Color; | |||||
import android.graphics.ColorFilter; | |||||
import android.graphics.Paint; | |||||
import android.graphics.PixelFormat; | |||||
import android.graphics.drawable.Drawable; | |||||
import android.graphics.drawable.GradientDrawable; | |||||
import android.graphics.drawable.LayerDrawable; | |||||
import android.os.Build; | |||||
import androidx.annotation.ColorInt; | |||||
import androidx.annotation.DrawableRes; | |||||
import androidx.annotation.IntRange; | |||||
import android.text.TextUtils; | |||||
import android.util.AttributeSet; | |||||
import android.view.Gravity; | |||||
import android.view.MotionEvent; | |||||
import android.view.View; | |||||
import android.view.ViewGroup; | |||||
import android.view.ViewTreeObserver; | |||||
import android.widget.AbsListView; | |||||
import android.widget.BaseAdapter; | |||||
import android.widget.ImageView; | |||||
import android.widget.LinearLayout; | |||||
import android.widget.ListAdapter; | |||||
import android.widget.ListView; | |||||
import android.widget.TextView; | |||||
import com.example.tidalairpeisong.utils.ConvertUtils; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
/** | |||||
* Created by Administrator on 2017/7/10. | |||||
*/ | |||||
public class WheelListView extends ListView implements ListView.OnScrollListener, View.OnTouchListener, | |||||
ViewTreeObserver.OnGlobalLayoutListener { | |||||
public static final int SMOOTH_SCROLL_DURATION = 50;//ms | |||||
public static final int SECTION_DELAY = 600;//ms | |||||
public static final int TEXT_SIZE = 16;//sp | |||||
public static final float TEXT_ALPHA = 0.8f; | |||||
public static final int TEXT_COLOR_FOCUS = 0XFF333333;//选中的字体颜色 | |||||
public static final int TEXT_COLOR_NORMAL = 0XFF999999;//未选中字体颜色 | |||||
public static final int ITEM_OFF_SET = 2; | |||||
public static final int ITEM_HEIGHT = 25;//dp | |||||
public static final int ITEM_PADDING_TOP_BOTTOM = 5;//dp | |||||
public static final int ITEM_PADDING_LEFT_RIGHT = 5;//dp | |||||
public static final int ITEM_MARGIN = 5;//dp | |||||
public static final int ITEM_TAG_IMAGE = 100; | |||||
public static final int ITEM_TAG_TEXT = 101; | |||||
private static final int MATCH_PARENT = ViewGroup.LayoutParams.MATCH_PARENT; | |||||
private static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT; | |||||
private int itemHeightPixels = 0; // 每一项高度 | |||||
private int currentPosition = -1; // 记录滚轮当前刻度 | |||||
private WheelAdapter adapter = new WheelAdapter(); | |||||
private OnWheelChangeListener onWheelChangeListener; | |||||
private int textSize = TEXT_SIZE; | |||||
private int textColorNormal = TEXT_COLOR_NORMAL; | |||||
private int textColorFocus = TEXT_COLOR_FOCUS; | |||||
private boolean isUserScroll = false;//是否用户手动滚动 | |||||
private LineConfig lineConfig = null;//分割线配置 | |||||
public WheelListView(Context context) { | |||||
super(context); | |||||
init(); | |||||
} | |||||
public WheelListView(Context context, AttributeSet attrs) { | |||||
super(context, attrs); | |||||
init(); | |||||
} | |||||
public WheelListView(Context context, AttributeSet attrs, int defStyleAttr) { | |||||
super(context, attrs, defStyleAttr); | |||||
init(); | |||||
} | |||||
private void init() { | |||||
setVerticalScrollBarEnabled(false); | |||||
setScrollingCacheEnabled(false); | |||||
setCacheColorHint(Color.TRANSPARENT); | |||||
setFadingEdgeLength(0); | |||||
setOverScrollMode(OVER_SCROLL_NEVER); | |||||
setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); | |||||
setDividerHeight(0); | |||||
setOnScrollListener(this); | |||||
setOnTouchListener(this); | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |||||
setNestedScrollingEnabled(true); | |||||
} | |||||
if (!isInEditMode()) { | |||||
getViewTreeObserver().addOnGlobalLayoutListener(this); | |||||
} | |||||
super.setAdapter(adapter); | |||||
} | |||||
/** | |||||
* 设置背景 | |||||
*/ | |||||
private void changeBackground() { | |||||
int wheelSize = adapter.getWheelSize(); | |||||
if (null == lineConfig) { | |||||
lineConfig = new LineConfig(); | |||||
} | |||||
lineConfig.setWidth(getWidth()); | |||||
lineConfig.setHeight(itemHeightPixels * wheelSize); | |||||
lineConfig.setWheelSize(wheelSize); | |||||
lineConfig.setItemHeight(itemHeightPixels); | |||||
Drawable drawable; | |||||
WheelDrawable holoWheelDrawable = new HoloWheelDrawable(lineConfig); | |||||
if (lineConfig.isShadowVisible()) { | |||||
WheelDrawable shadowWheelDrawable = new ShadowWheelDrawable(lineConfig); | |||||
if (lineConfig.isVisible()) { | |||||
drawable = new LayerDrawable(new Drawable[]{shadowWheelDrawable, holoWheelDrawable}); | |||||
} else { | |||||
drawable = shadowWheelDrawable; | |||||
} | |||||
} else if (lineConfig.isVisible()) { | |||||
drawable = holoWheelDrawable; | |||||
} else { | |||||
drawable = new WheelDrawable(lineConfig); | |||||
} | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |||||
super.setBackground(drawable); | |||||
} else { | |||||
//noinspection deprecation | |||||
super.setBackgroundDrawable(drawable); | |||||
} | |||||
} | |||||
private void _setItems(List<String> list) { | |||||
if (null == list || list.size() == 0) { | |||||
throw new IllegalArgumentException("data are empty"); | |||||
} | |||||
isUserScroll = false; | |||||
currentPosition = -1; | |||||
adapter.setData(list); | |||||
} | |||||
public void setItems(List<String> list) { | |||||
_setItems(list); | |||||
// 2015/12/25 初始化时设置默认选中项 | |||||
setSelectedIndex(0); | |||||
} | |||||
public void setItems(String[] list) { | |||||
setItems(Arrays.asList(list)); | |||||
} | |||||
public void setItems(List<String> list, int index) { | |||||
_setItems(list); | |||||
setSelectedIndex(index); | |||||
} | |||||
public void setItems(List<String> list, String item) { | |||||
_setItems(list); | |||||
setSelectedItem(item); | |||||
} | |||||
public void setItems(String[] list, int index) { | |||||
setItems(Arrays.asList(list), index); | |||||
} | |||||
public void setItems(String[] list, String item) { | |||||
setItems(Arrays.asList(list), item); | |||||
} | |||||
public void setTextSize(int textSize) { | |||||
this.textSize = textSize; | |||||
} | |||||
public void setUnSelectedTextColor(@ColorInt int unSelectedTextColor) { | |||||
this.textColorNormal = unSelectedTextColor; | |||||
} | |||||
public void setSelectedTextColor(@ColorInt int selectedTextColor) { | |||||
this.textColorFocus = selectedTextColor; | |||||
} | |||||
/** | |||||
* 设置滚轮个数偏移量 | |||||
*/ | |||||
public void setOffset(@IntRange(from = 1, to = 3) int offset) { | |||||
if (offset < 1 || offset > 3) { | |||||
throw new IllegalArgumentException("Offset must between 1 and 3"); | |||||
} | |||||
int wheelSize = offset * 2 + 1; | |||||
adapter.setWheelSize(wheelSize); | |||||
} | |||||
/** | |||||
* 设置滚轮是否禁用循环滚动 | |||||
*/ | |||||
public void setCanLoop(boolean canLoop) { | |||||
adapter.setLoop(!canLoop); | |||||
} | |||||
public int getSelectedIndex() { | |||||
return getCurrentPosition(); | |||||
} | |||||
public void setSelectedIndex(final int index) { | |||||
final int realPosition = getRealPosition(index); | |||||
//延时一下以保证数据初始化完成,才定位到选中项 | |||||
postDelayed(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
WheelListView.super.setSelection(realPosition); | |||||
refreshCurrentPosition(); | |||||
} | |||||
}, SECTION_DELAY); | |||||
} | |||||
/** | |||||
* 获取当前滚轮位置的数据 | |||||
*/ | |||||
@Override | |||||
public String getSelectedItem() { | |||||
return adapter.getItem(getCurrentPosition()); | |||||
} | |||||
public void setSelectedItem(String item) { | |||||
setSelectedIndex(adapter.getData().indexOf(item)); | |||||
} | |||||
/** | |||||
* 获得滚轮当前真实位置 | |||||
*/ | |||||
private int getRealPosition(int position) { | |||||
int realCount = adapter.getRealCount(); | |||||
if (realCount == 0) { | |||||
return 0; | |||||
} | |||||
if (adapter.isLoop()) { | |||||
int d = Integer.MAX_VALUE / 2 / realCount; | |||||
return position + d * realCount - adapter.getWheelSize() / 2; | |||||
} | |||||
return position; | |||||
} | |||||
/** | |||||
* 获取当前滚轮位置 | |||||
*/ | |||||
public int getCurrentPosition() { | |||||
if (currentPosition == -1) { | |||||
return 0; | |||||
} | |||||
return currentPosition; | |||||
} | |||||
/** | |||||
* 设置滚轮数据适配器 | |||||
* | |||||
* @deprecated 使用{@link #setItems}代替 | |||||
*/ | |||||
@Deprecated | |||||
@Override | |||||
public void setAdapter(ListAdapter adapter) { | |||||
if (adapter != null && adapter instanceof WheelAdapter) { | |||||
this.adapter = (WheelAdapter) adapter; | |||||
super.setAdapter(this.adapter); | |||||
} else { | |||||
throw new IllegalArgumentException("please invoke setItems"); | |||||
} | |||||
} | |||||
private void onSelectedCallback() { | |||||
int index = getSelectedIndex(); | |||||
String item = getSelectedItem(); | |||||
if (null != onWheelChangeListener) { | |||||
onWheelChangeListener.onItemSelected(isUserScroll, index, item); | |||||
} | |||||
} | |||||
private int obtainSmoothDistance(float scrollDistance) { | |||||
if (Math.abs(scrollDistance) <= 2) { | |||||
return (int) scrollDistance; | |||||
} else if (Math.abs(scrollDistance) < 12) { | |||||
return scrollDistance > 0 ? 2 : -2; | |||||
} else { | |||||
return (int) (scrollDistance / 6); // 减缓平滑滑动速率 | |||||
} | |||||
} | |||||
private void refreshCurrentPosition() { | |||||
if (getChildAt(0) == null || itemHeightPixels == 0) { | |||||
return; | |||||
} | |||||
int firstPosition = getFirstVisiblePosition(); | |||||
if (adapter.isLoop() && firstPosition == 0) { | |||||
return; | |||||
} | |||||
int position; | |||||
if (Math.abs(getChildAt(0).getY()) <= itemHeightPixels / 2) { | |||||
position = firstPosition; | |||||
} else { | |||||
position = firstPosition + 1; | |||||
} | |||||
//由这个逆推:int wheelSize = offset * 2 + 1; | |||||
int offset = (adapter.getWheelSize() - 1) / 2; | |||||
int curPosition = position + offset; | |||||
refreshVisibleItems(firstPosition, curPosition, offset); | |||||
if (adapter.isLoop()) { | |||||
position = curPosition % adapter.getRealCount(); | |||||
} | |||||
if (position == currentPosition) { | |||||
//LogUtils.verbose("scrolling position: " + position); | |||||
return; | |||||
} | |||||
currentPosition = position; | |||||
//LogUtils.verbose("refresh position as: " + position); | |||||
onSelectedCallback(); | |||||
} | |||||
private void refreshVisibleItems(int firstPosition, int curPosition, int offset) { | |||||
for (int i = curPosition - offset; i <= curPosition + offset; i++) { | |||||
View itemView = getChildAt(i - firstPosition); | |||||
if (itemView == null) { | |||||
continue; | |||||
} | |||||
TextView textView = (TextView) itemView.findViewWithTag(ITEM_TAG_TEXT); | |||||
refreshTextView(i, curPosition, itemView, textView); | |||||
} | |||||
} | |||||
private void refreshTextView(int position, int curPosition, View | |||||
itemView, TextView textView) { | |||||
//LogUtils.verbose("position=" + position + ", curPosition=" + curPosition); | |||||
if (curPosition == position) { // 选中 | |||||
setTextView(itemView, textView, textColorFocus, textSize, 1.0f); | |||||
} else { // 未选中 | |||||
int delta = Math.abs(position - curPosition); | |||||
float alpha = (float) Math.pow(TEXT_ALPHA, delta); | |||||
setTextView(itemView, textView, textColorNormal, textSize, alpha); | |||||
} | |||||
} | |||||
private void setTextView(View itemView, TextView textView, int textColor, float textSize, float textAlpha) { | |||||
textView.setTextColor(textColor); | |||||
textView.setTextSize(textSize); | |||||
itemView.setAlpha(textAlpha); | |||||
} | |||||
@Override | |||||
public void onGlobalLayout() { | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |||||
getViewTreeObserver().removeOnGlobalLayoutListener(this); | |||||
} else { | |||||
getViewTreeObserver().removeGlobalOnLayoutListener(this); | |||||
} | |||||
int childCount = getChildCount(); | |||||
if (childCount > 0 && itemHeightPixels == 0) { | |||||
itemHeightPixels = getChildAt(0).getHeight(); | |||||
if (itemHeightPixels == 0) { | |||||
return; | |||||
} | |||||
int wheelSize = adapter.getWheelSize(); | |||||
ViewGroup.LayoutParams params = getLayoutParams(); | |||||
params.height = itemHeightPixels * wheelSize; | |||||
refreshVisibleItems(getFirstVisiblePosition(), | |||||
getCurrentPosition() + wheelSize / 2, wheelSize / 2); | |||||
changeBackground(); | |||||
} | |||||
} | |||||
@Override | |||||
public boolean onTouch(View v, MotionEvent event) { | |||||
isUserScroll = true;//触发触摸事件,说明是用户在滚动 | |||||
//v.getParent().requestDisallowInterceptTouchEvent(true); | |||||
switch (event.getAction()) { | |||||
case MotionEvent.ACTION_DOWN: | |||||
break; | |||||
case MotionEvent.ACTION_UP: | |||||
break; | |||||
} | |||||
return false; | |||||
} | |||||
@Override | |||||
public void onScrollStateChanged(AbsListView view, int scrollState) { | |||||
if (scrollState != SCROLL_STATE_IDLE) { | |||||
return; | |||||
} | |||||
View itemView = getChildAt(0); | |||||
if (itemView == null) { | |||||
return; | |||||
} | |||||
float deltaY = itemView.getY(); | |||||
// fixed: 17-1-7 Equality tests should not be made with floating point values. | |||||
if ((int) deltaY == 0 || itemHeightPixels == 0) { | |||||
return; | |||||
} | |||||
if (Math.abs(deltaY) < itemHeightPixels / 2) { | |||||
int d = obtainSmoothDistance(deltaY); | |||||
smoothScrollBy(d, SMOOTH_SCROLL_DURATION); | |||||
} else { | |||||
int d = obtainSmoothDistance(itemHeightPixels + deltaY); | |||||
smoothScrollBy(d, SMOOTH_SCROLL_DURATION); | |||||
} | |||||
} | |||||
@Override | |||||
public void onScroll(AbsListView view, int firstVisibleItem, int | |||||
visibleItemCount, int totalItemCount) { | |||||
if (visibleItemCount != 0) { | |||||
refreshCurrentPosition(); | |||||
} | |||||
} | |||||
@Override | |||||
protected void onMeasure(int widthSpec, int heightSpec) { | |||||
int width = getLayoutParams().width; | |||||
//LogUtils.verbose(this, "onMeasure: width is " + width); | |||||
if (width == WRAP_CONTENT) { | |||||
//宽度自适应 | |||||
super.onMeasure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), heightSpec); | |||||
} else { | |||||
//宽度填充屏幕或明确设置了宽度 | |||||
super.onMeasure(widthSpec, heightSpec); | |||||
} | |||||
} | |||||
public void setOnWheelChangeListener(OnWheelChangeListener onWheelChangeListener) { | |||||
this.onWheelChangeListener = onWheelChangeListener; | |||||
} | |||||
public void setLineConfig(LineConfig lineConfig) { | |||||
this.lineConfig = lineConfig; | |||||
} | |||||
public interface OnWheelChangeListener { | |||||
/** | |||||
* 滑动选择回调 | |||||
* | |||||
* @param isUserScroll 是否用户手动滚动,用于联动效果判断是否自动重置选中项 | |||||
* @param index 当前选择项的索引 | |||||
* @param item 当前选择项的值 | |||||
*/ | |||||
void onItemSelected(boolean isUserScroll, int index, String item); | |||||
} | |||||
private static class ItemView extends LinearLayout { | |||||
private ImageView imageView; | |||||
private TextView textView; | |||||
public ItemView(Context context) { | |||||
super(context); | |||||
init(context); | |||||
} | |||||
public ItemView(Context context, AttributeSet attrs) { | |||||
super(context, attrs); | |||||
init(context); | |||||
} | |||||
public ItemView(Context context, AttributeSet attrs, int defStyleAttr) { | |||||
super(context, attrs, defStyleAttr); | |||||
init(context); | |||||
} | |||||
private void init(Context context) { | |||||
setOrientation(LinearLayout.HORIZONTAL); | |||||
int paddingTopBottom = ConvertUtils.toPx(context, ITEM_PADDING_TOP_BOTTOM); | |||||
int paddingLeftRight = ConvertUtils.toPx(context, ITEM_PADDING_LEFT_RIGHT); | |||||
setPadding(paddingLeftRight, paddingTopBottom, paddingLeftRight, paddingTopBottom); | |||||
setGravity(Gravity.CENTER); | |||||
int height = ConvertUtils.toPx(context, ITEM_HEIGHT); | |||||
// fixed: 17-1-8 #79 安卓4.x兼容问题,java.lang.ClassCastException……onMeasure…… | |||||
setLayoutParams(new AbsListView.LayoutParams(MATCH_PARENT, height)); | |||||
imageView = new ImageView(getContext()); | |||||
imageView.setTag(ITEM_TAG_IMAGE); | |||||
imageView.setVisibility(View.GONE); | |||||
LayoutParams imageParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT); | |||||
imageParams.rightMargin = ConvertUtils.toPx(context, ITEM_MARGIN); | |||||
addView(imageView, imageParams); | |||||
textView = new TextView(getContext()); | |||||
textView.setTag(ITEM_TAG_TEXT); | |||||
textView.setEllipsize(TextUtils.TruncateAt.END); | |||||
textView.setSingleLine(true); | |||||
textView.setIncludeFontPadding(false); | |||||
textView.setGravity(Gravity.CENTER); | |||||
textView.setTextColor(Color.BLACK); | |||||
LayoutParams textParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT); | |||||
addView(textView, textParams); | |||||
} | |||||
/** | |||||
* 设置文本 | |||||
*/ | |||||
public void setText(CharSequence text) { | |||||
textView.setText(text); | |||||
} | |||||
/** | |||||
* 设置图片资源 | |||||
*/ | |||||
public void setImage(@DrawableRes int resId) { | |||||
imageView.setVisibility(View.VISIBLE); | |||||
imageView.setImageResource(resId); | |||||
} | |||||
} | |||||
private static class WheelAdapter extends BaseAdapter { | |||||
private List<String> data = new ArrayList<>(); | |||||
private boolean isLoop = false; | |||||
private int wheelSize = 5; | |||||
public final int getRealCount() { | |||||
return data.size(); | |||||
} | |||||
public final int getCount() { | |||||
if (isLoop) { | |||||
return Integer.MAX_VALUE; | |||||
} | |||||
return data.size() > 0 ? (data.size() + wheelSize - 1) : 0; | |||||
} | |||||
@Override | |||||
public final long getItemId(int position) { | |||||
if (isLoop) { | |||||
return data.size() > 0 ? position % data.size() : position; | |||||
} | |||||
return position; | |||||
} | |||||
@Override | |||||
public final String getItem(int position) { | |||||
if (isLoop) { | |||||
return data.size() > 0 ? data.get(position % data.size()) : null; | |||||
} | |||||
if (data.size() <= position) { | |||||
position = data.size() - 1; | |||||
} | |||||
return data.get(position); | |||||
} | |||||
@Override | |||||
public boolean areAllItemsEnabled() { | |||||
return false; | |||||
} | |||||
@Override | |||||
public boolean isEnabled(int position) { | |||||
return false; | |||||
} | |||||
@Override | |||||
public final View getView(int position, View convertView, ViewGroup parent) { | |||||
if (isLoop) { | |||||
position = position % data.size(); | |||||
} else { | |||||
if (position < wheelSize / 2) { | |||||
position = -1; | |||||
} else if (position >= wheelSize / 2 + data.size()) { | |||||
position = -1; | |||||
} else { | |||||
position = position - wheelSize / 2; | |||||
} | |||||
} | |||||
ViewHolder holder; | |||||
if (convertView == null) { | |||||
holder = new ViewHolder(); | |||||
holder.itemView = new ItemView(parent.getContext()); | |||||
convertView = holder.itemView; | |||||
convertView.setTag(holder); | |||||
} else { | |||||
holder = (ViewHolder) convertView.getTag(); | |||||
} | |||||
if (!isLoop) { | |||||
holder.itemView.setVisibility(position == -1 ? View.INVISIBLE : View.VISIBLE); | |||||
} | |||||
if (position == -1) { | |||||
position = 0; | |||||
} | |||||
holder.itemView.setText(data.get(position)); | |||||
//holder.wheelItem.setImage(...); | |||||
return convertView; | |||||
} | |||||
public final WheelAdapter setLoop(boolean loop) { | |||||
if (loop != isLoop) { | |||||
isLoop = loop; | |||||
super.notifyDataSetChanged(); | |||||
} | |||||
return this; | |||||
} | |||||
public final WheelAdapter setWheelSize(int wheelSize) { | |||||
if ((wheelSize & 1) == 0) { | |||||
throw new IllegalArgumentException("wheel size must be an odd number."); | |||||
} | |||||
this.wheelSize = wheelSize; | |||||
super.notifyDataSetChanged(); | |||||
return this; | |||||
} | |||||
public final WheelAdapter setData(List<String> list) { | |||||
data.clear(); | |||||
if (null != list) { | |||||
data.addAll(list); | |||||
} | |||||
super.notifyDataSetChanged(); | |||||
return this; | |||||
} | |||||
public List<String> getData() { | |||||
return data; | |||||
} | |||||
public int getWheelSize() { | |||||
return wheelSize; | |||||
} | |||||
public boolean isLoop() { | |||||
return isLoop; | |||||
} | |||||
/** | |||||
* 数据已改变,重绘可见区域 | |||||
*/ | |||||
@Override | |||||
@Deprecated | |||||
public final void notifyDataSetChanged() { | |||||
super.notifyDataSetChanged(); | |||||
} | |||||
/** | |||||
* 数据失效,重绘控件 | |||||
*/ | |||||
@Override | |||||
@Deprecated | |||||
public final void notifyDataSetInvalidated() { | |||||
super.notifyDataSetInvalidated(); | |||||
} | |||||
private static class ViewHolder { | |||||
ItemView itemView; | |||||
} | |||||
} | |||||
private static class WheelDrawable extends Drawable { | |||||
protected int width; | |||||
protected int height; | |||||
private Paint bgPaint; | |||||
public WheelDrawable(LineConfig config) { | |||||
this.width = config.getWidth(); | |||||
this.height = config.getHeight(); | |||||
init(); | |||||
} | |||||
private void init() { | |||||
bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |||||
bgPaint.setColor(Color.TRANSPARENT); | |||||
} | |||||
@Override | |||||
public void draw(Canvas canvas) { | |||||
canvas.drawRect(0, 0, width, height, bgPaint); | |||||
} | |||||
@Override | |||||
public void setAlpha(int alpha) { | |||||
} | |||||
@Override | |||||
public void setColorFilter(ColorFilter colorFilter) { | |||||
} | |||||
@Override | |||||
public int getOpacity() { | |||||
return PixelFormat.UNKNOWN; | |||||
} | |||||
} | |||||
private static class HoloWheelDrawable extends WheelDrawable { | |||||
private Paint bgPaint, paint; | |||||
private int wheelSize, itemHeight; | |||||
private float ratio; | |||||
public HoloWheelDrawable(LineConfig config) { | |||||
super(config); | |||||
this.wheelSize = config.getWheelSize(); | |||||
this.itemHeight = config.getItemHeight(); | |||||
ratio = config.getRatio(); | |||||
init(config); | |||||
} | |||||
private void init(LineConfig config) { | |||||
bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |||||
bgPaint.setColor(Color.TRANSPARENT); | |||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG); | |||||
paint.setStrokeWidth(config.getThick()); | |||||
paint.setColor(config.getColor()); | |||||
paint.setAlpha(config.getAlpha()); | |||||
} | |||||
@Override | |||||
public void draw(Canvas canvas) { | |||||
// draw background | |||||
canvas.drawRect(0, 0, width, height, bgPaint); | |||||
// draw select border | |||||
if (itemHeight != 0) { | |||||
canvas.drawLine(width * ratio, itemHeight * (wheelSize / 2), width * (1 - ratio), | |||||
itemHeight * (wheelSize / 2), paint); | |||||
canvas.drawLine(width * ratio, itemHeight * (wheelSize / 2 + 1), width * (1 - ratio), | |||||
itemHeight * (wheelSize / 2 + 1), paint); | |||||
} | |||||
} | |||||
} | |||||
private static class ShadowWheelDrawable extends WheelDrawable { | |||||
private static final int[] SHADOWS_COLORS = | |||||
{ | |||||
0xFF999999, | |||||
0x00AAAAAA, | |||||
0x00AAAAAA | |||||
}; // 阴影色值 | |||||
private GradientDrawable topShadow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, | |||||
SHADOWS_COLORS); // 顶部阴影 | |||||
private GradientDrawable bottomShadow = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, | |||||
SHADOWS_COLORS); // 底部阴影 | |||||
private Paint bgPaint, paint, dividerPaint; | |||||
private int wheelSize, itemHeight; | |||||
public ShadowWheelDrawable(LineConfig config) { | |||||
super(config); | |||||
this.wheelSize = config.getWheelSize(); | |||||
this.itemHeight = config.getItemHeight(); | |||||
init(); | |||||
} | |||||
private void init() { | |||||
bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |||||
bgPaint.setColor(Color.TRANSPARENT); | |||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG); | |||||
paint.setColor(0XF0CFCFCF); | |||||
dividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |||||
dividerPaint.setColor(0XFFB5B5B5); | |||||
dividerPaint.setStrokeWidth(2); | |||||
} | |||||
@Override | |||||
public void draw(Canvas canvas) { | |||||
// draw background | |||||
canvas.drawRect(0, 0, width, height, bgPaint); | |||||
// draw select border | |||||
if (itemHeight != 0) { | |||||
canvas.drawRect(0, itemHeight * (wheelSize / 2), width, itemHeight | |||||
* (wheelSize / 2 + 1), paint); | |||||
canvas.drawLine(0, itemHeight * (wheelSize / 2), width, itemHeight | |||||
* (wheelSize / 2), dividerPaint); | |||||
canvas.drawLine(0, itemHeight * (wheelSize / 2 + 1), width, itemHeight | |||||
* (wheelSize / 2 + 1), dividerPaint); | |||||
// top, bottom | |||||
topShadow.setBounds(0, 0, width, itemHeight); | |||||
topShadow.draw(canvas); | |||||
bottomShadow.setBounds(0, height - itemHeight, width, height); | |||||
bottomShadow.draw(canvas); | |||||
} | |||||
} | |||||
} | |||||
} |
package com.example.tidalairpeisong.view; | |||||
import android.annotation.TargetApi; | |||||
import android.content.Context; | |||||
import android.os.Build; | |||||
import android.util.AttributeSet; | |||||
import android.view.View; | |||||
import android.view.WindowInsets; | |||||
import android.widget.FrameLayout; | |||||
/** | |||||
* @ProjectName: NewProject | |||||
* @Package: com.example.tidalair.view | |||||
* @ClassName: WindowInsetsFrameLayout | |||||
* @Description: java类作用描述 | |||||
* @Author: csd | |||||
* @CreateDate: 2021/10/19 23:15 | |||||
* @UpdateRemark: 更新说明 | |||||
* @Version: 1.0 | |||||
*/ | |||||
public class WindowInsetsFrameLayout extends FrameLayout { | |||||
public WindowInsetsFrameLayout(Context context) { | |||||
this(context, null); | |||||
} | |||||
public WindowInsetsFrameLayout(Context context, AttributeSet attrs) { | |||||
this(context, attrs, 0); | |||||
} | |||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |||||
public WindowInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { | |||||
super(context, attrs, defStyleAttr); | |||||
setOnHierarchyChangeListener(new OnHierarchyChangeListener() { | |||||
@Override | |||||
public void onChildViewAdded(View parent, View child) { | |||||
requestApplyInsets(); | |||||
} | |||||
@Override | |||||
public void onChildViewRemoved(View parent, View child) { | |||||
} | |||||
}); | |||||
} | |||||
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) | |||||
@Override | |||||
public WindowInsets onApplyWindowInsets(WindowInsets insets) { | |||||
int childCount = getChildCount(); | |||||
for (int index = 0; index < childCount; index++) | |||||
getChildAt(index).dispatchApplyWindowInsets(insets); | |||||
return insets; | |||||
} | |||||
} |
<?xml version="1.0" encoding="utf-8"?> | |||||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<translate | |||||
android:duration="200" | |||||
android:fromYDelta="100%" | |||||
android:toYDelta="0" /> | |||||
</set> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<translate | |||||
android:duration="200" | |||||
android:fromYDelta="0" | |||||
android:toYDelta="100%" /> | |||||
</set> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:width="1dp" | |||||
android:color="@color/color_145ECC"/> | |||||
<corners android:radius="5dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<stroke android:width="1dp" | |||||
android:color="@color/white"/> | |||||
<corners android:radius="2dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="@color/color_EBF0F8"/> | |||||
<corners android:radius="16dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<item android:drawable="@mipmap/dizhi_ic_kai" android:state_checked="true"/> | |||||
<item android:drawable="@mipmap/dizhi_ic_guan" android:state_checked="false"/> | |||||
</selector> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<corners android:radius="19dp"/> | |||||
<gradient | |||||
android:angle="0" | |||||
android:endColor="@color/color_145ECC" | |||||
android:startColor="@color/color_177EE6"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<corners android:radius="2dp"/> | |||||
<solid android:color="@color/color_E1ECFB"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<corners android:radius="2dp"/> | |||||
<solid android:color="@color/color_FFDFD9"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="@color/white"/> | |||||
<corners android:radius="12dp"/> | |||||
<stroke android:color="@color/color_CCCCCC" | |||||
android:width="1dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<stroke android:width="1dp" | |||||
android:color="@color/color_145ECC"/> | |||||
<corners android:radius="5dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<stroke android:width="1dp" | |||||
android:color="@color/color_C2C6CC"/> | |||||
<corners android:radius="5dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="@color/color_145ECC"/> | |||||
<corners android:radius="5dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<item android:drawable="@mipmap/recharge_ic_selected" android:state_checked="true"/> | |||||
<item android:drawable="@mipmap/recharge_ic_unselected2" android:state_checked="false"/> | |||||
</selector> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<item android:drawable="@mipmap/dizhi_ic_gou" android:state_checked="true"/> | |||||
<item android:drawable="@mipmap/dizhi_ic_quan" android:state_checked="false"/> | |||||
</selector> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="#C9CDD3"/> | |||||
<corners android:radius="19dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="@color/color_145ECC"/> | |||||
<corners android:radius="12dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="@color/white"/> | |||||
<corners android:radius="17dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="@color/white"/> | |||||
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<stroke android:width="1dp" | |||||
android:color="@color/color_145ECC"/> | |||||
<corners android:radius="1dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<corners android:radius="8dp"/> | |||||
<gradient | |||||
android:angle="0" | |||||
android:endColor="@color/color_145ECC" | |||||
android:startColor="@color/color_177EE6"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<solid android:color="@color/color_F23D18"/> | |||||
<corners android:radius="6dp"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<corners android:radius="5dp"/> | |||||
<solid android:color="@color/white"/> | |||||
</shape> |
<?xml version="1.0" encoding="utf-8"?> | |||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||||
<gradient | |||||
android:angle="0" | |||||
android:endColor="@color/color_003C96" | |||||
android:startColor="@color/color_4070B9"/> | |||||
</shape> |