Skip to content

Commit

Permalink
WIP: feat: Show my QR code (#5)
Browse files Browse the repository at this point in the history
feat: Show my QR code
  • Loading branch information
jorge-sanz committed Jan 12, 2018
1 parent cdc3510 commit 3d2024a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .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 app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ dependencies {

// Test helpers for Room
testImplementation "android.arch.persistence.room:testing:1.0.0"

//QR generation
compile 'com.journeyapps:zxing-android-embedded:3.5.0'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aros.naufal.qrreader">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -16,7 +18,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.activities.ShowQRActivity"></activity>
</application>
<uses-permission android:name="android.permission.CAMERA" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public LiveData<List<Card>> getAllCards() {
return mAllCards;
}


public void insert(Card card) {
new insertAsyncTask(mCardDao).execute(card);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public Card(String name) {
public String getName() {
return this.name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.design.internal.NavigationMenu;
import android.support.v7.app.AlertDialog;
Expand All @@ -12,6 +13,7 @@
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.aros.naufal.qrreader.R;
Expand Down Expand Up @@ -58,6 +60,10 @@ public boolean onMenuItemSelected(MenuItem menuItem) {
mScannerView.startCamera();
}

if (menuItem.getTitle().equals("Show my QR")) {
clickBtnGenerateQR(findViewById(android.R.id.content));
return true;
}
Toast.makeText(MainActivity.this, "" + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
Expand Down Expand Up @@ -106,4 +112,12 @@ public void handleResult(final Result result) {
finish();
startActivity(getIntent());
}

public void clickBtnGenerateQR(View v) {
Intent intent = new Intent(MainActivity.this, ShowQRActivity.class);
Bundle b = new Bundle();
b.putString("TEXT", "Joaquín Adiego");
intent.putExtras(b);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.aros.naufal.qrreader.ui.activities;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.aros.naufal.qrreader.R;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.journeyapps.barcodescanner.BarcodeEncoder;

public class ShowQRActivity extends AppCompatActivity {

private TextView txtSend;
ImageView qrCode;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_qr);
txtSend = (TextView) findViewById(R.id.TxtRead);
Bundle bundle = this.getIntent().getExtras();
String textToQr = bundle.getString("TEXT");
qrCode = (ImageView) findViewById(R.id.imageQRcode);
int width = getWindowManager().getDefaultDisplay().getWidth();
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();

try {
BitMatrix bitMatrix = multiFormatWriter.encode(textToQr, BarcodeFormat.QR_CODE, width, width);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
qrCode.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
}
}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/activity_show_qr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.aros.naufal.qrreader.ui.activities.ShowQRActivity">

<TextView
android:id="@+id/TxtRead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />

<ImageView
android:id="@+id/imageQRcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
7 changes: 3 additions & 4 deletions app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
android:id="@+id/show_qr"
android:icon="@drawable/ic_show_qr"
android:iconTint="@android:color/white"
android:title="Show my QR"
/>
android:title="Show my QR" />
/>

<item
android:id="@+id/capture_qr"
android:icon="@drawable/ic_capture_qr"
android:iconTint="@android:color/white"
android:title="Capture QR"
/>
android:title="Capture QR" />

</menu>

0 comments on commit 3d2024a

Please sign in to comment.