SeekArc

https://github.com/neild001/SeekArc

https://github.com/imflyn/SeekArc

转载于:https://www.cnblogs.com/pengmn/p/10149053.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的Android应用程序示例,可以在MainActivity上填写IP地址和端口号,然后通过socket监听该端口,并且可以通过两个半圆进度条向端口发送数字。 1. 首先,在Android Studio中创建一个新项目。 2. 然后,在MainActivity的布局文件中添加以下代码: ```xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="IP地址" /> <EditText android:id="@+id/ip_address" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" android:text="192.168.1.1" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="端口号" /> <EditText android:id="@+id/port_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:text="8080" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="进度条1" /> <com.github.lzyzsd.circleprogress.ArcProgress android:id="@+id/arc_progress1" android:layout_width="match_parent" android:layout_height="200dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="进度条2" /> <com.github.lzyzsd.circleprogress.ArcProgress android:id="@+id/arc_progress2" android:layout_width="match_parent" android:layout_height="200dp" /> </LinearLayout> ``` 3. 然后,在MainActivity中添加以下代码: ```java public class MainActivity extends AppCompatActivity { private EditText mIpAddressEditText; private EditText mPortNumberEditText; private ArcProgress mArcProgress1; private ArcProgress mArcProgress2; private Socket mSocket; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mIpAddressEditText = findViewById(R.id.ip_address); mPortNumberEditText = findViewById(R.id.port_number); mArcProgress1 = findViewById(R.id.arc_progress1); mArcProgress2 = findViewById(R.id.arc_progress2); mArcProgress1.setOnSeekArcChangeListener(new OnSeekArcChangeListener() { @Override public void onProgressChanged(SeekArc seekArc, int progress, boolean fromUser) { if (mSocket != null && mSocket.isConnected()) { try { OutputStream outputStream = mSocket.getOutputStream(); outputStream.write(progress); outputStream.flush(); } catch (IOException e) { e.printStackTrace(); } } } @Override public void onStartTrackingTouch(SeekArc seekArc) { } @Override public void onStopTrackingTouch(SeekArc seekArc) { } }); mArcProgress2.setOnSeekArcChangeListener(new OnSeekArcChangeListener() { @Override public void onProgressChanged(SeekArc seekArc, int progress, boolean fromUser) { if (mSocket != null && mSocket.isConnected()) { try { OutputStream outputStream = mSocket.getOutputStream(); outputStream.write(progress); outputStream.flush(); } catch (IOException e) { e.printStackTrace(); } } } @Override public void onStartTrackingTouch(SeekArc seekArc) { } @Override public void onStopTrackingTouch(SeekArc seekArc) { } }); new Thread(new Runnable() { @Override public void run() { try { String ipAddress = mIpAddressEditText.getText().toString(); int portNumber = Integer.parseInt(mPortNumberEditText.getText().toString()); mSocket = new Socket(ipAddress, portNumber); InputStream inputStream = mSocket.getInputStream(); OutputStream outputStream = mSocket.getOutputStream(); while (true) { byte[] buffer = new byte[1024]; int bytesRead = inputStream.read(buffer); if (bytesRead != -1) { String message = new String(buffer, 0, bytesRead); Log.d("MainActivity", "Received message: " + message); } } } catch (Exception e) { e.printStackTrace(); } } }).start(); } } ``` 4. 最后,添加以下依赖项: ``` implementation 'com.github.lzyzsd:circleprogress:1.2.1' ``` 完成以上步骤后,运行应用程序,即可在主页面上填写IP地址和端口号,监听该端口,并且可以通过两个半圆进度条向端口发送数字。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值