Skip to content

Commit 9049da6

Browse files
committed
first commit for SecondDisplaySampleAPI
1 parent e59478c commit 9049da6

File tree

45 files changed

+636
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+636
-1
lines changed

.gitlab-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ JoyaTouchCradleSampleAPIRelease:
100100
LANGUAGE_FOLDER: "Java"
101101
<<: *build_definition
102102

103+
SecondDisplaySampleAPIRelease:
104+
variables:
105+
PROJECT_FOLDER: "SecondDisplaySampleAPI"
106+
LANGUAGE_FOLDER: "Java"
107+
<<: *build_definition
108+
103109
ZXingSampleAPIRelease:
104110
variables:
105111
PROJECT_FOLDER: "ZXingSampleAPI"

Java/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ Java sample apps.
1515
| [DecodeSampleAPI](DecodeSampleAPI/) | Display barcodes, enable/disable symbologies and register/release listeners. | ![DecodeSampleAPI](screenshots/decode_sample.png)
1616
| [DeviceSampleAPI](DeviceSampleAPI/) | View and manage system settings.| ![DeviceSampleAPI](screenshots/device_api.png)
1717
| [JoyaTouchCradleSampleAPI](JoyaTouchCradleSampleAPI/) | Configure/Control scanner cradle including locking. | ![JoyaTouchCradleSampleAPI](screenshots/joyatouch_cradle_sample.jpg)
18-
| [ZXingSampleAPI](ZXingSampleAPI/) | | -
18+
| [SecondDisplaySampleAPI](SecondDisplaySampleAPI/) | Configure 2nd Display to show notifications only coming from your App. | ![SecondDisplaySampleAPI](screenshots/second_display_sample.jpg)
19+
| [ZXingSampleAPI](ZXingSampleAPI/) | | -
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gradle
2+
.idea
3+
.build
4+
local.properties
5+
*.iml
6+
build
7+
.DS_Store
8+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 'Datalogic:Datalogic SDK v1:28'
5+
buildToolsVersion '28.0.3'
6+
7+
defaultConfig {
8+
applicationId "com.datalogic.examples.seconddisplaysampleapi"
9+
minSdkVersion 28
10+
targetSdkVersion 29
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
implementation 'com.android.support:support-compat:28.0.0'
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.datalogic.examples.seconddisplaysampleapi"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk android:targetSdkVersion="28" />
8+
9+
<application
10+
android:allowBackup="true"
11+
android:icon="@drawable/ic_launcher"
12+
android:label="@string/app_name"
13+
android:theme="@style/AppTheme" >
14+
15+
<uses-library
16+
android:name="com.datalogic.device"
17+
android:required="true" />
18+
19+
<activity
20+
android:name="com.datalogic.examples.seconddisplaysampleapi.MainActivity"
21+
android:label="@string/app_name"
22+
android:screenOrientation="portrait" >
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN" />
25+
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
</activity>
29+
</application>
30+
31+
</manifest>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// ©2020 Datalogic S.p.A. and/or its affiliates. All rights reserved.
2+
3+
package com.datalogic.examples.seconddisplaysampleapi;
4+
5+
import android.app.Activity;
6+
import android.app.NotificationChannel;
7+
import android.app.NotificationManager;
8+
import android.os.Bundle;
9+
import android.support.v4.app.NotificationCompat;
10+
import android.util.Log;
11+
import android.view.Menu;
12+
import android.view.MotionEvent;
13+
import android.view.View;
14+
import android.view.Window;
15+
import android.view.WindowManager;
16+
import android.view.View.OnTouchListener;
17+
import android.widget.Button;
18+
import android.app.Notification;
19+
import java.util.List;
20+
21+
import com.datalogic.device.display.DLSecondDisplayManager;
22+
23+
public class MainActivity extends Activity {
24+
25+
static final String TAG = "Test-Scanner";
26+
private final String PACKAGE_NAME = "com.datalogic.examples.seconddisplaysampleapi";
27+
28+
// The send notification button
29+
private Button mSend;
30+
31+
private final String NOTIFICATION_CHANNEL_ID = "2nd Display Channel";
32+
private final String NOTIFICATION_CHANNEL_NAME = "2nd display notification sample channel";
33+
34+
private final int NOTIFICATION_ID = 0;
35+
private final String NOTIFICATION_TITLE_TEXT = "2nd Display Sample";
36+
private final String NOTIFICATION_CONTENT_TEXT = "this sample notification is rolling on second display!";
37+
38+
private NotificationManager mNotificationManager = null;
39+
private Notification mNotification = null;
40+
41+
@Override
42+
protected void onCreate(Bundle savedInstanceState) {
43+
super.onCreate(savedInstanceState);
44+
Window window = getWindow();
45+
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
46+
setContentView(R.layout.activity_main);
47+
48+
// 2nd Display configuration to enable the App
49+
// to shown notification on 2nd Display
50+
setupSecondDisplay();
51+
52+
// Configure the Notification System to
53+
// allow the App to send notifications
54+
setupNotificationSystem();
55+
56+
// create the View with the button
57+
// to send notifications
58+
setupView();
59+
}
60+
61+
private void setupNotificationSystem() {
62+
mNotificationManager = getSystemService(NotificationManager.class);
63+
CharSequence channelName = NOTIFICATION_CHANNEL_NAME;
64+
65+
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
66+
mNotificationManager.createNotificationChannel(notificationChannel);
67+
68+
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), NOTIFICATION_CHANNEL_ID)
69+
.setSmallIcon(R.drawable.ic_launcher)
70+
.setContentTitle(NOTIFICATION_TITLE_TEXT)
71+
.setContentText(NOTIFICATION_CONTENT_TEXT)
72+
.setPriority(NotificationCompat.PRIORITY_HIGH);
73+
74+
mNotification = builder.build();
75+
}
76+
77+
private void setupSecondDisplay() {
78+
// Retrieve the reference to the 2nd Display Manager
79+
DLSecondDisplayManager secondDisplayManager = DLSecondDisplayManager.getInstance();
80+
81+
// Check if the 2nd Display is available on the current device
82+
// 2nd Display is only available for Datalogic Memor20
83+
boolean available = secondDisplayManager.isSecondDisplayAvailable();
84+
85+
// if available, 2nd Display can be configured
86+
if (available) {
87+
// if disable, enable 2nd Display to show notifications
88+
boolean enabled = secondDisplayManager.isSecondDisplayEnabled();
89+
if (!enabled) {
90+
boolean result = secondDisplayManager.setSecondDisplayEnabled(true);
91+
if (!result)
92+
Log.d(TAG, "Error occurred enabling 2nd Display");
93+
}
94+
95+
// disable all configured Apps to show notification on 2nd Display
96+
List<String> allowedPackage = secondDisplayManager.getAllowedPackages();
97+
for (String packageName : allowedPackage) {
98+
boolean result = secondDisplayManager.removePackage(packageName);
99+
if (!result)
100+
Log.d(TAG, "Error disabling " + packageName + " to show notifications on 2nd Display");
101+
}
102+
103+
// disable by default Apps installed in the future
104+
boolean newAppEnabledByDefault = secondDisplayManager.getNewAppEnabled();
105+
if (newAppEnabledByDefault) {
106+
// This feature allow to configure the 2nd Display to discard by default
107+
// the notifications coming from Apps will be installed later.
108+
// With the following configuration, when a new App is installed on the device,
109+
// it shall be explicitly configured through "addPackage" to show notifications
110+
// on 2nd Display.
111+
// These operation could take a while, due to the storage of all the
112+
// installed Apps into the DB.
113+
secondDisplayManager.setNewAppEnabled(false);
114+
}
115+
116+
// enable only this App to show notification on 2nd Display
117+
boolean allowed = secondDisplayManager.isPackageAllowed(PACKAGE_NAME);
118+
if (!allowed) {
119+
boolean added = secondDisplayManager.addPackage(PACKAGE_NAME);
120+
if (!added)
121+
Log.d(TAG, "Error occurred allowing " + PACKAGE_NAME + " to show notification on 2nd Display");
122+
}
123+
} else {
124+
Log.d(TAG, "2nd Display is available only on Datlalogic Memor20");
125+
}
126+
}
127+
128+
private void setupView() {
129+
mSend = (Button) findViewById(R.id.send);
130+
mSend.setOnTouchListener(new OnTouchListener() {
131+
132+
@Override
133+
public boolean onTouch(View v, MotionEvent event) {
134+
if (event.getAction() == MotionEvent.ACTION_UP) {
135+
try {
136+
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
137+
mSend.setPressed(false);
138+
} catch (Exception e) {
139+
Log.e(TAG, "Action UP", e);
140+
//showMessage("ERROR! Check logcat");
141+
}
142+
v.performClick();
143+
}
144+
return true;
145+
}
146+
});
147+
}
148+
149+
@Override
150+
protected void onPause() {
151+
super.onPause();
152+
}
153+
154+
@Override
155+
protected void onResume() {
156+
super.onResume();
157+
}
158+
159+
@Override
160+
public boolean onCreateOptionsMenu(Menu menu) {
161+
getMenuInflater().inflate(R.menu.main, menu);
162+
return true;
163+
}
164+
}
328 Bytes
Loading
422 Bytes
Loading
399 Bytes
Loading

0 commit comments

Comments
 (0)