| @@ -26,11 +26,12 @@ | |||
| android:paddingTop="1dip" | |||
| android:text="@string/viewParams" | |||
| android:textColor="@color/white" | |||
| android:textStyle="bold" | |||
| android:textSize="15sp" | |||
| android:visibility="visible" | |||
| app:drawBorder="true" | |||
| app:drawBorderColor="@color/white" | |||
| app:drawBorderWidth="3dp" /> | |||
| app:drawBorderWidth="3dp" | |||
| app:font="@string/TitilliumWeb_Bold" /> | |||
| <ch.spherIC.recurvebowsight.components.XTextView | |||
| android:id="@+id/viewResults" | |||
| @@ -47,11 +48,13 @@ | |||
| android:paddingTop="1dip" | |||
| android:text="@string/viewResults" | |||
| android:textColor="@color/white" | |||
| android:textSize="15sp" | |||
| android:textStyle="normal|bold" | |||
| android:visibility="visible" | |||
| app:drawBorder="true" | |||
| app:drawBorderColor="@color/white" | |||
| app:drawBorderWidth="3dp" /> | |||
| app:drawBorderWidth="3dp" | |||
| app:font="@string/TitilliumWeb_Bold" /> | |||
| <ch.spherIC.recurvebowsight.components.XTextView | |||
| android:id="@+id/viewSight" | |||
| @@ -68,11 +71,13 @@ | |||
| android:paddingTop="1dip" | |||
| android:text="@string/viewSight" | |||
| android:textColor="@color/white" | |||
| android:textSize="15sp" | |||
| android:textStyle="bold" | |||
| android:visibility="visible" | |||
| app:drawBorder="true" | |||
| app:drawBorderColor="@color/white" | |||
| app:drawBorderWidth="3dp" /> | |||
| app:drawBorderWidth="3dp" | |||
| app:font="@string/TitilliumWeb_Bold" /> | |||
| </LinearLayout> | |||
| <ViewFlipper | |||
| @@ -106,7 +111,7 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/bowAndArrowParams" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| @@ -117,8 +122,9 @@ | |||
| android:paddingTop="3dip" | |||
| android:text="@string/titleBowAndArrowParams" | |||
| android:textColor="@color/black" | |||
| android:textStyle="bold" > | |||
| </TextView> | |||
| android:textStyle="bold" | |||
| app:font="@string/TitilliumWeb_Bold" /> | |||
| </TableRow> | |||
| <TableRow | |||
| @@ -128,13 +134,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/arrowDiameterLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/arrowDiameterLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/arrowDiameterTxtFld" | |||
| @@ -159,13 +166,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/arrowCwLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/arrowCwLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/arrowCwTxtFld" | |||
| @@ -189,13 +197,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/arrowWeightLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/arrowWeightLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/arrowWeightTxtFld" | |||
| @@ -219,13 +228,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/bowPulloutLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/bowPulloutLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/bowPulloutTxtFld" | |||
| @@ -250,13 +260,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/arrowV0Lbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/arrowV0Lbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/arrowV0TxtFld" | |||
| @@ -280,7 +291,7 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/atmosphericalParams" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| @@ -291,9 +302,8 @@ | |||
| android:paddingTop="3dip" | |||
| android:text="@string/titleAtmosphericalParams" | |||
| android:textColor="@color/black" | |||
| android:textStyle="bold" > | |||
| </TextView> | |||
| android:textStyle="bold" | |||
| app:font="@string/TitilliumWeb_Bold" /> | |||
| </TableRow> | |||
| @@ -304,13 +314,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/airTemperatureLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/airTemperatureLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/airTemperatureTxtFld" | |||
| @@ -334,13 +345,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/airRelativeHumidityLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/airRelativeHumidityLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/airRelativeHumidityTxtFld" | |||
| @@ -359,22 +371,56 @@ | |||
| <TableRow android:id="@+id/tableRow10" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="4dp"> | |||
| <TextView android:id="@+id/shootingParams" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@color/yellow" android:paddingBottom="3dip" android:paddingLeft="3dip" android:paddingTop="3dip" android:text="@string/titleShootingParams" android:textColor="@color/black" android:textStyle="bold" /> | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/shootingParams" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_weight="1" | |||
| android:background="@color/yellow" | |||
| android:paddingBottom="3dip" | |||
| android:paddingLeft="3dip" | |||
| android:paddingTop="3dip" | |||
| android:text="@string/titleShootingParams" | |||
| android:textColor="@color/black" | |||
| android:textStyle="bold" | |||
| app:font="@string/TitilliumWeb_Bold" /> | |||
| </TableRow><TableRow android:id="@+id/tableRow11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="4dp"> | |||
| <TextView android:id="@+id/shootingDistanzLbl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:text="@string/shootingDistanzLbl" android:textColor="@color/black" /> | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/shootingDistanzLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/shootingDistanzLbl" | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText android:id="@+id/shootingDistanzTxtFld" android:layout_width="150dp" android:layout_height="36dp" android:layout_marginLeft="4dp" android:ems="10" android:gravity="center_vertical" android:inputType="numberDecimal" android:paddingBottom="9dp" android:paddingTop="9dp" android:text="22" android:textSize="18sp" /> | |||
| </TableRow><TableRow android:id="@+id/tableRow12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="4dp"> | |||
| <TextView android:id="@+id/arrowNockHeightLbl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:text="@string/arrowNockHeightLbl" android:textColor="@color/black" /> | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/arrowNockHeightLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/arrowNockHeightLbl" | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText android:id="@+id/arrowNockHeightTxtFld" android:layout_width="150dp" android:layout_height="36dp" android:layout_marginLeft="4dp" android:ems="10" android:gravity="center_vertical" android:inputType="numberDecimal" android:paddingBottom="9dp" android:paddingTop="9dp" android:text="22" android:textSize="18sp" /> | |||
| </TableRow><TableRow android:id="@+id/tableRow13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="4dp"> | |||
| <TextView android:id="@+id/targetCenterHeightLbl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:text="@string/targetCenterHeightLbl" android:textColor="@color/black" /> | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/targetCenterHeightLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/targetCenterHeightLbl" | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText android:id="@+id/targetCenterHeightTxtFld" android:layout_width="150dp" android:layout_height="36dp" android:layout_marginLeft="4dp" android:ems="10" android:gravity="center_vertical" android:inputType="numberDecimal" android:paddingBottom="9dp" android:paddingTop="9dp" android:text="22" android:textSize="18sp" /> | |||
| @@ -385,7 +431,7 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/calculationParams" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| @@ -396,9 +442,8 @@ | |||
| android:paddingTop="3dip" | |||
| android:text="@string/titleCalculationParams" | |||
| android:textColor="@color/black" | |||
| android:textStyle="bold" > | |||
| </TextView> | |||
| android:textStyle="bold" | |||
| app:font="@string/TitilliumWeb_Bold" /> | |||
| </TableRow> | |||
| @@ -409,13 +454,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/deltaTimeLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/deltaTimeLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/deltaTimeTxtFld" | |||
| @@ -439,13 +485,14 @@ | |||
| android:layout_gravity="center" | |||
| android:layout_margin="4dp" > | |||
| <TextView | |||
| <ch.spherIC.recurvebowsight.components.FontTextView | |||
| android:id="@+id/calcPrecisionLbl" | |||
| android:layout_width="fill_parent" | |||
| android:layout_height="wrap_content" | |||
| android:layout_gravity="right|center_vertical" | |||
| android:text="@string/calcPrecisionLbl" | |||
| android:textColor="@color/black" /> | |||
| android:textColor="@color/black" | |||
| app:font="@string/TitilliumWeb_Regular" /> | |||
| <EditText | |||
| android:id="@+id/calcPrecisionTxtFld" | |||
| @@ -19,7 +19,7 @@ | |||
| <string name="arrowWeightLbl">Gewicht Pfeil [g]</string> | |||
| <string name="titleAtmosphericalParams">Atmosphärische Parameter</string> | |||
| <string name="airTemperatureLbl">Luftemperatur [°Celsius]</string> | |||
| <string name="airTemperatureLbl">Lufttemperatur [°Celsius]</string> | |||
| <string name="airRelativeHumidityLbl">Rel. Luftfeuchtigkeit [%]</string> | |||
| <string name="titleShootingParams">Schussparameter</string> | |||
| @@ -17,4 +17,21 @@ | |||
| </declare-styleable> | |||
| <declare-styleable | |||
| name="FontTextView"> | |||
| <attr | |||
| name="font" | |||
| format="string" /> | |||
| </declare-styleable> | |||
| <declare-styleable | |||
| name="FontButton"> | |||
| <attr | |||
| name="btnFont" | |||
| format="string" /> | |||
| </declare-styleable> | |||
| </resources> | |||
| @@ -0,0 +1,9 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <resources> | |||
| <string name="TitilliumWeb_Bold">fonts/TitilliumWeb-Bold.ttf</string> | |||
| <string name="TitilliumWeb_BoldItalic">fonts/TitilliumWeb-BoldItalic.ttf</string> | |||
| <string name="TitilliumWeb_Italic">fonts/TitilliumWeb-Italic.ttf</string> | |||
| <string name="TitilliumWeb_Light">fonts/TitilliumWeb-Light.ttf</string> | |||
| <string name="TitilliumWeb_Regular">fonts/TitilliumWeb-Regular.ttf</string> | |||
| </resources> | |||
| @@ -1,6 +1,6 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <resources> | |||
| <string name="app_name">Recurve Bow Sight </string> | |||
| <string name="title_rbs_main_activity">Recurve Bow Sight</string> | |||
| <string name="title_activity_riser_sight_configuration">Riser-Sight Configuration</string> | |||
| @@ -1,6 +1,33 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <resources> | |||
| <style | |||
| name="GlassSpinner" | |||
| parent="@android:style/Widget.Spinner"> | |||
| <item name="android:background">@drawable/dropdown_fs</item> | |||
| </style> | |||
| <style | |||
| name="GlassButton" | |||
| parent="@android:style/Widget.Button"> | |||
| <item name="android:background">@drawable/btn_fs</item> | |||
| <item name="android:textColor">@color/white</item> | |||
| </style> | |||
| <style | |||
| name="GlassButtonSmall" | |||
| parent="@android:style/Widget.Button.Small"> | |||
| <item name="android:background">@drawable/btn_fs</item> | |||
| <item name="android:textColor">@color/white</item> | |||
| </style> | |||
| <style | |||
| name="GlassButtonToggle" | |||
| parent="@android:style/Widget.Button.Toggle"> | |||
| <item name="android:background">@drawable/btn_fs</item> | |||
| <item name="android:textColor">@color/white</item> | |||
| </style> | |||
| <style | |||
| name="GlassDropdownItem" | |||
| parent="@android:style/Widget.TextView.SpinnerItem"> | |||
| @@ -20,6 +20,7 @@ import android.widget.ViewFlipper; | |||
| import ch.spherIC.recurvebowsight.R; | |||
| import ch.spherIC.recurvebowsight.components.XTextView; | |||
| import ch.spherIC.recurvebowsight.database.RBSDatabaseHelper; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| @@ -41,6 +42,11 @@ public class RBSMainActivity extends Activity { | |||
| super.onCreate(savedInstanceState); | |||
| setContentView(R.layout.rbs_main); | |||
| RBSDatabaseHelper.setContext(this); | |||
| RBSDatabaseHelper helper = RBSDatabaseHelper.getInstance(); | |||
| helper.getWritableDatabase(); | |||
| this.viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper); | |||
| this.scrollView = (ScrollView) findViewById(R.id.scrollView1); | |||
| @@ -0,0 +1,68 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.components; | |||
| import android.content.Context; | |||
| import android.content.res.TypedArray; | |||
| import android.graphics.Typeface; | |||
| import android.util.AttributeSet; | |||
| import android.util.Log; | |||
| import android.widget.Button; | |||
| import ch.spherIC.recurvebowsight.R; | |||
| /** | |||
| * Siehe http://stackoverflow.com/questions/2376250/custom-fonts-and-xml-layouts-android. | |||
| * | |||
| * @author FC Smilari | |||
| */ | |||
| public class FontButton extends Button { | |||
| private static final String TAG = "Button"; | |||
| public FontButton(final Context context) { | |||
| super(context); | |||
| } | |||
| public FontButton(final Context context, final AttributeSet attrs) { | |||
| super(context, attrs); | |||
| setBtnFont(context, attrs); | |||
| } | |||
| public FontButton(final Context context, final AttributeSet attrs, final int defStyle) { | |||
| super(context, attrs, defStyle); | |||
| setBtnFont(context, attrs); | |||
| } | |||
| private void setBtnFont(final Context ctx, final AttributeSet attrs) { | |||
| if (!isInEditMode()) { | |||
| TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.FontButton); | |||
| String font = a.getString(R.styleable.FontButton_btnFont); | |||
| if (font != null && !font.isEmpty()) { | |||
| setBtnFont(ctx, font); | |||
| } | |||
| a.recycle(); | |||
| } | |||
| } | |||
| public boolean setBtnFont(final Context ctx, final String font) { | |||
| Typeface tf = null; | |||
| try { | |||
| tf = Typeface.createFromAsset(ctx.getAssets(), font); | |||
| } catch (final Exception e) { | |||
| Log.e(TAG, "Could not get typeface: " + e.getMessage()); | |||
| return false; | |||
| } | |||
| setTypeface(tf); | |||
| return true; | |||
| } | |||
| } | |||
| @@ -0,0 +1,68 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.components; | |||
| import android.content.Context; | |||
| import android.content.res.TypedArray; | |||
| import android.graphics.Typeface; | |||
| import android.util.AttributeSet; | |||
| import android.util.Log; | |||
| import android.widget.TextView; | |||
| import ch.spherIC.recurvebowsight.R; | |||
| /** | |||
| * Siehe http://stackoverflow.com/questions/2376250/custom-fonts-and-xml-layouts-android. | |||
| * | |||
| * @author FC Smilari | |||
| */ | |||
| public class FontTextView extends TextView { | |||
| private static final String TAG = "TextView"; | |||
| public FontTextView(final Context context) { | |||
| super(context); | |||
| } | |||
| public FontTextView(final Context context, final AttributeSet attrs) { | |||
| super(context, attrs); | |||
| setFont(context, attrs); | |||
| } | |||
| public FontTextView(final Context context, final AttributeSet attrs, final int defStyle) { | |||
| super(context, attrs, defStyle); | |||
| setFont(context, attrs); | |||
| } | |||
| private void setFont(final Context ctx, final AttributeSet attrs) { | |||
| if (!isInEditMode()) { | |||
| TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.FontTextView); | |||
| String font = a.getString(R.styleable.FontTextView_font); | |||
| if (font != null && !font.isEmpty()) { | |||
| setFont(ctx, font); | |||
| } | |||
| a.recycle(); | |||
| } | |||
| } | |||
| public boolean setFont(final Context ctx, final String font) { | |||
| Typeface tf = null; | |||
| try { | |||
| tf = Typeface.createFromAsset(ctx.getAssets(), font); | |||
| } catch (final Exception e) { | |||
| Log.e(TAG, "Could not get typeface: " + e.getMessage()); | |||
| return false; | |||
| } | |||
| setTypeface(tf); | |||
| return true; | |||
| } | |||
| } | |||
| @@ -25,8 +25,6 @@ import android.graphics.Rect; | |||
| import android.util.AttributeSet; | |||
| import android.widget.TextView; | |||
| import ch.spherIC.recurvebowsight.R; | |||
| @@ -36,7 +34,7 @@ import ch.spherIC.recurvebowsight.R; | |||
| * @author $author$ | |||
| * @version $Revision$, $Date$ | |||
| */ | |||
| public class XTextView extends TextView { | |||
| public class XTextView extends FontTextView { | |||
| private boolean drawborder; | |||
| private int drawborderColor; | |||
| @@ -0,0 +1,76 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.database; | |||
| import android.content.Context; | |||
| import android.database.sqlite.SQLiteDatabase; | |||
| import android.database.sqlite.SQLiteOpenHelper; | |||
| import ch.spherIC.recurvebowsight.database.scheme.masterdata.TblRBSRiser; | |||
| /** | |||
| * Siehe http://www.sqlite.org/lang.html. | |||
| * | |||
| * @author FC Smilari | |||
| */ | |||
| public final class RBSDatabaseHelper extends SQLiteOpenHelper { | |||
| public static final String DB_NAME = "RecurveBowSight.db"; | |||
| public static final int DB_VERSION = 1; | |||
| private static RBSDatabaseHelper instance; | |||
| private static Context context; | |||
| private static String actualDBName = DB_NAME; | |||
| /** | |||
| * Konstruktor. | |||
| * | |||
| * @param context {@link Context} | |||
| */ | |||
| private RBSDatabaseHelper(final Context context) { | |||
| super(context, actualDBName, null, DB_VERSION); | |||
| } | |||
| public static RBSDatabaseHelper getInstance() { | |||
| if (instance == null) { | |||
| instance = new RBSDatabaseHelper(context); | |||
| } | |||
| return instance; | |||
| } | |||
| /** | |||
| * @param context the context to set | |||
| */ | |||
| public static void setContext(final Context context) { | |||
| RBSDatabaseHelper.context = context; | |||
| } | |||
| /** | |||
| * @param context the context to set | |||
| */ | |||
| public static void setDB(final String dbName) { | |||
| RBSDatabaseHelper.actualDBName = dbName; | |||
| } | |||
| @Override | |||
| public void onCreate(final SQLiteDatabase db) { | |||
| // Tabellen erstellen | |||
| db.execSQL(TblRBSRiser.getCreateStatement()); | |||
| // db.execSQL(TblSBLineup.getCreateStatement()); | |||
| // db.execSQL(TblSBGameType.getCreateStatement()); | |||
| } | |||
| @Override | |||
| public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| } | |||
| @@ -0,0 +1,122 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.database.dao; | |||
| import android.content.ContentValues; | |||
| import android.database.Cursor; | |||
| import android.database.sqlite.SQLiteDatabase; | |||
| import ch.spherIC.recurvebowsight.database.RBSDatabaseHelper; | |||
| import ch.spherIC.recurvebowsight.model.IEntity; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| /** | |||
| * DAO-Vaterklasse. | |||
| * | |||
| * @author FC Smilari | |||
| */ | |||
| public abstract class DAO<E extends IEntity> { | |||
| /** | |||
| * Konstruktor. | |||
| */ | |||
| public DAO() { | |||
| super(); | |||
| } | |||
| /** | |||
| * @return the db | |||
| */ | |||
| protected SQLiteDatabase getDb() { | |||
| return RBSDatabaseHelper.getInstance().getWritableDatabase(); | |||
| } | |||
| protected abstract E cursorToEntity(final Cursor cursor); | |||
| protected abstract ContentValues getContentValues(E entity); | |||
| protected abstract String getTableName(); | |||
| protected abstract String getIdColumn(); | |||
| /** | |||
| * Lädt das Entität über eine Id. | |||
| * | |||
| * @param id | |||
| * | |||
| * @return E | |||
| */ | |||
| public E loadById(final long id) { | |||
| E entity; | |||
| Cursor cursor = getDb().query(getTableName(), null, getIdColumn() + " = " + id, null, null, null, null); | |||
| cursor.moveToFirst(); | |||
| entity = cursorToEntity(cursor); | |||
| cursor.close(); | |||
| return entity; | |||
| } | |||
| /** | |||
| * Lädt alle Entitäten. | |||
| * | |||
| * @return | |||
| */ | |||
| public List<E> loadAll() { | |||
| List<E> entities = new ArrayList<E>(); | |||
| Cursor cursor = getDb().query(getTableName(), null, null, null, null, null, null); | |||
| cursor.moveToFirst(); | |||
| while (!cursor.isAfterLast()) { | |||
| E entity = cursorToEntity(cursor); | |||
| entities.add(entity); | |||
| cursor.moveToNext(); | |||
| } | |||
| cursor.close(); | |||
| return entities; | |||
| } | |||
| /** | |||
| * Fügt eine Entität in die DB ein. | |||
| * | |||
| * @param entity | |||
| * | |||
| * @return | |||
| */ | |||
| public E insert(final E entity) { | |||
| ContentValues values = getContentValues(entity); | |||
| long insertId = getDb().insert(getTableName(), null, values); | |||
| return loadById(insertId); | |||
| } | |||
| /** | |||
| * Updated eine Entität in der DB ein. | |||
| * | |||
| * @param entity | |||
| * | |||
| * @return | |||
| */ | |||
| public E update(final E entity) { | |||
| ContentValues values = getContentValues(entity); | |||
| getDb().update(getTableName(), values, getIdColumn() + " = " + entity.getId(), null); | |||
| return loadById(entity.getId()); | |||
| } | |||
| /** | |||
| * Löschet eine Entität aus der DB. | |||
| * | |||
| * @param entity | |||
| */ | |||
| public void delete(final E entity) { | |||
| getDb().delete(getTableName(), getIdColumn() + " = " + entity.getId(), null); | |||
| } | |||
| } | |||
| @@ -0,0 +1,68 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.database.dao; | |||
| import android.content.ContentValues; | |||
| import android.database.Cursor; | |||
| import ch.spherIC.recurvebowsight.database.scheme.masterdata.TblRBSRiser; | |||
| import ch.spherIC.recurvebowsight.model.IRiser; | |||
| import ch.spherIC.recurvebowsight.model.Riser; | |||
| /** | |||
| * @author FC Smilari | |||
| */ | |||
| public final class RiserDao extends DAO<IRiser> { | |||
| private static RiserDao instance; | |||
| private RiserDao() { | |||
| super(); | |||
| } | |||
| public static RiserDao getInstance() { | |||
| if (instance == null) { | |||
| instance = new RiserDao(); | |||
| } | |||
| return instance; | |||
| } | |||
| @Override | |||
| protected IRiser cursorToEntity(final Cursor cursor) { | |||
| IRiser riser = new Riser(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getDouble(3), cursor.getDouble(4), | |||
| cursor.getDouble(5)); | |||
| return riser; | |||
| } | |||
| @Override | |||
| protected ContentValues getContentValues(final IRiser entity) { | |||
| ContentValues values = new ContentValues(); | |||
| if (entity.getId() > 0) { | |||
| values.put(TblRBSRiser.COL_ID, entity.getId()); | |||
| } | |||
| values.put(TblRBSRiser.COL_MANUFACTURER, !entity.getManufacturer().isEmpty() ? entity.getManufacturer() : ""); | |||
| values.put(TblRBSRiser.COL_MODEL, !entity.getModel().isEmpty() ? entity.getModel() : ""); | |||
| values.put(TblRBSRiser.COL_SIZE, entity.getSize() != null ? entity.getSize() : 0d); | |||
| values.put(TblRBSRiser.COL_VVIS_H, entity.getVVisH() != null ? entity.getVVisH() : 0d); | |||
| values.put(TblRBSRiser.COL_VVIS_V, entity.getVVisV() != null ? entity.getVVisV() : 0d); | |||
| return values; | |||
| } | |||
| @Override | |||
| protected String getTableName() { | |||
| return TblRBSRiser.NAME; | |||
| } | |||
| @Override | |||
| protected String getIdColumn() { | |||
| return TblRBSRiser.COL_ID; | |||
| } | |||
| } | |||
| @@ -0,0 +1,33 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.database.scheme.masterdata; | |||
| public final class TblRBSRiser { | |||
| public static final String NAME = "RBS_RISER"; | |||
| public static final String COL_ID = "RISER_ID"; | |||
| public static final String COL_MANUFACTURER = "RISER_MANUFACTURER"; | |||
| public static final String COL_MODEL = "RISER_MODEL"; | |||
| public static final String COL_SIZE = "RISER_SIZE"; | |||
| public static final String COL_VVIS_H = "RISER_VVIS_H"; | |||
| public static final String COL_VVIS_V = "RISER_VVIS_V"; | |||
| private TblRBSRiser() { | |||
| } | |||
| public static String getCreateStatement() { | |||
| return "create table " + NAME + "(" | |||
| + COL_ID + " Integer primary key autoincrement, " | |||
| + COL_MANUFACTURER + " Text NOT NULL, " | |||
| + COL_MODEL + " Text NOT NULL, " | |||
| + COL_SIZE + " Real NOT NULL, " | |||
| + COL_VVIS_H + " Real NOT NULL, " | |||
| + COL_VVIS_V + " Real NOT NULL, " | |||
| + "constraint UNIQUE_MF_MODEL_SIZE UNIQUE (" + COL_MANUFACTURER + "," + COL_MODEL + "," + COL_SIZE + ")" | |||
| + ");"; | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.model; | |||
| /** | |||
| * Vaterklasse aller Entitäten. | |||
| * | |||
| * @author FC Smilari | |||
| */ | |||
| public interface IEntity { | |||
| long getId(); | |||
| void setId(long id); | |||
| } | |||
| @@ -0,0 +1,22 @@ | |||
| /** | |||
| * Copyright (C) 2012 - Florindo Smilari (spherIC) | |||
| */ | |||
| package ch.spherIC.recurvebowsight.model; | |||
| /** | |||
| * @author FC Smilari | |||
| */ | |||
| public interface IRiser extends IEntity { | |||
| String getManufacturer(); | |||
| String getModel(); | |||
| Double getSize(); | |||
| Double getVVisH(); | |||
| Double getVVisV(); | |||
| } | |||
| @@ -0,0 +1,122 @@ | |||
| /** | |||
| * Copyright (C) 2005-2012 XELOG AG | |||
| */ | |||
| package ch.spherIC.recurvebowsight.model; | |||
| /** | |||
| * @author FC Smilari | |||
| */ | |||
| public class Riser implements IRiser { | |||
| private long id; | |||
| private String manufacturer; | |||
| private String model; | |||
| private Double size; | |||
| private Double vVisH; | |||
| private Double vVisV; | |||
| /** | |||
| * Konstruktor. | |||
| * | |||
| * @param id | |||
| * @param maufacturer | |||
| * @param model | |||
| * @param size | |||
| * @param vVisH | |||
| * @param vVisV | |||
| */ | |||
| public Riser(final long id, final String manufacturer, final String model, final Double size, | |||
| final Double vVisH, final Double vVisV) { | |||
| super(); | |||
| this.id = id; | |||
| this.manufacturer = manufacturer; | |||
| this.model = model; | |||
| this.size = size; | |||
| this.vVisH = vVisH; | |||
| this.vVisV = vVisV; | |||
| } | |||
| /** | |||
| * @return the id | |||
| */ | |||
| public long getId() { | |||
| return this.id; | |||
| } | |||
| /** | |||
| * @param id the id to set | |||
| */ | |||
| public void setId(final long id) { | |||
| this.id = id; | |||
| } | |||
| /** | |||
| * @return the manufacturer | |||
| */ | |||
| public String getManufacturer() { | |||
| return this.manufacturer; | |||
| } | |||
| /** | |||
| * @param maufacturer the maufacturer to set | |||
| */ | |||
| public void setManufacturer(final String maufacturer) { | |||
| this.manufacturer = maufacturer; | |||
| } | |||
| /** | |||
| * @return the model | |||
| */ | |||
| public String getModel() { | |||
| return this.model; | |||
| } | |||
| /** | |||
| * @param model the model to set | |||
| */ | |||
| public void setModel(final String model) { | |||
| this.model = model; | |||
| } | |||
| /** | |||
| * @return the size | |||
| */ | |||
| public Double getSize() { | |||
| return this.size; | |||
| } | |||
| /** | |||
| * @param size the size to set | |||
| */ | |||
| public void setSize(final Double size) { | |||
| this.size = size; | |||
| } | |||
| /** | |||
| * @return the vVisH | |||
| */ | |||
| public Double getVVisH() { | |||
| return this.vVisH; | |||
| } | |||
| /** | |||
| * @param vVisH the vVisH to set | |||
| */ | |||
| public void setVVisH(final Double vVisH) { | |||
| this.vVisH = vVisH; | |||
| } | |||
| /** | |||
| * @return the vVisV | |||
| */ | |||
| public Double getVVisV() { | |||
| return this.vVisV; | |||
| } | |||
| /** | |||
| * @param vVisV the vVisV to set | |||
| */ | |||
| public void setVVisV(final Double vVisV) { | |||
| this.vVisV = vVisV; | |||
| } | |||
| } | |||