Skip to content

Commit

Permalink
Merge pull request #14 from ltrudu/master
Browse files Browse the repository at this point in the history
A13 RC1
  • Loading branch information
ltrudu committed Sep 12, 2023
2 parents 778227c + 7c656b3 commit e867bd9
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 41 deletions.
13 changes: 7 additions & 6 deletions ZebraPrintService/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 32
ndkVersion "21.0.6113669"
//ndkVersion "21.0.6113669"
ndkVersion "23.1.7779620"
defaultConfig {
compileSdk 34
applicationId "com.zebra.zebraprintservice"
minSdkVersion 24
targetSdkVersion 32
versionCode 29
versionName "1.1.7"
minSdkVersion 30
versionCode 31
versionName "1.3.0"
externalNativeBuild {
cmake {
cppFlags "-std=c++14"
Expand Down Expand Up @@ -41,6 +41,7 @@ android {
abortOnError false
checkReleaseBuilds false
}
namespace 'com.zebra.zebraprintservice'
}

dependencies {
Expand Down
16 changes: 12 additions & 4 deletions ZebraPrintService/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zebra.zebraprintservice">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:minSdkVersion="31"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:minSdkVersion="31"/>

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Expand All @@ -16,9 +16,16 @@
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />

<uses-feature
android:name="android.hardware.bluetooth"
android:required="false" />

<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="false" />


<uses-feature
android:name="android.hardware.usb.host"
android:required="false" />
Expand Down Expand Up @@ -71,6 +78,7 @@
android:name=".activities.AddActivity"
android:autoRemoveFromRecents="true"
android:exported="true"
android:theme="@style/Theme.AppCompat.Light"
android:label="@string/add_printer" />

<!-- Settings Activity -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected void onCreate(Bundle savedInstanceState)
setContentView(R.layout.activity_add);
overridePendingTransition(0,0);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
if(actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
mDb = new PrinterDatabase(this);
mListView = findViewById(R.id.printerList);
results = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import androidx.annotation.NonNull;

import android.Manifest;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -34,6 +37,24 @@ public class SettingsActivity extends Activity
private final static int REQUEST_CODE_IMPORT = 3;
private PrinterDatabase mDb;

private static ArrayList<String> ZEBRA_PRINTSERVICE_PERMISSIONS_LIST = new ArrayList<String>(){{
add(Manifest.permission.ACCESS_WIFI_STATE);
add(Manifest.permission.INTERNET);
add(Manifest.permission.BLUETOOTH_ADMIN);
add(Manifest.permission.BLUETOOTH);
add(Manifest.permission.ACCESS_FINE_LOCATION);
add(Manifest.permission.ACCESS_COARSE_LOCATION);
add(Manifest.permission.WAKE_LOCK);
add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}};

private static final ArrayList<String> ZEBRA_PRINTSERVICE_PERMISSIONS_LIST_A12 = new ArrayList<String>(){{
add(Manifest.permission.BLUETOOTH_CONNECT);
add(Manifest.permission.BLUETOOTH_SCAN);
addAll(ZEBRA_PRINTSERVICE_PERMISSIONS_LIST);
}};


/***********************************************************************************************/
@Override
protected void onCreate(Bundle savedInstanceState)
Expand Down Expand Up @@ -153,7 +174,21 @@ private boolean checkPermissions()
try
{
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS);
String[] requestedPermissions = packageInfo.requestedPermissions;
//Get Permissions
String[] requestedPermissions = null;

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
{
requestedPermissions = new String[ZEBRA_PRINTSERVICE_PERMISSIONS_LIST_A12.size()];
ZEBRA_PRINTSERVICE_PERMISSIONS_LIST_A12.toArray(requestedPermissions);
}
else
{
requestedPermissions = new String[ZEBRA_PRINTSERVICE_PERMISSIONS_LIST.size()];
ZEBRA_PRINTSERVICE_PERMISSIONS_LIST.toArray(requestedPermissions);
}


List<String> neededPermissions = new ArrayList<String>();
if(requestedPermissions != null)
{
Expand All @@ -175,7 +210,19 @@ public void onPermission(View v)
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS);

//Get Permissions
String[] requestedPermissions = packageInfo.requestedPermissions;
String[] requestedPermissions = null;

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
{
requestedPermissions = new String[ZEBRA_PRINTSERVICE_PERMISSIONS_LIST_A12.size()];
ZEBRA_PRINTSERVICE_PERMISSIONS_LIST_A12.toArray(requestedPermissions);
}
else
{
requestedPermissions = new String[ZEBRA_PRINTSERVICE_PERMISSIONS_LIST.size()];
ZEBRA_PRINTSERVICE_PERMISSIONS_LIST.toArray(requestedPermissions);
}

List<String> neededPermissions = new ArrayList<String>();

if(requestedPermissions != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public ZebraBluetoothPrinter(Context ctx,PrinterDatabase.Printer printer)
mBluetoothManager = (BluetoothManager) mCtx.getSystemService(Context.BLUETOOTH_SERVICE);
if (mBluetoothManager != null) mBluetoothAdapter = mBluetoothManager.getAdapter();
if (mBluetoothAdapter != null) mDevice = mBluetoothAdapter.getRemoteDevice(printer.mAddress);
PrinterDatabase mDb = new PrinterDatabase(mCtx);
mDb.updatePrinter(printer);
mDb.close();
}

/*********************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public ZebraFilePrinter(Context ctx, PrinterDatabase.Printer printer)
if (DEBUG) Log.i(TAG,"Creating File Printer -> " + printer.mWidth + "x" + printer.mHeight + " DPI:" + printer.mDPI);
mPrinter = printer;
mCtx = ctx;
PrinterDatabase mDb = new PrinterDatabase(mCtx);
mDb.updatePrinter(printer);
mDb.close();
}

/*********************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public ZebraUsbPrinter(Context ctx, PrinterDatabase.Printer printer)
mUsbManager = (UsbManager) mCtx.getSystemService(Context.USB_SERVICE);
mPermissionIntent = PendingIntent.getBroadcast(mCtx, 0, new Intent(ACTION_USB_PERMISSION), 0);
mHandler = new Handler(mCtx.getMainLooper());

PrinterDatabase mDb = new PrinterDatabase(mCtx);
mDb.updatePrinter(printer);
mDb.close();

mCtx.registerReceiver(UsbReciever,new IntentFilter(ACTION_USB_PERMISSION));

if (mUsbManager != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.print.PrinterInfo;
import android.util.Xml;

import com.zebra.zebraprintservice.service.ZebraPrinter;

import org.parceler.Parcel;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
Expand Down Expand Up @@ -125,6 +128,28 @@ private ContentValues populateValues(Printer item)
return Values;
}

/**********************************************************************************************/
private ContentValues populateValues(PrinterInfo item, PrinterDatabase.Printer zprinter)
{
ContentValues Values = new ContentValues();
Values.put(KEY_PRINTERID, item.getId().toString());
Values.put(KEY_NAME, item.getName());
Values.put(KEY_PRINTER, zprinter.mPrinter);
Values.put(KEY_DESCRIPTION, item.getDescription());
Values.put(KEY_TYPE, zprinter.mType);
Values.put(KEY_ADDRESS, zprinter.mAddress);
Values.put(KEY_PORT, zprinter.mPort);
Values.put(KEY_DPI, zprinter.mDPI);
Values.put(KEY_WIDTH, zprinter.mWidth);
Values.put(KEY_HEIGHT, zprinter.mHeight);
Values.put(KEY_VARIABLE_LENGTH, zprinter.mVariableLengthEnabled);
Values.put(KEY_TOPMARGIN, zprinter.mVariableLengthTopMargin);
Values.put(KEY_JPGQUALITY, zprinter.mJpegQuality);
Values.put(KEY_MODIFIED,zprinter.mTimeStamp.getTime());
Values.put(KEY_LANGUAGE,zprinter.mLanguage);
return Values;
}

/**********************************************************************************************/
private ArrayList<Printer> getItems(Cursor c)
{
Expand Down Expand Up @@ -164,6 +189,12 @@ public void replacePrinter(Printer item)
mDbHelper.getWritableDatabase().replace(DB_TABLE,null,Values);
}

public void replacePrinter(PrinterInfo sysPrinter, Printer dbPrinter)
{
ContentValues Values = populateValues(sysPrinter, dbPrinter);
mDbHelper.getWritableDatabase().replace(DB_TABLE,null,Values);
}

/**********************************************************************************************/
public Printer getPrinter(String printerId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,36 @@ public void onStartPrinterDiscovery(@NonNull List<PrinterId> priorityList)

//Remove Any Printers not in Database
List<PrinterInfo> mCurrentList = getPrinters();


if (DEBUG) Log.d(TAG, "Printers in stystem:" + mCurrentList.size());
for (PrinterInfo printer : mCurrentList)
{
if (DEBUG) Log.d(TAG, "------------------------------------------");
if (DEBUG) Log.d(TAG, "Printers ID:" + printer.getId());
boolean bFound = false;
for (PrinterDatabase.Printer stored : printers)
{
if (stored.mPrinterId.equals(printer.getId())) bFound = true;
if (DEBUG) Log.d(TAG, "Stored ID:" + stored.mPrinterId);
if (stored.mPrinterId.equals(printer.getId()))
{
bFound = true;
if (DEBUG) Log.d(TAG, "Found ID:" + stored.mPrinterId);
mDb.replacePrinter(printer, stored);
}
}
if (bFound == false) removePrinters(Collections.singletonList(printer.getId()));
if (DEBUG) Log.d(TAG, "------------------------------------------");
if (bFound == false)
removePrinters(Collections.singletonList(printer.getId()));
}

// Remove all existing printers
// TODO: check why actual printers get a pb when re discovered
List<PrinterInfo> printersList = getPrinters();
ArrayList<PrinterId> printersIds = new ArrayList<>(printersList.size());
for(PrinterInfo printInfo : printersList)
printersIds.add(printInfo.getId());
removePrinters(printersIds);
//List<PrinterInfo> printersList = getPrinters();
//ArrayList<PrinterId> printersIds = new ArrayList<>(printersList.size());
//for(PrinterInfo printInfo : printersList)
// printersIds.add(printInfo.getId());
//removePrinters(printersIds);

//Add Printers from database
int iReqCode =1;
Expand Down
40 changes: 21 additions & 19 deletions ZebraPrintService/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,32 @@
<View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" android:layout_marginTop="12dp"/>

<LinearLayout
style="@android:style/Widget.DeviceDefault.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@android:style/Widget.DeviceDefault.Button.Borderless"
android:clickable="true"
android:onClick="onPermission"
android:orientation="vertical"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:clickable="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/text"
android:id="@+id/permissionState"
android:text="@string/permissions" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/text"
android:id="@+id/permissions"
android:text="@string/enable_permissions" />
android:visibility="visible">

<TextView
android:id="@+id/permissionState"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/permissions"
android:textColor="@color/text"
android:textSize="16sp"
android:textStyle="bold" />

<TextView
android:id="@+id/permissions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enable_permissions"
android:textColor="@color/text"
android:textSize="14sp" />

</LinearLayout>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.android.tools.build:gradle:7.4.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

0 comments on commit e867bd9

Please sign in to comment.