263 lines
9.3 KiB
Java
263 lines
9.3 KiB
Java
package com.gh.gamecenter.personal;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v4.app.Fragment;
|
|
import android.support.v4.app.FragmentManager;
|
|
import android.support.v4.app.FragmentPagerAdapter;
|
|
import android.support.v4.view.ViewPager;
|
|
import android.util.DisplayMetrics;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.gh.base.AppController;
|
|
import com.gh.common.util.DisplayUtils;
|
|
import com.gh.gamecenter.R;
|
|
import com.gh.gamecenter.SettingActivity;
|
|
import com.gh.gamecenter.eventbus.EBMoveTop;
|
|
import com.gh.gamecenter.eventbus.EBSlide;
|
|
|
|
import de.greenrobot.event.EventBus;
|
|
|
|
/**
|
|
*
|
|
* @author 温冠超
|
|
* @email 294299195@qq.com
|
|
* @date 2015-8-8 主页fragment3页面
|
|
*/
|
|
public class PersonalFragment extends Fragment implements View.OnClickListener, ViewPager.OnPageChangeListener {
|
|
|
|
private View view;
|
|
private ViewPager me_vp_show;
|
|
|
|
private RelativeLayout me_rl_top;
|
|
private ImageView me_iv_top_setting;
|
|
private TextView me_tv_top_install;
|
|
private TextView me_tv_top_concern;
|
|
private View me_top_slide_line;
|
|
|
|
private LinearLayout me_ll_topbar;
|
|
private View me_topbar_status_bar;
|
|
private TextView me_tv_topbar_install;
|
|
private TextView me_tv_topbar_concern;
|
|
private View me_topbar_slide_line;
|
|
|
|
private RelativeLayout.LayoutParams top_line_rparams;
|
|
private RelativeLayout.LayoutParams topbar_line_rparams;
|
|
private RelativeLayout.LayoutParams top_rparams;
|
|
|
|
private int leftMargin;
|
|
private int dis;
|
|
private int previous;
|
|
|
|
@Override
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
view = View.inflate(getActivity(), R.layout.home3_fragment, null);
|
|
|
|
me_rl_top = (RelativeLayout) view.findViewById(R.id.me_rl_top);
|
|
top_rparams = (RelativeLayout.LayoutParams) me_rl_top.getLayoutParams();
|
|
|
|
me_iv_top_setting = (ImageView) view.findViewById(R.id.me_iv_top_setting);
|
|
me_iv_top_setting.setOnClickListener(this);
|
|
|
|
DisplayMetrics outMetrics = new DisplayMetrics();
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
|
|
|
me_tv_top_install = (TextView) view.findViewById(R.id.me_tv_top_install);
|
|
me_tv_top_install.setOnClickListener(this);
|
|
RelativeLayout.LayoutParams rparams1 = (RelativeLayout.LayoutParams) me_tv_top_install.getLayoutParams();
|
|
int width = outMetrics.widthPixels / 4;
|
|
rparams1.width = width;
|
|
rparams1.leftMargin = width - DisplayUtils.dip2px(getActivity(), 10);
|
|
me_tv_top_install.setLayoutParams(rparams1);
|
|
|
|
me_tv_top_concern = (TextView) view.findViewById(R.id.me_tv_top_concern);
|
|
me_tv_top_concern.setOnClickListener(this);
|
|
RelativeLayout.LayoutParams rparams2 = (RelativeLayout.LayoutParams) me_tv_top_concern.getLayoutParams();
|
|
rparams2.width = width;
|
|
rparams2.rightMargin = width - DisplayUtils.dip2px(getActivity(), 10);
|
|
me_tv_top_concern.setLayoutParams(rparams2);
|
|
|
|
me_top_slide_line = view.findViewById(R.id.me_top_slide_line);
|
|
top_line_rparams = (RelativeLayout.LayoutParams) me_top_slide_line.getLayoutParams();
|
|
top_line_rparams.width = outMetrics.widthPixels / 6;
|
|
leftMargin = outMetrics.widthPixels / 8 * 3 - outMetrics.widthPixels / 12 - DisplayUtils.dip2px(getActivity(), 10);
|
|
top_line_rparams.leftMargin = leftMargin;
|
|
me_top_slide_line.setLayoutParams(top_line_rparams);
|
|
|
|
dis = outMetrics.widthPixels / 4 + DisplayUtils.dip2px(getActivity(), 20);
|
|
|
|
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
|
me_tv_top_install.setClickable(false);
|
|
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.title));
|
|
me_tv_top_concern.setClickable(true);
|
|
|
|
me_ll_topbar = (LinearLayout) view.findViewById(R.id.me_ll_topbar);
|
|
|
|
me_topbar_status_bar = view.findViewById(R.id.me_topbar_status_bar);
|
|
LinearLayout.LayoutParams rparams = (LinearLayout.LayoutParams) me_topbar_status_bar.getLayoutParams();
|
|
rparams.height = DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height");
|
|
me_topbar_status_bar.setLayoutParams(rparams);
|
|
|
|
me_tv_topbar_install = (TextView) view.findViewById(R.id.me_tv_topbar_install);
|
|
me_tv_topbar_install.setOnClickListener(this);
|
|
RelativeLayout.LayoutParams rparams3 = (RelativeLayout.LayoutParams) me_tv_topbar_install.getLayoutParams();
|
|
rparams3.width = width;
|
|
rparams3.leftMargin = width - DisplayUtils.dip2px(getActivity(), 10);
|
|
me_tv_topbar_install.setLayoutParams(rparams3);
|
|
|
|
me_tv_topbar_concern = (TextView) view.findViewById(R.id.me_tv_topbar_concern);
|
|
me_tv_topbar_concern.setOnClickListener(this);
|
|
RelativeLayout.LayoutParams rparams4 = (RelativeLayout.LayoutParams) me_tv_topbar_concern.getLayoutParams();
|
|
rparams4.width = width;
|
|
rparams4.rightMargin = width - DisplayUtils.dip2px(getActivity(), 10);
|
|
me_tv_topbar_concern.setLayoutParams(rparams4);
|
|
|
|
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
|
me_tv_top_install.setClickable(false);
|
|
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.title));
|
|
me_tv_top_concern.setClickable(true);
|
|
|
|
me_topbar_slide_line = view.findViewById(R.id.me_topbar_slide_line);
|
|
topbar_line_rparams = (RelativeLayout.LayoutParams) me_topbar_slide_line.getLayoutParams();
|
|
topbar_line_rparams.width = outMetrics.widthPixels / 6;
|
|
leftMargin = outMetrics.widthPixels / 8 * 3 - outMetrics.widthPixels / 12 - DisplayUtils.dip2px(getActivity(), 10);
|
|
topbar_line_rparams.leftMargin = leftMargin;
|
|
me_topbar_slide_line.setLayoutParams(topbar_line_rparams);
|
|
|
|
me_vp_show = (ViewPager) view.findViewById(R.id.me_vp_show);
|
|
me_vp_show.setAdapter(new FragmentAdapter(getChildFragmentManager()));
|
|
me_vp_show.addOnPageChangeListener(this);
|
|
|
|
previous = 0;
|
|
|
|
EventBus.getDefault().register(this);
|
|
}
|
|
|
|
@Override
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
Bundle savedInstanceState) {
|
|
if (container != null) {
|
|
container.removeView(view);
|
|
}
|
|
return view;
|
|
}
|
|
|
|
@Override
|
|
public void onPageScrolled(int position, float positionOffset,
|
|
int positionOffsetPixels) {
|
|
if (positionOffset != 0) {
|
|
top_line_rparams.leftMargin = (int) (dis * (positionOffset + position)) + leftMargin;
|
|
topbar_line_rparams.leftMargin = (int) (dis * (positionOffset + position)) + leftMargin;
|
|
me_top_slide_line.setLayoutParams(top_line_rparams);
|
|
me_topbar_slide_line.setLayoutParams(topbar_line_rparams);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPageSelected(int position) {
|
|
if (position == 0) {
|
|
if (me_ll_topbar.getVisibility() == View.VISIBLE) {
|
|
EventBus.getDefault().post(new EBSlide(0, previous, true));
|
|
}
|
|
previous = 0;
|
|
|
|
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
|
me_tv_top_install.setClickable(false);
|
|
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.title));
|
|
me_tv_top_concern.setClickable(true);
|
|
|
|
me_tv_topbar_install.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
|
me_tv_topbar_install.setClickable(false);
|
|
me_tv_topbar_concern.setTextColor(getActivity().getResources().getColor(R.color.title));
|
|
me_tv_topbar_concern.setClickable(true);
|
|
} else {
|
|
if (me_ll_topbar.getVisibility() == View.VISIBLE) {
|
|
EventBus.getDefault().post(new EBSlide(0, previous, true));
|
|
}
|
|
previous = 1;
|
|
|
|
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.title));
|
|
me_tv_top_install.setClickable(true);
|
|
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
|
me_tv_top_concern.setClickable(false);
|
|
|
|
me_tv_topbar_install.setTextColor(getActivity().getResources().getColor(R.color.title));
|
|
me_tv_topbar_install.setClickable(true);
|
|
me_tv_topbar_concern.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
|
me_tv_topbar_concern.setClickable(false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPageScrollStateChanged(int state) {
|
|
|
|
}
|
|
|
|
private class FragmentAdapter extends FragmentPagerAdapter {
|
|
|
|
public FragmentAdapter(FragmentManager fm) {
|
|
super(fm);
|
|
}
|
|
|
|
@Override
|
|
public Fragment getItem(int position) {
|
|
if (position == 0) {
|
|
return new InstallFragment();
|
|
} else {
|
|
return new ConcernFragment();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getCount() {
|
|
return 2;
|
|
}
|
|
|
|
}
|
|
|
|
public void onEventMainThread(EBMoveTop moveTop) {
|
|
if (moveTop.getType().equals("top")) {
|
|
if (moveTop.getVisibility() == View.VISIBLE) {
|
|
me_ll_topbar.setVisibility(View.VISIBLE);
|
|
} else {
|
|
me_ll_topbar.setVisibility( View.GONE);
|
|
}
|
|
if (top_rparams.topMargin != moveTop.getTopMargin()) {
|
|
top_rparams.topMargin = moveTop.getTopMargin();
|
|
me_rl_top.setLayoutParams(top_rparams);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
if (v.getId() == R.id.me_iv_top_setting) {
|
|
startActivity(new Intent(getActivity(), SettingActivity.class));
|
|
} else if (v.getId() == R.id.me_tv_top_install
|
|
|| v.getId() == R.id.me_tv_topbar_install) {
|
|
me_vp_show.setCurrentItem(0);
|
|
} else if (v.getId() == R.id.me_tv_top_concern
|
|
|| v.getId() == R.id.me_tv_topbar_concern) {
|
|
me_vp_show.setCurrentItem(1);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
EventBus.getDefault().unregister(this);
|
|
AppController.canclePendingRequests(PersonalFragment.class);
|
|
view = null;
|
|
}
|
|
|
|
}
|