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 AvatarWithShadow contactPicture;
private RelativeLayout uploadLayout, textLayout;
private Handler mHandler = new Handler();
private List<BubbleChat> lastSentMessagesBubbles;
private HashMap<Integer, String> latestImageMessages;
private boolean useLinphoneMessageStorage;
private ListView messagesList;
private Handler mHandler = new Handler();
private ProgressBar progressBar;
private int bytesSent;
@ -678,21 +678,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
public void onMessageReceived(LinphoneAddress from, final LinphoneChatMessage message) {
if (from.asStringUriOnly().equals(sipUri)) {
if (message.getText() != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
adapter.refreshHistory();
adapter.notifyDataSetChanged();
}
});
adapter.refreshHistory();
adapter.notifyDataSetChanged();
} else if (message.getExternalBodyUrl() != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
adapter.refreshHistory();
adapter.notifyDataSetChanged();
}
});
adapter.refreshHistory();
adapter.notifyDataSetChanged();
}
scrollToEnd();
}
@ -704,38 +694,32 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
final String finalImage = finalMessage.getExternalBodyUrl();
final State finalState=state;
if (LinphoneActivity.isInstanciated() && state != State.InProgress) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (finalMessage != null && !finalMessage.equals("")) {
LinphoneActivity.instance().onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt());
} else if (finalImage != null && !finalImage.equals("")) {
if (latestImageMessages != null && latestImageMessages.containsValue(finalImage)) {
int id = -1;
for (int key : latestImageMessages.keySet()) {
String object = latestImageMessages.get(key);
if (object.equals(finalImage)) {
id = key;
break;
}
}
if (id != -1) {
LinphoneActivity.instance().onImageMessageStateChanged(sipUri, id, finalState.toInt());
}
if (finalMessage != null && !finalMessage.equals("")) {
LinphoneActivity.instance().onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt());
} else if (finalImage != null && !finalImage.equals("")) {
if (latestImageMessages != null && latestImageMessages.containsValue(finalImage)) {
int id = -1;
for (int key : latestImageMessages.keySet()) {
String object = latestImageMessages.get(key);
if (object.equals(finalImage)) {
id = key;
break;
}
}
if (lastSentMessagesBubbles != null && lastSentMessagesBubbles.size() > 0) {
for (BubbleChat bubble : lastSentMessagesBubbles) {
if (bubble.getNativeMessageObject() == finalMessage) {
bubble.updateStatusView(finalState);
}
}
if (id != -1) {
LinphoneActivity.instance().onImageMessageStateChanged(sipUri, id, finalState.toInt());
}
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
public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom room) {
if (chatRoom != null && room != null && chatRoom.getPeerAddress().asStringUriOnly().equals(room.getPeerAddress().asStringUriOnly())) {
mHandler.post(new Runnable() {
@Override
public void run() {
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
}
});
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.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
@ -60,8 +59,6 @@ import android.widget.TextView;
* @author Sylvain Berfini
*/
public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener {
private Handler mHandler = new Handler();
private LayoutInflater mInflater;
private List<String> mConversations, mDrafts;
private ListView chatList;
@ -112,15 +109,10 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
}
public void refresh() {
mHandler.post(new Runnable() {
@Override
public void run() {
mConversations = LinphoneActivity.instance().getChatList();
mDrafts = LinphoneActivity.instance().getDraftChatList();
mConversations.removeAll(mDrafts);
hideAndDisplayMessageIfNoChat();
}
});
mConversations = LinphoneActivity.instance().getChatList();
mDrafts = LinphoneActivity.instance().getDraftChatList();
mConversations.removeAll(mDrafts);
hideAndDisplayMessageIfNoChat();
}
private boolean isVersionUsingNewChatStorage() {

View file

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

View file

@ -30,7 +30,6 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.util.SparseArray;
import android.view.ContextMenu;
@ -53,7 +52,6 @@ import android.widget.TextView;
* @author Sylvain Berfini
*/
public class HistoryFragment extends Fragment implements OnClickListener, OnChildClickListener, OnGroupClickListener {
private Handler mHandler = new Handler();
private ExpandableListView historyList;
private LayoutInflater mInflater;
private TextView allCalls, missedCalls, edit, ok, deleteAll, noCallHistory, noMissedCallHistory;
@ -164,16 +162,11 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil
}
private void expandAllGroups() {
mHandler.post(new Runnable() {
@Override
public void run() {
for (int groupToExpand = 0; groupToExpand < historyList.getExpandableListAdapter().getGroupCount(); groupToExpand++) {
if (!historyList.isGroupExpanded(groupToExpand)) {
historyList.expandGroup(groupToExpand);
}
}
for (int groupToExpand = 0; groupToExpand < historyList.getExpandableListAdapter().getGroupCount(); groupToExpand++) {
if (!historyList.isGroupExpanded(groupToExpand)) {
historyList.expandGroup(groupToExpand);
}
});
}
}
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 static InCallActivity instance;
private Handler mHandler = new Handler();
private Handler mControlsHandler = new Handler();
private Handler mControlsHandler = new Handler();
private Runnable mControls;
private ImageView switchCamera;
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() {
if (mHandler == null) {
mHandler = new Handler();
}
mHandler.post(new Runnable() {
@Override
public void run() {
if (!LinphonePreferences.instance().isVideoEnabled()) {
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);
}
}
if (!LinphonePreferences.instance().isVideoEnabled()) {
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);
}
}
}
private void enableAndRefreshInCallActions() {
if (mHandler == null) {
mHandler = new Handler();
}
mHandler.post(new Runnable() {
@Override
public void run() {
addCall.setEnabled(LinphoneManager.getLc().getCallsNb() < LinphoneManager.getLc().getMaxCalls());
transfer.setEnabled(getResources().getBoolean(R.bool.allow_transfers));
options.setEnabled(!getResources().getBoolean(R.bool.disable_options_in_call) && (addCall.isEnabled() || transfer.isEnabled()));
video.setEnabled(true);
micro.setEnabled(true);
if(!isTablet()){
speaker.setEnabled(true);
}
transfer.setEnabled(true);
pause.setEnabled(true);
dialer.setEnabled(true);
conference.setEnabled(true);
addCall.setEnabled(LinphoneManager.getLc().getCallsNb() < LinphoneManager.getLc().getMaxCalls());
transfer.setEnabled(getResources().getBoolean(R.bool.allow_transfers));
options.setEnabled(!getResources().getBoolean(R.bool.disable_options_in_call) && (addCall.isEnabled() || transfer.isEnabled()));
video.setEnabled(true);
micro.setEnabled(true);
if(!isTablet()){
speaker.setEnabled(true);
}
transfer.setEnabled(true);
pause.setEnabled(true);
dialer.setEnabled(true);
conference.setEnabled(true);
refreshInCallActions();
}
});
refreshInCallActions();
}
public void updateStatusFragment(StatusFragment statusFragment) {
@ -459,45 +442,34 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
return;
}
mHandler.post(new Runnable() {
@Override
public void run() {
if (isVideoEnabled) {
video.setEnabled(true);
LinphoneCallParams params = call.getCurrentParamsCopy();
params.setVideoEnabled(false);
LinphoneManager.getLc().updateCall(call, params);
} else {
video.setEnabled(false);
videoProgress.setVisibility(View.VISIBLE);
if (!call.getRemoteParams().isLowBandwidthEnabled()) {
LinphoneManager.getInstance().addVideo();
} else {
displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
}
}
if (isVideoEnabled) {
video.setEnabled(true);
LinphoneCallParams params = call.getCurrentParamsCopy();
params.setVideoEnabled(false);
LinphoneManager.getLc().updateCall(call, params);
} else {
video.setEnabled(false);
videoProgress.setVisibility(View.VISIBLE);
if (!call.getRemoteParams().isLowBandwidthEnabled()) {
LinphoneManager.getInstance().addVideo();
} else {
displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
}
});
}
}
public void displayCustomToast(final String message, final int duration) {
mHandler.post(new Runnable() {
@Override
public void run() {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));
TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
toastText.setText(message);
TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
toastText.setText(message);
final Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(duration);
toast.setView(layout);
toast.show();
}
});
final Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(duration);
toast.setView(layout);
toast.show();
}
private void switchVideo(final boolean displayVideo) {
@ -506,25 +478,20 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
return;
}
mHandler.post(new Runnable() {
@Override
public void run() {
//Check if the call is not terminated
if(call.getState() == State.CallEnd || call.getState() == State.CallReleased) return;
if (!displayVideo) {
showAudioView();
} else {
if (!call.getRemoteParams().isLowBandwidthEnabled()) {
LinphoneManager.getInstance().addVideo();
if (videoCallFragment == null || !videoCallFragment.isVisible())
showVideoView();
} else {
displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
}
}
//Check if the call is not terminated
if(call.getState() == State.CallEnd || call.getState() == State.CallReleased) return;
if (!displayVideo) {
showAudioView();
} else {
if (!call.getRemoteParams().isLowBandwidthEnabled()) {
LinphoneManager.getInstance().addVideo();
if (videoCallFragment == null || !videoCallFragment.isVisible())
showVideoView();
} else {
displayCustomToast(getString(R.string.error_low_bandwidth), Toast.LENGTH_LONG);
}
});
}
}
private void showAudioView() {
@ -1080,13 +1047,7 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
}
if(!LinphonePreferences.instance().isVideoEnabled()){
mHandler.post(new Runnable() {
@Override
public void run() {
video.setEnabled(true);
}
});
video.setEnabled(true);
}
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) {
mHandler.post(new Runnable() {
@Override
public void run() {
video.setEnabled(false);
if(isVideoEnabled(call)){
showAudioView();
}
}
});
video.setEnabled(false);
if(isVideoEnabled(call)){
showAudioView();
}
}
if (state == State.Resuming) {
if(LinphonePreferences.instance().isVideoEnabled()){
mHandler.post(new Runnable() {
@Override
public void run() {
status.refreshStatusItems(call, isVideoEnabled(call));
if(call.getCurrentParamsCopy().getVideoEnabled()){
showVideoView();
}
}
});
status.refreshStatusItems(call, isVideoEnabled(call));
if(call.getCurrentParamsCopy().getVideoEnabled()){
showVideoView();
}
}
}
@ -1129,24 +1080,14 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
enableAndRefreshInCallActions();
if (status != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
videoProgress.setVisibility(View.GONE);
status.refreshStatusItems(call, isVideoEnabled(call));
}
});
videoProgress.setVisibility(View.GONE);
status.refreshStatusItems(call, isVideoEnabled(call));
}
}
refreshInCallActions();
mHandler.post(new Runnable() {
@Override
public void run() {
refreshCallList(getResources());
}
});
refreshCallList(getResources());
if (state == State.CallUpdatedByRemote) {
// 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 autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests();
if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) {
mHandler.post(new Runnable() {
public void run() {
showAcceptCallUpdateDialog();
timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) {
public void onTick(long millisUntilFinished) { }
public void onFinish() {
acceptCallUpdate(false);
}
}.start();
}
});
showAcceptCallUpdateDialog();
timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) {
public void onTick(long millisUntilFinished) { }
public void onFinish() {
acceptCallUpdate(false);
}
}.start();
}
// else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) {
// mHandler.post(new Runnable() {
@ -1183,11 +1120,7 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
// }
}
mHandler.post(new Runnable() {
public void run() {
transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
}
});
transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
}
private void showAcceptCallUpdateDialog() {
@ -1199,12 +1132,7 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
@Override
public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted, String authenticationToken) {
if (status != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled());
}
});
status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled());
}
}
@ -1291,7 +1219,6 @@ public class InCallActivity extends FragmentActivity implements LinphoneCallStat
}
mControls = null;
mControlsHandler = null;
mHandler = null;
unbindDrawables(findViewById(R.id.topLayout));
instance = null;

View file

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

View file

@ -138,7 +138,7 @@ public class LinphoneManager implements LinphoneListener {
public String wizardLoginViewDomain = null;
protected LinphoneManager(final Context c) {
sExited=false;
sExited = false;
mServiceContext = c;
basePath = c.getFilesDir().getAbsolutePath();
mLPConfigXsd = basePath + "/lpconfig.xsd";
@ -448,7 +448,12 @@ public class LinphoneManager implements LinphoneListener {
mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneFactoryConfigFile, null, c);
mLc.addListener((LinphoneCoreListener) c);
//initLiblinphone();
try {
initLiblinphone();
} catch (LinphoneCoreException e) {
Log.e(e);
}
TimerTask lTask = new TimerTask() {
@Override
@ -725,21 +730,6 @@ public class LinphoneManager implements LinphoneListener {
public void globalState(final LinphoneCore lc, final GlobalState state, final String message) {
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) {

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);
UIThreadDispatcher.Dispatch(new Runnable() {
@Override
public void run() {
LinphoneManager.createAndStart(LinphoneService.this);
}
});
LinphoneManager.createAndStart(LinphoneService.this);
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
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() {
StringBuilder sb = new StringBuilder();
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) {
LinphoneManager.getInstance().routeAudioToReceiver();
mHandler.post(new Runnable() {
public void run() {
CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(getString(R.string.pref_echo_cancellation_key));
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) {
echoCancellerCalibration.setSummary(R.string.no_echo);
echoCancellation.setChecked(false);
LinphonePreferences.instance().setEchoCancellation(false);
} else if (status == EcCalibratorStatus.Done) {
echoCancellerCalibration.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
echoCancellation.setChecked(true);
LinphonePreferences.instance().setEchoCancellation(true);
} else if (status == EcCalibratorStatus.Failed) {
echoCancellerCalibration.setSummary(R.string.failed);
echoCancellation.setChecked(true);
LinphonePreferences.instance().setEchoCancellation(true);
}
}
});
if (status == EcCalibratorStatus.DoneNoEcho) {
echoCancellerCalibration.setSummary(R.string.no_echo);
echoCancellation.setChecked(false);
LinphonePreferences.instance().setEchoCancellation(false);
} else if (status == EcCalibratorStatus.Done) {
echoCancellerCalibration.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
echoCancellation.setChecked(true);
LinphonePreferences.instance().setEchoCancellation(true);
} else if (status == EcCalibratorStatus.Failed) {
echoCancellerCalibration.setSummary(R.string.failed);
echoCancellation.setChecked(true);
LinphonePreferences.instance().setEchoCancellation(true);
}
}
@Override

View file

@ -199,26 +199,21 @@ public class StatusFragment extends Fragment implements LinphoneNotifyListener,
return;
}
mHandler.post(new Runnable() {
@Override
public void run() {
statusLed.setImageResource(getStatusIconResource(state, true));
statusText.setText(getStatusIconText(state));
try {
if (getResources().getBoolean(R.bool.lock_statusbar)) {
statusText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
lc.refreshRegisters();
}
});
statusLed.setImageResource(getStatusIconResource(state, true));
statusText.setText(getStatusIconText(state));
try {
if (getResources().getBoolean(R.bool.lock_statusbar)) {
statusText.setOnClickListener(new OnClickListener() {
@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() {

View file

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

View file

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

View file

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