SharedPreferences의 Json 객체 세션 부분 문자열 대체
구현 방법:
package X;XX
XXX
public class C_My1InfoPopWindows extends C_BaseActivity {
private EditText editText;
private String fromText,fromType,fromDefaultVal;
private String session;
JSONObject sessionJson;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.correcting_my_info_modify);
initDataAndView();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void initDataAndView() {
editText = (EditText) findViewById(R.id.editText);
fromText = getIntent().getStringExtra("text");
fromType = getIntent().getStringExtra("type");
fromDefaultVal = getIntent().getStringExtra("defaultText");
editText.setText(fromText);
/** */
CharSequence text = editText.getText();
if (text instanceof Spannable) {
Spannable spanText = (Spannable)text;
Selection.setSelection(spanText, text.length());
}
switch (fromType) {
case "name":
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)});
break;
case "phone":
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(11)});
editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL);
break;
case "email":
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)});
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
break;
case "company":
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)});
break;
}
}
public void save(View v) {
String saveStr = editText.getText().toString().trim();
if (StringUtil.isEmpty(saveStr)) {
// ,
new SaveDataAsynctask().execute(fromDefaultVal);
return;
} else {
//
String regexEmail = "^[\\w-]+(\\.[\\w-]+)*\\@([\\.\\w-]+)+$";
String regexPhone = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
String regex = (fromType.equals("phone")) ? regexPhone : (fromType.equals("email")) ? regexEmail : null;
//
if (regex != null) {
boolean isPass = Pattern.matches(regex, saveStr);
if (!isPass) {
Toast.makeText(this, " !", Toast.LENGTH_SHORT).show();
return;
}
}
new SaveDataAsynctask().execute(saveStr);
}
}
private class SaveDataAsynctask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String isRet = null;
//http://115.29.238.140:8017/api.ashx?fdBuyeIP=14.150.164.199&fdBuyeName=qwww&method=Buyer.Update&userUUID=f0ff399d-4a4e-4a8a-8e72-73bff8d08e90&fdBuyeUnit= &fdBuyeStatus=0&fdBuyeEmail=&fdAutoId=0&fdBuyeId=193&propStatusName= &fdBuyeMobile=15521392526&fdBuyeImage=http://115.29.238.140:8017/plugin/upload/web/store/demand/635866545788924671.png&fdBuyeAddress=
//"http://115.29.238.140:8017/api.ashx?"
//fdBuyeIP=14.150.164.199&
/*fdBuyeName=qwww&
method=Buyer.Update&
userUUID=f0ff399d-4a4e-4a8a-8e72-73bff8d08e90&
fdBuyeUnit= &
fdBuyeStatus=0&
fdBuyeEmail=&
fdAutoId=0&
fdBuyeId=193&
propStatusName= &
fdBuyeMobile=15521392526&
fdBuyeImage=http://115.29.238.140:8017/plugin/upload/web/store/demand/635866545788924671.png&
fdBuyeAddress=*/
try {
session = getSharedPreferences(Properties.LOGIN_INFO, 0).getString("o2OSetSession", null);
if(session == null) return null;
sessionJson = new JSONObject(session);
String detail = sessionJson.getString("detail");
JSONObject detailJson = new JSONObject(detail);
String propStatusName , fdBuyeId ,fdBuyeMobile ,
fdBuyeEmail , fdBuyeUnit ,fdBuyeAddress ,
fdBuyeName ,fdBuyeIP ,fdBuyeStatus ,fdBuyeImage ,fdAutoId;
propStatusName = detailJson.getString("propStatusName");
fdBuyeId = detailJson.getString("fdBuyeId");
fdBuyeMobile = detailJson.getString("fdBuyeMobile");
fdBuyeEmail = detailJson.getString("fdBuyeEmail");
fdBuyeUnit = detailJson.getString("fdBuyeUnit");
fdBuyeAddress = detailJson.getString("fdBuyeAddress");
fdBuyeName = detailJson.getString("fdBuyeName");
fdBuyeIP = detailJson.getString("fdBuyeIP");
fdBuyeStatus = detailJson.getString("fdBuyeStatus");
fdBuyeImage = detailJson.getString("fdBuyeImage");
fdAutoId = detailJson.getString("fdAutoId");
switch (fromType) {
case "name":
fdBuyeName = params[0];
detailJson.put("fdBuyeName", fdBuyeName);
break;
case "phone":
fdBuyeMobile = params[0];
detailJson.put("fdBuyeMobile", fdBuyeMobile);
break;
case "email":
fdBuyeEmail = params[0];
detailJson.put("fdBuyeEmail", fdBuyeEmail);
break;
case "company":
fdBuyeUnit = params[0];
detailJson.put("fdBuyeUnit", fdBuyeUnit);
break;
}
sessionJson.put("detail", detailJson);
StringBuilder paramBuider = new StringBuilder();
paramBuider.append("fdBuyeIP=" + fdBuyeIP);
paramBuider.append("&fdBuyeName=" + fdBuyeName);
paramBuider.append("&method=" + "Buyer.Update");
paramBuider.append("&userUUID=" + C_My1InfoPopWindows.this.getSharedPreferences(Properties.LOGIN_INFO,0).getString(Properties.LoginInfo.USERUUID, ""));
paramBuider.append("&fdBuyeUnit=" + fdBuyeUnit);
paramBuider.append("&fdBuyeStatus=" + fdBuyeStatus);
paramBuider.append("&fdBuyeEmail=" + fdBuyeEmail);
paramBuider.append("&fdAutoId=" + fdAutoId);
paramBuider.append("&fdBuyeId=" + fdBuyeId);
paramBuider.append("&propStatusName=" + propStatusName);
paramBuider.append("&fdBuyeMobile=" + fdBuyeMobile);
paramBuider.append("&fdBuyeImage=" + fdBuyeImage);
paramBuider.append("&fdBuyeAddress=" + fdBuyeAddress);
String uri = "/api.ashx?";
isRet = HttpManage.httpPost(C_My1InfoPopWindows.this.getApplicationContext(),
Properties.SERVER_URL_TEST + uri, paramBuider.toString(),null);
} catch (Exception e) {
}
return isRet;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result == null) {
Toast.makeText(C_My1InfoPopWindows.this, " , !", Toast.LENGTH_SHORT).show();
return;
} else {
try {
String errStr = new JSONObject(result).getString("error");
String msg = new JSONObject(errStr).getString("err_msg");
int code = Integer.parseInt( new JSONObject(errStr).getString("err_code") );
if (code == 1 ) {
//
Toast.makeText(C_My1InfoPopWindows.this, msg, Toast.LENGTH_SHORT).show();
getSharedPreferences(Properties.LOGIN_INFO, 0).edit().putString("o2OSetSession",sessionJson.toString()).commit();
C_My1InfoPopWindows.this.finish();
} else {
Toast.makeText(C_My1InfoPopWindows.this, msg, Toast.LENGTH_SHORT).show();
return;
}
} catch (Exception e) {
}
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.