Browse Source

Qr Code page done

old
Yiğit Çolakoğlu 6 years ago
parent
commit
dc6af84b79
7 changed files with 30 additions and 15 deletions
  1. +1
    -1
      MyCity/app/build.gradle
  2. +5
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java
  3. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java
  4. +23
    -13
      MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java
  5. BIN
      server_side/api/modules/__pycache__/rating_system.cpython-37.pyc
  6. BIN
      server_side/api/modules/__pycache__/utility.cpython-37.pyc
  7. BIN
      server_side/api/modules/__pycache__/voting_system.cpython-37.pyc

+ 1
- 1
MyCity/app/build.gradle View File

@ -24,7 +24,7 @@ dependencies {
api 'cz.msebera.android:httpclient:4.4.1.2' api 'cz.msebera.android:httpclient:4.4.1.2'
implementation 'com.google.zxing:core:3.2.0' implementation 'com.google.zxing:core:3.2.0'
implementation 'com.jjoe64:graphview:4.2.2' implementation 'com.jjoe64:graphview:4.2.2'
implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.0.0' implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0' implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'


+ 5
- 0
MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java View File

@ -50,6 +50,7 @@ public class MainActivity extends AppCompatActivity
RateFragment.OnFragmentInteractionListener, RateFragment.OnFragmentInteractionListener,
UtilityMain.OnFragmentInteractionListener, UtilityMain.OnFragmentInteractionListener,
TransitFragment.OnFragmentInteractionListener, TransitFragment.OnFragmentInteractionListener,
QRFragment.OnFragmentInteractionListener,
OnFragmentInteractionListener, OnFragmentInteractionListener,
responseListener, responseListener,
imageListener { imageListener {
@ -189,6 +190,10 @@ public class MainActivity extends AppCompatActivity
fragmentTransaction.replace(R.id.app_bar_main, fragment); fragmentTransaction.replace(R.id.app_bar_main, fragment);
fragmentTransaction.commit(); fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null); fragmentTransaction.addToBackStack(null);
}else if (id == R.id.qr_code){
QRFragment fragment= new QRFragment();
fragmentTransaction.replace(R.id.app_bar_main, fragment);
fragmentTransaction.commit();
} }


+ 1
- 1
MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java View File

@ -217,7 +217,7 @@ public class RateFragment extends Fragment implements WebRequest.responseListene
private void downloadImg(int i) throws JSONException { private void downloadImg(int i) throws JSONException {
ImageDownload downloader = new ImageDownload(); ImageDownload downloader = new ImageDownload();
downloader.addListener(this); downloader.addListener(this);
downloader.execute(url + ((JSONObject) ratings.get(i)).get("type"));
downloader.execute(url + ((JSONObject) ratings.get(i)).get("img"));
} }


+ 23
- 13
MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java View File

@ -12,24 +12,34 @@ import com.google.zxing.common.BitMatrix;
import java.util.Arrays; import java.util.Arrays;
import static android.graphics.Color.BLACK;
import static android.graphics.Color.WHITE;
public class QRCodeGenerator { public class QRCodeGenerator {
public static Bitmap Generate(String data, int height,int width) throws WriterException { public static Bitmap Generate(String data, int height,int width) throws WriterException {
MultiFormatWriter writer = new MultiFormatWriter();
String finalData = Uri.encode(data);
// Use 1 as the height of the matrix as this is a 1D Barcode.
BitMatrix bm = writer.encode(finalData, BarcodeFormat.CODE_128, width, 1);
int bmWidth = bm.getWidth();
Bitmap imageBitmap = Bitmap.createBitmap(bmWidth, height, Bitmap.Config.ARGB_8888);
BitMatrix result;
try {
result = new MultiFormatWriter().encode(data,
BarcodeFormat.QR_CODE, width, height, null);
} catch (IllegalArgumentException iae) {
// Unsupported format
return null;
}
for (int i = 0; i < bmWidth; i++) {
// Paint columns of width 1
int[] column = new int[height];
Arrays.fill(column, bm.get(i, 0) ? Color.BLACK : Color.WHITE);
imageBitmap.setPixels(column, 0, 1, i, 0, 1, height);
int w = result.getWidth();
int h = result.getHeight();
int[] pixels = new int[w * h];
for (int y = 0; y < h; y++) {
int offset = y * w;
for (int x = 0; x < w; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
} }
return imageBitmap;
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
return bitmap;
} }
} }

BIN
server_side/api/modules/__pycache__/rating_system.cpython-37.pyc View File


BIN
server_side/api/modules/__pycache__/utility.cpython-37.pyc View File


BIN
server_side/api/modules/__pycache__/voting_system.cpython-37.pyc View File


Loading…
Cancel
Save