<commit_before>package com.bubelov.coins.ui;

import android.app.Activity;
import android.app.LoaderManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Loader;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;

import com.bubelov.coins.Constants;
import com.bubelov.coins.manager.UserNotificationManager;
import com.bubelov.coins.service.MerchantsSyncService;
import com.bubelov.coins.util.OnCameraChangeMultiplexer;
import com.bubelov.coins.loader.PlacesLoader;
import com.bubelov.coins.R;
import com.bubelov.coins.model.Merchant;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.clustering.view.DefaultClusterRenderer;

import java.util.Collection;

public class MapActivity extends Activity implements LoaderManager.LoaderCallbacks<Collection<Merchant>> {
    private static final String SHOW_MERCHANT_EXTRA = "show_merchant";
    private static final String MERCHANT_LOCATION_EXTRA = "merchant_location";
    private static final String MY_LOCATION_EXTRA = "my_location";

    private static final int MERCHANTS_LOADER = 0;

    private GoogleMap map;
    private ClusterManager<Merchant> placesManager;

    private SwipeRefreshLayout refreshLayout;

    private BroadcastReceiver syncBroadcastReceiver;

    public static Intent makeIntent(Context context, double latitude, double longitude) {
        Intent intent = new Intent(context, MapActivity.class);
        intent.putExtra(SHOW_MERCHANT_EXTRA, true);
        intent.putExtra(MERCHANT_LOCATION_EXTRA, new LatLng(latitude, longitude));
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getActionBar().setBackgroundDrawable(null);

        refreshLayout = (SwipeRefreshLayout)findViewById(R.id.container);
        refreshLayout.setColorScheme(R.color.silver, R.color.gold, R.color.silver, R.color.gold);
        refreshLayout.setEnabled(false);

        MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
        map = mapFragment.getMap();
        map.setMyLocationEnabled(true);
        map.getUiSettings().setZoomControlsEnabled(false);

        if (getIntent().getBooleanExtra(SHOW_MERCHANT_EXTRA, false)) {
            showMerchant();
        } else {
            findMyLocationIfNotFound();
        }

        initClustering();

        map.setOnCameraChangeListener(new OnCameraChangeMultiplexer(placesManager, new CameraChangeListener()));

        LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
        getLoaderManager().initLoader(MERCHANTS_LOADER, PlacesLoader.prepareArguments(bounds), this);

        syncBroadcastReceiver = new SyncMerchantsBroadcastReceiver();
    }

    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter filter = new IntentFilter(MerchantsSyncService.SYNC_COMPLETED_ACTION);
        LocalBroadcastManager.getInstance(this).registerReceiver(syncBroadcastReceiver, filter);
    }

    @Override
    protected void onPause() {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(syncBroadcastReceiver);
        super.onPause();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        switch (id) {
            case R.id.action_refresh:
                refreshData();
                return true;
            case R.id.action_settings:
                startActivity(new Intent(this, SettingsActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public Loader<Collection<Merchant>> onCreateLoader(int id, Bundle args) {
        return new PlacesLoader(this, args);
    }

    @Override
    public void onLoadFinished(Loader<Collection<Merchant>> loader, final Collection<Merchant> data) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                placesManager.clearItems();
                placesManager.addItems(data);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        placesManager.cluster();
                    }
                });
            }
        }).start();

        placesManager.cluster();
    }

    @Override
    public void onLoaderReset(Loader<Collection<Merchant>> loader) {
        // Nothing to do here
    }

    private void showMerchant() {
        LatLng location = getIntent().getParcelableExtra(MERCHANT_LOCATION_EXTRA);

        if (location != null) {
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 12));
            getIntent().removeExtra(MERCHANT_LOCATION_EXTRA);
        }
    }<commit_msg>Changed zoom level for "show merchant" requests<commit_after>package com.bubelov.coins.ui;

import android.app.Activity;
import android.app.LoaderManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Loader;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;

import com.bubelov.coins.Constants;
import com.bubelov.coins.manager.UserNotificationManager;
import com.bubelov.coins.service.MerchantsSyncService;
import com.bubelov.coins.util.OnCameraChangeMultiplexer;
import com.bubelov.coins.loader.PlacesLoader;
import com.bubelov.coins.R;
import com.bubelov.coins.model.Merchant;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.clustering.view.DefaultClusterRenderer;

import java.util.Collection;

public class MapActivity extends Activity implements LoaderManager.LoaderCallbacks<Collection<Merchant>> {
    private static final String SHOW_MERCHANT_EXTRA = "show_merchant";
    private static final String MERCHANT_LOCATION_EXTRA = "merchant_location";
    private static final String MY_LOCATION_EXTRA = "my_location";

    private static final int MERCHANTS_LOADER = 0;

    private GoogleMap map;
    private ClusterManager<Merchant> placesManager;

    private SwipeRefreshLayout refreshLayout;

    private BroadcastReceiver syncBroadcastReceiver;

    public static Intent makeIntent(Context context, double latitude, double longitude) {
        Intent intent = new Intent(context, MapActivity.class);
        intent.putExtra(SHOW_MERCHANT_EXTRA, true);
        intent.putExtra(MERCHANT_LOCATION_EXTRA, new LatLng(latitude, longitude));
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getActionBar().setBackgroundDrawable(null);

        refreshLayout = (SwipeRefreshLayout)findViewById(R.id.container);
        refreshLayout.setColorScheme(R.color.silver, R.color.gold, R.color.silver, R.color.gold);
        refreshLayout.setEnabled(false);

        MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
        map = mapFragment.getMap();
        map.setMyLocationEnabled(true);
        map.getUiSettings().setZoomControlsEnabled(false);

        if (getIntent().getBooleanExtra(SHOW_MERCHANT_EXTRA, false)) {
            showMerchant();
        } else {
            findMyLocationIfNotFound();
        }

        initClustering();

        map.setOnCameraChangeListener(new OnCameraChangeMultiplexer(placesManager, new CameraChangeListener()));

        LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
        getLoaderManager().initLoader(MERCHANTS_LOADER, PlacesLoader.prepareArguments(bounds), this);

        syncBroadcastReceiver = new SyncMerchantsBroadcastReceiver();
    }

    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter filter = new IntentFilter(MerchantsSyncService.SYNC_COMPLETED_ACTION);
        LocalBroadcastManager.getInstance(this).registerReceiver(syncBroadcastReceiver, filter);
    }

    @Override
    protected void onPause() {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(syncBroadcastReceiver);
        super.onPause();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        switch (id) {
            case R.id.action_refresh:
                refreshData();
                return true;
            case R.id.action_settings:
                startActivity(new Intent(this, SettingsActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public Loader<Collection<Merchant>> onCreateLoader(int id, Bundle args) {
        return new PlacesLoader(this, args);
    }

    @Override
    public void onLoadFinished(Loader<Collection<Merchant>> loader, final Collection<Merchant> data) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                placesManager.clearItems();
                placesManager.addItems(data);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        placesManager.cluster();
                    }
                });
            }
        }).start();

        placesManager.cluster();
    }

    @Override
    public void onLoaderReset(Loader<Collection<Merchant>> loader) {
        // Nothing to do here
    }

    private void showMerchant() {
        LatLng location = getIntent().getParcelableExtra(MERCHANT_LOCATION_EXTRA);

        if (location != null) {
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 16));
            getIntent().removeExtra(MERCHANT_LOCATION_EXTRA);
        }
    }
{'fraction_non_alphanumeric': 0.0925764192139738, 'fraction_numerical': 0.0008733624454148472, 'mean_word_length': 3.2426824749907373, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6740612', 'n_tokens_mistral': 3211, 'n_tokens_neox': 3071, 'n_words': 566}