Java Code Examples for android.widget.RemoteViews#setCharSequence()

The following examples show how to use android.widget.RemoteViews#setCharSequence() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTransformation.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** @hide */
@Override
@TestApi
public void apply(@NonNull ValueFinder finder, @NonNull RemoteViews parentTemplate,
        int childViewId) throws Exception {
    final AutofillValue value = finder.findRawValueByAutofillId(mFieldId);
    if (value == null) {
        Log.w(TAG, "No value for id " + mFieldId);
        return;
    }
    if (!value.isDate()) {
        Log.w(TAG, "Value for " + mFieldId + " is not date: " + value);
        return;
    }

    try {
        final Date date = new Date(value.getDateValue());
        final String transformed = mDateFormat.format(date);
        if (sDebug) Log.d(TAG, "Transformed " + date + " to " + transformed);

        parentTemplate.setCharSequence(childViewId, "setText", transformed);
    } catch (Exception e) {
        Log.w(TAG, "Could not apply " + mDateFormat + " to " + value + ": " + e);
    }
}
 
Example 2
Source File: CharSequenceTransformation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
@TestApi
public void apply(@NonNull ValueFinder finder, @NonNull RemoteViews parentTemplate,
        int childViewId) throws Exception {
    final StringBuilder converted = new StringBuilder();
    final int size = mFields.size();
    if (sDebug) Log.d(TAG, size + " multiple fields on id " + childViewId);
    for (Entry<AutofillId, Pair<Pattern, String>> entry : mFields.entrySet()) {
        final AutofillId id = entry.getKey();
        final Pair<Pattern, String> field = entry.getValue();
        final String value = finder.findByAutofillId(id);
        if (value == null) {
            Log.w(TAG, "No value for id " + id);
            return;
        }
        try {
            final Matcher matcher = field.first.matcher(value);
            if (!matcher.find()) {
                if (sDebug) Log.d(TAG, "match for " + field.first + " failed on id " + id);
                return;
            }
            // replaceAll throws an exception if the subst is invalid
            final String convertedValue = matcher.replaceAll(field.second);
            converted.append(convertedValue);
        } catch (Exception e) {
            // Do not log full exception to avoid PII leaking
            Log.w(TAG, "Cannot apply " + field.first.pattern() + "->" + field.second + " to "
                    + "field with autofill id" + id + ": " + e.getClass());
            throw e;
        }
    }
    parentTemplate.setCharSequence(childViewId, "setText", converted);
}
 
Example 3
Source File: PersistentService.java    From NetCloud_android with GNU General Public License v2.0 5 votes vote down vote up
private void updateNotification(){
    int notificationID = NetWatcherApp.NOTIFICATION_ID;
    Notification notification = NetWatcherApp.getNotification();
    RemoteViews content = notification.contentView;
    if(content != null){
        content.setCharSequence(R.id.netcloud_notify_desc, "setText", ResTools.getString(NetCoreIface.isServerRunning()? R.string.vpn_running:R.string.vpn_not_running));
        content.setCharSequence(R.id.netcloud_notify_button, "setText", ResTools.getString(NetCoreIface.isServerRunning()? R.string.stop:R.string.start));
    }

    startForeground(notificationID, notification);
}