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-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application
android:networkSecurityConfig="@xml/network_security_configuration"

View file

@ -182,7 +182,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
super.onCreateOptionsMenu(menu);
final Intent i = getIntent();
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;
}

View file

@ -427,7 +427,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
} else {
binding.showInactiveDevices.setVisibility(View.GONE);
}
binding.scanButton.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
binding.scanButton.setVisibility(hasKeys && isCameraFeatureAvailable() ? View.VISIBLE : View.GONE);
if (hasKeys) {
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);
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);
}

View file

@ -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);

View file

@ -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();
}

View file

@ -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;
}