<commit_before>package com.facebook.samples.booleanog;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.facebook.*;

import java.text.SimpleDateFormat;
import java.util.*;

public class LogicActivity extends FragmentActivity {

    private static final String TAG = "BooleanOpenGraphSample";

    private static final String SAVE_ACTIVE_TAB = TAG + ".SAVE_ACTIVE_TAB";
    private static final String SAVE_CONTENT_SELECTION = TAG + ".SAVE_CONTENT_SELECTION";
    private static final String SAVE_LEFT_OPERAND_SELECTION = TAG + ".SAVE_LEFT_OPERAND_SELECTION";
    private static final String SAVE_RIGHT_OPERAND_SELECTION = TAG + ".SAVE_RIGHT_OPERAND_SELECTION";
    private static final String SAVE_RESULT_TEXT = TAG + ".SAVE_RESULT_TEXT";
    private static final String SAVE_POST_RESULT_TEXT = TAG + ".SAVE_POST_RESULT_TEXT";

    private static final String AND_ACTION = "fb_sample_boolean_og:and";
    private static final String OR_ACTION = "fb_sample_boolean_og:or";
    private static final String POST_AND_ACTION_PATH = "me/" + AND_ACTION;
    private static final String POST_OR_ACTION_PATH = "me/" + OR_ACTION;
    private static final String TRUE_GRAPH_OBJECT_URL = "http://samples.ogp.me/369360019783304";
    private static final String FALSE_GRAPH_OBJECT_URL = "http://samples.ogp.me/369360256449947";
    private static final String INSTALLED = "installed";

    private static volatile TruthValueGraphObject TRUE_GRAPH_OBJECT;
    private static volatile TruthValueGraphObject FALSE_GRAPH_OBJECT;
    private static volatile int TRUE_SPINNER_INDEX = -1;
    private static volatile int FALSE_SPINNER_INDEX = -1;

    // Main layout
    private Button logicButton;
    private Button friendsButton;
    private Button settingsButton;
    private Button contentButton;
    private String activeTab;

    // Logic group
    private ViewGroup logicGroup;
    private Spinner leftSpinner;
    private Spinner rightSpinner;
    private Button andButton;
    private Button orButton;
    private TextView resultText;
    private TextView postResultText;

    // Friends group
    private ViewGroup friendsGroup;
    private FriendPickerFragment friendPickerFragment;
    private RequestAsyncTask pendingRequest;
    private SimpleCursorAdapter friendActivityAdapter;
    private ProgressBar friendActivityProgressBar;

    // Login group
    private ViewGroup settingsGroup;
    private LoginFragment loginFragment;

    // Content group
    private ViewGroup contentGroup;
    private ImageView contentImage;
    private Spinner contentSpinner;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Views
        logicButton = (Button) findViewById(R.id.logic_button);
        friendsButton = (Button) findViewById(R.id.friends_button);
        settingsButton = (Button) findViewById(R.id.settings_button);
        contentButton = (Button) findViewById(R.id.content_button);

        logicGroup = (ViewGroup) findViewById(R.id.logic_group);
        leftSpinner = (Spinner) findViewById(R.id.left_spinner);
        rightSpinner = (Spinner) findViewById(R.id.right_spinner);
        andButton = (Button) findViewById(R.id.and_button);
        orButton = (Button) findViewById(R.id.or_button);
        resultText = (TextView) findViewById(R.id.result_text);
        postResultText = (TextView) findViewById(R.id.post_result_text);

        friendsGroup = (ViewGroup) findViewById(R.id.friends_group);
        ListView friendActivityList = (ListView) findViewById(R.id.friend_activity_list);
        String[] mapColumnNames = {"date", "action"};
        int[] mapViewIds = {R.id.friend_action_date, R.id.friend_action_data};
        friendActivityAdapter = new SimpleCursorAdapter(this, R.layout.friend_activity_row, createEmptyCursor(),
                mapColumnNames, mapViewIds);
        friendActivityList.setAdapter(friendActivityAdapter);
        friendActivityProgressBar = (ProgressBar) findViewById(R.id.friend_activity_progress_bar);

        settingsGroup = (ViewGroup) findViewById(R.id.settings_group);

        contentGroup = (ViewGroup) findViewById(R.id.content_group);
        contentImage = (ImageView) findViewById(R.id.content_image);
        contentSpinner = (Spinner) findViewById(R.id.content_spinner);

        // Fragments
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();

        friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
        if (friendPickerFragment == null) {
            friendPickerFragment = new FriendPickerFragment();
            friendPickerFragment.setExtraFields(Arrays.asList(INSTALLED));
            friendPickerFragment.setFilter(new PickerFragment.GraphObjectFilter<GraphUser>() {
                @Override
                public boolean includeItem(GraphUser graphObject) {
                    Boolean installed = graphObject.cast(GraphUserWithInstalled.class).getInstalled();
                    return (installed != null) && installed.booleanValue();
                }
            });
            transaction.add(R.id.friend_picker_fragment, friendPickerFragment);
        }

        loginFragment = (LoginFragment) fragmentManager.findFragmentById(R.id.login_fragment);
        if (loginFragment == null) {
            loginFragment = new LoginFragment();
            transaction.add(R.id.login_fragment, loginFragment);
        }

        transaction.commit();

        // Spinners
        ArrayAdapter<CharSequence> truthAdapter = ArrayAdapter
                .createFromResource(this, R.array.truth_values, android.R.layout.simple_spinner_item);
        truthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        leftSpinner.setAdapter(truthAdapter);
        rightSpinner.setAdapter(truthAdapter);
        contentSpinner.setAdapter(truthAdapter);
        leftSpinner.setSelection(0);
        rightSpinner.setSelection(0);

        // Navigation
        for (Button button : Arrays.asList(logicButton, friendsButton, settingsButton, contentButton)) {
            initializeNavigationButton(button);
        }

        // Logic
        initializeCalculationButton(andButton);
        initializeCalculationButton(orButton);

        // Friends
        friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(FacebookException error) {
                LogicActivity.this.onError(error);
            }
        });
        friendPickerFragment.setUserId("me");
        friendPickerFragment.setMultiSelect(false);
        friendPickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged() {
                LogicActivity.this.onFriendSelectionChanged();
            }
        });

        // Content
        contentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                LogicActivity.this.onContentSelectionChanged();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                LogicActivity.this.onContentSelectionChanged();
            }
        });
<commit_msg>Moved filter code for BoolOG for all fragments<commit_after>package com.facebook.samples.booleanog;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.facebook.*;

import java.text.SimpleDateFormat;
import java.util.*;

public class LogicActivity extends FragmentActivity {

    private static final String TAG = "BooleanOpenGraphSample";

    private static final String SAVE_ACTIVE_TAB = TAG + ".SAVE_ACTIVE_TAB";
    private static final String SAVE_CONTENT_SELECTION = TAG + ".SAVE_CONTENT_SELECTION";
    private static final String SAVE_LEFT_OPERAND_SELECTION = TAG + ".SAVE_LEFT_OPERAND_SELECTION";
    private static final String SAVE_RIGHT_OPERAND_SELECTION = TAG + ".SAVE_RIGHT_OPERAND_SELECTION";
    private static final String SAVE_RESULT_TEXT = TAG + ".SAVE_RESULT_TEXT";
    private static final String SAVE_POST_RESULT_TEXT = TAG + ".SAVE_POST_RESULT_TEXT";

    private static final String AND_ACTION = "fb_sample_boolean_og:and";
    private static final String OR_ACTION = "fb_sample_boolean_og:or";
    private static final String POST_AND_ACTION_PATH = "me/" + AND_ACTION;
    private static final String POST_OR_ACTION_PATH = "me/" + OR_ACTION;
    private static final String TRUE_GRAPH_OBJECT_URL = "http://samples.ogp.me/369360019783304";
    private static final String FALSE_GRAPH_OBJECT_URL = "http://samples.ogp.me/369360256449947";
    private static final String INSTALLED = "installed";

    private static volatile TruthValueGraphObject TRUE_GRAPH_OBJECT;
    private static volatile TruthValueGraphObject FALSE_GRAPH_OBJECT;
    private static volatile int TRUE_SPINNER_INDEX = -1;
    private static volatile int FALSE_SPINNER_INDEX = -1;

    // Main layout
    private Button logicButton;
    private Button friendsButton;
    private Button settingsButton;
    private Button contentButton;
    private String activeTab;

    // Logic group
    private ViewGroup logicGroup;
    private Spinner leftSpinner;
    private Spinner rightSpinner;
    private Button andButton;
    private Button orButton;
    private TextView resultText;
    private TextView postResultText;

    // Friends group
    private ViewGroup friendsGroup;
    private FriendPickerFragment friendPickerFragment;
    private RequestAsyncTask pendingRequest;
    private SimpleCursorAdapter friendActivityAdapter;
    private ProgressBar friendActivityProgressBar;

    // Login group
    private ViewGroup settingsGroup;
    private LoginFragment loginFragment;

    // Content group
    private ViewGroup contentGroup;
    private ImageView contentImage;
    private Spinner contentSpinner;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Views
        logicButton = (Button) findViewById(R.id.logic_button);
        friendsButton = (Button) findViewById(R.id.friends_button);
        settingsButton = (Button) findViewById(R.id.settings_button);
        contentButton = (Button) findViewById(R.id.content_button);

        logicGroup = (ViewGroup) findViewById(R.id.logic_group);
        leftSpinner = (Spinner) findViewById(R.id.left_spinner);
        rightSpinner = (Spinner) findViewById(R.id.right_spinner);
        andButton = (Button) findViewById(R.id.and_button);
        orButton = (Button) findViewById(R.id.or_button);
        resultText = (TextView) findViewById(R.id.result_text);
        postResultText = (TextView) findViewById(R.id.post_result_text);

        friendsGroup = (ViewGroup) findViewById(R.id.friends_group);
        ListView friendActivityList = (ListView) findViewById(R.id.friend_activity_list);
        String[] mapColumnNames = {"date", "action"};
        int[] mapViewIds = {R.id.friend_action_date, R.id.friend_action_data};
        friendActivityAdapter = new SimpleCursorAdapter(this, R.layout.friend_activity_row, createEmptyCursor(),
                mapColumnNames, mapViewIds);
        friendActivityList.setAdapter(friendActivityAdapter);
        friendActivityProgressBar = (ProgressBar) findViewById(R.id.friend_activity_progress_bar);

        settingsGroup = (ViewGroup) findViewById(R.id.settings_group);

        contentGroup = (ViewGroup) findViewById(R.id.content_group);
        contentImage = (ImageView) findViewById(R.id.content_image);
        contentSpinner = (Spinner) findViewById(R.id.content_spinner);

        // Fragments
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();

        friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
        if (friendPickerFragment == null) {
            friendPickerFragment = new FriendPickerFragment();
            transaction.add(R.id.friend_picker_fragment, friendPickerFragment);
        }

        loginFragment = (LoginFragment) fragmentManager.findFragmentById(R.id.login_fragment);
        if (loginFragment == null) {
            loginFragment = new LoginFragment();
            transaction.add(R.id.login_fragment, loginFragment);
        }

        transaction.commit();

        // Spinners
        ArrayAdapter<CharSequence> truthAdapter = ArrayAdapter
                .createFromResource(this, R.array.truth_values, android.R.layout.simple_spinner_item);
        truthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        leftSpinner.setAdapter(truthAdapter);
        rightSpinner.setAdapter(truthAdapter);
        contentSpinner.setAdapter(truthAdapter);
        leftSpinner.setSelection(0);
        rightSpinner.setSelection(0);

        // Navigation
        for (Button button : Arrays.asList(logicButton, friendsButton, settingsButton, contentButton)) {
            initializeNavigationButton(button);
        }

        // Logic
        initializeCalculationButton(andButton);
        initializeCalculationButton(orButton);

        // Friends
        friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(FacebookException error) {
                LogicActivity.this.onError(error);
            }
        });
        friendPickerFragment.setUserId("me");
        friendPickerFragment.setMultiSelect(false);
        friendPickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged() {
                LogicActivity.this.onFriendSelectionChanged();
            }
        });
        friendPickerFragment.setExtraFields(Arrays.asList(INSTALLED));
        friendPickerFragment.setFilter(new PickerFragment.GraphObjectFilter<GraphUser>() {
            @Override
            public boolean includeItem(GraphUser graphObject) {
                Boolean installed = graphObject.cast(GraphUserWithInstalled.class).getInstalled();
                return (installed != null) && installed.booleanValue();
            }
        });

        // Content
        contentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                LogicActivity.this.onContentSelectionChanged();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                LogicActivity.this.onContentSelectionChanged();
            }
        });

{'fraction_non_alphanumeric': 0.08260789035006483, 'fraction_numerical': 0.004692226955609063, 'mean_word_length': 3.4136239782016347, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4444390', 'n_tokens_mistral': 4318, 'n_tokens_neox': 4097, 'n_words': 863}