summaryrefslogtreecommitdiffstats
path: root/Android/02-Intents/IntentsLab/src/course/labs/intentslab
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-02-12 22:33:14 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-10 17:40:54 +0100
commitee3ef2bcf3656e3e7a02d86d43858cc8145508da (patch)
treec428969d47180877913f95201067f4b750f91b2a /Android/02-Intents/IntentsLab/src/course/labs/intentslab
parent339c57d3520c8de6f970b020c87f77ec266f3bf8 (diff)
downloadcoursera-ee3ef2bcf3656e3e7a02d86d43858cc8145508da.zip
coursera-ee3ef2bcf3656e3e7a02d86d43858cc8145508da.tar.gz
Android : 02-Intents: add
Diffstat (limited to 'Android/02-Intents/IntentsLab/src/course/labs/intentslab')
-rw-r--r--Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java85
-rw-r--r--Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java47
2 files changed, 132 insertions, 0 deletions
diff --git a/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java
new file mode 100644
index 0000000..407b371
--- /dev/null
+++ b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java
@@ -0,0 +1,85 @@
+package course.labs.intentslab;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class ActivityLoaderActivity extends Activity {
+
+ static private final int GET_TEXT_REQUEST_CODE = 1;
+ static private final String URL = "http://www.google.com";
+ static private final String TAG = "Lab-Intents";
+
+ // For use with app chooser
+ static private final String CHOOSER_TEXT = "Load " + URL + " with:";
+
+ // TextView that displays user-entered text from ExplicitlyLoadedActivity runs
+ private TextView mUserTextView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_loader_activity);
+
+ // Get reference to the textView
+ mUserTextView = (TextView) findViewById(R.id.textView1);
+
+ // Declare and setup Explicit Activation button
+ Button explicitActivationButton = (Button) findViewById(R.id.explicit_activation_button);
+ explicitActivationButton.setOnClickListener(new OnClickListener() {
+
+ // Call startExplicitActivation() when pressed
+ @Override
+ public void onClick(View v) {
+ startExplicitActivation();
+ }
+ });
+
+ // Declare and setup Implicit Activation button
+ Button implicitActivationButton = (Button) findViewById(R.id.implicit_activation_button);
+ implicitActivationButton.setOnClickListener(new OnClickListener() {
+
+ // Call startImplicitActivation() when pressed
+ @Override
+ public void onClick(View v) {
+ startImplicitActivation();
+ }
+ });
+ }
+
+ // Start the ExplicitlyLoadedActivity
+ private void startExplicitActivation() {
+ Log.i(TAG,"Entered startExplicitActivation()");
+ // TODO - Create a new intent to launch the ExplicitlyLoadedActivity class
+ // TODO - Start an Activity using that intent and the request code defined above
+ }
+
+ // Start a Browser Activity to view a web page or its URL
+ private void startImplicitActivation() {
+ Log.i(TAG, "Entered startImplicitActivation()");
+ // TODO - Create a base intent for viewing a URL
+ // (HINT: second parameter uses parse() from the Uri class)
+ // TODO - Create a chooser intent, for choosing which Activity
+ // will carry out the baseIntent. Store the Intent in the
+ // chooserIntent variable below. HINT: using the Intent class'
+ // createChooser())
+ Intent chooserIntent = null;
+ Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
+ // TODO - Start the chooser Activity, using the chooser intent
+ startActivity(chooserIntent);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ Log.i(TAG, "Entered onActivityResult()");
+ // TODO - Process the result only if this method received both a
+ // RESULT_OK result code and a recognized request code
+ // If so, update the Textview showing the user-entered text.
+ }
+}
diff --git a/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java
new file mode 100644
index 0000000..5c33228
--- /dev/null
+++ b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java
@@ -0,0 +1,47 @@
+package course.labs.intentslab;
+
+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 ExplicitlyLoadedActivity extends Activity {
+
+ static private final String TAG = "Lab-Intents";
+
+ private EditText mEditText;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.explicitly_loaded_activity);
+
+ // Get a reference to the EditText field
+ mEditText = (EditText) findViewById(R.id.editText);
+
+ // Declare and setup "Enter" button
+ Button enterButton = (Button) findViewById(R.id.enter_button);
+ enterButton.setOnClickListener(new OnClickListener() {
+
+ // Call enterClicked() when pressed
+ @Override
+ public void onClick(View v) {
+ enterClicked();
+ }
+ });
+ }
+
+ // Sets result to send back to calling Activity and finishes
+ private void enterClicked() {
+ Log.i(TAG,"Entered enterClicked()");
+ // TODO - Save user provided input from the EditText field
+ // TODO - Create a new intent and save the input from the EditText field as an extra
+ // TODO - Set Activity's result with result code RESULT_OK
+ // TODO - Finish the Activity
+ }
+}