MainActivity.java
5.03 KB
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
package com.huaheng.wms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huaheng.wms.R;
import com.huaheng.wms.fragment.FragmentPresenter;
import com.huaheng.wms.util.Constant;
import com.huaheng.wms.util.WMSUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends FragmentActivity {
@BindView(R.id.title)
TextView title;
@BindView(R.id.menu_view)
ImageView menuView;
@BindView(R.id.menu)
TextView menu;
@BindView(R.id.board_view)
ImageView boardView;
@BindView(R.id.board)
TextView board;
@BindView(R.id.setting_view)
ImageView settingView;
@BindView(R.id.setting)
TextView setting;
@BindView(R.id.content)
LinearLayout content;
@BindView(R.id.menu_layout)
LinearLayout menuLayout;
@BindView(R.id.board_layout)
LinearLayout boardLayout;
@BindView(R.id.setting_layout)
LinearLayout settingLayout;
private FragmentPresenter fragmentPresenter;
private int selectId = -1;
private final int MENU_INDEX = 0;
private final int BOARD_INDEX = 1;
private final int SETTING_INDEX = 2;
private String[] strarr;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
initSelect();
initFragment();
setSelect(MENU_INDEX);
stopWMSService();
startWMSService();
initBroadcast();
}
@OnClick({R.id.menu_layout, R.id.board_layout, R.id.setting_layout})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.menu_layout:
setSelect(MENU_INDEX);
break;
case R.id.board_layout:
setSelect(BOARD_INDEX);
break;
case R.id.setting_layout:
setSelect(SETTING_INDEX);
break;
}
}
private void initFragment() {
FragmentManager manager = this.getSupportFragmentManager();
strarr = getResources().getStringArray(R.array.home_string);
fragmentPresenter = new FragmentPresenter();
fragmentPresenter.setFragmentManager(manager);
fragmentPresenter.setStrarr(strarr);
}
private void setSelect(int position) {
initSelect();
fragmentPresenter.selectPage(selectId, position);
selectId = position;
switch (position) {
case MENU_INDEX:
title.setText(WMSUtils.getData(Constant.CURREN_WAREHOUSE));
menu.setTextColor(getResources().getColor(
R.color.bar_font_blue));
menuView.setImageResource(R.mipmap.bar_icon_menu_pre);
break;
case BOARD_INDEX:
title.setText(R.string.board);
board.setTextColor(getResources().getColor(
R.color.bar_font_blue));
boardView.setImageResource(R.mipmap.bar_icon_board_pre);
break;
case SETTING_INDEX:
title.setText(R.string.setting);
setting.setTextColor(getResources().getColor(
R.color.bar_font_blue));
settingView.setImageResource(R.mipmap.bar_icon_setting_pre);
break;
}
title.setText(WMSUtils.getData(Constant.CURREN_COMPANY_NAME, Constant.DEFAULT_COMPANY_NAME));
}
private void initSelect() {
menuView.setImageResource(R.drawable.selector_tab_main_menu);
menu.setTextColor(getResources().getColor(
R.color.font_gray));
boardView.setImageResource(R.drawable.selector_tab_main_board);
board.setTextColor(getResources().getColor(
R.color.font_gray));
settingView.setImageResource(R.drawable.selector_tab_main_setting);
setting.setTextColor(getResources().getColor(
R.color.font_gray));
}
private void startWMSService() {
Intent intent = new Intent();
intent.setClass(this, WMSService.class);
startService(intent);
}
private void stopWMSService() {
Intent intent = new Intent();
intent.setClass(this, WMSService.class);
stopService(intent);
}
private void initBroadcast() {
IntentFilter intentFilter = new IntentFilter("action.company_name");
this.registerReceiver(receiver, intentFilter);
}
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
title.setText(WMSUtils.getData(Constant.CURREN_COMPANY_NAME, Constant.DEFAULT_COMPANY_NAME));
}
};
}