diff options
author | Sergey Yakovlev <s.yakovlev@samsung.com> | 2016-05-23 13:05:53 +0300 |
---|---|---|
committer | Sergey Yakovlev <s.yakovlev@samsung.com> | 2016-05-23 13:05:53 +0300 |
commit | 784d18262da1ac00750f4f80b64a3edce7085506 (patch) | |
tree | b2bcd4c9cf646d3fa4db262a22db906fd72b0fb9 | |
parent | 3a33ee20e99646f38127c7aeca5f0616d268a5ce (diff) | |
download | experimental-784d18262da1ac00750f4f80b64a3edce7085506.tar.gz |
Samsung Printer Recommendation plugin
Samsung Printer Recommendation plugin based on Printer Recommendation Example
Change-Id: I26a62f103bad959418fe717dbc1a519e7ebc1337
34 files changed, 1318 insertions, 0 deletions
diff --git a/SamsungPrinterRecommendation/app/build.gradle b/SamsungPrinterRecommendation/app/build.gradle new file mode 100644 index 0000000..1fa7cfe --- /dev/null +++ b/SamsungPrinterRecommendation/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 'android-N' + buildToolsVersion "23.0.3" + + defaultConfig { + applicationId "com.example.android.discovery.recommendation" + minSdkVersion 'N' + targetSdkVersion 'N' + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + lintOptions { + disable 'AllowBackup', 'GoogleAppIndexingWarning' + abortOnError false + checkReleaseBuilds true + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:23.3.0' + compile 'com.android.support:design:23.3.0' +} diff --git a/SamsungPrinterRecommendation/app/proguard-rules.pro b/SamsungPrinterRecommendation/app/proguard-rules.pro new file mode 100644 index 0000000..002b260 --- /dev/null +++ b/SamsungPrinterRecommendation/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /toolbox/jdelhier/android-sdk-linux/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/SamsungPrinterRecommendation/app/src/main/AndroidManifest.xml b/SamsungPrinterRecommendation/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..745ec0c --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.discovery.recommendation" > + + <uses-permission android:name="android.permission.INTERNET"/> + <application + android:allowBackup="false" + android:fullBackupContent="false" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:supportsRtl="true" + android:theme="@style/AppTheme" > + <activity + android:name=".DeviceList" + android:label="@string/title_activity_device_list" + android:theme="@style/AppTheme.NoActionBar" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/MDnsUtils.java b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/MDnsUtils.java new file mode 100644 index 0000000..efc8c61 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/MDnsUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.discovery.recommendation; + +import android.net.nsd.NsdServiceInfo; +import android.text.TextUtils; + +import java.nio.charset.StandardCharsets; +import java.util.Locale; +import java.util.Map; + +public class MDnsUtils { + public static final String ATTRIBUTE__TY = "ty"; + public static final String ATTRIBUTE__PRODUCT = "product"; + public static final String ATTRIBUTE__USB_MFG = "usb_MFG"; + public static final String ATTRIBUTE__MFG = "mfg"; + + public static String getString(byte[] value) { + if (value != null) return new String(value,StandardCharsets.UTF_8); + return null; + } + + public static boolean isVendorPrinter(NsdServiceInfo networkDevice, String[] vendorValues) { + + Map<String,byte[]> attributes = networkDevice.getAttributes(); + String product = getString(attributes.get(ATTRIBUTE__PRODUCT)); + String ty = getString(attributes.get(ATTRIBUTE__TY)); + String usbMfg = getString(attributes.get(ATTRIBUTE__USB_MFG)); + String mfg = getString(attributes.get(ATTRIBUTE__MFG)); + return containsVendor(product, vendorValues) || containsVendor(ty, vendorValues) || containsVendor(usbMfg, vendorValues) || containsVendor(mfg, vendorValues); + + } + + public static String getVendor(NsdServiceInfo networkDevice) { + String vendor; + + Map<String,byte[]> attributes = networkDevice.getAttributes(); + vendor = getString(attributes.get(ATTRIBUTE__MFG)); + if (!TextUtils.isEmpty(vendor)) return vendor; + vendor = getString(attributes.get(ATTRIBUTE__USB_MFG)); + if (!TextUtils.isEmpty(vendor)) return vendor; + + return null; + } + + private static boolean containsVendor(String container, String[] vendorValues) { + if ((container == null) || (vendorValues == null)) return false; + for (String value : vendorValues) { + if (containsString(container, value) + || containsString(container.toLowerCase(Locale.US), value.toLowerCase(Locale.US)) + || containsString(container.toUpperCase(Locale.US), value.toUpperCase(Locale.US))) + return true; + } + return false; + } + + private static boolean containsString(String container, String contained) { + return (container != null) && (contained != null) && (container.equalsIgnoreCase(contained) || container.contains(contained + " ")); + } +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/PrintServicePlugin.java b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/PrintServicePlugin.java new file mode 100644 index 0000000..68aa435 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/PrintServicePlugin.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.discovery.recommendation; + +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.StringRes; + +/** + * Interface to be implemented by each print service plugin. + * <p/> + * A print service plugin is a minimal version of a real {@link android.printservice.PrintService + * print service}. You cannot print using the plugin. The only functionality in the plugin is to + * report the number of printers that the real service would discover. + */ +public interface PrintServicePlugin { + /** + * Call back used by the print service plugins. + */ + interface PrinterDiscoveryCallback { + /** + * Announce that something changed and the UI for this plugin should be updated. + * + * @param numDiscoveredPrinters The number of printers discovered. + */ + void onChanged(@IntRange(from = 0) int numDiscoveredPrinters); + } + /** + * Get the name (a string reference) of the {@link android.printservice.PrintService print + * service} with the {@link #getPackageName specified package name}. This is read once, hence + * returning different data at different times is not allowed. + * + * @return The name of the print service as a string reference. The localization is handled + * outside of the plugin. + */ + @StringRes int getName(); + /** + * The package name of the full print service. + * + * @return The package name + */ + @NonNull CharSequence getPackageName(); + /** + * Start the discovery plugin. + * + * @param callback Callbacks used by this plugin. + * + * @throws Exception If anything went wrong when starting the plugin + */ + void start(@NonNull PrinterDiscoveryCallback callback) throws Exception; + /** + * Stop the plugin. This can only return once the plugin is completely finished and cleaned up. + * + * @throws Exception If anything went wrong while stopping plugin + */ + void stop() throws Exception; +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/PrinterHashMap.java b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/PrinterHashMap.java new file mode 100644 index 0000000..e9e50d7 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/PrinterHashMap.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.discovery.recommendation; + +import android.net.nsd.NsdServiceInfo; + +import java.util.HashMap; + +public final class PrinterHashMap extends HashMap<String, NsdServiceInfo> { + public static String getKey(NsdServiceInfo serviceInfo) { + return serviceInfo.getServiceName(); + } + public NsdServiceInfo addPrinter(NsdServiceInfo device) { + return put(getKey(device), device); + } + public NsdServiceInfo removePrinter(NsdServiceInfo device) { + return remove(getKey(device)); + } +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceListener.java b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceListener.java new file mode 100644 index 0000000..3837a67 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceListener.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.discovery.recommendation; + +import android.content.Context; +import android.content.res.TypedArray; +import android.net.nsd.NsdManager; +import android.net.nsd.NsdServiceInfo; +import android.text.TextUtils; +import android.util.Pair; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.example.android.discovery.recommendation.R; + +public class ServiceListener implements ServiceResolveQueue.ResolveCallback { + + private final NsdManager mNSDManager; + private final Map<String, VendorInfo> mVendorInfoHashMap; + private final String[] mServiceType; + private final Observer mObserver; + private final ServiceResolveQueue mResolveQueue; + private List<NsdManager.DiscoveryListener> mListeners = new ArrayList<>(); + public HashMap<String, PrinterHashMap> mVendorHashMap = new HashMap<>(); + + public interface Observer { + boolean matchesCriteria(String vendor, NsdServiceInfo serviceInfo); + void dataSetChanged(); + } + + public ServiceListener(Context context, Observer observer, String[] serviceTypes) { + mResolveQueue = ServiceResolveQueue.getInstance(); + mObserver = observer; + mServiceType = serviceTypes; + mNSDManager = (NsdManager)context.getSystemService(Context.NSD_SERVICE); + + Map<String, VendorInfo> vendorInfoMap = new HashMap<>(); + TypedArray testArray = context.getResources().obtainTypedArray(R.array.known_print_plugin_vendors); + for(int i = 0; i < testArray.length(); i++) { + int arrayID = testArray.getResourceId(i, 0); + if (arrayID != 0) { + VendorInfo info = new VendorInfo(context.getResources(), arrayID); + vendorInfoMap.put(info.mVendorID, info); + vendorInfoMap.put(info.mPackageName, info); + } + } + testArray.recycle(); + mVendorInfoHashMap = vendorInfoMap; + } + + @Override + public void serviceResolved(NsdServiceInfo nsdServiceInfo) { + printerFound(nsdServiceInfo); + } + + private synchronized void printerFound(NsdServiceInfo nsdServiceInfo) { + if (nsdServiceInfo == null) return; + if (TextUtils.isEmpty(PrinterHashMap.getKey(nsdServiceInfo))) return; + String vendor = MDnsUtils.getVendor(nsdServiceInfo); + if (vendor == null) vendor = ""; + for(Map.Entry<String,VendorInfo> entry : mVendorInfoHashMap.entrySet()) { + for(String vendorValues : entry.getValue().mDNSValues) { + if (vendor.equalsIgnoreCase(vendorValues)) { + vendor = entry.getValue().mVendorID; + break; + } + } + // intentional pointer check + //noinspection StringEquality + if ((vendor != entry.getValue().mVendorID) && + MDnsUtils.isVendorPrinter(nsdServiceInfo, entry.getValue().mDNSValues)) { + vendor = entry.getValue().mVendorID; + } + // intentional pointer check + //noinspection StringEquality + if (vendor == entry.getValue().mVendorID) break; + } + + if (TextUtils.isEmpty(vendor)) { + return; + } + + if (!mObserver.matchesCriteria(vendor, nsdServiceInfo)) + return; + boolean mapsChanged; + + PrinterHashMap vendorHash = mVendorHashMap.get(vendor); + if (vendorHash == null) { + vendorHash = new PrinterHashMap(); + } + mapsChanged = (vendorHash.addPrinter(nsdServiceInfo) == null); + mVendorHashMap.put(vendor, vendorHash); + + if (mapsChanged) { + mObserver.dataSetChanged(); + } + } + + private synchronized void printerRemoved(NsdServiceInfo nsdServiceInfo) { + boolean wasRemoved = false; + Set<String> vendors = mVendorHashMap.keySet(); + for(String vendor : vendors) { + PrinterHashMap map = mVendorHashMap.get(vendor); + wasRemoved |= (map.removePrinter(nsdServiceInfo) != null); + if (map.isEmpty()) wasRemoved |= (mVendorHashMap.remove(vendor) != null); + } + if (wasRemoved) { + mObserver.dataSetChanged(); + } + } + + public void start() { + stop(); + for(final String service :mServiceType) { + NsdManager.DiscoveryListener listener = new NsdManager.DiscoveryListener() { + @Override + public void onStartDiscoveryFailed(String s, int i) { + + } + + @Override + public void onStopDiscoveryFailed(String s, int i) { + + } + + @Override + public void onDiscoveryStarted(String s) { + + } + + @Override + public void onDiscoveryStopped(String s) { + + } + + @Override + public void onServiceFound(NsdServiceInfo nsdServiceInfo) { + mResolveQueue.queueRequest(nsdServiceInfo, ServiceListener.this); + } + + @Override + public void onServiceLost(NsdServiceInfo nsdServiceInfo) { + mResolveQueue.removeRequest(nsdServiceInfo, ServiceListener.this); + printerRemoved(nsdServiceInfo); + } + }; + mNSDManager.discoverServices(service, NsdManager.PROTOCOL_DNS_SD, listener); + mListeners.add(listener); + } + } + + public void stop() { + for(NsdManager.DiscoveryListener listener : mListeners) { + mNSDManager.stopServiceDiscovery(listener); + } + mVendorHashMap.clear(); + mListeners.clear(); + } + + public Pair<Integer, Integer> getCount() { + int count = 0; + for (PrinterHashMap map : mVendorHashMap.values()) { + count += map.size(); + } + return Pair.create(mVendorHashMap.size(), count); + } +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceRecommendationPlugin.java b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceRecommendationPlugin.java new file mode 100644 index 0000000..fcb7ad0 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceRecommendationPlugin.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.discovery.recommendation; + +import android.content.Context; +import android.net.nsd.NsdManager; +import android.net.nsd.NsdServiceInfo; +import android.support.annotation.NonNull; +import android.text.TextUtils; + +public abstract class ServiceRecommendationPlugin implements PrintServicePlugin, ServiceListener.Observer { + + protected static final String PDL_ATTRIBUTE = "pdl"; + + protected final Object mLock = new Object(); + protected PrinterDiscoveryCallback mCallback = null; + protected final ServiceListener mListener; + protected final NsdManager mNSDManager; + protected final VendorInfo mVendorInfo; + private final int mVendorStringID; + + protected ServiceRecommendationPlugin(Context context, int vendorStringID, VendorInfo vendorInfo, String[] services) { + mNSDManager = (NsdManager)context.getSystemService(Context.NSD_SERVICE); + mVendorStringID = vendorStringID; + mVendorInfo = vendorInfo; + mListener = new ServiceListener(context, this, services); + } + + @Override + public int getName() { + return mVendorStringID; + } + + @NonNull + @Override + public CharSequence getPackageName() { + return mVendorInfo.mPackageName; + } + + @Override + public void start(@NonNull PrinterDiscoveryCallback callback) throws Exception { + synchronized (mLock) { + mCallback = callback; + } + mListener.start(); + } + + @Override + public void stop() throws Exception { + synchronized (mLock) { + mCallback = null; + } + mListener.stop(); + } + + @Override + public void dataSetChanged() { + synchronized (mLock) { + if (mCallback != null) mCallback.onChanged(getCount()); + } + } + + @Override + public boolean matchesCriteria(String vendor, NsdServiceInfo nsdServiceInfo) { + return TextUtils.equals(vendor, mVendorInfo.mVendorID); + } + + public int getCount() { + return mListener.getCount().second; + } +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceResolveQueue.java b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceResolveQueue.java new file mode 100644 index 0000000..cdfd937 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/ServiceResolveQueue.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.discovery.recommendation; + +import android.net.nsd.NsdManager; +import android.net.nsd.NsdServiceInfo; +import android.util.Pair; + +import java.util.LinkedList; + +public final class ServiceResolveQueue { + + private final NsdManager mNsdManager; + private final LinkedList<Pair<NsdServiceInfo, ResolveCallback>> mQueue = new LinkedList<>(); + private final Object mLock = new Object(); + + private static ServiceResolveQueue sInstance = null; + private Pair<NsdServiceInfo, ResolveCallback> mCurrentRequest = null; + + public static void createInstance(NsdManager nsdManager) { + if (sInstance == null) sInstance = new ServiceResolveQueue(nsdManager); + } + + public static ServiceResolveQueue getInstance() { + return sInstance; + } + + public static void destroyInstance() { + sInstance = null; + } + + public interface ResolveCallback { + void serviceResolved(NsdServiceInfo nsdServiceInfo); + } + + public ServiceResolveQueue(NsdManager nsdManager) { + mNsdManager = nsdManager; + } + + public void queueRequest(NsdServiceInfo serviceInfo, ResolveCallback callback) { + synchronized (mLock) { + Pair<NsdServiceInfo, ResolveCallback> newRequest = Pair.create(serviceInfo, callback); + if (mQueue.contains(newRequest)) return; + mQueue.add(newRequest); + makeNextRequest(); + } + } + + public void removeRequest(NsdServiceInfo serviceInfo, ResolveCallback callback) { + synchronized (mLock) { + Pair<NsdServiceInfo, ResolveCallback> newRequest = Pair.create(serviceInfo, callback); + mQueue.remove(newRequest); + if ((mCurrentRequest != null) && newRequest.equals(mCurrentRequest)) mCurrentRequest = null; + } + } + + private void makeNextRequest() { + synchronized (mLock) { + if (mCurrentRequest != null) return; + if (mQueue.isEmpty()) return; + mCurrentRequest = mQueue.removeFirst(); + mNsdManager.resolveService(mCurrentRequest.first, new NsdManager.ResolveListener() { + @Override + public void onResolveFailed(NsdServiceInfo nsdServiceInfo, int i) { + synchronized (mLock) { + if (mCurrentRequest != null) mQueue.add(mCurrentRequest); + makeNextRequest(); + } + } + + @Override + public void onServiceResolved(NsdServiceInfo nsdServiceInfo) { + synchronized (mLock) { + if (mCurrentRequest != null) { + mCurrentRequest.second.serviceResolved(nsdServiceInfo); + mCurrentRequest = null; + } + makeNextRequest(); + } + } + }); + + } + } + + +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/VendorInfo.java b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/VendorInfo.java new file mode 100644 index 0000000..595e048 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/android/discovery/recommendation/VendorInfo.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.discovery.recommendation; + +import android.content.res.Resources; + +import java.util.Arrays; + +public final class VendorInfo { + + public final String mPackageName; + public final String mVendorID; + public final String[] mDNSValues; + public final int mID; + + public VendorInfo(Resources resources, int vendor_info_id) { + mID = vendor_info_id; + String[] data = resources.getStringArray(vendor_info_id); + if ((data == null) || (data.length < 2)) { + data = new String[] { null, null }; + } + mPackageName = data[0]; + mVendorID = data[1]; + mDNSValues = (data.length > 2) ? Arrays.copyOfRange(data, 2, data.length) : new String[]{}; + } +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/example/android/discovery/recommendation/DeviceList.java b/SamsungPrinterRecommendation/app/src/main/java/com/example/android/discovery/recommendation/DeviceList.java new file mode 100644 index 0000000..2eeebc4 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/example/android/discovery/recommendation/DeviceList.java @@ -0,0 +1,32 @@ +/* + * (c) Copyright 2016 Mopria Alliance, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.discovery.recommendation; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; + +public class DeviceList extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_device_list2); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + } +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/example/android/discovery/recommendation/DeviceListFragment.java b/SamsungPrinterRecommendation/app/src/main/java/com/example/android/discovery/recommendation/DeviceListFragment.java new file mode 100644 index 0000000..94a6cb5 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/example/android/discovery/recommendation/DeviceListFragment.java @@ -0,0 +1,118 @@ +/* + * (c) Copyright 2016 Mopria Alliance, Inc. + * (c) Copyright 2016 Samsung Electronics.. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.discovery.recommendation; + +import android.content.Context; +import android.net.nsd.NsdManager; +import android.os.Bundle; +import android.support.annotation.IntRange; +import android.support.v4.app.ListFragment; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import com.android.discovery.recommendation.PrintServicePlugin; +import com.android.discovery.recommendation.ServiceRecommendationPlugin; +import com.android.discovery.recommendation.ServiceResolveQueue; +import com.samsung.discovery.recommendation.SamsungRecommendationPlugin; + +import java.util.Locale; + +public class DeviceListFragment extends ListFragment implements PrintServicePlugin.PrinterDiscoveryCallback { + + private ArrayAdapter<ServiceRecommendationPlugin> mArrayAdapter; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ServiceResolveQueue.createInstance((NsdManager)getActivity().getSystemService(Context.NSD_SERVICE)); + mArrayAdapter = new ArrayAdapter<ServiceRecommendationPlugin>(getActivity(), 0) { + + class ViewHolder { + final TextView mText1; + final TextView mText2; + public ViewHolder(TextView text1, TextView text2) { + mText1 = text1; + mText2 = text2; + } + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view; + ViewHolder holder; + if (convertView == null) { + view = getActivity().getLayoutInflater().inflate(android.R.layout.simple_list_item_2, parent, false); + view.setTag(new ViewHolder((TextView)view.findViewById(android.R.id.text1), + (TextView)view.findViewById(android.R.id.text2))); + } else { + view = convertView; + } + holder = (ViewHolder)view.getTag(); + holder.mText1.setText(getItem(position).getName()); + holder.mText2.setText(String.format(Locale.getDefault(), "%d",getItem(position).getCount())); + return view; + } + }; + mArrayAdapter.add(new SamsungRecommendationPlugin(getActivity())); + } + + @Override + public void onDestroy() { + super.onDestroy(); + ServiceResolveQueue.destroyInstance(); + } + + + @Override + public void onResume() { + super.onResume(); + for(int i = 0; i < mArrayAdapter.getCount(); i++) { + try { + mArrayAdapter.getItem(i).start(this); + } catch(Exception ignored) {} + } + } + + @Override + public void onPause() { + super.onPause(); + for(int i = 0; i < mArrayAdapter.getCount(); i++) { + try { + mArrayAdapter.getItem(i).stop(); + } catch(Exception ignored) {} + } + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + setListAdapter(mArrayAdapter); + } + + @Override + public void onChanged(@IntRange(from = 0) int numDiscoveredPrinters) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mArrayAdapter.notifyDataSetChanged(); + } + }); + } +} diff --git a/SamsungPrinterRecommendation/app/src/main/java/com/samsung/discovery/recommendation/SamsungRecommendationPlugin.java b/SamsungPrinterRecommendation/app/src/main/java/com/samsung/discovery/recommendation/SamsungRecommendationPlugin.java new file mode 100644 index 0000000..f5daa6a --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/java/com/samsung/discovery/recommendation/SamsungRecommendationPlugin.java @@ -0,0 +1,105 @@ +/*
+(c) Copyright 2016 Samsung Electronics..
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+
+package com.samsung.discovery.recommendation;
+
+import android.content.Context;
+import android.net.nsd.NsdServiceInfo;
+import android.text.TextUtils;
+
+import com.android.discovery.recommendation.MDnsUtils;
+import com.android.discovery.recommendation.ServiceRecommendationPlugin;
+import com.android.discovery.recommendation.VendorInfo;
+import com.example.android.discovery.recommendation.R;
+
+import java.util.Locale;
+import java.util.Map;
+
+public class SamsungRecommendationPlugin extends ServiceRecommendationPlugin {
+
+ private static final String TAG = "SamsungRecommendation";
+
+ private static final String ATTR_USB_MFG = "usb_MFG";
+ private static final String ATTR_MFG = "mfg";
+ private static final String ATTR_USB_MDL = "usb_MDL";
+ private static final String ATTR_MDL = "mdl";
+ private static final String ATTR_PRODUCT = "product";
+ private static final String ATTR_TY = "ty";
+
+ private static String[] mNotSupportedDevices = new String[]{
+ "SCX-5x15",
+ "SF-555P",
+ "CF-555P",
+ "SCX-4x16",
+ "SCX-4214F",
+ "CLP-500",
+ "CJX-",
+ "MJC-"
+ };
+
+ private static boolean isSupportedModel(String model) {
+ if (!TextUtils.isEmpty(model)) {
+ String modelToUpper = model.toUpperCase(Locale.US);
+ for (String unSupportedPrinter : mNotSupportedDevices) {
+ if (modelToUpper.contains(unSupportedPrinter)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public SamsungRecommendationPlugin(Context context) {
+ super(context, R.string.plugin_vendor_samsung, new VendorInfo(context.getResources(), R.array.known_print_vendor_info_for_samsung), new String[]{"_pdl-datastream._tcp"});
+ }
+
+ @Override
+ public boolean matchesCriteria(String vendor, NsdServiceInfo nsdServiceInfo) {
+ if (!TextUtils.equals(vendor, mVendorInfo.mVendorID)) return false;
+
+ String modelName = getModelName(nsdServiceInfo);
+ if (modelName != null) {
+ return (isSupportedModel(modelName));
+ }
+ return false;
+ }
+
+ private String getModelName(NsdServiceInfo resolvedDevice) {
+ Map<String,byte[]> attributes = resolvedDevice.getAttributes();
+ String usb_mfg = MDnsUtils.getString(attributes.get(ATTR_USB_MFG));
+ if (TextUtils.isEmpty(usb_mfg)) {
+ usb_mfg = MDnsUtils.getString(attributes.get(ATTR_MFG));
+ }
+
+ String usb_mdl = MDnsUtils.getString(attributes.get(ATTR_USB_MDL));
+ if (TextUtils.isEmpty(usb_mdl)) {
+ usb_mdl = MDnsUtils.getString(attributes.get(ATTR_MDL));
+ }
+
+ String modelName = null;
+ if (!TextUtils.isEmpty(usb_mfg) && !TextUtils.isEmpty(usb_mdl)) {
+ modelName = usb_mfg.trim() + " " + usb_mdl.trim();
+ } else {
+ modelName = MDnsUtils.getString(attributes.get(ATTR_PRODUCT));
+ if (TextUtils.isEmpty(modelName)) {
+ modelName = MDnsUtils.getString(attributes.get(ATTR_TY));
+ }
+ }
+
+ return modelName;
+ }
+}
diff --git a/SamsungPrinterRecommendation/app/src/main/res/layout/activity_device_list2.xml b/SamsungPrinterRecommendation/app/src/main/res/layout/activity_device_list2.xml new file mode 100644 index 0000000..62f06d2 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/layout/activity_device_list2.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.design.widget.CoordinatorLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" + android:layout_height="match_parent" android:fitsSystemWindows="true" + tools:context="com.example.android.discovery.recommendation.DeviceList"> + + <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" + android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> + + <android.support.v7.widget.Toolbar android:id="@+id/toolbar" + android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" + android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> + + </android.support.design.widget.AppBarLayout> + + <include layout="@layout/content_device_list" /> + +</android.support.design.widget.CoordinatorLayout> diff --git a/SamsungPrinterRecommendation/app/src/main/res/layout/content_device_list.xml b/SamsungPrinterRecommendation/app/src/main/res/layout/content_device_list.xml new file mode 100644 index 0000000..67e13ed --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/layout/content_device_list.xml @@ -0,0 +1,7 @@ +<fragment xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/fragment" + android:name="com.example.android.discovery.recommendation.DeviceListFragment" android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" + tools:layout="@layout/fragment_device_list" /> diff --git a/SamsungPrinterRecommendation/app/src/main/res/layout/fragment_device_list.xml b/SamsungPrinterRecommendation/app/src/main/res/layout/fragment_device_list.xml new file mode 100644 index 0000000..f6820da --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/layout/fragment_device_list.xml @@ -0,0 +1,11 @@ +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" + android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + android:paddingBottom="@dimen/activity_vertical_margin" + tools:showIn="@layout/activity_device_list2" + tools:context="com.example.android.discovery.recommendation.DeviceListFragment"> + + +</RelativeLayout> diff --git a/SamsungPrinterRecommendation/app/src/main/res/mipmap-hdpi/ic_launcher.png b/SamsungPrinterRecommendation/app/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..cde69bc --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/SamsungPrinterRecommendation/app/src/main/res/mipmap-mdpi/ic_launcher.png b/SamsungPrinterRecommendation/app/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..c133a0c --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/SamsungPrinterRecommendation/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/SamsungPrinterRecommendation/app/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..bfa42f0 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/SamsungPrinterRecommendation/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/SamsungPrinterRecommendation/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..324e72c --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/SamsungPrinterRecommendation/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/SamsungPrinterRecommendation/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..aee44e1 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/SamsungPrinterRecommendation/app/src/main/res/values-v21/styles.xml b/SamsungPrinterRecommendation/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..65d0c39 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,8 @@ +<resources>> + <style name="AppTheme.NoActionBar"> + <item name="windowActionBar">false</item> + <item name="windowNoTitle">true</item> + <item name="android:windowDrawsSystemBarBackgrounds">true</item> + <item name="android:statusBarColor">@android:color/transparent</item> + </style> +</resources> diff --git a/SamsungPrinterRecommendation/app/src/main/res/values-w820dp/dimens.xml b/SamsungPrinterRecommendation/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ +<resources> + <!-- Example customization of dimensions originally defined in res/values/dimens.xml + (such as screen margins) for screens with more than 820dp of available width. This + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> + <dimen name="activity_horizontal_margin">64dp</dimen> +</resources> diff --git a/SamsungPrinterRecommendation/app/src/main/res/values/colors.xml b/SamsungPrinterRecommendation/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#3F51B5</color> + <color name="colorPrimaryDark">#303F9F</color> + <color name="colorAccent">#FF4081</color> +</resources> diff --git a/SamsungPrinterRecommendation/app/src/main/res/values/dimens.xml b/SamsungPrinterRecommendation/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ +<resources> + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> +</resources> diff --git a/SamsungPrinterRecommendation/app/src/main/res/values/donottranslate.xml b/SamsungPrinterRecommendation/app/src/main/res/values/donottranslate.xml new file mode 100644 index 0000000..1966117 --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/values/donottranslate.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:tools="http://schemas.android.com/tools"> + <string-array name="known_print_vendor_info_for_mopria" translatable="false"> + <item>org.mopria.printplugin</item> + <item>WFDS</item> + <!-- no specific mDNS values to list --> + </string-array> + + <string-array name="known_print_vendor_info_for_hp" translatable="false"> + <item>com.hp.android.printservice</item> + <item>HP</item> + <!-- HP has used these values in mDNS records over the years --> + <item>HP</item> + <item>Hewlett-Packard</item> + <item>Hewlett Packard</item> + </string-array> + + <string-array name="known_print_vendor_info_for_samsung" translatable="false"> + <item>com.sec.app.samsungprintservice</item> + <item>Samsung Electronics</item> + <item>Samsung</item> + </string-array> + + + <array name="known_print_plugin_vendors" translatable="false"> + <item>@array/known_print_vendor_info_for_mopria</item> + <item>@array/known_print_vendor_info_for_hp</item> + <item>@array/known_print_vendor_info_for_samsung</item> + </array> +</resources> diff --git a/SamsungPrinterRecommendation/app/src/main/res/values/strings.xml b/SamsungPrinterRecommendation/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..d0af03a --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ +<resources> + <string name="app_name">AndroidDiscovery</string> + <string name="title_activity_device_list">DeviceList</string> + <string name="plugin_vendor_morpia">Mopria</string> + <string name="plugin_vendor_hp">HP</string> + <string name="plugin_vendor_samsung">Samsung</string> +</resources> diff --git a/SamsungPrinterRecommendation/app/src/main/res/values/styles.xml b/SamsungPrinterRecommendation/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..44f664f --- /dev/null +++ b/SamsungPrinterRecommendation/app/src/main/res/values/styles.xml @@ -0,0 +1,17 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <!-- Customize your theme here. --> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + </style> + <style name="AppTheme.NoActionBar"> + <item name="windowActionBar">false</item> + <item name="windowNoTitle">true</item> + </style> + <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> + <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> + +</resources> diff --git a/SamsungPrinterRecommendation/build.gradle b/SamsungPrinterRecommendation/build.gradle new file mode 100644 index 0000000..03bced9 --- /dev/null +++ b/SamsungPrinterRecommendation/build.gradle @@ -0,0 +1,23 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.1.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/SamsungPrinterRecommendation/gradle/wrapper/gradle-wrapper.jar b/SamsungPrinterRecommendation/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 0000000..8c0fb64 --- /dev/null +++ b/SamsungPrinterRecommendation/gradle/wrapper/gradle-wrapper.jar diff --git a/SamsungPrinterRecommendation/gradle/wrapper/gradle-wrapper.properties b/SamsungPrinterRecommendation/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..04b1b82 --- /dev/null +++ b/SamsungPrinterRecommendation/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Oct 01 09:52:57 PDT 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip diff --git a/SamsungPrinterRecommendation/gradlew b/SamsungPrinterRecommendation/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/SamsungPrinterRecommendation/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/SamsungPrinterRecommendation/gradlew.bat b/SamsungPrinterRecommendation/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/SamsungPrinterRecommendation/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/SamsungPrinterRecommendation/settings.gradle b/SamsungPrinterRecommendation/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/SamsungPrinterRecommendation/settings.gradle @@ -0,0 +1 @@ +include ':app' |