@Override protected void onResume() { super.onResume(); mListView.setAdapter(mAdapters[mViewPager.getCurrentItem()]); MainView mainView = mViewList.get(mViewPager.getCurrentItem()); mainView.refreshData(); mainView.registerAnimate(); IncrementAnimationUtil.getInstance().setChangeLevel(mainView.getScore()); IncrementAnimationUtil.getInstance().startAnimation(); }
@Override public void onPageSelected(int index) { IncrementAnimationUtil.getInstance().endAnimation(); for (int i = 0; i < mViewList.size(); i++) { if (i != index) { mViewList.get(index).unRegisterAnimate(); } } mViewList.get(index).refreshData(); mViewList.get(index).registerAnimate(); mListView.setAdapter(mAdapters[index]); mAdapters[index].notifyDataSetChanged(); if (mRadioGroup.getChildCount() > index) { RadioButton radioButton = (RadioButton) mRadioGroup.getChildAt(index); radioButton.setChecked(true); } IncrementAnimationUtil.getInstance().setChangeLevel(mViewList.get(index).getScore()); IncrementAnimationUtil.getInstance().startAnimation(); }
@SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity, R.layout.main_titlebar_layout); if (!isAddShortCut()) { addShortCut(); } ImageView settings = (ImageView) findViewById(R.id.settings_img); settings.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivity.this, SettingsActivity.class)); } }); mBackground = new MyColorBackground(); mViewPager = (ViewPager) findViewById(R.id.main_viewpager); mViewList = new ArrayList<MainView>(); MainView view = new CountMainView(this); mViewList.add(view); view = new TimeMainView(this); mViewList.add(view); MainPagerAdapter pagerAdapter = new MainPagerAdapter(mViewList); mViewPager.setAdapter(pagerAdapter); mViewPager.setOnPageChangeListener(this); LinearLayout layoutRoot = (LinearLayout) findViewById(R.id.main_layout_root); layoutRoot.setBackground(mBackground); mRadioGroup = (RadioGroup) findViewById(R.id.pagerRadioGroup); mRadioGroup.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int count = group.getChildCount(); for (int index = 0; index < count; index++) { RadioButton btn = (RadioButton) group.getChildAt(index); if (btn.getId() == checkedId) { if (mViewPager.getCurrentItem() != index) { mViewPager.setCurrentItem(index, true); } } } } }); mListView = (ExpandableListView) findViewById(R.id.unlock_detail_list); mListView.setGroupIndicator(null); mAdapters = new DetailListAdapter[2]; mAdapters[0] = new UnlockDetailListAdapter(this); mAdapters[1] = new TimeDetailListAdapter(this); mListView.setDivider(null); mListView.setChildDivider(null); mListBackground = new MyColorBackground(); mListView.setBackground(mListBackground); slidingDrawer = (SlidingDrawer) findViewById(R.id.sliding_detail); final ImageView arrow = (ImageView) findViewById(R.id.sliding_handle_arrow); final TextView handleText = (TextView) findViewById(R.id.sliding_handle_text); final ViewGroup slidingHandle = (ViewGroup) findViewById(R.id.sliding_handle); slidingDrawable = new SingleColorDrawable(1, true); slidingHandle.setBackground(slidingDrawable); slidingDrawer.setOnDrawerOpenListener( new OnDrawerOpenListener() { @Override public void onDrawerOpened() { handleText.setVisibility(View.GONE); arrow.setImageResource(R.drawable.down_arrow); mAdapters[mViewPager.getCurrentItem()].refreshData(); mAdapters[mViewPager.getCurrentItem()].notifyDataSetChanged(); int n = mListView.getCount(); for (int i = 0; i < n; i++) { mListView.expandGroup(i); } } }); slidingDrawer.setOnDrawerCloseListener( new OnDrawerCloseListener() { @Override public void onDrawerClosed() { handleText.setVisibility(View.VISIBLE); arrow.setImageResource(R.drawable.up_arrow); } }); setMainTitle(R.string.main_title); View title_layout = (View) findViewById(R.id.titlebar_layout_root); SingleColorDrawable back = new SingleColorDrawable(0, false); title_layout.setBackground(back); IncrementAnimationUtil.getInstance().addObserver(back); IncrementAnimationUtil.getInstance().addObserver(mBackground); IncrementAnimationUtil.getInstance().addObserver(mListBackground); IncrementAnimationUtil.getInstance().addObserver(slidingDrawable); }