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
14 | * all 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
22 | * THE SOFTWARE.
23 | */
24 | package com.loopedlabs.escposprintservicedemo;
25 |
26 | import android.Manifest;
27 | import android.app.Activity;
28 | import android.content.DialogInterface;
29 | import android.content.Intent;
30 | import android.content.pm.PackageManager;
31 | import android.content.pm.ResolveInfo;
32 | import android.net.Uri;
33 | import android.os.Build;
34 | import android.os.Bundle;
35 | import android.view.Menu;
36 | import android.view.MenuItem;
37 | import android.view.View;
38 | import android.view.inputmethod.InputMethodManager;
39 | import android.webkit.URLUtil;
40 | import android.widget.AdapterView;
41 | import android.widget.EditText;
42 | import android.widget.Spinner;
43 | import android.widget.TextView;
44 |
45 | import com.loopedlabs.selector.FileOperation;
46 | import com.loopedlabs.selector.FileSelector;
47 | import com.loopedlabs.selector.OnHandleFileListener;
48 | import com.loopedlabs.util.debug.DebugLog;
49 |
50 | import java.io.File;
51 | import java.io.IOException;
52 | import java.io.RandomAccessFile;
53 | import java.util.List;
54 |
55 | import androidx.appcompat.app.AlertDialog;
56 | import androidx.appcompat.app.AppCompatActivity;
57 | import androidx.core.app.ActivityCompat;
58 |
59 |
60 | public class DemoMain extends AppCompatActivity {
61 | private static final String ESC_POS_PRINT_INTENT_ACTION = "org.escpos.intent.action.PRINT";
62 | private static final String ESC_POS_BLUETOOTH_PRINT_SERVICE = "com.loopedlabs.escposprintservice";
63 | private static final String ESC_POS_WIFI_PRINT_SERVICE = "com.loopedlabs.netprintservice";
64 | private static final String ESC_POS_USB_PRINT_SERVICE = "com.loopedlabs.usbprintservice";
65 | private int iSelPrintService = 0;
66 | private int iSelPrintUrlType = 0;
67 | private int iSelPrintFileType = 0;
68 | private String sAppPackage = "com.loopedlabs.escposprintservice";
69 | private Spinner spPrintService;
70 | private String sPrintUrl = "";
71 | private String sPrintFile = "";
72 | private String sDataType = "";
73 | private String sFileType = "";
74 | private TextView tvPrintFile;
75 |
76 | @Override
77 | protected void onCreate(Bundle savedInstanceState) {
78 | super.onCreate(savedInstanceState);
79 | setContentView(R.layout.demo_main);
80 |
81 | DebugLog.setDebugMode(BuildConfig.DEBUG);
82 | DebugLog.logTrace();
83 |
84 | initControls();
85 |
86 | isStoragePermissionGranted();
87 | }
88 |
89 | private void initControls() {
90 | DebugLog.logTrace();
91 | iSelPrintService = 0;
92 | sAppPackage = ESC_POS_BLUETOOTH_PRINT_SERVICE;
93 | spPrintService = findViewById(R.id.spPrintService);
94 | spPrintService.setTag("a");
95 | spPrintService.setSelection(iSelPrintService, false);
96 | spPrintService.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
97 | @Override
98 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
99 | if (!spPrintService.getTag().equals("a")) {
100 | iSelPrintService = position;
101 | switch (iSelPrintService) {
102 | case 0:
103 | sAppPackage = ESC_POS_BLUETOOTH_PRINT_SERVICE;
104 | break;
105 | case 1:
106 | sAppPackage = ESC_POS_WIFI_PRINT_SERVICE;
107 | break;
108 | case 2:
109 | sAppPackage = ESC_POS_USB_PRINT_SERVICE;
110 | break;
111 | }
112 | alert("Selected Print Service : " + spPrintService.getItemAtPosition(position).toString());
113 | }
114 | else {
115 | spPrintService.setTag("");
116 | }
117 | }
118 |
119 | @Override
120 | public void onNothingSelected(AdapterView> parent) {
121 | }
122 | });
123 |
124 | findViewById(R.id.btnPrintConfig).setOnClickListener(new View.OnClickListener() {
125 | @Override
126 | public void onClick(View v) {
127 | PackageManager manager = getPackageManager();
128 | try {
129 | Intent i = manager.getLaunchIntentForPackage(sAppPackage);
130 | if (i != null) {
131 | i.addCategory(Intent.CATEGORY_LAUNCHER);
132 | startActivity(i);
133 | }
134 | else {
135 | requestInstallPrintService();
136 | }
137 | }
138 | catch (Exception ignored) {
139 | requestInstallPrintService();
140 | }
141 | }
142 | });
143 |
144 | final EditText etPrintUrl = findViewById(R.id.etPrintUrl);
145 |
146 | final Spinner spPrintURLType = findViewById(R.id.spPrintURLType);
147 | iSelPrintUrlType = 0;
148 | sPrintUrl = "https://loopedlabs.com/web-print/loopedlabs.png";
149 | sDataType = "PNG_URL";
150 | spPrintURLType.setSelection(iSelPrintUrlType, false);
151 | spPrintURLType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
152 | @Override
153 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
154 | iSelPrintUrlType = position;
155 | sPrintUrl = etPrintUrl.getText().toString();
156 | if (sPrintUrl.isEmpty() || sPrintUrl.contains("loopedlabs")) {
157 | switch (iSelPrintUrlType) {
158 | case 0:
159 | sPrintUrl = "https://loopedlabs.com/web-print/loopedlabs.png";
160 | sDataType = "PNG_URL";
161 | break;
162 | case 1:
163 | sPrintUrl = "https://loopedlabs.com/web-print/loopedlabs.jpg";
164 | sDataType = "JPG_URL";
165 | break;
166 | case 2:
167 | sPrintUrl = "https://loopedlabs.com/web-print/sample.pdf";
168 | sDataType = "PDF_URL";
169 | break;
170 | case 3:
171 | sPrintUrl = "https://loopedlabs.com/web-print/bill.html";
172 | sDataType = "HTML_URL";
173 | break;
174 | }
175 | etPrintUrl.setText(sPrintUrl);
176 | }
177 | }
178 |
179 | @Override
180 | public void onNothingSelected(AdapterView> parent) {
181 | }
182 | });
183 | findViewById(R.id.btnPrintUrl).setOnClickListener(new View.OnClickListener() {
184 | @Override
185 | public void onClick(View v) {
186 | sPrintUrl = etPrintUrl.getText().toString();
187 | if (!URLUtil.isNetworkUrl(sPrintUrl)) {
188 | etPrintUrl.requestFocus();
189 | alert("Please enter a valid absolute URL");
190 | }
191 | else {
192 | hideKeyboard(DemoMain.this);
193 | Intent printIntent = new Intent(ESC_POS_PRINT_INTENT_ACTION);
194 | printIntent.setPackage(sAppPackage);
195 | printIntent.putExtra("DATA_TYPE", sDataType);
196 | printIntent.putExtra(Intent.EXTRA_TEXT, sPrintUrl);
197 | DebugLog.logTrace("Print Intent");
198 | DebugLog.logTrace("Package : " + sAppPackage);
199 | DebugLog.logTrace("Data Type : " + sDataType);
200 | DebugLog.logTrace("Print Url : " + sPrintUrl);
201 | startActivity(printIntent);
202 | }
203 | }
204 | });
205 |
206 | tvPrintFile = findViewById(R.id.tvPrintFile);
207 | final Spinner spPrintFileType = findViewById(R.id.spPrintFileType);
208 | iSelPrintFileType = 0;
209 | sPrintFile = "";
210 | sFileType = "IMAGE_PNG";
211 | spPrintFileType.setSelection(iSelPrintFileType, false);
212 | spPrintFileType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
213 | @Override
214 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
215 | iSelPrintFileType = position;
216 | sPrintFile = "";
217 | switch (iSelPrintFileType) {
218 | case 0:
219 | sFileType = "IMAGE_PNG";
220 | break;
221 | case 1:
222 | sFileType = "IMAGE_JPG";
223 | break;
224 | case 2:
225 | sFileType = "PDF";
226 | break;
227 | case 3:
228 | sFileType = "HTML";
229 | break;
230 | }
231 | tvPrintFile.setText(sPrintFile);
232 | }
233 |
234 | @Override
235 | public void onNothingSelected(AdapterView> parent) {
236 | }
237 | });
238 |
239 | findViewById(R.id.btnBrowse).setOnClickListener(new View.OnClickListener() {
240 | @Override
241 | public void onClick(View view) {
242 | fileSelector();
243 | }
244 | });
245 |
246 | findViewById(R.id.tvLoopedLabs).setOnClickListener(new View.OnClickListener() {
247 | @Override
248 | public void onClick(View v) {
249 | String url = "https://loopedlabs.com";
250 | Intent i = new Intent(Intent.ACTION_VIEW);
251 | i.setData(Uri.parse(url));
252 | startActivity(i);
253 | }
254 | });
255 | }
256 |
257 | private void isStoragePermissionGranted() {
258 | if (Build.VERSION.SDK_INT >= 23) {
259 | if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
260 | == PackageManager.PERMISSION_GRANTED) {
261 | DebugLog.logTrace("Permission is granted");
262 | }
263 | else {
264 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
265 | }
266 | }
267 | else { //permission is automatically granted on sdk<23 upon installation
268 | DebugLog.logTrace("Permission is granted by default");
269 | }
270 | }
271 |
272 | private FileSelector mFileSel;
273 |
274 | private void fileSelector() {
275 | String[] fileHtmlFilter = {".html", ".htm"};
276 | String[] fileJpgFilter = {".jpg", ".jpeg"};
277 | String[] filePngFilter = {".png"};
278 | String[] filePdfFilter = {".pdf"};
279 | switch (sFileType) {
280 | case "IMAGE_PNG":
281 | mFileSel = new FileSelector(DemoMain.this, FileOperation.LOAD, mFileListener, filePngFilter);
282 | break;
283 | case "IMAGE_JPG":
284 | mFileSel = new FileSelector(DemoMain.this, FileOperation.LOAD, mFileListener, fileJpgFilter);
285 | break;
286 | case "PDF":
287 | mFileSel = new FileSelector(DemoMain.this, FileOperation.LOAD, mFileListener, filePdfFilter);
288 | break;
289 | case "HTML":
290 | mFileSel = new FileSelector(DemoMain.this, FileOperation.LOAD, mFileListener, fileHtmlFilter);
291 | break;
292 | }
293 | mFileSel.show();
294 | }
295 |
296 | private OnHandleFileListener mFileListener = new OnHandleFileListener() {
297 | @Override
298 | public void handleFile(final String selFileName) {
299 | DebugLog.logTrace("filePath " + selFileName);
300 | mFileSel.dismiss();
301 | tvPrintFile.setText(selFileName);
302 | if (isEscPosPrintServiceAvailable()) {
303 | File f = new File(selFileName);
304 | if (f.canRead()) {
305 | byte[] bytes = null;
306 | try {
307 | bytes = readFileAsByteArray(f);
308 | }
309 | catch (IOException e) {
310 | e.printStackTrace();
311 | alert("Unable to read file contents");
312 | }
313 |
314 | Intent i = new Intent();
315 | i.setAction(ESC_POS_PRINT_INTENT_ACTION);
316 | i.setPackage(sAppPackage);
317 | i.putExtra("PRINT_DATA", bytes);
318 | i.putExtra("DATA_TYPE", sFileType);
319 | DebugLog.logTrace("Print Intent");
320 | DebugLog.logTrace("Package : " + sAppPackage);
321 | DebugLog.logTrace("Data Type : " + sFileType);
322 | DebugLog.logTrace("File Name : " + selFileName);
323 | startActivity(i);
324 | }
325 | else {
326 | alert("Unable to read file");
327 | }
328 | }
329 | else {
330 | requestInstallPrintService();
331 | }
332 | }
333 | };
334 |
335 | @Override
336 | public boolean onCreateOptionsMenu(Menu menu) {
337 | getMenuInflater().inflate(R.menu.demo_main, menu);
338 | return true;
339 | }
340 |
341 | @Override
342 | public boolean onOptionsItemSelected(MenuItem item) {
343 | int id = item.getItemId();
344 |
345 | if (id == R.id.action_about) {
346 | alert("App Version : " + BuildConfig.VERSION_CODE + "\nDeveloped By : Looped Labs Pvt. Ltd.\nhttps://loopedlabs.com");
347 | return true;
348 | }
349 | return super.onOptionsItemSelected(item);
350 | }
351 |
352 | private boolean isEscPosPrintServiceAvailable() {
353 | DebugLog.logTrace();
354 | final PackageManager packageManager = getPackageManager();
355 | final Intent intent = new Intent(ESC_POS_PRINT_INTENT_ACTION);
356 | intent.setPackage(sAppPackage);
357 | List resolveInfo =
358 | packageManager.queryIntentActivities(intent,
359 | PackageManager.MATCH_DEFAULT_ONLY);
360 | return resolveInfo.size() > 0;
361 | }
362 |
363 | private static void hideKeyboard(Activity activity) {
364 | DebugLog.logTrace();
365 | InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
366 | if (imm != null) {
367 | View view = activity.getCurrentFocus();
368 | if (view == null) {
369 | view = new View(activity);
370 | }
371 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
372 | }
373 | }
374 |
375 | private void requestInstallPrintService() {
376 | DebugLog.logTrace();
377 | AlertDialog.Builder aboutBuilder = new AlertDialog.Builder(this);
378 | aboutBuilder.setTitle(R.string.app_name);
379 | aboutBuilder
380 | .setMessage(spPrintService.getItemAtPosition(iSelPrintService).toString() + " not installed, do you want to install the print service from Google Play Store ?")
381 | .setCancelable(true)
382 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
383 | public void onClick(DialogInterface dialog, int id) {
384 | dialog.cancel();
385 | Intent intentPlayStore = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + sAppPackage));
386 | startActivity(intentPlayStore);
387 | }
388 | })
389 | .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
390 | public void onClick(DialogInterface dialog, int id) {
391 | dialog.cancel();
392 | }
393 | });
394 | AlertDialog aboutDialog = aboutBuilder.create();
395 | aboutDialog.show();
396 | }
397 |
398 | private void alert(String sMsg) {
399 | DebugLog.logTrace();
400 | AlertDialog.Builder aboutBuilder = new AlertDialog.Builder(this);
401 | aboutBuilder.setTitle(R.string.app_name);
402 | aboutBuilder
403 | .setMessage(sMsg)
404 | .setCancelable(true)
405 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
406 | public void onClick(DialogInterface dialog, int id) {
407 | dialog.cancel();
408 | }
409 | });
410 | AlertDialog aboutDialog = aboutBuilder.create();
411 | aboutDialog.show();
412 | }
413 |
414 | private static byte[] readFileAsByteArray(File f) throws IOException {
415 | RandomAccessFile raf = new RandomAccessFile(f, "r");
416 | byte[] bytes = new byte[(int) raf.length()];
417 | raf.readFully(bytes);
418 | raf.close();
419 | return bytes;
420 | }
421 |
422 |
423 | }
424 |
--------------------------------------------------------------------------------
/app/src/main/looped_labs-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/looped_labs-web.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/big_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/drawable-nodpi/big_image.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/ll.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/drawable-nodpi/ll.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/demologo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/drawable/demologo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/no-dpi/store_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/drawable/no-dpi/store_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/demo_main.xml:
--------------------------------------------------------------------------------
1 |
24 |
33 |
34 |
44 |
45 |
53 |
54 |
60 |
61 |
68 |
69 |
75 |
76 |
87 |
88 |
95 |
96 |
101 |
102 |
111 |
112 |
119 |
120 |
121 |
127 |
128 |
129 |
139 |
140 |
147 |
148 |
153 |
154 |
163 |
164 |
171 |
172 |
173 |
179 |
180 |
181 |
193 |
194 |
195 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/demo_main.xml:
--------------------------------------------------------------------------------
1 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/looped_labs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-hdpi/looped_labs.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/looped_labs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-mdpi/looped_labs.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/looped_labs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-xhdpi/looped_labs.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/looped_labs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-xxhdpi/looped_labs.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/looped_labs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/app/src/main/res/mipmap-xxxhdpi/looped_labs.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 |
28 | 64dp
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ESC POS Bluetooth Print Service
5 | ESC POS Network/WIFI Print Service
6 |
7 |
8 |
9 | PNG Image URL
10 | JPG Image URL
11 | PDF URL
12 | HTML URL
13 |
14 |
15 | PNG Image File
16 | JPG Image File
17 | PDF File
18 | HTML File
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303f9f
5 | #FF4081
6 | #ff6c00
7 | #ffffff
8 | #d0dbcc
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 |
26 | 16dp
27 | 16dp
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 | ESC POS Print Service Demo
26 |
27 | Key in your commands to send to printer.
28 | About
29 | Looped Labs
30 | Select Print Service
31 | Open Printer Configuration
32 | Image / PDF / HTML URL
33 | Print URL
34 | https://loopedlabs.com/web-print/loopedlabs.png
35 | PDF URL
36 | https://loopedlabs/web-print/sample.pdf
37 | PDF / Image / HTML File
38 | Select a Image / PDF / HTML File
39 | Browse
40 | Print File
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:4.0.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
--------------------------------------------------------------------------------
/debug_log/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/debug_log/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 | useLibrary 'org.apache.http.legacy'
6 | defaultConfig {
7 | minSdkVersion 19
8 | targetSdkVersion 28
9 | versionCode 100
10 | versionName "1.0.0"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled true
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | debug {
18 | debuggable true
19 | jniDebuggable false
20 | renderscriptDebuggable false
21 | minifyEnabled false
22 | zipAlignEnabled true
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(include: ['*.jar'], dir: 'libs')
29 | implementation 'androidx.appcompat:appcompat:1.0.0'
30 | implementation 'com.google.code.gson:gson:2.8.5'
31 | implementation files('libs/android-async-http-1.4.8.jar')
32 | }
--------------------------------------------------------------------------------
/debug_log/debug_log.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | generateDebugSources
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/debug_log/libs/android-async-http-1.4.8.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/debug_log/libs/android-async-http-1.4.8.jar
--------------------------------------------------------------------------------
/debug_log/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/debug_log/src/main/java/com/loopedlabs/beans/DbgLog.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.beans;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.annotations.SerializedName;
5 | import com.loopedlabs.util.debug.DebugLog;
6 |
7 | public class DbgLog {
8 | @SerializedName("log_data")
9 | private String log_data;
10 |
11 | @SerializedName("log_ts")
12 | private String log_ts;
13 |
14 | public String getLog_data() {
15 | return log_data;
16 | }
17 |
18 | public void setLog_data(String log_data) {
19 | this.log_data = log_data;
20 | }
21 |
22 | public String getLog_ts() {
23 | return log_ts;
24 | }
25 |
26 | public void setLog_ts(String log_ts) {
27 | this.log_ts = log_ts;
28 | }
29 |
30 | public String toString() {
31 | return new Gson().toJson(this);
32 | }
33 |
34 | public void fromString(String sJson) {
35 | DebugLog.logTrace("log " + sJson);
36 | Gson g = new Gson();
37 | DbgLog a = g.fromJson(sJson,DbgLog.class);
38 | this.log_data = a.log_data;
39 | this.log_ts = a.log_ts;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/debug_log/src/main/java/com/loopedlabs/db/DebugLogDb.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.db;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 | import android.text.TextUtils;
7 | import android.util.Log;
8 |
9 | import com.loopedlabs.beans.DbgLog;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class DebugLogDb {
15 | private static final String TAG = "DebugLogDb";
16 |
17 | private static final String TABLE_NAME = "debug_logs";
18 | private static final String COLUMN_ID = "_id";
19 | private static final String COLUMN_LOG_DATA = "log_data";
20 | private static final String COLUMN_LOG_TS = "log_ts";
21 | private static final String ROWS = " 500";
22 |
23 | private static final String DATABASE_CREATE = "CREATE TABLE IF NOT EXISTS "
24 | + TABLE_NAME
25 | + " ("
26 | + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
27 | + COLUMN_LOG_DATA + " TEXT, "
28 | + COLUMN_LOG_TS + " DATETIME DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW', 'localtime'))"
29 | + ");";
30 |
31 | public static void onCreate (SQLiteDatabase db) {
32 | if (db == null) {
33 | return;
34 | }
35 |
36 | try {
37 | db.execSQL(DATABASE_CREATE);
38 | } catch (Exception e) {
39 | e.printStackTrace();
40 | Log.e(TAG, "DebugLogTable: Exception occurred while onCreate: " + e);
41 | }
42 | }
43 |
44 | public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
45 | if (db == null) {
46 | return;
47 | }
48 |
49 | try {
50 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
51 | onCreate(db);
52 |
53 | Log.i(TAG, "DebugLogTable onUpgrade called. Executing drop_table query to clear old logs.");
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | Log.e(TAG, "DebugLogTable: Exception occurred while onUpgrade: " + e);
57 | }
58 | }
59 |
60 | public static void addLog(SQLiteDatabase db, String sLog) {
61 | if (db == null || TextUtils.isEmpty(sLog)) {
62 | return;
63 | }
64 |
65 | ContentValues contentValues = new ContentValues();
66 | contentValues.put(COLUMN_LOG_DATA, sLog);
67 |
68 | try {
69 | db.insert(TABLE_NAME, null, contentValues);
70 | } catch (Exception e) {
71 | e.printStackTrace();
72 | Log.e(TAG, "DebugLogTable: Exception occurred while addLog: " + e);
73 | }
74 | }
75 |
76 | public static List listLogs(SQLiteDatabase db) {
77 | List dbgLogs = new ArrayList<>();
78 | if (db == null) {
79 | return dbgLogs;
80 | }
81 |
82 | Cursor c = db.rawQuery(
83 | "SELECT " + COLUMN_LOG_DATA + ", " + COLUMN_LOG_TS + " FROM " + TABLE_NAME + " ORDER BY " + COLUMN_ID + " LIMIT "+ ROWS,null);
84 | while (c.moveToNext()) {
85 | DbgLog dbgLog = new DbgLog();
86 | dbgLog.setLog_data(c.getString(c.getColumnIndex(COLUMN_LOG_DATA)));
87 | dbgLog.setLog_ts(c.getString(c.getColumnIndex(COLUMN_LOG_TS)));
88 | dbgLogs.add(dbgLog);
89 | }
90 | c.close();
91 |
92 | return dbgLogs;
93 | }
94 |
95 | public static void deleteAllLogs(SQLiteDatabase db) {
96 | if (db == null) {
97 | return;
98 | }
99 |
100 | try {
101 | db.delete(TABLE_NAME, null, null);
102 | db.delete("sqlite_sequence","name = '" + TABLE_NAME +"'",null);
103 | } catch (Exception e) {
104 | e.printStackTrace();
105 | Log.e(TAG, "DebugLogTable: Exception occurred while deleteAllLogs: " + e);
106 | }
107 | }
108 |
109 | public static void clearOldLogs(SQLiteDatabase db) {
110 | if (db == null) {
111 | return;
112 | }
113 |
114 | try {
115 | db.delete(TABLE_NAME, COLUMN_LOG_TS + " <= datetime('now', 'localtime', '-7 day')", null);
116 | db.delete("sqlite_sequence","name = '" + TABLE_NAME +"'",null);
117 | } catch (Exception e) {
118 | e.printStackTrace();
119 | Log.e(TAG, "DebugLogTable: Exception occurred while clearOldLogs: " + e);
120 | }
121 | }
122 |
123 | public static void clearLogs(SQLiteDatabase db, String sLogTs) {
124 | if (db == null && sLogTs.length() != 23) {
125 | return;
126 | }
127 |
128 | try {
129 | db.delete(TABLE_NAME, COLUMN_LOG_TS + " <= ?", new String[]{sLogTs});
130 | db.delete("sqlite_sequence","name = '" + TABLE_NAME +"'",null);
131 | } catch (Exception e) {
132 | e.printStackTrace();
133 | Log.e(TAG, "DebugLogTable: Exception occurred while clearOldLogs: " + e);
134 | }
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/debug_log/src/main/java/com/loopedlabs/db/DebugLogDbHelper.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.db;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | public class DebugLogDbHelper extends SQLiteOpenHelper {
8 |
9 | private static final String TAG = "DebugLogDbHelper";
10 | private static final String DATABASE_NAME = "debug_logs.db";
11 | private static final int DATABASE_VERSION = 1;
12 |
13 | private static SQLiteDatabase database;
14 |
15 | public static SQLiteDatabase getInstance(Context context) {
16 | if (database == null) {
17 | synchronized (DebugLogDbHelper.class) {
18 | new DebugLogDbHelper(context);
19 | }
20 | }
21 | return database;
22 | }
23 |
24 | private DebugLogDbHelper(Context context) {
25 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
26 | this.initializeDatabase();
27 | }
28 |
29 | private void initializeDatabase() {
30 | if (database == null)
31 | database = this.getWritableDatabase();
32 | }
33 |
34 | @Override
35 | public void onCreate(SQLiteDatabase db) {
36 | DebugLogDb.onCreate(db);
37 | }
38 |
39 | @Override
40 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
41 | DebugLogDb.onUpgrade(db, oldVersion, newVersion);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/debug_log/src/main/java/com/loopedlabs/net/DebugLogRestClient.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.net;
2 |
3 | import android.util.Log;
4 |
5 | import com.google.gson.Gson;
6 | import com.loopedlabs.beans.DbgLog;
7 | import com.loopedlabs.util.debug.DebugLog;
8 | import com.loopj.android.http.AsyncHttpClient;
9 | import com.loopj.android.http.JsonHttpResponseHandler;
10 | import com.loopj.android.http.RequestParams;
11 |
12 | import org.apache.http.Header;
13 | import org.json.JSONException;
14 | import org.json.JSONObject;
15 |
16 | import java.util.List;
17 |
18 | public class DebugLogRestClient {
19 | private static final String BASE_URL = "https://api.mobills.in/rpos/";
20 | private static boolean bPushing = false;
21 | private static AsyncHttpClient client = new AsyncHttpClient();
22 |
23 | public static void pushLogs(String app_id, String device_id, List dbgLogs) {
24 | if (dbgLogs.size() <= 0 || bPushing) {
25 | return;
26 | }
27 | bPushing = true;
28 | Log.d("DebugLogRestClient","Triggering Push Logs");
29 | client.post(getAbsoluteUrl("log-log"), makeParams(app_id, device_id, dbgLogs), new JsonHttpResponseHandler() {
30 | @Override
31 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
32 | bPushing = false;
33 | try {
34 | Log.d("DebugLogRestClient",response.getString("last_sync_ts"));
35 | DebugLog.clearLogs(response.getString("last_sync_ts"));
36 | }
37 | catch (JSONException e) {
38 | e.printStackTrace();
39 | }
40 | }
41 |
42 | @Override
43 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
44 | bPushing = false;
45 | super.onFailure(statusCode, headers, responseString, throwable);
46 | Log.d("DebugLogRestClient","Network Error : " + responseString);
47 | }
48 | });
49 | }
50 |
51 | private static RequestParams makeParams(String app_id, String device_id, List dbgLogs) {
52 | RequestParams params = new RequestParams();
53 | params.put("app_id", app_id);
54 | params.put("device_id", device_id);
55 | params.put("log", new Gson().toJson(dbgLogs));
56 | return params;
57 | }
58 |
59 | private static String getAbsoluteUrl(String relativeUrl) {
60 | return BASE_URL + relativeUrl;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/debug_log/src/main/java/com/loopedlabs/net/NetUtils.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.net;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 | import android.util.Log;
7 |
8 | public class NetUtils {
9 | public static boolean isNetConnected(Context context) {
10 | ConnectivityManager cm =
11 | (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
12 |
13 | NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
14 | Log.d("NetUtils", (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) ? "Device Online" : "Device Offline");
15 | return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/debug_log/src/main/java/com/loopedlabs/util/debug/DebugLog.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.util.debug;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 |
8 | import com.loopedlabs.db.DebugLogDb;
9 | import com.loopedlabs.db.DebugLogDbHelper;
10 | import com.loopedlabs.net.DebugLogRestClient;
11 | import com.loopedlabs.net.NetUtils;
12 |
13 | import org.json.JSONException;
14 | import org.json.JSONObject;
15 |
16 | import java.util.Set;
17 |
18 | public class DebugLog {
19 | private static final String TAG = "DebugLog";
20 | private static boolean debugMode = false;
21 | private static SQLiteDatabase logDb = null;
22 | private static String sAppId = "";
23 | private static String sDeviceId = "";
24 |
25 | public static void initialize(Context context, String sAppId, String sDeviceId) {
26 | if (context == null) {
27 | Log.e(TAG, "DebugLog isn't initialized: Context couldn't be null");
28 | return;
29 | }
30 | DebugLog.sAppId = sAppId;
31 | DebugLog.sDeviceId = sDeviceId;
32 |
33 | Context applicationContext = context.getApplicationContext();
34 |
35 | synchronized (DebugLog.class) {
36 | if (logDb == null && applicationContext != null) {
37 | logDb = DebugLogDbHelper.getInstance(applicationContext);
38 | }
39 | DebugLogDb.clearOldLogs(logDb);
40 | if (NetUtils.isNetConnected(context)) {
41 | pushLogs();
42 | }
43 | }
44 | }
45 |
46 | public static void pushLogs() {
47 | if (logDb == null) {
48 | return;
49 | }
50 | DebugLogRestClient.pushLogs(DebugLog.sAppId, DebugLog.sDeviceId, DebugLogDb.listLogs(logDb));
51 | }
52 |
53 | public static void clearLogs(String sLogTs) {
54 | DebugLogDb.clearLogs(logDb,sLogTs);
55 | }
56 |
57 | public static void logTrace() {
58 | final StackTraceElement[] ste = Thread.currentThread()
59 | .getStackTrace();
60 | if (debugMode) {
61 | Log.d(ste[3].getClassName(), ste[3].getMethodName());
62 | }
63 | DebugLogDb.addLog(logDb, ste[3].getClassName()+ " --- " + ste[3].getMethodName());
64 | }
65 |
66 | public static void logTrace(String s) {
67 | final StackTraceElement[] ste = Thread.currentThread()
68 | .getStackTrace();
69 | if (debugMode) {
70 | Log.d(ste[3].getClassName(), ste[3].getMethodName() + " --- " + s);
71 | }
72 | DebugLogDb.addLog(logDb, ste[3].getClassName()+ " --- " + ste[3].getMethodName() + " --- " + s);
73 | }
74 |
75 | public static void logTrace(int s) {
76 | logTrace(String.valueOf(s));
77 | }
78 |
79 | public static void logTrace(double s) {
80 | logTrace(String.valueOf(s));
81 | }
82 |
83 | public static void logTrace(boolean s) {
84 | logTrace(String.valueOf(s));
85 | }
86 |
87 | public static void logTrace(Bundle b) {
88 | if (debugMode) {
89 | final StackTraceElement[] ste = Thread.currentThread()
90 | .getStackTrace();
91 | JSONObject json = new JSONObject();
92 | Set keys = b.keySet();
93 | for (String key : keys) {
94 | try {
95 | json.put(key, JSONObject.wrap(b.get(key)));
96 | } catch(JSONException e) {
97 | logException(e);
98 | }
99 | }
100 | Log.d(ste[3].getClassName(), ste[3].getMethodName() + " --- " + json.toString());
101 | }
102 | }
103 |
104 | public static void logException(Exception e) {
105 | final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
106 | Log.d(ste[3].getClassName(),
107 | ste[3].getMethodName() + " --- " + e.toString());
108 | Log.e(ste[3].getMethodName() + " --- ", e.toString(), e);
109 | }
110 |
111 | public static void logException(String msg, Exception e) {
112 | final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
113 | Log.d(ste[3].getClassName(),
114 | ste[3].getMethodName() + " --- " + e.toString());
115 | Log.e(ste[3].getMethodName() + " --- ", msg, e);
116 | }
117 |
118 | private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
119 |
120 | public static String bytesToHex(byte[] bytes) {
121 | char[] hexChars = new char[bytes.length * 3];
122 | for (int j = 0; j < bytes.length; j++) {
123 | int v = bytes[j] & 0xFF;
124 | hexChars[j * 3] = hexArray[v >>> 4];
125 | hexChars[j * 3 + 1] = hexArray[v & 0x0F];
126 | hexChars[j * 3 + 2] = ' ';
127 | }
128 | return new String(hexChars);
129 | }
130 |
131 | public static String bytesToHex(byte b) {
132 | char[] hexChars = new char[3];
133 | int v = b & 0xFF;
134 | hexChars[0] = hexArray[v >>> 4];
135 | hexChars[1] = hexArray[v & 0x0F];
136 | hexChars[2] = ' ';
137 | return new String(hexChars);
138 | }
139 |
140 | public static boolean isDebugMode() {
141 | return debugMode;
142 | }
143 |
144 | public static void setDebugMode(boolean debugMode) {
145 | DebugLog.debugMode = debugMode;
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/debug_log/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | dubuglog
3 |
4 |
--------------------------------------------------------------------------------
/file_selector/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/file_selector/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | minSdkVersion 19
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 |
13 | buildTypes {
14 | release {
15 | minifyEnabled true
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 |
25 | implementation 'androidx.appcompat:appcompat:1.0.0'
26 | implementation project(path: ':debug_log')
27 | }
28 |
--------------------------------------------------------------------------------
/file_selector/file_selector.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | generateDebugSources
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/file_selector/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/file_selector/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/file_selector/src/main/icon_folder-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/icon_folder-web.png
--------------------------------------------------------------------------------
/file_selector/src/main/icon_html_file-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/icon_html_file-web.png
--------------------------------------------------------------------------------
/file_selector/src/main/icon_jpg_file-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/icon_jpg_file-web.png
--------------------------------------------------------------------------------
/file_selector/src/main/icon_pdf_file-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/icon_pdf_file-web.png
--------------------------------------------------------------------------------
/file_selector/src/main/icon_png_file-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/icon_png_file-web.png
--------------------------------------------------------------------------------
/file_selector/src/main/icon_unknown_file-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/icon_unknown_file-web.png
--------------------------------------------------------------------------------
/file_selector/src/main/icon_up_folder-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/icon_up_folder-web.png
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/FileData.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | /**
4 | * This class contais information about the file name and type
5 | */
6 | public class FileData implements Comparable {
7 |
8 | /**
9 | * Constant that specifies the object is a reference to the parent
10 | */
11 | public static final int UP_FOLDER = 0;
12 | /**
13 | * Constant that specifies the object is a folder
14 | */
15 | public static final int DIRECTORY = 1;
16 | /**
17 | * Constant that specifies the object is a file
18 | */
19 | public static final int FILE = 2;
20 | public static final int CSV_FILE = 3;
21 | public static final int ZIP_FILE = 4;
22 | public static final int PDF_FILE = 5;
23 | public static final int HTML_FILE = 6;
24 | public static final int PNG_FILE = 7;
25 | public static final int JPG_FILE = 8;
26 |
27 | /**
28 | * The file's name
29 | */
30 | final private String mFileName;
31 |
32 | /**
33 | * Defines the type of file. Can be one of UP_FOLDER, DIRECTORY or FILE
34 | */
35 | final private int mFileType;
36 |
37 | /**
38 | * This class holds information about the file.
39 | *
40 | * @param fileName - file name
41 | * @param fileType - file type - can be UP_FOLDER, DIRECTORY or FILE
42 | * @throws IllegalArgumentException - when illegal type (different than UP_FOLDER, DIRECTORY or
43 | * FILE)
44 | */
45 | public FileData(final String fileName,final int fileType) {
46 |
47 | // if (fileType != UP_FOLDER && fileType != DIRECTORY && fileType != FILE) {
48 | // throw new IllegalArgumentException("Illegel type of file");
49 | // }
50 | this.mFileName = fileName;
51 | this.mFileType = fileType;
52 | }
53 |
54 | @Override
55 | public int compareTo(final FileData another) {
56 | if (mFileType != another.mFileType) {
57 | return mFileType - another.mFileType;
58 | }
59 | return mFileName.compareTo(another.mFileName);
60 | }
61 |
62 | public String getFileName() {
63 | return mFileName;
64 | }
65 |
66 | public int getFileType() {
67 | return mFileType;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/FileListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Adapter used to display a files list
13 | */
14 | public class FileListAdapter extends BaseAdapter {
15 |
16 | /**
17 | * Array of FileData objects that will be used to display a list
18 | */
19 | private final ArrayList mFileDataArray;
20 |
21 | private final Context mContext;
22 |
23 | public FileListAdapter(Context context, List aFileDataArray) {
24 | mFileDataArray = (ArrayList) aFileDataArray;
25 | mContext = context;
26 | }
27 |
28 | @Override
29 | public int getCount() {
30 | return mFileDataArray.size();
31 | }
32 |
33 | @Override
34 | public Object getItem(int position) {
35 | return mFileDataArray.get(position);
36 | }
37 |
38 | @Override
39 | public long getItemId(int position) {
40 | return position;
41 | }
42 |
43 | @Override
44 | public View getView(int position, View convertView, ViewGroup parent) {
45 | FileData tempFileData = mFileDataArray.get(position);
46 | TextViewWithImage tempView = new TextViewWithImage(mContext);
47 | tempView.setText(tempFileData.getFileName());
48 | int imgRes = -1;
49 | switch (tempFileData.getFileType()) {
50 | case FileData.UP_FOLDER:
51 | imgRes = R.mipmap.icon_up_folder;
52 | break;
53 | case FileData.DIRECTORY:
54 | imgRes = R.mipmap.icon_folder;
55 | break;
56 | case FileData.FILE:
57 | imgRes = R.mipmap.icon_unknown_file;
58 | break;
59 | case FileData.ZIP_FILE:
60 | imgRes = R.mipmap.icon_zip_file;
61 | break;
62 | case FileData.CSV_FILE:
63 | imgRes = R.mipmap.icon_csv_file;
64 | break;
65 | case FileData.HTML_FILE:
66 | imgRes = R.mipmap.icon_html_file;
67 | break;
68 | case FileData.PDF_FILE:
69 | imgRes = R.mipmap.icon_pdf_file;
70 | break;
71 | case FileData.PNG_FILE:
72 | imgRes = R.mipmap.icon_png_file;
73 | break;
74 | case FileData.JPG_FILE:
75 | imgRes = R.mipmap.icon_jpg_file;
76 | break;
77 | }
78 | tempView.setImageResource(imgRes);
79 | return tempView;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/FileOperation.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | /**
4 | * Enum used to determine the file operation being performed.
5 | */
6 | public enum FileOperation {
7 | SAVE, LOAD
8 | }
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/FileSelector.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.content.SharedPreferences;
8 | import android.os.Environment;
9 | import android.preference.PreferenceManager;
10 | import android.util.Log;
11 | import android.view.Gravity;
12 | import android.view.View;
13 | import android.view.View.OnClickListener;
14 | import android.widget.AdapterView;
15 | import android.widget.AdapterView.OnItemClickListener;
16 | import android.widget.AdapterView.OnItemSelectedListener;
17 | import android.widget.ArrayAdapter;
18 | import android.widget.Button;
19 | import android.widget.EditText;
20 | import android.widget.ListView;
21 | import android.widget.Spinner;
22 | import android.widget.TextView;
23 | import android.widget.Toast;
24 |
25 | import com.loopedlabs.util.debug.DebugLog;
26 |
27 | import java.io.File;
28 | import java.util.ArrayList;
29 | import java.util.Collections;
30 |
31 | /**
32 | * Create the file selection dialog. This class will create a custom dialog for
33 | * file selection which can be used to save files.
34 | */
35 | public class FileSelector {
36 |
37 | /**
38 | * The list of files and folders which you can choose from
39 | */
40 | private ListView mFileListView;
41 | private SharedPreferences sp;
42 | /**
43 | * Button to save/load file
44 | */
45 | private Button mSaveLoadButton;
46 | /**
47 | * Cancel Button - close dialog
48 | */
49 | private Button mCancelButton;
50 | /**
51 | * Button to create a new folder
52 | */
53 | private Button mNewFolderButton;
54 |
55 | /**
56 | * Spinner by which to select the file type filtering
57 | */
58 | private Spinner mFilterSpinner;
59 |
60 | /**
61 | * Indicates current location in the directory structure displayed in the
62 | * dialog.
63 | */
64 | private File mCurrentLocation;
65 |
66 | /**
67 | * The file selector dialog.
68 | */
69 | private final Dialog mDialog;
70 |
71 | private Context mContext;
72 |
73 | /**
74 | * Save or Load file listener.
75 | */
76 | final OnHandleFileListener mOnHandleFileListener;
77 | private String csv;
78 |
79 | /**
80 | * Constructor that creates the file selector dialog.
81 | *
82 | * @param context The current context.
83 | * @param operation LOAD - to load file / SAVE - to save file
84 | * @param onHandleFileListener Notified after pressing the save or load button.
85 | * @param fileFilters Array with filters
86 | */
87 | public FileSelector(final Context context, final FileOperation operation,
88 | final OnHandleFileListener onHandleFileListener, final String[] fileFilters) {
89 |
90 | mContext = context;
91 | mOnHandleFileListener = onHandleFileListener;
92 |
93 | sp = PreferenceManager
94 | .getDefaultSharedPreferences(mContext);
95 | final File sdCard = Environment.getExternalStorageDirectory();
96 | if (sdCard.canRead()) {
97 | String path = sp.getString("location", "");
98 | if (path.length() > 0) {
99 | final File itemLocation = new File(path);
100 | Log.d("String", "location" + itemLocation);
101 | mCurrentLocation = itemLocation;
102 | }
103 | else {
104 | mCurrentLocation = sdCard;
105 | }
106 |
107 | }
108 | else {
109 | mCurrentLocation = Environment.getRootDirectory();
110 | }
111 |
112 | mDialog = new Dialog(context);
113 | mDialog.setContentView(R.layout.dialog);
114 | mDialog.setTitle(mCurrentLocation.getAbsolutePath());
115 |
116 | prepareFilterSpinner(fileFilters);
117 | prepareFilesList();
118 |
119 | setSaveLoadButton(operation);
120 | setNewFolderButton(operation);
121 | setCancelButton();
122 | }
123 |
124 | /**
125 | * This method prepares a filter's list with the String's array
126 | *
127 | * @param fitlesFilter - array of filters, the elements of the array will be used as
128 | * elements of the spinner
129 | */
130 | private void prepareFilterSpinner(String[] fitlesFilter) {
131 | mFilterSpinner = (Spinner) mDialog.findViewById(R.id.fileFilter);
132 | if (fitlesFilter == null || fitlesFilter.length == 0) {
133 | fitlesFilter = new String[]{FileUtils.FILTER_ALLOW_ALL};
134 | mFilterSpinner.setEnabled(true);
135 | }
136 | ArrayAdapter adapter = new ArrayAdapter(mContext, R.layout.spinner_item, fitlesFilter);
137 |
138 | mFilterSpinner.setAdapter(adapter);
139 | OnItemSelectedListener onItemSelectedListener = new OnItemSelectedListener() {
140 |
141 | @Override
142 | public void onItemSelected(AdapterView> aAdapter, View aView, int arg2, long arg3) {
143 | TextView textViewItem = (TextView) aView;
144 | String filtr = textViewItem.getText().toString();
145 | DebugLog.logTrace(filtr);
146 | makeList(mCurrentLocation, filtr);
147 | }
148 |
149 | @Override
150 | public void onNothingSelected(AdapterView> arg0) {
151 |
152 | }
153 | };
154 | mFilterSpinner.setOnItemSelectedListener(onItemSelectedListener);
155 | }
156 |
157 | /**
158 | * This method prepares the mFileListView
159 | */
160 | private void prepareFilesList() {
161 | mFileListView = mDialog.findViewById(R.id.fileList);
162 |
163 | mFileListView.setOnItemClickListener(new OnItemClickListener() {
164 |
165 | @Override
166 | public void onItemClick(final AdapterView> parent, final View view, final int position, final long id) {
167 | // Check if "../" item should be added.
168 | ((EditText) mDialog.findViewById(R.id.fileName)).setText("");
169 | if (id == 0) {
170 | final String parentLocation = mCurrentLocation.getParent();
171 | if (parentLocation != null) { // text == "../"
172 | String fileFilter = ((TextView) mFilterSpinner.getSelectedView()).getText().toString();
173 | mCurrentLocation = new File(parentLocation);
174 | mDialog.setTitle(parentLocation);
175 | SharedPreferences.Editor editor = sp.edit();
176 | editor.putString("location", mCurrentLocation.getAbsolutePath());
177 | editor.commit();
178 | makeList(mCurrentLocation, fileFilter);
179 | }
180 | else {
181 | onItemSelect(parent, position);
182 | }
183 | }
184 | else {
185 | onItemSelect(parent, position);
186 | }
187 | }
188 | });
189 | String filtr = mFilterSpinner.getSelectedItem().toString();
190 | makeList(mCurrentLocation, filtr);
191 | }
192 |
193 | /**
194 | * The method that fills the list with a directories contents.
195 | *
196 | * @param location Indicates the directory whose contents should be displayed in
197 | * the dialog.
198 | * @param fitlesFilter The filter specifies the type of file to be displayed
199 | */
200 | private void makeList(final File location, final String fitlesFilter) {
201 | final ArrayList fileList = new ArrayList();
202 | final String parentLocation = location.getParent();
203 | if (parentLocation != null) {
204 | // First item on the list.
205 | fileList.add(new FileData("../", FileData.UP_FOLDER));
206 | }
207 | File listFiles[] = location.listFiles();
208 | if (listFiles != null) {
209 | ArrayList fileDataList = new ArrayList();
210 | for (int index = 0; index < listFiles.length; index++) {
211 | File tempFile = listFiles[index];
212 | if (FileUtils.accept(tempFile, fitlesFilter)) {
213 | int type = tempFile.isDirectory() ? FileData.DIRECTORY : FileData.FILE;
214 | int lastIndexOfPoint = tempFile.getName().lastIndexOf('.');
215 | if (lastIndexOfPoint != -1) {
216 | String fileType = tempFile.getName().substring(lastIndexOfPoint).toLowerCase();
217 | DebugLog.logTrace("File type : " + fileType);
218 | switch (fileType) {
219 | case ".zip":
220 | type = FileData.ZIP_FILE;
221 | break;
222 | case ".csv":
223 | type = FileData.CSV_FILE;
224 | break;
225 | case ".pdf":
226 | type = FileData.PDF_FILE;
227 | break;
228 | case ".jpg":
229 | type = FileData.JPG_FILE;
230 | break;
231 | case ".png":
232 | type = FileData.PNG_FILE;
233 | break;
234 | case ".htm":
235 | case ".html":
236 | type = FileData.HTML_FILE;
237 | break;
238 | // default:
239 | // type = FileData.FILE;
240 | // break;
241 | }
242 | }
243 | DebugLog.logTrace("File type : " + type);
244 | fileDataList.add(new FileData(listFiles[index].getName(), type));
245 | }
246 | }
247 | fileList.addAll(fileDataList);
248 | Collections.sort(fileList);
249 | }
250 | // Fill the list with the contents of fileList.
251 | if (mFileListView != null) {
252 | FileListAdapter adapter = new FileListAdapter(mContext, fileList);
253 | mFileListView.setAdapter(adapter);
254 | }
255 | }
256 |
257 | /**
258 | * Handle the file list item selection.
259 | *
260 | * Change the directory on the list or change the name of the saved file if
261 | * the user selected a file.
262 | *
263 | * @param parent First parameter of the onItemClick() method of
264 | * OnItemClickListener. It's a value of text property of the
265 | * item.
266 | * @param position Third parameter of the onItemClick() method of
267 | * OnItemClickListener. It's the index on the list of the
268 | * selected item.
269 | */
270 | private void onItemSelect(final AdapterView> parent, final int position) {
271 | final String itemText = ((FileData) parent.getItemAtPosition(position)).getFileName();
272 | final String itemPath = mCurrentLocation.getAbsolutePath() + File.separator + itemText;
273 | mDialog.setTitle(itemPath);
274 | final File itemLocation = new File(itemPath);
275 |
276 | if (!itemLocation.canRead()) {
277 | Toast.makeText(mContext, "Access denied!!!", Toast.LENGTH_SHORT).show();
278 | }
279 | else if (itemLocation.isDirectory()) {
280 | mCurrentLocation = itemLocation;
281 | String fileFilter = ((TextView) mFilterSpinner.getSelectedView()).getText().toString();
282 | Log.d("String", "Directory" + itemLocation);
283 | SharedPreferences.Editor editor = sp.edit();
284 | editor.putString("location", itemLocation.getAbsolutePath());
285 | editor.commit();
286 | makeList(mCurrentLocation, fileFilter);
287 | }
288 | else if (itemLocation.isFile()) {
289 | final EditText fileName = mDialog.findViewById(R.id.fileName);
290 | fileName.setText(itemText);
291 | }
292 | }
293 |
294 | /**
295 | * Set button name and click handler for Save or Load button.
296 | *
297 | * @param operation Performed file operation.
298 | */
299 | private void setSaveLoadButton(final FileOperation operation) {
300 | mSaveLoadButton = mDialog.findViewById(R.id.fileSaveLoad);
301 | switch (operation) {
302 | case SAVE:
303 | mDialog.setTitle(mCurrentLocation.getAbsolutePath());
304 | mSaveLoadButton.setText(R.string.save);
305 | break;
306 | case LOAD:
307 | mSaveLoadButton.setText(R.string.load);
308 | break;
309 | }
310 | mSaveLoadButton.setOnClickListener(new SaveLoadClickListener(operation, this, mContext));
311 | }
312 |
313 | /**
314 | * Set button visibility and click handler for New folder button.
315 | *
316 | * @param operation Performed file operation.
317 | */
318 | private void setNewFolderButton(final FileOperation operation) {
319 | mNewFolderButton = mDialog.findViewById(R.id.newFolder);
320 | OnClickListener newFolderListener = new OnClickListener() {
321 | @Override
322 | public void onClick(final View v) {
323 | openNewFolderDialog();
324 | }
325 | };
326 | switch (operation) {
327 | case SAVE:
328 | mNewFolderButton.setVisibility(View.VISIBLE);
329 | mNewFolderButton.setOnClickListener(newFolderListener);
330 | break;
331 | case LOAD:
332 | mNewFolderButton.setVisibility(View.GONE);
333 | break;
334 | }
335 | }
336 |
337 | /**
338 | * Opens a dialog for creating a new folder.
339 | */
340 | private void openNewFolderDialog() {
341 | AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
342 | alert.setTitle(R.string.newFolderButtonText);
343 | alert.setMessage(R.string.newFolderDialogMessage);
344 | final EditText input = new EditText(mContext);
345 | alert.setView(input);
346 | alert.setPositiveButton(R.string.createButtonText, new DialogInterface.OnClickListener() {
347 | @Override
348 | public void onClick(final DialogInterface dialog, final int whichButton) {
349 | File file = new File(mCurrentLocation.getAbsolutePath() + File.separator + input.getText().toString());
350 | if (file.mkdir()) {
351 | Toast t = Toast.makeText(mContext, R.string.folderCreationOk, Toast.LENGTH_SHORT);
352 | t.setGravity(Gravity.CENTER, 0, 0);
353 | t.show();
354 | }
355 | else {
356 | Toast t = Toast.makeText(mContext, R.string.folderCreationError, Toast.LENGTH_SHORT);
357 | t.setGravity(Gravity.CENTER, 0, 0);
358 | t.show();
359 | }
360 | String fileFilter = ((TextView) mFilterSpinner.getSelectedView()).getText().toString();
361 | makeList(mCurrentLocation, fileFilter);
362 | }
363 | });
364 | alert.show();
365 | }
366 |
367 | /**
368 | * Set onClick() event handler for the cancel button.
369 | */
370 | private void setCancelButton() {
371 | mCancelButton = mDialog.findViewById(R.id.fileCancel);
372 | mCancelButton.setOnClickListener(new OnClickListener() {
373 | @Override
374 | public void onClick(final View view) {
375 | mDialog.cancel();
376 | }
377 | });
378 | }
379 |
380 | public String getSelectedFileName() {
381 | final EditText fileName = mDialog.findViewById(R.id.fileName);
382 | return fileName.getText().toString();
383 | }
384 |
385 | public File getCurrentLocation() {
386 | return mCurrentLocation;
387 | }
388 |
389 | /**
390 | * Simple wrapper around the Dialog.show() method.
391 | */
392 | public void show() {
393 | mDialog.show();
394 | }
395 |
396 | /**
397 | * Simple wrapper around the Dialog.dissmiss() method.
398 | */
399 | public void dismiss() {
400 | mDialog.dismiss();
401 | }
402 | }
403 |
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/FileSelectorActivity.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.view.View.OnClickListener;
7 | import android.widget.Button;
8 | import android.widget.Toast;
9 |
10 |
11 | public class FileSelectorActivity extends Activity {
12 |
13 | private Button mLoadButton;
14 |
15 | private Button mSaveButton;
16 |
17 | /**
18 | * Sample filters array
19 | */
20 | final String[] mFileFilter = {"*.*", ".jpeg", ".txt", ".png"};
21 |
22 | @Override
23 | public void onCreate(final Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.file_selector_main);
26 |
27 | mLoadButton = findViewById(R.id.button_load);
28 | mSaveButton = findViewById(R.id.button_save);
29 |
30 | mLoadButton.setOnClickListener(new OnClickListener() {
31 | @Override
32 | public void onClick(final View v) {
33 | new FileSelector(FileSelectorActivity.this, FileOperation.LOAD, mLoadFileListener, mFileFilter).show();
34 | }
35 | });
36 |
37 | mSaveButton.setOnClickListener(new OnClickListener() {
38 | @Override
39 | public void onClick(final View v) {
40 | new FileSelector(FileSelectorActivity.this, FileOperation.SAVE, mSaveFileListener, mFileFilter).show();
41 | }
42 | });
43 | }
44 |
45 | OnHandleFileListener mLoadFileListener = new OnHandleFileListener() {
46 | @Override
47 | public void handleFile(final String filePath) {
48 | Toast.makeText(FileSelectorActivity.this, "Load: " + filePath, Toast.LENGTH_SHORT).show();
49 | }
50 | };
51 |
52 | OnHandleFileListener mSaveFileListener = new OnHandleFileListener() {
53 | @Override
54 | public void handleFile(final String filePath) {
55 | Toast.makeText(FileSelectorActivity.this, "Save: " + filePath, Toast.LENGTH_SHORT).show();
56 | }
57 | };
58 |
59 | }
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | import com.loopedlabs.util.debug.DebugLog;
4 |
5 | import java.io.File;
6 |
7 | /**
8 | * A set of tools for file operations
9 | */
10 | public class FileUtils {
11 |
12 |
13 | /**
14 | * Filter which accepts every file
15 | */
16 | public static final String FILTER_ALLOW_ALL = "*.*";
17 |
18 | /**
19 | * This method checks that the file is accepted by the filter
20 | *
21 | * @param file - file that will be checked if there is a specific type
22 | * @param filter - criterion - the file type(for example ".jpg")
23 | * @return true - if file meets the criterion - false otherwise.
24 | */
25 | public static boolean accept(final File file,final String filter) {
26 | DebugLog.logTrace(" file : " + file.getName());
27 | if (filter.compareTo(FILTER_ALLOW_ALL) == 0) {
28 | return true;
29 | }
30 |
31 | int lastIndexOfPoint = file.getName().lastIndexOf('.');
32 | String fileType = "";
33 |
34 | if (file.isDirectory()) {
35 | if (lastIndexOfPoint == 0) {
36 | fileType = file.getName().substring(lastIndexOfPoint).toLowerCase();
37 | if (fileType.length() > 2) {
38 | return fileType.compareTo(filter) == 0;
39 | }
40 | }
41 | return true;
42 | }
43 |
44 | if (lastIndexOfPoint <= 0 ) {
45 | return false;
46 | }
47 |
48 | fileType = file.getName().substring(lastIndexOfPoint).toLowerCase();
49 | return fileType.compareTo(filter) == 0;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/OnHandleFileListener.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | public interface OnHandleFileListener {
4 | /**
5 | * This method is called after clicking the Save or Load button on the
6 | * dialog, if the file name was correct. It should be used to save or load a
7 | * file using the filePath path.
8 | *
9 | * @param filePath File path set in the dialog when the Save or Load button was
10 | * clicked.
11 | */
12 | void handleFile(String filePath);
13 | }
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/SaveLoadClickListener.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.view.Gravity;
6 | import android.view.View;
7 | import android.view.View.OnClickListener;
8 | import android.widget.Toast;
9 |
10 | import java.io.File;
11 |
12 |
13 | /**
14 | * This Listener handles Save or Load button clicks.
15 | */
16 | public class SaveLoadClickListener implements OnClickListener {
17 |
18 | /**
19 | * Performed operation.
20 | */
21 | private final FileOperation mOperation;
22 |
23 | /**
24 | * FileSelector in which you used SaveLoadClickListener
25 | */
26 | private final FileSelector mFileSelector;
27 |
28 | private final Context mContext;
29 |
30 | /**
31 | * @param operation Performed operation.
32 | * @param fileSelector The FileSeletor which used this Listener.
33 | * @param context context.
34 | */
35 | public SaveLoadClickListener(final FileOperation operation, final FileSelector fileSelector, final Context context) {
36 | mOperation = operation;
37 | mFileSelector = fileSelector;
38 | mContext = context;
39 | }
40 |
41 | @Override
42 | public void onClick(final View view) {
43 | final String text = mFileSelector.getSelectedFileName();
44 | if (checkFileName(text)) {
45 |
46 | final String filePath = mFileSelector.getCurrentLocation().getAbsolutePath() + File.separator + text;
47 | final File file = new File(filePath);
48 | int messageText = 0;
49 | // Check file access rights.
50 | switch (mOperation) {
51 | case SAVE:
52 | if ((file.exists()) && (!file.canWrite())) {
53 | messageText = R.string.cannotSaveFileMessage;
54 | }
55 | break;
56 | case LOAD:
57 | if (!file.exists()) {
58 | messageText = R.string.missingFile;
59 | } else if (!file.canRead()) {
60 | messageText = R.string.accessDenied;
61 | }
62 | break;
63 | }
64 | if (messageText != 0) {
65 | // Access denied.
66 | final Toast t = Toast.makeText(mContext, messageText, Toast.LENGTH_SHORT);
67 | t.setGravity(Gravity.CENTER, 0, 0);
68 | t.show();
69 | } else {
70 | // Access granted.
71 | mFileSelector.mOnHandleFileListener.handleFile(filePath);
72 | mFileSelector.dismiss();
73 | }
74 | }
75 | }
76 |
77 | /**
78 | * Check if file name is correct, e.g. if it isn't empty.
79 | *
80 | * @return False, if file name is empty true otherwise.
81 | */
82 | boolean checkFileName(String text) {
83 | if (text.length() == 0) {
84 | final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
85 | builder.setTitle(R.string.information);
86 | builder.setMessage(R.string.fileNameFirstMessage);
87 | builder.setNeutralButton(R.string.ok, null);
88 | builder.show();
89 | return false;
90 | }
91 | return true;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/file_selector/src/main/java/com/loopedlabs/selector/TextViewWithImage.java:
--------------------------------------------------------------------------------
1 | package com.loopedlabs.selector;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | /**
10 | * Class which combines ImageView and TextView in LineralLayout with horizontal
11 | * orientation
12 | */
13 | public class TextViewWithImage extends LinearLayout {
14 |
15 | /**
16 | * Image - in this project will be used to display icon representing the
17 | * file type
18 | */
19 | private ImageView mImage;
20 | /**
21 | * Text - in this project will be used to display the file name
22 | */
23 | private TextView mText;
24 |
25 | public TextViewWithImage(Context context) {
26 | super(context);
27 | setOrientation(HORIZONTAL);
28 | mImage = new ImageView(context);
29 | mText = new TextView(context);
30 |
31 | LayoutParams lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
32 | lp.weight = 1;
33 | addView(mImage, lp);
34 | lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 3);
35 | addView(mText, lp);
36 | }
37 |
38 | /**
39 | * Simple wrapper around the TextView.getText() method.
40 | */
41 | public CharSequence getText() {
42 | return mText.getText();
43 | }
44 |
45 | /**
46 | * Simple wrapper around ImageView.setImageResource() method. but if resId
47 | * is equal -1 this method sets Images visibility as GONE
48 | */
49 | public void setImageResource(int resId) {
50 | if (resId == -1) {
51 | mImage.setVisibility(View.GONE);
52 | return;
53 | }
54 | mImage.setImageResource(resId);
55 | }
56 |
57 | /**
58 | * Simple wrapper around TextView.setText() method.
59 | */
60 | public void setText(String aText) {
61 | mText.setText(aText);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/file_selector/src/main/res/drawable-hdpi/ic_dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/drawable-hdpi/ic_dropdown.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/drawable-mdpi/ic_dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/drawable-mdpi/ic_dropdown.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/drawable-xhdpi/ic_dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/drawable-xhdpi/ic_dropdown.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/drawable-xxhdpi/ic_dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/drawable-xxhdpi/ic_dropdown.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/drawable/spinner_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/file_selector/src/main/res/layout/dialog.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
14 |
22 |
23 |
30 |
31 |
37 |
38 |
43 |
44 |
50 |
51 |
58 |
59 |
65 |
66 |
67 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/file_selector/src/main/res/layout/file_selector_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/file_selector/src/main/res/layout/spinner_item.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_csv_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_csv_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_html_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_html_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_jpg_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_jpg_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_pdf_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_pdf_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_png_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_png_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_unknown_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_unknown_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_up_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_up_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-hdpi/icon_zip_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-hdpi/icon_zip_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_csv_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_csv_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_html_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_html_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_jpg_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_jpg_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_pdf_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_pdf_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_png_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_png_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_unknown_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_unknown_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_up_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_up_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/icon_zip_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/icon_zip_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-mdpi/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-mdpi/image.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_csv_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_csv_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_html_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_html_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_jpg_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_jpg_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_pdf_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_pdf_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_png_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_png_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_unknown_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_unknown_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_up_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_up_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xhdpi/icon_zip_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xhdpi/icon_zip_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_csv_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_csv_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_html_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_html_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_jpg_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_jpg_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_pdf_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_pdf_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_png_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_png_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_unknown_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_unknown_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_up_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_up_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxhdpi/icon_zip_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxhdpi/icon_zip_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_csv_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_csv_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_html_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_html_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_jpg_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_jpg_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_pdf_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_pdf_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_png_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_png_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_unknown_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_unknown_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_up_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_up_folder.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/mipmap-xxxhdpi/icon_zip_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/file_selector/src/main/res/mipmap-xxxhdpi/icon_zip_file.png
--------------------------------------------------------------------------------
/file_selector/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | file_selector
3 | Please enter the file name first
4 | Save
5 | Load
6 | New folder
7 | Create new folder
8 | Create
9 | Folder created successfully
10 | Error while creating folder
11 | Enter file name:
12 | Cancel
13 | Cannot save file
14 | No such file
15 | Access denied
16 | Information
17 | OK
18 |
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | android.enableJetifier=true
20 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/looped-labs/ESCPOSPrintServiceDemo/ceeb056c2c566e3061f1dc708e97ee5e1f21d8c6/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jun 08 15:09:33 IST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # ESC POS Print Service Demo
2 |
3 | Printing to a ESC/POS Thermal Receipt printer is simple now. Just send an intent.
4 |
5 | ## Print Intents to print PDF URL's
6 | Intent pi = new Intent();
7 | pi.setAction("org.escpos.intent.action.PRINT");
8 | pi.setPackage("com.loopedlabs.escposprintservice");
9 | pi.putExtra("DATA_TYPE", "PDF_URL");
10 | pi.putExtra(Intent.EXTRA_TEXT, "https://url.for.pdf");
11 | startActivity(i);
12 | #### You can also print Images, HTML & PDF Urls
13 | ------------------------------------------------------------------------------------------
14 | ## HeadingPrint Intents to print PDF data in a Byte Array
15 |
16 | Intent pi = new Intent();
17 | pi.setAction("org.escpos.intent.action.PRINT");
18 | pi.setPackage("com.loopedlabs.escposprintservice");
19 | pi.putExtra("PRINT_DATA", pdfByteArray);
20 | pi.putExtra("DATA_TYPE", "PDF");
21 | startActivity(i);
22 | #### You can also print Images, HTML & PDF Byte Arrays
23 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':file_selector', ':debug_log'
2 |
--------------------------------------------------------------------------------