网站改版repost

在软件工程14-15赛季的下半程综合创作训练(二)中,我完成了安卓大作业,这项作业完成的并没有什么心意,但是开创了webview应付大作业,做好UI给老师留下好印象就行拿分数的先河(给老师当面评分的过程中只要说的好,就能拿高分,某某同学直接提到自己研究了黑白棋游戏的算法,并参加了acm竟然就能拿高分,我呸)。


应用展示图:
应用截图 应用截图关于 应用截图用户 Screenshot_2015-07-01-13-19-31_compressed Screenshot_2015-07-01-13-19-45_compressed Screenshot_2015-07-01-13-19-50_compressed Screenshot_2015-07-01-13-10-28_compressed Screenshot_2015-07-01-13-19-54_compressed Screenshot_2015-07-01-13-20-01_compressed Screenshot_2015-07-01-13-20-06_compressed Screenshot_2015-07-01-13-10-35(1)_compressed
功能简述:

1 引导页面(使用下沉浸式状态栏)
2 用webview敷地把一些小瓜的网页app加入进来,如留言板、查跑操、表白墙
3 添加用户系统,使得上述功能可以更优秀
4 用json传递数据,服务器为php+mysql+apache
5 界面优化
6 本来打算添加一些纯原生的功能的,但是因为时间有限,老师突然把死线提前,只有2天时间做这个作品,幸好我ps实力不错。
7 写这篇博文可以顺便完成实验报告呢,不错

一些还行的代码

用一个activity作欢迎页,在适当时刻关闭自己启动首页

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_init);
		// 沉浸的状态栏
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			Window window = getWindow();
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		}
		new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					// 欢迎页面的效果在这执行
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				// 启动正式activity
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), MainActivity.class);
				startActivity(intent);
			}
		}).start();
	}

	@Override
	protected void onStop() {
		super.onStop();
		// 结束这个activity
		this.finish();
	}

王柏元哥哥提供的httpClient虽然过时,但可以学习,以后自己写一个吧

	private String hostUrl = "http://qxu1649350074.my3w.com";
	private String encode;

	/**
	 * 构造函数
	 *
	 * @param iurl
	 * @param iencode
	 */
	public XBhttpClient(String iurl, String iencode) {
		hostUrl = iurl;
		encode = iencode;
	}

	/**
	 * 发送post请求
	 *
	 * @param path
	 *            相对于根地址的文件地址,你向哪个URL发起请求
	 * @param params
	 *            MAP格式的键值对
	 * @return 完成提交post请求并获取服务器应答的字符串
	 * @throws ClientProtocolException
	 * @throws IOException
	 *
	 */
	public String sendHttpClientPOSTRequest(String path,
			Map<String, String> params) throws ClientProtocolException,
			IOException {
		// 组成post参数
		List pairs = new ArrayList();
		BufferedReader in = null;
		Log.e("httpclient", hostUrl + "/" + path);
		for (Map.Entry<String, String> entry : params.entrySet()) {
			pairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
		}
		// 防止客户端传递过去的参数发生乱码,需要对此重新编码成UTF-8
		UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, encode);
		HttpPost httpPost = new HttpPost(hostUrl + "/" + path);
		Log.e("httpclient", hostUrl + "/" + path);

		httpPost.setEntity(entity);
		HttpClient client = new DefaultHttpClient();
		client.getParams().setIntParameter(
				CoreConnectionPNames.CONNECTION_TIMEOUT, 15000);
		HttpResponse response = client.execute(httpPost);
		Log.e("httpclient", "client.execute(httpPost)");

		String result = "获取数据库数据失败";
		if (response.getStatusLine().getStatusCode() == 200) {
			in = new BufferedReader(new InputStreamReader(response.getEntity()
					.getContent()));
			StringBuffer sb = new StringBuffer("");
			String line = "";
			while ((line = in.readLine()) != null) {
				sb.append(line);
			}
			in.close();
			result = sb.toString();

		} else if (response.getStatusLine().getStatusCode() == 404) {
			Toast.makeText(null, "服务器无响应", Toast.LENGTH_SHORT);
		}
		Log.e("httpclient", result);
		return result;
	}

再按一次我就退出

	private long exitTime = 0;
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK
				&& event.getAction() == KeyEvent.ACTION_DOWN) {
			if ((System.currentTimeMillis() - exitTime) > 2000) {
				Toast.makeText(getApplicationContext(), "再按一次无情地离开小瓜",
						Toast.LENGTH_SHORT).show();
				exitTime = System.currentTimeMillis();
			} else {
				finish();
				System.exit(0);
			}
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

webview比较完整实现,以及cookie样例

	myView = (WebView) findViewById(R.id.bbq);
	myView.getSettings().setJavaScriptEnabled(true);
	// myView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
	myView.setWebViewClient(new WebViewClient() {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			myView.loadUrl(url);
			return true;
		}
		@Override
		public void onPageFinished(WebView view, String url) {
			super.onPageFinished(view, url);
			dialog.dismiss();
		}
		@Override
		public void onReceivedError(WebView view, int errorCode,
				String description, String failingUrl) {
			super.onReceivedError(view, errorCode, description, failingUrl);
			dialog.dismiss();
		}
	});

	dialog = ProgressDialog.show(this, null, "努力加载中");
	Intent intent = getIntent();
	String url = intent.getStringExtra("url");
	CookieManager cookieManager = CookieManager.getInstance();
	cookieManager.acceptCookie();
	cookieManager.setCookie("http://222.24.192.118/apps/zhewen/paocao2/","xuehao=");
	cookieManager.setCookie("http://222.24.192.118/apps/zhewen/paocao2/","aoxiangpwd=");
	cookieManager.setCookie("http://npuxiaogua.mgschool.cn/wx/apps/wish_for_app/index.php","nickname=");
	cookieManager.setCookie("http://npuxiaogua.mgschool.cn/wx/apps/liuyan_for_app/index.php","nickname=");
	pf = getSharedPreferences("user", MODE_PRIVATE);
	String log_status = pf.getString("log_status", null);
	if (log_status != null && log_status.equals("on")) {
		cookieManager.setCookie("http://222.24.192.118/apps/zhewen/paocao2/", "xuehao="
			+ pf.getString("xuehao", ""));
		cookieManager.setCookie("http://222.24.192.118/apps/zhewen/paocao2/", "aoxiangpwd="
			+ pf.getString("aoxiangpwd", ""));
		cookieManager.setCookie("http://npuxiaogua.mgschool.cn/wx/apps/wish_for_app/index.php",
			"nickname=" + pf.getString("nicheng", ""));
		cookieManager.setCookie("http://npuxiaogua.mgschool.cn/wx/apps/liuyan_for_app/index.php",
			"nickname=" + pf.getString("nicheng", ""));
		}

	System.out.println("cookie:" + cookieManager.getCookie(url));
	myView.loadUrl(url);

总结

本次作业其实就学了下综合app的开发,webview中cookie的使用,ps技术的加强,可重用的代码主要在优秀的ui控件上

「Unity Shaders」Surface Shaders and Texture Mapping

 本文内容参考《Unity 5.x Shaders and Effects Cookbook》 表面着色器和材质贴图 总的来说,一个表面着色器有两个关键的步骤。第一,必须确定材质的物理...

阅读全文

「Unity Shaders」Creating First Shader

创建第一个着色器 最近学习了一段时间Unity Shader相关知识,在进一步自顶向下学习计算机图形学之前,先将之前看《Unity 5.x Shaders and Effects Cookbook...

阅读全文

《Effective c++》、《Inside C++ Model》 小结(一)

最近瞻仰了一下Scott Meyers久负盛名的《effective c++》,特来总结一下,以加深一下印象与防止自己今后记忆力衰退。这本书里很多都是工程上很有意思的tips...

阅读全文

1 条评论

欢迎留言