1
- /**
2
- * $Id: MainActivity.java 196 2017-01-16 16:58:20Z hmueller $
1
+ /*
2
+ * @file MainActivity.java
3
3
*
4
- * Main activity of JobLog
5
- * based on Google EffectiveNavigation example
4
+ * Main activity of JobLogTimer
6
5
*
7
6
* Licensed under the Apache License, Version 2.0 (the "License")
8
7
* http://www.apache.org/licenses/LICENSE-2.0
9
8
*/
10
9
package de .euhm .jlt ;
11
10
12
- import java .io .File ;
13
- import java .util .Calendar ;
14
- import java .util .Locale ;
15
-
16
11
import android .Manifest ;
17
12
import android .annotation .TargetApi ;
18
13
import android .app .AlertDialog ;
26
21
import android .os .Bundle ;
27
22
import android .os .Environment ;
28
23
import android .preference .PreferenceManager ;
24
+ import android .support .annotation .NonNull ;
29
25
import android .support .design .widget .FloatingActionButton ;
30
26
import android .support .design .widget .NavigationView ;
31
27
import android .support .design .widget .TabLayout ;
39
35
import android .support .v4 .view .GravityCompat ;
40
36
import android .support .v4 .view .ViewPager ;
41
37
import android .support .v4 .widget .DrawerLayout ;
42
- import android .support .v7 .app .ActionBar ;
43
38
import android .support .v7 .app .ActionBarDrawerToggle ;
44
39
import android .support .v7 .app .AppCompatActivity ;
45
40
import android .support .v7 .widget .Toolbar ;
52
47
import android .widget .ImageView ;
53
48
import android .widget .TextView ;
54
49
import android .widget .Toast ;
50
+
51
+ import java .io .File ;
52
+ import java .util .Calendar ;
53
+ import java .util .Locale ;
54
+
55
55
import de .euhm .jlt .dao .Times ;
56
56
import de .euhm .jlt .dao .TimesWork ;
57
57
import de .euhm .jlt .database .JobLogContract ;
@@ -119,32 +119,23 @@ public class MainActivity extends AppCompatActivity implements
119
119
* Register in onCreate() and unregister in onDestroy()!
120
120
*/
121
121
private final BroadcastReceiver receiverRecreate = new BroadcastReceiver () {
122
- @ Override
123
- public void onReceive (Context context , Intent intent ) {
122
+ @ Override
123
+ public void onReceive (Context context , Intent intent ) {
124
124
Log .v (LOG_TAG , "Received BroadcastReceiver " + Constants .RECEIVER_RECREATE );
125
- if (Build .VERSION .SDK_INT >= 11 ) {
126
- recreate ();
127
- } else {
128
- Intent mainIntent = getIntent ();
129
- mainIntent .addFlags (Intent .FLAG_ACTIVITY_NO_ANIMATION );
130
- finish ();
131
- overridePendingTransition (0 , 0 );
132
- startActivity (mainIntent );
133
- overridePendingTransition (0 , 0 );
134
- }
135
- }
125
+ recreate ();
126
+ }
136
127
};
137
128
138
129
/**
139
130
* A {@link BroadcastReceiver} to update the view in this activity.<br>
140
131
* Register in onCreate() and unregister in onDestroy()!
141
132
*/
142
133
private final BroadcastReceiver receiverUpdateView = new BroadcastReceiver () {
143
- @ Override
144
- public void onReceive (Context context , Intent intent ) {
134
+ @ Override
135
+ public void onReceive (Context context , Intent intent ) {
145
136
Log .v (LOG_TAG , "Received BroadcastReceiver " + Constants .RECEIVER_UPDATE_VIEW );
146
- supportInvalidateOptionsMenu ();
147
- }
137
+ supportInvalidateOptionsMenu ();
138
+ }
148
139
};
149
140
150
141
@@ -183,7 +174,7 @@ public void onCreate(Bundle savedInstanceState) {
183
174
//mTW.timeEnd(-1); // only for debugging, resetting End time
184
175
185
176
// Setup FloatingActionButton from android.support.design.widget.FloatingActionButton for API < 21.
186
- mFab = ( FloatingActionButton ) findViewById (R .id .fab );
177
+ mFab = findViewById (R .id .fab );
187
178
// handle the FloatingActionButton click event
188
179
mFab .setOnClickListener (new View .OnClickListener () {
189
180
@ Override
@@ -204,25 +195,24 @@ public void onClick(View v) {
204
195
});
205
196
206
197
// Setup the action bar from android.support.v7.app.ActionBar for API < 21.
207
- Toolbar supportToolbar = ( Toolbar ) findViewById (R .id .toolbar );
198
+ Toolbar supportToolbar = findViewById (R .id .toolbar );
208
199
setSupportActionBar (supportToolbar );
209
- final ActionBar actionBar = getSupportActionBar ();
210
200
211
201
// Specify that the Home/Up button should not be enabled, since there is no hierarchical parent.
212
- actionBar .setHomeButtonEnabled (false );
202
+ getSupportActionBar () .setHomeButtonEnabled (false );
213
203
214
204
// Setup the ViewPager.
215
- mViewPager = ( CustomViewPager ) findViewById (R .id .pager );
205
+ mViewPager = findViewById (R .id .pager );
216
206
// Create the adapter that will return a fragment for each of the primary sections of the app.
217
207
mAppSectionsPagerAdapter = new AppSectionsPagerAdapter (getSupportFragmentManager (), context );
218
208
mViewPager .setAdapter (mAppSectionsPagerAdapter );
219
209
220
210
// Setup the TabLayout and connect it to the ViewPager.
221
- TabLayout tabLayout = ( TabLayout ) findViewById (R .id .tabLayout );
222
- // setupWithViewPager() does not work very well, so we do all the things ourself (see below)
211
+ TabLayout tabLayout = findViewById (R .id .tabLayout );
212
+ // setupWithViewPager() does not work very well, so we do all the things oneself (see below)
223
213
//tabLayout.setupWithViewPager(mViewPager);
224
214
mViewPager .addOnPageChangeListener (new TabLayout .TabLayoutOnPageChangeListener (tabLayout ));
225
- tabLayout .setOnTabSelectedListener (new TabLayout .OnTabSelectedListener () {
215
+ tabLayout .addOnTabSelectedListener (new TabLayout .OnTabSelectedListener () {
226
216
@ Override
227
217
public void onTabSelected (TabLayout .Tab tab ) {
228
218
// When the given tab is selected, switch to the corresponding page in the ViewPager.
@@ -266,8 +256,8 @@ public void onTabReselected(TabLayout.Tab tab) {
266
256
Tab tab = tabLayout .newTab ();
267
257
tab .setCustomView (R .layout .custom_tab_title );
268
258
View tab_view = tab .getCustomView ();
269
- TextView tab_title = ( TextView ) tab_view .findViewById (R .id .title );
270
- ImageView img = ( ImageView ) tab_view .findViewById (R .id .icon );
259
+ TextView tab_title = tab_view .findViewById (R .id .title );
260
+ ImageView img = tab_view .findViewById (R .id .icon );
271
261
tab_title .setText (mAppSectionsPagerAdapter .getPageTitle (i ));
272
262
int icon = mAppSectionsPagerAdapter .getPageIcon (i );
273
263
if (icon != 0 )
@@ -277,7 +267,7 @@ public void onTabReselected(TabLayout.Tab tab) {
277
267
278
268
279
269
// setup the navigation drawer view from android.support.v4.widget.DrawerLayout for API < 21.
280
- mDrawerLayout = ( DrawerLayout ) findViewById (R .id .drawerlayout );
270
+ mDrawerLayout = findViewById (R .id .drawerlayout );
281
271
// Necessary for automatically animated navigation drawer upon open and close.
282
272
// The two strings are not displayed to the user.
283
273
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (this , mDrawerLayout ,
@@ -290,7 +280,7 @@ public void onDrawerStateChanged(int newState) {
290
280
mDrawerLayout .addDrawerListener (toggle );
291
281
toggle .syncState ();
292
282
293
- NavigationView navigationView = ( NavigationView ) findViewById (R .id .navigation_drawer );
283
+ NavigationView navigationView = findViewById (R .id .navigation_drawer );
294
284
navigationView .setNavigationItemSelectedListener (this );
295
285
}
296
286
@@ -446,7 +436,7 @@ public boolean onKeyUp(int keycode, KeyEvent event) {
446
436
447
437
@ TargetApi (Build .VERSION_CODES .JELLY_BEAN )
448
438
@ Override
449
- public boolean onNavigationItemSelected (MenuItem item ) {
439
+ public boolean onNavigationItemSelected (@ NonNull MenuItem item ) {
450
440
// Close drawer on item click
451
441
mDrawerLayout .closeDrawers ();
452
442
@@ -568,7 +558,6 @@ public void onBackPressed() {
568
558
@ Override
569
559
public boolean dispatchTouchEvent (MotionEvent event ) {
570
560
boolean result = false ;
571
- boolean retVal = false ;
572
561
573
562
// detect pinching
574
563
int pointerCount = event .getPointerCount ();
@@ -598,7 +587,7 @@ public boolean dispatchTouchEvent(MotionEvent event) {
598
587
if (!result ) {
599
588
result = super .dispatchTouchEvent (event );
600
589
}
601
- return retVal || result ;
590
+ return result ;
602
591
}
603
592
604
593
// EditTimes Listener
@@ -775,8 +764,9 @@ public void onFinishDatePickerFragment(Calendar cal, int titleId) {
775
764
}
776
765
777
766
@ Override
778
- public void onRequestPermissionsResult (int requestCode ,
779
- String [] permissions , int [] grantResults ) {
767
+ public void onRequestPermissionsResult (int requestCode ,
768
+ @ NonNull String [] permissions ,
769
+ @ NonNull int [] grantResults ) {
780
770
// Handle the permissions request response.
781
771
switch (requestCode ) {
782
772
case Constants .PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE :
0 commit comments