This commit is contained in:
2020-08-28 11:37:41 +08:00
parent 7e8995b024
commit 46011a09c3
31 changed files with 5241 additions and 461 deletions

View File

@@ -2,14 +2,50 @@ package com.fenghoo.seven.base;
import java.io.Serializable;
/**
* @description 实体基类
* @author fangyan
* @date 2015年8月1日
*/
public class BaseBean implements Serializable {
private static final long serialVersionUID = 1L;
private ResultBean result;
private int status;
public ResultBean getResult() {
return result;
}
public void setResult(ResultBean result) {
this.result = result;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public static class ResultBean {
private String msg;
private int success;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getSuccess() {
return success;
}
public void setSuccess(int success) {
this.success = success;
}
}
}

View File

@@ -1,179 +0,0 @@
package com.fenghoo.seven.main.entity;
import com.fenghoo.seven.base.BaseBean;
/**
* 项目名NewJiaJieSong
* 包名com.example.administrator.newjiajiesong
* 创建者:任剑波
* 创建时间2018/8/28 11:14
* 描述TODO
*/
public class UserInfoModel extends BaseBean {
/**
* status : 0
* result : {"success":0,"msg":"登陆成功","data":{"store_name":"红星美凯龙太白店荣麟京瓷","uuid":"0a10f99c198b3cb659a62a765c83c648","phone_number":"13201532560","pet_name":"胡坚强","user_birthday":"","user_head":"http://www.fenghoo.cn/templates/fenghu/img/photo_icon.png","type":"1"}}
*/
private int status;
private ResultBean result;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public ResultBean getResult() {
return result;
}
public void setResult(ResultBean result) {
this.result = result;
}
@Override
public String toString() {
return "LoginRestwo{" +
"status=" + status +
", result=" + result +
'}';
}
public static class ResultBean{
/**
* success : 0
* msg : 登陆成功
* data : {"store_name":"红星美凯龙太白店荣麟京瓷","uuid":"0a10f99c198b3cb659a62a765c83c648","phone_number":"13201532560","pet_name":"胡坚强","user_birthday":"","user_head":"http://www.fenghoo.cn/templates/fenghu/img/photo_icon.png","type":"1"}
*/
private int success;
private String msg;
private DataBean data;
public int getSuccess() {
return success;
}
public void setSuccess(int success) {
this.success = success;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public DataBean getData() {
return data;
}
public void setData(DataBean data) {
this.data = data;
}
@Override
public String toString() {
return "ResultBean{" +
"success=" + success +
", msg='" + msg + '\'' +
", data=" + data +
'}';
}
public static class DataBean{
/**
* store_name : 红星美凯龙太白店荣麟京瓷
* uuid : 0a10f99c198b3cb659a62a765c83c648
* phone_number : 13201532560
* pet_name : 胡坚强
* user_birthday :
* user_head : http://www.fenghoo.cn/templates/fenghu/img/photo_icon.png
* type : 1
*/
private String store_name;
private String uuid;
private String phone_number;
private String pet_name;
private String user_birthday;
private String user_head;
private String type;
public String getStore_name() {
return store_name;
}
public void setStore_name(String store_name) {
this.store_name = store_name;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number) {
this.phone_number = phone_number;
}
public String getPet_name() {
return pet_name;
}
public void setPet_name(String pet_name) {
this.pet_name = pet_name;
}
public String getUser_birthday() {
return user_birthday;
}
public void setUser_birthday(String user_birthday) {
this.user_birthday = user_birthday;
}
public String getUser_head() {
return user_head;
}
public void setUser_head(String user_head) {
this.user_head = user_head;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "DataBean{" +
"store_name='" + store_name + '\'' +
", uuid='" + uuid + '\'' +
", phone_number='" + phone_number + '\'' +
", pet_name='" + pet_name + '\'' +
", user_birthday='" + user_birthday + '\'' +
", user_head='" + user_head + '\'' +
", type='" + type + '\'' +
'}';
}
}
}
}

View File

@@ -55,7 +55,7 @@ public class FindFragment extends BaseFragment {
@Override
public void onClick(View view) {
//进入添加客户和完善信息
ShowAty.AddCustomerActivity(getActivity());
ShowAty.AddCustomerActivity(getActivity(),"","");
}
});
marking_fragment = (TextView)view.findViewById(R.id.marking_fragment);

View File

@@ -0,0 +1,50 @@
package com.fenghoo.seven.main.find.adapter;
import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fenghoo.seven.R;
import com.fenghoo.seven.main.find.entity.StyleBean;
import com.fenghoo.seven.main.kehu.Bean.CustomerListBean;
import com.fenghoo.seven.utils.WidgetTools;
import java.util.List;
public class StyleAdapter extends BaseQuickAdapter<StyleBean.ResultBean.DataBean, BaseViewHolder> {
Context mcontext;
OnViewClickListener onViewClickListener;
public StyleAdapter(Context context, List list) {
super(R.layout.style_item, list);
this.mcontext = context;
}
@Override
protected void convert(final BaseViewHolder helper, final StyleBean.ResultBean.DataBean item) {
WidgetTools.setTextfive((TextView) helper.getView(R.id.tv_style), "", item.getStyle());
RelativeLayout rl_style = (RelativeLayout)helper.getView(R.id.rl_style);
rl_style.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onViewClickListener.enterCusDetail(item);
}
});
}
public void operationListenner(OnViewClickListener onViewClickListener){
this.onViewClickListener = onViewClickListener;
}
public interface OnViewClickListener{
void enterCusDetail(StyleBean.ResultBean.DataBean item);
}
}

View File

@@ -0,0 +1,99 @@
package com.fenghoo.seven.main.find.entity;
import com.fenghoo.seven.test.BaseModel;
import java.util.List;
/**
* Time: 2020/8/28
* Author: jianbo
* Description:
*/
public class StyleBean extends BaseModel {
/**
* result : {"msg":"成功","data":[{"style":"北欧","style_id":"1"}],"success":0}
* status : 0
*/
private ResultBean result;
private int status;
public ResultBean getResult() {
return result;
}
public void setResult(ResultBean result) {
this.result = result;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public static class ResultBean {
/**
* msg : 成功
* data : [{"style":"北欧","style_id":"1"}]
* success : 0
*/
private String msg;
private int success;
private List<DataBean> data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getSuccess() {
return success;
}
public void setSuccess(int success) {
this.success = success;
}
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
/**
* style : 北欧
* style_id : 1
*/
private String style;
private String style_id;
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public String getStyle_id() {
return style_id;
}
public void setStyle_id(String style_id) {
this.style_id = style_id;
}
}
}
}

View File

@@ -0,0 +1,21 @@
package com.fenghoo.seven.main.kehu.Bean;
/**
* Time: 2020/8/28
* Author: jianbo
* Description:
*/
public class FirstEvent {
private String mMsg;
private String sTyle;
public FirstEvent(String msg,String style) {
// TODO Auto-generated constructor stub
mMsg = msg;
sTyle = style;
}
public String getMsg(){
return mMsg;
}
public String getStyle() { return sTyle; }
}

View File

@@ -0,0 +1,17 @@
package com.fenghoo.seven.main.kehu.Bean;
/**
* Time: 2020/8/28
* Author: jianbo
* Description:
*/
public class SecondEvent {
private String mMsg;
public SecondEvent(String msg) {
// TODO Auto-generated constructor stub
mMsg = msg;
}
public String getMsg(){
return mMsg;
}
}

View File

@@ -0,0 +1,123 @@
package com.fenghoo.seven.main.kehu.Bean;
/**
* Time: 2020/8/28
* Author: jianbo
* Description:
*/
public class addCustomerBean {
// private String uid string 登录员工的uid 是 否
// private String headimg string 头像 否 否 base64 空
// private String name string 姓名 是 否
// private String phone string 电话 是 否
// private String wechat string 微信 否 否 空
// private String address string 住址 否 否 空
// private String decoration string 家装阶段 否 否 1毛坯2精装3旧房改造 1
// private String style_id string 风格id 否 否 空
// private String budget string 预算 否 否 空
// private String source string 客户来源 否 否 1添加客户 1
// private String customer_id string 客户id 否 否 有值代表完善信息,空代表添加
private String uid="";
private String headimg="";
private String name="";
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getHeadimg() {
return headimg;
}
public void setHeadimg(String headimg) {
this.headimg = headimg;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getWechat() {
return wechat;
}
public void setWechat(String wechat) {
this.wechat = wechat;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDecoration() {
return decoration;
}
public void setDecoration(String decoration) {
this.decoration = decoration;
}
public String getStyle_id() {
return style_id;
}
public void setStyle_id(String style_id) {
this.style_id = style_id;
}
public String getBudget() {
return budget;
}
public void setBudget(String budget) {
this.budget = budget;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getCustomer_id() {
return customer_id;
}
public void setCustomer_id(String customer_id) {
this.customer_id = customer_id;
}
private String phone="";
private String wechat="";
private String address="";
private String decoration="1";
private String style_id="";
private String budget="";
private String source="1";
private String customer_id="";
}

View File

@@ -67,7 +67,10 @@ public class CustomerFragment extends MobanFragment {
//信息完善
@Override
public void uploadAvatar() {
//进入添加客户和完善信息
String customer_id = item.getCustomer_id();
String source = item.getSource();
ShowAty.AddCustomerActivity(getActivity(),customer_id,source);
}
}).show();

View File

@@ -73,15 +73,15 @@ public class CusOperationDialog extends Dialog implements View.OnClickListener {
}
dismiss();
break;
case R.id.rl_tv_kaidan://开单
case R.id.rl_tv_uploadAvatar://信息完善
if (listener != null) {
listener.kaidanonClick();
listener.uploadAvatar();
}
dismiss();
break;
case R.id.rl_tv_uploadAvatar://上传头像
case R.id.rl_tv_kaidan://删除客户
if (listener != null) {
listener.uploadAvatar();
listener.kaidanonClick();
}
dismiss();
break;

View File

@@ -106,6 +106,7 @@ public class RreplyDialog extends Dialog implements View.OnClickListener {
listener.uploadAvatar();
}
dismiss();
break;
case R.id.reply_ima://快捷回复
if(flag){
reply_rcey.setVisibility(View.VISIBLE);

View File

@@ -58,9 +58,6 @@ public abstract class MoActivity extends BaseActivity {
public View errorView;
public TextView mLayTopTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -75,7 +72,7 @@ public abstract class MoActivity extends BaseActivity {
private void initView(View mContentView) {
mMarkingFragmentRecyclerView = (RecyclerView) findViewById(R.id.marking_fragment_recyclerView);
mSwl = mContentView.findViewById(R.id.srl);
mSwl = findViewById(R.id.srl);
notDataView = this.getLayoutInflater().inflate(R.layout.empty_view, (ViewGroup) mMarkingFragmentRecyclerView.getParent(), false);
notDataView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -114,7 +111,7 @@ public abstract class MoActivity extends BaseActivity {
private void refresh() {
mNextRequestPage = 1;
markingtwoAdapter.setEnableLoadMore(false);//这里的作用是防止下拉刷新的时候还可以上拉加载
// markingtwoAdapter.setEnableLoadMore(false);//这里的作用是防止下拉刷新的时候还可以上拉加载
requestData();
}

View File

@@ -2,30 +2,42 @@ package com.fenghoo.seven.main.kehu.activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.fenghoo.seven.R;
import com.fenghoo.seven.base.BaseActivity;
import com.fenghoo.seven.main.kehu.ui.AddCusFragment;
import com.fenghoo.seven.utils.StatusBarUtil;
import androidx.appcompat.app.AppCompatActivity;
import com.fenghoo.seven.widget.TitleBar;
/**
*添加客户和完善信息
*/
public class AddCustomerActivity extends AppCompatActivity{
private static final int RC_CAMERA_AND_LOCATION = 100;
public class AddCustomerActivity extends BaseActivity {
private static int REQUEST_CODE_CHOOSE = 100;
private AddCusFragment addCusFragment;
private TitleBar mTitleBar;
private String customer_id="";
private String source="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_customer);
StatusBarUtil.transparencyBar(this); //设置状态栏全透明
StatusBarUtil.setStatusBarColor(this,R.color.colortheme);
addCusFragment = new AddCusFragment();
mTitleBar = (TitleBar) findViewById(R.id.title_bar);
mTitleBar.setTitle("信息完善");
initNormalBack();
customer_id = getIntent().getStringExtra("customer_id");
source = getIntent().getStringExtra("source");
addCusFragment = new AddCusFragment(customer_id,source);
getSupportFragmentManager().beginTransaction().replace(R.id.containerrr,addCusFragment).commit();
findViewById(R.id.btn_comit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addCusFragment.comit();
}
});
}
@Override

View File

@@ -0,0 +1,68 @@
package com.fenghoo.seven.main.kehu.activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fenghoo.seven.R;
import com.fenghoo.seven.main.kehu.Bean.FirstEvent;
import com.fenghoo.seven.main.kehu.Bean.SecondEvent;
import com.fenghoo.seven.main.kehu.MoActivity;
import com.fenghoo.seven.utils.WidgetTools;
import com.fenghoo.seven.widget.TitleBar;
import java.util.ArrayList;
import androidx.recyclerview.widget.LinearLayoutManager;
import de.greenrobot.event.EventBus;
/**
*
*/
public class BudgetActivity extends MoActivity {
private ArrayList<String> budgets = new ArrayList<>();
private TitleBar mTitleBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTitleBar = (TitleBar) findViewById(R.id.title_bar);
mTitleBar.setTitle("选择预算");
initNormalBack();
}
@Override
public void initAdapter() {
mMarkingFragmentRecyclerView.setLayoutManager(new LinearLayoutManager(BudgetActivity.this));
mMarkingFragmentRecyclerView.setAdapter(new BaseQuickAdapter<String, BaseViewHolder>(R.layout.style_item, budgets) {
@Override
protected void convert(final BaseViewHolder helper, final String item) {
WidgetTools.setTextfive((TextView) helper.getView(R.id.tv_style), "", item);
RelativeLayout rl_style = (RelativeLayout)helper.getView(R.id.rl_style);
rl_style.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EventBus.getDefault().post(new SecondEvent(item));
finish();
}
});
}
});
}
@Override
public void requestData() {
mSwl.setRefreshing(false);
budgets.add("0万-5万");
budgets.add("5万-10万");
budgets.add("10万-15万");
budgets.add("15万-20万");
budgets.add("20万以上");
}
}

View File

@@ -120,10 +120,22 @@ public class ShowAty {
* @param
* @return
*/
public static void AddCustomerActivity(Context ctx) {
public static void AddCustomerActivity(Context ctx,String customer_id,String source) {
Intent i = new Intent(ctx, AddCustomerActivity.class);
i.putExtra("customer_id",customer_id);
i.putExtra("source",source);
ctx.startActivity(i);
}
public static void StyleActivity(Context ctx) {
Intent i = new Intent(ctx, StyleActivity.class);
ctx.startActivity(i);
}
public static void BudgetActivity(Context ctx) {
Intent i = new Intent(ctx, BudgetActivity.class);
ctx.startActivity(i);
}
}

View File

@@ -0,0 +1,92 @@
package com.fenghoo.seven.main.kehu.activity;
import android.os.Bundle;
import com.fenghoo.seven.JsonUtils;
import com.fenghoo.seven.R;
import com.fenghoo.seven.main.find.adapter.StyleAdapter;
import com.fenghoo.seven.main.find.entity.StyleBean;
import com.fenghoo.seven.main.kehu.Bean.FirstEvent;
import com.fenghoo.seven.main.kehu.Bean.WxuSerinfo;
import com.fenghoo.seven.main.kehu.MoActivity;
import com.fenghoo.seven.okgonet.NetApi;
import com.fenghoo.seven.okgonet.Observer;
import com.fenghoo.seven.widget.TitleBar;
import com.lzy.okgo.model.Response;
import java.util.List;
import androidx.recyclerview.widget.LinearLayoutManager;
import de.greenrobot.event.EventBus;
/**
*
*/
public class StyleActivity extends MoActivity {
private TitleBar mTitleBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTitleBar = (TitleBar) findViewById(R.id.title_bar);
mTitleBar.setTitle("选择风格");
initNormalBack();
}
@Override
public void initAdapter() {
mMarkingFragmentRecyclerView.setLayoutManager(new LinearLayoutManager(StyleActivity.this));
StyleAdapter markingtwoAdapter = new StyleAdapter(StyleActivity.this, null);
getAdpter(markingtwoAdapter);
mMarkingFragmentRecyclerView.setAdapter(markingtwoAdapter);
markingtwoAdapter.operationListenner(new StyleAdapter.OnViewClickListener() {
@Override
public void enterCusDetail(StyleBean.ResultBean.DataBean item) {
String style_id = item.getStyle_id();
String style = item.getStyle();
EventBus.getDefault().post(new FirstEvent(style_id,style));
finish();
}
});
}
@Override
public void requestData() {
new NetApi().style().subscribe(new Observer<Response>() {
@Override
public void onNext(Response response) {
String body = (String) response.body();
StyleBean.ResultBean result = JsonUtils.fromJson(body, StyleBean.class).getResult();
mSwl.setRefreshing(false);
if (result != null && String.valueOf(result.getSuccess()).equals("0")) {
List<StyleBean.ResultBean.DataBean> data = result.getData();
if (data.size() == 0) {
markingtwoAdapter.setEmptyView(notDataView);
return;
}
if (mNextRequestPage == 1) {
setData(true, data);
} else {
setData(false, data);
}
} else {
setData(true, null);
markingtwoAdapter.setEmptyView(notDataView);
mSwl.setRefreshing(false);
}
}
@Override
public void onError(Exception e) {
e.printStackTrace();
markingtwoAdapter.setEmptyView(errorView);
mSwl.setRefreshing(false);
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
}
}

View File

@@ -4,54 +4,111 @@ import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fenghoo.seven.JsonUtils;
import com.fenghoo.seven.R;
import com.fenghoo.seven.main.Fragment.MoFragment;
import com.fenghoo.seven.base.BaseBean;
import com.fenghoo.seven.main.kehu.Bean.FirstEvent;
import com.fenghoo.seven.main.kehu.Bean.LabelBean;
import com.fenghoo.seven.main.kehu.Bean.SecondEvent;
import com.fenghoo.seven.main.kehu.Bean.addCustomerBean;
import com.fenghoo.seven.main.kehu.MobanFragment;
import com.fenghoo.seven.main.kehu.activity.ShowAty;
import com.fenghoo.seven.main.kehu.adapter.AddCusAdapter;
import com.fenghoo.seven.okgonet.NetApi;
import com.fenghoo.seven.okgonet.Observer;
import com.fenghoo.seven.utils.AbImageUtil;
import com.fenghoo.seven.utils.AbStrUtil;
import com.fenghoo.seven.utils.GlideTools;
import com.fenghoo.seven.utils.ImageUtils;
import com.fenghoo.seven.utils.ToastUtils;
import com.fenghoo.seven.utils.checkVersionsUtils.ProfileSpUtils;
import com.fenghoo.seven.widget.CircleImageView;
import com.lzy.okgo.model.Response;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.PicassoEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import de.greenrobot.event.EventBus;
import io.reactivex.disposables.Disposable;
import static android.app.Activity.RESULT_OK;
import top.zibin.luban.CompressionPredicate;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;
/**
* 添加客户
*/
public class AddCusFragment extends AddCusParFragment {
public class AddCusFragment extends MobanFragment implements View.OnClickListener{
private RecyclerView recy_10;
private String selectType="1";
private ImageView imageView;
private CircleImageView imageView;
private static int REQUEST_CODE_CHOOSE = 100;
//调取系统摄像头的请求码
private static final int MY_ADD_CASE_CALL_PHONE = 6;
List<Uri> result;
List<String> resultPath;
private final addCustomerBean addCustomerBean;
private EditText textView0;
private EditText textView4;
private EditText textView6;
private EditText textView8;
private TextView textView12;
private TextView textView14;
private String customer_id;
private String source;
private ArrayList<LabelBean> label=new ArrayList<>();
public AddCusFragment() {
public AddCusFragment(String customer_id,String source) {
super();
this.customer_id=customer_id;
this.source=source;
addCustomerBean = new addCustomerBean();
EventBus.getDefault().register(this);
}
/**
* @description 接收选择的风格id
* @param
* @return
*/
public void onEvent(FirstEvent event) {
if (null != event ) {
String style_id = event.getMsg();
addCustomerBean.setStyle_id(style_id);
textView12.setText(event.getStyle());
}
}
/**
* @description 接收选择的预算
* @param
* @return
*/
public void onEventMainThread(SecondEvent event) {
if (null != event ) {
String budget = event.getMsg();
addCustomerBean.setBudget(budget);
textView14.setText(budget);
}
}
@Override
@@ -66,7 +123,7 @@ public class AddCusFragment extends AddCusParFragment {
private View getHeaderView() {
View view = getLayoutInflater().inflate(R.layout.addcus_head_view, (ViewGroup) mMarkingFragmentRecyclerView.getParent(), false);
imageView = (ImageView) view.findViewById(R.id.imageView);
imageView = (CircleImageView) view.findViewById(R.id.imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -74,11 +131,81 @@ public class AddCusFragment extends AddCusParFragment {
}
});
recy_10 = (RecyclerView) view.findViewById(R.id.recy_10);
ArrayList<LabelBean> label = addData();
label = addData();
setLabel(label);
textView0 = (EditText) view.findViewById(R.id.textView0);
textView4 = (EditText) view.findViewById(R.id.textView4);
textView6 = (EditText) view.findViewById(R.id.textView6);
textView8 = (EditText) view.findViewById(R.id.textView8);
textView12 = (TextView) view.findViewById(R.id.textView12);
textView14 = (TextView) view.findViewById(R.id.textView14);
ConstraintLayout constraintLayout7 = (ConstraintLayout) view.findViewById(R.id.constraintLayout7);
constraintLayout7.setOnClickListener(this);
ConstraintLayout constraintLayout8 = (ConstraintLayout) view.findViewById(R.id.constraintLayout8);
constraintLayout8.setOnClickListener(this);
return view;
}
public void comit(){
addCustomerBean.setName(textView0.getText().toString());
addCustomerBean.setPhone(textView4.getText().toString());
addCustomerBean.setWechat(textView6.getText().toString());
addCustomerBean.setAddress(textView8.getText().toString());
addCustomerBean.setSource(source);
addCustomerBean.setUid(ProfileSpUtils.getInstance().getUserProfie().getData().getUuid());
addCustomerBean.setCustomer_id(customer_id);
for(int i=0;i<label.size();i++){
LabelBean labelBean = label.get(i);
if(labelBean.getIf_sel_del().equals("1")){
addCustomerBean.setDecoration(labelBean.getDecorationid());
}
}
if( AbStrUtil.isEmpty(addCustomerBean.getName())){
ToastUtils.showToast(mContext, "请输入客户姓名");
return;
}
if( AbStrUtil.isEmpty(addCustomerBean.getPhone())){
ToastUtils.showToast(mContext, "请输入客户电话");
return;
}
if( AbStrUtil.isEmpty(addCustomerBean.getWechat())){
ToastUtils.showToast(mContext, "请输入客户微信");
return;
}
if( AbStrUtil.isEmpty(addCustomerBean.getAddress())){
ToastUtils.showToast(mContext, "请输入客户住址");
return;
}
if( AbStrUtil.isEmpty(addCustomerBean.getStyle_id())){
ToastUtils.showToast(mContext, "请选择装修风格");
return;
}
if( AbStrUtil.isEmpty(addCustomerBean.getBudget())){
ToastUtils.showToast(mContext, "请选择装修预算");
return;
}
//网络请求提交数据
new NetApi().addCustomer(addCustomerBean.getUid(),addCustomerBean.getHeadimg(),addCustomerBean.getName(),addCustomerBean.getPhone(),addCustomerBean.getWechat(),addCustomerBean.getAddress(),addCustomerBean.getDecoration(),addCustomerBean.getStyle_id(),addCustomerBean.getBudget(),addCustomerBean.getSource(),addCustomerBean.getCustomer_id()).subscribe(new Observer<Response>() {
@Override
public void onNext(Response response) {
String body = (String) response.body();
BaseBean.ResultBean result = JsonUtils.fromJson(body, BaseBean.class).getResult();
if(result.getSuccess()==0){
getActivity().finish();
}else {
String msg = result.getMsg();
ToastUtils.showToast(mContext, msg);
}
}
@Override
public void onError(Exception e) {
e.printStackTrace();
}
});
}
private ArrayList<LabelBean> addData() {
ArrayList<LabelBean> label = new ArrayList<>();
LabelBean labelBean = new LabelBean();
@@ -222,11 +349,7 @@ public class AddCusFragment extends AddCusParFragment {
@Override
public void requestData() {
}
@Override
public void onDestroy() {
super.onDestroy();
mSwl.setRefreshing(false);
}
@@ -238,6 +361,35 @@ public class AddCusFragment extends AddCusParFragment {
String s = uri.toString();
Log.e("url==",s);
GlideTools.init(mContext).displaypic(imageView, resultPath.get(0), R.mipmap.icon_default_head);
File file = new File(resultPath.get(0));
// 压缩文件
Luban.with(getActivity())
.load(file)
.ignoreBy(100)
.filter(new CompressionPredicate() {
@Override
public boolean apply(String path) {
return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif"));
}
})
.setCompressListener(new OnCompressListener() {
@Override
public void onStart() {
Log.e("测试", "开始");
}
@Override
public void onSuccess(File file) {
//转换成功后的文件
String resultt = AbImageUtil.bitmapToBase64(ImageUtils.getBitmap(file));
addCustomerBean.setHeadimg(resultt);
}
@Override
public void onError(Throwable e) {
Log.e("测试", "失败");
}
}).launch();
// // 图片选择结果回调
// String paymentpaper = "";
// selectList = PictureSelector.obtainMultipleResult(data);
@@ -258,11 +410,26 @@ public class AddCusFragment extends AddCusParFragment {
// sBuffer.append(resultt);
// paymentpaper = sBuffer.toString();
// }
// //引入黑名单的帮助类
// heimingdanHelper = HeimingdanHelper.of(getActivity(), paymentpaper, cameraInfo, "", uid);
// heimingdanHelper.huoqutuianlujing();
// heimingdanHelper.setzhilujing(path);
// //上传头像
// upLoadAvatar(paymentpaper);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.constraintLayout7:
ShowAty.StyleActivity(getActivity());
break;
case R.id.constraintLayout8:
ShowAty.BudgetActivity(getActivity());
break;
}
}
@Override
public void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
}

View File

@@ -1,171 +0,0 @@
package com.fenghoo.seven.main.kehu.ui;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.fenghoo.seven.R;
import com.fenghoo.seven.base.BaseFragment;
import com.fenghoo.seven.main.entity.Savaselect;
import java.util.List;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@SuppressLint("ValidFragment")
public abstract class AddCusParFragment extends BaseFragment {
public static final String ARG_PAGE = "ARG_PAGE";
private boolean IS_LOADED = false;
private static int mSerial = 0;
private boolean isFirst = true;
@SuppressLint("HandlerLeak")
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
Log.e("tag", "IS_LOADED=" + IS_LOADED);
if (!IS_LOADED) {
IS_LOADED = true;
//请求我的客户已流失数据
requesdata();
}
return;
}
};
public Savaselect savaselectbean;
private RelativeLayout rl_top;
private RelativeLayout layTop_left_tv;
public AddCusParFragment() {
}
public BaseQuickAdapter markingtwoAdapter;
public void sendMessage() {
Message message = handler.obtainMessage();
message.sendToTarget();
}
private String uid;
public RecyclerView mMarkingFragmentRecyclerView;
public int mNextRequestPage = 1;
private static final int PAGE_SIZE = 10;
View view;
public View notDataView;
public View errorView;
public TextView mLayTopTitle;
//头部图片(轮播图的高度)
public int mRecyclerHeaderBannerHeight;
//头部的高度
public int mRecyclerHeaderHeight;
private int mTextViewHeight;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeView(view);
}
return view;
}
view = inflater.inflate(R.layout.mobanfragment, container, false);
initView(view);
//设置页和当前页一致时加载,防止预加载
if (isFirst) {
isFirst = false;
sendMessage();
}
return view;
}
private void initView(View mContentView) {
rl_top = (RelativeLayout) view.findViewById(R.id.rl_top);
mLayTopTitle = (TextView) view.findViewById(R.id.layTop_title);
layTop_left_tv = (RelativeLayout) view.findViewById(R.id.layTop_left_tv);
layTop_left_tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().finish();
}
});
mLayTopTitle.setText("信息完善");
Thickening(mLayTopTitle);
mMarkingFragmentRecyclerView = (RecyclerView) view.findViewById(R.id.marking_fragment_recyclerView);
notDataView = getActivity().getLayoutInflater().inflate(R.layout.empty_view, (ViewGroup) mMarkingFragmentRecyclerView.getParent(), false);
notDataView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// refresh();
}
});
errorView = getActivity().getLayoutInflater().inflate(R.layout.error_view, (ViewGroup) mMarkingFragmentRecyclerView.getParent(), false);
errorView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// onRefresh();
}
});
}
public void requesdata() {
initAdapter();
// initRefreshLayout();
// mSwl.setRefreshing(true);
// refresh();
}
public abstract void initAdapter();
public void setData(boolean isRefresh, List data) {
mNextRequestPage++;
final int size = data == null ? 0 : data.size();
if (isRefresh) {
markingtwoAdapter.setNewData(data);
} else {
if (size > 0) {
markingtwoAdapter.addData(data);
}
}
if (size < PAGE_SIZE) {
//第一页如果不够一页就不显示没有更多数据布局
markingtwoAdapter.loadMoreEnd(isRefresh);
} else {
markingtwoAdapter.loadMoreComplete();
}
}
public abstract void requestData();
public void getAdpter(BaseQuickAdapter markingtwoAdapter){
this.markingtwoAdapter=markingtwoAdapter;
}
@Override
public void onDestroy() {
super.onDestroy();
}
}

View File

@@ -432,6 +432,16 @@ public class HttpConstants {
*/
public static String URi_device_AppCustomer_fpOrderInfo = URiBase + "/device/AppCustomer/fpOrderInfo";
/**
* 风格
*/
public static String URi_device_AppCustomer_style = URiBase + "/device/AppCustomer/style";
/**
* 添加客户和完善信息
*/
public static String URi_device_AppCustomer_addCustomer = URiBase + "/device/AppCustomer/addCustomer";
}

View File

@@ -421,4 +421,101 @@ public class NetApi {
}
/**
* style
*/
public Observable<Response> style() {
return new Observable<Response>() {
@Override
public void subscribe(final Observer<Response> observer) {
OkGo.<String>post(HttpConstants.URi_device_AppCustomer_style)
.converter(new StringConvert())//
.cacheMode(CacheMode.NO_CACHE) //无缓存模式 CacheMode.NO_CACHE
.adapt(new ObservableResponse<String>())//
.subscribeOn(Schedulers.io())//
.observeOn(AndroidSchedulers.mainThread())//
.subscribe(new io.reactivex.Observer<Response<String>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
// addDisposable(d);
}
@Override
public void onNext(@NonNull Response<String> response) {
observer.onNext(response);
}
@Override
public void onError(@NonNull Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
}
});
}
};
}
public Observable<Response> addCustomer(final String uid, final String headimg, final String name, final String phone, final String wechat, final String address, final String decoration, final String style_id, final String budget, final String source, final String customer_id) {
return new Observable<Response>() {
@Override
public void subscribe(final Observer<Response> observer) {
OkGo.<String>post(HttpConstants.URi_device_AppCustomer_addCustomer)
.params("uid", uid)
.params("headimg", headimg)
.params("name", name)
.params("phone", phone)
.params("wechat", wechat)
.params("address", address)
.params("decoration", decoration)
.params("style_id", style_id)
.params("budget", budget)
.params("source", source)
.params("customer_id", customer_id)
.converter(new StringConvert())//
.cacheMode(CacheMode.NO_CACHE) //无缓存模式 CacheMode.NO_CACHE
.adapt(new ObservableResponse<String>())//
.subscribeOn(Schedulers.io())//
.observeOn(AndroidSchedulers.mainThread())//
.subscribe(new io.reactivex.Observer<Response<String>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
// addDisposable(d);
}
@Override
public void onNext(@NonNull Response<String> response) {
observer.onNext(response);
}
@Override
public void onError(@NonNull Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
}
});
}
};
}
}

View File

@@ -0,0 +1,750 @@
/*
*
*/
package com.fenghoo.seven.utils;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Base64;
import android.view.View;
import android.view.View.MeasureSpec;
import android.widget.ImageView;
import com.fenghoo.seven.R;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
// TODO: Auto-generated Javadoc
/**
* 描述:图片处理类.
*
*/
public class AbImageUtil {
/**
* The tag.
*/
private static String TAG = "AbImageUtil";
private static OnImageUtilsListener onImageUtilsListener;
public void setOnImageUtilsListener(OnImageUtilsListener listener) {
onImageUtilsListener = listener;
}
public interface OnImageUtilsListener {
void backBitmap(Bitmap bt);
}
/**
* 描述:缩放图片.压缩
*
* @param file File对象
* @param newWidth 新图片的宽
* @param newHeight 新图片的高
* @return Bitmap 新图片
*/
@SuppressWarnings("resource")
public static Bitmap scaleImg(File file, int newWidth, int newHeight) {
Bitmap resizeBmp = null;
try {
BitmapFactory.Options opts = new BitmapFactory.Options();
// 设置为true,decodeFile先不创建内存 只获取一些解码边界信息即图片大小信息
opts.inJustDecodeBounds = true;
// BitmapFactory.decodeFile(file.getPath(), opts);
BitmapFactory.decodeFileDescriptor(new FileInputStream(file.getPath()).getFD(), null, opts);
if (newWidth != -1 && newHeight != -1) {
// inSampleSize=2表示图片宽高都为原来的二分之一即图片为原来的四分之一
// 缩放可以将像素点打薄
int srcWidth = opts.outWidth; // 获取图片的原始宽度
int srcHeight = opts.outHeight;// 获取图片原始高度
int destWidth = 0;
int destHeight = 0;
// 缩放的比例
double ratio = 0.0;
if (srcWidth < newWidth || srcHeight < newHeight) {
ratio = 0.0;
destWidth = srcWidth;
destHeight = srcHeight;
// 按比例计算缩放后的图片大小
} else if (srcWidth > srcHeight) {
ratio = (double) srcWidth / newWidth;
destWidth = newWidth;
destHeight = (int) (srcHeight / ratio);
} else {
ratio = (double) srcHeight / newHeight;
destHeight = newHeight;
destWidth = (int) (srcWidth / ratio);
}
// 缩放的比例缩放是很难按准备的比例进行缩放的目前我只发现只能通过inSampleSize来进行缩放其值表明缩放的倍数SDK中建议其值是2的指数值
opts.inSampleSize = (int) ratio + 1;
// 设置大小
opts.outHeight = destHeight;
opts.outWidth = destWidth;
} else {
opts.inSampleSize = 1;
}
// 创建内存
opts.inJustDecodeBounds = false;
// 使图片不抖动
opts.inDither = false;
resizeBmp = BitmapFactory.decodeFileDescriptor(new FileInputStream(file.getPath()).getFD(), null, opts);
// resizeBmp = BitmapFactory.decodeFile(file.getPath(), opts);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return resizeBmp;
}
/**
* 描述:缩放图片,不压缩的缩放.
*
* @param bitmap the bitmap
* @param newWidth 新图片的宽
* @param newHeight 新图片的高
* @return Bitmap 新图片
*/
public static Bitmap scaleImg(Bitmap bitmap, int newWidth, int newHeight) {
if (bitmap == null) {
return null;
}
if (newHeight <= 0 || newWidth <= 0) {
return bitmap;
}
// 获得图片的宽高
int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width <= 0 || height <= 0) {
return null;
}
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newBm = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
return newBm;
}
/**
* 描述:缩放图片.
*
* @param bitmap the bitmap
* @param scale 比例
* @return Bitmap 新图片
*/
public static Bitmap scaleImg(Bitmap bitmap, float scale) {
Bitmap resizeBmp = null;
try {
// 获取Bitmap资源的宽和高
int bmpW = bitmap.getWidth();
int bmpH = bitmap.getHeight();
// 注意这个Matirx是android.graphics底下的那个
Matrix mt = new Matrix();
// 设置缩放系数分别为原来的0.8和0.8
mt.postScale(scale, scale);
resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, mt, true);
} catch (Exception e) {
e.printStackTrace();
}
return resizeBmp;
}
/**
* 描述:裁剪图片.
*
* @param file File对象
* @param newWidth 新图片的宽
* @param newHeight 新图片的高
* @return Bitmap 新图片
*/
public static Bitmap cutImg(File file, int newWidth, int newHeight) {
Bitmap newBitmap = null;
try {
BitmapFactory.Options opts = new BitmapFactory.Options();
// 设置为true,decodeFile先不创建内存 只获取一些解码边界信息即图片大小信息
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(new FileInputStream(file.getPath()).getFD(), null, opts);
// BitmapFactory.decodeFile(file.getPath(), opts);
if (newWidth != -1 && newHeight != -1) {
// inSampleSize=2表示图片宽高都为原来的二分之一即图片为原来的四分之一
// 缩放可以将像素点打薄,裁剪前将图片缩放一些
int srcWidth = opts.outWidth; // 获取图片的原始宽度
int srcHeight = opts.outHeight;// 获取图片原始高度
int destWidth = 0;
int destHeight = 0;
int cutSrcWidth = newWidth * 2;
int cutSrcHeight = newHeight * 2;
// 缩放的比例
double ratio = 0.0;
if (srcWidth < cutSrcWidth || srcHeight < cutSrcHeight) {
ratio = 0.0;
destWidth = srcWidth;
destHeight = srcHeight;
// 按比例计算缩放后的图片大小
} else if (srcWidth > srcHeight) {
ratio = (double) srcWidth / cutSrcWidth;
destWidth = cutSrcWidth;
destHeight = (int) (srcHeight / ratio);
} else {
ratio = (double) srcHeight / cutSrcHeight;
destHeight = cutSrcHeight;
destWidth = (int) (srcWidth / ratio);
}
// 缩放的比例缩放是很难按准备的比例进行缩放的目前我只发现只能通过inSampleSize来进行缩放其值表明缩放的倍数SDK中建议其值是2的指数值
opts.inSampleSize = (int) ratio + 1;
// 设置大小
opts.outHeight = destHeight;
opts.outWidth = destWidth;
} else {
opts.inSampleSize = 1;
}
// 创建内存
opts.inJustDecodeBounds = false;
// 使图片不抖动
opts.inDither = false;
// Bitmap resizeBmp = BitmapFactory.decodeFile(file.getPath(), opts);
Bitmap resizeBmp = BitmapFactory.decodeFileDescriptor(new FileInputStream(file.getPath()).getFD(), null, opts);
if (resizeBmp != null) {
newBitmap = cutImg(resizeBmp, newWidth, newHeight);
}
if (newBitmap != null) {
return newBitmap;
} else {
return resizeBmp;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
return newBitmap;
} catch (IOException e) {
e.printStackTrace();
return newBitmap;
}
}
/**
* 描述:裁剪图片.
*
* @param bitmap the bitmap
* @param newWidth 新图片的宽
* @param newHeight 新图片的高
* @return Bitmap 新图片
*/
public static Bitmap cutImg(Bitmap bitmap, int newWidth, int newHeight) {
if (bitmap == null) {
return null;
}
Bitmap newBitmap = null;
if (newHeight <= 0 || newWidth <= 0) {
return bitmap;
}
int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width <= 0 || height <= 0) {
return null;
}
int offsetX = 0;
int offsetY = 0;
if (width > newWidth) {
offsetX = (width - newWidth) / 2;
}
if (height > newHeight) {
offsetY = (height - newHeight) / 2;
}
newBitmap = Bitmap.createBitmap(bitmap, offsetX, offsetY, newWidth, newHeight);
return newBitmap;
}
/**
* Drawable转Bitmap.
*
* @param drawable 要转化的Drawable
* @return Bitmap
*/
public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Config.ARGB_8888 : Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
/**
* Drawable对象转换Bitmap对象.
*
* @param bitmap 要转化的Bitmap对象
* @return Drawable 转化完成的Drawable对象
*/
@SuppressWarnings("deprecation")
public static Drawable bitmapToDrawable(Bitmap bitmap) {
BitmapDrawable mBitmapDrawable = null;
try {
if (bitmap == null) {
return null;
}
mBitmapDrawable = new BitmapDrawable(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
return mBitmapDrawable;
}
/**
* 将Bitmap转换为byte[].
*
* @param bitmap the bitmap
* @param mCompressFormat 图片格式 Bitmap.CompressFormat.JPEG,CompressFormat.PNG
* @param needRecycle 是否需要回收
* @return byte[] 图片的byte[]
*/
public static byte[] bitmap2Bytes(Bitmap bitmap, Bitmap.CompressFormat mCompressFormat, final boolean needRecycle) {
byte[] result = null;
ByteArrayOutputStream output = null;
try {
output = new ByteArrayOutputStream();
bitmap.compress(mCompressFormat, 100, output);
result = output.toByteArray();
if (needRecycle) {
bitmap.recycle();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return result;
}
/**
* 描述将byte[]转换为Bitmap.
*
* @param b 图片格式的byte[]数组
* @return bitmap 得到的Bitmap
*/
public static Bitmap bytes2Bimap(byte[] b) {
Bitmap bitmap = null;
try {
if (b.length != 0) {
bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
}
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
/**
* 将ImageView转换为Bitmap.
*
* @param view 要转换为bitmap的View
* @return byte[] 图片的byte[]
*/
public static Bitmap imageView2Bitmap(ImageView view) {
Bitmap bitmap = null;
try {
bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
/**
* 将View转换为Drawable.需要最上层布局为Linearlayout
*
* @param view 要转换为Drawable的View
* @return BitmapDrawable Drawable
*/
@SuppressWarnings("deprecation")
public static Drawable view2Drawable(View view) {
BitmapDrawable mBitmapDrawable = null;
try {
Bitmap newbmp = view2Bitmap(view);
if (newbmp != null) {
mBitmapDrawable = new BitmapDrawable(newbmp);
}
} catch (Exception e) {
e.printStackTrace();
}
return mBitmapDrawable;
}
/**
* 将View转换为Bitmap.需要最上层布局为Linearlayout
*
* @param view 要转换为bitmap的View
* @return byte[] 图片的byte[]
*/
public static Bitmap view2Bitmap(View view) {
Bitmap bitmap = null;
try {
if (view != null) {
view.setDrawingCacheEnabled(true);
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
bitmap = view.getDrawingCache();
}
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
/**
* 将View转换为byte[].
*
* @param view 要转换为byte[]的View
* @param compressFormat the compress format
* @return byte[] View图片的byte[]
*/
public static byte[] view2Bytes(View view, Bitmap.CompressFormat compressFormat) {
byte[] b = null;
try {
Bitmap bitmap = AbImageUtil.view2Bitmap(view);
b = AbImageUtil.bitmap2Bytes(bitmap, compressFormat, true);
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
/**
* 描述旋转Bitmap为一定的角度.
*
* @param bitmap the bitmap
* @param degrees the degrees
* @return the bitmap
*/
public static Bitmap rotateBitmap(Bitmap bitmap, float degrees) {
Bitmap mBitmap = null;
try {
Matrix m = new Matrix();
m.setRotate(degrees % 360);
mBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false);
} catch (Exception e) {
e.printStackTrace();
}
return mBitmap;
}
/**
* 描述旋转Bitmap为一定的角度并四周暗化处理.
*
* @param bitmap the bitmap
* @param degrees the degrees
* @return the bitmap
*/
public static Bitmap rotateBitmapTranslate(Bitmap bitmap, float degrees) {
Bitmap mBitmap = null;
int width;
int height;
try {
Matrix matrix = new Matrix();
if ((degrees / 90) % 2 != 0) {
width = bitmap.getWidth();
height = bitmap.getHeight();
} else {
width = bitmap.getHeight();
height = bitmap.getWidth();
}
int cx = width / 2;
int cy = height / 2;
matrix.preTranslate(-cx, -cy);
matrix.postRotate(degrees);
matrix.postTranslate(cx, cy);
} catch (Exception e) {
e.printStackTrace();
}
return mBitmap;
}
/**
* 转换图片转换成圆形.
*
* @param bitmap 传入Bitmap对象
* @return the bitmap
*/
public static Bitmap toRoundBitmap(Bitmap bitmap) {
if (bitmap == null) {
return null;
}
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float roundPx;
float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
if (width <= height) {
roundPx = width / 2;
top = 0;
bottom = width;
left = 0;
right = width;
height = width;
dst_left = 0;
dst_top = 0;
dst_right = width;
dst_bottom = width;
} else {
roundPx = height / 2;
float clip = (width - height) / 2;
left = clip;
right = width - clip;
top = 0;
bottom = height;
width = height;
dst_left = 0;
dst_top = 0;
dst_right = height;
dst_bottom = height;
}
Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
final RectF rectF = new RectF(dst);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, src, dst, paint);
return output;
}
public static byte[] imagePathToByte(String path) {
byte[] data = null;
FileInputStream input = null;
try {
input = new FileInputStream(new File(path));
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int numBytesRead = 0;
while ((numBytesRead = input.read(buf)) != -1) {
output.write(buf, 0, numBytesRead);
}
data = output.toByteArray();
output.close();
input.close();
} catch (FileNotFoundException ex1) {
ex1.printStackTrace();
} catch (IOException ex1) {
ex1.printStackTrace();
}
return data;
}
/**
* @param bitmap 原图
* @param edgeLength 希望得到的正方形部分的边长
* @return 缩放截取正中部分后的位图。
*/
public static Bitmap centerSquareScaleBitmap(Bitmap bitmap, int edgeLength) {
if (null == bitmap || edgeLength <= 0) {
return null;
}
Bitmap result = bitmap;
int widthOrg = bitmap.getWidth();
int heightOrg = bitmap.getHeight();
if (widthOrg > edgeLength && heightOrg > edgeLength) {
// 压缩到一个最小长度是edgeLength的bitmap
int longerEdge = edgeLength * Math.max(widthOrg, heightOrg) / Math.min(widthOrg, heightOrg);
int scaledWidth = widthOrg > heightOrg ? longerEdge : edgeLength;
int scaledHeight = widthOrg > heightOrg ? edgeLength : longerEdge;
Bitmap scaledBitmap;
try {
scaledBitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, true);
} catch (Exception e) {
return null;
}
// 从图中截取正中间的正方形部分。
int xTopLeft = (scaledWidth - edgeLength) / 2;
int yTopLeft = (scaledHeight - edgeLength) / 2;
try {
result = Bitmap.createBitmap(scaledBitmap, xTopLeft, yTopLeft, edgeLength, edgeLength);
scaledBitmap.recycle();
} catch (Exception e) {
return null;
}
}
return result;
}
/**
* @param bitmap 原图
* @param edgeLength 希望得到的正方形部分的边长
* @return 缩放截取上面部分后的位图。
*/
public static Bitmap topSquareScaleBitmap(Bitmap bitmap, int edgeLength) {
if (null == bitmap || edgeLength <= 0) {
return null;
}
Bitmap result = bitmap;
int widthOrg = bitmap.getWidth();
int heightOrg = bitmap.getHeight();
if (widthOrg > edgeLength && heightOrg > edgeLength) {
// 压缩到一个最小长度是edgeLength的bitmap
int longerEdge = edgeLength * Math.max(widthOrg, heightOrg) / Math.min(widthOrg, heightOrg);
int scaledWidth = widthOrg > heightOrg ? longerEdge : edgeLength;
int scaledHeight = widthOrg > heightOrg ? edgeLength : longerEdge;
Bitmap scaledBitmap;
try {
scaledBitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, true);
} catch (Exception e) {
return null;
}
// 从图中截取正中间的正方形部分。
int xTopLeft = (scaledWidth - edgeLength) / 2;
// int yTopLeft = (scaledHeight - edgeLength) / 2;
int yTopLeft = 0;
try {
result = Bitmap.createBitmap(scaledBitmap, xTopLeft, yTopLeft, edgeLength, edgeLength);
scaledBitmap.recycle();
} catch (Exception e) {
return null;
}
}
return result;
}
/**
* 转换Resources图片转换成Bitmap.
*/
public static Bitmap ResourcesToBitmap(Resources resId) {
Bitmap bmp = BitmapFactory.decodeResource(resId, R.mipmap.ic_launcher);
return bmp;
}
/**
* bitmap转为base64
* @param bitmap
* @return
*/
public static String bitmapToBase64(Bitmap bitmap) {
String result = null;
ByteArrayOutputStream baos = null;
try {
if (bitmap != null) {
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
baos.flush();
baos.close();
byte[] bitmapBytes = baos.toByteArray();
result ="data:image/jpg;base64," + Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (baos != null) {
baos.flush();
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
/**
* base64转为bitmap
* @param base64Data
* @return
*/
public static Bitmap base64ToBitmap(String base64Data) {
byte[] bytes = Base64.decode(base64Data, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
/**
* bitmap转成string
*
* @param bitmap
* @return
*/
public static String bitmapToString(Bitmap bitmap)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();// outputstream
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] appicon = baos.toByteArray();// 转为byte数组
return Base64.encodeToString(appicon, Base64.DEFAULT);
}
/**
* string转成bitmap
*
* @param st
*/
public static Bitmap stringToBitmap(String st)
{
Bitmap bitmap = null;
try
{
byte[] bitmapArray;
bitmapArray = Base64.decode(st, Base64.DEFAULT);
bitmap =
BitmapFactory.decodeByteArray(bitmapArray, 0,
bitmapArray.length);
return bitmap;
}
catch (Exception e)
{
return null;
}
}
}

View File

@@ -0,0 +1,54 @@
package com.fenghoo.seven.utils;
import java.io.Closeable;
import java.io.IOException;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/10/09
* desc : 关闭相关工具类
* </pre>
*/
public final class CloseUtils {
private CloseUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* 关闭IO
*
* @param closeables closeables
*/
public static void closeIO(final Closeable... closeables) {
if (closeables == null) return;
for (Closeable closeable : closeables) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 安静关闭IO
*
* @param closeables closeables
*/
public static void closeIOQuietly(final Closeable... closeables) {
if (closeables == null) return;
for (Closeable closeable : closeables) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException ignored) {
}
}
}
}
}

View File

@@ -0,0 +1,674 @@
package com.fenghoo.seven.utils;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2017/06/22
* desc : 文件读写相关工具类
* </pre>
*/
public final class FileIOUtils {
private FileIOUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
private static final String LINE_SEP = System.getProperty("line.separator");
private static int sBufferSize = 8192;
/**
* 将输入流写入文件
*
* @param filePath 路径
* @param is 输入流
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(final String filePath, final InputStream is) {
return writeFileFromIS(getFileByPath(filePath), is, false);
}
/**
* 将输入流写入文件
*
* @param filePath 路径
* @param is 输入流
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(final String filePath, final InputStream is, final boolean append) {
return writeFileFromIS(getFileByPath(filePath), is, append);
}
/**
* 将输入流写入文件
*
* @param file 文件
* @param is 输入流
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(final File file, final InputStream is) {
return writeFileFromIS(file, is, false);
}
/**
* 将输入流写入文件
*
* @param file 文件
* @param is 输入流
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(final File file, final InputStream is, final boolean append) {
if (!createOrExistsFile(file) || is == null) return false;
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(file, append));
byte data[] = new byte[sBufferSize];
int len;
while ((len = is.read(data, 0, sBufferSize)) != -1) {
os.write(data, 0, len);
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
CloseUtils.closeIO(is, os);
}
}
/**
* 将字节数组写入文件
*
* @param filePath 文件路径
* @param bytes 字节数组
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByStream(final String filePath, final byte[] bytes) {
return writeFileFromBytesByStream(getFileByPath(filePath), bytes, false);
}
/**
* 将字节数组写入文件
*
* @param filePath 文件路径
* @param bytes 字节数组
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByStream(final String filePath, final byte[] bytes, final boolean append) {
return writeFileFromBytesByStream(getFileByPath(filePath), bytes, append);
}
/**
* 将字节数组写入文件
*
* @param file 文件
* @param bytes 字节数组
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByStream(final File file, final byte[] bytes) {
return writeFileFromBytesByStream(file, bytes, false);
}
/**
* 将字节数组写入文件
*
* @param file 文件
* @param bytes 字节数组
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByStream(final File file, final byte[] bytes, final boolean append) {
if (bytes == null || !createOrExistsFile(file)) return false;
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(file, append));
bos.write(bytes);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
CloseUtils.closeIO(bos);
}
}
/**
* 将字节数组写入文件
*
* @param filePath 文件路径
* @param bytes 字节数组
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByChannel(final String filePath, final byte[] bytes, final boolean isForce) {
return writeFileFromBytesByChannel(getFileByPath(filePath), bytes, false, isForce);
}
/**
* 将字节数组写入文件
*
* @param filePath 文件路径
* @param bytes 字节数组
* @param append 是否追加在文件末
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByChannel(final String filePath, final byte[] bytes, final boolean append, final boolean isForce) {
return writeFileFromBytesByChannel(getFileByPath(filePath), bytes, append, isForce);
}
/**
* 将字节数组写入文件
*
* @param file 文件
* @param bytes 字节数组
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByChannel(final File file, final byte[] bytes, final boolean isForce) {
return writeFileFromBytesByChannel(file, bytes, false, isForce);
}
/**
* 将字节数组写入文件
*
* @param file 文件
* @param bytes 字节数组
* @param append 是否追加在文件末
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByChannel(final File file, final byte[] bytes, final boolean append, final boolean isForce) {
if (bytes == null) return false;
FileChannel fc = null;
try {
fc = new FileOutputStream(file, append).getChannel();
fc.position(fc.size());
fc.write(ByteBuffer.wrap(bytes));
if (isForce) fc.force(true);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
CloseUtils.closeIO(fc);
}
}
/**
* 将字节数组写入文件
*
* @param filePath 文件路径
* @param bytes 字节数组
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByMap(final String filePath, final byte[] bytes, final boolean isForce) {
return writeFileFromBytesByMap(filePath, bytes, false, isForce);
}
/**
* 将字节数组写入文件
*
* @param filePath 文件路径
* @param bytes 字节数组
* @param append 是否追加在文件末
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByMap(final String filePath, final byte[] bytes, final boolean append, final boolean isForce) {
return writeFileFromBytesByMap(getFileByPath(filePath), bytes, append, isForce);
}
/**
* 将字节数组写入文件
*
* @param file 文件
* @param bytes 字节数组
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByMap(final File file, final byte[] bytes, final boolean isForce) {
return writeFileFromBytesByMap(file, bytes, false, isForce);
}
/**
* 将字节数组写入文件
*
* @param file 文件
* @param bytes 字节数组
* @param append 是否追加在文件末
* @param isForce 是否写入文件
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromBytesByMap(final File file, final byte[] bytes, final boolean append, final boolean isForce) {
if (bytes == null || !createOrExistsFile(file)) return false;
FileChannel fc = null;
try {
fc = new FileOutputStream(file, append).getChannel();
MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, fc.size(), bytes.length);
mbb.put(bytes);
if (isForce) mbb.force();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
CloseUtils.closeIO(fc);
}
}
/**
* 将字符串写入文件
*
* @param filePath 文件路径
* @param content 写入内容
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(final String filePath, final String content) {
return writeFileFromString(getFileByPath(filePath), content, false);
}
/**
* 将字符串写入文件
*
* @param filePath 文件路径
* @param content 写入内容
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(final String filePath, final String content, final boolean append) {
return writeFileFromString(getFileByPath(filePath), content, append);
}
/**
* 将字符串写入文件
*
* @param file 文件
* @param content 写入内容
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(final File file, final String content) {
return writeFileFromString(file, content, false);
}
/**
* 将字符串写入文件
*
* @param file 文件
* @param content 写入内容
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(final File file, final String content, final boolean append) {
if (file == null || content == null) return false;
if (!createOrExistsFile(file)) return false;
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(file, append));
bw.write(content);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
CloseUtils.closeIO(bw);
}
}
///////////////////////////////////////////////////////////////////////////
// the divide line of write and read
///////////////////////////////////////////////////////////////////////////
/**
* 读取文件到字符串链表中
*
* @param filePath 文件路径
* @return 字符串链表中
*/
public static List<String> readFile2List(final String filePath) {
return readFile2List(getFileByPath(filePath), null);
}
/**
* 读取文件到字符串链表中
*
* @param filePath 文件路径
* @param charsetName 编码格式
* @return 字符串链表中
*/
public static List<String> readFile2List(final String filePath, final String charsetName) {
return readFile2List(getFileByPath(filePath), charsetName);
}
/**
* 读取文件到字符串链表中
*
* @param file 文件
* @return 字符串链表中
*/
public static List<String> readFile2List(final File file) {
return readFile2List(file, 0, 0x7FFFFFFF, null);
}
/**
* 读取文件到字符串链表中
*
* @param file 文件
* @param charsetName 编码格式
* @return 字符串链表中
*/
public static List<String> readFile2List(final File file, final String charsetName) {
return readFile2List(file, 0, 0x7FFFFFFF, charsetName);
}
/**
* 读取文件到字符串链表中
*
* @param filePath 文件路径
* @param st 需要读取的开始行数
* @param end 需要读取的结束行数
* @return 字符串链表中
*/
public static List<String> readFile2List(final String filePath, final int st, final int end) {
return readFile2List(getFileByPath(filePath), st, end, null);
}
/**
* 读取文件到字符串链表中
*
* @param filePath 文件路径
* @param st 需要读取的开始行数
* @param end 需要读取的结束行数
* @param charsetName 编码格式
* @return 字符串链表中
*/
public static List<String> readFile2List(final String filePath, final int st, final int end, final String charsetName) {
return readFile2List(getFileByPath(filePath), st, end, charsetName);
}
/**
* 读取文件到字符串链表中
*
* @param file 文件
* @param st 需要读取的开始行数
* @param end 需要读取的结束行数
* @return 字符串链表中
*/
public static List<String> readFile2List(final File file, final int st, final int end) {
return readFile2List(file, st, end, null);
}
/**
* 读取文件到字符串链表中
*
* @param file 文件
* @param st 需要读取的开始行数
* @param end 需要读取的结束行数
* @param charsetName 编码格式
* @return 字符串链表中
*/
public static List<String> readFile2List(final File file, final int st, final int end, final String charsetName) {
if (!isFileExists(file)) return null;
if (st > end) return null;
BufferedReader reader = null;
try {
String line;
int curLine = 1;
List<String> list = new ArrayList<>();
if (isSpace(charsetName)) {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
} else {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
}
while ((line = reader.readLine()) != null) {
if (curLine > end) break;
if (st <= curLine && curLine <= end) list.add(line);
++curLine;
}
return list;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
CloseUtils.closeIO(reader);
}
}
/**
* 读取文件到字符串中
*
* @param filePath 文件路径
* @return 字符串
*/
public static String readFile2String(final String filePath) {
return readFile2String(getFileByPath(filePath), null);
}
/**
* 读取文件到字符串中
*
* @param filePath 文件路径
* @param charsetName 编码格式
* @return 字符串
*/
public static String readFile2String(final String filePath, final String charsetName) {
return readFile2String(getFileByPath(filePath), charsetName);
}
/**
* 读取文件到字符串中
*
* @param file 文件
* @return 字符串
*/
public static String readFile2String(final File file) {
return readFile2String(file, null);
}
/**
* 读取文件到字符串中
*
* @param file 文件
* @param charsetName 编码格式
* @return 字符串
*/
public static String readFile2String(final File file, final String charsetName) {
if (!isFileExists(file)) return null;
BufferedReader reader = null;
try {
StringBuilder sb = new StringBuilder();
if (isSpace(charsetName)) {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
} else {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
}
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append(LINE_SEP);
}
// delete the last line separator
return sb.delete(sb.length() - LINE_SEP.length(), sb.length()).toString();
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
CloseUtils.closeIO(reader);
}
}
/**
* 读取文件到字节数组中
*
* @param filePath 文件路径
* @return 字符数组
*/
public static byte[] readFile2BytesByStream(final String filePath) {
return readFile2BytesByStream(getFileByPath(filePath));
}
/**
* 读取文件到字节数组中
*
* @param file 文件
* @return 字符数组
*/
public static byte[] readFile2BytesByStream(final File file) {
if (!isFileExists(file)) return null;
FileInputStream fis = null;
ByteArrayOutputStream os = null;
try {
fis = new FileInputStream(file);
os = new ByteArrayOutputStream();
byte[] b = new byte[sBufferSize];
int len;
while ((len = fis.read(b, 0, sBufferSize)) != -1) {
os.write(b, 0, len);
}
return os.toByteArray();
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
CloseUtils.closeIO(fis, os);
}
}
/**
* 读取文件到字节数组中
*
* @param filePath 文件路径
* @return 字符数组
*/
public static byte[] readFile2BytesByChannel(final String filePath) {
return readFile2BytesByChannel(getFileByPath(filePath));
}
/**
* 读取文件到字节数组中
*
* @param file 文件
* @return 字符数组
*/
public static byte[] readFile2BytesByChannel(final File file) {
if (!isFileExists(file)) return null;
FileChannel fc = null;
try {
fc = new RandomAccessFile(file, "r").getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate((int) fc.size());
while (true) {
if (!((fc.read(byteBuffer)) > 0)) break;
}
return byteBuffer.array();
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
CloseUtils.closeIO(fc);
}
}
/**
* 读取文件到字节数组中
*
* @param filePath 文件路径
* @return 字符数组
*/
public static byte[] readFile2BytesByMap(final String filePath) {
return readFile2BytesByMap(getFileByPath(filePath));
}
/**
* 读取文件到字节数组中
*
* @param file 文件
* @return 字符数组
*/
public static byte[] readFile2BytesByMap(final File file) {
if (!isFileExists(file)) return null;
FileChannel fc = null;
try {
fc = new RandomAccessFile(file, "r").getChannel();
int size = (int) fc.size();
MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, size).load();
byte[] result = new byte[size];
mbb.get(result, 0, size);
return result;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
CloseUtils.closeIO(fc);
}
}
/**
* 设置缓冲区尺寸
*
* @param bufferSize 缓冲区大小
*/
public static void setBufferSize(final int bufferSize) {
sBufferSize = bufferSize;
}
private static File getFileByPath(final String filePath) {
return isSpace(filePath) ? null : new File(filePath);
}
private static boolean createOrExistsFile(final String filePath) {
return createOrExistsFile(getFileByPath(filePath));
}
private static boolean createOrExistsFile(final File file) {
if (file == null) return false;
if (file.exists()) return file.isFile();
if (!createOrExistsDir(file.getParentFile())) return false;
try {
return file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
private static boolean createOrExistsDir(final File file) {
return file != null && (file.exists() ? file.isDirectory() : file.mkdirs());
}
private static boolean isFileExists(final File file) {
return file != null && file.exists();
}
private static boolean isSpace(final String s) {
if (s == null) return true;
for (int i = 0, len = s.length(); i < len; ++i) {
if (!Character.isWhitespace(s.charAt(i))) {
return false;
}
}
return true;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,192 @@
package com.fenghoo.seven.utils;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import java.io.ByteArrayInputStream;
import androidx.annotation.NonNull;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 16/12/08
* desc : Utils初始化相关
* </pre>
*/
public final class Utils {
@SuppressLint("StaticFieldLeak")
private static Context context;
private Utils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* 初始化工具类
*
* @param context 上下文
*/
public static void init(@NonNull final Context context) {
Utils.context = context.getApplicationContext();
}
/**
* 获取ApplicationContext
*
* @return ApplicationContext
*/
public static Context getContext() {
if (context != null) return context;
throw new NullPointerException("u should init first");
}
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale);
}
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale);
}
public static int getVisiblePercent(View pView) {
if (pView != null && pView.isShown()) {
DisplayMetrics displayMetrics = pView.getContext().getResources().getDisplayMetrics();
int displayWidth = displayMetrics.widthPixels;
Rect rect = new Rect();
pView.getGlobalVisibleRect(rect);
if ((rect.top > 0) && (rect.left < displayWidth)) {
double areaVisible = rect.width() * rect.height();
double areaTotal = pView.getWidth() * pView.getHeight();
return (int) ((areaVisible / areaTotal) * 100);
} else {
return -1;
}
}
return -1;
}
//is wifi connected
public static boolean isWifiConnected(Context context) {
if (context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_WIFI_STATE)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
return false;
}
/**
* 获取对应应用的版本号
*
* @param context
* @return
*/
public static String getAppVersion(Context context) {
String version = "1.0.0"; //默认1.0.0版本
PackageManager manager = context.getPackageManager();
try {
PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
version = info.versionName;
} catch (Exception e) {
}
return version;
}
public static DisplayMetrics getDisplayMetrics(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
if (windowManager == null) {
return displayMetrics;
}
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics;
}
public static BitmapDrawable decodeImage(String base64drawable) {
byte[] rawImageData = Base64.decode(base64drawable, 0);
return new BitmapDrawable(null, new ByteArrayInputStream(rawImageData));
}
public static boolean isPad(Context context) {
//如果能打电话那可能是平板或手机,再根据配置判断
if (canTelephone(context)) {
//能打电话可能是手机也可能是平板
return (context.getResources().getConfiguration().
screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
} else {
return true; //不能打电话一定是平板
}
}
private static boolean canTelephone(Context context) {
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
return (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) ? false : true;
}
public static boolean containString(String source, String destation) {
if (source.equals("") || destation.equals("")) {
return false;
}
if (source.contains(destation)) {
return true;
}
return false;
}
/**
* 获取view的屏幕属性
*
* @return
*/
public static final String VIEW_INFO_EXTRA = "view_into_extra";
public static final String PROPNAME_SCREENLOCATION_LEFT = "propname_sreenlocation_left";
public static final String PROPNAME_SCREENLOCATION_TOP = "propname_sreenlocation_top";
public static final String PROPNAME_WIDTH = "propname_width";
public static final String PROPNAME_HEIGHT = "propname_height";
public static Bundle getViewProperty(View view) {
Bundle bundle = new Bundle();
int[] screenLocation = new int[2];
view.getLocationOnScreen(screenLocation); //获取view在整个屏幕中的位置
bundle.putInt(PROPNAME_SCREENLOCATION_LEFT, screenLocation[0]);
bundle.putInt(PROPNAME_SCREENLOCATION_TOP, screenLocation[1]);
bundle.putInt(PROPNAME_WIDTH, view.getWidth());
bundle.putInt(PROPNAME_HEIGHT, view.getHeight());
Log.e("Utils", "Left: " + screenLocation[0] + " Top: " + screenLocation[1]
+ " Width: " + view.getWidth() + " Height: " + view.getHeight());
return bundle;
}
}