Search in sources :

Example 1 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    drawer = (ListView) findViewById(R.id.drawer);
    drawer.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    String[] rows = getResources().getStringArray(R.array.drawer_rows);
    drawer.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_row, rows));
    drawer.setOnItemClickListener(this);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    toggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
    drawerLayout.setDrawerListener(toggle);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getFragmentManager().addOnBackStackChangedListener(this);
    if (getFragmentManager().findFragmentById(R.id.content) == null) {
        showLorem();
    }
}
Also used : ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle)

Example 2 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project SimplifyReader by chentao0707.

the class HomeActivity method initializeViews.

@Override
public void initializeViews(List<BaseLazyFragment> fragments, List<NavigationEntity> navigationList) {
    mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            setTitle(getString(R.string.app_name));
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (null != mNavListAdapter) {
                setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
            }
        }
    };
    mActionBarDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
    if (null != fragments && !fragments.isEmpty()) {
        mViewPager.setEnableScroll(false);
        mViewPager.setOffscreenPageLimit(fragments.size());
        mViewPager.setAdapter(new VPFragmentAdapter(getSupportFragmentManager(), fragments));
    }
    mNavListAdapter = new ListViewDataAdapter<NavigationEntity>(new ViewHolderCreator<NavigationEntity>() {

        @Override
        public ViewHolderBase<NavigationEntity> createViewHolder(int position) {
            return new ViewHolderBase<NavigationEntity>() {

                ImageView itemIcon;

                TextView itemName;

                @Override
                public View createView(LayoutInflater layoutInflater) {
                    View convertView = layoutInflater.inflate(R.layout.list_item_navigation, null);
                    itemIcon = ButterKnife.findById(convertView, R.id.list_item_navigation_icon);
                    itemName = ButterKnife.findById(convertView, R.id.list_item_navigation_name);
                    return convertView;
                }

                @Override
                public void showData(int i, NavigationEntity navigationEntity) {
                    itemIcon.setImageResource(navigationEntity.getIconResId());
                    itemName.setText(navigationEntity.getName());
                    if (mCurrentMenuCheckedPos == i) {
                        // checked
                        itemName.setTextColor(getResources().getColor(mCheckedListItemColorResIds[i]));
                    } else {
                        // unchecked
                        itemName.setTextColor(getResources().getColor(android.R.color.black));
                    }
                }
            };
        }
    });
    mNavListView.setAdapter(mNavListAdapter);
    mNavListAdapter.getDataList().addAll(navigationList);
    mNavListAdapter.notifyDataSetChanged();
    setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
    mNavListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mCurrentMenuCheckedPos = position;
            mNavListAdapter.notifyDataSetChanged();
            mDrawerLayout.closeDrawer(Gravity.LEFT);
            mViewPager.setCurrentItem(mCurrentMenuCheckedPos, false);
        }
    });
}
Also used : ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) HomeView(com.github.obsessive.simplifyreader.view.HomeView) TextView(android.widget.TextView) ListView(android.widget.ListView) NavigationEntity(com.github.obsessive.simplifyreader.bean.NavigationEntity) VPFragmentAdapter(com.github.obsessive.simplifyreader.ui.adpter.VPFragmentAdapter) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator)

Example 3 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project GeekNews by codeestX.

the class MainActivity method initEventAndData.

@Override
protected void initEventAndData() {
    setToolBar(mToolbar, "知乎日报");
    mZhihuFragment = new ZhihuMainFragment();
    mGankFragment = new GankMainFragment();
    mWechatFragment = new WechatMainFragment();
    mGoldFragment = new GoldMainFragment();
    mVtexFragment = new VtexMainFragment();
    mLikeFragment = new LikeFragment();
    mSettingFragment = new SettingFragment();
    mAboutFragment = new AboutFragment();
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
    mDrawerToggle.syncState();
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mLastMenuItem = mNavigationView.getMenu().findItem(R.id.drawer_zhihu);
    loadMultipleRootFragment(R.id.fl_main_content, 0, mZhihuFragment, mWechatFragment, mGankFragment, mGoldFragment, mVtexFragment, mLikeFragment, mSettingFragment, mAboutFragment);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch(menuItem.getItemId()) {
                case R.id.drawer_zhihu:
                    showFragment = Constants.TYPE_ZHIHU;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_gank:
                    showFragment = Constants.TYPE_GANK;
                    mSearchMenuItem.setVisible(true);
                    break;
                case R.id.drawer_wechat:
                    showFragment = Constants.TYPE_WECHAT;
                    mSearchMenuItem.setVisible(true);
                    break;
                case R.id.drawer_gold:
                    showFragment = Constants.TYPE_GOLD;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_vtex:
                    showFragment = Constants.TYPE_VTEX;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_setting:
                    showFragment = Constants.TYPE_SETTING;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_like:
                    showFragment = Constants.TYPE_LIKE;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_about:
                    showFragment = Constants.TYPE_ABOUT;
                    mSearchMenuItem.setVisible(false);
                    break;
            }
            if (mLastMenuItem != null) {
                mLastMenuItem.setChecked(false);
            }
            mLastMenuItem = menuItem;
            SharedPreferenceUtil.setCurrentItem(showFragment);
            menuItem.setChecked(true);
            mToolbar.setTitle(menuItem.getTitle());
            mDrawerLayout.closeDrawers();
            showHideFragment(getTargetFragment(showFragment), getTargetFragment(hideFragment));
            hideFragment = showFragment;
            return true;
        }
    });
    mSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (showFragment == Constants.TYPE_GANK) {
                mGankFragment.doSearch(query);
            } else if (showFragment == Constants.TYPE_WECHAT) {
                RxBus.getDefault().post(new SearchEvent(query, Constants.TYPE_WECHAT));
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    if (!SharedPreferenceUtil.getVersionPoint() && SystemUtil.isWifiConnected()) {
        SharedPreferenceUtil.setVersionPoint(true);
        try {
            PackageManager pm = getPackageManager();
            PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
            String versionName = pi.versionName;
            mPresenter.checkVersion(versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
Also used : GankMainFragment(com.codeest.geeknews.ui.gank.fragment.GankMainFragment) AboutFragment(com.codeest.geeknews.ui.main.fragment.AboutFragment) SettingFragment(com.codeest.geeknews.ui.main.fragment.SettingFragment) NavigationView(android.support.design.widget.NavigationView) PackageInfo(android.content.pm.PackageInfo) WechatMainFragment(com.codeest.geeknews.ui.wechat.fragment.WechatMainFragment) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) VtexMainFragment(com.codeest.geeknews.ui.vtex.fragment.VtexMainFragment) MenuItem(android.view.MenuItem) SearchEvent(com.codeest.geeknews.model.event.SearchEvent) PackageManager(android.content.pm.PackageManager) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) GoldMainFragment(com.codeest.geeknews.ui.gold.fragment.GoldMainFragment) ZhihuMainFragment(com.codeest.geeknews.ui.zhihu.fragment.ZhihuMainFragment) LikeFragment(com.codeest.geeknews.ui.main.fragment.LikeFragment)

Example 4 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project Android-PanesLibrary by cricklet.

the class PhoneDelegate method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    if (findViewById(R.id.content_frame) == null)
        setContentView(R.layout.phone_layout);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    drawerToggle = new ActionBarDrawerToggle(getActivity(), drawer, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {

        public void onDrawerClosed(View view) {
            supportInvalidateOptionsMenu();
        // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            supportInvalidateOptionsMenu();
        // creates call to onPrepareOptionsMenu()
        }
    };
    drawer.setDrawerListener(drawerToggle);
    FragmentManager fm = getSupportFragmentManager();
    fm.addOnBackStackChangedListener(this);
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View)

Example 5 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project AnimeTaste by daimajia.

the class StartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = this;
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    mVideoList = (ListView) findViewById(R.id.videoList);
    mDrawerList = (ListView) findViewById(R.id.function_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);
    mLayoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mCategoryList = (ListView) findViewById(R.id.category_list);
    mFooterView = mLayoutInflater.inflate(R.layout.load_item, null);
    mLoadProgress = (ProgressBar) mFooterView.findViewById(R.id.loading);
    mLoadText = (TextView) mFooterView.findViewById(R.id.load_text);
    mVideoList.addFooterView(mFooterView);
    mVideoList.setOnScrollListener(this);
    mDrawer.setOnTouchListener(this);
    View headerView = mLayoutInflater.inflate(R.layout.gallery_item, null, false);
    mVideoList.addHeaderView(headerView);
    mRecommendPager = (ViewPager) headerView.findViewById(R.id.pager);
    mRecommendPager.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            PointF downP = new PointF();
            PointF curP = new PointF();
            int act = event.getAction();
            if (act == MotionEvent.ACTION_DOWN || act == MotionEvent.ACTION_MOVE || act == MotionEvent.ACTION_UP) {
                ((ViewGroup) v).requestDisallowInterceptTouchEvent(true);
                if (downP.x == curP.x && downP.y == curP.y) {
                    return false;
                }
            }
            return false;
        }
    });
    mRecommendIndicator = (UnderlinePageIndicator) headerView.findViewById(R.id.indicator);
    if (getIntent().hasExtra("Success")) {
        init(getIntent());
    } else {
        Toast.makeText(mContext, R.string.init_failed, Toast.LENGTH_SHORT).show();
        finish();
    }
    mDrawerAapter = new SimpleAdapter(this, getDrawerItems(), R.layout.drawer_item, new String[] { "img", "title" }, new int[] { R.id.item_icon, R.id.item_name });
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_action_navigation_menu, R.string.app_name, R.string.app_name) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (mPreviousType != mType || mPreviousCategoryId != mCategoryId) {
                mCurrentPage = 1;
                mIsEnd = false;
                mVideoAdapter.removeAllData();
                mFooterView.findViewById(R.id.loading).setVisibility(View.VISIBLE);
                mFooterView.findViewById(R.id.load_text).setVisibility(View.INVISIBLE);
                triggerApiConnector();
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            mPreviousType = mType;
            mPreviousCategoryId = mCategoryId;
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerList.setAdapter(mDrawerAapter);
    mDrawerList.setOnItemClickListener(this);
    ViewUtils.setListViewHeightBasedOnChildren(mDrawerList);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
    getSupportActionBar().setLogo(R.drawable.rsz_ab_icon);
    rateForUsOrCheckUpdate();
    showWhatsNew();
}
Also used : OnTouchListener(android.view.View.OnTouchListener) PointF(android.graphics.PointF) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) SimpleAdapter(android.widget.SimpleAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) MotionEvent(android.view.MotionEvent)

Aggregations

ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)80 View (android.view.View)76 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)34 TextView (android.widget.TextView)31 NavigationView (android.support.design.widget.NavigationView)30 AdapterView (android.widget.AdapterView)30 ListView (android.widget.ListView)29 Toolbar (android.support.v7.widget.Toolbar)25 DrawerLayout (android.support.v4.widget.DrawerLayout)23 ActionBar (android.support.v7.app.ActionBar)19 ImageView (android.widget.ImageView)16 SharedPreferences (android.content.SharedPreferences)14 Intent (android.content.Intent)12 RecyclerView (android.support.v7.widget.RecyclerView)8 SearchView (android.support.v7.widget.SearchView)8 Handler (android.os.Handler)6 PackageManager (android.content.pm.PackageManager)5 MenuItem (android.view.MenuItem)5 InjectView (butterknife.InjectView)5 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)5