From dc6af84b792aa314e8b61cc892c5772dd35e67e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yi=C4=9Fit=20=C3=87olako=C4=9Flu?= Date: Wed, 24 Apr 2019 17:35:23 +0300 Subject: [PATCH] Qr Code page done --- MyCity/app/build.gradle | 2 +- .../java/gq/yigit/mycity/MainActivity.java | 5 +++ .../java/gq/yigit/mycity/RateFragment.java | 2 +- .../yigit/mycity/tools/QRCodeGenerator.java | 36 +++++++++++------- .../__pycache__/rating_system.cpython-37.pyc | Bin 2890 -> 3161 bytes .../__pycache__/utility.cpython-37.pyc | Bin 1221 -> 1221 bytes .../__pycache__/voting_system.cpython-37.pyc | Bin 3522 -> 3445 bytes 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/MyCity/app/build.gradle b/MyCity/app/build.gradle index 8461eba..305382f 100644 --- a/MyCity/app/build.gradle +++ b/MyCity/app/build.gradle @@ -24,7 +24,7 @@ dependencies { api 'cz.msebera.android:httpclient:4.4.1.2' implementation 'com.google.zxing:core:3.2.0' 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:design:27.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java index ea5a9e8..bec9a85 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java @@ -50,6 +50,7 @@ public class MainActivity extends AppCompatActivity RateFragment.OnFragmentInteractionListener, UtilityMain.OnFragmentInteractionListener, TransitFragment.OnFragmentInteractionListener, + QRFragment.OnFragmentInteractionListener, OnFragmentInteractionListener, responseListener, imageListener { @@ -189,6 +190,10 @@ public class MainActivity extends AppCompatActivity fragmentTransaction.replace(R.id.app_bar_main, fragment); fragmentTransaction.commit(); fragmentTransaction.addToBackStack(null); + }else if (id == R.id.qr_code){ + QRFragment fragment= new QRFragment(); + fragmentTransaction.replace(R.id.app_bar_main, fragment); + fragmentTransaction.commit(); } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java index 99116fd..f4a70e3 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java @@ -217,7 +217,7 @@ public class RateFragment extends Fragment implements WebRequest.responseListene private void downloadImg(int i) throws JSONException { ImageDownload downloader = new ImageDownload(); downloader.addListener(this); - downloader.execute(url + ((JSONObject) ratings.get(i)).get("type")); + downloader.execute(url + ((JSONObject) ratings.get(i)).get("img")); } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java b/MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java index bdfbae5..f78c034 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java @@ -12,24 +12,34 @@ import com.google.zxing.common.BitMatrix; import java.util.Arrays; +import static android.graphics.Color.BLACK; +import static android.graphics.Color.WHITE; + public class QRCodeGenerator { 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; } } + diff --git a/server_side/api/modules/__pycache__/rating_system.cpython-37.pyc b/server_side/api/modules/__pycache__/rating_system.cpython-37.pyc index 18147da60b27d45d1f57be00b5955ab40e168617..44deb02427b037057a7719df2fdcc2359afd1953 100644 GIT binary patch delta 1191 zcmZ`%-%Aux6u$S)o!Qx+D(32%u0KL+3Kk=i0x>A14ARh&TC!!@J1#5xt2?uSqU?hb zK}5uTEvm;JBM^G4ryzRl#rY3<>ZPY1q;qCh5wRK0xA)#X_ssX5^LcD^?0_o?^}Vvj7FML6(O%=>`=fMF44lEI=(q1b@w6O|!=w>gYZz3ZGZ(vg32% zxOrbImJ1e_NLoe_VhC}755!_V%Z&N-i9|{=q5f!h8h;~`rK0QQtL55M3XWYQWEkrM zElrt%<7FmG)x2GDr(m(4Yf(QWo3dfaU8l6tDvPx{0DKLuc4J8nKo}H_9xB@Gz^6UB zL>tHPJzfP!)>leZ+ml$-=POlNmYujX>{`vK2+NcwU@Mad`1PzQ9WN(r&(0c6!V-06 z+nSqP$@bK))}1`cp4Y0bH>~FQ1l843K61VbEA}Ha+jp=+u`&#R-wec>)Qrlox@C;3 zu--n4Ej1wmJB-0%E#?K2?STm|f?M$Qz#>9>$2RDDD)FW2 znd@4hSE6Zr1NGaU#RAcOxTUEm4si_VA^9Z;7kLoMXiQO~^Ku$CasXivA&_{Sx*_=Y zE=1rClgc5`Hcx-5H%1Trp>~W$im&SE)Jft+y_kq?v6snB?!{LV>PF}*&8mobYj7AU zWOd-^xUK0ncT%3luUo2aTJ)59Yo=(M`fQH&o`hqtbj1tQ2K0QbJ ztIhkEO^@0z7}-O0Gu(GO&0@5dnQT40030$n;5i_2qzV5W@hH?^hS+bysM-lXGku<~ z*4E^Nnu*NNw0a&H$zDVvp}OnHoOmS1VJ9!)5eMUn=Je17foCMPR$^&CW($#%j$5tE dyyI)KUO6Kki9K8tQ&09beM7-O7K>QP8)r^uTI75BZR8`m1_jP@%e(oq=E0sI~PxAfM z(sJo-`4d%vU2~oLp=`u!>ANS!5><~_wNi#6(S}e#IHi7?om1Kod7ZYyW;2R;;A%6C zHdX~T6-9tWS46VTLm6s2FBT66H z&jLUPSjqrgs>=4w2L`%e*D-z-V5>)x11edIa#|%_>FFddkp25HfQ&`Zt% z4x@YAEb}r^`XF%|?6)YQPgU#*_0*|#e}!nS#es21q`7W!3VJZ{Q5`wE?ZwMP`m)6R zJ@&j~$CTyuHnrd$QLSo)yM6umzX1T41uuUwlS7CA<6~;S5Yz_2-EN;tBQd~}D2+$t zK=ing$~35`FNNX$cF1d^5z9=djDa>bqBs|CRQcZE7-}Yl5c0-&gsz?-nsLO9m{ap! z&%G-1X*YA(b^+vy#&LE2RSSCkcY{Wt(Ja^>u}0JfZ{HDTAtWxU+2RdaQ!k1`i&GHL z&L&W+^JOuK=}Q+siv<8Q%>{Y@ diff --git a/server_side/api/modules/__pycache__/voting_system.cpython-37.pyc b/server_side/api/modules/__pycache__/voting_system.cpython-37.pyc index 7689a6b2cff58dda274e0e290faac873e70bd2d1..0cc2f38d09ff4a906fa24d6ffe26d87bd45ea1b9 100644 GIT binary patch delta 293 zcmX>k{Z)$BiI#v;?rdOWg>0#+c!oFKvgM3_#F=8fUz5)kKNBb5Qb;=KE2}z_`#Q2(3oIBXh=>I8nsj#5`hF`h>I5r;oRFo%n=G|t4plm zCm0HAt*tES{1Nuf!cN{N@60=y{VRR#duN{K0KL!Pqx<&m{a90-I-7J(ibBHpQo5d#*}N>M`T22s51F1>BY<+NPIAtZ~fKya=2%;OVFZlxPiN6L4M9u|pL#hcC>ssXLV^K)zc5P~}^!rgbUfI0g50w);6s`=>8wPz*R$hyw z5SDW0!$>^#WJMRd>cX+Yo(gav(yCb_t6Yw7MT#;6K!)3x!xEZIM-yM1n~@w0gKDt+ zw(poB>a>&8+_HN@W^?y6>ADBlNycs~>(jJNiWtF0;V*yPL(DYP@|HqP!B5g&*G*;e I4yIMHe{1whNB{r;