Skip to content

Commit

Permalink
Ensure visible delete-button.
Browse files Browse the repository at this point in the history
Prevent NullPointer on missing handler.
Allow to stop receiving-process.
  • Loading branch information
Starcommander committed Oct 26, 2023
1 parent 8247c19 commit 38aa00b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -56,6 +57,7 @@ public enum EType { Export, Import, Transmit, Receive }
LinearLayout lExport;
LinearLayout lReceive;
LinearLayout lMaps;
Button rcOk;

/** Returns the selected Type. */
private EType getSelectedType()
Expand All @@ -68,7 +70,7 @@ private EType getSelectedType()
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_export);
Button exOk = (Button) findViewById(R.id.exOk);
Button rcOk = (Button) findViewById(R.id.rcOk);
rcOk = (Button) findViewById(R.id.rcOk);
exSpinner = (Spinner) findViewById(R.id.exSpinner);
exTypeSpinner = (Spinner) findViewById(R.id.exTypeSpinner);
exFullPathTv = (TextView) findViewById(R.id.exFullPathTv);
Expand Down Expand Up @@ -225,10 +227,23 @@ else if (!btUtil.isEnabled())
}
else
{
exStatus.setText("Receiving start ...");
exStatus.setTextColor(0xFF0000FF); // 0xAARRGGBB
String targetDir = ((PathElement)exSpinner.getSelectedItem()).getPath();
receiveNow(targetDir);
if (btUtil.isReceiving())
{
log("Cur state receiving");
btUtil.stopReceiver();
exStatus.setText("-----");
exStatus.setTextColor(0xFF000000); // 0xAARRGGBB
rcOk.setText(R.string.receive);
}
else
{
log("Cur state: not receiving");
exStatus.setText("Receiving start ...");
exStatus.setTextColor(0xFF0000FF); // 0xAARRGGBB
String targetDir = ((PathElement)exSpinner.getSelectedItem()).getPath();
receiveNow(targetDir);
rcOk.setText(R.string.stop);
}
}
}
else
Expand Down Expand Up @@ -392,6 +407,11 @@ else if (getSelectedType() == EType.Transmit)
Button button = new Button(this);
button.setText(f);
button.setOnClickListener(this);
DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
button.setMaxWidth((int)((float)outMetrics.widthPixels*0.8)); // Never use full width.
button.setMinWidth((int)((float)outMetrics.widthPixels*0.8)); // Never use full width.
button.setWidth((int)((float)outMetrics.widthPixels*0.8)); // Never use full width.
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
ll.addView(button);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BluetoothService {
private final static Logger log = Logger.getLogger(BluetoothService.class.getName());

private final BluetoothAdapter mAdapter;
Handler mReceiver;
Handler mReceiver = new Handler();
private AcceptThread mSecureAcceptThread;
private ConnectThread mConnectThread;
private ConnectedThread mConnectedThread;
Expand Down Expand Up @@ -243,6 +243,7 @@ public synchronized void stop() {
}
mState = STATE_NONE;
updateUserInterfaceTitle();
mReceiver = new Handler();
}

/**
Expand Down Expand Up @@ -339,7 +340,7 @@ public void run() {
// successful connection or an exception
socket = mmServerSocket.accept();
} catch (IOException e) {
log.log(Level.SEVERE, "Socket Type: " + mSocketType + "accept() failed", e);
log.log(Level.SEVERE, "Socket Type: " + mSocketType + " accept() failed", e);
break;
}

Expand Down Expand Up @@ -542,6 +543,7 @@ public boolean write(String msg)
catch (IOException e)
{
log.log(Level.SEVERE, "Exception during obj-write", e);
BluetoothService.this.stop();
return false;
}
return true;
Expand All @@ -558,6 +560,7 @@ public boolean write(byte[] buffer, int len) {
mmOutStream.flush(); // Ensure all data is written.
} catch (IOException e) {
log.log(Level.SEVERE, "Exception during write", e);
BluetoothService.this.stop();
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,21 @@ public boolean isConnected()
return service.getState() == BluetoothService.STATE_CONNECTED;
}

public boolean isReceiving()
{
return service.getState() == BluetoothService.STATE_LISTEN;
}

public void startReceiver(Handler receiver)
{
service.startReceiver(receiver);
}

public void stopReceiver()
{
service.stop();
}

int selectedIndex = -1;
/**
* Start the ConnectThread to initiate a connection to a remote device.
Expand Down

0 comments on commit 38aa00b

Please sign in to comment.