dd839264
badetitou
All done
|
1
2
3
4
|
package net.plil.clubinfo.etunicorn.app;
import android.app.PendingIntent;
import android.content.Intent;
|
6790f988
badetitou
Find way to somet...
|
5
|
import android.net.Uri;
|
dd839264
badetitou
All done
|
6
|
import android.nfc.NfcAdapter;
|
d6367fe9
badetitou
Ajout liste
|
7
|
import android.os.Bundle;
|
dd839264
badetitou
All done
|
8
|
import android.support.design.widget.TabLayout;
|
dd839264
badetitou
All done
|
9
10
11
12
|
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
|
d6367fe9
badetitou
Ajout liste
|
13
14
|
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
|
dd839264
badetitou
All done
|
15
16
|
import android.view.Menu;
import android.view.MenuItem;
|
73b70b1e
badetitou
Ajout de Consomation
|
17
|
import android.view.View;
|
dd839264
badetitou
All done
|
18
|
|
dd839264
badetitou
All done
|
19
|
import net.plil.clubinfo.etunicorn.R;
|
73b70b1e
badetitou
Ajout de Consomation
|
20
|
import net.plil.clubinfo.etunicorn.app.consomation.FragmentConsomation;
|
d6367fe9
badetitou
Ajout liste
|
21
|
import net.plil.clubinfo.etunicorn.data.Consomation;
|
dd839264
badetitou
All done
|
22
|
|
dd839264
badetitou
All done
|
23
|
|
d6367fe9
badetitou
Ajout liste
|
24
|
public class MainActivity extends AppCompatActivity implements Crediter.OnFragmentInteractionListener, Debiter.OnFragmentInteractionListener, FragmentConsomation.OnListFragmentInteractionListener{
|
dd839264
badetitou
All done
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
NfcAdapter mAdapter;
PendingIntent mPendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
|
dd839264
badetitou
All done
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
mAdapter = NfcAdapter.getDefaultAdapter(this);
if (mAdapter == null) {
//nfc not support your device.
return;
}
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
|
6790f988
badetitou
Find way to somet...
|
99
100
101
102
|
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
FragmentNFC fNFC = (FragmentNFC) getSupportFragmentManager().getFragments().get(mViewPager.getCurrentItem());
fNFC.processNFC();
}
|
dd839264
badetitou
All done
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
}
@Override
public void onResume(){
super.onResume();
mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
}
@Override
public void onPause(){
super.onPause();
if (mAdapter != null) {
mAdapter.disableForegroundDispatch(this);
}
}
|
6790f988
badetitou
Find way to somet...
|
119
120
|
@Override
public void onFragmentInteraction(Uri uri) {
|
dd839264
badetitou
All done
|
121
|
|
dd839264
badetitou
All done
|
122
123
|
}
|
d6367fe9
badetitou
Ajout liste
|
124
125
126
127
128
|
@Override
public void onListFragmentInteraction(Consomation item) {
}
|
dd839264
badetitou
All done
|
129
130
131
132
133
134
135
136
137
138
139
140
|
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
|
6790f988
badetitou
Find way to somet...
|
141
142
143
144
|
if (position == Action.CREDITER.getValue())
return Crediter.newInstance();
else if (position == Action.DEBITER.getValue())
return Debiter.newInstance();
|
d6367fe9
badetitou
Ajout liste
|
145
146
|
else if (position == Action.CONSOMATION.getValue())
return FragmentConsomation.newInstance();
|
6790f988
badetitou
Find way to somet...
|
147
148
|
else
return null;
|
dd839264
badetitou
All done
|
149
150
151
152
|
}
@Override
public int getCount() {
|
d6367fe9
badetitou
Ajout liste
|
153
|
return 3;
|
dd839264
badetitou
All done
|
154
155
156
157
158
159
160
161
|
}
@Override
public CharSequence getPageTitle(int position) {
if(position == Action.DEBITER.getValue())
return "Debiter";
else if (position == Action.CREDITER.getValue())
return "Crediter";
|
d6367fe9
badetitou
Ajout liste
|
162
163
|
else if (position == Action.CONSOMATION.getValue())
return "Consomation";
|
dd839264
badetitou
All done
|
164
165
166
167
168
|
return null;
}
}
private enum Action {
|
d6367fe9
badetitou
Ajout liste
|
169
|
DEBITER(0), CREDITER(1), CONSOMATION(2);
|
dd839264
badetitou
All done
|
170
171
172
173
174
175
176
177
178
179
180
|
private final int value;
Action(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
}
|