Commit e6e8e72d4e40472d7e026192ccaca6ed0b3bfd74
1 parent
37bce120
Use a BaseActivity and strings .
Showing
6 changed files
with
87 additions
and
33 deletions
Show diff stats
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/BaseActivity.java
0 → 100644
1 | +package fr.utbm.lo53.p2017.positionningapp; | |
2 | + | |
3 | +import android.content.Intent; | |
4 | +import android.support.v7.app.AppCompatActivity; | |
5 | +import android.view.Menu; | |
6 | +import android.view.MenuItem; | |
7 | + | |
8 | +public class BaseActivity extends AppCompatActivity { | |
9 | + | |
10 | + @Override | |
11 | + public boolean onOptionsItemSelected(MenuItem item) { | |
12 | + // Handle action bar item clicks here. The action bar will | |
13 | + // automatically handle clicks on the Home/Up button, so long | |
14 | + // as you specify a parent activity in AndroidManifest.xml. | |
15 | + int id = item.getItemId(); | |
16 | + | |
17 | + //noinspection SimplifiableIfStatement | |
18 | + if (id == R.id.action_settings) { | |
19 | + Intent intent = new Intent(this, SettingsActivity.class); | |
20 | + startActivity(intent); | |
21 | + return true; | |
22 | + } | |
23 | + if (id == R.id.open_locate_activity) { | |
24 | + Intent intent = new Intent(this, PositioningActivity.class); | |
25 | + startActivity(intent); | |
26 | + return true; | |
27 | + } | |
28 | + if (id == R.id.open_calibration_activity) { | |
29 | + Intent intent = new Intent(this, Calibration.class); | |
30 | + startActivity(intent); | |
31 | + return true; | |
32 | + } | |
33 | + return super.onOptionsItemSelected(item); | |
34 | + } | |
35 | + | |
36 | + @Override | |
37 | + public boolean onCreateOptionsMenu(Menu menu) { | |
38 | + // Inflate the menu; this adds items to the action bar if it is present. | |
39 | + getMenuInflater().inflate(R.menu.menu_calibration, menu); | |
40 | + return true; | |
41 | + } | |
42 | + | |
43 | +} | ... | ... |
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/Calibration.java
... | ... | @@ -12,7 +12,7 @@ import android.view.Menu; |
12 | 12 | import android.view.MenuItem; |
13 | 13 | import android.widget.ImageView; |
14 | 14 | |
15 | -public class Calibration extends AppCompatActivity { | |
15 | +public class Calibration extends BaseActivity { | |
16 | 16 | |
17 | 17 | @Override |
18 | 18 | protected void onCreate(Bundle savedInstanceState) { |
... | ... | @@ -54,30 +54,10 @@ public class Calibration extends AppCompatActivity { |
54 | 54 | |
55 | 55 | @Override |
56 | 56 | public boolean onCreateOptionsMenu(Menu menu) { |
57 | - // Inflate the menu; this adds items to the action bar if it is present. | |
58 | - getMenuInflater().inflate(R.menu.menu_calibration, menu); | |
57 | + super.onCreateOptionsMenu(menu); | |
58 | + MenuItem item = menu.findItem(R.id.open_locate_activity); | |
59 | + item.setVisible(true); | |
59 | 60 | return true; |
60 | 61 | } |
61 | 62 | |
62 | - @Override | |
63 | - public boolean onOptionsItemSelected(MenuItem item) { | |
64 | - // Handle action bar item clicks here. The action bar will | |
65 | - // automatically handle clicks on the Home/Up button, so long | |
66 | - // as you specify a parent activity in AndroidManifest.xml. | |
67 | - int id = item.getItemId(); | |
68 | - | |
69 | - //noinspection SimplifiableIfStatement | |
70 | - if (id == R.id.action_settings) { | |
71 | - Intent intent = new Intent(this, SettingsActivity.class); | |
72 | - startActivity(intent); | |
73 | - return true; | |
74 | - } | |
75 | - if (id == R.id.bt_open_locate_activity) { | |
76 | - Intent intent = new Intent(this, PositioningActivity.class); | |
77 | - startActivity(intent); | |
78 | - return true; | |
79 | - } | |
80 | - | |
81 | - return super.onOptionsItemSelected(item); | |
82 | - } | |
83 | 63 | } | ... | ... |
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/PositioningActivity.java
1 | 1 | package fr.utbm.lo53.p2017.positionningapp; |
2 | 2 | |
3 | +import android.content.Intent; | |
3 | 4 | import android.os.Bundle; |
4 | 5 | import android.support.design.widget.FloatingActionButton; |
5 | 6 | import android.support.design.widget.Snackbar; |
6 | 7 | import android.support.v7.app.AppCompatActivity; |
7 | 8 | import android.support.v7.widget.Toolbar; |
9 | +import android.view.Menu; | |
10 | +import android.view.MenuItem; | |
8 | 11 | import android.view.View; |
9 | 12 | import android.view.animation.AccelerateInterpolator; |
10 | 13 | import android.view.animation.AlphaAnimation; |
... | ... | @@ -12,7 +15,7 @@ import android.view.animation.Animation; |
12 | 15 | import android.widget.Button; |
13 | 16 | import android.widget.ImageView; |
14 | 17 | |
15 | -public class PositioningActivity extends AppCompatActivity { | |
18 | +public class PositioningActivity extends BaseActivity { | |
16 | 19 | |
17 | 20 | private ImageView alphaBackground; |
18 | 21 | private Button buttonStart; |
... | ... | @@ -35,6 +38,14 @@ public class PositioningActivity extends AppCompatActivity { |
35 | 38 | }); |
36 | 39 | } |
37 | 40 | |
41 | + @Override | |
42 | + public boolean onCreateOptionsMenu(Menu menu) { | |
43 | + super.onCreateOptionsMenu(menu); | |
44 | + MenuItem item = menu.findItem(R.id.open_calibration_activity); | |
45 | + item.setVisible(true); | |
46 | + return true; | |
47 | + } | |
48 | + | |
38 | 49 | private void fadeOutAndHideImage() { |
39 | 50 | Animation fadeOut = new AlphaAnimation(1, 0); |
40 | 51 | fadeOut.setInterpolator(new AccelerateInterpolator()); | ... | ... |
app/src/main/res/menu/menu_calibration.xml
... | ... | @@ -7,9 +7,19 @@ |
7 | 7 | android:orderInCategory="100" |
8 | 8 | android:title="@string/action_settings" |
9 | 9 | app:showAsAction="never" /> |
10 | + | |
10 | 11 | <item |
11 | - android:id="@+id/bt_open_locate_activity" | |
12 | + android:id="@+id/open_locate_activity" | |
12 | 13 | android:icon="@drawable/map_marker" |
13 | 14 | android:orderInCategory="101" |
14 | - android:title="Locate !" /> | |
15 | + android:title="@string/menu_title_locate" | |
16 | + android:visible="false" /> | |
17 | + | |
18 | + <item | |
19 | + android:id="@+id/open_calibration_activity" | |
20 | + android:icon="@drawable/map_marker" | |
21 | + android:orderInCategory="101" | |
22 | + android:title="@string/menu_title_calibrate" | |
23 | + android:visible="false" /> | |
24 | + | |
15 | 25 | </menu> | ... | ... |
app/src/main/res/values/strings.xml
... | ... | @@ -3,6 +3,9 @@ |
3 | 3 | <string name="action_settings">Settings</string> |
4 | 4 | <string name="title_activity_settings">Settings</string> |
5 | 5 | |
6 | + <string name="menu_title_locate">Locate</string> | |
7 | + <string name="menu_title_calibrate">Calibrate</string> | |
8 | + | |
6 | 9 | <!-- Strings related to Settings --> |
7 | 10 | |
8 | 11 | <!-- Example General settings --> |
... | ... | @@ -75,4 +78,11 @@ |
75 | 78 | |
76 | 79 | <string name="pref_title_vibrate">Vibrate</string> |
77 | 80 | <string name="title_activity_positioning">Positioning</string> |
81 | + | |
82 | + <!-- Pref settings --> | |
83 | + <string name="pref_title_hostname">Hostname</string> | |
84 | + <string name="pref_default_hostname">127.0.0.1</string> | |
85 | + | |
86 | + <string name="pref_title_port">Port</string> | |
87 | + <string name="default_port">8080</string> | |
78 | 88 | </resources> | ... | ... |
app/src/main/res/xml/pref_general.xml
... | ... | @@ -30,19 +30,19 @@ |
30 | 30 | android:positiveButtonText="@null" |
31 | 31 | android:title="@string/pref_title_add_friends_to_messages" /> |
32 | 32 | <EditTextPreference |
33 | - android:defaultValue="127.0.0.1" | |
34 | - android:key="edit_text_hostname" | |
33 | + android:defaultValue="@string/pref_default_hostname" | |
34 | + android:key="hostname" | |
35 | 35 | android:selectAllOnFocus="true" |
36 | 36 | android:singleLine="true" |
37 | - android:title="Hostname" /> | |
37 | + android:title="@string/pref_title_hostname" /> | |
38 | 38 | <EditTextPreference |
39 | 39 | android:layout_width="wrap_content" |
40 | 40 | android:layout_height="wrap_content" |
41 | - android:defaultValue="8080" | |
42 | - android:key="edit_text_port" | |
41 | + android:defaultValue="@string/default_port" | |
42 | + android:key="port" | |
43 | 43 | android:selectAllOnFocus="true" |
44 | 44 | android:singleLine="true" |
45 | - android:title="Port" /> | |
45 | + android:title="@string/pref_title_port" /> | |
46 | 46 | |
47 | 47 | |
48 | 48 | </PreferenceScreen> | ... | ... |