Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9089691

Browse files
committed
added loading screen
1 parent 90e1e5f commit 9089691

File tree

11 files changed

+106
-17
lines changed

11 files changed

+106
-17
lines changed

‎app/build.gradle‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ dependencies {
5858
implementation 'com.github.QuadFlask:colorpicker:0.0.13'
5959

6060
implementation 'com.google.code.gson:gson:2.8.6'
61+
62+
implementation 'com.pnikosis:materialish-progress:1.7'
6163
}

‎app/src/main/java/com/example/chatfull/ChatActivity.java‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class ChatActivity extends AppCompatActivity
9191
int[] colors;
9292

9393
List<Message> messageArrayList;
94-
boolean saved = false, loaded = false;
94+
boolean saved = false, loaded = false, offline = false;
9595

9696
@Override
9797
protected void onCreate(Bundle savedInstanceState) {
@@ -128,8 +128,6 @@ public void loadImage(ImageView imageView, @Nullable String url, @Nullable Objec
128128
.asBitmap()
129129
.load(byteArray)
130130
.error(R.drawable.baseline_insert_drive_file_24)
131-
.thumbnail(0.25f)
132-
.sizeMultiplier(.60f)
133131
.into(imageView);
134132
}
135133
};
@@ -433,6 +431,7 @@ public void stopSender() {
433431
public void setMessage(final Message msg) {
434432
Log.e("IN_SET", msg.toString());
435433
if (msg.isOffline()) {
434+
offline = true;
436435
if (sender != null)
437436
sender.cancel(true);
438437
if (messageReceiveServer != null)
@@ -507,14 +506,16 @@ public void onBackPressed() {
507506
saved = true;
508507
}
509508
loaded = false;
510-
Message message = new Message(Integer.toString(++cnt), MainActivity.me, null);
511-
message.setOffline(true);
512-
sender = new SendMessage(user.getIpAddress(), user.getPort(), message, this);
513-
sender.execute();
514-
try {
515-
Thread.sleep(500);
516-
} catch (InterruptedException e) {
517-
e.printStackTrace();
509+
if(offline == false) {
510+
Message message = new Message(Integer.toString(++cnt), MainActivity.me, null);
511+
message.setOffline(true);
512+
sender = new SendMessage(user.getIpAddress(), user.getPort(), message, this);
513+
sender.execute();
514+
try {
515+
Thread.sleep(500);
516+
} catch (InterruptedException e) {
517+
e.printStackTrace();
518+
}
518519
}
519520
super.onBackPressed();
520521
if (sender != null && !sender.isCancelled())
@@ -615,4 +616,5 @@ public static <T> List<T> removeDuplicates(List<T> list)
615616
}
616617
return newList;
617618
}
619+
618620
}

‎app/src/main/java/com/example/chatfull/Client.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.AsyncTask;
44
import android.util.Log;
5+
import android.view.View;
56
import android.widget.Toast;
67

78
import java.io.BufferedReader;
@@ -74,6 +75,7 @@ protected void onPostExecute(String result) {
7475
activity.runOnUiThread(new Runnable() {
7576
@Override
7677
public void run() {
78+
activity.progressOverlay.setVisibility(View.INVISIBLE);
7779
Toast.makeText(activity.getApplicationContext(), serverResponse, Toast.LENGTH_LONG).show();
7880
}
7981
});

‎app/src/main/java/com/example/chatfull/ConnectToUserActivity.java‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import android.content.Intent;
55
import android.os.Bundle;
66
import android.view.View;
7+
import android.view.inputmethod.InputMethodManager;
78
import android.widget.Button;
89
import android.widget.EditText;
10+
import android.widget.FrameLayout;
911
import android.widget.Toast;
1012

1113
import androidx.appcompat.app.AppCompatActivity;
@@ -14,21 +16,25 @@
1416
import androidx.fragment.app.FragmentTransaction;
1517

1618
import com.google.android.gms.vision.barcode.Barcode;
19+
import com.google.android.material.snackbar.Snackbar;
1720
import com.notbytes.barcode_reader.BarcodeReaderActivity;
1821

19-
public class ConnectToUserActivity extends AppCompatActivity{
22+
public class ConnectToUserActivity extends AppCompatActivity{
2023

2124
private static final int BARCODE_READER_ACTIVITY_REQUEST = 1208;
2225

2326
private EditText ipInput, portInput;
2427
private Button connectBtn, scanBtn;
2528
private Client myClient;
2629
private User user;
30+
FrameLayout progressOverlay;
2731

2832
public void setUser(User user) {
2933
this.user = user;
3034
Intent intent = new Intent(getApplicationContext(), ChatActivity.class);
3135
intent.putExtra("user", myClient.user);
36+
37+
progressOverlay.setVisibility(View.INVISIBLE);
3238
startActivity(intent);
3339
}
3440

@@ -41,11 +47,14 @@ protected void onCreate(Bundle savedInstanceState) {
4147
portInput = findViewById(R.id.portInput);
4248
connectBtn = findViewById(R.id.connectBtn);
4349
scanBtn = findViewById(R.id.scan_button);
50+
progressOverlay = findViewById(R.id.progress_overlay);
51+
4452
}
4553

4654
@Override
4755
protected void onResume() {
4856
super.onResume();
57+
progressOverlay.setVisibility(View.INVISIBLE);
4958
if (myClient != null && !myClient.isCancelled())
5059
myClient.cancel(true);
5160
}
@@ -65,6 +74,16 @@ protected void onDestroy() {
6574
}
6675

6776
public void connectBtnListener(View view) {
77+
if(portInput.getText().length() < 2 || ipInput.getText().length() < 2){
78+
Snackbar snackbar = Snackbar
79+
.make(ipInput, "Please Enter Valid IP Address and/or Port number.", Snackbar.LENGTH_LONG);
80+
snackbar.show();
81+
return;
82+
}
83+
84+
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
85+
imm.hideSoftInputFromWindow(portInput.getWindowToken(), 0);
86+
progressOverlay.setVisibility(View.VISIBLE);
6887
myClient = new Client(ipInput.getText().toString(), Integer.parseInt(portInput.getText().toString()), this);
6988
myClient.execute();
7089
}

‎app/src/main/java/com/example/chatfull/MessageReceiveServer.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import android.util.Log;
44

5-
import java.io.BufferedReader;
65
import java.io.IOException;
7-
import java.io.InputStreamReader;
86
import java.io.ObjectInputStream;
97
import java.net.ServerSocket;
108
import java.net.Socket;

‎app/src/main/java/com/example/chatfull/SendMessage.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.os.AsyncTask;
44
import android.util.Log;
55

6+
import com.google.android.material.snackbar.Snackbar;
7+
68
import java.io.ObjectOutputStream;
79
import java.net.Socket;
810

@@ -28,10 +30,26 @@ protected String doInBackground(Void... arg0) {
2830
Log.e("SEND_MSG", "Connected, Sending: " + message.getText());
2931

3032
if (clientSocket != null) {
33+
final Snackbar snackbar = Snackbar.make(activity.btnSend, "Uploading... Socket is busy, Please Wait", Snackbar.LENGTH_INDEFINITE);
34+
if(message.isFile() || message.isImage()){
35+
activity.runOnUiThread(new Runnable() {
36+
@Override
37+
public void run() {
38+
snackbar.show();
39+
}
40+
});
41+
}
3142
ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
3243
out.writeObject(message);
3344
out.flush();
3445

46+
activity.runOnUiThread(new Runnable() {
47+
@Override
48+
public void run() {
49+
if(snackbar.isShown()) snackbar.dismiss();
50+
}
51+
});
52+
3553
Log.e("SEND_MSG", "DONE: " + message.getText());
3654
activity.stopSender();
3755
}

‎app/src/main/res/layout/activity_connect_to_user.xml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:layout_width="match_parent"
@@ -10,7 +11,7 @@
1011
android:background="@drawable/background_gradient"
1112
>
1213

13-
14+
<includelayout="@layout/include_progress_overlay"/>
1415
<EditText
1516
android:id="@+id/ipInput"
1617
android:layout_width="265dp"
@@ -97,4 +98,6 @@
9798
app:layout_constraintEnd_toEndOf="parent"
9899
app:layout_constraintHorizontal_bias="0.497"
99100
app:layout_constraintStart_toStartOf="parent" />
101+
102+
100103
</androidx.constraintlayout.widget.ConstraintLayout>

‎app/src/main/res/layout/activity_main.xml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,22 @@
6969
android:layout_width="277dp"
7070
android:layout_height="45dp"
7171
android:layout_marginStart="8dp"
72+
android:layout_marginTop="8dp"
7273
android:layout_marginEnd="8dp"
7374
android:layout_marginBottom="16dp"
7475
android:background="@drawable/buttonshape"
7576
android:elevation="10dp"
76-
android:fontFamily="@font/moon_bold"
7777

78+
android:fontFamily="@font/moon_bold"
7879
android:text="Enter Ip : port"
7980
android:textColor="#FFFFFF"
8081
android:textSize="15sp"
8182
app:layout_constraintBottom_toTopOf="@+id/showInfo"
8283
app:layout_constraintEnd_toEndOf="parent"
83-
app:layout_constraintStart_toStartOf="parent" />
84+
app:layout_constraintHorizontal_bias="0.508"
85+
app:layout_constraintStart_toStartOf="parent"
86+
app:layout_constraintTop_toBottomOf="@+id/nameInput"
87+
app:layout_constraintVertical_bias="1.0" />
8488

8589

8690
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:wheel="http://schemas.android.com/apk/res-auto"
3+
android:id="@+id/progress_overlay"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:alpha="0.4"
7+
android:animateLayoutChanges="true"
8+
android:background="#000000"
9+
android:clickable="true"
10+
android:focusable="true"
11+
android:visibility="gone"
12+
android:elevation="50dp">
13+
14+
<com.pnikosis.materialishprogress.ProgressWheel
15+
android:id="@+id/progress_wheel"
16+
android:layout_width="80dp"
17+
android:layout_height="80dp"
18+
android:clickable="true"
19+
android:layout_gravity="center"
20+
wheel:matProg_barColor="#457CFF"
21+
wheel:matProg_progressIndeterminate="true"
22+
android:layout_marginBottom="30dp"
23+
wheel:matProg_fillRadius="false"
24+
/>
25+
<TextView
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:text="Connecting..."
29+
android:fontFamily="@font/moon_light"
30+
android:textSize="20sp"
31+
android:layout_gravity="center"
32+
android:layout_marginTop="20dp"
33+
android:textColor="#FFFFFF"
34+
/>
35+
36+
</FrameLayout>

‎app/src/main/res/values/attrs.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
</resources>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /