mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 06:15:12 +00:00
Refactoring
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
5cf0a80fdf
commit
79c0fa0ba6
@ -33,7 +33,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
@ -81,7 +80,6 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.webrtc.MagicAudioManager;
|
||||
import com.nextcloud.talk.webrtc.MagicPeerConnectionWrapper;
|
||||
import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
|
||||
import com.nextcloud.talk.webrtc.MagicWebRTCLists;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@ -487,9 +485,7 @@ public class CallActivity extends AppCompatActivity {
|
||||
if (camera2EnumeratorIsSupported) {
|
||||
cameraEnumerator = new Camera2Enumerator(this);
|
||||
} else {
|
||||
cameraEnumerator = new Camera1Enumerator(!MagicWebRTCLists.HARDWARE_ACCELERATION_VENDOR_BLACKLIST.contains(Build
|
||||
.MANUFACTURER.toLowerCase()) && !MagicWebRTCLists.HARDWARE_ACCELERATION_DEVICE_BLACKLIST.contains
|
||||
(Build.MODEL));
|
||||
cameraEnumerator = new Camera1Enumerator(MagicWebRTCUtils.shouldEnableVideoHardwareAcceleration());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,10 @@
|
||||
*/
|
||||
package com.nextcloud.talk.application;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.multidex.MultiDex;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.support.v7.widget.AppCompatDrawableManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.evernote.android.job.JobManager;
|
||||
@ -39,8 +37,9 @@ import com.nextcloud.talk.dagger.modules.RestModule;
|
||||
import com.nextcloud.talk.jobs.AccountRemovalJob;
|
||||
import com.nextcloud.talk.jobs.PushRegistrationJob;
|
||||
import com.nextcloud.talk.jobs.creator.MagicJobCreator;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.database.user.UserModule;
|
||||
import com.nextcloud.talk.webrtc.MagicWebRTCLists;
|
||||
import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
import com.squareup.leakcanary.RefWatcher;
|
||||
|
||||
@ -48,9 +47,6 @@ import org.webrtc.PeerConnectionFactory;
|
||||
import org.webrtc.voiceengine.WebRtcAudioManager;
|
||||
import org.webrtc.voiceengine.WebRtcAudioUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@ -89,43 +85,18 @@ public class NextcloudTalkApplication extends MultiDexApplication {
|
||||
//endregion
|
||||
|
||||
//region private methods
|
||||
// Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected
|
||||
private void useCompatVectorIfNeeded() {
|
||||
if (Build.VERSION.SDK_INT < 23) {
|
||||
try {
|
||||
@SuppressLint("RestrictedApi") AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get();
|
||||
Class<?> inflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$InflateDelegate");
|
||||
Class<?> vdcInflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate");
|
||||
|
||||
Constructor<?> constructor = vdcInflateDelegateClass.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
Object vdcInflateDelegate = constructor.newInstance();
|
||||
|
||||
Class<?> args[] = {String.class, inflateDelegateClass};
|
||||
Method addDelegate = AppCompatDrawableManager.class.getDeclaredMethod("addDelegate", args);
|
||||
addDelegate.setAccessible(true);
|
||||
addDelegate.invoke(drawableManager, "vector", vdcInflateDelegate);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |
|
||||
InvocationTargetException | IllegalAccessException e) {
|
||||
Log.e(TAG, "Failed to use reflection to enable proper vector scaling");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeWebRtc() {
|
||||
try {
|
||||
if (MagicWebRTCLists.HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) {
|
||||
if (MagicWebRTCUtils.HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) {
|
||||
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
|
||||
}
|
||||
|
||||
if (!MagicWebRTCLists.OPEN_SL_ES_WHITELIST.contains(Build.MODEL)) {
|
||||
if (!MagicWebRTCUtils.OPEN_SL_ES_WHITELIST.contains(Build.MODEL)) {
|
||||
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true);
|
||||
}
|
||||
|
||||
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(this)
|
||||
.setEnableVideoHwAcceleration(!MagicWebRTCLists.HARDWARE_ACCELERATION_VENDOR_BLACKLIST.contains(Build
|
||||
.MANUFACTURER.toLowerCase()) && !MagicWebRTCLists.HARDWARE_ACCELERATION_DEVICE_BLACKLIST
|
||||
.contains(Build.MODEL))
|
||||
.setEnableVideoHwAcceleration(MagicWebRTCUtils.shouldEnableVideoHardwareAcceleration())
|
||||
.createInitializationOptions());
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
Log.w(TAG, e);
|
||||
@ -144,7 +115,7 @@ public class NextcloudTalkApplication extends MultiDexApplication {
|
||||
sharedApplication = this;
|
||||
|
||||
initializeWebRtc();
|
||||
useCompatVectorIfNeeded();
|
||||
DisplayUtils.useCompatVectorIfNeeded();
|
||||
|
||||
|
||||
try {
|
||||
|
@ -40,7 +40,7 @@ import com.nextcloud.talk.api.helpers.api.ApiHelper;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.jobs.PushRegistrationJob;
|
||||
import com.nextcloud.talk.utils.ErrorMessageHolder;
|
||||
import com.nextcloud.talk.utils.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
|
||||
@ -218,8 +218,8 @@ public class AccountVerificationController extends BaseController {
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
} else {
|
||||
if (isAccountImport) {
|
||||
ErrorMessageHolder.getInstance().setMessageType(
|
||||
ErrorMessageHolder.ErrorMessageType.ACCOUNT_WAS_IMPORTED);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(
|
||||
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED);
|
||||
}
|
||||
getRouter().popToRoot();
|
||||
}
|
||||
@ -247,8 +247,8 @@ public class AccountVerificationController extends BaseController {
|
||||
}, throwable -> {
|
||||
progressText.setText(String.format(getResources().getString(
|
||||
R.string.nc_nextcloud_talk_app_not_installed), getResources().getString(R.string.nc_app_name)));
|
||||
ErrorMessageHolder.getInstance().setMessageType(
|
||||
ErrorMessageHolder.ErrorMessageType.SERVER_WITHOUT_TALK);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(
|
||||
ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK);
|
||||
|
||||
abortVerification();
|
||||
}, () -> dispose(roomsQueryDisposable));
|
||||
@ -317,8 +317,8 @@ public class AccountVerificationController extends BaseController {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ErrorMessageHolder.getInstance().setMessageType(
|
||||
ErrorMessageHolder.ErrorMessageType.FAILED_TO_IMPORT_ACCOUNT);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(
|
||||
ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -43,7 +43,7 @@ import com.nextcloud.talk.api.helpers.api.ApiHelper;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.utils.AccountUtils;
|
||||
import com.nextcloud.talk.utils.ErrorMessageHolder;
|
||||
import com.nextcloud.talk.utils.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
|
||||
@ -298,22 +298,22 @@ public class ServerSelectionController extends BaseController {
|
||||
@Override
|
||||
protected void onAttach(@NonNull View view) {
|
||||
super.onAttach(view);
|
||||
if (ErrorMessageHolder.getInstance().getMessageType() != null) {
|
||||
if (ErrorMessageHolder.getInstance().getMessageType()
|
||||
.equals(ErrorMessageHolder.ErrorMessageType.ACCOUNT_SCHEDULED_FOR_DELETION)) {
|
||||
if (ApplicationWideMessageHolder.getInstance().getMessageType() != null) {
|
||||
if (ApplicationWideMessageHolder.getInstance().getMessageType()
|
||||
.equals(ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION)) {
|
||||
textFieldBoxes.setError(getResources().getString(R.string.nc_account_scheduled_for_deletion),
|
||||
false);
|
||||
ErrorMessageHolder.getInstance().setMessageType(null);
|
||||
} else if (ErrorMessageHolder.getInstance().getMessageType()
|
||||
.equals(ErrorMessageHolder.ErrorMessageType.SERVER_WITHOUT_TALK)) {
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(null);
|
||||
} else if (ApplicationWideMessageHolder.getInstance().getMessageType()
|
||||
.equals(ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK)) {
|
||||
textFieldBoxes.setError(getResources().getString(R.string.nc_settings_no_talk_installed),
|
||||
false);
|
||||
} else if (ErrorMessageHolder.getInstance().getMessageType()
|
||||
.equals(ErrorMessageHolder.ErrorMessageType.FAILED_TO_IMPORT_ACCOUNT)) {
|
||||
} else if (ApplicationWideMessageHolder.getInstance().getMessageType()
|
||||
.equals(ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT)) {
|
||||
textFieldBoxes.setError(getResources().getString(R.string.nc_server_failed_to_import_account),
|
||||
false);
|
||||
}
|
||||
ErrorMessageHolder.getInstance().setMessageType(null);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.jobs.AccountRemovalJob;
|
||||
import com.nextcloud.talk.persistence.entities.UserEntity;
|
||||
import com.nextcloud.talk.utils.ErrorMessageHolder;
|
||||
import com.nextcloud.talk.utils.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
@ -356,8 +356,8 @@ public class SettingsController extends BaseController {
|
||||
|
||||
addAccountButton.setEnabled(true);
|
||||
|
||||
if (ErrorMessageHolder.getInstance().getMessageType() != null) {
|
||||
switch (ErrorMessageHolder.getInstance().getMessageType()) {
|
||||
if (ApplicationWideMessageHolder.getInstance().getMessageType() != null) {
|
||||
switch (ApplicationWideMessageHolder.getInstance().getMessageType()) {
|
||||
case ACCOUNT_UPDATED_NOT_ADDED:
|
||||
messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
|
||||
messageText.setText(getResources().getString(R.string.nc_settings_account_updated));
|
||||
@ -386,7 +386,7 @@ public class SettingsController extends BaseController {
|
||||
messageView.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
ErrorMessageHolder.getInstance().setMessageType(null);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(null);
|
||||
|
||||
messageView.animate()
|
||||
.translationY(0)
|
||||
|
@ -49,7 +49,7 @@ import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.events.CertificateEvent;
|
||||
import com.nextcloud.talk.models.LoginData;
|
||||
import com.nextcloud.talk.persistence.entities.UserEntity;
|
||||
import com.nextcloud.talk.utils.ErrorMessageHolder;
|
||||
import com.nextcloud.talk.utils.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.bundle.BundleBuilder;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
@ -268,28 +268,28 @@ public class WebViewLoginController extends BaseController {
|
||||
|
||||
UserEntity currentUser = userUtils.getCurrentUser();
|
||||
|
||||
ErrorMessageHolder.ErrorMessageType errorMessageType = null;
|
||||
ApplicationWideMessageHolder.MessageType messageType = null;
|
||||
if (currentUser != null && isPasswordUpdate &&
|
||||
!currentUser.getUsername().equals(loginData.getUsername())) {
|
||||
ErrorMessageHolder.getInstance().setMessageType(
|
||||
ErrorMessageHolder.ErrorMessageType.WRONG_ACCOUNT);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(
|
||||
ApplicationWideMessageHolder.MessageType.WRONG_ACCOUNT);
|
||||
getRouter().popToRoot();
|
||||
} else {
|
||||
|
||||
if (!isPasswordUpdate && userUtils.getIfUserWithUsernameAndServer(loginData.getUsername(), baseUrl)) {
|
||||
errorMessageType = ErrorMessageHolder.ErrorMessageType.ACCOUNT_UPDATED_NOT_ADDED;
|
||||
messageType = ApplicationWideMessageHolder.MessageType.ACCOUNT_UPDATED_NOT_ADDED;
|
||||
}
|
||||
|
||||
if (userUtils.checkIfUserIsScheduledForDeletion(loginData.getUsername(), baseUrl)) {
|
||||
ErrorMessageHolder.getInstance().setMessageType(
|
||||
ErrorMessageHolder.ErrorMessageType.ACCOUNT_SCHEDULED_FOR_DELETION);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(
|
||||
ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION);
|
||||
getRouter().popToRoot();
|
||||
}
|
||||
|
||||
ErrorMessageHolder.ErrorMessageType finalErrorMessageType = errorMessageType;
|
||||
ApplicationWideMessageHolder.MessageType finalMessageType = messageType;
|
||||
cookieManager.getCookieStore().removeAll();
|
||||
|
||||
if (!isPasswordUpdate && finalErrorMessageType == null) {
|
||||
if (!isPasswordUpdate && finalMessageType == null) {
|
||||
BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
|
||||
bundleBuilder.putString(BundleKeys.KEY_USERNAME, loginData.getUsername());
|
||||
bundleBuilder.putString(BundleKeys.KEY_TOKEN, loginData.getToken());
|
||||
@ -315,16 +315,16 @@ public class WebViewLoginController extends BaseController {
|
||||
null, null, null, true,
|
||||
null, currentUser.getId()).
|
||||
subscribe(userEntity -> {
|
||||
if (finalErrorMessageType != null) {
|
||||
ErrorMessageHolder.getInstance().setMessageType(finalErrorMessageType);
|
||||
if (finalMessageType != null) {
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
|
||||
}
|
||||
getRouter().popToRoot();
|
||||
}, throwable -> dispose(),
|
||||
this::dispose);
|
||||
}
|
||||
} else {
|
||||
if (finalErrorMessageType != null) {
|
||||
ErrorMessageHolder.getInstance().setMessageType(finalErrorMessageType);
|
||||
if (finalMessageType != null) {
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
|
||||
}
|
||||
getRouter().popToRoot();
|
||||
|
||||
|
@ -40,7 +40,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.events.BottomSheetLockEvent;
|
||||
import com.nextcloud.talk.persistence.entities.UserEntity;
|
||||
import com.nextcloud.talk.utils.ErrorMessageHolder;
|
||||
import com.nextcloud.talk.utils.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.ShareUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
@ -102,10 +102,10 @@ public class EntryMenuController extends BaseController {
|
||||
@Override
|
||||
protected void onAttach(@NonNull View view) {
|
||||
super.onAttach(view);
|
||||
if (ErrorMessageHolder.getInstance().getMessageType() != null &&
|
||||
ErrorMessageHolder.getInstance().getMessageType().equals(ErrorMessageHolder.ErrorMessageType.CALL_PASSWORD_WRONG)) {
|
||||
if (ApplicationWideMessageHolder.getInstance().getMessageType() != null &&
|
||||
ApplicationWideMessageHolder.getInstance().getMessageType().equals(ApplicationWideMessageHolder.MessageType.CALL_PASSWORD_WRONG)) {
|
||||
textFieldBoxes.setError(getResources().getString(R.string.nc_wrong_password), true);
|
||||
ErrorMessageHolder.getInstance().setMessageType(null);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(null);
|
||||
if (proceedButton.isEnabled()) {
|
||||
proceedButton.setEnabled(false);
|
||||
proceedButton.setAlpha(0.7f);
|
||||
|
@ -43,7 +43,7 @@ import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.events.BottomSheetLockEvent;
|
||||
import com.nextcloud.talk.persistence.entities.UserEntity;
|
||||
import com.nextcloud.talk.utils.ColorUtils;
|
||||
import com.nextcloud.talk.utils.ErrorMessageHolder;
|
||||
import com.nextcloud.talk.utils.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.bundle.BundleBuilder;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
@ -276,7 +276,7 @@ public class OperationsMenuController extends BaseController {
|
||||
if (((HttpException) e).response().code() == 403) {
|
||||
eventBus.post(new BottomSheetLockEvent(true, 0, false,
|
||||
false));
|
||||
ErrorMessageHolder.getInstance().setMessageType(ErrorMessageHolder.ErrorMessageType.CALL_PASSWORD_WRONG);
|
||||
ApplicationWideMessageHolder.getInstance().setMessageType(ApplicationWideMessageHolder.MessageType.CALL_PASSWORD_WRONG);
|
||||
getRouter().popCurrentController();
|
||||
} else {
|
||||
showResultImage(false);
|
||||
|
@ -22,23 +22,23 @@ package com.nextcloud.talk.utils;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class ErrorMessageHolder {
|
||||
private static final ErrorMessageHolder holder = new ErrorMessageHolder();
|
||||
private ErrorMessageType errorMessageType;
|
||||
public class ApplicationWideMessageHolder {
|
||||
private static final ApplicationWideMessageHolder holder = new ApplicationWideMessageHolder();
|
||||
private MessageType messageType;
|
||||
|
||||
public static ErrorMessageHolder getInstance() {
|
||||
public static ApplicationWideMessageHolder getInstance() {
|
||||
return holder;
|
||||
}
|
||||
|
||||
public ErrorMessageType getMessageType() {
|
||||
return errorMessageType;
|
||||
public MessageType getMessageType() {
|
||||
return messageType;
|
||||
}
|
||||
|
||||
public void setMessageType(@Nullable ErrorMessageType errorMessageType) {
|
||||
this.errorMessageType = errorMessageType;
|
||||
public void setMessageType(@Nullable MessageType messageType) {
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
public enum ErrorMessageType {
|
||||
public enum MessageType {
|
||||
WRONG_ACCOUNT, ACCOUNT_UPDATED_NOT_ADDED, ACCOUNT_SCHEDULED_FOR_DELETION, SERVER_WITHOUT_TALK,
|
||||
FAILED_TO_IMPORT_ACCOUNT, ACCOUNT_WAS_IMPORTED, CALL_PASSWORD_WRONG
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
public class DisplayHelper {
|
||||
|
||||
private static final String TAG = "DIsplayHelper";
|
||||
|
||||
public static float convertDpToPixel(float dp, Context context) {
|
||||
Resources resources = context.getResources();
|
||||
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||
float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||
return px;
|
||||
}
|
||||
}
|
69
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java
Normal file
69
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.support.v7.widget.AppCompatDrawableManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class DisplayUtils {
|
||||
|
||||
private static final String TAG = "DIsplayHelper";
|
||||
|
||||
public static float convertDpToPixel(float dp, Context context) {
|
||||
Resources resources = context.getResources();
|
||||
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||
float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||
return px;
|
||||
}
|
||||
|
||||
// Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected
|
||||
public static void useCompatVectorIfNeeded() {
|
||||
if (Build.VERSION.SDK_INT < 23) {
|
||||
try {
|
||||
@SuppressLint("RestrictedApi") AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get();
|
||||
Class<?> inflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$InflateDelegate");
|
||||
Class<?> vdcInflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate");
|
||||
|
||||
Constructor<?> constructor = vdcInflateDelegateClass.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
Object vdcInflateDelegate = constructor.newInstance();
|
||||
|
||||
Class<?> args[] = {String.class, inflateDelegateClass};
|
||||
Method addDelegate = AppCompatDrawableManager.class.getDeclaredMethod("addDelegate", args);
|
||||
addDelegate.setAccessible(true);
|
||||
addDelegate.invoke(drawableManager, "vector", vdcInflateDelegate);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |
|
||||
InvocationTargetException | IllegalAccessException e) {
|
||||
Log.e(TAG, "Failed to use reflection to enable proper vector scaling");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -27,23 +27,69 @@
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.webrtc;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MagicWebRTCUtils {
|
||||
private static final String TAG = "MagicWebRTCUtils";
|
||||
|
||||
/* AEC blacklist and SL_ES_WHITELIST are borrowed from Signal
|
||||
https://github.com/WhisperSystems/Signal-Android/blob/551470123d006b76a68d705d131bb12513a5e683/src/org/thoughtcrime/securesms/ApplicationContext.java
|
||||
*/
|
||||
public static Set<String> HARDWARE_AEC_BLACKLIST = new HashSet<String>() {{
|
||||
add("D6503"); // Sony Xperia Z2 D6503
|
||||
add("ONE A2005"); // OnePlus 2
|
||||
add("MotoG3"); // Moto G (3rd Generation)
|
||||
add("Nexus 6P"); // Nexus 6p
|
||||
add("Pixel"); // Pixel
|
||||
add("Pixel XL"); // Pixel XL
|
||||
add("MI 4LTE"); // Xiami Mi4
|
||||
add("Redmi Note 3"); // Redmi Note 3
|
||||
add("Redmi Note 4"); // Redmi Note 4
|
||||
add("SM-G900F"); // Samsung Galaxy S5
|
||||
add("g3_kt_kr"); // LG G3
|
||||
add("SM-G930F"); // Samsung Galaxy S7
|
||||
add("Xperia SP"); // Sony Xperia SP
|
||||
add("Nexus 6"); // Nexus 6
|
||||
add("ONE E1003"); // OnePlus X
|
||||
add("One"); // OnePlus One
|
||||
add("Moto G5");
|
||||
}};
|
||||
|
||||
public static Set<String> OPEN_SL_ES_WHITELIST = new HashSet<String>() {{
|
||||
add("Pixel");
|
||||
add("Pixel XL");
|
||||
}};
|
||||
|
||||
private static Set<String> HARDWARE_ACCELERATION_DEVICE_BLACKLIST = new HashSet<String>() {{
|
||||
add("GT-I9100"); // Samsung Galaxy S2
|
||||
add("GT-N8013"); // Samsung Galaxy Note 10.1
|
||||
add("SM-G930F"); // Samsung Galaxy S7
|
||||
add("AGS-W09"); // Huawei MediaPad T3 10
|
||||
}};
|
||||
|
||||
private static Set<String> HARDWARE_ACCELERATION_VENDOR_BLACKLIST = new HashSet<String>() {{
|
||||
add("samsung");
|
||||
}};
|
||||
|
||||
public static boolean shouldEnableVideoHardwareAcceleration() {
|
||||
return (!HARDWARE_ACCELERATION_VENDOR_BLACKLIST.contains(Build.MANUFACTURER.toLowerCase())
|
||||
&& !HARDWARE_ACCELERATION_DEVICE_BLACKLIST.contains(Build.MODEL));
|
||||
}
|
||||
|
||||
public static String preferCodec(String sdpDescription, String codec, boolean isAudio) {
|
||||
final String[] lines = sdpDescription.split("\r\n");
|
||||
final int mLineIndex = findMediaDescriptionLine(isAudio, lines);
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.webrtc;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MagicWebRTCLists {
|
||||
/*
|
||||
AEC blacklist and SL_ES_WHITELIST are borrowed from Signal
|
||||
https://github.com/WhisperSystems/Signal-Android/blob/551470123d006b76a68d705d131bb12513a5e683/src/org/thoughtcrime/securesms/ApplicationContext.java
|
||||
*/
|
||||
public static Set<String> HARDWARE_AEC_BLACKLIST = new HashSet<String>() {{
|
||||
add("D6503"); // Sony Xperia Z2 D6503
|
||||
add("ONE A2005"); // OnePlus 2
|
||||
add("MotoG3"); // Moto G (3rd Generation)
|
||||
add("Nexus 6P"); // Nexus 6p
|
||||
add("Pixel"); // Pixel
|
||||
add("Pixel XL"); // Pixel XL
|
||||
add("MI 4LTE"); // Xiami Mi4
|
||||
add("Redmi Note 3"); // Redmi Note 3
|
||||
add("Redmi Note 4"); // Redmi Note 4
|
||||
add("SM-G900F"); // Samsung Galaxy S5
|
||||
add("g3_kt_kr"); // LG G3
|
||||
add("SM-G930F"); // Samsung Galaxy S7
|
||||
add("Xperia SP"); // Sony Xperia SP
|
||||
add("Nexus 6"); // Nexus 6
|
||||
add("ONE E1003"); // OnePlus X
|
||||
add("One"); // OnePlus One
|
||||
add("Moto G5");
|
||||
}};
|
||||
|
||||
public static Set<String> OPEN_SL_ES_WHITELIST = new HashSet<String>() {{
|
||||
add("Pixel");
|
||||
add("Pixel XL");
|
||||
}};
|
||||
|
||||
public static Set<String> HARDWARE_ACCELERATION_DEVICE_BLACKLIST = new HashSet<String>() {{
|
||||
add("GT-I9100"); // Samsung Galaxy S2
|
||||
add("GT-N8013"); // Samsung Galaxy Note 10.1
|
||||
add("SM-G930F"); // Samsung Galaxy S7
|
||||
add("AGS-W09"); // Huawei MediaPad T3 10
|
||||
}};
|
||||
|
||||
public static Set<String> HARDWARE_ACCELERATION_VENDOR_BLACKLIST = new HashSet<String>() {{
|
||||
add("samsung");
|
||||
}};
|
||||
}
|
Loading…
Reference in New Issue
Block a user