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);
}
}
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));
}
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());
}
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();
}
}
}
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));
}
Aggregations