From 08a49ea2eabd8954560b5b68a4a09d4b4f83d5d3 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Mon, 20 Oct 2014 22:11:47 +0400 Subject: [PATCH] Enable screenshot detection --- TMessagesProj/build.gradle | 2 +- .../org/telegram/android/MediaController.java | 139 +++++++++--------- .../java/org/telegram/ui/ChatActivity.java | 4 +- .../main/res/drawable-v21/bar_selector.xml | 4 + .../res/drawable-v21/bar_selector_mode.xml | 4 + .../res/drawable-v21/bar_selector_picker.xml | 4 + .../res/drawable-v21/bar_selector_style.xml | 4 + .../res/drawable-v21/bar_selector_white.xml | 4 + .../main/res/drawable-v21/list_selector.xml | 5 + .../group_profile_add_member_layout.xml | 1 - .../src/main/res/values-ar/strings.xml | 8 +- .../src/main/res/values-de/strings.xml | 8 +- .../src/main/res/values-es/strings.xml | 8 +- .../src/main/res/values-it/strings.xml | 8 +- .../src/main/res/values-ko/strings.xml | 8 +- .../src/main/res/values-nl/strings.xml | 8 +- .../src/main/res/values-pt-rBR/strings.xml | 8 +- .../src/main/res/values-pt-rPT/strings.xml | 8 +- .../src/main/res/values-v21/styles.xml | 2 +- TMessagesProj/src/main/res/values/strings.xml | 8 +- 20 files changed, 153 insertions(+), 92 deletions(-) create mode 100644 TMessagesProj/src/main/res/drawable-v21/bar_selector.xml create mode 100644 TMessagesProj/src/main/res/drawable-v21/bar_selector_mode.xml create mode 100644 TMessagesProj/src/main/res/drawable-v21/bar_selector_picker.xml create mode 100644 TMessagesProj/src/main/res/drawable-v21/bar_selector_style.xml create mode 100644 TMessagesProj/src/main/res/drawable-v21/bar_selector_white.xml create mode 100644 TMessagesProj/src/main/res/drawable-v21/list_selector.xml diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 322e99a26..64fb45a6c 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -25,7 +25,7 @@ dependencies { android { compileSdkVersion 21 - buildToolsVersion '21.0.0' + buildToolsVersion '21.0.1' signingConfigs { debug { diff --git a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java index e91612919..acebe8a23 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java @@ -18,6 +18,8 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.database.ContentObserver; import android.database.Cursor; +import android.graphics.BitmapFactory; +import android.graphics.Point; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioRecord; @@ -36,7 +38,10 @@ import android.os.Environment; import android.os.ParcelFileDescriptor; import android.os.Vibrator; import android.provider.MediaStore; +import android.util.DisplayMetrics; +import android.view.Display; import android.view.View; +import android.view.WindowManager; import org.telegram.android.video.InputSurface; import org.telegram.android.video.MP4Builder; @@ -58,6 +63,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.lang.ref.WeakReference; +import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; @@ -340,13 +346,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel } } } - private String[] mediaProjections = new String[] { - MediaStore.Images.ImageColumns.DATA, - MediaStore.Images.ImageColumns.DISPLAY_NAME, - MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, - MediaStore.Images.ImageColumns.DATE_TAKEN, - MediaStore.Images.ImageColumns.TITLE - }; + private String[] mediaProjections = null; private static volatile MediaController Instance = null; public static MediaController getInstance() { @@ -413,6 +413,26 @@ public class MediaController implements NotificationCenter.NotificationCenterDel if (UserConfig.isClientActivated()) { checkAutodownloadSettings(); } + + if (Build.VERSION.SDK_INT >= 16) { + mediaProjections = new String[] { + MediaStore.Images.ImageColumns.DATA, + MediaStore.Images.ImageColumns.DISPLAY_NAME, + MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, + MediaStore.Images.ImageColumns.DATE_TAKEN, + MediaStore.Images.ImageColumns.TITLE, + MediaStore.Images.ImageColumns.WIDTH, + MediaStore.Images.ImageColumns.HEIGHT + }; + } else { + mediaProjections = new String[] { + MediaStore.Images.ImageColumns.DATA, + MediaStore.Images.ImageColumns.DISPLAY_NAME, + MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, + MediaStore.Images.ImageColumns.DATE_TAKEN, + MediaStore.Images.ImageColumns.TITLE + }; + } } private void startProgressTimer() { @@ -684,7 +704,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel } public void startMediaObserver() { - if (android.os.Build.VERSION.SDK_INT > 0) { //disable while it's not perferct + if (android.os.Build.VERSION.SDK_INT < 14) { return; } ApplicationLoader.applicationHandler.removeCallbacks(stopMediaObserverRunnable); @@ -706,7 +726,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel } public void stopMediaObserver() { - if (android.os.Build.VERSION.SDK_INT > 0) { //disable while it's not perferct + if (android.os.Build.VERSION.SDK_INT < 14) { return; } if (stopMediaObserverRunnable == null) { @@ -718,6 +738,30 @@ public class MediaController implements NotificationCenter.NotificationCenterDel public void processMediaObserver(Uri uri) { try { + int width = 0; + int height = 0; + + try { + WindowManager windowManager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + Point size = new Point(); + windowManager.getDefaultDisplay().getRealSize(size); + width = size.x; + height = size.y; + } else { + try { + Method mGetRawW = Display.class.getMethod("getRawWidth"); + Method mGetRawH = Display.class.getMethod("getRawHeight"); + width = (Integer) mGetRawW.invoke(windowManager.getDefaultDisplay()); + height = (Integer) mGetRawH.invoke(windowManager.getDefaultDisplay()); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + Cursor cursor = ApplicationLoader.applicationContext.getContentResolver().query(uri, mediaProjections, null, null, "date_added DESC LIMIT 1"); final ArrayList screenshotDates = new ArrayList(); if (cursor != null) { @@ -726,75 +770,33 @@ public class MediaController implements NotificationCenter.NotificationCenterDel String data = cursor.getString(0); String display_name = cursor.getString(1); String album_name = cursor.getString(2); - String title = cursor.getString(4); long date = cursor.getLong(3); + String title = cursor.getString(4); + int photoW = 0; + int photoH = 0; + if (Build.VERSION.SDK_INT >= 16) { + photoW = cursor.getInt(5); + photoH = cursor.getInt(6); + } if (data != null && data.toLowerCase().contains("screenshot") || display_name != null && display_name.toLowerCase().contains("screenshot") || album_name != null && album_name.toLowerCase().contains("screenshot") || title != null && title.toLowerCase().contains("screenshot")) { - /*BitmapRegionDecoder bitmapRegionDecoder = null; - boolean added = false; try { - int waitCount = 0; - while (waitCount < 5 && bitmapRegionDecoder == null) { - try { - bitmapRegionDecoder = BitmapRegionDecoder.newInstance(data, true); - if (bitmapRegionDecoder != null) { - break; - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - Thread.sleep(1000); + if (photoW == 0 || photoH == 0) { + BitmapFactory.Options bmOptions = new BitmapFactory.Options(); + bmOptions.inJustDecodeBounds = true; + BitmapFactory.decodeFile(data, bmOptions); + photoW = bmOptions.outWidth; + photoH = bmOptions.outHeight; } - if (bitmapRegionDecoder != null) { - Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(0, 0, AndroidUtilities.dp(44), AndroidUtilities.dp(44)), null); - int w = bitmap.getWidth(); - int h = bitmap.getHeight(); - for (int y = 0; y < h; y++) { - int rowCount = 0; - for (int x = 0; x < w; x++) { - int px = bitmap.getPixel(x, y); - if (px == 0xffffffff) { - rowCount++; - } else { - rowCount = 0; - } - if (rowCount > 8) { - break; - } - } - if (rowCount > 8) { - screenshotDates.add(date); - added = true; - break; - } - } - bitmapRegionDecoder.recycle(); - try { - if (bitmap != null) { - bitmap.recycle(); - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - try { - if (bitmapRegionDecoder != null) { - bitmapRegionDecoder.recycle(); - } - } catch (Exception e2) { - FileLog.e("tmessages", e2); - } - if (!added) { + if (photoW == 0 || photoH == 0 || (photoW == width && photoH == height || photoH == width && photoW == height)) { screenshotDates.add(date); } - }*/ - screenshotDates.add(date); + } catch (Exception e) { + screenshotDates.add(date); + } } - FileLog.e("tmessages", "screenshot!"); } cursor.close(); } @@ -1205,7 +1207,6 @@ public class MediaController implements NotificationCenter.NotificationCenterDel audioTrackPlayer = new AudioTrack(AudioManager.STREAM_MUSIC, 48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, playerBufferSize, AudioTrack.MODE_STREAM); audioTrackPlayer.setStereoVolume(1.0f, 1.0f); - //audioTrackPlayer.setNotificationMarkerPosition((int)currentTotalPcmDuration); audioTrackPlayer.setPlaybackPositionUpdateListener(new AudioTrack.OnPlaybackPositionUpdateListener() { @Override public void onMarkerReached(AudioTrack audioTrack) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 68e51bdc5..d7832c458 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -2424,10 +2424,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not chatActivityEnterView.setFieldFocused(false); MessagesController.getInstance().cancelTyping(dialog_id); - /*if (currentEncryptedChat != null) { disabled + if (currentEncryptedChat != null) { chatLeaveTime = System.currentTimeMillis(); updateInformationForScreenshotDetector(); - }*/ + } } private void updateInformationForScreenshotDetector() { diff --git a/TMessagesProj/src/main/res/drawable-v21/bar_selector.xml b/TMessagesProj/src/main/res/drawable-v21/bar_selector.xml new file mode 100644 index 000000000..7c7941ef9 --- /dev/null +++ b/TMessagesProj/src/main/res/drawable-v21/bar_selector.xml @@ -0,0 +1,4 @@ + + + diff --git a/TMessagesProj/src/main/res/drawable-v21/bar_selector_mode.xml b/TMessagesProj/src/main/res/drawable-v21/bar_selector_mode.xml new file mode 100644 index 000000000..386d01cee --- /dev/null +++ b/TMessagesProj/src/main/res/drawable-v21/bar_selector_mode.xml @@ -0,0 +1,4 @@ + + + diff --git a/TMessagesProj/src/main/res/drawable-v21/bar_selector_picker.xml b/TMessagesProj/src/main/res/drawable-v21/bar_selector_picker.xml new file mode 100644 index 000000000..8c28f1d3f --- /dev/null +++ b/TMessagesProj/src/main/res/drawable-v21/bar_selector_picker.xml @@ -0,0 +1,4 @@ + + + diff --git a/TMessagesProj/src/main/res/drawable-v21/bar_selector_style.xml b/TMessagesProj/src/main/res/drawable-v21/bar_selector_style.xml new file mode 100644 index 000000000..ed6784f52 --- /dev/null +++ b/TMessagesProj/src/main/res/drawable-v21/bar_selector_style.xml @@ -0,0 +1,4 @@ + + + diff --git a/TMessagesProj/src/main/res/drawable-v21/bar_selector_white.xml b/TMessagesProj/src/main/res/drawable-v21/bar_selector_white.xml new file mode 100644 index 000000000..46b442850 --- /dev/null +++ b/TMessagesProj/src/main/res/drawable-v21/bar_selector_white.xml @@ -0,0 +1,4 @@ + + + diff --git a/TMessagesProj/src/main/res/drawable-v21/list_selector.xml b/TMessagesProj/src/main/res/drawable-v21/list_selector.xml new file mode 100644 index 000000000..0ba2177bc --- /dev/null +++ b/TMessagesProj/src/main/res/drawable-v21/list_selector.xml @@ -0,0 +1,5 @@ + + + + diff --git a/TMessagesProj/src/main/res/layout/group_profile_add_member_layout.xml b/TMessagesProj/src/main/res/layout/group_profile_add_member_layout.xml index bb5acfc34..60c5e3e7d 100644 --- a/TMessagesProj/src/main/res/layout/group_profile_add_member_layout.xml +++ b/TMessagesProj/src/main/res/layout/group_profile_add_member_layout.xml @@ -15,7 +15,6 @@ android:id="@+id/done_button" android:paddingRight="16dp" android:paddingLeft="16dp" - android:background="@drawable/bar_selector" android:minHeight="60dp"/> \ No newline at end of file diff --git a/TMessagesProj/src/main/res/values-ar/strings.xml b/TMessagesProj/src/main/res/values-ar/strings.xml index b6bdf5658..846b80ddc 100644 --- a/TMessagesProj/src/main/res/values-ar/strings.xml +++ b/TMessagesProj/src/main/res/values-ar/strings.xml @@ -202,8 +202,12 @@ INFO الهاتف Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. تم تعيين كافة الإشعارات افتراضيا حجم نص الرسائل diff --git a/TMessagesProj/src/main/res/values-de/strings.xml b/TMessagesProj/src/main/res/values-de/strings.xml index 8db89f19f..2880d6f5e 100644 --- a/TMessagesProj/src/main/res/values-de/strings.xml +++ b/TMessagesProj/src/main/res/values-de/strings.xml @@ -202,8 +202,12 @@ INFO Telefon Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. Alle Einstellungen für Mitteilungen zurücksetzen Textgröße für Nachrichten diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml index 98c9d5fd6..b1fc02089 100644 --- a/TMessagesProj/src/main/res/values-es/strings.xml +++ b/TMessagesProj/src/main/res/values-es/strings.xml @@ -202,8 +202,12 @@ INFO Teléfono Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. Restablecer las notificaciones Tamaño del texto diff --git a/TMessagesProj/src/main/res/values-it/strings.xml b/TMessagesProj/src/main/res/values-it/strings.xml index cdab3e61d..46c1f7128 100644 --- a/TMessagesProj/src/main/res/values-it/strings.xml +++ b/TMessagesProj/src/main/res/values-it/strings.xml @@ -202,8 +202,12 @@ INFO Telefono Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. Ripristina tutte le impostazioni di notifica predefinite Dimensione testo messaggi diff --git a/TMessagesProj/src/main/res/values-ko/strings.xml b/TMessagesProj/src/main/res/values-ko/strings.xml index a61a43b31..9b62083e8 100644 --- a/TMessagesProj/src/main/res/values-ko/strings.xml +++ b/TMessagesProj/src/main/res/values-ko/strings.xml @@ -202,8 +202,12 @@ INFO 전화번호 Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. 모든 알림 설정이 초기화되었습니다 채팅 글자 크기 diff --git a/TMessagesProj/src/main/res/values-nl/strings.xml b/TMessagesProj/src/main/res/values-nl/strings.xml index c05fab203..dcb5fd21c 100644 --- a/TMessagesProj/src/main/res/values-nl/strings.xml +++ b/TMessagesProj/src/main/res/values-nl/strings.xml @@ -202,8 +202,12 @@ INFO Telefoon Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. Alle meldingsinstellingen herstellen Tekstgrootte berichten diff --git a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml index e4a8dadf2..37f19d0c9 100644 --- a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml +++ b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml @@ -202,8 +202,12 @@ INFO Telefone Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. Restaurar todas as configurações de notificação Tamanho do texto nas mensagens diff --git a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml index 894430297..af0f87210 100644 --- a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml +++ b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml @@ -202,8 +202,12 @@ INFO Telefone Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. Restaurar todas as configurações de notificação Tamanho do texto nas mensagens diff --git a/TMessagesProj/src/main/res/values-v21/styles.xml b/TMessagesProj/src/main/res/values-v21/styles.xml index c27fb0730..e9ca2a04b 100644 --- a/TMessagesProj/src/main/res/values-v21/styles.xml +++ b/TMessagesProj/src/main/res/values-v21/styles.xml @@ -27,7 +27,7 @@ @android:color/white @style/ActionBar.Transparent.TMessages.Item @style/Theme.TMessages.ListView - + @drawable/list_selector @style/Theme.TMessages.EditText @drawable/bar_selector_style diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index af9433480..c81884865 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -202,8 +202,12 @@ INFO Phone Username - Username already in use - Username invalid + Your Username + Sorry, this username is already taken. + Sorry, this username is invalid. + A username must have at least 5 characters. + Sorry, a username can't start with a number. + You can choose a username on ]]>Telegram]]>. If you do, other people will be able to find you by this username and contact you without knowing your phone number.\n\nYou can use ]]>a–z]]>, ]]>0–9]]> and underscores. Minimum length is ]]>5]]> characters. Reset all notification settings to default Messages Text Size