Skip to content

Commit

Permalink
announce result for each item
Browse files Browse the repository at this point in the history
  • Loading branch information
GobinathAL committed Apr 17, 2021
1 parent 93f6e05 commit cd91fd5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 58 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/com/network/p2pauction/BReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pInfo;
import android.net.wifi.p2p.WifiP2pManager;
import android.util.Log;

Expand Down
36 changes: 12 additions & 24 deletions app/src/main/java/com/network/p2pauction/GroupFormation.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,47 @@
package com.network.p2pauction;
package com.network.p2pauction;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo;
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract;
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.switchmaterial.SwitchMaterial;
import com.google.android.material.textview.MaterialTextView;

import org.w3c.dom.Text;

import java.io.BufferedReader;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.DoubleBuffer;
import java.security.acl.Group;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class GroupFormation extends AppCompatActivity {
public class GroupFormation extends AppCompatActivity {
TextView auctionName, noOfBidders;
ListView itemsList, log;
MaterialButton startButton;
Expand Down Expand Up @@ -154,6 +137,11 @@ else if(startButton.getText().equals("Next")){
playerBidHistory.clear();
activeBidders.clear();
announceResult();
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
currentItem++;
if(currentItem == itemArrList.size() - 1) {
startButton.setText("Finish");
Expand Down
37 changes: 27 additions & 10 deletions app/src/main/java/com/network/p2pauction/GroupJoin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.network.p2pauction;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.graphics.Color;
import android.net.nsd.NsdManager;
Expand All @@ -12,6 +8,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.LoginFilter;
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
Expand All @@ -22,6 +19,10 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
Expand All @@ -31,15 +32,13 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Timer;
import java.util.concurrent.TimeUnit;

public class GroupJoin extends AppCompatActivity {
String AUCTION_NAME;
Expand All @@ -57,6 +56,7 @@ public class GroupJoin extends AppCompatActivity {
ArrayList<String> itemArrList;
String ip, myip;
RelativeLayout relativeLayout;
MaterialTextView txtResult;
private int currentItem = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -73,6 +73,7 @@ protected void onCreate(Bundle savedInstanceState) {
txtBidAmount = (TextInputEditText) findViewById(R.id.BidAmount);
textInputLayout = (TextInputLayout) findViewById(R.id.inputLayout);
txtLeaderboardPosition = (MaterialTextView) findViewById(R.id.LeaderboardPosition);
txtResult = (MaterialTextView) findViewById(R.id.result);
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
myip = Formatter.formatIpAddress(wifiManager.getConnectionInfo().getIpAddress());
Thread myThread = new Thread(new MyServer());
Expand Down Expand Up @@ -294,8 +295,22 @@ public void run() {
@Override
public void run() {
if(message.contains("result")) {
currentItem++;
updateItemInfo();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
currentItem++;
txtResult.setText("");
Log.i("module6", "gone");
updateItemInfo();
}
}, 5000);

if(txtLeaderboardPosition.getText().toString().equals("Your Leaderboard Position: 1")) {
txtResult.setText("You won this bid");
Log.i("module6", "winner");
} else {
Log.i("module6", "not a winner");
}
}
else if(message.contains("update")) {
Log.i("module4", "message: " + message + "status: received");
Expand All @@ -316,6 +331,8 @@ else if(message.contains("finish")) {
btnSend.setVisibility(View.GONE);
txtBidAmount.setVisibility(View.GONE);
textInputLayout.setVisibility(View.GONE);
if(txtLeaderboardPosition.getText().toString().equals("Your Leaderboard Position: 1"))
txtResult.setText("You won this bid");
}
}
});
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/network/p2pauction/HomeScreen.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.network.p2pauction;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.textview.MaterialTextView;

Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/network/p2pauction/JoinActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.network.p2pauction;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
Expand Down
20 changes: 4 additions & 16 deletions app/src/main/java/com/network/p2pauction/createActivity.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
package com.network.p2pauction;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.wifi.WpsInfo;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pDevice;
import android.net.wifi.p2p.WifiP2pDeviceList;
import android.net.wifi.p2p.WifiP2pInfo;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.button.MaterialButton;

import java.net.InetAddress;
import java.nio.channels.Channel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class createActivity extends AppCompatActivity implements WifiP2pManager.ChannelListener {
WifiP2pManager manager;
Expand All @@ -59,7 +48,6 @@ protected void onCreate(Bundle savedInstanceState) {
P2PHandler();
P2PInfoReceiver();
service();

}
protected void P2PHandler() {
manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_group_join.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@
android:layout_marginTop="20dp"
android:text="Join"
android:layout_centerHorizontal="true" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sendToSocketBtn"
android:text=""
android:textSize="30dp"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true" />
</RelativeLayout>

0 comments on commit cd91fd5

Please sign in to comment.