use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.
the class ConnectivityReportPlugin method subscriptionsListen.
@RequiresApi(api = Build.VERSION_CODES.N)
private void subscriptionsListen() {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
subListener = TelephonyHelper.listenActiveSubscriptionIDs(context, subID -> {
TelephonyManager subTm = tm.createForSubscriptionId(subID);
Log.i("ConnectivityReport", "Added subscription ID " + subID);
states.put(subID, new SubscriptionState(subID));
PhoneStateListener listener = createListener(subID);
listeners.put(subID, listener);
subTm.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}, subID -> {
Log.i("ConnectivityReport", "Removed subscription ID " + subID);
tm.listen(listeners.get(subID), PhoneStateListener.LISTEN_NONE);
listeners.remove(subID);
states.remove(subID);
});
}
use of androidx.annotation.RequiresApi in project banner by youth5201314.
the class BannerUtils method setBannerRound.
/**
* 设置view圆角
*
* @param radius
* @return
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void setBannerRound(View view, float radius) {
view.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
}
});
view.setClipToOutline(true);
}
use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.
the class SmsMmsUtils method sendMmsMessageNative.
/**
* Send an MMS message using SmsManager.sendMultimediaMessage
*
* @param context
* @param message
* @param klinkerSettings
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
protected static void sendMmsMessageNative(Context context, Message message, Settings klinkerSettings) {
ArrayList<MMSPart> data = new ArrayList<>();
for (Message.Part p : message.getParts()) {
MMSPart part = new MMSPart();
if (p.getName() != null) {
part.Name = p.getName();
} else {
part.Name = p.getContentType().split("/")[0];
}
part.MimeType = p.getContentType();
part.Data = p.getMedia();
data.add(part);
}
if (message.getText() != null && !message.getText().equals("")) {
// add text to the end of the part and send
MMSPart part = new MMSPart();
part.Name = "text";
part.MimeType = "text/plain";
part.Data = message.getText().getBytes();
data.add(part);
}
SendReq sendReq = buildPdu(context, message.getFromAddress(), message.getAddresses(), message.getSubject(), data, klinkerSettings);
Bundle configOverrides = new Bundle();
configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, klinkerSettings.getGroup());
// Write the PDUs to disk so that we can pass them to the SmsManager
final String fileName = "send." + Math.abs(new Random().nextLong()) + ".dat";
File mSendFile = new File(context.getCacheDir(), fileName);
Uri contentUri = (new Uri.Builder()).authority(context.getPackageName() + ".MmsFileProvider").path(fileName).scheme(ContentResolver.SCHEME_CONTENT).build();
try (FileOutputStream writer = new FileOutputStream(mSendFile)) {
writer.write(new PduComposer(context, sendReq).make());
} catch (final IOException e) {
android.util.Log.e(SENDING_MESSAGE, "Error while writing temporary PDU file: ", e);
}
SmsManager mSmsManager;
if (klinkerSettings.getSubscriptionId() < 0) {
mSmsManager = SmsManager.getDefault();
} else {
mSmsManager = SmsManager.getSmsManagerForSubscriptionId(klinkerSettings.getSubscriptionId());
}
mSmsManager.sendMultimediaMessage(context, contentUri, null, null, null);
}
use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.
the class RunCommandActivity method onContextItemSelected.
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
if (item.getItemId() == R.id.copy_url_to_clipboard) {
CommandEntry entry = (CommandEntry) commandItems.get(info.position);
String url = "kdeconnect://runcommand/" + deviceId + "/" + entry.getKey();
ClipboardManager cm = ContextCompat.getSystemService(this, ClipboardManager.class);
cm.setText(url);
Toast toast = Toast.makeText(this, R.string.clipboard_toast, Toast.LENGTH_SHORT);
toast.show();
return true;
}
return false;
}
use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.
the class SendKeystrokesToHostActivity method onStart.
// needed for this.getReferrer()
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
@Override
protected void onStart() {
super.onStart();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean(getString(R.string.pref_sendkeystrokes_enabled), true)) {
Toast.makeText(getApplicationContext(), R.string.sendkeystrokes_disabled_toast, Toast.LENGTH_LONG).show();
finish();
} else {
final Intent intent = getIntent();
String type = intent.getType();
if ("text/x-keystrokes".equals(type)) {
String toSend = intent.getStringExtra(Intent.EXTRA_TEXT);
binding.textToSend.setText(toSend);
// (contentIsOkay gets used in updateComputerList again)
if (prefs.getBoolean(getString(R.string.pref_send_safe_text_immediately), true)) {
SafeTextChecker safeTextChecker = new SafeTextChecker(SAFE_CHARS, MAX_SAFE_LENGTH);
contentIsOkay = safeTextChecker.isSafe(toSend);
} else {
contentIsOkay = false;
}
// If we trust the sending app, check if there is only one device paired / reachable...
if (contentIsOkay) {
List<Device> reachableDevices = BackgroundService.getInstance().getDevices().values().stream().filter(Device::isReachable).limit(// we only need the first two; if its more than one, we need to show the user the device-selection
2).collect(Collectors.toList());
// if its exactly one just send the text to it
if (reachableDevices.size() == 1) {
// send the text and close this activity
sendKeys(reachableDevices.get(0));
this.finish();
return;
}
}
// subscribe to new connected devices
BackgroundService.RunCommand(this, service -> {
service.onNetworkChange();
service.addDeviceListChangedCallback("SendKeystrokesToHostActivity", this::updateComputerList);
});
// list all currently connected devices
updateComputerList();
} else {
Toast.makeText(getApplicationContext(), R.string.sendkeystrokes_wrong_data, Toast.LENGTH_LONG).show();
finish();
}
}
}
Aggregations