android端主要功能实现

因经常使用HttpClientl类现封装成WebApi类供日常调用,代码如下

public class WebAPI {

    public static final String API_HOST = Constant.BASEURL;
    private Context mContext = null;
    private AbHttpUtil mAbHttpUtil = null;
    private final static String TAG = "WebAPI";

    public WebAPI(Context context){
        // 创建Http工具类
        mContext = context;
        mAbHttpUtil = AbHttpUtil.getInstance(context);
    }

    public  void login(String userName,String password, final AbHttpListener abHttpListener){
        try {
            //AbHttpUtil httpUtil = AbHttpUtil.getInstance(mContext);
            // 一个url地址
            String url = API_HOST + "api/apiaccount/login";
            String returnValue = "";
            CRMAppUser user = new CRMAppUser();
            user.setUserName(userName);
            user.setPassword(password);
            user.setDeviceType(1);
            //String json = AbJsonUtil.toJson(user); //for post
            AbRequestParams params = new AbRequestParams();

            params.put("userName", user.getUserName());
            params.put("password", user.getPassword());
            params.put("deviceType", user.getDeviceType());


            mAbHttpUtil.get(url, params, new AbStringHttpResponseListener() {

                //获取数据成功会调用这里
                @Override
                public void onSuccess(int statusCode, String content) {
                    Log.d(TAG, "Tool CRM:onSuccess login:"+content);
                    abHttpListener.onSuccess(content);

移动PDA离线车辆盘点系统-PDA端代码实现_Sqlite

输入账号密码,便可以登录到主界面,代码如下

public class  LoginOnClickListener implements OnClickListener{
		
		@Override
		public void onClick(View v) {
			if(v == loginBtn){
				mStrName = userName.getText().toString();
				mStrPwd = userPwd.getText().toString();
				if (TextUtils.isEmpty(mStrName)) {
					AbToastUtil.showToast(LoginActivity.this, R.string.error_name);
					userName.setFocusable(true);
					userName.requestFocus();
					return;
				}
				if (AbStrUtil.isEmpty(mStrPwd)) {
					AbToastUtil.showToast(LoginActivity.this, R.string.error_pwd);
					userPwd.setFocusable(true);
					userPwd.requestFocus();
					return;
				}
				
				login(mStrName,mStrPwd);
				}
		}
}
public void  login(final String userName, final String password){
		AbDialogUtil.showProgressDialog(LoginActivity.this, 0, "正在登录...");
		abHttpListener = new AbHttpListener(){
			@Override
			public void onSuccess(String s) {
				CRMAppUser crmUser = new CRMAppUser();
				APIResultEntity<CRMAppUser> userResult = new APIResultEntity<CRMAppUser>(crmUser);
				userResult = (APIResultEntity<CRMAppUser>) AbJsonUtil.fromJson(s, userResult.getClass());
				AbDialogUtil.removeDialog(LoginActivity.this);
				if(userResult.getValidate()){
					AbToastUtil.showToast(LoginActivity.this, "登录成功!");
					User user = new User();
					user.setUserName(userName);
					user.setPassword(password);
					user.setAccessToken(userResult.getSessionKey());
					user.setLoginUser(true);
					application.updateLoginParams(user);
					saveUserData(user);
					setResult(RESULT_OK);
					finish();
				}else{
					AbToastUtil.showToast(LoginActivity.this, userResult.getMessage());
				}
			}
			@Override
			public void onStart() {
				// TODO 自动生成的方法存根
			}
			@Override
			public void onFinish() {
				// TODO 自动生成的方法存根
			}
			@Override
			public void onFailure(String s) {
				// TODO 自动生成的方法存根
				AbDialogUtil.removeDialog(LoginActivity.this);
				AbToastUtil.showToast(LoginActivity.this, s);
			}
		};
		WebAPI web = new WebAPI(LoginActivity.this);
		web.login(userName, password, abHttpListener);
	}

这段代码主要判断用户是否输入账号密码,如果输入则访问后台进行判断,给出相应提示信息。

点击盘点计划,显示盘点计划主界面,此为后台系统已发布的计划列表。

searchBT = (Button)findViewById(R.id.search);
        searchBT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v){
                refreshTask2();
            }
        });
        //end search area
        list = new ArrayList<Map<String, Object>>();


        newsListAdapter = new CheckPlanListAdapter(this, list, R.layout.yx_news_list_item, new String[]{"itemsTitle", "itemsText", "rightFlag","id"}, new int[]{R.id.itemsTitle, R.id.itemsText, R.id.rightFlag});
        mListView.setAdapter(newsListAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                Map<String, Object> dataSet = list.get(position);
                Intent intent = new Intent(CheckPlanActivity.this, CheckPlanDetailActivity.class);

                intent.putExtra("infoid", dataSet.get("id").toString());
                String result = AbJsonUtil.toJson(checkplanrealList.get(position));
                intent.putExtra("record", result);
                //AbToastUtil.showToast(CheckPlanActivity.this, result);
                startActivityForResult(intent, 1);
            }
        });

        mDialogFragment = AbDialogUtil.showLoadDialog(this, R.drawable.ic_load, "正在加载");
        mDialogFragment.setAbDialogOnLoadListener(new AbDialogFragment.AbDialogOnLoadListener() {

            @Override
            public void onLoad() {

                refreshTask2();
            }
        });
public void refreshTask2(){
        AbLogUtil.prepareLog(CheckPlanActivity.class);
        abHttpListener = new AbHttpListener(){

            @Override
            public void onSuccess(String s) {
                //AbDialogUtil.showAlertDialog(OrderListActivity.this, "", s);
                List<Map<String, Object>> newList = new ArrayList<Map<String, Object>>();
                try {
                    //List<LinkedHashMap<String, Object>> newsList = new ArrayList<LinkedHashMap<String, Object>>();
                    APIResultEntity<List<LinkedHashMap<String, Object>>> userResult = new APIResultEntity<List<LinkedHashMap<String, Object>>>(checkplanrealList);
                    userResult = (APIResultEntity<List<LinkedHashMap<String, Object>>>)AbJsonUtil.fromJson(s, userResult.getClass());

                    if (userResult.getValidate()) {
                        total = userResult.getRecordCount();
                        if (userResult.getResultObj() != null) {
                            checkplanrealList = (ArrayList<LinkedHashMap<String, Object>>) userResult.getResultObj();

                            newList = buildCheckPlanList(checkplanrealList);
                        }

                        //
                        mDialogFragment.loadFinish();
                        AbLogUtil.d(CheckPlanActivity.class, "", true);

                        list.clear();
                        if (newList != null && newList.size() > 0) {
                            list.addAll(newList);
                            newsListAdapter.notifyDataSetChanged();
                            newList.clear();
                        }
                        mAbPullToRefreshView.onHeaderRefreshFinish();
                    }
                }catch (Exception ex){
                    AbDialogUtil.showProgressDialog(CheckPlanActivity.this, 0, ex.getMessage());
                    ex.printStackTrace();
                }
            }

此段代码主要是显示服务器端已发布盘点计划,并在列表中显示。