public class OpenChangelogDialog {
} public class OpenForumEvent {

    public ForumPagerItem forumPagerItem;
    public PantipRestClient.ForumType forumType;

    public OpenForumEvent(ForumPagerItem forumPagerItem, PantipRestClient.ForumType forumType) {
        this.forumPagerItem = forumPagerItem;
        this.forumType = forumType;
    }
} public class OpenForumRearrangeEvent {
} public class OpenLoginScreenEvent {
} public class OpenTopicEvent {
    private Topic topic;
    private View animatedView;
    private int startingLocation;

    public OpenTopicEvent(Topic topic) {
        this.topic = topic;
    }

    public OpenTopicEvent(Topic topic, int startingLocation) {
        this.topic = topic;
        this.startingLocation = startingLocation;
    }

    public OpenTopicEvent(Topic topic, View animatedView) {
        this.topic = topic;
        this.animatedView = animatedView;
    }

    public Topic getTopic() {
        return topic;
    }

    public View getAnimatedView() {
        return animatedView;
    }

    public int getStartingLocation() {
        return startingLocation;
    }

    public void setStartingLocation(int startingLocation) {
        this.startingLocation = startingLocation;
    }
} public class OpenUserEvent {
    int userId;
    String username;
    String avatar;

    public OpenUserEvent(int userId, String username, String avatar) {
        this.userId = userId;
        this.username = username;
        this.avatar = avatar;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }
} public class SetTitleEvent {
    public String title;

    public SetTitleEvent(String title) {
        this.title = title;
    }
} public class ToggleDrawerEvent {
} public class UpdateForumListEvent {
} public class DialogMaterialFragment extends DialogFragment {

    public DialogMaterialFragment() {
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        ChangeLogListView chgList=(ChangeLogListView)layoutInflater.inflate(R.layout.changelog_fragment_material, null);

        return new AlertDialog.Builder(getActivity())
                .setTitle("รายการสิ่งที่เปลี่ยนแปลง")
                .setView(chgList)
                .setPositiveButton("ตกลง",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                            }
                        }
                )
                .create();

    }

} @EFragment(R.layout.fragment_forumholder)
public class ForumHolderFragment extends BaseFragment {

    public static final String TAG = "fragmentHolder";

    @ViewById
    ViewPager viewPager;
    @ViewById
    PagerSlidingTabStrip tabs;
    @ViewById
    Toolbar toolbar;
    @ViewById
    LinearLayout topPanel;

    private List<ForumPagerItem> forumPagerItems;
    private int tabsHeight;
    private CharSequence actionBarTitle;
    private ForumSlidePagerAdapter pagerAdapter;
    private int currentPage;
    private ActionBar actionBar;
    private boolean toolbarHiding = false;
    private boolean navbarHiding = false;
    private float topDefaultY;

    @AfterViews
    void init(){

        rateApp();

        getAttachedActivity().setSupportActionBar(toolbar);
        getAttachedActivity().initNavDrawer(toolbar);
        forumPagerItems = ForumPagerItem.getAll("enable");
        pagerAdapter = new ForumSlidePagerAdapter(getFragmentManager());
        final DisplayMetrics displaymetrics = new DisplayMetrics();
        getAttachedActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        viewPager.setAdapter(pagerAdapter);
        viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.padding_default));
        tabs.setTabBackground(android.R.color.transparent);
        tabs.setViewPager(viewPager);

        tabs.setOnPageChangeListener(
                new ViewPager.OnPageChangeListener() {


                    int sWidth = displaymetrics.widthPixels;

                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                    }

                    @Override
                    public void onPageSelected(int position) {
                        currentPage = position;
                        showTabs();
//                        View tab = tabs.getTab(position);
//                        Log.d("tabs", "widht = "+tab.getWidth());
//                        tabs.setScrollOffset((sWidth/2)-(tab.getWidth()/2), true);
                    }

                    @Override
                    public void onPageScrollStateChanged(int i) {

                    }
                }
        );
        tabs.setIndicatorColorResource(R.color.base_color_highlight);
        tabs.setDividerColorResource(android.R.color.transparent);
        tabs.setIndicatorHeight(getResources().getDimensionPixelOffset(R.dimen.tabs_indicator_height));

        actionBar = ((ActionBarActivity)getAttachedActivity()).getSupportActionBar();
        topDefaultY = topPanel.getY();
        showcase();
    }

    private void showcase() {
        ShowcaseView sv1 = new ShowcaseView.Builder(getAttachedActivity())
                .setTarget(Target.NONE)
                .singleShot(ShowcaseUtils.FIRST_TIME_LAUNCH_ID)
                .setContentTitle("ยินดีต้อนรับเข้าสู่ \"อมยิ้ม\"")
                .setContentText("ประสบการณ์ การเล่น Pantip ที่แปลกใหม่!")
                .setShowcaseEventListener(new OnShowcaseEventListener() {
                    @Override
                    public void onShowcaseViewHide(ShowcaseView showcaseView) {
                        ShowcaseView sv2 = new ShowcaseView.Builder(getAttachedActivity())
                                .setContentTitle("คุณคงไม่ได้อ่าน Pantip ทุกห้อง")
                                .setContentText("เราจึงทำระบบให้คุณเลือกแสดง" +
                                        "\nและจัดอันดับห้องตามที่คุณชอบได้" +
                                        "\nลองไปทำกันเลย")
                                .setShowcaseEventListener(new OnShowcaseEventListener() {
                                    @Override
                                    public void onShowcaseViewHide(ShowcaseView showcaseView) {
                                        BaseApplication.getEventBus().post(new OpenForumRearrangeEvent());
                                    }

                                    @Override
                                    public void onShowcaseViewDidHide(ShowcaseView showcaseView) {

                                    }

                                    @Override
                                    public void onShowcaseViewShow(ShowcaseView showcaseView) {

                                    }
                                })
                                .build();
                        sv2.setButtonPosition(ShowcaseUtils.getCenterInParentLayoutParam());
                    }

                    @Override
                    public void onShowcaseViewDidHide(ShowcaseView showcaseView) {

                    }

                    @Override
                    public void onShowcaseViewShow(ShowcaseView showcaseView) {

                    }
                })
                .build();
        sv1.setButtonPosition(ShowcaseUtils.getCenterInParentLayoutParam());
    }

    private void rateApp() {
        AppRater.app_launched(getAttachedActivity());
        AppRater.setLightTheme();
//        AppRater.setVersionCodeCheckEnabled(true);
        AppRater.setNumLaunchesForRemindLater(1);
//        AppRater.showRateDialog(getAttachedActivity());
    }

    @Override
    public void onResume() {
        super.onResume();
        app.getEventBus().register(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        app.getEventBus().unregister(this);

    }

    @Override
    void back() {
        app.getEventBus().post(new ToggleDrawerEvent());
    }

    private class ForumSlidePagerAdapter extends FragmentStatePagerAdapter{
        public ForumSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return forumPagerItems.get(position).title;
        }



        @Override
        public Fragment getItem(int position) {
            return ForumFragment_.builder().forumType(PantipRestClient.ForumType.Room).forumPagerItem(forumPagerItems.get(position)).build();
        }

        @Override
        public int getCount() {
            return forumPagerItems.size();
        }
    }

    @Subscribe
    public void hideTabs(ForumScrollDownEvent e){
//        Log.d("event", "hideTabs");
//        if (!toolbarHiding) {
//            tabsHeight = toolbar.getHeight();
//            topPanel.animate().translationYBy(0 - tabsHeight).setInterpolator(new AccelerateDecelerateInterpolator()).start();
//
////            actionBarTitle = actionBar.getTitle();
////            actionBar.setTitle(pagerAdapter.getPageTitle(currentPage));
////            app.getEventBus().post(new SetTitleEvent(pagerAdapter.getPageTitle(currentPage).toString()));
//            toolbarHiding = true;
//        }else if(!navbarHiding){
//            tabsHeight = tabs.getHeight();
//            topPanel.animate().translationYBy(0 - tabsHeight).setInterpolator(new AccelerateDecelerateInterpolator()).start();
//        }
    }



    @Subscribe
    public void showTabs(ForumScrollUpEvent e){
//        if (toolbarHiding) {
//            showTabs();
//        }
    }

    private void showTabs() {
        Log.d("event", "showTabs");


            topPanel.animate().translationY(topDefaultY).setInterpolator(new AccelerateDecelerateInterpolator()).start();
//            app.getEventBus().post(new SetTitleEvent(getString(R.string.app_name)));
            toolbarHiding = false;
    }


} public class BaseActivity extends ActionBarActivity {

    private static final String SAVED_SNACKBAR = "snackbar";
    private SnackBar mSnackBar;
    protected ActionBarDrawerToggle mDrawerToggle;
    protected CharSequence mTitle;
    protected CharSequence mDrawerTitle;
    private DrawerLayout drawerLayout;
    private String openTxt;
    private String closeTxt;
    private Toolbar toolbar;
    protected boolean noBackTransition;

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        if (!noBackTransition) {
            overridePendingTransition(R.anim.activity_scale_in_from_bottom_center, R.anim.activity_exit_slide_to_bottom);
        }else{
            overridePendingTransition(0,0);
        }
    }

    protected void setDrawerLayout(DrawerLayout drawerLayout) {
        this.drawerLayout = drawerLayout;
    }

    public void setDrawerOpenText(String openTxt) {
        this.openTxt = openTxt;
    }

    public void setDrawerCloseText(String closeTxt) {
        this.closeTxt = closeTxt;
    }

    public void initNavDrawer(final Toolbar toolbar) {
        mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {

            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                mDrawerTitle = toolbar.getTitle();
                toolbar.setTitle(closeTxt);
                supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                mTitle = toolbar.getTitle();
                toolbar.setTitle(openTxt);
                supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerToggle.syncState();

    }

    @Override
    protected void onSaveInstanceState(Bundle saveState) {
        super.onSaveInstanceState(saveState);
        // use this to save your snacks for later
//        saveState.putBundle(SAVED_SNACKBAR, mSnackBar.onSaveInstanceState());
    }

    @Override
    protected void onRestoreInstanceState(Bundle loadState) {
        super.onRestoreInstanceState(loadState);
        // use this to load your snacks for later
//        mSnackBar.onRestoreInstanceState(loadState.getBundle(SAVED_SNACKBAR));
    }

    protected void overrideAnimationBeforeStartActivity() {
        overridePendingTransition(R.anim.activity_enter_slide_from_bottom, R.anim.activity_scale_out_to_bottom_center);
    }

    public SnackBar getSnackBar() {
        if (mSnackBar == null) {
            mSnackBar = new SnackBar(this);
        }
        return mSnackBar;
    }

    void setToolbar(Toolbar toolbar) {
        this.toolbar = toolbar;
    }

    public Toolbar getToolbar() {
        return toolbar;
    }

    @Override
    public void setSupportActionBar(@Nullable Toolbar toolbar) {
        setToolbar(toolbar);
        super.setSupportActionBar(toolbar);
    }

}
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.MenuItem;
import android.widget.FrameLayout;
import com.google.android.gms.ads.AdRequest;
import com.nantaphop.pantipfanapp.event.OpenChangelogDialog;
import com.nantaphop.pantipfanapp.event.OpenForumEvent;
import com.nantaphop.pantipfanapp.event.OpenForumRearrangeEvent;
import com.nantaphop.pantipfanapp.event.OpenLoginScreenEvent;
import com.nantaphop.pantipfanapp.event.OpenTopicEvent;
import com.nantaphop.pantipfanapp.event.OpenUserEvent;
import com.nantaphop.pantipfanapp.event.SetTitleEvent;
import com.nantaphop.pantipfanapp.event.ToggleDrawerEvent;
import com.nantaphop.pantipfanapp.event.UpdateForumListEvent;
import com.nantaphop.pantipfanapp.fragment.DialogMaterialFragment;
import com.nantaphop.pantipfanapp.fragment.ForumHolderFragment;
import com.nantaphop.pantipfanapp.fragment.ForumHolderFragment_;
import com.nantaphop.pantipfanapp.view.BaseActivity;
import com.squareup.otto.Subscribe;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.App;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.StringArrayRes;
import org.androidannotations.annotations.res.StringRes;
package com.nantaphop.pantipfanapp;




@EActivity(R.layout.activity_main)
public class MainActivity extends BaseActivity {

    @App
    BaseApplication app;


    @ViewById
    FrameLayout content_frame;
    @ViewById
    DrawerLayout drawer_layout;

    @StringRes
    String drawer_open;
    @StringRes
    String drawer_close;
    @StringRes
    String topic_sort_type_title;
    @StringArrayRes
    String[] topic_sort_type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState == null) {
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.content_frame, new ForumHolderFragment_(), ForumHolderFragment.TAG);
            fragmentTransaction.setCustomAnimations(
                    R.anim.enter_slide_from_bottom,
                    0,
                    0,
                    R.anim.activity_scale_out_to_bottom_center
            );
            fragmentTransaction.commit();
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        System.out.print(item.toString());
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        if (drawer_layout.isDrawerOpen(Gravity.START))
            drawer_layout.closeDrawers();
        else
            super.onBackPressed();
    }

    @AfterViews
    void init() {
        setDrawerLayout(drawer_layout);
        setDrawerCloseText(drawer_close);
        setDrawerOpenText(drawer_open);

        // Set the drawer toggle as the DrawerListener
        drawer_layout.setDrawerListener(mDrawerToggle);
        AdRequest adRequest = new AdRequest.Builder().build();
    }

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        overridePendingTransition(R.anim.activity_enter_slide_from_bottom, R.anim.activity_exit_slide_to_bottom);

    }

    @Override
    protected void onResume() {
        super.onResume();
        app.getEventBus().register(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        app.getEventBus().unregister(this);
    }

    @Subscribe
    public void openTopic(final OpenTopicEvent e) {