当前位置: 首页>>代码示例>>Java>>正文


Java TextUtil类代码示例

本文整理汇总了Java中com.matejdro.pebblecommons.util.TextUtil的典型用法代码示例。如果您正苦于以下问题:Java TextUtil类的具体用法?Java TextUtil怎么用?Java TextUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextUtil类属于com.matejdro.pebblecommons.util包,在下文中一共展示了TextUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeLegacyPebbleString

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public static void writeLegacyPebbleString(DataOutputStream stream, String string)
{
	string = TextUtil.trimString(string, 255, true);
	byte[] stringData = string.getBytes();

	try
	{
		stream.writeByte(stringData.length & 0xFF);
		stream.write(stringData);

	} catch (IOException e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:matejdro,项目名称:PebbleAndroidCommons,代码行数:16,代码来源:PebbleDeveloperConnection.java

示例2: writeNullTerminatedPebbleStringList

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public static void writeNullTerminatedPebbleStringList(DataOutputStream stream, List<String> list, int limit) throws IOException
{
	for (String line : list)
	{
		if (limit == 0)
			break;

		line = TextUtil.trimString(line, limit - 1, true);
		byte[] bytes = line.getBytes();
		stream.write(bytes);
		stream.write(0);

		limit -= bytes.length + 1;
	}
}
 
开发者ID:matejdro,项目名称:PebbleAndroidCommons,代码行数:16,代码来源:PebbleDeveloperConnection.java

示例3: writeUTFPebbleString

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public static void writeUTFPebbleString(DataOutputStream stream, String string, int limit) throws IOException
{
	string = TextUtil.prepareString(string, limit);
	byte[] stringData = string.getBytes();

	writeUnsignedShortLittleEndian(stream, stringData.length);
	stream.write(stringData);
}
 
开发者ID:matejdro,项目名称:PebbleAndroidCommons,代码行数:9,代码来源:PebbleDeveloperConnection.java

示例4: sendNextListItems

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
private void sendNextListItems()
{
    Timber.d("Sending action list items");
    PebbleDictionary data = new PebbleDictionary();

    byte[] bytes = new byte[3];

    data.addUint8(0, (byte) 5);
    data.addUint8(1, (byte) 0);

    int segmentSize = Math.min(listSize - nextListItemToSend, 4);

    bytes[0] = (byte) nextListItemToSend;
    bytes[1] = (byte) listSize;
    bytes[2] = (byte) (tertiaryTextMode ? 1 : 0);

    byte[] textData = new byte[segmentSize * 19];

    for (int i = 0; i < segmentSize; i++)
    {
        String text = TextUtil.prepareString(actionList.get(i + nextListItemToSend), 18);
        System.arraycopy(text.getBytes(), 0, textData, i * 19, text.getBytes().length);

        textData[19 * (i + 1) -1 ] = 0;
    }

    data.addBytes(2, bytes);
    data.addBytes(3, textData);

    getService().getPebbleCommunication().sendToPebble(data);

    nextListItemToSend += 4;
    if (nextListItemToSend >= listSize)
        nextListItemToSend = -1;
}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:36,代码来源:SMSReplyModule.java

示例5: sendCallerName

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
private void sendCallerName()
{
    PebbleDictionary data = new PebbleDictionary();

    data.addUint8(0, (byte) 1);
    data.addUint8(1, (byte) 1);

    String name = TextUtil.prepareString(this.name, 100);
    data.addString(2, name == null ? number : name);

    getService().getPebbleCommunication().sendToPebble(data);
    Timber.d("Sent Caller name packet...");

    callerNameUpdateRequired = false;
}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:16,代码来源:CallModule.java

示例6: sendEntriesPacket

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public void sendEntriesPacket(int offset)
{
       if (entries.size() <= offset)
           return;

       CallLogEntry callLogEntry = entries.get(offset);

	PebbleDictionary data = new PebbleDictionary();

	data.addUint8(0, (byte) 2);
       data.addUint8(1, (byte) 0);
       data.addUint16(2, (short) offset);
	data.addUint16(3, (short) entries.size());

	data.addUint8(4, (byte) callLogEntry.eventType);
	data.addString(6, callLogEntry.date);

	if (callLogEntry.name == null)
           callLogEntry.name = TextUtil.prepareString(callLogEntry.number);

	data.addString(5, callLogEntry.name);

	if (callLogEntry.numberType == null)
           callLogEntry.numberType = "";
	data.addString(7, callLogEntry.numberType);

       if (openWindow)
           data.addUint8(999, (byte) 1);

       getService().getPebbleCommunication().sendToPebble(data);
}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:32,代码来源:CallLogModule.java

示例7: getFormattedDate

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public String getFormattedDate(long date)
{
    DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getService());
    DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(getService());
    Date dateO = new Date(date);

    String dateS = dateFormat.format(dateO) + " " + timeFormat.format(dateO);

    return TextUtil.prepareString(dateS);
}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:11,代码来源:CallLogModule.java

示例8: sendNumbers

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public void sendNumbers(int offset)
{
    PebbleDictionary data = new PebbleDictionary();


    data.addUint8(0, (byte) 4);
    data.addUint8(1, (byte) 0);

    data.addUint16(2, (short) offset);
    data.addUint16(3, (short) phoneNumbers.size());


    byte[] numberActions = new byte[2];
    for (int i = 0; i < 2; i++)
    {
        int listPos = offset + i;
        if (listPos >= phoneNumbers.size())
            break;

        PebbleNumberEntry numberEntry = phoneNumbers.get(listPos);

        data.addString(i + 4, TextUtil.prepareString(numberEntry.numberType));
        data.addString(i + 6, TextUtil.prepareString(numberEntry.number));
        numberActions[i] = (byte) numberEntry.numberAction;
    }

    data.addBytes(8, numberActions);

    if (openWindow)
        data.addUint8(999, (byte) 1);

    Timber.d("sendNumbers %d", offset);
    getService().getPebbleCommunication().sendToPebble(data);
}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:35,代码来源:NumberPickerModule.java

示例9: getFormattedDate

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public static String getFormattedDate(Context context, long date)
{
    DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
    DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
    Date dateO = new Date(date);

    String dateS = dateFormat.format(dateO) + " " + timeFormat.format(dateO);

    return TextUtil.trimString(dateS);
}
 
开发者ID:matejdro,项目名称:PebbleNotificationCenter-Android,代码行数:11,代码来源:ListModule.java

示例10: sendNextListItems

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
private void sendNextListItems()
{
    Timber.d("Sending action list items");
    PebbleDictionary data = new PebbleDictionary();

    byte[] bytes = new byte[3];

    data.addUint8(0, (byte) 4);
    data.addUint8(1, (byte) 0);

    int segmentSize = Math.min(listSize - nextListItemToSend, 4);

    bytes[0] = (byte) nextListItemToSend;
    bytes[1] = (byte) listSize;
    bytes[2] = (byte) (list.isTertiaryTextList() ? 1 : 0);

    byte[] textData = new byte[segmentSize * 19];

    for (int i = 0; i < segmentSize; i++)
    {
        String text = TextUtil.prepareString(list.getItem(i + nextListItemToSend), 18);
        System.arraycopy(text.getBytes(), 0, textData, i * 19, text.getBytes().length);

        textData[19 * (i + 1) -1 ] = 0;
    }

    data.addBytes(2, bytes);
    data.addBytes(3, textData);

    getService().getPebbleCommunication().sendToPebble(data);

    nextListItemToSend += 4;
    if (nextListItemToSend >= listSize)
        nextListItemToSend = -1;
}
 
开发者ID:matejdro,项目名称:PebbleNotificationCenter-Android,代码行数:36,代码来源:ActionsModule.java

示例11: sendUpdatePacket

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
private void sendUpdatePacket()
{
    PebbleDictionary data = new PebbleDictionary();

    data.addUint8(0, (byte) 1);
    data.addUint8(1, (byte) 0);

    boolean nameAtBottomWhenImageDisplayed = callerImage != null && getService().getGlobalSettings().getBoolean("bottomCallerName", true);

    if (name != null && type != null)
    {
        data.addString(2, TextUtil.prepareString(type, 30));
        data.addString(3, TextUtil.prepareString(number, 30));
    }
    else
    {
        data.addString(2, "");
        data.addString(3, "");
    }

    List<Byte> vibrationPattern;
    if (vibrating)
    {
        String vibrationPatternString = getService().getGlobalSettings().getString("vibrationPattern", "100, 100, 100, 1000");
        vibrationPattern = PebbleVibrationPattern.parseVibrationPattern(vibrationPatternString);
    }
    else
    {
        vibrationPattern = PebbleVibrationPattern.EMPTY_VIBRATION_PATTERN;
    }


    byte[] parameters = new byte[8 + vibrationPattern.size()];
    parameters[0] = (byte) (callState == CallState.ESTABLISHED ? 1 : 0);
    parameters[1] = (byte) (nameAtBottomWhenImageDisplayed ? 1 : 0);
    parameters[6] = (byte) (identityUpdateRequired ? 1 : 0);

    parameters[2] = (byte) getCallAction(getUserSelectedAction(getExtendedButtonId("Up"))).getIcon();
    parameters[3] = (byte) getCallAction(getUserSelectedAction(getExtendedButtonId("Select"))).getIcon();
    parameters[4] = (byte) getCallAction(getUserSelectedAction(getExtendedButtonId("Down"))).getIcon();

    parameters[7] = (byte) vibrationPattern.size();
    for (int i = 0; i < vibrationPattern.size(); i++)
        parameters[8 + i] = vibrationPattern.get(i);

    data.addBytes(4, parameters);

    if (callState == CallState.ESTABLISHED)
        data.addUint16(5, (short) Math.min(65000, (System.currentTimeMillis() - callStartTime) / 1000));

    data.addUint8(999, (byte) 1);

    callerImageNextByte = -1;
    if (identityUpdateRequired && getService().getPebbleCommunication().getConnectedWatchCapabilities().hasColorScreen())
    {
        int imageSize = 0;

        if (callerImage != null)
        {
            processContactImage();
            imageSize = callerImageBytes.length;
        }

        data.addUint16(7, (short) imageSize);

        if (imageSize != 0)
            callerImageNextByte = 0;

        Timber.d("Image size: %d", imageSize);
    }

    getService().getPebbleCommunication().sendToPebble(data);
    Timber.d("Sent Call update packet. New identity: %b", identityUpdateRequired);

    callerNameUpdateRequired = identityUpdateRequired;
    updateRequired = false;
    identityUpdateRequired = false;
}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:79,代码来源:CallModule.java

示例12: refreshCallLog

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
private void refreshCallLog()
{
    entries.clear();

    if (ContextCompat.checkSelfPermission(getService(), Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED)
        return;

    ContentResolver resolver = getService().getContentResolver();
    String sortOrder = CallLog.Calls.DEFAULT_SORT_ORDER + " LIMIT 100";
    Cursor cursor = resolver.query(CallLog.Calls.CONTENT_URI, null, null, null, sortOrder);

    if (cursor != null)
    {
        while (cursor.moveToNext())
        {
            String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
            String name = TextUtil.prepareString(cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)), 16);
            int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
            long date = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
            int numberType = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.CACHED_NUMBER_TYPE));
            String customLabel = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NUMBER_LABEL));

            if (number == null)
                continue;

            String numberTypeText = TextUtil.prepareString(ContactUtils.convertNumberType(numberType, customLabel));

            CallLogEntry callLogEntry = new CallLogEntry(name, number, numberTypeText, getFormattedDate(date), type);
            if (!entries.contains(callLogEntry))
            {
                if (name == null)
                    lookupContactInfo(callLogEntry);

                entries.add(callLogEntry);
            }
        }

        cursor.close();
    }

}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:42,代码来源:CallLogModule.java

示例13: refreshContacts

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
private void refreshContacts()
{
       if (ContextCompat.checkSelfPermission(getService(), Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED)
           return;

	ContentResolver resolver = getService().getContentResolver();

	String selection = "( " + buildSelection() + " )";
	String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " ASC";

	Uri uri;
	String idIndex;
	if (group >= 0)
	{
		uri = ContactsContract.Data.CONTENT_URI;
		selection += " AND " + ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = " + group;
		idIndex = "contact_id";
	}
	else
	{
		selection += " AND " + ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1";
		uri = ContactsContract.Contacts.CONTENT_URI;
		sortOrder += " LIMIT " + (filterMode ? "7" : "2000");
		idIndex = ContactsContract.Contacts._ID;
	}


	Cursor cursor = resolver.query(uri, null, selection, null, sortOrder);

	names.clear();
	ids.clear();
	idSet.clear();

       if (cursor != null)
       {
           while (cursor.moveToNext())
           {
               String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
               int id = cursor.getInt(cursor.getColumnIndex(idIndex));

               if (idSet.contains(id))
                   continue;

               if (name == null)
                   continue;

               names.add(TextUtil.prepareString(name));

               ids.add(id);
               idSet.add(id);

               if (ids.size() > (filterMode ? 7 : 2000))
                   break;
           }

           cursor.close();
       }

       Timber.d("Loaded " + names.size() + " contacts.");

}
 
开发者ID:matejdro,项目名称:PebbleDialer-Android,代码行数:62,代码来源:ContactsModule.java

示例14: parseWearActions

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public static void parseWearActions(Context context, Notification notification, PebbleNotification pebbleNotification, List<NotificationAction> storage)
{
    try
    {
        if (storage.size() >= NotificationAction.MAX_NUMBER_OF_ACTIONS)
            return;

        Bundle extras = NotificationTextParser.getExtras(notification);

        if (extras.containsKey("android.wearable.EXTENSIONS"))
        {
            Bundle wearExtras = extras.getBundle("android.wearable.EXTENSIONS");

            if (wearExtras.containsKey("actions"))
            {
                ArrayList<?> actionList = (ArrayList<?>) wearExtras.get("actions");
                for (Object obj : actionList)
                {
                    if (storage.size() >= NotificationAction.MAX_NUMBER_OF_ACTIONS)
                        break;

                    NotificationAction action = null;

                    if (obj instanceof  Bundle)
                        action = WearVoiceAction.parseFromBundle((Bundle) obj);
                    else if (obj instanceof Notification.Action)
                        action = WearVoiceAction.parseFromAction((Notification.Action) obj);

                    if (action != null)
                        storage.add(action);
                }
            }

            if (storage.size() >= NotificationAction.MAX_NUMBER_OF_ACTIONS)
                return;

            if (wearExtras.containsKey("pages"))
            {
                Parcelable[] pages = wearExtras.getParcelableArray("pages");
                int counter = 1;
                for (Parcelable page : pages)
                {
                    if (storage.size() >= NotificationAction.MAX_NUMBER_OF_ACTIONS)
                        return;

                    PebbleNotification pageNotification = NotificationHandler.getPebbleNotificationFromAndroidNotification(context, new NotificationKey(pebbleNotification.getKey().getPackage(), null, null), (Notification) page, false);
                    if (pageNotification == null)
                        continue;

                    pageNotification.setForceSwitch(true);
                    pageNotification.setText(TextUtil.trimStringFromBack(pageNotification.getText(), NotificationSendingModule.getMaximumTextLength(pebbleNotification.getSettingStorage(context))));

                    storage.add(new NotifyAction(context.getString(R.string.wearPageAction, counter), pageNotification));

                    counter++;
                }
            }
        }
    }
    catch (ParcelFormatException e) //Some phones (or apps?) seems to throw this when unparceling data.
    {
        Timber.w("Got ParcelFormatException at parseWearActions!");
    }
}
 
开发者ID:matejdro,项目名称:PebbleNotificationCenter-Android,代码行数:65,代码来源:ActionParser.java

示例15: sendListItem

import com.matejdro.pebblecommons.util.TextUtil; //导入依赖的package包/类
public void sendListItem(int index)
{
    PebbleDictionary data = new PebbleDictionary();

    if (index >= listAdapter.getNumOfNotifications())
    {
        data.addUint8(0, (byte) 2);
        data.addUint8(1, (byte) 0);
        data.addUint16(2, (short) 0);
        data.addUint16(3, (short) 1);
        data.addUint8(4, (byte) 1);
        data.addString(5, "No notifications");
        data.addString(6, "");
        data.addString(7, "");
        data.addUint16(8, (short) 0);

        if (openListWindow)
            data.addUint8(999, (byte) 1);

        getService().getPebbleCommunication().sendToPebble(data);

        return;
    }

    PebbleNotification notification = listAdapter.getNotificationAt(index);

    data.addUint8(0, (byte) 2);
    data.addUint8(1, (byte) 0);
    data.addUint16(2, (short) index);
    data.addUint16(3, (short) listAdapter.getNumOfNotifications());
    data.addUint8(4, (byte) (notification.isDismissable() ? 0 : 1));
    data.addString(5, TextUtil.prepareString(notification.getTitle()));
    data.addString(6, TextUtil.prepareString(notification.getSubtitle()));
    data.addString(7, getFormattedDate(getService(), notification.getRawPostTime()));
    data.addUint16(8, (short) 0); // Placeholder

    if (openListWindow)
        data.addUint8(999, (byte) 1);

    Bitmap icon = notification.getNotificationIcon();
    if (icon != null)
    {
        PebbleCapabilities connectedWatchCapabilities = getService().getPebbleCommunication().getConnectedWatchCapabilities();
        int iconColor = Color.BLACK;
        int notificationColor = notification.getColor();

        if (connectedWatchCapabilities.hasColorScreen() && notificationColor != Color.TRANSPARENT)
        {
            iconColor = notificationColor;
            //Make sure icon contrasts with white list background
            if (PebbleImageToolkit.getLuminance(iconColor) > 255 * 3 / 2)
                iconColor = PebbleImageToolkit.multiplyBrightness(iconColor, 0.5f);
        }
        byte[] iconData = ImageSendingModule.prepareTintedIcon(icon, getService(), connectedWatchCapabilities, iconColor, false);

        // This feature requires lots of memory on the watch to contain lots of icons for every list item
        // To weed out low memory devices, a device must be able to afford to receive at least 2048 bytes of the appmessage.
        int minAppmessageBufferSize = Math.max(2048, iconData.length);

        if (PebbleUtil.getBytesLeft(data, connectedWatchCapabilities) >= minAppmessageBufferSize)
        {
            data.addUint16(8, (short) iconData.length); // Placeholder
            data.addBytes(9, iconData);
        }
    }

    Timber.i("Sending list entry %d %s", index, data.getString(5));

    getService().getPebbleCommunication().sendToPebble(data);
}
 
开发者ID:matejdro,项目名称:PebbleNotificationCenter-Android,代码行数:71,代码来源:ListModule.java


注:本文中的com.matejdro.pebblecommons.util.TextUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。