diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..42653ef --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Sandun Isuru Niraj | CodeZilla 2018 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 076967f..b19e86b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,142 @@ -# WiCard -sandun.isuru@gmail.com Sandun Isuru Niraj Sandun-Isuru-Niraj IA7 + +sandun.isuru@gmail.com | Sandun Isuru Niraj | IA7 + +![launcher icon](http://i65.tinypic.com/25flje0.jpg) +# WiCard - Share Your Attitude + +[1. Introduction](#1-introduction) + +[2. How it Works](#2-how-it-works) + + [2.1 Creating a new WiCard](#21-creating-a-new-wicard) + + [2.2 Viewing Created WiCards](#22-viewing-created-wicards) + + [2.3 Sending Your WiCard](#23-sending-your-wicard) + + [2.4 Receiving WiCards](#24-receiving-wicards) + + [2.5 Viewing Received WiCards](#25-viewing-received-wicards) + +[3. Error Handling](#3-error-handling) + +[4. Tested Profile](#4-tested-profile) + +[5. Used Libraries](#5-used-libraries) + +[6. Used Services](#6-used-services) + +[7. Future Developments](#7-future-developments) + +[8. References](#8-references) + + +## 1. Introduction +With this application You can __Easily__ create your Virtual Name Card and Share them with your Business persons and others through the __WiFi__. +- It can save your WiCard, Without Internet Connection and Share them Without Internet. +- And Also Easily connect them with On Phone, SMS or Email. +- You can save them in to your contacts not remembering them. No need to re enter like traditional Business Cards. + +## 2. How it Works + +### 2.1 Creating a new WiCard + +You can simply click the __Create a WiCard__ button on main page or, __Create a WiCard__ on Drawer to enter the New WiCard Creation Wizard. + +![main page](http://i68.tinypic.com/2qvcltj.jpg) +![main page](http://i68.tinypic.com/ehdtp0.jpg) + +Then You can enter your WiCard Details and Click __Save__ Button. It will be create Your WiCard. + +![main page](http://i65.tinypic.com/282448o.jpg) + +### 2.2 Viewing Created WiCards + +If you need to see or send or delete your WiCard. You Can easily click on the drawer and select __My WiCard__. Then You can see your created WiCards. + +![my wicards](http://i64.tinypic.com/ux3zk.jpg) + +If you need to delete on this. You can tap and hold on the WiCard and popup menu will appear. + +![my wicards](http://i64.tinypic.com/p3ybq.jpg) + +Then Click on Delete. + +![my wicards](http://i67.tinypic.com/se7xu0.jpg) + +Then Click Yes. And It will be deleted your WiCard. + +### 2.3 Sending Your WiCard + +To Sending the WiCard. The Receiver also need to install WiCard App in his Mobile Phone. +In the senders phone he can click and hold on the WiCard that he needs to send and select Send option. +It will go to Sending Wizard. + +![my wicards](http://i65.tinypic.com/nye2rl.jpg) + +It will automatically search for nearby devices. If not click the Search Devices Button. If the device show on the List Click on the device and It will be connected. + +![my wicards](http://i64.tinypic.com/11bk8ip.jpg) + +Then Wait until the status Changed to the __Receiver__. + +![my wicards](http://i68.tinypic.com/14c8d3b.jpg) + +Now Click the send Button. + +### 2.4 Receiving WiCards. + +If you need to receive a WiCard from another person. Simply Click on __Receive WiCard__ Button on Home Screen or __Get a WiCard__ option on Drawer. +Then you will be redirect to the Receiving Wizard. + +![my wicards](http://i66.tinypic.com/6fz7sz.jpg) + +Then Wait for the other device discover you. Then Connected other Device will send the WiCard and it shows on your mobile. + +![my wicards](http://i64.tinypic.com/2w4mgkx.jpg) + +Then You Can Save or Delete it clicking on the action buttons. + +### 2.5 Viewing Received WiCards + +Clicking on the __Saved WiCards__ on the Drawer or Home Page. You can access the your received and saved WiCards. + +![my wicards](http://i63.tinypic.com/23rpf6u.jpg) + +Then Click and holding on the WiCards you can get calls to the Numbers, Send Messages to the Number, Send Emails to the Email address, Save the WiCard as Mobile Contact and Delete the received WiCard. + +![my wicards](http://i67.tinypic.com/vhutd.jpg) + +## 3. Error Handling + ++ __If Recievers mode Device is still disconnected__ - + Please simply click on the back button of your mobile and again click on the Get WiCard Option. + ++ __If Automatically Not Turn on WiFi__ - + Check Your permissions on Mobile Phone. Below the Android API 17 devices has some issues with WIFI connectivity. + +## 4. Tested Profile + + + Android API Level 16 / 17 + + 1GB Ram and 512MB Ram + +## 5. Used Libraries + +All are the Google Standard Libraries Only no Third party libraries used. + +## 6. Used Services + +All the services are Free and Open Source + +## 7. Future Developments + ++ Develop the Application upto sending Photo ID Profile through the WIFI. ++ Share WiCard through the Internet. ++ Share WiCards to the Social Media. + +## 8. References + ++ Official Android Doumentation ++ P Joby, Abby. (2016). Socket Programming WIFI Chat APP For Android Smartphone. 10.13140/RG.2.1.3692.2483. + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a372ec7..8269b65 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,9 +2,19 @@ + + + + + + + + + + - + + + + \ No newline at end of file diff --git a/app/src/main/java/me/morasquad/wicard/AboutActivity.java b/app/src/main/java/me/morasquad/wicard/AboutActivity.java new file mode 100644 index 0000000..7407cde --- /dev/null +++ b/app/src/main/java/me/morasquad/wicard/AboutActivity.java @@ -0,0 +1,52 @@ +package me.morasquad.wicard; + +import android.content.Intent; +import android.net.Uri; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; + +public class AboutActivity extends AppCompatActivity { + + Button github; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_about); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setTitle("WiCard : About"); + + github = (Button) findViewById(R.id.githubbtn); + + github.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/codezilla2018/WiCard")); + startActivity(browserIntent); + } + }); + } + + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if(id == android.R.id.home){ + SendUsertoMainActivity(); + } + return super.onOptionsItemSelected(item); + } + + private void SendUsertoMainActivity() { + + Intent home = new Intent(AboutActivity.this, MainActivity.class); + home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(home); + finish(); + + } +} diff --git a/app/src/main/java/me/morasquad/wicard/EditMyWiCardActivity.java b/app/src/main/java/me/morasquad/wicard/EditMyWiCardActivity.java new file mode 100644 index 0000000..56d1c86 --- /dev/null +++ b/app/src/main/java/me/morasquad/wicard/EditMyWiCardActivity.java @@ -0,0 +1,117 @@ +package me.morasquad.wicard; + +import android.content.Intent; +import android.database.Cursor; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class EditMyWiCardActivity extends AppCompatActivity { + + EditText email,address,mobileNo,fullName; + Button upadateBtn; + String intentEmail; + SqliteHelper sqliteHelper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_edit_my_wi_card); + + email = (EditText) findViewById(R.id.email_edit); + address = (EditText) findViewById(R.id.address_edit); + mobileNo = (EditText) findViewById(R.id.mobileNumber_edit); + fullName = (EditText) findViewById(R.id.fullName_edit); + upadateBtn = (Button) findViewById(R.id.update_data); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setTitle("WiCard : Edit My WiCard"); + + Intent intent = getIntent(); + intentEmail = intent.getStringExtra("email"); + + loadWiCard(); + + upadateBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String full_Name = fullName.getText().toString(); + String emailAdrress = email.getText().toString(); + String mobileNumber = mobileNo.getText().toString(); + String Address = address.getText().toString(); + + if(TextUtils.isEmpty(full_Name)){ + Toast.makeText(EditMyWiCardActivity.this, "You Need to Enter Full Name", Toast.LENGTH_SHORT).show(); + }else if(TextUtils.isEmpty(emailAdrress)){ + Toast.makeText(EditMyWiCardActivity.this, "You Need to Enter Email Address", Toast.LENGTH_SHORT).show(); + }else { + + boolean result = sqliteHelper.saveWiCard(emailAdrress, Address, mobileNumber, full_Name); + + if(result){ + Intent back = new Intent(EditMyWiCardActivity.this, ViewMyWiCardActivity.class); + back.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(back); + Toast.makeText(getApplicationContext(), "Your WiCard is Successfully Created!", Toast.LENGTH_SHORT).show(); + }else { + Toast.makeText(getApplicationContext(), "Failed Creating WiCard!", Toast.LENGTH_SHORT).show(); + + } + } + } + }); + + + } + + private void loadWiCard() { + sqliteHelper = new SqliteHelper(getApplicationContext()); + Cursor cursor = sqliteHelper.getUser(intentEmail); + if (cursor.getCount() != 0) { + cursor.moveToFirst(); + + String full_Name = cursor.getString(cursor.getColumnIndex("fullName")); + String emailAdrress = cursor.getString(cursor.getColumnIndex("email")); + String mobileNumber = cursor.getString(cursor.getColumnIndex("mobileNumber")); + String Address = cursor.getString(cursor.getColumnIndex("address")); + + fullName.setText(full_Name); + email.setText(emailAdrress); + mobileNo.setText(mobileNumber); + address.setText(Address); + if (!cursor.isClosed()) { + cursor.close(); + } + }else { + fullName.setText(""); + email.setText(""); + mobileNo.setText(""); + address.setText(""); + } + + } + + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if(id == android.R.id.home){ + SendUsertoMainActivity(); + } + return super.onOptionsItemSelected(item); + } + + private void SendUsertoMainActivity() { + + Intent home = new Intent(EditMyWiCardActivity.this, MainActivity.class); + home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(home); + finish(); + + } +} diff --git a/app/src/main/java/me/morasquad/wicard/MainActivity.java b/app/src/main/java/me/morasquad/wicard/MainActivity.java index b3a2957..015c9e9 100644 --- a/app/src/main/java/me/morasquad/wicard/MainActivity.java +++ b/app/src/main/java/me/morasquad/wicard/MainActivity.java @@ -8,7 +8,8 @@ import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.MenuItem; -import android.widget.Toast; +import android.view.View; +import android.widget.Button; public class MainActivity extends AppCompatActivity { @@ -16,12 +17,15 @@ public class MainActivity extends AppCompatActivity { private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mToggle; private NavigationView navigationView; + private Button createWicard, recieveWiCard, savedWicard; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + navigationView = (NavigationView) findViewById(R.id.nav_view); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close); @@ -29,7 +33,37 @@ protected void onCreate(Bundle savedInstanceState) { mToggle.syncState(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); + createWicard = (Button) findViewById(R.id.create_main); + recieveWiCard = (Button) findViewById(R.id.recieve_main); + savedWicard = (Button) findViewById(R.id.saved_main); + + + createWicard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent create = new Intent(MainActivity.this, CreateWiCardActivity.class); + startActivity(create); + } + }); + + recieveWiCard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent recieve = new Intent(MainActivity.this, RecieveWiCardActivity.class); + startActivity(recieve); + } + }); + + savedWicard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent saved = new Intent(MainActivity.this, RecievedWiCardActivity.class); + startActivity(saved); + } + }); + navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { + @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { UserMenuSelector(item); @@ -38,8 +72,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { }); - - } private void UserMenuSelector(MenuItem item) { @@ -60,16 +92,14 @@ private void UserMenuSelector(MenuItem item) { startActivity(create); break; - case R.id.send_wicard: - Toast.makeText(this, "Send WiCard", Toast.LENGTH_SHORT).show(); - break; - case R.id.get_wicard: - Toast.makeText(this, "Get WiCard", Toast.LENGTH_SHORT).show(); + Intent recieve = new Intent(MainActivity.this, RecieveWiCardActivity.class); + startActivity(recieve); break; case R.id.saved_wicards: - Toast.makeText(this, "Save WiCards", Toast.LENGTH_SHORT).show(); + Intent recieved = new Intent(MainActivity.this, RecievedWiCardActivity.class); + startActivity(recieved); break; diff --git a/app/src/main/java/me/morasquad/wicard/RecieveWiCardActivity.java b/app/src/main/java/me/morasquad/wicard/RecieveWiCardActivity.java new file mode 100644 index 0000000..2adb974 --- /dev/null +++ b/app/src/main/java/me/morasquad/wicard/RecieveWiCardActivity.java @@ -0,0 +1,328 @@ +package me.morasquad.wicard; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.wifi.WifiManager; +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.os.Handler; +import android.os.Message; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +public class RecieveWiCardActivity extends AppCompatActivity { + + TextView connectionStatus; + TextView fullNameText; + TextView emailText; + TextView addressText; + TextView mobileNumText; + Button saveWiCard, deleteWiCard; + SqliteHelper sqliteHelper; + String fullName, email, mobileNumber, address; + + WifiManager wifiManager; + WifiP2pManager mManager; + WifiP2pManager.Channel mChannel; + + BroadcastReceiver mReciever; + IntentFilter mIntentFilter; + + List peers = new ArrayList(); + String[] deviceNameArray; + WifiP2pDevice[] deviceArray; + + static final int MESSAGE_READ = 1; + + ServerClass serverClass; + ClientClass clientClass; + SendRecieve sendRecieve; + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_recieve_wi_card); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setTitle("WiCard : Receive WiCard"); + + fullNameText = (TextView) findViewById(R.id.fullNameTxtRec); + emailText = (TextView) findViewById(R.id.emailTxtRec); + addressText = (TextView) findViewById(R.id.addressTxtRec); + mobileNumText = (TextView) findViewById(R.id.mobileNumTxtRec); + connectionStatus = (TextView) findViewById(R.id.connectonStatusRec); + saveWiCard = (Button) findViewById(R.id.save_wicard); + deleteWiCard = (Button) findViewById(R.id.delete_wicard); + + saveWiCard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + boolean result = sqliteHelper.saveRecievedWiCard(email, address, mobileNumber, fullName); + + if(result){; + Toast.makeText(RecieveWiCardActivity.this, "Saved Successfully!", Toast.LENGTH_SHORT).show(); + }else { + Toast.makeText(RecieveWiCardActivity.this, "Failed to Saving!", Toast.LENGTH_SHORT).show(); + + } + } + }); + + initialLoading(); + initialListner(); + discoverPeers(); + + + + + } + Handler handler = new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(Message msg) { + switch (msg.what){ + case MESSAGE_READ: + byte[] readBuff = (byte[]) msg.obj; + String tempMsg = new String(readBuff, 0,msg.arg1); + String[] parts = tempMsg.split("&"); + fullName = parts[0]; + email = parts[1]; + address = parts[2]; + mobileNumber = parts[3]; + fullNameText.setText(fullName); + emailText.setText(email); + addressText.setText(address); + mobileNumText.setText(mobileNumber); + break; + } + return true; + } + }); + + private void discoverPeers() { + + mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() { + @Override + public void onSuccess() { + connectionStatus.setText("Discovery Started!"); + } + + @Override + public void onFailure(int i) { + connectionStatus.setText("Discovery Starting Failed!"); + } + }); + } + + private void initialListner() { + + if(wifiManager.isWifiEnabled()){ + return; + }else { + wifiManager.setWifiEnabled(true); + } + + + } + + private void initialLoading() { + + wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); + mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); + mChannel = mManager.initialize(this, getMainLooper(), null); + + mReciever = new WifiDirectBroadcastRecieverforReciever(mManager, mChannel, this); + mIntentFilter = new IntentFilter(); + + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); + } + + + + WifiP2pManager.PeerListListener peerListListener = new WifiP2pManager.PeerListListener() { + @Override + public void onPeersAvailable(WifiP2pDeviceList peerList) { + if(!peerList.getDeviceList().equals(peers)){ + peers.clear(); + peers.addAll(peerList.getDeviceList()); + + deviceNameArray = new String[peerList.getDeviceList().size()]; + deviceArray = new WifiP2pDevice[peerList.getDeviceList().size()]; + + int index = 0; + + for (WifiP2pDevice device : peerList.getDeviceList()){ + deviceNameArray[index] = device.deviceName; + deviceArray[index] = device; + index++; + } + + } + + if(peers.size() == 0){ + Toast.makeText(RecieveWiCardActivity.this, "No Devices Found!", Toast.LENGTH_SHORT).show(); + return; + } + } + }; + + WifiP2pManager.ConnectionInfoListener connectionInfoListener = new WifiP2pManager.ConnectionInfoListener() { + @Override + public void onConnectionInfoAvailable(WifiP2pInfo wifiP2pInfo) { + final InetAddress groupOwnerAddress = wifiP2pInfo.groupOwnerAddress; + + if(wifiP2pInfo.groupFormed && wifiP2pInfo.isGroupOwner){ + connectionStatus.setText("Sender"); + serverClass = new ServerClass(); + serverClass.start(); + }else if (wifiP2pInfo.groupFormed){ + connectionStatus.setText("Receiver"); + clientClass = new ClientClass(groupOwnerAddress); + clientClass.start(); + } + } + }; + + + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if(id == android.R.id.home){ + SendUsertoMainActivity(); + } + return super.onOptionsItemSelected(item); + } + + private void SendUsertoMainActivity() { + + Intent home = new Intent(RecieveWiCardActivity.this, MainActivity.class); + home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(home); + finish(); + } + + @Override + protected void onResume() { + super.onResume(); + registerReceiver(mReciever, mIntentFilter); + } + + @Override + protected void onPause() { + super.onPause(); + unregisterReceiver(mReciever); + } + + public class ServerClass extends Thread{ + Socket socket; + ServerSocket serverSocket; + + @Override + public void run() { + try { + serverSocket = new ServerSocket(8888); + socket = serverSocket.accept(); + sendRecieve = new SendRecieve(socket); + sendRecieve.start(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public class ClientClass extends Thread{ + + Socket socket; + String hostAdd; + + public ClientClass(InetAddress hostAddress){ + + hostAdd = hostAddress.getHostAddress(); + socket = new Socket(); + } + + @Override + public void run() { + + try { + socket.connect(new InetSocketAddress(hostAdd, 8888),500); + + sendRecieve = new SendRecieve(socket); + sendRecieve.start(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private class SendRecieve extends Thread{ + + private Socket socket; + private InputStream inputStream; + private OutputStream outputStream; + + public SendRecieve(Socket skt) throws IOException { + socket = skt; + inputStream = socket.getInputStream(); + outputStream = socket.getOutputStream(); + + + } + + @Override + public void run() { + + byte[] buffer = new byte[1024]; + int bytes; + + while (socket != null){ + try { + bytes = inputStream.read(buffer); + if(bytes > 0){ + handler.obtainMessage(MESSAGE_READ, bytes, -1,buffer).sendToTarget(); + + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + + public void write(byte[] bytes){ + try { + outputStream.write(bytes); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + + +} diff --git a/app/src/main/java/me/morasquad/wicard/RecievedWiCardActivity.java b/app/src/main/java/me/morasquad/wicard/RecievedWiCardActivity.java new file mode 100644 index 0000000..8aa7df8 --- /dev/null +++ b/app/src/main/java/me/morasquad/wicard/RecievedWiCardActivity.java @@ -0,0 +1,90 @@ +package me.morasquad.wicard; + +import android.content.Context; +import android.content.Intent; +import android.os.AsyncTask; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.MenuItem; + +import java.util.ArrayList; + +import me.morasquad.wicard.models.RecievedWiCards; + +public class RecievedWiCardActivity extends AppCompatActivity { + + private AppCompatActivity activity = RecievedWiCardActivity.this; + private Context context = RecievedWiCardActivity.this; + private RecyclerView recyclerView; + private ArrayList recievedWiCards; + private RecievedWiCardRecyclerAdapter recievedWiCardRecyclerAdapter; + private SqliteHelper sqliteHelper; + private ArrayList filteredList; + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_recieved_wi_card); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setTitle("WiCard : Received WiCards"); + + recyclerView = (RecyclerView) findViewById(R.id.rec_wicard_recycler); + recievedWiCards = new ArrayList<>(); + recievedWiCardRecyclerAdapter = new RecievedWiCardRecyclerAdapter(recievedWiCards, this); + + RecyclerView.LayoutManager mlayoutManager = new LinearLayoutManager(getApplicationContext()); + recyclerView.setLayoutManager(mlayoutManager); + recyclerView.setItemAnimator(new DefaultItemAnimator()); + recyclerView.setHasFixedSize(true); + recyclerView.setAdapter(recievedWiCardRecyclerAdapter); + + sqliteHelper = new SqliteHelper(this); + + getDataFromSqlite(); + } + + private void getDataFromSqlite() { + + new AsyncTask(){ + + @Override + protected Void doInBackground(Void... params) { + recievedWiCards.clear(); + recievedWiCards.addAll(sqliteHelper.getRecievedWiCards()); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + recievedWiCardRecyclerAdapter.notifyDataSetChanged(); + } + }.execute(); + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if(id == android.R.id.home){ + SendUsertoMainActivity(); + } + return super.onOptionsItemSelected(item); + } + + private void SendUsertoMainActivity() { + + Intent home = new Intent(RecievedWiCardActivity.this, MainActivity.class); + home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(home); + finish(); + } +} diff --git a/app/src/main/java/me/morasquad/wicard/SendWiCardActivity.java b/app/src/main/java/me/morasquad/wicard/SendWiCardActivity.java new file mode 100644 index 0000000..8b14c15 --- /dev/null +++ b/app/src/main/java/me/morasquad/wicard/SendWiCardActivity.java @@ -0,0 +1,92 @@ +package me.morasquad.wicard; + +import android.content.Intent; +import android.database.Cursor; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.MenuItem; +import android.widget.Button; +import android.widget.TextView; + +public class SendWiCardActivity extends AppCompatActivity { + + String intentEmail; + TextView connectionStatus; + TextView fullNameText; + TextView emailText; + TextView addressText; + TextView mobileNumText; + Button wicardSendBtn; + SqliteHelper sqliteHelper; + String fullName, email, mobileNumber, address; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_send_wi_card); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setTitle("WiCard : Send WiCard"); + + Intent intent = getIntent(); + intentEmail = intent.getStringExtra("email"); + + fullNameText = (TextView) findViewById(R.id.fullNameTxt); + emailText = (TextView) findViewById(R.id.emailTxt); + addressText = (TextView) findViewById(R.id.addressTxt); + mobileNumText = (TextView) findViewById(R.id.mobileNumTxt); + + wicardSendBtn = (Button) findViewById(R.id.sendWiCard); + + connectionStatus.setText(intentEmail); + + loadWiCard(); + + } + + private void loadWiCard() { + + sqliteHelper = new SqliteHelper(getApplicationContext()); + Cursor cursor = sqliteHelper.getUser(intentEmail); + if (cursor.getCount() != 0) { + cursor.moveToFirst(); + + fullName = cursor.getString(cursor.getColumnIndex("fullName")); + email = cursor.getString(cursor.getColumnIndex("email")); + mobileNumber = cursor.getString(cursor.getColumnIndex("mobileNumber")); + address = cursor.getString(cursor.getColumnIndex("address")); + + fullNameText.setText(fullName); + emailText.setText(email); + mobileNumText.setText(mobileNumber); + addressText.setText(address); + if (!cursor.isClosed()) { + cursor.close(); + } + }else { + fullNameText.setText(""); + emailText.setText(""); + mobileNumText.setText(""); + addressText.setText(""); + } + } + + + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if(id == android.R.id.home){ + SendUsertoMainActivity(); + } + return super.onOptionsItemSelected(item); + } + + private void SendUsertoMainActivity() { + + Intent home = new Intent(SendWiCardActivity.this, MainActivity.class); + home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(home); + finish(); + } +}