<commit_before>package com.biotronisis.pettplant.activity.fragment;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.biotronisis.pettplant.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public final class BluetoothScanFragment extends DialogFragment {
	
//    private static final String TAG = "BluetoothScanFragment";

    // Return Intent extra
//    public static String EXTRA_DEVICE_ADDRESS = "device_address";
    
    private LayoutInflater inflator;

    // Member fields
    private BluetoothAdapter bluetoothAdapter;
    private List<MyItem> items;
    private MyDeviceAdapter listAdapter;
    private MyBluetoothBroadcastReceiver receiver;
   private Context parentContext;
    
    private OnBluetoothDeviceSelectedListener listener;

   public void setContext(Context thisContext) {
      parentContext = thisContext;
   }
    
    public void setOnBluetoothDeviceSelectedListener(OnBluetoothDeviceSelectedListener listener) {
    	this.listener = listener;
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_bluetooth_scan, container, false);

        this.inflator = inflater;

//       v.setBackground(ContextCompat.getDrawable(parentContext, R.drawable.layout_background_spinner));

       getDialog().setTitle(getString(R.string.select_device));

        items = new ArrayList<MyItem>();
        listAdapter = new MyDeviceAdapter();

        // Find and set up the ListView for paired devices
        ListView listView = (ListView) v.findViewById(R.id.listView);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(listAdapter);
        listView.setBackground(ContextCompat.getDrawable(parentContext, R.drawable.layout_background_bluetooth));

        receiver = new MyBluetoothBroadcastReceiver();

        // Get the local Bluetooth adapter
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        return v;
    }
    
    @Override
    public void onResume() {
        super.onResume();

        items.clear();
        listAdapter.notifyDataSetChanged();

        // Register for broadcasts when a device is discovered
        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
        getActivity().registerReceiver(receiver, filter);

        // Register for broadcasts when discovery has finished
        filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
        getActivity().registerReceiver(receiver, filter);

        // Get a set of currently paired devices
        Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();<commit_msg>Added code to hide the dialog title. Changed a member name. Reformatted some code.<commit_after>package com.biotronisis.pettplant.activity.fragment;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.biotronisis.pettplant.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public final class BluetoothScanFragment extends DialogFragment {
	
//    private static final String TAG = "BluetoothScanFragment";

    // Return Intent extra
//    public static String EXTRA_DEVICE_ADDRESS = "device_address";

   private LayoutInflater inflator;

   // Member fields
   private BluetoothAdapter bluetoothAdapter;
   private List<MyItem> items;
   private MyDeviceAdapter listAdapter;
   private MyBluetoothBroadcastReceiver receiver;
   private Context parentContext;
    
    private OnBluetoothDeviceSelectedListener listener;

   public void setContext(Context thisContext) {
      parentContext = thisContext;
   }
    
    public void setOnBluetoothDeviceSelectedListener(OnBluetoothDeviceSelectedListener listener) {
    	this.listener = listener;
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_bluetooth_scan, container, false);

        this.inflator = inflater;

//       view.setBackground(ContextCompat.getDrawable(parentContext, R.drawable.layout_background_spinner));

//       getDialog().setTitle(getString(R.string.select_device));

       // Hide the title.
       getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        items = new ArrayList<MyItem>();
        listAdapter = new MyDeviceAdapter();

        // Find and set up the ListView for paired devices
        ListView listView = (ListView) view.findViewById(R.id.listView);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(listAdapter);
        listView.setBackground(ContextCompat.getDrawable(parentContext, R.drawable.layout_background_bluetooth));

        receiver = new MyBluetoothBroadcastReceiver();

        // Get the local Bluetooth adapter
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        return view;
    }
    
    @Override
    public void onResume() {
        super.onResume();

        items.clear();
        listAdapter.notifyDataSetChanged();

        // Register for broadcasts when a device is discovered
        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
        getActivity().registerReceiver(receiver, filter);

        // Register for broadcasts when discovery has finished
        filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
        getActivity().registerReceiver(receiver, filter);

        // Get a set of currently paired devices
        Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
{'fraction_non_alphanumeric': 0.07908534809204777, 'fraction_numerical': 0.0005825808330905913, 'mean_word_length': 3.92258064516129, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5760638', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1731, 'n_words': 410}