Docstoc

Android_Login

Document Sample
Android_Login Powered By Docstoc
					Android Login
WebService를 이용하여 로그인하는 것을 구현하였다.


초기화면




로그인 실패 시
로그인 성공 시




로그인 성공 시 화면 전환
Intropage.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent" android:layout_height="fill_parent"
   android:orientation="vertical" android:id="@+id/intro_page"
   android:baselineAligned="false" android:background="@drawable/login">
   <LinearLayout android:layout_width="match_parent"
       android:layout_height="270dip"
       android:id="@+id/linearLayout2">
   </LinearLayout>
   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="120dip"
       android:id="@+id/linearLayout1"
       android:orientation="vertical">
       <EditText
              android:id="@+id/ET_ID"
              android:hint="Input ID"
              android:layout_width="200dip"
              android:layout_height="wrap_content"
              android:layout_gravity="right"
              android:layout_marginBottom="10dip"></EditText>
              <EditText
                     android:id="@+id/ET_PW"
                     android:hint="Input Password"
                     android:layout_width="200dip"
                     android:layout_height="wrap_content"
                     android:layout_gravity="right"></EditText>
   </LinearLayout>
   <Button
       android:background="@drawable/loginbtnimg"
       android:id="@+id/BTN_Login"
       android:layout_width="fill_parent"
       android:layout_height="50dip"></Button>
</LinearLayout>



Android_Prototype.java
package com.pt.Android_Prototype;

import   org.ksoap2.SoapEnvelope;
import   org.ksoap2.serialization.SoapObject;
import   org.ksoap2.serialization.SoapPrimitive;
import   org.ksoap2.serialization.SoapSerializationEnvelope;
import   org.ksoap2.transport.HttpTransportSE;

import   com.pt.Android_Prototype.R;
import   android.app.Activity;
import   android.content.Intent;
import   android.os.Bundle;
import   android.view.View;
import   android.view.View.OnClickListener;
import   android.widget.Button;
import   android.widget.EditText;
import   android.widget.Toast;

public class Android_Prototype extends Activity implements OnClickListener{
   /** Called when the activity is first created. */
   private static final String SOAP_ACTION = "http://tempuri.org/Login";
   private static final String METHOD_NAME = "Login";
   private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL =
                               "http://192.168.34.69/asps/Service1.asmx";
    private Button intro;
    private EditText inputId, inputPw;

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.intropage);

        inputId = (EditText)findViewById(R.id.ET_ID);
        inputPw = (EditText)findViewById(R.id.ET_PW);
        intro = (Button)findViewById(R.id.BTN_Login);
        intro.setOnClickListener(this);
    }

    public String PostData()
    {
       try {
              SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
              request.addProperty("m_id", inputId.getText().toString());
              request.addProperty("m_pw", inputPw.getText().toString());
              SoapSerializationEnvelope envelope =
                        new SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.dotNet = true;
              envelope.setOutputSoapObject(request);
              HttpTransportSE androidHttpTransport =
                                                 new HttpTransportSE(URL);
              androidHttpTransport.call(SOAP_ACTION, envelope);
              SoapPrimitive resultString =
                                    (SoapPrimitive) envelope.getResponse();
              return resultString.toString();
       } catch (Exception e) {
              Toast.makeText(Android_Prototype.this, e.getMessage(),
                                                              1000).show();
       }
       return null;
    }

    public void onClick(View v) {
       String result = PostData();
       if(Integer.parseInt(result) == 1)
       {
          Toast.makeText(Android_Prototype.this, "로그인 성공!",1000).show();
           ChangeWindow();
        }
        else if(Integer.parseInt(result) == 0)
        {
          Toast.makeText(Android_Prototype.this, "로그인 실패!", 1000).show();
        }
        else
        {
             ChangeWindow();
        }
    }
    public void ChangeWindow()
    {
       Intent intent = new Intent(Android_Prototype.this, MainPage.class);
       startActivity(intent);
    }
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.pt.Android_Prototype"
     android:versionCode="1"
     android:versionName="1.0">
   <uses-sdk android:minSdkVersion="8" />

   <application android:icon="@drawable/icon"
       android:label="@string/app_name"
       android:theme="@style/MyTheme">
       <activity android:name=".Android_Prototype"
                android:label="@string/app_name">
          <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER"   />
          </intent-filter>
       </activity>
       <activity android:name="MainPage">
              <intent-filter>
              <category android:name="android.intent.category.LAUNCHER"   />
          </intent-filter>
       </activity>
       <activity android:name="InputSchedule">
              <intent-filter>
              <category android:name="android.intent.category.LAUNCHER"   />
          </intent-filter>
       </activity>
       <activity android:name="Schedule">
              <intent-filter>
              <category android:name="android.intent.category.LAUNCHER"   />
          </intent-filter>
       </activity>
       <activity android:name="StatisticsView"
          android:label="type2"></activity>
   </application>
   <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:11
posted:10/28/2011
language:Korean
pages:5