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

Commit ff49b72

Browse files
author
evgenii
committed
Added AddIncome and AddExpense fragments.
1 parent f42392d commit ff49b72

File tree

4 files changed

+462
-0
lines changed

4 files changed

+462
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.blogspot.e_kanivets.moneytracker.fragment;
2+
3+
import android.app.Activity;
4+
import android.net.Uri;
5+
import android.os.Bundle;
6+
import android.support.v4.app.Fragment;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
11+
import com.blogspot.e_kanivets.moneytracker.R;
12+
13+
/**
14+
* A simple {@link Fragment} subclass.
15+
* Activities that contain this fragment must implement the
16+
* {@link AddExpenseFragment.OnFragmentInteractionListener} interface
17+
* to handle interaction events.
18+
* Use the {@link AddExpenseFragment#newInstance} factory method to
19+
* create an instance of this fragment.
20+
*/
21+
public class AddExpenseFragment extends Fragment {
22+
// TODO: Rename parameter arguments, choose names that match
23+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
24+
private static final String ARG_PARAM1 = "param1";
25+
private static final String ARG_PARAM2 = "param2";
26+
27+
// TODO: Rename and change types of parameters
28+
private String mParam1;
29+
private String mParam2;
30+
31+
private OnFragmentInteractionListener mListener;
32+
33+
/**
34+
* Use this factory method to create a new instance of
35+
* this fragment using the provided parameters.
36+
*
37+
* @param param1 Parameter 1.
38+
* @param param2 Parameter 2.
39+
* @return A new instance of fragment AddExpenseFragment.
40+
*/
41+
// TODO: Rename and change types and number of parameters
42+
public static AddExpenseFragment newInstance(String param1, String param2) {
43+
AddExpenseFragment fragment = new AddExpenseFragment();
44+
Bundle args = new Bundle();
45+
args.putString(ARG_PARAM1, param1);
46+
args.putString(ARG_PARAM2, param2);
47+
fragment.setArguments(args);
48+
return fragment;
49+
}
50+
51+
public AddExpenseFragment() {
52+
// Required empty public constructor
53+
}
54+
55+
@Override
56+
public void onCreate(Bundle savedInstanceState) {
57+
super.onCreate(savedInstanceState);
58+
if (getArguments() != null) {
59+
mParam1 = getArguments().getString(ARG_PARAM1);
60+
mParam2 = getArguments().getString(ARG_PARAM2);
61+
}
62+
}
63+
64+
@Override
65+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
66+
Bundle savedInstanceState) {
67+
// Inflate the layout for this fragment
68+
return inflater.inflate(R.layout.fragment_add_expense, container, false);
69+
}
70+
71+
// TODO: Rename method, update argument and hook method into UI event
72+
public void onButtonPressed(Uri uri) {
73+
if (mListener != null) {
74+
mListener.onFragmentInteraction(uri);
75+
}
76+
}
77+
78+
@Override
79+
public void onAttach(Activity activity) {
80+
super.onAttach(activity);
81+
try {
82+
mListener = (OnFragmentInteractionListener) activity;
83+
} catch (ClassCastException e) {
84+
throw new ClassCastException(activity.toString()
85+
+ " must implement OnFragmentInteractionListener");
86+
}
87+
}
88+
89+
@Override
90+
public void onDetach() {
91+
super.onDetach();
92+
mListener = null;
93+
}
94+
95+
/**
96+
* This interface must be implemented by activities that contain this
97+
* fragment to allow an interaction in this fragment to be communicated
98+
* to the activity and potentially other fragments contained in that
99+
* activity.
100+
* <p/>
101+
* See the Android Training lesson <a href=
102+
* "http://developer.android.com/training/basics/fragments/communicating.html"
103+
* >Communicating with Other Fragments</a> for more information.
104+
*/
105+
public interface OnFragmentInteractionListener {
106+
// TODO: Update argument type and name
107+
public void onFragmentInteraction(Uri uri);
108+
}
109+
110+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.blogspot.e_kanivets.moneytracker.fragment;
2+
3+
import android.app.Activity;
4+
import android.net.Uri;
5+
import android.os.Bundle;
6+
import android.support.v4.app.Fragment;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
11+
import com.blogspot.e_kanivets.moneytracker.R;
12+
13+
/**
14+
* A simple {@link Fragment} subclass.
15+
* Activities that contain this fragment must implement the
16+
* {@link AddIncomeFragment.OnFragmentInteractionListener} interface
17+
* to handle interaction events.
18+
* Use the {@link AddIncomeFragment#newInstance} factory method to
19+
* create an instance of this fragment.
20+
*/
21+
public class AddIncomeFragment extends Fragment {
22+
// TODO: Rename parameter arguments, choose names that match
23+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
24+
private static final String ARG_PARAM1 = "param1";
25+
private static final String ARG_PARAM2 = "param2";
26+
27+
// TODO: Rename and change types of parameters
28+
private String mParam1;
29+
private String mParam2;
30+
31+
private OnFragmentInteractionListener mListener;
32+
33+
/**
34+
* Use this factory method to create a new instance of
35+
* this fragment using the provided parameters.
36+
*
37+
* @param param1 Parameter 1.
38+
* @param param2 Parameter 2.
39+
* @return A new instance of fragment AddIncomeFragment.
40+
*/
41+
// TODO: Rename and change types and number of parameters
42+
public static AddIncomeFragment newInstance(String param1, String param2) {
43+
AddIncomeFragment fragment = new AddIncomeFragment();
44+
Bundle args = new Bundle();
45+
args.putString(ARG_PARAM1, param1);
46+
args.putString(ARG_PARAM2, param2);
47+
fragment.setArguments(args);
48+
return fragment;
49+
}
50+
51+
public AddIncomeFragment() {
52+
// Required empty public constructor
53+
}
54+
55+
@Override
56+
public void onCreate(Bundle savedInstanceState) {
57+
super.onCreate(savedInstanceState);
58+
if (getArguments() != null) {
59+
mParam1 = getArguments().getString(ARG_PARAM1);
60+
mParam2 = getArguments().getString(ARG_PARAM2);
61+
}
62+
}
63+
64+
@Override
65+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
66+
Bundle savedInstanceState) {
67+
// Inflate the layout for this fragment
68+
return inflater.inflate(R.layout.fragment_add_income, container, false);
69+
}
70+
71+
// TODO: Rename method, update argument and hook method into UI event
72+
public void onButtonPressed(Uri uri) {
73+
if (mListener != null) {
74+
mListener.onFragmentInteraction(uri);
75+
}
76+
}
77+
78+
@Override
79+
public void onAttach(Activity activity) {
80+
super.onAttach(activity);
81+
try {
82+
mListener = (OnFragmentInteractionListener) activity;
83+
} catch (ClassCastException e) {
84+
throw new ClassCastException(activity.toString()
85+
+ " must implement OnFragmentInteractionListener");
86+
}
87+
}
88+
89+
@Override
90+
public void onDetach() {
91+
super.onDetach();
92+
mListener = null;
93+
}
94+
95+
/**
96+
* This interface must be implemented by activities that contain this
97+
* fragment to allow an interaction in this fragment to be communicated
98+
* to the activity and potentially other fragments contained in that
99+
* activity.
100+
* <p/>
101+
* See the Android Training lesson <a href=
102+
* "http://developer.android.com/training/basics/fragments/communicating.html"
103+
* >Communicating with Other Fragments</a> for more information.
104+
*/
105+
public interface OnFragmentInteractionListener {
106+
// TODO: Update argument type and name
107+
public void onFragmentInteraction(Uri uri);
108+
}
109+
110+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:layout_gravity="center"
7+
android:background="@color/white"
8+
android:orientation="vertical">
9+
10+
<TextView
11+
android:id="@+id/tv_title"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
android:layout_weight="1"
15+
android:background="@color/blue"
16+
android:gravity="center"
17+
android:text="@string/expense"
18+
android:textAppearance="?android:attr/textAppearanceLarge"
19+
android:textColor="@color/white" />
20+
21+
<LinearLayout
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
android:orientation="vertical">
25+
26+
<LinearLayout
27+
android:layout_width="fill_parent"
28+
android:layout_height="wrap_content"
29+
android:layout_margin="2dp"
30+
android:orientation="horizontal">
31+
32+
<TextView
33+
android:layout_width="match_parent"
34+
android:layout_height="match_parent"
35+
android:layout_weight="3"
36+
android:gravity="center_vertical|left"
37+
android:paddingLeft="10dp"
38+
android:text="@string/title" />
39+
40+
<EditText
41+
android:id="@+id/et_title"
42+
android:layout_width="match_parent"
43+
android:layout_height="match_parent"
44+
android:layout_marginRight="10dp"
45+
android:layout_weight="1" />
46+
</LinearLayout>
47+
48+
<LinearLayout
49+
android:layout_width="match_parent"
50+
android:layout_height="wrap_content"
51+
android:layout_margin="2dp"
52+
android:layout_weight="1"
53+
android:orientation="horizontal">
54+
55+
<TextView
56+
android:layout_width="match_parent"
57+
android:layout_height="match_parent"
58+
android:layout_weight="3"
59+
android:gravity="center_vertical|left"
60+
android:paddingLeft="10dp"
61+
android:text="@string/category" />
62+
63+
<EditText
64+
android:id="@+id/et_category"
65+
android:layout_width="match_parent"
66+
android:layout_height="match_parent"
67+
android:layout_marginRight="10dp"
68+
android:layout_weight="1" />
69+
70+
</LinearLayout>
71+
72+
<LinearLayout
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content"
75+
android:layout_gravity="center_horizontal"
76+
android:layout_margin="2dp"
77+
android:layout_weight="1"
78+
android:orientation="horizontal">
79+
80+
<TextView
81+
android:layout_width="match_parent"
82+
android:layout_height="match_parent"
83+
android:layout_weight="3"
84+
android:gravity="center_vertical|left"
85+
android:paddingLeft="10dp"
86+
android:text="@string/price" />
87+
88+
<EditText
89+
android:id="@+id/et_price"
90+
android:layout_width="match_parent"
91+
android:layout_height="wrap_content"
92+
android:layout_marginRight="10dp"
93+
android:layout_weight="1"
94+
android:inputType="numberSigned" />
95+
96+
</LinearLayout>
97+
</LinearLayout>
98+
99+
<LinearLayout
100+
android:layout_width="match_parent"
101+
android:layout_height="wrap_content"
102+
android:layout_gravity="center_horizontal"
103+
android:layout_margin="10dp"
104+
android:orientation="horizontal">
105+
106+
<Button
107+
android:id="@+id/b_add"
108+
android:layout_width="match_parent"
109+
android:layout_height="match_parent"
110+
android:layout_weight="1"
111+
android:text="@string/add" />
112+
113+
<Button
114+
android:id="@+id/b_cancel"
115+
android:layout_width="match_parent"
116+
android:layout_height="wrap_content"
117+
android:layout_weight="1"
118+
android:text="@string/cancel" />
119+
</LinearLayout>
120+
121+
</LinearLayout>

0 commit comments

Comments
 (0)