Skip to content

Commit

Permalink
Tyres in experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
yoh-there committed Nov 28, 2015
1 parent d903071 commit 1bdeaaa
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
android:name=".activities.FluenceKangooTempsActivity"
android:label="Fluence Kangoo Temp" >
</activity>
<activity
android:name=".activities.TyresActivity"
android:label="@string/title_activity_tyres" >
</activity>
</application>

</manifest>
162 changes: 162 additions & 0 deletions app/src/main/java/lu/fisch/canze/activities/TyresActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
CanZE
Take a closer look at your ZE car
Copyright (C) 2015 - The CanZE Team
http://canze.fisch.lu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package lu.fisch.canze.activities;

import android.os.Bundle;
import android.widget.TextView;

import java.util.ArrayList;

import lu.fisch.canze.R;
import lu.fisch.canze.actors.Field;
import lu.fisch.canze.interfaces.FieldListener;

// If you want to monitor changes, you must add a FieldListener to the fields.
// For the simple activity, the easiest way is to implement it in the actitviy itself.
public class TyresActivity extends CanzeActivity implements FieldListener {

public static final String SID_TyreSpdPresMisadaption = "673.0";
public static final String SID_TyreFLState = "673.11";
public static final String SID_TyreFLPressure = "673.40";
public static final String SID_TyreFRState = "673.8";
public static final String SID_TyreFRPressure = "673.32";
public static final String SID_TyreRLState = "673.5";
public static final String SID_TyreRLPressure = "673.24";
public static final String SID_TyreRRState = "673.2";
public static final String SID_TyreRRPressure = "673.16";

private ArrayList<Field> subscribedFields;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tyres);

initListeners();

}

private void addListener(String sid) {
Field field;
field = MainActivity.fields.getBySID(sid);
if (field != null) {
field.addListener(this);
MainActivity.device.addActivityField(field);
subscribedFields.add(field);
}
else
{
MainActivity.toast("sid " + sid + " does not exist in class Fields");
}

}

@Override
protected void onDestroy() {
super.onDestroy();

// free up the listeners again
for(Field field : subscribedFields)
{
field.removeListener(this);
}
subscribedFields.clear();
}

@Override
protected void onResume() {
super.onResume();

// initialise the widgets
initListeners();
}

private void initListeners() {

subscribedFields = new ArrayList<>();

addListener(SID_TyreSpdPresMisadaption);
addListener(SID_TyreFLState);
addListener(SID_TyreFLPressure);
addListener(SID_TyreFRState);
addListener(SID_TyreFRPressure);
addListener(SID_TyreRLState);
addListener(SID_TyreRLPressure);
addListener(SID_TyreRRState);
addListener(SID_TyreRRPressure);
}

// This is the event fired as soon as this the registered fields are
// getting updated by the corresponding reader class.
@Override
public void onFieldUpdateEvent(final Field field) {
// the update has to be done in a separate thread
// otherwise the UI will not be repainted
runOnUiThread(new Runnable() {
@Override
public void run() {
String fieldId = field.getSID();
TextView tv = null;

// get the text field
switch (fieldId) {

case SID_TyreSpdPresMisadaption:
tv = (TextView) findViewById(R.id.text_TyreSpdPresMisadaption);
break;
case SID_TyreFLState:
tv = (TextView) findViewById(R.id.text_TyreFLState);
break;
case SID_TyreFLPressure:
tv = (TextView) findViewById(R.id.text_TyreFLPressure);
break;
case SID_TyreFRState:
tv = (TextView) findViewById(R.id.text_TyreFRState);
break;
case SID_TyreFRPressure:
tv = (TextView) findViewById(R.id.text_TyreFRPressure);
break;
case SID_TyreRLState:
tv = (TextView) findViewById(R.id.text_TyreRLState);
break;
case SID_TyreRLPressure:
tv = (TextView) findViewById(R.id.text_TyreRLPressure);
break;
case SID_TyreRRState:
tv = (TextView) findViewById(R.id.text_TyreRRState);
break;
case SID_TyreRRPressure:
tv = (TextView) findViewById(R.id.text_TyreRRPressure);
break;
}
// set regular new content, all exeptions handled above
if (tv != null) {
tv.setText("" + (Math.round(field.getValue() * 10.0) / 10.0));
}

tv = (TextView) findViewById(R.id.textDebug);
tv.setText(fieldId);
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import lu.fisch.canze.activities.StatsActivity;
import lu.fisch.canze.activities.TachoActivity;
import lu.fisch.canze.activities.TemperatureActivity;
import lu.fisch.canze.activities.TyresActivity;

/**
* A simple {@link Fragment} subclass.
Expand Down Expand Up @@ -172,34 +173,30 @@ public void onClick(View v) {
}
});*/

button = (Button) view.findViewById(R.id.button_3);
button = (Button) view.findViewById(R.id.buttonFluenceKangooTemps);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!MainActivity.isSafe()) return;
if(MainActivity.device==null) {MainActivity.toast("You first need to adjust the settings ..."); return;}
MainActivity.getInstance().leaveBluetoothOn=true;
Intent intent = new Intent(MainActivity.getInstance(), ChargingTechActivity.class);
Intent intent = new Intent(MainActivity.getInstance(), FluenceKangooTempsActivity.class);
ExperimentalFragment.this.startActivityForResult(intent, MainActivity.LEAVE_BLUETOOTH_ON);
}
});

button = (Button) view.findViewById(R.id.buttonFluenceKangooTemps);
button = (Button) view.findViewById(R.id.buttonTyres);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!MainActivity.isSafe()) return;
if(MainActivity.device==null) {MainActivity.toast("You first need to adjust the settings ..."); return;}
MainActivity.getInstance().leaveBluetoothOn=true;
Intent intent = new Intent(MainActivity.getInstance(), FluenceKangooTempsActivity.class);
Intent intent = new Intent(MainActivity.getInstance(), TyresActivity.class);
ExperimentalFragment.this.startActivityForResult(intent, MainActivity.LEAVE_BLUETOOTH_ON);
}
});





return view;
}

Expand Down
164 changes: 164 additions & 0 deletions app/src/main/res/layout/activity_tyres.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:keepScreenOn="true"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="lu.fisch.canze.activities.TyresActivity">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/HeaderTyres"
android:text="@string/header_Tyres"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000" />

<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TableRow>
<TextView
android:text="@string/label_TyreSpdPresMisadaption"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreSpdPresMisadaption"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreFLState"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreFLState"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreFLPressure"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreFLPressure"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreFRState"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreFRState"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreFRPressure"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreFRPressure"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreRLState"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreRLState"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreRLPressure"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreRLPressure"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreRRState"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreRRState"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

<TableRow>
<TextView
android:text="@string/label_TyreRRPressure"
android:layout_weight="2"
/>
<TextView
android:id="@+id/text_TyreRRPressure"
android:gravity="right"
android:layout_weight="1"
/>
</TableRow>

</TableLayout>

</LinearLayout>


<!-- debug line -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>

<TableRow>
<TextView
android:text="@string/label_debug"
android:textColor="#000"
/>
<TextView
android:id="@+id/textDebug"
android:paddingLeft="8dp"
android:text="@string/default_debug"
/>
</TableRow>

</TableLayout>

</RelativeLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_experimental.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="-"
android:id="@+id/button_3"
android:text="@string/title_activity_tyres"
android:id="@+id/buttonTyres"
android:layout_column="1" />

</TableRow>
Expand Down
Loading

0 comments on commit 1bdeaaa

Please sign in to comment.