-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
214e4cf
commit c661aa5
Showing
38 changed files
with
187 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...uetoothprinter/ExampleInstrumentedTest.kt → ...rashed/example/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ersalbluetoothprinter/ApplicationClass.kt → ...m/mazenrashed/example/ApplicationClass.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
app/src/main/java/com/mazenrashed/example/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.mazenrashed.example | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.widget.Toast | ||
import com.mazenrashed.printooth.Printooth | ||
import com.mazenrashed.printooth.data.DefaultPrinter | ||
import com.mazenrashed.printooth.data.Printable | ||
import com.mazenrashed.printooth.ui.ScanningActivity | ||
import com.mazenrashed.printooth.utilities.Printing | ||
import com.mazenrashed.printooth.utilities.PrintingCallback | ||
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) | ||
initViews() | ||
initListeners() | ||
} | ||
|
||
private fun initListeners() { | ||
btnPrint.setOnClickListener { | ||
if (!Printooth.hasPairedPrinter()) startActivityForResult(Intent(this, | ||
ScanningActivity::class.java), | ||
ScanningActivity.SCANNING_FOR_PRINTER) | ||
else printSomePrintable() | ||
} | ||
btnPiarUnpair.setOnClickListener { | ||
if (Printooth.hasPairedPrinter()) Printooth.removeCurrentPrinter() | ||
else startActivityForResult(Intent(this, ScanningActivity::class.java), | ||
ScanningActivity.SCANNING_FOR_PRINTER) | ||
initViews() | ||
} | ||
} | ||
|
||
private fun initViews() { | ||
btnPiarUnpair.text = if (Printooth.hasPairedPrinter()) "Un-pair ${Printooth.getPairedPrinter()?.name}" else "Pair with printer" | ||
} | ||
|
||
private fun printSomePrintable() { | ||
val printing = Printooth.printer(this) | ||
|
||
printing.printingCallback = object : PrintingCallback { | ||
override fun connectingWithPrinter() { | ||
Toast.makeText(this@MainActivity, "Connecting with printer", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
override fun printingOrderSentSuccessfully() { | ||
Toast.makeText(this@MainActivity, "Order sent to printer", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
override fun connectionFailed(error: String) { | ||
Toast.makeText(this@MainActivity, "Failed to connect printer", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
override fun onError(error: String) { | ||
Toast.makeText(this@MainActivity, error, Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
override fun onMessage(message: String) { | ||
Toast.makeText(this@MainActivity, "Message: $message", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
} | ||
|
||
val printable = getSomePrintables() | ||
|
||
printing.print(printable) | ||
} | ||
|
||
private fun getSomePrintables() = ArrayList<Printable>().apply { | ||
add(Printable.PrintableBuilder() | ||
.setText("Hello World") | ||
.setFontSize(DefaultPrinter.FONT_SIZE_LARGE) | ||
.setNewLinesAfter(1) | ||
.build()) | ||
|
||
add(Printable.PrintableBuilder() | ||
.setText("Hello World") | ||
.setLineSpacing(DefaultPrinter.LINE_SPACING_60) | ||
.setAlignment(DefaultPrinter.ALLIGMENT_CENTER) | ||
.setEmphasizedMode(DefaultPrinter.EMPHASISED_MODE_BOLD) | ||
.setUnderlined(DefaultPrinter.UNDELINED_MODE_ON) | ||
.setNewLinesAfter(1) | ||
.build()) | ||
|
||
add(Printable.PrintableBuilder() | ||
.setText("Hello World") | ||
.setAlignment(DefaultPrinter.ALLIGMENT_REGHT) | ||
.setEmphasizedMode(DefaultPrinter.EMPHASISED_MODE_BOLD) | ||
.setUnderlined(DefaultPrinter.UNDELINED_MODE_ON) | ||
.setNewLinesAfter(1) | ||
.build()) | ||
|
||
add(Printable.PrintableBuilder() | ||
.setText("اختبار العربية") | ||
.setAlignment(DefaultPrinter.ALLIGMENT_CENTER) | ||
.setEmphasizedMode(DefaultPrinter.EMPHASISED_MODE_BOLD) | ||
.setFontSize(DefaultPrinter.FONT_SIZE_NORMAL) | ||
.setUnderlined(DefaultPrinter.UNDELINED_MODE_ON) | ||
.setCharacterCode(DefaultPrinter.CHARACTER_CODE_ARABIC_FARISI) | ||
.setNewLinesAfter(1) | ||
.build()) | ||
} | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
if (requestCode == ScanningActivity.SCANNING_FOR_PRINTER && resultCode == Activity.RESULT_OK) | ||
printSomePrintable() | ||
initViews() | ||
} | ||
} |
94 changes: 0 additions & 94 deletions
94
app/src/main/java/com/mazenrashed/universalbluetoothprinter/MainActivity.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<resources> | ||
<string name="app_name">UniversalBluetoothPrinter</string> | ||
<string name="app_name">Printooth example</string> | ||
</resources> |
2 changes: 1 addition & 1 deletion
2
...versalbluetoothprinter/ExampleUnitTest.kt → ...om/mazenrashed/example/ExampleUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.mazenrashed.universalbluetoothprinter | ||
package com.mazenrashed.example | ||
|
||
import org.junit.Test | ||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...hootprinting/src/main/AndroidManifest.xml → printooth/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...ed/universalbluethootprinter/Printooth.kt → ...va/com/mazenrashed/printooth/Printooth.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...luethootprinter/data/BluetoothCallback.kt → ...ashed/printooth/data/BluetoothCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...albluethootprinter/data/DefaultPrinter.kt → ...enrashed/printooth/data/DefaultPrinter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...albluethootprinter/data/DeviceCallback.kt → ...enrashed/printooth/data/DeviceCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...luethootprinter/data/DiscoveryCallback.kt → ...ashed/printooth/data/DiscoveryCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...salbluethootprinter/data/PairedPrinter.kt → ...zenrashed/printooth/data/PairedPrinter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...iversalbluethootprinter/data/Printable.kt → ...m/mazenrashed/printooth/data/Printable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...universalbluethootprinter/data/Printer.kt → ...com/mazenrashed/printooth/data/Printer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.