hi,
i have made a dialer class(activity) when user press the dial button
he get navigate form this activity to other activity on which i have
given a disconnect button but when user press on disconnect button my
application crash and show the error of null pointer exception
............................................................................................................................................
i have check the log file and notice that my dialer class first get
pause then it simply destroy .i want that my dialer class not to
get destroy it should be on pause state
Dialer.java
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.doubango.imsdroid.CallDialog;
import org.doubango.imsdroid.Main;
import org.doubango.imsdroid.R;
import org.doubango.imsdroid.Model.Configuration;
import org.doubango.imsdroid.Model.Configuration.CONFIGURATION_ENTRY;
import
org.doubango.imsdroid.Model.Configuration.CONFIGURATION_SECTION;
import org.doubango.imsdroid.Screens.Dialpad.OnDialKeyListener;
import org.doubango.imsdroid.Services.Impl.ServiceManager;
import org.doubango.imsdroid.media.MediaType;
import org.doubango.imsdroid.sip.MyAVSession;
import org.doubango.imsdroid.sip.MyAVSession.CallState;
import org.doubango.imsdroid.utils.UriUtils;
import org.doubango.imsdroid.Services.Impl.ConfigurationService;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.Vibrator;
import android.telephony.PhoneNumberFormattingTextWatcher;
import android.telephony.PhoneNumberUtils;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.DialerKeyListener;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Dialer extends Activity implements OnClickListener,
OnLongClickListener, OnDialKeyListener,TextWatcher{
private String etDisplayName;
private String etIMPU;
private String etIMPI;
private String etPassword;
private String etRealm;
//private CheckBox cbEarlyIMS;
public void getParameterMain(String usersip,String username1,String
password,String relam,String server1)
{
etDisplayName=username1;
etIMPI=username1;
etIMPU=usersip;
etRealm=relam;
//DEFAULT_PCSCF_HOST=server1;
//DEFAULT_XUI=usersip;
etPassword=password;
System.out.println("usersip"+usersip);
System.out.println("username"+username1);
System.out.println("password"+password);
System.out.println("relam"+relam);
System.out.println("server"+server1);
}
private CallState state;
public enum CallState{
NONE,
CALL_INCOMING,
CALL_INPROGRESS,
REMOTE_RINGING,
EARLY_MEDIA,
INCALL,
CALL_TERMINATED,
}
/** The length of DTMF tones in milliseconds */
private static final int TONE_LENGTH_MS = 150;
/** The DTMF tone volume relative to other sounds in the stream */
private static final int TONE_RELATIVE_VOLUME = 80;
/** Stream type used to play the DTMF tones off call, and mapped
to the volume control keys */
private static final int DIAL_TONE_STREAM_TYPE =
AudioManager.STREAM_MUSIC;
private ToneGenerator toneGenerator;
private Object toneGeneratorLock = new Object();
private static final String THIS_FILE = "Dialer";
private Drawable digitsBackground, digitsEmptyBackground;
private EditText digits;
private ImageButton dialButton,dialVButton, deleteButton;
private Vibrator vibrator;
private View digitDialer, textDialer, rootView;
private boolean isDigit;
private int[] buttonsToAttach = new int[] {
R.id.dialButton,
R.id.deleteButton,
R.id.domainButton,
//Text dialer
R.id.dialTextButton,
R.id.deleteTextButton,
R.id.domainTextButton
};
//private Activity contextToBindTo = this;
//private ServiceConnection connection = new ServiceConnection(){
/*public void onServiceConnected(ComponentName arg0, IBinder
arg1) {
//service = ISipService.Stub.asInterface(arg1);
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
//service = null;
}
};*/
private MyAVSession avSession;
private int ringerMode;
private GestureDetector gestureDetector;
private Dialpad dialPad;
public TextView status;
private EditText dialUser;
private EditText dialDomain;
private PreferencesWrapper prefsWrapper;
private ScreenAV screenav;
private Timer toneTimer;
//TODO : add an option for that
private boolean useDialtone = false;
private Object ConfigurationService;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// //Bind to the service
// if(getParent() != null) {
// contextToBindTo = getParent();
// }
prefsWrapper = new PreferencesWrapper(this);
// setContentView(R.layout.dialer_activity);
setContentView(R.layout.dialer_activity);
// Store the backgrounds objects that will be in use later
Resources r = getResources();
digitsBackground =
r.getDrawable(R.drawable.btn_dial_textfield_active);
digitsEmptyBackground =
r.getDrawable(R.drawable.btn_dial_textfield_normal);
// Store some object that could be useful later
dialButton = (ImageButton) findViewById(R.id.dialButton);
dialVButton = (ImageButton) findViewById(R.id.dialVButton);
deleteButton = (ImageButton) findViewById(R.id.deleteButton);
digits = (EditText) findViewById(R.id.digitsText);
dialPad = (Dialpad) findViewById(R.id.dialPad);
digitDialer = (View) findViewById(R.id.dialer_digit);
textDialer = (View) findViewById(R.id.dialer_text);
dialUser = (EditText) findViewById(R.id.dialtxt_user);
// dialDomain = (EditText) findViewById(R.id.dialtext_domain);
rootView = (View) findViewById(R.id.toplevel);
// status = (TextView) findViewById(R.id.ankush);
//status.setText("Registered");
// @ is a special char for layouts, I didn't find another way
to set
@ as text in xml
//TextView atxt = (TextView) findViewById(R.id.arobase_txt);
//atxt.setText("@");
//ScreenAV.updateState(avSession.getState());
String number=digits.toString();
isDigit = prefsWrapper.startIsDigit();
digitDialer.setVisibility(isDigit?View.VISIBLE:View.GONE);
textDialer.setVisibility(isDigit?View.GONE:View.VISIBLE);//gone
dialPad.setOnDialKeyListener(this);
initButtons();
this.dialButton.setOnClickListener(this.ibAudioCall_OnClickListener);
this.dialVButton.setOnClickListener(this.ibVideoCall_OnClickListener);
String phoneno = (String)
getIntent().getCharSequenceExtra("org.doubango.imsdroid");
digits.setText(phoneno);
// //Add gesture detector
gestureDetector = new GestureDetector(this, new
SwitchDialerGestureDetector());
//
//Add switcher gesture detector
OnTouchListener touchTransmiter = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
digitDialer.setOnTouchListener(touchTransmiter);
textDialer.setOnTouchListener(touchTransmiter);
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(THIS_FILE, "Dialer destroyed");
}
@Override
protected void onResume() {
super.onResume();
//Bind service
// contextToBindTo.bindService(new Intent(contextToBindTo,
SipService.class), connection, Context.BIND_AUTO_CREATE);
//
if(useDialtone ) {
//Create dialtone just for user feedback
synchronized (toneGeneratorLock) {
if(toneTimer == null) {
toneTimer = new Timer();
}
if (toneGenerator == null) {
try {
toneGenerator = new
ToneGenerator(DIAL_TONE_STREAM_TYPE,
TONE_RELATIVE_VOLUME);
//Allow user to control dialtone
setVolumeControlStream(DIAL_TONE_STREAM_TYPE);
} catch (RuntimeException e) {
//If impossible, nothing to do
toneGenerator = null;
}
}
}
}
//Create the virator
vibrator = (Vibrator)
getSystemService(Context.VIBRATOR_SERVICE);
// //Store the current ringer mode
AudioManager am = (AudioManager)
getSystemService(Context.AUDIO_SERVICE);
ringerMode = am.getRingerMode();
}
@Override
protected void onPause() {
Configuration.DEFAULT_DISPLAY_NAME=etDisplayName;
Configuration.DEFAULT_IMPU=etIMPU;
Configuration.DEFAULT_IMPI=etIMPI;
Configuration.DEFAULT_PASSWORD=etPassword;
Configuration.DEFAULT_REALM=etRealm;
super.onPause();
System.out.println("after pause"+etIMPI);
//Unbind service
//TODO : should be done by a cleaner way (check if bind
function
has been launched is better than check if bind has been done)
// if(service != null) {
// contextToBindTo.unbindService(connection);
// }
//Destroy dialtone
synchronized (toneGeneratorLock) {
if (toneGenerator != null) {
toneGenerator.release();
toneGenerator = null;
}
if(toneTimer != null) {
toneTimer.cancel();
toneTimer.purge();
toneTimer = null;
}
}
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
// Hide soft keyboard, if visible (it's fugly over button
dialer).
// The only known case where this will be true is when
launching the dialer with
// ACTION_DIAL via a soft keyboard. we dismiss it here
because we don't
// have a window token yet in onCreate / onNewIntent
InputMethodManager inputMethodManager =
(InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(digits.getWindowToken(),
0);
}
}
private void attachButtonListener(int id) {
Log.d(THIS_FILE, "Attaching "+id);
ImageButton button = (ImageButton) findViewById(id);
button.setOnClickListener(this);
if (id == R.id.button0 || id == R.id.button1 || id ==
R.id.deleteButton) {
button.setOnLongClickListener(this);
}
}
private void initButtons() {
for (int buttonId : buttonsToAttach) {
attachButtonListener(buttonId);
}
digits.setOnClickListener(this);
digits.setKeyListener(DialerKeyListener.getInstance());
PhoneNumberFormattingTextWatcher digitFormater = new
PhoneNumberFormattingTextWatcher();
digits.addTextChangedListener(digitFormater);
//// digits.addTextChangedListener(this);
digits.setInputType(android.text.InputType.TYPE_NULL);
digits.setCursorVisible(true);
//afterTextChanged(digits.getText());
}
private void playTone(int tone) {
boolean silent = (ringerMode ==
AudioManager.RINGER_MODE_SILENT) ||
(ringerMode == AudioManager.RINGER_MODE_VIBRATE);
//TODO add user pref for that
boolean vibrate = silent || true;
if(vibrate) {
vibrator.vibrate(30);
}
if(silent) {
return;
}
synchronized (toneGeneratorLock) {
if (toneGenerator == null) {
return;
}
toneGenerator.startTone(tone);
//TODO : see if it could not be factorized
toneTimer.schedule(new StopTimerTask(), TONE_LENGTH_MS);
}
}
class StopTimerTask extends TimerTask{
@Override
public void run() {
synchronized (toneGeneratorLock) {
if (toneGenerator == null) {
return;
}
toneGenerator.stopTone();
}
}
}
private void keyPressed(int keyCode) {
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
digits.onKeyDown(keyCode, event);
}
private OnClickListener ibAudioCall_OnClickListener = new
OnClickListener(){
//TabHome.onPause();
@Override
public void onClick(View v) {
/*Intent fake = new Intent(Dialer.this, ScreenAV.class);
fake.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(fake);
finish();*/
ScreenAV.makeCall(Dialer.this.digits.getText().toString().trim(),
MediaType.Audio);
//Dialer.onPause();
Intent screencall = new Intent(Dialer.this,
CallSharad.class);
//screencall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
screencall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(screencall);
finish();
//ScreenAV.updateState(CallState states);
}
};
private OnClickListener ibVideoCall_OnClickListener = new
OnClickListener(){
@Override
public void onClick(View v) {
ScreenAV.makeCall(Dialer.this.digits.getText().toString().trim(),
MediaType.AudioVideo);
Intent screencall1 = new Intent(Dialer.this,
ScreenAV.class);
screencall1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(screencall1);
finish();
}
};
public void onClick(View view) {
int view_id = view.getId();
Log.d(THIS_FILE, "Im clicked....");
switch (view_id) {
case R.id.deleteButton: {
keyPressed(KeyEvent.KEYCODE_DEL);
break;
}
case R.id.deleteTextButton: {
dialUser.getText().clear();
dialDomain.getText().clear();
break;
}
case R.id.dialButton:
case R.id.dialTextButton: {
//placeCall();
break;
}
case R.id.domainButton: {
flipView(true);
break;
}
case R.id.domainTextButton: {
flipView(false);
break;
}
case R.id.digitsText: {
digits.setCursorVisible(true);
break;
}
}
}
public boolean onLongClick(View view) {
switch (view.getId()) {
case R.id.button0: {
keyPressed(KeyEvent.KEYCODE_PLUS);
return true;
}
case R.id.deleteButton: {
digits.getText().clear();
deleteButton.setPressed(false);
return true;
}
}
return false;
}
public void afterTextChanged(Editable input) {
final boolean notEmpty = digits.length() != 0;
digits.setBackgroundDrawable(notEmpty? digitsBackground :
digitsEmptyBackground);
dialButton.setEnabled(notEmpty);
deleteButton.setEnabled(notEmpty);
}
private Intent serviceIntent;
private void flipView(boolean forward) {
if(forward && !isDigit) {
return;
}
if(!forward && isDigit) {
return;
}
if(serviceIntent != null){
stopService(serviceIntent);
}
// serviceIntent = null;
// Intent accountIntent = new Intent(this, AccountsList.class);
// accountIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(accountIntent);
}
//
// // Gesture detector
private class SwitchDialerGestureDetector extends
GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY) {
if(e1 == null || e2 == null) {
return false;
}
float deltaX = e2.getX() - e1.getX();
float deltaY = e2.getY() - e1.getY();
if(Math.abs(deltaX) > Math.abs(deltaY * 5)) {
if(deltaX > 0 ) {
flipView(true);
}else {
flipView(false);
}
return true;
}
return false;
}
}
//
@Override
public void onTrigger(int keyCode, int dialTone) {
playTone(dialTone);
keyPressed(keyCode);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
//Nothing to do here
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int
arg3) {
afterTextChanged(digits.getText());
}
}
.............................................................................................................................................package
org.doubango.imsdroid.Screens;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Timer;
import org.doubango.imsdroid.CallDialog;
import org.doubango.imsdroid.IMSDroid;
import org.doubango.imsdroid.Main;
import org.doubango.imsdroid.R;
import org.doubango.imsdroid.Model.Configuration;
import org.doubango.imsdroid.Model.Configuration.CONFIGURATION_ENTRY;
import
org.doubango.imsdroid.Model.Configuration.CONFIGURATION_SECTION;
import org.doubango.imsdroid.Screens.ScreenAV.ProxSensor;
import org.doubango.imsdroid.Services.IScreenService;
import org.doubango.imsdroid.Services.Impl.ServiceManager;
import org.doubango.imsdroid.events.IInviteEventHandler;
import org.doubango.imsdroid.events.InviteEventArgs;
import org.doubango.imsdroid.media.MediaType;
import org.doubango.imsdroid.sip.MyAVSession;
import org.doubango.imsdroid.sip.MySipStack;
import org.doubango.imsdroid.sip.MyAVSession.CallState;
import org.doubango.imsdroid.utils.UriUtils;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;
import org.doubango.imsdroid.Screens.ScreenAV;
import org.doubango.tinyWRAP.SipSession;
public class CallSharad extends Screen
{ public static HashMap<String, MyAVSession> sessionsvalue;
private static SimpleDateFormat __timerFormat;
private long startTime;
private final Timer timerInCall;
private final Timer timerSuicide;
private final Timer timerBlankPacket;
private ViewFlipper fvFlipper;
private ImageView ivDialer;
private LinearLayout llVideoLocal;
private LinearLayout llVideoRemote;
private ImageView ivState;
private TextView tvInfo;
private TextView tvTime;
private TextView tvRemoteUri;
private Button btBack2Call;
private Button cancelbutton;
private ImageButton btDtmf_0;
private ImageButton btDtmf_1;
private ImageButton btDtmf_2;
private ImageButton btDtmf_3;
private ImageButton btDtmf_4;
private ImageButton btDtmf_5;
private ImageButton btDtmf_6;
private ImageButton btDtmf_7;
private ImageButton btDtmf_8;
private ImageButton btDtmf_9;
private ImageButton btDtmf_Sharp;
private ImageButton btDtmf_Star;
private ProxSensor proxSensor;
private KeyguardLock keyguardLock;
private final IScreenService screenService;
private static final int SELECT_CONTENT = 1;
private final static int MENU_PICKUP = 0;
private final static int MENU_HANGUP= 1;
private final static int MENU_HOLD_RESUME = 2;
private final static int MENU_SEND_STOP_VIDEO = 3;
private final static int MENU_SHARE_CONTENT = 4;
private final static int MENU_SPEAKER = 5;
private static final String TAG = null;
private static MyAVSession avSession ;
private ScreenAV avScreen;
public CallSharad() {
super(SCREEN_TYPE.AV_T, null);
this.timerInCall = new Timer();
this.timerSuicide = new Timer();
this.timerBlankPacket = new Timer();
this.screenService = ServiceManager.getScreenService();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen_sharad);
OrientationEventListener mListener;
// retrieve id
this.id = getIntent().getStringExtra("id");
//this.avSession =
MyAVSession.getSession(Long.parseLong(this.id));
// MyAVSession.getCallEventHandler().setAvScreen(this);
// get controls
this.fvFlipper = (ViewFlipper)
this.findViewById(R.id.screen_av_flipperView);
this.ivDialer = (ImageView)
this.findViewById(R.id.screen_av_imageView_dialer);
this.llVideoLocal =
(LinearLayout)this.findViewById(R.id.screen_av_linearLayout_video_local);
this.llVideoRemote =
(LinearLayout)this.findViewById(R.id.screen_av_linearLayout_video_remote);
this.ivState =
(ImageView)this.findViewById(R.id.screen_av_imageView_state);
this.tvInfo =
(TextView)this.findViewById(R.id.screen_av_textView_info);
this.tvTime =
(TextView)this.findViewById(R.id.screen_av_textView_time);
this.tvRemoteUri =
(TextView)this.findViewById(R.id.screen_av_textView_remoteUri);
this.btBack2Call =
(Button)this.findViewById(R.id.screen_av_button_back2call);
this.cancelbutton=(Button)this.findViewById(R.id.cancelcall);
this.btDtmf_0 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_0);
this.btDtmf_1 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_1);
this.btDtmf_2 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_2);
this.btDtmf_3 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_3);
this.btDtmf_4 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_4);
this.btDtmf_5 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_5);
this.btDtmf_6 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_6);
this.btDtmf_7 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_7);
this.btDtmf_8 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_8);
this.btDtmf_9 =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_9);
this.btDtmf_Sharp =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_sharp);
this.btDtmf_Star =
(ImageButton)this.findViewById(R.id.screen_av_imageButton_star);
this.cancelbutton.setOnClickListener(this.cancelbutton_OnClickListener);
// Hide video preview
this.llVideoLocal.setVisibility(View.GONE);
}
//add by sharad
public void simplenext()
{ try{
id = getIntent().getStringExtra("id");
avSession = MyAVSession.getSession(Long.parseLong(this.id));
System.out.println("new value..in clas sharad>"+avSession);
Intent sharadIntent = new Intent(CallSharad.this,
TabHome.class);
sharadIntent.setFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(sharadIntent);
finish();
}
catch(Exception ex)
{
System.out.println("in the callsharad"+ex);
}
}
/*public void updateState(CallState state){ //change to the public
this.updateState(state, null);
}
public void updateState(CallState state, String phrase){
if(this.avSession== null){
return;
}
switch(state){
case CALL_INPROGRESS:
this.tvInfo.setText("In progress ...");
this.ivState.setImageResource(R.drawable.bullet_ball_glass_grey_16);
this.runOnUiThread(new Runnable(){
@Override
public void run() {
View layout =
CallDialog.getView(CallSharad.this,
UriUtils.getDisplayName(CallSharad.this.avSession.getRemoteParty()),
null
, new
OnClickListener() {
@Override
public void onClick(View v) {
CallSharad.this.tvInfo
.setText("Ending the call...");
CallSharad.this.avSession.hangUp();
}
});
layout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
));
CallSharad.this.llVideoRemote.removeAllViews();
CallSharad.this.llVideoRemote.addView(layout);
}
});
break;
/*case CALL_INCOMING:
//this.tvInfo.setText(String.format("Incoming Call from %s",
UriUtils.getDisplayName(remoteUri)));
this.ivState.setImageResource(R.drawable.bullet_ball_glass_grey_16);
this.runOnUiThread(new Runnable(){
@Override
public void run() {
View layout =
CallDialog.getView(CallSharad.this,
UriUtils.getDisplayName(CallSharad.this.avSession.getRemoteParty()),
new OnClickListener() {
@Override
public void onClick(View v) {
CallSharad.this.avSession.acceptCall();
}
}, new OnClickListener() {
@Override
public void onClick(View v) {
CallSharad.this.tvInfo
.setText("Ending the call...");
CallSharad.this.avSession.hangUp();
}
});
layout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
));
CallSharad.this.llVideoRemote.removeAllViews();
CallSharad.this.llVideoRemote.addView(layout);
}
});
break;
*/
/*case INCALL:
this.tvInfo.setText("In call");
this.ivState.setImageResource(R.drawable.bullet_ball_glass_green_16);
this.startTime =
this.avSession.getStartTime();
//this.timerInCall.schedule(this.timerTaskInCall, 0, 1000);
// Video consumer
this.llVideoRemote.removeAllViews();
if(this.avSession.getMediaType() ==
MediaType.AudioVideo ||
this.avSession.getMediaType() == MediaType.Video){
final View remote_preview =
MyAVSession.getVideoConsumer().startPreview();
if(remote_preview != null){
final ViewParent
viewParent = remote_preview.getParent();
if(viewParent != null
&& viewParent instanceof ViewGroup){
((ViewGroup)(viewParent)).removeView(remote_preview);
}
this.llVideoRemote.addView(remote_preview);
}
}
// Video producer
//this.startStopVideo(this.avSession.isSendingVideo());
break;
case CALL_TERMINATED:
CallSharad.this.tvInfo.setText(phrase == null ?
"Call
Terminated" : phrase);
CallSharad.this.ivState.setImageResource(R.drawable.bullet_ball_glass_red_16);
/* schedule suicide */
//this.timerSuicide.schedule(this.timerTaskSuicide, new Date(new
Date().getTime() + 1500));
//this.timerTaskInCall.cancel();
/*this.timerBlankPacket.cancel();
break;
}
if(this.avSession.isLocalHeld()){
this.tvInfo.setText("Call placed on hold");
}
else if(this.avSession.isRemoteHeld()){
this.tvInfo.setText("Placed on hold by remote party");
}
}
*/
//call ending button
private OnClickListener cancelbutton_OnClickListener = new
OnClickListener(){
@Override
public void onClick(View v) {
ScreenAV screendis=new ScreenAV();
//MyAVSession.disconneted();
System.out.println("//call sharad disconneted\\");
screendis.disconneted();
//HashMap session=(HashMap)
MyAVSession.sessions.values();
// System.out.println("vvvv"+session);
//System.out.println("//sharadkumar\\");
//avSession=avScreen.SessionValues();
// sessionsvalue=MyAVSession.getSession();
//if(session!=null){
// session.hangUp();
// long id = session.getId();
// session.delete();
//MyAVSession.sessions.remove(id);
//tvInfo.setText("Ending the call...");
//avSession=avScreen.SessionValues();
// System.out.println("second value
hang"+session);
//avSession.hangUp();
//System.out.println("//sharadkumar\\");
//Intent sharadIntent = new
Intent(CallSharad.this,
TabHome.class);
//sharadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//startActivity(sharadIntent);
//finish();
//}
//
ScreenAV.makeCall(Dialer.this.digits.getText().toString().trim(),
MediaType.AudioVideo);
// Intent screencall = new Intent(Dialer.this,
CallSharad.class);
// screencall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(screencall);
// finish();
}
};
/* private OnClickListener dtmf_OnClickListener = new OnClickListener()
{
@Override
public void onClick(View v) {
if(CallSharad.this.avSession == null){
return;
}
if(v == CallSharad.this.btDtmf_0){
if(CallSharad.this.avSession.sendDTMF(0)){
ServiceManager.getSoundService().playDTMF(0);
}
}
else if(v == CallSharad.this.btDtmf_1){
if(CallSharad.this.avSession.sendDTMF(1)){
ServiceManager.getSoundService().playDTMF(1);
}
}
else if(v == CallSharad.this.btDtmf_2){
if(CallSharad.this.avSession.sendDTMF(2)){
ServiceManager.getSoundService().playDTMF(2);
}
}
else if(v == CallSharad.this.btDtmf_3){
if(CallSharad.this.avSession.sendDTMF(3)){
ServiceManager.getSoundService().playDTMF(3);
}
}
else if(v == CallSharad.this.btDtmf_4){
if(CallSharad.this.avSession.sendDTMF(4)){
ServiceManager.getSoundService().playDTMF(4);
}
}
else if(v == CallSharad.this.btDtmf_5){
if(CallSharad.this.avSession.sendDTMF(5)){
ServiceManager.getSoundService().playDTMF(5);
}
}
else if(v == CallSharad.this.btDtmf_6){
if(CallSharad.this.avSession.sendDTMF(6)){
ServiceManager.getSoundService().playDTMF(6);
}
}
else if(v == CallSharad.this.btDtmf_7){
if(CallSharad.this.avSession.sendDTMF(7)){
ServiceManager.getSoundService().playDTMF(7);
}
}
else if(v == CallSharad.this.btDtmf_8){
if(CallSharad.this.avSession.sendDTMF(8)){
ServiceManager.getSoundService().playDTMF(8);
}
}
else if(v == CallSharad.this.btDtmf_9){
if(CallSharad.this.avSession.sendDTMF(9)){
ServiceManager.getSoundService().playDTMF(9);
}
}
else if(v == CallSharad.this.btDtmf_Star){
if(CallSharad.this.avSession.sendDTMF(10)){
ServiceManager.getSoundService().playDTMF(10);
}
}
else if(v == CallSharad.this.btDtmf_Sharp){
if(CallSharad.this.avSession.sendDTMF(11)){
ServiceManager.getSoundService().playDTMF(11);
}
}
}
};*/
private void startStopVideo(boolean start){
if(this.avSession== null || (this.avSession.getMediaType() !=
MediaType.AudioVideo && this.avSession.getMediaType() !=
MediaType.Video)){
return;
}
this.avSession.setSendingVideo(start);
this.llVideoLocal.removeAllViews();
if(start){
this.timerBlankPacket.cancel();
final View local_preview =
MyAVSession.getVideoProducer().startPreview();
if(local_preview != null){
final ViewParent viewParent =
local_preview.getParent();
if(viewParent != null && viewParent instanceof
ViewGroup){
((ViewGroup)(viewParent)).removeView(local_preview);
}
this.llVideoLocal.addView(local_preview);
}
}
this.llVideoLocal.setVisibility(start ? View.VISIBLE :
View.GONE);
}
// from here handling of the call will be done sharad
@Override
public boolean haveMenu(){
return true;
}
@Override
public boolean createOptionsMenu(Menu menu){
if(this.avSession == null){
return false;
}
MenuItem itemPickUp = menu.add(0, CallSharad.MENU_PICKUP, 0,
"Answer").setIcon(R.drawable.phone_pick_up_48);
MenuItem itemHangUp = menu.add(0, CallSharad.MENU_HANGUP, 0,
"Hang-
up").setIcon(R.drawable.phone_hang_up_48);
MenuItem itemHoldResume = menu.add(0,
CallSharad.MENU_HOLD_RESUME,
0, "Hold").setIcon(R.drawable.phone_hold_48);
MenuItem itemSendStopVideo = menu.add(1,
CallSharad.MENU_SEND_STOP_VIDEO, 0, "Send
Video").setIcon(R.drawable.video_start_48);
MenuItem itemShareContent = menu.add(1,
CallSharad.MENU_SHARE_CONTENT, 0, "Share
Content").setIcon(R.drawable.image_gallery_48);
MenuItem itemSpeaker = menu.add(1, CallSharad.MENU_SPEAKER, 0,
"Speaker ON").setIcon(R.drawable.phone_speaker_48);
switch(this.avSession.getState()){
case CALL_INCOMING:
itemPickUp.setEnabled(true);
itemHangUp.setEnabled(true);
itemHoldResume.setEnabled(false);
itemSpeaker.setEnabled(false);
itemSendStopVideo.setEnabled(false);
itemShareContent.setEnabled(false);
break;
case CALL_INPROGRESS:
itemPickUp.setEnabled(false);
itemHangUp.setEnabled(true);
itemHoldResume.setEnabled(false);
itemSpeaker.setEnabled(false);
itemSendStopVideo.setEnabled(false);
itemShareContent.setEnabled(false);
break;
case INCALL:
itemPickUp.setIcon(R.drawable.dialer_48);
itemPickUp.setEnabled(true);
//itemPickUp.setEnabled(false);
itemHangUp.setEnabled(true);
itemHoldResume.setEnabled(true);
itemSpeaker.setEnabled(true);
itemSpeaker.setTitle(((AudioManager)getSystemService(Context.AUDIO_SERVICE)).isSpeakerphoneOn()
?
"Speaker OFF" : "Speaker ON");
if((this.avSession.getMediaType() ==
MediaType.AudioVideo ||
this.avSession.getMediaType() == MediaType.Video)){
itemSendStopVideo.setTitle(this.avSession.isSendingVideo()? "Stop
Video" : "Send Video").setIcon(this.avSession.isSendingVideo()?
R.drawable.video_stop_48 : R.drawable.video_start_48);
itemSendStopVideo.setEnabled(true);
}
else{
itemSendStopVideo.setEnabled(false);
}
itemShareContent.setEnabled(true);
itemHoldResume.setTitle(this.avSession.isLocalHeld()? "Resume" :
"Hold").setIcon(this.avSession.isLocalHeld()?
R.drawable.phone_resume_48 : R.drawable.phone_hold_48);
break;
case CALL_TERMINATED:
itemPickUp.setEnabled(false);
itemHangUp.setEnabled(false);
itemHoldResume.setEnabled(false);
itemSpeaker.setEnabled(false);
itemSendStopVideo.setEnabled(false);
itemShareContent.setEnabled(false);
break;
}
return true;
}
public static boolean makeCall(String remoteUri, MediaType mediaType)
{
if(MyAVSession.getFirstId() != null){
Log.e(CallSharad.TAG, "There is already an outgoing
audio/video
session");
return false;
}
String validUri = UriUtils.makeValidSipUri(remoteUri);
if(validUri == null){
// Show DialogError
return false;
}
else{
remoteUri = validUri;
if(remoteUri.startsWith("tel:")){
// E.164 number => use ENUM protocol
final MySipStack sipStack =
ServiceManager.getSipService().getStack();
if(sipStack != null){
String phoneNumber =
UriUtils.getValidPhoneNumber(remoteUri);
if(phoneNumber != null){
System.out.println("make call");
String enumDomain =
ServiceManager.getConfigurationService().getString(CONFIGURATION_SECTION.GENERAL,
CONFIGURATION_ENTRY.ENUM_DOMAIN,
Configuration.DEFAULT_GENERAL_ENUM_DOMAIN);
String sipUri =
sipStack.dnsENUM("E2U+SIP", phoneNumber,
enumDomain);
if(sipUri != null){
remoteUri = sipUri;
}
}
}
}
}
MyAVSession avSession =
MyAVSession.createOutgoingSession(ServiceManager.getSipService().getStack(),
mediaType);
System.out.println(avSession);
avSession.setRemoteParty(remoteUri); // HACK
ServiceManager.getScreenService().show(CallSharad.class, new
Long(avSession.getId()).toString());
switch(mediaType){
case AudioVideo:
case Video:
System.out.println("make call");
return avSession.makeVideoCall(remoteUri);
default:
return avSession.makeAudioCall(remoteUri);
}
//}
/*public static class AVInviteEventHandler implements
IInviteEventHandler
{
final static String TAG =
AVInviteEventHandler.class.getCanonicalName();
private CallSharad callsharad;
final AudioManager audioManager;
final PowerManager.WakeLock wakeLock;
public AVInviteEventHandler(){
ServiceManager.getSipService().addInviteEventHandler(this);
this.audioManager =
(AudioManager)IMSDroid.getContext().getSystemService(Context.AUDIO_SERVICE);
PowerManager pm = (PowerManager)
IMSDroid.getContext().getSystemService(Context.POWER_SERVICE);
this.wakeLock = pm == null ? null :
pm.newWakeLock(PowerManager.ON_AFTER_RELEASE |
PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, AVInviteEventHandler.TAG);
}
@Override
protected void finalize() throws Throwable {
ServiceManager.getSipService().removeInviteEventHandler(this);
super.finalize();
}
void setAvScreen(CallSharad callsharad){
this.callsharad = callsharad;
}
@Override
public long getId(){
if(this.callsharad != null && this.callsharad.avSession
!= null){
return this.callsharad.avSession.getId();
}
return -1;
}
/*...@override
public boolean canHandle(long id){
return (MyAVSession.getSession(id) != null);
}
@Override
public boolean onInviteEvent(Object sender, InviteEventArgs e) {
final String phrase = e.getPhrase();
final MyAVSession avSession;
if((avSession =
MyAVSession.getSession(e.getSessionId())) == null){
return false;
}
switch(e.getType()){
case INCOMING:
ServiceManager.showAVCallNotif(R.drawable.phone_call_25,
"Incoming call");
avSession.setState(CallState.CALL_INCOMING);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.updateState(CallState.CALL_INCOMING);
}});
}
if(this.wakeLock != null &&
!this.wakeLock.isHeld()){
this.wakeLock.acquire();
}
ServiceManager.vibrate(500);
ServiceManager.getSoundService().playRingTone();
break;
case INPROGRESS:
ServiceManager.showAVCallNotif(R.drawable.phone_call_25,
"Outgoing Call");
avSession.setState(CallState.CALL_INPROGRESS);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.updateState(CallState.CALL_INPROGRESS);
}});
}
break;
case RINGING:
ServiceManager.getSoundService().playRingBackTone();
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.tvInfo.setText(phrase);
AVInviteEventHandler.this.callsharad.ivState.setImageResource(R.drawable.bullet_ball_glass_grey_16);
}});
}
break;
case EARLY_MEDIA:
if (Integer.parseInt(Build.VERSION.SDK)
< 5){
this.audioManager.setMode(AudioManager.MODE_IN_CALL);
}
this.audioManager.setSpeakerphoneOn(false);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
ServiceManager.getSoundService().stopRingBackTone();
ServiceManager.getSoundService().stopRingTone();
// Notification
AVInviteEventHandler.this.callsharad.tvInfo.setText(phrase);
}});
}
break;
case CONNECTED:
ServiceManager.getSoundService().stopRingBackTone();
ServiceManager.getSoundService().stopRingTone();
ServiceManager.showAVCallNotif(R.drawable.phone_call_25, "In
Call");
if (Integer.parseInt(Build.VERSION.SDK)
< 5){
this.audioManager.setMode(AudioManager.MODE_IN_CALL);
}
this.audioManager.setSpeakerphoneOn(false);
avSession.setState(CallState.INCALL);
if(this.wakeLock != null &&
this.wakeLock.isHeld()){
this.wakeLock.release();
}
if(this.callsharad != null){
// Send blank packets to open
NAT pinhole
if(this.callsharad.avSession !=
null &&
this.callsharad.avSession.getMediaType() == MediaType.AudioVideo ||
this.callsharad.avSession.getMediaType() == MediaType.Video){
//
this.callsharad.timerBlankPacket.schedule(this.callsharad.timerTaskBlankPacket,
0, 250);
}
// Update screen state
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.updateState(CallState.INCALL);
}});
}
break;
case DISCONNECTED:
case TERMWAIT:
ServiceManager.getSoundService().stopRingBackTone();
ServiceManager.getSoundService().stopRingTone();
ServiceManager.cancelAVCallNotif();
if(avSession.getState() ==
CallState.CALL_TERMINATED){
// already terminated by
termwait
break;
}
avSession.setState(CallState.CALL_TERMINATED);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.updateState(CallState.CALL_TERMINATED,
phrase);
}});
}
if(this.wakeLock != null &&
this.wakeLock.isHeld()){
this.wakeLock.release();
}
ServiceManager.vibrate(100);
MyAVSession.releaseSession(e.getSessionId());
this.audioManager.setMode(AudioManager.MODE_NORMAL);
break;
case LOCAL_HOLD_OK:
avSession.setLocalHold(true);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.tvInfo.setText("Call
placed on hold");
}});
}
break;
case LOCAL_HOLD_NOK:
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.tvInfo.setText("Failed to
place remote party on hold");
}});
}
break;
case LOCAL_RESUME_OK:
avSession.setLocalHold(false);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.tvInfo.setText("Call
taken off hold");
}});
}
break;
case LOCAL_RESUME_NOK:
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.tvInfo.setText("Failed to
unhold call");
}});
}
break;
case REMOTE_HOLD:
avSession.setRemoteHold(true);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.tvInfo.setText("Placed on
hold by remote party");
}});
}
break;
case REMOTE_RESUME:
avSession.setRemoteHold(false);
if(this.callsharad != null){
this.callsharad.runOnUiThread(new Runnable() {
public void run() {
AVInviteEventHandler.this.callsharad.tvInfo.setText("Taken off
hold by remote party");
}});
}
break;
}
return true;
}*/
}
}
please help me
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en