How to Use Q1 Buttons in Applications: Difference between revisions

From wizarPOS
No edit summary
Line 1: Line 1:
== Keyboard description ==
== Keyboard Description ==
{| class="wikitable"
{| class="wikitable"
|-
|-
! Key!! Value!! Description
! Key!! Value!! Description
|-
|-
| Period || KeyEvent.KEYCODE_PERIOD || The black dot button on the right-bottom of keyboard.
| Period || KeyEvent.KEYCODE_PERIOD || Black dot button on the right-bottom of the keyboard
|-
|-
| QRCode|| 232 || The orange button on the middle-bottom of keyboard
| QRCode|| 232 || Orange button on the middle-bottom of the keyboard
|-
|-
| Back|| KeyEvent.KEYCODE_ESCAPE|| The red X button on the left-bottom of keyboard
| Back|| KeyEvent.KEYCODE_ESCAPE|| Red 'X' button on the left-bottom of the keyboard
|-
|-
| Scann|| 229|| The orange button on the left of the LED
| Scann|| 229|| Orange button on the left of the LCD
|-
|-
| Delete|| KeyEvent.KEYCODE_DEL|| The yellow triangle button on the right-top of keyboard
| Delete|| KeyEvent.KEYCODE_DEL|| Yellow triangle button on the right-top of the keyboard
|-
|-
| Enter|| KeyEvent.KEYCODE_ENTER|| The green circle button on the right-bottom of keyboard
| Enter|| KeyEvent.KEYCODE_ENTER|| Green circle button on the right-bottom of the keyboard
|}
|}
The others are digital buttons which are defined in the Android system. See android.view.KeyEvent.
Digital Buttons: Other buttons are standard digital buttons as defined in android.view.KeyEvent.
 
== Scan Button and QR Code Button Usage ==
== Scan button and QR Code button ==
* '''Function:''' These buttons quickly launch scan applications.
The scan button and QR code button can quickly launch the scan application. If you press one of the buttons, the system will search for all the applications installed in the system and will launch the application with the scan intent-filter. If there are many applications, the system will provide a list for users to choose, and the selected application will start. The code for the scan intent-filter is as follows:
* '''Process:'''
** Pressing either button prompts the system to search for installed applications with a scan intent-filter.
** If multiple applications are available, the system displays a list for user selection.
** The selected application will start. The code for the scan intent-filter is as follows:
     <action android:name="android.intent.action.SCAN" />
     <action android:name="android.intent.action.SCAN" />
     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.DEFAULT" />
When there is no application in the system to define the scan intent-filter, pressing the scan button or QR code button will not work.
* '''Note:''' If no application with the scan intent-filter is installed, pressing these buttons has no effect.
=== Sample ===
== Implementation in Applications ==
There are two ways to use the scan button and the QR code button:
1. '''Defining Intent-Filter:'''
* In order to use the scan button to quickly launch the scan application, the application must define the scan intent-filter in its Android manifest file. The category and the action are defined as follows:
* To use the scan button and the QR code button, your application must define a scan intent-filter in the Android manifest file.
* Specify both the category and action.
     <activity
     <activity
     android:name="com.XX.activity.MainActivity"
     android:name="com.XX.activity.MainActivity"
Line 35: Line 39:
     </intent-filter>
     </intent-filter>
     </activity>
     </activity>
 
2. '''Handling Button Press:'''
* When the button is pressed, the active top task gets the key value and executes it as its logical source code. The application must override the function of onKeyDown as follows:
* When the button is pressed, the active top task receives the key value.
* Implement the logic in the application's ''''onKeyDown'''' function override.
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
  /** Key code constant: left scan key. */
  /** Key code constant: left scan key. */

Revision as of 17:22, 27 December 2023

Keyboard Description

Key Value Description
Period KeyEvent.KEYCODE_PERIOD Black dot button on the right-bottom of the keyboard
QRCode 232 Orange button on the middle-bottom of the keyboard
Back KeyEvent.KEYCODE_ESCAPE Red 'X' button on the left-bottom of the keyboard
Scann 229 Orange button on the left of the LCD
Delete KeyEvent.KEYCODE_DEL Yellow triangle button on the right-top of the keyboard
Enter KeyEvent.KEYCODE_ENTER Green circle button on the right-bottom of the keyboard

Digital Buttons: Other buttons are standard digital buttons as defined in android.view.KeyEvent.

Scan Button and QR Code Button Usage

  • Function: These buttons quickly launch scan applications.
  • Process:
    • Pressing either button prompts the system to search for installed applications with a scan intent-filter.
    • If multiple applications are available, the system displays a list for user selection.
    • The selected application will start. The code for the scan intent-filter is as follows:
   <action android:name="android.intent.action.SCAN" />
   <category android:name="android.intent.category.DEFAULT" />
  • Note: If no application with the scan intent-filter is installed, pressing these buttons has no effect.

Implementation in Applications

1. Defining Intent-Filter:

  • To use the scan button and the QR code button, your application must define a scan intent-filter in the Android manifest file.
  • Specify both the category and action.
   <activity
   android:name="com.XX.activity.MainActivity"
   android:label="@string/app_name" >
    <intent-filter>
      <action android:name="android.intent.action.SCAN" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
   </activity>

2. Handling Button Press:

  • When the button is pressed, the active top task receives the key value.
  • Implement the logic in the application's 'onKeyDown' function override.
 /** Key code constant: left scan key. */
 public static final int KEYCODE_SCAN_LEFT        	= 229;

 /** Key code constant: right scan key. */
 public static final int KEYCODE_SCAN_RIGHT        = 230;

 /** Key code constant: qr key. */
 public static final int KEYCODE_QR        		= 232;

 public boolean onKeyDown(int keyCode, KeyEvent event) { 
  // listen the key code
  if (keyCode == KEYCODE_SCAN_LEFT|| keyCode ==KEYCODE_SCAN_RIGHT|| keyCode ==KEYCODE_QR) {
  //do something, for example:scanner……
    return true;
  }
  return super.onKeyDown(keyCode, event);
}