summaryrefslogtreecommitdiffstats
path: root/Android/03-Permissions/PermissionsLab/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-02-11 22:29:02 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-10 17:40:54 +0100
commitc885a3c127a9ab64fad5535b6c1f9e42e4689f7b (patch)
tree52ce77898112155c41b179837fc3d6627bf53d54 /Android/03-Permissions/PermissionsLab/src
parent3c228228209bb186ab6881eb9b9bae10c1d5c893 (diff)
downloadcoursera-c885a3c127a9ab64fad5535b6c1f9e42e4689f7b.zip
coursera-c885a3c127a9ab64fad5535b6c1f9e42e4689f7b.tar.gz
Android : 03-Permissions: add
Diffstat (limited to 'Android/03-Permissions/PermissionsLab/src')
-rw-r--r--Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/ActivityLoaderActivity.java33
-rw-r--r--Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/BookmarksActivity.java73
-rw-r--r--Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/GoToDangerousActivity.java36
3 files changed, 142 insertions, 0 deletions
diff --git a/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/ActivityLoaderActivity.java b/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/ActivityLoaderActivity.java
new file mode 100644
index 0000000..eca3506
--- /dev/null
+++ b/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/ActivityLoaderActivity.java
@@ -0,0 +1,33 @@
+package course.labs.permissionslab;
+
+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;
+
+public class ActivityLoaderActivity extends Activity {
+
+ private static final String TAG = "Lab-Permissions";
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_loader_activity);
+
+ Button startBookmarksButton = (Button) findViewById(R.id.start_bookmarks_button);
+ startBookmarksButton.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ startBookMarksActivity();
+ }
+ });
+ }
+
+ private void startBookMarksActivity() {
+ Log.i(TAG, "Entered startBookMarksActivity()");
+ // TODO - Start the BookmarksActivity
+ }
+}
diff --git a/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/BookmarksActivity.java b/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/BookmarksActivity.java
new file mode 100644
index 0000000..6f4ae7e
--- /dev/null
+++ b/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/BookmarksActivity.java
@@ -0,0 +1,73 @@
+package course.labs.permissionslab;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.provider.Browser;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class BookmarksActivity extends Activity {
+
+ private static final String TAG = "Lab-Permissions";
+
+ static final String[] projection = {
+ Browser.BookmarkColumns.TITLE,
+ Browser.BookmarkColumns.URL
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.bookmarks_activity);
+
+ Button getBookmarksButton = (Button) findViewById(R.id.get_bookmarks_button);
+ getBookmarksButton.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ loadBookmarks();
+ }
+ });
+
+ Button goToDangerousActivityButton = (Button) findViewById(R.id.go_to_dangerous_activity_button);
+ goToDangerousActivityButton.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ startGoToDangerousActivity();
+ }
+ });
+ }
+
+ private void loadBookmarks() {
+
+ Log.i(TAG, "Entered loadBookmarks()");
+
+ String text = "";
+ Cursor query = getContentResolver().query(Browser.BOOKMARKS_URI, projection, null, null, null);
+
+ query.moveToFirst();
+ while (query.moveToNext()) {
+ text += query.getString(query
+ .getColumnIndex(Browser.BookmarkColumns.TITLE));
+ text += "\n";
+ text += query.getString(query
+ .getColumnIndex(Browser.BookmarkColumns.URL));
+ text += "\n\n";
+ }
+
+ TextView box = (TextView) findViewById(R.id.text);
+ box.setText(text);
+ Log.i(TAG, "Bookmarks loaded");
+ }
+
+ private void startGoToDangerousActivity() {
+ Log.i(TAG, "Entered startGoToDangerousActivity()");
+ // TODO - Start the GoToDangerousActivity
+ }
+}
diff --git a/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/GoToDangerousActivity.java b/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/GoToDangerousActivity.java
new file mode 100644
index 0000000..171f469
--- /dev/null
+++ b/Android/03-Permissions/PermissionsLab/src/course/labs/permissionslab/GoToDangerousActivity.java
@@ -0,0 +1,36 @@
+package course.labs.permissionslab;
+
+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;
+
+public class GoToDangerousActivity extends Activity {
+
+ private static final String TAG = "Lab-Permissions";
+
+ private static final String DANGEROUS_ACTIVITY_ACTION = "course.labs.dangerousapp.DANGEROUS_ACTIVITY";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.go_to_dangerous_activity);
+
+ Button startDangerousActivityButton = (Button) findViewById(R.id.start_dangerous_activity_button);
+ startDangerousActivityButton.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ startDangerousActivity();
+ }
+ });
+ }
+
+ private void startDangerousActivity() {
+ Log.i(TAG, "Entered startDangerousActivity()");
+ startActivity(new Intent(DANGEROUS_ACTIVITY_ACTION));
+ }
+}