/*
 * Copyright (C) 2008 ZXing authors
 *
 * 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.google.zxing.client.android.result;

import com.google.zxing.client.android.R;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.SMSParsedResult;

import android.app.Activity;
import android.telephony.PhoneNumberUtils;

/**
 * Handles SMS addresses, offering a choice of composing a new SMS or MMS message.
 *
 * @author dswitkin@google.com (Daniel Switkin)
 */
public final class SMSResultHandler extends ResultHandler {
  private static final int[] buttons = {
      R.string.button_sms,
      R.string.button_mms
  };

  public SMSResultHandler(Activity activity, ParsedResult result) {
    super(activity, result);
  }

  @Override
  public int getButtonCount() {
    return buttons.length;
  }

  @Override
  public int getButtonText(int index) {
    return buttons[index];
  }

  @Override
  public void handleButtonPress(int index) {
    SMSParsedResult smsResult = (SMSParsedResult) getResult();
    switch (index) {
      case 0:
        sendSMS(smsResult.getNumber(), smsResult.getBody());
        break;
      case 1:
        sendMMS(smsResult.getNumber(), smsResult.getSubject(), smsResult.getBody());
        break;
    }
  }

  @Override
  public CharSequence getDisplayContents() {
    SMSParsedResult smsResult = (SMSParsedResult) getResult();
    StringBuffer contents = new StringBuffer();
    ParsedResult.maybeAppend(PhoneNumberUtils.formatNumber(smsResult.getNumber()), contents);
    ParsedResult.maybeAppend(smsResult.getVia(), contents);
    ParsedResult.maybeAppend(smsResult.getSubject(), contents);
    ParsedResult.maybeAppend(smsResult.getBody(), contents);
    ParsedResult.maybeAppend(smsResult.getTitle(), contents);
    return contents.toString();
  }

  @Override
  public int getDisplayTitle() {
    return R.string.result_sms;
  }
}

@@ -1587,16 +1587,103 @@
 case 0:%0A
+        // Don't know of a way yet to express a SENDTO intent with multiple recipients%0A
         
@@ -1701,34 +1701,38 @@
 Result.getNumber
+s
 ()
+%5B0%5D
 , smsResult.getB
@@ -1803,18 +1803,22 @@
 etNumber
+s
 ()
+%5B0%5D
 , smsRes
@@ -2059,97 +2059,246 @@
     
-ParsedResult.maybeAppend(PhoneNumberUtils.
+String%5B%5D rawNumbers = smsResult.getNumbers();%0A    String%5B%5D 
 format
+ted
 Number
-(smsResult.getNumber()), contents);
+s = new String%5BrawNumbers.length%5D;%0A    for (int i = 0; i %3C rawNumbers.length; i++) %7B%0A      formattedNumbers%5Bi%5D = PhoneNumberUtils.formatNumber(rawNumbers%5Bi%5D);%0A    %7D
 %0A   
@@ -2327,26 +2327,24 @@
 end(
-smsResult.getVia()
+formattedNumbers
 , co
@@ -2481,70 +2481,8 @@
 s);%0A
-    ParsedResult.maybeAppend(smsResult.getTitle(), contents);%0A
     

Update sms: and geo: handling to better respect new RFCs