169 lines
5.6 KiB
Java
169 lines
5.6 KiB
Java
package com.gh.gamecenter;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.v4.app.Fragment;
|
|
import android.support.v4.content.ContextCompat;
|
|
import android.support.v4.view.ViewPager;
|
|
import android.util.DisplayMetrics;
|
|
import android.view.View;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.gh.base.BaseActivity;
|
|
import com.gh.base.adapter.FragmentAdapter;
|
|
import com.gh.common.util.DisplayUtils;
|
|
import com.gh.common.util.EntranceUtils;
|
|
import com.gh.gamecenter.eventbus.EBReuse;
|
|
import com.gh.gamecenter.eventbus.EBUISwitch;
|
|
import com.gh.gamecenter.libao.Libao1Fragment;
|
|
import com.gh.gamecenter.libao.Libao2Fragment;
|
|
import com.gh.gamecenter.libao.Libao3Fragment;
|
|
import com.lightgame.view.NoScrollableViewPager;
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.OnClick;
|
|
|
|
/**
|
|
* Created by khy on 2016/12/12.
|
|
*/
|
|
public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
|
ViewPager.OnPageChangeListener {
|
|
|
|
public final static String EB_LIBAOACTIVITY_TAG = "LibaoActivity";
|
|
@BindView(R.id.libao_vp_content)
|
|
NoScrollableViewPager mLibaoVp;
|
|
@BindView(R.id.libao_ll_top)
|
|
LinearLayout mLibaoTopLl;
|
|
@BindView(R.id.libao_slide_line)
|
|
View mLibaoLine;
|
|
@BindView(R.id.vp_tab)
|
|
LinearLayout mTabLl;
|
|
@BindView(R.id.libao_history_title)
|
|
TextView mHistoryTitle;
|
|
@BindView(R.id.libao_zuixun_tv)
|
|
TextView mZuixinTv;
|
|
@BindView(R.id.libao_concern_tv)
|
|
TextView mGuanzhuTv;
|
|
@BindView(R.id.libao_chunhaoxiang_tv)
|
|
TextView mChunhaoxiangTv;
|
|
private int currentItem;
|
|
private int width;
|
|
private LinearLayout.LayoutParams lparams;
|
|
|
|
@NonNull
|
|
public static Intent getIntent(Context context, String entrance) {
|
|
Intent intent = new Intent(context, LibaoActivity.class);
|
|
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
|
return intent;
|
|
}
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.activity_libao;
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
initTitle("礼包中心");
|
|
|
|
mZuixinTv.setSelected(true);
|
|
|
|
List<Fragment> list = new ArrayList<>();
|
|
list.add(new Libao1Fragment());
|
|
list.add(new Libao2Fragment());
|
|
list.add(new Libao3Fragment());
|
|
mLibaoVp.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
|
mLibaoVp.addOnPageChangeListener(this);
|
|
|
|
DisplayMetrics outMetrics = new DisplayMetrics();
|
|
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
|
width = outMetrics.widthPixels / 3;
|
|
lparams = new LinearLayout.LayoutParams(width / 2,
|
|
DisplayUtils.dip2px(this, 2));
|
|
lparams.leftMargin = (int) (width * (currentItem + 0.25f));
|
|
mLibaoLine.setLayoutParams(lparams);
|
|
|
|
mLibaoTopLl.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
EventBus.getDefault().post(new EBUISwitch(EB_LIBAOACTIVITY_TAG, 0));
|
|
}
|
|
}, 100);
|
|
|
|
}
|
|
|
|
@OnClick({R.id.libao_zuixun_tv, R.id.libao_concern_tv, R.id.libao_chunhaoxiang_tv})
|
|
public void onClick(View v) {
|
|
if (v == mZuixinTv) {
|
|
mLibaoVp.setCurrentItem(0);
|
|
} else if (v == mGuanzhuTv) {
|
|
mLibaoVp.setCurrentItem(1);
|
|
} else if (v == mChunhaoxiangTv) {
|
|
mLibaoVp.setCurrentItem(2);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
if (positionOffset != 0) {
|
|
lparams.leftMargin = (int) (width * (position + positionOffset + 0.25f));
|
|
mLibaoLine.setLayoutParams(lparams);
|
|
} else {
|
|
if (currentItem != mLibaoVp.getCurrentItem()) {
|
|
currentItem = mLibaoVp.getCurrentItem();
|
|
EventBus.getDefault().post(new EBUISwitch(EB_LIBAOACTIVITY_TAG, currentItem));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPageSelected(int position) {
|
|
if (position == 0) {
|
|
mZuixinTv.setSelected(true);
|
|
mGuanzhuTv.setSelected(false);
|
|
mChunhaoxiangTv.setSelected(false);
|
|
} else if (position == 1) {
|
|
mZuixinTv.setSelected(false);
|
|
mGuanzhuTv.setSelected(true);
|
|
mChunhaoxiangTv.setSelected(false);
|
|
} else if (position == 2) {
|
|
mZuixinTv.setSelected(false);
|
|
mGuanzhuTv.setSelected(false);
|
|
mChunhaoxiangTv.setSelected(true);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPageScrollStateChanged(int state) {
|
|
|
|
}
|
|
|
|
// 页面切换事件(查看历史礼包的页面)
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onEventMainThread(EBReuse reuse) {
|
|
if ("openPage".equals(reuse.getType())) {
|
|
mLibaoTopLl.setVisibility(View.GONE);
|
|
mLibaoLine.setVisibility(View.GONE);
|
|
mHistoryTitle.setVisibility(View.VISIBLE);
|
|
mHistoryTitle.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.hint));
|
|
mLibaoVp.setScrollable(false);
|
|
} else if ("closePage".equals(reuse.getType())) {
|
|
mLibaoTopLl.setVisibility(View.VISIBLE);
|
|
mLibaoLine.setVisibility(View.VISIBLE);
|
|
mHistoryTitle.setVisibility(View.GONE);
|
|
mLibaoVp.setScrollable(true);
|
|
}
|
|
}
|
|
}
|