package
com.gaoxiaotong.ctone.jiaoyuzixun;
import
java.util.ArrayList;
import
java.util.HashMap;
import
java.util.Iterator;
import
java.util.List;
import
java.util.Map;
import
org.json.JSONArray;
import
org.json.JSONObject;
import
com.gaoxiaotong.ctone.entity.Jiaoyuzixun_ViewPage_Adapter;
import
com.gaoxiaotong.ctone.entity.jianzhizhaopinAdapter;
import
com.gaoxiaotong.ctone.jianzhizhaopin.JianzhizhaopinActivity;
import
com.gaoxiaotong.info.Webserinfo;
import
com.gaoxiaotongctone.MainActivity;
import
com.gaoxiaotongctone.R;
import
android.app.Activity;
import
android.app.ProgressDialog;
import
android.content.Intent;
import
android.os.AsyncTask;
import
android.os.Bundle;
import
android.os.Parcelable;
import
android.support.v4.view.PagerAdapter;
import
android.support.v4.view.ViewPager;
import
android.support.v4.view.ViewPager.OnPageChangeListener;
import
android.util.Log;
import
android.view.KeyEvent;
import
android.view.View;
import
android.view.ViewGroup.LayoutParams;
import
android.view.animation.AnimationSet;
import
android.view.animation.TranslateAnimation;
import
android.widget.AdapterViewFlipper;
import
android.widget.HorizontalScrollView;
import
android.widget.ImageView;
import
android.widget.LinearLayout;
import
android.widget.ListView;
import
android.widget.ProgressBar;
import
android.widget.RadioButton;
import
android.widget.RadioGroup;
import
android.widget.TextView;
import
android.widget.RadioGroup.OnCheckedChangeListener;
/**
* HorizontalScrollView和ViewPager联动效果 上面为HorizontalScrollView,下面为ViewPager
**/
public
class
JiaoyuzixunActivity
extends
Activity
implements
OnCheckedChangeListener {
private
ProgressDialog dialog;
private
ProgressBar progressBar;
private
HashMap<Integer, Integer> hMap;
private
int
pageIndex;
private
boolean
load_pagesize;
private
int
thePage;
/**
* 设置布局显示属性
*/
private
LayoutParams mLayoutParams =
new
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
/**
* 设置布局显示目标最大化属性
*/
private
LayoutParams FFlayoutParams =
new
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
private
LinearLayout loadingLayout;
private
TextView texview_back;
private
RadioGroup mRadioGroup;
private
RadioButton mRadioButton1;
private
RadioButton mRadioButton2;
private
RadioButton mRadioButton3;
private
RadioButton mRadioButton4;
private
RadioButton mRadioButton5;
private
RadioButton mRadioButton6;
private
ImageView mImageView;
private
float
mCurrentCheckedRadioLeft;
private
HorizontalScrollView mHorizontalScrollView;
private
ViewPager mViewPager;
private
ArrayList<View> mViews;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.title_bar_education);
iniController();
iniListener();
iniVariable();
mRadioButton1.setChecked(
true
);
mViewPager.setCurrentItem(
1
);
mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();
texview_back.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View v) {
Intent intent =
new
Intent(JiaoyuzixunActivity.
this
,
MainActivity.
class
);
startActivity(intent);
JiaoyuzixunActivity.
this
.finish();
}
});
}
/**
* AsyncTask异步加载部分操作
*/
public
class
MyTaskJianzhi1
extends
AsyncTask<String, Void, List<Map<String, Object>>> {
private
ListView lvCont;
private
jianzhizhaopinAdapter adapter;
private
int
index;
public
MyTaskJianzhi1(ListView lvCont, jianzhizhaopinAdapter jzzpAdapter) {
super
();
this
.lvCont = lvCont;
if
(jzzpAdapter ==
null
) {
adapter =
new
jianzhizhaopinAdapter(JiaoyuzixunActivity.
this
);
}
else
{
adapter = jzzpAdapter;
}
}
@Override
protected
void
onPreExecute() {
super
.onPreExecute();
dialog =
new
ProgressDialog(JiaoyuzixunActivity.
this
);
dialog.setTitle(
"提示"
);
dialog.setMessage(
"正在下载,请稍后...."
);
dialog.show();
}
@Override
protected
void
onPostExecute(List<Map<String, Object>> result) {
super
.onPostExecute(result);
String aa =
""
;
try
{
if
(thePage ==
1
) {
adapter.setData(result);
lvCont.setAdapter(adapter);
}
if
(result.size() ==
0
) {
loadingLayout.setVisibility(View.GONE);
}
adapter.notifyDataSetChanged();
}
catch
(Exception e) {
e.getMessage();
e.printStackTrace();
}
dialog.dismiss();
}
@Override
protected
List<Map<String, Object>> doInBackground(String... params) {
List<Map<String, Object>> list =
new
ArrayList<Map<String, Object>>();
try
{
Webserinfo wsWebserinfo =
new
Webserinfo();
JSONArray data =
new
JSONArray();
if
(pageIndex ==
0
) {
data = wsWebserinfo.jobsByType(
""
+ Webserinfo.pageSize,
"2"
,
""
+ thePage);
}
else
if
(pageIndex ==
1
) {
data = wsWebserinfo.jobsByType(
""
+ Webserinfo.pageSize,
"1"
,
""
+ thePage);
}
else
if
(pageIndex ==
2
) {
data = wsWebserinfo.jobsByType(
""
+ Webserinfo.pageSize,
"3"
,
""
+ thePage);
}
if
(data.length() <
10
) {
load_pagesize =
false
;
}
for
(
int
i =
0
; i < data.length(); i++) {
JSONObject jsonObj = data.getJSONObject(i);
HashMap<String, Object> map =
new
HashMap<String, Object>();
Iterator<String> iterator = jsonObj.keys();
while
(iterator.hasNext()) {
String key = iterator.next();
Object value = jsonObj.get(key);
map.put(key, value);
}
if
(thePage >
1
) {
adapter.addItem(map);
}
list.add(map);
}
}
catch
(Exception e) {
}
return
list;
}
}
private
void
iniVariable() {
mViews =
new
ArrayList<View>();
mViews.add(getLayoutInflater().inflate(R.layout.layout_0,
null
));
mViews.add(getLayoutInflater().inflate(R.layout.layout_1,
null
));
mViews.add(getLayoutInflater().inflate(R.layout.layout_2,
null
));
mViews.add(getLayoutInflater().inflate(R.layout.layout_3,
null
));
mViews.add(getLayoutInflater().inflate(R.layout.layout_4,
null
));
mViews.add(getLayoutInflater().inflate(R.layout.layout_5,
null
));
mViews.add(getLayoutInflater().inflate(R.layout.layout_6,
null
));
mViews.add(getLayoutInflater().inflate(R.layout.layout_0,
null
));
mViewPager.setAdapter(
new
Jiaoyuzixun_ViewPage_Adapter(mViews));
}
/**
* RadioGroup点击CheckedChanged监听
*/
@Override
public
void
onCheckedChanged(RadioGroup group,
int
checkedId) {
AnimationSet _AnimationSet =
new
AnimationSet(
true
);
TranslateAnimation _TranslateAnimation;
Log.i(
"zj"
,
"checkedid="
+ checkedId);
if
(checkedId == R.id.btn1) {
_TranslateAnimation =
new
TranslateAnimation(
mCurrentCheckedRadioLeft, getResources().getDimension(
R.dimen.rdo1), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(
false
);
_AnimationSet.setFillAfter(
true
);
_AnimationSet.setDuration(
100
);
mImageView.startAnimation(_AnimationSet);
mViewPager.setCurrentItem(
1
);
}
else
if
(checkedId == R.id.btn2) {
_TranslateAnimation =
new
TranslateAnimation(
mCurrentCheckedRadioLeft, getResources().getDimension(
R.dimen.rdo2), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(
false
);
_AnimationSet.setFillAfter(
true
);
_AnimationSet.setDuration(
100
);
mImageView.startAnimation(_AnimationSet);
mViewPager.setCurrentItem(
2
);
}
else
if
(checkedId == R.id.btn3) {
_TranslateAnimation =
new
TranslateAnimation(
mCurrentCheckedRadioLeft, getResources().getDimension(
R.dimen.rdo3), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(
false
);
_AnimationSet.setFillAfter(
true
);
_AnimationSet.setDuration(
100
);
mImageView.startAnimation(_AnimationSet);
mViewPager.setCurrentItem(
3
);
}
else
if
(checkedId == R.id.btn4) {
_TranslateAnimation =
new
TranslateAnimation(
mCurrentCheckedRadioLeft, getResources().getDimension(
R.dimen.rdo4), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(
false
);
_AnimationSet.setFillAfter(
true
);
_AnimationSet.setDuration(
100
);
mImageView.startAnimation(_AnimationSet);
mViewPager.setCurrentItem(
4
);
}
else
if
(checkedId == R.id.btn5) {
_TranslateAnimation =
new
TranslateAnimation(
mCurrentCheckedRadioLeft, getResources().getDimension(
R.dimen.rdo5), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(
false
);
_AnimationSet.setFillAfter(
true
);
_AnimationSet.setDuration(
100
);
mImageView.startAnimation(_AnimationSet);
mViewPager.setCurrentItem(
5
);
}
else
if
(checkedId == R.id.btn6) {
_TranslateAnimation =
new
TranslateAnimation(
mCurrentCheckedRadioLeft, getResources().getDimension(
R.dimen.rdo6), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(
false
);
_AnimationSet.setFillAfter(
true
);
_AnimationSet.setDuration(
100
);
mImageView.startAnimation(_AnimationSet);
mViewPager.setCurrentItem(
6
);
}
mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();
mHorizontalScrollView.smoothScrollTo((
int
) mCurrentCheckedRadioLeft
- (
int
) getResources().getDimension(R.dimen.rdo2),
0
);
}
/**
* 获得当前被选中的RadioButton距离左侧的距离
*/
private
float
getCurrentCheckedRadioLeft() {
if
(mRadioButton1.isChecked()) {
return
getResources().getDimension(R.dimen.rdo1);
}
else
if
(mRadioButton2.isChecked()) {
return
getResources().getDimension(R.dimen.rdo2);
}
else
if
(mRadioButton3.isChecked()) {
return
getResources().getDimension(R.dimen.rdo3);
}
else
if
(mRadioButton4.isChecked()) {
return
getResources().getDimension(R.dimen.rdo4);
}
else
if
(mRadioButton5.isChecked()) {
return
getResources().getDimension(R.dimen.rdo5);
}
else
if
(mRadioButton6.isChecked()) {
return
getResources().getDimension(R.dimen.rdo6);
}
return
0f;
}
/**
* 监听部分操作
*/
private
void
iniListener() {
mRadioGroup.setOnCheckedChangeListener(
this
);
mViewPager.setOnPageChangeListener(
new
MyPagerOnPageChangeListener());
}
private
void
iniController() {
mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup);
mRadioButton1 = (RadioButton) findViewById(R.id.btn1);
mRadioButton2 = (RadioButton) findViewById(R.id.btn2);
mRadioButton3 = (RadioButton) findViewById(R.id.btn3);
mRadioButton4 = (RadioButton) findViewById(R.id.btn4);
mRadioButton5 = (RadioButton) findViewById(R.id.btn5);
mRadioButton6 = (RadioButton) findViewById(R.id.btn6);
mImageView = (ImageView) findViewById(R.id.img1);
texview_back = (TextView) findViewById(R.id.back_activity_button);
mHorizontalScrollView = (HorizontalScrollView) findViewById(R.id.horizontalScrollView);
mViewPager = (ViewPager) findViewById(R.id.pager);
}
/**
* ViewPager的PageChangeListener(页面改变的监听器)
*/
private
class
MyPagerOnPageChangeListener
implements
OnPageChangeListener {
@Override
public
void
onPageScrollStateChanged(
int
arg0) {
}
@Override
public
void
onPageScrolled(
int
arg0,
float
arg1,
int
arg2) {
}
/**
* 滑动ViewPager的时候,让上方的HorizontalScrollView自动切换
*/
@Override
public
void
onPageSelected(
int
position) {
if
(position ==
0
) {
mViewPager.setCurrentItem(
1
);
}
else
if
(position ==
1
) {
mRadioButton1.performClick();
}
else
if
(position ==
2
) {
mRadioButton2.performClick();
}
else
if
(position ==
3
) {
mRadioButton3.performClick();
}
else
if
(position ==
4
) {
mRadioButton4.performClick();
}
else
if
(position ==
5
) {
mRadioButton5.performClick();
}
else
if
(position ==
6
) {
mRadioButton6.performClick();
}
else
if
(position ==
7
) {
mViewPager.setCurrentItem(
6
);
}
}
}
@Override
public
boolean
onKeyDown(
int
keyCode, KeyEvent event) {
if
(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() ==
0
) {
Intent intent =
new
Intent();
intent.setClass(JiaoyuzixunActivity.
this
, MainActivity.
class
);
JiaoyuzixunActivity.
this
.startActivity(intent);
JiaoyuzixunActivity.
this
.finish();
}
else
{
return
false
;
}
return
super
.onKeyDown(keyCode, event);
}
}