From a907f710ada3c0976f4e493a43a26d40eee57ebe Mon Sep 17 00:00:00 2001 From: TommyLemon <1184482681@qq.com> Date: Sun, 29 Oct 2017 18:35:55 +0800 Subject: [PATCH] =?UTF-8?q?Client:=E5=90=8C=E6=AD=A5adt=E7=89=88=E8=87=B3s?= =?UTF-8?q?tudio=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/zuo/biao/apijson/StringUtil.java | 22 ++++-- .../zuo/biao/library/util/SettingUtil.java | 6 +- .../activity_fragment/MomentListActivity.java | 19 ++++- .../activity_fragment/MomentListFragment.java | 72 +++++++++++++++---- .../activity_fragment/PasswordActivity.java | 24 ++++--- .../activity_fragment/UserListFragment.java | 12 ++-- .../apijson/demo/client/model/Verify.java | 30 ++------ .../apijson/demo/client/util/HttpRequest.java | 39 ++++++++-- .../apijson/demo/server/model/Verify.java | 65 ++++++++--------- .../java/zuo/biao/apijson/StringUtil.java | 22 ++++-- .../java/apijson/demo/ui/RequestActivity.java | 2 +- 11 files changed, 200 insertions(+), 113 deletions(-) diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java index 205d6436f..b219b430a 100644 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java @@ -737,11 +737,21 @@ public static String[] split(String s) { return split(s, null); } /**将s用split分割成String[] + * trim = true; * @param s * @param split * @return */ public static String[] split(String s, String split) { + return split(s, split, true); + } + /**将s用split分割成String[] + * @param s + * @param split + * @param trim 去掉前后两端的split + * @return + */ + public static String[] split(String s, String split, boolean trim) { s = getString(s); if (s.isEmpty()) { return null; @@ -749,11 +759,13 @@ public static String[] split(String s, String split) { if (isNotEmpty(split, false) == false) { split = ","; } - while (s.startsWith(split)) { - s = s.substring(split.length()); - } - while (s.endsWith(split)) { - s = s.substring(0, s.length() - split.length()); + if (trim) { + while (s.startsWith(split)) { + s = s.substring(split.length()); + } + while (s.endsWith(split)) { + s = s.substring(0, s.length() - split.length()); + } } return s.contains(split) ? s.split(split) : new String[]{s}; } diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java index 3c41e957f..7133d42f1 100755 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/ZBLibrary/src/main/java/zuo/biao/library/util/SettingUtil.java @@ -229,15 +229,15 @@ public static boolean noDisturb() { /** * TODO 改为你的正式服务器地址 */ - public static final String URL_SERVER_ADDRESS_NORMAL_HTTP = "http://139.196.140.118:8080/";//正式服务器 + public static final String URL_SERVER_ADDRESS_NORMAL_HTTP = "http://39.108.143.172:8080/";//正式服务器 /** * TODO 改为你的正式服务器地址 */ - public static final String URL_SERVER_ADDRESS_NORMAL_HTTPS = "http://192.168.43.52:8080/";//正式服务器 + public static final String URL_SERVER_ADDRESS_NORMAL_HTTPS = "http://39.108.143.172:8080/";//正式服务器 /** * TODO 改为你的测试服务器地址,如果有的话 */ - public static final String URL_SERVER_ADDRESS_TEST = "http://192.168.0.118:8080/";//测试服务器 + public static final String URL_SERVER_ADDRESS_TEST = "http://192.168.0.100:8080/";//测试服务器 /**获取当前服务器地址 * isHttps = false diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListActivity.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListActivity.java index 02600f72c..0b579666f 100755 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListActivity.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListActivity.java @@ -19,6 +19,7 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; +import android.widget.ImageView; import com.alibaba.fastjson.JSONObject; @@ -134,9 +135,15 @@ protected void onCreate(Bundle savedInstanceState) { //UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + private boolean isCurrentUser = false; + + private ImageView ivMomentListForward; private MomentListFragment fragment; @Override public void initView() {//必须在onCreate方法内调用 + ivMomentListForward = (ImageView) findViewById(R.id.ivMomentListForward); + ivMomentListForward.setVisibility(showSearch ? View.VISIBLE : View.GONE); + String title; switch (range) { case MomentListFragment.RANGE_ALL: @@ -146,7 +153,14 @@ public void initView() {//必须在onCreate方法内调用 // title = "动态"; // break; case MomentListFragment.RANGE_USER: - title = APIJSONApplication.getInstance().isCurrentUser(id) ? "我的动态" : "TA的动态"; + isCurrentUser = APIJSONApplication.getInstance().isCurrentUser(id); + title = isCurrentUser ? "我的动态" : "TA的动态"; + if (isCurrentUser) { + ivMomentListForward.setVisibility(View.VISIBLE); + ivMomentListForward.setImageResource(R.drawable.add); + } else { + ivMomentListForward.setVisibility(View.GONE); + } break; case MomentListFragment.RANGE_USER_CIRCLE: title = "朋友圈"; @@ -158,10 +172,9 @@ public void initView() {//必须在onCreate方法内调用 tvBaseTitle.setText(title); autoSetTitle(); - findViewById(R.id.ivMomentListForward).setVisibility(showSearch ? View.VISIBLE : View.GONE); - fragment = MomentListFragment.createInstance(range, id, search); + fragment.setIsAdd(isCurrentUser); fragmentManager .beginTransaction() diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListFragment.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListFragment.java index e4c98989a..c012283a6 100644 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListFragment.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/MomentListFragment.java @@ -37,6 +37,7 @@ import apijson.demo.client.application.APIJSONApplication; import apijson.demo.client.base.BaseHttpListFragment; import apijson.demo.client.interfaces.TopBarMenuCallback; +import apijson.demo.client.model.Moment; import apijson.demo.client.model.MomentItem; import apijson.demo.client.util.CommentUtil; import apijson.demo.client.util.HttpRequest; @@ -204,7 +205,7 @@ public void refreshAdapter() { }); } - + private TextView leftMenu; @SuppressLint("InflateParams") @Override @@ -261,6 +262,12 @@ public void initData() {//必须调用 } + private boolean isAdd = false; + public void setIsAdd(boolean isAdd) { + this.isAdd = isAdd; + } + + @Override public void getListAsync(final int page) { HttpRequest.getMomentList(range, id, search, getCacheCount(), page, -page, this); @@ -332,10 +339,17 @@ public void onDragBottom(boolean rightToLeft) { return; } - showShortToast("输入为空则查看全部"); - toActivity(EditTextInfoWindow.createIntent(context - , EditTextInfoWindow.TYPE_NAME, "关键词", null), - REQUEST_TO_EDIT_TEXT_INFO, false); + if (isAdd) { + toActivity(EditTextInfoWindow.createIntent(context + , EditTextInfoWindow.TYPE_NOTE, "发动态", "说点什么吧~"), + REQUEST_TO_EDIT_TEXT_INFO, false); + } else { + showShortToast("输入为空则查看全部"); + toActivity(EditTextInfoWindow.createIntent(context + , EditTextInfoWindow.TYPE_NAME, "关键词", null), + REQUEST_TO_EDIT_TEXT_INFO, false); + } + } } @@ -346,6 +360,35 @@ public void onDataChanged() { } } + private static final int HTTP_ADD = 1; + + @Override + public void onHttpResponse(int requestCode, String resultJson, Exception e) { + switch (requestCode) { + case HTTP_ADD: + JSONResponse response = new JSONResponse(resultJson); + response = response.getJSONResponse(Moment.class.getSimpleName()); + + if (JSONResponse.isSuccess(response) == false) { + showShortToast("发布失败,请检查网络后重试"); + } else { + runUiThread(new Runnable() { + + @Override + public void run() { + showShortToast("发布成功"); + lvBaseList.onRefresh(); + } + }); + } + break; + default: + super.onHttpResponse(requestCode, resultJson, e); + break; + } + + } + //系统自带监听方法 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -363,14 +406,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { case REQUEST_TO_EDIT_TEXT_INFO: if (data != null) { String value = StringUtil.getString(data.getStringExtra(EditTextInfoWindow.RESULT_VALUE)); - String split = ""; - JSONRequest search = new JSONRequest(); - if (StringUtil.isNotEmpty(value, true)) { - split = ":"; - search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER); + + if (isAdd) { + HttpRequest.addMoment(value, HTTP_ADD, this); + } else { + String split = ""; + JSONRequest search = new JSONRequest(); + if (StringUtil.isNotEmpty(value, true)) { + split = ":"; + search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER); + } + toActivity(MomentListActivity.createIntent(context, range, id, search, false) + .putExtra(INTENT_TITLE, "搜索" + split + value)); } - toActivity(MomentListActivity.createIntent(context, range, id, search, false) - .putExtra(INTENT_TITLE, "搜索" + split + value)); } break; default: diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/PasswordActivity.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/PasswordActivity.java index cb9ced32f..1a3cbe0b3 100644 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/PasswordActivity.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/PasswordActivity.java @@ -87,7 +87,7 @@ public Activity getActivity() { public static final int TYPE_VERIFY = 0; public static final int TYPE_REGISTER = 1; - public static final int TYPE_RESET = 3; + public static final int TYPE_RESET = 2; private int type = TYPE_VERIFY; private String phone; @@ -212,7 +212,7 @@ private void getVerify() { /**从服务器获取验证码 */ - private void getVerifyFromServer() { + private void getVerifyFromServer(int type) { runUiThread(new Runnable() { @Override @@ -221,7 +221,7 @@ public void run() { } }); - HttpRequest.getVerify(StringUtil.getTrimedString(etPasswordPhone), HTTP_GET_VERIFY, this); + HttpRequest.getVerify(type, StringUtil.getTrimedString(etPasswordPhone), HTTP_GET_VERIFY, this); } /**下一步 @@ -245,16 +245,20 @@ private void toNextStep() { case TYPE_REGISTER: register(); break; - default: - checkVerify(true); + case TYPE_VERIFY: + checkVerify(Verify.TYPE_LOGIN, true); + break; + case TYPE_RESET: + checkVerify(Verify.TYPE_PASSWORD, true); break; } } /**验证验证码 + * @param type * @param fromServer */ - private boolean checkVerify(boolean fromServer) { + private boolean checkVerify(int type, boolean fromServer) { if (EditTextUtil.isInputedCorrect(context, etPasswordPhone, EditTextUtil.TYPE_PHONE) == false || EditTextUtil.isInputedCorrect(context, etPasswordVerify, EditTextUtil.TYPE_VERIFY) == false) { return false; @@ -262,7 +266,7 @@ private boolean checkVerify(boolean fromServer) { if (fromServer) { showProgressDialog(); - HttpRequest.checkVerify(StringUtil.getTrimedString(etPasswordPhone), + HttpRequest.checkVerify(type, StringUtil.getTrimedString(etPasswordPhone), StringUtil.getTrimedString(etPasswordVerify), HTTP_CHECK_VERIFY, this); } @@ -271,7 +275,7 @@ private boolean checkVerify(boolean fromServer) { private void register() { - if (checkVerify(false) == false) { + if (checkVerify(Verify.TYPE_REGISTER, false) == false) { return; } showProgressDialog(); @@ -357,11 +361,11 @@ public void run() { if (type == TYPE_REGISTER) { showShortToast("手机号已经注册"); } else { - getVerifyFromServer(); + getVerifyFromServer(type == TYPE_VERIFY ? Verify.TYPE_LOGIN : Verify.TYPE_PASSWORD); } } else {//手机号未被注册过 if (type == TYPE_REGISTER) { - getVerifyFromServer(); + getVerifyFromServer(Verify.TYPE_REGISTER); } else { showShortToast("手机号未注册"); } diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/UserListFragment.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/UserListFragment.java index 8c4cf8091..31d07d7e0 100755 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/UserListFragment.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/activity_fragment/UserListFragment.java @@ -337,15 +337,15 @@ public void onDragBottom(boolean rightToLeft) { if (searchType <= 0) { searchType = EditTextInfoWindow.TYPE_PHONE; } - if (searchType == EditTextInfoWindow.TYPE_NAME) { +// if (searchType == EditTextInfoWindow.TYPE_NAME) { toActivity(EditTextInfoWindow.createIntent(context , EditTextInfoWindow.TYPE_NAME, "姓名", null), REQUEST_TO_EDIT_TEXT_INFO_SEARCH, false); - } else { - toActivity(EditTextInfoWindow.createIntent(context - , EditTextInfoWindow.TYPE_PHONE, "手机号", null), - REQUEST_TO_EDIT_TEXT_INFO_ADD, false); - } +// } else { +// toActivity(EditTextInfoWindow.createIntent(context +// , EditTextInfoWindow.TYPE_PHONE, "手机号", null), +// REQUEST_TO_EDIT_TEXT_INFO_ADD, false); +// } } } diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/model/Verify.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/model/Verify.java index 6dc5924b2..0d72b828b 100644 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/model/Verify.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/model/Verify.java @@ -14,9 +14,6 @@ package apijson.demo.client.model; -import zuo.biao.library.util.StringUtil; - - /**验证码类 * @author Lemon */ @@ -26,32 +23,15 @@ public class Verify extends apijson.demo.server.model.Verify { public Verify() { super(); } - public Verify(long phone) { - super(phone); + + public Verify(int type, String phone) { + super(type, phone); } - public Verify(String verify) { - this(); - setVerify(verify); - } - + + @Override public Long getId() { return value(super.getId()); } - /**服务器用id作为phone - * @return - */ - public String getPhone() { - return "" + getId(); - } - public Verify setPhone(String phone) { - setId(Long.valueOf(0 + StringUtil.getNumber(phone))); - return this; - } - public Verify setPhone(Long phone) { - setId(Long.valueOf(0 + StringUtil.getNumber(phone))); - return this; - } - } diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/util/HttpRequest.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/util/HttpRequest.java index b3bb2d216..362ef438f 100755 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/util/HttpRequest.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/client/util/HttpRequest.java @@ -271,9 +271,13 @@ public static void setPassword(String verify, String phone, String password, int , int requestCode, OnHttpResponseListener listener) { JSONRequest request = new JSONRequest(); request.put(VERIFY, verify); - request.put(PHONE, phone); - request.put(PASSWORD, password); - request.put(TYPE, type); + Privacy privacy = new Privacy().setPhone(phone); + if (type == Privacy.PASSWORD_TYPE_LOGIN) { + privacy.setPassword(password); + } else { + privacy.setPayPassword(password); + } + request.put(privacy); HttpManager.getInstance().post(URL_BASE + "put/password", request, requestCode, listener); } @@ -281,23 +285,26 @@ public static void setPassword(String verify, String phone, String password, int /**获取验证码 + * @param type * @param phone * @param requestCode * @param listener */ - public static void getVerify(String phone, int requestCode, OnHttpResponseListener listener) { + public static void getVerify(int type, String phone, int requestCode, OnHttpResponseListener listener) { HttpManager.getInstance().post(URL_BASE + "post/verify/" - , new JSONRequest(PHONE, phone).setTag(VERIFY_) + , new JSONRequest(PHONE, phone).puts(TYPE, type).setTag(VERIFY_) , requestCode, listener); } /**校验验证码 + * @param type * @param phone * @param verify * @param requestCode * @param listener */ - public static void checkVerify(String phone, String verify, int requestCode, OnHttpResponseListener listener) { + public static void checkVerify(int type, String phone, String verify, int requestCode, OnHttpResponseListener listener) { JSONRequest request = new JSONRequest(); + request.put(TYPE, type); request.put(PHONE, phone); request.put(VERIFY, verify); @@ -571,6 +578,25 @@ public static void praiseMoment(long id, boolean toPraise, int requestCode, OnHt put(new JSONRequest(MOMENT_, data).setTag(MOMENT_), requestCode, listener); } + /**新增动态 + * @param content + * @param requestCode + * @param listener + */ + public static void addMoment(String content, int requestCode, OnHttpResponseListener listener) { + List list = new ArrayList(); + list.add("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000"); + list.add("http://common.cnblogs.com/images/icon_weibo_24.png"); + + post(new JSONRequest( + new Moment() + .setUserId(application.getCurrentUserId()) + .setContent(content) + .setPictureList(list) + ).setTag(MOMENT_) + , requestCode, listener); + } + /**删除动态 * @param id * @param requestCode @@ -580,6 +606,7 @@ public static void deleteMoment(Long id, int requestCode, OnHttpResponseListener delete(new JSONRequest(new Moment(id)).setTag(MOMENT_), requestCode, listener); } + //Moment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/server/model/Verify.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/server/model/Verify.java index 69e458f97..23062a00b 100644 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/server/model/Verify.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/app/src/main/java/apijson/demo/server/model/Verify.java @@ -22,26 +22,9 @@ import static zuo.biao.apijson.RequestRole.UNKNOWN; import zuo.biao.apijson.MethodAccess; -import zuo.biao.apijson.StringUtil; /**验证码 * @author Lemon - * @see - *
GETS:gets/authCode
-{
-    "Verify":{
-        "disallow":"id"
-    }
-}
- * 
- *
POST:post/authCode
-{
-    "Verify":{
-        "disallow":"!",
-        "necessary":"id"
-    }
-}
- * 
*/ @MethodAccess( GET = {}, @@ -55,42 +38,50 @@ public class Verify extends BaseModel { private static final long serialVersionUID = 1L; - private String verify; + public static final int TYPE_LOGIN = 0; //登录 + public static final int TYPE_REGISTER = 1; //注册 + public static final int TYPE_PASSWORD = 2; //设置密码 + + private String phone; //手机 + private String verify; //验证码 + private Integer type; //验证类型 public Verify() { super(); } - public Verify(String phone) { + /**type和phone为联合主键,必传 + * @param type + * @param phone + */ + public Verify(int type, String phone) { this(); + setType(type); setPhone(phone); } - public Verify(Long phone) { - this(); - setId(phone); - } - public Verify(Long phone, Integer verify) { - this(phone); - setVerify(verify == null ? null : ("" + verify)); - } - public Verify(String phone, String verify) { - this(phone); - setVerify(verify); - } public String getVerify() { return verify; } - public void setVerify(String verify) { + public Verify setVerify(String verify) { this.verify = verify; + return this; } - //phone is not column - // public String getPhone() { - // return StringUtil.getString(getId()); - // } + public String getPhone() { + return phone; + } public Verify setPhone(String phone) { - setId(Long.valueOf(0 + StringUtil.getNumber(phone))); + this.phone = phone; return this; } + + public Integer getType() { + return type; + } + public Verify setType(Integer type) { + this.type = type; + return this; + } + } diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java index 205d6436f..b219b430a 100644 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java @@ -737,11 +737,21 @@ public static String[] split(String s) { return split(s, null); } /**将s用split分割成String[] + * trim = true; * @param s * @param split * @return */ public static String[] split(String s, String split) { + return split(s, split, true); + } + /**将s用split分割成String[] + * @param s + * @param split + * @param trim 去掉前后两端的split + * @return + */ + public static String[] split(String s, String split, boolean trim) { s = getString(s); if (s.isEmpty()) { return null; @@ -749,11 +759,13 @@ public static String[] split(String s, String split) { if (isNotEmpty(split, false) == false) { split = ","; } - while (s.startsWith(split)) { - s = s.substring(split.length()); - } - while (s.endsWith(split)) { - s = s.substring(0, s.length() - split.length()); + if (trim) { + while (s.startsWith(split)) { + s = s.substring(split.length()); + } + while (s.endsWith(split)) { + s = s.substring(0, s.length() - split.length()); + } } return s.contains(split) ? s.split(split) : new String[]{s}; } diff --git a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/app/src/main/java/apijson/demo/ui/RequestActivity.java b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/app/src/main/java/apijson/demo/ui/RequestActivity.java index bfdf8d21b..91eba0e55 100644 --- a/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/app/src/main/java/apijson/demo/ui/RequestActivity.java +++ b/APIJSON-Android/APIJSON-AndroidStudio/APIJSONTest/app/src/main/java/apijson/demo/ui/RequestActivity.java @@ -121,7 +121,7 @@ protected void onCreate(Bundle savedInstanceState) { etRequestUrl.setText(StringUtil.getString(StringUtil.isNotEmpty(url, true) - ? url : "http://139.196.140.118:8080/"));//TODO 把这个ip地址改成你自己服务器的 + ? url : "http://39.108.143.172:8080/"));//TODO 把这个ip地址改成你自己服务器的 btnRequestRequest.setText(method); error = String.format(getResources().getString(R.string.request_error), StringUtil.getTrimedString(btnRequestRequest));