Skip to content

Commit

Permalink
[mintware-de#1] Update layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nhan1906duong committed Apr 1, 2020
1 parent 00f2490 commit ad68184
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.google.zxing.Result
import de.mintware.barcodescan.R
import me.dm7.barcodescanner.zxing.ZXingScannerView


class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {
class BarcodeScannerActivity : AppCompatActivity(), ZXingScannerView.ResultHandler {

lateinit var scannerView: ZXingScannerView

Expand All @@ -31,29 +32,30 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {
scannerView.setAutoFocus(true)
// this paramter will make your HUAWEI phone works great!
scannerView.setAspectTolerance(0.5f)
setSupportActionBar(findViewById(R.id.toolbar))
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
if (scannerView.flash) {
val item = menu.add(0,
TOGGLE_FLASH, 0, "Flash Off")
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
} else {
val item = menu.add(0,
TOGGLE_FLASH, 0, "Flash On")
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
}
return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == TOGGLE_FLASH) {
scannerView.flash = !scannerView.flash
this.invalidateOptionsMenu()
return true
}
return super.onOptionsItemSelected(item)
}
//
// override fun onCreateOptionsMenu(menu: Menu): Boolean {
// if (scannerView.flash) {
// val item = menu.add(0,
// TOGGLE_FLASH, 0, "Flash Off")
// item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
// } else {
// val item = menu.add(0,
// TOGGLE_FLASH, 0, "Flash On")
// item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
// }
// return super.onCreateOptionsMenu(menu)
// }
//
// override fun onOptionsItemSelected(item: MenuItem): Boolean {
// if (item.itemId == TOGGLE_FLASH) {
// scannerView.flash = !scannerView.flash
// this.invalidateOptionsMenu()
// return true
// }
// return super.onOptionsItemSelected(item)
// }

override fun onResume() {
super.onResume()
Expand Down
1 change: 1 addition & 0 deletions android/src/main/res/layout/activity_scanner_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="54dp"
app:title="SCAN"
Expand Down

0 comments on commit ad68184

Please sign in to comment.