1、tools、androidcode、custom、buildset、product共5个大仓,切忌在每轮版本完后都要按照当前的版本的版本号(时间)进行打tag,确保版本的完整性。
例如:整个版本是从B001-B030,但测试提出的问题单在B025(引入了重大问题)的版本上,这时我们就要把所有的仓都能够回退到B025版本上,进行问题打验证和代码的查看。
2、版本过点的时候进行拉分支:注意拉分支的时候也要打tag,保证在后续的开发过程中我能回退到拉分支时候的代码状态。拉分支后有些分支需要做CI设置,能够进行CI编译。在CI上也要设置相应提交代码人的权限。1.AndroidManifest.xml添加网络访问权限
<uses-permission android:name="android.permission.INTERNET"/>
2.在web项目中新建servlet
package cn.com.servlet;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//服务器接受统一编码iso-8859-1,然后获取字符串时转化为utf-8
String name = new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8");
String password = request.getParameter("password");
System.out.println("name:"+name);
System.out.println("password:"+password);
if(name.equals("张三")&&password.equals("123")){
//往浏览器写字符串
response.getOutputStream().write("HttpClienget方式登录成功".getBytes("utf-8")); //写到浏览器的编码是utf-8
}
else{
response.getOutputStream().write("HttpClienget方式登录失败".getBytes("utf-8")); //写到浏览器的编码是utf-8
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//doGet(request, response);
//服务器接受统一编码iso-8859-1,然后获取字符串时转化为utf-8
String name = new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8");
String password = request.getParameter("password");
System.out.println("name:"+name);
System.out.println("password:"+password);
if(name.equals("张三")&&password.equals("123")){
//往浏览器写字符串
response.getOutputStream().write("HttpClienpost方式登录成功".getBytes("utf-8")); //写到浏览器的编码是utf-8
}
else{
response.getOutputStream().write("HttpClientpost方式登录失败".getBytes("utf-8")); //写到浏览器的编码是utf-8
}
}
}
3.文件布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="输入用户名"
android:text="张三"
/>
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="输入密码" />
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ClientGet提交"
android:onClick="onClick3"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ClientPost提交"
android:onClick="onClick4"
/>
</LinearLayout>
4.MainActivity.java
package com.example.get;
import java.io.UnsupportedEncodingException;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText name,password;
private final int SUCCESS=1;
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(msg.what==SUCCESS){
String result = (String) msg.obj;
if(result!=null){
Toast.makeText(MainActivity.this, result, 1).show();
}else{
Toast.makeText(MainActivity.this, "登陆失败", 1).show();
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText) findViewById(R.id.name);
password = (EditText) findViewById(R.id.password);
}
/**
* clientget提交
* @param view
*/
public void onClick3(View view){
final String loginName = name.getText().toString();
final String loginPasswor = password.getText().toString();
new Thread(){
@Override
public void run() {
final String result=LoginService.loginClientGet(loginName, loginPasswor);
if(result!=null){
//在主线程上运行
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, result, 1).show();
}
});
}
}
}.start();
}
public void onClick4(View view){
final String loginName = name.getText().toString();
final String loginPasswor = password.getText().toString();
new Thread(){
@Override
public void run() {
final String result=LoginService.loginClientPost(loginName, loginPasswor);
if(result!=null){
//在主线程上运行
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, result, 1).show();
}
});
}
}
}.start();
}
}
5 业务类 LoginService .java
package com.example.get;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class LoginService {
/**
* clientget方式提交
* @param name
* @param password
* @return
*/
public static String loginClientGet(String name,String password){
try {
//打开浏览器
HttpClient client = new DefaultHttpClient();
//输入地址
String path = "http://10.162.0.171:8080/WebGet/LoginServlet?name="+URLEncoder.encode(name)+"&password="+URLEncoder.encode(password);
HttpGet get = new HttpGet(path);
//敲回车
HttpResponse response=client.execute(get);
int code=response.getStatusLine().getStatusCode();
if(code==200){
InputStream is=response.getEntity().getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len=0;
//将输入流不断的读,并放到缓冲区中去。直到读完
if((len=is.read(buffer))!=-1){
//将缓冲区的数据不断的写到内存中去。
baos.write(buffer, 0, len);
}
byte[] b=baos.toByteArray();
is.close();
baos.close();
return new String(b,"utf-8");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return null;
}
/**
* clientpost方式提交
* @param name
* @param password
* @return
*/
public static String loginClientPost(String name,String password){
try {
//打开浏览器
HttpClient client = new DefaultHttpClient();
//输入地址
String path="http://10.162.0.171:8080/WebGet/LoginServlet";
HttpPost post = new HttpPost(path);
//添加地址参数
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("name", name));
parameters.add(new BasicNameValuePair("password", password));
post.setEntity(new UrlEncodedFormEntity(parameters, "utf-8"));
//敲回车
HttpResponse response=client.execute(post);
int code=response.getStatusLine().getStatusCode();
if(code==200){
InputStream is=response.getEntity().getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len=0;
//将输入流不断的读,并放到缓冲区中去。直到读完
if((len=is.read(buffer))!=-1){
//将缓冲区的数据不断的写到内存中去。
baos.write(buffer, 0, len);
}
byte[] b=baos.toByteArray();
is.close();
baos.close();
return new String(b);
}
} catch (Exception e) {
// TODO Auto-generated catch block
return null;
}
return null;
}
}
package com.zongyi.trip.ui; import com.zongyi.trip.R; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.DashPathEffect; import android.graphics.Paint; import android.graphics.PathEffect; import android.util.AttributeSet; import android.widget.EditText; @SuppressLint({ "ResourceAsColor", "DrawAllocation" }) public class LinedEditText extends EditText { // private Paint mPaint = new Paint(); public LinedEditText(Context context) { super(context); initPaint(); } public LinedEditText(Context context, AttributeSet attrs) { super(context, attrs); initPaint(); } public LinedEditText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initPaint(); } private void initPaint() { // mPaint.setStyle(Paint.Style.STROKE); //// mPaint.setColor(0x80000000); // mPaint.setStyle(Paint.Style.STROKE); // mPaint.setColor(R.color.dashed_line_color); // PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1); // mPaint.setPathEffect(effects); } @Override protected void onDraw(Canvas canvas) { Paint mPaint = new Paint(); // mPaint.setColor(0x80000000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(Color.LTGRAY); PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},5); mPaint.setPathEffect(effects); int left = getLeft(); int right = getRight(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); int height = getHeight(); int lineHeight = getLineHeight(); int spcingHeight = (int) getLineSpacingExtra(); int count = (height-paddingTop-paddingBottom) / lineHeight; for (int i = 0; i < count; i++) { int baseline = lineHeight * (i+1) + paddingTop - spcingHeight/2 ; canvas.drawLine(left+paddingLeft, baseline, right-paddingRight, baseline, mPaint); } super.onDraw(canvas); } }
<com.zongyi.trip.ui.LinedEditText android:id="@+id/edittext_message" android:layout_width="fill_parent" android:layout_height="200dp" android:lineSpacingExtra="15dp" android:gravity="top" android:textColor="#ACB6BB" android:textSize="18sp" />