Initial commit.
26
AndroidManifest.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:installLocation="preferExternal"
|
||||
package="net.thauvin.erik.android.emprunt"
|
||||
android:versionCode="4"
|
||||
android:versionName="1.0.1" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Emprunt" >
|
||||
<activity
|
||||
android:name=".EmpruntActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="sensorPortait" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
59
gen/net/thauvin/erik/android/emprunt/R.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.android.emprunt;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int border=0x7f020000;
|
||||
public static final int green_gradient=0x7f020001;
|
||||
public static final int icon=0x7f020002;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int amount=0x7f060002;
|
||||
public static final int calculate=0x7f060007;
|
||||
public static final int cost=0x7f06000e;
|
||||
public static final int interest=0x7f060004;
|
||||
public static final int months=0x7f060006;
|
||||
public static final int payment=0x7f06000b;
|
||||
public static final int tableLayout1=0x7f060008;
|
||||
public static final int tableRow1=0x7f060009;
|
||||
public static final int tableRow2=0x7f06000c;
|
||||
public static final int textView1=0x7f060001;
|
||||
public static final int textView2=0x7f060003;
|
||||
public static final int textView3=0x7f060005;
|
||||
public static final int textView4=0x7f06000a;
|
||||
public static final int textView6=0x7f06000d;
|
||||
public static final int titleBar=0x7f060000;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int main=0x7f030000;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int about_copyright=0x7f040001;
|
||||
public static final int about_copyright_blackberry=0x7f040002;
|
||||
public static final int about_title=0x7f040003;
|
||||
public static final int app_name=0x7f040000;
|
||||
public static final int btn_calculate=0x7f040004;
|
||||
public static final int hint_amount=0x7f040005;
|
||||
public static final int hint_calculate=0x7f040006;
|
||||
public static final int hint_interest=0x7f040007;
|
||||
public static final int hint_months=0x7f040008;
|
||||
public static final int label_amount=0x7f040009;
|
||||
public static final int label_cost=0x7f04000a;
|
||||
public static final int label_interest=0x7f04000b;
|
||||
public static final int label_months=0x7f04000c;
|
||||
public static final int label_payment=0x7f04000d;
|
||||
public static final int label_version=0x7f04000e;
|
||||
public static final int menu_about=0x7f04000f;
|
||||
}
|
||||
public static final class style {
|
||||
public static final int Emprunt=0x7f050000;
|
||||
}
|
||||
}
|
BIN
res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 3 KiB |
BIN
res/drawable-xhdpi/icon.png
Normal file
After Width: | Height: | Size: 9 KiB |
8
res/drawable/border.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<stroke android:width="1px" android:color="#D6DBD6" />
|
||||
<solid android:color="@android:color/white" />
|
||||
<padding android:left="7dp" android:top="7dp"
|
||||
android:right="7dp" android:bottom="7dp" />
|
||||
<corners android:radius="4dp" />
|
||||
</shape>
|
11
res/drawable/green_gradient.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:endColor="#016701"
|
||||
android:startColor="#359D3A" />
|
||||
|
||||
<corners android:radius="0dp" />
|
||||
|
||||
</shape>
|
161
res/layout/main.xml
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleBar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="45dip"
|
||||
android:background="@drawable/green_gradient"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="10dip"
|
||||
android:shadowColor="#000000"
|
||||
android:shadowDx="2"
|
||||
android:shadowDy="2"
|
||||
android:shadowRadius="1.5"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textColor="@android:color/white" />
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingTop="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_amount"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" >
|
||||
</TextView>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/amount"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hint_amount"
|
||||
android:inputType="number"
|
||||
android:textColorHint="#FFCCCCCC" >
|
||||
|
||||
<requestFocus />
|
||||
</EditText>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_interest"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" >
|
||||
</TextView>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/interest"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hint_interest"
|
||||
android:inputType="numberDecimal"
|
||||
android:textColorHint="#FFCCCCCC" >
|
||||
</EditText>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_months"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" >
|
||||
</TextView>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/months"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hint_months"
|
||||
android:inputType="number"
|
||||
android:textColorHint="#FFCCCCCC" >
|
||||
</EditText>
|
||||
|
||||
<Button
|
||||
android:id="@+id/calculate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:drawableLeft="@drawable/icon"
|
||||
android:drawablePadding="5dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="@string/btn_calculate"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textStyle="bold" >
|
||||
</Button>
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/tableLayout1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="3dp"
|
||||
android:background="@drawable/border" >
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/tableRow1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingRight="10dp"
|
||||
android:text="@string/label_payment"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/payment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:gravity="right"
|
||||
android:text="@string/hint_calculate"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="#FFCCCCCC" >
|
||||
</TextView>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/tableRow2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingRight="10dp"
|
||||
android:text="@string/label_cost"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cost"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:gravity="right"
|
||||
android:text="@string/hint_calculate"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="#FFCCCCCC" >
|
||||
</TextView>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
21
res/values-fr/strings.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Emprunt</string>
|
||||
<string name="about_copyright">© 2011–12 Erik C. Thauvin.\nTous droits réservés.\n\nhttp://m.thauvin.net/android/</string>
|
||||
<string name="about_copyright_blackberry">© 2011–12 Erik C. Thauvin.\nTous droits réservés.\n\nhttp://m.thauvin.net/blackberry/</string>
|
||||
<string name="about_title">À propos d\'</string>
|
||||
<string name="btn_calculate">Calculer</string>
|
||||
<string name="hint_amount">ex. 100000</string>
|
||||
<string name="hint_calculate">à calculer…</string>
|
||||
<string name="hint_interest">ex. 5.2</string>
|
||||
<string name="hint_months">ex. 240</string>
|
||||
<string name="label_amount">Montant emprunté:</string>
|
||||
<string name="label_cost">Coût total:</string>
|
||||
<string name="label_interest">Taux d\'intérêt:</string>
|
||||
<string name="label_months">Nombre de mensualités:</string>
|
||||
<string name="label_payment">Mensualité:</string>
|
||||
<string name="label_version">Version:</string>
|
||||
<string name="menu_about">À propos</string>
|
||||
|
||||
</resources>
|
6
res/values-v11/themes.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Emprunt" parent="@android:style/Theme.Holo.Light" />
|
||||
|
||||
</resources>
|
21
res/values/strings.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Loan</string>
|
||||
<string name="about_copyright">© 2011–12 Erik C. Thauvin.\nAll Rights Reserved.\n\nhttp://m.thauvin.net/android/</string>
|
||||
<string name="about_copyright_blackberry">© 2011–12 Erik C. Thauvin.\nAll Rights Reserved.\n\nhttp://m.thauvin.net/blackberry/</string>
|
||||
<string name="about_title">About </string>
|
||||
<string name="btn_calculate">Calculate</string>
|
||||
<string name="hint_amount">e.g. 100000</string>
|
||||
<string name="hint_calculate">to be calculated…</string>
|
||||
<string name="hint_interest">e.g. 5.2</string>
|
||||
<string name="hint_months">e.g. 240</string>
|
||||
<string name="label_amount">Loan Amount:</string>
|
||||
<string name="label_cost">Total Cost:</string>
|
||||
<string name="label_interest">Interest Rate:</string>
|
||||
<string name="label_months">Number of Months:</string>
|
||||
<string name="label_payment">Payment:</string>
|
||||
<string name="label_version">Version:</string>
|
||||
<string name="menu_about">About</string>
|
||||
|
||||
</resources>
|
4
res/values/themes.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Emprunt" parent="@android:style/Theme.Light.NoTitleBar" />
|
||||
</resources>
|
BIN
screenshots/bb-640.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
screenshots/bb-featured.png
Normal file
After Width: | Height: | Size: 304 KiB |
BIN
screenshots/bb-fr-640.jpg
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
screenshots/bb-fr.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
screenshots/bb.jpg
Normal file
After Width: | Height: | Size: 43 KiB |
BIN
screenshots/icon480.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
screenshots/loan.gif
Normal file
After Width: | Height: | Size: 127 KiB |
76
src/net/thauvin/erik/android/emprunt/AboutDialogBuilder.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* @(#)AboutDialogBuilder.java
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
package net.thauvin.erik.android.emprunt;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.Color;
|
||||
import android.text.SpannableString;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* The <code>AboutDialogBuilder</code> class implements a simple "About" dialog.
|
||||
*
|
||||
* @author <a href="http://itkrauts.com/archives/26-Creating-a-simple-About-Dialog-in-Android-1.6.html">Sebastian Bauer</a>
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @version $Revision$
|
||||
* @created October 14, 2011
|
||||
* @since 1.0
|
||||
*/
|
||||
public class AboutDialogBuilder
|
||||
{
|
||||
public static AlertDialog create(Context context) throws NameNotFoundException
|
||||
{
|
||||
// Try to load the a package matching the name of our own package
|
||||
final PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
|
||||
final String versionInfo = pInfo.versionName;
|
||||
|
||||
final String aboutTitle = String.format("%s%s", context.getString(R.string.about_title), context.getString(R.string.app_name));
|
||||
final String versionString = String.format("%s %s", context.getString(R.string.label_version), versionInfo);
|
||||
|
||||
// Set up the TextView
|
||||
final TextView message = new TextView(context);
|
||||
// message.setTextSize(18);
|
||||
message.setTextAppearance(context, android.R.style.TextAppearance_Medium);
|
||||
message.setBackgroundColor(Color.WHITE);
|
||||
|
||||
// We'll use a spannablestring to be able to make links clickable
|
||||
final SpannableString s;
|
||||
if (System.getProperty("os.name").equalsIgnoreCase("qnx"))
|
||||
{
|
||||
s = new SpannableString(context.getString(R.string.about_copyright_blackberry));
|
||||
}
|
||||
else
|
||||
{
|
||||
s = new SpannableString(context.getString(R.string.about_copyright));
|
||||
}
|
||||
|
||||
// Get screen metrics
|
||||
final DisplayMetrics metrics = new DisplayMetrics();
|
||||
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
|
||||
|
||||
// Set some padding
|
||||
final int pad = (int) ((10 / metrics.density) + 0.5f);
|
||||
message.setPadding(pad, pad, pad, pad * 2);
|
||||
|
||||
// Set up the final string
|
||||
message.setText(versionString + "\n\n" + s);
|
||||
|
||||
// Now linkify the text
|
||||
Linkify.addLinks(message, Linkify.ALL);
|
||||
|
||||
return new AlertDialog.Builder(context).setTitle(aboutTitle).setCancelable(true).setIcon(R.drawable.icon)
|
||||
.setPositiveButton(context.getString(android.R.string.ok), null).setView(message).create();
|
||||
}
|
||||
|
||||
}
|
302
src/net/thauvin/erik/android/emprunt/EmpruntActivity.java
Normal file
|
@ -0,0 +1,302 @@
|
|||
/*
|
||||
* @(#)EmpruntActivity.java
|
||||
*
|
||||
* Copyright (c) 2011-2012 Erik C. Thauvin (http://erik.thauvin.net/)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the authors nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
package net.thauvin.erik.android.emprunt;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* The <code>EmpruntActivity</code> class implements a simple loan payment calculator.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @version $Revision$
|
||||
* @created October 14, 2011
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EmpruntActivity extends Activity
|
||||
{
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.main);
|
||||
|
||||
final TextView titleBar = (TextView) findViewById(R.id.titleBar);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
{
|
||||
titleBar.setLayoutParams(new LinearLayout.LayoutParams(0, 0, 0));
|
||||
titleBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
final TextView paymentFld = (TextView) findViewById(R.id.payment);
|
||||
final TextView costFld = (TextView) findViewById(R.id.cost);
|
||||
|
||||
final EditText amountFld = ((EditText) findViewById(R.id.amount));
|
||||
final EditText interestFld = ((EditText) findViewById(R.id.interest));
|
||||
final EditText monthsFld = ((EditText) findViewById(R.id.months));
|
||||
|
||||
final Drawable imgX = getResources().getDrawable(android.R.drawable.presence_offline);
|
||||
|
||||
final TextWatcher tw = new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
amountFld.setTextColor(Color.BLACK);
|
||||
interestFld.setTextColor(Color.BLACK);
|
||||
monthsFld.setTextColor(Color.BLACK);
|
||||
|
||||
paymentFld.setText(R.string.hint_calculate);
|
||||
paymentFld.setTextColor(Color.LTGRAY);
|
||||
|
||||
costFld.setText(R.string.hint_calculate);
|
||||
costFld.setTextColor(Color.LTGRAY);
|
||||
|
||||
manageClearButton(amountFld, imgX);
|
||||
manageClearButton(interestFld, imgX);
|
||||
manageClearButton(monthsFld, imgX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
};
|
||||
|
||||
amountFld.addTextChangedListener(tw);
|
||||
interestFld.addTextChangedListener(tw);
|
||||
monthsFld.addTextChangedListener(tw);
|
||||
|
||||
amountFld.setOnTouchListener(buildOnTouchListener(amountFld, imgX));
|
||||
interestFld.setOnTouchListener(buildOnTouchListener(interestFld, imgX));
|
||||
monthsFld.setOnTouchListener(buildOnTouchListener(monthsFld, imgX));
|
||||
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
final Button button = (Button) findViewById(R.id.calculate);
|
||||
button.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
// Hide the soft keyboard
|
||||
imm.hideSoftInputFromWindow(button.getApplicationWindowToken(), 0);
|
||||
|
||||
final String amount = amountFld.getText().toString();
|
||||
final String interest = interestFld.getText().toString();
|
||||
final String months = monthsFld.getText().toString();
|
||||
|
||||
if (amount.isEmpty())
|
||||
{
|
||||
amountFld.requestFocus();
|
||||
}
|
||||
else if (interest.isEmpty())
|
||||
{
|
||||
interestFld.requestFocus();
|
||||
}
|
||||
else if (months.isEmpty())
|
||||
{
|
||||
monthsFld.requestFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
amountFld.requestFocus();
|
||||
|
||||
final int capital = Integer.valueOf(amount);
|
||||
|
||||
if (capital > 0)
|
||||
{
|
||||
final double rate = Double.valueOf(interest);
|
||||
|
||||
if (rate > 0)
|
||||
{
|
||||
final int term = Integer.valueOf(months);
|
||||
|
||||
if (term > 0)
|
||||
{
|
||||
final double mrate = (rate / 100) / 12;
|
||||
final double payment = (capital * mrate) / (1 - Math.pow((1 + mrate), -term));
|
||||
final double cost = (payment * term) - capital;
|
||||
|
||||
final Editable s = Editable.Factory.getInstance().newEditable(
|
||||
NumberFormat.getCurrencyInstance().format(payment));
|
||||
|
||||
s.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
paymentFld.setTextColor(Color.BLACK);
|
||||
paymentFld.setText(s);
|
||||
|
||||
costFld.setTextColor(Color.BLACK);
|
||||
costFld.setText(NumberFormat.getCurrencyInstance().format(cost));
|
||||
}
|
||||
else
|
||||
{
|
||||
monthsFld.setTextColor(Color.RED);
|
||||
monthsFld.requestFocus();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
interestFld.setTextColor(Color.RED);
|
||||
interestFld.requestFocus();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
amountFld.setTextColor(Color.RED);
|
||||
amountFld.requestFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
menu.add(0, 0, 0, R.string.menu_about).setIcon(android.R.drawable.ic_menu_info_details);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == 0)
|
||||
{
|
||||
AlertDialog builder;
|
||||
try
|
||||
{
|
||||
builder = AboutDialogBuilder.create(this);
|
||||
builder.show();
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages the clear button.
|
||||
*
|
||||
* @param view The text view.
|
||||
* @param img The image.
|
||||
*/
|
||||
private void manageClearButton(TextView view, Drawable img)
|
||||
{
|
||||
if (view.getText().toString().equals(""))
|
||||
{
|
||||
view.setCompoundDrawablesWithIntrinsicBounds(view.getCompoundDrawables()[0], view.getCompoundDrawables()[1], null,
|
||||
view.getCompoundDrawables()[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
view.setCompoundDrawablesWithIntrinsicBounds(view.getCompoundDrawables()[0], view.getCompoundDrawables()[1], img,
|
||||
view.getCompoundDrawables()[3]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds OnTouchListener for clear buttons.
|
||||
*
|
||||
* @param field The EditText field.
|
||||
* @return A new OnTouchListener.
|
||||
*/
|
||||
private OnTouchListener buildOnTouchListener(final EditText field, final Drawable img)
|
||||
{
|
||||
return new OnTouchListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event)
|
||||
{
|
||||
// Is there an X showing?
|
||||
if (field.getCompoundDrawables()[2] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only do this for up touches
|
||||
if (event.getAction() != MotionEvent.ACTION_UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is touch one of our clear buttons?
|
||||
if (event.getX() > field.getWidth() - field.getPaddingRight() - img.getIntrinsicWidth())
|
||||
{
|
||||
field.requestFocusFromTouch();
|
||||
field.setText("");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|