<commit_before>package org.osmdroid;

import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.IOverlayMenuProvider;
import org.osmdroid.views.overlay.SafeDrawOverlay;
import org.osmdroid.views.safecanvas.ISafeCanvas;

import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;

public class RotationGestureOverlay extends SafeDrawOverlay implements
        RotationGestureDetector.RotationListener, IOverlayMenuProvider
{
    private final static int MENU_ENABLED = getSafeMenuId();

    private final RotationGestureDetector mRotationDetector;
    private MapView mMapView;
    private boolean mOptionsMenuEnabled = true;

    public RotationGestureOverlay(Context context, MapView mapView)
    {
        super(context);
        mMapView = mapView;
        mRotationDetector = new RotationGestureDetector(this);
    }

    @Override
    protected void drawSafe(ISafeCanvas canvas, MapView mapView, boolean shadow)
    {
        // No drawing necessary
    }

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView)
    {
        if (this.isEnabled()) {
            mRotationDetector.onTouch(event);
        }
        return super.onTouchEvent(event, mapView);
    }

    @Override
    public void onRotate(float deltaAngle)
    {
        mMapView.setMapOrientation(mMapView.getMapOrientation() + deltaAngle);
    }

    @Override
    public boolean isOptionsMenuEnabled()
    {
        return mOptionsMenuEnabled;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu pMenu, int pMenuIdOffset, MapView pMapView)
    {
        pMenu.add(0, MENU_ENABLED + pMenuIdOffset, Menu.NONE, "Enable rotation").setIcon(
                android.R.drawable.ic_menu_info_details);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem pItem, int pMenuIdOffset, MapView pMapView)
    {
        if (pItem.getItemId() == MENU_ENABLED + pMenuIdOffset) {
            if (this.isEnabled()) {
                mMapView.setMapOrientation(0);
                this.setEnabled(false);
            } else {
                this.setEnabled(true);
            }
            return true;
        }

        return false;
    }

    @Override
    public boolean onPrepareOptionsMenu(final Menu pMenu, final int pMenuIdOffset, final MapView pMapView)
    {
        pMenu.findItem(MENU_ENABLED + pMenuIdOffset).setTitle(
                this.isEnabled() ? "Disable rotation" : "Enable rotation");
        return false;
    }

    @Override
    public void setOptionsMenuEnabled(boolean enabled)
    {
        mOptionsMenuEnabled = enabled;
    }
}
<commit_msg>Added optional rotate menu items. Mostly for debugging in the emulator when we can't use multi-touch.<commit_after>package org.osmdroid;

import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.IOverlayMenuProvider;
import org.osmdroid.views.overlay.SafeDrawOverlay;
import org.osmdroid.views.safecanvas.ISafeCanvas;

import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;

public class RotationGestureOverlay extends SafeDrawOverlay implements
        RotationGestureDetector.RotationListener, IOverlayMenuProvider
{
	private final static boolean SHOW_ROTATE_MENU_ITEMS = false;

	private final static int MENU_ENABLED = getSafeMenuId();
	private final static int MENU_ROTATE_CCW = getSafeMenuId();
	private final static int MENU_ROTATE_CW = getSafeMenuId();

    private final RotationGestureDetector mRotationDetector;
    private MapView mMapView;
    private boolean mOptionsMenuEnabled = true;

    public RotationGestureOverlay(Context context, MapView mapView)
    {
        super(context);
        mMapView = mapView;
        mRotationDetector = new RotationGestureDetector(this);
    }

    @Override
    protected void drawSafe(ISafeCanvas canvas, MapView mapView, boolean shadow)
    {
        // No drawing necessary
    }

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView)
    {
        if (this.isEnabled()) {
            mRotationDetector.onTouch(event);
        }
        return super.onTouchEvent(event, mapView);
    }

    @Override
    public void onRotate(float deltaAngle)
    {
        mMapView.setMapOrientation(mMapView.getMapOrientation() + deltaAngle);
    }

    @Override
    public boolean isOptionsMenuEnabled()
    {
        return mOptionsMenuEnabled;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu pMenu, int pMenuIdOffset, MapView pMapView)
    {
		pMenu.add(0, MENU_ENABLED + pMenuIdOffset, Menu.NONE, "Enable rotation").setIcon(
				android.R.drawable.ic_menu_info_details);
		if (SHOW_ROTATE_MENU_ITEMS) {
			pMenu.add(0, MENU_ROTATE_CCW + pMenuIdOffset, Menu.NONE,
					"Rotate maps counter clockwise").setIcon(android.R.drawable.ic_menu_rotate);
			pMenu.add(0, MENU_ROTATE_CW + pMenuIdOffset, Menu.NONE, "Rotate maps clockwise")
					.setIcon(android.R.drawable.ic_menu_rotate);
		}
        return true;
    }

	@Override
	public boolean onOptionsItemSelected(MenuItem pItem, int pMenuIdOffset, MapView pMapView)
	{
		if (pItem.getItemId() == MENU_ENABLED + pMenuIdOffset) {
			if (this.isEnabled()) {
				mMapView.setMapOrientation(0);
				this.setEnabled(false);
			} else {
				this.setEnabled(true);
				return true;
			}
		} else if (pItem.getItemId() == MENU_ROTATE_CCW + pMenuIdOffset) {
			mMapView.setMapOrientation(mMapView.getMapOrientation() - 10);
		} else if (pItem.getItemId() == MENU_ROTATE_CW + pMenuIdOffset) {
			mMapView.setMapOrientation(mMapView.getMapOrientation() + 10);
		}

		return false;
	}

    @Override
    public boolean onPrepareOptionsMenu(final Menu pMenu, final int pMenuIdOffset, final MapView pMapView)
    {
        pMenu.findItem(MENU_ENABLED + pMenuIdOffset).setTitle(
                this.isEnabled() ? "Disable rotation" : "Enable rotation");
        return false;
    }

    @Override
    public void setOptionsMenuEnabled(boolean enabled)
    {
        mOptionsMenuEnabled = enabled;
    }
}

{'fraction_non_alphanumeric': 0.08050914876690533, 'fraction_numerical': 0.0015910898965791568, 'mean_word_length': 2.877853177051203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3435435', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1853, 'n_words': 387}