This commit is contained in:
parent
29b31fbf69
commit
cafdfe3e4d
|
|
@ -1,10 +1,14 @@
|
|||
package com.example.kingway.ptt;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
|
|
@ -12,29 +16,44 @@ import com.hjq.permissions.Permission;
|
|||
import com.hjq.permissions.XXPermissions;
|
||||
import com.stand.standapp.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class pttActivity extends AppCompatActivity {
|
||||
private Button pttBtn;
|
||||
private AutoCompleteTextView etIp, etAccount, etPassword, etGroupId;
|
||||
private static final String PREFS_NAME = "ptt_history";
|
||||
private static final String KEY_IP_HISTORY = "ip_history";
|
||||
private static final String KEY_ACCOUNT_HISTORY = "account_history";
|
||||
private static final String KEY_PASSWORD_HISTORY = "password_history";
|
||||
private static final String KEY_GROUP_HISTORY = "group_history";
|
||||
private static final String SEPARATOR = ",";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_ptt);
|
||||
pttBtn = (Button)findViewById(R.id.pttBtn);
|
||||
|
||||
etIp = findViewById(R.id.etIp);
|
||||
etAccount = findViewById(R.id.etAccount);
|
||||
etPassword = findViewById(R.id.etPassword);
|
||||
etGroupId = findViewById(R.id.etGroupId);
|
||||
|
||||
loadHistory();
|
||||
|
||||
pttBtn = (Button) findViewById(R.id.pttBtn);
|
||||
XXPermissions.with(this)
|
||||
.permission(Permission.RECORD_AUDIO)
|
||||
.request(null);
|
||||
pttBtn.setOnTouchListener(new View.OnTouchListener()
|
||||
{
|
||||
pttBtn.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent)
|
||||
{
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN)
|
||||
{
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
pttBtn.setBackgroundColor(Color.RED);
|
||||
SendAtUtil.speakPlay();
|
||||
}
|
||||
else if(motionEvent.getAction() == MotionEvent.ACTION_UP)
|
||||
{
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
|
||||
pttBtn.setBackgroundColor(Color.BLUE);
|
||||
SendAtUtil.speakRelease();
|
||||
}
|
||||
|
|
@ -42,7 +61,6 @@ public class pttActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -50,16 +68,31 @@ public class pttActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.btnCustomLogin).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String ip = etIp.getText().toString().trim();
|
||||
String account = etAccount.getText().toString().trim();
|
||||
String password = etPassword.getText().toString().trim();
|
||||
String groupId = etGroupId.getText().toString().trim();
|
||||
|
||||
if (ip.isEmpty() || account.isEmpty() || password.isEmpty() || groupId.isEmpty()) {
|
||||
Toast.makeText(pttActivity.this, "请填写所有字段", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
saveToHistory(ip, account, password, groupId);
|
||||
SendAtUtil.toLogin(account, password, ip, 1, 1);
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.login1).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// SendAtUtil.toLogin("gzzdweb01", "123456", "61.243.1.123", 1, 1);
|
||||
SendAtUtil.toLogin("test004", "123456", "220.154.131.231", 1, 1);
|
||||
}
|
||||
});
|
||||
|
||||
/** 获取群组 */
|
||||
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -67,7 +100,6 @@ public class pttActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
/** 获取群成员 */
|
||||
findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -75,7 +107,6 @@ public class pttActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
/** 切换群组 */
|
||||
findViewById(R.id.btnJumpGroup).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -90,7 +121,6 @@ public class pttActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
/** 切换群组 */
|
||||
findViewById(R.id.btnCancel2).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -98,4 +128,44 @@ public class pttActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadHistory() {
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
||||
setupAdapter(etIp, prefs.getString(KEY_IP_HISTORY, ""));
|
||||
setupAdapter(etAccount, prefs.getString(KEY_ACCOUNT_HISTORY, ""));
|
||||
setupAdapter(etPassword, prefs.getString(KEY_PASSWORD_HISTORY, ""));
|
||||
setupAdapter(etGroupId, prefs.getString(KEY_GROUP_HISTORY, ""));
|
||||
}
|
||||
|
||||
private void setupAdapter(AutoCompleteTextView view, String historyStr) {
|
||||
List<String> items = new ArrayList<>();
|
||||
if (!historyStr.isEmpty()) {
|
||||
items.addAll(Arrays.asList(historyStr.split(SEPARATOR)));
|
||||
}
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_dropdown_item_1line, items);
|
||||
view.setAdapter(adapter);
|
||||
view.setThreshold(1);
|
||||
}
|
||||
|
||||
private void saveToHistory(String ip, String account, String password, String groupId) {
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString(KEY_IP_HISTORY, addToHistory(prefs.getString(KEY_IP_HISTORY, ""), ip));
|
||||
editor.putString(KEY_ACCOUNT_HISTORY, addToHistory(prefs.getString(KEY_ACCOUNT_HISTORY, ""), account));
|
||||
editor.putString(KEY_PASSWORD_HISTORY, addToHistory(prefs.getString(KEY_PASSWORD_HISTORY, ""), password));
|
||||
editor.putString(KEY_GROUP_HISTORY, addToHistory(prefs.getString(KEY_GROUP_HISTORY, ""), groupId));
|
||||
editor.apply();
|
||||
loadHistory();
|
||||
}
|
||||
|
||||
private String addToHistory(String existing, String newValue) {
|
||||
LinkedHashSet<String> set = new LinkedHashSet<>();
|
||||
if (!existing.isEmpty()) {
|
||||
set.addAll(Arrays.asList(existing.split(SEPARATOR)));
|
||||
}
|
||||
set.remove(newValue);
|
||||
set.add(newValue);
|
||||
return String.join(SEPARATOR, set);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,71 +5,152 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.example.kingway.ptt.pttActivity">
|
||||
<LinearLayout
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
>
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="login"/>
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/pttBtn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="PTT" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="服务器IP"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:text="获取群组" />
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/etIp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="服务器IP"
|
||||
android:inputType="text"
|
||||
android:text="220.154.131.231"
|
||||
android:dropDownWidth="match_parent"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="获取成员" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="账号"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnTmpCall"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="开始单呼" />
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/etAccount"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="账号"
|
||||
android:inputType="text"
|
||||
android:text="test004"
|
||||
android:dropDownWidth="match_parent"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnTmpCallStop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="结束单呼" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="密码"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpGroup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="切换群组" />
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/etPassword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="密码"
|
||||
android:inputType="textPassword"
|
||||
android:text="123456"
|
||||
android:dropDownWidth="match_parent"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="取消登录" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="群组ID"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="注销" />
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/etGroupId"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="群组ID"
|
||||
android:inputType="text"
|
||||
android:text="00000001"
|
||||
android:dropDownWidth="match_parent"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/login1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="login1" />
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="默认登录(gzzdweb01)"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCustomLogin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="自定义登录"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/pttBtn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="PTT" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:text="获取群组" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="获取成员" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnTmpCall"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="开始单呼" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnTmpCallStop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="结束单呼" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpGroup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="切换群组" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="取消登录" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="注销" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/login1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="login1" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
|||
Loading…
Reference in New Issue