version:4.6
fix: update:优化订单页,增加快递详情页
This commit is contained in:
112
app/src/main/java/com/uiuios/aios/activity/ExpressActivity.java
Normal file
112
app/src/main/java/com/uiuios/aios/activity/ExpressActivity.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.base.BaseDataBindingActivity;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.ExpressData;
|
||||
import com.uiuios.aios.bean.LogisticsTrace;
|
||||
import com.uiuios.aios.bean.LogisticsTraceDeta;
|
||||
import com.uiuios.aios.databinding.ActivityExpressBinding;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.TimeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class ExpressActivity extends BaseDataBindingActivity {
|
||||
private static final String TAG = ExpressActivity.class.getSimpleName();
|
||||
|
||||
private ActivityExpressBinding mBinding;
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_express);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) {
|
||||
Log.e(TAG, "initData: intent is null");
|
||||
return;
|
||||
}
|
||||
String orderSn = intent.getStringExtra("order_sn");
|
||||
String orderId = intent.getStringExtra("order_id");
|
||||
if (TextUtils.isEmpty(orderSn) || TextUtils.isEmpty(orderId)) {
|
||||
Log.e(TAG, "initData: orderSn is empty or orderId is empty");
|
||||
return;
|
||||
}
|
||||
getOrderExpress(orderSn, orderId);
|
||||
}
|
||||
|
||||
private void getOrderExpress(String orderSn, String orderId) {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getOrderExpressObservable(orderSn, orderId)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<ExpressData>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getOrderExpress", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<ExpressData> expressDataBaseResponse) {
|
||||
Log.e("getOrderExpress", "onNext: " + expressDataBaseResponse);
|
||||
if (expressDataBaseResponse.code == 200) {
|
||||
ExpressData expressData = expressDataBaseResponse.data;
|
||||
if (expressData.isSuccess()) {
|
||||
LogisticsTrace logisticsTrace = expressData.getLogisticsTrace();
|
||||
mBinding.tvExpressNo.setText(logisticsTrace.getMailNo());
|
||||
List<LogisticsTraceDeta> logisticsTraceDetaList = logisticsTrace.getLogisticsTraceDetailList();
|
||||
for (LogisticsTraceDeta logisticsTraceDeta : logisticsTraceDetaList) {
|
||||
View view = LayoutInflater.from(ExpressActivity.this).inflate(R.layout.item_timeline, mBinding.timelineLayout, false);
|
||||
((TextView) view.findViewById(R.id.tv_action)).setText(logisticsTraceDeta.getDesc());
|
||||
((TextView) view.findViewById(R.id.tv_action_time)).setText(TimeUtils.transferLongToDate(logisticsTraceDeta.getTime()));
|
||||
((TextView) view.findViewById(R.id.tv_action_status)).setText(logisticsTraceDeta.getAreaName());
|
||||
mBinding.timelineLayout.addView(view);
|
||||
}
|
||||
mBinding.timelineLayout.setVisibility(View.VISIBLE);
|
||||
mBinding.clNodata.setVisibility(View.GONE);
|
||||
}else {
|
||||
mBinding.timelineLayout.setVisibility(View.GONE);
|
||||
mBinding.clNodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
mBinding.timelineLayout.setVisibility(View.GONE);
|
||||
mBinding.clNodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getOrderExpress", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getOrderExpress", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -38,10 +38,11 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
||||
public class InformationActivity extends DataBindingActivity {
|
||||
private static final String TAG = InformationActivity.class.getSimpleName();
|
||||
|
||||
|
||||
@BindView(R.id.tabLayout)
|
||||
TabLayout tabLayout;
|
||||
@BindView(R.id.root)
|
||||
ConstraintLayout root;
|
||||
@BindView(R.id.cl_bar)
|
||||
ConstraintLayout cl_bar;
|
||||
@BindView(R.id.rv_video)
|
||||
RecyclerView rv_video;
|
||||
@BindView(R.id.cl_nodata)
|
||||
@@ -60,7 +61,7 @@ public class InformationActivity extends DataBindingActivity {
|
||||
.transparent()
|
||||
.apply();
|
||||
|
||||
UltimateBarX.addStatusBarTopPadding(tabLayout);
|
||||
UltimateBarX.addStatusBarTopPadding(cl_bar);
|
||||
|
||||
mInformationAdapter = new InformationAdapter();
|
||||
LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(this);
|
||||
|
||||
@@ -4,6 +4,7 @@ import androidx.databinding.DataBindingUtil;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
@@ -81,6 +82,12 @@ public class OrderListActivity extends BaseDataBindingActivity {
|
||||
Log.e(TAG, "onTabReselected: " + tab.getText());
|
||||
}
|
||||
});
|
||||
mBinding.ivExit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,14 +124,22 @@ public class OrderListActivity extends BaseDataBindingActivity {
|
||||
OrderIndexData orderIndexData = baseResponse.data;
|
||||
List<OrderIndexBean> orderIndexBeanList = orderIndexData.getData();
|
||||
mOrderAdapter.setOrderIndexBeans(orderIndexBeanList);
|
||||
}else {
|
||||
mBinding.rvOrder.setVisibility(View.VISIBLE);
|
||||
mBinding.clNodata.setVisibility(View.GONE);
|
||||
} else {
|
||||
mOrderAdapter.setOrderIndexBeans(null);
|
||||
mBinding.rvOrder.setVisibility(View.GONE);
|
||||
mBinding.clNodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAllOrderListObserver", "onError: " + e.getMessage());
|
||||
mOrderAdapter.setOrderIndexBeans(null);
|
||||
mBinding.rvOrder.setVisibility(View.GONE);
|
||||
mBinding.clNodata.setVisibility(View.VISIBLE);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,7 @@ public class InformationAdapter extends RecyclerView.Adapter<InformationAdapter.
|
||||
ArticleInfo articleInfo = mArticleInfos.get(position);
|
||||
holder.tv_consult_title.setText(articleInfo.getTitle());
|
||||
GlideLoadUtils.getInstance().glideLoad(mContext, articleInfo.getImg(), holder.nv_consult);
|
||||
holder.tv_time.setText(TimeUtils.transferSecondgToDate(articleInfo.getUpdate_time()));
|
||||
holder.tv_time.setText(TimeUtils.transferSecondgToHour(articleInfo.getUpdate_time()));
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.uiuios.aios.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.ExpressActivity;
|
||||
import com.uiuios.aios.bean.OrderGoods;
|
||||
import com.uiuios.aios.bean.OrderIndexBean;
|
||||
import com.uiuios.aios.utils.GlideLoadUtils;
|
||||
@@ -63,6 +65,21 @@ public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.OrderHolder>
|
||||
holder.tv_unit_price.setText("¥" + orderGoods.getBuy_price());
|
||||
holder.tv_amount.setText(String.valueOf(orderIndexBean.getGoods_total()));
|
||||
holder.tv_paid.setText("实付:¥" + orderIndexBean.getPrice_total() + "元");
|
||||
String latest_transport = orderIndexBean.getLatest_transport();
|
||||
if (TextUtils.isEmpty(latest_transport)) {
|
||||
holder.tv_express_info.setText("暂无物流信息");
|
||||
} else {
|
||||
holder.tv_express_info.setText(latest_transport);
|
||||
}
|
||||
holder.tv_express.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(mContext, ExpressActivity.class);
|
||||
intent.putExtra("order_sn",orderIndexBean.getOrder_sn());
|
||||
intent.putExtra("order_id",orderIndexBean.getId());
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +88,7 @@ public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.OrderHolder>
|
||||
}
|
||||
|
||||
class OrderHolder extends RecyclerView.ViewHolder {
|
||||
TextView tv_statu, tv_title, tv_unit_price, tv_amount, tv_paid, tv_express;
|
||||
TextView tv_statu, tv_title, tv_unit_price, tv_amount, tv_paid, tv_express, tv_express_info;
|
||||
ImageView iv_goods;
|
||||
|
||||
public OrderHolder(@NonNull View itemView) {
|
||||
@@ -83,6 +100,7 @@ public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.OrderHolder>
|
||||
tv_paid = itemView.findViewById(R.id.tv_paid);
|
||||
tv_express = itemView.findViewById(R.id.tv_express);
|
||||
iv_goods = itemView.findViewById(R.id.iv_goods);
|
||||
tv_express_info = itemView.findViewById(R.id.tv_express_info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
44
app/src/main/java/com/uiuios/aios/bean/ExpressData.java
Normal file
44
app/src/main/java/com/uiuios/aios/bean/ExpressData.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.uiuios.aios.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ExpressData implements Serializable {
|
||||
private static final long serialVersionUID = 6282718995656979667L;
|
||||
|
||||
String traceId;
|
||||
String trace_id;
|
||||
boolean success;
|
||||
LogisticsTrace logisticsTrace;
|
||||
|
||||
public String getTraceId() {
|
||||
return traceId;
|
||||
}
|
||||
|
||||
public void setTraceId(String traceId) {
|
||||
this.traceId = traceId;
|
||||
}
|
||||
|
||||
public String getTrace_id() {
|
||||
return trace_id;
|
||||
}
|
||||
|
||||
public void setTrace_id(String trace_id) {
|
||||
this.trace_id = trace_id;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public LogisticsTrace getLogisticsTrace() {
|
||||
return logisticsTrace;
|
||||
}
|
||||
|
||||
public void setLogisticsTrace(LogisticsTrace logisticsTrace) {
|
||||
this.logisticsTrace = logisticsTrace;
|
||||
}
|
||||
}
|
||||
99
app/src/main/java/com/uiuios/aios/bean/LogisticsTrace.java
Normal file
99
app/src/main/java/com/uiuios/aios/bean/LogisticsTrace.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package com.uiuios.aios.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class LogisticsTrace implements Serializable {
|
||||
private static final long serialVersionUID = 3064293483233992595L;
|
||||
|
||||
String theLastTime;
|
||||
String cpCode;
|
||||
String cpUrl;
|
||||
String logisticsStatusDesc;
|
||||
List<LogisticsTraceDeta> logisticsTraceDetailList;
|
||||
String mailNo;
|
||||
String theLastMessage;
|
||||
String cpMobile;
|
||||
String logisticsCompanyName;
|
||||
String logisticsStatus;
|
||||
|
||||
public String getTheLastTime() {
|
||||
return theLastTime;
|
||||
}
|
||||
|
||||
public void setTheLastTime(String theLastTime) {
|
||||
this.theLastTime = theLastTime;
|
||||
}
|
||||
|
||||
public String getCpCode() {
|
||||
return cpCode;
|
||||
}
|
||||
|
||||
public void setCpCode(String cpCode) {
|
||||
this.cpCode = cpCode;
|
||||
}
|
||||
|
||||
public String getCpUrl() {
|
||||
return cpUrl;
|
||||
}
|
||||
|
||||
public void setCpUrl(String cpUrl) {
|
||||
this.cpUrl = cpUrl;
|
||||
}
|
||||
|
||||
public String getLogisticsStatusDesc() {
|
||||
return logisticsStatusDesc;
|
||||
}
|
||||
|
||||
public void setLogisticsStatusDesc(String logisticsStatusDesc) {
|
||||
this.logisticsStatusDesc = logisticsStatusDesc;
|
||||
}
|
||||
|
||||
public List<LogisticsTraceDeta> getLogisticsTraceDetailList() {
|
||||
return logisticsTraceDetailList;
|
||||
}
|
||||
|
||||
public void setLogisticsTraceDetailList(List<LogisticsTraceDeta> logisticsTraceDetailList) {
|
||||
this.logisticsTraceDetailList = logisticsTraceDetailList;
|
||||
}
|
||||
|
||||
public String getMailNo() {
|
||||
return mailNo;
|
||||
}
|
||||
|
||||
public void setMailNo(String mailNo) {
|
||||
this.mailNo = mailNo;
|
||||
}
|
||||
|
||||
public String getTheLastMessage() {
|
||||
return theLastMessage;
|
||||
}
|
||||
|
||||
public void setTheLastMessage(String theLastMessage) {
|
||||
this.theLastMessage = theLastMessage;
|
||||
}
|
||||
|
||||
public String getCpMobile() {
|
||||
return cpMobile;
|
||||
}
|
||||
|
||||
public void setCpMobile(String cpMobile) {
|
||||
this.cpMobile = cpMobile;
|
||||
}
|
||||
|
||||
public String getLogisticsCompanyName() {
|
||||
return logisticsCompanyName;
|
||||
}
|
||||
|
||||
public void setLogisticsCompanyName(String logisticsCompanyName) {
|
||||
this.logisticsCompanyName = logisticsCompanyName;
|
||||
}
|
||||
|
||||
public String getLogisticsStatus() {
|
||||
return logisticsStatus;
|
||||
}
|
||||
|
||||
public void setLogisticsStatus(String logisticsStatus) {
|
||||
this.logisticsStatus = logisticsStatus;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.uiuios.aios.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class LogisticsTraceDeta implements Serializable {
|
||||
private static final long serialVersionUID = 6775968129767296804L;
|
||||
|
||||
String areaCode;
|
||||
String areaName;
|
||||
String subLogisticsStatus;
|
||||
long time;
|
||||
String logisticsStatus;
|
||||
String desc;
|
||||
|
||||
public String getAreaCode() {
|
||||
return areaCode;
|
||||
}
|
||||
|
||||
public void setAreaCode(String areaCode) {
|
||||
this.areaCode = areaCode;
|
||||
}
|
||||
|
||||
public String getAreaName() {
|
||||
return areaName;
|
||||
}
|
||||
|
||||
public void setAreaName(String areaName) {
|
||||
this.areaName = areaName;
|
||||
}
|
||||
|
||||
public String getSubLogisticsStatus() {
|
||||
return subLogisticsStatus;
|
||||
}
|
||||
|
||||
public void setSubLogisticsStatus(String subLogisticsStatus) {
|
||||
this.subLogisticsStatus = subLogisticsStatus;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getLogisticsStatus() {
|
||||
return logisticsStatus;
|
||||
}
|
||||
|
||||
public void setLogisticsStatus(String logisticsStatus) {
|
||||
this.logisticsStatus = logisticsStatus;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.io.Serializable;
|
||||
public class OrderIndexBean implements Serializable {
|
||||
private static final long serialVersionUID = 4544929539747251262L;
|
||||
|
||||
int id;
|
||||
String id;
|
||||
String order_sn;
|
||||
String sn_id;
|
||||
String sn;
|
||||
@@ -39,11 +39,11 @@ public class OrderIndexBean implements Serializable {
|
||||
AdminInfo admin;// 关联企业
|
||||
|
||||
|
||||
public int getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ public class SecondFragment extends BaseFragment implements SecondContact.View,
|
||||
if (mNewGoodsAdapter.getItemCount() == 0 || mGoodsScrolling) {
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "run: " + mNewGoodsAdapter.getItemCount());
|
||||
Log.i(TAG, "run: " + mNewGoodsAdapter.getItemCount());
|
||||
if (mNewGoodsAdapter.getItemCount() <= mCurrentGoodsIndex) {
|
||||
mCurrentGoodsIndex = 0;
|
||||
} else {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.CategoryBean;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.bean.DemandBean;
|
||||
import com.uiuios.aios.bean.ExpressData;
|
||||
import com.uiuios.aios.bean.GoodsList;
|
||||
import com.uiuios.aios.bean.GoodsType;
|
||||
import com.uiuios.aios.bean.HealthCode;
|
||||
@@ -79,6 +80,7 @@ import com.uiuios.aios.network.api.UpdateDesktopApi;
|
||||
import com.uiuios.aios.network.api.UserInfoControl;
|
||||
import com.uiuios.aios.network.api.amap.GeocodingApi;
|
||||
import com.uiuios.aios.network.api.order.AllOrderApi;
|
||||
import com.uiuios.aios.network.api.order.OrderExpressApi;
|
||||
import com.uiuios.aios.network.api.order.OrderIndexApi;
|
||||
import com.uiuios.aios.network.interceptor.RepeatRequestInterceptor;
|
||||
|
||||
@@ -485,6 +487,12 @@ public class NetInterfaceManager {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse<ExpressData>> getOrderExpressObservable(String order_sn, String order_id) {
|
||||
return mRetrofit.create(OrderExpressApi.class)
|
||||
.getOrderExpress(RemoteManager.getInstance().getSerial(), order_sn,order_id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public RegionListApi getRegionListApi() {
|
||||
return mRetrofit.create(RegionListApi.class);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.uiuios.aios.network.api.order;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.ExpressData;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface OrderExpressApi {
|
||||
@GET(UrlAddress.ORDER_EXPRESS)
|
||||
Observable<BaseResponse<ExpressData>> getOrderExpress(
|
||||
@Query("sn") String sn,
|
||||
@Query("order_sn") String order_sn,
|
||||
@Query("order_id") String order_id
|
||||
);
|
||||
}
|
||||
@@ -33,6 +33,12 @@ public class TimeUtils {
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public static String transferSecondgToHour(long second) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||
Date date = new Date(second * 1000);
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public static String secToTime(int totalSecs) {
|
||||
int hours = totalSecs / 3600;
|
||||
int minutes = (totalSecs % 3600) / 60;
|
||||
|
||||
162
app/src/main/java/com/uiuios/aios/view/TimelineLayout.java
Normal file
162
app/src/main/java/com/uiuios/aios/view/TimelineLayout.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package com.uiuios.aios.view;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
|
||||
/**
|
||||
* Created by Jackie on 2017/3/8.
|
||||
* 时间轴控件
|
||||
*/
|
||||
|
||||
public class TimelineLayout extends LinearLayout {
|
||||
private Context mContext;
|
||||
|
||||
private int mLineMarginLeft;
|
||||
private int mLineMarginTop;
|
||||
private int mLineStrokeWidth;
|
||||
private int mLineColor;
|
||||
private int mPointSize;
|
||||
private int mPointColor;
|
||||
private Bitmap mIcon;
|
||||
|
||||
private Paint mLinePaint; //线的画笔
|
||||
private Paint mPointPaint; //点的画笔
|
||||
|
||||
|
||||
//第一个点的位置
|
||||
private int mFirstX;
|
||||
private int mFirstY;
|
||||
//最后一个图标的位置
|
||||
private int mLastX;
|
||||
private int mLastY;
|
||||
|
||||
public TimelineLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public TimelineLayout(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public TimelineLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TimelineLayout);
|
||||
mLineMarginLeft = ta.getDimensionPixelOffset(R.styleable.TimelineLayout_line_margin_left, 10);
|
||||
mLineMarginTop = ta.getDimensionPixelOffset(R.styleable.TimelineLayout_line_margin_top, 0);
|
||||
mLineStrokeWidth = ta.getDimensionPixelOffset(R.styleable.TimelineLayout_line_stroke_width, 5);
|
||||
mLineColor = ta.getColor(R.styleable.TimelineLayout_line_color, 0xff3dd1a5);
|
||||
mPointSize = ta.getDimensionPixelSize(R.styleable.TimelineLayout_point_size, 8);
|
||||
mPointColor = ta.getDimensionPixelOffset(R.styleable.TimelineLayout_point_color, 0xff3dd1a5);
|
||||
|
||||
int iconRes = ta.getResourceId(R.styleable.TimelineLayout_icon_src, R.drawable.ic_ok);
|
||||
BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(iconRes);
|
||||
if (drawable != null) {
|
||||
mIcon = drawable.getBitmap();
|
||||
}
|
||||
|
||||
ta.recycle();
|
||||
|
||||
setWillNotDraw(false);
|
||||
initView(context);
|
||||
}
|
||||
|
||||
private void initView(Context context) {
|
||||
this.mContext = context;
|
||||
|
||||
mLinePaint = new Paint();
|
||||
mLinePaint.setAntiAlias(true);
|
||||
mLinePaint.setDither(true);
|
||||
mLinePaint.setColor(mLineColor);
|
||||
mLinePaint.setStrokeWidth(mLineStrokeWidth);
|
||||
mLinePaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||
|
||||
mPointPaint = new Paint();
|
||||
mPointPaint.setAntiAlias(true);
|
||||
mPointPaint.setDither(true);
|
||||
mPointPaint.setColor(mPointColor);
|
||||
mPointPaint.setStyle(Paint.Style.FILL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
drawTimeline(canvas);
|
||||
Log.e("TimelineLayout", "onDraw: ");
|
||||
}
|
||||
|
||||
private void drawTimeline(Canvas canvas) {
|
||||
Log.e("TimelineLayout", "drawTimeline: ");
|
||||
int childCount = getChildCount();
|
||||
if (childCount > 0) {
|
||||
if (childCount > 1) {
|
||||
//大于1,证明至少有2个,也就是第一个和第二个之间连成线,第一个和最后一个分别有点和icon
|
||||
drawFirstPoint(canvas);
|
||||
drawLastIcon(canvas);
|
||||
drawBetweenLine(canvas);
|
||||
} else if (childCount == 1) {
|
||||
drawFirstPoint(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawFirstPoint(Canvas canvas) {
|
||||
View child = getChildAt(0);
|
||||
if (child != null) {
|
||||
int top = child.getTop();
|
||||
mFirstX = mLineMarginLeft;
|
||||
mFirstY = top + child.getPaddingTop() + mLineMarginTop;
|
||||
//画圆
|
||||
canvas.drawCircle(mFirstX, mFirstY, mPointSize, mPointPaint);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawLastIcon(Canvas canvas) {
|
||||
View child = getChildAt(getChildCount() - 1);
|
||||
if (child != null) {
|
||||
int top = child.getTop();
|
||||
mLastX = mLineMarginLeft;
|
||||
mLastY = top + child.getPaddingTop() + mLineMarginTop;
|
||||
//画图
|
||||
canvas.drawBitmap(mIcon, mLastX - (mIcon.getWidth() >> 1), mLastY, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawBetweenLine(Canvas canvas) {
|
||||
Log.e("TimelineLayout", "drawBetweenLine: " + getChildCount());
|
||||
//从开始的点到最后的图标之间,画一条线
|
||||
canvas.drawLine(mFirstX, mFirstY, mLastX, mLastY, mLinePaint);
|
||||
Log.e("TimelineLayout", "drawBetweenLine: mFirstX = " + mFirstX);
|
||||
Log.e("TimelineLayout", "drawBetweenLine: mFirstY = " + mFirstY);
|
||||
Log.e("TimelineLayout", "drawBetweenLine: mLastX = " + mLastX);
|
||||
Log.e("TimelineLayout", "drawBetweenLine: mLastY = " + mLastY);
|
||||
for (int i = 0; i < getChildCount() - 1; i++) {
|
||||
//画圆
|
||||
int top = getChildAt(i).getTop();
|
||||
int y = top + getChildAt(i).getPaddingTop() + mLineMarginTop;
|
||||
canvas.drawCircle(mFirstX, y, mPointSize, mPointPaint);
|
||||
Log.e("TimelineLayout", "drawBetweenLine: y = " + y);
|
||||
}
|
||||
}
|
||||
|
||||
public int getLineMarginLeft() {
|
||||
return mLineMarginLeft;
|
||||
}
|
||||
|
||||
public void setLineMarginLeft(int lineMarginLeft) {
|
||||
this.mLineMarginLeft = lineMarginLeft;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user