-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuideUI.java
More file actions
314 lines (273 loc) · 8.09 KB
/
GuideUI.java
File metadata and controls
314 lines (273 loc) · 8.09 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
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
package com.electronic_market.GuideUI;
import java.util.ArrayList;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import com.electronic_market.R;
import com.electronic_market.Acache.ACache;
import com.electronic_market.home.SplashActivity;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
/**
* 功能描述:主程序入口类
*/
public class GuideUI extends Activity implements OnClickListener,OnPageChangeListener {
//定义ViewPager对象
private ViewPager viewPager;
//定义ViewPager适配器
private ViewPagerAdapter vpAdapter;
//定义一个ArrayList来存放View
private ArrayList<View> views;
//引导图片资源
private static final int[] pics = {R.drawable.p1,R.drawable.p5,R.drawable.p3,R.drawable.p4};
//底部小点的图片
private ImageView[] points;
//进入按钮
private ImageButton button_in;
//记录当前选中位置
private int currentIndex;
Timer timer;
TimerTask task;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.guide_ui);
// 使用SharedPreferences来记录是否是首次使用
SharedPreferences sp = getSharedPreferences("logindata", MODE_PRIVATE);
// 取得相应的值,如果isFirstIn为true,说明还未写入,用true作为默认值
Boolean isFirstIn = sp.getBoolean("isFirstIn", true);
// 判断程序与第几次运行,如果是第一次运行则跳转到引导界面,否则跳转到主界面
if (isFirstIn == true || isFirstIn == null) {
//第一次使用
initView();
InitUser();
initData();
timer = new Timer();
task = new TimerTask() {
@Override
public void run() {
// 需要做的事:发送消息
int position;
Toast.makeText(getApplicationContext(), currentIndex, 0).show();
}
};
} else {
finish();
Intent intent = new Intent(getApplicationContext(),SplashActivity.class);
startActivity(intent);
}
}
/**
* 初始化组件
*/
private void initView(){
//实例化ArrayList对象
views = new ArrayList<View>();
//实例化ViewPager
viewPager = (ViewPager) findViewById(R.id.viewpager);
//进入按钮
button_in=(ImageButton)findViewById(R.id.button_in);
button_in.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// 使用SharedPreferences来记录是否是首次使用
SharedPreferences sp = getSharedPreferences("logindata", MODE_PRIVATE);
Editor edit=sp.edit();
edit.putBoolean("isFirstIn", false);
edit.commit();
finish();
Intent intent = new Intent(getApplicationContext(),SplashActivity.class);
startActivity(intent);
}
});
//实例化ViewPager适配器
vpAdapter = new ViewPagerAdapter(views);
}
//初始化用户信息,第一次登录时为空
private void InitUser() {
ACache instanceInfo = ACache.get(this);
//存放最近一次登录的用户信息
instanceInfo.put("uname", "马上登录", 3 * ACache.TIME_DAY);
instanceInfo.put("password", "", 3 * ACache.TIME_DAY);
instanceInfo.put("sex",-1, 3 * ACache.TIME_DAY);
instanceInfo.put("phone", "", 3 * ACache.TIME_DAY);
instanceInfo.put("email", "", 3 * ACache.TIME_DAY);
instanceInfo.put("addr1", "", 3 * ACache.TIME_DAY);
instanceInfo.put("addr2", "", 3 * ACache.TIME_DAY);
instanceInfo.put("time", new Date(), 3 * ACache.TIME_DAY);
instanceInfo.put("photo", "", 3 * ACache.TIME_DAY);
}
/**
* 初始化数据
*/
private void initData(){
//定义一个布局并设置参数
LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT);
//初始化引导图片列表
for(int i=0; i<pics.length; i++) {
ImageView iv = new ImageView(this);
iv.setLayoutParams(mParams);
iv.setImageResource(pics[i]);
views.add(iv);
}
//设置数据
viewPager.setAdapter(vpAdapter);
//设置监听
viewPager.setOnPageChangeListener(this);
//初始化底部小点
initPoint();
}
/**
* 初始化底部小点
*/
private void initPoint(){
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll);
points = new ImageView[pics.length];
//循环取得小点图片
for (int i = 0; i < pics.length; i++) {
//得到一个LinearLayout下面的每一个子元素
points[i] = (ImageView) linearLayout.getChildAt(i);
//默认都设为灰色
points[i].setEnabled(true);
//给每个小点设置监听
points[i].setOnClickListener(this);
//设置位置tag,方便取出与当前位置对应
points[i].setTag(i);
}
//设置当面默认的位置
currentIndex = 0;
//设置为白色,即选中状态
points[currentIndex].setEnabled(false);
}
/**
* 当滑动状态改变时调用
*/
@Override
public void onPageScrollStateChanged(int arg0) {
}
/**
* 当当前页面被滑动时调用
*/
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
/**
* 当新的页面被选中时调用
*/
@Override
public void onPageSelected(int position) {
//设置底部小点选中状态
setCurDot(position);
if(position == 3)
{
button_in.setVisibility(View.VISIBLE);
}
else{
button_in.setVisibility(View.INVISIBLE);
}
// timer.cancel();
//timer=null;
//task=null;
// try {
// Thread.currentThread();
// Thread.sleep(3000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// timer = new Timer();
//task = new TimerTask() {
// @Override
// public void run() {
// 需要做的事:发送消息
// int position;
// if(currentIndex == 3)
// {
// position=0;
// }
// else
// {
// position=currentIndex+1;
// }
//
// setCurView(position);
// setCurDot(position);
// }
//};
//timer.schedule(task, 1000, 1000); // 1s后执行task,经过1s再次执行
}
/**
* 通过点击事件来切换当前的页面
*/
@Override
public void onClick(View v) {
int position = (Integer)v.getTag();
setCurView(position);
setCurDot(position);
//Toast.makeText(getApplicationContext(), position, 0).show();
if(position == 3)
{
// Toast.makeText(this, "ffff", 0).show();
button_in.setVisibility(View.VISIBLE);
}
else{
button_in.setVisibility(View.INVISIBLE);
}
}
/**
* 设置当前页面的位置
*/
private void setCurView(int position){
if (position < 0 || position >= pics.length) {
return;
}
//if(position<0)
// {
// position=position+4;
// }
// else if(position>3)
// {
// position=position-4;
// }
// else {
//
// }
viewPager.setCurrentItem(position);
}
/**
* 设置当前的小点的位置
*/
private void setCurDot(int position){
if (position < 0 || position > pics.length - 1 || currentIndex == position) {
return;
}
//if(position<0)
//{
// position=position+4;
//}
//else if(position>3)
//{
// position=position-4;
//}
//else {
//
//}
points[position].setEnabled(false);
points[currentIndex].setEnabled(true);
currentIndex = position;
}
}