예제 #1
0
  private void initServiceDiscovery() {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(extXMPPConnection);
    try {
      if (capsCacheDir == null) {
        capsCacheDir = new File(service.getCacheDir(), "entity-caps-cache");
        capsCacheDir.mkdirs();
        EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(capsCacheDir));
      }
    } catch (java.io.IOException e) {
      Log.e(TAG, "Could not init : " + e.getLocalizedMessage());
    }

    PingManager.getInstanceFor(extXMPPConnection).setPingMinimumInterval(10 * 1000);
    String app_name = service.getString(R.string.app_name);
    String build_revision = service.getString(R.string.build_revision);
    Version.Manager.getInstanceFor(extXMPPConnection)
        .setVersion(new Version(app_name, build_revision, Constant.ANDROID));

    DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(extXMPPConnection);
    dm.enableAutoReceipts();
    dm.addReceiptReceivedListener(
        new ReceiptReceivedListener() { // DOES NOT WORK IN CARBONS
          public void onReceiptReceived(String fromJid, String toJid, String receiptId) {

            changeMessageDeliveryStatus(receiptId, ChatConstants.DS_ACKED);
          }
        });
  }
예제 #2
0
  private void initServiceDiscovery() {
    // register connection features
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mXMPPConnection);

    // init Entity Caps manager with storage in app's cache dir
    try {
      if (capsCacheDir == null) {
        capsCacheDir = new File(mService.getCacheDir(), "entity-caps-cache");
        capsCacheDir.mkdirs();
        EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(capsCacheDir));
      }
    } catch (java.io.IOException e) {
      Log.e(TAG, "Could not init Entity Caps cache: " + e.getLocalizedMessage());
    }

    // reference PingManager, set ping flood protection to 10s
    PingManager.getInstanceFor(mXMPPConnection).setPingMinimumInterval(10 * 1000);

    // set Version for replies
    String app_name = mService.getString(org.yaxim.androidclient.R.string.app_name);
    String build_revision = mService.getString(org.yaxim.androidclient.R.string.build_revision);
    Version.Manager.getInstanceFor(mXMPPConnection)
        .setVersion(new Version(app_name, build_revision, "Android"));

    // reference DeliveryReceiptManager, add listener
    DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(mXMPPConnection);
    dm.enableAutoReceipts();
    dm.addReceiptReceivedListener(
        new ReceiptReceivedListener() { // DOES NOT WORK IN CARBONS
          public void onReceiptReceived(String fromJid, String toJid, String receiptId) {
            Log.d(TAG, "got delivery receipt for " + receiptId);
            changeMessageDeliveryStatus(receiptId, ChatConstants.DS_ACKED);
          }
        });
  }
	private int getMaxLength() {
		String maxLength = mSharedPref.getString(mService.getString(R.string.pref_maxlength), "");
		if (!TextUtils.isEmpty(maxLength)){
			return Integer.valueOf(maxLength);
		}
		return 0;
	}
	public String getPreference(String key, boolean full) {
		String message = mSharedPref.getString(key, "");
		int maxlength = getMaxLength();
		message = message.replace("%f", toString());
		message = message.replace("%a", mPackageLabel);
		message = message.replace("%d", mDescription);
		message = message.replace("%m", mText);
		
		if (!full && key.equals(mService.getString(R.string.pref_metadata_title))) {
			if (maxlength != 0 && message.length() > maxlength) {
				int start = mOffset * maxlength;
				int end = start + maxlength;
				if (end >= message.length()) {
					end = message.length() -1;
					mOffset = -1;
				}
				String result = message.substring(start, end);
				mOffset++;
				return result;
			}
		}
		return message;
	}
 private String _(int id){
     return mService.getString(id);
 }