This commit is contained in:
parent
29b31fbf69
commit
cafdfe3e4d
|
|
@ -1,10 +1,14 @@
|
||||||
package com.example.kingway.ptt;
|
package com.example.kingway.ptt;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
|
@ -12,29 +16,44 @@ import com.hjq.permissions.Permission;
|
||||||
import com.hjq.permissions.XXPermissions;
|
import com.hjq.permissions.XXPermissions;
|
||||||
import com.stand.standapp.R;
|
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 {
|
public class pttActivity extends AppCompatActivity {
|
||||||
private Button pttBtn;
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_ptt);
|
setContentView(R.layout.activity_ptt);
|
||||||
|
|
||||||
|
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);
|
pttBtn = (Button) findViewById(R.id.pttBtn);
|
||||||
XXPermissions.with(this)
|
XXPermissions.with(this)
|
||||||
.permission(Permission.RECORD_AUDIO)
|
.permission(Permission.RECORD_AUDIO)
|
||||||
.request(null);
|
.request(null);
|
||||||
pttBtn.setOnTouchListener(new View.OnTouchListener()
|
pttBtn.setOnTouchListener(new View.OnTouchListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent motionEvent)
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||||
{
|
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN)
|
|
||||||
{
|
|
||||||
pttBtn.setBackgroundColor(Color.RED);
|
pttBtn.setBackgroundColor(Color.RED);
|
||||||
SendAtUtil.speakPlay();
|
SendAtUtil.speakPlay();
|
||||||
}
|
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
|
||||||
else if(motionEvent.getAction() == MotionEvent.ACTION_UP)
|
|
||||||
{
|
|
||||||
pttBtn.setBackgroundColor(Color.BLUE);
|
pttBtn.setBackgroundColor(Color.BLUE);
|
||||||
SendAtUtil.speakRelease();
|
SendAtUtil.speakRelease();
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +61,6 @@ public class pttActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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() {
|
findViewById(R.id.login1).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
SendAtUtil.toLogin("test004", "123456", "220.154.131.231", 1, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 获取群组 */
|
|
||||||
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
@ -67,7 +100,6 @@ public class pttActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 获取群成员 */
|
|
||||||
findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
@ -75,7 +107,6 @@ public class pttActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 切换群组 */
|
|
||||||
findViewById(R.id.btnJumpGroup).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.btnJumpGroup).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
@ -90,7 +121,6 @@ public class pttActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 切换群组 */
|
|
||||||
findViewById(R.id.btnCancel2).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.btnCancel2).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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,18 +5,97 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="com.example.kingway.ptt.pttActivity">
|
tools:context="com.example.kingway.ptt.pttActivity">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
android:padding="16dp">
|
||||||
>
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="服务器IP"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginBottom="4dp"/>
|
||||||
|
|
||||||
|
<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"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="账号"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginBottom="4dp"/>
|
||||||
|
|
||||||
|
<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"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="密码"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginBottom="4dp"/>
|
||||||
|
|
||||||
|
<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"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="群组ID"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginBottom="4dp"/>
|
||||||
|
|
||||||
|
<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
|
<Button
|
||||||
android:id="@+id/login"
|
android:id="@+id/login"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="login"/>
|
android:text="默认登录(gzzdweb01)"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnCustomLogin"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="自定义登录"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/pttBtn"
|
android:id="@+id/pttBtn"
|
||||||
|
|
@ -71,5 +150,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="login1" />
|
android:text="login1" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue