Last active
June 26, 2017 21:43
-
-
Save matiri132/4180ce0c351c91f6b177e94bbcc5d111 to your computer and use it in GitHub Desktop.
TrajeLedBT-src
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.trajeledbt; | |
import android.bluetooth.BluetoothSocket; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
/** | |
* Created by root on 12/06/17. | |
*/ | |
public class ConnectThread extends Thread { | |
private final InputStream mmInStream; | |
private final OutputStream mmOutStream; | |
public ConnectThread(BluetoothSocket socket) { | |
InputStream tmpIn = null; | |
OutputStream tmpOut = null; | |
try { | |
tmpIn = socket.getInputStream(); | |
tmpOut = socket.getOutputStream(); | |
} catch (IOException e) { } | |
mmInStream = tmpIn; | |
mmOutStream = tmpOut; | |
} | |
public void run() { | |
} | |
/* Call this from the main activity to send data to the remote device */ | |
public void send(String send) { | |
byte[] buffer = send.getBytes(); | |
try { | |
mmOutStream.write(buffer); | |
} catch (IOException e) { } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.trajeledbt; | |
import android.app.ListActivity; | |
import android.bluetooth.BluetoothAdapter; | |
import android.bluetooth.BluetoothDevice; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.view.View; | |
import android.widget.ArrayAdapter; | |
import android.widget.ListView; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import java.util.Set; | |
public class DevicesList extends ListActivity { | |
static String MAC_ADRESS = null; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ArrayAdapter<String> ArrayBluetooth = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); | |
if (BluetoothAdapter.getDefaultAdapter().getBondedDevices().size() > 0) { | |
for (BluetoothDevice device : BluetoothAdapter.getDefaultAdapter().getBondedDevices()) { | |
ArrayBluetooth.add(device.getName()); | |
} | |
} | |
setListAdapter(ArrayBluetooth); | |
} | |
@Override | |
protected void onListItemClick(ListView l, View v, int position, long id) { | |
super.onListItemClick(l, v, position, id); | |
String generalinfo = ((TextView) v).getText().toString(); | |
for (BluetoothDevice device : BluetoothAdapter.getDefaultAdapter().getBondedDevices()) { | |
if (device.getName().equals(generalinfo)) { | |
Intent macreturn = new Intent(); | |
macreturn.putExtra(MAC_ADRESS, device.getAddress()); | |
setResult(RESULT_OK, macreturn); | |
finish(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.trajeledbt; | |
import android.content.Intent; | |
import android.support.v4.app.Fragment; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.Button; | |
import android.widget.Toast; | |
import com.trajeledbt.R; | |
public class Tab1 extends Fragment { | |
Button mode1; | |
Button mode2; | |
Button modeoff; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.tab1 , container , false); | |
mode1 = (Button)view.findViewById(R.id.butMode1); | |
mode1.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
if(((MainMenu)getActivity()).connection){ | |
((MainMenu)getActivity()).connectedThread.send("led1"); | |
} | |
else{ | |
Toast.makeText(((MainMenu)getActivity()).getApplicationContext(), R.string.error, Toast.LENGTH_LONG).show(); | |
} | |
} | |
}); | |
mode2 = (Button)view.findViewById(R.id.butMode2); | |
mode2.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
if(((MainMenu)getActivity()).connection){ | |
((MainMenu)getActivity()).connectedThread.send("led2"); | |
} | |
else{ | |
Toast.makeText(((MainMenu)getActivity()).getApplicationContext(), R.string.error, Toast.LENGTH_LONG).show(); | |
} | |
} | |
}); | |
modeoff = (Button)view.findViewById(R.id.butOff); | |
modeoff.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
if(((MainMenu)getActivity()).connection){ | |
((MainMenu)getActivity()).connectedThread.send("off"); | |
} | |
else{ | |
Toast.makeText(((MainMenu)getActivity()).getApplicationContext(), R.string.error, Toast.LENGTH_LONG).show(); | |
} | |
} | |
}); | |
return view; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.trajeledbt; | |
import android.support.v4.app.Fragment; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import com.trajeledbt.R; | |
/** | |
* Created by root on 12/06/17. | |
*/ | |
public class Tab2 extends Fragment { | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { | |
return inflater.inflate(R.layout.tab2 , container , false); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.trajeledbt; | |
import android.support.v4.app.Fragment; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import com.trajeledbt.R; | |
/** | |
* Created by root on 12/06/17. | |
*/ | |
public class Tab3 extends Fragment { | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { | |
return inflater.inflate(R.layout.tab3 , container , false); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.trajeledbt; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.Button; | |
public class TabConectBt extends Fragment { | |
Button butconnectBt; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.conect_bt , container , false); | |
butconnectBt = (Button)view.findViewById(R.id.butconnectBt); | |
butconnectBt.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
((MainMenu)getActivity()).connectBluetooth(); | |
} | |
}); | |
return view; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment