Prechádzať zdrojové kódy

Initial commit for TwoActivitiesLifecycle project.

Cristian Tanas 11 rokov pred
rodič
commit
f62f80db6a

+ 31 - 0
TwoActivitiesLifecycle/AndroidManifest.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.example.twoactivitieslifecycle"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name="com.example.twoactivitieslifecycle.FirstActivity"
+            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="com.example.twoactivitieslifecycle.SecondActivity"
+            android:label="@string/title_activity_second" >
+        </activity>
+    </application>
+
+</manifest>

BIN
TwoActivitiesLifecycle/ic_launcher-web.png


BIN
TwoActivitiesLifecycle/res/drawable-hdpi/ic_launcher.png


BIN
TwoActivitiesLifecycle/res/drawable-mdpi/ic_launcher.png


BIN
TwoActivitiesLifecycle/res/drawable-xhdpi/ic_launcher.png


BIN
TwoActivitiesLifecycle/res/drawable-xxhdpi/ic_launcher.png


+ 30 - 0
TwoActivitiesLifecycle/res/layout-land/activity_first.xml

@@ -0,0 +1,30 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${packageName}.${activityClass}" >
+
+    <EditText
+        android:id="@+id/editText1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginTop="26dp"
+        android:layout_toLeftOf="@+id/button1"
+        android:ems="10"
+        android:hint="@string/form_info_hint"
+        android:inputType="text" >
+
+        <requestFocus />
+    </EditText>
+
+    <Button
+        android:id="@+id/button1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignBottom="@+id/editText1"
+        android:layout_alignParentRight="true"
+        android:text="@string/form_send_button" />
+
+</RelativeLayout>

+ 31 - 0
TwoActivitiesLifecycle/res/layout/activity_first.xml

@@ -0,0 +1,31 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${packageName}.${activityClass}" >
+
+    <EditText
+        android:id="@+id/editText1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginTop="26dp"
+        android:ems="10"
+        android:hint="@string/form_info_hint"
+        android:inputType="text" >
+
+        <requestFocus />
+    </EditText>
+
+    <Button
+        android:id="@+id/button1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/editText1"
+        android:layout_centerHorizontal="true"
+        android:layout_marginTop="18dp"
+        android:text="@string/form_send_button" />
+
+</RelativeLayout>

+ 15 - 0
TwoActivitiesLifecycle/res/layout/activity_second.xml

@@ -0,0 +1,15 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${packageName}.${activityClass}" >
+
+    <TextView
+        android:id="@+id/textView1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_centerVertical="true"
+        android:text="@string/hello_world" />
+
+</RelativeLayout>

+ 10 - 0
TwoActivitiesLifecycle/res/values-es/strings.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">TwoActivitiesLifecycle</string>
+    <string name="hello_world">Hola Barcelona</string>
+    <string name="form_info_hint">Introduce texto</string>
+    <string name="form_send_button">Enviame</string>
+    <string name="title_activity_second">SecondActivity</string>
+
+</resources>

+ 11 - 0
TwoActivitiesLifecycle/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
TwoActivitiesLifecycle/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 10 - 0
TwoActivitiesLifecycle/res/values/strings.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">TwoActivitiesLifecycle</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="form_info_hint">Write something</string>
+    <string name="form_send_button">Send me</string>
+    <string name="title_activity_second">SecondActivity</string>
+
+</resources>

+ 20 - 0
TwoActivitiesLifecycle/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 95 - 0
TwoActivitiesLifecycle/src/com/example/twoactivitieslifecycle/FirstActivity.java

@@ -0,0 +1,95 @@
+package com.example.twoactivitieslifecycle;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+
+public class FirstActivity extends Activity {
+	
+	private static final String LOG_TAG = "TWO_ACTIVITIES_LIFECYCLE";
+	
+	private EditText	sendInfoEditText;
+	private Button		sendMeButton;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Log.i(LOG_TAG, 
+    			"FIRST_ACTIVITY onCreate() The activity is not visible and about to be created.");
+        
+        setContentView(R.layout.activity_first);
+        
+        // Get a reference to the UI objects
+        sendInfoEditText = (EditText) findViewById(R.id.editText1);
+        sendMeButton = (Button) findViewById(R.id.button1);
+        
+        // Implement the Button's onClick functionality
+        sendMeButton.setOnClickListener(new OnClickListener() {
+			
+			@Override
+			public void onClick(View v) {
+				
+				// Get the text entered by the user
+				String enteredText = sendInfoEditText.getText().toString();
+				
+				// Create an Intent to start the new Activity
+				Intent gotoSecondActivityIntent = new Intent(
+						FirstActivity.this, 
+						SecondActivity.class);
+				
+				// Add the text entered by the user as an Intent extra
+				gotoSecondActivityIntent.putExtra("TEXT", enteredText);
+				
+				// Start SecondActivity
+				startActivity(gotoSecondActivityIntent);
+			}
+		});
+    }
+    
+    @Override
+    protected void onStart() {
+    	super.onStart();
+    	Log.i(LOG_TAG, 
+    			"FIRST_ACTIVITY onStart() The activity is visible and about to be started.");
+    }
+    
+    @Override
+    protected void onResume() {
+    	super.onResume();
+    	Log.i(LOG_TAG, 
+    			"FIRST_ACTIVITY onResume() The activity is visible and has focus (it is now \"resumed\")");
+    }
+    
+    @Override
+    protected void onRestart() {
+    	super.onRestart();
+    	Log.i(LOG_TAG, 
+    			"FIRST_ACTIVITY onRestart() The activity is visible and about to be restarted.");
+    }
+    
+    @Override
+    protected void onPause() {
+    	super.onPause();
+    	Log.i(LOG_TAG,
+				"FIRST_ACTIVITY onPause() Another activity is taking focus (this activity is about to be \"paused\")");
+    }
+    
+    @Override
+    protected void onStop() {
+    	super.onStop();
+    	Log.i(LOG_TAG, 
+    			"FIRST_ACTIVITY onStop() The activity is no longer visible (it is now \"stopped\")");
+    }
+    
+    @Override
+    protected void onDestroy() {
+    	super.onDestroy();
+    	Log.i(LOG_TAG, 
+    			"FIRST_ACTIVITY onDestroy() The activity is about to be destroyed.");
+    }
+}

+ 69 - 0
TwoActivitiesLifecycle/src/com/example/twoactivitieslifecycle/SecondActivity.java

@@ -0,0 +1,69 @@
+package com.example.twoactivitieslifecycle;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.TextView;
+
+public class SecondActivity extends Activity {
+	
+	private static final String LOG_TAG = "TWO_ACTIVITIES_LIFECYCLE";
+	
+	private TextView	textView;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		Log.i(LOG_TAG, 
+    			"SECOND_ACTIVITY onCreate() The activity is not visible and about to be created.");
+		
+		setContentView(R.layout.activity_second);
+		
+		textView = (TextView) findViewById(R.id.textView1);
+		
+		String inputText = getIntent().getStringExtra("TEXT");
+		textView.setText(inputText);
+	}
+	
+	@Override
+    protected void onStart() {
+    	super.onStart();
+    	Log.i(LOG_TAG, 
+    			"SECOND_ACTIVITY onStart() The activity is visible and about to be started.");
+    }
+    
+    @Override
+    protected void onResume() {
+    	super.onResume();
+    	Log.i(LOG_TAG, 
+    			"SECOND_ACTIVITY onResume() The activity is visible and has focus (it is now \"resumed\")");
+    }
+    
+    @Override
+    protected void onRestart() {
+    	super.onRestart();
+    	Log.i(LOG_TAG, 
+    			"SECOND_ACTIVITY onRestart() The activity is visible and about to be restarted.");
+    }
+    
+    @Override
+    protected void onPause() {
+    	super.onPause();
+    	Log.i(LOG_TAG,
+				"SECOND_ACTIVITY onPause() Another activity is taking focus (this activity is about to be \"paused\")");
+    }
+    
+    @Override
+    protected void onStop() {
+    	super.onStop();
+    	Log.i(LOG_TAG, 
+    			"SECOND_ACTIVITY onStop() The activity is no longer visible (it is now \"stopped\")");
+    }
+    
+    @Override
+    protected void onDestroy() {
+    	super.onDestroy();
+    	Log.i(LOG_TAG, 
+    			"SECOND_ACTIVITY onDestroy() The activity is about to be destroyed.");
+    }
+}