-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigationDrawerSliderActivity.java
932 lines (764 loc) · 28 KB
/
NavigationDrawerSliderActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
/**
*
*/
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
/**
* @author Hemant
*
*/
public class NavigationDrawerSliderActivity extends FragmentActivity implements OnClickListener, INavigationDrawer, TimeCounterCallback, MealBreakCallback, WakeLockListener, IExceptionCaughtHandler {
private static final String TAG = NavigationDrawerSliderActivity.class.getName();
protected NavigationDrawerPresenter mPresenter;
private NavigationDrawerSliderView mSliderView;
private View leftSideListView;
private View rightSideAppScreenView;
private TextView mTitleTextView;
private TextView mSubtitleTextView;
protected ImageView mHeaderImageView;
private TextView mTimeTrackerTextView;
private TimeCounter mealBreakTimeCounter;
private TimeCounter headerTimeCounter;
private View button;
boolean isposr;
boolean issbt;
boolean isDropEnabled = false;
private FunctionMenuAdapter menuAdapter;
private boolean isToggle = true;
private boolean isMenuVisible = false;
protected Typeface txtHeaderTypeface,txtHeaderTypefaceBold,txtHeaderTypefaceRegular;
private RelativeLayout mHeaderRelativeLayout;
protected KeyboardView mKeyboard;
private ImageButton btnSlide;
/**
* True if slidermenu out, false otherwise.
*/
private boolean menuOut = false;
private ArrayList<String> menuItems;
private int mAttachedViewID;
/**
* Horizontal scrollview holding the slidermenu and the acivity's layout.
*/
private NavigationDrawerSliderView scrollView;
/**
* Slidermenu instance.
*/
private View menu;
private ClickListenerForScrolling mSliderClickListener;
/**
* Indicates if Activity detsroyed or not.
*/
private boolean mIsDestroyed;
private PowerManager mPowerManager;
private WakeLock mWakeLock;
/**
* Layout containing home button (icon) and slider menu icon. Set click listener to increase responsiveness.
*/
private LinearLayout mHomeBtnLayout;
private LinearLayout mTimerLayout;
/**
* Item click listener for the slider menu list.
*/
private NavigationDrawerPresenter.ListItemClickListenerForScrolling mClickListener;
protected boolean isScanningDialogActivated = false;
/**
* Indicates whether timers should be destroyed in onPause.
*/
private boolean mNoDetsroyTimerOnPause;
private boolean mContinuousScanReqd = true;
private boolean mIsScannerEnabled = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
loadEnvironment();
loadPresenter();
showBaseScreen();
registerUncaughtExceptionHandler();
mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, “MyWakeLock”);
AppUtility.getAppUtilityInstance().acquireWakeLock(mWakeLock);
}
private void registerUncaughtExceptionHandler() {
ExceptionHandler exceptionHandler = new ExceptionHandler();
exceptionHandler.init(this, Thread.currentThread(), this);
}
public void setStoreVisitIconDisable() {
AppConfig.getAppConfigInstance(this).setStoreVisitIcosDisable();
}
public void setStoreVisitIconEnable() {
AppConfig.getAppConfigInstance(this).setStoreVisitIconEnable();
}
public void setShipmentArrivalsDisable() {
AppConfig.getAppConfigInstance(this).setShipmentArrivalsDisable();
}
public void setShipmentArrivalsEnable() {
AppConfig.getAppConfigInstance(this).setShipmentArrivalsEnable();
}
public void setTimeExpensesDisable() {
AppConfig.getAppConfigInstance(this).setTimeExpensesDisable();
}
public void setTimeExpensesEnable() {
AppConfig.getAppConfigInstance(this).setTimeExpensesEnable();
}
public void setTransmissionLogsDisable() {
AppConfig.getAppConfigInstance(this).setTransmissionLogsDisable();
}
public void setTransmissionLogsEnable() {
AppConfig.getAppConfigInstance(this).setTransmissionLogsEnable();
}
public void setAccountListDisable() {
AppConfig.getAppConfigInstance(this).setAccountListDisable();
}
public void setAccountListEnable() {
AppConfig.getAppConfigInstance(this).setAccountListEnable();
}
public void setHelpOptionDisable() {
AppConfig.getAppConfigInstance(this).setHelpOptionDisable();
}
public void setHelpOptionEnable() {
AppConfig.getAppConfigInstance(this).setHelpOptionEnable();
}
public void setSettingOptionDisable() {
AppConfig.getAppConfigInstance(this).setSettingsOptionDisable();
}
public void setSettingOptionEnable() {
AppConfig.getAppConfigInstance(this).setSettingsOptionEnable();
}
@Override
protected void onPause() {
super.onPause();
mealBreakTimeCounter = TimerUtility.getTimerUtilityInstance().getTimerObjectFromContainer(IAppConstants.TimerManagerConstants.TIMER_UTILITY_MEALBREAK_TIME);
if(mealBreakTimeCounter != null) {
if(mealBreakTimeCounter.isMealBreakRegistered()) {
mealBreakTimeCounter.unregisterMealBreakCounterCallback();
}
}
if(!isNoDetsroyTimerOnPause() && !isScanningDialogActivated){
AppLogs.d("!!Scanner", "flags: " + isNoDetsroyTimerOnPause() + ", " + isScanningDialogActivated);
DataWedgePresenter.getDataWedgePresenterInstance(this).resetTimers(this);
}
}
@Override
protected void onStop() {
//toggleSliderMenu(true);
if(menu != null) {
menuOut = mPresenter.toggleSliderMenu(true, menu, menuOut);
}
super.onStop();
}
@Override
protected void onResume() {
AppUtility.getAppUtilityInstance().checkAndInitializeDatabase(this);
super.onResume();
setListAdapter();
mealBreakTimeCounter = TimerUtility.getTimerUtilityInstance().getTimerObjectFromContainer(IAppConstants.TimerManagerConstants.TIMER_UTILITY_MEALBREAK_TIME);
if(mealBreakTimeCounter != null) {
if(mealBreakTimeCounter.isMealBreakRegistered()) {
mealBreakTimeCounter.unregisterMealBreakCounterCallback();
}
mealBreakTimeCounter.registerMealBreakCounterCallback(this);
headerTimeCounter = TimerUtility.getTimerUtilityInstance().getTimerObjectFromContainer(IAppConstants.TimerManagerConstants.TIMER_UTILITY_HEADER_TIMER_OBJECT);
if (headerTimeCounter == null) {
headerTimeCounter = new TimeCounter(this, IAppConstants.TimerManagerConstants.TIMER_UTILITY_HEADER_TIMER_OBJECT, false);
TimerUtility.getTimerUtilityInstance().addTimerObjectToContainer(IAppConstants.TimerManagerConstants.TIMER_UTILITY_HEADER_TIMER_OBJECT, headerTimeCounter);
}
headerTimeCounter.registerTimeCounterCallback(this);
}
/* if(AppConfig.getAppConfigInstance(this).isAppSyncing()) {
disableSlider();
} else {
enableSlider();
}*/
}
public void startRMServiceTimer() {
mPresenter.startRMServiceTimer();
}
public void startMAAServiceTimer() {
mPresenter.startMAAServiceTimer();
}
private void loadEnvironment() {
if( Build.VERSION.SDK_INT >= 9){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
txtHeaderTypeface = Typeface.createFromAsset(getAssets(),
IAppConstants.CommonConstants.FONT_PATH_PREFIX
+ IAppConstants.ROBOTO_MEDIUM_FONTS);
txtHeaderTypefaceBold = Typeface.createFromAsset(getAssets(),
IAppConstants.CommonConstants.FONT_PATH_PREFIX
+ IAppConstants.ROBOTO_MEDIUM_FONTS);
txtHeaderTypefaceRegular = Typeface.createFromAsset(getAssets(),
IAppConstants.CommonConstants.FONT_PATH_PREFIX
+ IAppConstants.ROBOTO_MEDIUM_FONTS);
if(getActionBar() != null)
getActionBar().hide();
}
private void loadPresenter() {
}
/**
* display base activity UI.
*/
private void showBaseScreen() {
LayoutInflater inflater = LayoutInflater.from(this);
mSliderView = (NavigationDrawerSliderView) inflater.inflate(R.layout.screen_scroll_with_list_menu, null);
setContentView(mSliderView);
leftSideListView = inflater.inflate(R.layout.left_pane_menu_list, null);
setListAdapter();
}
protected void setListAdapter() {
// TODO Auto-generated method stub
ListView listView = (ListView) leftSideListView.findViewById(R.id.list);
listView.setAdapter(new NavigationDrawerListAdapter(this, Typeface.createFromAsset(getAssets(), IAppConstants.CommonConstants.FONT_PATH_PREFIX + IAppConstants.ROBOTO_MEDIUM_FONTS), mPresenter.getScreenIcons()));
mClickListener = mPresenter.getListItemClickListenerInstance(mSliderView, leftSideListView, menuOut);
listView.setOnItemClickListener(mClickListener);
}
/**
* This method makes header menu bar visible to user.
*/
public void displayHeaderMenuBar() {
button = mHeaderRelativeLayout.findViewById(R.id.bt_header_dropdown_menu_icon);
mHeaderRelativeLayout = (RelativeLayout) mHeaderRelativeLayout.findViewById(R.id.ll_header_clickable_menubar);
mHeaderRelativeLayout.setOnClickListener(this);
mPresenter.displayHeaderMenuBar(button);
}
public void setDrawerContentView(int layout_id) {
LayoutInflater inflater = LayoutInflater.from(this);
rightSideAppScreenView = inflater.inflate(layout_id, null);
mAttachedViewID = rightSideAppScreenView.getId();
mHeaderRelativeLayout = (RelativeLayout)rightSideAppScreenView.findViewById(R.id.navigation_header);
mTitleTextView = (TextView)mHeaderRelativeLayout.findViewById(R.id.tv_header_title);
mSubtitleTextView = (TextView)mHeaderRelativeLayout.findViewById(R.id.tv_header_subtitle);
mHeaderImageView = (ImageView)mHeaderRelativeLayout.findViewById(R.id.iv_header_icon);
mTimeTrackerTextView = (TextView) mHeaderRelativeLayout.findViewById(R.id.menu_header_time_tracker);
mTimerLayout = (LinearLayout)mHeaderRelativeLayout.findViewById(R.id.timer_layout);
mSubtitleTextView.setOnClickListener(this);
mTimeTrackerTextView.setOnClickListener(this);
mTimerLayout.setOnClickListener(this);
ViewGroup tabBar = (ViewGroup) rightSideAppScreenView.findViewById(mAttachedViewID);
btnSlide = (ImageButton) tabBar.findViewById(R.id.bt_slider);
btnSlide.setVisibility(View.VISIBLE);
mSliderClickListener = new ClickListenerForScrolling(mSliderView, leftSideListView, menuOut);
btnSlide.setOnClickListener(mSliderClickListener);
mHomeBtnLayout = (LinearLayout)mHeaderRelativeLayout.findViewById(R.id.home_layout);
if(mHomeBtnLayout!= null)
{
mHomeBtnLayout.setOnClickListener(mSliderClickListener);
}
View[] children = new View[] { leftSideListView, rightSideAppScreenView };
int scrollToViewIdx = 1;
mSliderView.initViews(children, scrollToViewIdx, new SizeCallbackForMenu(btnSlide));
setSubTitle(AppConfig.getAppConfigInstance(this).getUserName());
setTitle(getResources().getString(R.string.app_title));
displayHeaderMenuBar();
//If learn mode is active, the titlebar color must be changed.
if (AppConfig.getAppConfigInstance(this).getDeviceSynched())
mPresenter.checkLearnMode(this, rightSideAppScreenView,
mSubtitleTextView);
}
public void disableSlidingBarButton() {
btnSlide.setClickable(false);
mHeaderImageView.setClickable(false);
if(mHomeBtnLayout != null){
mHomeBtnLayout.setClickable(false);
}
}
public boolean getSlidingBarEnable() {
return btnSlide.isClickable();
}
public void enableSlidingBarButton() {
btnSlide.setClickable(true);
if(mHomeBtnLayout != null){
mHomeBtnLayout.setClickable(true);
}
}
/*
* disable the slider button
*/
public void disableSlider()
{
btnSlide.setVisibility(View.GONE);
mHeaderImageView.setClickable(false);
if(mHomeBtnLayout != null){
mHomeBtnLayout.setClickable(false);
}
}
/*
* remove subtitle
*/
public void disableSubtitle() {
mSubtitleTextView.setVisibility(View.GONE);
}
public void enableSubtitle() {
setSubTitle(AppConfig.getAppConfigInstance(this).getUserName());
mSubtitleTextView.setVisibility(View.VISIBLE);
}
public void enableSlider() {
if(mHomeBtnLayout != null){
mHomeBtnLayout.setClickable(true);
}
btnSlide.setVisibility(View.VISIBLE);
}
/**
* set application header icon
* @param drawable header icon
*/
public void setLogo(Drawable drawable) {
mHeaderImageView.setBackground(drawable);
mHeaderImageView.setOnClickListener(mSliderClickListener);//To increase slider menu clickable area, added same clicklistener to logo.
}
/**
* set application subtitle
* @param subTitle
*/
public void setSubTitle(String subTitle) {
mSubtitleTextView.setText(subTitle);
mSubtitleTextView.setTypeface(txtHeaderTypeface);
}
/**
* Set application header title
* @param title
*/
public void setTitle(String title) {
mTitleTextView.setText(title);
mTitleTextView.setTypeface(txtHeaderTypeface);
}
/**
* This method makes the login time visible to user.
*/
public void displayLoginTimer() {
mPresenter.displayLoginTimer(mTimeTrackerTextView);
if(headerTimeCounter == null) {
headerTimeCounter = TimerUtility.getTimerUtilityInstance().getTimerObjectFromContainer(IAppConstants.TimerManagerConstants.TIMER_UTILITY_HEADER_TIMER_OBJECT);
}
headerTimeCounter.registerTimeCounterCallback(this);
}
/**
* This method hides login timer from user.
*/
public void hideLoginTimer() {
mTimeTrackerTextView.setVisibility(View.GONE);
}
public void showMenuListOnHeader() {
button.setVisibility(View.VISIBLE);
isDropEnabled = true;
}
public void showMenuListOnBottom() {
isMenuVisible = true;
}
public void hideMenuListOnHeader() {
button.setVisibility(View.GONE);
}
public void addItemToMenuList(String item) {
mPresenter.addItemToMenuList(item, menuItems);
}
public void addMultipleItemsToMenuList(ArrayList<String> items) {
if (menuItems == null) {
menuItems = new ArrayList<String>();
}
mPresenter.addMultipleItemsToMenuList(items, menuItems);
}
class SizeCallbackForMenu implements SizeCallback {
private int btnWidth;
private View btnSlide;
public SizeCallbackForMenu(View btnSlide) {
super();
this.btnSlide = btnSlide;
}
@Override
public void onGlobalLayout() {
btnWidth = btnSlide.getMeasuredWidth()+40;
// System.out.println("btnWidth=" + btnWidth);
}
@Override
public void getViewSize(int idx, int w, int h, int[] dims) {
dims[0] = w;
dims[1] = h;
final int menuIdx = 0;
if (idx == menuIdx) {
dims[0] = w - btnWidth;
}
}
}
class ClickListenerForScrolling implements OnClickListener {
/**
* Menu must NOT be out/shown to start with.
*/
public ClickListenerForScrolling(NavigationDrawerSliderView scrollView, View menu, boolean menuOut) {
super();
NavigationDrawerSliderActivity.this.scrollView = scrollView;
NavigationDrawerSliderActivity.this.menu = menu;
NavigationDrawerSliderActivity.this.menuOut = menuOut;
}
@Override
public void onClick(View v) {
menuOut = mPresenter.toggleSliderMenu(false, menu, menuOut);
mClickListener.setMenuState(menuOut);
//menuOut = !menuOut;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// if (isMenuVisible) {
// MenuInflater menuInflater = getMenuInflater();
// menuInflater.inflate(R.menu.lookup_options_menu, menu);
// return true;
// }
return super.onCreateOptionsMenu(menu);
}
//scroll the page and open the webview
// private void scrollView(NavigationDrawerSliderView scrollView, View menu) {
// int menuWidth = menu.getMeasuredWidth();
// menu.setVisibility(View.VISIBLE);
//
// if (!menuOut) {
// // Scroll to 0 to reveal menu
// AppLogs.d("===slide==","Scroll to right");
// int left = 0;
// scrollView.smoothScrollTo(left, 0);
// } else {
// // Scroll to menuWidth so menu isn't on screen.
// AppLogs.d("===slide==","Scroll to left");
// int left = menuWidth;
// scrollView.smoothScrollTo(left, 0);
//
// }
// menuOut = false;
// }
@Override
public void updateClockTime(String newtime) {
if ((mTimeTrackerTextView != null)
&& (mTimeTrackerTextView.getVisibility() == View.VISIBLE)) {
TimeCounter currentServiceRunningTime = AppUtility.getAppUtilityInstance().getCurrentRunningServiceTimeCounter();
if(currentServiceRunningTime != null && AppUtility.getAppUtilityInstance().isApplicationStartAfterCrash()) {
long currentSystemTime = currentServiceRunningTime.getCurrentSystemTime();
long currentSystemTimeMins = currentSystemTime/(60*1000);
/*long totalTimeInMins = AppUtility.getAppUtilityInstance().getAccumulatedPauseTime(currentServiceRunningTime.getStartTimeStamp(), AppUtility.getAppUtilityInstance().getCurrentTimeStampWithoutSecs());
currentSystemTimeMins -= totalTimeInMins;*/
Date mCurrentDate = new Date(currentSystemTimeMins*60*1000);
final SimpleDateFormat formatterTime = new SimpleDateFormat(IAppConstants.HOUR_MINS_FORMAT);
formatterTime.setTimeZone(TimeZone.getTimeZone(IAppConstants.UTC_TIMEZONE));
newtime = formatterTime.format(mCurrentDate);
}
mTimeTrackerTextView.setText(newtime);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.timer_layout://Layout made clickable to increase click area.
case R.id.menu_header_time_tracker:
if(AppUtility.getAppUtilityInstance().isConnectionEstablished()) {
AppUtility.getAppUtilityInstance().printTimerLogs();
Intent timerDrawerIntent = new Intent(this, TimeDrawerActivity.class);
timerDrawerIntent.putExtra(IAppConstants.IS_APP_ON_PAUSE_STATE, false);
timerDrawerIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Object setResult = v.getTag(R.id.menu_header_time_tracker);
if(setResult != null && (setResult instanceof Integer)) {
int requestCode = Integer.parseInt(setResult.toString());
if ((requestCode&0xffff0000) == 0) {
timerDrawerIntent.putExtra(IAppConstants.StoreVisitSummary.EXTRA_NOTIFY_REFRESH, requestCode );
startActivityForResult(timerDrawerIntent, requestCode);
} else {
startActivity(timerDrawerIntent);
}
} else {
startActivity(timerDrawerIntent);
}
}else {
AppLogs.d("NavigationDrawerSliderActivity", " connection not established!!");
}
break;
case R.id.tv_header_subtitle: //Set click listener to subtitle to increase clickable area.
case R.id.ll_header_clickable_menubar:
if (button.getVisibility() == View.VISIBLE) {
if (isToggle) {
final ListPopupWindow mPopupMenuWindow = new ListPopupWindow(
this);
mPopupMenuWindow.setAnchorView(v);
mPopupMenuWindow.setHeight(406);
mPopupMenuWindow.setWidth(325);
mPopupMenuWindow.getListView();
mPopupMenuWindow.setBackgroundDrawable(getResources()
.getDrawable(R.drawable.bg_popover_function_nine));
if (menuItems != null) {
menuAdapter = new FunctionMenuAdapter(this, menuItems,
txtHeaderTypeface);
}
mPopupMenuWindow.setAdapter(menuAdapter);
mPopupMenuWindow.setVerticalOffset(15);
mPopupMenuWindow.setHorizontalOffset(-19);
mPopupMenuWindow
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long arg3) {
//TODO: Call through Presenter. Currently, the "this" instance is of HomeScreenActivity, hence making local method call.
/*mPresenter.*/OnClickSelectedItem(menuItems
.get(position).toString());
mPopupMenuWindow.dismiss();
isToggle = !isToggle;
}
});
mPopupMenuWindow.show();
}
isToggle = !isToggle;
}
break;
}
}
/**
* invoke Connection settings screen
*/
@Override
public void showConnectionDetailsScreen() {
}
public void startServiceTimer(String key) {
mPresenter.startServiceTimer(key);
}
public void startGlobalTimer() {
mPresenter.startGlobalTimer();
}
public void startMealBreakTimer() {
mPresenter.startMealBreakTimer();
if(mealBreakTimeCounter == null) {
mealBreakTimeCounter = TimerUtility.getTimerUtilityInstance().getTimerObjectFromContainer(IAppConstants.TimerManagerConstants.TIMER_UTILITY_MEALBREAK_TIME);
}
mealBreakTimeCounter.registerMealBreakCounterCallback(this);
}
/**
* Pause timer for specific service
* @param key specific service name (ex : global, rmservice etc).
*/
public void pauseSystemTimer(String key) {
mPresenter.pauseSystemTimer(key);
}
/**
* resume application time for specific service.
* @param key
*/
public void resumeSystemTimer(String key) {
mPresenter.resumeSystemTimer(key);
}
/**
* Reset system time for specific service
* @param key
*/
public void resetSystemTimer(String key) {
mPresenter.resetSystemTimer(key);
}
/**
* Stops system time for specific service
* @param key
*/
public void stopSystemTimer(String key) {
mPresenter.stopSystemTimer(key);
}
/**
* Stops system time for specific service
* @param key
*/
public void stopMealBreakTimer(String key) {
mPresenter.stopMealBreakTimer(key);
}
@Override
public void onBackPressed() {
if(menuOut){ //If menu out, close.
menuOut = mPresenter.toggleSliderMenu(true, menu, menuOut);
} else if(isKeyBoardVisible()){
hideKeyBoard();
} else {
super.onBackPressed();
}
}
@Override
public void updateMealBreakTime(String newtime) {
// TODO Auto-generated method stub
}
/**
* Decide the next action on selection of any menu item.
*
* @param menuItem
* selected menu item.
*/
public void OnClickSelectedItem(String menuItem) {
if (menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.BACK_ORDERS1)) {
mPresenter.ShowBackorderScreen();
}else if (menuItem.toString().equalsIgnoreCase(
IAppConstants.StoreVisitConstantsStrings.EVERYDAY_CREDIT_TALLY1)) {
mPresenter.ShowEveryDayCreditScreen();
}else if (menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.INSTALLATIONS1)) {
mPresenter.ShowInstallationsScreen();
}else if (menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.POSR_AUDIT1)) {
mPresenter.ShowPOSRAuditScreen();
}else if (menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.SBT_DISCARD1)) {
mPresenter.ShowSBTDiscardScreen();
}else if (menuItem.toString()
.equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.SBT_TRANSFER_IN1)) {
mPresenter.ShowTransferScreen();
}else if (menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.SHIPMENTS1)) {
mPresenter.ShowShipmentScreen();
}else if (menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.STORE_DETAILS1)) {
mPresenter.ShowStoreDetailsScreen();
}else if (menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.POSR_AUDIT_SCAN)) {
mPresenter.ShowPOSRAuditScannerScreen();
} else if(menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.LOOKUP1)){
mPresenter.ShowLookupScreen();
} else if(menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.STORE_SUMMARY)) {
mPresenter.ShowStoreVisitSummaryScreen();
} else if(menuItem.toString().equalsIgnoreCase(IAppConstants.StoreVisitConstantsStrings.SEASON_CREDIT_TALLY1)) {
mPresenter.showSeasonalCreditScreen();
}
}
public void ShowLookupScreen() {
mPresenter.ShowLookupScreen();
}
public void ShowStoreVisitSummaryScreen() {
mPresenter.ShowStoreVisitSummaryScreen();
}
public Typeface getRobotoMedium(){
return txtHeaderTypeface;
}
/**
* Makes custom keyboard visible.
*/
protected void showKeyBoard() {
if(mKeyboard != null){
mKeyboard.setVisibility(View.VISIBLE);
}
}
/**
* Hides the custom keykoard.
*/
protected void hideKeyBoard() {
if(mKeyboard != null){
mKeyboard.setVisibility(View.GONE);
}
}
/**
* Hides system keyboard for the given EditText.
* @param field
*/
protected void hideSystemKeyBoard(EditText field){
mPresenter.hideSystemKeyBoard(field);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(mIsScannerEnabled) {
switch(keyCode)
{
case KeyEvent.KEYCODE_SOFT_LEFT:
// Log.d(TAG, "KeyEvent");
// mPresenter.enableDataWedgeScanner(NavigationDrawerSliderActivity.this);
DataWedgePresenter.getDataWedgePresenterInstance(this).enableDataWedgeScanner(this, isContinuousScanReqd(), this);
return true;
case KeyEvent.KEYCODE_BACK:
AppLogs.d("!!Timerout", "back key pressed");
break;
}
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if(mIsScannerEnabled) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
DataWedgePresenter.getDataWedgePresenterInstance(this).resetTimers(this);
break;
default:
break;
}
}
return super.onKeyUp(keyCode, event);
}
/**
* Returns if keyboard visible or not.
* @return false if keyboard instance null.
*/
protected boolean isKeyBoardVisible(){
if(mKeyboard != null){
if(mKeyboard.getVisibility() == View.VISIBLE){
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Returns current keyboard instance.
* @return keyboard instance. null if not set from the respective subclass Activities.
*/
public KeyboardView getKeyBoard(){
return mKeyboard;
}
/**
* If menu showing or not.
* @return true if showing, false if hidden.
*/
protected boolean isMenuShowing() {
return menuOut;
}
/**
* Returns true f Activity destroyed.
* @return
*/
protected boolean isDestoyed() {
return mIsDestroyed;
}
@Override
protected void onDestroy() {
super.onDestroy();
mIsDestroyed = true;
DataWedgePresenter.getDataWedgePresenterInstance(this).resetTimers(this);
}
public boolean isNoDetsroyTimerOnPause() {
return mNoDetsroyTimerOnPause;
}
public void setNoDetsroyTimerOnPause(boolean mNoDetsroyTimerOnPause) {
this.mNoDetsroyTimerOnPause = mNoDetsroyTimerOnPause;
}
protected boolean isContinuousScanReqd() {
return mContinuousScanReqd;
}
protected void setContinuousScanReqd(boolean mContinuousScanReqd) {
this.mContinuousScanReqd = mContinuousScanReqd;
}
public void releaseWakeLock() {
final Window window = getWindow();
if(window != null){
runOnUiThread(new Runnable() {
@Override
public void run() {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
AppLogs.d("!!Scanner", "Released wakelock");
}
});
}
}
public void setWakeLock(){
Window window = getWindow();
if(window != null){
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
AppLogs.d("!!Scanner", "wakelock set");
}
}
/**
* Enable/disable scanning in activity.
* @param enable true if scanner should be enabled on soft left press.
*/
public void enabledScanner(boolean enable) {
mIsScannerEnabled = enable;
}
@Override
public void unCaughtException(Context context, final String message) {
AppUtility.getAppUtilityInstance().showCrashDialog(context, message, (MyApp)getApplication());
}
}