Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit dee7bdb

Browse files
author
Evgeniy Kanivets
committed
Added buttons and dialogs
1 parent 6162c8e commit dee7bdb

File tree

10 files changed

+215
-124
lines changed

10 files changed

+215
-124
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.blogspot.e_kanivets.moneytracker" >
44

55
<application
6+
android:name=".MTApp"
67
android:allowBackup="true"
78
android:icon="@drawable/ic_launcher"
89
android:label="@string/app_name"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.blogspot.e_kanivets.moneytracker;
2+
3+
import android.app.Application;
4+
5+
/**
6+
* Created by eugene on 29/08/14.
7+
*/
8+
public class MTApp extends Application{
9+
10+
private static MTApp mtApp;
11+
12+
public static MTApp get() {
13+
return mtApp;
14+
}
15+
16+
@Override
17+
public void onCreate() {
18+
super.onCreate();
19+
20+
mtApp = this;
21+
}
22+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/MainActivity.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
11
package com.blogspot.e_kanivets.moneytracker;
22

3+
import android.app.Activity;
4+
import android.app.AlertDialog;
35
import android.support.v7.app.ActionBarActivity;
46
import android.os.Bundle;
57
import android.view.Menu;
68
import android.view.MenuItem;
9+
import android.view.View;
10+
import android.widget.Button;
711

812

913
public class MainActivity extends ActionBarActivity {
1014

15+
private Activity activity;
16+
17+
private Button btnAddIncome;
18+
private Button btnAddExpense;
19+
1120
@Override
1221
protected void onCreate(Bundle savedInstanceState) {
1322
super.onCreate(savedInstanceState);
1423
setContentView(R.layout.activity_main);
24+
25+
activity = this;
26+
27+
//Link views
28+
btnAddIncome = (Button) findViewById(R.id.b_add_income);
29+
btnAddExpense = (Button) findViewById(R.id.b_add_expense);
30+
31+
//Set listeners
32+
btnAddIncome.setOnClickListener(new View.OnClickListener() {
33+
@Override
34+
public void onClick(View v) {
35+
showAddIncomeDialog();
36+
}
37+
});
38+
39+
btnAddExpense.setOnClickListener(new View.OnClickListener() {
40+
@Override
41+
public void onClick(View v) {
42+
showAddExpenseDialog();
43+
}
44+
});
1545
}
1646

1747

@@ -33,4 +63,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
3363
}
3464
return super.onOptionsItemSelected(item);
3565
}
66+
67+
private void showAddExpenseDialog() {
68+
View layout = getLayoutInflater().inflate(R.layout.dialog_add_record, null);
69+
70+
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
71+
builder.setView(layout);
72+
builder.show();
73+
}
74+
75+
private void showAddIncomeDialog() {
76+
View layout = getLayoutInflater().inflate(R.layout.dialog_add_record, null);
77+
78+
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
79+
builder.setView(layout);
80+
builder.show();
81+
}
3682
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
</selector>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:state_pressed="false" android:drawable="@color/red_light"/>
5+
<item android:state_pressed="true" android:drawable="@color/red_dark"/>
6+
</selector>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:state_pressed="false" android:drawable="@color/green_light"/>
5+
<item android:state_pressed="true" android:drawable="@color/green_dark"/>
6+
</selector>

app/src/main/res/layout/activity_main.xml

Lines changed: 20 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -4,142 +4,38 @@
44
android:layout_height="fill_parent"
55
xmlns:android="http://schemas.android.com/apk/res/android">
66

7-
<LinearLayout
8-
android:layout_weight="1"
9-
android:orientation="vertical"
10-
android:layout_width="match_parent"
11-
android:layout_height="match_parent"
12-
android:layout_gravity="center_horizontal">
13-
14-
<TextView
15-
android:layout_width="match_parent"
16-
android:layout_height="match_parent"
17-
android:textAppearance="?android:attr/textAppearanceLarge"
18-
android:text="@string/expense"
19-
android:layout_weight="1"
20-
android:background="@color/blue"
21-
android:textColor="@color/white"
22-
android:gravity="center"
23-
android:textAllCaps="true"/>
24-
25-
<LinearLayout
26-
android:orientation="horizontal"
27-
android:layout_width="fill_parent"
28-
android:layout_height="wrap_content"
29-
android:layout_margin="10dp">
30-
31-
<TextView
32-
android:layout_width="wrap_content"
33-
android:layout_height="wrap_content"
34-
android:text="@string/category"/>
35-
36-
<EditText
37-
android:layout_width="wrap_content"
38-
android:layout_height="wrap_content"
39-
android:id="@+id/et_expense_category"
40-
android:layout_weight="1"
41-
android:layout_marginLeft="10dp" />
42-
</LinearLayout>
43-
44-
<LinearLayout
45-
android:orientation="horizontal"
46-
android:layout_width="match_parent"
47-
android:layout_height="wrap_content"
48-
android:layout_gravity="center_horizontal"
49-
android:layout_margin="10dp">
50-
51-
<TextView
52-
android:layout_width="wrap_content"
53-
android:layout_height="match_parent"
54-
android:text="@string/amount"
55-
android:gravity="center_vertical" />
567

57-
<EditText
58-
android:layout_width="126dp"
59-
android:layout_height="wrap_content"
60-
android:id="@+id/et_expense_amount"
61-
android:layout_marginLeft="10dp"
62-
android:layout_marginRight="10dp"
63-
android:layout_weight="0.50" />
64-
65-
<Button
66-
android:layout_width="wrap_content"
67-
android:layout_height="match_parent"
68-
android:text="@string/expense"
69-
android:id="@+id/b_add_expense" />
70-
</LinearLayout>
71-
72-
</LinearLayout>
73-
74-
<View
8+
<ListView
759
android:layout_width="match_parent"
76-
android:layout_height="3dp"
77-
android:background="@color/black"></View>
10+
android:layout_height="match_parent"
11+
android:id="@+id/listView"
12+
android:layout_gravity="center_horizontal"
13+
android:layout_weight="1" />
7814

7915
<LinearLayout
80-
android:layout_weight="1"
81-
android:orientation="vertical"
16+
android:orientation="horizontal"
8217
android:layout_width="match_parent"
83-
android:layout_height="match_parent"
18+
android:layout_height="wrap_content"
8419
android:layout_gravity="center_horizontal">
8520

86-
<TextView
21+
<Button
8722
android:layout_width="match_parent"
88-
android:layout_height="match_parent"
89-
android:textAppearance="?android:attr/textAppearanceLarge"
90-
android:text="@string/income"
91-
android:layout_weight="1"
92-
android:background="@color/blue"
93-
android:textColor="@color/white"
94-
android:gravity="center" />
95-
96-
<LinearLayout
97-
android:orientation="horizontal"
98-
android:layout_width="fill_parent"
9923
android:layout_height="wrap_content"
100-
android:layout_margin="10dp">
101-
102-
<TextView
103-
android:layout_width="wrap_content"
104-
android:layout_height="wrap_content"
105-
android:text="@string/category" />
106-
107-
<EditText
108-
android:layout_width="wrap_content"
109-
android:layout_height="wrap_content"
110-
android:id="@+id/et_income_category"
111-
android:layout_weight="1"
112-
android:layout_marginLeft="10dp" />
113-
</LinearLayout>
24+
android:text="@string/add_income"
25+
android:id="@+id/b_add_income"
26+
android:layout_gravity="right"
27+
android:background="@drawable/selector_add_income"
28+
android:layout_weight="1"
29+
android:padding="15dp" />
11430

115-
<LinearLayout
116-
android:orientation="horizontal"
31+
<Button
11732
android:layout_width="match_parent"
11833
android:layout_height="wrap_content"
119-
android:layout_gravity="center_horizontal"
120-
android:layout_margin="10dp"
121-
android:id="@+id/linearLayout">
122-
123-
<TextView
124-
android:layout_width="wrap_content"
125-
android:layout_height="match_parent"
126-
android:text="@string/amount"
127-
android:gravity="center_vertical" />
128-
129-
<EditText
130-
android:layout_width="126dp"
131-
android:layout_height="wrap_content"
132-
android:id="@+id/et_income_amount"
133-
android:layout_marginLeft="10dp"
134-
android:layout_marginRight="10dp"
135-
android:layout_weight="0.50" />
136-
137-
<Button
138-
android:layout_width="wrap_content"
139-
android:layout_height="match_parent"
140-
android:text="@string/income"
141-
android:id="@+id/b_add_income" />
142-
</LinearLayout>
34+
android:text="@string/add_expense"
35+
android:id="@+id/b_add_expense"
36+
android:background="@drawable/selector_add_expense"
37+
android:layout_weight="1"
38+
android:padding="15dp" />
14339
</LinearLayout>
14440

14541
</LinearLayout>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:orientation="vertical" android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<LinearLayout
8+
android:layout_weight="1"
9+
android:orientation="vertical"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
android:layout_gravity="center_horizontal">
13+
14+
<TextView
15+
android:layout_width="match_parent"
16+
android:layout_height="match_parent"
17+
android:textAppearance="?android:attr/textAppearanceLarge"
18+
android:text="@string/expense"
19+
android:layout_weight="1"
20+
android:background="@color/blue"
21+
android:textColor="@color/white"
22+
android:gravity="center"
23+
android:textAllCaps="true"/>
24+
25+
<LinearLayout
26+
android:orientation="horizontal"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content">
29+
30+
<LinearLayout
31+
android:orientation="vertical"
32+
android:layout_width="wrap_content"
33+
android:layout_height="match_parent"
34+
android:layout_margin="10dp">
35+
36+
<TextView
37+
android:layout_width="wrap_content"
38+
android:layout_height="match_parent"
39+
android:text="@string/category"
40+
android:gravity="center"
41+
android:layout_weight="1" />
42+
43+
<TextView
44+
android:layout_width="wrap_content"
45+
android:layout_height="match_parent"
46+
android:text="@string/amount"
47+
android:gravity="center_vertical"
48+
android:layout_weight="1" />
49+
50+
</LinearLayout>
51+
52+
<LinearLayout
53+
android:orientation="vertical"
54+
android:layout_width="match_parent"
55+
android:layout_height="wrap_content"
56+
android:layout_gravity="center_horizontal"
57+
android:layout_margin="10dp">
58+
59+
<EditText
60+
android:layout_width="match_parent"
61+
android:layout_height="match_parent"
62+
android:id="@+id/et_expense_category" />
63+
64+
<EditText
65+
android:layout_width="match_parent"
66+
android:layout_height="wrap_content"
67+
android:id="@+id/et_expense_amount" />
68+
69+
</LinearLayout>
70+
</LinearLayout>
71+
72+
<LinearLayout
73+
android:orientation="horizontal"
74+
android:layout_width="match_parent"
75+
android:layout_height="wrap_content"
76+
android:layout_gravity="center_horizontal"
77+
android:layout_margin="10dp"
78+
android:id="@+id/linearLayout">
79+
80+
<Button
81+
android:layout_width="match_parent"
82+
android:layout_height="match_parent"
83+
android:text="@string/add"
84+
android:id="@+id/b_add"
85+
android:layout_weight="1" />
86+
87+
<Button
88+
android:layout_width="match_parent"
89+
android:layout_height="wrap_content"
90+
android:text="@string/cancel"
91+
android:id="@+id/b_cancel"
92+
android:layout_weight="1" />
93+
</LinearLayout>
94+
95+
</LinearLayout>
96+
97+
</LinearLayout>

app/src/main/res/values/colors.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33
<color name="black">#000000</color>
44
<color name="white">#ffffff</color>
55
<color name="blue">#8dc6d9</color>
6+
7+
<color name="green_light">#99cc00</color>
8+
<color name="green">#7caf00</color>
9+
<color name="green_dark">#669900</color>
10+
11+
<color name="red_light">#ff4444</color>
12+
<color name="red">#e21d1d</color>
13+
<color name="red_dark">#cc0000</color>
614
</resources>

0 commit comments

Comments
 (0)