|
|
|
@ -1,20 +1,54 @@ |
|
|
|
package com.qhclh.ytzh.home; |
|
|
|
|
|
|
|
import android.support.v4.app.FragmentTransaction; |
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
import com.qhclh.ytzh.R; |
|
|
|
import com.qhclh.ytzh.base.BaseActivity; |
|
|
|
import com.qhclh.ytzh.index.IndexFragment; |
|
|
|
import com.qhclh.ytzh.me.MeFragment; |
|
|
|
import com.qhclh.ytzh.work.WorkFragment; |
|
|
|
|
|
|
|
import butterknife.BindView; |
|
|
|
import butterknife.OnClick; |
|
|
|
|
|
|
|
public class MainActivity extends BaseActivity { |
|
|
|
@BindView(R.id.textaaa) |
|
|
|
TextView textView; |
|
|
|
|
|
|
|
@BindView(R.id.toolbar) |
|
|
|
Toolbar mToolbar; |
|
|
|
@BindView(R.id.tv_toolbar_title) |
|
|
|
TextView mTvToolbarTitle; |
|
|
|
|
|
|
|
@BindView(R.id.iv_index) |
|
|
|
ImageView iv_index; |
|
|
|
@BindView(R.id.tv_index) |
|
|
|
TextView tv_index; |
|
|
|
@BindView(R.id.iv_work) |
|
|
|
ImageView iv_work; |
|
|
|
@BindView(R.id.tv_work) |
|
|
|
TextView tv_work; |
|
|
|
@BindView(R.id.iv_me) |
|
|
|
ImageView iv_me; |
|
|
|
@BindView(R.id.tv_me) |
|
|
|
TextView tv_me; |
|
|
|
|
|
|
|
|
|
|
|
private long mLastClickTime; |
|
|
|
private static final long DEFAULT_EXIT_TIME = 2000; |
|
|
|
///< 首页 |
|
|
|
private static final int TAB_POSITION_INDEX = 0; |
|
|
|
///< 工作 |
|
|
|
private static final int TAB_POSITION_WORK = 1; |
|
|
|
///< 我的 |
|
|
|
private static final int TAB_POSITION_ME = 2; |
|
|
|
private int mCurrentTabPosition = -1; |
|
|
|
private int mTargetTabPosition = TAB_POSITION_INDEX; |
|
|
|
|
|
|
|
private IndexFragment indexFragment; |
|
|
|
private WorkFragment workFragment; |
|
|
|
private MeFragment meFragment; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected int setLayoutId() { |
|
|
|
@ -23,21 +57,156 @@ public class MainActivity extends BaseActivity { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void initView() { |
|
|
|
initToolbar(mToolbar, "aaaaa", new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View view) { |
|
|
|
finish(); |
|
|
|
} |
|
|
|
}); |
|
|
|
initToolbar(mToolbar, "", null); |
|
|
|
///< 点击切换fragment |
|
|
|
onTabClick(mTargetTabPosition); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void initData() { |
|
|
|
textView.setText("aaaaaaaaaaa"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void initOper() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@OnClick({R.id.ll_index, R.id.ll_work, R.id.ll_me}) |
|
|
|
public void onClick(View view) { |
|
|
|
switch (view.getId()) { |
|
|
|
///< 首页 |
|
|
|
case R.id.ll_index: { |
|
|
|
onTabClick(TAB_POSITION_INDEX); |
|
|
|
break; |
|
|
|
} |
|
|
|
///< 工作 |
|
|
|
case R.id.ll_work: { |
|
|
|
onTabClick(TAB_POSITION_WORK); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
///< 我的 |
|
|
|
case R.id.ll_me: { |
|
|
|
onTabClick(TAB_POSITION_ME); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void onTabClick(int tabPosition) { |
|
|
|
if (mCurrentTabPosition == tabPosition) { |
|
|
|
return; |
|
|
|
} |
|
|
|
mCurrentTabPosition = tabPosition; |
|
|
|
changeTabState(tabPosition); |
|
|
|
changeFragment(tabPosition); |
|
|
|
} |
|
|
|
|
|
|
|
private void changeTabState(int tabPosition) { |
|
|
|
clearAllTabState(); |
|
|
|
switch (tabPosition) { |
|
|
|
case TAB_POSITION_INDEX: { |
|
|
|
// iv_index.setImageResource(R.drawable.ghs12x); |
|
|
|
tv_index.setTextColor(getResources().getColor(R.color.green029737)); |
|
|
|
mTvToolbarTitle.setText(R.string.index); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case TAB_POSITION_WORK: { |
|
|
|
// iv_work.setImageResource(R.drawable.gwc12x); |
|
|
|
tv_work.setTextColor(getResources().getColor(R.color.green029737)); |
|
|
|
mTvToolbarTitle.setText(R.string.work); |
|
|
|
break; |
|
|
|
} |
|
|
|
case TAB_POSITION_ME: { |
|
|
|
// iv_me.setImageResource(R.drawable.dd12x); |
|
|
|
tv_me.setTextColor(getResources().getColor(R.color.green029737)); |
|
|
|
mTvToolbarTitle.setText(R.string.me); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void clearAllTabState() { |
|
|
|
///< 首页 |
|
|
|
// iv_index.setImageResource(R.drawable.ghs2x); |
|
|
|
tv_index.setTextColor(getResources().getColor(R.color.grey888888)); |
|
|
|
///< 工作 |
|
|
|
// iv_work.setImageResource(R.drawable.gwc2x); |
|
|
|
tv_work.setTextColor(getResources().getColor(R.color.grey888888)); |
|
|
|
|
|
|
|
///< 我的 |
|
|
|
// iv_me.setImageResource(R.drawable.dd2x); |
|
|
|
tv_me.setTextColor(getResources().getColor(R.color.grey888888)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void changeFragment(int tabPosition) { |
|
|
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
|
|
|
hideFragment(transaction); |
|
|
|
switch (tabPosition) { |
|
|
|
case TAB_POSITION_INDEX: { |
|
|
|
if (indexFragment == null) { |
|
|
|
indexFragment = new IndexFragment(); |
|
|
|
transaction.add(R.id.main_container, indexFragment); |
|
|
|
} else { |
|
|
|
transaction.show(indexFragment); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case TAB_POSITION_WORK: { |
|
|
|
if (workFragment == null) { |
|
|
|
workFragment = new WorkFragment(); |
|
|
|
transaction.add(R.id.main_container, workFragment); |
|
|
|
} else { |
|
|
|
transaction.show(workFragment); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case TAB_POSITION_ME: { |
|
|
|
if (meFragment == null) { |
|
|
|
meFragment = new MeFragment(); |
|
|
|
transaction.add(R.id.main_container, meFragment); |
|
|
|
} else { |
|
|
|
transaction.show(meFragment); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
transaction.commitAllowingStateLoss(); |
|
|
|
} |
|
|
|
|
|
|
|
private void hideFragment(FragmentTransaction transaction) { |
|
|
|
if (indexFragment != null) { |
|
|
|
transaction.hide(indexFragment); |
|
|
|
} |
|
|
|
|
|
|
|
if (workFragment != null) { |
|
|
|
transaction.hide(workFragment); |
|
|
|
} |
|
|
|
if (meFragment != null) { |
|
|
|
transaction.hide(meFragment); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onBackPressed() { |
|
|
|
// super.onBackPressed(); |
|
|
|
exitApp(); |
|
|
|
} |
|
|
|
|
|
|
|
///< back键退出 |
|
|
|
private void exitApp() { |
|
|
|
long currentTime = System.currentTimeMillis(); |
|
|
|
if (currentTime - mLastClickTime < DEFAULT_EXIT_TIME) { |
|
|
|
finishAll(); |
|
|
|
} else { |
|
|
|
mLastClickTime = currentTime; |
|
|
|
showToast(getString(R.string.back_exit_app)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |