<commit_before>package org.wikipedia.nearby;

import org.wikipedia.PageTitle;
import org.wikipedia.R;
import org.wikipedia.Site;
import org.wikipedia.ThemedActionBarActivity;
import org.wikipedia.Utils;
import org.wikipedia.WikipediaApp;
import org.wikipedia.history.HistoryEntry;
import org.wikipedia.page.PageActivity;
import org.mediawiki.api.json.ApiException;
import com.squareup.picasso.Picasso;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.GeomagneticField;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * Displays a list of nearby pages.
 */
public class NearbyActivity extends ThemedActionBarActivity implements SensorEventListener {
    public static final int ACTIVITY_RESULT_NEARBY_SELECT = 1;
    private static final String PREF_KEY_UNITS = "nearbyUnits";
    private static final String NEARBY_LAST_RESULT = "lastRes";
    private static final String NEARBY_LAST_LOCATION = "lastLoc";
    private static final String NEARBY_NEXT_LOCATION = "curLoc";
    private static final int MIN_TIME_MILLIS = 5000;
    private static final int MIN_DISTANCE_METERS = 2;
    private static final int ONE_THOUSAND = 1000;
    private static final double ONE_THOUSAND_D = 1000.0d;
    private static final double METER_TO_FEET = 3.280839895;
    private static final int ONE_MILE = 5280;

    private ListView nearbyList;
    private View nearbyLoadingContainer;
    private View nearbyEmptyContainer;
    private NearbyAdapter adapter;

    private WikipediaApp app;
    private Site site;
    private LocationManager locationManager;
    private LocationListener locationListener;
    private boolean refreshing;
    private Location lastLocation;
    private Location nextLocation;
    private NearbyResult lastResult;

    private SensorManager mSensorManager;
    private Sensor mAccelerometer;
    private Sensor mMagnetometer;

    //this holds the actual data from the accelerometer and magnetometer, and automatically
    //maintains a moving average (low-pass filter) to reduce jitter.
    private MovingAverageArray accelData;
    private MovingAverageArray magneticData;

    //The size with which we'll initialize our low-pass filters. This size seems like
    //a good balance between effectively removing jitter, and good response speed.
    //(Mimics a physical compass needle)
    private static final int MOVING_AVERAGE_SIZE = 8;

    //geomagnetic field data, to be updated whenever we update location.
    //(will provide us with declination from true north)
    private GeomagneticField geomagneticField;

    //we'll maintain a list of CompassViews that are currently being displayed, and update them
    //whenever we receive updates from sensors.
    private List<NearbyCompassView> compassViews;

    //whether to display distances in imperial units (feet/miles) instead of metric
    private boolean showImperial = false;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        app = (WikipediaApp) getApplicationContext();
        site = app.getPrimarySite();

        setContentView(R.layout.activity_nearby);
        nearbyList = (ListView) findViewById(R.id.nearby_list);
        nearbyLoadingContainer = findViewById(R.id.nearby_loading_container);
        nearbyEmptyContainer = findViewById(R.id.nearby_empty_container);

        nearbyEmptyContainer.setVisibility(View.GONE);

        adapter = new NearbyAdapter(this, new ArrayList<NearbyPage>());
        nearbyList.setAdapter(adapter);
        nearbyList.setEmptyView(nearbyLoadingContainer);

        nearbyList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                NearbyPage nearbyPage = adapter.getItem(position);
                PageTitle title = new PageTitle(nearbyPage.getTitle(), site, nearbyPage.getThumblUrl());
                HistoryEntry newEntry = new HistoryEntry(title, HistoryEntry.SOURCE_NEARBY);

                Intent intent = new Intent();
                intent.setClass(NearbyActivity.this, PageActivity.class);
                intent.setAction(PageActivity.ACTION_PAGE_FOR_TITLE);
                intent.putExtra(PageActivity.EXTRA_PAGETITLE, title);
                intent.putExtra(PageActivity.EXTRA_HISTORYENTRY, newEntry);
                setResult(ACTIVITY_RESULT_NEARBY_SELECT, intent);
                finish();
            }
        });

        // Acquire a reference to the system Location Manager
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        // Define a listener that responds to location updates
        locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                // Called when a new location is found by the network location provider.
                makeUseOfNewLocation(location);
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {
                Log.d("Wikipedia", "onStatusChanged " + provider);
            }

            public void onProviderEnabled(String provider) {
                Log.d("Wikipedia", "onProviderEnabled " + provider);
            }
<commit_msg>Nearby: Open an intent with geo:// URL if item is long pressed<commit_after>package org.wikipedia.nearby;

import org.wikipedia.PageTitle;
import org.wikipedia.R;
import org.wikipedia.Site;
import org.wikipedia.ThemedActionBarActivity;
import org.wikipedia.Utils;
import org.wikipedia.WikipediaApp;
import org.wikipedia.history.HistoryEntry;
import org.wikipedia.page.PageActivity;
import org.mediawiki.api.json.ApiException;
import com.squareup.picasso.Picasso;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.GeomagneticField;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * Displays a list of nearby pages.
 */
public class NearbyActivity extends ThemedActionBarActivity implements SensorEventListener {
    public static final int ACTIVITY_RESULT_NEARBY_SELECT = 1;
    private static final String PREF_KEY_UNITS = "nearbyUnits";
    private static final String NEARBY_LAST_RESULT = "lastRes";
    private static final String NEARBY_LAST_LOCATION = "lastLoc";
    private static final String NEARBY_NEXT_LOCATION = "curLoc";
    private static final int MIN_TIME_MILLIS = 5000;
    private static final int MIN_DISTANCE_METERS = 2;
    private static final int ONE_THOUSAND = 1000;
    private static final double ONE_THOUSAND_D = 1000.0d;
    private static final double METER_TO_FEET = 3.280839895;
    private static final int ONE_MILE = 5280;

    private ListView nearbyList;
    private View nearbyLoadingContainer;
    private View nearbyEmptyContainer;
    private NearbyAdapter adapter;

    private WikipediaApp app;
    private Site site;
    private LocationManager locationManager;
    private LocationListener locationListener;
    private boolean refreshing;
    private Location lastLocation;
    private Location nextLocation;
    private NearbyResult lastResult;

    private SensorManager mSensorManager;
    private Sensor mAccelerometer;
    private Sensor mMagnetometer;

    //this holds the actual data from the accelerometer and magnetometer, and automatically
    //maintains a moving average (low-pass filter) to reduce jitter.
    private MovingAverageArray accelData;
    private MovingAverageArray magneticData;

    //The size with which we'll initialize our low-pass filters. This size seems like
    //a good balance between effectively removing jitter, and good response speed.
    //(Mimics a physical compass needle)
    private static final int MOVING_AVERAGE_SIZE = 8;

    //geomagnetic field data, to be updated whenever we update location.
    //(will provide us with declination from true north)
    private GeomagneticField geomagneticField;

    //we'll maintain a list of CompassViews that are currently being displayed, and update them
    //whenever we receive updates from sensors.
    private List<NearbyCompassView> compassViews;

    //whether to display distances in imperial units (feet/miles) instead of metric
    private boolean showImperial = false;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        app = (WikipediaApp) getApplicationContext();
        site = app.getPrimarySite();

        setContentView(R.layout.activity_nearby);
        nearbyList = (ListView) findViewById(R.id.nearby_list);
        nearbyLoadingContainer = findViewById(R.id.nearby_loading_container);
        nearbyEmptyContainer = findViewById(R.id.nearby_empty_container);

        nearbyEmptyContainer.setVisibility(View.GONE);

        adapter = new NearbyAdapter(this, new ArrayList<NearbyPage>());
        nearbyList.setAdapter(adapter);
        nearbyList.setEmptyView(nearbyLoadingContainer);

        nearbyList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                NearbyPage nearbyPage = adapter.getItem(position);
                PageTitle title = new PageTitle(nearbyPage.getTitle(), site, nearbyPage.getThumblUrl());
                HistoryEntry newEntry = new HistoryEntry(title, HistoryEntry.SOURCE_NEARBY);

                Intent intent = new Intent();
                intent.setClass(NearbyActivity.this, PageActivity.class);
                intent.setAction(PageActivity.ACTION_PAGE_FOR_TITLE);
                intent.putExtra(PageActivity.EXTRA_PAGETITLE, title);
                intent.putExtra(PageActivity.EXTRA_HISTORYENTRY, newEntry);
                setResult(ACTIVITY_RESULT_NEARBY_SELECT, intent);
                finish();
            }
        });

        // Long click creates an intent for viewing geo:// providers, which
        // opens up in the map application installed
        nearbyList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                NearbyPage nearbyPage = adapter.getItem(position);
                PageTitle title = new PageTitle(nearbyPage.getTitle(), site, nearbyPage.getThumblUrl());
                String geoUri = String.format(Locale.ENGLISH,
                        "geo:0,0?q=%s,%s(%s)",
                        nearbyPage.getLocation().getLatitude(),
                        nearbyPage.getLocation().getLongitude(),
                        title.getDisplayText()
                        );
                Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
                startActivity(geoIntent);
                return false;
            }
        });

        // Acquire a reference to the system Location Manager
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        // Define a listener that responds to location updates
        locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                // Called when a new location is found by the network location provider.
                makeUseOfNewLocation(location);
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {
                Log.d("Wikipedia", "onStatusChanged " + provider);
            }

            public void onProviderEnabled(String provider) {
                Log.d("Wikipedia", "onProviderEnabled " + provider);
            }

{'fraction_non_alphanumeric': 0.07399471466323834, 'fraction_numerical': 0.004428255124633955, 'mean_word_length': 3.5080489375402446, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '417587', 'n_tokens_mistral': 3745, 'n_tokens_neox': 3539, 'n_words': 1001}