diff --git a/android-smsmms/build.gradle b/android-smsmms/build.gradle index a3ab1d49..c5282cc6 100644 --- a/android-smsmms/build.gradle +++ b/android-smsmms/build.gradle @@ -17,6 +17,7 @@ * along with QKSMS. If not, see . */ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { compileSdkVersion 25 @@ -40,4 +41,8 @@ dependencies { compile 'com.klinkerapps:logger:1.0.3' compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0' + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" +} +repositories { + mavenCentral() } \ No newline at end of file diff --git a/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.java b/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.java deleted file mode 100755 index 01d9b5cd..00000000 --- a/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright 2013 Jacob Klinker - * - * 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.klinker.android.send_message; - -import android.os.Build; -import com.klinker.android.logger.Log; - -/** - * Class to house all of the settings that can be used to send a message - * - * @author Jake Klinker - */ -public class Settings { - - public static final int DEFAULT_SUBSCRIPTION_ID = -1; - - // MMS options - private String mmsc; - private String proxy; - private String port; - private String userAgent; - private String uaProfUrl; - private String uaProfTagName; - - // SMS options - private boolean deliveryReports; - private boolean split; - private boolean splitCounter; - private boolean stripUnicode; - private String signature; - private String preText; - private boolean sendLongAsMms; - private int sendLongAsMmsAfter; - - // SIM options - private int subscriptionId = DEFAULT_SUBSCRIPTION_ID; - - /** - * Default constructor to set everything to default values - */ - public Settings() { - this("", "", "0", true, false, false, false, false, "", "", true, 3, true, DEFAULT_SUBSCRIPTION_ID); - } - - /** - * Copy constuctor - * @param s is the Settings object to copy from - */ - public Settings(Settings s) { - this.mmsc = s.getMmsc(); - this.proxy = s.getProxy(); - this.port = s.getPort(); - this.userAgent = s.getAgent(); - this.uaProfUrl = s.getUserProfileUrl(); - this.uaProfTagName = s.getUaProfTagName(); - this.deliveryReports = s.getDeliveryReports(); - this.split = s.getSplit(); - this.splitCounter = s.getSplitCounter(); - this.stripUnicode = s.getStripUnicode(); - this.signature = s.getSignature(); - this.preText = s.getPreText(); - this.sendLongAsMms = s.getSendLongAsMms(); - this.sendLongAsMmsAfter = s.getSendLongAsMmsAfter(); - this.subscriptionId = s.getSubscriptionId(); - } - - /** - * @param mmsc is the address contained by the apn to send MMS to - * @param proxy is the proxy address in the apn to send MMS through - * @param port is the port from the apn to send MMS through - * @param group is a boolean specifying whether or not to send messages with multiple recipients as a group MMS message - * @param deliveryReports is a boolean to retrieve delivery reports from SMS messages - * @param split is a boolean to manually split messages (shouldn't be necessary, but some carriers do not split on their own) - * @param splitCounter adds a split counter to the front of all split messages - * @param stripUnicode replaces many unicode characters with their gsm compatible equivalent to allow for sending 160 characters instead of 70 - * @param signature a signature to attach at the end of each message - * @param sendLongAsMms if a message is too long to be multiple SMS, convert it to a single MMS - * @param sendLongAsMmsAfter is an int of how many pages long an SMS must be before it is split - * @param subscriptionId is the ID for the SIM card. Can be null unless you are trying to use dual SIM support - */ - public Settings(String mmsc, String proxy, String port, boolean group, - boolean deliveryReports, boolean split, boolean splitCounter, - boolean stripUnicode, String signature, String preText, boolean sendLongAsMms, - int sendLongAsMmsAfter, boolean useSystemSending, Integer subscriptionId) { - this.mmsc = mmsc; - this.proxy = proxy; - this.port = port; - this.userAgent = ""; - this.uaProfUrl = ""; - this.uaProfTagName = ""; - this.deliveryReports = deliveryReports; - this.split = split; - this.splitCounter = splitCounter; - this.stripUnicode = stripUnicode; - this.signature = signature; - this.preText = preText; - this.sendLongAsMms = sendLongAsMms; - this.sendLongAsMmsAfter = sendLongAsMmsAfter; - - this.subscriptionId = subscriptionId != null ? subscriptionId : DEFAULT_SUBSCRIPTION_ID; - } - - /** - * Sets MMSC - * - * @param mmsc is the mmsc from the apns - */ - public void setMmsc(String mmsc) { - this.mmsc = mmsc; - } - - /** - * Sets the MMS Proxy - * - * @param proxy is the proxy from the apns - */ - public void setProxy(String proxy) { - this.proxy = proxy; - } - - /** - * Sets the Port - * - * @param port is the port from the apns - */ - public void setPort(String port) { - this.port = port; - } - - /** - * Sets the user agent - * - * @param agent is the agent to send http request with - */ - public void setAgent(String agent) { this.userAgent = agent; } - - /** - * Sets the user agent profile url - * - * @param userProfileUrl is the user agent profile url - */ - public void setUserProfileUrl(String userProfileUrl) { this.uaProfUrl = userProfileUrl; } - - /** - * Sets the user agent profile tag name - * - * @param tagName the tag name to use - */ - public void setUaProfTagName(String tagName) { this.uaProfTagName = tagName; } - - /** - * Sets whether to receive delivery reports from SMS messages - * - * @param deliveryReports is a boolean to retrieve delivery reports from SMS messages - */ - public void setDeliveryReports(boolean deliveryReports) { - this.deliveryReports = deliveryReports; - } - - /** - * Sets whether to manually split an SMS or not - * - * @param split is a boolean to manually split messages (shouldn't be necessary, but some carriers do not split on their own) - */ - public void setSplit(boolean split) { - this.split = split; - } - - /** - * Adds a split counter to the front of each split SMS - * - * @param splitCounter adds a split counter to the front of all split messages - */ - public void setSplitCounter(boolean splitCounter) { - this.splitCounter = splitCounter; - } - - /** - * Sets whether or not unicode characters should be sent or converted to their GSM compatible alternative - * - * @param stripUnicode replaces many unicode characters with their gsm compatible equivalent to allow for sending 160 characters instead of 70 - */ - public void setStripUnicode(boolean stripUnicode) { - this.stripUnicode = stripUnicode; - } - - /** - * Sets a signature to be attached to each message - * - * @param signature a signature to attach at the end of each message - */ - public void setSignature(String signature) { - this.signature = signature; - } - - /** - * Sets the text to be sent before an SMS message - * - * @param preText text to be attached to the beginning of each message - */ - public void setPreText(String preText) { - this.preText = preText; - } - - /** - * Sets whether long SMS or Voice messages should instead be sent by a single MMS - * - * @param sendLongAsMms if a message is too long to be multiple SMS, convert it to a single MMS - */ - public void setSendLongAsMms(boolean sendLongAsMms) { - this.sendLongAsMms = sendLongAsMms; - } - - /** - * Sets when we should convert SMS or Voice into an MMS message - * - * @param sendLongAsMmsAfter is an int of how many pages long an SMS must be before it is split - */ - public void setSendLongAsMmsAfter(int sendLongAsMmsAfter) { - this.sendLongAsMmsAfter = sendLongAsMmsAfter; - } - - /** - * Set the subscription ID that should be used for sending. It isn't applied to receiving at this time. - * - * @param subscriptionId null if you do not want to use one. - */ - public void setSubscriptionId(Integer subscriptionId) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || subscriptionId == null) { - // we won't allow you to go away from the default if your device doesn't support it - this.subscriptionId = DEFAULT_SUBSCRIPTION_ID; - } else { - this.subscriptionId = subscriptionId; - } - } - - /** - * @return MMSC to send through - */ - public String getMmsc() { - return this.mmsc; - } - - /** - * @return the proxy to send MMS through - */ - public String getProxy() { - return this.proxy; - } - - /** - * @return the port to send MMS through - */ - public String getPort() { - return this.port; - } - - /** - * @return the user agent to send mms with - */ - public String getAgent() { return this.userAgent; } - - /** - * @return the user agent profile url to send mms with - */ - public String getUserProfileUrl() { return this.uaProfUrl; } - - /** - * @return the user agent profile tag name - */ - public String getUaProfTagName() { return this.uaProfTagName; } - - /** - * @return whether or not to request delivery reports on SMS messages - */ - public boolean getDeliveryReports() { - return this.deliveryReports; - } - - /** - * @return whether or not SMS should be split manually - */ - public boolean getSplit() { - return this.split; - } - - /** - * @return whether or not a split counter should be attached to manually split messages - */ - public boolean getSplitCounter() { - return this.splitCounter; - } - - /** - * @return whether or not unicode chars should be substituted with gms characters - */ - public boolean getStripUnicode() { - return this.stripUnicode; - } - - /** - * @return the signature attached to SMS messages - */ - public String getSignature() { - return this.signature; - } - - /** - * @return the text attached to the beginning of each SMS - */ - public String getPreText() { - return this.preText; - } - - /** - * @return whether or not to send long SMS or Voice as single MMS - */ - public boolean getSendLongAsMms() { - return this.sendLongAsMms; - } - - /** - * @return number of pages sms must be to send instead as MMS - */ - public int getSendLongAsMmsAfter() { - return this.sendLongAsMmsAfter; - } - - /** - * @return the subscription ID or the default if one isn't set. - */ - public int getSubscriptionId() { - return subscriptionId; - } - - /** - * Enables or disables logging for debug purposes logs will be written both to your devices - * logcat log and an external file you can specify so that other users can assist with debugging easily - * if you would like - * - * @param debugLogging true to enable debug logging when sending and receiving messages - * @param path the external path on the sd card to write the log to - */ - public static void setDebugLogging(boolean debugLogging, String path) { - Log.setDebug(debugLogging); - Log.setPath(path); - } -} diff --git a/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.kt b/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.kt new file mode 100755 index 00000000..1cfb823e --- /dev/null +++ b/android-smsmms/src/main/java/com/klinker/android/send_message/Settings.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2013 Jacob Klinker + * + * 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.klinker.android.send_message + +import android.os.Build + +/** + * Class to house all of the settings that can be used to send a message + */ +class Settings @JvmOverloads constructor( + // MMS options + var mmsc: String? = "", + var proxy: String? = "", + var port: String? = "0", + var agent: String? = "", + var userProfileUrl: String? = "", + var uaProfTagName: String? = "", + + // SMS options + var deliveryReports: Boolean = false, + var split: Boolean = false, + var splitCounter: Boolean = false, + var stripUnicode: Boolean = false, + var signature: String? = null, + var preText: String? = null, + var sendLongAsMms: Boolean = true, + var sendLongAsMmsAfter: Int = 3, + subscriptionId: Int = DEFAULT_SUBSCRIPTION_ID) { + + // SIM options + var subscriptionId: Int = subscriptionId + set(value) { + // we won't allow you to go away from the default if your device doesn't support it + field = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || false) { + DEFAULT_SUBSCRIPTION_ID + } else { + value + } + } + + companion object { + const val DEFAULT_SUBSCRIPTION_ID = -1 + } +}