Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding configurable sms length calculations #2

Merged
merged 1 commit into from
Sep 4, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/de/ub0r/android/websms/DefaultSMSLengthCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.ub0r.android.websms;

import android.os.Parcel;
import android.os.Parcelable;
import de.ub0r.android.lib.apis.TelephonyWrapper;
import de.ub0r.android.websms.connector.common.SMSLengthCalculator;

/**
*
* A SMSLengthCalculator that just delegates to
* TelephonyWrapper.getInstance().calculateLength
*
* @author Fintan Fairmichael
*
*/
public class DefaultSMSLengthCalculator implements SMSLengthCalculator {
private static final long serialVersionUID = -1021281060248896432L;

@Override
public void writeToParcel(final Parcel dest, final int flags) {
}

@Override
public int describeContents() {
return 0;
}

@Override
public int[] calculateLength(final String messageBody,
final boolean use7bitOnly) {
return TelephonyWrapper.getInstance().calculateLength(messageBody,
use7bitOnly);
}

public static final Parcelable.Creator<DefaultSMSLengthCalculator> CREATOR = new Parcelable.Creator<DefaultSMSLengthCalculator>() {
public DefaultSMSLengthCalculator createFromParcel(final Parcel in) {
return new DefaultSMSLengthCalculator();
}

public DefaultSMSLengthCalculator[] newArray(final int size) {
return new DefaultSMSLengthCalculator[size];
}
};
}
15 changes: 9 additions & 6 deletions src/de/ub0r/android/websms/WebSMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@
import de.ub0r.android.lib.DonationHelper;
import de.ub0r.android.lib.Market;
import de.ub0r.android.lib.apis.ContactsWrapper;
import de.ub0r.android.lib.apis.TelephonyWrapper;
import de.ub0r.android.websms.connector.common.Connector;
import de.ub0r.android.websms.connector.common.ConnectorCommand;
import de.ub0r.android.websms.connector.common.ConnectorSpec;
import de.ub0r.android.websms.connector.common.Log;
import de.ub0r.android.websms.connector.common.SMSLengthCalculator;
import de.ub0r.android.websms.connector.common.Utils;
import de.ub0r.android.websms.connector.common.ConnectorSpec.SubConnectorSpec;

Expand Down Expand Up @@ -134,9 +134,8 @@ public class WebSMS extends FragmentActivity implements OnClickListener,
AD_KEYWORDS.add("amazon");
}

/** {@link TelephonyWrapper}. */
private static final TelephonyWrapper TWRAPPER = TelephonyWrapper
.getInstance();
/** Default sms length calculator */
private static final SMSLengthCalculator SMS_LENGTH_CALCULATOR = new DefaultSMSLengthCalculator();

/** Static reference to running Activity. */
private static WebSMS me;
Expand Down Expand Up @@ -341,8 +340,12 @@ public void afterTextChanged(final Editable s) {
len += sig.length();
WebSMS.this.tvPaste.setVisibility(View.GONE);
if (len > TEXT_LABLE_MIN_LEN) {
int[] l = TWRAPPER.calculateLength(s.toString() + sig,
false);
SMSLengthCalculator calc = prefsConnectorSpec
.getSMSLengthCalculator();
if (calc == null) {
calc = SMS_LENGTH_CALCULATOR;
}
int[] l = calc.calculateLength(s.toString() + sig, false);
WebSMS.this.etTextLabel.setText(l[0] + "/" + l[2]);
WebSMS.this.etTextLabel.setVisibility(View.VISIBLE);
} else {
Expand Down