CMPS 4350 Lab-11
Software Prototyping
1. Produce a prototype for your project-3 application. 2. Identify the sensors your application will use or experiment with.
Use a pencil and paper to sketch out a step-by-step design of your application screens. Take photographs of your sketches and post them on your 4350/proj3.html web page. If you have some screen layouts already put together, you may also show those.
Android sensor identification:
Identify which sensors your application will use. Make this clear in your prototype sketch. Below is sensor documentation provided by Google. Android sensors Sensors supported: TYPE_ACCELEROMETER TYPE_AMBIENT_TEMPERATURE TYPE_GRAVITY TYPE_GYROSCOPE TYPE_LIGHT TYPE_LINEAR_ACCELERATION TYPE_MAGNETIC_FIELD TYPE_ORIENTATION TYPE_PRESSURE TYPE_PROXIMITY TYPE_RELATIVE_HUMIDITY TYPE_ROTATION_VECTOR TYPE_TEMPERATURE Examples of composit sensor output: Game rotation vector Geomagnetic rotation vector Low power sensor Glance gesture Low power sensor Gravity Gyroscope uncalibrated Linear acceleration Magnetic field uncalibrated Orientation (deprecated) Pick up gesture Low power sensor Rotation vector Significant motion Low power sensor Step counter Low power sensor Step detector Low power sensor Tilt detector Low power sensor Wake up gesture Low power sensor
Source code samples:
Below is sample code to draw graphics on a canvas (the screen).
public class MainActivity extends AppCompatActivity { ... protected void onCreate(Bundle savedInstanceState) { ... myView v; v = new myView(this); setContentView(v); ... } class myView extends View { private Paint paint; public myView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setStyle(Paint.Style.FILL_AND_STROKE); invalidate(); //causes a canvas draw } protected void onDraw(Canvas canvas) { paint.setColor(Color.rgb(255,255,0)); paint.setStyle(Paint.Style.FILL); canvas.drawRect(0, 0, x, y, paint); paint.setTextSize(100); canvas.drawText("4350 Lab-11", 0, 0, paint); } } }
Below is sample code to read a file from a web server.
Sources:get-text-from-web-page-to-string
how-to-use-separate-thread-to-perform-http-requests
public class Thx implements Runnable { @Override public void run() { try { URL url = new URL("https://cs.csub.edu/~you/4350/some-file.txt"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); StringBuilder total = new StringBuilder(); String line; while ((line = in.readLine()) != null) { total.append(line + " "); } strxx = total.toString(); in.close(); } catch (MalformedURLException e) { } catch (IOException e) { } return; } };
public class MainActivity extends AppCompatActivity implements SensorEventListener { private SensorManager mSensorManager; private Sensor mAccelerometer; private Sensor mGyroscope; ... @Override public void onCreate(Bundle savedInstanceState) { ... mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); ... } @Override protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); } @Override protected void onPause() { super.onPause(); mSensorManager.unregisterListener(this); } @Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { Toast.makeText( getApplicationContext(), "wiggle", Toast.LENGTH_SHORT ).show(); } } ... }