Asking permission for device ring tone at the start
This commit is contained in:
parent
2f54f90dd5
commit
69f1888b4f
10 changed files with 96 additions and 79 deletions
|
@ -3,7 +3,7 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.3.0'
|
||||
classpath 'com.android.tools.build:gradle:2.2.0'
|
||||
}
|
||||
}
|
||||
apply plugin: 'android'
|
||||
|
@ -14,7 +14,7 @@ dependencies {
|
|||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "20.0.0"
|
||||
buildToolsVersion "23.0.2"
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
|
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
|||
#Tue Dec 09 14:35:04 CET 2014
|
||||
#Sun Oct 09 18:19:14 CEST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
|
||||
|
|
|
@ -38,6 +38,7 @@ max_calls=10
|
|||
|
||||
[app]
|
||||
activation_code_length=4
|
||||
debug=1
|
||||
|
||||
[in-app-purchase]
|
||||
server_url=https://sip3.linphone.org:444/inapp.php
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
<string name="use_email_for_validation">Use email address for account validation</string>
|
||||
<string name="login_with_username">Use your username and password instead of your phone number</string>
|
||||
<string name="phone_number_info_title">What will my phone number be used for?</string>
|
||||
<string name="phone_number_info_content">\nThanks to your phone number, your friends will find you more easily.\n\n You will see in your addressbook who is using Linphone and your friends will know that they can rach you on Linphone as well.\n</string>
|
||||
<string name="phone_number_info_content">\nThanks to your phone number, your friends will find you more easily.\n\n You will see in your address book who is using Linphone and your friends will know that they can rach you on Linphone as well.\n</string>
|
||||
<string name="phone_number_link_info_content">\nYour friends will find you more easily if you link your account to your phone number\n\nYou will see in your address book who is using Linphone and your friends will know that they can reach you on Linphone as well.\n</string>
|
||||
<string name="phone_number_link_info_content_already_account">You can only use your phone number with one linphone account.\n\nIf you had already linked your number to an other account but you prefer to use this one simply link it now and your number will automatically be moved to this account.</string>
|
||||
|
||||
|
|
|
@ -49,18 +49,18 @@ public class DialerFragment extends Fragment {
|
|||
private ImageView mAddContact;
|
||||
private OnClickListener addContactListener, cancelListener, transferListener;
|
||||
private boolean shouldEmptyAddressField = true;
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.dialer, container, false);
|
||||
|
||||
|
||||
mAddress = (AddressText) view.findViewById(R.id.address);
|
||||
mAddress.setDialerFragment(this);
|
||||
|
||||
|
||||
EraseButton erase = (EraseButton) view.findViewById(R.id.erase);
|
||||
erase.setAddressWidget(mAddress);
|
||||
|
||||
|
||||
mCall = (CallButton) view.findViewById(R.id.call);
|
||||
mCall.setAddressWidget(mAddress);
|
||||
if (LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
|
||||
|
@ -72,15 +72,15 @@ public class DialerFragment extends Fragment {
|
|||
} else {
|
||||
mCall.setImageResource(R.drawable.call_audio_start);
|
||||
}
|
||||
|
||||
|
||||
numpad = (AddressAware) view.findViewById(R.id.numpad);
|
||||
if (numpad != null) {
|
||||
numpad.setAddressWidget(mAddress);
|
||||
}
|
||||
|
||||
|
||||
mAddContact = (ImageView) view.findViewById(R.id.add_contact);
|
||||
mAddContact.setEnabled(!(LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0));
|
||||
|
||||
|
||||
addContactListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -107,7 +107,7 @@ public class DialerFragment extends Fragment {
|
|||
};
|
||||
|
||||
resetLayout(isCallTransferOngoing);
|
||||
|
||||
|
||||
if (getArguments() != null) {
|
||||
shouldEmptyAddressField = false;
|
||||
String number = getArguments().getString("SipUri");
|
||||
|
@ -133,18 +133,18 @@ public class DialerFragment extends Fragment {
|
|||
public static DialerFragment instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
instance = null;
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
instance = this;
|
||||
|
||||
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.DIALER);
|
||||
LinphoneActivity.instance().updateDialerFragment(this);
|
||||
|
@ -166,14 +166,17 @@ public class DialerFragment extends Fragment {
|
|||
}
|
||||
resetLayout(isCallTransferOngoing);
|
||||
}
|
||||
|
||||
|
||||
public void resetLayout(boolean callTransfer) {
|
||||
if (!LinphoneActivity.isInstanciated()) {
|
||||
return;
|
||||
}
|
||||
isCallTransferOngoing = LinphoneActivity.instance().isCallTransfer();
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
if (lc == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (lc.getCallsNb() > 0) {
|
||||
if (isCallTransferOngoing) {
|
||||
mCall.setImageResource(R.drawable.call_transfer);
|
||||
|
@ -193,21 +196,21 @@ public class DialerFragment extends Fragment {
|
|||
enableDisableAddContact();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void enableDisableAddContact() {
|
||||
mAddContact.setEnabled(LinphoneManager.getLc().getCallsNb() > 0 || !mAddress.getText().toString().equals(""));
|
||||
}
|
||||
|
||||
|
||||
public void displayTextInAddressBar(String numberOrSipAddress) {
|
||||
shouldEmptyAddressField = false;
|
||||
mAddress.setText(numberOrSipAddress);
|
||||
}
|
||||
|
||||
|
||||
public void newOutgoingCall(String numberOrSipAddress) {
|
||||
displayTextInAddressBar(numberOrSipAddress);
|
||||
LinphoneManager.getInstance().newOutgoingCall(mAddress);
|
||||
}
|
||||
|
||||
|
||||
public void newOutgoingCall(Intent intent) {
|
||||
if (intent != null && intent.getData() != null) {
|
||||
String scheme = intent.getData().getScheme();
|
||||
|
@ -225,10 +228,10 @@ public class DialerFragment extends Fragment {
|
|||
mAddress.setText(intent.getData().getSchemeSpecificPart());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mAddress.clearDisplayedName();
|
||||
intent.setData(null);
|
||||
|
||||
|
||||
LinphoneManager.getInstance().newOutgoingCall(mAddress);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1138,7 +1138,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
lc.removeListener(mListener);
|
||||
}
|
||||
callTransfer = false;
|
||||
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -1271,7 +1271,11 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
}
|
||||
break;
|
||||
case PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE:
|
||||
((SettingsFragment) fragment).enableDeviceRingtone(grantResults[0] == PackageManager.PERMISSION_GRANTED);
|
||||
if (permissions[0].compareTo(Manifest.permission.READ_EXTERNAL_STORAGE) != 0)
|
||||
break;
|
||||
boolean enableRingtone = (grantResults[0] == PackageManager.PERMISSION_GRANTED);
|
||||
LinphonePreferences.instance().enableDeviceRingtone(enableRingtone);
|
||||
LinphoneManager.getInstance().enableDeviceRingtone(enableRingtone);
|
||||
break;
|
||||
case PERMISSIONS_RECORD_AUDIO_ECHO_TESTER:
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
|
@ -1283,6 +1287,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
ArrayList<String> permissionsList = new ArrayList<String>();
|
||||
|
||||
int contacts = getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName());
|
||||
Log.i("[Permission] Contacts permission is " + (contacts == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
|
||||
|
@ -1290,24 +1295,33 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
int readPhone = getPackageManager().checkPermission(Manifest.permission.READ_PHONE_STATE, getPackageName());
|
||||
Log.i("[Permission] Read phone state permission is " + (readPhone == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
|
||||
|
||||
if (contacts == PackageManager.PERMISSION_GRANTED) {
|
||||
if (readPhone == PackageManager.PERMISSION_DENIED) {
|
||||
checkAndRequestReadPhoneStatePermission();
|
||||
int ringtone = getPackageManager().checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE, getPackageName());
|
||||
Log.i("[Permission] Read external storage for ring tone permission is " + (ringtone == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
|
||||
|
||||
if (ringtone != PackageManager.PERMISSION_GRANTED) {
|
||||
if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||
Log.i("[Permission] Asking for read external storage for ring tone");
|
||||
permissionsList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
}
|
||||
if (!fetchedContactsOnce) {
|
||||
ContactsManager.getInstance().enableContactsAccess();
|
||||
ContactsManager.getInstance().fetchContactsAsync();
|
||||
fetchedContactsOnce = true;
|
||||
}
|
||||
if (readPhone != PackageManager.PERMISSION_GRANTED) {
|
||||
if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_PHONE_STATE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_PHONE_STATE)) {
|
||||
Log.i("[Permission] Asking for read phone state");
|
||||
permissionsList.add(Manifest.permission.READ_PHONE_STATE);
|
||||
}
|
||||
} else {
|
||||
if (!willContactsPermissionBeAsked()) {
|
||||
ContactsManager.getInstance().fetchContactsAsync();
|
||||
fetchedContactsOnce = true;
|
||||
checkAndRequestReadPhoneStatePermission();
|
||||
} else {
|
||||
checkAndRequestReadContactsPermission(); // This will ask for Read_Phone_State permission on it's cb
|
||||
}
|
||||
if (contacts != PackageManager.PERMISSION_GRANTED) {
|
||||
if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {
|
||||
Log.i("[Permission] Asking for contacts");
|
||||
permissionsList.add(Manifest.permission.READ_CONTACTS);
|
||||
}
|
||||
}
|
||||
|
||||
if (permissionsList.size() > 0) {
|
||||
String[] permissions = new String[permissionsList.size()];
|
||||
permissions = permissionsList.toArray(permissions);
|
||||
ActivityCompat.requestPermissions(this, permissions, PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1316,7 +1330,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
outState.putBoolean("fetchedContactsOnce", fetchedContactsOnce);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
|
@ -1339,7 +1353,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
if (isTablet()) {
|
||||
// Prevent fragmentContainer2 to be visible when rotating the device
|
||||
LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);
|
||||
if (currentFragment == FragmentsAvailable.DIALER
|
||||
if (currentFragment == FragmentsAvailable.DIALER
|
||||
|| currentFragment == FragmentsAvailable.ABOUT
|
||||
|| currentFragment == FragmentsAvailable.SETTINGS
|
||||
|| currentFragment == FragmentsAvailable.ACCOUNT_SETTINGS) {
|
||||
|
|
|
@ -1248,9 +1248,8 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
|||
routeAudioToSpeaker(); // Need to be able to ear the ringtone during the early media
|
||||
}
|
||||
|
||||
if (Hacks.needGalaxySAudioHack()) {
|
||||
if (Hacks.needGalaxySAudioHack())
|
||||
mAudioManager.setMode(MODE_RINGTONE);
|
||||
}
|
||||
|
||||
try {
|
||||
if ((mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE || mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) && mVibrator != null) {
|
||||
|
|
|
@ -591,15 +591,12 @@ public final class LinphoneUtils {
|
|||
if (ctxt != null) {
|
||||
if (status.equals(LinphoneAccountCreator.Status.EmailInvalid))
|
||||
return ctxt.getString(R.string.invalid_email);
|
||||
if (status.equals(LinphoneAccountCreator.Status.UsernameInvalid)) {
|
||||
if (status.equals(LinphoneAccountCreator.Status.UsernameInvalid))
|
||||
return ctxt.getString(R.string.invalid_username);
|
||||
}
|
||||
if (status.equals(LinphoneAccountCreator.Status.UsernameTooShort)) {
|
||||
if (status.equals(LinphoneAccountCreator.Status.UsernameTooShort))
|
||||
return ctxt.getString(R.string.username_too_short);
|
||||
}
|
||||
if (status.equals(LinphoneAccountCreator.Status.UsernameTooLong)) {
|
||||
if (status.equals(LinphoneAccountCreator.Status.UsernameTooLong))
|
||||
return ctxt.getString(R.string.username_too_long);
|
||||
}
|
||||
if (status.equals(LinphoneAccountCreator.Status.UsernameInvalidSize))
|
||||
return ctxt.getString(R.string.username_invalid_size);
|
||||
if (status.equals(LinphoneAccountCreator.Status.PhoneNumberTooShort))
|
||||
|
@ -635,7 +632,7 @@ public final class LinphoneUtils {
|
|||
|| status.equals(LinphoneAccountCreator.Status.AccountAlreadyActivated)
|
||||
|| status.equals(LinphoneAccountCreator.Status.AccountActivated)
|
||||
|| status.equals(LinphoneAccountCreator.Status.Ok)) {
|
||||
return "";
|
||||
return "allo";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -516,8 +516,6 @@ private static AssistantActivity instance;
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
builder.saveNewAccount();
|
||||
if(!newAccount) {
|
||||
|
@ -737,13 +735,13 @@ private static AssistantActivity instance;
|
|||
return json;
|
||||
}
|
||||
|
||||
public boolean countryExist(String countryCode) {
|
||||
public Country getCountryFromCountryCode(String countryCode) {
|
||||
countryCode = (countryCode.startsWith("+")) ? countryCode : "+" + countryCode;
|
||||
for (Country c : allCountries) {
|
||||
if (c.dial_code.equals("+"+countryCode)) {
|
||||
return true;
|
||||
}
|
||||
if (c.dial_code.compareTo("+"+countryCode) == 0)
|
||||
return c;
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -285,11 +285,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
}
|
||||
|
||||
case R.id.assistant_create: {
|
||||
if (linkAccount) {
|
||||
addAlias();
|
||||
} else {
|
||||
createAccount();
|
||||
}
|
||||
accountCreator.isAccountActivated();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -378,6 +374,8 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
boolean isOk = status.equals(LinphoneAccountCreator.Status.Ok);
|
||||
LinphoneUtils.displayError(isOk, phoneNumberError, LinphoneUtils.errorForStatus(status));
|
||||
|
||||
accountCreator.setUsername(getUsername());
|
||||
|
||||
// Username or phone number
|
||||
if (getResources().getBoolean(R.bool.assistant_allow_username) && useUsername.isChecked()
|
||||
|| (getResources().getBoolean(R.bool.isTablet) || useEmail.isChecked()
|
||||
|
@ -410,7 +408,15 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
|
||||
private void addPhoneNumberHandler(final EditText field, final ImageView icon) {
|
||||
field.addTextChangedListener(new TextWatcher() {
|
||||
public void afterTextChanged(Editable s) {}
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (field.equals(dialCode)) {
|
||||
AssistantActivity.Country c = AssistantActivity.instance().getCountryListAdapter().getCountryFromCountryCode(dialCode.getText().toString());
|
||||
if (c != null) {
|
||||
AssistantActivity.instance().country = c;
|
||||
LinphoneUtils.setCountry(AssistantActivity.instance().country, dialCode, selectCountry, countryCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
|
@ -434,18 +440,6 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int count, int after) {
|
||||
if(s.length() > 0){
|
||||
usernameOk = false;
|
||||
Status status = accountCreator.setUsername(field.getText().toString());
|
||||
if(status.equals(Status.Ok)){
|
||||
accountCreator.isAccountUsed();
|
||||
} else {
|
||||
LinphoneUtils.displayError(usernameOk, usernameError, LinphoneUtils.errorForStatus(status));
|
||||
sipUri.setText("");
|
||||
}
|
||||
} else {
|
||||
LinphoneUtils.displayError(true, usernameError, "");
|
||||
}
|
||||
onTextChanged2();
|
||||
}
|
||||
});
|
||||
|
@ -559,15 +553,26 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
|
|||
|
||||
@Override
|
||||
public void onAccountCreatorIsAccountActivated(LinphoneAccountCreator accountCreator, Status status) {
|
||||
if (status.equals(Status.AccountNotActivated)) {
|
||||
if (useEmail.isChecked() || !getResources().getBoolean(R.bool.use_phone_number_validation)) {
|
||||
AssistantActivity.instance().displayAssistantConfirm(getUsername(), passwordEdit.getText().toString());
|
||||
} else {
|
||||
AssistantActivity.instance().displayAssistantCodeConfirm(getUsername(), phoneNumberEdit.getText().toString(), LinphoneUtils.getCountryCode(dialCode), false);
|
||||
}
|
||||
} else {
|
||||
if (linkAccount) {
|
||||
addAlias();
|
||||
} else {
|
||||
createAccount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountCreatorPhoneAccountRecovered(LinphoneAccountCreator accountCreator, Status status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountCreatorIsAccountLinked(LinphoneAccountCreator accountCreator, Status status) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue