make camera feature optional

This commit is contained in:
Daniel Gultsch 2018-03-14 08:21:49 +01:00
parent f371da7d85
commit 7d1bd65a3b
7 changed files with 25 additions and 19 deletions

View File

@ -22,6 +22,9 @@
<uses-sdk tools:overrideLibrary="net.ypresto.androidtranscoder" /> <uses-sdk tools:overrideLibrary="net.ypresto.androidtranscoder" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application <application
android:networkSecurityConfig="@xml/network_security_configuration" android:networkSecurityConfig="@xml/network_security_configuration"

View File

@ -182,7 +182,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
final Intent i = getIntent(); final Intent i = getIntent();
boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false); boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
menu.findItem(R.id.action_scan_qr_code).setVisible(showEnterJid); menu.findItem(R.id.action_scan_qr_code).setVisible(isCameraFeatureAvailable() && showEnterJid);
return true; return true;
} }

View File

@ -427,7 +427,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
} else { } else {
binding.showInactiveDevices.setVisibility(View.GONE); binding.showInactiveDevices.setVisibility(View.GONE);
} }
binding.scanButton.setVisibility(hasKeys ? View.VISIBLE : View.GONE); binding.scanButton.setVisibility(hasKeys && isCameraFeatureAvailable() ? View.VISIBLE : View.GONE);
if (hasKeys) { if (hasKeys) {
binding.scanButton.setOnClickListener((v)-> ScanActivity.scan(this)); binding.scanButton.setOnClickListener((v)-> ScanActivity.scan(this));
} }

View File

@ -385,11 +385,15 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
getMenuInflater().inflate(R.menu.activity_conversations, menu); getMenuInflater().inflate(R.menu.activity_conversations, menu);
MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code); MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
if (qrCodeScanMenuItem != null) { if (qrCodeScanMenuItem != null) {
if (isCameraFeatureAvailable()) {
Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment); Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan) boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
&& fragment != null && fragment != null
&& fragment instanceof ConversationsOverviewFragment; && fragment instanceof ConversationsOverviewFragment;
qrCodeScanMenuItem.setVisible(visible); qrCodeScanMenuItem.setVisible(visible);
} else {
qrCodeScanMenuItem.setVisible(false);
}
} }
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }

View File

@ -614,8 +614,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
getMenuInflater().inflate(R.menu.start_conversation, menu); getMenuInflater().inflate(R.menu.start_conversation, menu);
MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline); MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
MenuItem joinGroupChat = menu.findItem(R.id.action_join_conference); MenuItem joinGroupChat = menu.findItem(R.id.action_join_conference);
MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
ActionBar bar = getSupportActionBar(); ActionBar bar = getSupportActionBar();
joinGroupChat.setVisible(bar != null && bar.getSelectedNavigationIndex() == 1); joinGroupChat.setVisible(bar != null && bar.getSelectedNavigationIndex() == 1);
qrCodeScanMenuItem.setVisible(isCameraFeatureAvailable());
menuHideOffline.setChecked(this.mHideOfflineContacts); menuHideOffline.setChecked(this.mHideOfflineContacts);
mMenuSearchView = menu.findItem(R.id.action_search); mMenuSearchView = menu.findItem(R.id.action_search);
mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener); mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);

View File

@ -111,7 +111,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.trust_keys, menu); getMenuInflater().inflate(R.menu.trust_keys, menu);
MenuItem scanQrCode = menu.findItem(R.id.action_scan_qr_code); 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); 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(); showCameraToast();
} }

View File

@ -83,12 +83,11 @@ public abstract class XmppActivity extends AppCompatActivity {
public boolean xmppConnectionServiceBound = false; public boolean xmppConnectionServiceBound = false;
protected boolean registeredListeners = false; protected boolean registeredListeners = false;
protected int mPrimaryBackgroundColor;
protected int mSecondaryBackgroundColor;
protected int mColorRed; protected int mColorRed;
protected int mColorOrange; protected int mColorOrange;
protected int mColorGreen; protected int mColorGreen;
protected int mPrimaryColor;
private boolean isCameraFeatureAvailable = false;
protected boolean mUseSubject = true; protected boolean mUseSubject = true;
protected int mTheme; protected int mTheme;
@ -408,19 +407,13 @@ public abstract class XmppActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
metrics = getResources().getDisplayMetrics(); metrics = getResources().getDisplayMetrics();
ExceptionHelper.init(getApplicationContext()); ExceptionHelper.init(getApplicationContext());
this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
mColorRed = ContextCompat.getColor(this, R.color.red800); mColorRed = ContextCompat.getColor(this, R.color.red800);
mColorOrange = ContextCompat.getColor(this, R.color.orange500); mColorOrange = ContextCompat.getColor(this, R.color.orange500);
mColorGreen = ContextCompat.getColor(this, R.color.green500); 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(); this.mTheme = findTheme();
if (isDarkTheme()) {
mPrimaryBackgroundColor = ContextCompat.getColor(this, R.color.grey800);
mSecondaryBackgroundColor = ContextCompat.getColor(this, R.color.grey900);
}
setTheme(this.mTheme); setTheme(this.mTheme);
this.mUsingEnterKey = usingEnterKey(); this.mUsingEnterKey = usingEnterKey();
@ -431,6 +424,10 @@ public abstract class XmppActivity extends AppCompatActivity {
} }
} }
protected boolean isCameraFeatureAvailable() {
return this.isCameraFeatureAvailable;
}
public boolean isDarkTheme() { public boolean isDarkTheme() {
return this.mTheme == R.style.ConversationsTheme_Dark; return this.mTheme == R.style.ConversationsTheme_Dark;
} }