use of androidx.annotation.StringRes in project kdeconnect-android by KDE.
the class DeviceFragment method displayBatteryInfoIfPossible.
/**
* This method tries to display battery info for the remote device. Includes
* <ul>
* <li>Current charge as a percentage</li>
* <li>Whether the remote device is low on power</li>
* <li>Whether the remote device is currently charging</li>
* </ul>
* <p>
* This will show a simple message on the view instead if we don't have
* accurate info right now.
* </p>
*/
private void displayBatteryInfoIfPossible() {
boolean canDisplayBatteryInfo = false;
BatteryPlugin batteryPlugin = (BatteryPlugin) device.getLoadedPlugins().get(Plugin.getPluginKey(BatteryPlugin.class));
if (batteryPlugin != null) {
DeviceBatteryInfo info = batteryPlugin.getRemoteBatteryInfo();
if (info != null) {
canDisplayBatteryInfo = true;
Context ctx = deviceBinding.viewBatteryStatus.getContext();
boolean isCharging = info.isCharging();
@StringRes int resId;
if (isCharging) {
resId = R.string.battery_status_charging_format;
} else if (BatteryPlugin.isLowBattery(info)) {
resId = R.string.battery_status_low_format;
} else {
resId = R.string.battery_status_format;
}
deviceBinding.viewBatteryStatus.setChecked(isCharging);
deviceBinding.viewBatteryStatus.setText(ctx.getString(resId, info.getCurrentCharge()));
}
}
if (!canDisplayBatteryInfo) {
deviceBinding.viewBatteryStatus.setText(R.string.battery_status_unknown);
}
}
use of androidx.annotation.StringRes in project Conversations by siacs.
the class StartConversationActivity method askForContactsPermissions.
private void askForContactsPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
if (mRequestedContactsPermission.compareAndSet(false, true)) {
if (QuickConversationsService.isQuicksy() || shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final AtomicBoolean requestPermission = new AtomicBoolean(false);
builder.setTitle(R.string.sync_with_contacts);
if (QuickConversationsService.isQuicksy()) {
builder.setMessage(Html.fromHtml(getString(R.string.sync_with_contacts_quicksy)));
} else {
builder.setMessage(getString(R.string.sync_with_contacts_long, getString(R.string.app_name)));
}
@StringRes int confirmButtonText;
if (QuickConversationsService.isConversations()) {
confirmButtonText = R.string.next;
} else {
confirmButtonText = R.string.confirm;
}
builder.setPositiveButton(confirmButtonText, (dialog, which) -> {
if (requestPermission.compareAndSet(false, true)) {
requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, REQUEST_SYNC_CONTACTS);
}
});
builder.setOnDismissListener(dialog -> {
if (QuickConversationsService.isConversations() && requestPermission.compareAndSet(false, true)) {
requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, REQUEST_SYNC_CONTACTS);
}
});
builder.setCancelable(QuickConversationsService.isQuicksy());
final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(QuickConversationsService.isQuicksy());
dialog.setOnShowListener(dialogInterface -> {
final TextView tv = dialog.findViewById(android.R.id.message);
if (tv != null) {
tv.setMovementMethod(LinkMovementMethod.getInstance());
}
});
dialog.show();
} else {
requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, REQUEST_SYNC_CONTACTS);
}
}
}
}
}
use of androidx.annotation.StringRes in project Conversations by siacs.
the class RtpSessionActivity method onRequestPermissionsResult.
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (PermissionUtils.allGranted(grantResults)) {
if (requestCode == REQUEST_ACCEPT_CALL) {
checkRecorderAndAcceptCall();
}
} else {
@StringRes int res;
final String firstDenied = getFirstDenied(grantResults, permissions);
if (Manifest.permission.RECORD_AUDIO.equals(firstDenied)) {
res = R.string.no_microphone_permission;
} else if (Manifest.permission.CAMERA.equals(firstDenied)) {
res = R.string.no_camera_permission;
} else {
throw new IllegalStateException("Invalid permission result request");
}
Toast.makeText(this, getString(res, getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
}
}
use of androidx.annotation.StringRes in project Conversations by siacs.
the class ConversationFragment method onRequestPermissionsResult.
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grantResults.length > 0) {
if (allGranted(grantResults)) {
switch(requestCode) {
case REQUEST_START_DOWNLOAD:
if (this.mPendingDownloadableMessage != null) {
startDownloadable(this.mPendingDownloadableMessage);
}
break;
case REQUEST_ADD_EDITOR_CONTENT:
if (this.mPendingEditorContent != null) {
attachEditorContentToConversation(this.mPendingEditorContent);
}
break;
case REQUEST_COMMIT_ATTACHMENTS:
commitAttachments();
break;
case REQUEST_START_AUDIO_CALL:
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
break;
case REQUEST_START_VIDEO_CALL:
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
break;
default:
attachFile(requestCode);
break;
}
} else {
@StringRes int res;
String firstDenied = getFirstDenied(grantResults, permissions);
if (Manifest.permission.RECORD_AUDIO.equals(firstDenied)) {
res = R.string.no_microphone_permission;
} else if (Manifest.permission.CAMERA.equals(firstDenied)) {
res = R.string.no_camera_permission;
} else {
res = R.string.no_storage_permission;
}
Toast.makeText(getActivity(), getString(res, getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
}
}
if (writeGranted(grantResults, permissions)) {
if (activity != null && activity.xmppConnectionService != null) {
activity.xmppConnectionService.getBitmapCache().evictAll();
activity.xmppConnectionService.restartFileObserver();
}
refresh();
}
}
use of androidx.annotation.StringRes in project Conversations by siacs.
the class BlockContactDialog method show.
public static void show(final XmppActivity xmppActivity, final Blockable blockable) {
final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
final boolean isBlocked = blockable.isBlocked();
builder.setNegativeButton(R.string.cancel, null);
DialogBlockContactBinding binding = DataBindingUtil.inflate(xmppActivity.getLayoutInflater(), R.layout.dialog_block_contact, null, false);
final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
builder.setView(binding.getRoot());
final String value;
@StringRes int res;
if (blockable.getJid().isFullJid()) {
builder.setTitle(isBlocked ? R.string.action_unblock_participant : R.string.action_block_participant);
value = blockable.getJid().toEscapedString();
res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
} else if (blockable.getJid().getLocal() == null || blockable.getAccount().isBlocked(blockable.getJid().getDomain())) {
builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
value = blockable.getJid().getDomain().toEscapedString();
res = isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text;
} else {
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
value = blockable.getJid().asBareJid().toEscapedString();
res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
}
binding.text.setText(JidDialog.style(xmppActivity, res, value));
builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, (dialog, which) -> {
if (isBlocked) {
xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
} else {
boolean toastShown = false;
if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, binding.reportSpam.isChecked())) {
Toast.makeText(xmppActivity, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
toastShown = true;
}
if (xmppActivity instanceof ContactDetailsActivity) {
if (!toastShown) {
Toast.makeText(xmppActivity, R.string.contact_blocked_past_tense, Toast.LENGTH_SHORT).show();
}
xmppActivity.finish();
}
}
});
builder.create().show();
}
Aggregations