From 7d1bd65a3b371e7e85c199706ef1aee81534e3fc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 14 Mar 2018 08:21:49 +0100 Subject: [PATCH] make camera feature optional --- src/main/AndroidManifest.xml | 3 +++ .../conversations/ui/ChooseContactActivity.java | 2 +- .../ui/ContactDetailsActivity.java | 2 +- .../conversations/ui/ConversationsActivity.java | 14 +++++++++----- .../ui/StartConversationActivity.java | 2 ++ .../conversations/ui/TrustKeysActivity.java | 4 ++-- .../eu/siacs/conversations/ui/XmppActivity.java | 17 +++++++---------- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index adbc294ff..fa9b8a82b 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -22,6 +22,9 @@ + + + ScanActivity.scan(this)); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index e0cbfcc66..4a04b931e 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -385,11 +385,15 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio getMenuInflater().inflate(R.menu.activity_conversations, menu); MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code); if (qrCodeScanMenuItem != null) { - Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment); - boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan) - && fragment != null - && fragment instanceof ConversationsOverviewFragment; - qrCodeScanMenuItem.setVisible(visible); + if (isCameraFeatureAvailable()) { + Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment); + boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan) + && fragment != null + && fragment instanceof ConversationsOverviewFragment; + qrCodeScanMenuItem.setVisible(visible); + } else { + qrCodeScanMenuItem.setVisible(false); + } } return super.onCreateOptionsMenu(menu); } diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 83f13a734..f7c0f98eb 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -614,8 +614,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU getMenuInflater().inflate(R.menu.start_conversation, menu); MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline); MenuItem joinGroupChat = menu.findItem(R.id.action_join_conference); + MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code); ActionBar bar = getSupportActionBar(); joinGroupChat.setVisible(bar != null && bar.getSelectedNavigationIndex() == 1); + qrCodeScanMenuItem.setVisible(isCameraFeatureAvailable()); menuHideOffline.setChecked(this.mHideOfflineContacts); mMenuSearchView = menu.findItem(R.id.action_search); mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener); diff --git a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index 77b8c7fef..0c2e06d7c 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -111,7 +111,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.trust_keys, menu); MenuItem scanQrCode = menu.findItem(R.id.action_scan_qr_code); - scanQrCode.setVisible(ownKeysToTrust.size() > 0 || foreignActuallyHasKeys()); + scanQrCode.setVisible((ownKeysToTrust.size() > 0 || foreignActuallyHasKeys()) && isCameraFeatureAvailable()); return super.onCreateOptionsMenu(menu); } @@ -223,7 +223,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat } } - if ((hasOwnKeys || foreignActuallyHasKeys()) && mUseCameraHintShown.compareAndSet(false,true)) { + if ((hasOwnKeys || foreignActuallyHasKeys()) && isCameraFeatureAvailable() && mUseCameraHintShown.compareAndSet(false,true)) { showCameraToast(); } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index a6d6b0e09..56db0c625 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -83,12 +83,11 @@ public abstract class XmppActivity extends AppCompatActivity { public boolean xmppConnectionServiceBound = false; protected boolean registeredListeners = false; - protected int mPrimaryBackgroundColor; - protected int mSecondaryBackgroundColor; protected int mColorRed; protected int mColorOrange; protected int mColorGreen; - protected int mPrimaryColor; + + private boolean isCameraFeatureAvailable = false; protected boolean mUseSubject = true; protected int mTheme; @@ -408,19 +407,13 @@ public abstract class XmppActivity extends AppCompatActivity { super.onCreate(savedInstanceState); metrics = getResources().getDisplayMetrics(); ExceptionHelper.init(getApplicationContext()); + this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); mColorRed = ContextCompat.getColor(this, R.color.red800); mColorOrange = ContextCompat.getColor(this, R.color.orange500); mColorGreen = ContextCompat.getColor(this, R.color.green500); - mPrimaryColor = ContextCompat.getColor(this, R.color.primary500); - mPrimaryBackgroundColor = ContextCompat.getColor(this, R.color.grey50); - mSecondaryBackgroundColor = ContextCompat.getColor(this, R.color.grey200); this.mTheme = findTheme(); - if (isDarkTheme()) { - mPrimaryBackgroundColor = ContextCompat.getColor(this, R.color.grey800); - mSecondaryBackgroundColor = ContextCompat.getColor(this, R.color.grey900); - } setTheme(this.mTheme); this.mUsingEnterKey = usingEnterKey(); @@ -431,6 +424,10 @@ public abstract class XmppActivity extends AppCompatActivity { } } + protected boolean isCameraFeatureAvailable() { + return this.isCameraFeatureAvailable; + } + public boolean isDarkTheme() { return this.mTheme == R.style.ConversationsTheme_Dark; }