毕业论文—android客户端

LogoAcitivty

private void showImg(final float startAlpha, final int drawableId, int delay)
    {

        new Handler().postDelayed(new Runnable()
        {

            @Override
            public void run()
            {
                logo_imageView.setImageResource(drawableId);
                AlphaAnimation animation = new AlphaAnimation(startAlpha, 1.0f);
                animation.setDuration(1000);
                logo_imageView.startAnimation(animation);
            }
        }, delay);
}

客户端与服务端交互数据

public static HttpClient getHttpClient()
    {
        // 创建 HttpParams 以用来设置 HTTP 参数(这一部分不是必需的)
        HttpParams httpParams = new BasicHttpParams();
        // 设置连接超时和 Socket 超时,以及 Socket 缓存大小
        HttpConnectionParams.setConnectionTimeout(httpParams, 5 * 1000);
        HttpConnectionParams.setSoTimeout(httpParams, 5 * 1000);
        HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
        // 设置重定向,缺省为 true
        HttpClientParams.setRedirecting(httpParams, true);
        // 设置 user agent
        String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";
        HttpProtocolParams.setUserAgent(httpParams, userAgent);
        // 创建一个 HttpClient 实例
        // 注意 HttpClient httpClient = new HttpClient(); 是Commons HttpClient
        // 中的用法,在 Android 1.5 中我们需要使用 Apache 的缺省实现 DefaultHttpClient
        HttpClient httpClient = new DefaultHttpClient(httpParams);
        return httpClient;
    }

post请求

   public static String postRequest(String url, Map<String, String> rawParams)
            throws Exception
    {
        // 创建HttpPost对象。
        HttpPost post = new HttpPost(url);
        // 如果传递参数个数比较多的话可以对传递的参数进行封装
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        for (String key : rawParams.keySet())
        {
            // 封装请求参数
            params.add(new BasicNameValuePair(key, rawParams.get(key)));
        }
        // 设置请求参数
        post.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
        // 发送POST请求
        HttpResponse httpResponse = httpClient.execute(post);
        // httpClient.getParams().setParameter(
        // CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
        // 如果服务器成功地返回响应
        if (httpResponse.getStatusLine().getStatusCode() == 200)
        {
            // 获取服务器响应字符串
            String result = EntityUtils.toString(httpResponse.getEntity());
            return result;
        }
        return null;
    }

客户端实际调用postrequest()

final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try
        {
            JSONArray jsonArray = new JSONArray(URLDecoder.decode(HttpUtil
                    .queryStringForPost(LESSON_URL), "UTF-8"));
            for (int i = 0; i < jsonArray.length(); i++)
            {

                HashMap<String, Object> hashMap = new HashMap<String, Object>();
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                hashMap.put(SQLUtil.ST_LESSONS_LESSON_NAME, jsonObject
                        .get(SQLUtil.ST_LESSONS_LESSON_NAME));
                list.add(hashMap);
            }

        }
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        }
        catch (JSONException e)
        {
            e.printStackTrace();
        }
登录验证代码实现
private boolean validate()
    {

        String student_id = et_id.getText().toString().trim();
        String student_pwd = et_pwd.getText().toString().trim();
        if (student_id.equals(""))
        {
            et_id.setFocusable(true);
            et_id.requestFocus();
            Toast
                    .makeText(LoginActivity2.this, "亲,帐号为空的噢!",
                            Toast.LENGTH_SHORT).show();
            return false;
        }
        else if (student_pwd.equals(""))
        {

            et_pwd.setFocusable(true);
            et_pwd.requestFocus();
            Toast.makeText(LoginActivity2.this, "亲,密码可是为空的哦!",
                    Toast.LENGTH_SHORT).show();
            return false;

        }
        else
        {
            return true;
        }

    }

    


试卷和课程主要功能代码实现

 listView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3)
            {

                studentTaoti.setTaoti_name(list.get(arg2).get(
                        SQLUtil.ST_TAOTIS_TAOTI_NAME).toString());
                studentTaoti.setTaoti_score(Integer.parseInt(list.get(arg2)
                        .get(SQLUtil.ST_TAOTIS_TAOTI_SCORE).toString()));
                studentTaoti.setTaoti_time(Integer.parseInt(list.get(arg2).get(
                        SQLUtil.ST_TAOTIS_TAOTI_TIME).toString()));
                studentTaoti.setTaoti_descript(list.get(arg2).get(
                        SQLUtil.ST_TAOTIS_TAOTI_DESCRIPT).toString());
                String url = HttpUtil.BASE_URL + QuestionActivity.QUESTION_URL;
                HashMap<String, String> param = new HashMap<String, String>();
                param.put(SQLUtil.ST_TAOTIS_TAOTI_NAME, studentTaoti
                        .getTaoti_name());
                try
                {
                    JSONArray jsonArray = new JSONArray(URLDecoder.decode(
                            HttpUtil.postRequest(url, param), "UTF-8"));
                    if (jsonArray.length() != 0)
                    {
                        Intent intent = new Intent(TaotiActivity.this,
                                QuestionActivity.class);
                        startActivity(intent);
                    }
                    else
                    {
                        Toast.makeText(TaotiActivity.this,
                                "亲," + studentTaoti.getTaoti_name() + "没有题目啊!",
                                Toast.LENGTH_SHORT).show();
                    }
                }
                catch (UnsupportedEncodingException e)
                {
                    e.printStackTrace();
                }
                catch (JSONException e)
                {
                    e.printStackTrace();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }

            }
        });



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值