Skip to content

Commit

Permalink
enhance example
Browse files Browse the repository at this point in the history
  • Loading branch information
mazenrashed committed Oct 23, 2018
1 parent 214e4cf commit c661aa5
Show file tree
Hide file tree
Showing 38 changed files with 187 additions and 137 deletions.
29 changes: 29 additions & 0 deletions .idea/misc.xml

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

4 changes: 2 additions & 2 deletions .idea/modules.xml

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

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(":universalbluethootprinting")
implementation project(':printooth')
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluetoothprinter
package com.mazenrashed.example

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mazenrashed.universalbluetoothprinter">
package="com.mazenrashed.example">

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Expand All @@ -12,8 +12,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".ApplicationClass">
<activity android:name=".MainActivity">
android:name="com.mazenrashed.example.ApplicationClass">
<activity android:name="com.mazenrashed.example.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mazenrashed.universalbluetoothprinter
package com.mazenrashed.example

import android.app.Application
import com.mazenrashed.universalbluethootprinter.Printooth
import com.mazenrashed.printooth.Printooth

class ApplicationClass : Application(){

Expand Down
117 changes: 117 additions & 0 deletions app/src/main/java/com/mazenrashed/example/MainActivity.kt
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()
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
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>
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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mazenrashed.universalbluethootprinter">
package="com.mazenrashed.printooth">

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<application
android:theme="@style/AppTheme">
<activity
android:name="com.mazenrashed.universalbluethootprinter.ui.ScanningActivity"
android:name="com.mazenrashed.printooth.ui.ScanningActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="com.mazenrashed.universalbluethootprinter.ui.ScanningActivity.LAUNCH" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.mazenrashed.universalbluethootprinter
package com.mazenrashed.printooth

import android.content.Context
import com.mazenrashed.universalbluethootprinter.data.DefaultPrinter
import com.mazenrashed.universalbluethootprinter.data.PairedPrinter
import com.mazenrashed.universalbluethootprinter.data.Printer
import com.mazenrashed.universalbluethootprinter.utilities.Printing
import com.mazenrashed.printooth.data.DefaultPrinter
import com.mazenrashed.printooth.data.PairedPrinter
import com.mazenrashed.printooth.data.Printer
import com.mazenrashed.printooth.utilities.Printing
import io.paperdb.Paper

object Printooth {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluethootprinter.data
package com.mazenrashed.printooth.data

/**
* Created by Omar on 20/12/2017.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluethootprinter.data
package com.mazenrashed.printooth.data

open class DefaultPrinter : Printer() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluethootprinter.data
package com.mazenrashed.printooth.data

import android.bluetooth.BluetoothDevice

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluethootprinter.data
package com.mazenrashed.printooth.data

import android.bluetooth.BluetoothDevice

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluethootprinter.data
package com.mazenrashed.printooth.data

import io.paperdb.Paper
import java.io.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluethootprinter.data
package com.mazenrashed.printooth.data

data class Printable private constructor(val text: String,
val fontSize: Byte,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mazenrashed.universalbluethootprinter.data
package com.mazenrashed.printooth.data

abstract class Printer {
var initPrinterCommand = initInitPrinterCommand()
Expand Down
Loading

0 comments on commit c661aa5

Please sign in to comment.