Author SHA1 Message Date
stan220 2e8cdd9e41 Added refresh button and control disabling. 2021-01-05 11:18:55 +03:00
stan220 6f4ef43481 Fix resume. 2020-12-24 16:09:50 +03:00
2 changed files with 41 additions and 7 deletions
@@ -6,7 +6,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@@ -51,20 +50,36 @@ public class MainActivity extends AppCompatActivity {
}));
System.out.println("App started!!!");
new DownloadFilesTask(this).execute();
}
@Override
protected void onResume() {
super.onResume();
System.out.println("App resumed!!!");
new DownloadFilesTask(this).execute();
}
public void onSwitchClick(View view) {
System.out.println("### click: " + view);
System.out.println("### switch clicked: " + view);
new DownloadFilesTask(this).execute((SwitchMaterial) view);
}
public void onRefreshButtonClick(View view) {
System.out.println("### refresh clicked: " + view);
new DownloadFilesTask(this).execute();
}
private static class DownloadFilesTask extends AsyncTask<SwitchMaterial, Void, List<String>> {
private MainActivity context;
public DownloadFilesTask(MainActivity context) {
context.findViewById(R.id.switchTab).setEnabled(false);
context.findViewById(R.id.switchTv).setEnabled(false);
context.findViewById(R.id.switchAlisa).setEnabled(false);
context.findViewById(R.id.button_refresh).setEnabled(false);
this.context = context;
}
@@ -72,7 +87,7 @@ public class MainActivity extends AppCompatActivity {
protected List<String> doInBackground(SwitchMaterial... switches) {
List<String> result = new ArrayList<>();
Socket s = null;
Socket s;
try {
s = new Socket(InetAddress.getByName("192.168.100.1"), 23);
@@ -170,7 +185,12 @@ public class MainActivity extends AppCompatActivity {
switchAlisa.setChecked(false);
}
Toast.makeText(context, "Состояние обновлено!", Toast.LENGTH_LONG).show();
context.findViewById(R.id.switchTab).setEnabled(true);
context.findViewById(R.id.switchTv).setEnabled(true);
context.findViewById(R.id.switchAlisa).setEnabled(true);
context.findViewById(R.id.button_refresh).setEnabled(true);
Toast.makeText(context, "Статус обновлён!", Toast.LENGTH_LONG).show();
}
}
+16 -2
View File
@@ -5,12 +5,23 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
android:foregroundGravity="fill"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="@+id/button_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onRefreshButtonClick"
android:text="Обновить" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/switchTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onSwitchClick"
android:text="Tab"
app:useMaterialThemeColors="true" />
@@ -19,6 +30,7 @@
android:id="@+id/switchTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onSwitchClick"
android:text="TV"
app:useMaterialThemeColors="true" />
@@ -27,6 +39,7 @@
android:id="@+id/switchAlisa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onSwitchClick"
android:text="Alisa"
app:useMaterialThemeColors="true" />
@@ -34,7 +47,8 @@
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="586dp"
android:layout_height="538dp"
android:layout_gravity="fill"
android:fadeScrollbars="false"
android:gravity="bottom"
android:isScrollContainer="true"