add daily results and tests, make async tasks parallel and endless
move color interpolate functions from async task to main class
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package de.weseng.wifiweatherstation;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -20,11 +23,16 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static de.weseng.wifiweatherstation.SettingsActivity.PREFS_NAME;
|
||||
|
||||
public class MainNativeActivity extends AppCompatActivity {
|
||||
private int pDialogLockCount = 0;
|
||||
private final String TAG = getClass().getSimpleName();
|
||||
private int pBarLockCount = 0;
|
||||
// In Android 4.4 (API 19) AsyncTask MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1; (maximum number of threads)
|
||||
ArrayList<AsyncTask<String, Void, Void>> endlessTasks = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -46,17 +54,84 @@ public class MainNativeActivity extends AppCompatActivity {
|
||||
if (urlGlobal != null && urlGlobal.length() > 0)
|
||||
urlPre = urlGlobal.substring(urlGlobal.length() - 1).equals("/") ? urlGlobal : urlGlobal + "/";
|
||||
}
|
||||
//Toast.makeText(getApplicationContext(), urlPre, Toast.LENGTH_LONG).show();
|
||||
new GetData(R.id.textViewTemperatureValue1, R.id.textViewHumidityValue1).execute(
|
||||
executeAsyncTask(new GetData(R.id.textViewTemperatureValue1, R.id.textViewHumidityValue1),
|
||||
urlPre + "api.php?host=192.168.1.71&last");
|
||||
new GetData(R.id.textViewTemperatureValue2, R.id.textViewHumidityValue2).execute(
|
||||
executeAsyncTask(new GetData(R.id.textViewTemperatureValue2, R.id.textViewHumidityValue2),
|
||||
urlPre + "api.php?host=192.168.1.72&last");
|
||||
new GetData(R.id.textViewTemperatureValue3, R.id.textViewHumidityValue3).execute(
|
||||
executeAsyncTask(new GetData(R.id.textViewTemperatureValue3, R.id.textViewHumidityValue3),
|
||||
urlPre + "api.php?host=192.168.1.73&last");
|
||||
|
||||
endlessTasks.add(new GetData(R.id.textViewTemperatureValue1, R.id.textViewHumidityValue1,
|
||||
R.id.textViewTemperatureMin1, R.id.textViewTemperatureMax1, R.id.textViewTemperatureDelta1,
|
||||
R.id.textViewHumidityMin1, R.id.textViewHumidityMax1, R.id.textViewHumidityDelta1,
|
||||
true));
|
||||
endlessTasks.add(new GetData(R.id.textViewTemperatureValue2, R.id.textViewHumidityValue2,
|
||||
R.id.textViewTemperatureMin2, R.id.textViewTemperatureMax2, R.id.textViewTemperatureDelta2,
|
||||
R.id.textViewHumidityMin2, R.id.textViewHumidityMax2, R.id.textViewHumidityDelta2,
|
||||
true));
|
||||
endlessTasks.add(new GetData(R.id.textViewTemperatureValue3, R.id.textViewHumidityValue3,
|
||||
R.id.textViewTemperatureMin3, R.id.textViewTemperatureMax3, R.id.textViewTemperatureDelta3,
|
||||
R.id.textViewHumidityMin3, R.id.textViewHumidityMax3, R.id.textViewHumidityDelta3,
|
||||
true));
|
||||
executeAsyncTask(endlessTasks.get(0), urlPre + "api.php?host=192.168.1.71&day");
|
||||
executeAsyncTask(endlessTasks.get(1), urlPre + "api.php?host=192.168.1.72&day");
|
||||
executeAsyncTask(endlessTasks.get(2), urlPre + "api.php?host=192.168.1.73&day");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Log.d(TAG, "onPause() called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Log.d(TAG, "onStop() called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.d(TAG, "onDestroy() called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Log.d(TAG, "onStart() called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log.d(TAG, "onResume() called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Check if the key event was the Back button and if there's history
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
for(int i=0; i<endlessTasks.size(); i++){
|
||||
endlessTasks.get(i).cancel(false); // cancel gently
|
||||
}
|
||||
finish();
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
}
|
||||
// If it wasn't the Back key, bubble up to the default
|
||||
// system behavior (probably exit the activity)
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11
|
||||
public static <T> void executeAsyncTask(AsyncTask<T, ?, ?> asyncTask, T... params) {
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
|
||||
else
|
||||
asyncTask.execute(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Async task class to get json by making HTTP call
|
||||
*/
|
||||
@@ -67,28 +142,90 @@ public class MainNativeActivity extends AppCompatActivity {
|
||||
ArrayList<HashMap<String, String>> dataList = new ArrayList<>();
|
||||
|
||||
int v1, v2;
|
||||
int idMin1, idMax1, idDelta1;
|
||||
int idMin2, idMax2, idDelta2;
|
||||
|
||||
/*
|
||||
* Properties to run endless
|
||||
*/
|
||||
boolean endless = false;
|
||||
private ProgressBar pBarSmall;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final Condition tryAgain = lock.newCondition();
|
||||
private volatile boolean finished = false;
|
||||
|
||||
GetData(int v1, int v2) {
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
pDialogLockCount += 1;
|
||||
pBarLockCount += 1;
|
||||
}
|
||||
|
||||
GetData(int v1, int v2, int min1, int max1, int delta1, int min2, int max2, int delta2) {
|
||||
this(v1, v2);
|
||||
idMin1 = min1;
|
||||
idMax1 = max1;
|
||||
idDelta1 = delta1;
|
||||
idMin2 = min2;
|
||||
idMax2 = max2;
|
||||
idDelta2 = delta2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor to run endless
|
||||
*/
|
||||
GetData(int v1, int v2, int min1, int max1, int delta1, int min2, int max2, int delta2, boolean endless) {
|
||||
this(v1, v2, min1, max1, delta1, min2, max2, delta2);
|
||||
this.endless = endless;
|
||||
pBarLockCount -= 1; // do not count for endless tasks, pBarSmall is used
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
// Showing progress bar
|
||||
// if (pBar == null) {
|
||||
// pBar= new ProgressBar(MainNativeActivity.this);
|
||||
// }
|
||||
pBar = findViewById(R.id.progressBar);
|
||||
if (pBar.getVisibility() == View.INVISIBLE) {
|
||||
pBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (endless) {
|
||||
// Showing progress bar
|
||||
pBarSmall = findViewById(R.id.progressBarSmall);
|
||||
if (pBarSmall.getVisibility() == View.INVISIBLE) {
|
||||
pBarSmall.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... params) {
|
||||
if(!endless)
|
||||
getJsonOverHttpData(params);
|
||||
else{
|
||||
lock.lock();
|
||||
do {
|
||||
getJsonOverHttpData(params);
|
||||
publishProgress();
|
||||
tryAgain.awaitUninterruptibly();
|
||||
//terminateTask();
|
||||
} while(!finished);
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
pBarLockCount -= 1;
|
||||
// Dismiss the progress bar
|
||||
if (pBar.getVisibility() == View.VISIBLE && pBarLockCount == 0) {
|
||||
pBar.setVisibility(View.GONE);
|
||||
}
|
||||
updateViews();
|
||||
}
|
||||
|
||||
void getJsonOverHttpData(String... params) {
|
||||
// URL to get contacts JSON
|
||||
String url = params[0];
|
||||
|
||||
@@ -140,7 +277,6 @@ public class MainNativeActivity extends AppCompatActivity {
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Couldn't get json from server.");
|
||||
@@ -153,10 +289,137 @@ public class MainNativeActivity extends AppCompatActivity {
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updating parsed JSON data into Views
|
||||
*/
|
||||
void updateViews() {
|
||||
int n = dataList.size();
|
||||
if (n > 0) {
|
||||
HashMap<String, String> hm = dataList.get(n - 1);
|
||||
|
||||
float temp = Float.parseFloat(hm.get("temperature"));
|
||||
String temperature = String.format("%.1f", temp);
|
||||
|
||||
float humi = Float.parseFloat(hm.get("humidity"));
|
||||
String humidity = String.format("%.1f", humi);
|
||||
|
||||
Color green = Color.valueOf(0xff00ff00);
|
||||
Color red = Color.valueOf(0xffd1655d);
|
||||
Color blue = Color.valueOf(Color.rgb(113, 157, 195));
|
||||
|
||||
Color textColor;
|
||||
|
||||
textColor = valueToColor(temp, 17, 19, 23, 25, blue, green, red);
|
||||
TextView tv1 = findViewById(v1);
|
||||
tv1.setText(temperature);
|
||||
tv1.setTextColor(textColor.toArgb());
|
||||
|
||||
textColor = valueToColor(humi, 25, 40, 60, 75, red, green, blue);
|
||||
TextView tv2 = findViewById(v2);
|
||||
tv2.setText(humidity);
|
||||
tv2.setTextColor(textColor.toArgb());
|
||||
|
||||
if (idMin1 != 0) {
|
||||
float min1 = 100, max1 = 0, val1;
|
||||
float min2 = 100, max2 = 0, val2;
|
||||
for (int i = 0; i < n; i++) {
|
||||
hm = dataList.get(i);
|
||||
val1 = Float.parseFloat(hm.get("temperature"));
|
||||
if (val1 < min1)
|
||||
min1 = val1;
|
||||
if (val1 > max1)
|
||||
max1 = val1;
|
||||
val2 = Float.parseFloat(hm.get("humidity"));
|
||||
if (val2 < min2)
|
||||
min2 = val2;
|
||||
if (val2 > max2)
|
||||
max2 = val2;
|
||||
}
|
||||
TextView tv;
|
||||
tv = findViewById(idMin1);
|
||||
tv.setText(String.format("%.1f", min1));
|
||||
tv = findViewById(idMax1);
|
||||
tv.setText(String.format("%.1f", max1));
|
||||
tv = findViewById(idDelta1);
|
||||
tv.setText(String.format("%.1f", max1 - min1));
|
||||
tv = findViewById(idMin2);
|
||||
tv.setText(String.format("%.1f", min2));
|
||||
tv = findViewById(idMax2);
|
||||
tv.setText(String.format("%.1f", max2));
|
||||
tv = findViewById(idDelta2);
|
||||
tv.setText(String.format("%.1f", max2 - min2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions to run endless
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Void... result) {
|
||||
//super.onProgressUpdate(result);
|
||||
// Treat this like onPostExecute(), do something with result
|
||||
if(endless) {
|
||||
updateViews();
|
||||
runAgain();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
// Make sure we clean up if the task is killed
|
||||
if(endless)
|
||||
terminateTask();
|
||||
}
|
||||
|
||||
public void runAgain() {
|
||||
// Call this to request data from the server again
|
||||
lock.lock();
|
||||
try {
|
||||
tryAgain.signal();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void terminateTask() {
|
||||
// The task will only finish when we call this method
|
||||
finished = true;
|
||||
//lock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle item selection
|
||||
switch (item.getItemId()) {
|
||||
case R.id.settings:
|
||||
settings();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user taps the Settings button
|
||||
*/
|
||||
public void settings() {
|
||||
Intent intentSettings = new Intent(this, SettingsActivity.class);
|
||||
//intentSettings.putExtra(MESSAGE, MESSAGE);
|
||||
startActivity(intentSettings);
|
||||
}
|
||||
|
||||
int interpolate(int pBegin, int pEnd, int pStep, int pMax) {
|
||||
@@ -201,9 +464,7 @@ public class MainNativeActivity extends AppCompatActivity {
|
||||
return valueToColorRGB(value, lowMin, lowMax, highMin, highMax, bel, ide, abo);
|
||||
}
|
||||
|
||||
int valueToColorRGB(float value, float lowMin, float lowMax, float highMin, float highMax,
|
||||
int below, int ideal, int above) {
|
||||
/*
|
||||
/**
|
||||
* lowMin < lowMax < highMin < highMax
|
||||
*
|
||||
* Example use for temperatures with color blue for too cold (below), green for ideal
|
||||
@@ -214,6 +475,8 @@ public class MainNativeActivity extends AppCompatActivity {
|
||||
* - Between highMin and highMax the color is linear interpolated between green and red
|
||||
* - Above highMax the color is red
|
||||
*/
|
||||
int valueToColorRGB(float value, float lowMin, float lowMax, float highMin, float highMax,
|
||||
int below, int ideal, int above) {
|
||||
int result = 0xFFFFFF; // white
|
||||
int theNumSteps = 100;
|
||||
int theColorBegin, theColorEnd, ratio;
|
||||
@@ -237,74 +500,4 @@ public class MainNativeActivity extends AppCompatActivity {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
pDialogLockCount -= 1;
|
||||
// Dismiss the progress bar
|
||||
if (pBar.getVisibility() == View.VISIBLE && pDialogLockCount == 0) {
|
||||
pBar.setVisibility(View.GONE);
|
||||
}
|
||||
/*
|
||||
* Updating parsed JSON data into Views
|
||||
* */
|
||||
|
||||
int n = dataList.size();
|
||||
if (n > 0) {
|
||||
HashMap<String, String> hm = dataList.get(n - 1);
|
||||
|
||||
float temp = Float.parseFloat(hm.get("temperature"));
|
||||
String temperature = String.format("%.1f", temp);
|
||||
|
||||
float humi = Float.parseFloat(hm.get("humidity"));
|
||||
String humidity = String.format("%.1f", humi);
|
||||
|
||||
Color green = Color.valueOf(0xff00ff00);
|
||||
Color red = Color.valueOf(0xffd1655d);
|
||||
Color blue = Color.valueOf(Color.rgb(113, 157, 195));
|
||||
|
||||
Color textColor;
|
||||
|
||||
textColor = valueToColor(temp, 17, 19, 23, 25, blue, green, red);
|
||||
TextView tv1 = findViewById(v1);
|
||||
tv1.setText(temperature);
|
||||
tv1.setTextColor(textColor.toArgb());
|
||||
|
||||
textColor = valueToColor(humi, 25, 40, 60, 75, red, green, blue);
|
||||
TextView tv2 = findViewById(v2);
|
||||
tv2.setText(humidity);
|
||||
tv2.setTextColor(textColor.toArgb());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle item selection
|
||||
switch (item.getItemId()) {
|
||||
case R.id.settings:
|
||||
settings();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user taps the Send button
|
||||
*/
|
||||
public void settings() {
|
||||
Intent intentSettings = new Intent(this, SettingsActivity.class);
|
||||
//intentSettings.putExtra(MESSAGE, MESSAGE);
|
||||
startActivity(intentSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginStart="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@@ -22,14 +20,14 @@
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="4">
|
||||
android:weightSum="6">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperature"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:layout_span="2"
|
||||
android:text="@string/temperature"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@@ -37,8 +35,8 @@
|
||||
android:id="@+id/textViewHumidity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:layout_span="2"
|
||||
android:text="@string/humidity"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@@ -46,146 +44,359 @@
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/widget_vertical_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureValue1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/dummy_value"
|
||||
android:textSize="36sp"
|
||||
android:textSize="@dimen/value_main_size"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureUnit1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text=" °C"
|
||||
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/temperature_unit"
|
||||
android:textSize="32sp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityValue1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/dummy_value"
|
||||
android:textSize="36sp"
|
||||
android:textSize="@dimen/value_main_size"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityUnit1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text=" %"
|
||||
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/humidity_unit"
|
||||
android:textSize="32sp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="6">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureMin1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureMax1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureDelta1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dummy_value2" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityMin1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityMax1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityDelta1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/widget_vertical_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureValue2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/dummy_value"
|
||||
android:textSize="36sp"
|
||||
android:textSize="@dimen/value_main_size"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureUnit2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text=" °C"
|
||||
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/temperature_unit"
|
||||
android:textSize="32sp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityValue2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/dummy_value"
|
||||
android:textSize="36sp"
|
||||
android:textSize="@dimen/value_main_size"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityUnit2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text=" %"
|
||||
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/humidity_unit"
|
||||
android:textSize="32sp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="6">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureMin2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureMax2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureDelta2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dummy_value2" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityMin2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityMax2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityDelta2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/widget_vertical_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureValue3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/dummy_value"
|
||||
android:textSize="36sp"
|
||||
android:textSize="@dimen/value_main_size"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureUnit3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text=" °C"
|
||||
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/temperature_unit"
|
||||
android:textSize="32sp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityValue3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:gravity="end"
|
||||
android:text="@string/dummy_value"
|
||||
android:textSize="36sp"
|
||||
android:textSize="@dimen/value_main_size"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityUnit3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text=" %"
|
||||
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/humidity_unit"
|
||||
android:textSize="32sp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="6">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureMin3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureMax3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTemperatureDelta3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dummy_value2" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_span="3"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityMin3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityMax3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/widget_horizontal_margin"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewHumidityDelta3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dummy_value2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="80dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<!-- size 48x48 -->
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
@@ -193,6 +404,19 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<!-- size 16x16 -->
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarSmall"
|
||||
style="?android:attr/progressBarStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
@@ -4,4 +4,5 @@
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="widget_horizontal_margin">8dp</dimen>
|
||||
<dimen name="widget_vertical_margin">8dp</dimen>
|
||||
<dimen name="value_main_size">40sp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
<string name="loading">Please wait, the view is loading…</string>
|
||||
<!-- Strings related to native view -->
|
||||
<string name="temperature">Temperature</string>
|
||||
<string name="temperature_unit" translatable="false">°C</string>
|
||||
<string name="humidity">Humidity</string>
|
||||
<string name="dummy_value" translatable="false">_._</string>
|
||||
<string name="humidity_unit" translatable="false">%</string>
|
||||
<string name="dummy_value" translatable="false">__._</string>
|
||||
<string name="dummy_value2" translatable="false">o</string>
|
||||
<!-- Strings related to settings -->
|
||||
<string name="settings">Settings</string>
|
||||
<string name="message" translatable="false">de.weseng.wifiweatherstation.MESSAGE</string>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package de.weseng.wifiweatherstation;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class MainNativeActivityTest {
|
||||
|
||||
@Test
|
||||
public void valueToColorRGB_below() {
|
||||
assertEquals(new MainNativeActivity().valueToColorRGB(
|
||||
10, 17, 19, 23, 25,
|
||||
0x719dc3, 0xff00ff00, 0xffd1655d),
|
||||
0x719dc3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueToColorRGB_ideal() {
|
||||
assertEquals(new MainNativeActivity().valueToColorRGB(
|
||||
20, 17, 19, 23, 25,
|
||||
0x719DC3, 0xff00ff00, 0xffd1655d),
|
||||
0xff00ff00);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueToColorRGB_above() {
|
||||
assertEquals(new MainNativeActivity().valueToColorRGB(
|
||||
30, 17, 19, 23, 25,
|
||||
0x719DC3, 0xff00ff00, 0xffd1655d),
|
||||
0xffd1655d);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user