First program with more than 1 activity.
authorgumartinm <gu.martinm@gmail.com>
Thu, 24 Nov 2011 00:53:07 +0000 (01:53 +0100)
committergumartinm <gu.martinm@gmail.com>
Thu, 24 Nov 2011 00:53:07 +0000 (01:53 +0100)
First steps with a http connection. Trying to use my WebService

Android/Testing/Test1/AndroidManifest.xml
Android/Testing/Test1/default.properties [new file with mode: 0644]
Android/Testing/Test1/gen/de/android/test1/R.java
Android/Testing/Test1/res/layout/main.xml
Android/Testing/Test1/res/layout/main2.xml [new file with mode: 0644]
Android/Testing/Test1/res/values/strings.xml
Android/Testing/Test1/src/de/android/test1/NextActivity.java [new file with mode: 0644]
Android/Testing/Test1/src/de/android/test1/Test1Activity.java

index 0084493..2ff5f86 100644 (file)
@@ -4,20 +4,30 @@
     android:versionCode="1"
     android:versionName="1.0" >
 
-    <uses-sdk android:minSdkVersion="14" />
+    <uses-sdk android:minSdkVersion="13" />
 
     <application
         android:icon="@drawable/ic_launcher"
         android:label="@string/app_name" >
         <activity
             android:label="@string/app_name"
-            android:name=".Test1Activity" >
+            android:name=".Test1Activity" 
+            android:screenOrientation="portrait" 
+            android:configChanges="touchscreen|keyboard"
+            android:theme="@android:style/Theme.Black" 
+            android:permission="android.permission.ACCESS_FINE_LOCATION" 
+            android:launchMode="standard">
             <intent-filter >
                 <action android:name="android.intent.action.MAIN" />
-
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+        
+        <activity 
+                       android:label="@string/app_name"
+                       android:name=".NextActivity" >
+               </activity>
+               
     </application>
 
 </manifest>
\ No newline at end of file
diff --git a/Android/Testing/Test1/default.properties b/Android/Testing/Test1/default.properties
new file mode 100644 (file)
index 0000000..ac9e1a0
--- /dev/null
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-13
index 34d4ccc..2e84069 100644 (file)
@@ -14,14 +14,24 @@ public final class R {
         public static final int ic_launcher=0x7f020000;
     }
     public static final class id {
-        public static final int ok=0x7f050000;
+        public static final int cancel_button=0x7f050005;
+        public static final int frameLayout1=0x7f050000;
+        public static final int frameLayout2=0x7f050003;
+        public static final int login_button=0x7f050004;
+        public static final int password=0x7f050002;
+        public static final int username=0x7f050001;
     }
     public static final class layout {
         public static final int main=0x7f030000;
+        public static final int main2=0x7f030001;
     }
     public static final class string {
         public static final int app_name=0x7f040001;
-        public static final int button_ok=0x7f040002;
+        public static final int button_cancel=0x7f040006;
+        public static final int button_login=0x7f040004;
+        public static final int button_ok=0x7f040005;
         public static final int hello=0x7f040000;
+        public static final int password=0x7f040003;
+        public static final int username=0x7f040002;
     }
 }
index a372bc4..15264ad 100644 (file)
@@ -1,21 +1,53 @@
 <?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:gravity="right"
-    android:orientation="vertical" >
-
-    <TextView
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/hello" />
-
-    <Button
-        android:id="@+id/ok"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="right"
-        android:onClick="onClickOk"
-        android:text="@string/button_ok" />
+    android:layout_width="match_parent" 
+    android:layout_height="match_parent" 
+    android:orientation="vertical" 
+    android:weightSum="1">
+    
+    <FrameLayout 
+       android:id="@+id/frameLayout1" 
+       android:layout_width="match_parent" android:layout_height="70dp">
+    </FrameLayout>
+           
+       <EditText
+               android:id="@+id/username"
+               android:singleLine="true"
+           android:layout_width="fill_parent"
+           android:layout_height="wrap_content" android:text="@string/username"/>
+       <TextView
+           android:layout_width="fill_parent"
+           android:layout_height="wrap_content"
+           android:text="Password:"
+           />
+       <EditText
+               android:id="@+id/password"
+               android:password="true"
+               android:singleLine="true"
+           android:layout_width="fill_parent"
+           android:layout_height="wrap_content"
+               android:text="@string/password"/>
+       <FrameLayout 
+               android:layout_width="match_parent" 
+               android:id="@+id/frameLayout2" 
+               android:layout_height="30dp">
+       </FrameLayout>
+       <Button
+               android:id="@+id/login_button"
+               android:onClick="onClickLogin"
+           android:layout_height="wrap_content" 
+           android:text="@string/button_login" 
+           android:layout_width="match_parent" 
+           android:layout_gravity="center"/>
+       <Button
+               android:id="@+id/cancel_button"
+               android:onClick="onClickCancel"
+               android:gravity="right" 
+           android:layout_height="wrap_content" 
+           android:layout_width="wrap_content" 
+           android:layout_gravity="right" 
+           android:text="@string/button_cancel"/>
+        
     
 </LinearLayout>
\ No newline at end of file
diff --git a/Android/Testing/Test1/res/layout/main2.xml b/Android/Testing/Test1/res/layout/main2.xml
new file mode 100644 (file)
index 0000000..5203a2b
--- /dev/null
@@ -0,0 +1,13 @@
+<?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:gravity="right"
+    android:orientation="vertical" >
+
+    <TextView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/hello" />
+    
+</LinearLayout>
\ No newline at end of file
index 35276bb..5519645 100644 (file)
@@ -3,7 +3,14 @@
 
     <string name="hello">Hello World, Test1Activity!</string>
     <string name="app_name">Test1</string>
+    <string name="username">Username</string>
+    <string name="password">Password</string>
+    <string name="button_login">Log In</string>
     <string name="button_ok">OK</string>
+    <string name="button_cancel">Cancel</string>
+    
+    
+    
     
 
 </resources>
\ No newline at end of file
diff --git a/Android/Testing/Test1/src/de/android/test1/NextActivity.java b/Android/Testing/Test1/src/de/android/test1/NextActivity.java
new file mode 100644 (file)
index 0000000..2242fe3
--- /dev/null
@@ -0,0 +1,13 @@
+package de.android.test1;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class NextActivity extends Activity {
+        /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main2);
+    }
+}
index 420eb67..117af92 100644 (file)
@@ -1,8 +1,15 @@
 package de.android.test1;
 
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+
 import android.app.Activity;
+import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
+import android.widget.EditText;
 
 public class Test1Activity extends Activity {
     /** Called when the activity is first created. */
@@ -13,6 +20,36 @@ public class Test1Activity extends Activity {
     }
     
     public void onClickOk(View v) {
+       Intent i = new Intent(Test1Activity.this, NextActivity.class);
+       this.startActivity(i);
+    }
+    
+    public void onClickLogin(View v) {
+       HttpClient httpclient = new DefaultHttpClient();
+       
+       //RESTful WebService
+       HttpPost httppost = new HttpPost("http://10.208.184.41/userfront.php/api/51,32/0,5/gpsads.xml");
+       
+       EditText uname = (EditText)findViewById(R.id.username);
+        String username = uname.getText().toString();
         
+        EditText pword = (EditText)findViewById(R.id.password);
+        String password = pword.getText().toString();
+        
+        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
+        nameValuePairs.add(new BasicNameValuePair("username", username));
+        nameValuePairs.add(new BasicNameValuePair("password", password));
+        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
+
+
+
+
+
+       Intent i = new Intent(Test1Activity.this, NextActivity.class);
+       this.startActivity(i);
+    }
+    
+    public void onClickCancel(View v) {
+       finish();
     }
 }
\ No newline at end of file