<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.mozstumbler.client.serialize;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.mozilla.mozstumbler.R;
import org.mozilla.mozstumbler.client.MainApp;
import org.mozilla.mozstumbler.client.ObservedLocationsReceiver;
import org.mozilla.mozstumbler.client.mapview.ObservationPoint;
import org.mozilla.mozstumbler.svclocator.services.log.LoggerUtil;

import java.io.File;
import java.io.FilenameFilter;
import java.lang.ref.WeakReference;
import java.util.LinkedList;

public class KMLFragment extends Fragment
        implements ObservationPointSerializer.IListener {

    private final String LOG_TAG = LoggerUtil.makeLogTag(KMLFragment.class);

    private LinkedList<ObservationPoint> mPointsToWrite;
    private WeakReference<ProgressDialog> mProgressDialog;
    private TextView mSavedFileLocation;

    private View mRootView;
    private boolean mIsRunning;
    private Dialog mLoadFileDialog;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_kml, container, false);
        mPointsToWrite =
            new LinkedList<ObservationPoint>(ObservedLocationsReceiver.getInstance().getObservationPoints_callerMustLock());
        mProgressDialog = new WeakReference<ProgressDialog>(null);
        mSavedFileLocation = (TextView) mRootView.findViewById(R.id.textViewSavedFile);

        View buttonLoad = mRootView.findViewById(R.id.buttonLoad);
        View buttonSave = mRootView.findViewById(R.id.buttonSave);

        buttonLoad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickLoad(v);
            }
        });
        buttonSave.setOnClickListener(new View.OnClickListener() {<commit_msg>KMLFragment needs to properly synchronize before copying the observation point list<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.mozstumbler.client.serialize;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.mozilla.mozstumbler.R;
import org.mozilla.mozstumbler.client.MainApp;
import org.mozilla.mozstumbler.client.ObservedLocationsReceiver;
import org.mozilla.mozstumbler.client.mapview.ObservationPoint;
import org.mozilla.mozstumbler.svclocator.services.log.LoggerUtil;

import java.io.File;
import java.io.FilenameFilter;
import java.lang.ref.WeakReference;
import java.util.LinkedList;
import java.util.List;

public class KMLFragment extends Fragment
        implements ObservationPointSerializer.IListener {

    private final String LOG_TAG = LoggerUtil.makeLogTag(KMLFragment.class);

    private LinkedList<ObservationPoint> mPointsToWrite;
    private WeakReference<ProgressDialog> mProgressDialog;
    private TextView mSavedFileLocation;

    private View mRootView;
    private boolean mIsRunning;
    private Dialog mLoadFileDialog;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_kml, container, false);
        List<ObservationPoint> points = ObservedLocationsReceiver.getInstance().getObservationPoints_callerMustLock();
        synchronized (points) {
            mPointsToWrite = new LinkedList<ObservationPoint>(points);
        }
        mProgressDialog = new WeakReference<ProgressDialog>(null);
        mSavedFileLocation = (TextView) mRootView.findViewById(R.id.textViewSavedFile);

        View buttonLoad = mRootView.findViewById(R.id.buttonLoad);
        View buttonSave = mRootView.findViewById(R.id.buttonSave);

        buttonLoad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickLoad(v);
            }
        });
        buttonSave.setOnClickListener(new View.OnClickListener() {
{'fraction_non_alphanumeric': 0.08594174054640855, 'fraction_numerical': 0.0018092998009770218, 'mean_word_length': 4.446305418719212, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '7062499', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1501, 'n_words': 343}