@Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    inLayout = true;
    final int width = r - l;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
      final View child = getChildAt(i);

      if (child.getVisibility() == GONE) {
        continue;
      }

      final LayoutParams lp = (LayoutParams) child.getLayoutParams();

      try {
        if (drawerLayout != child) {
          child.layout(
              lp.leftMargin,
              lp.topMargin,
              lp.leftMargin + child.getMeasuredWidth(),
              lp.topMargin + child.getMeasuredHeight());
        } else {
          child.layout(
              -child.getMeasuredWidth() + (int) drawerPosition,
              lp.topMargin,
              (int) drawerPosition,
              lp.topMargin + child.getMeasuredHeight());
        }
      } catch (Exception e) {
        FileLog.e("tmessages", e);
      }
    }
    inLayout = false;
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
      Bundle bundle = intent.getExtras();
      SmsMessage[] msgs;
      if (bundle != null) {
        try {
          Object[] pdus = (Object[]) bundle.get("pdus");
          msgs = new SmsMessage[pdus.length];
          String wholeString = "";
          for (int i = 0; i < msgs.length; i++) {
            msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            wholeString += msgs[i].getMessageBody();
          }

          try {
            Pattern pattern = Pattern.compile("[0-9]+");
            Matcher matcher = pattern.matcher(wholeString);
            if (matcher.find()) {
              String str = matcher.group(0);
              if (str.length() >= 3) {
                NotificationCenter.Instance.postNotificationName(998, matcher.group(0));
              }
            }
          } catch (Exception e) {
            FileLog.e("tmessages", e);
          }

        } catch (Exception e) {
          FileLog.e("tmessages", e);
        }
      }
    }
  }
 public TLObject TLdeserialize(AbsSerializedData stream, int constructor, TLObject request) {
   Class objClass = classStore.get(constructor);
   if (objClass != null) {
     try {
       TLObject response = (TLObject) objClass.newInstance();
       if (response instanceof TLRPC.Vector) {
         if (request != null) {
           request.parseVector((TLRPC.Vector) response, stream);
         } else {
           int size = stream.readInt32();
           for (int a = 0; a < size; a++) {
             ((TLRPC.Vector) response).objects.add(stream.readInt32());
           }
         }
       } else {
         response.readParams(stream);
       }
       return response;
     } catch (IllegalAccessException e) {
       FileLog.e("tmessages", "can't create class");
       return null;
     } catch (InstantiationException e2) {
       FileLog.e("tmessages", "can't create class");
       return null;
     }
   } else {
     FileLog.e("tmessages", String.format("unknown class %x", constructor));
     if (BuildVars.DEBUG_VERSION) {
       throw new RuntimeException(String.format("unknown class %x", constructor));
     } else {
       return null;
     }
   }
 }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (currentMessageObject == null) {
      setMeasuredDimension(
          MeasureSpec.getSize(widthMeasureSpec), textHeight + AndroidUtilities.dp(14));
      return;
    }
    int width = Math.max(AndroidUtilities.dp(30), MeasureSpec.getSize(widthMeasureSpec));
    if (width != previousWidth) {
      previousWidth = width;

      textLayout =
          new StaticLayout(
              currentMessageObject.messageText,
              textPaint,
              width - AndroidUtilities.dp(30),
              Layout.Alignment.ALIGN_CENTER,
              1.0f,
              0.0f,
              false);
      textHeight = 0;
      textWidth = 0;
      try {
        int linesCount = textLayout.getLineCount();
        for (int a = 0; a < linesCount; a++) {
          float lineWidth;
          try {
            lineWidth = textLayout.getLineWidth(a);
            textHeight = (int) Math.max(textHeight, Math.ceil(textLayout.getLineBottom(a)));
          } catch (Exception e) {
            FileLog.e("tmessages", e);
            return;
          }
          textWidth = (int) Math.max(textWidth, Math.ceil(lineWidth));
        }
      } catch (Exception e) {
        FileLog.e("tmessages", e);
      }

      textX = (width - textWidth) / 2;
      textY = AndroidUtilities.dp(7);
      textXLeft = (width - textLayout.getWidth()) / 2;

      if (currentMessageObject.type == MessageObject.Type.MSG_ACTION) {
        imageReceiver.setImageCoords(
            (width - AndroidUtilities.dp(64)) / 2,
            textHeight + AndroidUtilities.dp(15),
            AndroidUtilities.dp(64),
            AndroidUtilities.dp(64));
      }
    }
    setMeasuredDimension(
        width,
        textHeight
            + AndroidUtilities.dp(
                14 + (currentMessageObject.type == MessageObject.Type.MSG_ACTION ? 70 : 0)));
  }
 private void processSelectionOption(int which, TLRPC.TL_messages_stickerSet stickerSet) {
   if (which == 0) {
     StickersQuery.removeStickersSet(
         getParentActivity(), stickerSet.set, (stickerSet.set.flags & 2) == 0 ? 1 : 2);
   } else if (which == 1) {
     StickersQuery.removeStickersSet(getParentActivity(), stickerSet.set, 0);
   } else if (which == 2) {
     try {
       Intent intent = new Intent(Intent.ACTION_SEND);
       intent.setType("text/plain");
       intent.putExtra(
           Intent.EXTRA_TEXT,
           String.format(
               Locale.US, "https://telegram.me/addstickers/%s", stickerSet.set.short_name));
       getParentActivity()
           .startActivityForResult(
               Intent.createChooser(
                   intent, LocaleController.getString("StickersShare", R.string.StickersShare)),
               500);
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
   } else if (which == 3) {
     try {
       if (Build.VERSION.SDK_INT < 11) {
         android.text.ClipboardManager clipboard =
             (android.text.ClipboardManager)
                 ApplicationLoader.applicationContext.getSystemService(
                     Context.CLIPBOARD_SERVICE);
         clipboard.setText(
             String.format(
                 Locale.US, "https://telegram.me/addstickers/%s", stickerSet.set.short_name));
       } else {
         android.content.ClipboardManager clipboard =
             (android.content.ClipboardManager)
                 ApplicationLoader.applicationContext.getSystemService(
                     Context.CLIPBOARD_SERVICE);
         android.content.ClipData clip =
             android.content.ClipData.newPlainText(
                 "label",
                 String.format(
                     Locale.US,
                     "https://telegram.me/addstickers/%s",
                     stickerSet.set.short_name));
         clipboard.setPrimaryClip(clip);
       }
       Toast.makeText(
               getParentActivity(),
               LocaleController.getString("LinkCopied", R.string.LinkCopied),
               Toast.LENGTH_SHORT)
           .show();
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
   }
 }
 @Override
 public void onActivityStopped(Activity activity) {
   if (--refs == 0) {
     enterBackgroundTime = System.currentTimeMillis();
     wasInBackground = true;
     FileLog.e("tmessages", "switch to background");
     for (Listener listener : listeners) {
       try {
         listener.onBecameBackground();
       } catch (Exception e) {
         FileLog.e("tmessages", e);
       }
     }
   }
 }
  public long selectServerSalt(int date) {
    boolean cleanupNeeded = false;

    long result = 0;
    int maxRemainingInterval = 0;

    for (ServerSalt salt : authServerSaltSet) {
      if (salt.validUntil < date
          || (salt.validSince == 0 && salt.validUntil == Integer.MAX_VALUE)) {
        cleanupNeeded = true;
      } else if (salt.validSince <= date && salt.validUntil > date) {
        if (maxRemainingInterval == 0 || Math.abs(salt.validUntil - date) > maxRemainingInterval) {
          maxRemainingInterval = Math.abs(salt.validUntil - date);
          result = salt.value;
        }
      }
    }

    if (cleanupNeeded) {
      for (int i = 0; i < authServerSaltSet.size(); i++) {
        ServerSalt salt = authServerSaltSet.get(i);
        if (salt.validUntil < date) {
          authServerSaltSet.remove(i);
          i--;
        }
      }
    }

    if (result == 0) {
      FileLog.e("tmessages", "Valid salt not found");
    }

    return result;
  }
 public void searchDialogs(final String query) {
   if (query == null) {
     searchResult = null;
     searchResultNames = null;
   } else {
     try {
       if (searchTimer != null) {
         searchTimer.cancel();
       }
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
     searchTimer = new Timer();
     searchTimer.schedule(
         new TimerTask() {
           @Override
           public void run() {
             try {
               searchTimer.cancel();
               searchTimer = null;
             } catch (Exception e) {
               FileLog.e("tmessages", e);
             }
             processSearch(query);
           }
         },
         100,
         300);
   }
 }
 @Override
 public void onActivityStarted(Activity activity) {
   if (++refs == 1) {
     if (System.currentTimeMillis() - enterBackgroundTime < 200) {
       wasInBackground = false;
     }
     FileLog.e("tmessages", "switch to foreground");
     for (Listener listener : listeners) {
       try {
         listener.onBecameForeground();
       } catch (Exception e) {
         FileLog.e("tmessages", e);
       }
     }
   }
 }
 private void setTypingAnimation(boolean start) {
   if (actionBar == null) {
     return;
   }
   if (start) {
     try {
       Integer type =
           MessagesController.getInstance()
               .printingStringsTypes
               .get(currentMessageObject.getDialogId());
       if (type == 0) {
         onlineTextView.setCompoundDrawablesWithIntrinsicBounds(
             typingDotsDrawable, null, null, null);
         onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
         typingDotsDrawable.start();
         recordStatusDrawable.stop();
       } else if (type == 1) {
         onlineTextView.setCompoundDrawablesWithIntrinsicBounds(
             recordStatusDrawable, null, null, null);
         onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
         recordStatusDrawable.start();
         typingDotsDrawable.stop();
       }
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
   } else {
     onlineTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
     onlineTextView.setCompoundDrawablePadding(0);
     typingDotsDrawable.stop();
     recordStatusDrawable.stop();
   }
 }
Exemple #11
0
 public static int getColorIndex(int id) {
   int[] arr;
   if (id >= 0) {
     arr = arrUsersAvatars;
   } else {
     arr = arrGroupsAvatars;
   }
   try {
     String str;
     if (id >= 0) {
       str = String.format(Locale.US, "%d%d", id, UserConfig.clientUserId);
     } else {
       str = String.format(Locale.US, "%d", id);
     }
     if (str.length() > 15) {
       str = str.substring(0, 15);
     }
     java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
     byte[] digest = md.digest(str.getBytes());
     int b = digest[Math.abs(id % 16)];
     if (b < 0) {
       b += 256;
     }
     return Math.abs(b) % arr.length;
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return id % arr.length;
 }
Exemple #12
0
 static {
   density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
   SharedPreferences preferences =
       ApplicationLoader.applicationContext.getSharedPreferences("primes", Context.MODE_PRIVATE);
   String primes = preferences.getString("primes", null);
   if (primes == null) {
     goodPrimes.add(
         "C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C3720FD51F69458705AC68CD4FE6B6B13ABDC9746512969328454F18FAF8C595F642477FE96BB2A941D5BCD1D4AC8CC49880708FA9B378E3C4F3A9060BEE67CF9A4A4A695811051907E162753B56B0F6B410DBA74D8A84B2A14B3144E0EF1284754FD17ED950D5965B4B9DD46582DB1178D169C6BC465B0D6FF9CA3928FEF5B9AE4E418FC15E83EBEA0F87FA9FF5EED70050DED2849F47BF959D956850CE929851F0D8115F635B105EE2E4E15D04B2454BF6F4FADF034B10403119CD8E3B92FCC5B");
   } else {
     try {
       byte[] bytes = Base64.decode(primes, Base64.DEFAULT);
       if (bytes != null) {
         SerializedData data = new SerializedData(bytes);
         int count = data.readInt32();
         for (int a = 0; a < count; a++) {
           goodPrimes.add(data.readString());
         }
       }
     } catch (Exception e) {
       FileLog.e("tmessages", e);
       goodPrimes.clear();
       goodPrimes.add(
           "C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C3720FD51F69458705AC68CD4FE6B6B13ABDC9746512969328454F18FAF8C595F642477FE96BB2A941D5BCD1D4AC8CC49880708FA9B378E3C4F3A9060BEE67CF9A4A4A695811051907E162753B56B0F6B410DBA74D8A84B2A14B3144E0EF1284754FD17ED950D5965B4B9DD46582DB1178D169C6BC465B0D6FF9CA3928FEF5B9AE4E418FC15E83EBEA0F87FA9FF5EED70050DED2849F47BF959D956850CE929851F0D8115F635B105EE2E4E15D04B2454BF6F4FADF034B10403119CD8E3B92FCC5B");
     }
   }
   System.loadLibrary("tmessages");
 }
 @Override
 public void showAsDropDown(View anchor, int xoff, int yoff) {
   try {
     super.showAsDropDown(anchor, xoff, yoff);
     registerListener(anchor);
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
 }
Exemple #14
0
 public static byte[] computeSHA1(byte[] convertme) {
   try {
     MessageDigest md = MessageDigest.getInstance("SHA-1");
     return md.digest(convertme);
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
Exemple #15
0
 public static byte[] computeSHA1(byte[] convertme, int offset, int len) {
   try {
     MessageDigest md = MessageDigest.getInstance("SHA-1");
     md.update(convertme, offset, len);
     return md.digest();
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
 @Override
 public boolean onTouchEvent(
     @NonNull TextView widget, @NonNull Spannable buffer, @NonNull MotionEvent event) {
   try {
     return super.onTouchEvent(widget, buffer, event);
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return false;
 }
Exemple #17
0
 public static File generatePicturePath() {
   try {
     File storageDir = getAlbumDir();
     String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
     String imageFileName = "IMG_" + timeStamp + "_";
     return File.createTempFile(imageFileName, ".jpg", storageDir);
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
Exemple #18
0
 @Override
 public void needHideProgress() {
   if (progressDialog == null) {
     return;
   }
   try {
     progressDialog.dismiss();
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
 }
Exemple #19
0
 public static void checkDisplaySize() {
   try {
     WindowManager manager =
         (WindowManager)
             ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
     if (manager != null) {
       Display display = manager.getDefaultDisplay();
       if (display != null) {
         if (android.os.Build.VERSION.SDK_INT < 13) {
           displaySize.set(display.getWidth(), display.getHeight());
         } else {
           display.getSize(displaySize);
         }
         FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y);
       }
     }
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
 }
 @Override
 public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
   if (resultCode == Activity.RESULT_OK) {
     if (requestCode == 10) {
       Utilities.addMediaToGallery(currentPicturePath);
       try {
         Bitmap bitmap =
             ImageLoader.loadBitmap(
                 currentPicturePath, null, AndroidUtilities.dp(320), AndroidUtilities.dp(480));
         File toFile =
             new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
         FileOutputStream stream = new FileOutputStream(toFile);
         bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);
         selectedBackground = -1;
         selectedColor = 0;
         backgroundImage.setImageBitmap(bitmap);
       } catch (Exception e) {
         FileLog.e("tmessages", e);
       }
       currentPicturePath = null;
     } else if (requestCode == 11) {
       if (data == null || data.getData() == null) {
         return;
       }
       try {
         Bitmap bitmap =
             ImageLoader.loadBitmap(
                 null, data.getData(), AndroidUtilities.dp(320), AndroidUtilities.dp(480));
         File toFile =
             new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
         FileOutputStream stream = new FileOutputStream(toFile);
         bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);
         selectedBackground = -1;
         selectedColor = 0;
         backgroundImage.setImageBitmap(bitmap);
       } catch (Exception e) {
         FileLog.e("tmessages", e);
       }
     }
   }
 }
 @Override
 public void didReceivedNotification(int id, final Object... args) {
   if (id == MessagesController.updateInterfaces) {
     int mask = (Integer) args[0];
     if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0
         || (mask & MessagesController.UPDATE_MASK_NAME) != 0
         || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
       updateVisibleRows(mask);
     }
   } else if (id == MessagesController.chatDidFailCreate) {
     if (progressDialog != null) {
       try {
         progressDialog.dismiss();
       } catch (Exception e) {
         FileLog.e("tmessages", e);
       }
     }
     donePressed = false;
     FileLog.e("tmessages", "did fail create chat");
   } else if (id == MessagesController.chatDidCreated) {
     Utilities.RunOnUIThread(
         new Runnable() {
           @Override
           public void run() {
             if (progressDialog != null) {
               try {
                 progressDialog.dismiss();
               } catch (Exception e) {
                 FileLog.e("tmessages", e);
               }
             }
             ChatActivity fragment = new ChatActivity();
             Bundle bundle = new Bundle();
             bundle.putInt("chat_id", (Integer) args[0]);
             fragment.setArguments(bundle);
             ((LaunchActivity) parentActivity)
                 .presentFragment(fragment, "chat" + Math.random(), true, false);
           }
         });
   }
 }
Exemple #22
0
  private static File getAlbumDir() {
    File storageDir = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
      storageDir =
          new File(
              Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
              ApplicationLoader.applicationContext.getResources().getString(R.string.AppName));
      if (storageDir != null) {
        if (!storageDir.mkdirs()) {
          if (!storageDir.exists()) {
            FileLog.d("tmessages", "failed to create directory");
            return null;
          }
        }
      }
    } else {
      FileLog.d("tmessages", "External storage is not mounted READ/WRITE.");
    }

    return storageDir;
  }
Exemple #23
0
 public static byte[] encryptWithRSA(BigInteger[] key, byte[] data) {
   try {
     KeyFactory fact = KeyFactory.getInstance("RSA");
     RSAPublicKeySpec keySpec = new RSAPublicKeySpec(key[0], key[1]);
     PublicKey publicKey = fact.generatePublic(keySpec);
     final Cipher cipher = Cipher.getInstance("RSA");
     cipher.init(Cipher.ENCRYPT_MODE, publicKey);
     return cipher.doFinal(data);
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
Exemple #24
0
 public static String MD5(String md5) {
   try {
     java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
     byte[] array = md.digest(md5.getBytes());
     StringBuilder sb = new StringBuilder();
     for (byte anArray : array) {
       sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3));
     }
     return sb.toString();
   } catch (java.security.NoSuchAlgorithmException e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
Exemple #25
0
 public static Typeface getTypeface(String assetPath) {
   synchronized (cache) {
     if (!cache.containsKey(assetPath)) {
       try {
         Typeface t =
             Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
         cache.put(assetPath, t);
       } catch (Exception e) {
         FileLog.e(TAG, "Could not get typeface '" + assetPath + "' because " + e.getMessage());
         return null;
       }
     }
     return cache.get(assetPath);
   }
 }
 @SuppressWarnings("unchecked")
 @Override
 public boolean onFragmentCreate() {
   super.onFragmentCreate();
   NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
   NotificationCenter.getInstance().addObserver(this, MessagesController.chatDidCreated);
   NotificationCenter.getInstance().addObserver(this, MessagesController.chatDidFailCreate);
   avatarUpdater.parentFragment = this;
   avatarUpdater.delegate = this;
   selectedContacts = getArguments().getIntegerArrayList("result");
   final ArrayList<Integer> usersToLoad = new ArrayList<Integer>();
   for (Integer uid : selectedContacts) {
     if (MessagesController.getInstance().users.get(uid) == null) {
       usersToLoad.add(uid);
     }
   }
   if (!usersToLoad.isEmpty()) {
     final Semaphore semaphore = new Semaphore(0);
     final ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
     final boolean[] error = new boolean[1];
     MessagesStorage.getInstance()
         .storageQueue
         .postRunnable(
             new Runnable() {
               @Override
               public void run() {
                 users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad, error));
                 semaphore.release();
               }
             });
     try {
       semaphore.acquire();
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
     if (error[0]) {
       return false;
     }
     if (!users.isEmpty()) {
       for (TLRPC.User user : users) {
         MessagesController.getInstance().users.putIfAbsent(user.id, user);
       }
     } else {
       return false;
     }
   }
   return true;
 }
Exemple #27
0
 public static byte[] computeSHA1(ByteBuffer convertme, int offset, int len) {
   try {
     MessageDigest md = MessageDigest.getInstance("SHA-1");
     int oldp = convertme.position();
     int oldl = convertme.limit();
     convertme.position(offset);
     convertme.limit(len);
     md.update(convertme);
     convertme.position(oldp);
     convertme.limit(oldl);
     return md.digest();
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
Exemple #28
0
  public static File generateVideoPath() {
    try {
      File storageDir = getAlbumDir();
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
      String imageFileName = "VID_" + timeStamp + "_";
      return File.createTempFile(imageFileName, ".mp4", storageDir);
      /*

      String fileName = "VID" + id + ".mp4";
      return new File(ApplicationLoader.applicationContext.getCacheDir(), fileName);
       */
    } catch (Exception e) {
      FileLog.e("tmessages", e);
    }
    return null;
  }
 public void postNotificationNameInternal(int id, boolean allowDuringAnimation, Object... args) {
   if (BuildVars.DEBUG_VERSION) {
     if (Thread.currentThread() != ApplicationLoader.applicationHandler.getLooper().getThread()) {
       throw new RuntimeException("postNotificationName allowed only from MAIN thread");
     }
   }
   if (!allowDuringAnimation && animationInProgress) {
     DelayedPost delayedPost = new DelayedPost(id, args);
     delayedPosts.add(delayedPost);
     if (BuildVars.DEBUG_VERSION) {
       FileLog.e(
           "tmessages", "delay post notification " + id + " with args count = " + args.length);
     }
     return;
   }
   broadcasting++;
   ArrayList<Object> objects = observers.get(id);
   if (objects != null && !objects.isEmpty()) {
     for (int a = 0; a < objects.size(); a++) {
       Object obj = objects.get(a);
       ((NotificationCenterDelegate) obj).didReceivedNotification(id, args);
     }
   }
   broadcasting--;
   if (broadcasting == 0) {
     if (removeAfterBroadcast.size() != 0) {
       for (int a = 0; a < removeAfterBroadcast.size(); a++) {
         int key = removeAfterBroadcast.keyAt(a);
         ArrayList<Object> arrayList = removeAfterBroadcast.get(key);
         for (int b = 0; b < arrayList.size(); b++) {
           removeObserver(arrayList.get(b), key);
         }
       }
       removeAfterBroadcast.clear();
     }
     if (addAfterBroadcast.size() != 0) {
       for (int a = 0; a < addAfterBroadcast.size(); a++) {
         int key = addAfterBroadcast.keyAt(a);
         ArrayList<Object> arrayList = addAfterBroadcast.get(key);
         for (int b = 0; b < arrayList.size(); b++) {
           addObserver(arrayList.get(b), key);
         }
       }
       addAfterBroadcast.clear();
     }
   }
 }
Exemple #30
0
  public static byte[] compress(byte[] data) {
    if (data == null) {
      return null;
    }

    byte[] packedData = null;
    ByteArrayOutputStream bytesStream = new ByteArrayOutputStream();
    try {
      GZIPOutputStream zip = new GZIPOutputStream(bytesStream);
      zip.write(data);
      zip.close();
      packedData = bytesStream.toByteArray();
    } catch (IOException e) {
      FileLog.e("tmessages", e);
    }
    return packedData;
  }