Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Ambient backgroundcolor enabled for Lines and Dots
Browse files Browse the repository at this point in the history
  • Loading branch information
jilleb committed Jan 17, 2019
1 parent 20e52c3 commit 28f6d42
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 57 additions & 24 deletions app/src/main/java/com/mqbcoding/stats/DashboardFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.LightingColorFilter;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -64,7 +65,7 @@ public class DashboardFragment extends CarFragment {
private RaySpeedometer mRayLeft, mRayCenter, mRayRight;
private ImageView mSteeringWheelAngle;
private String mElement1Query, mElement2Query, mElement3Query, mElement4Query;
private String selectedTheme;
private String selectedTheme, selectedBackground;
private String mClockLQuery, mClockCQuery, mClockRQuery;
private String pressureUnit, temperatureUnit, selectedFont;
private float pressureFactor, speedFactor;
Expand Down Expand Up @@ -93,11 +94,13 @@ public class DashboardFragment extends CarFragment {
private LineGraphSeries<DataPoint> mSpeedSeriesLeft;
private LineGraphSeries<DataPoint> mSpeedSeriesCenter;
private LineGraphSeries<DataPoint> mSpeedSeriesRight;
private View mBackGroundLayout;
private double graphLeftLastXValue = 5d;
private double graphCenterLastXValue = 5d;
private double graphRightLastXValue = 5d;
//value displayed on graphlayout
private TextView mGraphValueLeft, mGraphValueCenter, mGraphValueRight;
private View rootView;

public DashboardFragment() {
// Required empty public constructor
Expand Down Expand Up @@ -258,7 +261,7 @@ public void run() {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i(TAG, "onCreateView");
View rootView = inflater.inflate(R.layout.fragment_dashboard, container, false);
rootView = inflater.inflate(R.layout.fragment_dashboard, container, false);

//Get preferences
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
Expand All @@ -273,6 +276,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
ticksOn = sharedPreferences.getBoolean("ticksActive", false); // if true, it will display the value of each of the ticks
ambientOn = sharedPreferences.getBoolean("ambientActive", false); //true = use ambient colors, false = don't use.
selectedTheme = sharedPreferences.getString("selectedTheme", "");
//todo: fix this. currently not very efficient, because this is already requested in MainCarActivity
selectedBackground = sharedPreferences.getString("selectedBackground", "Black");

Log.d(TAG,"Background: " + selectedBackground);


//set textview to have a custom digital font:
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "digital.ttf");
Expand Down Expand Up @@ -313,6 +321,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

//-------------------------------------------------------------
//find all elements needed

mBackGroundLayout = rootView.findViewById(R.id.fragment_container);

//layouts/constrains:
mConstraintClockLeft = rootView.findViewById(R.id.constraintClockLeft);
mConstraintClockCenter = rootView.findViewById(R.id.constraintClockCenter);
Expand All @@ -322,7 +333,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mConstraintGraphCenter = rootView.findViewById(R.id.constraintGraphCenter);
mConstraintGraphRight = rootView.findViewById(R.id.constraintGraphRight);


//clocks:
mClockLeft = rootView.findViewById(R.id.dial_Left);
mClockCenter = rootView.findViewById(R.id.dial_Center);
Expand Down Expand Up @@ -866,20 +876,36 @@ private void doUpdate() {
String ambientColor = (String) mLastMeasurements.get("Car_ambienceLightColour.ColourSRGB");
//ambientColor = "#FF0000"; // for testing purposes
if (ambientColor != null) {
if (raysOn) {
mRayLeft.setLowSpeedColor(Color.parseColor(ambientColor));
mRayCenter.setLowSpeedColor(Color.parseColor(ambientColor));
mRayRight.setLowSpeedColor(Color.parseColor(ambientColor));
mRayLeft.setMediumSpeedColor(Color.parseColor(ambientColor));
mRayCenter.setMediumSpeedColor(Color.parseColor(ambientColor));
mRayRight.setMediumSpeedColor(Color.parseColor(ambientColor));
} else {
mClockLeft.setIndicatorColor(Color.parseColor(ambientColor));
mClockCenter.setIndicatorColor(Color.parseColor(ambientColor));
mClockRight.setIndicatorColor(Color.parseColor(ambientColor));
mClockLeft.setIndicatorLightColor(Color.parseColor(ambientColor));
mClockCenter.setIndicatorLightColor(Color.parseColor(ambientColor));
mClockRight.setIndicatorLightColor(Color.parseColor(ambientColor));
if ((Color.parseColor(ambientColor) != mClockLeft.getIndicatorColor()) || ((Color.parseColor(ambientColor) != mRayLeft.getLowSpeedColor()))){
if (raysOn) {
mRayLeft.setLowSpeedColor(Color.parseColor(ambientColor));
mRayCenter.setLowSpeedColor(Color.parseColor(ambientColor));
mRayRight.setLowSpeedColor(Color.parseColor(ambientColor));
mRayLeft.setMediumSpeedColor(Color.parseColor(ambientColor));
mRayCenter.setMediumSpeedColor(Color.parseColor(ambientColor));
mRayRight.setMediumSpeedColor(Color.parseColor(ambientColor));
} else {
mClockLeft.setIndicatorColor(Color.parseColor(ambientColor));
mClockCenter.setIndicatorColor(Color.parseColor(ambientColor));
mClockRight.setIndicatorColor(Color.parseColor(ambientColor));
mClockLeft.setIndicatorLightColor(Color.parseColor(ambientColor));
mClockCenter.setIndicatorLightColor(Color.parseColor(ambientColor));
mClockRight.setIndicatorLightColor(Color.parseColor(ambientColor));
}

switch (selectedBackground) {
case "background_incar_dots":
case "background_incar_skoda2":
int resId = getResources().getIdentifier(selectedBackground, "drawable", getContext().getPackageName());
Drawable wallpaperImage = getResources().getDrawable(resId);

wallpaperImage.setColorFilter(new LightingColorFilter(Color.parseColor(ambientColor), Color.parseColor("#010101")));

rootView.setBackground(wallpaperImage);
break;
}


}
}
}
Expand Down Expand Up @@ -908,6 +934,7 @@ private void setupElement(String queryElement, TextView value, TextView label) {

// set items to have a "-" as value.
switch (queryElement) {
//todo: clean this up. This can be done much nicer.
case "test":
case "torque_version":
case "batteryVoltage":
Expand Down Expand Up @@ -979,6 +1006,7 @@ private void setupElement(String queryElement, TextView value, TextView label) {

// set the labels
switch (queryElement) {
//todo: clean this up. maybe get the needed icons/labels from arrays.xml, so it's not needed here.
case "none":
icon = "empty";
break;
Expand Down Expand Up @@ -1199,8 +1227,10 @@ private void setupGraph(Speedometer clock, GraphView graph, LineGraphSeries seri
//graph.getViewport().setMinY(0);
graph.getViewport().setScrollable(false);
graph.getGridLabelRenderer().setVerticalLabelsVisible(true);
graph.getGridLabelRenderer().setGridColor(Color.parseColor("#44FFFFFF"));

graph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.NONE);
graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.HORIZONTAL);
graph.getViewport().setBackgroundColor(Color.argb(0, 255, 0, 0));
serie.setDrawDataPoints(false);
serie.setThickness(3);
Expand Down Expand Up @@ -1648,13 +1678,13 @@ private void updateClock(String query, Speedometer clock, RaySpeedometer visray,
break;
}

// only shift x asis 2 positions when there's new data
// only shift x asis 0.5 positions when there's new data
if (clock == mClockLeft) {
graphLeftLastXValue += 1d;
graphLeftLastXValue += 0.5d;
} else if (clock == mClockCenter) {
graphCenterLastXValue += 1d;
graphCenterLastXValue += 0.5d;
} else if (clock == mClockRight) {
graphRightLastXValue += 1d;
graphRightLastXValue += 0.5d;
}

// don't update when there's nothing to update
Expand Down Expand Up @@ -1732,15 +1762,18 @@ private void updateTitle() {
if (location2 == null) {
leftTitle = location1;
} else if (location2 != null) {
leftTitle = location1 + ", " + location2;
if (location1 ==""){
leftTitle = location2;
} else {
leftTitle = location1 + ", " + location2;
}
}
}

if (currentLeftTitleValue != leftTitle) {
mTitleElementLeft.setText(leftTitle);
}


// Display temperature in right side of Title bar
Float currentTemperature = (Float) mLastMeasurements.get("outsideTemperature");
if (currentTemperature != null) {
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/com/mqbcoding/stats/MainCarActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mqbcoding.stats;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
Expand All @@ -9,7 +8,6 @@
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;

import com.google.android.apps.auto.sdk.CarActivity;
Expand Down Expand Up @@ -148,11 +146,15 @@ public void onCreate(Bundle bundle) {
setContentView(R.layout.activity_car_main);

// todo: make background user selectable:
View someView = findViewById(R.id.fragment_container);
someView.setBackgroundResource(R.drawable.background_incar_black);
View container = findViewById(R.id.fragment_container);
container.setBackgroundResource(R.drawable.background_incar_black);

int resId = getResources().getIdentifier(selectedBackground, "drawable", this.getPackageName());
someView.setBackgroundResource(resId);
Drawable wallpaperImage = getResources().getDrawable(resId);
container.setBackground(wallpaperImage);

//container.setBackgroundResource(resId);



CarUiController carUiController = getCarUiController();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@
<item>@string/bg_skodaone</item>
<item>@string/bg_test</item>
<item>@string/bg_beetle</item>
<item>@string/bg_dots</item>

</array>

Expand All @@ -420,6 +421,7 @@
<item>background_incar_skodaone</item>
<item>background_incar_test</item>
<item>background_incar_beetle</item>
<item>background_incar_dots</item>
</array>


Expand All @@ -442,6 +444,8 @@
<item>@drawable/thumb_background_incar_skodaone</item>
<item>@drawable/thumb_background_incar_test</item>
<item>@drawable/thumb_background_incar_beetle</item>
<item>@drawable/thumb_background_incar_dots</item>

</array>


Expand Down Expand Up @@ -607,4 +611,5 @@ barometric pressure from vehicle = 33


<string name="font_ford">United Sans</string>
<string name="bg_dots">Dots</string>
</resources>

0 comments on commit 28f6d42

Please sign in to comment.