Skip to content

Commit

Permalink
Merge pull request #1 from you96m/master
Browse files Browse the repository at this point in the history
Fix project config's.
  • Loading branch information
mazenrashed authored Oct 23, 2018
2 parents 101c5e4 + 92f0255 commit 214e4cf
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 61 deletions.
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions .idea/markdown-navigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/markdown-navigator/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 5 additions & 29 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@ package com.mazenrashed.universalbluetoothprinter

import android.app.Activity
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.mazenrashed.universalbluethootprinter.Printooth
import com.mazenrashed.universalbluethootprinter.data.DefaultPrinter
import com.mazenrashed.universalbluethootprinter.data.Printable
import com.mazenrashed.universalbluethootprinter.ui.ScanningActivity
import kotlinx.android.synthetic.main.activity_main.btnPiarUnpair
import kotlinx.android.synthetic.main.activity_main.btnPrint

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

print.setOnClickListener {
if (!Printooth.hasPairedPrinter())
startActivityForResult(Intent(this, ScanningActivity::class.java), ScanningActivity.SCANNING_FOR_PRINTER)
else
printSomePrintables()
btnPrint.setOnClickListener {
if (!Printooth.hasPairedPrinter()) startActivityForResult(Intent(this,
ScanningActivity::class.java),
ScanningActivity.SCANNING_FOR_PRINTER)
else printSomePrintable()
}

piarUnpair.text = if (Printooth.hasPairedPrinter()) "Unpair ${Printooth.getPairedPrinter()?.name}" else "Pair with printer"
btnPiarUnpair.text = if (Printooth.hasPairedPrinter()) "Unpair ${Printooth.getPairedPrinter()?.name}" else "Pair with printer"

piarUnpair.setOnClickListener {
if (Printooth.hasPairedPrinter())
Printooth.removeCurrentPrinter()
else
startActivityForResult(Intent(this, ScanningActivity::class.java), ScanningActivity.SCANNING_FOR_PRINTER)
btnPiarUnpair.setOnClickListener {
if (Printooth.hasPairedPrinter()) Printooth.removeCurrentPrinter()
else startActivityForResult(Intent(this, ScanningActivity::class.java),
ScanningActivity.SCANNING_FOR_PRINTER)
}
}

private fun printSomePrintables() {
var printables = ArrayList<Printable>()
printables.add(
private fun printSomePrintable() {
val printable = ArrayList<Printable>()
printable.add(
Printable.PrintableBuilder()
.setText("Hello World")
.setLineSpacing(DefaultPrinter.LINE_SPACING_60)
Expand All @@ -46,7 +47,7 @@ class MainActivity : AppCompatActivity() {
.setNewLinesAfter(1)
.build()
)
printables.add(
printable.add(
Printable.PrintableBuilder()
.setText("Hello World")
.setAlignment(DefaultPrinter.ALLIGMENT_LEFT)
Expand All @@ -57,7 +58,7 @@ class MainActivity : AppCompatActivity() {
.setNewLinesAfter(1)
.build()
)
printables.add(
printable.add(
Printable.PrintableBuilder()
.setText("Hello World")
.setAlignment(DefaultPrinter.ALLIGMENT_REGHT)
Expand All @@ -68,7 +69,7 @@ class MainActivity : AppCompatActivity() {
.setNewLinesAfter(1)
.build()
)
printables.add(
printable.add(
Printable.PrintableBuilder()
.setText("اختبار العربية")
.setAlignment(DefaultPrinter.ALLIGMENT_CENTER)
Expand All @@ -80,14 +81,14 @@ class MainActivity : AppCompatActivity() {
.build()
)

Printooth.printer(this).print(printables)
Printooth.printer(this).print(printable)


}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == ScanningActivity.SCANNING_FOR_PRINTER && resultCode == Activity.RESULT_OK)
printSomePrintables()
printSomePrintable()
}
}
21 changes: 10 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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=".MainActivity">

<Button
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnPrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Print Hello World"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Print Hello World"
android:id="@+id/print"/>
app:layout_constraintTop_toTopOf="parent" />

<Button
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnPiarUnpair"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/piarUnpair"
app:layout_constraintTop_toBottomOf="@id/print"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnPrint" />

</RelativeLayout>
</android.support.constraint.ConstraintLayout>

0 comments on commit 214e4cf

Please sign in to comment.