Skip to content

Commit c8d466d

Browse files
committed
Added qr code scanner
1 parent d472e64 commit c8d466d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3298
-141
lines changed

.idea/vcs.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/build.gradle

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ android {
2323
repositories {
2424
mavenCentral()
2525
google()
26+
jcenter()
27+
maven { url "https://jitpack.io" }
2628
}
2729

2830
dependencies {
2931
implementation fileTree(dir: 'libs', include: ['*.jar'])
30-
implementation 'androidx.appcompat:appcompat:1.0.2'
32+
implementation 'androidx.appcompat:appcompat:1.1.0'
3133
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3234
implementation 'com.google.android.material:material:1.0.0'
3335
testImplementation 'junit:junit:4.12'
@@ -39,9 +41,18 @@ dependencies {
3941
implementation 'com.squareup.picasso:picasso:2.71828'
4042
implementation 'androidx.media:media:1.1.0'
4143

42-
implementation ("com.github.bumptech.glide:glide:4.9.0") {
44+
implementation('com.github.bumptech.glide:glide:4.10.0') {
4345
exclude group: "com.android.support"
4446
}
45-
implementation "com.android.support:support-fragment:26.1.0"
47+
implementation 'com.android.support:support-fragment:28.0.0'
4648
implementation project(':colorpicker')
49+
implementation project(':barcode-reader')
50+
51+
implementation 'com.google.android.gms:play-services-vision:18.0.0'
52+
implementation 'com.android.support:design:28.0.0'
53+
implementation 'androidx.fragment:fragment:1.2.0-alpha04'
54+
55+
implementation 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
56+
implementation 'com.google.zxing:core:3.2.0'
57+
implementation 'com.github.kenglxn.QRGen:android:2.6.0'
4758
}

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
88
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
99

10+
<uses-feature android:name="android.hardware.camera" />
11+
12+
<uses-permission android:name="android.permission.CAMERA" />
13+
1014
<application
1115
android:allowBackup="true"
1216
android:icon="@mipmap/ic_launcher"
13-
android:label="@string/app_name"
17+
android:label="ChatFull"
1418
android:roundIcon="@mipmap/ic_launcher_round"
1519
android:supportsRtl="true"
1620
android:theme="@style/AppTheme">
17-
<activity android:name=".MessageListActivity"></activity>
1821
<activity android:name=".ConnectToUserActivity" />
1922
<activity android:name=".ChatActivity" />
2023
<activity android:name=".ShowInfoActivity" />

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.android.colorpicker.ColorPickerSwatch;
3131
import com.bumptech.glide.Glide;
3232
import com.stfalcon.chatkit.commons.ImageLoader;
33-
import com.stfalcon.chatkit.commons.models.IMessage;
3433
import com.stfalcon.chatkit.messages.MessageHolders;
3534
import com.stfalcon.chatkit.messages.MessagesList;
3635
import com.stfalcon.chatkit.messages.MessagesListAdapter;
@@ -40,7 +39,6 @@
4039
import java.io.FileOutputStream;
4140
import java.io.IOException;
4241
import java.io.InputStream;
43-
import java.io.UnsupportedEncodingException;
4442
import java.util.Calendar;
4543

4644
public class ChatActivity extends AppCompatActivity
@@ -135,7 +133,7 @@ public void loadImage(ImageView imageView, @Nullable String url, @Nullable Objec
135133
}
136134

137135
private void setClipboard(Context context, String text) {
138-
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
136+
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
139137
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
140138
clipboard.setText(text);
141139
} else {
@@ -291,7 +289,6 @@ public static byte[] getBytes(Context context, Uri uri) throws IOException {
291289
}
292290
}
293291

294-
295292
/**
296293
* get bytes from input stream.
297294
*
@@ -345,10 +342,10 @@ public void run() {
345342
} else if (msg.isImage()) {
346343
msg.setUser(user);
347344
adapter.addToStart(msg, true);
348-
} else if(msg.isFile()) {
345+
} else if (msg.isFile()) {
349346
msg.setUser(user);
350347
adapter.addToStart(msg, true);
351-
} else if(msg.isColor()) {
348+
} else if (msg.isColor()) {
352349
back_view.setBackgroundColor(msg.getColor());
353350
}
354351
}
@@ -399,17 +396,17 @@ public boolean hasContentFor(Message message, byte type) {
399396

400397
@Override
401398
public void onMessageLongClick(Message message) {
402-
Log.e("CLICK","MSG CLICK");
403-
if(message.getText() != null){
404-
setClipboard(getApplicationContext(),message.getText());
405-
Toast.makeText(getApplicationContext(),"Text Copied",Toast.LENGTH_SHORT).show();
406-
} else if(message.isFile()) {
399+
Log.e("CLICK", "MSG CLICK");
400+
if (message.getText() != null) {
401+
setClipboard(getApplicationContext(), message.getText());
402+
Toast.makeText(getApplicationContext(), "Text Copied", Toast.LENGTH_SHORT).show();
403+
} else if (message.isFile()) {
407404
try {
408405
// String uriString = new String(message.getFile(),"UTF-8");
409406
// Uri downloadUri = Uri.parse(uriString);
410407

411-
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),message.getId()+message.getFilename());
412-
Log.e("FILE",file.getAbsolutePath());
408+
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), message.getId() + message.getFilename());
409+
Log.e("FILE", file.getAbsolutePath());
413410
try {
414411
file.createNewFile();
415412
FileOutputStream fileOuputStream = new FileOutputStream(file);
@@ -418,15 +415,15 @@ public void onMessageLongClick(Message message) {
418415
} catch (IOException e) {
419416
e.printStackTrace();
420417
}
421-
String fileType = message.getFilename().substring(message.getFilename().indexOf('.')+1);
418+
String fileType = message.getFilename().substring(message.getFilename().indexOf('.') + 1);
422419
DownloadManager downloadManager = (DownloadManager) getApplicationContext().getSystemService(DOWNLOAD_SERVICE);
423-
downloadManager.addCompletedDownload(message.getId()+message.getFilename(), message.getId()+message.getFilename(), true, (fileType.equalsIgnoreCase("txt") ? "text/*" : "*/*"),file.getAbsolutePath(),file.length(),true);
420+
downloadManager.addCompletedDownload(message.getId() + message.getFilename(), message.getId() + message.getFilename(), true, (fileType.equalsIgnoreCase("txt") ? "text/*" : "*/*"), file.getAbsolutePath(), file.length(), true);
424421

425422
} catch (Exception e) {
426423
e.printStackTrace();
427424
}
428-
} else if(message.isImage()){
429-
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),message.getId()+message.getFilename());
425+
} else if (message.isImage()) {
426+
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), message.getId() + message.getFilename());
430427
try {
431428
file.createNewFile();
432429
FileOutputStream fileOuputStream = new FileOutputStream(file);
@@ -436,7 +433,7 @@ public void onMessageLongClick(Message message) {
436433
e.printStackTrace();
437434
}
438435
DownloadManager downloadManager = (DownloadManager) getApplicationContext().getSystemService(DOWNLOAD_SERVICE);
439-
downloadManager.addCompletedDownload(message.getId()+message.getFilename(), message.getId()+message.getFilename(), true, "image/*",file.getAbsolutePath(),file.length(),true);
436+
downloadManager.addCompletedDownload(message.getId() + message.getFilename(), message.getId() + message.getFilename(), true, "image/*", file.getAbsolutePath(), file.length(), true);
440437
}
441438
}
442439
}

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public class Client extends AsyncTask<Void, Void, String> {
2727
@Override
2828
protected String doInBackground(Void... arg0) {
2929
try {
30-
Log.e("CLIENT","Before Connection");
30+
Log.e("CLIENT", "Before Connection");
3131
clientSocket = new Socket(dstAddress, dstPort);
3232

33-
if(clientSocket != null) {
33+
if (clientSocket != null) {
3434

35-
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true);
36-
out.println(ShowInfoActivity.getSelfIpAddress()+":"+ShowInfoActivity.getSelfPort());
35+
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
36+
out.println(ShowInfoActivity.getSelfIpAddress() + ":" + ShowInfoActivity.getSelfPort());
3737

38-
Log.e("CLIENT","After Connection");
38+
Log.e("CLIENT", "After Connection");
3939
user = new User(dstAddress, dstPort);
4040
activity.setUser(user);
4141
//MainActivity.userArrayList.add(user);
@@ -44,16 +44,15 @@ protected String doInBackground(Void... arg0) {
4444
try {
4545
BufferedReader input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
4646
serverResponse = input.readLine();
47-
}catch (IOException e){
47+
} catch (IOException e) {
4848
e.printStackTrace();
49-
Log.e("CLIENT","Could not read socket");
49+
Log.e("CLIENT", "Could not read socket");
5050
}
5151

5252
} catch (Exception e) {
5353
e.printStackTrace();
5454
serverResponse = e.getCause().toString();
55-
}
56-
finally {
55+
} finally {
5756
if (clientSocket != null) {
5857
try {
5958
clientSocket.close();

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
package com.example.chatfull;
22

3+
import android.app.Activity;
34
import android.content.Intent;
45
import android.os.Bundle;
56
import android.view.View;
67
import android.widget.Button;
78
import android.widget.EditText;
9+
import android.widget.Toast;
810

911
import androidx.appcompat.app.AppCompatActivity;
12+
import androidx.fragment.app.Fragment;
13+
import androidx.fragment.app.FragmentManager;
14+
import androidx.fragment.app.FragmentTransaction;
15+
16+
import com.google.android.gms.vision.barcode.Barcode;
17+
import com.notbytes.barcode_reader.BarcodeReaderActivity;
1018

1119
public class ConnectToUserActivity extends AppCompatActivity {
1220

21+
private static final int BARCODE_READER_ACTIVITY_REQUEST = 1208;
22+
1323
private EditText ipInput, portInput;
14-
private Button connectBtn;
24+
private Button connectBtn, scanBtn;
1525
private Client myClient;
1626
private User user;
1727

@@ -30,31 +40,60 @@ protected void onCreate(Bundle savedInstanceState) {
3040
ipInput = findViewById(R.id.ipInput);
3141
portInput = findViewById(R.id.portInput);
3242
connectBtn = findViewById(R.id.connectBtn);
43+
scanBtn = findViewById(R.id.scan_button);
3344
}
3445

3546
@Override
3647
protected void onResume() {
3748
super.onResume();
38-
if(myClient != null && !myClient.isCancelled())
49+
if (myClient != null && !myClient.isCancelled())
3950
myClient.cancel(true);
4051
}
4152

4253
@Override
4354
protected void onPause() {
4455
super.onPause();
45-
if(myClient != null && !myClient.isCancelled())
56+
if (myClient != null && !myClient.isCancelled())
4657
myClient.cancel(true);
4758
}
4859

4960
@Override
5061
protected void onDestroy() {
5162
super.onDestroy();
52-
if(myClient != null && !myClient.isCancelled())
63+
if (myClient != null && !myClient.isCancelled())
5364
myClient.cancel(true);
5465
}
5566

56-
public void connectBtnListener(View view){
57-
myClient = new Client(ipInput.getText().toString(),Integer.parseInt(portInput.getText().toString()),this);
67+
public void connectBtnListener(View view) {
68+
myClient = new Client(ipInput.getText().toString(), Integer.parseInt(portInput.getText().toString()), this);
5869
myClient.execute();
5970
}
71+
72+
public void onScanBtnClick(View view) {
73+
FragmentManager supportFragmentManager = getSupportFragmentManager();
74+
FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
75+
Fragment fragmentById = supportFragmentManager.findFragmentById(R.id.fm_container);
76+
if (fragmentById != null) {
77+
fragmentTransaction.remove(fragmentById);
78+
}
79+
fragmentTransaction.commitAllowingStateLoss();
80+
Intent launchIntent = BarcodeReaderActivity.getLaunchIntent(this, true, false);
81+
startActivityForResult(launchIntent, BARCODE_READER_ACTIVITY_REQUEST);
82+
}
83+
84+
@Override
85+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
86+
super.onActivityResult(requestCode, resultCode, data);
87+
88+
if (resultCode != Activity.RESULT_OK) {
89+
Toast.makeText(this, "error in scanning", Toast.LENGTH_SHORT).show();
90+
return;
91+
}
92+
93+
if (requestCode == BARCODE_READER_ACTIVITY_REQUEST && data != null) {
94+
Barcode barcode = data.getParcelableExtra(BarcodeReaderActivity.KEY_CAPTURED_BARCODE);
95+
Toast.makeText(this, barcode.rawValue, Toast.LENGTH_SHORT).show();
96+
}
97+
98+
}
6099
}

0 commit comments

Comments
 (0)