コード例 #1
0
  @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 == 11) {
        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 == 11 ? 70 : 0)));
  }
コード例 #2
0
 @Override
 public void onFragmentDestroy() {
   try {
     if (receiverRegistered) {
       ApplicationLoader.applicationContext.unregisterReceiver(receiver);
     }
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   super.onFragmentDestroy();
 }
コード例 #3
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (Build.VERSION.SDK_INT >= 21) {
     super.onMeasure(
         widthMeasureSpec,
         MeasureSpec.makeMeasureSpec(
             AndroidUtilities.dp(148) + AndroidUtilities.statusBarHeight, MeasureSpec.EXACTLY));
   } else {
     try {
       super.onMeasure(
           widthMeasureSpec,
           MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(148), MeasureSpec.EXACTLY));
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
   }
 }
コード例 #4
0
  public boolean draw(Canvas canvas) {
    try {
      BitmapDrawable bitmapDrawable = null;
      if (!forcePreview && currentImage != null) {
        bitmapDrawable = currentImage;
      } else if (staticThumb instanceof BitmapDrawable) {
        bitmapDrawable = (BitmapDrawable) staticThumb;
      } else if (currentThumb != null) {
        bitmapDrawable = currentThumb;
      }
      if (bitmapDrawable != null) {
        if (crossfadeAlpha != 0) {
          if (crossfadeWithThumb && currentAlpha != 1.0f) {
            Drawable thumbDrawable = null;
            if (bitmapDrawable == currentImage) {
              if (staticThumb != null) {
                thumbDrawable = staticThumb;
              } else if (currentThumb != null) {
                thumbDrawable = currentThumb;
              }
            } else if (bitmapDrawable == currentThumb) {
              if (staticThumb != null) {
                thumbDrawable = staticThumb;
              }
            }
            if (thumbDrawable != null) {
              drawDrawable(canvas, thumbDrawable, (int) (overrideAlpha * 255));
            }
          }
          drawDrawable(canvas, bitmapDrawable, (int) (overrideAlpha * currentAlpha * 255));
        } else {
          drawDrawable(canvas, bitmapDrawable, (int) (overrideAlpha * 255));
        }

        checkAlphaAnimation();
        return true;
      } else if (staticThumb != null) {
        drawDrawable(canvas, staticThumb, 255);
        checkAlphaAnimation();
        return true;
      }
    } catch (Exception e) {
      FileLog.e("tmessages", e);
    }
    return false;
  }
コード例 #5
0
 private String getRootSubtitle(String path) {
   try {
     StatFs stat = new StatFs(path);
     long total = (long) stat.getBlockCount() * (long) stat.getBlockSize();
     long free = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
     if (total == 0) {
       return "";
     }
     return LocaleController.formatString(
         "FreeOfTotal",
         R.string.FreeOfTotal,
         AndroidUtilities.formatFileSize(free),
         AndroidUtilities.formatFileSize(total));
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return path;
 }
コード例 #6
0
  public static void init() {
    if (initialized) {
      return;
    }

    try {
      final Class<?> textDirClass;
      if (Build.VERSION.SDK_INT >= 18) {
        textDirClass = TextDirectionHeuristic.class;
        sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;
      } else {
        ClassLoader loader = StaticLayoutEx.class.getClassLoader();
        textDirClass = loader.loadClass(TEXT_DIR_CLASS);
        Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS);
        sTextDirection = textDirsClass.getField(TEXT_DIR_FIRSTSTRONG_LTR).get(textDirsClass);
      }

      final Class<?>[] signature =
          new Class[] {
            CharSequence.class,
            int.class,
            int.class,
            TextPaint.class,
            int.class,
            Layout.Alignment.class,
            textDirClass,
            float.class,
            float.class,
            boolean.class,
            TextUtils.TruncateAt.class,
            int.class,
            int.class
          };

      sConstructor = StaticLayout.class.getDeclaredConstructor(signature);
      sConstructor.setAccessible(true);
      sConstructorArgs = new Object[signature.length];
      initialized = true;
    } catch (Throwable e) {
      FileLog.e("tmessages", e);
    }
  }
コード例 #7
0
  @SuppressLint("NewApi")
  private void listRoots() {
    currentDir = null;
    items.clear();

    HashSet<String> paths = new HashSet<>();
    String defaultPath = Environment.getExternalStorageDirectory().getPath();
    boolean isDefaultPathRemovable =
        Build.VERSION.SDK_INT >= 9 && Environment.isExternalStorageRemovable();
    String defaultPathState = Environment.getExternalStorageState();
    if (defaultPathState.equals(Environment.MEDIA_MOUNTED)
        || defaultPathState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
      ListItem ext = new ListItem();
      if (Build.VERSION.SDK_INT < 9 || Environment.isExternalStorageRemovable()) {
        ext.title = LocaleController.getString("SdCard", R.string.SdCard);
        ext.icon = R.drawable.ic_external_storage;
      } else {
        ext.title = LocaleController.getString("InternalStorage", R.string.InternalStorage);
        ext.icon = R.drawable.ic_storage;
      }
      ext.subtitle = getRootSubtitle(defaultPath);
      ext.file = Environment.getExternalStorageDirectory();
      items.add(ext);
      paths.add(defaultPath);
    }

    BufferedReader bufferedReader = null;
    try {
      bufferedReader = new BufferedReader(new FileReader("/proc/mounts"));
      String line;
      while ((line = bufferedReader.readLine()) != null) {
        if (line.contains("vfat") || line.contains("/mnt")) {
          FileLog.e("tmessages", line);
          StringTokenizer tokens = new StringTokenizer(line, " ");
          String unused = tokens.nextToken();
          String path = tokens.nextToken();
          if (paths.contains(path)) {
            continue;
          }
          if (line.contains("/dev/block/vold")) {
            if (!line.contains("/mnt/secure")
                && !line.contains("/mnt/asec")
                && !line.contains("/mnt/obb")
                && !line.contains("/dev/mapper")
                && !line.contains("tmpfs")) {
              if (!new File(path).isDirectory()) {
                int index = path.lastIndexOf('/');
                if (index != -1) {
                  String newPath = "/storage/" + path.substring(index + 1);
                  if (new File(newPath).isDirectory()) {
                    path = newPath;
                  }
                }
              }
              paths.add(path);
              try {
                ListItem item = new ListItem();
                if (path.toLowerCase().contains("sd")) {
                  item.title = LocaleController.getString("SdCard", R.string.SdCard);
                } else {
                  item.title =
                      LocaleController.getString("ExternalStorage", R.string.ExternalStorage);
                }
                item.icon = R.drawable.ic_external_storage;
                item.subtitle = getRootSubtitle(path);
                item.file = new File(path);
                items.add(item);
              } catch (Exception e) {
                FileLog.e("tmessages", e);
              }
            }
          }
        }
      }
    } catch (Exception e) {
      FileLog.e("tmessages", e);
    } finally {
      if (bufferedReader != null) {
        try {
          bufferedReader.close();
        } catch (Exception e) {
          FileLog.e("tmessages", e);
        }
      }
    }
    ListItem fs = new ListItem();
    fs.title = "/";
    fs.subtitle = LocaleController.getString("SystemRoot", R.string.SystemRoot);
    fs.icon = R.drawable.ic_directory;
    fs.file = new File("/");
    items.add(fs);

    try {
      File telegramPath = new File(Environment.getExternalStorageDirectory(), "Telegram");
      if (telegramPath.exists()) {
        fs = new ListItem();
        fs.title = "Telegram";
        fs.subtitle = telegramPath.toString();
        fs.icon = R.drawable.ic_directory;
        fs.file = telegramPath;
        items.add(fs);
      }
    } catch (Exception e) {
      FileLog.e("tmessages", e);
    }

    fs = new ListItem();
    fs.title = LocaleController.getString("Gallery", R.string.Gallery);
    fs.subtitle = LocaleController.getString("GalleryInfo", R.string.GalleryInfo);
    fs.icon = R.drawable.ic_storage_gallery;
    fs.file = null;
    items.add(fs);

    AndroidUtilities.clearDrawableAnimation(listView);
    scrolling = true;
    listAdapter.notifyDataSetChanged();
  }
コード例 #8
0
 public static StaticLayout createStaticLayout(
     CharSequence source,
     int bufstart,
     int bufend,
     TextPaint paint,
     int outerWidth,
     Layout.Alignment align,
     float spacingMult,
     float spacingAdd,
     boolean includePad,
     TextUtils.TruncateAt ellipsize,
     int ellipsisWidth,
     int maxLines) {
   /*if (Build.VERSION.SDK_INT >= 14) {
       init();
       try {
           sConstructorArgs[0] = source;
           sConstructorArgs[1] = bufstart;
           sConstructorArgs[2] = bufend;
           sConstructorArgs[3] = paint;
           sConstructorArgs[4] = outerWidth;
           sConstructorArgs[5] = align;
           sConstructorArgs[6] = sTextDirection;
           sConstructorArgs[7] = spacingMult;
           sConstructorArgs[8] = spacingAdd;
           sConstructorArgs[9] = includePad;
           sConstructorArgs[10] = ellipsize;
           sConstructorArgs[11] = ellipsisWidth;
           sConstructorArgs[12] = maxLines;
           return sConstructor.newInstance(sConstructorArgs);
       } catch (Exception e) {
           FileLog.e("tmessages", e);
       }
   }*/
   try {
     if (maxLines == 1) {
       CharSequence text =
           TextUtils.ellipsize(source, paint, ellipsisWidth, TextUtils.TruncateAt.END);
       return new StaticLayout(
           text, 0, text.length(), paint, outerWidth, align, spacingMult, spacingAdd, includePad);
     } else {
       StaticLayout layout =
           new StaticLayout(source, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
       if (layout.getLineCount() <= maxLines) {
         return layout;
       } else {
         int off;
         float left = layout.getLineLeft(maxLines - 1);
         if (left != 0) {
           off = layout.getOffsetForHorizontal(maxLines - 1, left);
         } else {
           off = layout.getOffsetForHorizontal(maxLines - 1, layout.getLineWidth(maxLines - 1));
         }
         SpannableStringBuilder stringBuilder =
             new SpannableStringBuilder(source.subSequence(0, Math.max(0, off - 1)));
         stringBuilder.append("\u2026");
         return new StaticLayout(
             stringBuilder, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
       }
     }
   } catch (Exception e) {
     FileLog.e("tmessages", e);
   }
   return null;
 }
コード例 #9
0
  private void drawDrawable(Canvas canvas, Drawable drawable, int alpha) {
    if (drawable instanceof BitmapDrawable) {
      BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

      Paint paint = bitmapDrawable.getPaint();
      boolean hasFilter = paint != null && paint.getColorFilter() != null;
      if (hasFilter && !isPressed) {
        bitmapDrawable.setColorFilter(null);
      } else if (!hasFilter && isPressed) {
        bitmapDrawable.setColorFilter(
            new PorterDuffColorFilter(0xffdddddd, PorterDuff.Mode.MULTIPLY));
      }
      if (colorFilter != null) {
        bitmapDrawable.setColorFilter(colorFilter);
      }
      if (bitmapShader != null) {
        drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
        if (isVisible) {
          roundRect.set(drawRegion);
          shaderMatrix.reset();
          shaderMatrix.setRectToRect(bitmapRect, roundRect, Matrix.ScaleToFit.FILL);
          bitmapShader.setLocalMatrix(shaderMatrix);
          roundPaint.setAlpha(alpha);
          canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
        }
      } else {
        int bitmapW;
        int bitmapH;
        if (orientation == 90 || orientation == 270) {
          bitmapW = bitmapDrawable.getIntrinsicHeight();
          bitmapH = bitmapDrawable.getIntrinsicWidth();
        } else {
          bitmapW = bitmapDrawable.getIntrinsicWidth();
          bitmapH = bitmapDrawable.getIntrinsicHeight();
        }
        float scaleW = bitmapW / (float) imageW;
        float scaleH = bitmapH / (float) imageH;

        if (isAspectFit) {
          float scale = Math.max(scaleW, scaleH);
          canvas.save();
          bitmapW /= scale;
          bitmapH /= scale;
          drawRegion.set(
              imageX + (imageW - bitmapW) / 2,
              imageY + (imageH - bitmapH) / 2,
              imageX + (imageW + bitmapW) / 2,
              imageY + (imageH + bitmapH) / 2);
          bitmapDrawable.setBounds(drawRegion);
          try {
            bitmapDrawable.setAlpha(alpha);
            bitmapDrawable.draw(canvas);
          } catch (Exception e) {
            if (bitmapDrawable == currentImage && currentKey != null) {
              ImageLoader.getInstance().removeImage(currentKey);
              currentKey = null;
            } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
              ImageLoader.getInstance().removeImage(currentThumbKey);
              currentThumbKey = null;
            }
            setImage(
                currentImageLocation,
                currentHttpUrl,
                currentFilter,
                currentThumb,
                currentThumbLocation,
                currentThumbFilter,
                currentSize,
                currentExt,
                currentCacheOnly);
            FileLog.e("tmessages", e);
          }
          canvas.restore();
        } else {
          if (Math.abs(scaleW - scaleH) > 0.00001f) {
            canvas.save();
            canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);

            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }

            if (bitmapW / scaleH > imageW) {
              bitmapW /= scaleH;
              drawRegion.set(
                  imageX - (bitmapW - imageW) / 2,
                  imageY,
                  imageX + (bitmapW + imageW) / 2,
                  imageY + imageH);
            } else {
              bitmapH /= scaleW;
              drawRegion.set(
                  imageX,
                  imageY - (bitmapH - imageH) / 2,
                  imageX + imageW,
                  imageY + (bitmapH + imageH) / 2);
            }
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }

            canvas.restore();
          } else {
            canvas.save();
            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }
            drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }
            canvas.restore();
          }
        }
      }
    } else {
      drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
      drawable.setBounds(drawRegion);
      if (isVisible) {
        try {
          drawable.setAlpha(alpha);
          drawable.draw(canvas);
        } catch (Exception e) {
          FileLog.e("tmessages", e);
        }
      }
    }
  }