<commit_before>
package com.trovebox.android.app.common;

import android.os.Bundle;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.trovebox.android.app.R;

/**
 * Abstract fragment with the refresh menu available
 * 
 * @author <NAME>
 */
public abstract class CommonRefreshableFragment extends
        CommonFragment implements
        Refreshable {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.refreshable, menu);
    }

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        reinitMenu(menu);
        super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId())
        {
            case R.id.menu_refresh: {
                refresh();
                return true;
            }
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    protected void reinitMenu(Menu menu)
    {
        menu.findItem(R.id.menu_refresh).setVisible(isRefreshMenuVisible());
    }

    protected abstract boolean isRefreshMenuVisible();

}<commit_msg>#409 - CommonRefreshableFragment: surrounded reinitMenu method body with try/catch block to avoid crash on NPE on Android 2.x devices<commit_after>
package com.trovebox.android.app.common;

import android.os.Bundle;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.trovebox.android.app.R;
import com.trovebox.android.app.util.GuiUtils;

/**
 * Abstract fragment with the refresh menu available
 * 
 * @author <NAME>
 */
public abstract class CommonRefreshableFragment extends
        CommonFragment implements
        Refreshable {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

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

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        reinitMenu(menu);
        super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId())
        {
            case R.id.menu_refresh: {
                refresh();
                return true;
            }
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    protected void reinitMenu(Menu menu)
    {
        try
        {
            MenuItem refreshItem = menu.findItem(R.id.menu_refresh);
            refreshItem.setVisible(isRefreshMenuVisible());
        } catch (Exception ex)
        {
            GuiUtils.noAlertError(TAG, ex);
        }
    }

    protected abstract boolean isRefreshMenuVisible();

}
{'fraction_non_alphanumeric': 0.08561749307052664, 'fraction_numerical': 0.0012319063751154912, 'mean_word_length': 2.620958751393534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1220025', 'n_tokens_mistral': 915, 'n_tokens_neox': 868, 'n_words': 186}