Search in sources :

Example 6 with MenuItem

use of android.view.MenuItem in project cw-omnibus by commonsguy.

the class QuestionsFragment method configureSearchView.

private void configureSearchView(Menu menu) {
    MenuItem search = menu.findItem(R.id.search);
    search.setOnActionExpandListener(this);
    sv = (SearchView) search.getActionView();
    sv.setOnQueryTextListener(this);
    sv.setSubmitButtonEnabled(true);
    sv.setIconifiedByDefault(true);
    if (initialQuery != null) {
        sv.setIconified(false);
        search.expandActionView();
        sv.setQuery(initialQuery, true);
    }
}
Also used : MenuItem(android.view.MenuItem)

Example 7 with MenuItem

use of android.view.MenuItem in project cw-omnibus by commonsguy.

the class MainActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.actions, menu);
    MenuItem item = menu.findItem(R.id.share);
    share = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    share.setOnShareTargetSelectedListener(this);
    return (super.onCreateOptionsMenu(menu));
}
Also used : MenuItem(android.view.MenuItem)

Example 8 with MenuItem

use of android.view.MenuItem in project PhotoView by chrisbanes.

the class SimpleSampleActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Simple Sample");
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    toolbar.inflateMenu(R.menu.main_menu);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.menu_zoom_toggle:
                    mPhotoView.setZoomable(!mPhotoView.isZoomEnabled());
                    item.setTitle(mPhotoView.isZoomEnabled() ? R.string.menu_zoom_disable : R.string.menu_zoom_enable);
                    return true;
                case R.id.menu_scale_fit_center:
                    mPhotoView.setScaleType(ImageView.ScaleType.CENTER);
                    return true;
                case R.id.menu_scale_fit_start:
                    mPhotoView.setScaleType(ImageView.ScaleType.FIT_START);
                    return true;
                case R.id.menu_scale_fit_end:
                    mPhotoView.setScaleType(ImageView.ScaleType.FIT_END);
                    return true;
                case R.id.menu_scale_fit_xy:
                    mPhotoView.setScaleType(ImageView.ScaleType.FIT_XY);
                    return true;
                case R.id.menu_scale_scale_center:
                    mPhotoView.setScaleType(ImageView.ScaleType.CENTER);
                    return true;
                case R.id.menu_scale_scale_center_crop:
                    mPhotoView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    return true;
                case R.id.menu_scale_scale_center_inside:
                    mPhotoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                    return true;
                case R.id.menu_scale_random_animate:
                case R.id.menu_scale_random:
                    Random r = new Random();
                    float minScale = mPhotoView.getMinimumScale();
                    float maxScale = mPhotoView.getMaximumScale();
                    float randomScale = minScale + (r.nextFloat() * (maxScale - minScale));
                    mPhotoView.setScale(randomScale, item.getItemId() == R.id.menu_scale_random_animate);
                    showToast(String.format(SCALE_TOAST_STRING, randomScale));
                    return true;
                case R.id.menu_matrix_restore:
                    if (mCurrentDisplayMatrix == null)
                        showToast("You need to capture display matrix first");
                    else
                        mPhotoView.setDisplayMatrix(mCurrentDisplayMatrix);
                    return true;
                case R.id.menu_matrix_capture:
                    mCurrentDisplayMatrix = new Matrix();
                    mPhotoView.getDisplayMatrix(mCurrentDisplayMatrix);
                    return true;
            }
            return false;
        }
    });
    mPhotoView = (PhotoView) findViewById(R.id.iv_photo);
    mCurrMatrixTv = (TextView) findViewById(R.id.tv_current_matrix);
    Drawable bitmap = ContextCompat.getDrawable(this, R.drawable.wallpaper);
    mPhotoView.setImageDrawable(bitmap);
    // Lets attach some listeners, not required though!
    mPhotoView.setOnMatrixChangeListener(new MatrixChangeListener());
    mPhotoView.setOnPhotoTapListener(new PhotoTapListener());
    mPhotoView.setOnSingleFlingListener(new SingleFlingListener());
}
Also used : Matrix(android.graphics.Matrix) Random(java.util.Random) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) OnPhotoTapListener(com.github.chrisbanes.photoview.OnPhotoTapListener) OnSingleFlingListener(com.github.chrisbanes.photoview.OnSingleFlingListener) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 9 with MenuItem

use of android.view.MenuItem 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 10 with MenuItem

use of android.view.MenuItem in project cw-omnibus by commonsguy.

the class AbstractDragDropDemoActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    new MenuInflater(this).inflate(R.menu.actions, menu);
    MenuItem item = menu.findItem(getOwnMenuId());
    if (item != null) {
        item.setVisible(false);
    }
    return (super.onCreateOptionsMenu(menu));
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem)

Aggregations

MenuItem (android.view.MenuItem)713 View (android.view.View)125 Intent (android.content.Intent)75 TextView (android.widget.TextView)66 ImageView (android.widget.ImageView)55 PopupMenu (android.widget.PopupMenu)54 Menu (android.view.Menu)47 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 SearchView (android.support.v7.widget.SearchView)41 RecyclerView (android.support.v7.widget.RecyclerView)32 MenuInflater (android.view.MenuInflater)29 AdapterView (android.widget.AdapterView)27 ListView (android.widget.ListView)27 SubMenu (android.view.SubMenu)26 ComponentName (android.content.ComponentName)25 PackageManager (android.content.pm.PackageManager)24 Parcelable (android.os.Parcelable)23 Toolbar (android.support.v7.widget.Toolbar)19 ResolveInfo (android.content.pm.ResolveInfo)18 Bundle (android.os.Bundle)18