Convert class to kotlin

This commit is contained in:
ligi 2016-05-23 16:50:05 +02:00
parent 99476b1d4c
commit c0ee5cdf78
4 changed files with 34 additions and 45 deletions

View file

@ -63,7 +63,7 @@ public class BarcodeHelper {
public static BitMatrix getBitMatrix(String data, PassBarCodeFormat type) throws WriterException {
final Writer writer = new MultiFormatWriter();
return writer.encode(data, type.getZxingBarCodeFormat(), 0, 0);
return writer.encode(data, type.zxingBarCodeFormat(), 0, 0);
}
}

View file

@ -1,43 +0,0 @@
package org.ligi.passandroid.model.pass;
import com.google.zxing.BarcodeFormat;
public enum PassBarCodeFormat {
PDF_417,
AZTEC,
CODE_39,
CODE_128,
QR_CODE,
EAN_13;
public boolean isQuadratic() {
switch (this) {
case QR_CODE:
case AZTEC:
return true;
default:
return false;
}
}
public BarcodeFormat getZxingBarCodeFormat() {
switch (this) {
case QR_CODE:
return BarcodeFormat.QR_CODE;
case AZTEC:
return BarcodeFormat.AZTEC;
case CODE_39:
return BarcodeFormat.CODE_39;
case CODE_128:
return BarcodeFormat.CODE_128;
case PDF_417:
return BarcodeFormat.PDF_417;
case EAN_13:
return BarcodeFormat.EAN_13;
default:
return BarcodeFormat.QR_CODE;
}
}
}

View file

@ -0,0 +1,32 @@
package org.ligi.passandroid.model.pass
import com.google.zxing.BarcodeFormat
enum class PassBarCodeFormat {
PDF_417,
AZTEC,
CODE_39,
CODE_128,
QR_CODE,
EAN_13;
fun isQuadratic(): Boolean {
when (this) {
QR_CODE, AZTEC -> return true
else -> return false
}
}
fun zxingBarCodeFormat(): BarcodeFormat {
when (this) {
QR_CODE -> return BarcodeFormat.QR_CODE
AZTEC -> return BarcodeFormat.AZTEC
CODE_39 -> return BarcodeFormat.CODE_39
CODE_128 -> return BarcodeFormat.CODE_128
PDF_417 -> return BarcodeFormat.PDF_417
EAN_13 -> return BarcodeFormat.EAN_13
else -> return BarcodeFormat.QR_CODE
}
}
}

View file

@ -69,7 +69,7 @@ internal class BarcodeUIController(rootView: View, private val barCode: BarCode?
}
currentBarcodeWidth = width
val quadratic = barCode!!.format!!.isQuadratic
val quadratic = barCode!!.format!!.isQuadratic()
barcode_img.layoutParams = LinearLayout.LayoutParams(width, if (quadratic) width else ViewGroup.LayoutParams.WRAP_CONTENT)
}