├── CameraBasics
├── AndroidManifest.xml
├── libs
│ └── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── main_layout.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── edu
│ └── stanford
│ └── cs231m
│ └── camerabasics
│ └── CameraActivity.java
├── HelloAndroid
├── Part1
│ ├── AndroidManifest.xml
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-v11
│ │ │ └── styles.xml
│ │ ├── values-v14
│ │ │ └── styles.xml
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ └── src
│ │ └── edu
│ │ └── stanford
│ │ └── cs231m
│ │ └── HelloAndroidActivity.java
├── Part2
│ ├── AndroidManifest.xml
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── layout
│ │ │ └── main_layout.xml
│ │ ├── values-v11
│ │ │ └── styles.xml
│ │ ├── values-v14
│ │ │ └── styles.xml
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ └── src
│ │ └── edu
│ │ └── stanford
│ │ └── cs231m
│ │ └── HelloAndroidActivity.java
├── Part3
│ ├── AndroidManifest.xml
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── layout
│ │ │ └── main_layout.xml
│ │ ├── values-v11
│ │ │ └── styles.xml
│ │ ├── values-v14
│ │ │ └── styles.xml
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ └── src
│ │ └── edu
│ │ └── stanford
│ │ └── cs231m
│ │ └── HelloAndroidActivity.java
└── Part4
│ ├── AndroidManifest.xml
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── main_layout.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── src
│ └── edu
│ └── stanford
│ └── cs231m
│ └── HelloAndroidActivity.java
├── HelloNDK
├── AndroidManifest.xml
├── jni
│ ├── Android.mk
│ ├── Application.mk
│ ├── HelloAndroid.cpp
│ └── edu_stanford_cs231m_helloandroid_HelloAndroidActivity.h
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── main_layout.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── edu
│ └── stanford
│ └── cs231m
│ └── helloandroid
│ └── HelloAndroidActivity.java
└── README.md
/CameraBasics/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/CameraBasics/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/CameraBasics/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/CameraBasics/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/CameraBasics/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/CameraBasics/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/CameraBasics/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraBasics/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/CameraBasics/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraBasics/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/CameraBasics/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CameraBasics/res/layout/main_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
14 |
15 |
16 |
21 |
22 |
27 |
28 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/CameraBasics/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/CameraBasics/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/CameraBasics/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | CameraBasics
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CameraBasics/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/CameraBasics/src/edu/stanford/cs231m/camerabasics/CameraActivity.java:
--------------------------------------------------------------------------------
1 | package edu.stanford.cs231m.camerabasics;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.app.Activity;
7 | import android.content.Context;
8 | import android.hardware.camera2.CameraAccessException;
9 | import android.hardware.camera2.CameraCaptureSession;
10 | import android.hardware.camera2.CameraCharacteristics;
11 | import android.hardware.camera2.CameraDevice;
12 | import android.hardware.camera2.CaptureRequest;
13 | import android.hardware.camera2.CameraDevice.StateCallback;
14 | import android.hardware.camera2.CameraManager;
15 | import android.hardware.camera2.params.StreamConfigurationMap;
16 | import android.os.Bundle;
17 | import android.util.Log;
18 | import android.view.Surface;
19 | import android.view.SurfaceHolder;
20 | import android.view.SurfaceView;
21 | import android.widget.TextView;
22 |
23 | public class CameraActivity extends Activity {
24 |
25 | final static String TAG = "CameraActivity";
26 |
27 | TextView mMainTxt;
28 | SurfaceView mCameraView;
29 |
30 | CameraManager mCameraManager;
31 | CameraDevice mCameraDevice;
32 | CameraCaptureSession mCaptureSession;
33 |
34 | @Override
35 | protected void onPause() {
36 | if (mCameraDevice != null) {
37 | mCameraDevice.close();
38 | }
39 |
40 | super.onPause();
41 | }
42 |
43 | @Override
44 | public void onCreate(Bundle settings) {
45 |
46 | setContentView(R.layout.main_layout);
47 |
48 | mCameraView = (SurfaceView) findViewById(R.id.cameraView);
49 | mCameraView.getHolder().addCallback( new SurfaceHolder.Callback() {
50 |
51 | @Override
52 | public void surfaceDestroyed(SurfaceHolder holder) {
53 | }
54 |
55 | @Override
56 | public void surfaceCreated(SurfaceHolder holder) {
57 | holder.setFixedSize(1296, 972);
58 | openBackFacingCamera();
59 | }
60 |
61 | @Override
62 | public void surfaceChanged(SurfaceHolder holder, int format, int width,
63 | int height) {
64 | // TODO Auto-generated method stub
65 |
66 | }
67 | });
68 |
69 | mCameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
70 | super.onCreate(settings);
71 | }
72 |
73 | private void startCamera() {
74 |
75 | try {
76 | CaptureRequest.Builder builder;
77 |
78 | // Create the request builder.
79 | builder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
80 | builder.addTarget( mCameraView.getHolder().getSurface() );
81 |
82 | mCaptureSession.setRepeatingRequest( builder.build(), null, null);
83 |
84 | } catch( CameraAccessException e) {
85 | Log.e(TAG, "Camera Access Exception in call to createCaptureRequest");
86 | }
87 | }
88 |
89 | private void createCaptureSession() {
90 |
91 | // Create the list of outputs.
92 | ArrayList outputs = new ArrayList();
93 | outputs.add( mCameraView.getHolder().getSurface() );
94 |
95 | try {
96 | mCameraDevice.createCaptureSession(
97 | outputs,
98 | new CameraCaptureSession.StateCallback() {
99 |
100 | @Override
101 | public void onConfigureFailed(CameraCaptureSession session) {
102 | Log.e(TAG, "Failed to configure capture session");
103 |
104 | }
105 |
106 | @Override
107 | public void onConfigured(CameraCaptureSession session) {
108 | Log.i(TAG, "CaptureSession configured successfuly");
109 | mCaptureSession = session;
110 | startCamera();
111 | }
112 |
113 | },
114 | null);
115 |
116 | } catch( CameraAccessException e) {
117 | Log.e(TAG, "Camera Access Exception in call to createCaptureSession");
118 | }
119 | }
120 |
121 | private void openBackFacingCamera()
122 | {
123 | String cameraId = findBackFacingCamera();
124 |
125 | try
126 | {
127 | mCameraManager.openCamera(
128 |
129 | cameraId,
130 |
131 | new StateCallback() {
132 |
133 | @Override
134 | public void onDisconnected(CameraDevice arg0) {
135 | Log.e(TAG, "Camera was disconnected\n");
136 | }
137 |
138 | @Override
139 | public void onError(CameraDevice arg0, int arg1) {
140 | Log.e(TAG, "Error opening camera");
141 | }
142 |
143 | @Override
144 | public void onOpened(CameraDevice arg0) {
145 | Log.i(TAG, "Opened camera!");
146 | mCameraDevice = arg0;
147 | createCaptureSession();
148 | }
149 |
150 | }
151 |
152 | , null);
153 | }
154 | catch ( CameraAccessException e)
155 | {
156 |
157 | }
158 | }
159 |
160 | private String findBackFacingCamera()
161 | {
162 | try {
163 | String cameraIdList[] = mCameraManager.getCameraIdList();
164 |
165 | for ( int i = 0; i < cameraIdList.length; ++i )
166 | {
167 | // Get the camera characteristics
168 | CameraCharacteristics properties;
169 | properties = mCameraManager.getCameraCharacteristics(cameraIdList[i]);
170 |
171 | if ( properties.get( CameraCharacteristics.LENS_FACING ) ==
172 | CameraCharacteristics.LENS_FACING_BACK ) {
173 |
174 | // We have found the camera, list the available sizes.
175 | StreamConfigurationMap map = mCameraManager.getCameraCharacteristics(cameraIdList[i]).
176 | get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
177 |
178 | android.util.Size sizes[] = map.getOutputSizes(SurfaceHolder.class);
179 |
180 | for ( int j = 0; j < sizes.length; j++ ) {
181 | Log.i(TAG, "- " + sizes[j].getWidth() + " x " + sizes[j].getHeight());
182 | }
183 |
184 | return cameraIdList[i];
185 | }
186 |
187 | }
188 |
189 | } catch( CameraAccessException e ) {
190 |
191 | Log.e(TAG, "CameraAccessException in enumerateCameras()");
192 | }
193 |
194 | return null;
195 | }
196 |
197 | }
198 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part1/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part1/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part1/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part1/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part1/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part1/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloAndroid
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part1/src/edu/stanford/cs231m/HelloAndroidActivity.java:
--------------------------------------------------------------------------------
1 | package edu.stanford.cs231m;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | public class HelloAndroidActivity extends Activity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 |
12 | TextView txtView = new TextView(this);
13 | txtView.setText("Hello Android!");
14 | setContentView(txtView);
15 |
16 | super.onCreate(savedInstanceState);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part2/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part2/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part2/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/layout/main_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloAndroid
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part2/src/edu/stanford/cs231m/HelloAndroidActivity.java:
--------------------------------------------------------------------------------
1 | package edu.stanford.cs231m;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.view.View.OnClickListener;
8 | import android.widget.Button;
9 | import android.widget.TextView;
10 |
11 | public class HelloAndroidActivity extends Activity {
12 |
13 | protected static final String TAG = "HelloAndroid";
14 | private TextView mMainText;
15 | private Button mButton1;
16 | private Button mButton2;
17 |
18 |
19 | @Override
20 | public void onCreate(Bundle settings) {
21 |
22 | setContentView(R.layout.main_layout);
23 |
24 | mMainText = (TextView) findViewById(R.id.txtMain);
25 | mButton1 = (Button) findViewById(R.id.button1);
26 | mButton2 = (Button) findViewById(R.id.button2);
27 |
28 | mMainText.setText("Hello Android!\n");
29 |
30 | mButton1.setOnClickListener( new OnClickListener() {
31 |
32 | @Override
33 | public void onClick(View v) {
34 | mMainText.append("Button 1 was pressed!\n");
35 | Log.i(TAG, "Button 1 was pressed");
36 | }
37 | });
38 |
39 | mButton2.setOnClickListener( new OnClickListener() {
40 |
41 | @Override
42 | public void onClick(View v) {
43 | mMainText.append("Button 2 was pressed!\n");
44 | Log.i(TAG, "Button 2 was pressed");
45 | }
46 | });
47 |
48 | super.onCreate(settings);
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/HelloAndroid/Part3/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part3/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part3/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part3/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/layout/main_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloAndroid
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part3/src/edu/stanford/cs231m/HelloAndroidActivity.java:
--------------------------------------------------------------------------------
1 | package edu.stanford.cs231m;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.File;
5 | import java.io.FileWriter;
6 | import java.io.IOException;
7 |
8 | import android.app.Activity;
9 | import android.os.Bundle;
10 | import android.os.Environment;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.view.View.OnClickListener;
14 | import android.widget.Button;
15 | import android.widget.TextView;
16 |
17 | public class HelloAndroidActivity extends Activity {
18 |
19 | protected static final String TAG = "HelloAndroid";
20 | private TextView mMainText;
21 | private Button mButton1;
22 | private Button mButton2;
23 | private BufferedWriter mLogWriter;
24 |
25 |
26 | @Override
27 | public void onCreate(Bundle settings) {
28 |
29 | setContentView(R.layout.main_layout);
30 | mLogWriter = openLogFile();
31 |
32 | mMainText = (TextView) findViewById(R.id.txtMain);
33 | mButton1 = (Button) findViewById(R.id.button1);
34 | mButton2 = (Button) findViewById(R.id.button2);
35 |
36 | mMainText.setText("Hello Android!\n");
37 |
38 | mButton1.setOnClickListener( new OnClickListener() {
39 |
40 | @Override
41 | public void onClick(View v) {
42 | mMainText.append("Button 1 was pressed!\n");
43 | Log.i(TAG, "Button 1 was pressed");
44 | logMessage("Button 1 was pressed");
45 | }
46 | });
47 |
48 | mButton2.setOnClickListener( new OnClickListener() {
49 |
50 | @Override
51 | public void onClick(View v) {
52 | mMainText.append("Button 2 was pressed!\n");
53 | Log.i(TAG, "Button 2 was pressed");
54 | logMessage("Button 2 was pressed");
55 | }
56 | });
57 |
58 | super.onCreate(settings);
59 | }
60 |
61 | private void logMessage( String message )
62 | {
63 | if ( mLogWriter != null )
64 | {
65 | try {
66 | mLogWriter.write(message);
67 | mLogWriter.newLine();
68 | mLogWriter.flush();
69 | } catch (IOException e) {
70 | Log.e(TAG, "Failed to write to log file");
71 | }
72 |
73 | }
74 | }
75 |
76 | private BufferedWriter openLogFile()
77 | {
78 |
79 | File appExternalDir = new File( Environment.getExternalStorageDirectory(),
80 | "HelloAndroid");
81 |
82 | if ( !appExternalDir.exists() )
83 | {
84 | if ( appExternalDir.mkdirs() )
85 | {
86 | Log.i(TAG, "External storage directory created: " + appExternalDir.toString() );
87 | }
88 | else
89 | {
90 | Log.e(TAG, "Failed to create directory " + appExternalDir.toString() );
91 | return null;
92 | }
93 | }
94 |
95 | File logFile = new File( appExternalDir, "log.txt");
96 |
97 | BufferedWriter writer = null;
98 | try {
99 | writer = new BufferedWriter( new FileWriter(logFile));
100 | Log.i(TAG, "Created log file" + logFile);
101 | } catch (IOException e) {
102 | Log.e(TAG, "Failed to create file " + logFile.toString() );
103 | return null;
104 | }
105 |
106 | return writer;
107 | }
108 |
109 |
110 | }
--------------------------------------------------------------------------------
/HelloAndroid/Part4/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part4/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part4/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloAndroid/Part4/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/layout/main_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloAndroid
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/HelloAndroid/Part4/src/edu/stanford/cs231m/HelloAndroidActivity.java:
--------------------------------------------------------------------------------
1 | package edu.stanford.cs231m;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.File;
5 | import java.io.FileWriter;
6 | import java.io.IOException;
7 | import java.lang.Thread;
8 |
9 | import android.app.Activity;
10 | import android.app.ProgressDialog;
11 | import android.os.Bundle;
12 | import android.os.Environment;
13 | import android.os.Handler;
14 | import android.os.Message;
15 | import android.util.Log;
16 | import android.view.View;
17 | import android.view.View.OnClickListener;
18 | import android.widget.Button;
19 | import android.widget.TextView;
20 |
21 | public class HelloAndroidActivity extends Activity {
22 |
23 | protected static final String TAG = "HelloAndroid";
24 | private TextView mMainText;
25 | private Button mButton1;
26 | private Button mButton2;
27 | private BufferedWriter mLogWriter;
28 | private Thread mWorkerThread;
29 | private Handler mHandler;
30 | private ProgressDialog mProgress;
31 |
32 |
33 | private final static int MSG_ASYNC_TASK_STARTED = 0;
34 | private final static int MSG_ASYNC_TASK_COMPLETED = 1;
35 |
36 |
37 | @Override
38 | public void onCreate(Bundle settings) {
39 |
40 | setContentView(R.layout.main_layout);
41 | mLogWriter = openLogFile();
42 | mHandler = new Handler(mHandlerCallback);
43 | mProgress = new ProgressDialog(this);
44 |
45 | mMainText = (TextView) findViewById(R.id.txtMain);
46 | mButton1 = (Button) findViewById(R.id.button1);
47 | mButton2 = (Button) findViewById(R.id.button2);
48 |
49 | mMainText.setText("Hello Android!\n");
50 |
51 | mButton1.setOnClickListener( new OnClickListener() {
52 |
53 | @Override
54 | public void onClick(View v) {
55 | mMainText.append("Button 1 was pressed!\n");
56 | Log.i(TAG, "Button 1 was pressed");
57 | logMessage("Button 1 was pressed");
58 | }
59 | });
60 |
61 | mButton2.setOnClickListener( new OnClickListener() {
62 |
63 | @Override
64 | public void onClick(View v) {
65 | mMainText.append("Button 2 was pressed!\n");
66 | Log.i(TAG, "Button 2 was pressed");
67 | logMessage("Button 2 was pressed");
68 | mWorkerThread = new Thread ( new Runnable() {
69 |
70 | @Override
71 | public void run() {
72 | longRunningTask(6000);
73 | };
74 | });
75 | mWorkerThread.start();
76 | }
77 | });
78 |
79 | super.onCreate(settings);
80 | }
81 |
82 | private void logMessage( String message )
83 | {
84 | if ( mLogWriter != null )
85 | {
86 | try {
87 | mLogWriter.write(message);
88 | mLogWriter.newLine();
89 | mLogWriter.flush();
90 | } catch (IOException e) {
91 | Log.e(TAG, "Failed to write to log file");
92 | }
93 |
94 | }
95 | }
96 |
97 | private BufferedWriter openLogFile()
98 | {
99 |
100 | File appExternalDir = new File( Environment.getExternalStorageDirectory(),
101 | "HelloAndroid");
102 |
103 | if ( !appExternalDir.exists() )
104 | {
105 | if ( appExternalDir.mkdirs() )
106 | {
107 | Log.i(TAG, "External storage directory created: " + appExternalDir.toString() );
108 | }
109 | else
110 | {
111 | Log.e(TAG, "Failed to create directory " + appExternalDir.toString() );
112 | return null;
113 | }
114 | }
115 |
116 | File logFile = new File( appExternalDir, "log.txt");
117 |
118 | BufferedWriter writer = null;
119 | try {
120 | writer = new BufferedWriter( new FileWriter(logFile));
121 | Log.i(TAG, "Created log file" + logFile);
122 | } catch (IOException e) {
123 | Log.e(TAG, "Failed to create file " + logFile.toString() );
124 | return null;
125 | }
126 |
127 | return writer;
128 | }
129 |
130 | private void longRunningTask( long taskDurationInMs )
131 | {
132 | long startTime = System.currentTimeMillis();
133 | mHandler.sendEmptyMessage(MSG_ASYNC_TASK_STARTED);
134 |
135 | long currentTime = startTime;
136 | do
137 | {
138 | try {
139 | Thread.sleep( taskDurationInMs );
140 | } catch (InterruptedException e) {
141 | }
142 |
143 | currentTime = System.currentTimeMillis();
144 |
145 | } while ( currentTime < startTime + taskDurationInMs );
146 |
147 | mHandler.sendEmptyMessage(MSG_ASYNC_TASK_COMPLETED);
148 | }
149 |
150 | private Handler.Callback mHandlerCallback = new Handler.Callback() {
151 |
152 | @Override
153 | public boolean handleMessage(Message msg) {
154 |
155 | long currentTime = System.currentTimeMillis();
156 | switch( msg.what )
157 | {
158 | case MSG_ASYNC_TASK_STARTED:
159 | mMainText.append("Async task started at " + currentTime + "\n");
160 | mProgress.setTitle("Running async task");
161 | mProgress.setMessage("Wait...");
162 | mProgress.show();
163 | return true;
164 | case MSG_ASYNC_TASK_COMPLETED:
165 | mMainText.append("Async task ended at " + currentTime + "\n");
166 | mProgress.dismiss();
167 | return true;
168 | default:
169 | // The message was not handled, return false
170 | return false;
171 | }
172 | }
173 | };
174 | }
--------------------------------------------------------------------------------
/HelloNDK/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/HelloNDK/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | ifeq (1, $(NDK_DEBUG))
6 | LOCAL_CFLAGS += -DWAIT_FOR_DEBUGGER
7 | endif
8 |
9 | LOCAL_MODULE := HelloAndroid
10 | LOCAL_SRC_FILES := HelloAndroid.cpp
11 |
12 | include $(BUILD_SHARED_LIBRARY)
13 |
--------------------------------------------------------------------------------
/HelloNDK/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_PLATFORM := android-19
2 | APP_ABI := armeabi-v7a
3 | APP_STL := gnustl_static
--------------------------------------------------------------------------------
/HelloNDK/jni/HelloAndroid.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | #if defined(WAIT_FOR_DEBUGGER)
5 |
6 | void waitForDebugger()
7 | {
8 | static volatile int debug = 1;
9 | while( debug )
10 | {}
11 | }
12 |
13 | #else
14 |
15 | void waitForDebugger() {}
16 |
17 | #endif;
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | /*
24 | * Class: edu_stanford_cs231m_helloandroid_HelloAndroidActivity
25 | * Method: square
26 | * Signature: (I)I
27 | */
28 | JNIEXPORT jint JNICALL Java_edu_stanford_cs231m_helloandroid_HelloAndroidActivity_square
29 | (JNIEnv *jni, jobject thiz, jint n)
30 | {
31 | return n * n;
32 | }
33 |
34 | #ifdef __cplusplus
35 | }
36 | #endif
37 |
--------------------------------------------------------------------------------
/HelloNDK/jni/edu_stanford_cs231m_helloandroid_HelloAndroidActivity.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class edu_stanford_cs231m_helloandroid_HelloAndroidActivity */
4 |
5 | #ifndef _Included_edu_stanford_cs231m_helloandroid_HelloAndroidActivity
6 | #define _Included_edu_stanford_cs231m_helloandroid_HelloAndroidActivity
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_ABOVE_CLIENT
11 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_ABOVE_CLIENT 8L
12 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_ADJUST_WITH_ACTIVITY
13 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_ADJUST_WITH_ACTIVITY 128L
14 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_ALLOW_OOM_MANAGEMENT
15 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_ALLOW_OOM_MANAGEMENT 16L
16 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_AUTO_CREATE
17 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_AUTO_CREATE 1L
18 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_DEBUG_UNBIND
19 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_DEBUG_UNBIND 2L
20 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_IMPORTANT
21 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_IMPORTANT 64L
22 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_NOT_FOREGROUND
23 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_NOT_FOREGROUND 4L
24 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_WAIVE_PRIORITY
25 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_BIND_WAIVE_PRIORITY 32L
26 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_CONTEXT_IGNORE_SECURITY
27 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_CONTEXT_IGNORE_SECURITY 2L
28 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_CONTEXT_INCLUDE_CODE
29 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_CONTEXT_INCLUDE_CODE 1L
30 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_CONTEXT_RESTRICTED
31 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_CONTEXT_RESTRICTED 4L
32 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_APPEND
33 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_APPEND 32768L
34 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_ENABLE_WRITE_AHEAD_LOGGING
35 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_ENABLE_WRITE_AHEAD_LOGGING 8L
36 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_MULTI_PROCESS
37 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_MULTI_PROCESS 4L
38 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_PRIVATE
39 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_PRIVATE 0L
40 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_WORLD_READABLE
41 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_WORLD_READABLE 1L
42 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_WORLD_WRITEABLE
43 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MODE_WORLD_WRITEABLE 2L
44 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_DIALER
45 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_DIALER 1L
46 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_DISABLE
47 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_DISABLE 0L
48 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_SEARCH_GLOBAL
49 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_SEARCH_GLOBAL 4L
50 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_SEARCH_LOCAL
51 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_SEARCH_LOCAL 3L
52 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_SHORTCUT
53 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_DEFAULT_KEYS_SHORTCUT 2L
54 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_RESULT_CANCELED
55 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_RESULT_CANCELED 0L
56 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_RESULT_FIRST_USER
57 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_RESULT_FIRST_USER 1L
58 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_RESULT_OK
59 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_RESULT_OK -1L
60 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MSG_ASYNC_TASK_STARTED
61 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MSG_ASYNC_TASK_STARTED 0L
62 | #undef edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MSG_ASYNC_TASK_COMPLETED
63 | #define edu_stanford_cs231m_helloandroid_HelloAndroidActivity_MSG_ASYNC_TASK_COMPLETED 1L
64 | /*
65 | * Class: edu_stanford_cs231m_helloandroid_HelloAndroidActivity
66 | * Method: square
67 | * Signature: (I)I
68 | */
69 | JNIEXPORT jint JNICALL Java_edu_stanford_cs231m_helloandroid_HelloAndroidActivity_square
70 | (JNIEnv *, jobject, jint);
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 | #endif
76 |
--------------------------------------------------------------------------------
/HelloNDK/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/HelloNDK/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/HelloNDK/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloNDK/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloNDK/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloNDK/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloNDK/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cvgl-edu/cs231m-2015/5942e1e73bc3eaad22dc615262a8ed2ca9ffe81d/HelloNDK/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/HelloNDK/res/layout/main_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/HelloNDK/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/HelloNDK/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/HelloNDK/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloAndroid
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloNDK/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/HelloNDK/src/edu/stanford/cs231m/helloandroid/HelloAndroidActivity.java:
--------------------------------------------------------------------------------
1 | package edu.stanford.cs231m.helloandroid;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.File;
5 | import java.io.FileWriter;
6 | import java.io.IOException;
7 |
8 | import android.app.Activity;
9 | import android.app.ProgressDialog;
10 | import android.os.Bundle;
11 | import android.os.Environment;
12 | import android.os.Handler;
13 | import android.os.Message;
14 | import android.util.Log;
15 | import android.view.View;
16 | import android.view.View.OnClickListener;
17 | import android.widget.Button;
18 | import android.widget.TextView;
19 |
20 | public class HelloAndroidActivity extends Activity {
21 |
22 | protected static final String TAG = "HelloAndroid";
23 | private TextView mMainText;
24 | private Button mButton1;
25 | private Button mButton2;
26 |
27 | private BufferedWriter mLogWriter;
28 | private Thread mWorkerThread;
29 | private Handler mHandler;
30 | private ProgressDialog mProgress;
31 |
32 | private final static int MSG_ASYNC_TASK_STARTED = 0;
33 | private final static int MSG_ASYNC_TASK_COMPLETED = 1;
34 |
35 | @Override
36 | public void onCreate(Bundle settings) {
37 |
38 | setContentView(R.layout.main_layout);
39 |
40 | mLogWriter = openLogFile();
41 | mHandler = new Handler(mHandlerCallback);
42 | mProgress = new ProgressDialog(this);
43 |
44 | mMainText = (TextView) findViewById(R.id.txtMain);
45 | mButton1 = (Button) findViewById(R.id.button1);
46 | mButton2 = (Button) findViewById(R.id.button2);
47 |
48 | mMainText.setText("Hello Android!\n");
49 |
50 | mButton1.setOnClickListener( new OnClickListener() {
51 |
52 | @Override
53 | public void onClick(View v) {
54 | mMainText.append("Button 1 was pressed!\n");
55 | mMainText.append("The square of 2 is " + square(2) + "\n");
56 | logMessage("Button 1 was pressed!");
57 | Log.i(TAG, "Button 1 was pressed!");
58 | }
59 | });
60 |
61 | mButton2.setOnClickListener( new OnClickListener() {
62 |
63 | @Override
64 | public void onClick(View v) {
65 | mMainText.append("Button 2 was pressed!\n");
66 | logMessage("Button 2 was pressed!");
67 | Log.i(TAG, "Button 2 was pressed");
68 |
69 | mWorkerThread = new Thread( new Runnable() {
70 |
71 | @Override
72 | public void run() {
73 | longRunningTask(6000);
74 | }
75 | });
76 |
77 | mWorkerThread.start();
78 | }
79 | });
80 |
81 | super.onCreate(settings);
82 | }
83 |
84 | private void logMessage( String message )
85 | {
86 | if ( mLogWriter != null )
87 | {
88 | try {
89 | mLogWriter.write(message);
90 | mLogWriter.newLine();
91 | mLogWriter.flush();
92 | } catch (IOException e) {
93 | Log.e(TAG, "Failed to write to log file");
94 | }
95 |
96 | }
97 | }
98 |
99 | private Handler.Callback mHandlerCallback = new Handler.Callback() {
100 |
101 | @Override
102 | public boolean handleMessage(Message msg) {
103 |
104 | long currentTime = System.currentTimeMillis();
105 | switch( msg.what )
106 | {
107 | case MSG_ASYNC_TASK_STARTED:
108 | mMainText.append("Async task started at " + currentTime + "\n");
109 | mProgress.setTitle("Running async task");
110 | mProgress.setMessage("Wait...");
111 | mProgress.show();
112 | return true;
113 | case MSG_ASYNC_TASK_COMPLETED:
114 | mMainText.append("Async task ended at " + currentTime + "\n");
115 | mProgress.dismiss();
116 | return true;
117 | default:
118 | // The message was not handled, return false
119 | return false;
120 | }
121 | }
122 | };
123 |
124 | private void longRunningTask( long taskDurationInMs )
125 | {
126 | long startTime = System.currentTimeMillis();
127 | mHandler.sendEmptyMessage(MSG_ASYNC_TASK_STARTED);
128 |
129 | long currentTime = startTime;
130 | do
131 | {
132 | try {
133 | Thread.sleep( taskDurationInMs );
134 | } catch (InterruptedException e) {
135 | }
136 |
137 | currentTime = System.currentTimeMillis();
138 |
139 | } while ( currentTime < startTime + taskDurationInMs );
140 |
141 | mHandler.sendEmptyMessage(MSG_ASYNC_TASK_COMPLETED);
142 |
143 | }
144 |
145 | private BufferedWriter openLogFile()
146 | {
147 |
148 | File appExternalDir = new File( Environment.getExternalStorageDirectory(),
149 | "HelloAndroid");
150 |
151 | if ( !appExternalDir.exists() )
152 | {
153 | if ( appExternalDir.mkdirs() )
154 | {
155 | Log.i(TAG, "External storage directory created: " + appExternalDir.toString() );
156 | }
157 | else
158 | {
159 | Log.e(TAG, "Failed to create directory " + appExternalDir.toString() );
160 | return null;
161 | }
162 | }
163 |
164 | File logFile = new File( appExternalDir, "log.txt");
165 |
166 | BufferedWriter writer = null;
167 | try {
168 | writer = new BufferedWriter( new FileWriter(logFile));
169 | } catch (IOException e) {
170 | Log.e(TAG, "Failed to create file " + logFile.toString() );
171 | return null;
172 | }
173 |
174 | return writer;
175 | }
176 |
177 | private native int square(int n);
178 |
179 | static {
180 | System.loadLibrary("HelloAndroid");
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Welcome to the CS231M code repository!
2 |
--------------------------------------------------------------------------------