Example usage for android.view MenuInflater inflate

List of usage examples for android.view MenuInflater inflate

Introduction

In this page you can find the example usage for android.view MenuInflater inflate.

Prototype

public void inflate(@MenuRes int menuRes, Menu menu) 

Source Link

Document

Inflate a menu hierarchy from the specified XML resource.

Usage

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    if (view == playlistView) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
        boolean offline = Util.isOffline(this);
        //  playlistView.setVisibility((downloadFile.getSong().getType().equals("ad"))?View.INVISIBLE:View.VISIBLE);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.nowplaying_context, menu);

        menu.findItem(R.id.menu_pin).setVisible(!offline && !downloadFile.isSaved());
        menu.findItem(R.id.menu_unpin).setVisible(!offline && downloadFile.isSaved());
        // menu.findItem(R.id.download_menu_star).setVisible(!offline && !downloadFile.getSong().isStarred());
        // menu.findItem(R.id.download_menu_unstar).setVisible(!offline && downloadFile.getSong().isStarred());
        // menu.findItem(R.id.download_menu_share).setVisible(!offline);
        menu.findItem(R.id.download_menu_remove).setVisible(true);
        // menu.findItem(R.id.download_menu_show_album).setVisible(downloadFile.getSong().getParent() != null);
        // menu.findItem(R.id.download_menu_lyrics).setVisible(!Util.isOffline(this));
    }/*from w  w  w.j a  va2  s  . c o m*/
}

From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    ImgurHoloActivity activity = (ImgurHoloActivity) getActivity();
    if (activity.getApiCall().settings.getString("theme", MainActivity.HOLO_LIGHT)
            .equals(MainActivity.HOLO_LIGHT))
        inflater.inflate(R.menu.main, menu);
    else/*from   w  w w.  jav  a 2 s  .c  o m*/
        inflater.inflate(R.menu.main_dark, menu);
    menu.findItem(R.id.action_upload).setVisible(false);
    menu.findItem(R.id.action_refresh).setVisible(true);
    menu.findItem(R.id.action_download).setVisible(true);
    if (albumId != null && galleryAlbumData == null) {
        menu.findItem(R.id.action_new).setVisible(true);
    }
    if (albumId != null && galleryAlbumData != null) {
        menu.findItem(R.id.action_comments).setVisible(true);
    }
    if (albumId != null) {
        menu.findItem(R.id.action_copy).setVisible(true);
        menu.findItem(R.id.action_share).setVisible(true);
    }
}

From source file:com.ruesga.rview.fragments.EditorFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.edit_options, menu);
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate menu and hold reference in toolbarMenu
    inflater.inflate(R.menu.source_list_menu, menu);
    super.onCreateOptionsMenu(menu, inflater);
    toolbarMenu = menu;/* w w w .j av a  2s  .com*/

    // Sets correct colors of toolbar icons
    int colorFilterInt = AppSettings.getColorFilterInt(appContext);
    Drawable refreshIcon = getResources().getDrawable(R.drawable.ic_refresh_white_24dp);
    Drawable storageIcon = getResources().getDrawable(R.drawable.ic_sort_white_24dp);
    refreshIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY);
    storageIcon.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY);
    menu.getItem(0).setIcon(refreshIcon);
    menu.getItem(2).setIcon(storageIcon);

    // Recounts images
    new ImageCountTask().execute();
}

From source file:com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.ic_tools_cpu_control));
    setContentView(R.layout.card_cpu_control);
    bootPrefs = getSharedPreferences("BOOT_PREFS", 0);

    graph = (LineGraph) findViewById(R.id.graph);
    line = new Line();
    LinePoint point = new LinePoint();
    point.setX(currX);//from  ww w.  j  a v a 2s  . com
    point.setY(1);
    line.addPoint(point);
    line.setColor(Color.parseColor("#FFBB33"));
    graph.addLine(line);
    graph.setLineToFill(0);

    availableFrequencies = new String[0];
    String availableFrequenciesLine;

    mCoresOnline = (TextView) findViewById(R.id.cores_online);
    mGeneralGovernor = (Spinner) findViewById(R.id.general_governor);
    mGovernor = (Spinner) findViewById(R.id.governor);
    mGovernor2 = (Spinner) findViewById(R.id.governor2);
    mGovernor3 = (Spinner) findViewById(R.id.governor3);
    mGovernor4 = (Spinner) findViewById(R.id.governor4);

    Button customizeGov = (Button) findViewById(R.id.governor_customize_btn);
    customizeGov.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            GovernorDialog editNameDialog = new GovernorDialog();
            editNameDialog.show(fm, "governor_fragment");
        }
    });

    if (Helpers.doesFileExist(STEPS)) {
        availableFrequenciesLine = CPUHelper.readOneLineNotRoot(STEPS);

        if (availableFrequenciesLine != null) {
            availableFrequencies = availableFrequenciesLine.split(" ");
            Arrays.sort(availableFrequencies, new Comparator<String>() {
                @Override
                public int compare(String object1, String object2) {
                    return Integer.valueOf(object1).compareTo(Integer.valueOf(object2));
                }
            });
        }
    }

    Switch snakeCharmer = (Switch) findViewById(R.id.snake_charmer_switch);
    if (!Helpers.doesFileExist(SNAKE_CHARMER_MAX_FREQ)) {
        LinearLayout cardSnakeCharmer = (LinearLayout) findViewById(R.id.card_snake_charmer);
        cardSnakeCharmer.setVisibility(View.GONE);
    } else {
        if (Helpers.doesFileExist(SNAKE_CHARMER_VERSION)) {
            TextView snakeTitle = (TextView) findViewById(R.id.snake_charmer);
            String snakeVersion = CPUHelper.readOneLineNotRoot(SNAKE_CHARMER_VERSION);
            snakeVersion = snakeVersion.replaceAll("version: ", "v");
            snakeTitle.setText(snakeTitle.getText() + " " + snakeVersion);
            if (snakeVersion.equals("v1.2")) {
                TextView snakeDesc = (TextView) findViewById(R.id.snake_charmer_text);
                snakeDesc.setText(snakeDesc.getText() + "\n" + getString(R.string.snake_charmer_built_in));
                snakeCharmer.setEnabled(false);
            }
        }

        if (bootPrefs.getBoolean("SNAKE_CHARMER", true)) {
            snakeCharmer.setChecked(true);
            snakeCharmerEnabled = true;
        }

        snakeCharmer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isOn) {
                snakeCharmerEnabled = isOn;
            }
        });
    }

    int frequenciesNum = availableFrequencies.length - 1;

    Switch thermalControl = (Switch) findViewById(R.id.msm_thermal_switch);
    if (Helpers.doesFileExist(MSM_THERMAL)) {
        String thermal = CPUHelper.readOneLineNotRoot(MSM_THERMAL);
        if (thermal.equals("Y"))
            thermalControl.setChecked(true);
        else
            thermalControl.setChecked(false);

        thermalControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked)
                    Helpers.CMDProcessorWrapper.runSuCommand("echo Y > " + MSM_THERMAL);
                else
                    Helpers.CMDProcessorWrapper.runSuCommand("echo N > " + MSM_THERMAL);

                bootPrefs.edit().putBoolean("MSM_THERMAL", isChecked).commit();
            }
        });
    }
    thermalControl.setChecked(bootPrefs.getBoolean("MSM_THERMAL", true));

    perCoreGovernor = (Switch) findViewById(R.id.per_core_governors_switch);
    perCoreGovernor.setChecked(bootPrefs.getBoolean("PER_CORE_GOV", true));

    if (perCoreGovernor.isChecked()) {
        findViewById(R.id.card_general_governor).setVisibility(View.GONE);
        findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE);
    } else {
        findViewById(R.id.card_per_core_governors).setVisibility(View.GONE);
        findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE);
    }

    perCoreGovernor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (isChecked) {
                findViewById(R.id.card_general_governor).setVisibility(View.GONE);
                findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE);
                handleGovernors();
            } else {
                findViewById(R.id.card_per_core_governors).setVisibility(View.GONE);
                findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE);
                handleGovernors();
            }

            bootPrefs.edit().putBoolean("PER_CORE_GOV", isChecked).commit();
        }
    });

    String currentIo = "";
    if (Helpers.doesFileExist(IO_SCHEDULER))
        currentIo = CPUHelper.getIOScheduler();

    String currentTcp = "";
    if (Helpers.doesFileExist(CURR_TCP_ALGORITHM))
        currentTcp = Helpers.getCurrentTcpAlgorithm();

    String curMaxSpeed = "NaN";
    if (Helpers.doesFileExist(MAX_FREQ_ALL_CORES))
        curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ_ALL_CORES);
    else if (Helpers.doesFileExist(MAX_FREQ))
        curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ);

    String curMinSpeed = "NaN";
    if (Helpers.doesFileExist(MIN_FREQ_ALL_CORES))
        curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ_ALL_CORES);
    else if (Helpers.doesFileExist(MIN_FREQ))
        curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ);

    if (mIsTegra3) {
        String curTegraMaxSpeed = "NaN";
        if (Helpers.doesFileExist(TEGRA_MAX_FREQ)) {
            curTegraMaxSpeed = CPUHelper.readOneLineNotRoot(TEGRA_MAX_FREQ);
            int curTegraMax = 0;
            try {
                curTegraMax = Integer.parseInt(curTegraMaxSpeed);
                if (curTegraMax > 0) {
                    curMaxSpeed = Integer.toString(curTegraMax);
                }
            } catch (NumberFormatException ex) {
                curTegraMax = 0;
            }
        }
    }

    if (Helpers.doesFileExist(NUM_OF_CPUS))
        mNumOfCpus = Helpers.getNumOfCpus();

    mCurFreq = (TextView) findViewById(R.id.currspeed);

    mMaxSlider = (SeekBar) findViewById(R.id.max_slider);
    mMaxSlider.setMax(frequenciesNum);
    mMaxSpeedText = (TextView) findViewById(R.id.max_speed_text);
    mMaxSpeedText.setText(toMHz(curMaxSpeed));
    mMaxSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMaxSpeed));
    mMaxSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser)
                setMaxSpeed(seekBar, progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            startSupportActionMode(new ActionMode.Callback() {
                @Override
                public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                    MenuInflater inflater = actionMode.getMenuInflater();
                    inflater.inflate(R.menu.contextual_menu, menu);
                    return true;
                }

                @Override
                public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                    return false;
                }

                @Override
                public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
                    switch (menuItem.getItemId()) {
                    case R.id.apply:
                        if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty()) {
                            bootPrefs.edit().putString("CPU_MAX_FREQ", mMaxFreqSetting).commit();
                            for (int i = 0; i < mNumOfCpus; i++)
                                Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMaxFreqSetting
                                        + " > " + MAX_FREQ.replace("cpu0", "cpu" + i));

                            if (snakeCharmerEnabled)
                                Helpers.CMDProcessorWrapper.runSuCommand(
                                        "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ);
                        }

                        if (mIsTegra3) {
                            if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty())
                                Helpers.CMDProcessorWrapper.runSuCommand(
                                        "busybox echo " + mMaxFreqSetting + " > " + TEGRA_MAX_FREQ);

                            if (snakeCharmerEnabled)
                                Helpers.CMDProcessorWrapper.runSuCommand(
                                        "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ);
                        }
                        actionMode.finish();
                        return true;
                    default:
                        return false;
                    }
                }

                @Override
                public void onDestroyActionMode(ActionMode actionMode) {

                }
            });
        }
    });

    mMinSlider = (SeekBar) findViewById(R.id.min_slider);
    mMinSlider.setMax(frequenciesNum);
    mMinSpeedText = (TextView) findViewById(R.id.min_speed_text);
    mMinSpeedText.setText(toMHz(curMinSpeed));
    mMinSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMinSpeed));
    mMinSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser)
                setMinSpeed(seekBar, progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            startSupportActionMode(new ActionMode.Callback() {
                @Override
                public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                    MenuInflater inflater = actionMode.getMenuInflater();
                    inflater.inflate(R.menu.contextual_menu, menu);
                    return true;
                }

                @Override
                public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                    return false;
                }

                @Override
                public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
                    switch (menuItem.getItemId()) {
                    case R.id.apply:
                        if (mMinFreqSetting != null && !mMinFreqSetting.isEmpty()) {
                            bootPrefs.edit().putString("CPU_MIN_FREQ", mMinFreqSetting).commit();
                            for (int i = 0; i < mNumOfCpus; i++)
                                Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMinFreqSetting
                                        + " > " + MIN_FREQ.replace("cpu0", "cpu" + i));
                        }
                        actionMode.finish();
                        return true;
                    default:
                        return false;
                    }
                }

                @Override
                public void onDestroyActionMode(ActionMode actionMode) {

                }
            });
        }
    });

    handleGovernors();

    /** TCP Congestion Spinner */
    Spinner mTcp = (Spinner) findViewById(R.id.tcp);
    ArrayAdapter<CharSequence> tcpAdapter = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row);
    tcpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    ArrayList<String> algorithms = Helpers.getTcpAlgorithms();
    for (String algorithm : algorithms)
        tcpAdapter.add(algorithm);
    mTcp.setAdapter(tcpAdapter);
    mTcp.setSelection(algorithms.indexOf(currentTcp));
    mTcp.setOnItemSelectedListener(new TCPListener());

    onlineCoresPolling();
}

From source file:com.aimfire.main.MainActivity.java

/**
 * Override Activity lifecycle method./*  w w  w  . j a v a 2  s  .  c o  m*/
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_main, menu);

    /*
      * To show icon (instead of only text) in action bar overflow
      */
    if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
        try {
            Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
            m.setAccessible(true);
            m.invoke(menu, true);
        } catch (NoSuchMethodException e) {
            if (BuildConfig.DEBUG)
                Log.e(TAG, "onMenuOpened", e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.openerp.addons.messages.Message.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_fragment_message, menu);
    // Associate searchable configuration with the SearchView
    searchView = (SearchView) menu.findItem(R.id.menu_message_search).getActionView();
    Bundle bundle = getArguments();//from w w  w.j  av a  2  s. c o  m
    if (bundle != null && bundle.containsKey("group_id")) {
        MenuItem compose = menu.findItem(R.id.menu_message_compose);
        compose.setVisible(false);
    }
}

From source file:fr.univsavoie.ltp.client.MainActivity.java

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.map_menu, menu);
}

From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //        super.onCreateOptionsMenu(menu, inflater);
    for (int i = 0; i < menu.size(); i++) {
        menu.removeItem(i);/* www . j av a 2 s .c o  m*/
    }
    inflater.inflate(R.menu.menu_map, menu);
}

From source file:com.android.contacts.activities.DialtactsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.dialtacts_options, menu);

    // set up intents and onClick listeners
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);

    callSettingsMenuItem.setIntent(DialtactsActivity.getCallSettingsIntent());
    searchMenuItem.setOnMenuItemClickListener(mSearchMenuItemClickListener);
    filterOptionMenuItem.setOnMenuItemClickListener(mFilterOptionsMenuItemClickListener);
    addContactOptionMenuItem.setIntent(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));

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