/*
* Copyright (C) 2009 Show SMS 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.bydavy.android.showsms;
//~--- non-JDK imports --------------------------------------------------------
import java.util.ArrayList;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bydavy.model.showsms.Contact;
import com.bydavy.model.showsms.SSMessage;
import com.bydavy.util.showsms.AppLog;
/**
* Quick reply
*
* @version 1.0, 09/11/08
* @author Davy L.
*/
public class QuickReplyActivity extends Activity {
//~--- fields -------------------------------------------------------------
/** Field description */
private final String BUNDLE_REPLY_TEXT_KEY = "REPLY_TEXT";
/** Height and Weight of the photo */
private final int PHOTO_HEIGHT_WIDTH = 80;
/** Field description */
private SSMessage message = null;
/** Field description */
private TextView bodyTV;
/** Field description */
private TextView hourTV;
/** Field description */
private TextView nameTV;
/** Field description */
private ImageView photoIV;
/** Field description */
private EditText quickReplyET;
/** Field description */
private Button sendB;
//~--- methods ------------------------------------------------------------
/**
* Method description
*
*
* @param savedInstanceState
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppLog.v("QuickReplyActivity : onCreate()");
setContentView(R.layout.quick_reply);
// Layout View
nameTV = (TextView) findViewById(R.id.PreviewNameTV);
photoIV = (ImageView) findViewById(R.id.PreviewPhotoSenderImageView);
hourTV = (TextView) findViewById(R.id.PreviewTVHour);
bodyTV = (TextView) findViewById(R.id.QuickReplyBodyTV);
quickReplyET = (EditText) findViewById(R.id.QuickReplyET);
// bouton envoyer
sendB = (Button) findViewById(R.id.QuickReplySendB);
sendB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sendMessage();
}
});
message = SSMessage.constructFromBundle(getIntent().getExtras());
String reply = null;
if (savedInstanceState != null) {
reply = (String) savedInstanceState.get(BUNDLE_REPLY_TEXT_KEY);
}
populateViews(message, reply);
}
public static final String MMS_PACKAGE_NAME = "com.android.mms";
public static final String MMS_SENT_CLASS_NAME = "com.android.mms.transaction.SmsReceiver";
/**
* Method description
*
*/
public void sendMessage() {
String reply = quickReplyET.getText().toString();
String tel = message.getPerson().getPhoneNumber();
int messageCount;
Uri messageUri;
AppLog.v("QuickReplyActivity : tel " + tel + ", msg " + reply);
try {
SmsManager sm = SmsManager.getDefault();
ArrayList<String> messages = sm.divideMessage(reply);
messageCount=messages.size();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>(messageCount);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(messageCount);
messageUri = message.messageSendedToUri(getApplicationContext(), reply, System.currentTimeMillis());
for(int i=0;i<messageCount;i++)
{
Intent sentIntent=new Intent("com.android.mms.transaction.MESSAGE_SENT");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, sentIntent, 0);
sentIntents.add(pi);
Intent sentIntent2=new Intent("com.android.mms.transaction.MessageStatusReceiver.MESSAGE_STATUS_RECEIVED");
PendingIntent pi2 = PendingIntent.getBroadcast(this, 0, sentIntent2, 0);
deliveryIntents.add(pi2);
}
sm.sendMultipartTextMessage(tel, null, messages, sentIntents, deliveryIntents);
Toast.makeText(this, getString(R.string.quick_reply_msg_sent), Toast.LENGTH_LONG).show();
} catch (Exception e) {}
finish();
}
public static final String MMS_STATUS_RECEIVED_CLASS_NAME = "com.android.mms.transaction.MessageStatusReceiver";
/**
* Method description
*
*
* @param theMessage
* @param reply
*/
private void populateViews(SSMessage theMessage, String reply) {
AppLog.v("PreviewActivity : populateViews()");
Contact contact = theMessage.getPerson();
Bitmap originalPhoto = contact.getPhoto(getApplicationContext());
Bitmap photo;
photo = Bitmap.createScaledBitmap(originalPhoto, PHOTO_HEIGHT_WIDTH, PHOTO_HEIGHT_WIDTH, false);
photoIV.setImageBitmap(photo);
nameTV.setText(contact.getNameOrPhoneNumber());
hourTV.setText(theMessage.getHour(getApplicationContext()));
bodyTV.setText(theMessage.getBody());
// If a reply previously saved exist, we set the EditText
if (reply != null) {
quickReplyET.setText(reply);
}
}
/**
* Method description
*
*/
public void onStart() {
super.onStart();
AppLog.v("QuickReplyActivity : onStart()");
}
/**
* When application loose the screen
*
*/
public void onStop() {
super.onStop();
AppLog.v("QuickReplyActivity : onStop()");
}
/**
* Method description
*
*
* @param outState
*/
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
AppLog.v("QuickReplyActivity: onSaveInstanceState()");
// We save the message currently write
Editable reply = quickReplyET.getText();
outState.putString(BUNDLE_REPLY_TEXT_KEY, reply.toString());
}
/**
* Method description
*
*/
@Override
public void onDestroy() {
super.onDestroy();
AppLog.v("QuickReplyActivity: onDestroy()");
}
}
|