diff --git a/app/build.gradle b/app/build.gradle index 993b139f1..28e1a8e6b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' -def getPackageName() { +static def getPackageName() { return "org.linphone" } -def firebaseEnabled() { +static def firebaseEnabled() { File googleFile = new File('app/google-services.json') return googleFile.exists() } -def isLocalAarAvailable() { +static def isLocalAarAvailable() { File debugAar = new File('linphone-sdk-android/linphone-sdk-android-debug.aar') File releaseAar = new File('linphone-sdk-android/linphone-sdk-android-release.aar') return debugAar.exists() || releaseAar.exists() @@ -103,9 +103,9 @@ android { } dependencies { - implementation 'com.google.firebase:firebase-messaging:15.0.2' + implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.android.billingclient:billing:1.2' - implementation 'org.apache.commons:commons-compress:1.16.1' + implementation 'org.apache.commons:commons-compress:1.18' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.appcompat:appcompat:1.0.2' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 93c982f89..87e98f0a8 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -232,7 +232,7 @@ + android:enabled="false"/> diff --git a/app/src/main/java/org/linphone/LinphoneActivity.java b/app/src/main/java/org/linphone/LinphoneActivity.java index bc08c24f2..723275915 100644 --- a/app/src/main/java/org/linphone/LinphoneActivity.java +++ b/app/src/main/java/org/linphone/LinphoneActivity.java @@ -85,8 +85,7 @@ import org.linphone.compatibility.Compatibility; import org.linphone.contacts.ContactAddress; import org.linphone.contacts.ContactDetailsFragment; import org.linphone.contacts.ContactEditorFragment; -import org.linphone.contacts.ContactPicked; -import org.linphone.contacts.ContactsListFragment; +import org.linphone.contacts.ContactsFragment; import org.linphone.contacts.ContactsManager; import org.linphone.contacts.LinphoneContact; import org.linphone.core.Address; @@ -122,9 +121,7 @@ import org.linphone.xmlrpc.XmlRpcHelper; import org.linphone.xmlrpc.XmlRpcListenerBase; public class LinphoneActivity extends LinphoneGenericActivity - implements OnClickListener, - ContactPicked, - ActivityCompat.OnRequestPermissionsResultCallback { + implements OnClickListener, ActivityCompat.OnRequestPermissionsResultCallback { private static final int SETTINGS_ACTIVITY = 123; private static final int CALL_ACTIVITY = 19; private static final int PERMISSIONS_REQUEST_OVERLAY = 206; @@ -146,7 +143,6 @@ public class LinphoneActivity extends LinphoneGenericActivity private ImageView mCancel; private FragmentsAvailable mPendingFragmentTransaction, mCurrentFragment, mLeftFragment; private Fragment mFragment; - private List mFragmentsHistory; private Fragment.SavedState mDialerSavedState; private boolean mNewProxyConfig; private boolean mEmptyFragment = false; @@ -163,11 +159,11 @@ public class LinphoneActivity extends LinphoneGenericActivity private boolean mIsOnBackground = false; private int mAlwaysChangingPhoneAngle = -1; - public static final boolean isInstanciated() { + public static boolean isInstanciated() { return sInstance != null; } - public static final LinphoneActivity instance() { + public static LinphoneActivity instance() { if (sInstance != null) return sInstance; throw new RuntimeException("LinphoneActivity not instantiated yet"); } @@ -219,7 +215,6 @@ public class LinphoneActivity extends LinphoneGenericActivity setContentView(R.layout.main); sInstance = this; - mFragmentsHistory = new ArrayList<>(); mPendingFragmentTransaction = FragmentsAvailable.UNKNOW; initButtons(); @@ -262,10 +257,6 @@ public class LinphoneActivity extends LinphoneGenericActivity if (state.equals(RegistrationState.Failed) && mNewProxyConfig) { mNewProxyConfig = false; - if (proxy.getError() == Reason.Forbidden) { - // displayCustomToast(getString(R.string.error_bad_credentials), - // Toast.LENGTH_LONG); - } if (proxy.getError() == Reason.Unauthorized) { displayCustomToast( getString(R.string.error_unauthorized), Toast.LENGTH_LONG); @@ -400,6 +391,7 @@ public class LinphoneActivity extends LinphoneGenericActivity DialerFragment dialerFragment = DialerFragment.instance(); mDialerSavedState = getFragmentManager().saveFragmentInstanceState(dialerFragment); } catch (Exception e) { + Log.e(e); } } @@ -413,7 +405,7 @@ public class LinphoneActivity extends LinphoneGenericActivity break; case CONTACTS_LIST: checkAndRequestWriteContactsPermission(); - mFragment = new ContactsListFragment(); + mFragment = new ContactsFragment(); break; case CONTACT_DETAIL: mFragment = new ContactDetailsFragment(); @@ -478,7 +470,7 @@ public class LinphoneActivity extends LinphoneGenericActivity ((HistoryFragment) mFragment).displayFirstLog(); break; case CONTACTS_LIST: - ((ContactsListFragment) mFragment).displayFirstContact(); + ((ContactsFragment) mFragment).displayFirstContact(); break; case CHAT_LIST: ((ChatRoomsFragment) mFragment).displayFirstChat(); @@ -584,10 +576,9 @@ public class LinphoneActivity extends LinphoneGenericActivity getFragmentManager() .popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } catch (java.lang.IllegalStateException e) { - + Log.e(e); } } - mFragmentsHistory.add(mCurrentFragment); } } @@ -681,11 +672,11 @@ public class LinphoneActivity extends LinphoneGenericActivity changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras); } - public void displayAbout() { + private void displayAbout() { changeCurrentFragment(FragmentsAvailable.ABOUT, null); } - public void displayRecordings() { + private void displayRecordings() { changeCurrentFragment(FragmentsAvailable.RECORDING_LIST, null); } @@ -697,11 +688,11 @@ public class LinphoneActivity extends LinphoneGenericActivity changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras); } - public void displayAssistant() { + private void displayAssistant() { startActivity(new Intent(LinphoneActivity.this, AssistantActivity.class)); } - public void displayInapp() { + private void displayInapp() { startActivity(new Intent(LinphoneActivity.this, InAppPurchaseActivity.class)); } @@ -930,11 +921,11 @@ public class LinphoneActivity extends LinphoneGenericActivity mTopBarTitle.setText(""); } - public void showTopBar() { + private void showTopBar() { mTopBar.setVisibility(View.VISIBLE); } - public void showTopBarWithTitle(String title) { + private void showTopBarWithTitle(String title) { showTopBar(); mTopBarTitle.setText(title); } @@ -1004,7 +995,7 @@ public class LinphoneActivity extends LinphoneGenericActivity | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); } - public void goToDialerFragment() { + private void goToDialerFragment() { Bundle extras = new Bundle(); extras.putString("SipUri", ""); changeCurrentFragment(FragmentsAvailable.DIALER, extras); @@ -1019,7 +1010,7 @@ public class LinphoneActivity extends LinphoneGenericActivity changeCurrentFragment(FragmentsAvailable.SETTINGS, null); } - public void displayDialer() { + private void displayDialer() { changeCurrentFragment(FragmentsAvailable.DIALER, null); } @@ -1053,7 +1044,6 @@ public class LinphoneActivity extends LinphoneGenericActivity mMissedChats.setVisibility(View.GONE); } if (mCurrentFragment == FragmentsAvailable.CHAT_LIST - && mFragment != null && mFragment instanceof ChatRoomsFragment) { ((ChatRoomsFragment) mFragment).invalidate(); } @@ -1108,8 +1098,7 @@ public class LinphoneActivity extends LinphoneGenericActivity return dialog; } - @Override - public void setAddresGoToDialerAndCall(String number, String name, Uri photo) { + public void setAddresGoToDialerAndCall(String number, String name) { // Bundle extras = new Bundle(); // extras.putString("SipUri", number); // extras.putString("DisplayName", name); @@ -1181,14 +1170,7 @@ public class LinphoneActivity extends LinphoneGenericActivity changeCurrentFragment(FragmentsAvailable.CONTACT_EDITOR, extras); } - public void editContact(LinphoneContact contact, String sipAddress) { - Bundle extras = new Bundle(); - extras.putSerializable("Contact", contact); - extras.putSerializable("NewSipAdress", sipAddress); - changeCurrentFragment(FragmentsAvailable.CONTACT_EDITOR, extras); - } - - public void quit() { + private void quit() { finish(); stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); @@ -1272,7 +1254,7 @@ public class LinphoneActivity extends LinphoneGenericActivity checkAndRequestPermission(Manifest.permission.CAMERA, 0); } - public void checkAndRequestWriteContactsPermission() { + private void checkAndRequestWriteContactsPermission() { checkAndRequestPermission(Manifest.permission.WRITE_CONTACTS, 0); } @@ -1333,7 +1315,7 @@ public class LinphoneActivity extends LinphoneGenericActivity Manifest.permission.WRITE_SYNC_SETTINGS, PERMISSIONS_REQUEST_SYNC); } - public void checkAndRequestPermission(String permission, int result) { + private void checkAndRequestPermission(String permission, int result) { int permissionGranted = getPackageManager().checkPermission(permission, getPackageName()); Log.i( "[Permission] " @@ -1550,7 +1532,7 @@ public class LinphoneActivity extends LinphoneGenericActivity intent.putExtra("msgShared", ""); } if (intent.getStringExtra("fileShared") != null - && intent.getStringExtra("fileShared") != "") { + && !intent.getStringExtra("fileShared").equals("")) { displayChat(null, null, intent.getStringExtra("fileShared")); intent.putExtra("fileShared", ""); } @@ -1704,7 +1686,7 @@ public class LinphoneActivity extends LinphoneGenericActivity } // SIDE MENU - public void openOrCloseSideMenu(boolean open) { + private void openOrCloseSideMenu(boolean open) { if (open) { mSideMenu.openDrawer(mSideMenuContent); } else { @@ -1712,7 +1694,7 @@ public class LinphoneActivity extends LinphoneGenericActivity } } - public void initSideMenu() { + private void initSideMenu() { mSideMenu = findViewById(R.id.side_menu); mSideMenuItems = new ArrayList<>(); if (!getResources().getBoolean(R.bool.hide_assistant_from_side_menu)) { @@ -1909,7 +1891,7 @@ public class LinphoneActivity extends LinphoneGenericActivity } @Override - public void onError(String error) {} + public void onError() {} }, LinphonePreferences.instance() .getAccountUsername( @@ -1947,7 +1929,7 @@ public class LinphoneActivity extends LinphoneGenericActivity } @Override - public void onError(String error) {} + public void onError() {} }, LinphonePreferences.instance() .getAccountUsername( @@ -1958,7 +1940,7 @@ public class LinphoneActivity extends LinphoneGenericActivity } } - public void displayInappNotification(String date) { + private void displayInappNotification(String date) { Timestamp now = new Timestamp(new Date().getTime()); if (LinphonePreferences.instance().getInappPopupTime() != null && Long.parseLong(LinphonePreferences.instance().getInappPopupTime()) @@ -2004,7 +1986,7 @@ public class LinphoneActivity extends LinphoneGenericActivity } private class LocalOrientationEventListener extends OrientationEventListener { - public LocalOrientationEventListener(Context context) { + LocalOrientationEventListener(Context context) { super(context); } @@ -2047,7 +2029,7 @@ public class LinphoneActivity extends LinphoneGenericActivity refresh(); } - public void refresh() { + void refresh() { proxy_list = new ArrayList<>(); for (ProxyConfig proxyConfig : LinphoneManager.getLc().getProxyConfigList()) { if (proxyConfig != LinphoneManager.getLc().getDefaultProxyConfig()) { @@ -2088,7 +2070,7 @@ public class LinphoneActivity extends LinphoneGenericActivity address.setText(sipAddress); int nbAccounts = LinphonePreferences.instance().getAccountCount(); - int accountIndex = 0; + int accountIndex; for (int i = 0; i < nbAccounts; i++) { String username = LinphonePreferences.instance().getAccountUsername(i); @@ -2106,10 +2088,10 @@ public class LinphoneActivity extends LinphoneGenericActivity } private class MenuItem { - public String name; - public int icon; + final String name; + final int icon; - public MenuItem(String name, int icon) { + MenuItem(String name, int icon) { this.name = name; this.icon = icon; } @@ -2120,11 +2102,10 @@ public class LinphoneActivity extends LinphoneGenericActivity } private class MenuAdapter extends ArrayAdapter { - private List mItems; - private int mResource; + private final List mItems; + private final int mResource; - public MenuAdapter( - @NonNull Context context, int resource, @NonNull List objects) { + MenuAdapter(@NonNull Context context, int resource, @NonNull List objects) { super(context, resource, objects); mResource = resource; mItems = objects; diff --git a/app/src/main/java/org/linphone/LinphoneLauncherActivity.java b/app/src/main/java/org/linphone/LinphoneLauncherActivity.java index d420c7898..6929d3c6b 100644 --- a/app/src/main/java/org/linphone/LinphoneLauncherActivity.java +++ b/app/src/main/java/org/linphone/LinphoneLauncherActivity.java @@ -72,9 +72,8 @@ public class LinphoneLauncherActivity extends Activity { } else if (Intent.ACTION_VIEW.equals(action)) { if (LinphoneService.isReady()) { mAddressToCall = - ContactsManager.getInstance() - .getAddressOrNumberForAndroidContact( - getContentResolver(), intent.getData()); + ContactsManager.getAddressOrNumberForAndroidContact( + getContentResolver(), intent.getData()); } else { mUriToResolve = intent.getData(); } @@ -91,17 +90,7 @@ public class LinphoneLauncherActivity extends Activity { } } - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - } - - protected void onServiceReady() { + private void onServiceReady() { final Class classToStart; /*if (getResources().getBoolean(R.bool.show_tutorials_instead_of_app)) { classToStart = TutorialLauncherActivity.class; @@ -128,12 +117,11 @@ public class LinphoneLauncherActivity extends Activity { newIntent.setData(intent.getData()); if (Intent.ACTION_SEND.equals(action) && type != null) { if (("text/plain").equals(type) - && (String) intent.getStringExtra(Intent.EXTRA_TEXT) - != null) { + && intent.getStringExtra(Intent.EXTRA_TEXT) != null) { stringFileShared = intent.getStringExtra(Intent.EXTRA_TEXT); newIntent.putExtra("msgShared", stringFileShared); } else { - fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); + fileUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); stringUriFileShared = FileUtils.getFilePath(getBaseContext(), fileUri); newIntent.putExtra("fileShared", stringUriFileShared); @@ -155,9 +143,8 @@ public class LinphoneLauncherActivity extends Activity { } if (mUriToResolve != null) { mAddressToCall = - ContactsManager.getInstance() - .getAddressOrNumberForAndroidContact( - getContentResolver(), mUriToResolve); + ContactsManager.getAddressOrNumberForAndroidContact( + getContentResolver(), mUriToResolve); Log.i( "LinphoneLauncher", "Intent has uri to resolve : " + mUriToResolve.toString()); diff --git a/app/src/main/java/org/linphone/LinphoneManager.java b/app/src/main/java/org/linphone/LinphoneManager.java index 7bdf524d5..4e5d3e69b 100644 --- a/app/src/main/java/org/linphone/LinphoneManager.java +++ b/app/src/main/java/org/linphone/LinphoneManager.java @@ -71,6 +71,7 @@ import org.linphone.assistant.AssistantActivity; import org.linphone.call.CallActivity; import org.linphone.call.CallIncomingActivity; import org.linphone.call.CallManager; +import org.linphone.compatibility.Compatibility; import org.linphone.contacts.ContactsManager; import org.linphone.contacts.LinphoneContact; import org.linphone.core.AccountCreator; @@ -90,7 +91,6 @@ import org.linphone.core.ConfiguringState; import org.linphone.core.Content; import org.linphone.core.Core; import org.linphone.core.Core.LogCollectionUploadState; -import org.linphone.core.CoreException; import org.linphone.core.CoreListener; import org.linphone.core.EcCalibratorStatus; import org.linphone.core.Event; @@ -151,7 +151,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou private static LinphoneManager sInstance; private static boolean sExited; - public String configFile; + public final String configFile; public String wizardLoginViewDomain = null; /** Called when the activity is first created. */ @@ -164,21 +164,21 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou private final String mCallLogDatabaseFile; private final String mFriendsDatabaseFile; private final String mUserCertsPath; - private Context mServiceContext; - private AudioManager mAudioManager; - private PowerManager mPowerManager; - private Resources mRessources; - private LinphonePreferences mPrefs; + private final Context mServiceContext; + private final AudioManager mAudioManager; + private final PowerManager mPowerManager; + private final Resources mRessources; + private final LinphonePreferences mPrefs; private Core mCore; private OpenH264DownloadHelper mCodecDownloader; private OpenH264DownloadHelperListener mCodecListener; - private String mBasePath; + private final String mBasePath; private boolean mAudioFocused; private boolean mEchoTesterIsRunning; private boolean mDozeModeEnabled; private boolean mCallGsmON; private int mLastNetworkType = -1; - private ConnectivityManager mConnectivityManager; + private final ConnectivityManager mConnectivityManager; private BroadcastReceiver mKeepAliveReceiver; private BroadcastReceiver mDozeReceiver; private BroadcastReceiver mHookReceiver; @@ -189,23 +189,23 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou private IntentFilter mHookIntentFilter; private IntentFilter mCallIntentFilter; private IntentFilter mNetworkIntentFilter; - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private WakeLock mProximityWakelock; private AccountCreator mAccountCreator; - private SensorManager mSensorManager; - private Sensor mProximity; + private final SensorManager mSensorManager; + private final Sensor mProximity; private boolean mProximitySensingEnabled; private boolean mHandsetON = false; private Address mCurrentChatRoomAddress; private Timer mTimer; - private Map mUnreadChatsPerRoom; - private MediaScanner mMediaScanner; + private final Map mUnreadChatsPerRoom; + private final MediaScanner mMediaScanner; private Call mRingingCall; private MediaPlayer mRingerPlayer; - private Vibrator mVibrator; + private final Vibrator mVibrator; private boolean mIsRinging; - protected LinphoneManager(Context c) { + private LinphoneManager(Context c) { mUnreadChatsPerRoom = new HashMap(); sExited = false; mEchoTesterIsRunning = false; @@ -241,7 +241,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou mMediaScanner = new MediaScanner(c); } - public static final synchronized LinphoneManager createAndStart(Context c) { + public static synchronized void createAndStart(Context c) { if (sInstance != null) { Log.e( "Linphone Manager is already initialized ! Destroying it and creating a new one..."); @@ -254,11 +254,9 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou // H264 codec Management - set to auto mode -> MediaCodec >= android 5.0 >= OpenH264 H264Helper.setH264Mode(H264Helper.MODE_AUTO, getLc()); - - return sInstance; } - public static final synchronized LinphoneManager getInstance() { + public static synchronized LinphoneManager getInstance() { if (sInstance != null) return sInstance; if (sExited) { @@ -270,11 +268,11 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou throw new RuntimeException("Linphone Manager should be created before accessed"); } - public static final synchronized Core getLc() { + public static synchronized Core getLc() { return getInstance().mCore; } - public static Boolean isProximitySensorNearby(final SensorEvent event) { + private static Boolean isProximitySensorNearby(final SensorEvent event) { float threshold = 4.001f; // <= 4 cm is near final float distanceInCm = event.values[0]; @@ -293,7 +291,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou return distanceInCm < threshold; } - public static void ContactsManagerDestroy() { + private static void ContactsManagerDestroy() { if (LinphoneManager.sInstance != null && LinphoneManager.sInstance.mServiceContext != null) LinphoneManager.sInstance .mServiceContext @@ -302,7 +300,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou ContactsManager.getInstance().destroy(); } - public static void BluetoothManagerDestroy() { + private static void BluetoothManagerDestroy() { BluetoothManager.getInstance().destroy(); } @@ -315,7 +313,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou sInstance = null; } - public static boolean reinviteWithVideo() { + private static boolean reinviteWithVideo() { return CallManager.getInstance().reinviteWithVideo(); } @@ -329,7 +327,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou return getLc(); } - public static final boolean isInstanciated() { + public static boolean isInstanciated() { return sInstance != null; } @@ -351,7 +349,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou mAudioManager.setSpeakerphoneOn(enable); } - public void initOpenH264DownloadHelper() { + private void initOpenH264DownloadHelper() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { Log.i("Android >= 5.1 we disable the download of OpenH264"); OpenH264DownloadHelper.setOpenH264DownloadEnabled(false); @@ -362,7 +360,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou mCodecListener = new OpenH264DownloadHelperListener() { ProgressDialog progress; - int ctxt = 0; + final int ctxt = 0; int box = 1; @Override @@ -491,7 +489,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou } } - public void changeStatusToOffline() { + private void changeStatusToOffline() { Core lc = getLcIfManagerNotDestroyedOrNull(); if (isInstanciated() && lc != null) { PresenceModel model = lc.getPresenceModel(); @@ -542,7 +540,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou ProxyConfig lpc = mCore.getDefaultProxyConfig(); if (mRessources.getBoolean(R.bool.forbid_self_call) && lpc != null - && lAddress.asStringUriOnly().equals(lpc.getIdentityAddress())) { + && lAddress.weakEqual(lpc.getIdentityAddress())) { return; } lAddress.setDisplayName(displayName); @@ -592,7 +590,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou LinphoneManager.getLc().setVideoDevice(newDevice); } - public void enableCamera(Call call, boolean enable) { + private void enableCamera(Call call, boolean enable) { if (call != null) { call.enableCamera(enable); if (mServiceContext.getResources().getBoolean(R.bool.enable_call_notification)) @@ -609,12 +607,13 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou return; } } catch (SettingNotFoundException e) { + Log.e(e); } getLc().playDtmf(dtmf, -1); } - public void terminateCall() { + private void terminateCall() { if (mCore.inCall()) { mCore.terminateCall(mCore.getCurrentCall()); } @@ -673,7 +672,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou } } - public final synchronized void destroyCore() { + private final synchronized void destroyCore() { sExited = true; ContactsManagerDestroy(); BluetoothManagerDestroy(); @@ -707,8 +706,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou } try { dozeManager(false); - } catch (IllegalArgumentException iae) { - Log.e(iae); } catch (Exception e) { Log.e(e); } @@ -776,12 +773,12 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou } } - private synchronized void initLiblinphone(Core lc) throws CoreException { + private synchronized void initLiblinphone(Core lc) { mCore = lc; mCore.setZrtpSecretsFile(mBasePath + "/zrtp_secrets"); - String deviceName = LinphoneUtils.getDeviceName(mServiceContext); + String deviceName = Compatibility.getDeviceName(mServiceContext); String appName = mServiceContext.getResources().getString(R.string.user_agent); String androidVersion = BuildConfig.VERSION_NAME; String userAgent = appName + "/" + androidVersion + " (" + deviceName + ") LinphoneSDK"; @@ -907,14 +904,14 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou copyFromPackage(R.raw.assistant_create, new File(mDynamicConfigFile).getName()); } - public void copyIfNotExist(int ressourceId, String target) throws IOException { + private void copyIfNotExist(int ressourceId, String target) throws IOException { File lFileToCopy = new File(target); if (!lFileToCopy.exists()) { copyFromPackage(ressourceId, lFileToCopy.getName()); } } - public void copyFromPackage(int ressourceId, String target) throws IOException { + private void copyFromPackage(int ressourceId, String target) throws IOException { FileOutputStream lOutputStream = mServiceContext.openFileOutput(target, 0); InputStream lInputStream = mRessources.openRawResource(ressourceId); int readByte; @@ -998,7 +995,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou mCore = null; } - public void dozeManager(boolean enable) { + private void dozeManager(boolean enable) { if (enable) { Log.i("[Doze Mode]: register"); mServiceContext.registerReceiver(mDozeReceiver, mDozeIntentFilter); @@ -1068,7 +1065,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou I/Linphone( 8397): Managing tunnel I/Linphone( 8397): WIFI connected: setting network reachable */ - public void connectivityChanged(ConnectivityManager cm, boolean noConnectivity) { + public void connectivityChanged() { updateNetworkReachability(); } @@ -1241,8 +1238,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou } catch (IllegalArgumentException iae) { Log.e(iae); - } catch (CoreException e) { - Log.e(e); } } } @@ -1276,7 +1271,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou mAudioManager.setMode(AudioManager.MODE_NORMAL); } - public void setAudioManagerInCallMode() { + private void setAudioManagerInCallMode() { if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) { Log.w("[AudioManager] already in MODE_IN_COMMUNICATION, skipping..."); return; @@ -1392,7 +1387,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou if (remoteVideo && !localVideo && !autoAcceptCameraPolicy - && !(LinphoneManager.getLc().getConference() != null)) { + && LinphoneManager.getLc().getConference() == null) { LinphoneManager.getLc().deferCallUpdate(call); } } @@ -1410,7 +1405,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou } } - public void startBluetooth() { + private void startBluetooth() { if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { BluetoothManager.getInstance().routeAudioToBluetooth(); } @@ -1427,7 +1422,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou public void onCallEncryptionChanged( Core lc, Call call, boolean encrypted, String authenticationToken) {} - public void startEcCalibration() throws CoreException { + public void startEcCalibration() { routeAudioToSpeaker(); setAudioManagerInCallMode(); Log.i("Set audio mode on 'Voice Communication'"); @@ -1439,25 +1434,23 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou mAudioManager.setStreamVolume(STREAM_VOICE_CALL, oldVolume, 0); } - public int startEchoTester() throws CoreException { + public int startEchoTester() { routeAudioToSpeaker(); setAudioManagerInCallMode(); Log.i("Set audio mode on 'Voice Communication'"); requestAudioFocus(STREAM_VOICE_CALL); int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL); - int sampleRate = 44100; + int sampleRate; mAudioManager.setStreamVolume(STREAM_VOICE_CALL, maxVolume, 0); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - String sampleRateProperty = - mAudioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); - sampleRate = Integer.parseInt(sampleRateProperty); - } + String sampleRateProperty = + mAudioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); + sampleRate = Integer.parseInt(sampleRateProperty); mCore.startEchoTester(sampleRate); mEchoTesterIsRunning = true; return 1; } - public int stopEchoTester() throws CoreException { + public int stopEchoTester() { mEchoTesterIsRunning = false; mCore.stopEchoTester(); routeAudioToReceiver(); @@ -1607,31 +1600,17 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou return false; } - return acceptCallWithParams(call, params); - } - - public boolean acceptCallWithParams(Call call, CallParams params) { mCore.acceptCallWithParams(call, params); return true; } public void adjustVolume(int i) { - if (Build.VERSION.SDK_INT < 15) { - int oldVolume = mAudioManager.getStreamVolume(LINPHONE_VOLUME_STREAM); - int maxVolume = mAudioManager.getStreamMaxVolume(LINPHONE_VOLUME_STREAM); - - int nextVolume = oldVolume + i; - if (nextVolume > maxVolume) nextVolume = maxVolume; - if (nextVolume < 0) nextVolume = 0; - - mCore.setPlaybackGainDb((nextVolume - maxVolume) * dbStep); - } else - // starting from ICS, volume must be adjusted by the application, at least for - // STREAM_VOICE_CALL volume stream - mAudioManager.adjustStreamVolume( - LINPHONE_VOLUME_STREAM, - i < 0 ? AudioManager.ADJUST_LOWER : AudioManager.ADJUST_RAISE, - AudioManager.FLAG_SHOW_UI); + // starting from ICS, volume must be adjusted by the application, at least for + // STREAM_VOICE_CALL volume stream + mAudioManager.adjustStreamVolume( + LINPHONE_VOLUME_STREAM, + i < 0 ? AudioManager.ADJUST_LOWER : AudioManager.ADJUST_RAISE, + AudioManager.FLAG_SHOW_UI); } public void isAccountWithAlias() { diff --git a/app/src/main/java/org/linphone/LinphoneService.java b/app/src/main/java/org/linphone/LinphoneService.java index d555696a6..62038d5ea 100644 --- a/app/src/main/java/org/linphone/LinphoneService.java +++ b/app/src/main/java/org/linphone/LinphoneService.java @@ -69,11 +69,11 @@ public final class LinphoneService extends Service { /* Listener needs to be implemented in the Service as it calls * setLatestEventInfo and startActivity() which needs a context. */ - public static final String START_LINPHONE_LOGS = " ==== Phone information dump ===="; + private static final String START_LINPHONE_LOGS = " ==== Phone information dump ===="; private static LinphoneService sInstance; - public Handler handler = new Handler(); + public final Handler handler = new Handler(); private boolean mTestDelayElapsed = true; private CoreListenerStub mListener; @@ -108,7 +108,7 @@ public final class LinphoneService extends Service { } } - protected void onBackgroundMode() { + private void onBackgroundMode() { Log.i("App has entered background mode"); if (LinphonePreferences.instance() != null && LinphonePreferences.instance().isFriendlistsubscriptionEnabled()) { @@ -120,7 +120,7 @@ public final class LinphoneService extends Service { } } - protected void onForegroundMode() { + private void onForegroundMode() { Log.i("App has left background mode"); if (LinphonePreferences.instance() != null && LinphonePreferences.instance().isFriendlistsubscriptionEnabled()) { @@ -316,7 +316,7 @@ public final class LinphoneService extends Service { sb.append("SDK=").append(Build.VERSION.SDK_INT).append("\n"); sb.append("Supported ABIs="); for (String abi : Version.getCpuAbis()) { - sb.append(abi + ", "); + sb.append(abi).append(", "); } sb.append("\n"); Log.i(sb.toString()); @@ -327,6 +327,7 @@ public final class LinphoneService extends Service { try { info = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (NameNotFoundException nnfe) { + Log.e(nnfe); } if (info != null) { @@ -400,7 +401,7 @@ public final class LinphoneService extends Service { } } - protected void onIncomingReceived() { + private void onIncomingReceived() { // wakeup linphone startActivity( new Intent() @@ -412,7 +413,7 @@ public final class LinphoneService extends Service { After two days of hard work I ended with the following class, that does the job more or less reliabily. */ class ActivityMonitor implements Application.ActivityLifecycleCallbacks { - private ArrayList activities = new ArrayList<>(); + private final ArrayList activities = new ArrayList<>(); private boolean mActive = false; private int mRunningActivities = 0; private InactivityChecker mLastChecker; @@ -459,9 +460,7 @@ public final class LinphoneService extends Service { @Override public synchronized void onActivityDestroyed(Activity activity) { Log.i("Activity destroyed:" + activity); - if (activities.contains(activity)) { - activities.remove(activity); - } + activities.remove(activity); } void startInactivityChecker() { @@ -488,7 +487,7 @@ public final class LinphoneService extends Service { class InactivityChecker implements Runnable { private boolean isCanceled; - public void cancel() { + void cancel() { isCanceled = true; } diff --git a/app/src/main/java/org/linphone/assistant/AssistantActivity.java b/app/src/main/java/org/linphone/assistant/AssistantActivity.java index f0ae19a75..eda31b318 100644 --- a/app/src/main/java/org/linphone/assistant/AssistantActivity.java +++ b/app/src/main/java/org/linphone/assistant/AssistantActivity.java @@ -356,16 +356,16 @@ public class AssistantActivity extends Activity } } - public void checkAndRequestAudioPermission() { + private void checkAndRequestAudioPermission() { checkAndRequestPermission( Manifest.permission.RECORD_AUDIO, PERMISSIONS_REQUEST_RECORD_AUDIO); } - public void checkAndRequestVideoPermission() { + private void checkAndRequestVideoPermission() { checkAndRequestPermission(Manifest.permission.CAMERA, PERMISSIONS_REQUEST_CAMERA); } - public void checkAndRequestPermission(String permission, int result) { + private void checkAndRequestPermission(String permission, int result) { int permissionGranted = getPackageManager().checkPermission(permission, getPackageName()); Log.i( "[Permission] " @@ -405,7 +405,7 @@ public class AssistantActivity extends Activity break; case PERMISSIONS_REQUEST_RECORD_AUDIO: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - launchEchoCancellerCalibration(true); + launchEchoCancellerCalibration(); } else { isEchoCalibrationFinished(); } @@ -413,7 +413,7 @@ public class AssistantActivity extends Activity } } - private void launchEchoCancellerCalibration(boolean sendEcCalibrationResult) { + private void launchEchoCancellerCalibration() { int recordAudio = getPackageManager() .checkPermission(Manifest.permission.RECORD_AUDIO, getPackageName()); @@ -425,7 +425,7 @@ public class AssistantActivity extends Activity if (recordAudio == PackageManager.PERMISSION_GRANTED) { EchoCancellerCalibrationFragment fragment = new EchoCancellerCalibrationFragment(); - fragment.enableEcCalibrationResultSending(sendEcCalibrationResult); + fragment.enableEcCalibrationResultSending(true); changeFragment(fragment); mCurrentFragment = AssistantFragmentsEnum.ECHO_CANCELLER_CALIBRATION; mBack.setVisibility(View.VISIBLE); @@ -435,7 +435,7 @@ public class AssistantActivity extends Activity } } - public void configureProxyConfig(AccountCreator accountCreator) { + private void configureProxyConfig(AccountCreator accountCreator) { Core lc = LinphoneManager.getLc(); ProxyConfig proxyConfig = lc.createProxyConfig(); AuthInfo authInfo; @@ -526,7 +526,7 @@ public class AssistantActivity extends Activity } } - public void displayMenu() { + private void displayMenu() { mFragment = new WelcomeFragment(); changeFragment(mFragment); country = null; @@ -617,7 +617,7 @@ public class AssistantActivity extends Activity goToLinphoneActivity(); } - public void saveCreatedAccount( + private void saveCreatedAccount( String username, String userid, String password, @@ -665,7 +665,7 @@ public class AssistantActivity extends Activity } } - public void displayRegistrationInProgressDialog() { + private void displayRegistrationInProgressDialog() { if (LinphoneManager.getLc().isNetworkReachable()) { mProgress = ProgressDialog.show(this, null, null); Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorE)); @@ -741,7 +741,7 @@ public class AssistantActivity extends Activity mBack.setVisibility(View.VISIBLE); } - public void isAccountVerified(String username) { + public void isAccountVerified() { Toast.makeText(this, getString(R.string.assistant_account_validated), Toast.LENGTH_LONG) .show(); hideKeyboard(); @@ -752,7 +752,7 @@ public class AssistantActivity extends Activity launchDownloadCodec(); } - public Dialog createErrorDialog(ProxyConfig proxy, String message) { + private Dialog createErrorDialog(ProxyConfig proxy, String message) { AlertDialog.Builder builder = new AlertDialog.Builder(this); if (message.equals("Forbidden")) { message = getString(R.string.assistant_error_bad_credentials); @@ -784,7 +784,7 @@ public class AssistantActivity extends Activity public void success() { boolean needsEchoCalibration = LinphoneManager.getLc().isEchoCancellerCalibrationRequired(); if (needsEchoCalibration && mPrefs.isFirstLaunch()) { - launchEchoCancellerCalibration(true); + launchEchoCancellerCalibration(); } else { launchDownloadCodec(); } @@ -896,11 +896,11 @@ public class AssistantActivity extends Activity public class CountryListAdapter extends BaseAdapter implements Filterable { private LayoutInflater mInflater; - private DialPlan[] allCountries; + private final DialPlan[] allCountries; private List filteredCountries; - private Context context; + private final Context context; - public CountryListAdapter(Context ctx) { + CountryListAdapter(Context ctx) { context = ctx; allCountries = Factory.instance().getDialPlans(); filteredCountries = new ArrayList<>(Arrays.asList(allCountries)); @@ -964,7 +964,7 @@ public class AssistantActivity extends Activity return new Filter() { @Override protected FilterResults performFiltering(CharSequence constraint) { - ArrayList filteredCountries = new ArrayList(); + ArrayList filteredCountries = new ArrayList<>(); for (DialPlan c : allCountries) { if (c.getCountry().toLowerCase().contains(constraint) || c.getCountryCallingCode().contains(constraint)) { diff --git a/app/src/main/java/org/linphone/assistant/CodecDownloaderFragment.java b/app/src/main/java/org/linphone/assistant/CodecDownloaderFragment.java index f28cd7440..4d4ec41ee 100644 --- a/app/src/main/java/org/linphone/assistant/CodecDownloaderFragment.java +++ b/app/src/main/java/org/linphone/assistant/CodecDownloaderFragment.java @@ -36,7 +36,7 @@ import org.linphone.core.tools.OpenH264DownloadHelper; import org.linphone.core.tools.OpenH264DownloadHelperListener; public class CodecDownloaderFragment extends Fragment { - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private TextView mQuestion; private TextView mDownloading; private TextView mDownloaded; diff --git a/app/src/main/java/org/linphone/assistant/CountryListFragment.java b/app/src/main/java/org/linphone/assistant/CountryListFragment.java index 81d54bae5..34dbedca7 100644 --- a/app/src/main/java/org/linphone/assistant/CountryListFragment.java +++ b/app/src/main/java/org/linphone/assistant/CountryListFragment.java @@ -77,8 +77,7 @@ public class CountryListFragment extends Fragment @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - DialPlan c = (DialPlan) view.getTag(); - AssistantActivity.instance().country = c; + AssistantActivity.instance().country = (DialPlan) view.getTag(); AssistantActivity.instance().onBackPressed(); } diff --git a/app/src/main/java/org/linphone/assistant/CreateAccountActivationFragment.java b/app/src/main/java/org/linphone/assistant/CreateAccountActivationFragment.java index 796cba82d..dc15184a9 100644 --- a/app/src/main/java/org/linphone/assistant/CreateAccountActivationFragment.java +++ b/app/src/main/java/org/linphone/assistant/CreateAccountActivationFragment.java @@ -109,7 +109,7 @@ public class CreateAccountActivationFragment extends Fragment .show(); } else if (status.equals(AccountCreator.Status.AccountActivated)) { AssistantActivity.instance().linphoneLogIn(accountCreator); - AssistantActivity.instance().isAccountVerified(mUsername); + AssistantActivity.instance().isAccountVerified(); } else { Toast.makeText( getActivity(), diff --git a/app/src/main/java/org/linphone/assistant/CreateAccountCodeActivationFragment.java b/app/src/main/java/org/linphone/assistant/CreateAccountCodeActivationFragment.java index b58cf8659..8354458e3 100644 --- a/app/src/main/java/org/linphone/assistant/CreateAccountCodeActivationFragment.java +++ b/app/src/main/java/org/linphone/assistant/CreateAccountCodeActivationFragment.java @@ -155,14 +155,14 @@ public class CreateAccountCodeActivationFragment extends Fragment if (accountCreator.getUsername() != null) { AssistantActivity.instance().linphoneLogIn(accountCreator); if (!mRecoverAccount) { - AssistantActivity.instance().isAccountVerified(accountCreator.getUsername()); + AssistantActivity.instance().isAccountVerified(); } else { AssistantActivity.instance().success(); } } else { AssistantActivity.instance().linphoneLogIn(accountCreator); if (!mRecoverAccount) { - AssistantActivity.instance().isAccountVerified(accountCreator.getPhoneNumber()); + AssistantActivity.instance().isAccountVerified(); } else { AssistantActivity.instance().success(); } diff --git a/app/src/main/java/org/linphone/assistant/CreateAccountFragment.java b/app/src/main/java/org/linphone/assistant/CreateAccountFragment.java index 7257c295c..17d67e55a 100644 --- a/app/src/main/java/org/linphone/assistant/CreateAccountFragment.java +++ b/app/src/main/java/org/linphone/assistant/CreateAccountFragment.java @@ -180,8 +180,8 @@ public class CreateAccountFragment extends Fragment mUseUsername.setVisibility(View.VISIBLE); mUseUsername.setOnCheckedChangeListener(this); } - addPhoneNumberHandler(mPhoneNumberEdit, null); - addPhoneNumberHandler(mDialCode, null); + addPhoneNumberHandler(mPhoneNumberEdit); + addPhoneNumberHandler(mDialCode); } // Password & email address @@ -205,9 +205,9 @@ public class CreateAccountFragment extends Fragment } } - addPasswordHandler(mPasswordEdit, null); - addConfirmPasswordHandler(mPasswordEdit, mPasswordConfirmEdit, null); - addEmailHandler(mEmailEdit, null); + addPasswordHandler(mPasswordEdit); + addConfirmPasswordHandler(mPasswordEdit, mPasswordConfirmEdit); + addEmailHandler(mEmailEdit); } // Hide phone number and display username/email/password @@ -242,7 +242,7 @@ public class CreateAccountFragment extends Fragment mAccountCreator.setLanguage(Locale.getDefault().toLanguageTag()); } - addUsernameHandler(mUsernameEdit, null); + addUsernameHandler(mUsernameEdit); mCreateAccount.setEnabled(true); mCreateAccount.setOnClickListener(this); @@ -472,7 +472,7 @@ public class CreateAccountFragment extends Fragment return status; } - public void onTextChanged2() { + private void onTextChanged2() { String msg = ""; mAccountCreator.setUsername(getUsername()); @@ -532,7 +532,7 @@ public class CreateAccountFragment extends Fragment mSipUri.setText(msg); } - private void addPhoneNumberHandler(final EditText field, final ImageView icon) { + private void addPhoneNumberHandler(final EditText field) { field.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) { @@ -560,7 +560,7 @@ public class CreateAccountFragment extends Fragment }); } - private void addUsernameHandler(final EditText field, final ImageView icon) { + private void addUsernameHandler(final EditText field) { field.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) { @@ -584,7 +584,7 @@ public class CreateAccountFragment extends Fragment }); } - private void addEmailHandler(final EditText field, final ImageView icon) { + private void addEmailHandler(final EditText field) { field.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) { @@ -609,7 +609,7 @@ public class CreateAccountFragment extends Fragment }); } - private void addPasswordHandler(final EditText field1, final ImageView icon) { + private void addPasswordHandler(final EditText field1) { TextWatcher passwordListener = new TextWatcher() { public void afterTextChanged(Editable s) { @@ -636,8 +636,7 @@ public class CreateAccountFragment extends Fragment field1.addTextChangedListener(passwordListener); } - private void addConfirmPasswordHandler( - final EditText field1, final EditText field2, final ImageView icon) { + private void addConfirmPasswordHandler(final EditText field1, final EditText field2) { TextWatcher passwordListener = new TextWatcher() { public void afterTextChanged(Editable s) { diff --git a/app/src/main/java/org/linphone/assistant/EchoCancellerCalibrationFragment.java b/app/src/main/java/org/linphone/assistant/EchoCancellerCalibrationFragment.java index bf1948b22..9b4960503 100644 --- a/app/src/main/java/org/linphone/assistant/EchoCancellerCalibrationFragment.java +++ b/app/src/main/java/org/linphone/assistant/EchoCancellerCalibrationFragment.java @@ -29,7 +29,6 @@ import android.view.ViewGroup; import org.linphone.LinphoneManager; import org.linphone.R; import org.linphone.core.Core; -import org.linphone.core.CoreException; import org.linphone.core.CoreListenerStub; import org.linphone.core.EcCalibratorStatus; import org.linphone.core.XmlRpcArgType; @@ -40,7 +39,7 @@ import org.linphone.mediastream.Log; import org.linphone.settings.LinphonePreferences; public class EchoCancellerCalibrationFragment extends Fragment implements XmlRpcRequestListener { - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private boolean mSendEcCalibrationResult = false; private CoreListenerStub mListener; private XmlRpcSession mXmlRpcSession; @@ -80,13 +79,8 @@ public class EchoCancellerCalibrationFragment extends Fragment implements XmlRpc mXmlRpcSession.createRequest(XmlRpcArgType.None, "add_ec_calibration_result"); mXmlRpcRequest.setListener(this); - try { - LinphoneManager.getLc().addListener(mListener); - LinphoneManager.getInstance().startEcCalibration(); - } catch (CoreException e) { - Log.e(e, "Unable to calibrate EC"); - AssistantActivity.instance().isEchoCalibrationFinished(); - } + LinphoneManager.getLc().addListener(mListener); + LinphoneManager.getInstance().startEcCalibration(); return view; } diff --git a/app/src/main/java/org/linphone/assistant/LinphoneLoginFragment.java b/app/src/main/java/org/linphone/assistant/LinphoneLoginFragment.java index c8d5d817b..d17e931e2 100644 --- a/app/src/main/java/org/linphone/assistant/LinphoneLoginFragment.java +++ b/app/src/main/java/org/linphone/assistant/LinphoneLoginFragment.java @@ -195,13 +195,13 @@ public class LinphoneLoginFragment extends Fragment mAccountCreator.setLanguage(Locale.getDefault().toLanguageTag()); } - addPhoneNumberHandler(mDialCode, null); - addPhoneNumberHandler(mPhoneNumberEdit, null); + addPhoneNumberHandler(mDialCode); + addPhoneNumberHandler(mPhoneNumberEdit); return view; } - public void linphoneLogIn() { + private void linphoneLogIn() { if (mLogin.getText() == null || mLogin.length() == 0 || mPassword.getText() == null @@ -222,7 +222,7 @@ public class LinphoneLoginFragment extends Fragment mPhoneNumberEdit.getText().toString(), LinphoneUtils.getCountryCode(mDialCode)); } - private void addPhoneNumberHandler(final EditText field, final ImageView icon) { + private void addPhoneNumberHandler(final EditText field) { field.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) { @@ -253,8 +253,7 @@ public class LinphoneLoginFragment extends Fragment @Override public void onResume() { super.onResume(); - if (mUseUsername != null && mUseUsername.isChecked()) mRecoverAccount = false; - else mRecoverAccount = true; + mRecoverAccount = mUseUsername == null || !mUseUsername.isChecked(); } @Override @@ -305,7 +304,7 @@ public class LinphoneLoginFragment extends Fragment @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - public void onTextChanged2() { + private void onTextChanged2() { int status = getPhoneNumberStatus(); boolean isOk = status == AccountCreator.PhoneNumberStatus.Ok.toInt(); LinphoneUtils.displayError( diff --git a/app/src/main/java/org/linphone/assistant/QrCodeFragment.java b/app/src/main/java/org/linphone/assistant/QrCodeFragment.java index 0862d5e6a..95a06104a 100644 --- a/app/src/main/java/org/linphone/assistant/QrCodeFragment.java +++ b/app/src/main/java/org/linphone/assistant/QrCodeFragment.java @@ -66,12 +66,12 @@ public class QrCodeFragment extends Fragment { } } - private void setBackCamera(boolean useBackCamera) { + private void setBackCamera() { int camId = 0; AndroidCameraConfiguration.AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras(); for (AndroidCameraConfiguration.AndroidCamera androidCamera : cameras) { - if (androidCamera.frontFacing == !useBackCamera) camId = androidCamera.id; + if (!androidCamera.frontFacing) camId = androidCamera.id; } String[] devices = LinphoneManager.getLc().getVideoDevicesList(); String newDevice = devices[camId]; @@ -79,7 +79,7 @@ public class QrCodeFragment extends Fragment { } private void launchQrcodeReader() { - setBackCamera(true); + setBackCamera(); enableQrcodeReader(true); } diff --git a/app/src/main/java/org/linphone/assistant/RemoteProvisioningActivity.java b/app/src/main/java/org/linphone/assistant/RemoteProvisioningActivity.java index 5c8ab5a65..844fa9c2b 100644 --- a/app/src/main/java/org/linphone/assistant/RemoteProvisioningActivity.java +++ b/app/src/main/java/org/linphone/assistant/RemoteProvisioningActivity.java @@ -41,7 +41,7 @@ import org.linphone.mediastream.Log; import org.linphone.settings.LinphonePreferences; public class RemoteProvisioningActivity extends Activity { - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private String mConfigUriParam = null; private ProgressBar mSpinner; private CoreListenerStub mListener; @@ -92,11 +92,6 @@ public class RemoteProvisioningActivity extends Activity { super.onPause(); } - @Override - protected void onDestroy() { - super.onDestroy(); - } - @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); diff --git a/app/src/main/java/org/linphone/assistant/RemoteProvisioningLoginActivity.java b/app/src/main/java/org/linphone/assistant/RemoteProvisioningLoginActivity.java index d73110d3f..5429c7698 100644 --- a/app/src/main/java/org/linphone/assistant/RemoteProvisioningLoginActivity.java +++ b/app/src/main/java/org/linphone/assistant/RemoteProvisioningLoginActivity.java @@ -75,17 +75,15 @@ public class RemoteProvisioningLoginActivity extends Activity implements OnClick }; } - private void cancelWizard(boolean bypassCheck) { - if (bypassCheck - || getResources() - .getBoolean(R.bool.allow_cancel_remote_provisioning_login_activity)) { + private void cancelWizard() { + if (getResources().getBoolean(R.bool.allow_cancel_remote_provisioning_login_activity)) { LinphonePreferences.instance().disableProvisioningLoginView(); - setResult(bypassCheck ? Activity.RESULT_OK : Activity.RESULT_CANCELED); + setResult(Activity.RESULT_CANCELED); finish(); } } - private boolean storeAccount(String username, String password, String domain) { + private void storeAccount(String username, String password, String domain) { XmlRpcHelper xmlRpcHelper = new XmlRpcHelper(); xmlRpcHelper.getRemoteProvisioningFilenameAsync( new XmlRpcListenerBase() { @@ -95,14 +93,13 @@ public class RemoteProvisioningLoginActivity extends Activity implements OnClick LinphoneManager.getInstance().restartCore(); } }, - username.toString(), - password.toString(), - domain.toString()); + username, + password, + domain); LinphonePreferences.instance().firstLaunchSuccessful(); setResult(Activity.RESULT_OK); finish(); - return true; } @Override @@ -128,7 +125,7 @@ public class RemoteProvisioningLoginActivity extends Activity implements OnClick int id = v.getId(); if (id == R.id.cancel) { - cancelWizard(false); + cancelWizard(); } if (id == R.id.assistant_connect) { storeAccount( @@ -140,6 +137,6 @@ public class RemoteProvisioningLoginActivity extends Activity implements OnClick @Override public void onBackPressed() { - cancelWizard(false); + cancelWizard(); } } diff --git a/app/src/main/java/org/linphone/call/BandwidthManager.java b/app/src/main/java/org/linphone/call/BandwidthManager.java index ac51c387e..a6f63105b 100644 --- a/app/src/main/java/org/linphone/call/BandwidthManager.java +++ b/app/src/main/java/org/linphone/call/BandwidthManager.java @@ -20,17 +20,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import org.linphone.core.CallParams; -import org.linphone.core.Core; public class BandwidthManager { - public static final int HIGH_RESOLUTION = 0; - public static final int LOW_RESOLUTION = 1; - public static final int LOW_BANDWIDTH = 2; + private static final int HIGH_RESOLUTION = 0; + private static final int LOW_RESOLUTION = 1; + private static final int LOW_BANDWIDTH = 2; private static BandwidthManager sInstance; - private int currentProfile = HIGH_RESOLUTION; + private final int currentProfile = HIGH_RESOLUTION; private BandwidthManager() { // FIXME register a listener on NetworkManager to get notified of network state @@ -39,12 +38,12 @@ public class BandwidthManager { // FIXME initially get those values } - public static final synchronized BandwidthManager getInstance() { + public static synchronized BandwidthManager getInstance() { if (sInstance == null) sInstance = new BandwidthManager(); return sInstance; } - public void updateWithProfileSettings(Core lc, CallParams callParams) { + public void updateWithProfileSettings(CallParams callParams) { if (callParams != null) { // in call // Update video parm if if (!isVideoPossible()) { // NO VIDEO @@ -57,7 +56,7 @@ public class BandwidthManager { } } - public boolean isVideoPossible() { + private boolean isVideoPossible() { return currentProfile != LOW_BANDWIDTH; } } diff --git a/app/src/main/java/org/linphone/call/CallActivity.java b/app/src/main/java/org/linphone/call/CallActivity.java index 8cacfd00c..b7273d2af 100644 --- a/app/src/main/java/org/linphone/call/CallActivity.java +++ b/app/src/main/java/org/linphone/call/CallActivity.java @@ -29,7 +29,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; -import android.content.res.Resources; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -58,7 +57,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; import java.text.DecimalFormat; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Timer; @@ -149,7 +148,7 @@ public class CallActivity extends LinphoneGenericActivity private CoreListenerStub mListener; private DrawerLayout mSideMenu; - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private Timer mTimer; private TimerTask mTask; private HashMap mEncoderTexts; @@ -225,7 +224,7 @@ public class CallActivity extends LinphoneGenericActivity } } else if (state == State.Resuming) { if (LinphonePreferences.instance().isVideoEnabled()) { - mStatus.refreshStatusItems(call, isVideoEnabled(call)); + mStatus.refreshStatusItems(call); if (call.getCurrentParams().videoEnabled()) { showVideoView(); } @@ -239,7 +238,7 @@ public class CallActivity extends LinphoneGenericActivity if (mStatus != null) { mVideoProgress.setVisibility(View.GONE); - mStatus.refreshStatusItems(call, isVideoEnabled(call)); + mStatus.refreshStatusItems(call); } } else if (state == State.UpdatedByRemote) { // If the correspondent proposes mVideo while audio call @@ -279,8 +278,7 @@ public class CallActivity extends LinphoneGenericActivity && !call.getAuthenticationTokenVerified()) { mStatus.showZRTPDialog(call); } - mStatus.refreshStatusItems( - call, call.getCurrentParams().videoEnabled()); + mStatus.refreshStatusItems(call); } } }; @@ -337,7 +335,7 @@ public class CallActivity extends LinphoneGenericActivity } } - public void createTimerForDialog(long time) { + private void createTimerForDialog(long time) { mCountDownTimer = new CountDownTimer(time, 1000) { public void onTick(long millisUntilFinished) { @@ -494,7 +492,7 @@ public class CallActivity extends LinphoneGenericActivity LinphoneManager.getInstance().changeStatusToOnThePhone(); } - public void checkAndRequestPermission(String permission, int result) { + private void checkAndRequestPermission(String permission, int result) { int permissionGranted = getPackageManager().checkPermission(permission, getPackageName()); Log.i( "[Permission] " @@ -570,7 +568,7 @@ public class CallActivity extends LinphoneGenericActivity } } - public void createInCallStats() { + private void createInCallStats() { mSideMenu = findViewById(R.id.side_menu); mMenu = findViewById(R.id.call_quality); @@ -596,7 +594,7 @@ public class CallActivity extends LinphoneGenericActivity private void refreshIncallUi() { refreshInCallActions(); - refreshCallList(getResources()); + refreshCallList(); enableAndRefreshInCallActions(); displayMissedChats(); } @@ -713,10 +711,6 @@ public class CallActivity extends LinphoneGenericActivity public void onClick(View v) { int id = v.getId(); - if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) { - // displayVideoCallControlsIfHidden(); - } - if (id == R.id.video) { int camera = getPackageManager() @@ -868,7 +862,7 @@ public class CallActivity extends LinphoneGenericActivity } } - public void displayCustomToast(final String message, final int duration) { + private void displayCustomToast(final String message, final int duration) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot)); @@ -962,6 +956,7 @@ public class CallActivity extends LinphoneGenericActivity try { transaction.commitAllowingStateLoss(); } catch (Exception e) { + Log.e(e); } } @@ -974,6 +969,7 @@ public class CallActivity extends LinphoneGenericActivity try { transaction.commitAllowingStateLoss(); } catch (Exception e) { + Log.e(e); } } @@ -984,7 +980,7 @@ public class CallActivity extends LinphoneGenericActivity mMicro.setSelected(mIsMicMuted); } - protected void toggleSpeaker() { + private void toggleSpeaker() { mIsSpeakerEnabled = !mIsSpeakerEnabled; if (LinphoneManager.getLc().getCurrentCall() != null) { if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) @@ -1001,7 +997,7 @@ public class CallActivity extends LinphoneGenericActivity } } - public void pauseOrResumeCall(Call call) { + private void pauseOrResumeCall(Call call) { Core lc = LinphoneManager.getLc(); if (call != null && LinphoneManager.getLc().getCurrentCall() == call) { lc.pauseCall(call); @@ -1037,7 +1033,7 @@ public class CallActivity extends LinphoneGenericActivity } } - public void displayVideoCall(boolean display) { + private void displayVideoCall(boolean display) { if (display) { showStatusBar(); mControlsLayout.setVisibility(View.VISIBLE); @@ -1157,7 +1153,7 @@ public class CallActivity extends LinphoneGenericActivity } } - public void goBackToDialer() { + private void goBackToDialer() { Intent intent = new Intent(); intent.setClass(this, LinphoneActivity.class); intent.putExtra("AddCall", true); @@ -1178,7 +1174,7 @@ public class CallActivity extends LinphoneGenericActivity startActivity(intent); } - public void acceptCallUpdate(boolean accept) { + private void acceptCallUpdate(boolean accept) { if (mCountDownTimer != null) { mCountDownTimer.cancel(); } @@ -1202,7 +1198,7 @@ public class CallActivity extends LinphoneGenericActivity startActivity(new Intent(this, CallIncomingActivity.class)); } - public void hideStatusBar() { + private void hideStatusBar() { if (isTablet()) { return; } @@ -1211,7 +1207,7 @@ public class CallActivity extends LinphoneGenericActivity findViewById(R.id.fragmentContainer).setPadding(0, 0, 0, 0); } - public void showStatusBar() { + private void showStatusBar() { if (isTablet()) { return; } @@ -1324,7 +1320,7 @@ public class CallActivity extends LinphoneGenericActivity private void handleViewIntent() { Intent intent = getIntent(); - if (intent != null && intent.getAction() == "android.intent.action.VIEW") { + if (intent != null && intent.getAction().equals("android.intent.action.VIEW")) { Call call = LinphoneManager.getLc().getCurrentCall(); if (call != null && isVideoEnabled(call)) { Player player = call.getPlayer(); @@ -1415,7 +1411,6 @@ public class CallActivity extends LinphoneGenericActivity mDialog.dismiss(); mDialog = null; } - return; } public void bindAudioFragment(CallAudioFragment fragment) { @@ -1434,7 +1429,7 @@ public class CallActivity extends LinphoneGenericActivity registerCallDurationTimer(null, call); } - private void displayPausedCalls(Resources resources, final Call call, int index) { + private void displayPausedCalls(final Call call, int index) { // Control Row LinearLayout callView; @@ -1482,8 +1477,7 @@ public class CallActivity extends LinphoneGenericActivity } } - private boolean displayCallStatusIconAndReturnCallPaused(LinearLayout callView, Call call) { - boolean isCallPaused, isInConference; + private void displayCallStatusIconAndReturnCallPaused(LinearLayout callView, Call call) { ImageView onCallStateChanged = callView.findViewById(R.id.call_pause); onCallStateChanged.setTag(call); onCallStateChanged.setOnClickListener(this); @@ -1492,19 +1486,10 @@ public class CallActivity extends LinphoneGenericActivity || call.getState() == State.PausedByRemote || call.getState() == State.Pausing) { onCallStateChanged.setSelected(false); - isCallPaused = true; - isInConference = false; } else if (call.getState() == State.OutgoingInit || call.getState() == State.OutgoingProgress || call.getState() == State.OutgoingRinging) { - isCallPaused = false; - isInConference = false; - } else { - isInConference = mIsConferenceRunning && call.getConference() != null; - isCallPaused = false; } - - return isCallPaused || isInConference; } private void registerCallDurationTimer(View v, Call call) { @@ -1528,11 +1513,11 @@ public class CallActivity extends LinphoneGenericActivity timer.start(); } - public void refreshCallList(Resources resources) { + private void refreshCallList() { mIsConferenceRunning = LinphoneManager.getLc().isInConference(); List pausedCalls = LinphoneUtils.getCallsInState( - LinphoneManager.getLc(), Arrays.asList(State.PausedByRemote)); + LinphoneManager.getLc(), Collections.singletonList(State.PausedByRemote)); // MultiCalls if (LinphoneManager.getLc().getCallsNb() > 1) { @@ -1580,8 +1565,8 @@ public class CallActivity extends LinphoneGenericActivity index++; } else { if (call != LinphoneManager.getLc().getCurrentCall() - && !(call.getConference() != null)) { - displayPausedCalls(resources, call, index); + && call.getConference() == null) { + displayPausedCalls(call, index); index++; } else { displayCurrentCall(call); @@ -1592,7 +1577,7 @@ public class CallActivity extends LinphoneGenericActivity if (!mIsConferenceRunning) { if (isConfPaused) { mCallsList.setVisibility(View.VISIBLE); - displayPausedCalls(resources, null, index); + displayPausedCalls(null, index); } } } @@ -1622,7 +1607,7 @@ public class CallActivity extends LinphoneGenericActivity LinphoneManager.getLc().addAllToConference(); } - public void pauseOrResumeConference() { + private void pauseOrResumeConference() { Core lc = LinphoneManager.getLc(); mConferenceStatus = findViewById(R.id.conference_pause); if (mConferenceStatus != null) { @@ -1634,7 +1619,7 @@ public class CallActivity extends LinphoneGenericActivity lc.enterConference(); } } - refreshCallList(getResources()); + refreshCallList(); } private void displayConferenceParticipant(int index, final Call call) { @@ -1838,7 +1823,7 @@ public class CallActivity extends LinphoneGenericActivity } } - public void initCallStatsRefresher(final Call call, final View view) { + private void initCallStatsRefresher(final Call call, final View view) { if (mCallDisplayedInStats == call) return; if (mTimer != null && mTask != null) { diff --git a/app/src/main/java/org/linphone/call/CallAudioFragment.java b/app/src/main/java/org/linphone/call/CallAudioFragment.java index d49e3fc0c..68b20c9c6 100644 --- a/app/src/main/java/org/linphone/call/CallAudioFragment.java +++ b/app/src/main/java/org/linphone/call/CallAudioFragment.java @@ -30,8 +30,7 @@ public class CallAudioFragment extends Fragment { @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.audio, container, false); - return view; + return inflater.inflate(R.layout.audio, container, false); } @Override diff --git a/app/src/main/java/org/linphone/call/CallIncomingActivity.java b/app/src/main/java/org/linphone/call/CallIncomingActivity.java index 0d15763f3..d9592c10b 100644 --- a/app/src/main/java/org/linphone/call/CallIncomingActivity.java +++ b/app/src/main/java/org/linphone/call/CallIncomingActivity.java @@ -267,7 +267,7 @@ public class CallIncomingActivity extends LinphoneGenericActivity { } private void checkAndRequestCallPermissions() { - ArrayList permissionsList = new ArrayList(); + ArrayList permissionsList = new ArrayList<>(); int recordAudio = getPackageManager() diff --git a/app/src/main/java/org/linphone/call/CallManager.java b/app/src/main/java/org/linphone/call/CallManager.java index 1d74ec9f7..6d078cebf 100644 --- a/app/src/main/java/org/linphone/call/CallManager.java +++ b/app/src/main/java/org/linphone/call/CallManager.java @@ -34,7 +34,7 @@ public class CallManager { private static CallManager sInstance; - public static final synchronized CallManager getInstance() { + public static synchronized CallManager getInstance() { if (sInstance == null) sInstance = new CallManager(); return sInstance; } @@ -57,7 +57,7 @@ public class CallManager { Core lc = LinphoneManager.getLc(); CallParams params = lc.createCallParams(null); - getBandwidthManager().updateWithProfileSettings(lc, params); + getBandwidthManager().updateWithProfileSettings(params); if (videoEnabled && params.videoEnabled()) { params.enableVideo(true); @@ -96,7 +96,7 @@ public class CallManager { if (params.videoEnabled()) return false; // Check if video possible regarding bandwidth limitations - getBandwidthManager().updateWithProfileSettings(lc, params); + getBandwidthManager().updateWithProfileSettings(params); // Abort if not enough bandwidth... if (!params.videoEnabled()) { @@ -121,7 +121,7 @@ public class CallManager { return; } CallParams params = lc.createCallParams(lCall); - getBandwidthManager().updateWithProfileSettings(lc, params); + getBandwidthManager().updateWithProfileSettings(params); lc.updateCall(lCall, null); } } diff --git a/app/src/main/java/org/linphone/call/CallOutgoingActivity.java b/app/src/main/java/org/linphone/call/CallOutgoingActivity.java index 6b23ad51a..8ab334277 100644 --- a/app/src/main/java/org/linphone/call/CallOutgoingActivity.java +++ b/app/src/main/java/org/linphone/call/CallOutgoingActivity.java @@ -61,10 +61,6 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC private CoreListenerStub mListener; private boolean mIsMicMuted, mIsSpeakerEnabled; - public static CallOutgoingActivity instance() { - return sInstance; - } - public static boolean isInstanciated() { return sInstance != null; } @@ -152,7 +148,6 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC if (LinphoneManager.getLc().getCallsNb() == 0) { finish(); - return; } } }; @@ -266,7 +261,7 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC return super.onKeyDown(keyCode, event); } - public void displayCustomToast(final String message, final int duration) { + private void displayCustomToast(final String message, final int duration) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot)); @@ -286,7 +281,7 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC } private void checkAndRequestCallPermissions() { - ArrayList permissionsList = new ArrayList(); + ArrayList permissionsList = new ArrayList<>(); int recordAudio = getPackageManager() diff --git a/app/src/main/java/org/linphone/chat/ChatMessageOldViewHolder.java b/app/src/main/java/org/linphone/chat/ChatMessageOldViewHolder.java index c47df56eb..102bdeaae 100644 --- a/app/src/main/java/org/linphone/chat/ChatMessageOldViewHolder.java +++ b/app/src/main/java/org/linphone/chat/ChatMessageOldViewHolder.java @@ -19,7 +19,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import android.content.Context; import android.view.View; import android.widget.Button; import android.widget.CheckBox; @@ -36,40 +35,37 @@ public class ChatMessageOldViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { public String messageId; public ChatMessage message; - public LinearLayout eventLayout; - public TextView eventMessage; + public final LinearLayout eventLayout; + public final TextView eventMessage; - public RelativeLayout bubbleLayout; - public LinearLayout separatorLayout; - public LinearLayout background; - public RelativeLayout avatarLayout; - public TextView contactName; + public final RelativeLayout bubbleLayout; + public final LinearLayout separatorLayout; + public final LinearLayout background; + public final RelativeLayout avatarLayout; + public final TextView contactName; - public ImageView messageStatus; - public ProgressBar messageSendingInProgress; - public LinearLayout imdmLayout; - public ImageView imdmIcon; - public TextView imdmLabel; + public final ImageView messageStatus; + public final ProgressBar messageSendingInProgress; + public final LinearLayout imdmLayout; + public final ImageView imdmIcon; + public final TextView imdmLabel; - public TextView messageText; - public ImageView messageImage; + public final TextView messageText; + public final ImageView messageImage; - public RelativeLayout fileTransferLayout; - public ProgressBar fileTransferProgressBar; - public Button fileTransferAction; + public final RelativeLayout fileTransferLayout; + public final ProgressBar fileTransferProgressBar; + public final Button fileTransferAction; - public TextView fileName; - public Button openFileButton; + public final TextView fileName; + public final Button openFileButton; - public CheckBox delete; + public final CheckBox delete; - private Context mContext; private ChatMessageViewHolderClickListener mListener; - public ChatMessageOldViewHolder( - Context context, View view, ChatMessageViewHolderClickListener listener) { + public ChatMessageOldViewHolder(View view, ChatMessageViewHolderClickListener listener) { this(view); - mContext = context; mListener = listener; view.setOnClickListener(this); } diff --git a/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java b/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java index 3d01860b6..447c06789 100644 --- a/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java +++ b/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java @@ -61,28 +61,27 @@ import org.linphone.views.BitmapWorkerTask; import org.linphone.views.ContactAvatar; public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - public ChatMessage message; - public LinearLayout eventLayout; - public TextView eventMessage; + public final LinearLayout eventLayout; + public final TextView eventMessage; - public LinearLayout securityEventLayout; - public TextView securityEventMessage; + public final LinearLayout securityEventLayout; + public final TextView securityEventMessage; - public View rightAnchor; - public RelativeLayout bubbleLayout; - public LinearLayout background; - public RelativeLayout avatarLayout; + public final View rightAnchor; + public final RelativeLayout bubbleLayout; + public final LinearLayout background; + public final RelativeLayout avatarLayout; - public ProgressBar sendInProgress; - public TextView timeText; - public ImageView outgoingImdn; - public TextView messageText; + public final ProgressBar sendInProgress; + public final TextView timeText; + public final ImageView outgoingImdn; + public final TextView messageText; - public FlexboxLayout pictures; + public final FlexboxLayout pictures; - public CheckBox deleteEvent; - public CheckBox deleteMessage; + public final CheckBox deleteEvent; + public final CheckBox deleteMessage; private Context mContext; private ChatMessageViewHolderClickListener mListener; @@ -356,7 +355,7 @@ public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements Vi if (bitmapWorkerTask != null) { final String bitmapData = bitmapWorkerTask.path; // If bitmapData is not yet set or it differs from the new data - if (bitmapData == null || bitmapData != path) { + if (bitmapData == null || !bitmapData.equals(path)) { // Cancel previous task bitmapWorkerTask.cancel(true); } else { diff --git a/app/src/main/java/org/linphone/chat/ChatMessageViewHolderClickListener.java b/app/src/main/java/org/linphone/chat/ChatMessageViewHolderClickListener.java index 02403370b..e5b49ebb2 100644 --- a/app/src/main/java/org/linphone/chat/ChatMessageViewHolderClickListener.java +++ b/app/src/main/java/org/linphone/chat/ChatMessageViewHolderClickListener.java @@ -19,6 +19,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -public interface ChatMessageViewHolderClickListener { +interface ChatMessageViewHolderClickListener { void onItemClicked(int position); } diff --git a/app/src/main/java/org/linphone/chat/ChatMessagesAdapter.java b/app/src/main/java/org/linphone/chat/ChatMessagesAdapter.java index 16548ac21..f6b12f56b 100644 --- a/app/src/main/java/org/linphone/chat/ChatMessagesAdapter.java +++ b/app/src/main/java/org/linphone/chat/ChatMessagesAdapter.java @@ -41,17 +41,17 @@ import org.linphone.utils.SelectableHelper; public class ChatMessagesAdapter extends SelectableAdapter implements ChatMessagesGenericAdapter { - public static int MAX_TIME_TO_GROUP_MESSAGES = 60; + private static final int MAX_TIME_TO_GROUP_MESSAGES = 60; - private Context mContext; + private final Context mContext; private List mHistory; private List mParticipants; - private int mItemResource; - private ChatMessagesFragment mFragment; + private final int mItemResource; + private final ChatMessagesFragment mFragment; - private List mTransientMessages; + private final List mTransientMessages; - private ChatMessageViewHolderClickListener mClickListener; + private final ChatMessageViewHolderClickListener mClickListener; public ChatMessagesAdapter( ChatMessagesFragment fragment, @@ -292,10 +292,6 @@ public class ChatMessagesAdapter extends SelectableAdapter 0) { for (String file : files) { @@ -1352,8 +1350,7 @@ public class ChatMessagesFragment extends Fragment // This is a workaround to prevent a crash from happening while rotating the device private class LinphoneLinearLayoutManager extends LinearLayoutManager { - public LinphoneLinearLayoutManager( - Context context, int orientation, boolean reverseLayout) { + LinphoneLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { super(context, orientation, reverseLayout); } diff --git a/app/src/main/java/org/linphone/chat/ChatMessagesGenericAdapter.java b/app/src/main/java/org/linphone/chat/ChatMessagesGenericAdapter.java index f4176bf08..b9e90ffd6 100644 --- a/app/src/main/java/org/linphone/chat/ChatMessagesGenericAdapter.java +++ b/app/src/main/java/org/linphone/chat/ChatMessagesGenericAdapter.java @@ -23,7 +23,7 @@ import java.util.ArrayList; import org.linphone.contacts.LinphoneContact; import org.linphone.core.EventLog; -public interface ChatMessagesGenericAdapter { +interface ChatMessagesGenericAdapter { void addToHistory(EventLog log); void addAllToHistory(ArrayList logs); diff --git a/app/src/main/java/org/linphone/chat/ChatMessagesOldAdapter.java b/app/src/main/java/org/linphone/chat/ChatMessagesOldAdapter.java index 31578916d..51affc4d8 100644 --- a/app/src/main/java/org/linphone/chat/ChatMessagesOldAdapter.java +++ b/app/src/main/java/org/linphone/chat/ChatMessagesOldAdapter.java @@ -67,17 +67,17 @@ import org.linphone.views.ContactAvatar; public class ChatMessagesOldAdapter extends SelectableAdapter implements ChatMessagesGenericAdapter { - private static int MARGIN_BETWEEN_MESSAGES = 10; - private static int SIDE_MARGIN = 100; - private Context mContext; + private static final int MARGIN_BETWEEN_MESSAGES = 10; + private static final int SIDE_MARGIN = 100; + private final Context mContext; private List mHistory; private List mParticipants; - private int mItemResource; + private final int mItemResource; private Bitmap mDefaultBitmap; - private ChatMessagesFragment mFragment; - private ChatMessageListenerStub mListener; + private final ChatMessagesFragment mFragment; + private final ChatMessageListenerStub mListener; - private ChatMessageViewHolderClickListener mClickListener; + private final ChatMessageViewHolderClickListener mClickListener; public ChatMessagesOldAdapter( ChatMessagesFragment fragment, @@ -140,7 +140,7 @@ public class ChatMessagesOldAdapter extends SelectableAdapter 0 ? true : false; + mOnlyDisplayLinphoneContacts = ContactsManager.getInstance().getSIPContacts().size() > 0; if (savedInstanceState != null) { mOnlyDisplayLinphoneContacts = savedInstanceState.getBoolean("onlySipContact", true); } @@ -431,7 +431,7 @@ public class ChatRoomCreationFragment extends Fragment @Override public void onSaveInstanceState(Bundle outState) { if (mContactsSelected != null && mContactsSelected.size() > 0) { - ArrayList listUri = new ArrayList(); + ArrayList listUri = new ArrayList<>(); for (ContactAddress ca : mContactsSelected) { listUri.add(ca.getAddressAsDisplayableString()); } @@ -507,7 +507,7 @@ public class ChatRoomCreationFragment extends Fragment Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); ProxyConfig lpc = lc.getDefaultProxyConfig(); boolean createEncryptedChatRoom = mSecurityToggle.isChecked(); - if (lpc == null || lpc.getConferenceFactoryUri() == null || mCreateGroupChatRoom == false) { + if (lpc == null || lpc.getConferenceFactoryUri() == null || !mCreateGroupChatRoom) { if (createEncryptedChatRoom && lpc != null && lpc.getConferenceFactoryUri() != null) { mChatRoom = lc.findOneToOneChatRoom(lpc.getIdentityAddress(), ca.getAddress(), true); diff --git a/app/src/main/java/org/linphone/chat/ChatRoomViewHolder.java b/app/src/main/java/org/linphone/chat/ChatRoomViewHolder.java index 4495da06b..3bc0fcef0 100644 --- a/app/src/main/java/org/linphone/chat/ChatRoomViewHolder.java +++ b/app/src/main/java/org/linphone/chat/ChatRoomViewHolder.java @@ -39,16 +39,16 @@ import org.linphone.views.ContactAvatar; public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { - public TextView lastMessageView; - public TextView date; - public TextView displayName; - public TextView unreadMessages; - public CheckBox delete; - public RelativeLayout avatarLayout; + public final TextView lastMessageView; + public final TextView date; + public final TextView displayName; + public final TextView unreadMessages; + public final CheckBox delete; + public final RelativeLayout avatarLayout; public ChatRoom room; - private Context mContext; - private ClickListener mListener; + private final Context mContext; + private final ClickListener mListener; public ChatRoomViewHolder(Context context, View itemView, ClickListener listener) { super(itemView); @@ -71,12 +71,12 @@ public class ChatRoomViewHolder extends RecyclerView.ViewHolder ChatMessage lastMessage = this.room.getLastMessageInHistory(); if (lastMessage != null) { - String messageContent = ""; + StringBuilder messageContent = new StringBuilder(); for (Content c : lastMessage.getContents()) { if (c.isFile() || c.isFileTransfer()) { - messageContent += c.getName() + " "; + messageContent.append(c.getName()).append(" "); } else if (c.isText()) { - messageContent = c.getStringBuffer() + " " + messageContent; + messageContent.insert(0, c.getStringBuffer() + " "); } } lastMessageView.setText(getSender(this.room) + messageContent); diff --git a/app/src/main/java/org/linphone/chat/ChatRoomsAdapter.java b/app/src/main/java/org/linphone/chat/ChatRoomsAdapter.java index c17ccc590..8fd1e5c5b 100644 --- a/app/src/main/java/org/linphone/chat/ChatRoomsAdapter.java +++ b/app/src/main/java/org/linphone/chat/ChatRoomsAdapter.java @@ -34,10 +34,10 @@ import org.linphone.utils.SelectableAdapter; import org.linphone.utils.SelectableHelper; public class ChatRoomsAdapter extends SelectableAdapter { - private Context mContext; - public List mRooms; - private int mItemResource; - private ChatRoomViewHolder.ClickListener mClickListener; + private final Context mContext; + private List mRooms; + private final int mItemResource; + private final ChatRoomViewHolder.ClickListener mClickListener; public ChatRoomsAdapter( Context context, diff --git a/app/src/main/java/org/linphone/chat/ChatScrollListener.java b/app/src/main/java/org/linphone/chat/ChatScrollListener.java index 61442fa6d..496bd5a26 100644 --- a/app/src/main/java/org/linphone/chat/ChatScrollListener.java +++ b/app/src/main/java/org/linphone/chat/ChatScrollListener.java @@ -22,20 +22,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -public abstract class ChatScrollListener extends RecyclerView.OnScrollListener { +abstract class ChatScrollListener extends RecyclerView.OnScrollListener { // The minimum amount of items to have below your current scroll position // before mLoading more. - private int mVisibleThreshold = 5; - // The current offset index of data you have loaded - private int mCurrentPage = 0; + private final int mVisibleThreshold = 5; // The total number of items in the dataset after the last load private int mPreviousTotalItemCount = 0; // True if we are still waiting for the last set of data to load. private boolean mLoading = true; // Sets the starting page index - private int mStartingPageIndex = 0; + private final int mStartingPageIndex = 0; - private LinearLayoutManager mLayoutManager; + private final LinearLayoutManager mLayoutManager; public ChatScrollListener(LinearLayoutManager layoutManager) { mLayoutManager = layoutManager; @@ -46,7 +44,7 @@ public abstract class ChatScrollListener extends RecyclerView.OnScrollListener { // but first we check if we are waiting for the previous load to finish. @Override public void onScrolled(RecyclerView view, int dx, int dy) { - int lastVisibleItemPosition = 0; + int lastVisibleItemPosition; int totalItemCount = mLayoutManager.getItemCount(); lastVisibleItemPosition = mLayoutManager.findLastVisibleItemPosition(); @@ -54,7 +52,6 @@ public abstract class ChatScrollListener extends RecyclerView.OnScrollListener { // If the total item count is zero and the previous isn't, assume the // list is invalidated and should be reset back to initial state if (totalItemCount < mPreviousTotalItemCount) { - this.mCurrentPage = this.mStartingPageIndex; this.mPreviousTotalItemCount = totalItemCount; if (totalItemCount == 0) { this.mLoading = true; @@ -73,12 +70,11 @@ public abstract class ChatScrollListener extends RecyclerView.OnScrollListener { // If we do need to reload some more data, we execute onLoadMore to fetch the data. // threshold should reflect how many total columns there are too if (!mLoading && (lastVisibleItemPosition + mVisibleThreshold) > totalItemCount) { - mCurrentPage++; - onLoadMore(mCurrentPage, totalItemCount, view); + onLoadMore(totalItemCount); mLoading = true; } } // Defines the process for actually mLoading more data based on page - public abstract void onLoadMore(int page, int totalItemsCount, RecyclerView view); + protected abstract void onLoadMore(int totalItemsCount); } diff --git a/app/src/main/java/org/linphone/chat/DeviceChildViewHolder.java b/app/src/main/java/org/linphone/chat/DeviceChildViewHolder.java index 43f4adf70..2498372be 100644 --- a/app/src/main/java/org/linphone/chat/DeviceChildViewHolder.java +++ b/app/src/main/java/org/linphone/chat/DeviceChildViewHolder.java @@ -24,9 +24,9 @@ import android.widget.ImageView; import android.widget.TextView; import org.linphone.R; -public class DeviceChildViewHolder { - public TextView deviceName; - public ImageView securityLevel; +class DeviceChildViewHolder { + public final TextView deviceName; + public final ImageView securityLevel; public DeviceChildViewHolder(View v) { deviceName = v.findViewById(R.id.name); diff --git a/app/src/main/java/org/linphone/chat/DeviceGroupViewHolder.java b/app/src/main/java/org/linphone/chat/DeviceGroupViewHolder.java index a928ca3cc..332318953 100644 --- a/app/src/main/java/org/linphone/chat/DeviceGroupViewHolder.java +++ b/app/src/main/java/org/linphone/chat/DeviceGroupViewHolder.java @@ -25,10 +25,10 @@ import android.widget.RelativeLayout; import android.widget.TextView; import org.linphone.R; -public class DeviceGroupViewHolder { - public RelativeLayout avatarLayout; - public TextView participantName; - public ImageView groupExpander; +class DeviceGroupViewHolder { + public final RelativeLayout avatarLayout; + public final TextView participantName; + public final ImageView groupExpander; public DeviceGroupViewHolder(View v) { avatarLayout = v.findViewById(R.id.avatar_layout); diff --git a/app/src/main/java/org/linphone/chat/DevicesAdapter.java b/app/src/main/java/org/linphone/chat/DevicesAdapter.java index fcc690a37..9e2d7a872 100644 --- a/app/src/main/java/org/linphone/chat/DevicesAdapter.java +++ b/app/src/main/java/org/linphone/chat/DevicesAdapter.java @@ -36,8 +36,8 @@ import org.linphone.core.ParticipantDevice; import org.linphone.utils.LinphoneUtils; import org.linphone.views.ContactAvatar; -public class DevicesAdapter extends BaseExpandableListAdapter { - private Context mContext; +class DevicesAdapter extends BaseExpandableListAdapter { + private final Context mContext; private List mParticipants; private boolean mOnlyDisplayChildsAsGroups; diff --git a/app/src/main/java/org/linphone/chat/GroupInfoAdapter.java b/app/src/main/java/org/linphone/chat/GroupInfoAdapter.java index e3eaf8882..ca7d6b795 100644 --- a/app/src/main/java/org/linphone/chat/GroupInfoAdapter.java +++ b/app/src/main/java/org/linphone/chat/GroupInfoAdapter.java @@ -33,7 +33,7 @@ import org.linphone.core.ChatRoom; import org.linphone.core.Participant; import org.linphone.views.ContactAvatar; -public class GroupInfoAdapter extends RecyclerView.Adapter { +class GroupInfoAdapter extends RecyclerView.Adapter { private List mItems; private View.OnClickListener mDeleteListener; private boolean mHideAdminFeatures; @@ -136,11 +136,7 @@ public class GroupInfoAdapter extends RecyclerView.Adapter mChatRoom = room; } - public int getCount() { - return mItems.size(); - } - - public Object getItem(int i) { + private Object getItem(int i) { return mItems.get(i); } diff --git a/app/src/main/java/org/linphone/chat/GroupInfoFragment.java b/app/src/main/java/org/linphone/chat/GroupInfoFragment.java index 4d7339c9f..ce2ee4bc1 100644 --- a/app/src/main/java/org/linphone/chat/GroupInfoFragment.java +++ b/app/src/main/java/org/linphone/chat/GroupInfoFragment.java @@ -62,7 +62,6 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener { private RelativeLayout mAddParticipantsLayout; private Address mGroupChatRoomAddress; private EditText mSubjectField; - private LayoutInflater mInflater; private RecyclerView mParticipantsList; @@ -84,7 +83,6 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener { @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mInflater = inflater; View view = inflater.inflate(R.layout.chat_infos, container, false); if (getArguments() == null || getArguments().isEmpty()) { diff --git a/app/src/main/java/org/linphone/chat/GroupInfoViewHolder.java b/app/src/main/java/org/linphone/chat/GroupInfoViewHolder.java index 757bc4bae..2dc336d30 100644 --- a/app/src/main/java/org/linphone/chat/GroupInfoViewHolder.java +++ b/app/src/main/java/org/linphone/chat/GroupInfoViewHolder.java @@ -28,11 +28,11 @@ import androidx.recyclerview.widget.RecyclerView; import org.linphone.R; public class GroupInfoViewHolder extends RecyclerView.ViewHolder { - public TextView name; - public RelativeLayout avatarLayout; - public ImageView delete; - public LinearLayout isAdmin; - public LinearLayout isNotAdmin; + public final TextView name; + public final RelativeLayout avatarLayout; + public final ImageView delete; + public final LinearLayout isAdmin; + public final LinearLayout isNotAdmin; public GroupInfoViewHolder(View view) { super(view); diff --git a/app/src/main/java/org/linphone/compatibility/ApiTwentyEightPlus.java b/app/src/main/java/org/linphone/compatibility/ApiTwentyEightPlus.java index 38169d978..37c736d0c 100644 --- a/app/src/main/java/org/linphone/compatibility/ApiTwentyEightPlus.java +++ b/app/src/main/java/org/linphone/compatibility/ApiTwentyEightPlus.java @@ -40,7 +40,7 @@ import org.linphone.notifications.NotifiableMessage; import org.linphone.notifications.NotificationBroadcastReceiver; @TargetApi(28) -public class ApiTwentyEightPlus { +class ApiTwentyEightPlus { public static Notification createMessageNotification( Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) { String replyLabel = context.getResources().getString(R.string.notification_reply_label); diff --git a/app/src/main/java/org/linphone/compatibility/ApiTwentyFourPlus.java b/app/src/main/java/org/linphone/compatibility/ApiTwentyFourPlus.java index 99aee97ad..c4f3c7d31 100644 --- a/app/src/main/java/org/linphone/compatibility/ApiTwentyFourPlus.java +++ b/app/src/main/java/org/linphone/compatibility/ApiTwentyFourPlus.java @@ -40,7 +40,7 @@ import org.linphone.notifications.NotifiableMessage; import org.linphone.notifications.NotificationBroadcastReceiver; @TargetApi(24) -public class ApiTwentyFourPlus { +class ApiTwentyFourPlus { public static Notification createRepliedNotification(Context context, String reply) { return new Notification.Builder(context) diff --git a/app/src/main/java/org/linphone/compatibility/ApiTwentyOnePlus.java b/app/src/main/java/org/linphone/compatibility/ApiTwentyOnePlus.java index 55f2366fb..9802b5e77 100644 --- a/app/src/main/java/org/linphone/compatibility/ApiTwentyOnePlus.java +++ b/app/src/main/java/org/linphone/compatibility/ApiTwentyOnePlus.java @@ -28,7 +28,7 @@ import androidx.core.content.ContextCompat; import org.linphone.R; @TargetApi(21) -public class ApiTwentyOnePlus { +class ApiTwentyOnePlus { @SuppressWarnings("deprecation") public static Notification createMessageNotification( @@ -47,61 +47,54 @@ public class ApiTwentyOnePlus { .replace("%i", String.valueOf(msgCount)); } - Notification notif = - new Notification.Builder(context) - .setContentTitle(title) - .setContentText(msg) - .setSmallIcon(R.drawable.topbar_chat_notification) - .setAutoCancel(true) - .setContentIntent(intent) - .setDefaults( - Notification.DEFAULT_SOUND - | Notification.DEFAULT_VIBRATE - | Notification.DEFAULT_LIGHTS) - .setLargeIcon(contactIcon) - .setLights( - ContextCompat.getColor(context, R.color.notification_color_led), - context.getResources().getInteger(R.integer.notification_ms_on), - context.getResources().getInteger(R.integer.notification_ms_off)) - .setCategory(Notification.CATEGORY_MESSAGE) - .setVisibility(Notification.VISIBILITY_PRIVATE) - .setPriority(Notification.PRIORITY_HIGH) - .setNumber(msgCount) - .setWhen(System.currentTimeMillis()) - .setShowWhen(true) - .build(); - - return notif; + return new Notification.Builder(context) + .setContentTitle(title) + .setContentText(msg) + .setSmallIcon(R.drawable.topbar_chat_notification) + .setAutoCancel(true) + .setContentIntent(intent) + .setDefaults( + Notification.DEFAULT_SOUND + | Notification.DEFAULT_VIBRATE + | Notification.DEFAULT_LIGHTS) + .setLargeIcon(contactIcon) + .setLights( + ContextCompat.getColor(context, R.color.notification_color_led), + context.getResources().getInteger(R.integer.notification_ms_on), + context.getResources().getInteger(R.integer.notification_ms_off)) + .setCategory(Notification.CATEGORY_MESSAGE) + .setVisibility(Notification.VISIBILITY_PRIVATE) + .setPriority(Notification.PRIORITY_HIGH) + .setNumber(msgCount) + .setWhen(System.currentTimeMillis()) + .setShowWhen(true) + .build(); } public static Notification createInCallNotification( Context context, - String title, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) { - Notification notif = - new Notification.Builder(context) - .setContentTitle(contactName) - .setContentText(msg) - .setSmallIcon(iconID) - .setAutoCancel(false) - .setContentIntent(intent) - .setLargeIcon(contactIcon) - .setCategory(Notification.CATEGORY_CALL) - .setVisibility(Notification.VISIBILITY_PUBLIC) - .setPriority(Notification.PRIORITY_HIGH) - .setLights( - ContextCompat.getColor(context, R.color.notification_color_led), - context.getResources().getInteger(R.integer.notification_ms_on), - context.getResources().getInteger(R.integer.notification_ms_off)) - .setShowWhen(true) - .build(); - - return notif; + return new Notification.Builder(context) + .setContentTitle(contactName) + .setContentText(msg) + .setSmallIcon(iconID) + .setAutoCancel(false) + .setContentIntent(intent) + .setLargeIcon(contactIcon) + .setCategory(Notification.CATEGORY_CALL) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setPriority(Notification.PRIORITY_HIGH) + .setLights( + ContextCompat.getColor(context, R.color.notification_color_led), + context.getResources().getInteger(R.integer.notification_ms_on), + context.getResources().getInteger(R.integer.notification_ms_off)) + .setShowWhen(true) + .build(); } public static Notification createNotification( @@ -112,7 +105,6 @@ public class ApiTwentyOnePlus { int level, Bitmap largeIcon, PendingIntent intent, - boolean isOngoingEvent, int priority) { Notification notif; @@ -160,49 +152,45 @@ public class ApiTwentyOnePlus { public static Notification createMissedCallNotification( Context context, String title, String text, PendingIntent intent) { - Notification notif = - new Notification.Builder(context) - .setContentTitle(title) - .setContentText(text) - .setSmallIcon(R.drawable.call_status_missed) - .setAutoCancel(true) - .setContentIntent(intent) - .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) - .setCategory(Notification.CATEGORY_EVENT) - .setVisibility(Notification.VISIBILITY_PRIVATE) - .setLights( - ContextCompat.getColor(context, R.color.notification_color_led), - context.getResources().getInteger(R.integer.notification_ms_on), - context.getResources().getInteger(R.integer.notification_ms_off)) - .setPriority(Notification.PRIORITY_HIGH) - .setWhen(System.currentTimeMillis()) - .setShowWhen(true) - .build(); - return notif; + return new Notification.Builder(context) + .setContentTitle(title) + .setContentText(text) + .setSmallIcon(R.drawable.call_status_missed) + .setAutoCancel(true) + .setContentIntent(intent) + .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) + .setCategory(Notification.CATEGORY_EVENT) + .setVisibility(Notification.VISIBILITY_PRIVATE) + .setLights( + ContextCompat.getColor(context, R.color.notification_color_led), + context.getResources().getInteger(R.integer.notification_ms_on), + context.getResources().getInteger(R.integer.notification_ms_off)) + .setPriority(Notification.PRIORITY_HIGH) + .setWhen(System.currentTimeMillis()) + .setShowWhen(true) + .build(); } public static Notification createSimpleNotification( Context context, String title, String text, PendingIntent intent) { - Notification notif = - new Notification.Builder(context) - .setContentTitle(title) - .setContentText(text) - .setSmallIcon(R.drawable.linphone_logo) - .setAutoCancel(true) - .setContentIntent(intent) - .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) - .setCategory(Notification.CATEGORY_MESSAGE) - .setVisibility(Notification.VISIBILITY_PRIVATE) - .setLights( - ContextCompat.getColor(context, R.color.notification_color_led), - context.getResources().getInteger(R.integer.notification_ms_on), - context.getResources().getInteger(R.integer.notification_ms_off)) - .setWhen(System.currentTimeMillis()) - .setPriority(Notification.PRIORITY_HIGH) - .setShowWhen(true) - .build(); - return notif; + return new Notification.Builder(context) + .setContentTitle(title) + .setContentText(text) + .setSmallIcon(R.drawable.linphone_logo) + .setAutoCancel(true) + .setContentIntent(intent) + .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) + .setCategory(Notification.CATEGORY_MESSAGE) + .setVisibility(Notification.VISIBILITY_PRIVATE) + .setLights( + ContextCompat.getColor(context, R.color.notification_color_led), + context.getResources().getInteger(R.integer.notification_ms_on), + context.getResources().getInteger(R.integer.notification_ms_off)) + .setWhen(System.currentTimeMillis()) + .setPriority(Notification.PRIORITY_HIGH) + .setShowWhen(true) + .build(); } } diff --git a/app/src/main/java/org/linphone/compatibility/ApiTwentySixPlus.java b/app/src/main/java/org/linphone/compatibility/ApiTwentySixPlus.java index 0a6bea2b1..e25780428 100644 --- a/app/src/main/java/org/linphone/compatibility/ApiTwentySixPlus.java +++ b/app/src/main/java/org/linphone/compatibility/ApiTwentySixPlus.java @@ -34,16 +34,35 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.RemoteInput; +import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; +import android.os.Build; +import android.provider.Settings; import org.linphone.R; import org.linphone.notifications.Notifiable; import org.linphone.notifications.NotifiableMessage; import org.linphone.notifications.NotificationBroadcastReceiver; @TargetApi(26) -public class ApiTwentySixPlus { +class ApiTwentySixPlus { + public static String getDeviceName(Context context) { + String name = + Settings.Global.getString( + context.getContentResolver(), Settings.Global.DEVICE_NAME); + if (name == null) { + name = BluetoothAdapter.getDefaultAdapter().getName(); + } + if (name == null) { + name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name"); + } + if (name == null) { + name = Build.MANUFACTURER + " " + Build.MODEL; + } + return name; + } + public static Notification createRepliedNotification(Context context, String reply) { return new Notification.Builder( context, context.getString(R.string.notification_channel_id)) @@ -213,7 +232,6 @@ public class ApiTwentySixPlus { int level, Bitmap largeIcon, PendingIntent intent, - boolean isOngoingEvent, int priority) { if (largeIcon != null) { diff --git a/app/src/main/java/org/linphone/compatibility/ApiTwentyThreePlus.java b/app/src/main/java/org/linphone/compatibility/ApiTwentyThreePlus.java index f9b68598d..afacf3fd5 100644 --- a/app/src/main/java/org/linphone/compatibility/ApiTwentyThreePlus.java +++ b/app/src/main/java/org/linphone/compatibility/ApiTwentyThreePlus.java @@ -23,7 +23,7 @@ import android.annotation.TargetApi; import android.widget.TextView; @TargetApi(23) -public class ApiTwentyThreePlus { +class ApiTwentyThreePlus { public static void setTextAppearance(TextView textview, int style) { textview.setTextAppearance(style); } diff --git a/app/src/main/java/org/linphone/compatibility/Compatibility.java b/app/src/main/java/org/linphone/compatibility/Compatibility.java index d8c591bd6..9067cae44 100644 --- a/app/src/main/java/org/linphone/compatibility/Compatibility.java +++ b/app/src/main/java/org/linphone/compatibility/Compatibility.java @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import android.app.FragmentTransaction; import android.app.Notification; import android.app.PendingIntent; +import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -39,6 +40,21 @@ public class Compatibility { public static final String INTENT_ANSWER_CALL_NOTIF_ACTION = "org.linphone.ANSWER_CALL_ACTION"; public static final String INTENT_LOCAL_IDENTITY = "LOCAL_IDENTITY"; + public static String getDeviceName(Context context) { + if (Version.sdkAboveOrEqual(25)) { + return ApiTwentySixPlus.getDeviceName(context); + } + + String name = BluetoothAdapter.getDefaultAdapter().getName(); + if (name == null) { + name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name"); + } + if (name == null) { + name = Build.MANUFACTURER + " " + Build.MODEL; + } + return name; + } + public static void createNotificationChannels(Context context) { if (Version.sdkAboveOrEqual(Version.API26_O_80)) { ApiTwentySixPlus.createServiceChannel(context); @@ -94,7 +110,6 @@ public class Compatibility { Context context, int callId, boolean showAnswerAction, - String title, String msg, int iconID, Bitmap contactIcon, @@ -122,7 +137,7 @@ public class Compatibility { intent); } return ApiTwentyOnePlus.createInCallNotification( - context, title, msg, iconID, contactIcon, contactName, intent); + context, msg, iconID, contactIcon, contactName, intent); } public static Notification createNotification( @@ -137,26 +152,10 @@ public class Compatibility { int priority) { if (Version.sdkAboveOrEqual(Version.API26_O_80)) { return ApiTwentySixPlus.createNotification( - context, - title, - message, - icon, - iconLevel, - largeIcon, - intent, - isOngoingEvent, - priority); + context, title, message, icon, iconLevel, largeIcon, intent, priority); } return ApiTwentyOnePlus.createNotification( - context, - title, - message, - icon, - iconLevel, - largeIcon, - intent, - isOngoingEvent, - priority); + context, title, message, icon, iconLevel, largeIcon, intent, priority); } public static boolean canDrawOverlays(Context context) { diff --git a/app/src/main/java/org/linphone/compatibility/CompatibilityScaleGestureListener.java b/app/src/main/java/org/linphone/compatibility/CompatibilityScaleGestureListener.java index f9f76b85e..8bc83e8fc 100644 --- a/app/src/main/java/org/linphone/compatibility/CompatibilityScaleGestureListener.java +++ b/app/src/main/java/org/linphone/compatibility/CompatibilityScaleGestureListener.java @@ -20,5 +20,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ public interface CompatibilityScaleGestureListener { - public boolean onScale(CompatibilityScaleGestureDetector detector); + boolean onScale(CompatibilityScaleGestureDetector detector); } diff --git a/app/src/main/java/org/linphone/contacts/ContactAddress.java b/app/src/main/java/org/linphone/contacts/ContactAddress.java index 2d662d9d8..a6ae84bdf 100644 --- a/app/src/main/java/org/linphone/contacts/ContactAddress.java +++ b/app/src/main/java/org/linphone/contacts/ContactAddress.java @@ -72,10 +72,6 @@ public class ContactAddress implements Serializable { return mContact; } - public SearchResult getResult() { - return mResult; - } - public void setResult(SearchResult result) { this.mResult = result; } @@ -140,8 +136,8 @@ public class ContactAddress implements Serializable { if (other == null) return false; if (other == this) return true; if (!(other instanceof ContactAddress)) return false; - if (((ContactAddress) other).getAddressAsDisplayableString() - == this.getAddressAsDisplayableString()) return true; - return false; + return ((ContactAddress) other) + .getAddressAsDisplayableString() + .equals(getAddressAsDisplayableString()); } } diff --git a/app/src/main/java/org/linphone/contacts/ContactDetailsFragment.java b/app/src/main/java/org/linphone/contacts/ContactDetailsFragment.java index 47abe5318..4c46b5987 100644 --- a/app/src/main/java/org/linphone/contacts/ContactDetailsFragment.java +++ b/app/src/main/java/org/linphone/contacts/ContactDetailsFragment.java @@ -62,20 +62,19 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener private ChatRoom mChatRoom; private ChatRoomListenerStub mChatRoomCreationListener; - private OnClickListener mDialListener = + private final OnClickListener mDialListener = new OnClickListener() { @Override public void onClick(View v) { if (LinphoneActivity.isInstanciated()) { String tag = (String) v.getTag(); LinphoneActivity.instance() - .setAddresGoToDialerAndCall( - tag, mContact.getFullName(), mContact.getPhotoUri()); + .setAddresGoToDialerAndCall(tag, mContact.getFullName()); } } }; - private OnClickListener mChatListener = + private final OnClickListener mChatListener = new OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/org/linphone/contacts/ContactEditorFragment.java b/app/src/main/java/org/linphone/contacts/ContactEditorFragment.java index 9cb61b269..a34daabc5 100644 --- a/app/src/main/java/org/linphone/contacts/ContactEditorFragment.java +++ b/app/src/main/java/org/linphone/contacts/ContactEditorFragment.java @@ -337,8 +337,6 @@ public class ContactEditorFragment extends Fragment { public void onResume() { super.onResume(); - if (LinphoneActivity.isInstanciated()) {} - // Force hide keyboard getActivity() .getWindow() @@ -465,6 +463,7 @@ public class ContactEditorFragment extends Fragment { } catch (Exception e) { Log.e(e); } + c.close(); return value; } @@ -535,15 +534,6 @@ public class ContactEditorFragment extends Fragment { private View displayNumberOrAddress( final LinearLayout controls, String numberOrAddress, boolean isSIP) { - return displayNumberOrAddress(controls, numberOrAddress, isSIP, false); - } - - @SuppressLint("InflateParams") - private View displayNumberOrAddress( - final LinearLayout controls, - String numberOrAddress, - boolean isSIP, - boolean forceAddNumber) { String displayNumberOrAddress = numberOrAddress; if (isSIP) { if (mFirstSipAddressIndex == -1) { @@ -554,21 +544,14 @@ public class ContactEditorFragment extends Fragment { } if ((getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) && !isSIP) || (getResources().getBoolean(R.bool.hide_sip_addresses_in_editor) && isSIP)) { - if (forceAddNumber) - isSIP = !isSIP; // If number can't be displayed because we hide a sort of number, - // change that category - else return null; + return null; } LinphoneNumberOrAddress tempNounoa; - if (forceAddNumber) { - tempNounoa = new LinphoneNumberOrAddress(null, isSIP); + if (mIsNewContact || mNewSipOrNumberToAdd != null) { + tempNounoa = new LinphoneNumberOrAddress(numberOrAddress, isSIP); } else { - if (mIsNewContact || mNewSipOrNumberToAdd != null) { - tempNounoa = new LinphoneNumberOrAddress(numberOrAddress, isSIP); - } else { - tempNounoa = new LinphoneNumberOrAddress(null, isSIP, numberOrAddress); - } + tempNounoa = new LinphoneNumberOrAddress(null, isSIP, numberOrAddress); } final LinphoneNumberOrAddress nounoa = tempNounoa; mNumbersAndAddresses.add(nounoa); @@ -594,9 +577,6 @@ public class ContactEditorFragment extends Fragment { @Override public void afterTextChanged(Editable s) {} }); - if (forceAddNumber) { - nounoa.setValue(noa.getText().toString()); - } ImageView delete = view.findViewById(R.id.delete_field); if ((getResources().getBoolean(R.bool.allow_only_one_phone_number) && !isSIP) diff --git a/app/src/main/java/org/linphone/contacts/ContactPicked.java b/app/src/main/java/org/linphone/contacts/ContactPicked.java deleted file mode 100644 index 6aa8de15d..000000000 --- a/app/src/main/java/org/linphone/contacts/ContactPicked.java +++ /dev/null @@ -1,26 +0,0 @@ -/* -ContactPicked.java -Copyright (C) 2017 Belledonne Communications, Grenoble, France - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -package org.linphone.contacts; - -import android.net.Uri; - -public interface ContactPicked { - void setAddresGoToDialerAndCall(String number, String name, Uri photo); -} diff --git a/app/src/main/java/org/linphone/contacts/ContactViewHolder.java b/app/src/main/java/org/linphone/contacts/ContactViewHolder.java new file mode 100644 index 000000000..78f9d6845 --- /dev/null +++ b/app/src/main/java/org/linphone/contacts/ContactViewHolder.java @@ -0,0 +1,77 @@ +package org.linphone.contacts; + +/* +ContactViewHolder.java +Copyright (C) 2018 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import android.view.View; +import android.widget.CheckBox; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; +import org.linphone.R; + +public class ContactViewHolder extends RecyclerView.ViewHolder + implements View.OnClickListener, View.OnLongClickListener { + public final CheckBox delete; + public final ImageView linphoneFriend; + public final TextView name; + public final LinearLayout separator; + public final TextView separatorText; + public final RelativeLayout avatarLayout; + public final TextView organization; + private final ClickListener mListener; + + public ContactViewHolder(View view, ClickListener listener) { + super(view); + + delete = view.findViewById(R.id.delete); + linphoneFriend = view.findViewById(R.id.friendLinphone); + name = view.findViewById(R.id.name); + separator = view.findViewById(R.id.separator); + separatorText = view.findViewById(R.id.separator_text); + avatarLayout = view.findViewById(R.id.avatar_layout); + organization = view.findViewById(R.id.contactOrganization); + // friendStatus = view.findViewById(R.id.friendStatus); + mListener = listener; + view.setOnClickListener(this); + view.setOnLongClickListener(this); + } + + @Override + public void onClick(View view) { + if (mListener != null) { + mListener.onItemClicked(getAdapterPosition()); + } + } + + public boolean onLongClick(View v) { + if (mListener != null) { + return mListener.onItemLongClicked(getAdapterPosition()); + } + return false; + } + + public interface ClickListener { + void onItemClicked(int position); + + boolean onItemLongClicked(int position); + } +} diff --git a/app/src/main/java/org/linphone/contacts/ContactsListAdapter.java b/app/src/main/java/org/linphone/contacts/ContactsAdapter.java similarity index 68% rename from app/src/main/java/org/linphone/contacts/ContactsListAdapter.java rename to app/src/main/java/org/linphone/contacts/ContactsAdapter.java index 31e2415c4..146608d72 100644 --- a/app/src/main/java/org/linphone/contacts/ContactsListAdapter.java +++ b/app/src/main/java/org/linphone/contacts/ContactsAdapter.java @@ -1,7 +1,7 @@ package org.linphone.contacts; /* -ContactsListAdapter.java +ContactsAdapter.java Copyright (C) 2018 Belledonne Communications, Grenoble, France This program is free software; you can redistribute it and/or @@ -23,14 +23,8 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.SectionIndexer; -import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -41,20 +35,20 @@ import org.linphone.utils.SelectableAdapter; import org.linphone.utils.SelectableHelper; import org.linphone.views.ContactAvatar; -public class ContactsListAdapter extends SelectableAdapter +public class ContactsAdapter extends SelectableAdapter implements SectionIndexer { private List mContacts; private String[] mSections; private ArrayList mSectionsList; private Map mMap = new LinkedHashMap<>(); - private ViewHolder.ClickListener mClickListener; - private Context mContext; + private final ContactViewHolder.ClickListener mClickListener; + private final Context mContext; private boolean mIsSearchMode; - ContactsListAdapter( + ContactsAdapter( Context context, List contactsList, - ViewHolder.ClickListener clickListener, + ContactViewHolder.ClickListener clickListener, SelectableHelper helper) { super(helper); mContext = context; @@ -64,15 +58,15 @@ public class ContactsListAdapter extends SelectableAdapter 0) { - ContactsListAdapter mAdapt = (ContactsListAdapter) mContactsList.getAdapter(); + ContactsAdapter mAdapt = (ContactsAdapter) mContactsList.getAdapter(); LinphoneActivity.instance().displayContact((LinphoneContact) mAdapt.getItem(0), false); } else { LinphoneActivity.instance().displayEmptyFragment(); @@ -210,7 +210,7 @@ public class ContactsListFragment extends Fragment isEditionEnabled = true; } - mContactAdapter = new ContactsListAdapter(mContext, listContact, this, mSelectionHelper); + mContactAdapter = new ContactsAdapter(mContext, listContact, this, mSelectionHelper); // mContactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); mSelectionHelper.setAdapter(mContactAdapter); @@ -228,7 +228,7 @@ public class ContactsListFragment extends Fragment mNoContact.setVisibility(View.GONE); mContactsList.setVisibility(View.VISIBLE); boolean isEditionEnabled = false; - if (mSearchView.getQuery().toString() == "") { + if (mSearchView.getQuery().toString().equals("")) { if (mOnlyDisplayLinphoneContacts) { listContact = ContactsManager.getInstance().getSIPContacts(); } else { @@ -250,7 +250,7 @@ public class ContactsListFragment extends Fragment isEditionEnabled = true; } - mContactAdapter = new ContactsListAdapter(mContext, listContact, this, mSelectionHelper); + mContactAdapter = new ContactsAdapter(mContext, listContact, this, mSelectionHelper); mSelectionHelper.setAdapter(mContactAdapter); @@ -366,7 +366,7 @@ public class ContactsListFragment extends Fragment mContactsFetchInProgress.setVisibility(View.GONE); } - public void invalidate() { + private void invalidate() { if (mSearchView != null && mSearchView.getQuery().toString().length() > 0) { searchContacts(mSearchView.getQuery().toString()); } else { diff --git a/app/src/main/java/org/linphone/contacts/ContactsManager.java b/app/src/main/java/org/linphone/contacts/ContactsManager.java index 98928c547..5618876d4 100644 --- a/app/src/main/java/org/linphone/contacts/ContactsManager.java +++ b/app/src/main/java/org/linphone/contacts/ContactsManager.java @@ -78,7 +78,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen private List mContacts, mSipContacts; private MagicSearch mMagicSearch; - private Bitmap mDefaultAvatar; + private final Bitmap mDefaultAvatar; private boolean mContactsFetchedOnce = false; private Context mContext; private AsyncContactsLoader mLoadContactTask; @@ -104,7 +104,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen sContactsUpdatedListeners.remove(listener); } - public static final ContactsManager getInstance() { + public static ContactsManager getInstance() { if (sInstance == null) sInstance = new ContactsManager(); return sInstance; } @@ -115,27 +115,28 @@ public class ContactsManager extends ContentObserver implements FriendListListen String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER}; Cursor c = resolver.query(contactUri, projection, null, null, null); if (c != null) { - while (c.moveToNext()) { + if (c.moveToNext()) { int numberIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); String number = c.getString(numberIndex); c.close(); return number; } } + c.close(); // SIP addresses projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS}; c = resolver.query(contactUri, projection, null, null, null); if (c != null) { - while (c.moveToNext()) { + if (c.moveToNext()) { int numberIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS); String address = c.getString(numberIndex); c.close(); return address; } - c.close(); } + c.close(); return null; } @@ -182,7 +183,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen } } - public void setContacts(List c) { + private void setContacts(List c) { synchronized (mContacts) { mContacts = c; } @@ -259,10 +260,8 @@ public class ContactsManager extends ContentObserver implements FriendListListen public boolean isLinphoneContactsPrefered() { ProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig(); - if (lpc != null - && lpc.getIdentityAddress().getDomain().equals(getString(R.string.default_domain))) - return true; - return false; + return lpc != null + && lpc.getIdentityAddress().getDomain().equals(getString(R.string.default_domain)); } public void initializeContactManager(Context context) { @@ -296,8 +295,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); Friend lf = lc.findFriend(address); if (lf != null) { - LinphoneContact contact = (LinphoneContact) lf.getUserData(); - return contact; + return (LinphoneContact) lf.getUserData(); } return findContactFromPhoneNumber(address.getUsername()); } @@ -321,13 +319,12 @@ public class ContactsManager extends ContentObserver implements FriendListListen lc.findFriend( addr); // Without this, the hashmap inside liblinphone won't find it... if (lf != null) { - LinphoneContact contact = (LinphoneContact) lf.getUserData(); - return contact; + return (LinphoneContact) lf.getUserData(); } return null; } - public synchronized boolean refreshSipContact(Friend lf) { + private synchronized boolean refreshSipContact(Friend lf) { LinphoneContact contact = (LinphoneContact) lf.getUserData(); if (contact != null && !getSIPContacts().contains(contact)) { addSipContact(contact); @@ -398,7 +395,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen mLoadContactTask.executeOnExecutor(THREAD_POOL_EXECUTOR); } - public synchronized void setSipContacts(List c) { + private synchronized void setSipContacts(List c) { synchronized (mSipContacts) { mSipContacts = c; } @@ -441,10 +438,10 @@ public class ContactsManager extends ContentObserver implements FriendListListen } class AsyncContactsData { - List contacts; - List sipContacts; + final List contacts; + final List sipContacts; - public AsyncContactsData() { + AsyncContactsData() { contacts = new ArrayList<>(); sipContacts = new ArrayList<>(); } @@ -560,6 +557,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen contact.setFirstNameAndLastName(data2, data3, false); } } + c.close(); for (FriendList list : lc.getFriendsLists()) { for (Friend friend : list.getFriends()) { diff --git a/app/src/main/java/org/linphone/contacts/LinphoneContact.java b/app/src/main/java/org/linphone/contacts/LinphoneContact.java index bedcd19dd..554f6ccfe 100644 --- a/app/src/main/java/org/linphone/contacts/LinphoneContact.java +++ b/app/src/main/java/org/linphone/contacts/LinphoneContact.java @@ -129,7 +129,7 @@ public class LinphoneContact implements Serializable, Comparable 0) { - for (ContentProviderOperation cpo : mChangesToCommit2) { - batch.add(cpo); - } + batch.addAll(mChangesToCommit2); } try { diff --git a/app/src/main/java/org/linphone/contacts/LinphoneNumberOrAddress.java b/app/src/main/java/org/linphone/contacts/LinphoneNumberOrAddress.java index 54a363f06..37b777095 100644 --- a/app/src/main/java/org/linphone/contacts/LinphoneNumberOrAddress.java +++ b/app/src/main/java/org/linphone/contacts/LinphoneNumberOrAddress.java @@ -24,9 +24,9 @@ import java.io.Serializable; public class LinphoneNumberOrAddress implements Serializable, Comparable { private static final long serialVersionUID = -2301689469730072896L; - private boolean mIsSIPAddress; + private final boolean mIsSIPAddress; private String mValue, mOldValueForUpdatePurpose; - private String mNormalizedPhone; + private final String mNormalizedPhone; public LinphoneNumberOrAddress(String v, boolean isSIP) { mValue = v; diff --git a/app/src/main/java/org/linphone/contacts/SearchContactViewHolder.java b/app/src/main/java/org/linphone/contacts/SearchContactViewHolder.java new file mode 100644 index 000000000..9ba6a1176 --- /dev/null +++ b/app/src/main/java/org/linphone/contacts/SearchContactViewHolder.java @@ -0,0 +1,60 @@ +package org.linphone.contacts; + +/* +SearchContactViewHolder.java +Copyright (C) 2018 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import android.view.View; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; +import org.linphone.R; + +public class SearchContactViewHolder extends RecyclerView.ViewHolder + implements View.OnClickListener { + public final TextView name; + public final TextView address; + public final ImageView linphoneContact; + public final ImageView isSelect; + public final RelativeLayout avatarLayout; + + private final ClickListener mListener; + + public SearchContactViewHolder(View view, ClickListener listener) { + super(view); + name = view.findViewById(R.id.contact_name); + address = view.findViewById(R.id.contact_address); + linphoneContact = view.findViewById(R.id.contact_linphone); + isSelect = view.findViewById(R.id.contact_is_select); + avatarLayout = view.findViewById(R.id.avatar_layout); + mListener = listener; + view.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + if (mListener != null) { + mListener.onItemClicked(getAdapterPosition()); + } + } + + public interface ClickListener { + void onItemClicked(int position); + } +} diff --git a/app/src/main/java/org/linphone/contacts/SearchContactsListAdapter.java b/app/src/main/java/org/linphone/contacts/SearchContactsAdapter.java similarity index 85% rename from app/src/main/java/org/linphone/contacts/SearchContactsListAdapter.java rename to app/src/main/java/org/linphone/contacts/SearchContactsAdapter.java index ab2e03600..041a8d305 100644 --- a/app/src/main/java/org/linphone/contacts/SearchContactsListAdapter.java +++ b/app/src/main/java/org/linphone/contacts/SearchContactsAdapter.java @@ -1,5 +1,7 @@ +package org.linphone.contacts; + /* -SearchContactsListAdapter.java +SearchContactsAdapter.java Copyright (C) 2017 Belledonne Communications, Grenoble, France This program is free software; you can redistribute it and/or @@ -17,15 +19,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.linphone.contacts; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import android.widget.ProgressBar; -import android.widget.RelativeLayout; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; @@ -41,23 +38,22 @@ import org.linphone.core.ProxyConfig; import org.linphone.core.SearchResult; import org.linphone.views.ContactAvatar; -public class SearchContactsListAdapter - extends RecyclerView.Adapter { +public class SearchContactsAdapter extends RecyclerView.Adapter { @SuppressWarnings("unused") - private static final String TAG = SearchContactsListAdapter.class.getSimpleName(); + private static final String TAG = SearchContactsAdapter.class.getSimpleName(); private List mContacts; private List mContactsSelected; - private ProgressBar mProgressBar; + private final ProgressBar mProgressBar; private boolean mOnlySipContact = false; - private ViewHolder.ClickListener mListener; - private boolean mHideSelectionMark; + private SearchContactViewHolder.ClickListener mListener; + private final boolean mHideSelectionMark; private String mPreviousSearch; - public SearchContactsListAdapter( + public SearchContactsAdapter( List contactsList, ProgressBar pB, - ViewHolder.ClickListener clickListener, + SearchContactViewHolder.ClickListener clickListener, boolean hideSelectionMark) { mHideSelectionMark = hideSelectionMark; mListener = clickListener; @@ -75,21 +71,21 @@ public class SearchContactsListAdapter mOnlySipContact = enable; } - public void setListener(ViewHolder.ClickListener listener) { + public void setListener(SearchContactViewHolder.ClickListener listener) { mListener = listener; } @NonNull @Override - public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + public SearchContactViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.search_contact_cell, parent, false); - return new ViewHolder(v, mListener); + return new SearchContactViewHolder(v, mListener); } @Override - public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + public void onBindViewHolder(@NonNull SearchContactViewHolder holder, int position) { ContactAddress contact = getItem(position); final String a = (contact.getAddressAsDisplayableString().isEmpty()) @@ -229,7 +225,7 @@ public class SearchContactsListAdapter return list; } - public void setContactsList(List contactsList) { + private void setContactsList(List contactsList) { if (contactsList == null) { mContacts = getContactsList(); if (mProgressBar != null) mProgressBar.setVisibility(View.GONE); @@ -238,11 +234,7 @@ public class SearchContactsListAdapter } } - public int getCount() { - return mContacts.size(); - } - - public ContactAddress getItem(int position) { + private ContactAddress getItem(int position) { return mContacts.get(position); } @@ -337,36 +329,4 @@ public class SearchContactsListAdapter resultContactsSearch.setAdapter(this); notifyDataSetChanged(); } - - public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - public TextView name; - public TextView address; - public ImageView linphoneContact; - public ImageView isSelect; - public RelativeLayout avatarLayout; - - private ClickListener mListener; - - public ViewHolder(View view, ClickListener listener) { - super(view); - name = view.findViewById(R.id.contact_name); - address = view.findViewById(R.id.contact_address); - linphoneContact = view.findViewById(R.id.contact_linphone); - isSelect = view.findViewById(R.id.contact_is_select); - avatarLayout = view.findViewById(R.id.avatar_layout); - mListener = listener; - view.setOnClickListener(this); - } - - @Override - public void onClick(View view) { - if (mListener != null) { - mListener.onItemClicked(getAdapterPosition()); - } - } - - public interface ClickListener { - void onItemClicked(int position); - } - } } diff --git a/app/src/main/java/org/linphone/fragments/AboutFragment.java b/app/src/main/java/org/linphone/fragments/AboutFragment.java index e837ea40f..ae0c3a5f4 100644 --- a/app/src/main/java/org/linphone/fragments/AboutFragment.java +++ b/app/src/main/java/org/linphone/fragments/AboutFragment.java @@ -181,9 +181,4 @@ public class AboutFragment extends Fragment implements OnClickListener { } } } - - @Override - public void onDestroy() { - super.onDestroy(); - } } diff --git a/app/src/main/java/org/linphone/fragments/EmptyFragment.java b/app/src/main/java/org/linphone/fragments/EmptyFragment.java index 9ea81516c..3aca04fa3 100644 --- a/app/src/main/java/org/linphone/fragments/EmptyFragment.java +++ b/app/src/main/java/org/linphone/fragments/EmptyFragment.java @@ -32,7 +32,6 @@ public class EmptyFragment extends Fragment { public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.empty_fragment, container, false); - return view; + return inflater.inflate(R.layout.empty_fragment, container, false); } } diff --git a/app/src/main/java/org/linphone/fragments/StatusFragment.java b/app/src/main/java/org/linphone/fragments/StatusFragment.java index 1b305ead0..5feffa67e 100644 --- a/app/src/main/java/org/linphone/fragments/StatusFragment.java +++ b/app/src/main/java/org/linphone/fragments/StatusFragment.java @@ -54,7 +54,7 @@ import org.linphone.mediastream.Log; import org.linphone.settings.LinphonePreferences; public class StatusFragment extends Fragment { - private Handler mRefreshHandler = new Handler(); + private final Handler mRefreshHandler = new Handler(); private TextView mStatusText, mVoicemailCount; private ImageView mStatusLed, mCallQuality, mEncryption, mMenu, mVoicemail; private Runnable mCallQualityUpdater; @@ -100,10 +100,10 @@ public class StatusFragment extends Fragment { if (lc.getDefaultProxyConfig() != null && lc.getDefaultProxyConfig().equals(proxy)) { - mStatusLed.setImageResource(getStatusIconResource(state, true)); + mStatusLed.setImageResource(getStatusIconResource(state)); mStatusText.setText(getStatusIconText(state)); } else if (lc.getDefaultProxyConfig() == null) { - mStatusLed.setImageResource(getStatusIconResource(state, true)); + mStatusLed.setImageResource(getStatusIconResource(state)); mStatusText.setText(getStatusIconText(state)); } @@ -116,6 +116,7 @@ public class StatusFragment extends Fragment { } }); } catch (IllegalStateException ise) { + Log.e(ise); } } @@ -128,7 +129,7 @@ public class StatusFragment extends Fragment { if (content.getSize() == 0) return; - int unreadCount = -1; + int unreadCount; String data = content.getStringBuffer(); String[] voiceMail = data.split("voice-message: "); final String[] intToParse = voiceMail[1].split("/", 0); @@ -211,16 +212,13 @@ public class StatusFragment extends Fragment { mMenu.setEnabled(enabled); } - private int getStatusIconResource(RegistrationState state, boolean isDefaultAccount) { + private int getStatusIconResource(RegistrationState state) { try { Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); boolean defaultAccountConnected = - (isDefaultAccount - && lc != null - && lc.getDefaultProxyConfig() != null - && lc.getDefaultProxyConfig().getState() - == RegistrationState.Ok) - || !isDefaultAccount; + (lc != null + && lc.getDefaultProxyConfig() != null + && lc.getDefaultProxyConfig().getState() == RegistrationState.Ok); if (state == RegistrationState.Ok && defaultAccountConnected) { return R.drawable.led_connected; } else if (state == RegistrationState.Progress) { @@ -270,7 +268,7 @@ public class StatusFragment extends Fragment { mRefreshHandler.postDelayed( mCallQualityUpdater = new Runnable() { - Call mCurrentCall = LinphoneManager.getLc().getCurrentCall(); + final Call mCurrentCall = LinphoneManager.getLc().getCurrentCall(); public void run() { if (mCurrentCall == null) { @@ -288,7 +286,7 @@ public class StatusFragment extends Fragment { 1000); } - void updateQualityOfSignalIcon(float quality) { + private void updateQualityOfSignalIcon(float quality) { int iQuality = (int) quality; if (iQuality == mDisplayedQuality) return; @@ -327,7 +325,7 @@ public class StatusFragment extends Fragment { if (mIsInCall && (call != null || lc.getConferenceSize() > 1 || lc.getCallsNb() > 0)) { if (call != null) { startCallQuality(); - refreshStatusItems(call, call.getCurrentParams().videoEnabled()); + refreshStatusItems(call); } mMenu.setVisibility(View.INVISIBLE); mCallQuality.setVisibility(View.VISIBLE); @@ -338,7 +336,7 @@ public class StatusFragment extends Fragment { mStatusText.setText(getString(R.string.no_account)); } else { mStatusLed.setImageResource( - getStatusIconResource(lc.getDefaultProxyConfig().getState(), true)); + getStatusIconResource(lc.getDefaultProxyConfig().getState())); mStatusText.setText(getStatusIconText(lc.getDefaultProxyConfig().getState())); } } @@ -363,17 +361,11 @@ public class StatusFragment extends Fragment { } } - public void refreshStatusItems(final Call call, boolean isVideoEnabled) { + public void refreshStatusItems(final Call call) { if (call != null) { mVoicemailCount.setVisibility(View.GONE); MediaEncryption mediaEncryption = call.getCurrentParams().getMediaEncryption(); - if (isVideoEnabled) { - // background.setVisibility(View.GONE); - } else { - // background.setVisibility(View.VISIBLE); - } - mEncryption.setVisibility(View.VISIBLE); if (mediaEncryption == MediaEncryption.SRTP || (mediaEncryption == MediaEncryption.ZRTP diff --git a/app/src/main/java/org/linphone/history/HistoryAdapter.java b/app/src/main/java/org/linphone/history/HistoryAdapter.java index d224d0410..b4f46bea3 100644 --- a/app/src/main/java/org/linphone/history/HistoryAdapter.java +++ b/app/src/main/java/org/linphone/history/HistoryAdapter.java @@ -41,9 +41,9 @@ import org.linphone.utils.SelectableHelper; import org.linphone.views.ContactAvatar; public class HistoryAdapter extends SelectableAdapter { - private List mLogs; - private Context mContext; - private HistoryViewHolder.ClickListener mClickListener; + private final List mLogs; + private final Context mContext; + private final HistoryViewHolder.ClickListener mClickListener; public HistoryAdapter( Context aContext, @@ -56,10 +56,6 @@ public class HistoryAdapter extends SelectableAdapter { mClickListener = listener; } - public int getCount() { - return mLogs.size(); - } - public Object getItem(int position) { return mLogs.get(position); } diff --git a/app/src/main/java/org/linphone/history/HistoryDetailFragment.java b/app/src/main/java/org/linphone/history/HistoryDetailFragment.java index fd3d6a2f5..a3650cf4b 100644 --- a/app/src/main/java/org/linphone/history/HistoryDetailFragment.java +++ b/app/src/main/java/org/linphone/history/HistoryDetailFragment.java @@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import android.app.Fragment; -import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -217,11 +216,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener { getFragmentManager().popBackStackImmediate(); } if (id == R.id.call) { - LinphoneActivity.instance() - .setAddresGoToDialerAndCall( - mSipUri, - mDisplayName, - mPictureUri == null ? null : Uri.parse(mPictureUri)); + LinphoneActivity.instance().setAddresGoToDialerAndCall(mSipUri, mDisplayName); } else if (id == R.id.chat) { Core lc = LinphoneManager.getLc(); Address participant = Factory.instance().createAddress(mSipUri); diff --git a/app/src/main/java/org/linphone/history/HistoryFragment.java b/app/src/main/java/org/linphone/history/HistoryFragment.java index afe244665..a2eed13f0 100644 --- a/app/src/main/java/org/linphone/history/HistoryFragment.java +++ b/app/src/main/java/org/linphone/history/HistoryFragment.java @@ -101,7 +101,7 @@ public class HistoryFragment extends Fragment return view; } - public void refresh() { + private void refresh() { mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs()); } @@ -122,7 +122,7 @@ public class HistoryFragment extends Fragment private void removeNotMissedCallsFromLogs() { if (mOnlyDisplayMissedCalls) { - List missedCalls = new ArrayList(); + List missedCalls = new ArrayList<>(); for (CallLog log : mLogs) { if (log.getStatus() == Call.Status.Missed) { missedCalls.add(log); @@ -248,7 +248,7 @@ public class HistoryFragment extends Fragment } LinphoneActivity.instance() .setAddresGoToDialerAndCall( - address.asStringUriOnly(), address.getDisplayName(), null); + address.asStringUriOnly(), address.getDisplayName()); } } } diff --git a/app/src/main/java/org/linphone/history/HistoryViewHolder.java b/app/src/main/java/org/linphone/history/HistoryViewHolder.java index 90b3d6132..3823ec869 100644 --- a/app/src/main/java/org/linphone/history/HistoryViewHolder.java +++ b/app/src/main/java/org/linphone/history/HistoryViewHolder.java @@ -30,16 +30,15 @@ import org.linphone.R; public class HistoryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { - public TextView contact; - public ImageView detail; - public CheckBox select; - public ImageView callDirection; - public RelativeLayout avatarLayout; - public RelativeLayout CallContact; - public LinearLayout separator; - public TextView separatorText; + public final TextView contact; + public final ImageView detail; + public final CheckBox select; + public final ImageView callDirection; + public final RelativeLayout avatarLayout; + public final LinearLayout separator; + public final TextView separatorText; - private ClickListener mListener; + private final ClickListener mListener; public HistoryViewHolder(View view, ClickListener listener) { super(view); @@ -48,7 +47,6 @@ public class HistoryViewHolder extends RecyclerView.ViewHolder select = view.findViewById(R.id.delete); callDirection = view.findViewById(R.id.icon); avatarLayout = view.findViewById(R.id.avatar_layout); - CallContact = view.findViewById(R.id.history_click); separator = view.findViewById(R.id.separator); separatorText = view.findViewById(R.id.separator_text); mListener = listener; diff --git a/app/src/main/java/org/linphone/notifications/Notifiable.java b/app/src/main/java/org/linphone/notifications/Notifiable.java index 46c64fef1..66cd86d2e 100644 --- a/app/src/main/java/org/linphone/notifications/Notifiable.java +++ b/app/src/main/java/org/linphone/notifications/Notifiable.java @@ -23,7 +23,7 @@ import java.util.ArrayList; import java.util.List; public class Notifiable { - private int mNotificationId; + private final int mNotificationId; private List mMessages; private boolean mIsGroup; private String mGroupTitle; diff --git a/app/src/main/java/org/linphone/notifications/NotifiableMessage.java b/app/src/main/java/org/linphone/notifications/NotifiableMessage.java index c580a0b11..15700e148 100644 --- a/app/src/main/java/org/linphone/notifications/NotifiableMessage.java +++ b/app/src/main/java/org/linphone/notifications/NotifiableMessage.java @@ -23,12 +23,12 @@ import android.graphics.Bitmap; import android.net.Uri; public class NotifiableMessage { - private String mMessage; - private String mSender; - private long mTime; + private final String mMessage; + private final String mSender; + private final long mTime; private Bitmap mSenderBitmap; - private Uri mFilePath; - private String mFileMime; + private final Uri mFilePath; + private final String mFileMime; public NotifiableMessage( String message, String sender, long time, Uri filePath, String fileMime) { diff --git a/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.java b/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.java index d4c682874..f40beb306 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.java +++ b/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.java @@ -45,7 +45,7 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver { final int notifId = intent.getIntExtra(Compatibility.INTENT_NOTIF_ID, 0); final String localyIdentity = intent.getStringExtra(Compatibility.INTENT_LOCAL_IDENTITY); - if (intent.getAction() == Compatibility.INTENT_REPLY_NOTIF_ACTION) { + if (intent.getAction().equals(Compatibility.INTENT_REPLY_NOTIF_ACTION)) { final String reply = getMessageText(intent).toString(); if (reply == null) { Log.e("Couldn't get reply text"); @@ -113,8 +113,8 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver { } } }); - } else if (intent.getAction() == Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION - || intent.getAction() == Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION) { + } else if (intent.getAction().equals(Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION) + || intent.getAction().equals(Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION)) { String remoteAddr = LinphoneService.instance() .getNotificationManager() @@ -131,7 +131,7 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver { return; } - if (intent.getAction() == Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION) { + if (intent.getAction().equals(Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION)) { call.accept(); } else { call.terminate(); diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.java b/app/src/main/java/org/linphone/notifications/NotificationsManager.java index c765a7c36..d6121ad91 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.java +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.java @@ -39,6 +39,7 @@ import org.linphone.contacts.ContactsManager; import org.linphone.contacts.LinphoneContact; import org.linphone.core.Address; import org.linphone.core.Call; +import org.linphone.mediastream.Log; import org.linphone.mediastream.Version; import org.linphone.settings.LinphonePreferences; import org.linphone.utils.ImageUtils; @@ -49,11 +50,12 @@ public class NotificationsManager { private static final int MISSED_CALLS_NOTIF_ID = 2; private static final int IN_APP_NOTIF_ID = 3; - private Context mContext; - private NotificationManager mNM; - private HashMap mChatNotifMap, mCallNotifMap; + private final Context mContext; + private final NotificationManager mNM; + private final HashMap mChatNotifMap; + private final HashMap mCallNotifMap; private int mLastNotificationId; - private Notification mServiceNotification; + private final Notification mServiceNotification; public NotificationsManager(Context context) { mContext = context; @@ -80,6 +82,7 @@ public class NotificationsManager { try { bm = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher); } catch (Exception e) { + Log.e(e); } PendingIntent pendingIntent = @@ -126,7 +129,7 @@ public class NotificationsManager { } } - public boolean isServiceNotificationDisplayed() { + private boolean isServiceNotificationDisplayed() { return LinphonePreferences.instance().getServiceNotificationVisibility(); } @@ -327,7 +330,6 @@ public class NotificationsManager { mContext, notif.getNotificationId(), showAnswerAction, - mContext.getString(R.string.service_name), mContext.getString(notificationTextId), iconId, bm, diff --git a/app/src/main/java/org/linphone/purchase/InAppPurchaseActivity.java b/app/src/main/java/org/linphone/purchase/InAppPurchaseActivity.java index 0c142902e..4f5382f0f 100644 --- a/app/src/main/java/org/linphone/purchase/InAppPurchaseActivity.java +++ b/app/src/main/java/org/linphone/purchase/InAppPurchaseActivity.java @@ -47,7 +47,7 @@ public class InAppPurchaseActivity extends Activity private List mPurchasedItems; private Fragment mFragment; - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); public static InAppPurchaseActivity instance() { return sInstance; @@ -78,7 +78,7 @@ public class InAppPurchaseActivity extends Activity transaction.commitAllowingStateLoss(); } - public void displayInappList() { + private void displayInappList() { mFragment = new InAppPurchaseListFragment(); changeFragment(mFragment); } @@ -138,9 +138,7 @@ public class InAppPurchaseActivity extends Activity // purchasableItemsLayout.removeAllViews(); mInProgress.setVisibility(View.GONE); mPurchasedItems = new ArrayList<>(); - for (Purchasable item : items) { - mPurchasedItems.add(item); - } + mPurchasedItems.addAll(items); displayInappList(); } @@ -170,7 +168,7 @@ public class InAppPurchaseActivity extends Activity xmlRpcHelper.updateAccountExpireAsync( new XmlRpcListenerBase() { @Override - public void onAccountExpireUpdated(String result) { + public void onAccountExpireUpdated() { // TODO } }, @@ -199,7 +197,7 @@ public class InAppPurchaseActivity extends Activity } @Override - public void onRecoverAccountSuccessful(boolean success) {} + public void onRecoverAccountSuccessful() {} @Override public void onError(final String error) { diff --git a/app/src/main/java/org/linphone/purchase/InAppPurchaseHelper.java b/app/src/main/java/org/linphone/purchase/InAppPurchaseHelper.java index 47965ca98..6273dbd93 100644 --- a/app/src/main/java/org/linphone/purchase/InAppPurchaseHelper.java +++ b/app/src/main/java/org/linphone/purchase/InAppPurchaseHelper.java @@ -42,7 +42,7 @@ import org.linphone.settings.LinphonePreferences; import org.linphone.xmlrpc.XmlRpcHelper; import org.linphone.xmlrpc.XmlRpcListenerBase; -public class InAppPurchaseHelper { +class InAppPurchaseHelper { public static final int API_VERSION = 3; public static final int ACTIVITY_RESULT_CODE_PURCHASE_ITEM = 11089; @@ -90,12 +90,12 @@ public class InAppPurchaseHelper { public static final String CLIENT_ERROR_BILLING_SERVICE_UNAVAILABLE = "BILLING_SERVICE_UNAVAILABLE"; - private Context mContext; - private InAppPurchaseListener mListener; + private final Context mContext; + private final InAppPurchaseListener mListener; private IInAppBillingService mService; - private ServiceConnection mServiceConn; - private Handler mHandler = new Handler(); - private String mGmailAccount; + private final ServiceConnection mServiceConn; + private final Handler mHandler = new Handler(); + private final String mGmailAccount; public InAppPurchaseHelper(Activity context, InAppPurchaseListener listener) { mContext = context; @@ -320,8 +320,7 @@ public class InAppPurchaseHelper { for (Account account : accounts) { if (isEmailCorrect(account.name)) { - String possibleEmail = account.name; - return possibleEmail; + return account.name; } } @@ -333,7 +332,7 @@ public class InAppPurchaseHelper { return emailPattern.matcher(email).matches(); } - private Purchasable verifySignature(String payload, String signature) { + private Purchasable verifySignature() { // TODO FIXME rework to be async /*XmlRpcHelper helper = new XmlRpcHelper(); if (helper.verifySignature(payload, signature)) { diff --git a/app/src/main/java/org/linphone/purchase/InAppPurchaseListener.java b/app/src/main/java/org/linphone/purchase/InAppPurchaseListener.java index b2d42a05d..a67acf80d 100644 --- a/app/src/main/java/org/linphone/purchase/InAppPurchaseListener.java +++ b/app/src/main/java/org/linphone/purchase/InAppPurchaseListener.java @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import java.util.ArrayList; -public interface InAppPurchaseListener { +interface InAppPurchaseListener { /** Callback called when the in-app purchase listener is connected and available for queries */ void onServiceAvailableForQueries(); @@ -45,12 +45,8 @@ public interface InAppPurchaseListener { */ void onPurchasedItemConfirmationQueryFinished(boolean success); - /** - * Callback called when the account has been recovered (or not) - * - * @param success true if the recover has been successful, false otherwise - */ - void onRecoverAccountSuccessful(boolean success); + /** Callback called when the account has been recovered (or not) */ + void onRecoverAccountSuccessful(); /** * Callback called when the account has been activated (or not) diff --git a/app/src/main/java/org/linphone/purchase/InAppPurchaseListenerBase.java b/app/src/main/java/org/linphone/purchase/InAppPurchaseListenerBase.java index a961c51ba..774f1a312 100644 --- a/app/src/main/java/org/linphone/purchase/InAppPurchaseListenerBase.java +++ b/app/src/main/java/org/linphone/purchase/InAppPurchaseListenerBase.java @@ -47,7 +47,7 @@ public class InAppPurchaseListenerBase implements InAppPurchaseListener { } @Override - public void onRecoverAccountSuccessful(boolean success) { + public void onRecoverAccountSuccessful() { // TODO Auto-generated method stub } diff --git a/app/src/main/java/org/linphone/purchase/Purchasable.java b/app/src/main/java/org/linphone/purchase/Purchasable.java index f28db24af..55d83b8be 100644 --- a/app/src/main/java/org/linphone/purchase/Purchasable.java +++ b/app/src/main/java/org/linphone/purchase/Purchasable.java @@ -25,7 +25,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ public class Purchasable { - private String mId, mTitle, mDescription, mPrice; + private final String mId; + private String mTitle; + private String mDescription; + private String mPrice; private long mExpire; private String mPurchasePayload, mPurchasePayloadSignature; private String mUserData; @@ -65,15 +68,6 @@ public class Purchasable { return this; } - public long getExpire() { - return mExpire; - } - - public Purchasable setExpire(long expire) { - this.mExpire = expire; - return this; - } - public String getExpireDate() { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()); Date date = new Date(mExpire); diff --git a/app/src/main/java/org/linphone/receivers/BluetoothManager.java b/app/src/main/java/org/linphone/receivers/BluetoothManager.java index 9089b69ee..666419f32 100644 --- a/app/src/main/java/org/linphone/receivers/BluetoothManager.java +++ b/app/src/main/java/org/linphone/receivers/BluetoothManager.java @@ -32,6 +32,7 @@ import java.util.List; import org.linphone.LinphoneManager; import org.linphone.LinphoneService; import org.linphone.call.CallActivity; +import org.linphone.mediastream.Log; public class BluetoothManager extends BroadcastReceiver { private static BluetoothManager sInstance; @@ -181,6 +182,7 @@ public class BluetoothManager extends BroadcastReceiver { try { Thread.sleep(200); } catch (InterruptedException e) { + Log.e(e); } if (mAudioManager != null) { @@ -257,6 +259,7 @@ public class BluetoothManager extends BroadcastReceiver { try { Thread.sleep(200); } catch (InterruptedException e) { + Log.e(e); } mAudioManager.stopBluetoothSco(); @@ -266,7 +269,7 @@ public class BluetoothManager extends BroadcastReceiver { } } - public void stopBluetooth() { + private void stopBluetooth() { android.util.Log.w("BluetoothManager", "[Bluetooth] Stopping..."); mIsBluetoothConnected = false; @@ -295,6 +298,7 @@ public class BluetoothManager extends BroadcastReceiver { mContext.unregisterReceiver(this); android.util.Log.d("BluetoothManager", "[Bluetooth] Receiver stopped"); } catch (Exception e) { + Log.e(e); } } catch (Exception e) { android.util.Log.e("BluetoothManager", e.getMessage()); diff --git a/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java b/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java index f4d301627..ea69e0373 100644 --- a/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java @@ -39,9 +39,7 @@ import org.linphone.utils.LinphoneUtils; public class KeepAliveReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (!LinphoneService.isReady()) { - return; - } else { + if (LinphoneService.isReady()) { boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled(); LinphoneUtils.initLoggingService(isDebugEnabled, context.getString(R.string.app_name)); Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); diff --git a/app/src/main/java/org/linphone/receivers/NetworkManager.java b/app/src/main/java/org/linphone/receivers/NetworkManager.java index 388597cfa..541895126 100644 --- a/app/src/main/java/org/linphone/receivers/NetworkManager.java +++ b/app/src/main/java/org/linphone/receivers/NetworkManager.java @@ -35,7 +35,7 @@ public class NetworkManager extends BroadcastReceiver { Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); if (LinphoneManager.isInstanciated()) { - LinphoneManager.getInstance().connectivityChanged(cm, lNoConnectivity); + LinphoneManager.getInstance().connectivityChanged(); } } } diff --git a/app/src/main/java/org/linphone/recording/Recording.java b/app/src/main/java/org/linphone/recording/Recording.java index 1b7f87eb6..b78ff920f 100644 --- a/app/src/main/java/org/linphone/recording/Recording.java +++ b/app/src/main/java/org/linphone/recording/Recording.java @@ -33,15 +33,16 @@ import org.linphone.core.Player; import org.linphone.core.PlayerListener; import org.linphone.mediastream.Log; -public class Recording implements PlayerListener, Comparable { +class Recording implements PlayerListener, Comparable { public static final Pattern RECORD_PATTERN = Pattern.compile(".*/(.*)_(\\d{2}-\\d{2}-\\d{4}-\\d{2}-\\d{2}-\\d{2})\\..*"); - private String mRecordPath, mName; + private final String mRecordPath; + private String mName; private Date mRecordDate; - private Player mPlayer; + private final Player mPlayer; private RecordingListener mListener; - private Handler mHandler; + private final Handler mHandler; private Runnable mUpdateCurrentPositionTimer; @SuppressLint("SimpleDateFormat") diff --git a/app/src/main/java/org/linphone/recording/RecordingListener.java b/app/src/main/java/org/linphone/recording/RecordingListener.java index 8853d8c14..bb3abc82b 100644 --- a/app/src/main/java/org/linphone/recording/RecordingListener.java +++ b/app/src/main/java/org/linphone/recording/RecordingListener.java @@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -public interface RecordingListener { +interface RecordingListener { void currentPositionChanged(int currentPosition); void endOfRecordReached(); diff --git a/app/src/main/java/org/linphone/recording/RecordingViewHolder.java b/app/src/main/java/org/linphone/recording/RecordingViewHolder.java index eca08a9c3..1075e46a4 100644 --- a/app/src/main/java/org/linphone/recording/RecordingViewHolder.java +++ b/app/src/main/java/org/linphone/recording/RecordingViewHolder.java @@ -30,14 +30,17 @@ import org.linphone.R; public class RecordingViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { - public ImageView playButton; - public TextView name, date, currentPosition, duration; - public SeekBar progressionBar; - public CheckBox select; - public LinearLayout separator; - public TextView separatorText; + public final ImageView playButton; + public final TextView name; + public final TextView date; + public final TextView currentPosition; + public final TextView duration; + public final SeekBar progressionBar; + public final CheckBox select; + public final LinearLayout separator; + public final TextView separatorText; - private RecordingViewHolder.ClickListener mListener; + private final RecordingViewHolder.ClickListener mListener; public RecordingViewHolder(View view, RecordingViewHolder.ClickListener listener) { super(view); diff --git a/app/src/main/java/org/linphone/recording/RecordingsAdapter.java b/app/src/main/java/org/linphone/recording/RecordingsAdapter.java index f99efb8ec..47dd6fdc9 100644 --- a/app/src/main/java/org/linphone/recording/RecordingsAdapter.java +++ b/app/src/main/java/org/linphone/recording/RecordingsAdapter.java @@ -30,15 +30,16 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeUnit; import org.linphone.R; import org.linphone.utils.SelectableAdapter; import org.linphone.utils.SelectableHelper; public class RecordingsAdapter extends SelectableAdapter { - private List mRecordings; - private Context mContext; - private RecordingViewHolder.ClickListener mClickListener; + private final List mRecordings; + private final Context mContext; + private final RecordingViewHolder.ClickListener mClickListener; public RecordingsAdapter( Context context, @@ -119,6 +120,7 @@ public class RecordingsAdapter extends SelectableAdapter { int position = record.getCurrentPosition(); viewHolder.currentPosition.setText( String.format( + Locale.getDefault(), "%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(position), TimeUnit.MILLISECONDS.toSeconds(position) @@ -128,6 +130,7 @@ public class RecordingsAdapter extends SelectableAdapter { int duration = record.getDuration(); viewHolder.duration.setText( String.format( + Locale.getDefault(), "%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) @@ -154,6 +157,7 @@ public class RecordingsAdapter extends SelectableAdapter { int currentPosition = record.getCurrentPosition(); viewHolder.currentPosition.setText( String.format( + Locale.getDefault(), "%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(currentPosition), TimeUnit.MILLISECONDS.toSeconds(currentPosition) @@ -176,6 +180,7 @@ public class RecordingsAdapter extends SelectableAdapter { public void currentPositionChanged(int currentPosition) { viewHolder.currentPosition.setText( String.format( + Locale.getDefault(), "%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(currentPosition), TimeUnit.MILLISECONDS.toSeconds(currentPosition) diff --git a/app/src/main/java/org/linphone/recording/RecordingsFragment.java b/app/src/main/java/org/linphone/recording/RecordingsFragment.java index 5a42c62f2..9c7a76be1 100644 --- a/app/src/main/java/org/linphone/recording/RecordingsFragment.java +++ b/app/src/main/java/org/linphone/recording/RecordingsFragment.java @@ -104,7 +104,7 @@ public class RecordingsFragment extends Fragment } } - public void removeDeletedRecordings() { + private void removeDeletedRecordings() { String recordingsDirectory = FileUtils.getRecordingsDirectory(mContext); File directory = new File(recordingsDirectory); @@ -127,7 +127,7 @@ public class RecordingsFragment extends Fragment } } - public void searchForRecordings() { + private void searchForRecordings() { String recordingsDirectory = FileUtils.getRecordingsDirectory(mContext); File directory = new File(recordingsDirectory); diff --git a/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java b/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java index 2311be64f..776edcf4d 100644 --- a/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java +++ b/app/src/main/java/org/linphone/settings/AccountPreferencesFragment.java @@ -48,7 +48,7 @@ import org.linphone.utils.LinphoneUtils; public class AccountPreferencesFragment extends PreferencesListFragment implements AccountCreatorListener { private int mN; - private OnPreferenceClickListener linkAccountListener = + private final OnPreferenceClickListener linkAccountListener = new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -62,8 +62,8 @@ public class AccountPreferencesFragment extends PreferencesListFragment } }; private boolean mIsNewAccount = false; - private LinphonePreferences mPrefs; - private OnPreferenceChangeListener mAvpfRRIntervalChangedListener = + private final LinphonePreferences mPrefs; + private final OnPreferenceChangeListener mAvpfRRIntervalChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -74,6 +74,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return false; } } catch (NumberFormatException nfe) { + Log.e(nfe); } if (mIsNewAccount) { // TODO @@ -84,7 +85,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mEscapeChangedListener = + private final OnPreferenceChangeListener mEscapeChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -97,7 +98,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mPushNotificationListener = + private final OnPreferenceChangeListener mPushNotificationListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -110,7 +111,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mIceChangedListener = + private final OnPreferenceChangeListener mIceChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -123,7 +124,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mStunTurnChangedListener = + private final OnPreferenceChangeListener mStunTurnChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -137,7 +138,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment } }; private EditTextPreference mProxyPreference; - private OnPreferenceChangeListener mTransportChangedListener = + private final OnPreferenceChangeListener mTransportChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -160,7 +161,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment }; private ListPreference mTransportPreference; private AccountBuilder mBuilder; - private OnPreferenceChangeListener mUsernameChangedListener = + private final OnPreferenceChangeListener mUsernameChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -174,7 +175,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mUseridChangedListener = + private final OnPreferenceChangeListener mUseridChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -187,7 +188,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mPasswordChangedListener = + private final OnPreferenceChangeListener mPasswordChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -200,7 +201,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mDomainChangedListener = + private final OnPreferenceChangeListener mDomainChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -214,7 +215,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mDisplayNameChangedListener = + private final OnPreferenceChangeListener mDisplayNameChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -227,7 +228,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mProxyChangedListener = + private final OnPreferenceChangeListener mProxyChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -247,7 +248,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mOutboundProxyChangedListener = + private final OnPreferenceChangeListener mOutboundProxyChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -259,7 +260,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mExpiresChangedListener = + private final OnPreferenceChangeListener mExpiresChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -272,7 +273,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mPrefixChangedListener = + private final OnPreferenceChangeListener mPrefixChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -286,7 +287,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mAvpfChangedListener = + private final OnPreferenceChangeListener mAvpfChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -297,7 +298,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment return true; } }; - private OnPreferenceChangeListener mDisableChangedListener = + private final OnPreferenceChangeListener mDisableChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -317,7 +318,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment mPrefs = LinphonePreferences.instance(); } - public static boolean isEditTextEmpty(String s) { + private static boolean isEditTextEmpty(String s) { return s.equals(""); // really empty. } @@ -340,7 +341,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment mIsNewAccount = true; mBuilder = new AccountBuilder(LinphoneManager.getLc()); } - initAccountPreferencesFields(screen); + initAccountPreferencesFields(); // Force hide keyboard getActivity() @@ -348,7 +349,7 @@ public class AccountPreferencesFragment extends PreferencesListFragment .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); } - private void initAccountPreferencesFields(PreferenceScreen parent) { + private void initAccountPreferencesFields() { boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == mN; NatPolicy natPolicy = null; if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null @@ -531,8 +532,8 @@ public class AccountPreferencesFragment extends PreferencesListFragment } private void initializeTransportPreference(ListPreference pref) { - List entries = new ArrayList(); - List values = new ArrayList(); + List entries = new ArrayList<>(); + List values = new ArrayList<>(); entries.add(getString(R.string.pref_transport_udp)); values.add(getString(R.string.pref_transport_udp_key)); entries.add(getString(R.string.pref_transport_tcp)); diff --git a/app/src/main/java/org/linphone/settings/LinphonePreferences.java b/app/src/main/java/org/linphone/settings/LinphonePreferences.java index 3cd68abb4..092319e23 100644 --- a/app/src/main/java/org/linphone/settings/LinphonePreferences.java +++ b/app/src/main/java/org/linphone/settings/LinphonePreferences.java @@ -61,7 +61,7 @@ public class LinphonePreferences { private LinphonePreferences() {} - public static final synchronized LinphonePreferences instance() { + public static synchronized LinphonePreferences instance() { if (sInstance == null) { sInstance = new LinphonePreferences(); } @@ -147,8 +147,7 @@ public class LinphonePreferences { ProxyConfig prxCfg = getProxyConfig(n); if (prxCfg == null) return null; Address addr = prxCfg.getIdentityAddress(); - AuthInfo authInfo = getLc().findAuthInfo(null, addr.getUsername(), addr.getDomain()); - return authInfo; + return getLc().findAuthInfo(null, addr.getUsername(), addr.getDomain()); } /** @@ -207,7 +206,7 @@ public class LinphonePreferences { } } - public TransportType getAccountTransport(int n) { + private TransportType getAccountTransport(int n) { TransportType transport = null; ProxyConfig proxyConfig = getProxyConfig(n); @@ -303,16 +302,12 @@ public class LinphonePreferences { return authInfo == null ? null : authInfo.getUserid(); } - public String getAccountRealm(int n) { + private String getAccountRealm(int n) { AuthInfo authInfo = getAuthInfo(n); return authInfo == null ? null : authInfo.getRealm(); } public void setAccountPassword(int n, String password) { - setAccountPassword(n, password, null); - } - - private void setAccountPassword(int n, String password, String ha1) { if (getLc() == null) return; String user = getAccountUsername(n); String domain = getAccountDomain(n); @@ -327,7 +322,7 @@ public class LinphonePreferences { .removeAuthInfo(LinphoneManager.getLc().getAuthInfoList()[n]); } AuthInfo authInfo = - Factory.instance().createAuthInfo(user, userid, password, ha1, realm, domain); + Factory.instance().createAuthInfo(user, userid, password, null, realm, domain); LinphoneManager.getLc().addAuthInfo(authInfo); } } @@ -422,8 +417,7 @@ public class LinphonePreferences { } public String getAccountProxy(int n) { - String proxy = getProxyConfig(n).getServerAddr(); - return proxy; + return getProxyConfig(n).getServerAddr(); } public void setAccountOutboundProxyEnabled(int n, boolean enabled) { @@ -442,13 +436,6 @@ public class LinphonePreferences { return getProxyConfig(n).getRoute() != null; } - public void setAccountContactParameters(int n, String contactParams) { - ProxyConfig prxCfg = getProxyConfig(n); - prxCfg.edit(); - prxCfg.setContactUriParameters(contactParams); - prxCfg.done(); - } - public String getExpires(int n) { return String.valueOf(getProxyConfig(n).getExpires()); } @@ -460,6 +447,7 @@ public class LinphonePreferences { prxCfg.setExpires(Integer.parseInt(expire)); prxCfg.done(); } catch (NumberFormatException nfe) { + Log.e(nfe); } } @@ -496,6 +484,7 @@ public class LinphonePreferences { prxCfg.setAvpfRrInterval(Integer.parseInt(interval)); prxCfg.done(); } catch (NumberFormatException nfe) { + Log.e(nfe); } } @@ -798,7 +787,7 @@ public class LinphonePreferences { useRandomPort(enabled, true); } - public void useRandomPort(boolean enabled, boolean apply) { + private void useRandomPort(boolean enabled, boolean apply) { getConfig().setBool("app", "random_port", enabled); if (apply) { if (enabled) { @@ -850,7 +839,6 @@ public class LinphonePreferences { NatPolicy nat = getOrCreateNatPolicy(); nat.setStunServer(stun); - if (stun != null && !stun.isEmpty()) {} getLc().setNatPolicy(nat); } @@ -1017,7 +1005,7 @@ public class LinphonePreferences { } } - public String getPushNotificationRegistrationID() { + private String getPushNotificationRegistrationID() { return getConfig().getString("app", "push_notification_regid", null); } @@ -1185,7 +1173,7 @@ public class LinphonePreferences { public boolean isProvisioningLoginViewEnabled() { - return (getConfig() != null) ? getConfig().getBool("app", "show_login_view", false) : false; + return (getConfig() != null) && getConfig().getBool("app", "show_login_view", false); } // End of tunnel settings @@ -1230,11 +1218,7 @@ public class LinphonePreferences { getConfig().getString("in-app-purchase", "purchase_item_signature", null); String username = getConfig().getString("in-app-purchase", "purchase_item_username", null); - Purchasable item = - new Purchasable(id) - .setPayloadAndSignature(payload, signature) - .setUserData(username); - return item; + return new Purchasable(id).setPayloadAndSignature(payload, signature).setUserData(username); } public void setInAppPurchasedItem(Purchasable item) { @@ -1249,7 +1233,7 @@ public class LinphonePreferences { } public ArrayList getInAppPurchasables() { - ArrayList purchasables = new ArrayList(); + ArrayList purchasables = new ArrayList<>(); String list = getConfig().getString("in-app-purchase", "purchasable_items_ids", null); if (list != null) { for (String purchasable : list.split(";")) { @@ -1344,7 +1328,7 @@ public class LinphonePreferences { return firstTimeAskingForPermission(permission, true); } - public boolean firstTimeAskingForPermission(String permission, boolean toggle) { + private boolean firstTimeAskingForPermission(String permission, boolean toggle) { boolean firstTime = getConfig().getBool("app", permission, true); if (toggle) { permissionHasBeenAsked(permission); @@ -1352,7 +1336,7 @@ public class LinphonePreferences { return firstTime; } - public void permissionHasBeenAsked(String permission) { + private void permissionHasBeenAsked(String permission) { getConfig().setBool("app", permission, false); } @@ -1421,7 +1405,7 @@ public class LinphonePreferences { } public static class AccountBuilder { - private Core lc; + private final Core lc; private String tempUsername; private String tempDisplayName; private String tempUserId; @@ -1434,10 +1418,10 @@ public class LinphonePreferences { private String tempExpire; private TransportType tempTransport; private int tempAvpfRRInterval = 0; - private boolean tempQualityReportingEnabled = false; - private int tempQualityReportingInterval = 0; + private final boolean tempQualityReportingEnabled = false; + private final int tempQualityReportingInterval = 0; private boolean tempEnabled = true; - private boolean tempNoDefault = false; + private final boolean tempNoDefault = false; public AccountBuilder(Core lc) { this.lc = lc; diff --git a/app/src/main/java/org/linphone/settings/PreferencesListFragment.java b/app/src/main/java/org/linphone/settings/PreferencesListFragment.java index 97cf656ac..5dd13bffd 100644 --- a/app/src/main/java/org/linphone/settings/PreferencesListFragment.java +++ b/app/src/main/java/org/linphone/settings/PreferencesListFragment.java @@ -51,7 +51,7 @@ public class PreferencesListFragment extends ListFragment { private PreferenceManager mPreferenceManager; private ListView mPreferencesList; - private Handler mHandler = + private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { @@ -64,7 +64,7 @@ public class PreferencesListFragment extends ListFragment { }; private int mXmlResID; - public PreferencesListFragment(int xmlId) { + PreferencesListFragment(int xmlId) { mXmlResID = xmlId; } @@ -188,9 +188,7 @@ public class PreferencesListFragment extends ListFragment { Constructor c = PreferenceManager.class.getDeclaredConstructor(Activity.class, int.class); c.setAccessible(true); - PreferenceManager preferenceManager = - c.newInstance(this.getActivity(), FIRST_REQUEST_CODE); - return preferenceManager; + return c.newInstance(this.getActivity(), FIRST_REQUEST_CODE); } catch (Exception e) { Log.e("[PreferencesListFragment] onCreatePreferenceManager " + e); return null; @@ -202,7 +200,7 @@ public class PreferencesListFragment extends ListFragment { * * @return The {@link PreferenceManager}. */ - public PreferenceManager getPreferenceManager() { + PreferenceManager getPreferenceManager() { return mPreferenceManager; } @@ -211,7 +209,7 @@ public class PreferencesListFragment extends ListFragment { * * @return The {@link PreferenceScreen} that is the root of the preference hierarchy. */ - public PreferenceScreen getPreferenceScreen() { + PreferenceScreen getPreferenceScreen() { try { Method m = PreferenceManager.class.getDeclaredMethod("getPreferenceScreen"); m.setAccessible(true); @@ -228,7 +226,7 @@ public class PreferencesListFragment extends ListFragment { * * @param preferenceScreen The root {@link PreferenceScreen} of the preference hierarchy. */ - public void setPreferenceScreen(PreferenceScreen preferenceScreen) { + private void setPreferenceScreen(PreferenceScreen preferenceScreen) { try { Method m = PreferenceManager.class.getDeclaredMethod( @@ -249,7 +247,7 @@ public class PreferencesListFragment extends ListFragment { * * @param preferencesResId The XML resource ID to inflate. */ - public void addPreferencesFromResource(int preferencesResId) { + private void addPreferencesFromResource(int preferencesResId) { try { Method m = PreferenceManager.class.getDeclaredMethod( @@ -278,7 +276,7 @@ public class PreferencesListFragment extends ListFragment { * @return The {@link Preference} with the key, or null. * @see PreferenceGroup#findPreference(CharSequence) */ - public Preference findPreference(CharSequence key) { + Preference findPreference(CharSequence key) { if (mPreferenceManager == null) { Log.e("[PreferencesListFragment] PreferenceManager is null !"); return null; diff --git a/app/src/main/java/org/linphone/settings/SettingsFragment.java b/app/src/main/java/org/linphone/settings/SettingsFragment.java index c418530cb..f41cdaa90 100644 --- a/app/src/main/java/org/linphone/settings/SettingsFragment.java +++ b/app/src/main/java/org/linphone/settings/SettingsFragment.java @@ -28,6 +28,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.media.AudioManager; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.preference.CheckBoxPreference; @@ -48,7 +49,6 @@ import org.linphone.LinphoneService; import org.linphone.R; import org.linphone.core.Address; import org.linphone.core.Core; -import org.linphone.core.CoreException; import org.linphone.core.CoreListenerStub; import org.linphone.core.EcCalibratorStatus; import org.linphone.core.Factory; @@ -69,10 +69,10 @@ import org.linphone.views.LedPreference; public class SettingsFragment extends PreferencesListFragment { private LinphonePreferences mPrefs; - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private CoreListenerStub mListener; private PreferenceScreen mCurrentPreferenceScreen; - private Preference.OnPreferenceClickListener mPrefClickListener = + private final Preference.OnPreferenceClickListener mPrefClickListener = new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -445,8 +445,8 @@ public class SettingsFragment extends PreferencesListFragment { } private void initMediaEncryptionPreference(ListPreference pref) { - List entries = new ArrayList(); - List values = new ArrayList(); + List entries = new ArrayList<>(); + List values = new ArrayList<>(); entries.add(getString(R.string.pref_none)); values.add(getString(R.string.pref_media_encryption_key_none)); @@ -493,8 +493,8 @@ public class SettingsFragment extends PreferencesListFragment { } private void initializePreferredVideoSizePreferences(ListPreference pref) { - List entries = new ArrayList(); - List values = new ArrayList(); + List entries = new ArrayList<>(); + List values = new ArrayList<>(); for (VideoDefinition vd : Factory.instance().getSupportedVideoDefinitions()) { entries.add(vd.getName()); values.add(vd.getName()); @@ -508,8 +508,8 @@ public class SettingsFragment extends PreferencesListFragment { } private void initializePreferredVideoFpsPreferences(ListPreference pref) { - List entries = new ArrayList(); - List values = new ArrayList(); + List entries = new ArrayList<>(); + List values = new ArrayList<>(); entries.add(getString(R.string.pref_none)); values.add("0"); for (int i = 5; i <= 30; i += 5) { @@ -582,13 +582,7 @@ public class SettingsFragment extends PreferencesListFragment { codec.setTitle(pt.getMimeType()); /* Special case */ if (pt.getMimeType().equals("mpeg4-generic")) { - if (android.os.Build.VERSION.SDK_INT < 16) { - /* Make sure AAC is disabled */ - pt.enable(false); - continue; - } else { - codec.setTitle("AAC-ELD"); - } + codec.setTitle("AAC-ELD"); } codec.setSummary(pt.getClockRate() + " Hz"); @@ -733,34 +727,22 @@ public class SettingsFragment extends PreferencesListFragment { public void startEchoTester() { Preference preference = findPreference(getString(R.string.pref_echo_tester_key)); - try { - if (LinphoneManager.getInstance().startEchoTester() > 0) { - preference.setSummary("Is running"); - } - } catch (CoreException e) { - e.printStackTrace(); + if (LinphoneManager.getInstance().startEchoTester() > 0) { + preference.setSummary("Is running"); } } - public void stopEchoTester() { + private void stopEchoTester() { Preference preference = findPreference(getString(R.string.pref_echo_tester_key)); - try { - if (LinphoneManager.getInstance().stopEchoTester() > 0) { - preference.setSummary("Is stopped"); - } - } catch (CoreException e) { - e.printStackTrace(); + if (LinphoneManager.getInstance().stopEchoTester() > 0) { + preference.setSummary("Is stopped"); } } public void startEchoCancellerCalibration() { - try { - if (LinphoneManager.getInstance().getEchoTesterStatus()) stopEchoTester(); - LinphoneManager.getLc().addListener(mListener); - LinphoneManager.getInstance().startEcCalibration(); - } catch (CoreException e) { - Log.e(e); - } + if (LinphoneManager.getInstance().getEchoTesterStatus()) stopEchoTester(); + LinphoneManager.getLc().addListener(mListener); + LinphoneManager.getInstance().startEcCalibration(); } public void echoCalibrationFail() { @@ -891,20 +873,7 @@ public class SettingsFragment extends PreferencesListFragment { mCodecDownloader.downloadCodec(); } }); - builder.setNegativeButton( - "No", - new DialogInterface.OnClickListener() { - @Override - public void onClick( - DialogInterface dialog, int which) { - if (which - == DialogInterface - .BUTTON_NEGATIVE) { - // Disable H264 - } - } - }) - .show(); + builder.setNegativeButton("No", null).show(); } } pt.enable(enable); @@ -915,7 +884,7 @@ public class SettingsFragment extends PreferencesListFragment { codecs.addPreference(codec); } // Adding OpenH264 button on device < 5.1 - if (mCodecDownloader.isOpenH264DownloadEnabled() && !h264IsHere) { + if (OpenH264DownloadHelper.isOpenH264DownloadEnabled() && !h264IsHere) { final CheckBoxPreference codec = new CheckBoxPreference(getActivity()); codec.setTitle("OpenH264"); codec.setSummary(mCodecDownloader.getLicenseMessage()); @@ -925,7 +894,7 @@ public class SettingsFragment extends PreferencesListFragment { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean enable = (Boolean) newValue; - if (mCodecDownloader.isOpenH264DownloadEnabled()) { + if (OpenH264DownloadHelper.isOpenH264DownloadEnabled()) { if (enable && Version.getCpuAbis().contains("armeabi-v7a") && !Version.getCpuAbis().contains("x86") @@ -1401,19 +1370,23 @@ public class SettingsFragment extends PreferencesListFragment { @Override public boolean onPreferenceClick(Preference preference) { synchronized (SettingsFragment.this) { - Context context = SettingsFragment.this.getActivity(); - Intent i = new Intent(); - i.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); - i.putExtra( - Settings.EXTRA_APP_PACKAGE, context.getPackageName()); - i.putExtra( - Settings.EXTRA_CHANNEL_ID, - context.getString(R.string.notification_channel_id)); - i.addCategory(Intent.CATEGORY_DEFAULT); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); - i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - context.startActivity(i); + if (Build.VERSION.SDK_INT >= Version.API26_O_80) { + Context context = SettingsFragment.this.getActivity(); + Intent i = new Intent(); + i.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); + i.putExtra( + Settings.EXTRA_APP_PACKAGE, + context.getPackageName()); + i.putExtra( + Settings.EXTRA_CHANNEL_ID, + context.getString( + R.string.notification_channel_id)); + i.addCategory(Intent.CATEGORY_DEFAULT); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + context.startActivity(i); + } return true; } } @@ -1631,6 +1604,7 @@ public class SettingsFragment extends PreferencesListFragment { try { port = Integer.parseInt(newValue.toString()); } catch (NumberFormatException nfe) { + Log.e(nfe); } mPrefs.setSipPort(port); diff --git a/app/src/main/java/org/linphone/sync/Authenticator.java b/app/src/main/java/org/linphone/sync/Authenticator.java index 56c082d3a..3d04fde20 100644 --- a/app/src/main/java/org/linphone/sync/Authenticator.java +++ b/app/src/main/java/org/linphone/sync/Authenticator.java @@ -22,11 +22,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import android.accounts.AbstractAccountAuthenticator; import android.accounts.Account; import android.accounts.AccountAuthenticatorResponse; -import android.accounts.NetworkErrorException; import android.content.Context; import android.os.Bundle; -public class Authenticator extends AbstractAccountAuthenticator { +class Authenticator extends AbstractAccountAuthenticator { public Authenticator(Context context) { super(context); @@ -39,21 +38,19 @@ public class Authenticator extends AbstractAccountAuthenticator { @Override public Bundle addAccount( - AccountAuthenticatorResponse r, String s, String s2, String[] strings, Bundle bundle) - throws NetworkErrorException { + AccountAuthenticatorResponse r, String s, String s2, String[] strings, Bundle bundle) { return null; } @Override - public Bundle confirmCredentials(AccountAuthenticatorResponse r, Account account, Bundle bundle) - throws NetworkErrorException { + public Bundle confirmCredentials( + AccountAuthenticatorResponse r, Account account, Bundle bundle) { return null; } @Override public Bundle getAuthToken( - AccountAuthenticatorResponse r, Account account, String s, Bundle bundle) - throws NetworkErrorException { + AccountAuthenticatorResponse r, Account account, String s, Bundle bundle) { throw new UnsupportedOperationException(); } @@ -64,14 +61,12 @@ public class Authenticator extends AbstractAccountAuthenticator { @Override public Bundle updateCredentials( - AccountAuthenticatorResponse r, Account account, String s, Bundle bundle) - throws NetworkErrorException { + AccountAuthenticatorResponse r, Account account, String s, Bundle bundle) { throw new UnsupportedOperationException(); } @Override - public Bundle hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings) - throws NetworkErrorException { + public Bundle hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings) { throw new UnsupportedOperationException(); } } diff --git a/app/src/main/java/org/linphone/sync/SyncAdapter.java b/app/src/main/java/org/linphone/sync/SyncAdapter.java index 50509eb45..c41553f34 100755 --- a/app/src/main/java/org/linphone/sync/SyncAdapter.java +++ b/app/src/main/java/org/linphone/sync/SyncAdapter.java @@ -26,7 +26,7 @@ import android.content.Context; import android.content.SyncResult; import android.os.Bundle; -public class SyncAdapter extends AbstractThreadedSyncAdapter { +class SyncAdapter extends AbstractThreadedSyncAdapter { public SyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); diff --git a/app/src/main/java/org/linphone/utils/FileUtils.java b/app/src/main/java/org/linphone/utils/FileUtils.java index d2c83f829..2f110b0ff 100644 --- a/app/src/main/java/org/linphone/utils/FileUtils.java +++ b/app/src/main/java/org/linphone/utils/FileUtils.java @@ -127,15 +127,12 @@ public class FileUtils { private static boolean copyToFile(InputStream inputStream, File destFile) { if (inputStream == null || destFile == null) return false; try { - OutputStream out = new FileOutputStream(destFile); - try { + try (OutputStream out = new FileOutputStream(destFile)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) >= 0) { out.write(buffer, 0, bytesRead); } - } finally { - out.close(); } return true; } catch (IOException e) { @@ -143,7 +140,7 @@ public class FileUtils { } } - public static File createFile(Context context, String fileName) throws IOException { + private static File createFile(Context context, String fileName) { if (TextUtils.isEmpty(fileName)) fileName = getStartDate(); if (!fileName.contains(".")) { @@ -162,10 +159,9 @@ public class FileUtils { FriendList[] friendList = LinphoneManager.getLc().getFriendsLists(); for (FriendList list : friendList) { for (Friend friend : list.getFriends()) { - if (friend.getRefKey().toString().equals(contactId)) { + if (friend.getRefKey().equals(contactId)) { String contactVcard = friend.getVcard().asVcard4String(); - Uri path = createCvsFromString(contactVcard); - return path; + return createCvsFromString(contactVcard); } } } diff --git a/app/src/main/java/org/linphone/utils/ImageUtils.java b/app/src/main/java/org/linphone/utils/ImageUtils.java index bde3c7488..88825d8da 100644 --- a/app/src/main/java/org/linphone/utils/ImageUtils.java +++ b/app/src/main/java/org/linphone/utils/ImageUtils.java @@ -34,7 +34,6 @@ import android.util.TypedValue; import android.widget.ImageView; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; import org.linphone.R; import org.linphone.contacts.ContactsManager; @@ -49,14 +48,13 @@ public class ImageUtils { url = new URL(uri.toString()); is = url.openStream(); return BitmapFactory.decodeStream(is); - } catch (MalformedURLException e) { - Log.e(e, e.getMessage()); } catch (IOException e) { Log.e(e, e.getMessage()); } finally { try { is.close(); } catch (IOException x) { + Log.e(x); } } return null; @@ -83,6 +81,7 @@ public class ImageUtils { MediaStore.Images.Media.getBitmap( c.getContentResolver(), thumbnailUri); } catch (IOException ie) { + Log.e(ie); } } } @@ -118,7 +117,7 @@ public class ImageUtils { return bm; } - public static Bitmap getRoundBitmap(Bitmap bitmap) { + private static Bitmap getRoundBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); diff --git a/app/src/main/java/org/linphone/utils/LinphoneGenericActivity.java b/app/src/main/java/org/linphone/utils/LinphoneGenericActivity.java index 0d185d805..842a928f1 100644 --- a/app/src/main/java/org/linphone/utils/LinphoneGenericActivity.java +++ b/app/src/main/java/org/linphone/utils/LinphoneGenericActivity.java @@ -37,7 +37,6 @@ public class LinphoneGenericActivity extends Activity { if (!LinphoneService.isReady() || !LinphoneManager.isInstanciated()) { finish(); startActivity(getIntent().setClass(this, LinphoneLauncherActivity.class)); - return; } } } diff --git a/app/src/main/java/org/linphone/utils/LinphoneUtils.java b/app/src/main/java/org/linphone/utils/LinphoneUtils.java index 7fbd8fcfa..1c9402597 100644 --- a/app/src/main/java/org/linphone/utils/LinphoneUtils.java +++ b/app/src/main/java/org/linphone/utils/LinphoneUtils.java @@ -21,15 +21,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import android.app.Activity; import android.app.AlertDialog; -import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.os.Build; import android.os.Handler; import android.os.Looper; -import android.provider.Settings; import android.telephony.TelephonyManager; import android.text.Html; import android.text.Spanned; @@ -65,26 +62,10 @@ import org.linphone.settings.LinphonePreferences; /** Helpers. */ public final class LinphoneUtils { private static Context sContext = null; - private static Handler sHandler = new Handler(Looper.getMainLooper()); + private static final Handler sHandler = new Handler(Looper.getMainLooper()); private LinphoneUtils() {} - public static String getDeviceName(Context context) { - String name = - Settings.Global.getString( - context.getContentResolver(), Settings.Global.DEVICE_NAME); - if (name == null) { - name = BluetoothAdapter.getDefaultAdapter().getName(); - } - if (name == null) { - name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name"); - } - if (name == null) { - name = Build.MANUFACTURER + " " + Build.MODEL; - } - return name; - } - public static void initLoggingService(boolean isDebugEnabled, String appName) { if (!LinphonePreferences.instance().useJavaLogger()) { Factory.instance().enableLogCollection(LogCollectionState.Enabled); @@ -135,7 +116,7 @@ public final class LinphoneUtils { // private static final String strictSipAddressRegExp = // "^sip:(\\+)?[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$"; - public static boolean isSipAddress(String numberOrAddress) { + private static boolean isSipAddress(String numberOrAddress) { Factory.instance().createAddress(numberOrAddress); return true; } @@ -211,11 +192,11 @@ public final class LinphoneUtils { } } - static boolean isToday(Calendar cal) { + private static boolean isToday(Calendar cal) { return isSameDay(cal, Calendar.getInstance()); } - static boolean isSameDay(Calendar cal1, Calendar cal2) { + private static boolean isSameDay(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { return false; } @@ -237,7 +218,7 @@ public final class LinphoneUtils { return true; } - public static final List getCallsInState(Core lc, Collection states) { + public static List getCallsInState(Core lc, Collection states) { List foundCalls = new ArrayList<>(); for (Call call : lc.getCalls()) { if (states.contains(call.getState())) { @@ -247,7 +228,7 @@ public final class LinphoneUtils { return foundCalls; } - public static boolean isCallRunning(Call call) { + private static boolean isCallRunning(Call call) { if (call == null) { return false; } diff --git a/app/src/main/java/org/linphone/utils/MediaScanner.java b/app/src/main/java/org/linphone/utils/MediaScanner.java index be60b552c..d5f4e4180 100644 --- a/app/src/main/java/org/linphone/utils/MediaScanner.java +++ b/app/src/main/java/org/linphone/utils/MediaScanner.java @@ -26,7 +26,7 @@ import java.io.File; import org.linphone.mediastream.Log; public class MediaScanner implements MediaScannerConnection.MediaScannerConnectionClient { - private MediaScannerConnection mMediaConnection; + private final MediaScannerConnection mMediaConnection; private boolean mIsConnected; private File mFileWaitingForScan; private MediaScannerListener mListener; @@ -52,7 +52,7 @@ public class MediaScanner implements MediaScannerConnection.MediaScannerConnecti scanFile(file, FileUtils.getMimeFromFile(file.getAbsolutePath()), listener); } - public void scanFile(File file, String mime, MediaScannerListener listener) { + private void scanFile(File file, String mime, MediaScannerListener listener) { mListener = listener; if (!mIsConnected) { diff --git a/app/src/main/java/org/linphone/utils/SelectableAdapter.java b/app/src/main/java/org/linphone/utils/SelectableAdapter.java index f5da92301..ebc0203c2 100644 --- a/app/src/main/java/org/linphone/utils/SelectableAdapter.java +++ b/app/src/main/java/org/linphone/utils/SelectableAdapter.java @@ -26,11 +26,11 @@ import java.util.List; public abstract class SelectableAdapter extends RecyclerView.Adapter { - private SparseBooleanArray mSelectedItems; + private final SparseBooleanArray mSelectedItems; private boolean mIsEditionEnabled = false; - private SelectableHelper mListHelper; + private final SelectableHelper mListHelper; - public SelectableAdapter(SelectableHelper helper) { + protected SelectableAdapter(SelectableHelper helper) { mSelectedItems = new SparseBooleanArray(); mListHelper = helper; } @@ -52,7 +52,7 @@ public abstract class SelectableAdapter * @param position Position of the item to check * @return true if the item is selected, false otherwise */ - public boolean isSelected(int position) { + protected boolean isSelected(int position) { return getSelectedItems().contains(position); } diff --git a/app/src/main/java/org/linphone/utils/SelectableHelper.java b/app/src/main/java/org/linphone/utils/SelectableHelper.java index 85c3281cb..ad183ab2d 100644 --- a/app/src/main/java/org/linphone/utils/SelectableHelper.java +++ b/app/src/main/java/org/linphone/utils/SelectableHelper.java @@ -30,15 +30,16 @@ import org.linphone.LinphoneActivity; import org.linphone.R; public class SelectableHelper { - private ImageView mEditButton, - mSelectAllButton, - mDeselectAllButton, - mDeleteSelectionButton, - mCancelButton; - private LinearLayout mEditTopBar, mTopBar; + private final ImageView mEditButton; + private final ImageView mSelectAllButton; + private final ImageView mDeselectAllButton; + private final ImageView mDeleteSelectionButton; + private final ImageView mCancelButton; + private final LinearLayout mEditTopBar; + private final LinearLayout mTopBar; private SelectableAdapter mAdapter; - private DeleteListener mDeleteListener; - private Context mContext; + private final DeleteListener mDeleteListener; + private final Context mContext; private int mDialogDeleteMessageResourceId; public SelectableHelper(View view, DeleteListener listener) { @@ -159,7 +160,7 @@ public class SelectableHelper { } } - public void quitEditionMode() { + private void quitEditionMode() { mAdapter.enableEdition(false); mTopBar.setVisibility(View.VISIBLE); mEditTopBar.setVisibility(View.GONE); diff --git a/app/src/main/java/org/linphone/views/AddressText.java b/app/src/main/java/org/linphone/views/AddressText.java index 6ed85b814..8d932e406 100644 --- a/app/src/main/java/org/linphone/views/AddressText.java +++ b/app/src/main/java/org/linphone/views/AddressText.java @@ -33,7 +33,7 @@ import org.linphone.fragments.DialerFragment; public class AddressText extends EditText implements AddressType { private String mDisplayedName; - private Paint mTestPaint; + private final Paint mTestPaint; private DialerFragment mDialer; public AddressText(Context context, AttributeSet attrs) { diff --git a/app/src/main/java/org/linphone/views/BitmapWorkerTask.java b/app/src/main/java/org/linphone/views/BitmapWorkerTask.java index 30a12d47a..b3dd2e0f2 100644 --- a/app/src/main/java/org/linphone/views/BitmapWorkerTask.java +++ b/app/src/main/java/org/linphone/views/BitmapWorkerTask.java @@ -31,7 +31,6 @@ import android.provider.MediaStore; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RelativeLayout; -import java.io.FileNotFoundException; import java.io.IOException; import java.lang.ref.WeakReference; import org.linphone.mediastream.Log; @@ -42,8 +41,8 @@ public class BitmapWorkerTask extends AsyncTask { public String path; private final WeakReference mImageViewReference; - private Context mContext; - private Bitmap mDefaultBitmap; + private final Context mContext; + private final Bitmap mDefaultBitmap; public BitmapWorkerTask(Context context, ImageView imageView, Bitmap defaultBitmap) { mContext = context; @@ -85,8 +84,6 @@ public class BitmapWorkerTask extends AsyncTask { bm = MediaStore.Images.Media.getBitmap( mContext.getContentResolver(), Uri.parse(path)); - } catch (FileNotFoundException e) { - Log.e(e); } catch (IOException e) { Log.e(e); } diff --git a/app/src/main/java/org/linphone/views/ContactAvatar.java b/app/src/main/java/org/linphone/views/ContactAvatar.java index 734680e60..1e7691029 100644 --- a/app/src/main/java/org/linphone/views/ContactAvatar.java +++ b/app/src/main/java/org/linphone/views/ContactAvatar.java @@ -33,8 +33,10 @@ import org.linphone.mediastream.Log; import org.linphone.utils.ImageUtils; class ContactAvatarHolder { - public ImageView contactPicture, avatarMask, securityLevel; - public TextView generatedAvatar; + public final ImageView contactPicture; + public final ImageView avatarMask; + public final ImageView securityLevel; + public final TextView generatedAvatar; public ContactAvatarHolder(View v) { contactPicture = v.findViewById(R.id.contact_picture); @@ -54,11 +56,11 @@ public class ContactAvatar { private static String generateAvatar(String displayName) { String[] names = displayName.split(" "); - String generatedAvatarText = ""; + StringBuilder generatedAvatarText = new StringBuilder(); for (String name : names) { - generatedAvatarText += name.charAt(0); + generatedAvatarText.append(name.charAt(0)); } - return generatedAvatarText.toUpperCase(); + return generatedAvatarText.toString().toUpperCase(); } private static void setSecurityLevel(ChatRoomSecurityLevel level, View v) { diff --git a/app/src/main/java/org/linphone/views/ContactSelectView.java b/app/src/main/java/org/linphone/views/ContactSelectView.java index 7fa294796..2a331db6f 100644 --- a/app/src/main/java/org/linphone/views/ContactSelectView.java +++ b/app/src/main/java/org/linphone/views/ContactSelectView.java @@ -29,8 +29,8 @@ import org.linphone.R; import org.linphone.contacts.ContactAddress; public class ContactSelectView extends View { - private TextView mContactName; - private ImageView mDeleteContact; + private final TextView mContactName; + private final ImageView mDeleteContact; public ContactSelectView(Context context) { super(context); diff --git a/app/src/main/java/org/linphone/views/Digit.java b/app/src/main/java/org/linphone/views/Digit.java index af6861156..f3b973fbd 100644 --- a/app/src/main/java/org/linphone/views/Digit.java +++ b/app/src/main/java/org/linphone/views/Digit.java @@ -77,11 +77,11 @@ public class Digit extends Button implements AddressAware { setOnClickListener(lListener); setOnTouchListener(lListener); - if ("0+".equals(text)) { + if ("0+".equals(text.toString())) { setOnLongClickListener(lListener); } - if ("1".equals(text)) { + if ("1".equals(text.toString())) { setOnLongClickListener(lListener); } } @@ -136,7 +136,7 @@ public class Digit extends Button implements AddressAware { } } - public void displayDebugPopup() { + void displayDebugPopup() { AlertDialog.Builder alertDialog = new AlertDialog.Builder(getContext()); alertDialog.setTitle(getContext().getString(R.string.debug_popup_title)); if (LinphonePreferences.instance().isDebugEnabled()) { diff --git a/app/src/main/java/org/linphone/views/LinphoneOverlay.java b/app/src/main/java/org/linphone/views/LinphoneOverlay.java index d397eaa13..4fc54b3cf 100644 --- a/app/src/main/java/org/linphone/views/LinphoneOverlay.java +++ b/app/src/main/java/org/linphone/views/LinphoneOverlay.java @@ -39,12 +39,12 @@ import org.linphone.mediastream.Version; import org.linphone.mediastream.video.AndroidVideoWindowImpl; public class LinphoneOverlay extends org.linphone.mediastream.video.display.GL2JNIView { - private WindowManager mWindowManager; - private WindowManager.LayoutParams mParams; - private DisplayMetrics mMetrics; + private final WindowManager mWindowManager; + private final WindowManager.LayoutParams mParams; + private final DisplayMetrics mMetrics; private float mX, mY, mTouchX, mTouchY; private boolean mDragEnabled; - private AndroidVideoWindowImpl mAndroidVideoWindowImpl; + private final AndroidVideoWindowImpl mAndroidVideoWindowImpl; public LinphoneOverlay(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); diff --git a/app/src/main/java/org/linphone/views/Numpad.java b/app/src/main/java/org/linphone/views/Numpad.java index e0a0e921c..3dbbcdbf7 100644 --- a/app/src/main/java/org/linphone/views/Numpad.java +++ b/app/src/main/java/org/linphone/views/Numpad.java @@ -32,7 +32,7 @@ import org.linphone.R; public class Numpad extends LinearLayout implements AddressAware { - private boolean mPlayDtmf; + private final boolean mPlayDtmf; public Numpad(Context context, boolean playDtmf) { super(context); @@ -51,10 +51,6 @@ public class Numpad extends LinearLayout implements AddressAware { setLongClickable(true); } - public void setPlayDtmf(boolean sendDtmf) { - this.mPlayDtmf = sendDtmf; - } - @Override protected final void onFinishInflate() { for (Digit v : retrieveChildren(this, Digit.class)) { @@ -69,7 +65,7 @@ public class Numpad extends LinearLayout implements AddressAware { } } - private final Collection retrieveChildren(ViewGroup viewGroup, Class clazz) { + private Collection retrieveChildren(ViewGroup viewGroup, Class clazz) { final Collection views = new ArrayList<>(); for (int i = 0; i < viewGroup.getChildCount(); i++) { diff --git a/app/src/main/java/org/linphone/views/SlidingDrawer.java b/app/src/main/java/org/linphone/views/SlidingDrawer.java deleted file mode 100644 index 9475c0afe..000000000 --- a/app/src/main/java/org/linphone/views/SlidingDrawer.java +++ /dev/null @@ -1,1133 +0,0 @@ -package org.linphone.views; - -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Modifications by: Sylvain Berfini - */ - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.os.Handler; -import android.os.Message; -import android.os.SystemClock; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.SoundEffectConstants; -import android.view.VelocityTracker; -import android.view.View; -import android.view.ViewGroup; -import android.view.accessibility.AccessibilityEvent; -import org.linphone.R; - -public class SlidingDrawer extends ViewGroup { - - public static final int ORIENTATION_RTL = 0; - public static final int ORIENTATION_BTT = 1; - public static final int ORIENTATION_LTR = 2; - public static final int ORIENTATION_TTB = 3; - - private static final int TAP_THRESHOLD = 6; - private static final float MAXIMUM_TAP_VELOCITY = 100.0f; - private static final float MAXIMUM_MINOR_VELOCITY = 150.0f; - private static final float MAXIMUM_MAJOR_VELOCITY = 200.0f; - private static final float MAXIMUM_ACCELERATION = 2000.0f; - private static final int VELOCITY_UNITS = 1000; - private static final int MSG_ANIMATE = 1000; - private static final int ANIMATION_FRAME_DURATION = 1000 / 60; - - private static final int EXPANDED_FULL_OPEN = -10001; - private static final int COLLAPSED_FULL_CLOSED = -10002; - - private final int mHandleId; - private final int mContentId; - private final Rect mFrame = new Rect(); - private final Rect mInvalidate = new Rect(); - private final Handler mHandler = new SlidingHandler(); - private final int mTapThreshold; - private final int mMaximumTapVelocity; - private final int mVelocityUnits; - private View mHandle; - private View mContent; - private boolean mTracking; - private boolean mLocked; - private VelocityTracker mVelocityTracker; - private boolean mInvert; - private boolean mVertical; - private boolean mExpanded; - private int mBottomOffset; - private int mTopOffset; - private int mHandleHeight; - private int mHandleWidth; - private OnDrawerOpenListener mOnDrawerOpenListener; - private OnDrawerCloseListener mOnDrawerCloseListener; - private OnDrawerScrollListener mOnDrawerScrollListener; - private float mAnimatedAcceleration; - private float mAnimatedVelocity; - private float mAnimationPosition; - private long mAnimationLastTime; - private long mCurrentAnimationTime; - private int mTouchDelta; - private boolean mAnimating; - private boolean mAllowSingleTap; - private boolean mAnimateOnClick; - private int mMaximumMinorVelocity; - private int mMaximumMajorVelocity; - private int mMaximumAcceleration; - - /** - * Creates a new SlidingDrawer from a specified set of attributes defined in XML. - * - * @param context The application's environment. - * @param attrs The attributes defined in XML. - */ - public SlidingDrawer(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - /** - * Creates a new SlidingDrawer from a specified set of attributes defined in XML. - * - * @param context The application's environment. - * @param attrs The attributes defined in XML. - * @param defStyle The style to apply to this widget. - */ - @SuppressWarnings("deprecation") - public SlidingDrawer(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - TypedArray a = - context.obtainStyledAttributes(attrs, R.styleable.SlidingDrawer, defStyle, 0); - - mBottomOffset = 0; - mTopOffset = 0; - mAllowSingleTap = true; - mAnimateOnClick = true; - - int orientation = a.getInt(R.styleable.SlidingDrawer_direction, ORIENTATION_BTT); - mVertical = (orientation == ORIENTATION_BTT || orientation == ORIENTATION_TTB); - mInvert = (orientation == ORIENTATION_TTB || orientation == ORIENTATION_LTR); - - int handleId = a.getResourceId(R.styleable.SlidingDrawer_handle, 0); - if (handleId == 0) { - throw new IllegalArgumentException( - "The handle attribute is required and must refer " + "to a valid child."); - } - - int contentId = a.getResourceId(R.styleable.SlidingDrawer_content, 0); - if (contentId == 0) { - throw new IllegalArgumentException( - "The content attribute is required and must refer " + "to a valid child."); - } - - if (handleId == contentId) { - throw new IllegalArgumentException( - "The content and handle attributes must refer " + "to different children."); - } - mHandleId = handleId; - mContentId = contentId; - - final float density = getResources().getDisplayMetrics().density; - mTapThreshold = (int) (TAP_THRESHOLD * density + 0.5f); - mMaximumTapVelocity = (int) (MAXIMUM_TAP_VELOCITY * density + 0.5f); - mMaximumMinorVelocity = (int) (MAXIMUM_MINOR_VELOCITY * density + 0.5f); - mMaximumMajorVelocity = (int) (MAXIMUM_MAJOR_VELOCITY * density + 0.5f); - mMaximumAcceleration = (int) (MAXIMUM_ACCELERATION * density + 0.5f); - mVelocityUnits = (int) (VELOCITY_UNITS * density + 0.5f); - - if (mInvert) { - mMaximumAcceleration = -mMaximumAcceleration; - mMaximumMajorVelocity = -mMaximumMajorVelocity; - mMaximumMinorVelocity = -mMaximumMinorVelocity; - } - - a.recycle(); - setAlwaysDrawnWithCacheEnabled(false); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - mHandle = findViewById(mHandleId); - if (mHandle == null) { - throw new IllegalArgumentException( - "The handle attribute is must refer to an" + " existing child."); - } - mHandle.setOnClickListener(new DrawerToggler()); - - mContent = findViewById(mContentId); - if (mContent == null) { - throw new IllegalArgumentException( - "The content attribute is must refer to an" + " existing child."); - } - mContent.setVisibility(View.GONE); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); - int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); - - int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); - int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec); - - if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) { - throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions"); - } - - final View handle = mHandle; - measureChild(handle, widthMeasureSpec, heightMeasureSpec); - - if (mVertical) { - int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset; - mContent.measure( - MeasureSpec.makeMeasureSpec(widthSpecSize, MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST)); - } else { - int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset; - mContent.measure( - MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(heightSpecSize, MeasureSpec.EXACTLY)); - } - - setMeasuredDimension(widthSpecSize, heightSpecSize); - } - - private int getCustomBottom() { - return mContent.getBottom() + mHandleHeight; - } - - @Override - protected void dispatchDraw(Canvas canvas) { - final long drawingTime = getDrawingTime(); - final View handle = mHandle; - final boolean isVertical = mVertical; - - drawChild(canvas, handle, drawingTime); - - if (mTracking || mAnimating) { - final Bitmap cache = mContent.getDrawingCache(); - if (cache != null) { - if (isVertical) { - if (mInvert) { - canvas.drawBitmap( - cache, - 0, - handle.getTop() - (getCustomBottom() - getTop()) + mHandleHeight, - null); - } else { - canvas.drawBitmap(cache, 0, handle.getBottom(), null); - } - } else { - canvas.drawBitmap( - cache, - mInvert ? handle.getLeft() - cache.getWidth() : handle.getRight(), - 0, - null); - } - } else { - canvas.save(); - if (mInvert) { - canvas.translate( - isVertical - ? 0 - : handle.getLeft() - mTopOffset - mContent.getMeasuredWidth(), - isVertical - ? handle.getTop() - mTopOffset - mContent.getMeasuredHeight() - : 0); - } else { - canvas.translate( - isVertical ? 0 : handle.getLeft() - mTopOffset, - isVertical ? handle.getTop() - mTopOffset : 0); - } - drawChild(canvas, mContent, drawingTime); - canvas.restore(); - } - invalidate(); - } else if (mExpanded) { - drawChild(canvas, mContent, drawingTime); - } - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - if (mTracking) { - return; - } - - final int width = r - l; - final int height = b - t; - - final View handle = mHandle; - - int handleWidth = handle.getMeasuredWidth(); - int handleHeight = handle.getMeasuredHeight(); - - int handleLeft; - int handleTop; - - final View content = mContent; - - if (mVertical) { - handleLeft = (width - handleWidth) / 2; - if (mInvert) { - handleTop = mExpanded ? content.getMeasuredHeight() - mBottomOffset : mTopOffset; - content.layout( - 0, - mTopOffset, - content.getMeasuredWidth(), - mTopOffset + content.getMeasuredHeight()); - } else { - handleTop = mExpanded ? mTopOffset : height - handleHeight + mBottomOffset; - content.layout( - 0, - mTopOffset + handleHeight, - content.getMeasuredWidth(), - mTopOffset + handleHeight + content.getMeasuredHeight()); - } - } else { - handleTop = (height - handleHeight) / 2; - if (mInvert) { - handleLeft = mExpanded ? width - mBottomOffset - handleWidth : mTopOffset; - content.layout( - mTopOffset, - 0, - mTopOffset + content.getMeasuredWidth(), - content.getMeasuredHeight()); - } else { - handleLeft = mExpanded ? mTopOffset : width - handleWidth + mBottomOffset; - content.layout( - mTopOffset + handleWidth, - 0, - mTopOffset + handleWidth + content.getMeasuredWidth(), - content.getMeasuredHeight()); - } - } - - handle.layout(handleLeft, handleTop, handleLeft + handleWidth, handleTop + handleHeight); - mHandleHeight = handle.getHeight(); - mHandleWidth = handle.getWidth(); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent event) { - if (mLocked) { - return false; - } - - final int action = event.getAction(); - - float x = event.getX(); - float y = event.getY(); - - final Rect frame = mFrame; - final View handle = mHandle; - - handle.getHitRect(frame); - if (!mTracking && !frame.contains((int) x, (int) y)) { - return false; - } - - if (action == MotionEvent.ACTION_DOWN) { - mTracking = true; - - handle.setPressed(true); - // Must be called before prepareTracking() - prepareContent(); - - // Must be called after prepareContent() - if (mOnDrawerScrollListener != null) { - mOnDrawerScrollListener.onScrollStarted(); - } - - if (mVertical) { - final int top = mHandle.getTop(); - mTouchDelta = (int) y - top; - prepareTracking(top); - } else { - final int left = mHandle.getLeft(); - mTouchDelta = (int) x - left; - prepareTracking(left); - } - mVelocityTracker.addMovement(event); - } - - return onTouchEvent(event); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if (mLocked) { - return false; - } - - if (mTracking) { - mVelocityTracker.addMovement(event); - final int action = event.getAction(); - switch (action) { - case MotionEvent.ACTION_MOVE: - moveHandle((int) (mVertical ? event.getY() : event.getX()) - mTouchDelta); - break; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - { - final VelocityTracker velocityTracker = mVelocityTracker; - velocityTracker.computeCurrentVelocity(mVelocityUnits); - - float yVelocity = velocityTracker.getYVelocity(); - float xVelocity = velocityTracker.getXVelocity(); - boolean negative; - - final boolean vertical = mVertical; - if (vertical) { - negative = yVelocity < 0; - if (xVelocity < 0) { - xVelocity = -xVelocity; - } - // fix by Maciej Ciemięga. - if ((!mInvert && xVelocity > mMaximumMinorVelocity) - || (mInvert && xVelocity < mMaximumMinorVelocity)) { - xVelocity = mMaximumMinorVelocity; - } - } else { - negative = xVelocity < 0; - if (yVelocity < 0) { - yVelocity = -yVelocity; - } - // fix by Maciej Ciemięga. - if ((!mInvert && yVelocity > mMaximumMinorVelocity) - || (mInvert && yVelocity < mMaximumMinorVelocity)) { - yVelocity = mMaximumMinorVelocity; - } - } - - float velocity = (float) Math.hypot(xVelocity, yVelocity); - if (negative) { - velocity = -velocity; - } - - final int handleTop = mHandle.getTop(); - final int handleLeft = mHandle.getLeft(); - final int handleBottom = mHandle.getBottom(); - final int handleRight = mHandle.getRight(); - - if (Math.abs(velocity) < mMaximumTapVelocity) { - boolean c1; - boolean c2; - boolean c3; - boolean c4; - - if (mInvert) { - c1 = - (mExpanded - && (getCustomBottom() - handleBottom) - < mTapThreshold + mBottomOffset); - c2 = - (!mExpanded - && handleTop - < mTopOffset - + mHandleHeight - - mTapThreshold); - c3 = - (mExpanded - && (getRight() - handleRight) - < mTapThreshold + mBottomOffset); - c4 = - (!mExpanded - && handleLeft - > mTopOffset - + mHandleWidth - + mTapThreshold); - } else { - c1 = (mExpanded && handleTop < mTapThreshold + mTopOffset); - c2 = - (!mExpanded - && handleTop - > mBottomOffset - + getCustomBottom() - - getTop() - - mHandleHeight - - mTapThreshold); - c3 = (mExpanded && handleLeft < mTapThreshold + mTopOffset); - c4 = - (!mExpanded - && handleLeft - > mBottomOffset - + getRight() - - getLeft() - - mHandleWidth - - mTapThreshold); - } - - if (vertical ? c1 || c2 : c3 || c4) { - - if (mAllowSingleTap) { - playSoundEffect(SoundEffectConstants.CLICK); - - if (mExpanded) { - animateClose(vertical ? handleTop : handleLeft); - } else { - animateOpen(vertical ? handleTop : handleLeft); - } - } else { - performFling( - vertical ? handleTop : handleLeft, velocity, false); - } - } else { - performFling(vertical ? handleTop : handleLeft, velocity, false); - } - } else { - performFling(vertical ? handleTop : handleLeft, velocity, false); - } - } - break; - } - } - - return false; - } - - private void animateClose(int position) { - prepareTracking(position); - performFling(position, mMaximumAcceleration, true); - } - - private void animateOpen(int position) { - prepareTracking(position); - performFling(position, -mMaximumAcceleration, true); - } - - private void performFling(int position, float velocity, boolean always) { - mAnimationPosition = position; - mAnimatedVelocity = velocity; - - boolean c1; - boolean c2; - boolean c3; - - if (mExpanded) { - int bottom = mVertical ? getCustomBottom() + mHandleHeight : getRight(); - int handleHeight = mVertical ? mHandleHeight : mHandleWidth; - - c1 = mInvert ? velocity < mMaximumMajorVelocity : velocity > mMaximumMajorVelocity; - c2 = - mInvert - ? (bottom - (position + handleHeight)) + mBottomOffset > handleHeight - : position > mTopOffset + (mVertical ? mHandleHeight : mHandleWidth); - c3 = mInvert ? velocity < -mMaximumMajorVelocity : velocity > -mMaximumMajorVelocity; - if (always || (c1 || (c2 && c3))) { - // We are expanded, So animate to CLOSE! - mAnimatedAcceleration = mMaximumAcceleration; - if (mInvert) { - if (velocity > 0) { - mAnimatedVelocity = 0; - } - } else { - if (velocity < 0) { - mAnimatedVelocity = 0; - } - } - } else { - // We are expanded, but they didn't move sufficiently to cause - // us to retract. Animate back to the expanded position. so - // animate BACK to expanded! - mAnimatedAcceleration = -mMaximumAcceleration; - - if (mInvert) { - if (velocity < 0) { - mAnimatedVelocity = 0; - } - } else { - if (velocity > 0) { - mAnimatedVelocity = 0; - } - } - } - } else { - - // WE'RE COLLAPSED - - c1 = mInvert ? velocity < mMaximumMajorVelocity : velocity > mMaximumMajorVelocity; - c2 = - mInvert - ? (position < (mVertical ? getHeight() : getWidth()) / 2) - : (position > (mVertical ? getHeight() : getWidth()) / 2); - c3 = mInvert ? velocity < -mMaximumMajorVelocity : velocity > -mMaximumMajorVelocity; - - if (!always && (c1 || (c2 && c3))) { - mAnimatedAcceleration = mMaximumAcceleration; - - if (mInvert) { - if (velocity > 0) { - mAnimatedVelocity = 0; - } - } else { - if (velocity < 0) { - mAnimatedVelocity = 0; - } - } - } else { - mAnimatedAcceleration = -mMaximumAcceleration; - - if (mInvert) { - if (velocity < 0) { - mAnimatedVelocity = 0; - } - } else { - if (velocity > 0) { - mAnimatedVelocity = 0; - } - } - } - } - - long now = SystemClock.uptimeMillis(); - mAnimationLastTime = now; - mCurrentAnimationTime = now + ANIMATION_FRAME_DURATION; - mAnimating = true; - mHandler.removeMessages(MSG_ANIMATE); - mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE), mCurrentAnimationTime); - stopTracking(); - } - - private void prepareTracking(int position) { - mTracking = true; - mVelocityTracker = VelocityTracker.obtain(); - boolean opening = !mExpanded; - - if (opening) { - mAnimatedAcceleration = mMaximumAcceleration; - mAnimatedVelocity = mMaximumMajorVelocity; - if (mInvert) mAnimationPosition = mTopOffset; - else - mAnimationPosition = - mBottomOffset - + (mVertical - ? getHeight() - mHandleHeight - : getWidth() - mHandleWidth); - moveHandle((int) mAnimationPosition); - mAnimating = true; - mHandler.removeMessages(MSG_ANIMATE); - long now = SystemClock.uptimeMillis(); - mAnimationLastTime = now; - mCurrentAnimationTime = now + ANIMATION_FRAME_DURATION; - mAnimating = true; - } else { - if (mAnimating) { - mAnimating = false; - mHandler.removeMessages(MSG_ANIMATE); - } - moveHandle(position); - } - } - - private void moveHandle(int position) { - final View handle = mHandle; - - if (mVertical) { - if (position == EXPANDED_FULL_OPEN) { - if (mInvert) - handle.offsetTopAndBottom( - mBottomOffset + getCustomBottom() - getTop() - mHandleHeight); - else handle.offsetTopAndBottom(mTopOffset - handle.getTop()); - invalidate(); - } else if (position == COLLAPSED_FULL_CLOSED) { - if (mInvert) { - handle.offsetTopAndBottom(mTopOffset - handle.getTop()); - } else { - handle.offsetTopAndBottom( - mBottomOffset - + getCustomBottom() - - getTop() - - mHandleHeight - - handle.getTop()); - } - invalidate(); - } else { - final int top = handle.getTop(); - int deltaY = position - top; - if (position < mTopOffset) { - deltaY = mTopOffset - top; - } else if (deltaY - > mBottomOffset + getCustomBottom() - getTop() - mHandleHeight - top) { - deltaY = mBottomOffset + getCustomBottom() - getTop() - mHandleHeight - top; - } - - handle.offsetTopAndBottom(deltaY); - - final Rect frame = mFrame; - final Rect region = mInvalidate; - - handle.getHitRect(frame); - region.set(frame); - - region.union(frame.left, frame.top - deltaY, frame.right, frame.bottom - deltaY); - region.union( - 0, - frame.bottom - deltaY, - getWidth(), - frame.bottom - deltaY + mContent.getHeight()); - - invalidate(region); - } - } else { - if (position == EXPANDED_FULL_OPEN) { - if (mInvert) - handle.offsetLeftAndRight( - mBottomOffset + getRight() - getLeft() - mHandleWidth); - else handle.offsetLeftAndRight(mTopOffset - handle.getLeft()); - invalidate(); - } else if (position == COLLAPSED_FULL_CLOSED) { - if (mInvert) handle.offsetLeftAndRight(mTopOffset - handle.getLeft()); - else - handle.offsetLeftAndRight( - mBottomOffset - + getRight() - - getLeft() - - mHandleWidth - - handle.getLeft()); - invalidate(); - } else { - final int left = handle.getLeft(); - int deltaX = position - left; - if (position < mTopOffset) { - deltaX = mTopOffset - left; - } else if (deltaX > mBottomOffset + getRight() - getLeft() - mHandleWidth - left) { - deltaX = mBottomOffset + getRight() - getLeft() - mHandleWidth - left; - } - handle.offsetLeftAndRight(deltaX); - - final Rect frame = mFrame; - final Rect region = mInvalidate; - - handle.getHitRect(frame); - region.set(frame); - - region.union(frame.left - deltaX, frame.top, frame.right - deltaX, frame.bottom); - region.union( - frame.right - deltaX, - 0, - frame.right - deltaX + mContent.getWidth(), - getHeight()); - - invalidate(region); - } - } - } - - private void prepareContent() { - if (mAnimating) { - return; - } - - // Something changed in the content, we need to honor the layout request - // before creating the cached bitmap - final View content = mContent; - if (content.isLayoutRequested()) { - - if (mVertical) { - final int handleHeight = mHandleHeight; - int height = getBottom() - getTop() - handleHeight - mTopOffset; - content.measure( - MeasureSpec.makeMeasureSpec(getRight() - getLeft(), MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST)); - - if (mInvert) - content.layout( - 0, - mTopOffset, - content.getMeasuredWidth(), - mTopOffset + content.getMeasuredHeight()); - else - content.layout( - 0, - mTopOffset + handleHeight, - content.getMeasuredWidth(), - mTopOffset + handleHeight + content.getMeasuredHeight()); - - } else { - - final int handleWidth = mHandle.getWidth(); - int width = getRight() - getLeft() - handleWidth - mTopOffset; - content.measure( - MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(getBottom() - getTop(), MeasureSpec.EXACTLY)); - - if (mInvert) - content.layout( - mTopOffset, - 0, - mTopOffset + content.getMeasuredWidth(), - content.getMeasuredHeight()); - else - content.layout( - handleWidth + mTopOffset, - 0, - mTopOffset + handleWidth + content.getMeasuredWidth(), - content.getMeasuredHeight()); - } - } - // Try only once... we should really loop but it's not a big deal - // if the draw was cancelled, it will only be temporary anyway - content.getViewTreeObserver().dispatchOnPreDraw(); - content.buildDrawingCache(); - - content.setVisibility(View.GONE); - } - - private void stopTracking() { - mHandle.setPressed(false); - mTracking = false; - - if (mOnDrawerScrollListener != null) { - mOnDrawerScrollListener.onScrollEnded(); - } - - if (mVelocityTracker != null) { - mVelocityTracker.recycle(); - mVelocityTracker = null; - } - } - - private void doAnimation() { - if (mAnimating) { - incrementAnimation(); - - if (mInvert) { - if (mAnimationPosition < mTopOffset) { - mAnimating = false; - closeDrawer(); - } else if (mAnimationPosition - >= mTopOffset + (mVertical ? getHeight() : getWidth()) - 1) { - mAnimating = false; - openDrawer(); - } else { - moveHandle((int) mAnimationPosition); - mCurrentAnimationTime += ANIMATION_FRAME_DURATION; - mHandler.sendMessageAtTime( - mHandler.obtainMessage(MSG_ANIMATE), mCurrentAnimationTime); - } - } else { - if (mAnimationPosition - >= mBottomOffset + (mVertical ? getHeight() : getWidth()) - 1) { - mAnimating = false; - closeDrawer(); - } else if (mAnimationPosition < mTopOffset) { - mAnimating = false; - openDrawer(); - } else { - moveHandle((int) mAnimationPosition); - mCurrentAnimationTime += ANIMATION_FRAME_DURATION; - mHandler.sendMessageAtTime( - mHandler.obtainMessage(MSG_ANIMATE), mCurrentAnimationTime); - } - } - } - } - - private void incrementAnimation() { - long now = SystemClock.uptimeMillis(); - float t = (now - mAnimationLastTime) / 1000.0f; // ms -> s - final float position = mAnimationPosition; - final float v = mAnimatedVelocity; // px/s - final float a = mInvert ? mAnimatedAcceleration : mAnimatedAcceleration; // px/s/s - mAnimationPosition = position + (v * t) + (0.5f * a * t * t); // px - mAnimatedVelocity = v + (a * t); // px/s - mAnimationLastTime = now; // ms - } - - /** - * Toggles the drawer open and close. Takes effect immediately. - * - * @see #open() - * @see #close() - * @see #animateClose() - * @see #animateOpen() - * @see #animateToggle() - */ - public void toggle() { - if (!mExpanded) { - openDrawer(); - } else { - closeDrawer(); - } - invalidate(); - requestLayout(); - } - - /** - * Toggles the drawer open and close with an animation. - * - * @see #open() - * @see #close() - * @see #animateClose() - * @see #animateOpen() - * @see #toggle() - */ - public void animateToggle() { - if (!mExpanded) { - animateOpen(); - } else { - animateClose(); - } - } - - /** - * Opens the drawer immediately. - * - * @see #toggle() - * @see #close() - * @see #animateOpen() - */ - public void open() { - openDrawer(); - invalidate(); - requestLayout(); - - sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); - } - - /** - * Closes the drawer immediately. - * - * @see #toggle() - * @see #open() - * @see #animateClose() - */ - public void close() { - closeDrawer(); - invalidate(); - requestLayout(); - } - - /** - * Closes the drawer with an animation. - * - * @see #close() - * @see #open() - * @see #animateOpen() - * @see #animateToggle() - * @see #toggle() - */ - public void animateClose() { - if (!isOpened()) { - return; - } - - prepareContent(); - final OnDrawerScrollListener scrollListener = mOnDrawerScrollListener; - if (scrollListener != null) { - scrollListener.onScrollStarted(); - } - animateClose(mVertical ? mHandle.getTop() : mHandle.getLeft()); - - if (scrollListener != null) { - scrollListener.onScrollEnded(); - } - } - - /** - * Opens the drawer with an animation. - * - * @see #close() - * @see #open() - * @see #animateClose() - * @see #animateToggle() - * @see #toggle() - */ - public void animateOpen() { - prepareContent(); - final OnDrawerScrollListener scrollListener = mOnDrawerScrollListener; - if (scrollListener != null) { - scrollListener.onScrollStarted(); - } - animateOpen(mVertical ? mHandle.getTop() : mHandle.getLeft()); - - sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); - - if (scrollListener != null) { - scrollListener.onScrollEnded(); - } - } - - private void closeDrawer() { - moveHandle(COLLAPSED_FULL_CLOSED); - mContent.setVisibility(View.GONE); - mContent.destroyDrawingCache(); - - if (!mExpanded) { - return; - } - - mExpanded = false; - if (mOnDrawerCloseListener != null) { - mOnDrawerCloseListener.onDrawerClosed(); - } - } - - private void openDrawer() { - moveHandle(EXPANDED_FULL_OPEN); - mContent.setVisibility(View.VISIBLE); - - if (mExpanded) { - return; - } - - mExpanded = true; - - if (mOnDrawerOpenListener != null) { - mOnDrawerOpenListener.onDrawerOpened(); - } - } - - /** - * Sets the listener that receives a notification when the drawer becomes open. - * - * @param onDrawerOpenListener The listener to be notified when the drawer is opened. - */ - public void setOnDrawerOpenListener(OnDrawerOpenListener onDrawerOpenListener) { - mOnDrawerOpenListener = onDrawerOpenListener; - } - - /** - * Sets the listener that receives a notification when the drawer becomes close. - * - * @param onDrawerCloseListener The listener to be notified when the drawer is closed. - */ - public void setOnDrawerCloseListener(OnDrawerCloseListener onDrawerCloseListener) { - mOnDrawerCloseListener = onDrawerCloseListener; - } - - /** - * Sets the listener that receives a notification when the drawer starts or ends a scroll. A - * fling is considered as a scroll. A fling will also trigger a drawer opened or drawer closed - * event. - * - * @param onDrawerScrollListener The listener to be notified when scrolling starts or stops. - */ - public void setOnDrawerScrollListener(OnDrawerScrollListener onDrawerScrollListener) { - mOnDrawerScrollListener = onDrawerScrollListener; - } - - /** - * Returns the handle of the drawer. - * - * @return The View reprenseting the handle of the drawer, identified by the "handle" id in XML. - */ - public View getHandle() { - return mHandle; - } - - /** - * Returns the content of the drawer. - * - * @return The View reprenseting the content of the drawer, identified by the "content" id in - * XML. - */ - public View getContent() { - return mContent; - } - - /** - * Unlocks the SlidingDrawer so that touch events are processed. - * - * @see #lock() - */ - public void unlock() { - mLocked = false; - } - - /** - * Locks the SlidingDrawer so that touch events are ignores. - * - * @see #unlock() - */ - public void lock() { - mLocked = true; - } - - /** - * Indicates whether the drawer is currently fully opened. - * - * @return True if the drawer is opened, false otherwise. - */ - public boolean isOpened() { - return mExpanded; - } - - /** - * Indicates whether the drawer is scrolling or flinging. - * - * @return True if the drawer is scroller or flinging, false otherwise. - */ - public boolean isMoving() { - return mTracking || mAnimating; - } - - /** Callback invoked when the drawer is opened. */ - public static interface OnDrawerOpenListener { - - /** Invoked when the drawer becomes fully open. */ - public void onDrawerOpened(); - } - - /** Callback invoked when the drawer is closed. */ - public static interface OnDrawerCloseListener { - - /** Invoked when the drawer becomes fully closed. */ - public void onDrawerClosed(); - } - - /** Callback invoked when the drawer is scrolled. */ - public static interface OnDrawerScrollListener { - - /** Invoked when the user starts dragging/flinging the drawer's handle. */ - public void onScrollStarted(); - - /** Invoked when the user stops dragging/flinging the drawer's handle. */ - public void onScrollEnded(); - } - - private class DrawerToggler implements OnClickListener { - - public void onClick(View v) { - if (mLocked) { - return; - } - // mAllowSingleTap isn't relevant here; you're *always* - // allowed to open/close the drawer by clicking with the - // trackball. - - if (mAnimateOnClick) { - animateToggle(); - } else { - toggle(); - } - } - } - - private class SlidingHandler extends Handler { - - public void handleMessage(Message m) { - switch (m.what) { - case MSG_ANIMATE: - doAnimation(); - break; - } - } - } -} diff --git a/app/src/main/java/org/linphone/xmlrpc/XmlRpcHelper.java b/app/src/main/java/org/linphone/xmlrpc/XmlRpcHelper.java index 126a3d24b..39a3395fc 100644 --- a/app/src/main/java/org/linphone/xmlrpc/XmlRpcHelper.java +++ b/app/src/main/java/org/linphone/xmlrpc/XmlRpcHelper.java @@ -44,7 +44,7 @@ public class XmlRpcHelper { public static final String CLIENT_ERROR_INVALID_SERVER_URL = "INVALID_SERVER_URL"; public static final String CLIENT_ERROR_SERVER_NOT_REACHABLE = "SERVER_NOT_REACHABLE"; - private XmlRpcSession mXmlRpcSession; + private final XmlRpcSession mXmlRpcSession; public XmlRpcHelper() { mXmlRpcSession = @@ -66,13 +66,13 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onAccountCreated(result); + listener.onAccountCreated(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -94,13 +94,13 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } listener.onAccountExpireFetched(result); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -126,13 +126,13 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onAccountExpireUpdated(result); + listener.onAccountExpireUpdated(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -156,13 +156,13 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onAccountActivated(result); + listener.onAccountActivated(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -181,16 +181,16 @@ public class XmlRpcHelper { String result = request.getStringResponse(); if (request.getStatus() == XmlRpcStatus.Ok) { if ("OK".equals(result)) { - listener.onAccountActivatedFetched(true); + listener.onAccountActivatedFetched(); return; } else if (!"ERROR_ACCOUNT_NOT_ACTIVATED".equals(result)) { Log.e(result); - listener.onError(result); + listener.onError(); } - listener.onAccountActivatedFetched(false); + listener.onAccountActivatedFetched(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -209,12 +209,12 @@ public class XmlRpcHelper { String result = request.getStringResponse(); if (request.getStatus() == XmlRpcStatus.Ok) { if (!"NOK".equals(result) && !"OK".equals(result)) { - listener.onError(result); + listener.onError(); } listener.onTrialAccountFetched("OK".equals(result)); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -233,16 +233,16 @@ public class XmlRpcHelper { String result = request.getStringResponse(); if (request.getStatus() == XmlRpcStatus.Ok) { if ("OK".equals(result)) { - listener.onAccountFetched(true); + listener.onAccountFetched(); return; } else if (!"ERROR_ACCOUNT_DOESNT_EXIST".equals(result)) { Log.e(result); - listener.onError(result); + listener.onError(); } - listener.onAccountFetched(false); + listener.onAccountFetched(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -262,14 +262,14 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onAccountEmailChanged(result); + listener.onAccountEmailChanged(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -294,14 +294,14 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onAccountPasswordChanged(result); + listener.onAccountPasswordChanged(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -326,14 +326,14 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onAccountPasswordChanged(result); + listener.onAccountPasswordChanged(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -356,14 +356,14 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onRecoverPasswordLinkSent(result); + listener.onRecoverPasswordLinkSent(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -383,14 +383,14 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onActivateAccountLinkSent(result); + listener.onActivateAccountLinkSent(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -409,14 +409,14 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } - listener.onUsernameSent(result); + listener.onUsernameSent(); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -437,14 +437,14 @@ public class XmlRpcHelper { Log.w(result); if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } listener.onSignatureVerified("OK".equals(result)); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); @@ -466,14 +466,14 @@ public class XmlRpcHelper { if (request.getStatus() == XmlRpcStatus.Ok) { if (result.startsWith("ERROR_")) { Log.e(result); - listener.onError(result); + listener.onError(); return; } listener.onRemoteProvisioningFilenameSent(result); } else if (request.getStatus() == XmlRpcStatus.Failed) { Log.e(result); - listener.onError(result); + listener.onError(); } } }); diff --git a/app/src/main/java/org/linphone/xmlrpc/XmlRpcListener.java b/app/src/main/java/org/linphone/xmlrpc/XmlRpcListener.java index 96104f844..d7c981622 100644 --- a/app/src/main/java/org/linphone/xmlrpc/XmlRpcListener.java +++ b/app/src/main/java/org/linphone/xmlrpc/XmlRpcListener.java @@ -19,34 +19,34 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -public interface XmlRpcListener { - void onError(String error); +interface XmlRpcListener { + void onError(); - void onAccountCreated(String result); + void onAccountCreated(); void onAccountExpireFetched(String result); - void onAccountExpireUpdated(String result); + void onAccountExpireUpdated(); - void onAccountActivated(String result); + void onAccountActivated(); - void onAccountActivatedFetched(boolean isActivated); + void onAccountActivatedFetched(); void onTrialAccountFetched(boolean isTrial); - void onAccountFetched(boolean isExisting); + void onAccountFetched(); - void onAccountEmailChanged(String result); + void onAccountEmailChanged(); - void onAccountPasswordChanged(String result); + void onAccountPasswordChanged(); - void onRecoverPasswordLinkSent(String result); + void onRecoverPasswordLinkSent(); - void onActivateAccountLinkSent(String result); + void onActivateAccountLinkSent(); void onSignatureVerified(boolean success); - void onUsernameSent(String result); + void onUsernameSent(); void onRemoteProvisioningFilenameSent(String result); } diff --git a/app/src/main/java/org/linphone/xmlrpc/XmlRpcListenerBase.java b/app/src/main/java/org/linphone/xmlrpc/XmlRpcListenerBase.java index c0ad7771f..5d49d601f 100644 --- a/app/src/main/java/org/linphone/xmlrpc/XmlRpcListenerBase.java +++ b/app/src/main/java/org/linphone/xmlrpc/XmlRpcListenerBase.java @@ -21,13 +21,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. public class XmlRpcListenerBase implements XmlRpcListener { @Override - public void onError(String error) { + public void onError() { // TODO Auto-generated method stub } @Override - public void onAccountCreated(String result) { + public void onAccountCreated() { // TODO Auto-generated method stub } @@ -39,13 +39,13 @@ public class XmlRpcListenerBase implements XmlRpcListener { } @Override - public void onAccountActivated(String result) { + public void onAccountActivated() { // TODO Auto-generated method stub } @Override - public void onAccountActivatedFetched(boolean isActivated) { + public void onAccountActivatedFetched() { // TODO Auto-generated method stub } @@ -57,37 +57,37 @@ public class XmlRpcListenerBase implements XmlRpcListener { } @Override - public void onAccountFetched(boolean isExisting) { + public void onAccountFetched() { // TODO Auto-generated method stub } @Override - public void onAccountEmailChanged(String result) { + public void onAccountEmailChanged() { // TODO Auto-generated method stub } @Override - public void onAccountPasswordChanged(String result) { + public void onAccountPasswordChanged() { // TODO Auto-generated method stub } @Override - public void onRecoverPasswordLinkSent(String result) { + public void onRecoverPasswordLinkSent() { // TODO Auto-generated method stub } @Override - public void onActivateAccountLinkSent(String result) { + public void onActivateAccountLinkSent() { // TODO Auto-generated method stub } @Override - public void onAccountExpireUpdated(String result) { + public void onAccountExpireUpdated() { // TODO Auto-generated method stub } @@ -99,7 +99,7 @@ public class XmlRpcListenerBase implements XmlRpcListener { } @Override - public void onUsernameSent(String result) { + public void onUsernameSent() { // TODO Auto-generated method stub } diff --git a/app/src/main/res/drawable/clean_field.xml b/app/src/main/res/drawable/clean_field.xml index 4136a6670..00b0bc086 100644 --- a/app/src/main/res/drawable/clean_field.xml +++ b/app/src/main/res/drawable/clean_field.xml @@ -1,8 +1,8 @@ - + diff --git a/app/src/main/res/layout-land/call.xml b/app/src/main/res/layout-land/call.xml index b35084dfd..28d746c0a 100644 --- a/app/src/main/res/layout-land/call.xml +++ b/app/src/main/res/layout-land/call.xml @@ -154,7 +154,7 @@ android:layout_alignParentBottom="true" android:layout_gravity="bottom" android:background="@color/colorH" - android:orientation="vertical"> + android:orientation="vertical"/> + android:visibility="gone"/> + android:layout_height="match_parent"> - - - - - - - \ No newline at end of file + android:paddingTop="40dp"/> \ No newline at end of file diff --git a/app/src/main/res/layout/call.xml b/app/src/main/res/layout/call.xml index 72771ea4e..2c052915f 100644 --- a/app/src/main/res/layout/call.xml +++ b/app/src/main/res/layout/call.xml @@ -154,7 +154,7 @@ android:layout_alignParentBottom="true" android:layout_gravity="bottom" android:background="@color/colorH" - android:orientation="vertical"> + android:orientation="vertical"/> @@ -434,7 +432,6 @@ @@ -141,7 +141,7 @@ + android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/chat_imdn.xml b/app/src/main/res/layout/chat_imdn.xml index d8dc1eb55..22bf89ce9 100644 --- a/app/src/main/res/layout/chat_imdn.xml +++ b/app/src/main/res/layout/chat_imdn.xml @@ -59,7 +59,7 @@ diff --git a/app/src/main/res/layout/chatlist_cell.xml b/app/src/main/res/layout/chatlist_cell.xml index e6b524667..f9ee9bbbf 100644 --- a/app/src/main/res/layout/chatlist_cell.xml +++ b/app/src/main/res/layout/chatlist_cell.xml @@ -49,7 +49,6 @@ + android:visibility="gone"/> + android:text="sip:[user@]host[:port]"/> + android:text="Call"/> @@ -30,27 +30,27 @@ android:layout_height="wrap_content" android:hint="enter my sip identity (sip:[user@]host)" android:text="" - android:visibility="gone"> + android:visibility="gone"/> + android:visibility="gone"/> + android:text="Debug"/> + android:text="STOP"/> diff --git a/app/src/main/res/layout/hidden.xml b/app/src/main/res/layout/hidden.xml index e14c67df5..6bf2573db 100644 --- a/app/src/main/res/layout/hidden.xml +++ b/app/src/main/res/layout/hidden.xml @@ -2,4 +2,4 @@ + android:visibility="gone"/> diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index f7c7a3096..ee0c731e2 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -65,8 +65,7 @@ + android:layout_height="match_parent"> @@ -44,7 +43,6 @@ style="@style/font2" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerVertical="true" android:ellipsize="end" android:gravity="bottom|left" android:lines="1" /> diff --git a/app/src/main/res/layout/tuto_carddav.xml b/app/src/main/res/layout/tuto_carddav.xml index 9540950b9..6e78b6b73 100644 --- a/app/src/main/res/layout/tuto_carddav.xml +++ b/app/src/main/res/layout/tuto_carddav.xml @@ -48,7 +48,7 @@ \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml deleted file mode 100644 index ee722e7b1..000000000 --- a/app/src/main/res/values/attrs.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file