Skip to content

Commit c52e224

Browse files
author
Douglas Nassif Roma Junior
committed
Added image printing sample
1 parent d8dcb53 commit c52e224

File tree

15 files changed

+554
-38
lines changed

15 files changed

+554
-38
lines changed

Sample/libs/print_lib_0.13.jar

45 KB
Binary file not shown.

Sample/libs/zxing.jar

239 KB
Binary file not shown.

Sample/src/main/AndroidManifest.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
99

1010
<application
11+
android:name=".SampleApplication"
1112
android:icon="@mipmap/ic_launcher"
1213
android:label="@string/app_name"
1314
android:theme="@style/AppTheme.NoActionBar">
1415
<activity
1516
android:name=".MainActivity"
16-
android:label="@string/app_name">
17+
android:label="@string/app_name"
18+
android:screenOrientation="portrait">
1719
<intent-filter>
1820
<action android:name="android.intent.action.MAIN" />
1921

@@ -24,8 +26,14 @@
2426
<activity
2527
android:name=".DeviceActivity"
2628
android:label="@string/activity_device"
27-
android:windowSoftInputMode="adjustResize"/>
29+
android:screenOrientation="portrait"
30+
android:windowSoftInputMode="adjustResize" />
2831

32+
<activity
33+
android:name=".BitmapActivity"
34+
android:label="@string/activity_device"
35+
android:screenOrientation="portrait"
36+
android:windowSoftInputMode="adjustResize" />
2937

3038
</application>
3139

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2015 Douglas Nassif Roma Junior
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.github.douglasjunior.bluetoothsample;
26+
27+
import android.graphics.Bitmap;
28+
import android.graphics.BitmapFactory;
29+
import android.os.Bundle;
30+
import android.support.design.widget.FloatingActionButton;
31+
import android.support.v7.app.AppCompatActivity;
32+
import android.support.v7.widget.Toolbar;
33+
import android.view.View;
34+
import android.widget.ImageView;
35+
36+
import com.github.douglasjunior.bluetoothclassiclibrary.BluetoothService;
37+
import com.wpx.util.WPXUtils;
38+
39+
/**
40+
* Created by douglas on 26/05/17.
41+
*/
42+
43+
public class BitmapActivity extends AppCompatActivity implements View.OnClickListener {
44+
45+
private FloatingActionButton mFab;
46+
private ImageView mImgOriginal;
47+
private ImageView mImgBlackWhite;
48+
49+
private BluetoothService mService;
50+
51+
private Bitmap imageBitmap;
52+
53+
@Override
54+
protected void onCreate(Bundle savedInstanceState) {
55+
super.onCreate(savedInstanceState);
56+
57+
setContentView(R.layout.activity_bitmap);
58+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
59+
setSupportActionBar(toolbar);
60+
61+
mFab = (FloatingActionButton) findViewById(R.id.fab);
62+
mFab.setOnClickListener(this);
63+
64+
mService = BluetoothService.getDefaultInstance();
65+
66+
mImgOriginal = (ImageView) findViewById(R.id.img_original);
67+
mImgBlackWhite = (ImageView) findViewById(R.id.img_blackwhite);
68+
69+
new Thread() {
70+
@Override
71+
public void run() {
72+
final Bitmap original = BitmapFactory.decodeResource(getResources(), R.drawable.bmw);
73+
74+
final Bitmap resized = Bitmap.createScaledBitmap(original, 255, 255, false);
75+
76+
final Bitmap editedBrightness = BitmapHelper.changeBitmapContrastBrightness(resized, 1, 50);
77+
78+
resized.recycle();
79+
80+
imageBitmap = editedBrightness;
81+
82+
final Bitmap editedGray = BitmapHelper.changeBitmapBlackWhite(editedBrightness);
83+
84+
runOnUiThread(new Runnable() {
85+
@Override
86+
public void run() {
87+
mImgOriginal.setImageBitmap(original);
88+
mImgBlackWhite.setImageBitmap(editedGray);
89+
}
90+
});
91+
}
92+
}.start();
93+
}
94+
95+
@Override
96+
public void onClick(View v) {
97+
new Thread() {
98+
@Override
99+
public void run() {
100+
try {
101+
byte[] bytes = WPXUtils.decodeBitmap(imageBitmap);
102+
mService.write(bytes);
103+
} catch (Exception e) {
104+
e.printStackTrace();
105+
}
106+
}
107+
}.start();
108+
}
109+
110+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2015 Douglas Nassif Roma Junior
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.github.douglasjunior.bluetoothsample;
26+
27+
import android.graphics.Bitmap;
28+
import android.graphics.Canvas;
29+
import android.graphics.ColorMatrix;
30+
import android.graphics.ColorMatrixColorFilter;
31+
import android.graphics.Paint;
32+
33+
/**
34+
* Created by douglas on 30/05/17.
35+
*/
36+
public final class BitmapHelper {
37+
38+
private BitmapHelper(){}
39+
40+
/**
41+
* From https://stackoverflow.com/a/17887577/2826279
42+
*
43+
* @param bmp input bitmap
44+
* @param contrast 0..10 1 is default
45+
* @param brightness -255..255 0 is default
46+
* @return new bitmap
47+
*/
48+
public static Bitmap changeBitmapContrastBrightness(Bitmap bmp, float contrast, float brightness) {
49+
ColorMatrix cm = new ColorMatrix(new float[]
50+
{
51+
contrast, 0, 0, 0, brightness,
52+
0, contrast, 0, 0, brightness,
53+
0, 0, contrast, 0, brightness,
54+
0, 0, 0, 1, 0
55+
});
56+
Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
57+
58+
Canvas canvas = new Canvas(ret);
59+
60+
Paint paint = new Paint();
61+
paint.setColorFilter(new ColorMatrixColorFilter(cm));
62+
canvas.drawBitmap(bmp, 0, 0, paint);
63+
64+
return ret;
65+
}
66+
67+
public static Bitmap changeBitmapBlackWhite(Bitmap bmp) {
68+
ColorMatrix cm = new ColorMatrix(new float[]
69+
{
70+
1.5f, 1.5f, 1.5f, 0, 0,
71+
1.5f, 1.5f, 1.5f, 0, 0,
72+
1.5f, 1.5f, 1.5f, 0, 0,
73+
0, 0, 0, 1, 0
74+
});
75+
cm.setSaturation(0);
76+
Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
77+
78+
Canvas canvas = new Canvas(ret);
79+
80+
Paint paint = new Paint();
81+
paint.setColorFilter(new ColorMatrixColorFilter(cm));
82+
canvas.drawBitmap(bmp, 0, 0, paint);
83+
84+
return ret;
85+
}
86+
87+
}

Sample/src/main/java/com/github/douglasjunior/bluetoothsample/DeviceActivity.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2015 Douglas Nassif Roma Junior
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package com.github.douglasjunior.bluetoothsample;
226

327
import android.os.Bundle;
@@ -13,7 +37,7 @@
1337
import com.github.douglasjunior.bluetoothclassiclibrary.BluetoothWriter;
1438

1539
/**
16-
* Created by dougl on 10/04/2017.
40+
* Created by douglas on 10/04/2017.
1741
*/
1842

1943
public class DeviceActivity extends AppCompatActivity implements BluetoothService.OnBluetoothEventCallback, View.OnClickListener {

Sample/src/main/java/com/github/douglasjunior/bluetoothsample/DeviceItemAdapter.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2015 Douglas Nassif Roma Junior
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package com.github.douglasjunior.bluetoothsample;
226

327
import android.bluetooth.BluetoothDevice;
@@ -17,7 +41,7 @@
1741
import java.util.Set;
1842

1943
/**
20-
* Created by dougl on 10/04/2017.
44+
* Created by douglas on 10/04/2017.
2145
*/
2246

2347
public class DeviceItemAdapter extends RecyclerView.Adapter<DeviceItemAdapter.ViewHolder> {

0 commit comments

Comments
 (0)