├── .gitignore
├── .travis.yml
├── README.md
├── app
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── codepath
│ │ └── apps
│ │ └── demointroandroid
│ │ ├── ActionBarMenuActivity.java
│ │ ├── AsyncTaskPerformActivity.java
│ │ ├── BasicClickHandlersActivity.java
│ │ ├── BasicImageDownloadActivity.java
│ │ ├── BasicTextViewActivity.java
│ │ ├── BasicViewsActivity.java
│ │ ├── ContactListActivity.java
│ │ ├── DemoSelector.java
│ │ ├── ExerciseActivityMapper.java
│ │ ├── ExplicitIntentActivity.java
│ │ ├── GridViewDemoActivity.java
│ │ ├── ImplicitIntentsActivity.java
│ │ ├── IntentWithResultActivity.java
│ │ ├── LayoutGravityActivity.java
│ │ ├── LinearLayoutDemoActivity.java
│ │ ├── ListViewClicksActivity.java
│ │ ├── PersistSettingsActivity.java
│ │ ├── ProgressBarActivity.java
│ │ ├── PublishingInstructionsActivity.java
│ │ ├── SimpleAlertDialog.java
│ │ ├── SimpleBundleDemoActivity.java
│ │ ├── SimpleListViewActivity.java
│ │ ├── SimpleReturnResultActivity.java
│ │ ├── SmartImageDownloadActivity.java
│ │ ├── SpinnerWithToastActivity.java
│ │ ├── TimePickerDemoActivity.java
│ │ ├── ToastFormInputsActivity.java
│ │ └── ViewAttributesActivity.java
│ └── res
│ ├── drawable-hdpi
│ ├── ad.png
│ ├── ae.png
│ ├── af.png
│ ├── ag.png
│ ├── ai.png
│ ├── al.png
│ ├── am.png
│ ├── an.png
│ └── ic_launcher.png
│ ├── drawable-ldpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable
│ └── simple_list_selector.xml
│ ├── layout
│ ├── activity_action_bar_menu.xml
│ ├── activity_async_task_perform.xml
│ ├── activity_basic_click_handlers.xml
│ ├── activity_basic_image_download.xml
│ ├── activity_basic_text_view.xml
│ ├── activity_basic_views.xml
│ ├── activity_button_toast.xml
│ ├── activity_contact_list.xml
│ ├── activity_demo_selector.xml
│ ├── activity_explicit_intent.xml
│ ├── activity_grid_view_demo.xml
│ ├── activity_implicit_intents.xml
│ ├── activity_intent_with_result.xml
│ ├── activity_layout_gravity.xml
│ ├── activity_linear_layout_demo.xml
│ ├── activity_list_view_clicks.xml
│ ├── activity_persist_settings.xml
│ ├── activity_progress_bar.xml
│ ├── activity_publishing_instructions.xml
│ ├── activity_simple_bundle_demo.xml
│ ├── activity_simple_list_view.xml
│ ├── activity_simple_return_result.xml
│ ├── activity_smart_image_download.xml
│ ├── activity_spinner_with_toast.xml
│ ├── activity_time_picker_demo.xml
│ ├── activity_toast_form_inputs.xml
│ ├── activity_view_attributes.xml
│ └── simple_list_view_item.xml
│ ├── menu
│ ├── activity_action_bar_menu.xml
│ ├── activity_async_task_perform.xml
│ ├── activity_basic_click_handlers.xml
│ ├── activity_basic_image_download.xml
│ ├── activity_basic_text_view.xml
│ ├── activity_basic_views.xml
│ ├── activity_button_toast.xml
│ ├── activity_contact_list.xml
│ ├── activity_demo_selector.xml
│ ├── activity_explicit_intent.xml
│ ├── activity_grid_view_demo.xml
│ ├── activity_implicit_intents.xml
│ ├── activity_intent_with_result.xml
│ ├── activity_layout_gravity.xml
│ ├── activity_linear_layout_demo.xml
│ ├── activity_list_view_clicks.xml
│ ├── activity_persist_settings.xml
│ ├── activity_progress_bar.xml
│ ├── activity_publishing_instructions.xml
│ ├── activity_simple_bundle_demo.xml
│ ├── activity_simple_list_view.xml
│ ├── activity_simple_return_result.xml
│ ├── activity_smart_image_download.xml
│ ├── activity_spinner_with_toast.xml
│ ├── activity_time_picker_demo.xml
│ ├── activity_toast_form_inputs.xml
│ └── activity_view_attributes.xml
│ ├── values-v11
│ └── styles.xml
│ ├── values-v14
│ └── styles.xml
│ └── values
│ ├── colors.xml
│ ├── exercises_list.xml
│ ├── spinner_values.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 | proguard-project.txt
25 |
26 | # Intellij project files
27 | *.iml
28 | *.ipr
29 | *.iws
30 | .idea/
31 |
32 | *.pydevproject
33 | .project
34 | .metadata
35 | .gradle
36 | build/**
37 | bin/**
38 | tmp/**
39 | tmp/**/*
40 | *.tmp
41 | *.bak
42 | *.swp
43 | *~.nib
44 | local.properties
45 | .classpath
46 | .settings/
47 | .loadpath
48 |
49 | # External tool builders
50 | .externalToolBuilders/
51 |
52 | # Locally stored "Eclipse launch configurations"
53 | *.launch
54 |
55 | # CDT-specific
56 | .cproject
57 |
58 | # PDT-specific
59 | .buildpath
60 |
61 | # Android Studio project files
62 | *.iml
63 | .gradle
64 | .idea
65 | build
66 | import-summary.txt
67 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk:
3 | - oraclejdk8
4 | sudo: false
5 | android:
6 | components:
7 | - tools
8 | - platform-tools
9 | - build-tools-28.0.3
10 | - android-28
11 | licenses:
12 | - android-sdk-license-.+
13 | script:
14 | - "./gradlew build check --daemon"
15 | after_failure: "cat $TRAVIS_BUILD_DIR/app/build/outputs/lint-results-debug.xml"
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | intro_android_demo
2 | ==================
3 |
4 | Demo of app exercises for Intro to Android App Development
5 |
6 |
7 |
8 |
9 | Sample Listing:
10 |
11 | - Chapter 1: App Fundamentals
12 | - Basic TextViews Example
13 | - Chapter 2: User Interface
14 | - Linear Layout Demo
15 | - Chapter 3: View Controls
16 | - Layout Gravity
17 | - Basic Views
18 | - View Attributes
19 | - Simple ListView
20 | - Chapter 4: User Interactions
21 | - Basic Click Handlers
22 | - Handling ListView Clicks
23 | - Action Bar Demo
24 | - Chapter 5: User Flows
25 | - Explicit Intents
26 | - Implicit Intents
27 | - Intent with Results
28 | - Chapter 6: Networking
29 | - Basic Image Download
30 | - AsyncTask Example
31 | - Smart Image Download
32 | - Chapter 7: Advanced Views
33 | - Toast Inputs
34 | - Spinner Toast
35 | - TimePicker
36 | - ProgressBar
37 | - GridView
38 | - Chapter 8: Preferences
39 | - Persist Settings
40 | - Chapter 9: Content Providers
41 | - Contact List
42 | - Chapter 10: Publishing
43 | - APK Instructions
44 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | applicationId "codepath.apps.demointroandroid"
8 | minSdkVersion 21
9 | targetSdkVersion 28
10 | }
11 |
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
22 | implementation 'com.codepath.libraries:asynchttpclient:0.1.0'
23 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
32 |
33 |
36 |
37 |
40 |
41 |
44 |
45 |
48 |
49 |
52 |
53 |
56 |
57 |
60 |
61 |
64 |
65 |
68 |
69 |
72 |
73 |
76 |
77 |
80 |
81 |
84 |
85 |
88 |
89 |
92 |
93 |
96 |
97 |
100 |
101 |
104 |
105 |
108 |
109 |
112 |
113 |
116 |
117 |
120 |
121 |
124 |
125 |
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ActionBarMenuActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.annotation.SuppressLint;
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.widget.Toast;
10 |
11 | public class ActionBarMenuActivity extends Activity {
12 |
13 | @SuppressLint("NewApi")
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_action_bar_menu);
18 | getActionBar().setTitle("Click an Icon");
19 | }
20 |
21 | @Override
22 | public boolean onCreateOptionsMenu(Menu menu) {
23 | // Inflate the menu; this adds items to the action bar if it is present.
24 | getMenuInflater().inflate(R.menu.activity_action_bar_menu, menu);
25 | return true;
26 | }
27 |
28 |
29 | @Override
30 | public boolean onOptionsItemSelected(MenuItem item) {
31 | switch (item.getItemId()) {
32 | case R.id.menu_toast:
33 | Toast.makeText(this, "Toasted", Toast.LENGTH_SHORT).show();
34 | break;
35 | case R.id.menu_launch:
36 | Intent i = new Intent(this, SimpleBundleDemoActivity.class);
37 | startActivity(i);
38 | break;
39 | default:
40 | break;
41 | }
42 | return true;
43 | }
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/AsyncTaskPerformActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.AsyncTask;
4 | import android.os.Bundle;
5 | import android.app.Activity;
6 | import android.view.Menu;
7 | import android.widget.Toast;
8 |
9 | public class AsyncTaskPerformActivity extends Activity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_async_task_perform);
15 | new MyAsyncTask().execute();
16 | }
17 |
18 | @Override
19 | public boolean onCreateOptionsMenu(Menu menu) {
20 | // Inflate the menu; this adds items to the action bar if it is present.
21 | getMenuInflater().inflate(R.menu.activity_async_task_perform, menu);
22 | return true;
23 | }
24 |
25 | public void doneCounting() {
26 | Toast.makeText(this, "Done Counting to 100000", Toast.LENGTH_SHORT).show();
27 | }
28 |
29 | private class MyAsyncTask extends AsyncTask {
30 | public Void doInBackground(Void... params) {
31 | for (long i=0; i < 100000; i++) {
32 | System.out.println(i);
33 | }
34 | return null;
35 | }
36 |
37 | protected void onPostExecute(Void result) {
38 | doneCounting();
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/BasicClickHandlersActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class BasicClickHandlersActivity extends Activity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_basic_click_handlers);
15 | Button secondButton = (Button) findViewById(R.id.btnClick2);
16 | secondButton.setOnClickListener(new View.OnClickListener() {
17 | @Override
18 | public void onClick(View v) {
19 | secondButtonClicked(v);
20 | }
21 | });
22 | }
23 |
24 | @Override
25 | public boolean onCreateOptionsMenu(Menu menu) {
26 | // Inflate the menu; this adds items to the action bar if it is present.
27 | getMenuInflater().inflate(R.menu.activity_basic_click_handlers, menu);
28 | return true;
29 | }
30 |
31 | public void firstButtonClicked(View v) {
32 | SimpleAlertDialog.displayWithOK(this, "firstButton clicked via XML handler");
33 | }
34 |
35 | private void secondButtonClicked(View v) {
36 | SimpleAlertDialog.displayWithOK(this, "secondButton clicked via Java handler in onCreate");
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/BasicImageDownloadActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.os.Bundle;
8 | import android.os.StrictMode;
9 | import android.view.Menu;
10 | import android.widget.ImageView;
11 |
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.net.MalformedURLException;
15 | import java.net.URL;
16 | import java.net.URLConnection;
17 |
18 | public class BasicImageDownloadActivity extends Activity {
19 |
20 | @SuppressLint("NewApi")
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_basic_image_download);
25 | StrictMode.setThreadPolicy(
26 | new StrictMode.ThreadPolicy.Builder().permitNetwork().build());
27 | downloadImageFromUri("https://2.gravatar.com/avatar/858dfac47ab8176458c005414d3f0c36?s=128&d=&r=G");
28 | }
29 |
30 | private void downloadImageFromUri(String address) {
31 | URL url;
32 | try {
33 | url = new URL(address);
34 | } catch (MalformedURLException e1) {
35 | url = null;
36 | }
37 |
38 | URLConnection conn;
39 | InputStream in;
40 | Bitmap bitmap;
41 | try {
42 | conn = url.openConnection();
43 | conn.connect();
44 | in = conn.getInputStream();
45 | bitmap = BitmapFactory.decodeStream(in);
46 | in.close();
47 | } catch (IOException e) {
48 | bitmap = null;
49 | }
50 |
51 | if (bitmap != null) {
52 | ImageView img = (ImageView) findViewById(R.id.ivBasicImage);
53 | img.setImageBitmap(bitmap);
54 | }
55 | }
56 |
57 | @Override
58 | public boolean onCreateOptionsMenu(Menu menu) {
59 | // Inflate the menu; this adds items to the action bar if it is present.
60 | getMenuInflater().inflate(R.menu.activity_basic_image_download, menu);
61 | return true;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/BasicTextViewActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.util.Log;
6 | import android.view.Menu;
7 |
8 | public class BasicTextViewActivity extends Activity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_basic_text_view);
14 | Log.d("DEBUG", "onCreate was just called!");
15 | }
16 |
17 | protected void onResume() {
18 | super.onResume();
19 | Log.d("DEBUG", "onResume was just called!");
20 | }
21 |
22 | protected void onPause() {
23 | super.onPause();
24 | Log.d("DEBUG", "onPause was just called!");
25 | }
26 |
27 | @Override
28 | public boolean onCreateOptionsMenu(Menu menu) {
29 | // Inflate the menu; this adds items to the action bar if it is present.
30 | getMenuInflater().inflate(R.menu.activity_basic_text_view, menu);
31 | return true;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/BasicViewsActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 |
7 | public class BasicViewsActivity extends Activity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_basic_views);
13 | }
14 |
15 | @Override
16 | public boolean onCreateOptionsMenu(Menu menu) {
17 | // Inflate the menu; this adds items to the action bar if it is present.
18 | getMenuInflater().inflate(R.menu.activity_basic_views, menu);
19 | return true;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ContactListActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.CursorLoader;
6 | import android.content.pm.PackageManager;
7 | import android.database.Cursor;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 | import android.provider.ContactsContract;
11 | import androidx.core.app.ActivityCompat;
12 | import android.util.Log;
13 | import android.view.Menu;
14 | import android.view.View;
15 | import android.widget.AdapterView;
16 | import android.widget.AdapterView.OnItemClickListener;
17 | import android.widget.ArrayAdapter;
18 | import android.widget.ListView;
19 | import android.widget.Toast;
20 |
21 | import java.util.ArrayList;
22 |
23 | public class ContactListActivity extends Activity {
24 |
25 | private static final int REQUEST_READ_CONTACTS = 1;
26 | ArrayList names = new ArrayList();
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_contact_list);
32 | if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_CONTACTS)
33 | == PackageManager.PERMISSION_GRANTED) {
34 | loadContacts();
35 | } else {
36 | ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_CONTACTS},
37 | REQUEST_READ_CONTACTS);
38 | }
39 | populateListView();
40 | }
41 |
42 | private void populateListView() {
43 | ArrayAdapter adapter = new ArrayAdapter(this,
44 | android.R.layout.simple_list_item_1, names);
45 |
46 | ListView listView = (ListView) findViewById(R.id.lvContacts);
47 | listView.setAdapter(adapter);
48 | listView.setOnItemClickListener(new OnItemClickListener() {
49 | @Override
50 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
51 | Toast.makeText(ContactListActivity.this, names.get(position), Toast.LENGTH_SHORT).show();
52 | }
53 | });
54 | }
55 |
56 | @Override
57 | public void onRequestPermissionsResult(int requestCode,
58 | String permissions[], int[] grantResults) {
59 | if (requestCode == REQUEST_READ_CONTACTS) {
60 | if (grantResults.length > 0
61 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
62 | loadContacts();
63 | } else {
64 | Toast.makeText(this, "Permission Denied, Not able to load contact", Toast.LENGTH_SHORT).show();
65 | }
66 | }
67 | }
68 |
69 | @SuppressLint("NewApi")
70 | private void loadContacts() {
71 | Uri allContacts = Uri.parse("content://contacts/people");
72 | CursorLoader cursorLoader = new CursorLoader(this, allContacts,
73 | null, // the columns to retrive
74 | null, // the selection criteria
75 | null, // the selection args
76 | null // the sort order
77 | );
78 |
79 | Cursor c = cursorLoader.loadInBackground();
80 | if (c.moveToFirst()) {
81 | do {
82 | // Get Contact ID
83 | int idIndex = c.getColumnIndex(ContactsContract.Contacts._ID);
84 | String contactID = c.getString(idIndex);
85 |
86 | // Get Contact Name
87 | int nameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
88 | String contactDisplayName = c.getString(nameIndex);
89 | names.add(contactDisplayName);
90 |
91 | Log.d("debug", contactID + ", " + contactDisplayName);
92 | } while (c.moveToNext());
93 | }
94 | }
95 |
96 | @Override
97 | public boolean onCreateOptionsMenu(Menu menu) {
98 | // Inflate the menu; this adds items to the action bar if it is present.
99 | getMenuInflater().inflate(R.menu.activity_contact_list, menu);
100 | return true;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/DemoSelector.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.annotation.SuppressLint;
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.view.Gravity;
8 | import android.view.Menu;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.AbsListView;
12 | import android.widget.BaseExpandableListAdapter;
13 | import android.widget.ExpandableListView;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | public class DemoSelector extends Activity {
18 |
19 | ExpandableListView elvChapters;
20 | ChaptersListAdapter elaAdapter;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_demo_selector);
26 | setupChaptersListView();
27 | }
28 |
29 | @Override
30 | public boolean onCreateOptionsMenu(Menu menu) {
31 | // Inflate the menu; this adds items to the action bar if it is present.
32 | getMenuInflater().inflate(R.menu.activity_demo_selector, menu);
33 | return true;
34 | }
35 |
36 | private void setupChaptersListView() {
37 | elvChapters = (ExpandableListView)findViewById(R.id.elvChapters);
38 | elaAdapter = new ChaptersListAdapter();
39 | elvChapters.setAdapter(elaAdapter);
40 | elvChapters.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
41 | public boolean onChildClick(ExpandableListView parent, View v,
42 | int groupPosition, int childPosition, long id) {
43 |
44 | String exerciseTitle = (String)elaAdapter.getChild(groupPosition, childPosition);
45 | Class extends Activity> exerciseClass = elaAdapter.getExerciseClass(groupPosition, childPosition, id);
46 | if (exerciseClass != null) {
47 | Toast.makeText(DemoSelector.this, exerciseTitle, Toast.LENGTH_LONG).show();
48 | startActivity(new Intent(DemoSelector.this, exerciseClass));
49 | } else {
50 | Toast.makeText(DemoSelector.this, "Exercise Not Available", Toast.LENGTH_SHORT).show();
51 | }
52 | return false;
53 | }
54 | });
55 |
56 | }
57 |
58 | private class ChaptersListAdapter extends BaseExpandableListAdapter {
59 | private String[] chapters = getResources().getStringArray(R.array.chapters);
60 | private String[][] exercises;
61 |
62 | public ChaptersListAdapter() {
63 | super();
64 | exercises = new String[chapters.length][];
65 | for (int i=0; i < exercises.length; i++) {
66 | int resId = getResources().getIdentifier("chap" + (i+1), "array", getPackageName());
67 | exercises[i] = getResources().getStringArray(resId);
68 | }
69 | }
70 |
71 |
72 | public Object getChild(int groupPosition, int childPosition) {
73 | return exercises[groupPosition][childPosition];
74 | }
75 |
76 | public long getChildId(int groupPosition, int childPosition) {
77 | return childPosition;
78 | }
79 |
80 | public int getChildrenCount(int groupPosition) {
81 | return exercises[groupPosition].length;
82 | }
83 |
84 | public TextView getGenericView() {
85 | // Layout parameters for the ExpandableListView
86 | AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
87 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
88 |
89 | TextView textView = new TextView(DemoSelector.this);
90 | textView.setLayoutParams(lp);
91 | // Center the text vertically
92 | textView.setTextSize(20);
93 | textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
94 | // Set the text starting position
95 | textView.setPadding(60, 20, 20, 20);
96 | return textView;
97 | }
98 |
99 | public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
100 | View convertView, ViewGroup parent) {
101 | TextView textView = getGenericView();
102 | textView.setPadding(80, 20, 20, 20);
103 | textView.setText(getChild(groupPosition, childPosition).toString());
104 | return textView;
105 | }
106 |
107 | public Object getGroup(int groupPosition) {
108 | return "Chapter " + (groupPosition + 1) + ": " + chapters[groupPosition];
109 | }
110 |
111 | public int getGroupCount() {
112 | return chapters.length;
113 | }
114 |
115 | public long getGroupId(int groupPosition) {
116 | return groupPosition;
117 | }
118 |
119 | public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
120 | ViewGroup parent) {
121 | TextView textView = getGenericView();
122 | textView.setText(getGroup(groupPosition).toString());
123 | return textView;
124 | }
125 |
126 | public boolean isChildSelectable(int groupPosition, int childPosition) {
127 | return true;
128 | }
129 |
130 | public boolean hasStableIds() {
131 | return true;
132 | }
133 |
134 | public Class extends Activity> getExerciseClass(int groupPosition, int childPosition, long id) {
135 | String exerciseId = "chap" + (groupPosition + 1) + "ex" + (childPosition + 1);
136 | return ExerciseActivityMapper.getExerciseClass(exerciseId);
137 | }
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ExerciseActivityMapper.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import java.util.HashMap;
4 |
5 | import android.app.Activity;
6 |
7 | public class ExerciseActivityMapper {
8 | private static ExerciseActivityMapper singleton;
9 | private HashMap> exerciseClassMap;
10 |
11 | public ExerciseActivityMapper() {
12 | defineExerciseMappings();
13 | }
14 |
15 | // ExerciseActivityMapper.getExerciseClass("chap1ex1");
16 | public static Class extends Activity> getExerciseClass(String exerciseId) {
17 | return getSingleton().exerciseClassMap.get(exerciseId);
18 | }
19 |
20 | private static ExerciseActivityMapper getSingleton() {
21 | if (singleton == null) {
22 | singleton = new ExerciseActivityMapper();
23 | }
24 | return singleton;
25 | }
26 |
27 | private void defineExerciseMappings() {
28 | exerciseClassMap = new HashMap>();
29 | // Chapter 1: App Fundamentals
30 | exerciseClassMap.put("chap1ex1", BasicTextViewActivity.class);
31 | // Chapter 2: User Interface
32 | exerciseClassMap.put("chap2ex1", LinearLayoutDemoActivity.class);
33 | // Chapter 3: View Controls
34 | exerciseClassMap.put("chap3ex1", LayoutGravityActivity.class);
35 | exerciseClassMap.put("chap3ex2", BasicViewsActivity.class);
36 | exerciseClassMap.put("chap3ex3", ViewAttributesActivity.class);
37 | exerciseClassMap.put("chap3ex4", SimpleListViewActivity.class);
38 | // Chapter 4: User Interactions
39 | exerciseClassMap.put("chap4ex1", BasicClickHandlersActivity.class);
40 | exerciseClassMap.put("chap4ex2", ListViewClicksActivity.class);
41 | // Chapter 5: User Flows
42 | exerciseClassMap.put("chap5ex1", ExplicitIntentActivity.class); // Explicit Intents
43 | exerciseClassMap.put("chap5ex2", ImplicitIntentsActivity.class); // Implicit Intents
44 | exerciseClassMap.put("chap5ex3", IntentWithResultActivity.class); // Intent with Results
45 | exerciseClassMap.put("chap5ex4", ActionBarMenuActivity.class); // Action Bar
46 | // Chapter 6: Networking
47 | exerciseClassMap.put("chap6ex1", BasicImageDownloadActivity.class); // Basic Image Download
48 | exerciseClassMap.put("chap6ex2", AsyncTaskPerformActivity.class); // AsyncTask
49 | exerciseClassMap.put("chap6ex3", SmartImageDownloadActivity.class); // Smart Image Download
50 | // Chapter 7: Advanced Views
51 | exerciseClassMap.put("chap7ex1", ToastFormInputsActivity.class); // Toast Inputs
52 | exerciseClassMap.put("chap7ex2", SpinnerWithToastActivity.class); // Spinner Toast
53 | exerciseClassMap.put("chap7ex3", TimePickerDemoActivity.class); // TimePicker
54 | exerciseClassMap.put("chap7ex4", ProgressBarActivity.class); // ProgressBar
55 | exerciseClassMap.put("chap7ex5", GridViewDemoActivity.class); // GridView
56 | // Chapter 8: Preferences
57 | exerciseClassMap.put("chap8ex1", PersistSettingsActivity.class); // Persist Settings
58 | // Chapter 9: ContentProviders
59 | exerciseClassMap.put("chap9ex1", ContactListActivity.class); // Contact List
60 | // Chapter 10: Publishing
61 | exerciseClassMap.put("chap10ex1", PublishingInstructionsActivity.class); // APK Generation
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ExplicitIntentActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.view.Menu;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Button;
10 |
11 | public class ExplicitIntentActivity extends Activity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_explicit_intent);
17 | Button btnLaunchSecond = (Button) findViewById(R.id.btnLaunchSecond);
18 | btnLaunchSecond.setOnClickListener(new OnClickListener() {
19 | @Override
20 | public void onClick(View v) {
21 | Intent i = new Intent(ExplicitIntentActivity.this, SimpleBundleDemoActivity.class);
22 | i.putExtra("text", "Passed String Extra!");
23 | startActivity(i);
24 | }
25 | });
26 | }
27 |
28 | @Override
29 | public boolean onCreateOptionsMenu(Menu menu) {
30 | // Inflate the menu; this adds items to the action bar if it is present.
31 | getMenuInflater().inflate(R.menu.activity_explicit_intent, menu);
32 | return true;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/GridViewDemoActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.view.Menu;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ArrayAdapter;
10 | import android.widget.GridView;
11 | import android.widget.ImageView;
12 |
13 | public class GridViewDemoActivity extends Activity {
14 |
15 | GridView gvImages;
16 | GridImageAdapter adapter;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_grid_view_demo);
22 | populateGridViewImages();
23 | }
24 |
25 | private void populateGridViewImages() {
26 | gvImages = (GridView) findViewById(R.id.gvImages);
27 | String[] numbers = new String[] { "ad", "ae", "af", "ag", "ai", "al"};
28 | adapter = new GridImageAdapter(this,
29 | android.R.layout.simple_list_item_1, numbers);
30 | gvImages.setAdapter(adapter);
31 | }
32 |
33 | @Override
34 | public boolean onCreateOptionsMenu(Menu menu) {
35 | // Inflate the menu; this adds items to the action bar if it is present.
36 | getMenuInflater().inflate(R.menu.activity_grid_view_demo, menu);
37 | return true;
38 | }
39 |
40 | class GridImageAdapter extends ArrayAdapter {
41 |
42 | public GridImageAdapter(Context context, int textViewResourceId, String[] numbers) {
43 | super(context, textViewResourceId, numbers);
44 | }
45 |
46 | public View getView(int position, View convertView, ViewGroup parent) {
47 | ImageView v = new ImageView(GridViewDemoActivity.this);
48 | int resId = getResources().getIdentifier(getItem(position), "drawable", getPackageName());
49 | v.setImageDrawable(getResources().getDrawable(resId));
50 | return v;
51 | }
52 |
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ImplicitIntentsActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.net.Uri;
4 | import android.os.Bundle;
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.view.Menu;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | public class ImplicitIntentsActivity extends Activity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_implicit_intents);
17 | }
18 |
19 | @Override
20 | public boolean onCreateOptionsMenu(Menu menu) {
21 | // Inflate the menu; this adds items to the action bar if it is present.
22 | getMenuInflater().inflate(R.menu.activity_implicit_intents, menu);
23 | return true;
24 | }
25 |
26 | public void visitUrlAddress(View v) {
27 | Uri url = getUriToVisit();
28 | if (url != null) {
29 | Intent i = new Intent(Intent.ACTION_VIEW);
30 | i.setData(url);
31 | startActivity(i);
32 | }
33 |
34 | }
35 |
36 | public Uri getUriToVisit() {
37 | String urlAddress = ((TextView) findViewById(R.id.txtUrlAddress)).getText().toString();
38 | if (urlAddress != null) {
39 | if (!urlAddress.startsWith("http://"))
40 | urlAddress = "http://" + urlAddress;
41 | return Uri.parse(urlAddress);
42 | } else {
43 | return null;
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/IntentWithResultActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.provider.ContactsContract;
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.util.Log;
8 | import android.view.Menu;
9 | import android.view.View;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | public class IntentWithResultActivity extends Activity {
14 |
15 | final static int GET_RESULT_TEXT = 0;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_intent_with_result);
21 | }
22 |
23 | @Override
24 | public boolean onCreateOptionsMenu(Menu menu) {
25 | // Inflate the menu; this adds items to the action bar if it is present.
26 | getMenuInflater().inflate(R.menu.activity_intent_with_result, menu);
27 | return true;
28 | }
29 |
30 | public void enterText(View v) {
31 | startActivityForResult(
32 | new Intent(IntentWithResultActivity.this, SimpleReturnResultActivity.class),
33 | GET_RESULT_TEXT);
34 | }
35 |
36 | // Handle the result once the activity returns a result, display contact
37 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
38 | if (requestCode == 0) {
39 | if (resultCode == RESULT_OK) {
40 | TextView tvResult = (TextView)findViewById(R.id.txtDisplayResult);
41 | tvResult.setText(data.getStringExtra("result"));
42 | Toast.makeText(this, data.getStringExtra("result"), Toast.LENGTH_SHORT).show();
43 | }
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/LayoutGravityActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 |
7 | public class LayoutGravityActivity extends Activity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_layout_gravity);
13 | }
14 |
15 | @Override
16 | public boolean onCreateOptionsMenu(Menu menu) {
17 | // Inflate the menu; this adds items to the action bar if it is present.
18 | getMenuInflater().inflate(R.menu.activity_layout_gravity, menu);
19 | return true;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/LinearLayoutDemoActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 |
7 | public class LinearLayoutDemoActivity extends Activity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_linear_layout_demo);
13 | }
14 |
15 | @Override
16 | public boolean onCreateOptionsMenu(Menu menu) {
17 | // Inflate the menu; this adds items to the action bar if it is present.
18 | getMenuInflater().inflate(R.menu.activity_linear_layout_demo, menu);
19 | return true;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ListViewClicksActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 | import android.view.View;
7 | import android.widget.AdapterView;
8 | import android.widget.Toast;
9 | import android.widget.AdapterView.OnItemClickListener;
10 | import android.widget.ArrayAdapter;
11 | import android.widget.ListView;
12 |
13 | public class ListViewClicksActivity extends Activity {
14 | ArrayAdapter adapter;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_list_view_clicks);
20 | String[] myCountries = { "United States", "Canada", "Mexico", "Japan" };
21 | adapter = new ArrayAdapter(this,
22 | android.R.layout.simple_list_item_1, myCountries);
23 |
24 | ListView listView = (ListView) findViewById(R.id.lvDemo);
25 | listView.setAdapter(adapter);
26 | listView.setOnItemClickListener(new OnItemClickListener() {
27 | @Override
28 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
29 | String country = adapter.getItem(position);
30 | SimpleAlertDialog.displayWithOK(ListViewClicksActivity.this, country);
31 | Toast.makeText(ListViewClicksActivity.this, country, Toast.LENGTH_SHORT).show();
32 | }
33 |
34 | });
35 | }
36 |
37 | @Override
38 | public boolean onCreateOptionsMenu(Menu menu) {
39 | // Inflate the menu; this adds items to the action bar if it is present.
40 | getMenuInflater().inflate(R.menu.activity_list_view_clicks, menu);
41 | return true;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/PersistSettingsActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.content.SharedPreferences;
6 | import android.content.SharedPreferences.Editor;
7 | import android.view.Menu;
8 | import android.view.View;
9 | import android.widget.CheckBox;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | public class PersistSettingsActivity extends Activity {
14 |
15 | SharedPreferences prefs;
16 | Editor edits;
17 | TextView txtPersist;
18 | CheckBox chkPersist;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_persist_settings);
24 | txtPersist = (TextView) findViewById(R.id.txtPersistText);
25 | chkPersist = (CheckBox) findViewById(R.id.chkPersistState);
26 | prefs = getSharedPreferences("view", 0);
27 | edits = prefs.edit();
28 | populateValues();
29 | }
30 |
31 |
32 | @Override
33 | public boolean onCreateOptionsMenu(Menu menu) {
34 | // Inflate the menu; this adds items to the action bar if it is present.
35 | getMenuInflater().inflate(R.menu.activity_persist_settings, menu);
36 | return true;
37 | }
38 |
39 | public void populateValues() {
40 | String persistedText = prefs.getString("txtVal", "None Stored Yet");
41 | boolean isChecked = prefs.getBoolean("chkState", false);
42 | txtPersist.setText(persistedText);
43 | chkPersist.setChecked(isChecked);
44 | }
45 |
46 | public void persistValues(View v) {
47 | edits.putString("txtVal", txtPersist.getText().toString());
48 | edits.putBoolean("chkState", chkPersist.isChecked());
49 | edits.commit();
50 | Toast.makeText(this, "Persisted!", Toast.LENGTH_SHORT).show();
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ProgressBarActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.app.Activity;
4 | import android.os.AsyncTask;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.Menu;
8 | import android.view.View;
9 | import android.widget.ProgressBar;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.facebook.stetho.server.http.HttpStatus;
14 |
15 | import java.io.ByteArrayOutputStream;
16 | import java.io.IOException;
17 | import java.util.ArrayList;
18 |
19 | import okhttp3.OkHttpClient;
20 | import okhttp3.Request;
21 | import okhttp3.Response;
22 |
23 | public class ProgressBarActivity extends Activity {
24 |
25 | ProgressBar pb;
26 | TextView tvResult;
27 | ArrayList lines = new ArrayList();
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_progress_bar);
33 | pb = (ProgressBar) findViewById(R.id.pgDownloading);
34 | tvResult = (TextView) findViewById(R.id.txtUrlOutput);
35 | }
36 |
37 | @Override
38 | public boolean onCreateOptionsMenu(Menu menu) {
39 | // Inflate the menu; this adds items to the action bar if it is present.
40 | getMenuInflater().inflate(R.menu.activity_progress_bar, menu);
41 | return true;
42 | }
43 |
44 | public void startFourUrlAsync(View v) {
45 | new DelayTask().execute();
46 | }
47 |
48 | public class DelayTask extends AsyncTask {
49 | int count = 0;
50 |
51 | @Override
52 | protected void onPreExecute() {
53 | pb.setVisibility(ProgressBar.VISIBLE);
54 | }
55 |
56 | @Override
57 | protected String doInBackground(Void... params) {
58 | String res = loadUrlBody("https://google.com");
59 | lines.add(res.split("\n")[0]);
60 | publishProgress(25);
61 | res = loadUrlBody("https://yahoo.com");
62 | lines.add(res.split("\n")[0]);
63 | publishProgress(50);
64 | res = loadUrlBody("https://twitter.com");
65 | lines.add(res.split("\n")[0]);
66 | publishProgress(75);
67 | res = loadUrlBody("https://facebook.com");
68 | lines.add(res.split("\n")[0]);
69 | publishProgress(100);
70 | return "complete";
71 | }
72 |
73 | @Override
74 | protected void onProgressUpdate(Integer... values) {
75 | pb.setProgress(values[0]);
76 | }
77 |
78 | @Override
79 | protected void onPostExecute(String result) {
80 | Toast.makeText(ProgressBarActivity.this, "Completed!", Toast.LENGTH_SHORT).show();
81 | tvResult.setText(lines.toString());
82 | }
83 |
84 | protected String loadUrlBody(String address) {
85 | OkHttpClient httpclient = new OkHttpClient();
86 | Response response;
87 | String responseString = null;
88 | try {
89 | response = httpclient.newCall(new Request.Builder().url(address).build()).execute();
90 | int statusCode = response.code();
91 | if (statusCode == HttpStatus.HTTP_OK) {
92 | ByteArrayOutputStream out = new ByteArrayOutputStream();
93 | out.write(response.body().bytes());
94 | responseString = out.toString();
95 | out.close();
96 | } else {
97 | response.body().byteStream().close();
98 | throw new IOException(response.message());
99 | }
100 | } catch (IOException e) {
101 | Log.e(ProgressBarActivity.class.getSimpleName(),
102 | "Error retrieving data from: " + address, e);
103 | }
104 |
105 | return responseString;
106 | }
107 |
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/PublishingInstructionsActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 |
7 | public class PublishingInstructionsActivity extends Activity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_publishing_instructions);
13 | }
14 |
15 | @Override
16 | public boolean onCreateOptionsMenu(Menu menu) {
17 | // Inflate the menu; this adds items to the action bar if it is present.
18 | getMenuInflater()
19 | .inflate(R.menu.activity_publishing_instructions, menu);
20 | return true;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/SimpleAlertDialog.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 |
7 | // SimpleAlertDialog.displayWithOK(this, "Hello", "Title");
8 | public class SimpleAlertDialog {
9 | public static void displayWithOK(Context c, String message) {
10 | displayWithOK(c, message, "CodePath Demo Intro Android");
11 | }
12 |
13 | public static void displayWithOK(Context c, String message, String title) {
14 | final AlertDialog alertDialog = new AlertDialog.Builder(c).create();
15 |
16 | // Setting Dialog Title
17 | alertDialog.setTitle(title);
18 |
19 | // Setting Dialog Message
20 | alertDialog.setMessage(message);
21 |
22 | // Setting OK Button
23 | alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
24 | public void onClick(DialogInterface dialog, int which) {
25 | alertDialog.hide();
26 | }
27 | });
28 |
29 | // Showing Alert Message
30 | alertDialog.show();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/SimpleBundleDemoActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.annotation.SuppressLint;
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.widget.TextView;
10 |
11 | public class SimpleBundleDemoActivity extends Activity {
12 |
13 | @SuppressLint("NewApi")
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_simple_bundle_demo);
18 | String initialText = getIntent().getStringExtra("text");
19 | TextView tvDisplayText = (TextView) findViewById(R.id.tvDisplayText);
20 | if (initialText != null)
21 | tvDisplayText.setText(initialText);
22 | getActionBar().setHomeButtonEnabled(true);
23 | }
24 |
25 | @Override
26 | public boolean onCreateOptionsMenu(Menu menu) {
27 | // Inflate the menu; this adds items to the action bar if it is present.
28 | getMenuInflater().inflate(R.menu.activity_simple_bundle_demo, menu);
29 | return true;
30 | }
31 |
32 |
33 |
34 | @Override
35 | public boolean onOptionsItemSelected(MenuItem item) {
36 | switch (item.getItemId()) {
37 | case android.R.id.home:
38 | Intent i = new Intent(this, ActionBarMenuActivity.class);
39 | startActivity(i);
40 | break;
41 | default:
42 | break;
43 | }
44 | return true;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/SimpleListViewActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 | import android.widget.ArrayAdapter;
7 | import android.widget.ListView;
8 |
9 | public class SimpleListViewActivity extends Activity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_simple_list_view);
15 | String[] myStringArray = { "Bruce", "Wayne", "Bill" };
16 | ArrayAdapter adapter = new ArrayAdapter(this,
17 | R.layout.simple_list_view_item, myStringArray);
18 |
19 | ListView listView = (ListView) findViewById(R.id.lvDemo);
20 | listView.setAdapter(adapter);
21 | }
22 |
23 | @Override
24 | public boolean onCreateOptionsMenu(Menu menu) {
25 | // Inflate the menu; this adds items to the action bar if it is present.
26 | getMenuInflater().inflate(R.menu.activity_simple_list_view, menu);
27 | return true;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/SimpleReturnResultActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.view.Menu;
7 | import android.view.View;
8 | import android.widget.EditText;
9 |
10 | public class SimpleReturnResultActivity extends Activity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_simple_return_result);
16 | }
17 |
18 | @Override
19 | public boolean onCreateOptionsMenu(Menu menu) {
20 | // Inflate the menu; this adds items to the action bar if it is present.
21 | getMenuInflater().inflate(R.menu.activity_simple_return_result, menu);
22 | return true;
23 | }
24 |
25 | public void sendResult(View v) {
26 | String result = ((EditText) findViewById(R.id.txtRandomResultText)).getText().toString();
27 | Intent i = new Intent();
28 | i.putExtra("result", result);
29 | setResult(RESULT_OK, i);
30 | finish();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/SmartImageDownloadActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.os.Bundle;
7 | import android.view.Menu;
8 | import android.widget.ImageView;
9 |
10 | import androidx.annotation.Nullable;
11 |
12 | import com.codepath.asynchttpclient.AsyncHttpClient;
13 | import com.codepath.asynchttpclient.callback.BinaryHttpResponseHandler;
14 |
15 | import java.io.IOException;
16 |
17 | import okhttp3.Headers;
18 | import okhttp3.Response;
19 |
20 |
21 | public class SmartImageDownloadActivity extends Activity {
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_smart_image_download);
27 | downloadSmartImageFromUrl("https://2.gravatar.com/avatar/858dfac47ab8176458c005414d3f0c36?s=128&d=&r=G");
28 | }
29 |
30 | private void downloadSmartImageFromUrl(String address) {
31 | AsyncHttpClient client = new AsyncHttpClient();
32 | client.get(address, new BinaryHttpResponseHandler() {
33 | @Override
34 | public void onSuccess(int statusCode, Headers headers, Response response) {
35 | try {
36 | byte[] image = response.body().bytes();
37 | Bitmap bitmap = BitmapFactory.decodeByteArray(image, 0, image.length);
38 | ImageView img = findViewById(R.id.ivSmartImage);
39 | img.setImageBitmap(bitmap);
40 | } catch (IOException e) {
41 | e.printStackTrace();
42 | }
43 |
44 | }
45 |
46 | @Override
47 | public void onFailure(int statusCode, @Nullable Headers headers,
48 | String errorResponse, @Nullable Throwable throwable) {
49 |
50 | }
51 | }
52 | );
53 | }
54 |
55 | @Override
56 | public boolean onCreateOptionsMenu(Menu menu) {
57 | // Inflate the menu; this adds items to the action bar if it is present.
58 | getMenuInflater().inflate(R.menu.activity_smart_image_download, menu);
59 | return true;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/SpinnerWithToastActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 | import android.view.View;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.Button;
9 | import android.widget.Spinner;
10 | import android.widget.Toast;
11 |
12 | public class SpinnerWithToastActivity extends Activity {
13 | Spinner spinner;
14 | Button btnSpinnerVal;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_spinner_with_toast);
20 | spinner = (Spinner) findViewById(R.id.spnOptions);
21 | btnSpinnerVal = (Button) findViewById(R.id.btnSpinnerValue);
22 | loadSpinner();
23 | }
24 |
25 | private void loadSpinner() {
26 | ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
27 | R.array.spinner_options, android.R.layout.simple_spinner_item);
28 | // Set layout style during dropdown
29 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
30 | // Load data from adapter
31 | spinner.setAdapter(adapter);
32 | }
33 |
34 | @Override
35 | public boolean onCreateOptionsMenu(Menu menu) {
36 | // Inflate the menu; this adds items to the action bar if it is present.
37 | getMenuInflater().inflate(R.menu.activity_spinner_with_toast, menu);
38 | return true;
39 | }
40 |
41 | public void displayVal(View v) {
42 | Toast.makeText(this, spinner.getSelectedItem().toString(), Toast.LENGTH_SHORT).show();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/TimePickerDemoActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 | import android.view.View;
7 | import android.widget.TimePicker;
8 | import android.widget.Toast;
9 |
10 | public class TimePickerDemoActivity extends Activity {
11 |
12 | TimePicker tpTime;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_time_picker_demo);
18 | tpTime = (TimePicker) findViewById(R.id.tpTime);
19 | }
20 |
21 | @Override
22 | public boolean onCreateOptionsMenu(Menu menu) {
23 | // Inflate the menu; this adds items to the action bar if it is present.
24 | getMenuInflater().inflate(R.menu.activity_time_picker_demo, menu);
25 | return true;
26 | }
27 |
28 | public void displayTime(View v) {
29 | String time = tpTime.getCurrentHour() + ":" + tpTime.getCurrentMinute();
30 | Toast.makeText(this, time, Toast.LENGTH_SHORT).show();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ToastFormInputsActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.view.Menu;
6 | import android.view.View;
7 | import android.widget.CheckBox;
8 | import android.widget.EditText;
9 | import android.widget.RadioButton;
10 | import android.widget.RadioGroup;
11 | import android.widget.Toast;
12 |
13 | public class ToastFormInputsActivity extends Activity {
14 |
15 | EditText etVal;
16 | CheckBox chkVal;
17 | RadioGroup rdgVal;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_toast_form_inputs);
23 | etVal = (EditText) findViewById(R.id.etVal);
24 | chkVal = (CheckBox) findViewById(R.id.chkVal);
25 | rdgVal = (RadioGroup) findViewById(R.id.rdgVal);
26 | }
27 |
28 | @Override
29 | public boolean onCreateOptionsMenu(Menu menu) {
30 | // Inflate the menu; this adds items to the action bar if it is present.
31 | getMenuInflater().inflate(R.menu.activity_toast_form_inputs, menu);
32 | return true;
33 | }
34 |
35 | public void toastInputs(View v) {
36 | int selected = rdgVal.getCheckedRadioButtonId();
37 | RadioButton b = (RadioButton) findViewById(selected);
38 |
39 | String text = etVal.getText() + " | " + chkVal.isChecked() + " | " + b.getText();
40 | Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/codepath/apps/demointroandroid/ViewAttributesActivity.java:
--------------------------------------------------------------------------------
1 | package codepath.apps.demointroandroid;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.widget.TextView;
8 | import android.widget.Toast;
9 |
10 | public class ViewAttributesActivity extends Activity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_view_attributes);
16 | TextView tvMain = (TextView) findViewById(R.id.tvMain);
17 | Log.d("DEBUG", tvMain.getText().toString());
18 | Toast.makeText(this, tvMain.getText().toString(), Toast.LENGTH_SHORT).show();
19 | }
20 |
21 | @Override
22 | public boolean onCreateOptionsMenu(Menu menu) {
23 | // Inflate the menu; this adds items to the action bar if it is present.
24 | getMenuInflater().inflate(R.menu.activity_view_attributes, menu);
25 | return true;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/ad.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ae.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/ae.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/af.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/af.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/ag.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ai.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/ai.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/al.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/al.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/am.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/am.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/an.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/an.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/simple_list_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_action_bar_menu.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_async_task_perform.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_basic_click_handlers.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
15 |
16 |
22 |
23 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_basic_image_download.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_basic_text_view.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_basic_views.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
14 |
15 |
22 |
23 |
24 |
25 |
26 |
32 |
33 |
40 |
41 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_button_toast.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_contact_list.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_demo_selector.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_explicit_intent.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_grid_view_demo.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_implicit_intents.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
17 |
18 |
19 |
20 |
21 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_intent_with_result.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
16 |
17 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_layout_gravity.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
20 |
21 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_linear_layout_demo.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_list_view_clicks.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_persist_settings.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
17 |
18 |
24 |
25 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_progress_bar.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
16 |
17 |
25 |
26 |
34 |
35 |
36 |
37 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_publishing_instructions.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
39 |
40 |
50 |
51 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_simple_bundle_demo.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_simple_list_view.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_simple_return_result.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_smart_image_download.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_spinner_with_toast.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_time_picker_demo.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_toast_form_inputs.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
17 |
18 |
24 |
25 |
30 |
31 |
37 |
38 |
43 |
44 |
49 |
50 |
51 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_view_attributes.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/simple_list_view_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_action_bar_menu.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_async_task_perform.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_basic_click_handlers.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_basic_image_download.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_basic_text_view.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_basic_views.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_button_toast.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_contact_list.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_demo_selector.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_explicit_intent.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_grid_view_demo.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_implicit_intents.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_intent_with_result.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_layout_gravity.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_linear_layout_demo.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_list_view_clicks.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_persist_settings.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_progress_bar.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_publishing_instructions.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_simple_bundle_demo.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_simple_list_view.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_simple_return_result.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_smart_image_download.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_spinner_with_toast.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_time_picker_demo.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_toast_form_inputs.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_view_attributes.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4b6d92
4 | #71869e
5 | #213851
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/exercises_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - App Fundamentals
5 | - User Interface
6 | - View Controls
7 | - User Interactions
8 | - User Flows
9 | - Networking
10 | - Advanced Views
11 | - Preferences
12 | - Content Providers
13 | - Publishing
14 |
15 |
16 |
17 | - Basic TextView
18 |
19 |
20 | - Linear Layout Demo
21 |
22 |
23 | - Layout Gravity
24 | - Basic Views
25 | - View Attributes
26 | - Simple ListView
27 |
28 |
29 | - Basic Click Handlers
30 | - Handling ListView Clicks
31 |
32 |
33 | - Explicit Intents
34 | - Implicit Intents
35 | - Intent with Results
36 | - Action Bar
37 |
38 |
39 | - Basic Image Download
40 | - AsyncTask
41 | - Smart Image Download
42 |
43 |
44 | - Toast Inputs
45 | - Spinner Toast
46 | - TimePicker
47 | - ProgressBar
48 | - GridView
49 |
50 |
51 | - Persist Settings
52 |
53 |
54 | - Contact List
55 |
56 |
57 | - APK Instructions
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/values/spinner_values.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - Red
5 | - Orange
6 | - Yellow
7 | - Green
8 | - Blue
9 | - Indigo
10 | - Violet
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CodePath Android Demo
5 | Hello world!
6 | Settings
7 | Basic TextView
8 |
9 | Second TextView for Chapter 1
10 | LinearLayoutDemoActivity
11 | LayoutGravityActivity
12 | BasicViewsActivity
13 | ViewAttributesActivity
14 | SimpleListViewActivity
15 | BasicClickHandlersActivity
16 | ButtonToastActivity
17 | ListViewClicksActivity
18 | ExplicitIntentActivity
19 | ImplicitIntentsActivity
20 | IntentWithResultActivity
21 | ActionBarMenuActivity
22 | SimpleBundleDemoActivity
23 | SimpleReturnResultActivity
24 | BasicImageDownloadActivity
25 | AsyncTaskPerformActivity
26 | SmartImageDownloadActivity
27 | ToastFormInputsActivity
28 | SpinnerWithToastActivity
29 | TimePickerDemoActivity
30 | ProgressBarActivity
31 | GridViewDemoActivity
32 | PersistSettingsActivity
33 | ContactListActivity
34 | PublishingInstructionsActivity
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | jcenter()
5 | google()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:3.5.0'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | jcenter()
15 | google()
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.enableJetifier=true
2 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codepath/intro_android_demo/0ddcdf083ba09f798d5c2f28c4d5217fbe5f2c7b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Aug 24 23:02:30 PDT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------