List of usage examples for android.content ComponentName flattenToString
public @NonNull String flattenToString()
From source file:com.androidzeitgeist.dashwatch.dashclock.ExtensionManager.java
private ExtensionData deserializeExtensionData(ComponentName componentName) { ExtensionData extensionData = new ExtensionData(); String val = mValuesPreferences.getString(componentName.flattenToString(), ""); if (!TextUtils.isEmpty(val)) { try {/* w w w . java2s.c o m*/ extensionData.deserialize((JSONObject) new JSONTokener(val).nextValue()); } catch (JSONException e) { Log.e(TAG, "Error loading extension data cache for " + componentName + ".", e); } } return extensionData; }
From source file:com.google.android.apps.dashclock.ExtensionManager.java
private void serializeExtensionData(ComponentName componentName, ExtensionData extensionData) { try {/* www . ja va2s .c o m*/ mValuesPreferences.edit() .putString(componentName.flattenToString(), extensionData.serialize().toString()).apply(); } catch (JSONException e) { LOGE(TAG, "Error storing extension data cache for " + componentName + ".", e); } }
From source file:com.google.android.apps.dashclock.ExtensionManager.java
private ExtensionData deserializeExtensionData(ComponentName componentName) { ExtensionData extensionData = new ExtensionData(); String val = mValuesPreferences.getString(componentName.flattenToString(), ""); if (!TextUtils.isEmpty(val)) { try {//ww w . j a v a 2 s . co m extensionData.deserialize((JSONObject) new JSONTokener(val).nextValue()); } catch (JSONException e) { LOGE(TAG, "Error loading extension data cache for " + componentName + ".", e); } } return extensionData; }
From source file:com.google.android.apps.dashclock.ExtensionManager.java
/** * Replaces the set of active extensions with the given list. *//*from w w w. j a v a 2s . c om*/ public void setInternalActiveExtensions(List<ComponentName> extensions) { StringBuilder sb = new StringBuilder(); for (ComponentName extension : extensions) { if (sb.length() > 0) { sb.append(","); } sb.append(extension.flattenToString()); } mDefaultPreferences.edit().putString(PREF_ACTIVE_EXTENSIONS, sb.toString()).apply(); new BackupManager(mApplicationContext).dataChanged(); mInternalActiveExtensions.clear(); mInternalActiveExtensions.addAll(extensions); setActiveExtensions(getActiveExtensionNames()); }
From source file:com.google.android.apps.dashclock.DashClockService.java
private void internalRequestUpdateData(final IDataConsumerHostCallback cb, List<ComponentName> extensions) { // Recover the updatable extensions for this caller List<ComponentName> updatableExtensions = new ArrayList<>(); List<ComponentName> registeredExtensions = mRegisteredCallbacks.get(cb.asBinder()).mExtensions; if (extensions == null) { updatableExtensions.addAll(registeredExtensions); } else {/* w w w . ja v a 2 s. c o m*/ for (ComponentName extension : extensions) { if (registeredExtensions.contains(extension)) { updatableExtensions.add(extension); } } } // Request an update of all the extensions in the list final LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); for (ComponentName updatableExtension : updatableExtensions) { Intent intent = new Intent(ACTION_EXTENSION_UPDATE_REQUESTED); intent.putExtra(EXTRA_COMPONENT_NAME, updatableExtension.flattenToString()); intent.putExtra(EXTRA_UPDATE_REASON, DashClockExtension.UPDATE_REASON_MANUAL); lbm.sendBroadcast(intent); } }
From source file:com.android.settings.accessibility.AccessibilitySettings.java
private void updateServicePreferences() { // Since services category is auto generated we have to do a pass // to generate it since services can come and go and then based on // the global accessibility state to decided whether it is enabled. // Generate.//from w w w .j a v a 2 s . co m ArrayList<Preference> servicePreferences = new ArrayList<>( mServicePreferenceToPreferenceCategoryMap.keySet()); for (int i = 0; i < servicePreferences.size(); i++) { Preference service = servicePreferences.get(i); PreferenceCategory category = mServicePreferenceToPreferenceCategoryMap.get(service); category.removePreference(service); } initializePreBundledServicesMapFromArray(CATEGORY_SCREEN_READER, R.array.config_preinstalled_screen_reader_services); initializePreBundledServicesMapFromArray(CATEGORY_AUDIO_AND_CAPTIONS, R.array.config_preinstalled_audio_and_caption_services); initializePreBundledServicesMapFromArray(CATEGORY_DISPLAY, R.array.config_preinstalled_display_services); initializePreBundledServicesMapFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_preinstalled_interaction_control_services); AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity()); List<AccessibilityServiceInfo> installedServices = accessibilityManager .getInstalledAccessibilityServiceList(); Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(getActivity()); List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId()); final boolean accessibilityEnabled = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; PreferenceCategory downloadedServicesCategory = mCategoryToPrefCategoryMap .get(CATEGORY_DOWNLOADED_SERVICES); // Temporarily add the downloaded services category back if it was previously removed. if (findPreference(CATEGORY_DOWNLOADED_SERVICES) == null) { getPreferenceScreen().addPreference(downloadedServicesCategory); } for (int i = 0, count = installedServices.size(); i < count; ++i) { AccessibilityServiceInfo info = installedServices.get(i); RestrictedPreference preference = new RestrictedPreference(downloadedServicesCategory.getContext()); String title = info.getResolveInfo().loadLabel(getPackageManager()).toString(); Drawable icon; if (info.getResolveInfo().getIconResource() == 0) { icon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_accessibility_generic); } else { icon = info.getResolveInfo().loadIcon(getPackageManager()); } ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo; String packageName = serviceInfo.packageName; ComponentName componentName = new ComponentName(packageName, serviceInfo.name); String componentNameKey = componentName.flattenToString(); preference.setKey(componentName.flattenToString()); preference.setTitle(title); preference.setIcon(icon); final boolean serviceEnabled = accessibilityEnabled && enabledServices.contains(componentName); final String serviceState = serviceEnabled ? getString(R.string.accessibility_summary_state_enabled) : getString(R.string.accessibility_summary_state_disabled); final CharSequence serviceSummary = info.loadSummary(getPackageManager()); final String stateSummaryCombo = getString(R.string.accessibility_summary_default_combination, serviceState, serviceSummary); preference.setSummary((TextUtils.isEmpty(serviceSummary)) ? serviceState : stateSummaryCombo); // Disable all accessibility services that are not permitted. boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName); if (!serviceAllowed && !serviceEnabled) { EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(getActivity(), packageName, UserHandle.myUserId()); if (admin != null) { preference.setDisabledByAdmin(admin); } else { preference.setEnabled(false); } } else { preference.setEnabled(true); } preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName()); preference.setPersistent(true); Bundle extras = preference.getExtras(); extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey()); extras.putBoolean(EXTRA_CHECKED, serviceEnabled); extras.putString(EXTRA_TITLE, title); String description = info.loadDescription(getPackageManager()); if (TextUtils.isEmpty(description)) { description = getString(R.string.accessibility_service_default_description); } extras.putString(EXTRA_SUMMARY, description); String settingsClassName = info.getSettingsActivityName(); if (!TextUtils.isEmpty(settingsClassName)) { extras.putString(EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings)); extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, new ComponentName(packageName, settingsClassName).flattenToString()); } extras.putParcelable(EXTRA_COMPONENT_NAME, componentName); PreferenceCategory prefCategory = downloadedServicesCategory; // Set the appropriate category if the service comes pre-installed. if (mPreBundledServiceComponentToCategoryMap.containsKey(componentName)) { prefCategory = mPreBundledServiceComponentToCategoryMap.get(componentName); } preference.setOrder(FIRST_PREFERENCE_IN_CATEGORY_INDEX); prefCategory.addPreference(preference); mServicePreferenceToPreferenceCategoryMap.put(preference, prefCategory); } // If the user has not installed any additional services, hide the category. if (downloadedServicesCategory.getPreferenceCount() == 0) { PreferenceScreen screen = getPreferenceScreen(); screen.removePreference(downloadedServicesCategory); } }
From source file:org.envirocar.app.activity.MainActivity.java
private void bindToBackgroundService() { if (!bindService(new Intent(this, BackgroundServiceImpl.class), new ServiceConnection() { @Override/*from w w w .ja v a2 s.c o m*/ public void onServiceDisconnected(ComponentName name) { logger.info(String.format("BackgroundService %S disconnected!", name.flattenToString())); } @Override public void onServiceConnected(ComponentName name, IBinder service) { backgroundService = (BackgroundServiceInteractor) service; serviceState = backgroundService.getServiceState(); updateStartStopButton(); } }, 0)) { logger.warn("Could not connect to BackgroundService."); } }
From source file:org.envirocar.app.activity.MainActivity.java
private void bindToDeviceInRangeService() { if (!bindService(new Intent(this, DeviceInRangeService.class), new ServiceConnection() { @Override/* w ww. ja v a 2 s .c o m*/ public void onServiceDisconnected(ComponentName name) { logger.info(String.format("DeviceInRangeService %S disconnected!", name.flattenToString())); } @Override public void onServiceConnected(ComponentName name, IBinder service) { deviceInRangeService = (DeviceInRangeServiceInteractor) service; if (deviceInRangeService.isDiscoveryPending()) { serviceState = ServiceState.SERVICE_DEVICE_DISCOVERY_PENDING; } updateStartStopButton(); discoveryTargetTime = deviceInRangeService.getNextDiscoveryTargetTime(); invokeRemainingTimeThread(); } }, 0)) { logger.warn("Could not connect to DeviceInRangeService."); } }
From source file:de.schildbach.wallet.ui.SendCoinsFragmentBackup.java
private void handleGo() { state = State.PREPARATION;// ww w .j av a 2 s . co m updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress, finalAmount, null, paymentIntent.payeeData); directPay(payment); application.broadcastTransaction(sentTransaction); final ComponentName callingActivity = activity.getCallingActivity(); if (callingActivity != null) { log.info("returning result to calling activity: {}", callingActivity.flattenToString()); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); if (paymentIntent.standard == Standard.BIP70) BitcoinIntegration.paymentToResult(result, payment.toByteArray()); activity.setResult(Activity.RESULT_OK, result); } } private void directPay(final Payment payment) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(payment); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl, application.httpUserAgent()).send(paymentIntent.standard, payment); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment); } } } @Override protected void onInsufficientMoney(@Nullable final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder(); if (missing != null) msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))) .append("\n\n"); if (pending.signum() > 0) msg.append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n"); msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }
From source file:com.jculb.wallet.ui.SendCoinsFragment.java
private void handleGo() { state = State.PREPARATION;//ww w. ja v a 2s .c om updateView(); // final payment intent final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues( amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null); final BigInteger finalAmount = finalPaymentIntent.getAmount(); // prepare send request final SendRequest sendRequest = finalPaymentIntent.toSendRequest(); final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS); sendRequest.changeAddress = returnAddress; sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE)); //Emptying a wallet with less than 2 DOGE can't be possible due to min fee 2 DOGE of such a tx. /* if (amount.compareTo(BigInteger.valueOf(200000000)) < 0 && sendRequest.emptyWallet) { AlertDialog.Builder bld = new AlertDialog.Builder(activity); bld.setTitle(R.string.send_coins_error_msg); bld.setMessage(R.string.send_coins_error_desc); bld.setNeutralButton(activity.getResources().getString(android.R.string.ok), null); bld.setCancelable(false); bld.create().show(); state = State.FAILED; updateView(); return; }*/ new SendCoinsOfflineTask(wallet, backgroundHandler) { @Override protected void onSuccess(final Transaction transaction) { sentTransaction = transaction; state = State.SENDING; updateView(); sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener); final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress, finalAmount, null, paymentIntent.payeeData); directPay(payment); application.broadcastTransaction(sentTransaction); final ComponentName callingActivity = activity.getCallingActivity(); if (callingActivity != null) { log.info("returning result to calling activity: {}", callingActivity.flattenToString()); final Intent result = new Intent(); BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString()); if (paymentIntent.standard == Standard.BIP70) BitcoinIntegration.paymentToResult(result, payment.toByteArray()); activity.setResult(Activity.RESULT_OK, result); } } private void directPay(final Payment payment) { if (directPaymentEnableView.isChecked()) { final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() { @Override public void onResult(final boolean ack) { directPaymentAck = ack; if (state == State.SENDING) state = State.SENT; updateView(); } @Override public void onFail(final int messageResId, final Object... messageArgs) { final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title); dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg)); dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { directPay(payment); } }); dialog.setNegativeButton(R.string.button_dismiss, null); dialog.show(); } }; if (paymentIntent.isHttpPaymentUrl()) { new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl, application.httpUserAgent()).send(paymentIntent.standard, payment); } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment); } } } @Override protected void onInsufficientMoney(@Nullable final BigInteger missing) { state = State.INPUT; updateView(); final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); final int btcShift = config.getBtcShift(); final int btcPrecision = config.getBtcMaxPrecision(); final String btcPrefix = config.getBtcPrefix(); final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title); final StringBuilder msg = new StringBuilder(); if (missing != null) msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1), btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift))) .append("\n\n"); if (pending.signum() > 0) msg.append(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n"); msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2)); dialog.setMessage(msg); dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { handleEmpty(); } }); dialog.setNegativeButton(R.string.button_cancel, null); dialog.show(); } @Override protected void onFailure() { state = State.FAILED; updateView(); activity.longToast(R.string.send_coins_error_msg); } }.sendCoinsOffline(sendRequest); // send asynchronously }