Skip to content

Commit

Permalink
Merge pull request #21 from VladimirJevtic95/master
Browse files Browse the repository at this point in the history
Contact barcode edit
  • Loading branch information
androidmads authored Jun 21, 2022
2 parents 2ded3dd + 74f4162 commit 1f53d1e
Show file tree
Hide file tree
Showing 24 changed files with 474 additions and 38 deletions.
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
18 changes: 18 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions QRGenearator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ group = 'androidmads.library.qrgenearator' // Change this to match your package
version = '1.0.4' // Change this to match your version number

android {
compileSdkVersion 28
compileSdkVersion 30
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
Expand All @@ -24,7 +24,7 @@ android {
}

dependencies {
implementation 'com.google.zxing:core:3.2.0'
implementation 'com.google.zxing:core:3.3.2'
}

Properties properties = new Properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ public static final class Type {
public static final String LOCATION = "LOCATION_TYPE";
}

public static final String URL_KEY = "URL_KEY";

public static final String NOTE_KEY = "NOTE_KEY";

// When using Type.CONTACT, these arrays provide the keys for adding or retrieving multiple
// phone numbers and addresses.
public static final String[] PHONE_KEYS = {
ContactsContract.Intents.Insert.PHONE, ContactsContract.Intents.Insert.SECONDARY_PHONE,
ContactsContract.Intents.Insert.PHONE,
ContactsContract.Intents.Insert.SECONDARY_PHONE,
ContactsContract.Intents.Insert.TERTIARY_PHONE
};

Expand All @@ -48,7 +45,8 @@ public static final class Type {
};

public static final String[] EMAIL_KEYS = {
ContactsContract.Intents.Insert.EMAIL, ContactsContract.Intents.Insert.SECONDARY_EMAIL,
ContactsContract.Intents.Insert.EMAIL,
ContactsContract.Intents.Insert.SECONDARY_EMAIL,
ContactsContract.Intents.Insert.TERTIARY_EMAIL
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,20 @@ private void encodeQRCodeContents(String data, Bundle bundle, String type) {
StringBuilder newContents = new StringBuilder(100);
StringBuilder newDisplayContents = new StringBuilder(100);

newContents.append("VCARD:");
newContents.append("BEGIN:VCARD\n");

String name = trim(bundle.getString(ContactsContract.Intents.Insert.NAME));
if (name != null) {
newContents.append("N:").append(escapeVCard(name)).append(';');
newDisplayContents.append(name);
newContents.append("\n");
}

String address = trim(bundle.getString(ContactsContract.Intents.Insert.POSTAL));
if (address != null) {
newContents.append("ADR:").append(escapeVCard(address)).append(';');
//the append ; is removed because it is unnecessary because we are breaking into new row
newContents.append("ADR:").append(escapeVCard(address));//.append(';')
newContents.append("\n");
newDisplayContents.append('\n').append(address);
}

Expand All @@ -135,7 +138,8 @@ private void encodeQRCodeContents(String data, Bundle bundle, String type) {
}
}
for (String phone : uniquePhones) {
newContents.append("TEL:").append(escapeVCard(phone)).append(';');
newContents.append("TEL:").append(escapeVCard(phone));//.append(';')
newContents.append("\n");
//noinspection deprecation
newDisplayContents.append('\n').append(PhoneNumberUtils.formatNumber(phone));
}
Expand All @@ -148,25 +152,37 @@ private void encodeQRCodeContents(String data, Bundle bundle, String type) {
}
}
for (String email : uniqueEmails) {
newContents.append("EMAIL:").append(escapeVCard(email)).append(';');
newContents.append("EMAIL:").append(escapeVCard(email));//.append(';')
newContents.append("\n");
newDisplayContents.append('\n').append(email);
}

String url = trim(bundle.getString(QRGContents.URL_KEY));
String organization = trim(bundle.getString(ContactsContract.Intents.Insert.COMPANY));
if (organization != null) {
newContents.append("ORG:").append(organization);//.append(';')
newContents.append("\n");
newDisplayContents.append('\n').append(organization);
}

String url = trim(bundle.getString(ContactsContract.Intents.Insert.DATA));
if (url != null) {
// escapeVCard(url) -> wrong escape e.g. http\://zxing.google.com
newContents.append("URL:").append(url).append(';');
// in this field only the website name and the domain are necessary (example : somewebsite.com)
newContents.append("URL:").append(escapeVCard(url));//.append(';');
newContents.append("\n");
newDisplayContents.append('\n').append(url);
}

String note = trim(bundle.getString(QRGContents.NOTE_KEY));
String note = trim(bundle.getString(ContactsContract.Intents.Insert.NOTES));
if (note != null) {
newContents.append("NOTE:").append(escapeVCard(note)).append(';');
newContents.append("NOTE:").append(escapeVCard(note));//.append(';')
newContents.append("\n");
newDisplayContents.append('\n').append(note);
}

// Make sure we've encoded at least one field.
if (newDisplayContents.length() > 0) {
//this end vcard needs to be at the end in order for the default phone reader to recognize it as a contact
newContents.append("END:VCARD");
newContents.append(';');
contents = newContents.toString();
displayContents = newDisplayContents.toString();
Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
implementation project(':QRGenearator')
//implementation 'androidmads.library.qrgenearator:QRGenearator:1.0.3'
}
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="androidmads.example">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand All @@ -17,6 +17,12 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GenDataActivity"
android:screenOrientation="portrait" />
<activity
android:name=".GenQRActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
52 changes: 52 additions & 0 deletions app/src/main/java/androidmads/example/GenDataActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package androidmads.example;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class GenDataActivity extends AppCompatActivity {

EditText editTextName, editTextAddress, editTextPhone, editTextAddressMail, editTextNotes, editTextOrganization, editTextURL;
Button btnGenerate;

private static final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gen_data);

editTextName = findViewById(R.id.editTextName);
editTextAddress = findViewById(R.id.editTextAddress);
editTextPhone = findViewById(R.id.editTextPhone);
editTextAddressMail = findViewById(R.id.editTextAddressMail);
btnGenerate = findViewById(R.id.btnGenerate);
editTextNotes = findViewById(R.id.editTextNotes);
editTextOrganization = findViewById(R.id.editTextOrganization);
editTextURL = findViewById(R.id.editTextURL);

btnGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

//keys in bundle correspond to the fields in the ContactsContract.class
Intent intent = new Intent(getApplicationContext(), GenQRActivity.class);
Bundle bundle = new Bundle();
bundle.putString("name", editTextName.getText().toString());
bundle.putString("postal", editTextAddress.getText().toString());
bundle.putString("phone", editTextPhone.getText().toString());
bundle.putString("email", editTextAddressMail.getText().toString());
bundle.putString("notes", editTextNotes.getText().toString());
bundle.putString("company", editTextOrganization.getText().toString());
bundle.putString("data", editTextURL.getText().toString());
intent.putExtras(bundle);
startActivity(intent);
}
});

}
}
50 changes: 50 additions & 0 deletions app/src/main/java/androidmads/example/GenQRActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package androidmads.example;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import androidmads.library.qrgenearator.QRGContents;
import androidmads.library.qrgenearator.QRGEncoder;

public class GenQRActivity extends AppCompatActivity {

ImageView imageQR;
Bitmap bitmap;
private static final String TAG = "QRActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gen_q_r);

imageQR = findViewById(R.id.imageQR);

final Bundle bundle = getIntent().getExtras();
// String name = bundle.getString("name");
// String address = bundle.getString("postal");
// String phone = bundle.getString("phone");
// String email = bundle.getString("email");
// String notes = bundle.getString("notes");
// String organization = bundle.getString("company");
// String url = bundle.getString("data");
// Toast.makeText(this, name + address + phone, Toast.LENGTH_SHORT).show();


//setting the data as null and bundle of data from the previous activity because of the type of the QR
QRGEncoder qrgEncoder = new QRGEncoder(null, bundle, QRGContents.Type.CONTACT, 500);
try {
// Getting QR-Code as Bitmap
bitmap = qrgEncoder.getBitmap();
// Setting Bitmap to ImageView
imageQR.setImageBitmap(bitmap);
} catch (Exception e) {
Log.v(TAG, e.toString());
}

}
}
Loading

0 comments on commit 1f53d1e

Please sign in to comment.