Removed useless mHandler.post() now that everything runs in the same thread

This commit is contained in:
Sylvain Berfini 2014-12-11 17:13:04 +01:00
parent 304565ef1a
commit 5c2265956d
13 changed files with 255 additions and 434 deletions

View file

@ -110,11 +110,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
private TextView sendImage, sendMessage, contactName, remoteComposing; private TextView sendImage, sendMessage, contactName, remoteComposing;
private AvatarWithShadow contactPicture; private AvatarWithShadow contactPicture;
private RelativeLayout uploadLayout, textLayout; private RelativeLayout uploadLayout, textLayout;
private Handler mHandler = new Handler();
private List<BubbleChat> lastSentMessagesBubbles; private List<BubbleChat> lastSentMessagesBubbles;
private HashMap<Integer, String> latestImageMessages; private HashMap<Integer, String> latestImageMessages;
private boolean useLinphoneMessageStorage; private boolean useLinphoneMessageStorage;
private ListView messagesList; private ListView messagesList;
private Handler mHandler = new Handler();
private ProgressBar progressBar; private ProgressBar progressBar;
private int bytesSent; private int bytesSent;
@ -678,21 +678,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
public void onMessageReceived(LinphoneAddress from, final LinphoneChatMessage message) { public void onMessageReceived(LinphoneAddress from, final LinphoneChatMessage message) {
if (from.asStringUriOnly().equals(sipUri)) { if (from.asStringUriOnly().equals(sipUri)) {
if (message.getText() != null) { if (message.getText() != null) {
mHandler.post(new Runnable() { adapter.refreshHistory();
@Override adapter.notifyDataSetChanged();
public void run() {
adapter.refreshHistory();
adapter.notifyDataSetChanged();
}
});
} else if (message.getExternalBodyUrl() != null) { } else if (message.getExternalBodyUrl() != null) {
mHandler.post(new Runnable() { adapter.refreshHistory();
@Override adapter.notifyDataSetChanged();
public void run() {
adapter.refreshHistory();
adapter.notifyDataSetChanged();
}
});
} }
scrollToEnd(); scrollToEnd();
} }
@ -704,38 +694,32 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
final String finalImage = finalMessage.getExternalBodyUrl(); final String finalImage = finalMessage.getExternalBodyUrl();
final State finalState=state; final State finalState=state;
if (LinphoneActivity.isInstanciated() && state != State.InProgress) { if (LinphoneActivity.isInstanciated() && state != State.InProgress) {
mHandler.post(new Runnable() { if (finalMessage != null && !finalMessage.equals("")) {
@Override LinphoneActivity.instance().onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt());
public void run() { } else if (finalImage != null && !finalImage.equals("")) {
if (finalMessage != null && !finalMessage.equals("")) { if (latestImageMessages != null && latestImageMessages.containsValue(finalImage)) {
LinphoneActivity.instance().onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt()); int id = -1;
} else if (finalImage != null && !finalImage.equals("")) { for (int key : latestImageMessages.keySet()) {
if (latestImageMessages != null && latestImageMessages.containsValue(finalImage)) { String object = latestImageMessages.get(key);
int id = -1; if (object.equals(finalImage)) {
for (int key : latestImageMessages.keySet()) { id = key;
String object = latestImageMessages.get(key); break;
if (object.equals(finalImage)) {
id = key;
break;
}
}
if (id != -1) {
LinphoneActivity.instance().onImageMessageStateChanged(sipUri, id, finalState.toInt());
}
} }
} }
if (id != -1) {
if (lastSentMessagesBubbles != null && lastSentMessagesBubbles.size() > 0) { LinphoneActivity.instance().onImageMessageStateChanged(sipUri, id, finalState.toInt());
for (BubbleChat bubble : lastSentMessagesBubbles) {
if (bubble.getNativeMessageObject() == finalMessage) {
bubble.updateStatusView(finalState);
}
}
} }
adapter.notifyDataSetChanged();
} }
}
});
if (lastSentMessagesBubbles != null && lastSentMessagesBubbles.size() > 0) {
for (BubbleChat bubble : lastSentMessagesBubbles) {
if (bubble.getNativeMessageObject() == finalMessage) {
bubble.updateStatusView(finalState);
}
}
}
adapter.notifyDataSetChanged();
} }
} }
@ -1092,12 +1076,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
@Override @Override
public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom room) { public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom room) {
if (chatRoom != null && room != null && chatRoom.getPeerAddress().asStringUriOnly().equals(room.getPeerAddress().asStringUriOnly())) { if (chatRoom != null && room != null && chatRoom.getPeerAddress().asStringUriOnly().equals(room.getPeerAddress().asStringUriOnly())) {
mHandler.post(new Runnable() { remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
@Override
public void run() {
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
}
});
} }
} }
} }

View file

@ -37,7 +37,6 @@ import android.graphics.Bitmap;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.ContextMenu; import android.view.ContextMenu;
@ -60,8 +59,6 @@ import android.widget.TextView;
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener { public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener {
private Handler mHandler = new Handler();
private LayoutInflater mInflater; private LayoutInflater mInflater;
private List<String> mConversations, mDrafts; private List<String> mConversations, mDrafts;
private ListView chatList; private ListView chatList;
@ -112,15 +109,10 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
} }
public void refresh() { public void refresh() {
mHandler.post(new Runnable() { mConversations = LinphoneActivity.instance().getChatList();
@Override mDrafts = LinphoneActivity.instance().getDraftChatList();
public void run() { mConversations.removeAll(mDrafts);
mConversations = LinphoneActivity.instance().getChatList(); hideAndDisplayMessageIfNoChat();
mDrafts = LinphoneActivity.instance().getDraftChatList();
mConversations.removeAll(mDrafts);
hideAndDisplayMessageIfNoChat();
}
});
} }
private boolean isVersionUsingNewChatStorage() { private boolean isVersionUsingNewChatStorage() {

View file

@ -28,7 +28,6 @@ import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -52,8 +51,6 @@ import android.widget.TextView;
*/ */
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public class ContactsFragment extends Fragment implements OnClickListener, OnItemClickListener { public class ContactsFragment extends Fragment implements OnClickListener, OnItemClickListener {
private Handler mHandler = new Handler();
private LayoutInflater mInflater; private LayoutInflater mInflater;
private ListView contactsList; private ListView contactsList;
private TextView allContacts, linphoneContacts, newContact, noSipContact, noContact; private TextView allContacts, linphoneContacts, newContact, noSipContact, noContact;
@ -278,17 +275,12 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
} }
public void invalidate() { public void invalidate() {
mHandler.post(new Runnable() { if (searchField != null && searchField.getText().toString().length() > 0) {
@Override searchContacts(searchField.getText().toString());
public void run() { } else {
if (searchField != null && searchField.getText().toString().length() > 0) { changeContactsAdapter();
searchContacts(searchField.getText().toString()); }
} else { contactsList.setSelectionFromTop(lastKnownPosition, 0);
changeContactsAdapter();
}
contactsList.setSelectionFromTop(lastKnownPosition, 0);
}
});
} }
class ContactsListAdapter extends BaseAdapter implements SectionIndexer { class ContactsListAdapter extends BaseAdapter implements SectionIndexer {

View file

@ -30,7 +30,6 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.ContextMenu; import android.view.ContextMenu;
@ -53,7 +52,6 @@ import android.widget.TextView;
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public class HistoryFragment extends Fragment implements OnClickListener, OnChildClickListener, OnGroupClickListener { public class HistoryFragment extends Fragment implements OnClickListener, OnChildClickListener, OnGroupClickListener {
private Handler mHandler = new Handler();
private ExpandableListView historyList; private ExpandableListView historyList;
private LayoutInflater mInflater; private LayoutInflater mInflater;
private TextView allCalls, missedCalls, edit, ok, deleteAll, noCallHistory, noMissedCallHistory; private TextView allCalls, missedCalls, edit, ok, deleteAll, noCallHistory, noMissedCallHistory;
@ -164,16 +162,11 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil
} }
private void expandAllGroups() { private void expandAllGroups() {
mHandler.post(new Runnable() { for (int groupToExpand = 0; groupToExpand < historyList.getExpandableListAdapter().getGroupCount(); groupToExpand++) {
@Override if (!historyList.isGroupExpanded(groupToExpand)) {
public void run() { historyList.expandGroup(groupToExpand);
for (int groupToExpand = 0; groupToExpand < historyList.getExpandableListAdapter().getGroupCount(); groupToExpand++) {
if (!historyList.isGroupExpanded(groupToExpand)) {
historyList.expandGroup(groupToExpand);
}
}
} }
}); }
} }
private String getCorrespondentDisplayName(LinphoneCallLog log) { private String getCorrespondentDisplayName(LinphoneCallLog log) {

View file

@ -75,9 +75,8 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
private final static int SECONDS_BEFORE_DENYING_CALL_UPDATE = 30000; private final static int SECONDS_BEFORE_DENYING_CALL_UPDATE = 30000;
private static InCallActivity instance; private static InCallActivity instance;
private Handler mHandler = new Handler(); private Handler mControlsHandler = new Handler();
private Handler mControlsHandler = new Handler();
private Runnable mControls; private Runnable mControls;
private ImageView switchCamera; private ImageView switchCamera;
private TextView pause, hangUp, dialer, video, micro, speaker, options, addCall, transfer, conference; private TextView pause, hangUp, dialer, video, micro, speaker, options, addCall, transfer, conference;
@ -281,91 +280,75 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
} }
private void refreshInCallActions() { private void refreshInCallActions() {
if (mHandler == null) { if (!LinphonePreferences.instance().isVideoEnabled()) {
mHandler = new Handler(); video.setEnabled(false);
} } else {
mHandler.post(new Runnable() { if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) {
@Override video.setBackgroundResource(R.drawable.video_on);
public void run() { } else {
if (!LinphonePreferences.instance().isVideoEnabled()) { video.setBackgroundResource(R.drawable.video_off);
video.setEnabled(false);
} else {
if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) {
video.setBackgroundResource(R.drawable.video_on);
} else {
video.setBackgroundResource(R.drawable.video_off);
}
}
try {
if (isSpeakerEnabled) {
speaker.setBackgroundResource(R.drawable.speaker_on);
routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on);
routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
} else {
speaker.setBackgroundResource(R.drawable.speaker_off);
routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off);
if (BluetoothManager.getInstance().isUsingBluetoothAudioRoute()) {
routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on);
} else {
routeReceiver.setBackgroundResource(R.drawable.route_receiver_on);
routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
}
}
} catch (NullPointerException npe) {
Log.e("Bluetooth: Audio routes menu disabled on tablets for now (4)");
}
if (isMicMuted) {
micro.setBackgroundResource(R.drawable.micro_off);
} else {
micro.setBackgroundResource(R.drawable.micro_on);
}
if (LinphoneManager.getLc().getCallsNb() > 1) {
conference.setVisibility(View.VISIBLE);
pause.setVisibility(View.GONE);
} else {
conference.setVisibility(View.GONE);
pause.setVisibility(View.VISIBLE);
List<LinphoneCall> pausedCalls = LinphoneUtils.getCallsInState(LinphoneManager.getLc(), Arrays.asList(State.Paused));
if (pausedCalls.size() == 1) {
pause.setBackgroundResource(R.drawable.pause_on);
} else {
pause.setBackgroundResource(R.drawable.pause_off);
}
}
} }
}); }
try {
if (isSpeakerEnabled) {
speaker.setBackgroundResource(R.drawable.speaker_on);
routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on);
routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
} else {
speaker.setBackgroundResource(R.drawable.speaker_off);
routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off);
if (BluetoothManager.getInstance().isUsingBluetoothAudioRoute()) {
routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on);
} else {
routeReceiver.setBackgroundResource(R.drawable.route_receiver_on);
routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
}
}
} catch (NullPointerException npe) {
Log.e("Bluetooth: Audio routes menu disabled on tablets for now (4)");
}
if (isMicMuted) {
micro.setBackgroundResource(R.drawable.micro_off);
} else {
micro.setBackgroundResource(R.drawable.micro_on);
}
if (LinphoneManager.getLc().getCallsNb() > 1) {
conference.setVisibility(View.VISIBLE);
pause.setVisibility(View.GONE);
} else {
conference.setVisibility(View.GONE);
pause.setVisibility(View.VISIBLE);
List<LinphoneCall> pausedCalls = LinphoneUtils.getCallsInState(LinphoneManager.getLc(), Arrays.asList(State.Paused));
if (pausedCalls.size() == 1) {
pause.setBackgroundResource(R.drawable.pause_on);
} else {
pause.setBackgroundResource(R.drawable.pause_off);
}
}
} }
private void enableAndRefreshInCallActions() { private void enableAndRefreshInCallActions() {
if (mHandler == null) { addCall.setEnabled(LinphoneManager.getLc().getCallsNb() < LinphoneManager.getLc().getMaxCalls());
mHandler = new Handler(); transfer.setEnabled(getResources().getBoolean(R.bool.allow_transfers));
} options.setEnabled(!getResources().getBoolean(R.bool.disable_options_in_call) && (addCall.isEnabled() || transfer.isEnabled()));
mHandler.post(new Runnable() {
@Override video.setEnabled(true);
public void run() { micro.setEnabled(true);
addCall.setEnabled(LinphoneManager.getLc().getCallsNb() < LinphoneManager.getLc().getMaxCalls()); if(!isTablet()){
transfer.setEnabled(getResources().getBoolean(R.bool.allow_transfers)); speaker.setEnabled(true);
options.setEnabled(!getResources().getBoolean(R.bool.disable_options_in_call) && (addCall.isEnabled() || transfer.isEnabled())); }
transfer.setEnabled(true);
video.setEnabled(true); pause.setEnabled(true);
micro.setEnabled(true); dialer.setEnabled(true);
if(!isTablet()){ conference.setEnabled(true);
speaker.setEnabled(true);
}
transfer.setEnabled(true);
pause.setEnabled(true);
dialer.setEnabled(true);
conference.setEnabled(true);
refreshInCallActions(); refreshInCallActions();
}
});
} }
public void updateStatusFragment(StatusFragment statusFragment) { public void updateStatusFragment(StatusFragment statusFragment) {
@ -459,45 +442,34 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
return; return;
} }
mHandler.post(new Runnable() { if (isVideoEnabled) {
@Override video.setEnabled(true);
public void run() { LinphoneCallParams params = call.getCurrentParamsCopy();
if (isVideoEnabled) { params.setVideoEnabled(false);
video.setEnabled(true); LinphoneManager.getLc().updateCall(call, params);
LinphoneCallParams params = call.getCurrentParamsCopy(); } else {
params.setVideoEnabled(false); video.setEnabled(false);
LinphoneManager.getLc().updateCall(call, params); videoProgress.setVisibility(View.VISIBLE);
} else { if (!call.getRemoteParams().isLowBandwidthEnabled()) {
video.setEnabled(false); LinphoneManager.getInstance().addVideo();
videoProgress.setVisibility(View.VISIBLE); } else {
if (!call.getRemoteParams().isLowBandwidthEnabled()) { displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
LinphoneManager.getInstance().addVideo();
} else {
displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
}
}
} }
}); }
} }
public void displayCustomToast(final String message, final int duration) { public void displayCustomToast(final String message, final int duration) {
mHandler.post(new Runnable() { LayoutInflater inflater = getLayoutInflater();
@Override View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));
public void run() {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));
TextView toastText = (TextView) layout.findViewById(R.id.toastMessage); TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
toastText.setText(message); toastText.setText(message);
final Toast toast = new Toast(getApplicationContext()); final Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER, 0, 0); toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(duration); toast.setDuration(duration);
toast.setView(layout); toast.setView(layout);
toast.show(); toast.show();
}
});
} }
private void switchVideo(final boolean displayVideo) { private void switchVideo(final boolean displayVideo) {
@ -506,25 +478,20 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
return; return;
} }
mHandler.post(new Runnable() { //Check if the call is not terminated
@Override if(call.getState() == State.CallEnd || call.getState() == State.CallReleased) return;
public void run() {
//Check if the call is not terminated if (!displayVideo) {
if(call.getState() == State.CallEnd || call.getState() == State.CallReleased) return; showAudioView();
} else {
if (!displayVideo) { if (!call.getRemoteParams().isLowBandwidthEnabled()) {
showAudioView(); LinphoneManager.getInstance().addVideo();
} else { if (videoCallFragment == null || !videoCallFragment.isVisible())
if (!call.getRemoteParams().isLowBandwidthEnabled()) { showVideoView();
LinphoneManager.getInstance().addVideo(); } else {
if (videoCallFragment == null || !videoCallFragment.isVisible()) displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
showVideoView();
} else {
displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
}
}
} }
}); }
} }
private void showAudioView() { private void showAudioView() {
@ -1080,13 +1047,7 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
} }
if(!LinphonePreferences.instance().isVideoEnabled()){ if(!LinphonePreferences.instance().isVideoEnabled()){
mHandler.post(new Runnable() { video.setEnabled(true);
@Override
public void run() {
video.setEnabled(true);
}
});
} }
if (state == State.IncomingReceived) { if (state == State.IncomingReceived) {
@ -1095,28 +1056,18 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
} }
if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) { if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) {
mHandler.post(new Runnable() { video.setEnabled(false);
@Override if(isVideoEnabled(call)){
public void run() { showAudioView();
video.setEnabled(false); }
if(isVideoEnabled(call)){
showAudioView();
}
}
});
} }
if (state == State.Resuming) { if (state == State.Resuming) {
if(LinphonePreferences.instance().isVideoEnabled()){ if(LinphonePreferences.instance().isVideoEnabled()){
mHandler.post(new Runnable() { status.refreshStatusItems(call, isVideoEnabled(call));
@Override if(call.getCurrentParamsCopy().getVideoEnabled()){
public void run() { showVideoView();
status.refreshStatusItems(call, isVideoEnabled(call)); }
if(call.getCurrentParamsCopy().getVideoEnabled()){
showVideoView();
}
}
});
} }
} }
@ -1129,24 +1080,14 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
enableAndRefreshInCallActions(); enableAndRefreshInCallActions();
if (status != null) { if (status != null) {
mHandler.post(new Runnable() { videoProgress.setVisibility(View.GONE);
@Override status.refreshStatusItems(call, isVideoEnabled(call));
public void run() {
videoProgress.setVisibility(View.GONE);
status.refreshStatusItems(call, isVideoEnabled(call));
}
});
} }
} }
refreshInCallActions(); refreshInCallActions();
mHandler.post(new Runnable() { refreshCallList(getResources());
@Override
public void run() {
refreshCallList(getResources());
}
});
if (state == State.CallUpdatedByRemote) { if (state == State.CallUpdatedByRemote) {
// If the correspondent proposes video while audio call // If the correspondent proposes video while audio call
@ -1160,18 +1101,14 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled(); boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
boolean autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests(); boolean autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests();
if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) { if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) {
mHandler.post(new Runnable() { showAcceptCallUpdateDialog();
public void run() {
showAcceptCallUpdateDialog(); timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) {
public void onTick(long millisUntilFinished) { }
timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) { public void onFinish() {
public void onTick(long millisUntilFinished) { } acceptCallUpdate(false);
public void onFinish() { }
acceptCallUpdate(false); }.start();
}
}.start();
}
});
} }
// else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) { // else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) {
// mHandler.post(new Runnable() { // mHandler.post(new Runnable() {
@ -1183,11 +1120,7 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
// } // }
} }
mHandler.post(new Runnable() { transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
public void run() {
transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
}
});
} }
private void showAcceptCallUpdateDialog() { private void showAcceptCallUpdateDialog() {
@ -1199,12 +1132,7 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
@Override @Override
public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted, String authenticationToken) { public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted, String authenticationToken) {
if (status != null) { if (status != null) {
mHandler.post(new Runnable() { status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled());
@Override
public void run() {
status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled());
}
});
} }
} }
@ -1291,7 +1219,6 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
} }
mControls = null; mControls = null;
mControlsHandler = null; mControlsHandler = null;
mHandler = null;
unbindDrawables(findViewById(R.id.topLayout)); unbindDrawables(findViewById(R.id.topLayout));
instance = null; instance = null;

View file

@ -61,7 +61,6 @@ import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.Fragment.SavedState; import android.support.v4.app.Fragment.SavedState;
@ -108,7 +107,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
private Fragment dialerFragment, messageListenerFragment, messageListFragment, friendStatusListenerFragment; private Fragment dialerFragment, messageListenerFragment, messageListFragment, friendStatusListenerFragment;
private SavedState dialerSavedState; private SavedState dialerSavedState;
private boolean preferLinphoneContacts = false, isAnimationDisabled = false, isContactPresenceDisabled = true; private boolean preferLinphoneContacts = false, isAnimationDisabled = false, isContactPresenceDisabled = true;
private Handler mHandler = new Handler();
private List<Contact> contactList, sipContactList; private List<Contact> contactList, sipContactList;
private Cursor contactCursor, sipContactCursor; private Cursor contactCursor, sipContactCursor;
private OrientationEventListener mOrientationHelper; private OrientationEventListener mOrientationHelper;
@ -775,44 +773,34 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
} }
private void displayMissedCalls(final int missedCallsCount) { private void displayMissedCalls(final int missedCallsCount) {
mHandler.post(new Runnable() { if (missedCallsCount > 0) {
@Override missedCalls.setText(missedCallsCount + "");
public void run() { missedCalls.setVisibility(View.VISIBLE);
if (missedCallsCount > 0) { if (!isAnimationDisabled) {
missedCalls.setText(missedCallsCount + ""); missedCalls.startAnimation(AnimationUtils.loadAnimation(LinphoneActivity.this, R.anim.bounce));
missedCalls.setVisibility(View.VISIBLE);
if (!isAnimationDisabled) {
missedCalls.startAnimation(AnimationUtils.loadAnimation(LinphoneActivity.this, R.anim.bounce));
}
} else {
missedCalls.clearAnimation();
missedCalls.setVisibility(View.GONE);
}
} }
}); } else {
missedCalls.clearAnimation();
missedCalls.setVisibility(View.GONE);
}
} }
private void displayMissedChats(final int missedChatCount) { private void displayMissedChats(final int missedChatCount) {
mHandler.post(new Runnable() { if (missedChatCount > 0) {
@Override missedChats.setText(missedChatCount + "");
public void run() { if (missedChatCount > 99) {
if (missedChatCount > 0) { missedChats.setTextSize(12);
missedChats.setText(missedChatCount + ""); } else {
if (missedChatCount > 99) { missedChats.setTextSize(20);
missedChats.setTextSize(12);
} else {
missedChats.setTextSize(20);
}
missedChats.setVisibility(View.VISIBLE);
if (!isAnimationDisabled) {
missedChats.startAnimation(AnimationUtils.loadAnimation(LinphoneActivity.this, R.anim.bounce));
}
} else {
missedChats.clearAnimation();
missedChats.setVisibility(View.GONE);
}
} }
}); missedChats.setVisibility(View.VISIBLE);
if (!isAnimationDisabled) {
missedChats.startAnimation(AnimationUtils.loadAnimation(LinphoneActivity.this, R.anim.bounce));
}
} else {
missedChats.clearAnimation();
missedChats.setVisibility(View.GONE);
}
} }
@Override @Override
@ -842,22 +830,17 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
} }
public void displayCustomToast(final String message, final int duration) { public void displayCustomToast(final String message, final int duration) {
mHandler.post(new Runnable() { LayoutInflater inflater = getLayoutInflater();
@Override View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));
public void run() {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));
TextView toastText = (TextView) layout.findViewById(R.id.toastMessage); TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
toastText.setText(message); toastText.setText(message);
final Toast toast = new Toast(getApplicationContext()); final Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER, 0, 0); toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(duration); toast.setDuration(duration);
toast.setView(layout); toast.setView(layout);
toast.show(); toast.show();
}
});
} }
@Override @Override
@ -1153,25 +1136,20 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
} }
public void resetClassicMenuLayoutAndGoBackToCallIfStillRunning() { public void resetClassicMenuLayoutAndGoBackToCallIfStillRunning() {
mHandler.post(new Runnable() { if (dialerFragment != null) {
@Override ((DialerFragment) dialerFragment).resetLayout(false);
public void run() { }
if (dialerFragment != null) {
((DialerFragment) dialerFragment).resetLayout(false);
}
if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) { if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
if (call.getState() == LinphoneCall.State.IncomingReceived) { if (call.getState() == LinphoneCall.State.IncomingReceived) {
startActivity(new Intent(LinphoneActivity.this, IncomingCallActivity.class)); startActivity(new Intent(LinphoneActivity.this, IncomingCallActivity.class));
} else if (call.getCurrentParamsCopy().getVideoEnabled()) { } else if (call.getCurrentParamsCopy().getVideoEnabled()) {
startVideoActivity(call); startVideoActivity(call);
} else { } else {
startIncallActivity(call); startIncallActivity(call);
}
}
} }
}); }
} }
public FragmentsAvailable getCurrentFragment() { public FragmentsAvailable getCurrentFragment() {

View file

@ -138,7 +138,7 @@ public class LinphoneManager implements LinphoneListener {
public String wizardLoginViewDomain = null; public String wizardLoginViewDomain = null;
protected LinphoneManager(final Context c) { protected LinphoneManager(final Context c) {
sExited=false; sExited = false;
mServiceContext = c; mServiceContext = c;
basePath = c.getFilesDir().getAbsolutePath(); basePath = c.getFilesDir().getAbsolutePath();
mLPConfigXsd = basePath + "/lpconfig.xsd"; mLPConfigXsd = basePath + "/lpconfig.xsd";
@ -448,7 +448,12 @@ public class LinphoneManager implements LinphoneListener {
mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneFactoryConfigFile, null, c); mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneFactoryConfigFile, null, c);
mLc.addListener((LinphoneCoreListener) c); mLc.addListener((LinphoneCoreListener) c);
//initLiblinphone();
try {
initLiblinphone();
} catch (LinphoneCoreException e) {
Log.e(e);
}
TimerTask lTask = new TimerTask() { TimerTask lTask = new TimerTask() {
@Override @Override
@ -725,21 +730,6 @@ public class LinphoneManager implements LinphoneListener {
public void globalState(final LinphoneCore lc, final GlobalState state, final String message) { public void globalState(final LinphoneCore lc, final GlobalState state, final String message) {
Log.i("new state [",state,"]"); Log.i("new state [",state,"]");
if (state == GlobalState.GlobalOn) {
mHandler.post(new Runnable() {
@Override
public void run() {
synchronized (this) {
try {
initLiblinphone();
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
}
});
}
} }
public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig proxy,final RegistrationState state,final String message) { public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig proxy,final RegistrationState state,final String message) {

View file

@ -156,12 +156,7 @@ public final class LinphoneService extends Service implements LinphoneCallStateL
} }
mNotif = Compatibility.createNotification(this, mNotificationTitle, "", R.drawable.status_level, IC_LEVEL_OFFLINE, bm, mNotifContentIntent, true); mNotif = Compatibility.createNotification(this, mNotificationTitle, "", R.drawable.status_level, IC_LEVEL_OFFLINE, bm, mNotifContentIntent, true);
UIThreadDispatcher.Dispatch(new Runnable() { LinphoneManager.createAndStart(LinphoneService.this);
@Override
public void run() {
LinphoneManager.createAndStart(LinphoneService.this);
}
});
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (Version.sdkAboveOrEqual(Version.API12_HONEYCOMB_MR1_31X)) { if (Version.sdkAboveOrEqual(Version.API12_HONEYCOMB_MR1_31X)) {
@ -419,6 +414,7 @@ public final class LinphoneService extends Service implements LinphoneCallStateL
} }
} }
@SuppressWarnings("deprecation")
private void dumpDeviceInformation() { private void dumpDeviceInformation() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("DEVICE=").append(Build.DEVICE).append("\n"); sb.append("DEVICE=").append(Build.DEVICE).append("\n");

View file

@ -929,26 +929,22 @@ public class SettingsFragment extends PreferencesListFragment implements Linphon
public void ecCalibrationStatus(LinphoneCore lc, final EcCalibratorStatus status, final int delayMs, Object data) { public void ecCalibrationStatus(LinphoneCore lc, final EcCalibratorStatus status, final int delayMs, Object data) {
LinphoneManager.getInstance().routeAudioToReceiver(); LinphoneManager.getInstance().routeAudioToReceiver();
mHandler.post(new Runnable() { CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(getString(R.string.pref_echo_cancellation_key));
public void run() { Preference echoCancellerCalibration = findPreference(getString(R.string.pref_echo_canceller_calibration_key));
CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(getString(R.string.pref_echo_cancellation_key));
Preference echoCancellerCalibration = findPreference(getString(R.string.pref_echo_canceller_calibration_key));
if (status == EcCalibratorStatus.DoneNoEcho) { if (status == EcCalibratorStatus.DoneNoEcho) {
echoCancellerCalibration.setSummary(R.string.no_echo); echoCancellerCalibration.setSummary(R.string.no_echo);
echoCancellation.setChecked(false); echoCancellation.setChecked(false);
LinphonePreferences.instance().setEchoCancellation(false); LinphonePreferences.instance().setEchoCancellation(false);
} else if (status == EcCalibratorStatus.Done) { } else if (status == EcCalibratorStatus.Done) {
echoCancellerCalibration.setSummary(String.format(getString(R.string.ec_calibrated), delayMs)); echoCancellerCalibration.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
echoCancellation.setChecked(true); echoCancellation.setChecked(true);
LinphonePreferences.instance().setEchoCancellation(true); LinphonePreferences.instance().setEchoCancellation(true);
} else if (status == EcCalibratorStatus.Failed) { } else if (status == EcCalibratorStatus.Failed) {
echoCancellerCalibration.setSummary(R.string.failed); echoCancellerCalibration.setSummary(R.string.failed);
echoCancellation.setChecked(true); echoCancellation.setChecked(true);
LinphonePreferences.instance().setEchoCancellation(true); LinphonePreferences.instance().setEchoCancellation(true);
} }
}
});
} }
@Override @Override

View file

@ -199,26 +199,21 @@ public class StatusFragment extends Fragment implements LinphoneNotifyListener,
return; return;
} }
mHandler.post(new Runnable() { statusLed.setImageResource(getStatusIconResource(state, true));
@Override statusText.setText(getStatusIconText(state));
public void run() { try {
statusLed.setImageResource(getStatusIconResource(state, true)); if (getResources().getBoolean(R.bool.lock_statusbar)) {
statusText.setText(getStatusIconText(state)); statusText.setOnClickListener(new OnClickListener() {
try { @Override
if (getResources().getBoolean(R.bool.lock_statusbar)) { public void onClick(View v) {
statusText.setOnClickListener(new OnClickListener() { lc.refreshRegisters();
@Override
public void onClick(View v) {
lc.refreshRegisters();
}
});
} }
// setMiniLedsForEachAccount(); });
populateSliderContent();
sliderContentAccounts.invalidate();
} catch (IllegalStateException ise) {}
} }
}); // setMiniLedsForEachAccount();
populateSliderContent();
sliderContentAccounts.invalidate();
} catch (IllegalStateException ise) {}
} }
// private void setMiniLedsForEachAccount() { // private void setMiniLedsForEachAccount() {

View file

@ -59,7 +59,6 @@ public class EchoCancellerCalibrationFragment extends Fragment implements Linpho
} catch (LinphoneCoreException e) { } catch (LinphoneCoreException e) {
Log.e(e, "Unable to calibrate EC"); Log.e(e, "Unable to calibrate EC");
} }
return view; return view;
} }

View file

@ -83,17 +83,12 @@ public class RemoteProvisioningActivity extends Activity implements LinphoneRemo
@Override @Override
public void configuringStatus(LinphoneCore lc, final RemoteProvisioningState state, String message) { public void configuringStatus(LinphoneCore lc, final RemoteProvisioningState state, String message) {
mHandler.post(new Runnable() { if (spinner != null) spinner.setVisibility(View.GONE);
@Override if (state == RemoteProvisioningState.ConfiguringSuccessful) {
public void run() { goToLinphoneActivity();
if (spinner != null) spinner.setVisibility(View.GONE); } else if (state == RemoteProvisioningState.ConfiguringFailed) {
if (state == RemoteProvisioningState.ConfiguringSuccessful) { Toast.makeText(RemoteProvisioningActivity.this, R.string.remote_provisioning_failure, Toast.LENGTH_LONG).show();
goToLinphoneActivity(); }
} else if (state == RemoteProvisioningState.ConfiguringFailed) {
Toast.makeText(RemoteProvisioningActivity.this, R.string.remote_provisioning_failure, Toast.LENGTH_LONG).show();
}
}
});
} }
@Override @Override

View file

@ -22,8 +22,8 @@ import org.linphone.LinphonePreferences;
import org.linphone.LinphonePreferences.AccountBuilder; import org.linphone.LinphonePreferences.AccountBuilder;
import org.linphone.R; import org.linphone.R;
import org.linphone.core.LinphoneAddress.TransportType; import org.linphone.core.LinphoneAddress.TransportType;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreListener; import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneProxyConfig;
@ -32,7 +32,6 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
@ -53,7 +52,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener,
private Fragment fragment; private Fragment fragment;
private LinphonePreferences mPrefs; private LinphonePreferences mPrefs;
private boolean accountCreated = false; private boolean accountCreated = false;
private Handler mHandler = new Handler();
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -223,20 +221,11 @@ public class SetupActivity extends FragmentActivity implements OnClickListener,
public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState state, String smessage) { public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState state, String smessage) {
if (state == RegistrationState.RegistrationOk) { if (state == RegistrationState.RegistrationOk) {
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) { if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
mHandler .post(new Runnable () { launchEchoCancellerCalibration(true);
public void run() {
launchEchoCancellerCalibration(true);
}
});
} }
} else if (state == RegistrationState.RegistrationFailed) { } else if (state == RegistrationState.RegistrationFailed) {
mHandler.post(new Runnable () { Toast.makeText(SetupActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show();
public void run() {
Toast.makeText(SetupActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show();
}
});
} }
} }