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;
|
package de.weseng.wifiweatherstation;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -20,11 +23,16 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.locks.Condition;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import static de.weseng.wifiweatherstation.SettingsActivity.PREFS_NAME;
|
import static de.weseng.wifiweatherstation.SettingsActivity.PREFS_NAME;
|
||||||
|
|
||||||
public class MainNativeActivity extends AppCompatActivity {
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -46,17 +54,84 @@ public class MainNativeActivity extends AppCompatActivity {
|
|||||||
if (urlGlobal != null && urlGlobal.length() > 0)
|
if (urlGlobal != null && urlGlobal.length() > 0)
|
||||||
urlPre = urlGlobal.substring(urlGlobal.length() - 1).equals("/") ? urlGlobal : urlGlobal + "/";
|
urlPre = urlGlobal.substring(urlGlobal.length() - 1).equals("/") ? urlGlobal : urlGlobal + "/";
|
||||||
}
|
}
|
||||||
//Toast.makeText(getApplicationContext(), urlPre, Toast.LENGTH_LONG).show();
|
executeAsyncTask(new GetData(R.id.textViewTemperatureValue1, R.id.textViewHumidityValue1),
|
||||||
new GetData(R.id.textViewTemperatureValue1, R.id.textViewHumidityValue1).execute(
|
|
||||||
urlPre + "api.php?host=192.168.1.71&last");
|
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");
|
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");
|
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
|
* 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<>();
|
ArrayList<HashMap<String, String>> dataList = new ArrayList<>();
|
||||||
|
|
||||||
int v1, v2;
|
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) {
|
GetData(int v1, int v2) {
|
||||||
this.v1 = v1;
|
this.v1 = v1;
|
||||||
this.v2 = v2;
|
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
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
super.onPreExecute();
|
super.onPreExecute();
|
||||||
// Showing progress bar
|
// Showing progress bar
|
||||||
// if (pBar == null) {
|
|
||||||
// pBar= new ProgressBar(MainNativeActivity.this);
|
|
||||||
// }
|
|
||||||
pBar = findViewById(R.id.progressBar);
|
pBar = findViewById(R.id.progressBar);
|
||||||
if (pBar.getVisibility() == View.INVISIBLE) {
|
if (pBar.getVisibility() == View.INVISIBLE) {
|
||||||
pBar.setVisibility(View.VISIBLE);
|
pBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
if (endless) {
|
||||||
|
// Showing progress bar
|
||||||
|
pBarSmall = findViewById(R.id.progressBarSmall);
|
||||||
|
if (pBarSmall.getVisibility() == View.INVISIBLE) {
|
||||||
|
pBarSmall.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(String... params) {
|
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
|
// URL to get contacts JSON
|
||||||
String url = params[0];
|
String url = params[0];
|
||||||
|
|
||||||
@@ -140,7 +277,6 @@ public class MainNativeActivity extends AppCompatActivity {
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Couldn't get json from server.");
|
Log.e(TAG, "Couldn't get json from server.");
|
||||||
@@ -153,103 +289,13 @@ public class MainNativeActivity extends AppCompatActivity {
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int interpolate(int pBegin, int pEnd, int pStep, int pMax) {
|
|
||||||
if (pBegin < pEnd) {
|
|
||||||
return ((pEnd - pBegin) * (pStep / pMax)) + pBegin;
|
|
||||||
} else {
|
|
||||||
return ((pBegin - pEnd) * (1 - (pStep / pMax))) + pEnd;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int interpolateColor(int theColorBegin, int theColorEnd,
|
/**
|
||||||
int theNumStep, int theNumSteps) {
|
* Updating parsed JSON data into Views
|
||||||
int theR0 = (theColorBegin & 0xff0000) >> 16;
|
*/
|
||||||
int theG0 = (theColorBegin & 0x00ff00) >> 8;
|
void updateViews() {
|
||||||
int theB0 = (theColorBegin & 0x0000ff);
|
|
||||||
//int theB0 = (theColorBegin & 0x0000ff) >> 0;
|
|
||||||
|
|
||||||
int theR1 = (theColorEnd & 0xff0000) >> 16;
|
|
||||||
int theG1 = (theColorEnd & 0x00ff00) >> 8;
|
|
||||||
int theB1 = (theColorEnd & 0x0000ff);
|
|
||||||
//int theB1 = (theColorEnd & 0x0000ff) >> 0;
|
|
||||||
|
|
||||||
int theR = interpolate(theR0, theR1, theNumStep, theNumSteps);
|
|
||||||
int theG = interpolate(theG0, theG1, theNumStep, theNumSteps);
|
|
||||||
int theB = interpolate(theB0, theB1, theNumStep, theNumSteps);
|
|
||||||
|
|
||||||
return (((theR << 8) | theG) << 8) | theB;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color valueToColor(float value, float lowMin, float lowMax, float highMin, float highMax,
|
|
||||||
Color below, Color ideal, Color above) {
|
|
||||||
return Color.valueOf(Color.parseColor(String.format("#%06X",
|
|
||||||
valueToColorRGB(value, lowMin, lowMax, highMin, highMax, below, ideal, above))));
|
|
||||||
}
|
|
||||||
|
|
||||||
int valueToColorRGB(float value, float lowMin, float lowMax, float highMin, float highMax,
|
|
||||||
Color below, Color ideal, Color above) {
|
|
||||||
int bel = Integer.parseInt(String.format("%06X", (0xFFFFFF & below.toArgb())), 16);
|
|
||||||
int ide = Integer.parseInt(String.format("%06X", (0xFFFFFF & ideal.toArgb())), 16);
|
|
||||||
int abo = Integer.parseInt(String.format("%06X", (0xFFFFFF & above.toArgb())), 16);
|
|
||||||
|
|
||||||
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
|
|
||||||
* and red for too warm (above) temperatures:
|
|
||||||
* - Below lowMin the color is blue
|
|
||||||
* - Between lowMin and lowMax is color is linear interpolated between blue and green
|
|
||||||
* - Between lowMax and highMin the color is green
|
|
||||||
* - Between highMin and highMax the color is linear interpolated between green and red
|
|
||||||
* - Above highMax the color is red
|
|
||||||
*/
|
|
||||||
int result = 0xFFFFFF; // white
|
|
||||||
int theNumSteps = 100;
|
|
||||||
int theColorBegin, theColorEnd, ratio;
|
|
||||||
|
|
||||||
if (value <= highMin && value >= lowMax)
|
|
||||||
result = ideal;
|
|
||||||
else if (value > highMax)
|
|
||||||
result = above;
|
|
||||||
else if (value > highMin) {
|
|
||||||
theColorBegin = ideal;
|
|
||||||
theColorEnd = above;
|
|
||||||
ratio = (int) ((value - highMin) / (highMax - highMin) * 100);
|
|
||||||
result = interpolateColor(theColorBegin, theColorEnd, ratio, theNumSteps);
|
|
||||||
} else if (value < lowMin)
|
|
||||||
result = below;
|
|
||||||
else if (value < lowMax) {
|
|
||||||
theColorBegin = ideal;
|
|
||||||
theColorEnd = below;
|
|
||||||
ratio = (int) ((lowMax - value) / (lowMax - lowMin) * 100);
|
|
||||||
result = interpolateColor(theColorBegin, theColorEnd, ratio, theNumSteps);
|
|
||||||
}
|
|
||||||
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();
|
int n = dataList.size();
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
HashMap<String, String> hm = dataList.get(n - 1);
|
HashMap<String, String> hm = dataList.get(n - 1);
|
||||||
@@ -275,9 +321,77 @@ public class MainNativeActivity extends AppCompatActivity {
|
|||||||
TextView tv2 = findViewById(v2);
|
TextView tv2 = findViewById(v2);
|
||||||
tv2.setText(humidity);
|
tv2.setText(humidity);
|
||||||
tv2.setTextColor(textColor.toArgb());
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -300,11 +414,90 @@ public class MainNativeActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user taps the Send button
|
* Called when the user taps the Settings button
|
||||||
*/
|
*/
|
||||||
public void settings() {
|
public void settings() {
|
||||||
Intent intentSettings = new Intent(this, SettingsActivity.class);
|
Intent intentSettings = new Intent(this, SettingsActivity.class);
|
||||||
//intentSettings.putExtra(MESSAGE, MESSAGE);
|
//intentSettings.putExtra(MESSAGE, MESSAGE);
|
||||||
startActivity(intentSettings);
|
startActivity(intentSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int interpolate(int pBegin, int pEnd, int pStep, int pMax) {
|
||||||
|
if (pBegin < pEnd) {
|
||||||
|
return ((pEnd - pBegin) * (pStep / pMax)) + pBegin;
|
||||||
|
} else {
|
||||||
|
return ((pBegin - pEnd) * (1 - (pStep / pMax))) + pEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int interpolateColor(int theColorBegin, int theColorEnd,
|
||||||
|
int theNumStep, int theNumSteps) {
|
||||||
|
int theR0 = (theColorBegin & 0xff0000) >> 16;
|
||||||
|
int theG0 = (theColorBegin & 0x00ff00) >> 8;
|
||||||
|
int theB0 = (theColorBegin & 0x0000ff);
|
||||||
|
//int theB0 = (theColorBegin & 0x0000ff) >> 0;
|
||||||
|
|
||||||
|
int theR1 = (theColorEnd & 0xff0000) >> 16;
|
||||||
|
int theG1 = (theColorEnd & 0x00ff00) >> 8;
|
||||||
|
int theB1 = (theColorEnd & 0x0000ff);
|
||||||
|
//int theB1 = (theColorEnd & 0x0000ff) >> 0;
|
||||||
|
|
||||||
|
int theR = interpolate(theR0, theR1, theNumStep, theNumSteps);
|
||||||
|
int theG = interpolate(theG0, theG1, theNumStep, theNumSteps);
|
||||||
|
int theB = interpolate(theB0, theB1, theNumStep, theNumSteps);
|
||||||
|
|
||||||
|
return (((theR << 8) | theG) << 8) | theB;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color valueToColor(float value, float lowMin, float lowMax, float highMin, float highMax,
|
||||||
|
Color below, Color ideal, Color above) {
|
||||||
|
return Color.valueOf(Color.parseColor(String.format("#%06X",
|
||||||
|
valueToColorRGB(value, lowMin, lowMax, highMin, highMax, below, ideal, above))));
|
||||||
|
}
|
||||||
|
|
||||||
|
int valueToColorRGB(float value, float lowMin, float lowMax, float highMin, float highMax,
|
||||||
|
Color below, Color ideal, Color above) {
|
||||||
|
int bel = Integer.parseInt(String.format("%06X", (0xFFFFFF & below.toArgb())), 16);
|
||||||
|
int ide = Integer.parseInt(String.format("%06X", (0xFFFFFF & ideal.toArgb())), 16);
|
||||||
|
int abo = Integer.parseInt(String.format("%06X", (0xFFFFFF & above.toArgb())), 16);
|
||||||
|
|
||||||
|
return valueToColorRGB(value, lowMin, lowMax, highMin, highMax, bel, ide, abo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lowMin < lowMax < highMin < highMax
|
||||||
|
*
|
||||||
|
* Example use for temperatures with color blue for too cold (below), green for ideal
|
||||||
|
* and red for too warm (above) temperatures:
|
||||||
|
* - Below lowMin the color is blue
|
||||||
|
* - Between lowMin and lowMax is color is linear interpolated between blue and green
|
||||||
|
* - Between lowMax and highMin the color is green
|
||||||
|
* - 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;
|
||||||
|
|
||||||
|
if (value <= highMin && value >= lowMax)
|
||||||
|
result = ideal;
|
||||||
|
else if (value > highMax)
|
||||||
|
result = above;
|
||||||
|
else if (value > highMin) {
|
||||||
|
theColorBegin = ideal;
|
||||||
|
theColorEnd = above;
|
||||||
|
ratio = (int) ((value - highMin) / (highMax - highMin) * 100);
|
||||||
|
result = interpolateColor(theColorBegin, theColorEnd, ratio, theNumSteps);
|
||||||
|
} else if (value < lowMin)
|
||||||
|
result = below;
|
||||||
|
else if (value < lowMax) {
|
||||||
|
theColorBegin = ideal;
|
||||||
|
theColorEnd = below;
|
||||||
|
ratio = (int) ((lowMax - value) / (lowMax - lowMin) * 100);
|
||||||
|
result = interpolateColor(theColorBegin, theColorEnd, ratio, theNumSteps);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,9 @@
|
|||||||
<TableLayout
|
<TableLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="@dimen/activity_horizontal_margin"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="1.0"
|
app:layout_constraintHorizontal_bias="1.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@@ -22,14 +20,14 @@
|
|||||||
<TableRow
|
<TableRow
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:weightSum="4">
|
android:weightSum="6">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewTemperature"
|
android:id="@+id/textViewTemperature"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_span="3"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_span="2"
|
|
||||||
android:text="@string/temperature"
|
android:text="@string/temperature"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
@@ -37,8 +35,8 @@
|
|||||||
android:id="@+id/textViewHumidity"
|
android:id="@+id/textViewHumidity"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_span="3"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_span="2"
|
|
||||||
android:text="@string/humidity"
|
android:text="@string/humidity"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
@@ -46,146 +44,359 @@
|
|||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="@dimen/widget_vertical_margin">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewTemperatureValue1"
|
android:id="@+id/textViewTemperatureValue1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="5dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:text="@string/dummy_value"
|
android:text="@string/dummy_value"
|
||||||
android:textSize="36sp"
|
android:textSize="@dimen/value_main_size"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewTemperatureUnit1"
|
android:id="@+id/textViewTemperatureUnit1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||||
android:paddingStart="0dp"
|
android:text="@string/temperature_unit"
|
||||||
android:paddingEnd="5dp"
|
|
||||||
android:text=" °C"
|
|
||||||
android:textSize="32sp" />
|
android:textSize="32sp" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewHumidityValue1"
|
android:id="@+id/textViewHumidityValue1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="5dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:text="@string/dummy_value"
|
android:text="@string/dummy_value"
|
||||||
android:textSize="36sp"
|
android:textSize="@dimen/value_main_size"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewHumidityUnit1"
|
android:id="@+id/textViewHumidityUnit1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||||
android:paddingStart="0dp"
|
android:text="@string/humidity_unit"
|
||||||
android:paddingEnd="5dp"
|
|
||||||
android:text=" %"
|
|
||||||
android:textSize="32sp" />
|
android:textSize="32sp" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_width="match_parent"
|
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
|
<TextView
|
||||||
android:id="@+id/textViewTemperatureValue2"
|
android:id="@+id/textViewTemperatureValue2"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="5dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:text="@string/dummy_value"
|
android:text="@string/dummy_value"
|
||||||
android:textSize="36sp"
|
android:textSize="@dimen/value_main_size"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewTemperatureUnit2"
|
android:id="@+id/textViewTemperatureUnit2"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||||
android:paddingStart="0dp"
|
android:text="@string/temperature_unit"
|
||||||
android:paddingEnd="5dp"
|
|
||||||
android:text=" °C"
|
|
||||||
android:textSize="32sp" />
|
android:textSize="32sp" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewHumidityValue2"
|
android:id="@+id/textViewHumidityValue2"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="5dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:text="@string/dummy_value"
|
android:text="@string/dummy_value"
|
||||||
android:textSize="36sp"
|
android:textSize="@dimen/value_main_size"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewHumidityUnit2"
|
android:id="@+id/textViewHumidityUnit2"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||||
android:paddingStart="0dp"
|
android:text="@string/humidity_unit"
|
||||||
android:paddingEnd="5dp"
|
|
||||||
android:text=" %"
|
|
||||||
android:textSize="32sp" />
|
android:textSize="32sp" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_width="match_parent"
|
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
|
<TextView
|
||||||
android:id="@+id/textViewTemperatureValue3"
|
android:id="@+id/textViewTemperatureValue3"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="5dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:text="@string/dummy_value"
|
android:text="@string/dummy_value"
|
||||||
android:textSize="36sp"
|
android:textSize="@dimen/value_main_size"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewTemperatureUnit3"
|
android:id="@+id/textViewTemperatureUnit3"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||||
android:paddingStart="0dp"
|
android:text="@string/temperature_unit"
|
||||||
android:paddingEnd="5dp"
|
|
||||||
android:text=" °C"
|
|
||||||
android:textSize="32sp" />
|
android:textSize="32sp" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewHumidityValue3"
|
android:id="@+id/textViewHumidityValue3"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="5dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:text="@string/dummy_value"
|
android:text="@string/dummy_value"
|
||||||
android:textSize="36sp"
|
android:textSize="@dimen/value_main_size"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewHumidityUnit3"
|
android:id="@+id/textViewHumidityUnit3"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="@dimen/widget_horizontal_margin"
|
||||||
android:paddingStart="0dp"
|
android:text="@string/humidity_unit"
|
||||||
android:paddingEnd="5dp"
|
|
||||||
android:text=" %"
|
|
||||||
android:textSize="32sp" />
|
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>
|
</TableRow>
|
||||||
</TableLayout>
|
</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
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
style="?android:attr/progressBarStyle"
|
style="?android:attr/progressBarStyle"
|
||||||
@@ -193,6 +404,19 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginBottom="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_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
||||||
@@ -4,4 +4,5 @@
|
|||||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
<dimen name="widget_horizontal_margin">8dp</dimen>
|
<dimen name="widget_horizontal_margin">8dp</dimen>
|
||||||
<dimen name="widget_vertical_margin">8dp</dimen>
|
<dimen name="widget_vertical_margin">8dp</dimen>
|
||||||
|
<dimen name="value_main_size">40sp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
<string name="loading">Please wait, the view is loading…</string>
|
<string name="loading">Please wait, the view is loading…</string>
|
||||||
<!-- Strings related to native view -->
|
<!-- Strings related to native view -->
|
||||||
<string name="temperature">Temperature</string>
|
<string name="temperature">Temperature</string>
|
||||||
|
<string name="temperature_unit" translatable="false">°C</string>
|
||||||
<string name="humidity">Humidity</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 -->
|
<!-- Strings related to settings -->
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="message" translatable="false">de.weseng.wifiweatherstation.MESSAGE</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