Skip to content
Snippets Groups Projects
Commit 8f3b6a16 authored by Vietanh Le Trung's avatar Vietanh Le Trung
Browse files

added qrgenerator

now i have to just kill myself.

need a parser, and a reader, and importing
parent f5d57115
No related branches found
No related tags found
No related merge requests found
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ireallydontcare.viet.posseidon"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
implementation 'com.android.support:recyclerview-v7:28.0.0'
api 'com.github.kenglxn.QRGen:android:2.5.0'
}
......@@ -22,7 +22,8 @@
<activity
android:name=".SubjectActivity"
android:label="@string/title_activity_subject"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".QRActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package com.ireallydontcare.viet.posseidon;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import net.glxn.qrgen.android.QRCode;
import net.glxn.qrgen.core.image.ImageType;
public class QRActivity extends AppCompatActivity {
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qr);
Bitmap myBitmap = QRCode.from("www.example.org").bitmap();
imageView = findViewById(R.id.QRimage);
imageView.setImageBitmap(myBitmap);
}
}
......@@ -2,6 +2,8 @@ package com.ireallydontcare.viet.posseidon;
import android.app.DatePickerDialog;
import android.arch.persistence.room.Room;
import android.content.ClipData;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
......@@ -10,6 +12,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.ireallydontcare.viet.posseidon.adapter.EventAdapter;
......@@ -33,9 +37,7 @@ public class SubjectActivity extends AppCompatActivity
private EventAdapter eventAdapter;
private RecyclerView.LayoutManager eventLayoutManager;
private EventDatabase database;
private MenuItem qrButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -54,6 +56,8 @@ public class SubjectActivity extends AppCompatActivity
}
});
qrButton = (MenuItem) findViewById(R.id.genQR);
eventRecyclerView = (RecyclerView) findViewById(R.id.EventRecyclerView);
eventRecyclerView.setHasFixedSize(true);
......@@ -108,4 +112,24 @@ public class SubjectActivity extends AppCompatActivity
}
}.execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_subject, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.genQR:
Intent showDetailsIntent = new Intent();
showDetailsIntent.setClass(SubjectActivity.this, QRActivity.class);
startActivity(showDetailsIntent);
return true;
default:
return true;
}
}
}
package com.ireallydontcare.viet.posseidon.outsource;
import android.graphics.Bitmap;
import android.graphics.Color;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
public class QRCodeUtil {
private QRCodeUtil() {}
public static Bitmap encodeAsBitmap(String source, int width, int height) {
BitMatrix result;
try {
result = new MultiFormatWriter().encode(source, BarcodeFormat.QR_CODE, width, height, null);
} catch (IllegalArgumentException | WriterException e) {
// Unsupported format
return null;
}
final int w = result.getWidth();
final int h = result.getHeight();
final int[] pixels = new int[w * h];
for (int y = 0; y < h; y++) {
final int offset = y * w;
for (int x = 0; x < w; x++) {
pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE;
}
}
final Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, w, h);
return bitmap;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".QRActivity">
<ImageView
android:id="@+id/QRimage"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -7,6 +7,28 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".SubjectActivity"
tools:showIn="@layout/activity_subject">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="targykod"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="leiras"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="kredit"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
......@@ -16,4 +38,5 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -3,8 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.ireallydontcare.viet.posseidon.MainActivity">
<item
android:id="@+id/action_settings"
android:id="@+id/deleteSubject"
android:orderInCategory="100"
android:title="@string/action_settings"
android:title="Delete"
app:showAsAction="never" />
<item
android:id="@+id/genQR"
android:orderInCategory="100"
android:title="Generate QR"
app:showAsAction="never" />
</menu>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment