1
- package com .android .kickstart .activity ;
1
+ package com .android .kickstart .activities ;
2
2
3
3
import android .app .Fragment ;
4
4
import android .app .FragmentManager ;
12
12
import android .view .inputmethod .InputMethodManager ;
13
13
14
14
import com .android .kickstart .R ;
15
- import com .android .kickstart .dialog .MyProgressDialog ;
16
- import com .android .kickstart .utility .PreferenceUtil ;
15
+ import com .android .kickstart .dialogs .CustomProgressDialog ;
16
+ import com .android .kickstart .utils .PreferenceUtil ;
17
+
17
18
18
19
public abstract class BaseActivity extends AppCompatActivity implements View .OnClickListener {
19
20
@@ -24,7 +25,15 @@ public abstract class BaseActivity extends AppCompatActivity implements View.OnC
24
25
* lastClickedTime contains last clicked time of view
25
26
*/
26
27
public static final long MAX_CLICK_INTERVAL = 1000 ;
28
+ /*
29
+ * SharedPreferences
30
+ */
31
+ public PreferenceUtil mPreferenceUtil ;
27
32
protected long lastClickedTime = 0 ;
33
+ /*
34
+ * ProgressDialog
35
+ */
36
+ private CustomProgressDialog progressDialog ;
28
37
29
38
/*
30
39
* abstract method for set view
@@ -37,23 +46,14 @@ public abstract class BaseActivity extends AppCompatActivity implements View.OnC
37
46
*/
38
47
public abstract void initializeComponents ();
39
48
40
- /*
41
- * ProgressDialog
42
- */
43
- private MyProgressDialog progressDialog ;
44
-
45
- /*
46
- * SharedPreferences
47
- */
48
- private PreferenceUtil mPreferenceUtil ;
49
49
50
50
@ Override
51
51
protected void onCreate (Bundle savedInstanceState ) {
52
52
super .onCreate (savedInstanceState );
53
53
setContentView (getActivityView ());
54
54
55
55
// Initialize preference utility
56
- mPreferenceUtil = new PreferenceUtil (getApplicationContext (),getString (R .string .app_name ));
56
+ mPreferenceUtil = new PreferenceUtil (getApplicationContext (), getString (R .string .app_name ));
57
57
58
58
initializeComponents ();
59
59
}
@@ -78,59 +78,60 @@ public void onClick(View view) {
78
78
}
79
79
lastClickedTime = SystemClock .elapsedRealtime ();
80
80
81
+
81
82
}
82
83
83
- /*
84
- * @param intent
84
+ /**
85
+ * @param className Name of the next Activity (NextActivity.class)
85
86
*/
86
- public void navigateActivity ( Intent intent ) {
87
- startActivity (intent );
87
+ public void startActivity ( Class <?> className ) {
88
+ startActivity (new Intent ( getApplicationContext (), className ) );
88
89
}
89
90
90
- /*
91
- * @param intent
92
- * @param enterAnim
93
- * @param exitAnim
91
+ /**
92
+ * @param className Name of the next Activity (NextActivity.class)
93
+ * @param resultCode Activity result code
94
94
*/
95
- public void navigateActivity (Intent intent , int enterAnim , int exitAnim ) {
96
- startActivity (intent );
97
- overridePendingTransition (enterAnim , exitAnim );
95
+ public void startActivity (Class <?> className , int resultCode ) {
96
+ startActivityForResult (new Intent (getApplicationContext (), className ), resultCode );
98
97
}
99
98
100
- /*
101
- * @param intent
102
- * @param resultCode
99
+ /**
100
+ * @param intent Activity Intent
101
+ * @param resultCode Activity result code
103
102
*/
104
- public void navigateActivityForResult (Intent intent , int resultCode ) {
105
- startActivityForResult ( intent , resultCode );
103
+ public void startActivityForResultBack (Intent intent , int resultCode ) {
104
+ setResult ( resultCode , intent );
106
105
}
107
106
108
- /*
109
- * @param intent
110
- * @param resultCode
111
- * @param enterAnim
112
- * @param exitAnim
107
+ /**
108
+ * @param className Name of the next Activity (NextActivity.class)
109
+ * @param enterAnim enter animation
110
+ * @param exitAnim exit animation
113
111
*/
114
- public void navigateActivityForResult ( Intent intent , int resultCode , int enterAnim , int exitAnim ) {
115
- startActivityForResult ( intent , resultCode );
112
+ public void startActivity ( Class <?> className , int enterAnim , int exitAnim ) {
113
+ startActivity ( new Intent ( getApplicationContext (), className ) );
116
114
overridePendingTransition (enterAnim , exitAnim );
117
115
}
118
116
119
- /*
120
- * @param intent
121
- * @param resultCode
117
+ /**
118
+ * @param className Name of the next Activity (NextActivity.class)
119
+ * @param resultCode Activity result code
120
+ * @param enterAnim enter animation
121
+ * @param exitAnim exit animation
122
122
*/
123
- public void navigateActivityForResultBack (Intent intent , int resultCode ) {
124
- setResult (resultCode , intent );
123
+ public void startActivity (Class <?> className , int resultCode , int enterAnim , int exitAnim ) {
124
+ startActivityForResult (new Intent (getApplicationContext (), className ), resultCode );
125
+ overridePendingTransition (enterAnim , exitAnim );
125
126
}
126
127
127
- /*
128
- * @param intent
129
- * @param resultCode
130
- * @param enterAnim
131
- * @param exitAnim
128
+ /**
129
+ * @param intent Activity Intent
130
+ * @param resultCode Activity result code
131
+ * @param enterAnim enter animation
132
+ * @param exitAnim exit animation
132
133
*/
133
- public void navigateActivityForResultBack (Intent intent , int resultCode , int enterAnim , int exitAnim ) {
134
+ public void startActivityForResultBack (Intent intent , int resultCode , int enterAnim , int exitAnim ) {
134
135
setResult (resultCode , intent );
135
136
overridePendingTransition (enterAnim , exitAnim );
136
137
}
@@ -143,16 +144,15 @@ public void navigateActivityForResultBack(Intent intent, int resultCode, int ent
143
144
* @param nextFragment New Fragment to be loaded into fragmentContainerResourceId
144
145
* @param requiredAnimation true if screen transition animation is required
145
146
* @param commitAllowingStateLoss true if commitAllowingStateLoss is needed
146
- * @return true if new Fragment added successfully into container, false otherwise
147
- * @throws IllegalStateException Exception if Fragment transaction is invalid
147
+ * @return true if new Fragment added successfully into container, false otherwise
148
148
*/
149
- public boolean addFragment (final int fragmentContainerResourceId , final Fragment currentFragment , final Fragment nextFragment , final boolean requiredAnimation , final boolean commitAllowingStateLoss ) {
149
+ public boolean addFragment (int fragmentContainerResourceId , Fragment currentFragment , Fragment nextFragment , boolean requiredAnimation , boolean commitAllowingStateLoss ) {
150
150
try {
151
151
if (currentFragment == null || nextFragment == null ) {
152
152
return false ;
153
153
}
154
- final FragmentManager fragmentManager = getFragmentManager ();
155
- final FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction ();
154
+ FragmentManager fragmentManager = getFragmentManager ();
155
+ FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction ();
156
156
157
157
if (requiredAnimation ) {
158
158
fragmentTransaction .setTransition (FragmentTransaction .TRANSIT_NONE );
@@ -161,7 +161,7 @@ public boolean addFragment(final int fragmentContainerResourceId, final Fragment
161
161
fragmentTransaction .add (fragmentContainerResourceId , nextFragment , nextFragment .getClass ().getSimpleName ());
162
162
fragmentTransaction .addToBackStack (nextFragment .getClass ().getSimpleName ());
163
163
164
- final Fragment parentFragment ;
164
+ Fragment parentFragment ;
165
165
if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
166
166
parentFragment = currentFragment .getParentFragment ();
167
167
if (parentFragment == null ) {
@@ -176,7 +176,6 @@ public boolean addFragment(final int fragmentContainerResourceId, final Fragment
176
176
} else {
177
177
fragmentTransaction .commitAllowingStateLoss ();
178
178
}
179
-
180
179
return true ;
181
180
} catch (IllegalStateException e ) {
182
181
e .printStackTrace ();
@@ -193,14 +192,14 @@ public boolean addFragment(final int fragmentContainerResourceId, final Fragment
193
192
* @param nextFragment New Fragment to be loaded into fragmentContainerResourceId
194
193
* @param requiredAnimation true if screen transition animation is required
195
194
* @param commitAllowingStateLoss true if commitAllowingStateLoss is needed
196
- * @return true if new Fragment added successfully into container, false otherwise
195
+ * @return true if new Fragment added successfully into container, false otherwise
197
196
*/
198
- public boolean replaceFragment (final int fragmentContainerResourceId , final FragmentManager fragmentManager , final Fragment nextFragment , final boolean requiredAnimation , final boolean commitAllowingStateLoss ) {
197
+ public boolean replaceFragment (int fragmentContainerResourceId , FragmentManager fragmentManager , Fragment nextFragment , boolean requiredAnimation , boolean commitAllowingStateLoss ) {
199
198
try {
200
199
if (nextFragment == null || fragmentManager == null ) {
201
200
return false ;
202
201
}
203
- final FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction ();
202
+ FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction ();
204
203
if (requiredAnimation ) {
205
204
fragmentTransaction .setTransition (FragmentTransaction .TRANSIT_NONE );
206
205
}
@@ -211,21 +210,27 @@ public boolean replaceFragment(final int fragmentContainerResourceId, final Frag
211
210
} else {
212
211
fragmentTransaction .commitAllowingStateLoss ();
213
212
}
214
-
215
213
return true ;
216
214
} catch (IllegalStateException e ) {
217
215
e .printStackTrace ();
218
216
}
219
217
return false ;
220
218
}
221
219
222
- private void displayDialog (String message ,boolean isCancelable ) {
223
- progressDialog = new MyProgressDialog (this ,message , isCancelable );
220
+ /**
221
+ * @param message ProgressDialog message
222
+ * @param isCancelable true if user need to cancel dialog on touch else false
223
+ */
224
+ private void displayDialog (String message , boolean isCancelable ) {
225
+ progressDialog = new CustomProgressDialog (this , message , isCancelable );
224
226
if (!isFinishing ()) {
225
227
progressDialog .show ();
226
228
}
227
229
}
228
230
231
+ /**
232
+ *
233
+ */
229
234
private void dismissDialog () {
230
235
if (progressDialog != null && progressDialog .isShowing ())
231
236
progressDialog .dismiss ();
@@ -246,4 +251,4 @@ protected void onDestroy() {
246
251
if (progressDialog != null && progressDialog .isShowing ())
247
252
dismissDialog ();
248
253
}
249
- }
254
+ }
0 commit comments