Example #1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.munu_shezhi:
        Intent exitIntent = new Intent();
        exitIntent.setClass(this, SettingActivity.class);
        startActivity(exitIntent);
        return true;
      case R.id.munu_tonghuashezhi:
        startprefActivity();
        return true;
      case R.id.munu_bangzhu:
        Intent intent = new Intent();
        intent.setClass(this, HelpActivity.class);
        startActivity(intent);
        break;
      case R.id.munu_guanyu:
        Intent in = new Intent(Intent.ACTION_MAIN);
        in.setClass(this, AboutZhizhiActivity.class);
        startActivity(in);
        return true;
      case R.id.munu_zijinzhanghu:
        if (LinphoneService.instance().username == null
            || LinphoneService.instance().username.length() == 0) {
          Intent intent2 = new Intent();
          intent2.setClass(this, LoginActivity.class);
          startActivity(intent2);
        } else {
          Intent intent2 = new Intent();
          intent2.setClass(this, AccountActivity.class);
          startActivity(intent2);
        }
        return true;
      case R.id.munu_tuichu:
        if (LinphoneService.instance().username != null
            && LinphoneService.instance().username.length() != 0) {
          try {
            String str = NetworkUtils.getExitResultForHttpGet();
          } catch (ClientProtocolException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }

        Intent aa = new Intent(Intent.ACTION_MAIN);
        aa.setClass(this, LinphoneService.class);
        stopService(aa);
        finish();
        return true;
      default:
        Log.e(LinphoneService.TAG, "Unknown menu item [" + item + "]");
        break;
    }

    return false;
  }
Example #2
0
 void startService() {
   try {
     if (LinphoneService.instance() == null) {
       Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN);
       lLinphoneServiceIntent.setClass(this, LinphoneService.class);
       startService(lLinphoneServiceIntent);
     }
     LinphoneService.instance().initFromConf();
   } catch (LinphoneConfigException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @Override
  protected void onResume() {
    super.onResume();

    if (!LinphoneService.isReady()) {
      startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
    }

    ContactsManager.getInstance().prepareContactsInBackground();

    updateMissedChatCount();

    displayMissedCalls(LinphoneManager.getLc().getMissedCallsCount());

    LinphoneManager.getInstance().changeStatusToOnline();

    if (getIntent().getIntExtra("PreviousActivity", 0) != CALL_ACTIVITY) {
      if (LinphoneManager.getLc().getCalls().length > 0) {
        LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
        LinphoneCall.State callState = call.getState();
        if (callState == State.IncomingReceived) {
          startActivity(new Intent(this, IncomingCallActivity.class));
        } else {

          if (call.getCurrentParamsCopy().getVideoEnabled()) {
            startVideoActivity(call);
          } else {
            startIncallActivity(call);
          }
        }
      }
    }
  }
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Bundle extras = intent.getExtras();
    if (extras != null && extras.getBoolean("GoToChat", false)) {
      LinphoneService.instance().removeMessageNotification();
      String sipUri = extras.getString("ChatContactSipUri");
      displayChat(sipUri);
    } else if (extras != null && extras.getBoolean("Notification", false)) {
      if (LinphoneManager.getLc().getCallsNb() > 0) {
        LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
        if (call.getCurrentParamsCopy().getVideoEnabled()) {
          startVideoActivity(call);
        } else {
          startIncallActivity(call);
        }
      }
    } else {
      if (dialerFragment != null) {
        if (extras != null && extras.containsKey("SipUriOrNumber")) {
          if (getResources().getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) {
            ((DialerFragment) dialerFragment).newOutgoingCall(extras.getString("SipUriOrNumber"));
          } else {
            ((DialerFragment) dialerFragment)
                .displayTextInAddressBar(extras.getString("SipUriOrNumber"));
          }
        } else {
          ((DialerFragment) dialerFragment).newOutgoingCall(intent);
        }
      }
      if (LinphoneManager.getLc().getCalls().length > 0) {
        LinphoneCall calls[] = LinphoneManager.getLc().getCalls();
        if (calls.length > 0) {
          LinphoneCall call = calls[0];

          if (call != null && call.getState() != LinphoneCall.State.IncomingReceived) {
            if (call.getCurrentParamsCopy().getVideoEnabled()) {
              startVideoActivity(call);
            } else {
              startIncallActivity(call);
            }
          }
        }

        // If a call is ringing, start incomingcallactivity
        Collection<LinphoneCall.State> incoming = new ArrayList<LinphoneCall.State>();
        incoming.add(LinphoneCall.State.IncomingReceived);
        if (LinphoneUtils.getCallsInState(LinphoneManager.getLc(), incoming).size() > 0) {
          if (InCallActivity.isInstanciated()) {
            InCallActivity.instance().startIncomingCallActivity();
          } else {
            startActivity(new Intent(this, IncomingCallActivity.class));
          }
        }
      }
    }
  }
  @Override
  public void onPause() {
    latestImageMessages = null;
    message.removeTextChangedListener(textWatcher);
    removeVirtualKeyboardVisiblityListener();

    LinphoneService.instance().removeMessageNotification();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      lc.removeListener(this);
    }

    super.onPause();

    onSaveInstanceState(getArguments());
  }
Example #6
0
  @Override
  public void onPause() {
    message.removeTextChangedListener(textWatcher);
    removeVirtualKeyboardVisiblityListener();

    LinphoneService.instance().removeMessageNotification();

    if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().updateChatFragment(null);
    }

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      lc.removeListener(mListener);
    }

    onSaveInstanceState(getArguments());

    // Hide keybord
    InputMethodManager imm =
        (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
    super.onPause();
  }
  public void displayChat(String sipUri) {
    if (getResources().getBoolean(R.bool.disable_chat)) {
      return;
    }

    LinphoneAddress lAddress;
    try {
      lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    } catch (LinphoneCoreException e) {
      Log.e("Cannot display chat", e);
      return;
    }
    Contact contact =
        ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
    String displayName = contact != null ? contact.getName() : null;

    String pictureUri = null;
    String thumbnailUri = null;
    if (contact != null && contact.getPhotoUri() != null) {
      pictureUri = contact.getPhotoUri().toString();
      thumbnailUri = contact.getThumbnailUri().toString();
    }

    if (isTablet()) {
      if (currentFragment == FragmentsAvailable.CHATLIST
          || currentFragment == FragmentsAvailable.CHAT) {
        Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2);
        if (fragment2 != null
            && fragment2.isVisible()
            && currentFragment == FragmentsAvailable.CHAT) {
          ChatFragment chatFragment = (ChatFragment) fragment2;
          chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri);
        } else {
          Bundle extras = new Bundle();
          extras.putString("SipUri", sipUri);
          if (contact != null) {
            extras.putString("DisplayName", displayName);
            extras.putString("PictureUri", pictureUri);
            extras.putString("ThumbnailUri", thumbnailUri);
          }
          changeCurrentFragment(FragmentsAvailable.CHAT, extras);
        }
      } else {
        changeCurrentFragment(FragmentsAvailable.CHATLIST, null);
        displayChat(sipUri);
      }
      if (messageListFragment != null && messageListFragment.isVisible()) {
        ((ChatListFragment) messageListFragment).refresh();
      }
    } else {
      Intent intent = new Intent(this, ChatActivity.class);
      intent.putExtra("SipUri", sipUri);
      if (contact != null) {
        intent.putExtra("DisplayName", contact.getName());
        intent.putExtra("PictureUri", pictureUri);
        intent.putExtra("ThumbnailUri", thumbnailUri);
      }
      startOrientationSensor();
      startActivityForResult(intent, CHAT_ACTIVITY);
    }

    LinphoneService.instance().resetMessageNotifCount();
    LinphoneService.instance().removeMessageNotification();
    displayMissedChats(getChatStorage().getUnreadMessageCount());
  }
  private void createAccount(
      final String username, final String password, String email, boolean suscribe) {
    final Runnable runNotReachable =
        new Runnable() {
          public void run() {
            errorMessage.setText(R.string.wizard_server_unavailable);
          }
        };

    final Context context =
        SetupActivity.instance() == null
            ? LinphoneService.instance().getApplicationContext()
            : SetupActivity.instance();

    try {
      XMLRPCClient client = new XMLRPCClient(new URL(context.getString(R.string.wizard_url)));

      XMLRPCCallback listener =
          new XMLRPCCallback() {
            Runnable runNotOk =
                new Runnable() {
                  public void run() {
                    errorMessage.setText(R.string.wizard_failed);
                  }
                };

            Runnable runOk =
                new Runnable() {
                  public void run() {
                    SetupActivity.instance()
                        .saveCreatedAccount(
                            username, password, context.getString(R.string.default_domain));
                    SetupActivity.instance().displayWizardConfirm(username);
                  }
                };

            public void onResponse(long id, Object result) {
              int answer = (Integer) result;
              if (answer != 0) {
                mHandler.post(runNotOk);
              } else {
                mHandler.post(runOk);
              }
            }

            public void onError(long id, XMLRPCException error) {
              mHandler.post(runNotReachable);
            }

            public void onServerError(long id, XMLRPCServerException error) {
              mHandler.post(runNotReachable);
            }
          };

      client.callAsync(
          listener,
          "create_account_with_useragent",
          username,
          password,
          email,
          LinphoneManager.getInstance().getUserAgent());
    } catch (Exception ex) {
      mHandler.post(runNotReachable);
    }
  }