Example usage for android.view MenuItem setIcon

List of usage examples for android.view MenuItem setIcon

Introduction

In this page you can find the example usage for android.view MenuItem setIcon.

Prototype

public MenuItem setIcon(@DrawableRes int iconRes);

Source Link

Document

Change the icon associated with this item.

Usage

From source file:com.google.appinventor.components.runtime.Form.java

public void addAboutInfoToMenu(Menu menu) {
    MenuItem aboutAppItem = menu.add(Menu.NONE, Menu.NONE, 2, "About this application")
            .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    showAboutApplicationNotification();
                    return true;
                }//ww  w  .  j a  v a 2  s  . c  om
            });
    aboutAppItem.setIcon(android.R.drawable.sym_def_app_icon);
}

From source file:com.google.appinventor.components.runtime.Form.java

public void addExitButtonToMenu(Menu menu) {
    MenuItem stopApplicationItem = menu.add(Menu.NONE, Menu.NONE, Menu.FIRST, "Stop this application")
            .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    showExitApplicationNotification();
                    return true;
                }//from  w w w. ja  va2 s.  c  o m
            });
    stopApplicationItem.setIcon(android.R.drawable.ic_notification_clear_all);
}

From source file:org.alfresco.mobile.android.application.fragments.workflow.task.TaskDetailsFragment.java

public void getMenu(Menu menu) {
    MenuItem mi;

    String processDefinitionKey = WorkflowUtils.getKeyFromProcessDefinitionId(processDefinitionId);

    if (endedAt == null && processDefinitionKey.startsWith(WorkflowModel.KEY_PREFIX_ACTIVITI)) {
        mi = menu.add(Menu.NONE, R.id.menu_process_details, Menu.FIRST, R.string.process_diagram);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }/*  w  w w .j a va 2s  .c  o m*/

    mi = menu.add(Menu.NONE, R.id.menu_process_history, Menu.FIRST + 1, R.string.tasks_history);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    if (currentTask == null || endedAt != null) {
        return;
    }

    // unclaim : I unassign myself (generally created by a pooled process)
    if (currentTask.getAssigneeIdentifier() != null
            && WorkflowModel.FAMILY_PROCESS_POOLED_REVIEW.contains(processDefinitionKey)) {
        mi = menu.add(Menu.NONE, R.id.menu_task_unclaim, Menu.FIRST + 2, R.string.task_unclaim);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    }
    // reassign : I have a task and I decide I dont want to be responsible
    // anymore of this task so I reassign to a specific person
    else if (currentTask.getAssigneeIdentifier() != null) {
        mi = menu.add(Menu.NONE, R.id.menu_task_reassign, Menu.FIRST + 3, R.string.task_reassign);
        mi.setIcon(R.drawable.ic_reassign);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
    // claim : I assign to me an unassigned task (created by a pooled
    // process)
    else if ((currentTask.getAssigneeIdentifier() == null
            && WorkflowModel.FAMILY_PROCESS_POOLED_REVIEW.contains(processDefinitionKey))
            || "unclaimed".equals(state)) {
        mi = menu.add(Menu.NONE, R.id.menu_task_claim, Menu.FIRST + 4, R.string.task_claim);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    }
}

From source file:com.Beat.RingdroidEditActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    MenuItem item;

    item = menu.add(0, CMD_SAVE, 0, R.string.menu_save);
    item.setIcon(R.drawable.menu_save);

    item = menu.add(0, CMD_RESET, 0, R.string.menu_reset);
    item.setIcon(R.drawable.menu_reset);

    item = menu.add(0, CMD_ABOUT, 0, R.string.menu_about);
    item.setIcon(R.drawable.menu_about);

    return true;/*from   www.ja v  a  2s. c o  m*/
}

From source file:org.opendatakit.survey.activities.MainMenuActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    PropertiesSingleton props = CommonToolProperties.get(this, getAppName());

    int showOption = MenuItem.SHOW_AS_ACTION_IF_ROOM;
    MenuItem item;
    if (currentFragment != ScreenList.WEBKIT) {
        ActionBar actionBar = getActionBar();
        actionBar.setCustomView(R.layout.action_bar);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.show();/*  w w w . ja va  2  s  . c  om*/

        item = menu.add(Menu.NONE, MENU_CLOUD_FORMS, Menu.NONE, R.string.sync);
        item.setIcon(R.drawable.ic_cached_black_24dp).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

        item = menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, R.string.about);
        item.setIcon(R.drawable.ic_info_outline_black_24dp).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    } else {
        ActionBar actionBar = getActionBar();
        actionBar.hide();
    }

    return true;
}

From source file:org.dmfs.tasks.ViewTaskFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.edit_task) {
        // open editor for this task
        mCallback.onEditTask(mTaskUri, mContentSet);
        return true;
    } else if (itemId == R.id.delete_task) {
        new AlertDialog.Builder(getActivity()).setTitle(R.string.confirm_delete_title).setCancelable(true)
                .setNegativeButton(android.R.string.cancel, new OnClickListener() {
                    @Override/* w  w w  . j  a v a2 s .  c  o  m*/
                    public void onClick(DialogInterface dialog, int which) {
                        // nothing to do here
                    }
                }).setPositiveButton(android.R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO: remove the task in a background task
                        mContentSet.delete(mAppContext);
                        mCallback.onDelete(mTaskUri);
                    }
                }).setMessage(R.string.confirm_delete_message).create().show();
        return true;
    } else if (itemId == R.id.complete_task) {
        completeTask();
        return true;
    } else if (itemId == R.id.pin_task) {
        if (TaskFieldAdapters.PINNED.get(mContentSet)) {
            item.setIcon(R.drawable.ic_pin_white_24dp);
            TaskNotificationHandler.unpinTask(mAppContext, mContentSet);
        } else {
            item.setIcon(R.drawable.ic_pin_off_white_24dp);
            TaskNotificationHandler.pinTask(mAppContext, mContentSet);
        }
        persistTask();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.spydiko.rotationmanager.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings: // Refresh button
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "action_settings");
        packageManager = getPackageManager();
        UpdateData updateData = new UpdateData();
        this.adapter = new InteractiveArrayAdapter(this, activities, (AppSpecificOrientation) getApplication());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            updateData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
        else//from w w  w. j  a  va  2s .co  m
            updateData.execute((Void[]) null);
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "execute");
        lv.setAdapter(adapter);
        break;
    case R.id.itemToggleService: // Play - Stop Service
        //                if(AppSpecificOrientation.LOG) Log.d(TAG, "entered");
        if (AppSpecificOrientation.isServiceRunning()) {
            item.setTitle(R.string.titleServiceStop);
            //               item.setIcon(android.R.drawable.ic_media_play);
            stopService(new Intent(this, NewOrieService.class));
            AppSpecificOrientation.setServiceRunning(false);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "if");
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_off_button_rotation_manager);
        } else {
            item.setTitle(R.string.titleServiceStart);
            //               item.setIcon(android.R.drawable.ic_media_pause);
            startService(new Intent(this, NewOrieService.class));
            Toast toast = Toast.makeText(this, getString(R.string.notification_text), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
            toast.show();
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_on_button_rotation_manager);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "else");
        }
        break;

    case R.id.setOnBoot: // Set broadcast receiver on or off
        if (AppSpecificOrientation.getBoot()) {
            item.setChecked(false);
            AppSpecificOrientation.setBoot(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setBoot(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
        }

        break;
    case R.id.howTo: // Open How To Activity
        startActivityForResult((new Intent(this, HowToActivity.class)), 1);
        break;
    case R.id.about: // Open About Activity
        startActivityForResult((new Intent(this, AboutActivity.class)), 1);
        break;
    case R.id.donate:
        startActivity(new Intent(this, DonateActivity.class));
        break;
    case R.id.permNotification:
        if (AppSpecificOrientation.isPermNotification()) {
            item.setChecked(false);
            AppSpecificOrientation.setPermNotification(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setPermNotification(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        }

        break;
    case R.id.license:
        startActivity(new Intent(this, License.class));
        break;
    case android.R.id.home:
        menu.toggle();
        return true;
    }
    return true;
}

From source file:org.alfresco.mobile.android.application.fragments.node.details.NodeDetailsFragment.java

public void getMenu(Context context, AlfrescoSession session, Menu menu, Node node) {
    MenuItem mi;

    if (node == null) {
        return;//ww w. j a va2 s .c  o  m
    }
    if (node instanceof NodeSyncPlaceHolder) {
        return;
    }

    boolean isRestrict = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    if (node.isDocument()) {
        if (((Document) node).getContentStreamLength() > 0 && !isRestrict
                && ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
                        ConfigurableActionHelper.ACTION_NODE_DOWNLOAD)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_download, Menu.FIRST, R.string.download);
            mi.setIcon(R.drawable.ic_download_light);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (((Document) node).isLatestVersion() && ConfigurableActionHelper.isVisible(getActivity(),
                getAccount(), getSession(), node, ConfigurableActionHelper.ACTION_NODE_UPDATE)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_update, Menu.FIRST + 130, R.string.update);
            mi.setIcon(R.drawable.ic_upload);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (!(session instanceof CloudSession) && ConfigurableActionHelper.isVisible(getActivity(),
                getAccount(), getSession(), node, ConfigurableActionHelper.ACTION_NODE_REVIEW)) {
            mi = menu.add(Menu.NONE, R.id.menu_workflow_add, Menu.FIRST + 500, R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }

    if (session == null) {
        return;
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_EDIT)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_edit, Menu.FIRST + 10, R.string.edit);
        mi.setIcon(R.drawable.ic_properties);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (node.hasAspect(ContentModel.ASPECT_GEOGRAPHIC)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_location, Menu.FIRST + 50, R.string.geolocation);
        mi.setIcon(R.drawable.ic_location);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_DELETE)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_delete, Menu.FIRST + 1000, R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }
}

From source file:com.artur.softwareproject.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.disconnect:

        if (!recording) {
            stopService(bluetoothServiceIntent);

            final ProgressDialog disconnectingDialog = new ProgressDialog(Main.this);

            disconnectingDialog.setMessage("Disconnecting...");
            disconnectingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            disconnectingDialog.setCancelable(false);
            disconnectingDialog.show();// w w  w  .  j  a  v  a2s . c o m

            disconDialog = disconnectingDialog;

            final DisconnectHandlerClass disconnectHandler = new DisconnectHandlerClass(this);

            disconnectThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    int stop = 0;

                    while (stop == 0) {
                        stop = getDisconnect();
                        sleep(1500);
                    }

                    disconnectHandler.sendEmptyMessage(0);
                }
            });

            disconnectThread.start();
        }

        return true;

    case R.id.record_data:

        Log.d(TAG, "Record button was Pressed. Gps status: " + gpsStatus);

        if (!recording && gpsStatus) {
            Intent resetIntent = new Intent();

            resetIntent.putExtra("reset", "");
            resetIntent.setAction("resetFilter");

            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(resetIntent);

            item.setIcon(R.drawable.ic_action_stop);

            Toast.makeText(getApplicationContext(), "Start recording data", Toast.LENGTH_LONG).show();

            currentTime = System.currentTimeMillis();
            recordClock.setVisibility(View.VISIBLE);

            Animation a = AnimationUtils.loadAnimation(this, R.anim.textslide);
            TextView tv = (TextView) findViewById(R.id.recordClock);

            tv.startAnimation(a);

            recording = true;

            if (!rBound) {
                Intent intent = new Intent(this, RecordService.class);
                bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
            }
        } else if (recording) {
            stopRecording();
        }

        return true;

    case R.id.vr_menu:

        if (!recording) {
            Intent vrIntent = new Intent(Main.this, VRmenuMap.class);
            Main.this.startActivity(vrIntent);
        }

        return true;

    default:

        return super.onOptionsItemSelected(item);
    }
}

From source file:com.hichinaschool.flashcards.anki.CardEditor.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item;
    Resources res = getResources();
    // Lookup.initialize(this, mDeck.getDeckPath());
    // item = menu.add(Menu.NONE, MENU_LOOKUP, Menu.NONE,
    // Lookup.getSearchStringTitle());
    // item.setIcon(R.drawable.ic_menu_search);
    // item.setEnabled(Lookup.isAvailable());
    // item = menu.add(Menu.NONE, MENU_RESET, Menu.NONE,
    // res.getString(R.string.card_editor_reset));
    // item.setIcon(R.drawable.ic_menu_revert);
    if (!mAddNote) {
        item = menu.add(Menu.NONE, MENU_ADD_CARD, Menu.NONE, res.getString(R.string.card_editor_add_card));
        item.setIcon(R.drawable.ic_menu_add);
    }//from  w w w  . ja v  a 2 s  . c  o  m
    item = menu.add(Menu.NONE, MENU_COPY_CARD, Menu.NONE, res.getString(R.string.card_editor_copy_card));
    item.setIcon(R.drawable.ic_menu_upload);
    if (!mAddNote) {
        item = menu.add(Menu.NONE, MENU_RESET_CARD_PROGRESS, Menu.NONE,
                res.getString(R.string.card_editor_reset_card));
        item.setIcon(R.drawable.ic_menu_delete);
    }
    if (mCaller != CALLER_CARDEDITOR_INTENT_ADD) {
        mIntentInformation = MetaDB.getIntentInformation(this);
        item = menu.add(Menu.NONE, MENU_SAVED_INTENT, Menu.NONE,
                res.getString(R.string.intent_add_saved_information));
        item.setIcon(R.drawable.ic_menu_archive);
    }
    return true;
}