Java Code Examples for android.view.MenuItem#setActionView()

The following examples show how to use android.view.MenuItem#setActionView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntryListFragment.java    From android-BasicSyncAdapter with Apache License 2.0 6 votes vote down vote up
/**
 * Set the state of the Refresh button. If a sync is active, turn on the ProgressBar widget.
 * Otherwise, turn it off.
 *
 * @param refreshing True if an active sync is occuring, false otherwise
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void setRefreshActionButtonState(boolean refreshing) {
    if (mOptionsMenu == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return;
    }

    final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
    if (refreshItem != null) {
        if (refreshing) {
            refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
        } else {
            refreshItem.setActionView(null);
        }
    }
}
 
Example 2
Source File: TimelineFragment.java    From catnut with MIT License 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	menu.add(Menu.NONE, R.id.refresh, Menu.NONE, R.string.refresh)
			.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); // prefer actionbar refresh
	menu.add(Menu.NONE, R.id.action_back_top, Menu.NONE, getString(R.string.back_to_top))
			.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
	// 本地微博搜索
	MenuItem search = menu.add(android.R.string.search_go);
	search.setIcon(R.drawable.ic_title_search_default);
	search.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
			| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	mSearchView = VividSearchView.getSearchView(getActivity());
	mSearchView.setOnQueryTextListener(this);
	mSearchView.setOnCloseListener(this);
	search.setActionView(mSearchView);
}
 
Example 3
Source File: EditCameraLocationActivity.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.activity_edit_camera_location, menu);

    MenuItem supportMenuItem = menu.findItem(R.id.menu_action_support);
    if (supportMenuItem != null) {
        LinearLayout menuLayout = (LinearLayout) LayoutInflater.from(this)
                .inflate(R.layout.edit_location_menu_item, null);
        supportMenuItem.setActionView(menuLayout);
        supportMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        menuLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PatchCameraBuilder patchCameraBuilder = buildPatchCameraWithLocalCheck();
                if (patchCameraBuilder != null) {
                    new PatchCameraTask(patchCameraBuilder.build(),
                            EditCameraLocationActivity.this).executeOnExecutor(AsyncTask
                            .THREAD_POOL_EXECUTOR);
                } else {
                    Log.e("Log", "Camera to patch is null");
                }
            }
        });
    }
    return true;
}
 
Example 4
Source File: CreateGroupChatActivity.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_confirm, menu);
    ProgressBar pb = new ProgressBar(this);
    MenuItem progressItem = menu.findItem(R.id.menu_confirm_progress);
    int px = (int) (24 * Resources.getSystem().getDisplayMetrics().density);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(3*px, 3*px);
    pb.setLayoutParams(lp);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        pb.setIndeterminateTintList(
            ColorStateList.valueOf(0xff000000)
        );
    }
    pb.setPaddingRelative(px, px, px, px);
    progressItem.setActionView(pb);
    return true;
}
 
Example 5
Source File: ProfileActivity.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
	if (isLoading)
	{
		MenuItem refreshItem = menu.add(Menu.NONE, R.id.menu_refresh, 1, R.string.refresh);
		refreshItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		refreshItem.setActionView(R.layout.actionbar_item_refresh);
	}

	return super.onCreateOptionsMenu(menu);
}
 
Example 6
Source File: MapFragment.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
public void setRefreshActionButtonState(final boolean refreshing) {
    if (mOptionsMenu != null) {
        final MenuItem refreshItem = mOptionsMenu.findItem(R.id.get_opencellid);
        if (refreshItem != null) {
            if (refreshing) {
                refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
            } else {
                refreshItem.setActionView(null);
            }
        }
    }
}
 
Example 7
Source File: ShadowSupportMenuInflater.java    From open with GNU General Public License v3.0 5 votes vote down vote up
private void addActionViewToItem(MenuItem item, RoboAttributeSet attributes) {
    String actionViewClassName = attributes.getAttributeValue(APP_NS, "actionViewClass");
    if (actionViewClassName != null) {
        try {
            View actionView = (View) Class.forName(actionViewClassName)
                    .getConstructor(Context.class)
                    .newInstance(context);
            item.setActionView(actionView);
        } catch (Exception e) {
            throw new RuntimeException("Action View class not found!", e);
        }
    }
}
 
Example 8
Source File: SyncCapableCommCareActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void addAnimationToMenuItem(MenuItem menuItem, @LayoutRes int layoutResource,
                                    @AnimRes int animationId) {
    LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ImageView iv = (ImageView)inflater.inflate(layoutResource, null);
    Animation animation = AnimationUtils.loadAnimation(this, animationId);
    iv.startAnimation(animation);
    menuItem.setActionView(iv);
}
 
Example 9
Source File: SyncCapableCommCareActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void clearCurrentAnimation(MenuItem item) {
    if (item != null && item.getActionView() != null) {
        item.getActionView().clearAnimation();
        item.setActionView(null);
    }
}
 
Example 10
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void onRefresh(boolean isRefresh) {
    MenuItem refreshItem = mToolbar.getMenu().findItem(R.id.menu_refresh);
    if (null != refreshItem) {
        if (isRefresh) {
            if (refreshItem.getActionView() == null) {
                refreshItem.setActionView(R.layout.layout_refresh);
                ProgressBar progress = (ProgressBar) refreshItem.getActionView().findViewById(R.id.refreshingProgress);
                if (progress != null)
                    progress.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(this, R.color.color_grey_200), PorterDuff.Mode.SRC_IN);
            }
        } else
            stopRefresh(refreshItem);
    }
}
 
Example 11
Source File: MotionSampleActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.motion_parallax, menu);

    // Add parallax toggle
    final Switch mParallaxToggle = new Switch(getActivity());
    mParallaxToggle.setPadding(0, 0, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getResources().getDisplayMetrics()), 0);
    mParallaxToggle.setChecked(mParallaxSet);
    mParallaxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mBackground.registerSensorManager();
            } else {
                mBackground.unregisterSensorManager();
            }

            mParallaxSet = isChecked;
        }
    });
    MenuItem switchItem = menu.findItem(R.id.action_parallax);
    if (switchItem != null)
        switchItem.setActionView(mParallaxToggle);

    // Set lock/ unlock orientation text
    if (mPortraitLock) {
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        MenuItem orientationItem = menu.findItem(R.id.action_portrait);
        if (orientationItem != null)
            orientationItem.setTitle("action_unlock_portrait");
    }
}
 
Example 12
Source File: TaskEditActivity.java    From Kandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case android.R.id.home:
            onBackPressed();
            return true;
        case R.id.action_save:
            ownerId = spinnerProjectUsers.getSelectedItemPosition();
            if (spinnerProjectUsers.getSelectedItemPosition() != 0) {
                for (Enumeration<Integer> iter = projectUsers.keys(); iter.hasMoreElements();) {
                    Integer key = iter.nextElement();
                    if (projectUsers.get(key).contentEquals((String) spinnerProjectUsers.getSelectedItem())) {
                        ownerId = key;
                        break;
                    }
                }
            }
            if (isNewTask) {
                kanboardAPI.createTask(editTextTitle.getText().toString(), projectid, colorId != null ? colorId : defaultColor, columnId, ownerId, null, dueDate, editTextDescription.getText().toString(), null, null, swimlaneId, null, null, null, null, null, null, null, startDate);

            } else {
                kanboardAPI.updateTask(task.getId(), editTextTitle.getText().toString(), colorId != null ? colorId : defaultColor, ownerId, dueDate, editTextDescription.getText().toString(), null, null, null, null, null, null, null, null, null, startDate);
            }
            ProgressBar prog = new ProgressBar(TaskEditActivity.this);
            prog.getIndeterminateDrawable().setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.MULTIPLY);
            item.setActionView(prog);
            item.expandActionView();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 13
Source File: SettingsActivity.java    From AnkiDroid-Wear with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.clear();
    super.onCreateOptionsMenu(menu);
    //inflate a menu which shows the non-animated refresh icon
    getMenuInflater().inflate(R.menu.menu_settings, menu);

    if(rotation == null){
        rotation = AnimationUtils.loadAnimation(this, R.anim.refresh_animation);
        rotation.setRepeatCount(Animation.INFINITE);
    }

    MenuItem item = menu.findItem(R.id.sendIcon);
    item.setActionView(R.layout.action_bar_indeterminate_progress);
    sendingIndicator = (ImageView) item.getActionView().findViewById(R.id.loadingImageView);
    if (isRefreshing) {
        rotation.setRepeatCount(Animation.INFINITE);
        sendingIndicator.startAnimation(rotation);
    }
        if(rotation != null)rotation.setRepeatCount(0);
        item.getActionView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!isRefreshing) {
                    sendPreferencesToWatch();
                    isRefreshing = true;
                    rotation.setRepeatCount(Animation.INFINITE);
                    sendingIndicator.startAnimation(rotation);
                }
            }
        });


    return true;
}
 
Example 14
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected void stopRefresh(final MenuItem refreshItem) {
    Handler handler = new Handler(Looper.getMainLooper());
    final Runnable r = new Runnable() {
        public void run() {
            if (refreshItem != null && refreshItem.getActionView() != null) {
                refreshItem.getActionView().clearAnimation();
                refreshItem.setActionView(null);
            }
        }
    };
    handler.post(r);
}
 
Example 15
Source File: FeedDetailActivity.java    From v2ex with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.feeds, menu);

    MenuItem refreshMenu = menu.findItem(R.id.menu_refresh);
    if (isRefreshing()) {
        refreshMenu.setVisible(true);
        refreshMenu.setActionView(R.layout.progress_bar);
    }

    return true;
}
 
Example 16
Source File: ScanActivity.java    From easyble-x with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.scan, menu);
    MenuItem item = menu.findItem(R.id.menuProgress);
    item.setActionView(R.layout.toolbar_indeterminate_progress);
    item.setVisible(EasyBLE.getInstance().isScanning());
    return super.onCreateOptionsMenu(menu);
}
 
Example 17
Source File: MainActivity.java    From Klyph with MIT License 4 votes vote down vote up
public boolean onCreateOptionsMenu(Menu menu)
{
	if (notificationsFragment != null && menu.findItem(R.id.menu_notifications) == null)
	{
		final MenuItem notificationItem = menu.add(Menu.NONE, R.id.menu_notifications, 2, R.string.menu_notifications);
		notificationItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		notificationItem.setActionView(R.layout.actionbar_item_notifications);

		final TextView notificationTextView = (TextView) notificationItem.getActionView().findViewById(R.id.textView);

		int count = notificationsFragment.getUnreadCount();

		notificationTextView.setText(String.valueOf(count));

		if (count > 0)
		{
			notificationTextView.setBackgroundResource(AttrUtil.getResourceId(this, R.attr.notificationsItemBackground));
		}
		else
		{
			notificationTextView.setBackgroundResource(R.drawable.notifications_read_background);

		}

		notificationItem.getActionView().setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v)
			{
				onOptionsItemSelected(notificationItem);
			}
		});
	}

	if (!KlyphFlags.IS_PRO_VERSION && menu.findItem(R.id.menu_buy_pro) == null)
	{
		menu.add(Menu.NONE, R.id.menu_buy_pro, 2, R.string.menu_buy_pro).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
	}

	if (menu.findItem(R.id.menu_faq) == null)
	{
		menu.add(Menu.NONE, R.id.menu_faq, Menu.NONE, R.string.menu_faq).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
	}

	return super.onCreateOptionsMenu(menu);
}
 
Example 18
Source File: MenuItemCompatHoneycomb.java    From guideshow with MIT License 4 votes vote down vote up
public static MenuItem setActionView(MenuItem item, int resId) {
    return item.setActionView(resId);
}
 
Example 19
Source File: MenuItemCompatHoneycomb.java    From guideshow with MIT License 4 votes vote down vote up
public static MenuItem setActionView(MenuItem item, View view) {
    return item.setActionView(view);
}
 
Example 20
Source File: MenuItemCompatHoneycomb.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static MenuItem setActionView(MenuItem item, View view) {
    return item.setActionView(view);
}