Commit 54bcae80 authored by Thiago M's avatar Thiago M

Initial commit

parents
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/AnalyticalBalanceDroid.iml" filepath="$PROJECT_DIR$/AnalyticalBalanceDroid.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
//noinspection GroovyMissingReturnStatement
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "tmendes.com.analyticalbalancedroid"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
testCompile 'junit:junit:4.12'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/mmosanai/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="tmendes.com.analyticalbalancedroid">
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package tmendes.com.analyticalbalancedroid;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private ArrayList<Product> prodList;
private EditText prodKgPrice;
private EditText prodName;
private EditText prodWeight;
private TextView prodIndValue;
private TextView totalValue;
private TextWatcher kgTw;
private TextWatcher wgTw;
private LinearLayout llProdList;
private ScrollView scrollView;
private Float price;
private Float weight;
private String name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prodList = new ArrayList<>();
price = Float.valueOf(0);
weight = Float.valueOf(0);
prodKgPrice = (EditText) findViewById(R.id.editTextKgPrice);
prodName = (EditText) findViewById(R.id.editTextProdName);
prodWeight = (EditText) findViewById(R.id.editTextWeight);
prodIndValue = (TextView) findViewById(R.id.textIndValueData);
totalValue = (TextView) findViewById(R.id.textTotalValueData);
llProdList = (LinearLayout) findViewById(R.id.llProdList);
scrollView = (ScrollView) findViewById(R.id.scroll);
kgTw = new TextWatcher() {
public void afterTextChanged(Editable s){
prodKgPrice.setSelection(s.length());
}
public void beforeTextChanged(CharSequence s,int start,int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateValues();
prodKgPrice.removeTextChangedListener(kgTw);
prodIndValue.setText(String.valueOf(doTheMath()));
prodKgPrice.addTextChangedListener(kgTw);
}
};
prodKgPrice.addTextChangedListener(kgTw);
wgTw = new TextWatcher() {
public void afterTextChanged(Editable s){
prodWeight.setSelection(s.length());
}
public void beforeTextChanged(CharSequence s,int start,int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateValues();
prodWeight.removeTextChangedListener(wgTw);
prodIndValue.setText(String.valueOf(doTheMath()));
prodWeight.addTextChangedListener(wgTw);
}
};
prodWeight.addTextChangedListener(wgTw);
}
private void updateProductView() {
if(llProdList.getChildCount() > 0) {
llProdList.removeAllViews();
}
int i = 1;
for (Product prod : prodList) {
TextView valueTV = new TextView(this);
StringBuilder sb = new StringBuilder();
sb.append("#");
sb.append(i);
sb.append(" - ");
sb.append(prod.toString());
valueTV.setPadding(5, 3, 0, 3);
valueTV.setText(sb.toString());
if ( i % 2 == 0) {
valueTV.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorTextOne));
} else {
valueTV.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorTextTwo));
}
llProdList.addView(valueTV);
scrollView.fullScroll(View.FOCUS_DOWN);
++i;
}
}
public void addNewProduct(View v) {
int prodCounter = prodList.size() + 1;
Float total;
if (prodName.getText() != null) {
if (prodName.length() > 0) {
name = prodName.getText().toString();
} else {
name = "#" + prodCounter;
}
}
float valueToAdd = doTheMath();
if ((price > 0) && (weight > 0)) {
Product newProd = new Product(getApplicationContext(), name, weight, price);
prodList.add(newProd);
total = Float.valueOf(totalValue.getText().toString()) + valueToAdd;
totalValue.setText(String.valueOf(total));
updateProductView();
}
}
public void remLastProd(View v) {
int lastProdPos = prodList.size() - 1;
if (lastProdPos >= 0) {
Product removedProd = prodList.remove(lastProdPos);
float total = Float.valueOf(totalValue.getText().toString()) - removedProd.getInd_price();
totalValue.setText(String.valueOf(total));
updateProductView();
}
}
public void cleanList(View v) {
prodList.clear();
totalValue.setText(getResources().getString(R.string.number));
if(llProdList.getChildCount() > 0) {
llProdList.removeAllViews();
}
}
private void updateValues() {
if (prodKgPrice.getText() != null) {
if (prodKgPrice.length() > 0 ) {
price = Float.valueOf(prodKgPrice.getText().toString());
}
}
if (prodWeight.getText() != null) {
if (prodWeight.length() > 0 ) {
weight = Float.valueOf(prodWeight.getText().toString());
}
}
}
private Float doTheMath() {
Float res = Float.valueOf(0);
if ((price > 0) && (weight > 0)) {
res = price * weight;
}
res = Float.valueOf(Math.round(res));
return res;
}
}
package tmendes.com.analyticalbalancedroid;
import android.content.Context;
public class Product {
private String name = "";
private float weight;
private float kg_price;
private float ind_price;
private final Context ctx;
public Product(Context ctx, String name, float weight, float kg_price) {
this.name = name;
this.weight = weight;
this.kg_price = kg_price;
this.ind_price = Math.round(this.kg_price * this.weight);
this.ctx = ctx;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getInd_price() {
return ind_price;
}
public void setInd_price(float ind_price) {
this.ind_price = ind_price;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public float getKg_price() {
return kg_price;
}
public void setKg_price(float kg_price) {
this.kg_price = kg_price;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(ctx.getResources().getString(R.string.prod_name_list));
sb.append(" ");
sb.append(this.getName());
sb.append(" - ");
sb.append(ctx.getResources().getString(R.string.prod_price_kg_list));
sb.append(" ");
sb.append(this.getKg_price());
sb.append(" - ");
sb.append(ctx.getResources().getString(R.string.prod_weight_list));
sb.append(" ");
sb.append(this.getWeight());
sb.append(" - ");
sb.append(ctx.getResources().getString(R.string.prod_to_pay_list));
sb.append(" ");
sb.append(this.getInd_price());
return sb.toString();
}
}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="0.5dp"
android:color="@android:color/holo_green_dark" />
</shape>
</item>
</layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="tmendes.com.analyticalbalancedroid.MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dataLayout"
android:layout_alignParentEnd="true"
android:padding="5dp"
android:background="@android:color/holo_orange_light">
<TextView
android:text="@string/price_kg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textTitleKgPrice"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:padding="5dp"
android:textSize="16sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/number"
android:inputType="numberSigned|numberDecimal"
android:digits="0123456789.,"
android:ems="10"
android:id="@+id/editTextKgPrice"
android:background="@drawable/et_botton_line"
android:textAlignment="center"
android:padding="5dp" />
<TextView
android:text="@string/weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textTitleWeight"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="16sp"
android:padding="5dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned|numberDecimal"
android:hint="@string/number"
android:digits="0123456789.,"
android:background="@drawable/et_botton_line"
android:ems="10"
android:id="@+id/editTextWeight"
android:textAlignment="center"
android:padding="5dp" />
<TextView
android:text="@string/prod_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textTitleProdName"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="16sp"
android:padding="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:background="@drawable/et_botton_line"
android:ems="10"
android:id="@+id/editTextProdName"
android:textAlignment="center"
android:padding="5dp"
android:hint="@string/prod_name_optional" />
</LinearLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/dataLayout"
android:id="@+id/tableValues"
android:layout_centerHorizontal="true"
android:background="@color/colorAccent"
android:stretchColumns="*"
android:padding="5dp">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="24dp"
android:padding="5dp">
<TextView
android:text="@string/ind_value"
android:textAlignment="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textIndValueTitle"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="16sp"
android:padding="5dp"
android:textStyle="normal|bold" />
<TextView
android:text="@string/tot_value"
android:textAlignment="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textTotalValueTitle"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="16sp"
android:padding="5dp"
android:textStyle="normal|bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="24dp"
android:padding="5dp">
<TextView
android:text="@string/number"
android:layout_width="wrap_content"
android:textAlignment="center"
android:layout_height="wrap_content"
android:id="@+id/textIndValueData"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textStyle="normal|bold"
android:textSize="16sp"
android:padding="5dp"/>
<TextView
android:text="@string/number"
android:layout_width="wrap_content"
android:textAlignment="center"
android:layout_height="wrap_content"
android:id="@+id/textTotalValueData"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textStyle="normal|bold"
android:textSize="16sp"
android:padding="5dp"/>
</TableRow>
</TableLayout>
<TextView
android:text="@string/list_action_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tableValues"
android:layout_alignParentStart="true"
android:id="@+id/txActionValue"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="16sp"
android:textStyle="normal|bold"
android:textAlignment="center"
android:padding="5dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/actions"
android:layout_below="@+id/txActionValue"
android:layout_alignParentStart="true">
<Button
android:text="@string/bt_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonAdd"
android:onClick="addNewProduct"
android:textAlignment="center" />
<Button
android:text="@string/bt_rem_last"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonRemSpecific"
android:onClick="remLastProd"
android:textAlignment="center" />
<Button
android:text="@string/bt_clean_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonCleanList"
android:onClick="cleanList"
android:textAlignment="center" />
</LinearLayout>
<TextView
android:text="@string/list_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/actions"
android:layout_alignParentStart="true"
android:id="@+id/txList"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="16sp"
android:textStyle="normal|bold"
android:textAlignment="center"
android:padding="5dp" />
<ScrollView