Example usage for android.view MenuItem setVisible

List of usage examples for android.view MenuItem setVisible

Introduction

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

Prototype

public MenuItem setVisible(boolean visible);

Source Link

Document

Sets the visibility of the menu item.

Usage

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    if (v == getListView()) {

        if (info.position > mAdapter_Accounts.getCount() + 5) {

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

            FolderInfoHolder folder = (FolderInfoHolder) mAdapter
                    .getItem(info.position - (mAdapter_Accounts.getCount() + 6));

            menu.setHeaderTitle(folder.displayName);

        } else if (info.position < mAdapter_Accounts.getCount()) {

            menu.setHeaderTitle(R.string.accounts_context_menu_title);

            if (mAdapter_Accounts == null) {

                Log.d("info =", "mAdapter_Accounts = null");

            }/*w ww .j a  v  a 2 s .  c  o  m*/

            BaseAccount account = (BaseAccount) mergeadapter.getItem(info.position);

            if ((account instanceof Account) && !((Account) account).isEnabled()) {
                getMenuInflater().inflate(R.menu.disabled_accounts_context, menu);
            } else {
                getMenuInflater().inflate(R.menu.accounts_context, menu);
            }

            if (account instanceof SearchAccount) {
                for (int i = 0; i < menu.size(); i++) {
                    android.view.MenuItem item = menu.getItem(i);
                    item.setVisible(false);
                }
            } else {
                EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account);
                if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
                    menu.findItem(R.id.move_up).setEnabled(false);
                } else {
                    menu.findItem(R.id.move_up).setEnabled(true);
                }
                if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) {
                    menu.findItem(R.id.move_down).setEnabled(false);
                } else {
                    menu.findItem(R.id.move_down).setEnabled(true);
                }
            }

        }

    }
}

From source file:com.nest5.businessClient.Initialactivity.java

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    // ////Log.i(TAG, String.valueOf(redeemCoupon));
    if (scanResult != null) {

    }//from  w w  w .  j  a va  2  s .c om

    if (requestCode == RETURN_FROM_DESIGN_TABLE) {
        String result = null;
        if (resultCode == RESULT_OK) {
            result = intent.getStringExtra(Setup.SAVED_TABLES);
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
        if (result != null) {
            //load tables view and allow to make order for it
            showMesasLayout();
        }
    }

    if (requestCode == RETURN_FROM_OPENCLOSE_TABLE) {
        Table actual = null;
        int clientes = 0;
        if (resultCode == RESULT_OK) {
            actual = intent.getParcelableExtra("MIMESA");
            clientes = intent.getIntExtra("MIMESACLIENTES", 0);
            if (actual != null) {
                //load tables view and allow to make order for it
                currentTable = new CurrentTable<Table, Integer>(actual, clientes);
                statusText.setVisibility(View.VISIBLE);
                statusText.setText(actual.getName() + " con " + clientes + " Clientes.");
                //Log.i("MISPRUEBAS",currentTable.getTable().getName());
            }
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }

        if (resultCode == Setup.CLOSE_TABLE) {
            //Log.i("MISPRUEBAS","volviendo de cerrar mesa");
            actual = intent.getParcelableExtra("MIMESA");
            //tomar mesa que se cierra, preguntar si es cancelar venta o pagar, si es cancelar borra de opentables, de orders etc y si es pagar, pone en currentsale y abre dialogo pagar
            if (actual != null) {
                //Log.i("MISPRUEBAS","volviendo de cerrar mesa y no esta nulo");
                //load tables view and allow to make order for it
                currentTable = new CurrentTable<Table, Integer>(actual, 0);
                //Log.i("MISPRUEBAS","regreasa de dar clic en cerrar mesa con: "+currentTable.getTable().getName());
                statusText.setVisibility(View.VISIBLE);
                statusText.setText("Cerrando: " + actual.getName());
                openOtherWindow = true;
                openOtherWindowAction = OPEN_TABLE_ACTION;
            }
        }

    }

    // else continue with any other code you need in the method

    SharedPreferences defaultprefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    boolean layouttables = defaultprefs.getBoolean("arrange_tables", false);
    MenuItem tablelayouts = mMenu.findItem(R.id.layouttables);
    MenuItem showtables = mMenu.findItem(R.id.menu_show_tables);
    boolean change = false;
    if (tablelayouts.isVisible() != layouttables)
        change = true;
    tablelayouts.setVisible(layouttables);
    showtables.setVisible(layouttables);
    if (change) {
        invalidateOptionsMenu();
    }

}

From source file:jmri.enginedriver.throttle.java

/**
 * Display the ESU MCII knob action button if configured
 *
 * @param menu the menu upon which the action should be shown
 *//* www  .ja v  a2  s. co  m*/
private void displayEsuMc2KnobMenuButton(Menu menu) {
    MenuItem mi = menu.findItem(R.id.EsuMc2Knob_button);
    if (mi == null)
        return;

    if (prefs.getBoolean("prefEsuMc2KnobButtonDisplay", false)) {
        mi.setVisible(true);
    } else {
        mi.setVisible(false);
    }
    setEsuMc2KnobButton(menu);

}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

/**
 * Hide menu items not appropriate for the current context.
 * /*from  w  ww  .  ja v  a 2s  . c  o m*/
 * <p>
 * <strong>Note:</strong> Please adjust the comments in
 * {@code res/menu/message_list_option.xml} if you change the visibility of
 * a menu item in this method.
 * </p>
 * 
 * @param mMenu2
 *            The {@link Menu} instance that should be modified. May be
 *            {@code null}; in that case the method does nothing and
 *            immediately returns.
 */
private void configureMenu(android.view.Menu mMenu2) {
    if (mMenu2 == null) {
        return;
    }

    // Set visibility of account/folder settings menu items
    if (mMessageListFragment == null) {
        mMenu2.findItem(R.id.account_settings).setVisible(false);
        mMenu2.findItem(R.id.folder_settings).setVisible(false);
    } else {
        mMenu2.findItem(R.id.account_settings).setVisible(mMessageListFragment.isSingleAccountMode());
        mMenu2.findItem(R.id.folder_settings).setVisible(mMessageListFragment.isSingleFolderMode());
    }

    /*
     * Set visibility of menu items related to the message view
     */

    if (mDisplayMode == DisplayMode.MESSAGE_LIST || mMessageViewFragment == null
            || !mMessageViewFragment.isInitialized()) {
        mMenu2.findItem(R.id.next_message).setVisible(false);
        mMenu2.findItem(R.id.previous_message).setVisible(false);
        mMenu2.findItem(R.id.single_message_options).setVisible(false);
        mMenu2.findItem(R.id.delete).setVisible(false);
        mMenu2.findItem(R.id.composeList).setVisible(false);
        mMenu2.findItem(R.id.composeView).setVisible(false);
        mMenu2.findItem(R.id.archive).setVisible(false);
        mMenu2.findItem(R.id.move).setVisible(false);
        mMenu2.findItem(R.id.copy).setVisible(false);
        mMenu2.findItem(R.id.spam).setVisible(false);
        mMenu2.findItem(R.id.refile).setVisible(false);
        mMenu2.findItem(R.id.toggle_unread).setVisible(false);
        mMenu2.findItem(R.id.select_text).setVisible(false);
        mMenu2.findItem(R.id.toggle_message_view_theme).setVisible(false);
        mMenu2.findItem(R.id.show_headers).setVisible(false);
        mMenu2.findItem(R.id.hide_headers).setVisible(false);

        final int splitBarId = getResources().getIdentifier("split_action_bar", "id", "android");
        final View splitActionBar = findViewById(splitBarId);

        SharedPreferences sharedpref = getSharedPreferences("actionbar_color", Context.MODE_PRIVATE);

        if (!sharedpref.contains("actionbar_color")) {

            if (splitActionBar != null) {

                splitActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#4285f4")));

            }

        } else {

            actionbar_colors = sharedpref.getString("actionbar_color", null);

            if (splitActionBar != null) {

                splitActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(actionbar_colors)));
            }

        }

    } else {
        // hide prev/next buttons in split mode
        if (mDisplayMode != DisplayMode.MESSAGE_VIEW) {
            mMenu2.findItem(R.id.next_message).setVisible(false);
            mMenu2.findItem(R.id.previous_message).setVisible(false);
        } else {
            MessageReference ref = mMessageViewFragment.getMessageReference();
            boolean initialized = (mMessageListFragment != null && mMessageListFragment.isLoadFinished());
            boolean canDoPrev = (initialized && !mMessageListFragment.isFirst(ref));
            boolean canDoNext = (initialized && !mMessageListFragment.isLast(ref));

            MenuItem prev = mMenu2.findItem(R.id.previous_message);
            prev.setEnabled(canDoPrev);
            // prev.getIcon().setAlpha(canDoPrev ? 255 : 127);

            // MenuItem next = menu.findItem(R.id.next_message);
            // next.setEnabled(canDoNext);
            // next.getIcon().setAlpha(canDoNext ? 255 : 127);

            final int splitBarId = getResources().getIdentifier("split_action_bar", "id", "android");
            final View splitActionBar = findViewById(splitBarId);

            if (splitActionBar != null) {

                splitActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
            }

        }

        MenuItem toggleTheme = mMenu2.findItem(R.id.toggle_message_view_theme);
        if (K9.useFixedMessageViewTheme()) {
            toggleTheme.setVisible(false);
        } else {
            // Set title of menu item to switch to dark/light theme
            if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
                toggleTheme.setTitle(R.string.message_view_theme_action_light);
            } else {
                toggleTheme.setTitle(R.string.message_view_theme_action_dark);
            }
            toggleTheme.setVisible(true);
        }

        // Set title of menu item to toggle the read state of the currently
        // displayed message
        if (mMessageViewFragment.isMessageRead()) {
            mMenu2.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_unread_action);
        } else {
            mMenu2.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_read_action);
        }

        // Jellybean has built-in long press selection support
        mMenu2.findItem(R.id.select_text).setVisible(Build.VERSION.SDK_INT < 16);

        mMenu2.findItem(R.id.delete).setVisible(K9.isMessageViewDeleteActionVisible());

        /*
         * Set visibility of copy, move, archive, spam in action bar and
         * refile submenu
         */
        if (mMessageViewFragment.isCopyCapable()) {
            mMenu2.findItem(R.id.copy).setVisible(K9.isMessageViewCopyActionVisible());
            mMenu2.findItem(R.id.refile_copy).setVisible(true);
        } else {
            mMenu2.findItem(R.id.copy).setVisible(false);
            mMenu2.findItem(R.id.refile_copy).setVisible(false);
        }

        if (mMessageViewFragment.isMoveCapable()) {
            boolean canMessageBeArchived = mMessageViewFragment.canMessageBeArchived();
            boolean canMessageBeMovedToSpam = mMessageViewFragment.canMessageBeMovedToSpam();

            mMenu2.findItem(R.id.move).setVisible(K9.isMessageViewMoveActionVisible());
            mMenu2.findItem(R.id.archive)
                    .setVisible(canMessageBeArchived && K9.isMessageViewArchiveActionVisible());
            mMenu2.findItem(R.id.spam)
                    .setVisible(canMessageBeMovedToSpam && K9.isMessageViewSpamActionVisible());

            mMenu2.findItem(R.id.refile_move).setVisible(true);
            mMenu2.findItem(R.id.refile_archive).setVisible(canMessageBeArchived);
            mMenu2.findItem(R.id.refile_spam).setVisible(canMessageBeMovedToSpam);
        } else {
            mMenu2.findItem(R.id.move).setVisible(false);
            mMenu2.findItem(R.id.archive).setVisible(false);
            mMenu2.findItem(R.id.spam).setVisible(false);

            mMenu2.findItem(R.id.refile).setVisible(false);
        }

        if (mMessageViewFragment.allHeadersVisible()) {
            mMenu2.findItem(R.id.show_headers).setVisible(false);
        } else {
            mMenu2.findItem(R.id.hide_headers).setVisible(false);
        }
    }

    /*
     * Set visibility of menu items related to the message list
     */

    // Hide both search menu items by default and enable one when
    // appropriate
    mMenu2.findItem(R.id.search).setVisible(false);
    mMenu2.findItem(R.id.search_remote).setVisible(false);

    if (mDisplayMode == DisplayMode.MESSAGE_VIEW || mMessageListFragment == null
            || !mMessageListFragment.isInitialized()) {
        mMenu2.findItem(R.id.check_mail).setVisible(false);
        mMenu2.findItem(R.id.set_sort).setVisible(false);
        mMenu2.findItem(R.id.select_all).setVisible(false);
        mMenu2.findItem(R.id.send_messages).setVisible(false);
        mMenu2.findItem(R.id.expunge).setVisible(false);
        mMenu2.findItem(R.id.mark_all_as_read).setVisible(false);
        mMenu2.findItem(R.id.show_folder_list).setVisible(false);
    } else {
        mMenu2.findItem(R.id.set_sort).setVisible(true);
        mMenu2.findItem(R.id.select_all).setVisible(true);
        mMenu2.findItem(R.id.composeList).setVisible(true);
        mMenu2.findItem(R.id.mark_all_as_read).setVisible(mMessageListFragment.isMarkAllAsReadSupported());

        if (!mMessageListFragment.isSingleAccountMode()) {
            mMenu2.findItem(R.id.expunge).setVisible(false);
            mMenu2.findItem(R.id.send_messages).setVisible(false);
            mMenu2.findItem(R.id.show_folder_list).setVisible(false);
        } else {
            mMenu2.findItem(R.id.send_messages).setVisible(mMessageListFragment.isOutbox());
            mMenu2.findItem(R.id.expunge).setVisible(
                    mMessageListFragment.isRemoteFolder() && mMessageListFragment.isAccountExpungeCapable());
            mMenu2.findItem(R.id.show_folder_list).setVisible(true);
        }

        mMenu2.findItem(R.id.check_mail).setVisible(mMessageListFragment.isCheckMailSupported());

        // If this is an explicit local search, show the option to search on
        // the server
        if (!mMessageListFragment.isRemoteSearch() && mMessageListFragment.isRemoteSearchAllowed()) {
            mMenu2.findItem(R.id.search_remote).setVisible(true);
        } else if (!mMessageListFragment.isManualSearch()) {
            mMenu2.findItem(R.id.search).setVisible(true);
        }
    }
}

From source file:com.tct.mail.compose.ComposeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    final boolean superCreated = super.onCreateOptionsMenu(menu);
    // Don't render any menu items when there are no accounts.
    if (mAccounts == null || mAccounts.length == 0) {
        return superCreated;
    }/*from  w w w  . j  av  a2s .c o m*/
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.compose_menu, menu);

    /*
     * Start save in the correct enabled state.
     * 1) If a user launches compose from within gmail, save is disabled
     * until they add something, at which point, save is enabled, auto save
     * on exit; if the user empties everything, save is disabled, exiting does not
     * auto-save
     * 2) if a user replies/ reply all/ forwards from within gmail, save is
     * disabled until they change something, at which point, save is
     * enabled, auto save on exit; if the user empties everything, save is
     * disabled, exiting does not auto-save.
     * 3) If a user launches compose from another application and something
     * gets populated (attachments, recipients, body, subject, etc), save is
     * enabled, auto save on exit; if the user empties everything, save is
     * disabled, exiting does not auto-save
     */
    mSave = menu.findItem(R.id.save);
    String action = getIntent() != null ? getIntent().getAction() : null;
    boolean fromWidget = getIntent() != null && getIntent().getBooleanExtra(EXTRA_FROM_EMAIL_WIDGET, false);//TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 ADD
    enableSave(mInnerSavedState != null ? mInnerSavedState.getBoolean(EXTRA_SAVE_ENABLED)
            : ((Intent.ACTION_SEND.equals(action) && !fromWidget) //TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 MOD
                    || Intent.ACTION_SEND_MULTIPLE.equals(action) || Intent.ACTION_SENDTO.equals(action)
                    || shouldSave()));

    final MenuItem helpItem = menu.findItem(R.id.help_info_menu_item);
    final MenuItem sendFeedbackItem = menu.findItem(R.id.feedback_menu_item);
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_S
    //For feature:long click the attachment icon menu can show the menu discription,
    //we should remove its useless sub menu.
    //        final MenuItem attachFromServiceItem = menu.findItem(R.id.attach_from_service_stub1);
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_E
    //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398)
    MenuItem priority = menu.findItem(R.id.priority);
    if (priority != null) {
        // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_S
        //priority.setVisible(getResources().getBoolean(R.bool.feature_email_priority_on));
        priority.setVisible(PLFUtils.getBoolean(this, "feature_email_priority_on"));
        // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_E
    }
    //[FEATURE]-Add-END by TSCD.chao zhang
    if (helpItem != null) {
        helpItem.setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT));
    }
    if (sendFeedbackItem != null) {
        sendFeedbackItem
                .setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK));
    }
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_S
    //For feature:long click the attachment icon menu can show the menu discription,
    //we should remove its useless sub menu.
    //        if (attachFromServiceItem != null) {
    //            attachFromServiceItem.setVisible(shouldEnableAttachFromServiceMenu(mAccount));
    //        }
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_E

    //TS: yanhua.chen 2015-4-30 EMAIL BUGFIX_989399 MOD_S
    // Show attach picture on pre-K devices.
    //menu.findItem(R.id.add_photo_attachment).setVisible(!Utils.isRunningKitkatOrLater());
    //TS: yanhua.chen 2015-4-30 EMAIL BUGFIX_989399 MOD_E

    // TS: Gantao 2015-10-30 EMAIL FEATURE_1104470 ADD_S
    MenuItem saveGroupItem = menu.findItem(R.id.group);
    if (saveGroupItem != null) {
        saveGroupItem.setVisible(PLFUtils.getBoolean(this, "feature_email_save_group"));
    }
    // TS: Gantao 2015-10-30 EMAIL FEATURE_1104470 ADD_E

    return true;
}

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

/**
 * Shows a test question on screen/*from   w w w.j a va  2 s.co m*/
 *
 * @param pos Question's position in questions's list of the test
 */
private void showQuestion(int pos) {
    TestQuestion question = test.getQuestions().get(pos);
    List<TestAnswer> answers = question.getAnswers();
    TestAnswer a;
    ScrollView scrollContent = (ScrollView) findViewById(R.id.testMakeScroll);
    LinearLayout testMakeList = (LinearLayout) findViewById(R.id.testMakeList);
    TextView stem = (TextView) findViewById(R.id.testMakeQuestionStem);
    TextView questionFeedback = (TextView) findViewById(R.id.testMakeQuestionFeedback);
    TextView answerFeedback = (TextView) findViewById(R.id.testMakeAnswerFeedback);
    TextView score = (TextView) findViewById(R.id.testMakeQuestionScore);
    TextView textCorrectAnswer = (TextView) findViewById(R.id.testMakeCorrectAnswer);
    EditText textAnswer = (EditText) findViewById(R.id.testMakeEditText);
    ImageView img = (ImageView) findViewById(R.id.testMakeCorrectAnswerImage);
    MenuItem actionScoreItem = menu.findItem(R.id.action_score);
    CheckedAnswersArrayAdapter checkedAnswersAdapter;
    String answerType = question.getAnswerType();
    String feedback = test.getFeedback();
    String questionFeedbackText = question.getFeedback();
    String correctAnswer = "";
    int numAnswers = answers.size();
    Float questionScore;
    DecimalFormat df = new DecimalFormat("0.00");
    int feedbackLevel;
    int mediumFeedbackLevel = Test.FEEDBACK_VALUES.indexOf(Test.FEEDBACK_MEDIUM);
    int maxFeedbackLevel = Test.FEEDBACK_VALUES.indexOf(Test.FEEDBACK_MAX);

    scrollContent.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            findViewById(R.id.testMakeList).getParent().requestDisallowInterceptTouchEvent(false);
            return false;
        }
    });
    testMakeList.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // Disallow the touch request for parent scroll on touch of child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

    questionFeedback.setVisibility(View.GONE);
    answerFeedback.setVisibility(View.GONE);
    textAnswer.setVisibility(View.GONE);
    textCorrectAnswer.setVisibility(View.GONE);
    testMakeList.setVisibility(View.GONE);
    img.setVisibility(View.GONE);

    testMakeList.removeAllViews();
    stem.setText(Html.fromHtml(question.getStem()));

    if ((questionFeedbackText != null) && (!questionFeedbackText.equals(Constants.NULL_VALUE))) {
        questionFeedback.setText(Html.fromHtml(questionFeedbackText));
    }

    feedbackLevel = Test.FEEDBACK_VALUES.indexOf(feedback);

    if (test.isEvaluated() && (feedbackLevel == maxFeedbackLevel)
            && !question.getFeedback().equals(Constants.NULL_VALUE)) {
        questionFeedback.setVisibility(View.VISIBLE);
    } else {
        questionFeedback.setVisibility(View.GONE);
    }

    if (answerType.equals(TestAnswer.TYPE_TEXT) || answerType.equals(TestAnswer.TYPE_INT)
            || answerType.equals(TestAnswer.TYPE_FLOAT)) {

        if (answerType.equals(TestAnswer.TYPE_INT)) {
            textAnswer.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
        } else if (answerType.equals(TestAnswer.TYPE_FLOAT)) {
            textAnswer.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                    | InputType.TYPE_NUMBER_FLAG_SIGNED);
        } else {
            textAnswer.setInputType(InputType.TYPE_CLASS_TEXT);
        }

        a = answers.get(0);
        textAnswer.setText(a.getUserAnswer());
        textAnswer.setVisibility(View.VISIBLE);

        answerFeedback.setText(Html.fromHtml(a.getFeedback()));

        if (test.isEvaluated() && (feedbackLevel > mediumFeedbackLevel)) {
            if (answerType.equals(TestAnswer.TYPE_FLOAT)) {
                correctAnswer = "[" + a.getAnswer() + ";" + answers.get(1).getAnswer() + "]";

                if ((feedbackLevel == maxFeedbackLevel) && !a.getFeedback().equals(Constants.NULL_VALUE)) {
                    answerFeedback.setVisibility(View.VISIBLE);
                } else {
                    answerFeedback.setVisibility(View.GONE);
                }
            } else {
                for (int i = 0; i < numAnswers; i++) {
                    a = answers.get(i);

                    if ((feedbackLevel == maxFeedbackLevel) && !a.getFeedback().equals(Constants.NULL_VALUE)) {
                        correctAnswer += "<strong>" + a.getAnswer() + "</strong><br/>";
                        correctAnswer += "<i>" + a.getFeedback() + "</i><br/><br/>";
                    } else {
                        correctAnswer += a.getAnswer() + "<br/>";
                    }
                }
            }

            textCorrectAnswer.setText(Html.fromHtml(correctAnswer));
            textCorrectAnswer.setVisibility(View.VISIBLE);
        }
    } else if (answerType.equals(TestAnswer.TYPE_MULTIPLE_CHOICE)) {
        checkedAnswersAdapter = new CheckedAnswersArrayAdapter(this, R.layout.list_item_multiple_choice,
                answers, test.isEvaluated(), test.getFeedback(), answerType);

        for (int i = 0; i < numAnswers; i++) {
            a = answers.get(i);
            CheckableLinearLayout item = (CheckableLinearLayout) checkedAnswersAdapter.getView(i, null, null);
            item.setChecked(Utils.parseStringBool(a.getUserAnswer()));
            testMakeList.addView(item);
        }

        testMakeList.setVisibility(View.VISIBLE);
    } else {
        if (answerType.equals(TestAnswer.TYPE_TRUE_FALSE) && (numAnswers < 2)) {
            if (answers.get(0).getAnswer().equals(TestAnswer.VALUE_TRUE)) {
                answers.add(1,
                        new TestAnswer(0, 1, 0, false, TestAnswer.VALUE_FALSE, answers.get(0).getFeedback()));
            } else {
                answers.add(0,
                        new TestAnswer(0, 0, 0, false, TestAnswer.VALUE_TRUE, answers.get(0).getFeedback()));
            }

            numAnswers = 2;
        }

        checkedAnswersAdapter = new CheckedAnswersArrayAdapter(this, R.layout.list_item_single_choice, answers,
                test.isEvaluated(), test.getFeedback(), answerType);

        for (int i = 0; i < numAnswers; i++) {
            a = answers.get(i);
            CheckableLinearLayout item = (CheckableLinearLayout) checkedAnswersAdapter.getView(i, null, null);
            item.setChecked(a.getAnswer().equals(answers.get(0).getUserAnswer()));
            testMakeList.addView(item);
        }

        testMakeList.setVisibility(View.VISIBLE);
    }

    if (test.isEvaluated() && (feedbackLevel > mediumFeedbackLevel)) {
        textAnswer.setEnabled(false);
        textAnswer.setOnClickListener(null);

        if (feedback.equals(Test.FEEDBACK_HIGH)) {
            img.setImageResource(R.drawable.btn_check_buttonless_on);
            if (!answerType.equals(TestAnswer.TYPE_TRUE_FALSE)
                    && !answerType.equals(TestAnswer.TYPE_MULTIPLE_CHOICE)
                    && !answerType.equals(TestAnswer.TYPE_UNIQUE_CHOICE)) {

                if (!answers.get(0).isCorrectAnswered()) {
                    img.setImageResource(android.R.drawable.ic_delete);
                }

                img.setVisibility(View.VISIBLE);
            }
        }

        questionScore = test.getQuestionScore(pos);
        if (questionScore > 0) {
            score.setTextColor(getResources().getColor(R.color.green));
        } else if (questionScore < 0) {
            score.setTextColor(getResources().getColor(R.color.red));
        } else {
            score.setTextColor(Color.BLACK);
        }

        score.setText(df.format(questionScore));

        MenuItemCompat.setActionView(actionScoreItem, score);
        actionScoreItem.setVisible(true);
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    ////  w  w w. java 2  s  . com
    menu.clear();

    // load the menu from XML
    getMenuInflater().inflate(R.menu.actionbaricons, menu);

    // NavitOverflowMenuItemID = R.id.item_overflow_menu_button;
    menu.findItem(R.id.share_menu_destination).setTitle(Navit.get_text("Share Destination"));
    menu.findItem(R.id.share_menu_location).setTitle(Navit.get_text("Share my Location"));
    menu.findItem(R.id.search_menu_offline).setTitle(get_text("address search (offline)"));
    menu.findItem(R.id.search_menu_online).setTitle(get_text("address search (online)"));
    menu.findItem(R.id.item_recentdest_menu_button).setTitle(get_text("Recent destinations"));
    menu.findItem(R.id.item_settings_menu_button).setTitle(get_text("Settings"));
    menu.findItem(R.id.item_search_menu_button).setTitle(get_text("Search"));

    // --- download icon ---
    menu.findItem(R.id.item_download_menu_button).setTitle(get_text("downloading map"));
    // --- download icon ---

    //
    menu.findItem(R.id.overflow_share_location).setTitle(Navit.get_text("Share my Location"));
    menu.findItem(R.id.overflow_share_destination).setTitle(Navit.get_text("Share Destination"));
    menu.findItem(R.id.overflow_settings).setTitle(Navit.get_text("Settings"));
    menu.findItem(R.id.overflow_zoom_to_route).setTitle(Navit.get_text("Zoom to Route"));

    if (ZANaviNormalDonateActivity.on_amazon_device) {
        menu.findItem(R.id.overflow_donate_item).setTitle(Navit.get_text("Donate"));
    } else {
        menu.findItem(R.id.overflow_donate_item).setTitle(Navit.get_text("Donate with Google Play"));
    }
    menu.findItem(R.id.overflow_donate_bitcoins_item).setTitle(Navit.get_text("Donate with Bitcoin"));
    //. TRANSLATORS: text to translate is: exit ZANavi
    menu.findItem(R.id.overflow_exit).setTitle(Navit.get_text("exit navit"));
    menu.findItem(R.id.overflow_toggle_poi).setTitle(Navit.get_text("toggle POI"));
    menu.findItem(R.id.overflow_announcer_on).setTitle(Navit.get_text("Announcer On"));
    menu.findItem(R.id.overflow_announcer_off).setTitle(Navit.get_text("Announcer Off"));
    menu.findItem(R.id.overflow_download_maps).setTitle(Navit.get_text("download maps"));
    menu.findItem(R.id.overflow_delete_maps).setTitle(Navit.get_text("delete maps"));
    menu.findItem(R.id.overflow_maps_age).setTitle(Navit.get_text("show Maps age"));
    menu.findItem(R.id.overflow_coord_dialog).setTitle(Navit.get_text("Coord Dialog"));
    menu.findItem(R.id.overflow_add_traffic_block).setTitle(Navit.get_text("add Traffic block"));
    menu.findItem(R.id.overflow_clear_traffic_block).setTitle(Navit.get_text("clear Traffic blocks"));
    menu.findItem(R.id.overflow_convert_gpx_file).setTitle(Navit.get_text("convert GPX file"));
    menu.findItem(R.id.overflow_replay_gps_file).setTitle(Navit.get_text("replay a ZANavi gps file"));
    menu.findItem(R.id.overflow_yaml_tests).setTitle(Navit.get_text("run YAML tests"));
    menu.findItem(R.id.overflow_clear_gpx_map).setTitle(Navit.get_text("clear GPX map"));
    // menu.findItem(R.id.overflow_dummy2)
    menu.findItem(R.id.overflow_demo_v_normal).setTitle(get_text("Demo Vehicle") + " [normal]");
    menu.findItem(R.id.overflow_demo_v_fast).setTitle(get_text("Demo Vehicle") + " [fast]");
    menu.findItem(R.id.overflow_speech_texts).setTitle(Navit.get_text("Speech Texts"));
    menu.findItem(R.id.overflow_nav_commands).setTitle(Navit.get_text("Nav. Commands"));
    menu.findItem(R.id.overflow_toggle_route_graph).setTitle(Navit.get_text("toggle Routegraph"));
    //menu.findItem(R.id.overflow_dummy1)
    menu.findItem(R.id.overflow_export_map_points_to_sdcard).setTitle(Navit.get_text("export Destinations"));
    menu.findItem(R.id.overflow_import_map_points_from_sdcard).setTitle(Navit.get_text("import Destinations"));
    menu.findItem(R.id.overflow_send_feedback).setTitle(Navit.get_text("send feedback"));
    menu.findItem(R.id.overflow_online_help).setTitle(Navit.get_text("online Help"));
    menu.findItem(R.id.overflow_about).setTitle(Navit.get_text("About"));
    //. TRANSLATORS: it means: "show current target in google maps"
    //. TRANSLATORS: please keep this text short, to fit in the android menu!
    menu.findItem(R.id.overflow_target_in_gmaps).setTitle(Navit.get_text("Target in gmaps"));
    //
    //
    menu.findItem(R.id.item_share_menu_button).setTitle(get_text("Share"));

    Display display_ = getWindowManager().getDefaultDisplay();
    Log.e("Navit", "Navit width in DP -> " + display_.getWidth() / Navit.metrics.density);
    Log.e("Navit", "Navit width in DP -> density=" + Navit.metrics.density);

    try {
        View v4 = findViewById(R.id.item_settings_menu_button);
        // Log.e("Navit", "Navit width in DP -> v4=" + v4);
        if ((v4 != null) && (v4.getWidth() > 0)) {
            Log.e("Navit", "Navit width in DP -> v4.w=" + v4.getWidth());
            MenuItem menuItem = menu.findItem(R.id.item_settings_menu_button);
            // Log.e("Navit", "Navit width in DP -> mi=" + menuItem);
            // Log.e("Navit", "Navit width in DP -> i=" + menuItem.getIcon());
            Log.e("Navit", "Navit width in DP -> i.w=" + menuItem.getIcon().getIntrinsicWidth());
            actionbar_item_width = (int) ((v4.getWidth() + (menuItem.getIcon().getIntrinsicWidth() * 1.5f))
                    / 2);
        } else {
            MenuItem menuItem = menu.findItem(R.id.item_settings_menu_button);
            // Log.e("Navit", "Navit width in DP -> mi=" + menuItem);
            // Log.e("Navit", "Navit width in DP -> i=" + menuItem.getIcon());
            Log.e("Navit", "Navit width in DP -> i.w=" + menuItem.getIcon().getIntrinsicWidth());
            actionbar_item_width = (int) ((menuItem.getIcon().getIntrinsicWidth()) * 1.7f);
        }

        actionbar_items_will_fit = display_.getWidth() / actionbar_item_width;
        Log.e("Navit", "Navit width in DP -> number of items that will fit=" + actionbar_items_will_fit);
        if (actionbar_items_will_fit > 6) // now we need to fit max. 6 items on actionbar
        {
            actionbar_all_items_will_fit = true;
        } else {
            actionbar_all_items_will_fit = false;
        }
    } catch (Exception e) {
        if ((display_.getWidth() / Navit.metrics.density) < NAVIT_MIN_HORIZONTAL_DP_FOR_ACTIONBAR) {
            actionbar_all_items_will_fit = false;
        } else {
            actionbar_all_items_will_fit = true;
        }
    }

    if (actionbar_all_items_will_fit == false) {
        menu.findItem(R.id.item_share_menu_button).setVisible(false);
        menu.findItem(R.id.overflow_share_location).setVisible(true);
        if (NavitGraphics.CallbackDestinationValid2() == 0) {
            menu.findItem(R.id.overflow_share_destination).setVisible(false);
        } else {
            menu.findItem(R.id.overflow_share_destination).setVisible(true);
        }

        if (actionbar_items_will_fit < 6) {
            // also push the settings icons to overflow menu
            menu.findItem(R.id.item_settings_menu_button).setVisible(false);
            menu.findItem(R.id.overflow_settings).setVisible(true);
        } else {
            menu.findItem(R.id.item_settings_menu_button).setVisible(true);
            menu.findItem(R.id.overflow_settings).setVisible(false);
        }
    } else {
        menu.findItem(R.id.item_settings_menu_button).setVisible(true);
        menu.findItem(R.id.overflow_settings).setVisible(false);
        menu.findItem(R.id.overflow_share_location).setVisible(false);
        menu.findItem(R.id.overflow_share_destination).setVisible(false);
        menu.findItem(R.id.item_share_menu_button).setVisible(true);
    }

    cur_menu = menu;

    System.out.println("down_icon:000");

    try {
        MenuItem downloadViewMenuItem = menu.findItem(R.id.item_download_menu_button);
        System.out.println("down_icon:001");
        downloadViewMenuItem.setVisible(true);
        System.out.println("down_icon:002");
        System.out.println("down_icon:003");
        android.widget.ImageView v = (android.widget.ImageView) MenuItemCompat
                .getActionView(menu.findItem(R.id.item_download_menu_button));
        System.out.println("down_icon:004");
        v.setVisibility(View.VISIBLE);
        if (v != null) {
            System.out.println("down_icon:005");
            v.setImageBitmap(null);
            System.out.println("down_icon:006");

            v.setBackgroundResource(R.drawable.anim_download_icon_2);
            final AnimationDrawable anim = (AnimationDrawable) v.getBackground();

            // ----------------------------------
            // thanks to: http://stackoverflow.com/questions/14686802/animationdrawable-is-not-working-on-2-3-6-android-version
            // ----------------------------------
            v.post(new Runnable() {
                public void run() {
                    try {
                        anim.start();
                        System.out.println("down_icon:006a");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });

            System.out.println("down_icon:007");

            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent mapdownload_cancel_activity = new Intent(Navit.this,
                            ZANaviDownloadMapCancelActivity.class);
                    mapdownload_cancel_activity
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(mapdownload_cancel_activity);
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("down_icon:099:EE");
    }

    if (actionabar_download_icon_visible) {
        menu.findItem(R.id.item_download_menu_button).setVisible(true);
    } else {
        menu.findItem(R.id.item_download_menu_button).setVisible(false);
    }

    if (NavitGraphics.CallbackDestinationValid2() > 0) {
        menu.findItem(R.id.item_endnavigation_menu_button).setVisible(true);
        menu.findItem(R.id.item_endnavigation_menu_button).setTitle(get_text("Stop Navigation"));
        menu.findItem(R.id.overflow_zoom_to_route).setVisible(true);
        menu.findItem(R.id.overflow_target_in_gmaps).setVisible(true);
        menu.findItem(R.id.share_menu_destination).setVisible(true);
    } else {
        menu.findItem(R.id.item_endnavigation_menu_button).setVisible(false);
        menu.findItem(R.id.overflow_zoom_to_route).setVisible(false);
        menu.findItem(R.id.overflow_target_in_gmaps).setVisible(false);
        menu.findItem(R.id.share_menu_destination).setVisible(false);
    }

    if (Navit_Announcer == true) {
        menu.findItem(R.id.overflow_announcer_off).setVisible(true);
        menu.findItem(R.id.overflow_announcer_on).setVisible(false);
    } else {
        menu.findItem(R.id.overflow_announcer_off).setVisible(false);
        menu.findItem(R.id.overflow_announcer_on).setVisible(true);
    }

    if (p.PREF_enable_debug_functions) {
        menu.findItem(R.id.overflow_dummy2).setVisible(true);
        menu.findItem(R.id.overflow_demo_v_normal).setVisible(true);
        menu.findItem(R.id.overflow_demo_v_fast).setVisible(true);
        menu.findItem(R.id.overflow_speech_texts).setVisible(true);
        menu.findItem(R.id.overflow_nav_commands).setVisible(true);
        menu.findItem(R.id.overflow_toggle_route_graph).setVisible(true);
        menu.findItem(R.id.overflow_replay_gps_file).setVisible(true);
        menu.findItem(R.id.overflow_yaml_tests).setVisible(true);
    } else {
        menu.findItem(R.id.overflow_dummy2).setVisible(false);
        menu.findItem(R.id.overflow_demo_v_normal).setVisible(false);
        menu.findItem(R.id.overflow_demo_v_fast).setVisible(false);
        menu.findItem(R.id.overflow_speech_texts).setVisible(false);
        menu.findItem(R.id.overflow_nav_commands).setVisible(false);
        menu.findItem(R.id.overflow_toggle_route_graph).setVisible(false);
        menu.findItem(R.id.overflow_replay_gps_file).setVisible(false);
        menu.findItem(R.id.overflow_yaml_tests).setVisible(false);
    }

    return true;
}