public void addGlobalHeaders(HttpURLConnection connection) { try { connection.setRequestProperty( APPLICATION_KEY_HEADER, MobiComKitClientService.getApplicationKey(context)); connection.setRequestProperty(SOURCE_HEADER, SOURCE_HEADER_VALUE); connection.setRequestProperty(USERID_HEADER, USERID_HEADER_VALUE); connection.setRequestProperty( DEVICE_KEY_HEADER, MobiComUserPreference.getInstance(context).getDeviceKeyString()); Short authenticationType = Short.valueOf(MobiComUserPreference.getInstance(context).getAuthenticationType()); if (User.AuthenticationType.APPLOZIC.getValue() == authenticationType) { connection.setRequestProperty( ACCESS_TOKEN, MobiComUserPreference.getInstance(context).getPassword()); } if (MobiComKitClientService.getAppModuleName(context) != null) { connection.setRequestProperty( APP_MODULE_NAME_KEY_HEADER, MobiComKitClientService.getAppModuleName(context)); } MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context); if (userPreferences.isRegistered()) { String userCredentials = getCredentials().getUserName() + ":" + String.valueOf(getCredentials().getPassword()); String basicAuth = "Basic " + Base64.encodeToString(userCredentials.getBytes(), Base64.NO_WRAP); connection.setRequestProperty("Authorization", basicAuth); } } catch (Exception e) { e.printStackTrace(); } }
@Override public void run() { try { new MessageClientService(MessageIntentService.this) .sendMessageToServer(message, ScheduleMessageService.class); if (message.hasAttachment() && !message.isAttachmentUploadInProgress()) { runningTaskMap.remove(getMapKey(message)); } int groupSmsDelayInSec = MobiComUserPreference.getInstance(MessageIntentService.this).getGroupSmsDelayInSec(); boolean isDelayRequire = (groupSmsDelayInSec > 0 && message.isSentViaCarrier() && message.isSentToMany()); if (message.getScheduledAt() == null) { String[] toList = message.getTo().trim().replace("undefined,", "").split(","); for (String tofield : toList) { if (isDelayRequire && !message.getTo().startsWith(tofield)) { new Timer() .schedule( new MessageSenderTimerTask( new MobiComMessageService( MessageIntentService.this, MessageIntentService.class), message, tofield), groupSmsDelayInSec * 1000); } else { new MobiComMessageService(MessageIntentService.this, MessageIntentService.class) .processMessage(message, tofield); } } } } catch (Exception e) { e.printStackTrace(); } }
public PasswordAuthentication getCredentials() { MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context); if (!userPreferences.isRegistered()) { return null; } return new PasswordAuthentication( userPreferences.getUserId(), userPreferences.getDeviceKeyString().toCharArray()); }
public ContactDatabase(Context context) { this.context = context; this.userPreferences = MobiComUserPreference.getInstance(context); this.dbHelper = MobiComDatabaseHelper.getInstance(context); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(this); setContentView(R.layout.activity_login); setupUI(findViewById(R.id.layout)); // Set up the login form. mEmailView = (AutoCompleteTextView) findViewById(R.id.email); populateAutoComplete(); mPhoneNumberView = (EditText) findViewById(R.id.phoneNumber); mPhoneNumberView.setVisibility(View.GONE); mUserIdView = (EditText) findViewById(R.id.userId); mPasswordView = (EditText) findViewById(R.id.password); mPasswordView.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { if (id == R.id.login || id == EditorInfo.IME_NULL) { attemptLogin(User.AuthenticationType.APPLOZIC); return true; } return false; } }); mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); mEmailSignInButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { Utils.toggleSoftKeyBoard(LoginActivity.this, true); attemptLogin(User.AuthenticationType.APPLOZIC); } }); mLoginFormView = findViewById(R.id.login_form); mProgressView = findViewById(R.id.login_progress); callbackManager = CallbackManager.Factory.create(); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setReadPermissions("user_friends"); // Callback registration loginButton.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { mUserIdView.setText(loginResult.getAccessToken().getUserId()); mPasswordView.setText(loginResult.getAccessToken().getToken()); attemptLogin(User.AuthenticationType.FACEBOOK); } @Override public void onCancel() {} @Override public void onError(FacebookException exception) {} }); mSpinnerView = (Spinner) findViewById(R.id.spinner_for_url); mSpinnerView.setVisibility(View.INVISIBLE); mTitleView = (TextView) findViewById(R.id.textViewTitle); mTitleView.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { touchCount += 1; if (touchCount == 5) { mSpinnerView.setVisibility(View.VISIBLE); touchCount = 0; } else { Toast.makeText( getApplicationContext(), "Click more " + Integer.toString(5 - touchCount), Toast.LENGTH_SHORT) .show(); } } }); mobiComUserPreference = MobiComUserPreference.getInstance(this); mSpinnerView.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mobiComUserPreference.setUrl(adapterView.getItemAtPosition(i).toString()); } @Override public void onNothingSelected(AdapterView<?> adapterView) {} }); }