Last active
September 8, 2017 04:13
-
-
Save chaynika/5b972f6635db6a12116f57485785934c to your computer and use it in GitHub Desktop.
oncreate() for MC 08/30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
tools:context="com.healthmonitor.khann.healthmonitor.MainActivity"> | |
<Button | |
android:id="@+id/run" | |
style="@style/Widget.AppCompat.Button.Borderless" | |
android:layout_width="89dp" | |
android:layout_height="40dp" | |
android:layout_marginLeft="387dp" | |
android:layout_marginStart="387dp" | |
android:layout_marginTop="16dp" | |
android:background="@android:color/holo_green_light" | |
android:text="Run" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<Button | |
android:id="@+id/stop" | |
android:layout_width="87dp" | |
android:layout_height="40dp" | |
android:layout_marginTop="16dp" | |
android:background="@android:color/holo_red_light" | |
android:text="Stop" | |
app:layout_constraintTop_toTopOf="parent" | |
app:layout_constraintLeft_toRightOf="@+id/run" | |
android:layout_marginLeft="8dp" /> | |
<com.jjoe64.graphview.GraphView | |
android:id="@+id/graph" | |
android:layout_width="558dp" | |
android:layout_height="204dp" | |
android:layout_marginEnd="8dp" | |
android:layout_marginLeft="16dp" | |
android:layout_marginRight="8dp" | |
android:layout_marginStart="16dp" | |
android:layout_marginTop="67dp" | |
app:layout_constraintHorizontal_bias="0.0" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<EditText | |
android:id="@+id/editText" | |
android:layout_width="60dp" | |
android:layout_height="42dp" | |
android:ems="10" | |
android:inputType="textPersonName" | |
android:text="P Name" | |
android:textSize="12sp" | |
app:layout_constraintTop_toTopOf="parent" | |
android:layout_marginTop="16dp" | |
app:layout_constraintLeft_toRightOf="@+id/editText5" | |
android:layout_marginLeft="8dp" /> | |
<EditText | |
android:id="@+id/editText2" | |
android:layout_width="45dp" | |
android:layout_height="42dp" | |
android:ems="10" | |
android:inputType="textPersonName" | |
android:text="P ID:" | |
android:textSize="12sp" | |
tools:layout_editor_absoluteX="16dp" | |
app:layout_constraintTop_toTopOf="parent" | |
android:layout_marginTop="16dp" /> | |
<EditText | |
android:id="@+id/editText5" | |
android:layout_width="50dp" | |
android:layout_height="42dp" | |
android:ems="10" | |
android:inputType="number" | |
android:text="Age" | |
android:textSize="12sp" | |
app:layout_constraintLeft_toRightOf="@+id/editText2" | |
android:layout_marginLeft="9dp" | |
app:layout_constraintTop_toTopOf="parent" | |
android:layout_marginTop="16dp" /> | |
<TextView | |
android:id="@+id/textView6" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Sex:" | |
android:textSize="12sp" | |
app:layout_constraintTop_toTopOf="parent" | |
android:layout_marginTop="34dp" | |
app:layout_constraintLeft_toRightOf="@+id/editText" | |
android:layout_marginLeft="12dp" /> | |
<RadioGroup | |
android:id="@+id/radioSex" | |
android:layout_width="159dp" | |
android:layout_height="57dp" | |
android:layout_marginLeft="12dp" | |
android:layout_marginTop="-1dp" | |
android:checkedButton="@+id/radioButton" | |
android:orientation='horizontal' | |
app:layout_constraintLeft_toRightOf="@+id/editText" | |
app:layout_constraintTop_toTopOf="parent">> | |
<RadioButton | |
android:id="@+id/radioButton" | |
android:layout_width="75dp" | |
android:layout_height="26dp" | |
android:layout_marginLeft="14dp" | |
android:layout_marginTop="30dp" | |
android:scaleX="0.5" | |
android:scaleY="0.5" | |
android:text="Female" | |
android:textSize="12sp" | |
app:layout_constraintLeft_toRightOf="@+id/radioButton2" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<RadioButton | |
android:id="@+id/radioButton2" | |
android:layout_width="64dp" | |
android:layout_height="27dp" | |
android:layout_marginLeft="14dp" | |
android:layout_marginTop="29dp" | |
android:scaleX="0.5" | |
android:scaleY="0.5" | |
android:text="Male" | |
android:textSize="12sp" | |
app:layout_constraintLeft_toRightOf="@+id/editText" | |
app:layout_constraintTop_toTopOf="parent" /> | |
</RadioGroup> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.healthmonitor.khann.healthmonitor; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import com.jjoe64.graphview.GraphView; | |
import com.jjoe64.graphview.series.DataPoint; | |
import com.jjoe64.graphview.series.LineGraphSeries; | |
import com.jjoe64.graphview.Viewport; | |
import java.util.Random; | |
import android.widget.Button; | |
import android.view.View.OnClickListener; | |
import android.util.Log; | |
public class MainActivity extends AppCompatActivity implements OnClickListener { | |
// Declare all the private variables for this class | |
private LineGraphSeries mSeries1 = new LineGraphSeries<>(); | |
Random rand = new Random(); | |
int x_value = 0; | |
Button runButton, stopButton; | |
GraphView graphView; | |
boolean firstRun = true; | |
// Reference to implement own Runnable class: | |
// https://www.tutorialspoint.com/java/java_thread_control.htm | |
class RunnableDemo implements Runnable { | |
public Thread thread; | |
public boolean suspended = false; | |
RunnableDemo() { | |
} | |
public void run() { | |
// we add 5000 new entries | |
for (int i = 0; i < 5000; i++) { | |
runOnUiThread(new RunnableDemo() { | |
@Override | |
public void run() { | |
addEntry(); | |
} | |
}); | |
// sleep to slow down the add of entries | |
try { | |
Thread.sleep(500); | |
synchronized (this) { | |
while (suspended) { | |
wait(); | |
} | |
} | |
} catch (InterruptedException e) { | |
// manage error ... | |
} | |
} | |
} | |
void start () { | |
if (thread == null) { | |
thread = new Thread (this); | |
thread.start (); | |
} | |
} | |
void suspend() { | |
suspended = true; | |
} | |
synchronized void resume() { | |
suspended = false; | |
notify(); | |
} | |
} | |
RunnableDemo R1 = new RunnableDemo(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
// All initializations should go here | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
runButton = (Button) findViewById(R.id.run); | |
runButton.setOnClickListener(this); | |
stopButton = (Button) findViewById(R.id.stop); | |
stopButton.setOnClickListener(this); | |
graphView = (GraphView) findViewById(R.id.graph); | |
Viewport viewport = graphView.getViewport(); | |
viewport.setYAxisBoundsManual(true); | |
viewport.setMinY(0); | |
viewport.setMaxY(2000); | |
viewport.setScrollable(true); | |
viewport.setBackgroundColor(-16777216); | |
viewport.setDrawBorder(true); | |
viewport.setXAxisBoundsManual(true); | |
viewport.setMinX(0); | |
viewport.setMaxX(40); | |
viewport.setScalable(true); | |
} | |
@Override | |
public void onClick(View view) { | |
switch (view.getId()) { | |
case R.id.run: | |
Log.d("MR.bool", "Run was clicked "); | |
runButton.setEnabled(false); | |
stopButton.setEnabled(true); | |
graphView.addSeries(mSeries1); | |
if (firstRun) { | |
R1.start(); | |
} else { | |
R1.resume(); | |
} | |
break; | |
case R.id.stop: | |
// TODO Need to write function for stop by adding wait() to the thread | |
Log.d("MR.bool", "Stop was clicked "); | |
GraphView graph = (GraphView) findViewById(R.id.graph); | |
graph.removeAllSeries(); | |
runButton.setEnabled(true); | |
stopButton.setEnabled(false); | |
firstRun = false; | |
R1.suspend(); | |
break; | |
} | |
} | |
private void addEntry() { | |
float y = rand.nextFloat() * (2000 - 20) + 20; | |
mSeries1.appendData(new DataPoint(x_value, y), true, 500); | |
x_value += 1; | |
} | |
} |
package com.healthmonitor.khann.healthmonitor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.Viewport;
import java.util.Random;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.util.Log;
// Wherever not marked as reference, is our code.
public class MainActivity extends AppCompatActivity implements OnClickListener {
// Declare all the private variables for this class
private LineGraphSeries mSeries1 = new LineGraphSeries<>();
Random rand = new Random();
int x_value = 0;
Button runButton, stopButton;
GraphView graphView;
boolean firstRun = true;
// Reference to implement own Runnable class:
// https://www.tutorialspoint.com/java/java_thread_control.htm
class RunnableDemo implements Runnable {
public Thread thread;
public boolean suspended = false;
public void run() {
// we add 5000 new entries
for (int i = 0; i < 5000; i++) {
runOnUiThread(new RunnableDemo() {
@Override
public void run() {
addEntry();
}
});
// sleep to slow down the add of entries
try {
Thread.sleep(500);
synchronized (this) {
while (suspended) {
wait();
}
}
} catch (InterruptedException e) {
System.out.println("Exception caught: " + e);
}
}
}
void start () {
if (thread == null) {
thread = new Thread (this);
thread.start ();
}
}
void suspend() {
suspended = true;
}
synchronized void resume() {
suspended = false;
notify();
}
}
RunnableDemo R1 = new RunnableDemo();
@Override
protected void onCreate(Bundle savedInstanceState) {
// All initializations should go here
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
runButton = (Button) findViewById(R.id.run);
runButton.setOnClickListener(this);
stopButton = (Button) findViewById(R.id.stop);
stopButton.setOnClickListener(this);
graphView = (GraphView) findViewById(R.id.graph);
Viewport viewport = graphView.getViewport();
viewport.setYAxisBoundsManual(true);
viewport.setMinY(0);
viewport.setMaxY(2000);
viewport.setScrollable(true);
viewport.setBackgroundColor(-16777216);
viewport.setDrawBorder(true);
viewport.setXAxisBoundsManual(true);
viewport.setMinX(0);
viewport.setMaxX(40);
viewport.setScalable(true);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.run:
// Triggered when run is clicked
Log.d("MR.bool", "Run was clicked ");
// runButton.setEnabled(false);
// stopButton.setEnabled(true);
graphView.addSeries(mSeries1);
if (firstRun) {
R1.start();
} else {
R1.resume();
}
break;
case R.id.stop:
//Triggered when stop is clicked
Log.d("MR.bool", "Stop was clicked ");
GraphView graph = (GraphView) findViewById(R.id.graph);
graph.removeAllSeries();
//runButton.setEnabled(true);
// stopButton.setEnabled(false);
firstRun = false;
R1.suspend();
break;
}
}
// Appends series objects to list after sleep in thread.
// http://www.ssaurel.com/blog/create-a-real-time-line-graph-in-android-with-graphview/
private void addEntry() {
float y = rand.nextFloat() * (2000 - 20) + 20;
mSeries1.appendData(new DataPoint(x_value, y), true, 500);
x_value += 1;
}
}
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:context="com.healthmonitor.khann.healthmonitor.MainActivity">
<Button
android:id="@+id/run"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="114dp"
android:layout_height="57dp"
android:background="@android:color/holo_green_light"
android:text="Run"
android:layout_marginLeft="61dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="76dp" />
<Button
android:id="@+id/stop"
android:layout_width="114dp"
android:layout_height="57dp"
android:background="@android:color/holo_red_light"
android:text="Stop"
app:layout_constraintLeft_toRightOf="@+id/run"
android:layout_marginLeft="13dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="76dp" />
<com.jjoe64.graphview.GraphView
android:id="@+id/graph"
android:layout_width="327dp"
android:layout_height="328dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="158dp"
app:layout_constraintHorizontal_bias="0.166"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText"
android:layout_width="60dp"
android:layout_height="42dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="P Name"
android:textSize="12sp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toRightOf="@+id/editText5"
android:layout_marginLeft="8dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="45dp"
android:layout_height="42dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="P ID:"
android:textSize="12sp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" />
<EditText
android:id="@+id/editText5"
android:layout_width="50dp"
android:layout_height="42dp"
android:ems="10"
android:inputType="number"
android:hint="Age"
android:textSize="12sp"
app:layout_constraintLeft_toRightOf="@+id/editText2"
android:layout_marginLeft="17dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sex:"
android:textSize="12sp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="34dp"
app:layout_constraintLeft_toRightOf="@+id/editText"
android:layout_marginLeft="12dp" />
<RadioGroup
android:id="@+id/radioSex"
android:layout_width="159dp"
android:layout_height="57dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="-1dp"
android:checkedButton="@+id/radioButton"
android:orientation='horizontal'
app:layout_constraintLeft_toRightOf="@+id/editText"
app:layout_constraintTop_toTopOf="parent">>
<RadioButton
android:id="@+id/radioButton"
android:layout_width="75dp"
android:layout_height="26dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="30dp"
android:scaleX="0.5"
android:scaleY="0.5"
android:text="Female"
android:textSize="12sp"
app:layout_constraintLeft_toRightOf="@+id/radioButton2"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="64dp"
android:layout_height="27dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="29dp"
android:scaleX="0.5"
android:scaleY="0.5"
android:text="Male"
android:textSize="12sp"
app:layout_constraintLeft_toRightOf="@+id/editText"
app:layout_constraintTop_toTopOf="parent" />
</RadioGroup>
</android.support.constraint.ConstraintLayout>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`package com.healthmonitor.khann.healthmonitor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.Viewport;
import java.util.Random;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.util.Log;
// Wherever not marked as reference, is our code.
public class MainActivity extends AppCompatActivity implements OnClickListener {
// Declare all the private variables for this class
private LineGraphSeries mSeries1 = new LineGraphSeries<>();
}`