ritzelrechner

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit c54c6e8575cd869d16fd37e2d900d32e9f4434a8
Author: Jan Dankert <devnull@localhost>
Date:   Wed, 22 Feb 2012 00:07:48 +0100

Initiale Version des Ritzelrechners.

Diffstat:
.classpath | 7+++++++
.project | 33+++++++++++++++++++++++++++++++++
AndroidManifest.xml | 21+++++++++++++++++++++
res/drawable/kettenblatt.png | 0
res/layout/calculate.xml | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
res/menu/main.xml | 8++++++++
res/values-en/strings.xml | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
res/values/strings.xml | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
res/xml/preferences.xml | 14++++++++++++++
src/de/jandankert/ritzelrechner/CalculateActivity.java | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/jandankert/ritzelrechner/PreferencesActivity.java | 24++++++++++++++++++++++++
11 files changed, 477 insertions(+), 0 deletions(-)

diff --git a/.classpath b/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="gen"/> + <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/.project b/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>Ritzelrechner</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.android.ide.eclipse.adt.ApkBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>com.android.ide.eclipse.adt.AndroidNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/AndroidManifest.xml b/AndroidManifest.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="de.jandankert.ritzelrechner" android:versionCode="1" + android:versionName="1.0"> + <application android:icon="@drawable/kettenblatt" + android:label="@string/app_name"> + <activity android:name=".CalculateActivity" android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <activity android:name="PreferencesActivity"></activity> + </application> + + <!-- Android 1.6 --> + <uses-sdk android:minSdkVersion="4"></uses-sdk> + +</manifest> + \ No newline at end of file diff --git a/res/drawable/kettenblatt.png b/res/drawable/kettenblatt.png Binary files differ. diff --git a/res/layout/calculate.xml b/res/layout/calculate.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" android:layout_width="fill_parent" + android:layout_height="fill_parent" android:padding="20sp"> + + <LinearLayout android:orientation="horizontal" + android:layout_width="fill_parent" android:layout_height="wrap_content"> + <TextView android:text="@string/zaehne_vorne" + android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> + <TextView android:text=": " android:layout_width="wrap_content" + android:layout_height="wrap_content"></TextView> + <TextView android:text="test" android:id="@+id/text_zaehne_vorne" + android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> + </LinearLayout> + <SeekBar android:max="53" android:progress="48" + android:id="@+id/seek_anzahl_zaehne_vorne" android:layout_width="fill_parent" + android:layout_height="wrap_content"></SeekBar> + + <LinearLayout android:orientation="horizontal" + android:layout_width="fill_parent" android:layout_height="wrap_content"> + <TextView android:text="@string/zaehne_hinten" + android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> + <TextView android:text=": " android:layout_width="wrap_content" + android:layout_height="wrap_content"></TextView> + <TextView android:text="" android:id="@+id/text_zaehne_hinten" + android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> + </LinearLayout> + <SeekBar android:max="36" android:progress="10" + android:id="@+id/seek_anzahl_zaehne_hinten" android:layout_width="fill_parent" + android:contentDescription="@string/zaehne_hinten" + android:layout_height="wrap_content"></SeekBar> + + <LinearLayout android:orientation="horizontal" + android:layout_width="fill_parent" android:layout_height="wrap_content"> + <TextView android:text="@string/trittfrequenz" + android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> + <TextView android:text=": " android:layout_width="wrap_content" + android:layout_height="wrap_content"></TextView> + <TextView android:text="" android:id="@+id/text_trittfrequenz" + android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> + <TextView android:text=" " android:layout_width="wrap_content" + android:layout_height="wrap_content"></TextView> + <TextView android:text="@string/umin" android:layout_width="wrap_content" + android:layout_height="wrap_content"></TextView> + </LinearLayout> + <SeekBar android:max="120" android:progress="85" + android:id="@+id/seek_trittfrequenz" android:layout_width="fill_parent" + android:contentDescription="@string/trittfrequenz" + android:layout_height="wrap_content"></SeekBar> + + <TextView android:text="" android:textSize="50sp" + android:gravity="center_horizontal" android:id="@+id/geschwindigkeit" + android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView> + +</LinearLayout> diff --git a/res/menu/main.xml b/res/menu/main.xml @@ -0,0 +1,7 @@ +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:id="@+id/menu_preferences" android:title="@string/preferences" + android:icon="@android:drawable/ic_menu_preferences"></item> + +</menu> + + \ No newline at end of file diff --git a/res/values-en/strings.xml b/res/values-en/strings.xml @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">Pinion</string> + <string name="preferences">Preferences</string> + <string name="geschwindigkeit">Speed</string> + + <string name="trittfrequenz">Cadence</string> + <string name="zaehne_vorne">Tooths front</string> + <string name="zaehne_hinten">Tooths rear</string> + + <string-array name="umfang_label"> + <item>20&quot; 40-406</item> + <item>20&quot; 47-406</item> + <item>20&quot; 54-406</item> + <item>24&quot; 47-507</item> + <item>24&quot; 54-507</item> + <item>26&quot; 25-559</item> + <item>26&quot; 35-559</item> + <item>26&quot; 40-559</item> + <item>26&quot; 47-559</item> + <item>26&quot; 50-559</item> + <item>26&quot; 54-559</item> + <item>26&quot; 57-559</item> + <item>26&quot; 60-559</item> + <item>26&quot; 37-590</item> + <item>28&quot; 20-622</item> + <item>28&quot; 23-622</item> + <item>28&quot; 25-622</item> + <item>28&quot; 28-622</item> + <item>28&quot; 30-622</item> + <item>28&quot; 32-622</item> + <item>28&quot; 35-622</item> + <item>28&quot; 37-622</item> + <item>28&quot; 40-622</item> + <item>28&quot; 42-622</item> + <item>28&quot; 47-622</item> + <item>28&quot; 50-622</item> + <item>28&quot; 54-622</item> + <item>28&quot; 60-622</item> + <item>27&quot; 32-630</item> + <item>28&quot; 40-635</item> + </string-array> + + <string-array name="umfang_value"> + <item>1530</item> + <item>1550</item> + <item>1590</item> + <item>1860</item> + <item>1920</item> + <item>1940</item> + <item>1980</item> + <item>2000</item> + <item>2020</item> + <item>2040</item> + <item>2080</item> + <item>2100</item> + <item>2150</item> + <item>2090</item> + <item>2110</item> + <item>2120</item> + <item>2130</item> + <item>2150</item> + <item>2260</item> + <item>2160</item> + <item>2285</item> + <item>2190</item> + <item>2220</item> + <item>2230</item> + <item>2280</item> + <item>2280</item> + <item>2295</item> + <item>2350</item> + <item>2180</item> + <item>2240</item> + </string-array> + + + <string-array name="einheit_label"> + <item>km/h</item> + <item>mph</item> + </string-array> + + <string-array name="einheit_value"> + <item>kmh</item> + <item>mph</item> + </string-array> + + <string name="groesse">Wheelsize</string> + <string name="umin">RPM</string> +</resources> diff --git a/res/values/strings.xml b/res/values/strings.xml @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">Ritzelrechner</string> + <string name="preferences">Einstellungen</string> + <string name="geschwindigkeit">Geschwindigkeit</string> + + <string name="trittfrequenz">Trittfrequenz</string> + <string name="zaehne_vorne">Zähne vorne</string> + <string name="zaehne_hinten">Zähne hinten</string> + + <string-array name="umfang_label"> + <item>20 Zoll 40-406</item> + <item>20 Zoll 47-406</item> + <item>20 Zoll 54-406</item> + <item>24 Zoll 47-507</item> + <item>24 Zoll 54-507</item> + <item>26 Zoll 25-559</item> + <item>26 Zoll 35-559</item> + <item>26 Zoll 40-559</item> + <item>26 Zoll 47-559</item> + <item>26 Zoll 50-559</item> + <item>26 Zoll 54-559</item> + <item>26 Zoll 57-559</item> + <item>26 Zoll 60-559</item> + <item>26 Zoll 37-590</item> + <item>28 Zoll 20-622</item> + <item>28 Zoll 23-622</item> + <item>28 Zoll 25-622</item> + <item>28 Zoll 28-622</item> + <item>28 Zoll 30-622</item> + <item>28 Zoll 32-622</item> + <item>28 Zoll 35-622</item> + <item>28 Zoll 37-622</item> + <item>28 Zoll 40-622</item> + <item>28 Zoll 42-622</item> + <item>28 Zoll 47-622</item> + <item>28 Zoll 50-622</item> + <item>28 Zoll 54-622</item> + <item>28 Zoll 60-622</item> + <item>27 Zoll 32-630</item> + <item>28 Zoll 40-635</item> + </string-array> + + <string-array name="umfang_value"> + <item>1530</item> + <item>1550</item> + <item>1590</item> + <item>1860</item> + <item>1920</item> + <item>1940</item> + <item>1980</item> + <item>2000</item> + <item>2020</item> + <item>2040</item> + <item>2080</item> + <item>2100</item> + <item>2150</item> + <item>2090</item> + <item>2110</item> + <item>2120</item> + <item>2130</item> + <item>2150</item> + <item>2260</item> + <item>2160</item> + <item>2285</item> + <item>2190</item> + <item>2220</item> + <item>2230</item> + <item>2280</item> + <item>2280</item> + <item>2295</item> + <item>2350</item> + <item>2180</item> + <item>2240</item> + </string-array> + + + <string-array name="einheit_label"> + <item>km/h</item> + <item>mph</item> + </string-array> + + <string-array name="einheit_value"> + <item>kmh</item> + <item>mph</item> + </string-array> + + <string name="groesse">Radgröße</string> + <string name="umin">U/Min.</string> +</resources> diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + android:title="@string/app_name"> + + + <ListPreference android:defaultValue="2150" + android:title="@string/groesse" android:entries="@array/umfang_label" + android:entryValues="@array/umfang_value" android:key="umfang" /> + + <ListPreference android:defaultValue="kmh" + android:title="@string/geschwindigkeit" android:entries="@array/einheit_label" + android:entryValues="@array/einheit_value" android:key="einheit" /> + +</PreferenceScreen> diff --git a/src/de/jandankert/ritzelrechner/CalculateActivity.java b/src/de/jandankert/ritzelrechner/CalculateActivity.java @@ -0,0 +1,134 @@ +package de.jandankert.ritzelrechner; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.widget.SeekBar; +import android.widget.TextView; +import android.widget.SeekBar.OnSeekBarChangeListener; + +public class CalculateActivity extends Activity +{ + private SeekBar anzahlZaehneVorneView; + private SeekBar anzahlZaehneHintenView; + private SeekBar trittfrequenzView; + + private TextView geschwindigkeitView; + + private SharedPreferences prefs; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.calculate); + + prefs = PreferenceManager.getDefaultSharedPreferences(this); + + anzahlZaehneVorneView = (SeekBar) findViewById(R.id.seek_anzahl_zaehne_vorne); + anzahlZaehneHintenView = (SeekBar) findViewById(R.id.seek_anzahl_zaehne_hinten); + trittfrequenzView = (SeekBar) findViewById(R.id.seek_trittfrequenz); + geschwindigkeitView = (TextView) findViewById(R.id.geschwindigkeit); + + OnSeekBarChangeListener onSeekBarChangeDoCalculate = new OnSeekBarChangeListener() + { + @Override + public void onStopTrackingTouch(SeekBar seekBar) + { + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) + { + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, + boolean fromUser) + { + calculate(); + } + }; + + trittfrequenzView + .setOnSeekBarChangeListener(onSeekBarChangeDoCalculate); + anzahlZaehneVorneView + .setOnSeekBarChangeListener(onSeekBarChangeDoCalculate); + anzahlZaehneHintenView + .setOnSeekBarChangeListener(onSeekBarChangeDoCalculate); + + calculate(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) + { + super.onCreateOptionsMenu(menu); + MenuInflater mi = new MenuInflater(getApplication()); + mi.inflate(R.menu.main, menu); + + return true; + } + + private void calculate() + { + // Umfang im Millimeter + int umfang = Integer.parseInt(prefs.getString("umfang", "2150")); + int anzahlZaehneVorne = anzahlZaehneVorneView.getProgress(); + ((TextView) findViewById(R.id.text_zaehne_vorne)).setText("" + + anzahlZaehneVorne); + + int anzahlZaehneHinten = anzahlZaehneHintenView.getProgress(); + ((TextView) findViewById(R.id.text_zaehne_hinten)).setText("" + + anzahlZaehneHinten); + + int trittfrequenz = trittfrequenzView.getProgress(); + ((TextView) findViewById(R.id.text_trittfrequenz)).setText(Integer + .toString(trittfrequenz)); + + BigDecimal geschwindigkeit = new BigDecimal( + (((double) anzahlZaehneVorne / (double) anzahlZaehneHinten)) + * ((double) (umfang * trittfrequenz)) * 60 / 1000000) + .setScale(1, RoundingMode.HALF_UP); + + String einheit = "km/h"; + if ("mph".equals(prefs.getString("einheit", ""))) + { + geschwindigkeit = geschwindigkeit.divide(new BigDecimal("1.61"),RoundingMode.HALF_UP); + einheit = "mph"; + } + + geschwindigkeitView.setText(geschwindigkeit.toString() + " " + einheit); + + } + + public boolean onOptionsItemSelected(MenuItem item) + { + switch (item.getItemId()) + { + case R.id.menu_preferences: + startActivity(new Intent(this, PreferencesActivity.class)); + return true; + + } + return false; + } + + @Override + protected void onResume() + { + super.onResume(); + + calculate(); + } + +}+ \ No newline at end of file diff --git a/src/de/jandankert/ritzelrechner/PreferencesActivity.java b/src/de/jandankert/ritzelrechner/PreferencesActivity.java @@ -0,0 +1,24 @@ +package de.jandankert.ritzelrechner; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.os.Bundle; +import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; +import android.widget.Toast; + +public class PreferencesActivity extends PreferenceActivity +{ + private SharedPreferences prefs; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + + prefs = PreferenceManager.getDefaultSharedPreferences(this); + + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.preferences); + } +}