-->

안드로이드

 

 

        

 

        

 

 

 

 < DB    >

 

 

create table `USER` (

    userID varchar(20) not null,
    userPassword  varchar(20) not null,
    userName varchar(20) not null,
    userAge int not null,
    primary key (userID)


);

create table braverokmc2.`USER` ( userID varchar(20) not null, userPassword varchar(20) not null, userName varchar(20) not null, userAge int not null, primary key (userID) ) 

insert into braverokmc2.`USER` ( userID , userPassword , userName , userAge ) values( 'hong', '1111', '홍길동' , 39) 

select * from user where userID = 'hong' and userPassword = '1111' 

 

 

 

     <     PHP       >

 

 1. Login.php  

 



<?php 
//http://braverokmc2.dothome.co.kr/Login.php?userID=hong&userPassword=1111


/* mysql_connect('localhost', 'mysql_user', 'mysql_password'); */
	$con =mysql_connect("localhost", "braverokmc2", "ehtjrhks5382");
	

	/* 	3. Mysql 입출력 인코딩을 지정
	 Mysql 연동을 한다면 입출력 인코딩이 달라서가 원인이 될 수 있다고 합니다.
	아래 3줄의 소스를 추가함으로써 해결하였습니다.
	
	출처: http://jhrun.tistory.com/140 [JHRunning] */
	
	mysql_query("set session character_set_connection=utf8;");
	
	mysql_query("set session character_set_results=utf8;");
	
	mysql_query("set session character_set_client=utf8;");
	
	
	mysql_set_charset("utf8");//sql 에서 한글 깨짐
	
	if($con==true){
	//	echo "yes 연결 되었습니다.";
		
		$_POST = array_map('mysql_escape_string', $_POST);
		$_GET=array_map('mysql_escape_string', $_GET);
		
		if(isset($_GET["userID"])){
			$userID =$_GET["userID"];
			$userPassword =$_GET["userPassword"];
			
		}else if(isset($_POST["userID"])){
			$userID =$_POST["userID"];
			$userPassword =$_POST["userPassword"];
		}

		
		if(isset($userID) && isset($userPassword)){
			
				
				$stmt = "select * from braverokmc2.USER where `userID` = '$userID' and `userPassword` = '$userPassword' ";
				$rs =mysql_query($stmt, $con);
				
				if($rs === FALSE) {
					die(mysql_error()); // TODO: better error handling
				}
				
			
	/* 			
				echo "<table border='1' >";
				echo
					"<tr>
				<th>번호</th>
				<th>이름</th>
				<th>내용</th>
				<th>이메일</th>
				<th>날짜</th>
				</tr>
				"; */
					
				$response =array();
				$response["success"]=false;
				
			if($row=mysql_fetch_array($rs)){
				
				$response["success"]=true;
				$response["userID"]=$row[userID];
				$response["userPassword"]=$row[userPassword];
				$response["userName"]=$row[userName];
				$response["userAge"]=$row[userAge];
			/* 	echo "
				<tr>
				<td>$row[userID]</td>
				<td>$row[userPassword] </td>
				<td>$row[userName] </td>
				<td>$row[userAge]</td>
				<td></td>
					
				</tr>"; */
				
			}
			
			
			echo json_encode($response);

			mysql_close();
			
			
		}
		

	}else{
		//echo "no - 연결 실패 하였습습니다.";
	}
	
	

	
	


?>

 

 

 

  2. List.php  



<?php 

	//http://braverokmc2.dothome.co.kr/Login.php?userID=hong&userPassword=1111
	
	
	/* mysql_connect('localhost', 'mysql_user', 'mysql_password'); */
	$con =mysql_connect("localhost", "braverokmc2", "ehtjrhks5382");
	
	
	/* 	3. Mysql 입출력 인코딩을 지정
	 Mysql 연동을 한다면 입출력 인코딩이 달라서가 원인이 될 수 있다고 합니다.
	아래 3줄의 소스를 추가함으로써 해결하였습니다.
	
	출처: http://jhrun.tistory.com/140 [JHRunning] */
	
	mysql_query("set session character_set_connection=utf8;");
	
	mysql_query("set session character_set_results=utf8;");
	
	mysql_query("set session character_set_client=utf8;");	



	mysql_set_charset("utf8");//sql 에서 한글 깨짐
	$stmt ="select * from braverokmc2.USER ";
	$rs =mysql_query($stmt, $con);
	$response =array();
	
	while($row =mysql_fetch_array($rs)){
		array_push($response, array("userID" =>$row[0], "userPassword"=>$row[1],
			"userName"=>$row[2],  "userAge" =>$row[3] ) );
	}
	
	echo json_encode(array("response" =>$response));
	
	mysql_close($con);
	
	

?>

 

 

  3.Register.php  

<?php 

/* http://braverokmc2.dothome.co.kr/Register.php?userID=q1&userPassword=1111&userName=김길&userAge=89 */

	$con =mysql_connect("localhost", "braverokmc2", "ehtjrhks5382");
	
	
/* 	3. Mysql 입출력 인코딩을 지정
	Mysql 연동을 한다면 입출력 인코딩이 달라서가 원인이 될 수 있다고 합니다.
	아래 3줄의 소스를 추가함으로써 해결하였습니다.
	
	출처: http://jhrun.tistory.com/140 [JHRunning] */
	
	mysql_query("set session character_set_connection=utf8;");
	
	mysql_query("set session character_set_results=utf8;");
	
	mysql_query("set session character_set_client=utf8;");
	
	
	
	
	
	mysql_set_charset("SET NAMES utf8");
	if($con==true){
	
		//echo "연결";

		//Injection 방어
		$_POST = array_map('mysql_escape_string', $_POST);
		$_GET=array_map('mysql_escape_string', $_GET);
		
		if(isset($_POST["userID"])){
			$userID =$_POST["userID"];
			$userPassword=$_POST["userPassword"];
			$userName=$_POST["userName"];
			$userAge=$_POST["userAge"];
			
		}else if(isset($_GET["userID"])	){
			$userID =$_GET["userID"];
			$userPassword=$_GET["userPassword"];
			$userName=$_GET["userName"];
			$userAge=$_GET["userAge"];
		}

	/* 	//한글 인코딩 확인 후 utf8 아니 면 utf8 로 변경
		$enc=mb_detect_encoding($userName, array("UTF-8", "EUC-KR", "SJIS"));
		if($userName !="UTF-8"){
			$userName=iconv($enc, "UTF-8", $userName);
		}	
		
		 *
		 *
		 */
		$stmt= "insert into braverokmc2.USER values ( '$userID', '$userPassword', '$userName' , $userAge  ) ";
		mysql_query( $stmt);
		
		
		
	/* 	mysqli_stmt_bind_param($statement, "sssi", $userID, $userPassword, $userName, $userAge);
		mysqli_stmt_execute($statement);
		 */
		$response=array();
		$response["success"] =true;
		
		//echo $userName;
		echo json_encode($response);

	}

?>



 

 

 

  4.Delete.php  

 

<?php 


	//http://braverokmc2.dothome.co.kr/Login.php?userID=hong&userPassword=1111
	//http://braverokmc2.dothome.co.kr/Delete.php?userID=g7
	
	/* mysql_connect('localhost', 'mysql_user', 'mysql_password'); */
	$con =mysql_connect("localhost", "braverokmc2", "ehtjrhks5382");
	
	
	/* 	3. Mysql 입출력 인코딩을 지정
	 Mysql 연동을 한다면 입출력 인코딩이 달라서가 원인이 될 수 있다고 합니다.
	아래 3줄의 소스를 추가함으로써 해결하였습니다.
	
	출처: http://jhrun.tistory.com/140 [JHRunning] */
	
	mysql_query("set session character_set_connection=utf8;");
	
	mysql_query("set session character_set_results=utf8;");
	
	mysql_query("set session character_set_client=utf8;");
	
	if($con){
		
		//sql Injection 
		//$_POST = array_map('mysql_escape_string', $_POST);
		//$_GET=array_map('mysql_escape_string', $_GET);
		
		
/* 		$userID=null;
		if(isset($_GET["userID"])){
			$userID =$_GET["userID"];
				
		}else if(isset($_POST["userID"])){
			$userID =$_POST["userID"];
			
		} */
		
		
		$userID =$_POST["userID"];
		
		$statement = "delete from braverokmc2.USER where userID = '$userID' " ;
		mysql_query($statement);
			
		$response=array();
		$response["success"] =true;
			
		echo json_encode($response);
		
		
	/* 	$statement="select * from braverokmc2.USER where userID ='$userID' ";
		$result=mysql_query($statement);
		$row =mysql_fetch_array($result);
		//셀렉트로 검색해서 아이디가 존재하면 삭제 후 succs 반환
		if(isset($row[0])){
			
			$statement = "delete from braverokmc2.USER where userID = '$userID' " ;
			$result=mysql_query($statement);
			
			$response=array();
			$response["success"] =true;
			
			echo json_encode($response);
			
		}else{
			
			echo "error";
		} */
		/* $response["success"] =true;
			
		echo json_encode($response); */
	}
	

?>

 

 

  < App  >

 

 

  compile 'com.android.volley:volley:1.0.0'

 

 

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.volley:volley:1.0.0'
    testCompile 'junit:junit:4.12'
}

 

<  AndroidMainfest.xml  >

  <uses-permission android:name="android.permission.INTERNET"/>

 

 

 

 

  < class  >  

 

 1. DelteRequst 

package kr.co.dothome.braverokmc.managerment;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by choi on 2017-05-09.
 */

public class DeleteRequest extends StringRequest{

    final static private String URL="http://braverokmc2.dothome.co.kr/Delete.php";
    private Map<String, String> parameter;

    public DeleteRequest(String userID,
                         Response.Listener<String> listener) {

        super(Method.POST, URL, listener, null);

        try {
            parameter=new HashMap<>();
            parameter.put("userID", userID);

        }catch (Exception e){
            e.printStackTrace();
        }

    }

    @Override
    protected Map<String, String> getParams()  {
        return parameter;
    }


}

 

 

 2. LoginAcitivity

package kr.co.dothome.braverokmc.managerment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

//로그인 초기 화면
public class LoginActivity extends AppCompatActivity {


    EditText idText, passwordText;
    Button loginButton;

    TextView registerBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_main);


        idText =(EditText)findViewById(R.id.idText);
        passwordText =(EditText)findViewById(R.id.pswordText);
        registerBtn =(TextView)findViewById(R.id.registerBtn);
        loginButton=(Button)findViewById(R.id.loginButton);



        registerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(LoginActivity.this, RegisterActivity.class);
                startActivity(intent);
            }
        });


        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String userID=idText.getText().toString();
                final String userPassword=passwordText.getText().toString();


                Response.Listener<String> responseListenser =new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try{

                            JSONObject jsoneRessponse=new JSONObject(response);
                            boolean succcess=jsoneRessponse.getBoolean("success");
                            if(succcess){
                                String userID= jsoneRessponse.getString("userID");
                                String userPassword=jsoneRessponse.getString("userPassword");
                                Intent intent=new Intent(LoginActivity.this, MainActivity.class);
                                intent.putExtra("userID", userID);
                                intent.putExtra("userPassword", userPassword);
                                LoginActivity.this.startActivity(intent);
                            }else{
                                AlertDialog.Builder builder=new AlertDialog.Builder(LoginActivity.this);
                                builder.setMessage("로그인에 실패하였습니다.");
                                builder.setNegativeButton("다시 시도", null);
                                builder.create();
                                builder.show();
                            }

                        }catch(Exception e){

                        }

                    }
                };

                LoginRequest loginRequest= new LoginRequest(userID, userPassword, responseListenser);
                RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
                queue.add(loginRequest);



            }
        });

    }
}









 

 

 3. LoginRequest

package kr.co.dothome.braverokmc.managerment;


import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by choi on 2017-05-02.
 */

public class LoginRequest extends StringRequest {

    final static private String URL="http://braverokmc2.dothome.co.kr/Login.php";

    private Map<String, String> parameters;

/*    public RegisterRequest(int method, String url,
                           Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(method, url, listener, errorListener);
    }*/

    public LoginRequest(String userID, String userPassword,
                        Response.Listener<String> listener){

        super(Method.POST, URL, listener, null);
        try {
            //한글 깨짐 방지
          //  String st=URLEncoder.encode(userName, "UTF-8");

            parameters=new HashMap<>();
            parameters.put("userID", userID);
            parameters.put("userPassword", userPassword);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    @Override
    protected Map<String, String> getParams() {
        return parameters;
    }


}



 

 

 

 4. MainActivity

package kr.co.dothome.braverokmc.managerment;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;


//로그인 성공시
public class MainActivity extends AppCompatActivity {


    TextView idText, pswordText, welcome;
    Button manageMentButton;
    String userID, userPassword,message;
    ArrayList<MemberDTO> members ;
    StringBuffer stringBuffer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        idText =(TextView)findViewById(R.id.idText);
        pswordText =(TextView)findViewById(R.id.pswordText);
        welcome=(TextView)findViewById(R.id.welcome);

        manageMentButton=(Button)findViewById(R.id.manageMentButton);


        manageMentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new BackgroundTask().execute();
            }
        });


        Intent intent=getIntent();
        if(intent!=null){
            userID=intent.getStringExtra("userID");
            userPassword=intent.getStringExtra("userPassword");
            message ="환영 합니다. " + userID + "님!";

            idText.setText(userID);
            pswordText.setText(userPassword);
            welcome.setText(message);
        }


        if(!userID.equals("admin")){
            manageMentButton.setVisibility(View.GONE);
        }


    }


    //실제 회원 목록 가져오기,, AsyncTask 이용 또는 스레드 사용

    class BackgroundTask extends AsyncTask<Void, Void,  String>{

        String target;

        @Override
        protected void onPreExecute() {
            target="http://braverokmc2.dothome.co.kr/List.php";
        }


        @Override
        protected String doInBackground(Void... params) {

            InputStream is=null;
            InputStreamReader isr =null;
            BufferedReader reader=null;
            stringBuffer =new StringBuffer();


            try{

                URL url =new URL(target);
                HttpURLConnection httpURLConnection =(HttpURLConnection)url.openConnection();

                httpURLConnection.setConnectTimeout(10000);
                if(httpURLConnection.getResponseCode()==HttpURLConnection.HTTP_OK){

                    is=httpURLConnection.getInputStream();
                    reader=new BufferedReader(new InputStreamReader(is));

                    while(true){
                        String stringLine =reader.readLine();
                        if(stringLine==null)break;
                        stringBuffer.append(stringLine+"\n");
                    }

                }

                parsing(stringBuffer.toString());
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                try {
                    if(reader!=null) reader.close();
                    if(isr!=null) isr.close();
                    if(is!=null)is.close();

                }catch (Exception e){
                    e.printStackTrace();
                }

            }
            return null;
        }


        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }


        @Override
        protected void onPostExecute(String s) {

            Intent intent =new Intent(MainActivity.this, ManagementActivity.class);
/*

            Bundle bundle =new Bundle();
            bundle.putSerializable("members", members);
            intent.putExtra("members",  bundle);
*/

            //
            intent.putExtra("members", stringBuffer.toString());
            intent.putExtra("saveList", stringBuffer.toString());
            startActivity(intent);

        }

    }


    public void parsing(String data){

        members=new ArrayList<>();
        try{
            JSONObject jsonObject =new JSONObject(data);
            JSONArray jsonArray=new JSONArray(jsonObject.getString("response"));

            //arrayList 클리어
            members.clear();

            for(int i=0; i<jsonArray.length(); i++){

                MemberDTO member=new MemberDTO();

                JSONObject jsonObject1=(JSONObject)jsonArray.get(i);
                member.setUserID(jsonObject1.getString("userID"));
                member.setUserName(jsonObject1.getString("userName"));
                member.setUserPassword(jsonObject1.getString("userPassword"));
                member.setUserAge(jsonObject1.getInt("userAge"));

                if(!member.getUserID().equals("admin")) {
                    members.add(member);
                }
            }

        }catch (Exception e){
            e.printStackTrace();
        }

    }





}

 

 5. ManagementActivity

package kr.co.dothome.braverokmc.managerment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

public class ManagementActivity extends AppCompatActivity {

    //TextView userListTextView;
    private ListView listView;

    private ArrayList<MemberDTO> members;
    private ArrayList<MemberDTO> saveList;
    private UserListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_management);


      //  userListTextView=(TextView)findViewById(userListTextView);
        listView=(ListView)findViewById(R.id.listView);


        Intent intent=getIntent();

        if(intent!=null) {

     /*        Bundle membersBundle = intent.getBundleExtra("members");
             membsers=(ArrayList<MemberDTO>) membersBundle.get("members");
*/
            //검색처리에서 members 를 클리어 할 때 saveList 도 클리어 되는 현상 때문에
            //데이터를 다르게 처리 하였다.
            //=>오류 Bundle 에서 오류 가 있어서 변경


            members=new ArrayList<>();
            saveList = new ArrayList<>();

            String membersData =intent.getStringExtra("members");
            String saveListData =intent.getStringExtra("saveList");
            members=parsing(membersData);
            saveList=parsing(saveListData);


            adapter =new UserListAdapter(ManagementActivity.this, members, this, saveList);
            listView.setAdapter(adapter);


/*
            StringBuilder builder = new StringBuilder();
            for (MemberDTO dto : membsers) {

                builder.append("아이디 : "  + dto.getUserID()+"\n");
                builder.append( "이름 : " + dto.getUserName() +"\n");
                builder.append("패스워드 : " + dto.getUserPassword() +"\n");
                builder.append("나이 : " +dto.getUserAge() + "\n");
                builder.append("--------------------------------------\n\n\n");

            }
*/


        }


        EditText search =(EditText)findViewById(R.id.search);
        search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

               searchUser(s.toString());

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });



    }


    public void searchUser(String search){
        //검색에 글자를 입력하면 members 리스트는 제거
        members.clear();

      Toast.makeText(ManagementActivity.this, "memberSize : " + members.size() + " ,  saverList Size :" +
                saveList.size()+" ", Toast.LENGTH_SHORT).show();

        //saver List 에서 검색 목록을 찾은 후 이것을
        //members 에 데이터를 담는다.
        for(int i=0; i<saveList.size(); i++){

            if(saveList.get(i).getUserID().contains(search)){
                members.add(saveList.get(i));
                Log.i("TT", String.valueOf(i));
                //Toast.makeText(ManagementActivity.this, String.valueOf(i), Toast.LENGTH_SHORT).show();
            }
        }

        // 데이터가 갱신 되었음을 어댑터에 알린다.
        adapter.notifyDataSetChanged();

    }



    public  ArrayList<MemberDTO> parsing(String data) {

        ArrayList<MemberDTO> arrayList=new ArrayList<>();
         try {
            JSONObject jsonObject = new JSONObject(data);
            JSONArray jsonArray = new JSONArray(jsonObject.getString("response"));


            for (int i = 0; i < jsonArray.length(); i++) {

                MemberDTO member = new MemberDTO();

                JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
                member.setUserID(jsonObject1.getString("userID"));
                member.setUserName(jsonObject1.getString("userName"));
                member.setUserPassword(jsonObject1.getString("userPassword"));
                member.setUserAge(jsonObject1.getInt("userAge"));

                if (!member.getUserID().equals("admin")) {
                    arrayList.add(member);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return arrayList;
    }


}







 

 

 6. MemberDTO

package kr.co.dothome.braverokmc.managerment;

import java.io.Serializable;

/**
 * Created by choi on 2017-05-08.
 */

public class MemberDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    private String userID;
    private String userPassword;
    private String userName;
    private Integer userAge;


    public MemberDTO() {
    }

    public MemberDTO(String userID, String userPassword, String userName, Integer userAge) {
        this.userID = userID;
        this.userPassword = userPassword;
        this.userName = userName;
        this.userAge = userAge;
    }

    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Integer getUserAge() {
        return userAge;
    }

    public void setUserAge(Integer userAge) {
        this.userAge = userAge;
    }

    @Override
    public String toString() {
        return "MemberDTO{" +
                "userID='" + userID + '\'' +
                ", userPassword='" + userPassword + '\'' +
                ", userName='" + userName + '\'' +
                ", userAge=" + userAge +
                '}';
    }
}

 

 

 7. RegisterActivity

package kr.co.dothome.braverokmc.managerment;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.InputFilter;
import android.text.Spanned;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

import java.util.regex.Pattern;

public class RegisterActivity extends AppCompatActivity {

    EditText idText, pswordText, nameText, ageText;
    Button registerButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        idText =(EditText)findViewById(R.id.idText);
        pswordText =(EditText)findViewById(R.id.pswordText);
        nameText =(EditText)findViewById(R.id.nameText);
        ageText =(EditText)findViewById(R.id.ageText);

        idText.setFilters(new InputFilter[] {filter});



        registerButton=(Button)findViewById(R.id.registerbutton);

        registerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userID=idText.getText().toString();
                String userPassword=pswordText.getText().toString();
                String userName=nameText.getText().toString();
                int userAge=Integer.parseInt(ageText.getText().toString());

                Response.Listener<String> responseListener=new Response.Listener<String>(){

                    @Override
                    public void onResponse(String response) {
                        try{
                            JSONObject jsonResponse=new JSONObject(response);
                            boolean success=jsonResponse.getBoolean("success");

                            if(success){
                                AlertDialog.Builder builder=new AlertDialog.Builder(RegisterActivity.this);
                                builder.setMessage("회원 등록에 성공했습니다.")
                                        .setPositiveButton("확인", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                             /*   Intent intent=new Intent(RegisterActivity.this, LoginActivity.class);
                                                RegisterActivity.this.startActivity(intent);*/
                                             finish();
                                            }
                                        })
                                        .create()
                                        .show();

                            }else{
                                AlertDialog.Builder builder=new AlertDialog.Builder(RegisterActivity.this);
                                builder.setMessage("회원 등록에 실패했습니다.")
                                        .setNegativeButton("다시 시도", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                Intent intent=new Intent(RegisterActivity.this, RegisterActivity.class);
                                                RegisterActivity.this.startActivity(intent);
                                            }
                                        })
                                        .create()
                                        .show();
                            }

                        }catch (Exception e){
                            e.printStackTrace();
                        }

                    }
                };

                RegisterRequest registerRequest=new RegisterRequest(userID, userPassword,
                        userName,userAge, responseListener);
                RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);

                queue.add(registerRequest);
            }
        });
    }


    // 영문만 허용 (숫자 포함)

    protected InputFilter filter= new InputFilter() {

        public CharSequence filter(CharSequence source, int start, int end,

                                   Spanned dest, int dstart, int dend) {



            Pattern ps = Pattern.compile("^[a-zA-Z0-9]+$");

            if (!ps.matcher(source).matches()) {

                return "";

            }

            return null;

        }

    };

    // 한글만 허용
    public InputFilter filterKor = new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end,

                                   Spanned dest, int dstart, int dend) {



            Pattern ps = Pattern.compile("^[ㄱ-가-힣]+$");

            if (!ps.matcher(source).matches()) {

                return "";

            }

            return null;

        }

    };






}

 

 

 8. RegisterRequest

package kr.co.dothome.braverokmc.managerment;


import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by choi on 2017-05-02.
 */

public class RegisterRequest extends StringRequest {

    final static private String URL="http://braverokmc2.dothome.co.kr/Register.php";

    private Map<String, String> parameters;

/*    public RegisterRequest(int method, String url,
                           Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(method, url, listener, errorListener);
    }*/

    public RegisterRequest(String userID, String userPassword, String userName, int userAge,
                           Response.Listener<String> listener){

        super(Method.POST, URL, listener, null);
        try {
            //한글 깨짐 방지
          //  String st=URLEncoder.encode(userName, "UTF-8");

            parameters=new HashMap<>();
            parameters.put("userID", userID);
            parameters.put("userPassword", userPassword);
            parameters.put("userName", userName);
            parameters.put("userAge", userAge +"");


        } catch (Exception e) {
            e.printStackTrace();
        }


    }


    @Override
    protected Map<String, String> getParams() {
        return parameters;
    }


}



 

 

 9. UserListAdapter

package kr.co.dothome.braverokmc.managerment;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by choi on 2017-05-08.
 */

public class UserListAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<MemberDTO> memberList;
    private LayoutInflater inflater;

    private Activity activity;
    private ArrayList<MemberDTO> saveList;


    public UserListAdapter(Context mContext, ArrayList<MemberDTO> memberList, Activity parentAtivity,
                           ArrayList<MemberDTO> saveList
                           ) {
        this.mContext = mContext;
        this.memberList = memberList;
        inflater=(LayoutInflater)mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        activity=parentAtivity;
        this.saveList=saveList;
    }

    @Override
    public int getCount() {
        return memberList.size();
    }

    @Override
    public Object getItem(int position) {
        return memberList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {

        if(convertView==null){
            convertView=inflater.inflate(R.layout.user, parent, false);
        }

         TextView userID =(TextView)convertView.findViewById(R.id.userID);
         TextView userName =(TextView)convertView.findViewById(R.id.userName);
         TextView userPassword=(TextView)convertView.findViewById(R.id.userPassword);
         TextView userAge =(TextView)convertView.findViewById(R.id.userAge);

        userID.setText("아이디 : " +memberList.get(position).getUserID());
        userName.setText("이름 : " +memberList.get(position).getUserName());
        userPassword.setText("패스워드 : "+ memberList.get(position).getUserPassword());
        userAge.setText("나이 : " + memberList.get(position).getUserAge());



        Button button =(Button)convertView.findViewById(R.id.deleteButton);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

               // Toast.makeText(activity, "e" +position, Toast.LENGTH_SHORT).show();


                Response.Listener<String> responseListener =new Response.Listener<String>(){

                    @Override
                    public void onResponse(String response) {

                        try{
                            JSONObject jsonResposne =new JSONObject(response);
                            boolean success=jsonResposne.getBoolean("success");
                            if(success){

                                //검색 처리를 위한 saveList 제거
                                //현재 memberList i 값과 검색 처리를 위한 i 값이 다르다.
                                //즉 memberList 는 검색 결과 데이터 만 담겨 있고
                                //saverList 는 전체 데이터가 담겨 있기 때문이다.
                                for(int i=0; i<saveList.size(); i++){
                                    if(saveList.get(i).getUserID().equals(
                                            memberList.get(position).getUserID().toString())){
                                        saveList.remove(i);
                                        break;
                                    }
                                }

                                //ArrayList 에서 해당부분 제거
                                memberList.remove(position);

                                //어댑터에 알려줌
                                notifyDataSetChanged();
                            }

                        }catch (Exception e){
                            e.printStackTrace();
                        }

                    }
                };

               // Toast.makeText(activity, userID.getText().toString(), Toast.LENGTH_SHORT).show();

                DeleteRequest deleteRequest =new DeleteRequest(memberList.get(position).getUserID().toString(), responseListener);
                RequestQueue queue= Volley.newRequestQueue(activity);
                queue.add(deleteRequest);


            }
        });


/*
        if((position%2)==1){
          //  convertView.setBackgroundColor(0xffff8800);

        }else {
            convertView.setBackgroundColor(0xff748790);
        }
*/

        return convertView;
    }




}




 

 

 

 

 

 

 <  drawable >   

 

 1. button1.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" android:drawable="@drawable/button2_login" />
    <item android:state_hovered="true" android:drawable="@drawable/button2_login" />
    <item android:drawable="@drawable/button_login"/>

</selector>

 

 

 

 2. button2_login.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <solid android:color="@color/colorOrange_dark"/>

    <padding
        android:left="10dp"
        android:top="4dp"
        android:right="10dp"
        android:bottom="4dp"
        />

    <corners
        android:radius="10dp" />


</shape>

 

 

 3.button_login.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <solid android:color="@color/colorOrange_light"/>

    <padding
        android:left="10dp"
        android:top="4dp"
        android:right="10dp"
        android:bottom="4dp"
        />

    <corners
        android:radius="10dp" />


</shape>

 

 

 4.edittext_login.xml

 

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <solid android:color="@color/colorWhite"/>

    <padding
        android:left="10dp"
        android:top="4dp"
        android:right="10dp"
        android:bottom="4dp"
        />

    <corners
        android:radius="10dp" />


</shape>

 

 

 

 5.textview_main.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <solid android:color="@color/colorAccent"/>

    <padding
        android:left="10dp"
        android:top="4dp"
        android:right="10dp"
        android:bottom="4dp"
        />




</shape>

 

 

 

 

  < layout >  

 

 1. activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/colorPrimary"
    tools:context="kr.co.dothome.braverokmc.managerment.MainActivity">

    <TextView
        android:id="@+id/welcome"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1"
        android:textColor="@color/colorWhite"
        android:layout_marginTop="10dp"
        />

    <TextView
        android:id="@+id/idTextText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="당신의 아이디"

        android:background="@drawable/textview_main"
        android:textColor="@color/colorWhite"
        android:layout_marginTop="10dp"
        />

    <TextView
        android:id="@+id/idText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textColor="@color/colorWhite"
        android:layout_marginTop="10dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1" />


    <TextView
        android:id="@+id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="당신의 비밀번호"
        android:background="@drawable/textview_main"
        android:textColor="@color/colorWhite"
        android:layout_marginTop="10dp"
        />


    <TextView
        android:id="@+id/pswordText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textColor="@color/colorWhite"
        android:layout_marginTop="10dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1" />

    <Button
        android:id="@+id/manageMentButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="회원관리"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/button_login"
        android:layout_marginTop="30dp"
        android:textColor="#ffffff"
        />


</LinearLayout>

 

 

 2. activity_management.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#d1d1d1">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/search"
        android:hint="검색"
        />


    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listView"
        android:layout_marginTop="10dp"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp"
        android:dividerHeight="10dp"
        android:divider="#d1d1d1">


    </ListView>






</LinearLayout>

 

 

 3. activity_register.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="kr.co.dothome.braverokmc.managerment.RegisterActivity">

    <EditText
        android:id="@+id/idText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:ems="10"
        android:hint="아이디"
        android:inputType="" />

    <EditText
        android:id="@+id/pswordText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="비밀번호"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/nameText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="18dp"
        android:ems="10"
        android:hint="이름"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/ageText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="나이"
        android:inputType="number" />

    <Button
        android:id="@+id/registerbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:text="회원가입"
        android:textColor="@color/colorWhite"
        android:layout_marginTop="10dp"
        android:background="@drawable/button_login"
        />



</LinearLayout>

 

 

 4. login_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="16dp"
    android:paddingLeft="20dp"
    android:paddingRight="24dp"
    android:paddingTop="16dp"
    android:background="@color/colorPrimary"
    tools:context="kr.co.dothome.braverokmc.managerment.LoginActivity"
    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="로그인 화면"
        android:textColor="@color/colorWhite"
        android:textSize="30sp"
        android:textStyle="bold"
        android:layout_marginBottom="50dp"
        tools:ignore="HardcodedText"
        android:layout_weight="0.04" />


    <EditText
        android:id="@+id/idText"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:background="@drawable/edittext_login"
        android:ems="10"
        android:hint="아이디"
        android:inputType="textPersonName"
        android:textColor="@color/colorGray"
        android:textColorHint="@color/colorGray" />

    <EditText
        android:id="@+id/pswordText"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/idText"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/edittext_login"
        android:ems="10"
        android:hint="비밀번호"
        android:inputType="textPassword"
        android:textColor="@color/colorGray"
        android:textColorHint="@color/colorGray" />

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/text1"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:background="@drawable/button1"
        android:text="@string/app_login"
        android:textColor="@color/colorWhite"
        android:textSize="24sp"
        tools:ignore="ObsoleteLayoutParam"

        />


    <TextView
        android:id="@+id/registerBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/loginButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:text="회원가입"
        android:textAlignment="center"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textSize="24sp"
        android:textColor="@color/colorWhite"
        />




</LinearLayout>

 

 

 5 . user.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:background="#ffffff"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:layout_weight="6"
        android:layout_gravity="center_vertical"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/userID"
            android:text="아이디"
            android:textSize="20dp"
            android:textColor="#00a7f5"
            />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/userPassword"
            android:text="비밀번호"
            android:textSize="15dp"
            android:textColor="#f92a3f"
            />



        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/userName"
            android:text="이름"
            android:textSize="26dp"
            android:textColor="#000000"
            />



        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/userAge"
            android:text="나이"
            android:textSize="18dp"
            android:textColor="#775533"
            />


    </LinearLayout>
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:layout_weight="1"
            android:layout_gravity="center_vertical"
            >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/deleteButton"
                android:text="삭제"
                android:textColor="#fff"
                android:textSize="18dp"
                android:background="#00a7f5"
                />


        </LinearLayout>



</LinearLayout>

 

 

 

 

 <values> 

 

 1. color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#039BE5</color>
    <color name="colorPrimaryDark">#0277B0</color>
    <color name="colorAccent">#2478FF</color>
    <color name="colorWhite">#ffffff</color>
    <color name="colorGray">#909090</color>
    <color name="colorOrange_light">#FFBB33</color>
    <color name="colorOrange_dark">#FF8800</color>

</resources>

 

 

 2. string.xml

<resources>
    <string name="app_name">Managerment</string>
    <string name="app_login">로그인</string>
</resources>

 

 

 3. styles.xml

 

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>


</resources>

 

 

 

 

 

android

 

about author

PHRASE

Level 1  머나먼나라

댓글 ( 4)

댓글 남기기

작성