Update to 2.5.2.1
This commit is contained in:
parent
94763585e4
commit
a9c7a8fd18
@ -9,14 +9,14 @@
|
||||
<uses-feature android:name="android.hardware.LOCATION" android:required="false" />
|
||||
|
||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
||||
<uses-permission android:name="org.telegram.messenger.permission.MAPS_RECEIVE"/>
|
||||
<uses-permission android:name="org.telegram.messenger.permission.C2D_MESSAGE" />
|
||||
<uses-permission android:name="org.telegram.plus.permission.MAPS_RECEIVE"/>
|
||||
<uses-permission android:name="org.telegram.plus.permission.C2D_MESSAGE" />
|
||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<permission android:name="org.telegram.messenger.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
|
||||
<permission android:name="org.telegram.messenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
|
||||
<permission android:name="org.telegram.plus.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
|
||||
<permission android:name="org.telegram.plus.permission.C2D_MESSAGE" android:protectionLevel="signature" />
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
@ -24,10 +24,10 @@
|
||||
android:label="@string/AppName"
|
||||
android:theme="@style/Theme.TMessages.Start"
|
||||
android:name=".ApplicationLoader"
|
||||
android:hardwareAccelerated="true"
|
||||
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||
android:largeHeap="true">
|
||||
|
||||
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCTNmNqbWovP9ETcAob98YlrfOQEAC0CJ4" />
|
||||
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCZi83oDrfsCQ3_Aokfmlv53gTBYPIGJ2Q" /><!--AIzaSyCq2oezhsHUM0e_FPU-DpP93c0WxpEK4Fc-->
|
||||
|
||||
<activity android:name="net.hockeyapp.android.UpdateActivity" />
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
||||
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
|
||||
<category android:name="org.telegram.messenger" />
|
||||
<category android:name="org.telegram.plus" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
android:label="@string/AppName"
|
||||
android:theme="@style/Theme.TMessages.Start"
|
||||
android:name=".ApplicationLoader"
|
||||
android:hardwareAccelerated="true"
|
||||
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||
android:largeHeap="true">
|
||||
|
||||
</application>
|
||||
|
@ -9,14 +9,14 @@
|
||||
<uses-feature android:name="android.hardware.LOCATION" android:required="false" />
|
||||
|
||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
||||
<uses-permission android:name="org.telegram.messenger.permission.MAPS_RECEIVE"/>
|
||||
<uses-permission android:name="org.telegram.messenger.permission.C2D_MESSAGE" />
|
||||
<uses-permission android:name="org.telegram.plus.permission.MAPS_RECEIVE"/>
|
||||
<uses-permission android:name="org.telegram.plus.permission.C2D_MESSAGE" />
|
||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<permission android:name="org.telegram.messenger.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
|
||||
<permission android:name="org.telegram.messenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
|
||||
<permission android:name="org.telegram.plus.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
|
||||
<permission android:name="org.telegram.plus.permission.C2D_MESSAGE" android:protectionLevel="signature" />
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
@ -24,10 +24,10 @@
|
||||
android:label="@string/AppName"
|
||||
android:theme="@style/Theme.TMessages.Start"
|
||||
android:name=".ApplicationLoader"
|
||||
android:hardwareAccelerated="true"
|
||||
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||
android:largeHeap="true">
|
||||
|
||||
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyA-t0jLPjUt2FxrA8VPK2EiYHcYcboIR6k" />
|
||||
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyDn35qaQ9j2WRQC6fdu3VxD1bLfxxNNR3E" />
|
||||
|
||||
<activity android:name="net.hockeyapp.android.UpdateActivity" />
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
||||
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
|
||||
<category android:name="org.telegram.messenger" />
|
||||
<category android:name="org.telegram.plus" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
@ -104,7 +104,7 @@ include $(BUILD_STATIC_LIBRARY)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_PRELINK_MODULE := false
|
||||
LOCAL_STATIC_LIBRARIES := webp sqlite
|
||||
LOCAL_MODULE := tmessages.5
|
||||
LOCAL_MODULE := tmessages.6
|
||||
LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
|
||||
LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno
|
||||
LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -ffast-math
|
||||
|
@ -21,6 +21,9 @@ jmethodID jclass_Bitmap_createBitmap;
|
||||
jclass jclass_Config;
|
||||
jfieldID jclass_Config_ARGB_8888;
|
||||
|
||||
const uint32_t PGPhotoEnhanceHistogramBins = 256;
|
||||
const uint32_t PGPhotoEnhanceSegments = 4;
|
||||
|
||||
jclass createGlobarRef(JNIEnv *env, jclass class) {
|
||||
if (class) {
|
||||
return (*env)->NewGlobalRef(env, class);
|
||||
@ -312,6 +315,110 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jcl
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass class, jobject hsvBuffer, int width, int height, jobject buffer) {
|
||||
float imageWidth = width;
|
||||
float imageHeight = height;
|
||||
float _clipLimit = 1.25f;
|
||||
|
||||
uint32_t totalSegments = PGPhotoEnhanceSegments * PGPhotoEnhanceSegments;
|
||||
uint32_t tileArea = (uint32_t)(floorf(imageWidth / PGPhotoEnhanceSegments) * floorf(imageHeight / PGPhotoEnhanceSegments));
|
||||
uint32_t clipLimit = (uint32_t)max(1, _clipLimit * tileArea / (float) PGPhotoEnhanceHistogramBins);
|
||||
float scale = 255.0f / (float) tileArea;
|
||||
|
||||
|
||||
unsigned char *bytes = (*env)->GetDirectBufferAddress(env, hsvBuffer);
|
||||
|
||||
uint32_t **hist = calloc(totalSegments, sizeof(uint32_t *));
|
||||
uint32_t **cdfs = calloc(totalSegments, sizeof(uint32_t *));
|
||||
uint32_t *cdfsMin = calloc(totalSegments, sizeof(uint32_t));
|
||||
uint32_t *cdfsMax = calloc(totalSegments, sizeof(uint32_t));
|
||||
|
||||
for (uint32_t a = 0; a < totalSegments; a++) {
|
||||
hist[a] = calloc(PGPhotoEnhanceHistogramBins, sizeof(uint32_t));
|
||||
cdfs[a] = calloc(PGPhotoEnhanceHistogramBins, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
float xMul = PGPhotoEnhanceSegments / imageWidth;
|
||||
float yMul = PGPhotoEnhanceSegments / imageHeight;
|
||||
|
||||
for (uint32_t y = 0; y < imageHeight; y++) {
|
||||
uint32_t yOffset = y * width * 4;
|
||||
for (uint32_t x = 0; x < imageWidth; x++) {
|
||||
uint32_t index = x * 4 + yOffset;
|
||||
|
||||
uint32_t tx = (uint32_t)(x * xMul);
|
||||
uint32_t ty = (uint32_t)(y * yMul);
|
||||
uint32_t t = ty * PGPhotoEnhanceSegments + tx;
|
||||
|
||||
hist[t][bytes[index + 2]]++;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < totalSegments; i++) {
|
||||
if (clipLimit > 0) {
|
||||
uint32_t clipped = 0;
|
||||
for (uint32_t j = 0; j < PGPhotoEnhanceHistogramBins; ++j) {
|
||||
if (hist[i][j] > clipLimit) {
|
||||
clipped += hist[i][j] - clipLimit;
|
||||
hist[i][j] = clipLimit;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t redistBatch = clipped / PGPhotoEnhanceHistogramBins;
|
||||
uint32_t residual = clipped - redistBatch * PGPhotoEnhanceHistogramBins;
|
||||
|
||||
for (uint32_t j = 0; j < PGPhotoEnhanceHistogramBins; ++j) {
|
||||
hist[i][j] += redistBatch;
|
||||
}
|
||||
|
||||
for (uint32_t j = 0; j < residual; ++j) {
|
||||
hist[i][j]++;
|
||||
}
|
||||
}
|
||||
memcpy(cdfs[i], hist[i], PGPhotoEnhanceHistogramBins * sizeof(uint32_t));
|
||||
|
||||
uint32_t hMin = PGPhotoEnhanceHistogramBins - 1;
|
||||
for (uint32_t j = 0; j < hMin; ++j) {
|
||||
if (cdfs[j] != 0) {
|
||||
hMin = j;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t cdf = 0;
|
||||
for (uint32_t j = hMin; j < PGPhotoEnhanceHistogramBins; ++j) {
|
||||
cdf += cdfs[i][j];
|
||||
cdfs[i][j] = (uint8_t) min(255, cdf * scale);
|
||||
}
|
||||
|
||||
cdfsMin[i] = cdfs[i][hMin];
|
||||
cdfsMax[i] = cdfs[i][PGPhotoEnhanceHistogramBins - 1];
|
||||
}
|
||||
|
||||
uint32_t resultSize = 4 * PGPhotoEnhanceHistogramBins * totalSegments;
|
||||
uint32_t resultBytesPerRow = 4 * PGPhotoEnhanceHistogramBins;
|
||||
|
||||
unsigned char *result = (*env)->GetDirectBufferAddress(env, buffer);
|
||||
for (uint32_t tile = 0; tile < totalSegments; tile++) {
|
||||
uint32_t yOffset = tile * resultBytesPerRow;
|
||||
for (uint32_t i = 0; i < PGPhotoEnhanceHistogramBins; i++) {
|
||||
uint32_t index = i * 4 + yOffset;
|
||||
result[index] = (uint8_t)cdfs[tile][i];
|
||||
result[index + 1] = (uint8_t)cdfsMin[tile];
|
||||
result[index + 2] = (uint8_t)cdfsMax[tile];
|
||||
result[index + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t a = 0; a < totalSegments; a++) {
|
||||
free(hist[a]);
|
||||
free(cdfs[a]);
|
||||
}
|
||||
free(hist);
|
||||
free(cdfs);
|
||||
free(cdfsMax);
|
||||
free(cdfsMin);
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale, int width, int height, int stride) {
|
||||
|
||||
AndroidBitmapInfo info;
|
||||
|
BIN
TMessagesProj/libs/armeabi-v7a/libtmessages.5.so → TMessagesProj/libs/armeabi-v7a/libtmessages.6.so
Executable file → Normal file
BIN
TMessagesProj/libs/armeabi-v7a/libtmessages.5.so → TMessagesProj/libs/armeabi-v7a/libtmessages.6.so
Executable file → Normal file
Binary file not shown.
BIN
TMessagesProj/libs/armeabi/libtmessages.5.so → TMessagesProj/libs/armeabi/libtmessages.6.so
Executable file → Normal file
BIN
TMessagesProj/libs/armeabi/libtmessages.5.so → TMessagesProj/libs/armeabi/libtmessages.6.so
Executable file → Normal file
Binary file not shown.
BIN
TMessagesProj/libs/x86/libtmessages.5.so → TMessagesProj/libs/x86/libtmessages.6.so
Executable file → Normal file
BIN
TMessagesProj/libs/x86/libtmessages.5.so → TMessagesProj/libs/x86/libtmessages.6.so
Executable file → Normal file
Binary file not shown.
@ -43,7 +43,7 @@
|
||||
<application
|
||||
android:name=".ApplicationLoader"
|
||||
android:allowBackup="false"
|
||||
android:hardwareAccelerated="true"
|
||||
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/AppName"
|
||||
android:largeHeap="true"
|
||||
@ -52,7 +52,7 @@
|
||||
<activity
|
||||
android:name="org.telegram.ui.LaunchActivity"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||
android:hardwareAccelerated="true"
|
||||
android:hardwareAccelerated="@bool/useHardwareAcceleration"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustPan">
|
||||
<intent-filter>
|
||||
|
@ -28,7 +28,7 @@ public class ByteStream {
|
||||
private final ArrayList<ByteBufferDesc> queue;
|
||||
|
||||
public ByteStream() {
|
||||
this.queue = new ArrayList<ByteBufferDesc>();
|
||||
this.queue = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void append(ByteBufferDesc buf) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
package org.telegram.PhoneFormat;
|
||||
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
@ -97,9 +98,11 @@ public class PhoneFormat {
|
||||
}
|
||||
|
||||
public void init(String countryCode) {
|
||||
InputStream stream = null;
|
||||
ByteArrayOutputStream bos = null;
|
||||
try {
|
||||
InputStream stream = ApplicationLoader.applicationContext.getAssets().open("PhoneFormats.dat");
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
stream = ApplicationLoader.applicationContext.getAssets().open("PhoneFormats.dat");
|
||||
bos = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = stream.read(buf, 0, 1024)) != -1) {
|
||||
@ -111,6 +114,21 @@ public class PhoneFormat {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} finally {
|
||||
try {
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
try {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (countryCode != null && countryCode.length() != 0) {
|
||||
@ -119,10 +137,10 @@ public class PhoneFormat {
|
||||
Locale loc = Locale.getDefault();
|
||||
defaultCountry = loc.getCountry().toLowerCase();
|
||||
}
|
||||
callingCodeOffsets = new HashMap<String, Integer>(255);
|
||||
callingCodeCountries = new HashMap<String, ArrayList<String>>(255);
|
||||
callingCodeData = new HashMap<String, CallingCodeInfo>(10);
|
||||
countryCallingCode = new HashMap<String, String>(255);
|
||||
callingCodeOffsets = new HashMap<>(255);
|
||||
callingCodeCountries = new HashMap<>(255);
|
||||
callingCodeData = new HashMap<>(10);
|
||||
countryCallingCode = new HashMap<>(255);
|
||||
|
||||
parseDataHeader();
|
||||
initialzed = true;
|
||||
@ -293,7 +311,7 @@ public class PhoneFormat {
|
||||
|
||||
offset += 2;
|
||||
|
||||
ArrayList<String> strs = new ArrayList<String>(5);
|
||||
ArrayList<String> strs = new ArrayList<>(5);
|
||||
String str;
|
||||
while ((str = valueString(offset)).length() != 0) {
|
||||
strs.add(str);
|
||||
@ -302,14 +320,14 @@ public class PhoneFormat {
|
||||
res.trunkPrefixes = strs;
|
||||
offset++;
|
||||
|
||||
strs = new ArrayList<String>(5);
|
||||
strs = new ArrayList<>(5);
|
||||
while ((str = valueString(offset)).length() != 0) {
|
||||
strs.add(str);
|
||||
offset += str.length() + 1;
|
||||
}
|
||||
res.intlPrefixes = strs;
|
||||
|
||||
ArrayList<RuleSet> ruleSets = new ArrayList<RuleSet>(setCnt);
|
||||
ArrayList<RuleSet> ruleSets = new ArrayList<>(setCnt);
|
||||
offset = start + block1Len;
|
||||
for (int s = 0; s < setCnt; s++) {
|
||||
RuleSet ruleSet = new RuleSet();
|
||||
@ -317,7 +335,7 @@ public class PhoneFormat {
|
||||
offset += 2;
|
||||
int ruleCnt = value16(offset);
|
||||
offset += 2;
|
||||
ArrayList<PhoneRule> rules = new ArrayList<PhoneRule>(ruleCnt);
|
||||
ArrayList<PhoneRule> rules = new ArrayList<>(ruleCnt);
|
||||
for (int r = 0; r < ruleCnt; r++) {
|
||||
PhoneRule rule = new PhoneRule();
|
||||
rule.minVal = value32(offset);
|
||||
@ -380,7 +398,7 @@ public class PhoneFormat {
|
||||
callingCodeOffsets.put(callingCode, offset);
|
||||
ArrayList<String> countries = callingCodeCountries.get(callingCode);
|
||||
if (countries == null) {
|
||||
countries = new ArrayList<String>();
|
||||
countries = new ArrayList<>();
|
||||
callingCodeCountries.put(callingCode, countries);
|
||||
}
|
||||
countries.add(country);
|
||||
|
@ -9,20 +9,30 @@
|
||||
package org.telegram.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.StateSet;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
@ -33,20 +43,34 @@ import android.widget.AbsListView;
|
||||
import android.widget.EdgeEffect;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.ui.ActionBar.ActionBar;
|
||||
import org.telegram.ui.Components.ForegroundDetector;
|
||||
import org.telegram.ui.Components.NumberPicker;
|
||||
import org.telegram.ui.Components.TypefaceSpan;
|
||||
import org.telegram.ui.LaunchActivity;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidUtilities {
|
||||
|
||||
@ -59,15 +83,26 @@ public class AndroidUtilities {
|
||||
public static float density = 1;
|
||||
public static Point displaySize = new Point();
|
||||
public static Integer photoSize = null;
|
||||
public static DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
private static Boolean isTablet = null;
|
||||
|
||||
public static final String THEME_PREFS = "theme";
|
||||
private static final String TAG = "AndroidUtilities";
|
||||
public static final int defColor = 0xff58BCD5;//0xff43C3DB;//0xff2f8cc9;58BCD5//0xff55abd2
|
||||
public static int themeColor = getIntColor("themeColor");
|
||||
|
||||
public static boolean needRestart = false;
|
||||
|
||||
//public static boolean hideScreenshot = false;
|
||||
//public static boolean hideMobile = false;
|
||||
|
||||
static {
|
||||
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
|
||||
checkDisplaySize();
|
||||
}
|
||||
|
||||
public static void lockOrientation(Activity activity) {
|
||||
if (activity == null || prevOrientation != -10) {
|
||||
if (activity == null || prevOrientation != -10 || Build.VERSION.SDK_INT < 9) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@ -115,7 +150,7 @@ public class AndroidUtilities {
|
||||
}
|
||||
|
||||
public static void unlockOrientation(Activity activity) {
|
||||
if (activity == null) {
|
||||
if (activity == null || Build.VERSION.SDK_INT < 9) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@ -228,12 +263,13 @@ public class AndroidUtilities {
|
||||
if (manager != null) {
|
||||
Display display = manager.getDefaultDisplay();
|
||||
if (display != null) {
|
||||
display.getMetrics(displayMetrics);
|
||||
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);
|
||||
FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y + " " + displayMetrics.xdpi + "x" + displayMetrics.ydpi);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -241,6 +277,10 @@ public class AndroidUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
public static float getPixelsInCM(float cm, boolean isX) {
|
||||
return (cm / 2.54f) * (isX ? displayMetrics.xdpi : displayMetrics.ydpi);
|
||||
}
|
||||
|
||||
public static long makeBroadcastId(int id) {
|
||||
return 0x0000000100000000L | ((long)id & 0x00000000FFFFFFFFL);
|
||||
}
|
||||
@ -421,6 +461,19 @@ public class AndroidUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setProgressBarAnimationDuration(ProgressBar progressBar, int duration) {
|
||||
if (progressBar == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Field mCursorDrawableRes = ProgressBar.class.getDeclaredField("mDuration");
|
||||
mCursorDrawableRes.setAccessible(true);
|
||||
mCursorDrawableRes.setInt(progressBar, duration);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getViewInset(View view) {
|
||||
if (view == null || Build.VERSION.SDK_INT < 21) {
|
||||
return 0;
|
||||
@ -530,4 +583,364 @@ public class AndroidUtilities {
|
||||
}
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
public static boolean needShowPasscode(boolean reset) {
|
||||
boolean wasInBackground;
|
||||
if (Build.VERSION.SDK_INT >= 14) {
|
||||
wasInBackground = ForegroundDetector.getInstance().isWasInBackground(reset);
|
||||
if (reset) {
|
||||
ForegroundDetector.getInstance().resetBackgroundVar();
|
||||
}
|
||||
} else {
|
||||
wasInBackground = UserConfig.lastPauseTime != 0;
|
||||
}
|
||||
return UserConfig.passcodeHash.length() > 0 && wasInBackground &&
|
||||
(UserConfig.appLocked || UserConfig.autoLockIn != 0 && UserConfig.lastPauseTime != 0 && !UserConfig.appLocked && (UserConfig.lastPauseTime + UserConfig.autoLockIn) <= ConnectionsManager.getInstance().getCurrentTime());
|
||||
}
|
||||
|
||||
/*public static void turnOffHardwareAcceleration(Window window) {
|
||||
if (window == null || Build.MODEL == null || Build.VERSION.SDK_INT < 11) {
|
||||
return;
|
||||
}
|
||||
if (Build.MODEL.contains("GT-S5301") ||
|
||||
Build.MODEL.contains("GT-S5303") ||
|
||||
Build.MODEL.contains("GT-B5330") ||
|
||||
Build.MODEL.contains("GT-S5302") ||
|
||||
Build.MODEL.contains("GT-S6012B") ||
|
||||
Build.MODEL.contains("MegaFon_SP-AI")) {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||
}
|
||||
}*/
|
||||
//NEW
|
||||
public static int getIntColor(String key){
|
||||
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
return themePrefs.getInt(key, defColor);
|
||||
}
|
||||
|
||||
public static int getIntDef(String key, int def){
|
||||
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
return themePrefs.getInt(key, def);
|
||||
}
|
||||
|
||||
public static int getIntAlphaColor(String key, float factor){
|
||||
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
int color = themePrefs.getInt(key, defColor);
|
||||
int alpha = Math.round(Color.alpha(color) * factor);
|
||||
int red = Color.red(color);
|
||||
int green = Color.green(color);
|
||||
int blue = Color.blue(color);
|
||||
return Color.argb(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
public static int getIntDarkerColor(String key, int factor){
|
||||
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
int color = themePrefs.getInt(key, defColor);
|
||||
return setDarkColor(color, factor);
|
||||
}
|
||||
|
||||
public static int setDarkColor(int color, int factor){
|
||||
int red = Color.red(color) - factor;
|
||||
int green = Color.green(color) - factor;
|
||||
int blue = Color.blue(color) - factor;
|
||||
if(factor < 0){
|
||||
red = (red > 0xff) ? 0xff : red;
|
||||
green = (green > 0xff) ? 0xff : green;
|
||||
blue = (blue > 0xff) ? 0xff : blue;
|
||||
if(red == 0xff && green == 0xff && blue == 0xff){
|
||||
red = factor;
|
||||
green = factor;
|
||||
blue = factor;
|
||||
}
|
||||
}
|
||||
if(factor > 0){
|
||||
red = (red < 0) ? 0 : red;
|
||||
green = (green < 0) ? 0 : green;
|
||||
blue = (blue < 0) ? 0 : blue;
|
||||
if(red == 0 && green == 0 && blue == 0){
|
||||
red = factor;
|
||||
green = factor;
|
||||
blue = factor;
|
||||
}
|
||||
}
|
||||
return Color.argb(0xff, red, green, blue);
|
||||
}
|
||||
|
||||
public static void setIntColor(String key, int value){
|
||||
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor e = themePrefs.edit();
|
||||
e.putInt(key, value);
|
||||
e.commit();
|
||||
}
|
||||
|
||||
public static void setBoolPref(Context context, String key, Boolean b){
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(THEME_PREFS, 0);
|
||||
SharedPreferences.Editor e = sharedPref.edit();
|
||||
e.putBoolean(key, b);
|
||||
e.commit();
|
||||
}
|
||||
|
||||
public static void setStringPref(Context context, String key, String s){
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(THEME_PREFS, 0);
|
||||
SharedPreferences.Editor e = sharedPref.edit();
|
||||
e.putString(key, s);
|
||||
e.commit();
|
||||
}
|
||||
|
||||
public static boolean getBoolPref(Context context,String key){
|
||||
boolean s = false;
|
||||
if (context.getSharedPreferences(THEME_PREFS, 0).getBoolean(key, false)) s=true;
|
||||
return s;
|
||||
}
|
||||
|
||||
public static boolean getBoolMain(String key){
|
||||
boolean s = false;
|
||||
if (ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean(key, false)) s=true;
|
||||
return s;
|
||||
}
|
||||
|
||||
public static int getIntPref(Context context,String key){
|
||||
int i=0;
|
||||
if(key.contains("picker")){
|
||||
int intColor = context.getSharedPreferences(THEME_PREFS, 0).getInt(key, Color.WHITE );
|
||||
i=intColor;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
/*
|
||||
public static int getIntColorDef(Context context, String key, int def){
|
||||
int i=def;
|
||||
if(context.getSharedPreferences(THEME_PREFS, 0).getBoolean(key, false)){
|
||||
i = context.getSharedPreferences(THEME_PREFS, 0).getInt(key.replace("_check", "_picker"), def);
|
||||
}
|
||||
return i;
|
||||
}*/
|
||||
|
||||
public static void setTVTextColor(Context ctx, TextView tv, String key, int def){
|
||||
if(tv==null)return;
|
||||
if(getBoolPref(ctx, key))
|
||||
def = getIntPref(ctx, key.replace("_check", "_picker"));
|
||||
tv.setTextColor(def);
|
||||
}
|
||||
|
||||
public static int getSizePref(Context context,String key, int def){
|
||||
if(key.contains("picker"))return context.getSharedPreferences(THEME_PREFS, 0).getInt(key, def);
|
||||
return def;
|
||||
}
|
||||
|
||||
public static void paintActionBarHeader(Activity a, ActionBar ab, String hdCheck, String gdMode){
|
||||
if(ab==null)return;
|
||||
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#54759E")));
|
||||
if(getBoolPref(a, hdCheck)){
|
||||
int i = getIntPref(a, hdCheck.replace("_check", "_picker"));
|
||||
Drawable d = new ColorDrawable(i);
|
||||
try{
|
||||
ab.setBackgroundDrawable(d);
|
||||
d = paintGradient(a,i,gdMode.replace("mode","color_picker"),gdMode);
|
||||
if(d!=null)ab.setBackgroundDrawable(d);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Drawable paintGradient(Context c, int mainColor, String gColor, String g){
|
||||
GradientDrawable gd = null;
|
||||
int[] a ={mainColor,getIntPref(c,gColor)};
|
||||
int gType = Integer.parseInt(c.getSharedPreferences(THEME_PREFS, 0).getString(g, "0"));
|
||||
if(gType==2) gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,a);
|
||||
if(gType==1) gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM ,a);
|
||||
return gd;
|
||||
}
|
||||
|
||||
public static Drawable paintDrawable(Context c, int resId, int resIdW, String color){
|
||||
Drawable d = c.getResources().getDrawable(resId);
|
||||
if(color.contains("_check")){
|
||||
if(getBoolPref(c, color)){
|
||||
d = c.getResources().getDrawable(resIdW);
|
||||
d.setColorFilter(getIntPref(c, color.replace("_check", "_picker")), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
public static void restartApp(){
|
||||
Intent mRestartApp = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
|
||||
int mPendingIntentId = 123456;
|
||||
PendingIntent mPendingIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, mPendingIntentId, mRestartApp, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
AlarmManager mgr = (AlarmManager)ApplicationLoader.applicationContext.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public static void savePreferencesToSD(Context context, String prefName, String tName, boolean toast){
|
||||
String folder = "/Telegram/Themes";
|
||||
File dataF = new File (findPrefFolder(context),prefName);
|
||||
if(checkSDStatus() > 1){
|
||||
File f = new File (Environment.getExternalStorageDirectory(), folder);
|
||||
f.mkdirs();
|
||||
File sdF = new File(f, tName);
|
||||
String s = getError(copyFile(dataF,sdF,true));
|
||||
if (s.equalsIgnoreCase("4")) {
|
||||
if(toast && sdF.getName()!="")Toast.makeText(context,context.getString(R.string.SavedTo,sdF.getName(),folder),Toast.LENGTH_SHORT ).show();
|
||||
}else if (s.contains("0")) {
|
||||
s = context.getString(R.string.SaveErrorMsg0);
|
||||
Toast.makeText(context,"ERROR: "+ s ,Toast.LENGTH_LONG ).show();
|
||||
}else{
|
||||
Toast.makeText(context,"ERROR: "+s,Toast.LENGTH_LONG ).show();
|
||||
Toast.makeText(context,dataF.getAbsolutePath(),Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
}else{
|
||||
Toast.makeText(context,"ERROR: " + context.getString(R.string.NoMediaMessage) , Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyWallpaperToSD(Context context, String tName, boolean toast){
|
||||
String folder = "/Telegram/Themes";
|
||||
String nFile = "wallpaper.jpg";
|
||||
if(checkSDStatus()>0){
|
||||
File f1 = context.getFilesDir();
|
||||
f1 = new File (f1.getAbsolutePath(), nFile);
|
||||
File f2 = new File (Environment.getExternalStorageDirectory(), folder);
|
||||
f2.mkdirs();
|
||||
f2 = new File(f2, tName+"_"+nFile);
|
||||
if(f1.length()>1){
|
||||
String s = getError(copyFile(f1,f2,true));
|
||||
if(s.contains("4")){
|
||||
if(toast && f2.getName()!="" && folder !="")Toast.makeText(context,context.getString(R.string.SavedTo,f2.getName(),folder),Toast.LENGTH_SHORT ).show();
|
||||
if(f2.getName()=="" || folder =="") Toast.makeText(context,"ERROR: "+s,Toast.LENGTH_SHORT ).show();
|
||||
|
||||
}else{
|
||||
Toast.makeText(context,"ERROR: "+s+"\n"+f1.getAbsolutePath(),Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String findPrefFolder(Context context){
|
||||
File f = context.getFilesDir();
|
||||
String appDir = f.getAbsolutePath();
|
||||
File SPDir = new File (appDir.substring(0,appDir.lastIndexOf('/')+1)+ "shared_prefs/");
|
||||
if(!SPDir.exists()) {// && SPDir.isDirectory()) {
|
||||
String pck = context.getPackageName();
|
||||
SPDir=new File ("/dbdata/databases/"+pck+"/shared_prefs/");
|
||||
}
|
||||
//Log.i("TAG", SPDir.getAbsolutePath());
|
||||
return SPDir.getAbsolutePath();
|
||||
}
|
||||
|
||||
static int checkSDStatus(){
|
||||
int b=0;
|
||||
String s = Environment.getExternalStorageState();
|
||||
if (s.equals(Environment.MEDIA_MOUNTED))b=2;
|
||||
else if (s.equals(Environment.MEDIA_MOUNTED_READ_ONLY))b=1;
|
||||
return b;
|
||||
}
|
||||
|
||||
static String getError(int i){
|
||||
String s="-1";
|
||||
if(i==0)s="0: SOURCE FILE DOESN'T EXIST";
|
||||
if(i==1)s="1: DESTINATION FILE DOESN'T EXIST";
|
||||
if(i==2)s="2: NULL SOURCE & DESTINATION FILES";
|
||||
if(i==3)s="3: NULL SOURCE FILE";
|
||||
if(i==4)s="4";
|
||||
return s;
|
||||
}
|
||||
|
||||
//0: source file doesn't exist
|
||||
//1: dest file doesn't exist
|
||||
//2: source & dest = NULL
|
||||
//3: source = NULL
|
||||
//4: dest = NULL
|
||||
static int copyFile(File sourceFile, File destFile, boolean save) {
|
||||
int i=-1;
|
||||
try{
|
||||
if (!sourceFile.exists()) {
|
||||
return i+1;
|
||||
}
|
||||
if (!destFile.exists()) {
|
||||
if(save)i=i+2;
|
||||
destFile.createNewFile();
|
||||
}
|
||||
FileChannel source = null;
|
||||
FileChannel destination = null;
|
||||
FileInputStream fileInputStream = new FileInputStream(sourceFile);
|
||||
source = fileInputStream.getChannel();
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(destFile);
|
||||
destination = fileOutputStream.getChannel();
|
||||
if (destination != null && source != null) {
|
||||
destination.transferFrom(source, 0, source.size());
|
||||
i=2;
|
||||
}
|
||||
if (source != null) {
|
||||
source.close();
|
||||
i=3;
|
||||
}
|
||||
if (destination != null) {
|
||||
destination.close();
|
||||
i=4;
|
||||
}
|
||||
fileInputStream.close();
|
||||
fileOutputStream.close();
|
||||
}catch (Exception e)
|
||||
{
|
||||
System.err.println("Error saving preferences: " + e.getMessage());
|
||||
Log.e(e.getMessage() , e.toString());
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static int loadPrefFromSD(Context context, String prefPath){
|
||||
File dataF = new File (findPrefFolder(context), THEME_PREFS + ".xml");
|
||||
File prefFile = new File (prefPath);
|
||||
String s = getError(copyFile(prefFile, dataF, false));
|
||||
if (s.contains("0")) {
|
||||
Toast.makeText(context,"ERROR: "+ context.getString(R.string.restoreErrorMsg, prefFile.getAbsolutePath()) , Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
public static int loadWallpaperFromSDPath(Context context, String wPath){
|
||||
String nFile = "wallpaper.jpg";
|
||||
File f1 = context.getFilesDir();
|
||||
f1= new File (f1.getAbsolutePath(), nFile);
|
||||
//Log.i("f1", f1.getAbsolutePath());
|
||||
File wFile = new File (wPath);
|
||||
//Log.i("wPath", wPath);
|
||||
//Log.i("wFile", wFile.getAbsolutePath());
|
||||
String s = "-1";
|
||||
if (wFile.exists()){
|
||||
s = getError(copyFile(wFile,f1,false));
|
||||
if (s.contains("0")) {
|
||||
Toast.makeText(context,"ERROR: "+ context.getString(R.string.restoreErrorMsg,wFile.getAbsolutePath()) ,Toast.LENGTH_LONG ).show();
|
||||
}else{
|
||||
Toast.makeText(context,"ERROR: "+s+"\n"+wFile.getAbsolutePath(),Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
}
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
/*
|
||||
static void modifyXMLfile(File preffile,String sname){
|
||||
try {
|
||||
File file = preffile;
|
||||
//Log.e("modifyXMLfile",preffile.getAbsolutePath());
|
||||
//Log.e("modifyXMLfile",preffile.exists()+"");
|
||||
List<String> lines = new ArrayList<String>();
|
||||
// first, read the file and store the changes
|
||||
BufferedReader in = new BufferedReader(new FileReader(file));
|
||||
String line = in.readLine();
|
||||
while (line != null) {
|
||||
if (!line.contains(sname))lines.add(line);
|
||||
//Log.e("modifyXMLfile",line);
|
||||
line = in.readLine();
|
||||
}
|
||||
in.close();
|
||||
// now, write the file again with the changes
|
||||
PrintWriter out = new PrintWriter(file);
|
||||
for (String l : lines)
|
||||
out.println(l);
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ public class ContactsController {
|
||||
private ArrayList<Integer> delayedContactsUpdate = new ArrayList<>();
|
||||
private String inviteText;
|
||||
private boolean updatingInviteText = false;
|
||||
private HashMap<String, String> sectionsToReplace = new HashMap<>();
|
||||
|
||||
private int loadingDeleteInfo = 0;
|
||||
private int deleteAccountTTL;
|
||||
@ -114,6 +115,28 @@ public class ContactsController {
|
||||
if (preferences.getBoolean("needGetStatuses", false)) {
|
||||
reloadContactsStatuses();
|
||||
}
|
||||
|
||||
sectionsToReplace.put("À", "A");
|
||||
sectionsToReplace.put("Á", "A");
|
||||
sectionsToReplace.put("Ä", "A");
|
||||
sectionsToReplace.put("Ù", "U");
|
||||
sectionsToReplace.put("Ú", "U");
|
||||
sectionsToReplace.put("Ü", "U");
|
||||
sectionsToReplace.put("Ì", "I");
|
||||
sectionsToReplace.put("Í", "I");
|
||||
sectionsToReplace.put("Ï", "I");
|
||||
sectionsToReplace.put("È", "E");
|
||||
sectionsToReplace.put("É", "E");
|
||||
sectionsToReplace.put("Ê", "E");
|
||||
sectionsToReplace.put("Ë", "E");
|
||||
sectionsToReplace.put("Ò", "O");
|
||||
sectionsToReplace.put("Ó", "O");
|
||||
sectionsToReplace.put("Ö", "O");
|
||||
sectionsToReplace.put("Ç", "C");
|
||||
sectionsToReplace.put("Ñ", "N");
|
||||
sectionsToReplace.put("Ÿ", "Y");
|
||||
sectionsToReplace.put("Ý", "Y");
|
||||
sectionsToReplace.put("Ţ", "Y");
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
@ -514,10 +537,10 @@ public class ContactsController {
|
||||
checkContactsInternal();
|
||||
}
|
||||
final HashMap<Integer, Contact> contactsMap = readContactsFromPhoneBook();
|
||||
final HashMap<String, Contact> contactsBookShort = new HashMap<String, Contact>();
|
||||
final HashMap<String, Contact> contactsBookShort = new HashMap<>();
|
||||
int oldCount = contactHashMap.size();
|
||||
|
||||
ArrayList<TLRPC.TL_inputPhoneContact> toImport = new ArrayList<TLRPC.TL_inputPhoneContact>();
|
||||
ArrayList<TLRPC.TL_inputPhoneContact> toImport = new ArrayList<>();
|
||||
if (!contactHashMap.isEmpty()) {
|
||||
for (HashMap.Entry<Integer, Contact> pair : contactsMap.entrySet()) {
|
||||
Integer id = pair.getKey();
|
||||
@ -619,10 +642,10 @@ public class ContactsController {
|
||||
}
|
||||
}
|
||||
|
||||
final ArrayList<TLRPC.User> toDelete = new ArrayList<TLRPC.User>();
|
||||
final ArrayList<TLRPC.User> toDelete = new ArrayList<>();
|
||||
if (contactHashMap != null && !contactHashMap.isEmpty()) {
|
||||
try {
|
||||
final HashMap<String, TLRPC.User> contactsPhonesShort = new HashMap<String, TLRPC.User>();
|
||||
final HashMap<String, TLRPC.User> contactsPhonesShort = new HashMap<>();
|
||||
|
||||
for (TLRPC.TL_contact value : contacts) {
|
||||
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
||||
@ -692,7 +715,7 @@ public class ContactsController {
|
||||
}
|
||||
final int count = (int)Math.ceil(toImport.size() / 500.0f);
|
||||
for (int a = 0; a < count; a++) {
|
||||
ArrayList<TLRPC.TL_inputPhoneContact> finalToImport = new ArrayList<TLRPC.TL_inputPhoneContact>();
|
||||
ArrayList<TLRPC.TL_inputPhoneContact> finalToImport = new ArrayList<>();
|
||||
finalToImport.addAll(toImport.subList(a * 500, Math.min((a + 1) * 500, toImport.size())));
|
||||
TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
|
||||
req.contacts = finalToImport;
|
||||
@ -713,7 +736,7 @@ public class ContactsController {
|
||||
// }
|
||||
}
|
||||
MessagesStorage.getInstance().putUsersAndChats(res.users, null, true, true);
|
||||
ArrayList<TLRPC.TL_contact> cArr = new ArrayList<TLRPC.TL_contact>();
|
||||
ArrayList<TLRPC.TL_contact> cArr = new ArrayList<>();
|
||||
for (TLRPC.TL_importedContact c : res.imported) {
|
||||
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
||||
contact.user_id = c.user_id;
|
||||
@ -848,7 +871,7 @@ public class ContactsController {
|
||||
public void run() {
|
||||
MessagesController.getInstance().putUsers(usersArr, from == 1);
|
||||
|
||||
final HashMap<Integer, TLRPC.User> usersDict = new HashMap<Integer, TLRPC.User>();
|
||||
final HashMap<Integer, TLRPC.User> usersDict = new HashMap<>();
|
||||
|
||||
final boolean isEmpty = contactsArr.isEmpty();
|
||||
|
||||
@ -933,9 +956,9 @@ public class ContactsController {
|
||||
}
|
||||
});
|
||||
|
||||
final SparseArray<TLRPC.TL_contact> contactsDictionary = new SparseArray<TLRPC.TL_contact>();
|
||||
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<String, ArrayList<TLRPC.TL_contact>>();
|
||||
final ArrayList<String> sortedSectionsArray = new ArrayList<String>();
|
||||
final SparseArray<TLRPC.TL_contact> contactsDictionary = new SparseArray<>();
|
||||
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
|
||||
final ArrayList<String> sortedSectionsArray = new ArrayList<>();
|
||||
HashMap<String, TLRPC.TL_contact> contactsByPhonesDict = null;
|
||||
|
||||
if (!contactsBookLoaded) {
|
||||
@ -958,13 +981,17 @@ public class ContactsController {
|
||||
if (key == null || key.length() == 0) {
|
||||
key = user.last_name;
|
||||
}
|
||||
if (key.length() > 1) {
|
||||
key = key.substring(0, 1);
|
||||
}
|
||||
if (key.length() == 0) {
|
||||
key = "#";
|
||||
} else {
|
||||
key = key.toUpperCase();
|
||||
}
|
||||
if (key.length() > 1) {
|
||||
key = key.substring(0, 1);
|
||||
String replace = sectionsToReplace.get(key);
|
||||
if (replace != null) {
|
||||
key = replace;
|
||||
}
|
||||
ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
|
||||
if (arr == null) {
|
||||
@ -1067,7 +1094,7 @@ public class ContactsController {
|
||||
}
|
||||
|
||||
private void updateUnregisteredContacts(final ArrayList<TLRPC.TL_contact> contactsArr) {
|
||||
final HashMap<String, TLRPC.TL_contact> contactsPhonesShort = new HashMap<String, TLRPC.TL_contact>();
|
||||
final HashMap<String, TLRPC.TL_contact> contactsPhonesShort = new HashMap<>();
|
||||
|
||||
for (TLRPC.TL_contact value : contactsArr) {
|
||||
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
||||
@ -1077,7 +1104,7 @@ public class ContactsController {
|
||||
contactsPhonesShort.put(user.phone, value);
|
||||
}
|
||||
|
||||
final ArrayList<Contact> sortedPhoneBookContacts = new ArrayList<Contact>();
|
||||
final ArrayList<Contact> sortedPhoneBookContacts = new ArrayList<>();
|
||||
for (HashMap.Entry<Integer, Contact> pair : contactsBook.entrySet()) {
|
||||
Contact value = pair.getValue();
|
||||
int id = pair.getKey();
|
||||
@ -1135,8 +1162,8 @@ public class ContactsController {
|
||||
}
|
||||
|
||||
StringBuilder ids = new StringBuilder();
|
||||
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<String, ArrayList<TLRPC.TL_contact>>();
|
||||
final ArrayList<String> sortedSectionsArray = new ArrayList<String>();
|
||||
final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
|
||||
final ArrayList<String> sortedSectionsArray = new ArrayList<>();
|
||||
|
||||
for (TLRPC.TL_contact value : contacts) {
|
||||
TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
|
||||
@ -1148,17 +1175,21 @@ public class ContactsController {
|
||||
if (key == null || key.length() == 0) {
|
||||
key = user.last_name;
|
||||
}
|
||||
if (key.length() > 1) {
|
||||
key = key.substring(0, 1);
|
||||
}
|
||||
if (key.length() == 0) {
|
||||
key = "#";
|
||||
} else {
|
||||
key = key.toUpperCase();
|
||||
}
|
||||
if (key.length() > 1) {
|
||||
key = key.substring(0, 1);
|
||||
String replace = sectionsToReplace.get(key);
|
||||
if (replace != null) {
|
||||
key = replace;
|
||||
}
|
||||
ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
|
||||
if (arr == null) {
|
||||
arr = new ArrayList<TLRPC.TL_contact>();
|
||||
arr = new ArrayList<>();
|
||||
sectionsDict.put(key, arr);
|
||||
sortedSectionsArray.add(key);
|
||||
}
|
||||
@ -1193,7 +1224,7 @@ public class ContactsController {
|
||||
try {
|
||||
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
|
||||
Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
|
||||
HashMap<Integer, Long> bookContacts = new HashMap<Integer, Long>();
|
||||
HashMap<Integer, Long> bookContacts = new HashMap<>();
|
||||
if (c1 != null) {
|
||||
while (c1.moveToNext()) {
|
||||
bookContacts.put(c1.getInt(1), c1.getLong(0));
|
||||
@ -1213,7 +1244,7 @@ public class ContactsController {
|
||||
}
|
||||
|
||||
private void performWriteContactsToPhoneBook() {
|
||||
final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<TLRPC.TL_contact>();
|
||||
final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<>();
|
||||
contactsArray.addAll(contacts);
|
||||
Utilities.photoBookQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
@ -1225,8 +1256,8 @@ public class ContactsController {
|
||||
|
||||
private void applyContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict, ArrayList<TLRPC.TL_contact> newC, ArrayList<Integer> contactsTD) {
|
||||
if (newC == null || contactsTD == null) {
|
||||
newC = new ArrayList<TLRPC.TL_contact>();
|
||||
contactsTD = new ArrayList<Integer>();
|
||||
newC = new ArrayList<>();
|
||||
contactsTD = new ArrayList<>();
|
||||
for (Integer uid : ids) {
|
||||
if (uid > 0) {
|
||||
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
||||
@ -1351,8 +1382,8 @@ public class ContactsController {
|
||||
}
|
||||
|
||||
public void processContactsUpdates(ArrayList<Integer> ids, ConcurrentHashMap<Integer, TLRPC.User> userDict) {
|
||||
final ArrayList<TLRPC.TL_contact> newContacts = new ArrayList<TLRPC.TL_contact>();
|
||||
final ArrayList<Integer> contactsToDelete = new ArrayList<Integer>();
|
||||
final ArrayList<TLRPC.TL_contact> newContacts = new ArrayList<>();
|
||||
final ArrayList<Integer> contactsToDelete = new ArrayList<>();
|
||||
for (Integer uid : ids) {
|
||||
if (uid > 0) {
|
||||
TLRPC.TL_contact contact = new TLRPC.TL_contact();
|
||||
@ -1406,7 +1437,7 @@ public class ContactsController {
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<ContentProviderOperation> query = new ArrayList<ContentProviderOperation>();
|
||||
ArrayList<ContentProviderOperation> query = new ArrayList<>();
|
||||
|
||||
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
|
||||
builder.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name);
|
||||
@ -1471,7 +1502,7 @@ public class ContactsController {
|
||||
}
|
||||
|
||||
TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
|
||||
ArrayList<TLRPC.TL_inputPhoneContact> contactsParams = new ArrayList<TLRPC.TL_inputPhoneContact>();
|
||||
ArrayList<TLRPC.TL_inputPhoneContact> contactsParams = new ArrayList<>();
|
||||
TLRPC.TL_inputPhoneContact c = new TLRPC.TL_inputPhoneContact();
|
||||
c.phone = user.phone;
|
||||
if (!c.phone.startsWith("+")) {
|
||||
@ -1510,7 +1541,7 @@ public class ContactsController {
|
||||
});
|
||||
TLRPC.TL_contact newContact = new TLRPC.TL_contact();
|
||||
newContact.user_id = u.id;
|
||||
ArrayList<TLRPC.TL_contact> arrayList = new ArrayList<TLRPC.TL_contact>();
|
||||
ArrayList<TLRPC.TL_contact> arrayList = new ArrayList<>();
|
||||
arrayList.add(newContact);
|
||||
MessagesStorage.getInstance().putContacts(arrayList, false);
|
||||
|
||||
@ -1552,7 +1583,7 @@ public class ContactsController {
|
||||
return;
|
||||
}
|
||||
TLRPC.TL_contacts_deleteContacts req = new TLRPC.TL_contacts_deleteContacts();
|
||||
final ArrayList<Integer> uids = new ArrayList<Integer>();
|
||||
final ArrayList<Integer> uids = new ArrayList<>();
|
||||
for (TLRPC.User user : users) {
|
||||
TLRPC.InputUser inputUser = MessagesController.getInputUser(user);
|
||||
if (inputUser == null) {
|
||||
@ -1631,7 +1662,7 @@ public class ContactsController {
|
||||
editor.remove("needGetStatuses").commit();
|
||||
TLRPC.Vector vector = (TLRPC.Vector) response;
|
||||
if (!vector.objects.isEmpty()) {
|
||||
ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<TLRPC.User>();
|
||||
ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<>();
|
||||
for (Object object : vector.objects) {
|
||||
TLRPC.User toDbUser = new TLRPC.User();
|
||||
TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;
|
||||
|
@ -344,7 +344,7 @@ public class ImageLoader {
|
||||
});
|
||||
}
|
||||
});
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
imageLoadQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runHttpTasks(true);
|
||||
@ -354,7 +354,7 @@ public class ImageLoader {
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
imageLoadQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runHttpTasks(true);
|
||||
@ -449,6 +449,11 @@ public class ImageLoader {
|
||||
originalBitmap = scaledBitmap;
|
||||
FileOutputStream stream = new FileOutputStream(thumbFile);
|
||||
originalBitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);
|
||||
try {
|
||||
stream.close();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
final BitmapDrawable bitmapDrawable = new BitmapDrawable(originalBitmap);
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
@ -615,7 +620,9 @@ public class ImageLoader {
|
||||
if (mediaId != null) {
|
||||
MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, opts);
|
||||
} else {
|
||||
BitmapFactory.decodeFile(cacheImage.finalFilePath.getAbsolutePath(), opts);
|
||||
FileInputStream is = new FileInputStream(cacheFileFinal);
|
||||
image = BitmapFactory.decodeStream(is, null, opts);
|
||||
is.close();
|
||||
}
|
||||
|
||||
float photoW = opts.outWidth;
|
||||
@ -633,7 +640,7 @@ public class ImageLoader {
|
||||
}
|
||||
}
|
||||
|
||||
if (cacheImage.filter == null || blur) {
|
||||
if (cacheImage.filter == null || blur || cacheImage.httpUrl != null) {
|
||||
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
} else {
|
||||
opts.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
@ -1057,6 +1064,12 @@ public class ImageLoader {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
new File(cachePath, ".nomedia").createNewFile();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
|
||||
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, cachePath);
|
||||
FileLog.e("tmessages", "cache path = " + cachePath);
|
||||
|
||||
@ -1678,42 +1691,47 @@ public class ImageLoader {
|
||||
runHttpFileLoadTasks(null, 0);
|
||||
}
|
||||
|
||||
private void runHttpFileLoadTasks(HttpFileTask oldTask, int reason) {
|
||||
if (oldTask != null) {
|
||||
currentHttpFileLoadTasksCount--;
|
||||
}
|
||||
if (oldTask != null) {
|
||||
if (reason == 1) {
|
||||
if (oldTask.canRetry) {
|
||||
final HttpFileTask newTask = new HttpFileTask(oldTask.url, oldTask.tempFile, oldTask.ext);
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
httpFileLoadTasks.add(newTask);
|
||||
runHttpFileLoadTasks(null, 0);
|
||||
}
|
||||
};
|
||||
retryHttpsTasks.put(oldTask.url, runnable);
|
||||
AndroidUtilities.runOnUIThread(runnable, 1000);
|
||||
} else {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidFailedLoad, oldTask.url);
|
||||
private void runHttpFileLoadTasks(final HttpFileTask oldTask, final int reason) {
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (oldTask != null) {
|
||||
currentHttpFileLoadTasksCount--;
|
||||
}
|
||||
if (oldTask != null) {
|
||||
if (reason == 1) {
|
||||
if (oldTask.canRetry) {
|
||||
final HttpFileTask newTask = new HttpFileTask(oldTask.url, oldTask.tempFile, oldTask.ext);
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
httpFileLoadTasks.add(newTask);
|
||||
runHttpFileLoadTasks(null, 0);
|
||||
}
|
||||
};
|
||||
retryHttpsTasks.put(oldTask.url, runnable);
|
||||
AndroidUtilities.runOnUIThread(runnable, 1000);
|
||||
} else {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidFailedLoad, oldTask.url);
|
||||
}
|
||||
} else if (reason == 2) {
|
||||
httpFileLoadTasksByKeys.remove(oldTask.url);
|
||||
File file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(oldTask.url) + "." + oldTask.ext);
|
||||
String result = oldTask.tempFile.renameTo(file) ? file.toString() : oldTask.tempFile.toString();
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidLoaded, oldTask.url, result);
|
||||
}
|
||||
}
|
||||
while (currentHttpFileLoadTasksCount < 2 && !httpFileLoadTasks.isEmpty()) {
|
||||
HttpFileTask task = httpFileLoadTasks.poll();
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
|
||||
} else {
|
||||
task.execute(null, null, null);
|
||||
}
|
||||
currentHttpFileLoadTasksCount++;
|
||||
}
|
||||
} else if (reason == 2) {
|
||||
httpFileLoadTasksByKeys.remove(oldTask.url);
|
||||
File file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(oldTask.url) + "." + oldTask.ext);
|
||||
String result = oldTask.tempFile.renameTo(file) ? file.toString() : oldTask.tempFile.toString();
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.httpFileDidLoaded, oldTask.url, result);
|
||||
}
|
||||
}
|
||||
while (currentHttpFileLoadTasksCount < 2 && !httpFileLoadTasks.isEmpty()) {
|
||||
HttpFileTask task = httpFileLoadTasks.poll();
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
|
||||
} else {
|
||||
task.execute(null, null, null);
|
||||
}
|
||||
currentHttpFileLoadTasksCount++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxHeight, boolean useMaxScale) {
|
||||
|
@ -69,6 +69,8 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||
private int alpha = 255;
|
||||
private boolean isPressed;
|
||||
private boolean disableRecycle;
|
||||
private int orientation;
|
||||
private boolean centerRotation;
|
||||
private ImageReceiverDelegate delegate;
|
||||
|
||||
public ImageReceiver() {
|
||||
@ -209,6 +211,15 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||
return isPressed;
|
||||
}
|
||||
|
||||
public void setOrientation(int angle, boolean center) {
|
||||
orientation = angle;
|
||||
centerRotation = center;
|
||||
}
|
||||
|
||||
public int getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setImageBitmap(Bitmap bitmap) {
|
||||
setImageBitmap(bitmap != null ? new BitmapDrawable(null, bitmap) : null);
|
||||
}
|
||||
@ -280,8 +291,17 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||
canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
|
||||
}
|
||||
} else {
|
||||
int bitmapW = bitmapDrawable.getIntrinsicWidth();
|
||||
int bitmapH = bitmapDrawable.getIntrinsicHeight();
|
||||
int bitmapW;
|
||||
int bitmapH;
|
||||
int originalW = bitmapDrawable.getIntrinsicWidth();
|
||||
int originalH = bitmapDrawable.getIntrinsicHeight();
|
||||
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;
|
||||
|
||||
@ -312,14 +332,32 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||
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;
|
||||
originalW /= scaleH;
|
||||
drawRegion.set(imageX - (bitmapW - imageW) / 2, imageY, imageX + (bitmapW + imageW) / 2, imageY + imageH);
|
||||
} else {
|
||||
bitmapH /= scaleW;
|
||||
originalH /= scaleW;
|
||||
drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2, imageX + imageW, imageY + (bitmapH + imageH) / 2);
|
||||
}
|
||||
bitmapDrawable.setBounds(drawRegion);
|
||||
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);
|
||||
@ -339,8 +377,24 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||
|
||||
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);
|
||||
bitmapDrawable.setBounds(drawRegion);
|
||||
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);
|
||||
@ -357,6 +411,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -391,6 +446,16 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getBitmapWidth() {
|
||||
Bitmap bitmap = getBitmap();
|
||||
return orientation == 0 || orientation == 180 ? bitmap.getWidth() : bitmap.getHeight();
|
||||
}
|
||||
|
||||
public int getBitmapHeight() {
|
||||
Bitmap bitmap = getBitmap();
|
||||
return orientation == 0 || orientation == 180 ? bitmap.getHeight() : bitmap.getWidth();
|
||||
}
|
||||
|
||||
public void setVisible(boolean value, boolean invalidate) {
|
||||
if (isVisible == value) {
|
||||
return;
|
||||
|
@ -54,6 +54,7 @@ public class LocaleController {
|
||||
public static FastDateFormat formatterWeek;
|
||||
public static FastDateFormat formatterMonth;
|
||||
public static FastDateFormat formatterYear;
|
||||
public static FastDateFormat formatterMonthYear;
|
||||
public static FastDateFormat formatterYearMax;
|
||||
public static FastDateFormat chatDate;
|
||||
public static FastDateFormat chatFullDate;
|
||||
@ -135,7 +136,7 @@ public class LocaleController {
|
||||
addRules(new String[]{"bem", "brx", "da", "de", "el", "en", "eo", "es", "et", "fi", "fo", "gl", "he", "iw", "it", "nb",
|
||||
"nl", "nn", "no", "sv", "af", "bg", "bn", "ca", "eu", "fur", "fy", "gu", "ha", "is", "ku",
|
||||
"lb", "ml", "mr", "nah", "ne", "om", "or", "pa", "pap", "ps", "so", "sq", "sw", "ta", "te",
|
||||
"tk", "ur", "zu", "mn", "gsw", "chr", "rm", "pt"}, new PluralRules_One());
|
||||
"tk", "ur", "zu", "mn", "gsw", "chr", "rm", "pt", "an", "ast"}, new PluralRules_One());
|
||||
addRules(new String[]{"cs", "sk"}, new PluralRules_Czech());
|
||||
addRules(new String[]{"ff", "fr", "kab"}, new PluralRules_French());
|
||||
addRules(new String[]{"hr", "ru", "sr", "uk", "be", "bs", "sh"}, new PluralRules_Balkan());
|
||||
@ -443,10 +444,12 @@ public class LocaleController {
|
||||
}
|
||||
|
||||
private HashMap<String, String> getLocaleFileStrings(File file) {
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
HashMap<String, String> stringMap = new HashMap<>();
|
||||
XmlPullParser parser = Xml.newPullParser();
|
||||
parser.setInput(new FileInputStream(file), "UTF-8");
|
||||
stream = new FileInputStream(file);
|
||||
parser.setInput(stream, "UTF-8");
|
||||
int eventType = parser.getEventType();
|
||||
String name = null;
|
||||
String value = null;
|
||||
@ -483,6 +486,15 @@ public class LocaleController {
|
||||
return stringMap;
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
} finally {
|
||||
try {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
stream = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -544,6 +556,9 @@ public class LocaleController {
|
||||
currentLocale = newLocale;
|
||||
currentLocaleInfo = localeInfo;
|
||||
currentPluralRules = allRules.get(currentLocale.getLanguage());
|
||||
if (currentPluralRules == null) {
|
||||
currentPluralRules = allRules.get("en");
|
||||
}
|
||||
changingConfiguration = true;
|
||||
Locale.setDefault(currentLocale);
|
||||
android.content.res.Configuration config = new android.content.res.Configuration();
|
||||
@ -571,6 +586,9 @@ public class LocaleController {
|
||||
if (value == null) {
|
||||
value = ApplicationLoader.applicationContext.getString(res);
|
||||
}
|
||||
if (value == null) {
|
||||
value = "LOC_ERR:" + key;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -638,6 +656,9 @@ public class LocaleController {
|
||||
}
|
||||
currentLocale = newLocale;
|
||||
currentPluralRules = allRules.get(currentLocale.getLanguage());
|
||||
if (currentPluralRules == null) {
|
||||
currentPluralRules = allRules.get("en");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -695,6 +716,20 @@ public class LocaleController {
|
||||
}
|
||||
}
|
||||
|
||||
private FastDateFormat createFormatter(Locale locale, String format, String defaultFormat) {
|
||||
if (format == null || format.length() == 0) {
|
||||
format = defaultFormat;
|
||||
}
|
||||
FastDateFormat formatter = null;
|
||||
try {
|
||||
formatter = FastDateFormat.getInstance(format, locale);
|
||||
} catch (Exception e) {
|
||||
format = defaultFormat;
|
||||
formatter = FastDateFormat.getInstance(format, locale);
|
||||
}
|
||||
return formatter;
|
||||
}
|
||||
|
||||
public void recreateFormatters() {
|
||||
Locale locale = currentLocale;
|
||||
if (locale == null) {
|
||||
@ -706,59 +741,15 @@ public class LocaleController {
|
||||
}
|
||||
isRTL = lang.toLowerCase().equals("ar");
|
||||
nameDisplayOrder = lang.toLowerCase().equals("ko") ? 2 : 1;
|
||||
String formatString = getStringInternal("formatterMonth", R.string.formatterMonth);
|
||||
if (formatString == null || formatString.length() == 0) {
|
||||
formatString = "dd MMM";
|
||||
}
|
||||
formatterMonth = FastDateFormat.getInstance(formatString, locale);
|
||||
|
||||
formatString = getStringInternal("formatterYear", R.string.formatterYear);
|
||||
if (formatString == null || formatString.length() == 0) {
|
||||
formatString = "dd.MM.yy";
|
||||
}
|
||||
formatterYear = FastDateFormat.getInstance(formatString, locale);
|
||||
|
||||
formatString = getStringInternal("formatterYearMax", R.string.formatterYearMax);
|
||||
if (formatString == null || formatString.length() == 0) {
|
||||
formatString = "dd.MM.yyyy";
|
||||
}
|
||||
formatterYearMax = FastDateFormat.getInstance(formatString, locale);
|
||||
|
||||
formatString = getStringInternal("chatDate", R.string.chatDate);
|
||||
if (formatString == null || formatString.length() == 0) {
|
||||
formatString = "d MMMM";
|
||||
}
|
||||
chatDate = FastDateFormat.getInstance(formatString, locale);
|
||||
|
||||
formatString = getStringInternal("chatFullDate", R.string.chatFullDate);
|
||||
if (formatString == null || formatString.length() == 0) {
|
||||
formatString = "d MMMM yyyy";
|
||||
}
|
||||
chatFullDate = FastDateFormat.getInstance(formatString, locale);
|
||||
|
||||
formatString = getStringInternal("formatterWeek", R.string.formatterWeek);
|
||||
if (formatString == null || formatString.length() == 0) {
|
||||
formatString = "EEE";
|
||||
}
|
||||
formatterWeek = FastDateFormat.getInstance(formatString, locale);
|
||||
|
||||
if (is24HourFormat) {
|
||||
formatString = getStringInternal("formatterDay24H", R.string.formatterDay24H);
|
||||
} else {
|
||||
formatString = getStringInternal("formatterDay12H", R.string.formatterDay12H);
|
||||
}
|
||||
if (formatString == null || formatString.length() == 0) {
|
||||
if (is24HourFormat) {
|
||||
formatString = "HH:mm";
|
||||
} else {
|
||||
formatString = "h:mm a";
|
||||
}
|
||||
}
|
||||
if (lang.toLowerCase().equals("ar") || lang.toLowerCase().equals("ko")) {
|
||||
formatterDay = FastDateFormat.getInstance(formatString, locale);
|
||||
} else {
|
||||
formatterDay = FastDateFormat.getInstance(formatString, Locale.US);
|
||||
}
|
||||
formatterMonth = createFormatter(locale, getStringInternal("formatterMonth", R.string.formatterMonth), "dd MMM");
|
||||
formatterYear = createFormatter(locale, getStringInternal("formatterYear", R.string.formatterYear), "dd.MM.yy");
|
||||
formatterYearMax = createFormatter(locale, getStringInternal("formatterYearMax", R.string.formatterYearMax), "dd.MM.yyyy");
|
||||
chatDate = createFormatter(locale, getStringInternal("chatDate", R.string.chatDate), "d MMMM");
|
||||
chatFullDate = createFormatter(locale, getStringInternal("chatFullDate", R.string.chatFullDate), "d MMMM yyyy");
|
||||
formatterWeek = createFormatter(locale, getStringInternal("formatterWeek", R.string.formatterWeek), "EEE");
|
||||
formatterMonthYear = createFormatter(locale, getStringInternal("formatterMonthYear", R.string.formatterMonthYear), "MMMM yyyy");
|
||||
formatterDay = createFormatter(lang.toLowerCase().equals("ar") || lang.toLowerCase().equals("ko") ? locale : Locale.US, is24HourFormat ? getStringInternal("formatterDay24H", R.string.formatterDay24H) : getStringInternal("formatterDay12H", R.string.formatterDay12H), is24HourFormat ? "HH:mm" : "h:mm a");
|
||||
}
|
||||
|
||||
public static String stringForMessageListDate(long date) {
|
||||
|
@ -165,6 +165,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||
public int size;
|
||||
public int type;
|
||||
public int date;
|
||||
public String thumbPath;
|
||||
public String imagePath;
|
||||
}
|
||||
|
||||
public final static String MIME_TYPE = "video/avc";
|
||||
@ -1696,10 +1698,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||
FileLog.e("tmessages", e);
|
||||
result = false;
|
||||
} finally {
|
||||
if(source != null) {
|
||||
if (source != null) {
|
||||
source.close();
|
||||
}
|
||||
if(destination != null) {
|
||||
if (destination != null) {
|
||||
destination.close();
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ public class MessageObject {
|
||||
public int type;
|
||||
public int contentType;
|
||||
public String dateKey;
|
||||
public String monthKey;
|
||||
public boolean deleted = false;
|
||||
public float audioProgress;
|
||||
public int audioProgressSec;
|
||||
@ -71,6 +72,12 @@ public class MessageObject {
|
||||
textPaint.linkColor = 0xff316f9f;
|
||||
}
|
||||
|
||||
int color = AndroidUtilities.getIntDef("chatRTextColor", 0xff000000);
|
||||
textPaint.setColor(color);
|
||||
if(color != 0xff000000){
|
||||
textPaint.linkColor = AndroidUtilities.getIntDarkerColor("chatRTextColor", -0x50);
|
||||
}
|
||||
|
||||
textPaint.setTextSize(AndroidUtilities.dp(MessagesController.getInstance().fontSize));
|
||||
|
||||
messageOwner = message;
|
||||
@ -199,7 +206,7 @@ public class MessageObject {
|
||||
}
|
||||
}
|
||||
} else if (message.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
||||
String date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(((long)message.date) * 1000), LocaleController.formatterDay.format(((long)message.date) * 1000));
|
||||
String date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(((long) message.date) * 1000), LocaleController.formatterDay.format(((long) message.date) * 1000));
|
||||
TLRPC.User to_user = UserConfig.getCurrentUser();
|
||||
if (to_user == null) {
|
||||
if (users != null) {
|
||||
@ -346,11 +353,14 @@ public class MessageObject {
|
||||
}
|
||||
|
||||
Calendar rightNow = new GregorianCalendar();
|
||||
rightNow.setTimeInMillis((long)(messageOwner.date) * 1000);
|
||||
rightNow.setTimeInMillis((long) (messageOwner.date) * 1000);
|
||||
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
|
||||
int dateYear = rightNow.get(Calendar.YEAR);
|
||||
int dateMonth = rightNow.get(Calendar.MONTH);
|
||||
dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay);
|
||||
if (contentType == 1 || contentType == 2) {
|
||||
monthKey = String.format("%d_%02d", dateYear, dateMonth);
|
||||
}
|
||||
|
||||
if (generateLayout) {
|
||||
generateLayout();
|
||||
@ -556,7 +566,7 @@ public class MessageObject {
|
||||
textHeight = textLayout.getHeight();
|
||||
int linesCount = textLayout.getLineCount();
|
||||
|
||||
int blocksCount = (int)Math.ceil((float)linesCount / LINES_PER_BLOCK);
|
||||
int blocksCount = (int) Math.ceil((float) linesCount / LINES_PER_BLOCK);
|
||||
int linesOffset = 0;
|
||||
float prevOffset = 0;
|
||||
|
||||
@ -581,7 +591,7 @@ public class MessageObject {
|
||||
block.textLayout = new StaticLayout(str, textPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
||||
block.textYOffset = textLayout.getLineTop(linesOffset);
|
||||
if (a != 0) {
|
||||
blockHeight = Math.min(blockHeight, (int)(block.textYOffset - prevOffset));
|
||||
blockHeight = Math.min(blockHeight, (int) (block.textYOffset - prevOffset));
|
||||
}
|
||||
prevOffset = block.textYOffset;
|
||||
/*if (a != blocksCount - 1) {
|
||||
@ -613,7 +623,7 @@ public class MessageObject {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
|
||||
int linesMaxWidth = (int)Math.ceil(lastLine);
|
||||
int linesMaxWidth = (int) Math.ceil(lastLine);
|
||||
int lastLineWidthWithLeft;
|
||||
int linesMaxWidthWithLeft;
|
||||
boolean hasNonRTL = false;
|
||||
@ -622,7 +632,7 @@ public class MessageObject {
|
||||
lastLineWidth = linesMaxWidth;
|
||||
}
|
||||
|
||||
linesMaxWidthWithLeft = lastLineWidthWithLeft = (int)Math.ceil(lastLine + lastLeft);
|
||||
linesMaxWidthWithLeft = lastLineWidthWithLeft = (int) Math.ceil(lastLine + lastLeft);
|
||||
if (lastLeft == 0) {
|
||||
hasNonRTL = true;
|
||||
}
|
||||
@ -655,8 +665,8 @@ public class MessageObject {
|
||||
}
|
||||
textRealMaxWidth = Math.max(textRealMaxWidth, lineWidth);
|
||||
textRealMaxWidthWithLeft = Math.max(textRealMaxWidthWithLeft, lineWidth + lineLeft);
|
||||
linesMaxWidth = Math.max(linesMaxWidth, (int)Math.ceil(lineWidth));
|
||||
linesMaxWidthWithLeft = Math.max(linesMaxWidthWithLeft, (int)Math.ceil(lineWidth + lineLeft));
|
||||
linesMaxWidth = Math.max(linesMaxWidth, (int) Math.ceil(lineWidth));
|
||||
linesMaxWidthWithLeft = Math.max(linesMaxWidthWithLeft, (int) Math.ceil(lineWidth + lineLeft));
|
||||
}
|
||||
if (hasNonRTL) {
|
||||
textRealMaxWidth = textRealMaxWidthWithLeft;
|
||||
@ -667,7 +677,7 @@ public class MessageObject {
|
||||
} else if (a == blocksCount - 1) {
|
||||
lastLineWidth = linesMaxWidth;
|
||||
}
|
||||
textWidth = Math.max(textWidth, (int)Math.ceil(textRealMaxWidth));
|
||||
textWidth = Math.max(textWidth, (int) Math.ceil(textRealMaxWidth));
|
||||
} else {
|
||||
textWidth = Math.max(textWidth, Math.min(maxWidth, linesMaxWidth));
|
||||
}
|
||||
@ -696,7 +706,7 @@ public class MessageObject {
|
||||
}
|
||||
|
||||
public void setIsRead() {
|
||||
messageOwner.flags &=~ TLRPC.MESSAGE_FLAG_UNREAD;
|
||||
messageOwner.flags &= ~TLRPC.MESSAGE_FLAG_UNREAD;
|
||||
}
|
||||
|
||||
public boolean isSecretPhoto() {
|
||||
@ -714,7 +724,7 @@ public class MessageObject {
|
||||
if (unread) {
|
||||
message.flags |= TLRPC.MESSAGE_FLAG_UNREAD;
|
||||
} else {
|
||||
message.flags &=~ TLRPC.MESSAGE_FLAG_UNREAD;
|
||||
message.flags &= ~TLRPC.MESSAGE_FLAG_UNREAD;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,12 @@
|
||||
package org.telegram.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.util.Base64;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
@ -20,11 +22,14 @@ import org.telegram.messenger.FileLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.RPCRequest;
|
||||
import org.telegram.messenger.SerializedData;
|
||||
import org.telegram.messenger.TLClassStore;
|
||||
import org.telegram.messenger.TLObject;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.ui.ActionBar.BaseFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -86,6 +91,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
public int fontSize = AndroidUtilities.dp(16);
|
||||
public int maxGroupCount = 200;
|
||||
public int maxBroadcastCount = 100;
|
||||
public int groupBigSize;
|
||||
private ArrayList<TLRPC.TL_disabledFeature> disabledFeatures = new ArrayList<>();
|
||||
|
||||
private class UserActionUpdates extends TLRPC.Updates {
|
||||
|
||||
@ -102,6 +109,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
public static final int UPDATE_MASK_READ_DIALOG_MESSAGE = 256;
|
||||
public static final int UPDATE_MASK_SELECT_DIALOG = 512;
|
||||
public static final int UPDATE_MASK_PHONE = 1024;
|
||||
public static final int UPDATE_MASK_NEW_MESSAGE = 2048;
|
||||
public static final int UPDATE_MASK_SEND_STATE = 4096;
|
||||
public static final int UPDATE_MASK_ALL = UPDATE_MASK_AVATAR | UPDATE_MASK_STATUS | UPDATE_MASK_NAME | UPDATE_MASK_CHAT_AVATAR | UPDATE_MASK_CHAT_NAME | UPDATE_MASK_CHAT_MEMBERS | UPDATE_MASK_USER_PRINT | UPDATE_MASK_USER_PHONE | UPDATE_MASK_READ_DIALOG_MESSAGE | UPDATE_MASK_PHONE;
|
||||
|
||||
public static class PrintingUser {
|
||||
@ -138,7 +147,26 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
maxGroupCount = preferences.getInt("maxGroupCount", 200);
|
||||
maxBroadcastCount = preferences.getInt("maxBroadcastCount", 100);
|
||||
groupBigSize = preferences.getInt("groupBigSize", 10);
|
||||
fontSize = preferences.getInt("fons_size", AndroidUtilities.isTablet() ? 18 : 16);
|
||||
String disabledFeaturesString = preferences.getString("disabledFeatures", null);
|
||||
if (disabledFeaturesString != null && disabledFeaturesString.length() != 0) {
|
||||
try {
|
||||
byte[] bytes = Base64.decode(disabledFeaturesString, Base64.DEFAULT);
|
||||
if (bytes != null) {
|
||||
SerializedData data = new SerializedData(bytes);
|
||||
int count = data.readInt32();
|
||||
for (int a = 0; a < count; a++) {
|
||||
TLRPC.TL_disabledFeature feature = (TLRPC.TL_disabledFeature) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
if (feature != null && feature.feature != null && feature.description != null) {
|
||||
disabledFeatures.add(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConfig(final TLRPC.TL_config config) {
|
||||
@ -147,15 +175,52 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
public void run() {
|
||||
maxBroadcastCount = config.broadcast_size_max;
|
||||
maxGroupCount = config.chat_size_max;
|
||||
groupBigSize = config.chat_big_size;
|
||||
disabledFeatures = config.disabled_features;
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putInt("maxGroupCount", maxGroupCount);
|
||||
editor.putInt("maxBroadcastCount", maxBroadcastCount);
|
||||
editor.putInt("groupBigSize", groupBigSize);
|
||||
try {
|
||||
SerializedData data = new SerializedData();
|
||||
data.writeInt32(disabledFeatures.size());
|
||||
for (TLRPC.TL_disabledFeature disabledFeature : disabledFeatures) {
|
||||
disabledFeature.serializeToStream(data);
|
||||
}
|
||||
String string = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
|
||||
if (string != null && string.length() != 0) {
|
||||
editor.putString("disabledFeatures", string);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
editor.remove("disabledFeatures");
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
editor.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isFeatureEnabled(String feature, BaseFragment fragment) {
|
||||
if (feature == null || feature.length() == 0 || getInstance().disabledFeatures.isEmpty() || fragment == null) {
|
||||
return true;
|
||||
}
|
||||
for (TLRPC.TL_disabledFeature disabledFeature : getInstance().disabledFeatures) {
|
||||
if (disabledFeature.feature.equals(feature)) {
|
||||
if (fragment.getParentActivity() != null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
||||
builder.setTitle("Oops!");
|
||||
builder.setPositiveButton(R.string.OK, null);
|
||||
builder.setMessage(disabledFeature.description);
|
||||
fragment.showAlertDialog(builder);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addSupportUser() {
|
||||
TLRPC.TL_userForeign user = new TLRPC.TL_userForeign();
|
||||
user.phone = "333";
|
||||
@ -863,6 +928,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mainUserInfoChanged);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
||||
UserConfig.saveConfig(true);
|
||||
}
|
||||
@ -944,10 +1010,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
}
|
||||
|
||||
public void deleteDialog(final long did, int offset, final boolean onlyHistory) {
|
||||
if (offset == 0) {
|
||||
MessagesStorage.getInstance().deleteDialog(did, onlyHistory);
|
||||
}
|
||||
|
||||
int lower_part = (int)did;
|
||||
int high_id = (int)(did >> 32);
|
||||
|
||||
@ -963,7 +1025,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
dialog.unread_count = 0;
|
||||
}
|
||||
dialogMessage.remove(dialog.top_message);
|
||||
dialog.top_message = 0;
|
||||
}
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, did);
|
||||
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -978,8 +1043,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
});
|
||||
}
|
||||
});
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, did);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
|
||||
MessagesStorage.getInstance().deleteDialog(did, onlyHistory);
|
||||
}
|
||||
|
||||
if (high_id == 1) {
|
||||
@ -1437,8 +1502,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
currentDialog.unread_count = entry.getValue();
|
||||
}
|
||||
}
|
||||
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1533,8 +1598,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
dialogsServerOnly.add(d);
|
||||
}
|
||||
}
|
||||
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1554,8 +1619,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
if (resetEnd) {
|
||||
dialogsEndReached = false;
|
||||
}
|
||||
loadDialogs(offset, serverOffset, count, false);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
loadDialogs(offset, serverOffset, count, false);
|
||||
}
|
||||
});
|
||||
return;
|
||||
@ -1713,6 +1778,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
req.peer.chat_id = -lower_part;
|
||||
} else {
|
||||
TLRPC.User user = getUser(lower_part);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
|
||||
req.peer = new TLRPC.TL_inputPeerForeign();
|
||||
req.peer.user_id = user.id;
|
||||
@ -1865,8 +1933,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
arr.add(newMsg);
|
||||
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
|
||||
updateInterfaceWithMessages(newMsg.dialog_id, objArr);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat.id);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat.id);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
@ -1903,8 +1971,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
messagesObj.add(new MessageObject(res.message, users, true));
|
||||
TLRPC.Chat chat = res.chats.get(0);
|
||||
updateInterfaceWithMessages(-chat.id, messagesObj);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat.id);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat.id);
|
||||
if (uploadedAvatar != null) {
|
||||
changeChatAvatar(chat.id, uploadedAvatar);
|
||||
}
|
||||
@ -1950,8 +2018,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
messagesObj.add(new MessageObject(res.message, users, true));
|
||||
TLRPC.Chat chat = res.chats.get(0);
|
||||
updateInterfaceWithMessages(-chat.id, messagesObj);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
|
||||
|
||||
if (info != null) {
|
||||
for (TLRPC.TL_chatParticipant p : info.participants) {
|
||||
@ -2032,8 +2100,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
messagesObj.add(new MessageObject(res.message, users, true));
|
||||
TLRPC.Chat chat = res.chats.get(0);
|
||||
updateInterfaceWithMessages(-chat.id, messagesObj);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
|
||||
}
|
||||
boolean changed = false;
|
||||
if (info != null) {
|
||||
@ -2851,10 +2919,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
}
|
||||
|
||||
public boolean isDialogMuted(long dialog_id) {
|
||||
TLRPC.TL_dialog dialog = dialogs_dict.get(dialog_id);
|
||||
/*TLRPC.TL_dialog dialog = dialogs_dict.get(dialog_id);
|
||||
if (dialog != null) {
|
||||
return isNotifySettingsMuted(dialog.notify_settings);
|
||||
} else {
|
||||
} else {*/
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
int mute_type = preferences.getInt("notify2_" + dialog_id, 0);
|
||||
if (mute_type == 2) {
|
||||
@ -2865,7 +2933,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3577,4 +3645,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -838,6 +838,59 @@ public class MessagesStorage {
|
||||
//database.executeFast("DELETE FROM secret_holes WHERE uid = " + high_id).stepThis().dispose();
|
||||
}
|
||||
}
|
||||
|
||||
if ((int) did == 0) {
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM messages WHERE uid = " + did));
|
||||
ArrayList<File> filesToDelete = new ArrayList<>();
|
||||
try {
|
||||
while (cursor.next()) {
|
||||
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
|
||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
||||
TLRPC.Message message = (TLRPC.Message) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
if (message == null || message.media == null) {
|
||||
continue;
|
||||
}
|
||||
if (message.media instanceof TLRPC.TL_messageMediaAudio) {
|
||||
File file = FileLoader.getPathToAttach(message.media.audio);
|
||||
if (file != null && file.toString().length() > 0) {
|
||||
filesToDelete.add(file);
|
||||
}
|
||||
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||
for (TLRPC.PhotoSize photoSize : message.media.photo.sizes) {
|
||||
File file = FileLoader.getPathToAttach(photoSize);
|
||||
if (file != null && file.toString().length() > 0) {
|
||||
filesToDelete.add(file);
|
||||
}
|
||||
}
|
||||
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
|
||||
File file = FileLoader.getPathToAttach(message.media.video);
|
||||
if (file != null && file.toString().length() > 0) {
|
||||
filesToDelete.add(file);
|
||||
}
|
||||
file = FileLoader.getPathToAttach(message.media.video.thumb);
|
||||
if (file != null && file.toString().length() > 0) {
|
||||
filesToDelete.add(file);
|
||||
}
|
||||
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
||||
File file = FileLoader.getPathToAttach(message.media.document);
|
||||
if (file != null && file.toString().length() > 0) {
|
||||
filesToDelete.add(file);
|
||||
}
|
||||
file = FileLoader.getPathToAttach(message.media.document.thumb);
|
||||
if (file != null && file.toString().length() > 0) {
|
||||
filesToDelete.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
buffersStorage.reuseFreeBuffer(data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
cursor.dispose();
|
||||
FileLoader.getInstance().deleteFiles(filesToDelete);
|
||||
}
|
||||
|
||||
database.executeFast("UPDATE dialogs SET unread_count = 0 WHERE did = " + did).stepThis().dispose();
|
||||
database.executeFast("DELETE FROM messages WHERE uid = " + did).stepThis().dispose();
|
||||
database.executeFast("DELETE FROM media_counts_v2 WHERE uid = " + did).stepThis().dispose();
|
||||
@ -3178,6 +3231,7 @@ public class MessagesStorage {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messagesDeleted, mids);
|
||||
}
|
||||
});
|
||||
MessagesStorage.getInstance().updateDialogsWithReadedMessagesInternal(mids);
|
||||
MessagesStorage.getInstance().markMessagesAsDeletedInternal(mids);
|
||||
MessagesStorage.getInstance().updateDialogsWithDeletedMessagesInternal(mids);
|
||||
}
|
||||
@ -3189,9 +3243,6 @@ public class MessagesStorage {
|
||||
}
|
||||
|
||||
private void markMessagesAsDeletedInternal(final ArrayList<Integer> messages) {
|
||||
if (Thread.currentThread().getId() != storageQueue.getId()) {
|
||||
throw new RuntimeException("wrong db thread");
|
||||
}
|
||||
try {
|
||||
String ids = TextUtils.join(",", messages);
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT uid, data FROM messages WHERE mid IN(%s)", ids));
|
||||
@ -3287,7 +3338,7 @@ public class MessagesStorage {
|
||||
ArrayList<Integer> usersToLoad = new ArrayList<>();
|
||||
ArrayList<Integer> chatsToLoad = new ArrayList<>();
|
||||
ArrayList<Integer> encryptedToLoad = new ArrayList<>();
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid WHERE d.did IN(%s)", ids));
|
||||
cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, m.date FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid WHERE d.did IN(%s)", ids));
|
||||
while (cursor.next()) {
|
||||
TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
|
||||
dialog.id = cursor.longValue(0);
|
||||
@ -3302,6 +3353,10 @@ public class MessagesStorage {
|
||||
MessageObject.setIsUnread(message, cursor.intValue(5) != 1);
|
||||
message.id = cursor.intValue(6);
|
||||
message.send_state = cursor.intValue(7);
|
||||
int date = cursor.intValue(8);
|
||||
if (date != 0) {
|
||||
dialog.last_message_date = date;
|
||||
}
|
||||
dialogs.messages.add(message);
|
||||
|
||||
if (!usersToLoad.contains(message.from_id)) {
|
||||
@ -3471,7 +3526,7 @@ public class MessagesStorage {
|
||||
usersToLoad.add(UserConfig.getClientUserId());
|
||||
ArrayList<Integer> chatsToLoad = new ArrayList<>();
|
||||
ArrayList<Integer> encryptedToLoad = new ArrayList<>();
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid LEFT JOIN dialog_settings as s ON d.did = s.did ORDER BY d.date DESC LIMIT %d,%d", offset, count));
|
||||
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags, m.date FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid LEFT JOIN dialog_settings as s ON d.did = s.did ORDER BY d.date DESC LIMIT %d,%d", offset, count));
|
||||
while (cursor.next()) {
|
||||
TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
|
||||
dialog.id = cursor.longValue(0);
|
||||
@ -3495,6 +3550,10 @@ public class MessagesStorage {
|
||||
if (message != null) {
|
||||
MessageObject.setIsUnread(message, cursor.intValue(5) != 1);
|
||||
message.id = cursor.intValue(6);
|
||||
int date = cursor.intValue(9);
|
||||
if (date != 0) {
|
||||
dialog.last_message_date = date;
|
||||
}
|
||||
message.send_state = cursor.intValue(7);
|
||||
dialogs.messages.add(message);
|
||||
|
||||
|
@ -23,7 +23,7 @@ import java.util.zip.ZipFile;
|
||||
|
||||
public class NativeLoader {
|
||||
|
||||
private final static int LIB_VERSION = 5;
|
||||
private final static int LIB_VERSION = 6;
|
||||
private final static String LIB_NAME = "tmessages." + LIB_VERSION;
|
||||
private final static String LIB_SO_NAME = "lib" + LIB_NAME + ".so";
|
||||
private final static String LOCALE_LIB_SO_NAME = "lib" + LIB_NAME + "loc.so";
|
||||
|
@ -48,6 +48,9 @@ public class NotificationCenter {
|
||||
public static final int updateMessageMedia = totalEvents++;
|
||||
public static final int recentImagesDidLoaded = totalEvents++;
|
||||
public static final int replaceMessagesObjects = totalEvents++;
|
||||
public static final int didSetPasscode = totalEvents++;
|
||||
public static final int screenStateChanged = totalEvents++;
|
||||
public static final int appSwitchedToForeground = totalEvents++;
|
||||
|
||||
public static final int httpFileDidLoaded = totalEvents++;
|
||||
public static final int httpFileDidFailedLoad = totalEvents++;
|
||||
|
@ -11,6 +11,7 @@ package org.telegram.android;
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -29,6 +30,7 @@ import android.support.v4.app.RemoteInput;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.DispatchQueue;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.RPCRequest;
|
||||
@ -48,6 +50,7 @@ public class NotificationsController {
|
||||
|
||||
public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
|
||||
|
||||
private DispatchQueue notificationsQueue = new DispatchQueue("notificationsQueue");
|
||||
private ArrayList<MessageObject> pushMessages = new ArrayList<>();
|
||||
private HashMap<Integer, MessageObject> pushMessagesDict = new HashMap<>();
|
||||
private NotificationManagerCompat notificationManager = null;
|
||||
@ -130,7 +133,9 @@ public class NotificationsController {
|
||||
}
|
||||
|
||||
String msg = null;
|
||||
if ((int)dialog_id != 0) {
|
||||
if ((int)dialog_id == 0 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
|
||||
msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
||||
} else {
|
||||
if (chat_id == 0 && user_id != 0) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||
if (preferences.getBoolean("EnablePreviewAll", true)) {
|
||||
@ -237,8 +242,6 @@ public class NotificationsController {
|
||||
msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, ContactsController.formatName(user.first_name, user.last_name), chat.title);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
@ -250,7 +253,7 @@ public class NotificationsController {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
int minutes = preferences.getInt("repeat_messages", 60);
|
||||
if (minutes > 0 && personal_count > 0) {
|
||||
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + minutes * 60 * 1000, pintent);
|
||||
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent);
|
||||
} else {
|
||||
alarm.cancel(pintent);
|
||||
}
|
||||
@ -266,9 +269,9 @@ public class NotificationsController {
|
||||
PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
||||
if (onlineReason) {
|
||||
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3 * 1000, pintent);
|
||||
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 3 * 1000, pintent);
|
||||
} else {
|
||||
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, pintent);
|
||||
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, pintent);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
@ -416,6 +419,9 @@ public class NotificationsController {
|
||||
intent.putExtra("userId", user_id);
|
||||
}
|
||||
}
|
||||
if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
|
||||
photoPath = null;
|
||||
} else {
|
||||
if (pushDialogs.size() == 1) {
|
||||
if (chat != null) {
|
||||
if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
|
||||
@ -427,6 +433,7 @@ public class NotificationsController {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (pushDialogs.size() == 1) {
|
||||
intent.putExtra("encId", (int) (dialog_id >> 32));
|
||||
@ -436,7 +443,7 @@ public class NotificationsController {
|
||||
|
||||
String name = null;
|
||||
boolean replace = true;
|
||||
if ((int)dialog_id == 0 || pushDialogs.size() > 1) {
|
||||
if ((int)dialog_id == 0 || pushDialogs.size() > 1 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
|
||||
name = LocaleController.getString("AppName", R.string.AppName);
|
||||
replace = false;
|
||||
} else {
|
||||
@ -451,7 +458,7 @@ public class NotificationsController {
|
||||
if (pushDialogs.size() == 1) {
|
||||
detailText = LocaleController.formatPluralString("NewMessages", total_unread_count);
|
||||
} else {
|
||||
detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromContacts", pushDialogs.size()));
|
||||
detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size()));
|
||||
}
|
||||
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
|
||||
@ -462,7 +469,8 @@ public class NotificationsController {
|
||||
.setContentIntent(contentIntent)
|
||||
.setGroup("messages")
|
||||
.setGroupSummary(true)
|
||||
.setColor(0xff2ca5e0);
|
||||
//.setColor(0xff2ca5e0);
|
||||
.setColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
|
||||
if (priority == 0) {
|
||||
mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
||||
@ -834,7 +842,7 @@ public class NotificationsController {
|
||||
notifyCheck = isLast;
|
||||
}
|
||||
|
||||
if (!popupMessages.isEmpty() && oldCount != popupMessages.size()) {
|
||||
if (!popupMessages.isEmpty() && oldCount != popupMessages.size() && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) {
|
||||
if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn) {
|
||||
MessageObject messageObject = messageObjects.get(0);
|
||||
if (popup == 3 || popup == 1 && ApplicationLoader.isScreenOn || popup == 2 && !ApplicationLoader.isScreenOn) {
|
||||
@ -988,7 +996,18 @@ public class NotificationsController {
|
||||
setBadge(ApplicationLoader.applicationContext, enabled ? total_unread_count : 0);
|
||||
}
|
||||
|
||||
private void setBadge(Context context, int count) {
|
||||
private void setBadge(final Context context, final int count) {
|
||||
notificationsQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put("tag", "org.telegram.messenger/org.telegram.ui.LaunchActivity");
|
||||
cv.put("count", count);
|
||||
context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);
|
||||
} catch (Throwable e) {
|
||||
//ignore
|
||||
}
|
||||
try {
|
||||
String launcherClassName = getLauncherClassName(context);
|
||||
if (launcherClassName == null) {
|
||||
@ -1003,6 +1022,8 @@ public class NotificationsController {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getLauncherClassName(Context context) {
|
||||
try {
|
||||
|
@ -28,5 +28,6 @@ public class ScreenReceiver extends BroadcastReceiver {
|
||||
ConnectionsManager.getInstance().setAppPaused(false, true);
|
||||
ApplicationLoader.isScreenOn = true;
|
||||
}
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.screenStateChanged);
|
||||
}
|
||||
}
|
||||
|
@ -1072,8 +1072,8 @@ public class SecretChatHelper {
|
||||
}
|
||||
});
|
||||
MessagesStorage.getInstance().deleteDialog(did, true);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, did);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, did);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
@ -1616,7 +1616,7 @@ public class SecretChatHelper {
|
||||
}
|
||||
|
||||
public void startSecretChat(final Context context, final TLRPC.User user) {
|
||||
if (user == null) {
|
||||
if (user == null || context == null) {
|
||||
return;
|
||||
}
|
||||
startingSecretChat = true;
|
||||
@ -1777,6 +1777,10 @@ public class SecretChatHelper {
|
||||
}
|
||||
}
|
||||
});
|
||||
progressDialog.show();
|
||||
try {
|
||||
progressDialog.show();
|
||||
} catch (Exception e) {
|
||||
//don't promt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -481,6 +481,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||
sendMessage(null, null, null, null, null, null, user, null, null, null, peer, false, null);
|
||||
}
|
||||
|
||||
public void sendMessage(ArrayList<MessageObject> messages) {
|
||||
|
||||
}
|
||||
|
||||
public void sendMessage(MessageObject message) {
|
||||
sendMessage(null, null, null, null, null, message, null, null, null, null, message.getDialogId(), true, message.messageOwner.attachPath);
|
||||
}
|
||||
@ -1610,6 +1614,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||
try {
|
||||
Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90, true);
|
||||
if (bitmap != null) {
|
||||
fileName.file_name = "animation.gif";
|
||||
document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, isEncrypted);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -1744,7 +1749,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||
document.id = 0;
|
||||
document.date = ConnectionsManager.getInstance().getCurrentTime();
|
||||
TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
|
||||
fileName.file_name = md5;
|
||||
fileName.file_name = "animation.gif";
|
||||
document.attributes.add(fileName);
|
||||
document.size = searchImage.size;
|
||||
document.dc_id = 0;
|
||||
@ -1940,112 +1945,116 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
boolean isEncrypted = (int)dialog_id == 0;
|
||||
|
||||
String path = videoPath;
|
||||
String originalPath = videoPath;
|
||||
File temp = new File(originalPath);
|
||||
originalPath += temp.length() + "_" + temp.lastModified();
|
||||
if (videoEditedInfo != null) {
|
||||
originalPath += duration + "_" + videoEditedInfo.startTime + "_" + videoEditedInfo.endTime;
|
||||
}
|
||||
TLRPC.TL_video video = null;
|
||||
if (!isEncrypted) {
|
||||
video = (TLRPC.TL_video) MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 2 : 5);
|
||||
}
|
||||
if (video == null) {
|
||||
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
|
||||
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(thumb, 90, 90, 55, isEncrypted);
|
||||
video = new TLRPC.TL_video();
|
||||
video.thumb = size;
|
||||
if (video.thumb == null) {
|
||||
video.thumb = new TLRPC.TL_photoSizeEmpty();
|
||||
video.thumb.type = "s";
|
||||
} else {
|
||||
video.thumb.type = "s";
|
||||
}
|
||||
video.caption = "";
|
||||
video.mime_type = "video/mp4";
|
||||
video.id = 0;
|
||||
UserConfig.saveConfig(false);
|
||||
|
||||
if (videoEditedInfo != null || videoPath.endsWith("mp4")) {
|
||||
String path = videoPath;
|
||||
String originalPath = videoPath;
|
||||
File temp = new File(originalPath);
|
||||
originalPath += temp.length() + "_" + temp.lastModified();
|
||||
if (videoEditedInfo != null) {
|
||||
video.duration = (int)(duration / 1000);
|
||||
if (videoEditedInfo.rotationValue == 90 || videoEditedInfo.rotationValue == 270) {
|
||||
video.w = height;
|
||||
video.h = width;
|
||||
originalPath += duration + "_" + videoEditedInfo.startTime + "_" + videoEditedInfo.endTime;
|
||||
}
|
||||
TLRPC.TL_video video = null;
|
||||
if (!isEncrypted) {
|
||||
video = (TLRPC.TL_video) MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 2 : 5);
|
||||
}
|
||||
if (video == null) {
|
||||
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
|
||||
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(thumb, 90, 90, 55, isEncrypted);
|
||||
video = new TLRPC.TL_video();
|
||||
video.thumb = size;
|
||||
if (video.thumb == null) {
|
||||
video.thumb = new TLRPC.TL_photoSizeEmpty();
|
||||
video.thumb.type = "s";
|
||||
} else {
|
||||
video.w = width;
|
||||
video.h = height;
|
||||
video.thumb.type = "s";
|
||||
}
|
||||
video.size = (int)estimatedSize;
|
||||
video.videoEditedInfo = videoEditedInfo;
|
||||
String fileName = Integer.MIN_VALUE + "_" + UserConfig.lastLocalId + ".mp4";
|
||||
UserConfig.lastLocalId--;
|
||||
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
||||
video.caption = "";
|
||||
video.mime_type = "video/mp4";
|
||||
video.id = 0;
|
||||
UserConfig.saveConfig(false);
|
||||
path = cacheFile.getAbsolutePath();
|
||||
} else {
|
||||
if (temp != null && temp.exists()) {
|
||||
video.size = (int) temp.length();
|
||||
}
|
||||
boolean infoObtained = false;
|
||||
if (Build.VERSION.SDK_INT >= 14) {
|
||||
MediaMetadataRetriever mediaMetadataRetriever = null;
|
||||
try {
|
||||
mediaMetadataRetriever = new MediaMetadataRetriever();
|
||||
mediaMetadataRetriever.setDataSource(videoPath);
|
||||
String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
|
||||
if (width != null) {
|
||||
video.w = Integer.parseInt(width);
|
||||
}
|
||||
String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
|
||||
if (height != null) {
|
||||
video.h = Integer.parseInt(height);
|
||||
}
|
||||
String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
||||
if (duration != null) {
|
||||
video.duration = (int) Math.ceil(Long.parseLong(duration) / 1000.0f);
|
||||
}
|
||||
infoObtained = true;
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
} finally {
|
||||
|
||||
if (videoEditedInfo != null) {
|
||||
video.duration = (int) (duration / 1000);
|
||||
if (videoEditedInfo.rotationValue == 90 || videoEditedInfo.rotationValue == 270) {
|
||||
video.w = height;
|
||||
video.h = width;
|
||||
} else {
|
||||
video.w = width;
|
||||
video.h = height;
|
||||
}
|
||||
video.size = (int) estimatedSize;
|
||||
video.videoEditedInfo = videoEditedInfo;
|
||||
String fileName = Integer.MIN_VALUE + "_" + UserConfig.lastLocalId + ".mp4";
|
||||
UserConfig.lastLocalId--;
|
||||
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
||||
UserConfig.saveConfig(false);
|
||||
path = cacheFile.getAbsolutePath();
|
||||
} else {
|
||||
if (temp != null && temp.exists()) {
|
||||
video.size = (int) temp.length();
|
||||
}
|
||||
boolean infoObtained = false;
|
||||
if (Build.VERSION.SDK_INT >= 14) {
|
||||
MediaMetadataRetriever mediaMetadataRetriever = null;
|
||||
try {
|
||||
if (mediaMetadataRetriever != null) {
|
||||
mediaMetadataRetriever.release();
|
||||
mediaMetadataRetriever = null;
|
||||
mediaMetadataRetriever = new MediaMetadataRetriever();
|
||||
mediaMetadataRetriever.setDataSource(videoPath);
|
||||
String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
|
||||
if (width != null) {
|
||||
video.w = Integer.parseInt(width);
|
||||
}
|
||||
String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
|
||||
if (height != null) {
|
||||
video.h = Integer.parseInt(height);
|
||||
}
|
||||
String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
||||
if (duration != null) {
|
||||
video.duration = (int) Math.ceil(Long.parseLong(duration) / 1000.0f);
|
||||
}
|
||||
infoObtained = true;
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
} finally {
|
||||
try {
|
||||
if (mediaMetadataRetriever != null) {
|
||||
mediaMetadataRetriever.release();
|
||||
mediaMetadataRetriever = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!infoObtained) {
|
||||
try {
|
||||
MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath)));
|
||||
if (mp != null) {
|
||||
video.duration = (int) Math.ceil(mp.getDuration() / 1000.0f);
|
||||
video.w = mp.getVideoWidth();
|
||||
video.h = mp.getVideoHeight();
|
||||
mp.release();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!infoObtained) {
|
||||
try {
|
||||
MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath)));
|
||||
if (mp != null) {
|
||||
video.duration = (int) Math.ceil(mp.getDuration() / 1000.0f);
|
||||
video.w = mp.getVideoWidth();
|
||||
video.h = mp.getVideoHeight();
|
||||
mp.release();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
final TLRPC.TL_video videoFinal = video;
|
||||
final String originalPathFinal = originalPath;
|
||||
final String finalPath = path;
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SendMessagesHelper.getInstance().sendMessage(videoFinal, originalPathFinal, finalPath, dialog_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
prepareSendingDocumentInternal(videoPath, videoPath, null, null, dialog_id);
|
||||
}
|
||||
|
||||
final TLRPC.TL_video videoFinal = video;
|
||||
final String originalPathFinal = originalPath;
|
||||
final String finalPath = path;
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SendMessagesHelper.getInstance().sendMessage(videoFinal, originalPathFinal, finalPath, dialog_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class MP4Builder {
|
||||
private long dataOffset = 0;
|
||||
private long writedSinceLastMdat = 0;
|
||||
private boolean writeNewMdat = true;
|
||||
private HashMap<Track, long[]> track2SampleSizes = new HashMap<Track, long[]>();
|
||||
private HashMap<Track, long[]> track2SampleSizes = new HashMap<>();
|
||||
private ByteBuffer sizeBuffer = null;
|
||||
|
||||
public MP4Builder createMovie(Mp4Movie mp4Movie) throws Exception {
|
||||
@ -158,7 +158,7 @@ public class MP4Builder {
|
||||
}
|
||||
|
||||
protected FileTypeBox createFileTypeBox() {
|
||||
LinkedList<String> minorBrands = new LinkedList<String>();
|
||||
LinkedList<String> minorBrands = new LinkedList<>();
|
||||
minorBrands.add("isom");
|
||||
minorBrands.add("3gp4");
|
||||
return new FileTypeBox("isom", 0, minorBrands);
|
||||
@ -347,7 +347,7 @@ public class MP4Builder {
|
||||
|
||||
protected void createStts(Track track, SampleTableBox stbl) {
|
||||
TimeToSampleBox.Entry lastEntry = null;
|
||||
List<TimeToSampleBox.Entry> entries = new ArrayList<TimeToSampleBox.Entry>();
|
||||
List<TimeToSampleBox.Entry> entries = new ArrayList<>();
|
||||
|
||||
for (long delta : track.getSampleDurations()) {
|
||||
if (lastEntry != null && lastEntry.getDelta() == delta) {
|
||||
@ -418,7 +418,7 @@ public class MP4Builder {
|
||||
}
|
||||
|
||||
protected void createStco(Track track, SampleTableBox stbl) {
|
||||
ArrayList<Long> chunksOffsets = new ArrayList<Long>();
|
||||
ArrayList<Long> chunksOffsets = new ArrayList<>();
|
||||
long lastOffset = -1;
|
||||
for (Sample sample : track.getSamples()) {
|
||||
long offset = sample.getOffset();
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
package org.telegram.messenger;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Application;
|
||||
import android.app.PendingIntent;
|
||||
@ -19,6 +20,7 @@ import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
@ -38,10 +40,13 @@ import org.telegram.android.LocaleController;
|
||||
import org.telegram.android.MessagesController;
|
||||
import org.telegram.android.NativeLoader;
|
||||
import org.telegram.android.ScreenReceiver;
|
||||
import org.telegram.ui.Components.ForegroundDetector;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ApplicationLoader extends Application {
|
||||
|
||||
private GoogleCloudMessaging gcm;
|
||||
private AtomicInteger msgId = new AtomicInteger();
|
||||
private String regid;
|
||||
@ -49,15 +54,80 @@ public class ApplicationLoader extends Application {
|
||||
public static final String PROPERTY_REG_ID = "registration_id";
|
||||
private static final String PROPERTY_APP_VERSION = "appVersion";
|
||||
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
|
||||
public static Drawable cachedWallpaper = null;
|
||||
private static Drawable cachedWallpaper;
|
||||
private static int selectedColor;
|
||||
private static boolean isCustomTheme;
|
||||
private static final Object sync = new Object();
|
||||
|
||||
public static volatile Context applicationContext = null;
|
||||
public static volatile Handler applicationHandler = null;
|
||||
public static volatile Context applicationContext;
|
||||
public static volatile Handler applicationHandler;
|
||||
private static volatile boolean applicationInited = false;
|
||||
|
||||
public static volatile boolean isScreenOn = false;
|
||||
public static volatile boolean mainInterfacePaused = true;
|
||||
|
||||
public static boolean isCustomTheme() {
|
||||
return isCustomTheme;
|
||||
}
|
||||
|
||||
public static int getSelectedColor() {
|
||||
return selectedColor;
|
||||
}
|
||||
|
||||
public static void reloadWallpaper() {
|
||||
cachedWallpaper = null;
|
||||
loadWallpaper();
|
||||
}
|
||||
|
||||
public static void loadWallpaper() {
|
||||
if (cachedWallpaper != null) {
|
||||
return;
|
||||
}
|
||||
Utilities.searchQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (sync) {
|
||||
int selectedColor = 0;
|
||||
try {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
|
||||
selectedColor = preferences.getInt("selectedColor", 0);
|
||||
int cacheColorHint = 0;
|
||||
if (selectedColor == 0) {
|
||||
if (selectedBackground == 1000001) {
|
||||
cachedWallpaper = applicationContext.getResources().getDrawable(R.drawable.background_hd);
|
||||
isCustomTheme = false;
|
||||
} else {
|
||||
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
|
||||
if (toFile.exists()) {
|
||||
cachedWallpaper = Drawable.createFromPath(toFile.getAbsolutePath());
|
||||
isCustomTheme = true;
|
||||
} else {
|
||||
cachedWallpaper = applicationContext.getResources().getDrawable(R.drawable.background_hd);
|
||||
isCustomTheme = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
//ignore
|
||||
}
|
||||
if (cachedWallpaper == null) {
|
||||
if (selectedColor == 0) {
|
||||
selectedColor = -2693905;
|
||||
}
|
||||
cachedWallpaper = new ColorDrawable(selectedColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Drawable getCachedWallpaper() {
|
||||
synchronized (sync) {
|
||||
return cachedWallpaper;
|
||||
}
|
||||
}
|
||||
|
||||
public static void postInitApplication() {
|
||||
if (applicationInited) {
|
||||
return;
|
||||
@ -117,6 +187,10 @@ public class ApplicationLoader extends Application {
|
||||
applicationContext = getApplicationContext();
|
||||
NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 14) {
|
||||
new ForegroundDetector(this);
|
||||
}
|
||||
|
||||
applicationHandler = new Handler(applicationContext.getMainLooper());
|
||||
|
||||
startPushService();
|
||||
|
@ -366,6 +366,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
datacenters.put(datacenter.datacenterId, datacenter);
|
||||
}
|
||||
currentDatacenterId = data.readInt32();
|
||||
data.cleanup();
|
||||
} catch (Exception e) {
|
||||
UserConfig.clearConfig();
|
||||
}
|
||||
@ -388,6 +389,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
for (int a = 0; a < count; a++) {
|
||||
sessionsToDestroy.add(data.readInt64());
|
||||
}
|
||||
data.cleanup();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -405,6 +407,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
Datacenter datacenter = new Datacenter(data, 1);
|
||||
datacenters.put(datacenter.datacenterId, datacenter);
|
||||
}
|
||||
data.cleanup();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -452,7 +455,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
|
||||
datacenter = new Datacenter();
|
||||
datacenter.datacenterId = 3;
|
||||
datacenter.addAddressAndPort("174.140.142.6", 443);
|
||||
datacenter.addAddressAndPort("149.154.175.100", 443);
|
||||
datacenters.put(datacenter.datacenterId, datacenter);
|
||||
|
||||
datacenter = new Datacenter();
|
||||
@ -488,7 +491,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
|
||||
datacenter = new Datacenter();
|
||||
datacenter.datacenterId = 3;
|
||||
datacenter.addAddressAndPort("174.140.142.6", 443);
|
||||
datacenter.addAddressAndPort("149.154.175.100", 443);
|
||||
datacenters.put(datacenter.datacenterId, datacenter);
|
||||
|
||||
datacenter = new Datacenter();
|
||||
@ -528,6 +531,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
data.writeInt64(session);
|
||||
}
|
||||
editor.putString("sessionsToDestroy", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
||||
data.cleanup();
|
||||
} else {
|
||||
editor.remove("sessionsToDestroy");
|
||||
}
|
||||
@ -539,6 +543,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
datacenter.SerializeToStream(data);
|
||||
}
|
||||
editor.putString("datacenters", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
||||
data.cleanup();
|
||||
} else {
|
||||
editor.remove("datacenters");
|
||||
}
|
||||
@ -763,8 +768,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
return;
|
||||
}
|
||||
if (error == null) {
|
||||
lastDcUpdateTime = (int)(System.currentTimeMillis() / 1000);
|
||||
TLRPC.TL_config config = (TLRPC.TL_config)response;
|
||||
int updateIn = config.expires - getCurrentTime();
|
||||
if (updateIn <= 0) {
|
||||
updateIn = 120;
|
||||
}
|
||||
lastDcUpdateTime = (int)(System.currentTimeMillis() / 1000) - DC_UPDATE_TIME + updateIn;
|
||||
ArrayList<Datacenter> datacentersArr = new ArrayList<>();
|
||||
HashMap<Integer, Datacenter> datacenterMap = new HashMap<>();
|
||||
for (TLRPC.TL_dcOption datacenterDesc : config.dc_options) {
|
||||
@ -1338,6 +1347,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
if (canCompress) {
|
||||
try {
|
||||
byte[] data = Utilities.compress(os.toByteArray());
|
||||
os.cleanup();
|
||||
if (data.length < requestLength) {
|
||||
TLRPC.TL_gzip_packed packed = new TLRPC.TL_gzip_packed();
|
||||
packed.packed_data = data;
|
||||
@ -1345,6 +1355,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
os = new SerializedData(true);
|
||||
packed.serializeToStream(os);
|
||||
requestLength = os.length();
|
||||
os.cleanup();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
@ -1406,6 +1417,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
if (rawRequest != null && (rawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
||||
rawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
||||
rawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
||||
rawRequest instanceof TLRPC.TL_messages_forwardMessage ||
|
||||
rawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
||||
rawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
||||
rawRequest instanceof TLRPC.TL_messages_sendEncryptedService)) {
|
||||
@ -1426,6 +1438,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
if (currentRawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
||||
currentRawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
||||
currentRawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
||||
currentRawRequest instanceof TLRPC.TL_messages_forwardMessage ||
|
||||
currentRawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
||||
currentRawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
||||
currentRawRequest instanceof TLRPC.TL_messages_sendEncryptedService) {
|
||||
@ -1438,6 +1451,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
if (request.rawRequest instanceof TLRPC.TL_messages_sendMessage ||
|
||||
request.rawRequest instanceof TLRPC.TL_messages_sendMedia ||
|
||||
request.rawRequest instanceof TLRPC.TL_messages_forwardMessages ||
|
||||
request.rawRequest instanceof TLRPC.TL_messages_forwardMessage ||
|
||||
request.rawRequest instanceof TLRPC.TL_messages_sendEncrypted ||
|
||||
request.rawRequest instanceof TLRPC.TL_messages_sendEncryptedFile ||
|
||||
request.rawRequest instanceof TLRPC.TL_messages_sendEncryptedService) {
|
||||
@ -1720,6 +1734,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||
if (quickAckId != null) {
|
||||
SerializedData data = new SerializedData(messageKeyFull);
|
||||
quickAckId.add(data.readInt32() & 0x7fffffff);
|
||||
data.cleanup();
|
||||
}
|
||||
|
||||
MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, false);
|
||||
|
@ -638,7 +638,7 @@ public class FileLoader {
|
||||
continue;
|
||||
}
|
||||
int currentSide = obj.w >= obj.h ? obj.w : obj.h;
|
||||
if (closestObject == null || obj instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
|
||||
if (closestObject == null || side > 100 && closestObject.location != null && closestObject.location.dc_id == Integer.MIN_VALUE || obj instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
|
||||
closestObject = obj;
|
||||
lastSide = currentSide;
|
||||
}
|
||||
|
@ -91,6 +91,14 @@ public class FileUploadOperation {
|
||||
remove(fileKey + "_iv").
|
||||
remove(fileKey + "_key").
|
||||
remove(fileKey + "_ivc").commit();
|
||||
try {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
stream = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkNewDataAvailable(final long finalSize) {
|
||||
|
@ -55,7 +55,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
}
|
||||
datacenter.connection.delegate = this;
|
||||
|
||||
processedMessageIds = new ArrayList<Long>();
|
||||
processedMessageIds = new ArrayList<>();
|
||||
authNonce = null;
|
||||
authServerNonce = null;
|
||||
authNewNonce = null;
|
||||
@ -92,10 +92,10 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
HashMap<String, Object> selectPublicKey(ArrayList<Long> fingerprints) {
|
||||
synchronized (lock) {
|
||||
if (serverPublicKeys == null) {
|
||||
serverPublicKeys = new ArrayList<HashMap<String, Object>>();
|
||||
serverPublicKeys = new ArrayList<>();
|
||||
HashMap<String, Object> map;
|
||||
|
||||
map = new HashMap<String, Object>();
|
||||
map = new HashMap<>();
|
||||
map.put("key", new BigInteger[]{
|
||||
new BigInteger("c150023e2f70db7985ded064759cfecf0af328e69a41daf4d6f01b538135" +
|
||||
"a6f91f8f8b2a0ec9ba9720ce352efcf6c5680ffc424bd634864902de0b4bd6d49f4e580230e" +
|
||||
@ -108,7 +108,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
map.put("fingerprint", 0xc3b42b026ce86b21L);
|
||||
serverPublicKeys.add(map);
|
||||
|
||||
map = new HashMap<String, Object>();
|
||||
map = new HashMap<>();
|
||||
map.put("key", new BigInteger[]{
|
||||
new BigInteger("c6aeda78b02a251db4b6441031f467fa871faed32526c436524b1fb3b5dc" +
|
||||
"a28efb8c089dd1b46d92c895993d87108254951c5f001a0f055f3063dcd14d431a300eb9e29" +
|
||||
@ -121,7 +121,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
map.put("fingerprint", 0x9a996a1db11c729bL);
|
||||
serverPublicKeys.add(map);
|
||||
|
||||
map = new HashMap<String, Object>();
|
||||
map = new HashMap<>();
|
||||
map.put("key", new BigInteger[]{
|
||||
new BigInteger("b1066749655935f0a5936f517034c943bea7f3365a8931ae52c8bcb14856" +
|
||||
"f004b83d26cf2839be0f22607470d67481771c1ce5ec31de16b20bbaa4ecd2f7d2ecf6b6356" +
|
||||
@ -134,7 +134,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
map.put("fingerprint", 0xb05b2a6f70cdea78L);
|
||||
serverPublicKeys.add(map);
|
||||
|
||||
map = new HashMap<String, Object>();
|
||||
map = new HashMap<>();
|
||||
map.put("key", new BigInteger[]{
|
||||
new BigInteger("c2a8c55b4a62e2b78a19b91cf692bcdc4ba7c23fe4d06f194e2a0c30f6d9" +
|
||||
"996f7d1a2bcc89bc1ac4333d44359a6c433252d1a8402d9970378b5912b75bc8cc3fa76710a" +
|
||||
@ -190,7 +190,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
if (message instanceof TLRPC.TL_resPQ) {
|
||||
if (processedPQRes) {
|
||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||
msgsAck.msg_ids = new ArrayList<Long>();
|
||||
msgsAck.msg_ids = new ArrayList<>();
|
||||
msgsAck.msg_ids.add(messageId);
|
||||
sendMessageData(msgsAck, generateMessageId());
|
||||
return;
|
||||
@ -250,6 +250,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
innerData.serializeToStream(os);
|
||||
|
||||
byte[] innerDataBytes = os.toByteArray();
|
||||
os.cleanup();
|
||||
|
||||
SerializedData dataWithHash = new SerializedData();
|
||||
dataWithHash.writeRaw(Utilities.computeSHA1(innerDataBytes));
|
||||
@ -261,6 +262,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
}
|
||||
|
||||
byte[] encryptedBytes = Utilities.encryptWithRSA((BigInteger[])publicKey.get("key"), dataWithHash.toByteArray());
|
||||
dataWithHash.cleanup();
|
||||
SerializedData encryptedData = new SerializedData();
|
||||
encryptedData.writeRaw(encryptedBytes);
|
||||
if (encryptedData.length() < 256) {
|
||||
@ -269,12 +271,14 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
newEncryptedData.writeByte(0);
|
||||
}
|
||||
newEncryptedData.writeRaw(encryptedData.toByteArray());
|
||||
encryptedData.cleanup();
|
||||
encryptedData = newEncryptedData;
|
||||
}
|
||||
reqDH.encrypted_data = encryptedData.toByteArray();
|
||||
encryptedData.cleanup();
|
||||
|
||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||
msgsAck.msg_ids = new ArrayList<Long>();
|
||||
msgsAck.msg_ids = new ArrayList<>();
|
||||
msgsAck.msg_ids.add(messageIdf);
|
||||
sendMessageData(msgsAck, generateMessageId());
|
||||
|
||||
@ -305,8 +309,10 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
serverNonceAndNewNonce.writeRaw(authServerNonce);
|
||||
serverNonceAndNewNonce.writeRaw(authNewNonce);
|
||||
tmpAesKey.writeRaw(Utilities.computeSHA1(newNonceAndServerNonce.toByteArray()));
|
||||
newNonceAndServerNonce.cleanup();
|
||||
|
||||
byte[] serverNonceAndNewNonceHash = Utilities.computeSHA1(serverNonceAndNewNonce.toByteArray());
|
||||
serverNonceAndNewNonce.cleanup();
|
||||
byte[] serverNonceAndNewNonceHash0_12 = new byte[12];
|
||||
System.arraycopy(serverNonceAndNewNonceHash, 0, serverNonceAndNewNonceHash0_12, 0, 12);
|
||||
|
||||
@ -322,6 +328,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
newNonceAndNewNonce.writeRaw(authNewNonce);
|
||||
newNonceAndNewNonce.writeRaw(authNewNonce);
|
||||
tmpAesIv.writeRaw(Utilities.computeSHA1(newNonceAndNewNonce.toByteArray()));
|
||||
newNonceAndNewNonce.cleanup();
|
||||
|
||||
byte[] newNonce0_4 = new byte[4];
|
||||
System.arraycopy(authNewNonce, 0, newNonce0_4, 0, 4);
|
||||
@ -417,6 +424,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
serverSaltData.writeByte(x);
|
||||
}
|
||||
ByteBuffer saltBuffer = ByteBuffer.wrap(serverSaltData.toByteArray());
|
||||
serverSaltData.cleanup();
|
||||
|
||||
timeDifference = dhInnerData.server_time - (int)(System.currentTimeMillis() / 1000);
|
||||
|
||||
@ -455,8 +463,11 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
Utilities.aesIgeEncryption(clientDataWithHash.buffer, tmpAesKey.toByteArray(), tmpAesIv.toByteArray(), true, false, 0, clientDataWithHash.length());
|
||||
setClientDhParams.encrypted_data = clientDataWithHash;
|
||||
|
||||
tmpAesKey.cleanup();
|
||||
tmpAesIv.cleanup();
|
||||
|
||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||
msgsAck.msg_ids = new ArrayList<Long>();
|
||||
msgsAck.msg_ids = new ArrayList<>();
|
||||
msgsAck.msg_ids.add(messageId);
|
||||
sendMessageData(msgsAck, generateMessageId());
|
||||
|
||||
@ -494,7 +505,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
}
|
||||
|
||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||
msgsAck.msg_ids = new ArrayList<Long>();
|
||||
msgsAck.msg_ids = new ArrayList<>();
|
||||
msgsAck.msg_ids.add(messageId);
|
||||
sendMessageData(msgsAck, generateMessageId());
|
||||
|
||||
@ -507,6 +518,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
newNonce1.writeByte(1);
|
||||
newNonce1.writeRaw(authKeyAuxHash);
|
||||
byte[] newNonceHash1Full = Utilities.computeSHA1(newNonce1.toByteArray());
|
||||
newNonce1.cleanup();
|
||||
byte[] newNonceHash1 = new byte[16];
|
||||
System.arraycopy(newNonceHash1Full, newNonceHash1Full.length - 16, newNonceHash1, 0, 16);
|
||||
|
||||
@ -515,6 +527,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
newNonce2.writeByte(2);
|
||||
newNonce2.writeRaw(authKeyAuxHash);
|
||||
byte[] newNonceHash2Full = Utilities.computeSHA1(newNonce2.toByteArray());
|
||||
newNonce2.cleanup();
|
||||
byte[] newNonceHash2 = new byte[16];
|
||||
System.arraycopy(newNonceHash2Full, newNonceHash2Full.length - 16, newNonceHash2, 0, 16);
|
||||
|
||||
@ -523,6 +536,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
newNonce3.writeByte(3);
|
||||
newNonce3.writeRaw(authKeyAuxHash);
|
||||
byte[] newNonceHash3Full = Utilities.computeSHA1(newNonce3.toByteArray());
|
||||
newNonce3.cleanup();
|
||||
byte[] newNonceHash3 = new byte[16];
|
||||
System.arraycopy(newNonceHash3Full, newNonceHash3Full.length - 16, newNonceHash3, 0, 16);
|
||||
|
||||
@ -544,7 +558,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
datacenter.authKey = authKey;
|
||||
datacenter.authKeyId = authKeyId;
|
||||
datacenter.addServerSalt(serverSalt);
|
||||
HashMap<String, Object> resultDict = new HashMap<String, Object>();
|
||||
HashMap<String, Object> resultDict = new HashMap<>();
|
||||
resultDict.put("timeDifference", timeDifference);
|
||||
if (delegate != null) {
|
||||
delegate.ActionDidFinishExecution(parent, resultDict);
|
||||
@ -575,7 +589,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||
}
|
||||
} else {
|
||||
TLRPC.TL_msgs_ack msgsAck = new TLRPC.TL_msgs_ack();
|
||||
msgsAck.msg_ids = new ArrayList<Long>();
|
||||
msgsAck.msg_ids = new ArrayList<>();
|
||||
msgsAck.msg_ids.add(messageId);
|
||||
sendMessageData(msgsAck, generateMessageId());
|
||||
}
|
||||
|
@ -49,6 +49,41 @@ public class SerializedData extends AbsSerializedData {
|
||||
in = new DataInputStream(inbuf);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
try {
|
||||
if (inbuf != null) {
|
||||
inbuf.close();
|
||||
inbuf = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
in = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
try {
|
||||
if (outbuf != null) {
|
||||
outbuf.close();
|
||||
outbuf = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
try {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
out = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
public SerializedData(File file) throws Exception {
|
||||
FileInputStream is = new FileInputStream(file);
|
||||
byte[] data = new byte[(int)file.length()];
|
||||
|
@ -216,6 +216,7 @@ public class TLClassStore {
|
||||
classStore.put(TLRPC.TL_userStatusRecently.constructor, TLRPC.TL_userStatusRecently.class);
|
||||
classStore.put(TLRPC.TL_msg_copy.constructor, TLRPC.TL_msg_copy.class);
|
||||
classStore.put(TLRPC.TL_contacts_importedContacts.constructor, TLRPC.TL_contacts_importedContacts.class);
|
||||
classStore.put(TLRPC.TL_disabledFeature.constructor, TLRPC.TL_disabledFeature.class);
|
||||
classStore.put(TLRPC.TL_futureSalt.constructor, TLRPC.TL_futureSalt.class);
|
||||
classStore.put(TLRPC.TL_updateEncryptedMessagesRead.constructor, TLRPC.TL_updateEncryptedMessagesRead.class);
|
||||
classStore.put(TLRPC.TL_updateContactLink.constructor, TLRPC.TL_updateContactLink.class);
|
||||
@ -413,6 +414,7 @@ public class TLClassStore {
|
||||
classStore.put(TLRPC.TL_decryptedMessageHolder.constructor, TLRPC.TL_decryptedMessageHolder.class);
|
||||
classStore.put(TLRPC.TL_documentEncrypted_old.constructor, TLRPC.TL_documentEncrypted_old.class);
|
||||
classStore.put(TLRPC.TL_document_old.constructor, TLRPC.TL_document_old.class);
|
||||
classStore.put(TLRPC.TL_config_old.constructor, TLRPC.TL_config_old.class);
|
||||
}
|
||||
|
||||
static TLClassStore store = null;
|
||||
|
@ -16,7 +16,7 @@ public class TLRPC {
|
||||
|
||||
public static final int MESSAGE_FLAG_UNREAD = 1;
|
||||
public static final int MESSAGE_FLAG_OUT = 2;
|
||||
public static final int LAYER = 22;
|
||||
public static final int LAYER = 23;
|
||||
|
||||
public static class ChatPhoto extends TLObject {
|
||||
public FileLocation photo_small;
|
||||
@ -3743,6 +3743,24 @@ public class TLRPC {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TL_disabledFeature extends TLObject {
|
||||
public static int constructor = 0xae636f24;
|
||||
|
||||
public String feature;
|
||||
public String description;
|
||||
|
||||
public void readParams(AbsSerializedData stream) {
|
||||
feature = stream.readString();
|
||||
description = stream.readString();
|
||||
}
|
||||
|
||||
public void serializeToStream(AbsSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeString(feature);
|
||||
stream.writeString(description);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TL_futureSalt extends TLObject {
|
||||
public static int constructor = 0x0949d9dc;
|
||||
|
||||
@ -5023,17 +5041,21 @@ public class TLRPC {
|
||||
}
|
||||
|
||||
public static class TL_config extends TLObject {
|
||||
public static int constructor = 0x2e54dd74;
|
||||
public static int constructor = 0x7dae33e0;
|
||||
|
||||
public int date;
|
||||
public int expires;
|
||||
public boolean test_mode;
|
||||
public int this_dc;
|
||||
public ArrayList<TL_dcOption> dc_options = new ArrayList<>();
|
||||
public int chat_big_size;
|
||||
public int chat_size_max;
|
||||
public int broadcast_size_max;
|
||||
public ArrayList<TL_disabledFeature> disabled_features = new ArrayList<>();
|
||||
|
||||
public void readParams(AbsSerializedData stream) {
|
||||
date = stream.readInt32();
|
||||
expires = stream.readInt32();
|
||||
test_mode = stream.readBool();
|
||||
this_dc = stream.readInt32();
|
||||
stream.readInt32();
|
||||
@ -5041,23 +5063,37 @@ public class TLRPC {
|
||||
for (int a = 0; a < count; a++) {
|
||||
dc_options.add((TL_dcOption)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32()));
|
||||
}
|
||||
chat_big_size = stream.readInt32();
|
||||
chat_size_max = stream.readInt32();
|
||||
broadcast_size_max = stream.readInt32();
|
||||
stream.readInt32();
|
||||
count = stream.readInt32();
|
||||
for (int a = 0; a < count; a++) {
|
||||
disabled_features.add((TL_disabledFeature)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32()));
|
||||
}
|
||||
}
|
||||
|
||||
public void serializeToStream(AbsSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeInt32(date);
|
||||
stream.writeInt32(expires);
|
||||
stream.writeBool(test_mode);
|
||||
stream.writeInt32(this_dc);
|
||||
stream.writeInt32(0x1cb5c415);
|
||||
int count = dc_options.size();
|
||||
stream.writeInt32(count);
|
||||
for (TL_dcOption dc_option : dc_options) {
|
||||
dc_option.serializeToStream(stream);
|
||||
for (int a = 0; a < count; a++) {
|
||||
dc_options.get(a).serializeToStream(stream);
|
||||
}
|
||||
stream.writeInt32(chat_big_size);
|
||||
stream.writeInt32(chat_size_max);
|
||||
stream.writeInt32(broadcast_size_max);
|
||||
stream.writeInt32(0x1cb5c415);
|
||||
count = disabled_features.size();
|
||||
stream.writeInt32(count);
|
||||
for (int a = 0; a < count; a++) {
|
||||
disabled_features.get(a).serializeToStream(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9298,6 +9334,40 @@ public class TLRPC {
|
||||
|
||||
//manually created
|
||||
|
||||
public static class TL_config_old extends TL_config {
|
||||
public static int constructor = 0x2e54dd74;
|
||||
|
||||
public void readParams(AbsSerializedData stream) {
|
||||
date = stream.readInt32();
|
||||
test_mode = stream.readBool();
|
||||
this_dc = stream.readInt32();
|
||||
stream.readInt32();
|
||||
int count = stream.readInt32();
|
||||
for (int a = 0; a < count; a++) {
|
||||
dc_options.add((TL_dcOption) TLClassStore.Instance().TLdeserialize(stream, stream.readInt32()));
|
||||
}
|
||||
chat_size_max = stream.readInt32();
|
||||
broadcast_size_max = stream.readInt32();
|
||||
expires = (int) (System.currentTimeMillis() / 1000) + 3600;
|
||||
chat_big_size = 10;
|
||||
}
|
||||
|
||||
public void serializeToStream(AbsSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeInt32(date);
|
||||
stream.writeBool(test_mode);
|
||||
stream.writeInt32(this_dc);
|
||||
stream.writeInt32(0x1cb5c415);
|
||||
int count = dc_options.size();
|
||||
stream.writeInt32(count);
|
||||
for (TL_dcOption dc_option : dc_options) {
|
||||
dc_option.serializeToStream(stream);
|
||||
}
|
||||
stream.writeInt32(chat_size_max);
|
||||
stream.writeInt32(broadcast_size_max);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TL_document_old extends TL_document {
|
||||
public static int constructor = 0x9efc6326;
|
||||
|
||||
|
@ -31,6 +31,12 @@ public class UserConfig {
|
||||
public static boolean saveIncomingPhotos = false;
|
||||
public static int contactsVersion = 1;
|
||||
public static boolean waitingForPasswordEnter = false;
|
||||
public static String passcodeHash = "";
|
||||
public static boolean appLocked = false;
|
||||
public static int passcodeType = 0;
|
||||
public static int autoLockIn = 60 * 60;
|
||||
public static int lastPauseTime = 0;
|
||||
public static boolean isWaitingForPasscodeEnter = false;
|
||||
|
||||
public static int getNewMessageId() {
|
||||
int id;
|
||||
@ -62,12 +68,19 @@ public class UserConfig {
|
||||
editor.putBoolean("registeredForInternalPush", registeredForInternalPush);
|
||||
editor.putBoolean("blockedUsersLoaded", blockedUsersLoaded);
|
||||
editor.putBoolean("waitingForPasswordEnter", waitingForPasswordEnter);
|
||||
editor.putString("passcodeHash1", passcodeHash);
|
||||
editor.putBoolean("appLocked", appLocked);
|
||||
editor.putInt("passcodeType", passcodeType);
|
||||
editor.putInt("autoLockIn", autoLockIn);
|
||||
editor.putInt("lastPauseTime", lastPauseTime);
|
||||
|
||||
if (currentUser != null) {
|
||||
if (withFile) {
|
||||
SerializedData data = new SerializedData();
|
||||
currentUser.serializeToStream(data);
|
||||
String userString = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
|
||||
editor.putString("user", userString);
|
||||
data.cleanup();
|
||||
}
|
||||
} else {
|
||||
editor.remove("user");
|
||||
@ -172,6 +185,7 @@ public class UserConfig {
|
||||
if (lastSendMessageId > -210000) {
|
||||
lastSendMessageId = -210000;
|
||||
}
|
||||
data.cleanup();
|
||||
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -195,12 +209,18 @@ public class UserConfig {
|
||||
registeredForInternalPush = preferences.getBoolean("registeredForInternalPush", false);
|
||||
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
|
||||
waitingForPasswordEnter = preferences.getBoolean("waitingForPasswordEnter", false);
|
||||
passcodeHash = preferences.getString("passcodeHash1", "");
|
||||
appLocked = preferences.getBoolean("appLocked", false);
|
||||
passcodeType = preferences.getInt("passcodeType", 0);
|
||||
autoLockIn = preferences.getInt("autoLockIn", 60 * 60);
|
||||
lastPauseTime = preferences.getInt("lastPauseTime", 0);
|
||||
String user = preferences.getString("user", null);
|
||||
if (user != null) {
|
||||
byte[] userBytes = Base64.decode(user, Base64.DEFAULT);
|
||||
if (userBytes != null) {
|
||||
SerializedData data = new SerializedData(userBytes);
|
||||
currentUser = (TLRPC.TL_userSelf)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
data.cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -214,12 +234,17 @@ public class UserConfig {
|
||||
waitingForPasswordEnter = false;
|
||||
contactsHash = "";
|
||||
importHash = "";
|
||||
lastLocalId = -210000;
|
||||
lastSendMessageId = -210000;
|
||||
contactsVersion = 1;
|
||||
lastBroadcastId = -1;
|
||||
saveIncomingPhotos = false;
|
||||
blockedUsersLoaded = false;
|
||||
appLocked = false;
|
||||
passcodeType = 0;
|
||||
passcodeHash = "";
|
||||
autoLockIn = 60 * 60;
|
||||
lastPauseTime = 0;
|
||||
isWaitingForPasscodeEnter = false;
|
||||
saveConfig(true);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ import net.hockeyapp.android.CrashManager;
|
||||
import net.hockeyapp.android.CrashManagerListener;
|
||||
import net.hockeyapp.android.UpdateManager;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -97,6 +99,7 @@ public class Utilities {
|
||||
for (int a = 0; a < count; a++) {
|
||||
goodPrimes.add(data.readString());
|
||||
}
|
||||
data.cleanup();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
@ -109,6 +112,7 @@ public class Utilities {
|
||||
public native static long doPQNative(long _what);
|
||||
public native static void loadBitmap(String path, Bitmap bitmap, int scale, int width, int height, int stride);
|
||||
public native static void blurBitmap(Object bitmap, int radius);
|
||||
public native static void calcCDT(ByteBuffer hsvBuffer, int width, int height, ByteBuffer buffer);
|
||||
public native static Bitmap loadWebpImage(ByteBuffer buffer, int len, BitmapFactory.Options options);
|
||||
public native static Bitmap loadBpgImage(ByteBuffer buffer, int len, BitmapFactory.Options options);
|
||||
public native static int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding, int swap);
|
||||
@ -228,6 +232,7 @@ public class Utilities {
|
||||
data.writeString(pr);
|
||||
}
|
||||
byte[] bytes = data.toByteArray();
|
||||
data.cleanup();
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("primes", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putString("primes", Base64.encodeToString(bytes, Base64.DEFAULT));
|
||||
@ -363,35 +368,41 @@ public class Utilities {
|
||||
data.writeRaw(messageKey);
|
||||
data.writeRaw(authKey, x, 32);
|
||||
byte[] sha1_a = Utilities.computeSHA1(data.toByteArray());
|
||||
data.cleanup();
|
||||
|
||||
data = new SerializedData();
|
||||
data.writeRaw(authKey, 32 + x, 16);
|
||||
data.writeRaw(messageKey);
|
||||
data.writeRaw(authKey, 48 + x, 16);
|
||||
byte[] sha1_b = Utilities.computeSHA1(data.toByteArray());
|
||||
data.cleanup();
|
||||
|
||||
data = new SerializedData();
|
||||
data.writeRaw(authKey, 64 + x, 32);
|
||||
data.writeRaw(messageKey);
|
||||
byte[] sha1_c = Utilities.computeSHA1(data.toByteArray());
|
||||
data.cleanup();
|
||||
|
||||
data = new SerializedData();
|
||||
data.writeRaw(messageKey);
|
||||
data.writeRaw(authKey, 96 + x, 32);
|
||||
byte[] sha1_d = Utilities.computeSHA1(data.toByteArray());
|
||||
data.cleanup();
|
||||
|
||||
SerializedData aesKey = new SerializedData();
|
||||
aesKey.writeRaw(sha1_a, 0, 8);
|
||||
aesKey.writeRaw(sha1_b, 8, 12);
|
||||
aesKey.writeRaw(sha1_c, 4, 12);
|
||||
keyData.aesKey = aesKey.toByteArray();
|
||||
data = new SerializedData();
|
||||
data.writeRaw(sha1_a, 0, 8);
|
||||
data.writeRaw(sha1_b, 8, 12);
|
||||
data.writeRaw(sha1_c, 4, 12);
|
||||
keyData.aesKey = data.toByteArray();
|
||||
data.cleanup();
|
||||
|
||||
SerializedData aesIv = new SerializedData();
|
||||
aesIv.writeRaw(sha1_a, 8, 12);
|
||||
aesIv.writeRaw(sha1_b, 0, 8);
|
||||
aesIv.writeRaw(sha1_c, 16, 4);
|
||||
aesIv.writeRaw(sha1_d, 0, 8);
|
||||
keyData.aesIv = aesIv.toByteArray();
|
||||
data = new SerializedData();
|
||||
data.writeRaw(sha1_a, 8, 12);
|
||||
data.writeRaw(sha1_b, 0, 8);
|
||||
data.writeRaw(sha1_c, 16, 4);
|
||||
data.writeRaw(sha1_d, 0, 8);
|
||||
keyData.aesIv = data.toByteArray();
|
||||
data.cleanup();
|
||||
|
||||
return keyData;
|
||||
}
|
||||
@ -408,10 +419,25 @@ public class Utilities {
|
||||
while ((bytesRead = gis.read(data)) != -1) {
|
||||
bytesOutput.write(data, 0, bytesRead);
|
||||
}
|
||||
try {
|
||||
gis.close();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
try {
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
SerializedData stream = new SerializedData(bytesOutput.toByteArray());
|
||||
return TLClassStore.Instance().TLdeserialize(stream, stream.readInt32(), parentObject);
|
||||
try {
|
||||
bytesOutput.close();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
TLObject object = TLClassStore.Instance().TLdeserialize(stream, stream.readInt32(), parentObject);
|
||||
stream.cleanup();
|
||||
return object;
|
||||
} catch (IOException e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
@ -432,6 +458,12 @@ public class Utilities {
|
||||
packedData = bytesStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
FileLog.e("tmessages", e);
|
||||
} finally {
|
||||
try {
|
||||
bytesStream.close();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
return packedData;
|
||||
}
|
||||
@ -449,23 +481,23 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public static boolean copyFile(File sourceFile, File destFile) throws IOException {
|
||||
if(!destFile.exists()) {
|
||||
if (!destFile.exists()) {
|
||||
destFile.createNewFile();
|
||||
}
|
||||
FileChannel source = null;
|
||||
FileChannel destination = null;
|
||||
FileInputStream source = null;
|
||||
FileOutputStream destination = null;
|
||||
try {
|
||||
source = new FileInputStream(sourceFile).getChannel();
|
||||
destination = new FileOutputStream(destFile).getChannel();
|
||||
destination.transferFrom(source, 0, source.size());
|
||||
source = new FileInputStream(sourceFile);
|
||||
destination = new FileOutputStream(destFile);
|
||||
destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size());
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
return false;
|
||||
} finally {
|
||||
if(source != null) {
|
||||
if (source != null) {
|
||||
source.close();
|
||||
}
|
||||
if(destination != null) {
|
||||
if (destination != null) {
|
||||
destination.close();
|
||||
}
|
||||
}
|
||||
@ -638,7 +670,7 @@ public class Utilities {
|
||||
}
|
||||
wholeString = wholeString.trim();
|
||||
String lower = " " + wholeString.toLowerCase();
|
||||
|
||||
String hexDarkColor = String.format("#%06X", (0xFFFFFF & AndroidUtilities.getIntDarkerColor("themeColor", 0x15)));
|
||||
int index = -1;
|
||||
int lastIndex = 0;
|
||||
while ((index = lower.indexOf(" " + q, lastIndex)) != -1) {
|
||||
@ -656,7 +688,8 @@ public class Utilities {
|
||||
builder.append(" ");
|
||||
}
|
||||
query.trim();
|
||||
builder.append(Html.fromHtml("<font color=\"#4d83b3\">" + query + "</font>"));
|
||||
builder.append(Html.fromHtml("<font color=" + hexDarkColor + ">" + query + "</font>"));
|
||||
//builder.append(Html.fromHtml("<font color=\"#4d83b3\">" + query + "</font>"));
|
||||
|
||||
lastIndex = end;
|
||||
}
|
||||
@ -711,7 +744,13 @@ public class Utilities {
|
||||
buffer.write(b);
|
||||
}
|
||||
}
|
||||
return buffer.toByteArray();
|
||||
byte[] array = buffer.toByteArray();
|
||||
try {
|
||||
buffer.close();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static void checkForCrashes(Activity context) {
|
||||
|
@ -94,7 +94,7 @@ public class AccountPasswordActivity extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
if (fragmentView == null) {
|
||||
if (type == 0) {
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
@ -271,7 +271,7 @@ public class AccountPasswordActivity extends BaseFragment {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void needShowAlert(final String text) {
|
||||
private void ShowAlert(final String text) {
|
||||
if (text == null || getParentActivity() == null) {
|
||||
return;
|
||||
}
|
||||
@ -355,20 +355,20 @@ public class AccountPasswordActivity extends BaseFragment {
|
||||
String hint = hintPasswordCell.getFieldText();
|
||||
if (hasPassword) {
|
||||
if (oldPassword.length() == 0) {
|
||||
needShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
||||
ShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (newPassword.length() == 0) {
|
||||
needShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
|
||||
ShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
|
||||
return;
|
||||
}
|
||||
if (!newPassword.equals(verifyPasswrod)) {
|
||||
needShowAlert(LocaleController.getString("PasswordDoNotMatch", R.string.PasswordDoNotMatch));
|
||||
ShowAlert(LocaleController.getString("PasswordDoNotMatch", R.string.PasswordDoNotMatch));
|
||||
return;
|
||||
}
|
||||
if (hint.toLowerCase().contains(newPassword.toLowerCase())) {
|
||||
needShowAlert(LocaleController.getString("HintIncorrect", R.string.HintIncorrect));
|
||||
ShowAlert(LocaleController.getString("HintIncorrect", R.string.HintIncorrect));
|
||||
return;
|
||||
}
|
||||
byte[] oldPasswordBytes = null;
|
||||
@ -418,13 +418,13 @@ public class AccountPasswordActivity extends BaseFragment {
|
||||
finishFragment();
|
||||
} else {
|
||||
if (error.text.contains("PASSWORD_HASH_INVALID")) {
|
||||
needShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
||||
ShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
||||
} else if (error.text.contains("NEW_PASSWORD_BAD")) {
|
||||
needShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
|
||||
ShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
|
||||
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
||||
needShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
|
||||
ShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
|
||||
} else {
|
||||
needShowAlert(error.text);
|
||||
ShowAlert(error.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -434,7 +434,7 @@ public class AccountPasswordActivity extends BaseFragment {
|
||||
} else if (type == 1) {
|
||||
String oldPassword = oldPasswordCell.getFieldText();
|
||||
if (oldPassword.length() == 0) {
|
||||
needShowAlert(LocaleController.getString("PasswordIncorrect", R.string.PasswordIncorrect));
|
||||
ShowAlert(LocaleController.getString("PasswordIncorrect", R.string.PasswordIncorrect));
|
||||
return;
|
||||
}
|
||||
byte[] oldPasswordBytes = null;
|
||||
@ -486,11 +486,11 @@ public class AccountPasswordActivity extends BaseFragment {
|
||||
}
|
||||
} else {
|
||||
if (error.text.contains("PASSWORD_HASH_INVALID")) {
|
||||
needShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
||||
ShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
|
||||
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
||||
needShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
|
||||
ShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
|
||||
} else {
|
||||
needShowAlert(error.text);
|
||||
ShowAlert(error.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,11 +8,14 @@
|
||||
|
||||
package org.telegram.ui.ActionBar;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
@ -91,9 +94,9 @@ public class ActionBar extends FrameLayout {
|
||||
|
||||
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
|
||||
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
titleTextView.setTextSize(18);
|
||||
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
||||
} else {
|
||||
titleTextView.setTextSize(20);
|
||||
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
||||
}
|
||||
|
||||
layoutParams = (LayoutParams) titleTextView.getLayoutParams();
|
||||
@ -106,9 +109,9 @@ public class ActionBar extends FrameLayout {
|
||||
}
|
||||
if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) {
|
||||
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
subTitleTextView.setTextSize(14);
|
||||
subTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||
} else {
|
||||
subTitleTextView.setTextSize(16);
|
||||
subTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||
}
|
||||
|
||||
layoutParams = (LayoutParams) subTitleTextView.getLayoutParams();
|
||||
@ -136,7 +139,7 @@ public class ActionBar extends FrameLayout {
|
||||
}
|
||||
|
||||
if (menu != null) {
|
||||
maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - AndroidUtilities.dp(16));
|
||||
maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - AndroidUtilities.dp(16) - x);
|
||||
}
|
||||
|
||||
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
|
||||
@ -173,7 +176,7 @@ public class ActionBar extends FrameLayout {
|
||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams();
|
||||
layoutParams.width = isSearchFieldVisible ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = height;
|
||||
layoutParams.leftMargin = isSearchFieldVisible ? AndroidUtilities.dp(54) : 0;
|
||||
layoutParams.leftMargin = isSearchFieldVisible ? AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66) : 0;
|
||||
layoutParams.topMargin = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
|
||||
menu.setLayoutParams(layoutParams);
|
||||
menu.measure(width, height);
|
||||
@ -366,7 +369,7 @@ public class ActionBar extends FrameLayout {
|
||||
return;
|
||||
}
|
||||
actionMode.setVisibility(VISIBLE);
|
||||
if (actionModeTop != null) {
|
||||
if (occupyStatusBar && actionModeTop != null) {
|
||||
actionModeTop.setVisibility(VISIBLE);
|
||||
}
|
||||
if (titleFrameLayout != null) {
|
||||
@ -382,7 +385,7 @@ public class ActionBar extends FrameLayout {
|
||||
return;
|
||||
}
|
||||
actionMode.setVisibility(GONE);
|
||||
if (actionModeTop != null) {
|
||||
if (occupyStatusBar && actionModeTop != null) {
|
||||
actionModeTop.setVisibility(GONE);
|
||||
}
|
||||
if (titleFrameLayout != null) {
|
||||
@ -473,6 +476,9 @@ public class ActionBar extends FrameLayout {
|
||||
|
||||
public void setOccupyStatusBar(boolean value) {
|
||||
occupyStatusBar = value;
|
||||
if (actionMode != null) {
|
||||
actionMode.setPadding(0, occupyStatusBar ? AndroidUtilities.statusBarHeight : 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getOccupyStatusBar() {
|
||||
@ -484,6 +490,11 @@ public class ActionBar extends FrameLayout {
|
||||
if (backButtonImageView != null) {
|
||||
backButtonImageView.setBackgroundResource(itemsBackgroundResourceId);
|
||||
}
|
||||
//
|
||||
//SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
//setBackgroundColor(themePrefs.getInt("themeColor", 0x000000));
|
||||
setBackgroundColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
//
|
||||
}
|
||||
|
||||
public void setCastShadows(boolean value) {
|
||||
|
@ -225,7 +225,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
||||
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
||||
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
return delegate != null && delegate.onPreIme() || super.dispatchKeyEventPreIme(event);
|
||||
}
|
||||
return super.dispatchKeyEventPreIme(event);
|
||||
@ -321,7 +321,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||
beginTrackingSent = false;
|
||||
|
||||
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
||||
View fragmentView = lastFragment.createView(parentActivity.getLayoutInflater(), null);
|
||||
View fragmentView = lastFragment.createView(parentActivity.getLayoutInflater());
|
||||
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(fragmentView);
|
||||
@ -502,8 +502,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
public boolean checkTransitionAnimation() {
|
||||
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 400) {
|
||||
transitionAnimationInProgress = false;
|
||||
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 1000) {
|
||||
onAnimationEndCheck(true);
|
||||
}
|
||||
return transitionAnimationInProgress;
|
||||
@ -556,7 +555,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||
final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null;
|
||||
|
||||
fragment.setParentLayout(this);
|
||||
View fragmentView = fragment.createView(parentActivity.getLayoutInflater(), null);
|
||||
View fragmentView = fragment.createView(parentActivity.getLayoutInflater());
|
||||
if (fragment.needAddActionBar() && fragment.actionBar != null) {
|
||||
if (removeActionBarExtraHeight) {
|
||||
fragment.actionBar.setOccupyStatusBar(false);
|
||||
@ -585,6 +584,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||
containerView = containerViewBack;
|
||||
containerViewBack = temp;
|
||||
containerView.setVisibility(View.VISIBLE);
|
||||
setInnerTranslationX(0);
|
||||
|
||||
bringChildToFront(containerView);
|
||||
|
||||
@ -633,6 +633,8 @@ public class ActionBarLayout extends FrameLayout {
|
||||
ViewProxy.setTranslationX(containerView, 0);
|
||||
}
|
||||
};
|
||||
ViewProxy.setAlpha(containerView, 0.0f);
|
||||
ViewProxy.setTranslationX(containerView, 48.0f);
|
||||
currentAnimation = new AnimatorSetProxy();
|
||||
currentAnimation.playTogether(
|
||||
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f, 1.0f),
|
||||
@ -640,6 +642,11 @@ public class ActionBarLayout extends FrameLayout {
|
||||
currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
|
||||
currentAnimation.setDuration(200);
|
||||
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
||||
@Override
|
||||
public void onAnimationStart(Object animation) {
|
||||
transitionAnimationStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Object animation) {
|
||||
onAnimationEndCheck(false);
|
||||
@ -672,6 +679,22 @@ public class ActionBarLayout extends FrameLayout {
|
||||
}
|
||||
fragment.setParentLayout(this);
|
||||
if (position == -1) {
|
||||
if (!fragmentsStack.isEmpty()) {
|
||||
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
||||
previousFragment.onPause();
|
||||
if (previousFragment.actionBar != null) {
|
||||
ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(previousFragment.actionBar);
|
||||
}
|
||||
}
|
||||
if (previousFragment.fragmentView != null) {
|
||||
ViewGroup parent = (ViewGroup) previousFragment.fragmentView.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(previousFragment.fragmentView);
|
||||
}
|
||||
}
|
||||
}
|
||||
fragmentsStack.add(fragment);
|
||||
} else {
|
||||
fragmentsStack.add(position, fragment);
|
||||
@ -689,12 +712,13 @@ public class ActionBarLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
public void closeLastFragment(boolean animated) {
|
||||
if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation()) {
|
||||
if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation() || fragmentsStack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (parentActivity.getCurrentFocus() != null) {
|
||||
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
|
||||
}
|
||||
setInnerTranslationX(0);
|
||||
boolean needAnimation = Build.VERSION.SDK_INT > 10 && animated && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
|
||||
final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
||||
BaseFragment previousFragment = null;
|
||||
@ -709,7 +733,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||
containerView.setVisibility(View.VISIBLE);
|
||||
|
||||
previousFragment.setParentLayout(this);
|
||||
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater(), null);
|
||||
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater());
|
||||
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
|
||||
if (removeActionBarExtraHeight) {
|
||||
previousFragment.actionBar.setOccupyStatusBar(false);
|
||||
@ -754,6 +778,11 @@ public class ActionBarLayout extends FrameLayout {
|
||||
currentAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
|
||||
currentAnimation.setDuration(200);
|
||||
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
||||
@Override
|
||||
public void onAnimationStart(Object animation) {
|
||||
transitionAnimationStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Object animation) {
|
||||
onAnimationEndCheck(false);
|
||||
@ -796,6 +825,11 @@ public class ActionBarLayout extends FrameLayout {
|
||||
currentAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
currentAnimation.setDuration(200);
|
||||
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
||||
@Override
|
||||
public void onAnimationStart(Object animation) {
|
||||
transitionAnimationStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Object animation) {
|
||||
onAnimationEndCheck(false);
|
||||
@ -823,7 +857,7 @@ public class ActionBarLayout extends FrameLayout {
|
||||
}
|
||||
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
||||
previousFragment.setParentLayout(this);
|
||||
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater(), null);
|
||||
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater());
|
||||
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
|
||||
if (removeActionBarExtraHeight) {
|
||||
previousFragment.actionBar.setOccupyStatusBar(false);
|
||||
|
@ -348,6 +348,10 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
|
||||
}
|
||||
}
|
||||
|
||||
public void setIcon(int resId) {
|
||||
iconView.setImageResource(resId);
|
||||
}
|
||||
|
||||
public EditText getSearchField() {
|
||||
return searchField;
|
||||
}
|
||||
@ -399,7 +403,7 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
|
||||
searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH || event != null && event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH || event != null && (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
|
||||
AndroidUtilities.hideKeyboard(searchField);
|
||||
if (listener != null) {
|
||||
listener.onSearchPressed(searchField);
|
||||
|
@ -200,7 +200,11 @@ public class ActionBarPopupWindow extends PopupWindow {
|
||||
@Override
|
||||
public void dismiss() {
|
||||
setFocusable(false);
|
||||
try {
|
||||
super.dismiss();
|
||||
} catch (Exception e) {
|
||||
//don't promt
|
||||
}
|
||||
unregisterListener();
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class BaseFragment {
|
||||
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
||||
}
|
||||
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ public class BaseFragment {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void showAlertDialog(AlertDialog.Builder builder) {
|
||||
public void showAlertDialog(AlertDialog.Builder builder) {
|
||||
if (parentLayout == null || parentLayout.checkTransitionAnimation() || parentLayout.animationInProgress || parentLayout.startedTracking) {
|
||||
return;
|
||||
}
|
||||
|
@ -165,6 +165,9 @@ public class DrawerLayoutContainer extends FrameLayout {
|
||||
}
|
||||
|
||||
public void openDrawer(boolean fast) {
|
||||
if (!allowOpenDrawer) {
|
||||
return;
|
||||
}
|
||||
if (AndroidUtilities.isTablet() && parentActionBarLayout != null && parentActionBarLayout.parentActivity != null) {
|
||||
AndroidUtilities.hideKeyboard(parentActionBarLayout.parentActivity.getCurrentFocus());
|
||||
}
|
||||
|
@ -8,13 +8,16 @@
|
||||
|
||||
package org.telegram.ui.Adapters;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.LocaleController;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.android.ContactsController;
|
||||
import org.telegram.android.MessagesController;
|
||||
@ -28,6 +31,7 @@ import org.telegram.ui.Cells.UserCell;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ContactsAdapter extends BaseSectionsAdapter {
|
||||
|
||||
@ -187,12 +191,15 @@ public class ContactsAdapter extends BaseSectionsAdapter {
|
||||
if (convertView == null) {
|
||||
convertView = new GreySectionCell(mContext);
|
||||
((GreySectionCell) convertView).setText(LocaleController.getString("Contacts", R.string.Contacts).toUpperCase());
|
||||
//((GreySectionCell) convertView).setText(String.format(Locale.US, " %d " + LocaleController.getString("Contacts", R.string.Contacts).toUpperCase(), arr0.size()));
|
||||
((GreySectionCell) convertView).setBackgroundColor(AndroidUtilities.getIntDef("contactsRowColor", 0xffffffff));
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (convertView == null) {
|
||||
convertView = new TextCell(mContext);
|
||||
}
|
||||
TextCell actionCell = (TextCell) convertView;
|
||||
actionCell.setTextColor(AndroidUtilities.getIntDef("contactsNameColor", 0xff000000));
|
||||
if (needPhonebook) {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite);
|
||||
} else {
|
||||
@ -207,6 +214,8 @@ public class ContactsAdapter extends BaseSectionsAdapter {
|
||||
} else if (type == 1) {
|
||||
if (convertView == null) {
|
||||
convertView = new TextCell(mContext);
|
||||
((TextCell) convertView).setTextColor(AndroidUtilities.getIntDef("contactsNameColor", 0xff000000));
|
||||
((TextCell) convertView).setTextSize(AndroidUtilities.getIntDef("contactsNameSize", 16));
|
||||
}
|
||||
ContactsController.Contact contact = ContactsController.getInstance().phoneBookContacts.get(position);
|
||||
if (contact.first_name != null && contact.last_name != null) {
|
||||
@ -219,7 +228,9 @@ public class ContactsAdapter extends BaseSectionsAdapter {
|
||||
} else if (type == 0) {
|
||||
if (convertView == null) {
|
||||
convertView = new UserCell(mContext, 58);
|
||||
((UserCell) convertView).setStatusColors(0xffa8a8a8, 0xff3b84c0);
|
||||
//((UserCell) convertView).setStatusColors(0xffa8a8a8, 0xff3b84c0);
|
||||
((UserCell) convertView).setStatusColors(AndroidUtilities.getIntDef("contactsStatusColor", 0xffa8a8a8), AndroidUtilities.getIntDef("contactsOnlineColor", AndroidUtilities.getIntDarkerColor("themeColor",0x15)));
|
||||
((UserCell) convertView).setNameColor(AndroidUtilities.getIntDef("contactsNameColor", 0xff000000));
|
||||
}
|
||||
|
||||
ArrayList<TLRPC.TL_contact> arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section - (onlyUsers ? 0 : 1)));
|
||||
@ -236,6 +247,7 @@ public class ContactsAdapter extends BaseSectionsAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
parent.setBackgroundColor(AndroidUtilities.getIntDef("contactsRowColor", 0xffffffff));
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
@ -124,10 +124,14 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
}
|
||||
|
||||
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
|
||||
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||
if (name.equals(tName)) {
|
||||
tName = null;
|
||||
}
|
||||
|
||||
int found = 0;
|
||||
for (String q : search) {
|
||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
||||
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||
found = 1;
|
||||
} else if (user.username != null && user.username.startsWith(q)) {
|
||||
found = 2;
|
||||
@ -234,7 +238,7 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
view = new ProfileSearchCell(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
String hexDarkColor = String.format("#%06X", (0xFFFFFF & AndroidUtilities.getIntDarkerColor("themeColor", 0x15)));
|
||||
TLRPC.User user = getItem(i);
|
||||
if (user != null) {
|
||||
CharSequence username = null;
|
||||
@ -253,7 +257,8 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
foundUserName = foundUserName.substring(1);
|
||||
}
|
||||
try {
|
||||
username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||
username = Html.fromHtml(String.format("<font color="+ hexDarkColor +">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||
//username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||
} catch (Exception e) {
|
||||
username = user.username;
|
||||
FileLog.e("tmessages", e);
|
||||
|
@ -8,13 +8,17 @@
|
||||
|
||||
package org.telegram.ui.Adapters;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.MessageObject;
|
||||
import org.telegram.android.MessagesController;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.ui.Cells.DialogCell;
|
||||
import org.telegram.ui.Cells.LoadingCell;
|
||||
@ -24,6 +28,7 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||
private Context mContext;
|
||||
private boolean serverOnly;
|
||||
private long openedDialogId;
|
||||
private int currentCount;
|
||||
|
||||
public DialogsAdapter(Context context, boolean onlyFromServer) {
|
||||
mContext = context;
|
||||
@ -34,6 +39,11 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||
openedDialogId = id;
|
||||
}
|
||||
|
||||
public boolean isDataSetChanged() {
|
||||
int current = currentCount;
|
||||
return current != getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return true;
|
||||
@ -58,6 +68,7 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||
if (!MessagesController.getInstance().dialogsEndReached) {
|
||||
count++;
|
||||
}
|
||||
currentCount = count;
|
||||
return count;
|
||||
}
|
||||
|
||||
@ -97,6 +108,7 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||
if (view == null) {
|
||||
view = new DialogCell(mContext);
|
||||
}
|
||||
if (view instanceof DialogCell) { //TODO finally i need to find this crash
|
||||
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
||||
TLRPC.TL_dialog dialog = null;
|
||||
if (serverOnly) {
|
||||
@ -111,13 +123,18 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
MessageObject message = MessagesController.getInstance().dialogMessage.get(dialog.top_message);
|
||||
((DialogCell) view).setDialog(dialog.id, message, true, dialog.last_message_date, dialog.unread_count, MessagesController.getInstance().isDialogMuted(dialog.id));
|
||||
((DialogCell) view).setDialog(dialog, i, serverOnly);
|
||||
}
|
||||
}
|
||||
|
||||
updateColors(viewGroup);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void updateColors(ViewGroup viewGroup){
|
||||
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
viewGroup.setBackgroundColor(themePrefs.getInt("chatsRowColor", 0xffffffff));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
if (serverOnly && i == MessagesController.getInstance().dialogsServerOnly.size() || !serverOnly && i == MessagesController.getInstance().dialogs.size()) {
|
||||
@ -133,9 +150,6 @@ public class DialogsAdapter extends BaseFragmentAdapter {
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
int count;
|
||||
if (serverOnly) {
|
||||
count = MessagesController.getInstance().dialogsServerOnly.size();
|
||||
|
@ -215,6 +215,10 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, status, name FROM users WHERE uid IN(%s)", TextUtils.join(",", usersToLoad)));
|
||||
while (cursor.next()) {
|
||||
String name = cursor.stringValue(2);
|
||||
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||
if (name.equals(tName)) {
|
||||
tName = null;
|
||||
}
|
||||
String username = null;
|
||||
int usernamePos = name.lastIndexOf(";;;");
|
||||
if (usernamePos != -1) {
|
||||
@ -222,7 +226,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
}
|
||||
int found = 0;
|
||||
for (String q : search) {
|
||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
||||
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||
found = 1;
|
||||
} else if (username != null && username.startsWith(q)) {
|
||||
found = 2;
|
||||
@ -257,8 +261,12 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, name FROM chats WHERE uid IN(%s)", TextUtils.join(",", chatsToLoad)));
|
||||
while (cursor.next()) {
|
||||
String name = cursor.stringValue(1);
|
||||
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||
if (name.equals(tName)) {
|
||||
tName = null;
|
||||
}
|
||||
for (String q : search) {
|
||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
||||
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
|
||||
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
|
||||
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
@ -285,6 +293,10 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out, q.use_count, q.exchange_id, q.key_date, q.fprint, q.fauthkey, q.khash FROM enc_chats as q INNER JOIN users as u ON q.user = u.uid WHERE q.uid IN(%s)", TextUtils.join(",", encryptedToLoad)));
|
||||
while (cursor.next()) {
|
||||
String name = cursor.stringValue(1);
|
||||
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||
if (name.equals(tName)) {
|
||||
tName = null;
|
||||
}
|
||||
|
||||
String username = null;
|
||||
int usernamePos = name.lastIndexOf(";;;");
|
||||
@ -293,7 +305,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
}
|
||||
int found = 0;
|
||||
for (String q : search) {
|
||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
||||
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||
found = 1;
|
||||
} else if (username != null && username.startsWith(q)) {
|
||||
found = 2;
|
||||
@ -378,6 +390,10 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
continue;
|
||||
}
|
||||
String name = cursor.stringValue(2);
|
||||
String tName = LocaleController.getInstance().getTranslitString(name);
|
||||
if (name.equals(tName)) {
|
||||
tName = null;
|
||||
}
|
||||
String username = null;
|
||||
int usernamePos = name.lastIndexOf(";;;");
|
||||
if (usernamePos != -1) {
|
||||
@ -385,7 +401,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
}
|
||||
int found = 0;
|
||||
for (String q : search) {
|
||||
if (name.startsWith(q) || name.contains(" " + q)) {
|
||||
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
|
||||
found = 1;
|
||||
} else if (username != null && username.startsWith(q)) {
|
||||
found = 2;
|
||||
@ -573,7 +589,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
|
||||
int localCount = searchResult.size();
|
||||
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
|
||||
|
||||
String hexDarkColor = String.format("#%06X", (0xFFFFFF & AndroidUtilities.getIntDarkerColor("themeColor", 0x15)));
|
||||
((ProfileSearchCell) view).useSeparator = (i != getCount() - 1 && i != localCount - 1 && i != localCount + globalCount - 1);
|
||||
Object obj = getItem(i);
|
||||
if (obj instanceof TLRPC.User) {
|
||||
@ -604,7 +620,8 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
foundUserName = foundUserName.substring(1);
|
||||
}
|
||||
try {
|
||||
username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||
username = Html.fromHtml(String.format("<font color=" + hexDarkColor + ">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||
//username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
|
||||
} catch (Exception e) {
|
||||
username = user.username;
|
||||
FileLog.e("tmessages", e);
|
||||
@ -618,7 +635,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
|
||||
}
|
||||
((DialogCell) view).useSeparator = (i != getCount() - 1);
|
||||
MessageObject messageObject = (MessageObject)getItem(i);
|
||||
((DialogCell) view).setDialog(messageObject.getDialogId(), messageObject, false, messageObject.messageOwner.date, 0, false);
|
||||
((DialogCell) view).setDialog(messageObject.getDialogId(), messageObject, messageObject.messageOwner.date);
|
||||
} else if (type == 3) {
|
||||
if (view == null) {
|
||||
view = new LoadingCell(mContext);
|
||||
|
@ -9,22 +9,34 @@
|
||||
package org.telegram.ui.Adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import org.telegram.android.LocaleController;
|
||||
import org.telegram.android.MessagesController;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.ui.Cells.DrawerActionCell;
|
||||
import org.telegram.ui.Cells.DividerCell;
|
||||
import org.telegram.ui.Cells.EmptyCell;
|
||||
import org.telegram.ui.Cells.DrawerActionCell;
|
||||
import org.telegram.ui.Cells.DrawerProfileCell;
|
||||
import org.telegram.ui.Cells.EmptyCell;
|
||||
import org.telegram.ui.Cells.TextInfoCell;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class DrawerLayoutAdapter extends BaseAdapter {
|
||||
|
||||
private Context mContext;
|
||||
private int versionType = 4;
|
||||
private int versionRow = 10;
|
||||
private int themingRow = 7;
|
||||
private int communityRow = 9;
|
||||
|
||||
private int rowCount = 0;
|
||||
|
||||
public DrawerLayoutAdapter(Context context) {
|
||||
mContext = context;
|
||||
@ -42,7 +54,8 @@ public class DrawerLayoutAdapter extends BaseAdapter {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return UserConfig.isClientActivated() ? 10 : 0;
|
||||
//return UserConfig.isClientActivated() ? 10 : 0;
|
||||
return UserConfig.isClientActivated() ? 11 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,12 +102,26 @@ public class DrawerLayoutAdapter extends BaseAdapter {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList), R.drawable.menu_broadcast);
|
||||
} else if (i == 6) {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("Contacts", R.string.Contacts), R.drawable.menu_contacts);
|
||||
} else if (i == 7) {
|
||||
}/* else if (i == 7) {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite);
|
||||
}*/ else if (i == themingRow) {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("Theming", R.string.Theming), R.drawable.menu_theming);
|
||||
} else if (i == 8) {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("Settings", R.string.Settings), R.drawable.menu_settings);
|
||||
} else if (i == 9) {
|
||||
} else if (i == communityRow) {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("Community", R.string.Community), R.drawable.menu_forum);
|
||||
} /*else if (i == 10) {
|
||||
actionCell.setTextAndIcon(LocaleController.getString("TelegramFaq", R.string.TelegramFaq), R.drawable.menu_help);
|
||||
}*/
|
||||
} else if (type == versionType) {
|
||||
view = new TextInfoCell(mContext);
|
||||
if (i == versionRow) {
|
||||
try {
|
||||
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
|
||||
((TextInfoCell) view).setText(String.format(Locale.US, LocaleController.getString("TelegramForAndroid", R.string.TelegramForAndroid)+" v%s (%d)", pInfo.versionName, pInfo.versionCode));
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,12 +137,17 @@ public class DrawerLayoutAdapter extends BaseAdapter {
|
||||
} else if (i == 5) {
|
||||
return 2;
|
||||
}
|
||||
//new
|
||||
else if (i == versionRow) {
|
||||
return versionType;
|
||||
}
|
||||
//
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -203,6 +203,9 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
|
||||
}
|
||||
HashMap<Long, TLRPC.Document> documents = new HashMap<>();
|
||||
for (TLRPC.Document document : res.documents) {
|
||||
if (document == null) {
|
||||
continue;
|
||||
}
|
||||
documents.put(document.id, document);
|
||||
if (document.thumb != null && document.thumb.location != null) {
|
||||
document.thumb.location.ext = "webp";
|
||||
|
@ -25,10 +25,10 @@ import java.util.List;
|
||||
|
||||
public final class AnimatorSet10 extends Animator10 {
|
||||
|
||||
private ArrayList<Animator10> mPlayingSet = new ArrayList<Animator10>();
|
||||
private HashMap<Animator10, Node> mNodeMap = new HashMap<Animator10, Node>();
|
||||
private ArrayList<Node> mNodes = new ArrayList<Node>();
|
||||
private ArrayList<Node> mSortedNodes = new ArrayList<Node>();
|
||||
private ArrayList<Animator10> mPlayingSet = new ArrayList<>();
|
||||
private HashMap<Animator10, Node> mNodeMap = new HashMap<>();
|
||||
private ArrayList<Node> mNodes = new ArrayList<>();
|
||||
private ArrayList<Node> mSortedNodes = new ArrayList<>();
|
||||
private boolean mNeedsSort = true;
|
||||
private AnimatorSetListener mSetListener = null;
|
||||
boolean mTerminated = false;
|
||||
@ -89,7 +89,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
}
|
||||
|
||||
public ArrayList<Animator10> getChildAnimations() {
|
||||
ArrayList<Animator10> childList = new ArrayList<Animator10>();
|
||||
ArrayList<Animator10> childList = new ArrayList<>();
|
||||
for (Node node : mNodes) {
|
||||
childList.add(node.animation);
|
||||
}
|
||||
@ -295,7 +295,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
ArrayList<AnimatorListener> oldListeners = node.animation.getListeners();
|
||||
if (oldListeners != null && oldListeners.size() > 0) {
|
||||
final ArrayList<AnimatorListener> clonedListeners = new
|
||||
ArrayList<AnimatorListener>(oldListeners);
|
||||
ArrayList<>(oldListeners);
|
||||
|
||||
for (AnimatorListener listener : clonedListeners) {
|
||||
if (listener instanceof DependencyListener ||
|
||||
@ -306,7 +306,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
}
|
||||
}
|
||||
|
||||
final ArrayList<Node> nodesToStart = new ArrayList<Node>();
|
||||
final ArrayList<Node> nodesToStart = new ArrayList<>();
|
||||
for (Node node : mSortedNodes) {
|
||||
if (mSetListener == null) {
|
||||
mSetListener = new AnimatorSetListener(this);
|
||||
@ -379,12 +379,12 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
anim.mNeedsSort = true;
|
||||
anim.mTerminated = false;
|
||||
anim.mStarted = false;
|
||||
anim.mPlayingSet = new ArrayList<Animator10>();
|
||||
anim.mNodeMap = new HashMap<Animator10, Node>();
|
||||
anim.mNodes = new ArrayList<Node>();
|
||||
anim.mSortedNodes = new ArrayList<Node>();
|
||||
anim.mPlayingSet = new ArrayList<>();
|
||||
anim.mNodeMap = new HashMap<>();
|
||||
anim.mNodes = new ArrayList<>();
|
||||
anim.mSortedNodes = new ArrayList<>();
|
||||
|
||||
HashMap<Node, Node> nodeCloneMap = new HashMap<Node, Node>();
|
||||
HashMap<Node, Node> nodeCloneMap = new HashMap<>();
|
||||
for (Node node : mNodes) {
|
||||
Node nodeClone = node.clone();
|
||||
nodeCloneMap.put(node, nodeClone);
|
||||
@ -400,7 +400,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
for (AnimatorListener listener : cloneListeners) {
|
||||
if (listener instanceof AnimatorSetListener) {
|
||||
if (listenersToRemove == null) {
|
||||
listenersToRemove = new ArrayList<AnimatorListener>();
|
||||
listenersToRemove = new ArrayList<>();
|
||||
}
|
||||
listenersToRemove.add(listener);
|
||||
}
|
||||
@ -543,14 +543,14 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
private void sortNodes() {
|
||||
if (mNeedsSort) {
|
||||
mSortedNodes.clear();
|
||||
ArrayList<Node> roots = new ArrayList<Node>();
|
||||
ArrayList<Node> roots = new ArrayList<>();
|
||||
int numNodes = mNodes.size();
|
||||
for (Node node : mNodes) {
|
||||
if (node.dependencies == null || node.dependencies.size() == 0) {
|
||||
roots.add(node);
|
||||
}
|
||||
}
|
||||
ArrayList<Node> tmpRoots = new ArrayList<Node>();
|
||||
ArrayList<Node> tmpRoots = new ArrayList<>();
|
||||
while (roots.size() > 0) {
|
||||
int numRoots = roots.size();
|
||||
for (Node root : roots) {
|
||||
@ -582,7 +582,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
for (int j = 0; j < numDependencies; ++j) {
|
||||
Dependency dependency = node.dependencies.get(j);
|
||||
if (node.nodeDependencies == null) {
|
||||
node.nodeDependencies = new ArrayList<Node>();
|
||||
node.nodeDependencies = new ArrayList<>();
|
||||
}
|
||||
if (!node.nodeDependencies.contains(dependency.node)) {
|
||||
node.nodeDependencies.add(dependency.node);
|
||||
@ -620,8 +620,8 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
|
||||
public void addDependency(Dependency dependency) {
|
||||
if (dependencies == null) {
|
||||
dependencies = new ArrayList<Dependency>();
|
||||
nodeDependencies = new ArrayList<Node>();
|
||||
dependencies = new ArrayList<>();
|
||||
nodeDependencies = new ArrayList<>();
|
||||
}
|
||||
dependencies.add(dependency);
|
||||
if (!nodeDependencies.contains(dependency.node)) {
|
||||
@ -629,7 +629,7 @@ public final class AnimatorSet10 extends Animator10 {
|
||||
}
|
||||
Node dependencyNode = dependency.node;
|
||||
if (dependencyNode.nodeDependents == null) {
|
||||
dependencyNode.nodeDependents = new ArrayList<Node>();
|
||||
dependencyNode.nodeDependents = new ArrayList<>();
|
||||
}
|
||||
dependencyNode.nodeDependents.add(this);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class View10 extends Animation {
|
||||
|
||||
public static boolean NEED_PROXY = Build.VERSION.SDK_INT < 11;
|
||||
|
||||
private static final WeakHashMap<View, View10> PROXIES = new WeakHashMap<View, View10>();
|
||||
private static final WeakHashMap<View, View10> PROXIES = new WeakHashMap<>();
|
||||
|
||||
public static View10 wrap(View view) {
|
||||
View10 proxy = PROXIES.get(view);
|
||||
@ -68,7 +68,7 @@ public class View10 extends Animation {
|
||||
setDuration(0);
|
||||
setFillAfter(true);
|
||||
view.setAnimation(this);
|
||||
mView = new WeakReference<View>(view);
|
||||
mView = new WeakReference<>(view);
|
||||
}
|
||||
|
||||
public float getAlpha() {
|
||||
|
@ -64,7 +64,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
if (fragmentView == null) {
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
actionBar.setAllowOverlayTitle(true);
|
||||
|
@ -12,6 +12,7 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Layout;
|
||||
import android.text.Spannable;
|
||||
@ -45,6 +46,8 @@ public class ChatActionCell extends BaseCell {
|
||||
private static Drawable backgroundBlue;
|
||||
private static TextPaint textPaint;
|
||||
|
||||
private static Drawable backgroundWhite;
|
||||
|
||||
private URLSpan pressedLink;
|
||||
|
||||
private ImageReceiver imageReceiver;
|
||||
@ -69,6 +72,9 @@ public class ChatActionCell extends BaseCell {
|
||||
backgroundBlack = getResources().getDrawable(R.drawable.system_black);
|
||||
backgroundBlue = getResources().getDrawable(R.drawable.system_blue);
|
||||
|
||||
backgroundWhite = getResources().getDrawable(R.drawable.system_white);
|
||||
backgroundBlue = backgroundWhite;
|
||||
|
||||
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
||||
textPaint.setColor(0xffffffff);
|
||||
textPaint.linkColor = 0xffffffff;
|
||||
@ -220,6 +226,7 @@ public class ChatActionCell extends BaseCell {
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
updateColor();
|
||||
if (currentMessageObject == null) {
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), textHeight + AndroidUtilities.dp(14));
|
||||
return;
|
||||
@ -286,4 +293,14 @@ public class ChatActionCell extends BaseCell {
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateColor(){
|
||||
int color = AndroidUtilities.getIntDef("chatDateColor", 0xffffffff);
|
||||
textPaint.setColor(color);
|
||||
if(color != 0xffffffff){
|
||||
textPaint.linkColor = AndroidUtilities.getIntDarkerColor("chatDateColor", -0x50);
|
||||
}
|
||||
textPaint.setTextSize(AndroidUtilities.dp(AndroidUtilities.getIntDef("chatDateSize",16)));//16
|
||||
backgroundWhite.setColorFilter(AndroidUtilities.getIntDef("chatDateBubbleColor",0x59000000), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ package org.telegram.ui.Cells;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Html;
|
||||
import android.text.Layout;
|
||||
@ -73,6 +74,14 @@ public class ChatBaseCell extends BaseCell {
|
||||
private static TextPaint namePaint;
|
||||
private static TextPaint forwardNamePaint;
|
||||
|
||||
private static Drawable backgroundDrawableOutWhite;
|
||||
private static Drawable backgroundDrawableOutWhiteSelected;
|
||||
private static Drawable backgroundMediaDrawableOutWhite;
|
||||
private static Drawable backgroundMediaDrawableOutWhiteSelected;
|
||||
private static Drawable checkDrawableWhite;
|
||||
private static Drawable halfCheckDrawableWhite;
|
||||
private static Drawable clockDrawableWhite;
|
||||
|
||||
protected int backgroundWidth = 100;
|
||||
|
||||
protected int layoutWidth;
|
||||
@ -138,6 +147,15 @@ public class ChatBaseCell extends BaseCell {
|
||||
broadcastDrawable = getResources().getDrawable(R.drawable.broadcast3);
|
||||
broadcastMediaDrawable = getResources().getDrawable(R.drawable.broadcast4);
|
||||
|
||||
backgroundDrawableOutWhite = getResources().getDrawable(R.drawable.msg_out_white);
|
||||
backgroundDrawableOutWhiteSelected = getResources().getDrawable(R.drawable.msg_out_white_selected);
|
||||
backgroundMediaDrawableOutWhite = getResources().getDrawable(R.drawable.msg_out_photo_white);
|
||||
backgroundMediaDrawableOutWhiteSelected = getResources().getDrawable(R.drawable.msg_out_photo_white_selected);
|
||||
|
||||
checkDrawableWhite = getResources().getDrawable(R.drawable.msg_check_white);
|
||||
halfCheckDrawableWhite = getResources().getDrawable(R.drawable.msg_halfcheck_white);
|
||||
clockDrawableWhite = getResources().getDrawable(R.drawable.msg_clock_white);
|
||||
|
||||
timePaintIn = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
||||
timePaintIn.setTextSize(AndroidUtilities.dp(12));
|
||||
timePaintIn.setColor(0xffa1aab3);
|
||||
@ -161,6 +179,26 @@ public class ChatBaseCell extends BaseCell {
|
||||
avatarDrawable = new AvatarDrawable();
|
||||
}
|
||||
|
||||
private void updateColors(){
|
||||
int tColor = AndroidUtilities.getIntColor("themeColor");
|
||||
int lColor = AndroidUtilities.getIntDarkerColor("themeColor",-0x80);
|
||||
int dColor = AndroidUtilities.getIntDarkerColor("themeColor",0x15);
|
||||
backgroundDrawableOutWhite.setColorFilter(AndroidUtilities.getIntDef("chatRBubbleColor", lColor), PorterDuff.Mode.MULTIPLY);
|
||||
backgroundMediaDrawableOutWhite.setColorFilter(AndroidUtilities.getIntDef("chatRBubbleColor", lColor), PorterDuff.Mode.MULTIPLY);
|
||||
backgroundDrawableIn.setColorFilter(AndroidUtilities.getIntDef("chatLBubbleColor",0xffffffff), PorterDuff.Mode.MULTIPLY);
|
||||
backgroundMediaDrawableIn.setColorFilter(AndroidUtilities.getIntDef("chatLBubbleColor",0xffffffff), PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
int checksColor = AndroidUtilities.getIntDef("chatChecksColor", tColor);
|
||||
checkDrawableWhite.setColorFilter(checksColor, PorterDuff.Mode.MULTIPLY);
|
||||
halfCheckDrawableWhite.setColorFilter(checksColor, PorterDuff.Mode.MULTIPLY);
|
||||
clockDrawableWhite.setColorFilter(checksColor, PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
timePaintOut.setColor(AndroidUtilities.getIntDef("chatRTimeColor",dColor));
|
||||
timePaintOut.setTextSize(AndroidUtilities.dp(AndroidUtilities.getIntDef("chatTimeSize",12)));
|
||||
timePaintIn.setColor(AndroidUtilities.getIntDef("chatLTimeColor",0xffa1aab3));
|
||||
timePaintIn.setTextSize(AndroidUtilities.dp(AndroidUtilities.getIntDef("chatTimeSize",12)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
@ -427,6 +465,7 @@ public class ChatBaseCell extends BaseCell {
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
updateColors();
|
||||
if (currentMessageObject == null) {
|
||||
return;
|
||||
}
|
||||
@ -444,15 +483,15 @@ public class ChatBaseCell extends BaseCell {
|
||||
if (currentMessageObject.isOut()) {
|
||||
if (isPressed() && isCheckPressed || !isCheckPressed && isPressed) {
|
||||
if (!media) {
|
||||
currentBackgroundDrawable = backgroundDrawableOutSelected;
|
||||
currentBackgroundDrawable = backgroundDrawableOutWhiteSelected;//backgroundDrawableOutSelected;
|
||||
} else {
|
||||
currentBackgroundDrawable = backgroundMediaDrawableOutSelected;
|
||||
currentBackgroundDrawable = backgroundMediaDrawableOutWhiteSelected;//backgroundMediaDrawableOutSelected;
|
||||
}
|
||||
} else {
|
||||
if (!media) {
|
||||
currentBackgroundDrawable = backgroundDrawableOut;
|
||||
currentBackgroundDrawable = backgroundDrawableOutWhite;//backgroundDrawableOut;
|
||||
} else {
|
||||
currentBackgroundDrawable = backgroundMediaDrawableOut;
|
||||
currentBackgroundDrawable = backgroundMediaDrawableOutWhite;//backgroundMediaDrawableOut;
|
||||
}
|
||||
}
|
||||
setDrawableBounds(currentBackgroundDrawable, layoutWidth - backgroundWidth - (!media ? 0 : AndroidUtilities.dp(9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));
|
||||
@ -553,6 +592,7 @@ public class ChatBaseCell extends BaseCell {
|
||||
|
||||
if (drawClock) {
|
||||
if (!media) {
|
||||
clockDrawable = clockDrawableWhite;
|
||||
setDrawableBounds(clockDrawable, layoutWidth - AndroidUtilities.dp(18.5f) - clockDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.5f) - clockDrawable.getIntrinsicHeight());
|
||||
clockDrawable.draw(canvas);
|
||||
} else {
|
||||
@ -573,6 +613,7 @@ public class ChatBaseCell extends BaseCell {
|
||||
} else {
|
||||
if (drawCheck2) {
|
||||
if (!media) {
|
||||
checkDrawable = checkDrawableWhite;
|
||||
if (drawCheck1) {
|
||||
setDrawableBounds(checkDrawable, layoutWidth - AndroidUtilities.dp(22.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.5f) - checkDrawable.getIntrinsicHeight());
|
||||
} else {
|
||||
@ -590,6 +631,7 @@ public class ChatBaseCell extends BaseCell {
|
||||
}
|
||||
if (drawCheck1) {
|
||||
if (!media) {
|
||||
halfCheckDrawable = halfCheckDrawableWhite;
|
||||
setDrawableBounds(halfCheckDrawable, layoutWidth - AndroidUtilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - AndroidUtilities.dp(8.5f) - halfCheckDrawable.getIntrinsicHeight());
|
||||
halfCheckDrawable.draw(canvas);
|
||||
} else {
|
||||
|
@ -530,19 +530,14 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||
break;
|
||||
}
|
||||
}
|
||||
float maxWidth;
|
||||
if (AndroidUtilities.isTablet()) {
|
||||
maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
|
||||
} else {
|
||||
maxWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.5f);
|
||||
}
|
||||
float maxHeight = AndroidUtilities.displaySize.y * 0.4f;
|
||||
if (photoWidth == 0) {
|
||||
photoWidth = (int)maxWidth;
|
||||
photoHeight = photoWidth + AndroidUtilities.dp(100);
|
||||
photoHeight = (int) maxHeight;
|
||||
photoWidth = photoHeight + AndroidUtilities.dp(100);
|
||||
}
|
||||
if (photoWidth > maxWidth) {
|
||||
photoHeight *= maxWidth / photoWidth;
|
||||
photoWidth = (int)maxWidth;
|
||||
if (photoHeight > maxHeight) {
|
||||
photoWidth *= maxHeight / photoHeight;
|
||||
photoHeight = (int)maxHeight;
|
||||
}
|
||||
backgroundWidth = photoWidth + AndroidUtilities.dp(12);
|
||||
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
|
||||
@ -870,8 +865,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||
if (currentMessageObject.type == 9) {
|
||||
Drawable menuDrawable = null;
|
||||
if (currentMessageObject.isOut()) {
|
||||
infoPaint.setColor(0xff75b166);
|
||||
docBackPaint.setColor(0xffd0f3b3);
|
||||
infoPaint.setColor(0xff70b15c);
|
||||
docBackPaint.setColor(0xffdaf5c3);
|
||||
menuDrawable = docMenuOutDrawable;
|
||||
} else {
|
||||
infoPaint.setColor(0xffa1adbb);
|
||||
|
@ -8,9 +8,12 @@
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Html;
|
||||
import android.text.Layout;
|
||||
@ -22,6 +25,7 @@ import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.android.LocaleController;
|
||||
import org.telegram.android.MessageObject;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.android.ContactsController;
|
||||
@ -52,15 +56,26 @@ public class DialogCell extends BaseCell {
|
||||
private static Drawable broadcastDrawable;
|
||||
private static Drawable muteDrawable;
|
||||
|
||||
private static Drawable checkWhiteDrawable;
|
||||
private static Drawable halfCheckWhiteDrawable;
|
||||
private static Drawable countWhiteDrawable;
|
||||
private static Drawable lockWhiteDrawable;
|
||||
private static Drawable groupWhiteDrawable;
|
||||
private static Drawable broadcastWhiteDrawable;
|
||||
private static Drawable muteWhiteDrawable;
|
||||
|
||||
private static Paint linePaint;
|
||||
|
||||
private long currentDialogId;
|
||||
private boolean allowPrintStrings;
|
||||
private boolean isDialogCell;
|
||||
private int lastMessageDate;
|
||||
private int unreadCount;
|
||||
private boolean lastUnreadState;
|
||||
private int lastSendState;
|
||||
private boolean dialogMuted;
|
||||
private MessageObject message;
|
||||
private int index;
|
||||
private boolean isServerOnly;
|
||||
|
||||
private ImageReceiver avatarImage;
|
||||
private AvatarDrawable avatarDrawable;
|
||||
@ -155,6 +170,22 @@ public class DialogCell extends BaseCell {
|
||||
groupDrawable = getResources().getDrawable(R.drawable.list_group);
|
||||
broadcastDrawable = getResources().getDrawable(R.drawable.list_broadcast);
|
||||
muteDrawable = getResources().getDrawable(R.drawable.mute_grey);
|
||||
|
||||
checkWhiteDrawable = getResources().getDrawable(R.drawable.dialogs_check_white);
|
||||
checkDrawable = checkWhiteDrawable;
|
||||
halfCheckWhiteDrawable = getResources().getDrawable(R.drawable.dialogs_halfcheck_white);
|
||||
halfCheckDrawable = halfCheckWhiteDrawable;
|
||||
countWhiteDrawable = getResources().getDrawable(R.drawable.dialogs_badge_white);
|
||||
countDrawable = countWhiteDrawable;
|
||||
lockWhiteDrawable = getResources().getDrawable(R.drawable.list_secret_white);
|
||||
lockDrawable = lockWhiteDrawable;
|
||||
groupWhiteDrawable = getResources().getDrawable(R.drawable.list_group_white);
|
||||
groupDrawable = groupWhiteDrawable;
|
||||
broadcastWhiteDrawable = getResources().getDrawable(R.drawable.list_broadcast_white);
|
||||
broadcastDrawable = broadcastWhiteDrawable;
|
||||
muteWhiteDrawable = getResources().getDrawable(R.drawable.mute_white);
|
||||
muteDrawable = muteWhiteDrawable;
|
||||
updateColors();
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,17 +194,28 @@ public class DialogCell extends BaseCell {
|
||||
init();
|
||||
avatarImage = new ImageReceiver(this);
|
||||
avatarImage.setRoundRadius(AndroidUtilities.dp(26));
|
||||
//avatarImage.setRoundRadius(AndroidUtilities.dp(5));
|
||||
avatarDrawable = new AvatarDrawable();
|
||||
//avatarDrawable.setRadius(5);
|
||||
}
|
||||
public void setDialog(TLRPC.TL_dialog dialog, int i, boolean server) {
|
||||
currentDialogId = dialog.id;
|
||||
isDialogCell = true;
|
||||
index = i;
|
||||
isServerOnly = server;
|
||||
update(0);
|
||||
}
|
||||
|
||||
public void setDialog(long dialog_id, MessageObject messageObject, boolean usePrintStrings, int date, int unread, boolean muted) {
|
||||
public void setDialog(long dialog_id, MessageObject messageObject, int date) {
|
||||
currentDialogId = dialog_id;
|
||||
message = messageObject;
|
||||
allowPrintStrings = usePrintStrings;
|
||||
isDialogCell = false;
|
||||
lastMessageDate = date;
|
||||
unreadCount = unread;
|
||||
dialogMuted = muted;
|
||||
unreadCount = 0;
|
||||
lastUnreadState = messageObject != null && messageObject.isUnread();
|
||||
if (message != null) {
|
||||
lastSendState = message.messageOwner.send_state;
|
||||
}
|
||||
update(0);
|
||||
}
|
||||
|
||||
@ -211,7 +253,7 @@ public class DialogCell extends BaseCell {
|
||||
String countString = null;
|
||||
CharSequence messageString = "";
|
||||
CharSequence printingString = null;
|
||||
if (allowPrintStrings) {
|
||||
if (isDialogCell) {
|
||||
printingString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
||||
}
|
||||
TextPaint currentNamePaint = namePaint;
|
||||
@ -328,9 +370,13 @@ public class DialogCell extends BaseCell {
|
||||
}
|
||||
}
|
||||
checkMessage = false;
|
||||
String hexColor = String.format("#%06X", (0xFFFFFF & AndroidUtilities.getIntColor("themeColor")));
|
||||
String hexMsgColor = String.format("#%06X", (0xFFFFFF & AndroidUtilities.getIntDef("chatsMessageColor",0xff8f8f8f)));
|
||||
String hexDarkColor = String.format("#%06X", (0xFFFFFF & AndroidUtilities.getIntDef("chatsParticipantColor", AndroidUtilities.getIntDarkerColor("themeColor",0x15))));
|
||||
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
||||
currentMessagePaint = messagePrintingPaint;
|
||||
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#4d83b3>%s</font>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
//messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#4d83b3>%s</font>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=" + hexColor + ">%s:</font> <font color=" + hexColor + ">%s</font>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
} else {
|
||||
if (message.messageOwner.message != null) {
|
||||
String mess = message.messageOwner.message;
|
||||
@ -338,7 +384,8 @@ public class DialogCell extends BaseCell {
|
||||
mess = mess.substring(0, 150);
|
||||
}
|
||||
mess = mess.replace("\n", " ");
|
||||
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#808080>%s</font>", name, mess.replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
//messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#808080>%s</font>", name, mess.replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=" + hexDarkColor + ">%s:</font> <font color=" + hexMsgColor + ">%s</font>", name, mess.replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -543,15 +590,15 @@ public class DialogCell extends BaseCell {
|
||||
if (LocaleController.isRTL) {
|
||||
if (nameLayout != null && nameLayout.getLineCount() > 0) {
|
||||
left = nameLayout.getLineLeft(0);
|
||||
if (left == 0) {
|
||||
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
||||
if (dialogMuted) {
|
||||
nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - muteDrawable.getIntrinsicWidth());
|
||||
}
|
||||
if (left == 0) {
|
||||
if (widthpx < nameWidth) {
|
||||
nameLeft += (nameWidth - widthpx);
|
||||
}
|
||||
}
|
||||
if (dialogMuted) {
|
||||
nameMuteLeft = (nameLeft - AndroidUtilities.dp(6) - muteDrawable.getIntrinsicWidth());
|
||||
}
|
||||
}
|
||||
if (messageLayout != null && messageLayout.getLineCount() > 0) {
|
||||
left = messageLayout.getLineLeft(0);
|
||||
@ -587,10 +634,43 @@ public class DialogCell extends BaseCell {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkCurrentDialogIndex() {
|
||||
TLRPC.TL_dialog dialog = null;
|
||||
if (isServerOnly) {
|
||||
if (index < MessagesController.getInstance().dialogsServerOnly.size()) {
|
||||
dialog = MessagesController.getInstance().dialogsServerOnly.get(index);
|
||||
}
|
||||
} else {
|
||||
if (index < MessagesController.getInstance().dialogs.size()) {
|
||||
dialog = MessagesController.getInstance().dialogs.get(index);
|
||||
}
|
||||
}
|
||||
if (dialog != null) {
|
||||
if (currentDialogId != dialog.id || message != null && message.messageOwner.id != dialog.top_message || unreadCount != dialog.unread_count) {
|
||||
currentDialogId = dialog.id;
|
||||
update(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void update(int mask) {
|
||||
updateColors();
|
||||
if (isDialogCell) {
|
||||
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
|
||||
if (dialog != null && mask == 0) {
|
||||
message = MessagesController.getInstance().dialogMessage.get(dialog.top_message);
|
||||
lastUnreadState = message != null && message.isUnread();
|
||||
unreadCount = dialog.unread_count;
|
||||
lastMessageDate = dialog.last_message_date;
|
||||
if (message != null) {
|
||||
lastSendState = message.messageOwner.send_state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mask != 0) {
|
||||
boolean continueUpdate = false;
|
||||
if (allowPrintStrings && (mask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
||||
if (isDialogCell && (mask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
||||
CharSequence printString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
||||
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
||||
continueUpdate = true;
|
||||
@ -618,8 +698,9 @@ public class DialogCell extends BaseCell {
|
||||
}
|
||||
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
|
||||
if (message != null && lastUnreadState != message.isUnread()) {
|
||||
lastUnreadState = message.isUnread();
|
||||
continueUpdate = true;
|
||||
} else if (allowPrintStrings) {
|
||||
} else if (isDialogCell) {
|
||||
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
|
||||
if (dialog != null && unreadCount != dialog.unread_count) {
|
||||
unreadCount = dialog.unread_count;
|
||||
@ -627,11 +708,19 @@ public class DialogCell extends BaseCell {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_SEND_STATE) != 0) {
|
||||
if (message != null && lastSendState != message.messageOwner.send_state) {
|
||||
lastSendState = message.messageOwner.send_state;
|
||||
continueUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!continueUpdate) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
dialogMuted = isDialogCell && MessagesController.getInstance().isDialogMuted(currentDialogId);
|
||||
user = null;
|
||||
chat = null;
|
||||
encryptedChat = null;
|
||||
@ -756,4 +845,44 @@ public class DialogCell extends BaseCell {
|
||||
|
||||
avatarImage.draw(canvas);
|
||||
}
|
||||
|
||||
private void updateColors(){
|
||||
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, Activity.MODE_PRIVATE);
|
||||
int tColor = AndroidUtilities.getIntColor("themeColor");
|
||||
int dColor = AndroidUtilities.getIntDarkerColor("themeColor",0x15);
|
||||
|
||||
namePaint.setTextSize(AndroidUtilities.dp(themePrefs.getInt("chatsNameSize", 17)));
|
||||
namePaint.setColor(themePrefs.getInt("chatsNameColor", 0xff212121));
|
||||
|
||||
nameEncryptedPaint.setTextSize(AndroidUtilities.dp(themePrefs.getInt("chatsNameSize", 17)));
|
||||
nameEncryptedPaint.setColor(themePrefs.getInt("chatsNameColor", dColor));//0xff00a60e
|
||||
|
||||
nameUnknownPaint.setTextSize(AndroidUtilities.dp(themePrefs.getInt("chatsNameSize", 17)));
|
||||
nameUnknownPaint.setColor(themePrefs.getInt("chatsNameColor", 0xff000000));//0xff4d83b3
|
||||
|
||||
messagePaint.setTextSize(AndroidUtilities.dp(themePrefs.getInt("chatsMessageSize", 16)));
|
||||
messagePaint.setColor(themePrefs.getInt("chatsMessageColor", 0xff8f8f8f));
|
||||
//Audio Archivo ... te expulsó
|
||||
messagePrintingPaint.setTextSize(AndroidUtilities.dp(themePrefs.getInt("chatsMessageSize", 16)));
|
||||
messagePrintingPaint.setColor(themePrefs.getInt("chatsMessageColor", tColor));//0xff4d83b3
|
||||
|
||||
timePaint.setTextSize(AndroidUtilities.dp(themePrefs.getInt("chatsTimeSize", 13)));
|
||||
timePaint.setColor(themePrefs.getInt("chatsTimeColor", 0xff999999));
|
||||
|
||||
countPaint.setTextSize(AndroidUtilities.dp(themePrefs.getInt("chatsCountSize", 13)));
|
||||
countPaint.setColor(themePrefs.getInt("chatsCountColor", 0xffffffff));
|
||||
|
||||
checkWhiteDrawable.setColorFilter(AndroidUtilities.getIntDef("chatsChecksColor",AndroidUtilities.getIntColor("themeColor")), PorterDuff.Mode.MULTIPLY);
|
||||
halfCheckWhiteDrawable.setColorFilter(AndroidUtilities.getIntDef("chatsChecksColor",AndroidUtilities.getIntColor("themeColor")), PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
countWhiteDrawable.setColorFilter(themePrefs.getInt("chatsCountBGColor", tColor), PorterDuff.Mode.MULTIPLY);
|
||||
lockWhiteDrawable.setColorFilter(dColor, PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
int nColor = themePrefs.getInt("chatsNameColor", 0xff000000);
|
||||
groupWhiteDrawable.setColorFilter(nColor, PorterDuff.Mode.MULTIPLY);
|
||||
broadcastWhiteDrawable.setColorFilter(nColor, PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
int mColor = themePrefs.getInt("chatsMuteColor", 0xffa8a8a8);
|
||||
muteWhiteDrawable.setColorFilter(mColor, PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,11 @@
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
@ -18,7 +22,9 @@ import android.widget.TextView;
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.ContactsController;
|
||||
import org.telegram.android.MessagesController;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.ui.Components.AvatarDrawable;
|
||||
import org.telegram.ui.Components.BackupImageView;
|
||||
|
||||
@ -86,6 +92,7 @@ public class DrawerProfileCell extends FrameLayout {
|
||||
} else {
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(148), MeasureSpec.EXACTLY));
|
||||
}
|
||||
updateColors();
|
||||
}
|
||||
|
||||
public void setUser(TLRPC.User user) {
|
||||
@ -102,4 +109,23 @@ public class DrawerProfileCell extends FrameLayout {
|
||||
avatarDrawable.setColor(0xff5c98cd);
|
||||
avatarImageView.setImage(photo, "50_50", avatarDrawable);
|
||||
}
|
||||
|
||||
private void updateColors(){
|
||||
setBackgroundColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
phoneTextView.setTextColor(AndroidUtilities.getIntDarkerColor("themeColor",-0x40));
|
||||
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
|
||||
TLRPC.FileLocation photo = null;
|
||||
if (user.photo != null) {
|
||||
photo = user.photo.photo_small;
|
||||
}
|
||||
AvatarDrawable avatarDrawable = new AvatarDrawable(user);
|
||||
avatarDrawable.setColor(AndroidUtilities.getIntDarkerColor("themeColor",0x15));
|
||||
avatarImageView.setImage(photo, "50_50", avatarDrawable);
|
||||
|
||||
if(AndroidUtilities.getBoolMain("hideMobile")){
|
||||
phoneTextView.setVisibility(GONE);
|
||||
}else{
|
||||
phoneTextView.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.widget.FrameLayout;
|
||||
@ -21,7 +20,9 @@ import org.telegram.android.LocaleController;
|
||||
public class GreySectionCell extends FrameLayout {
|
||||
private TextView textView;
|
||||
|
||||
private void init() {
|
||||
public GreySectionCell(Context context) {
|
||||
super(context);
|
||||
|
||||
setBackgroundColor(0xfff2f2f2);
|
||||
|
||||
textView = new TextView(getContext());
|
||||
@ -39,26 +40,6 @@ public class GreySectionCell extends FrameLayout {
|
||||
textView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
public GreySectionCell(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public GreySectionCell(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public GreySectionCell(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public GreySectionCell(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(36), MeasureSpec.EXACTLY));
|
||||
|
@ -8,7 +8,9 @@
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
@ -26,7 +28,10 @@ public class HeaderCell extends FrameLayout {
|
||||
textView = new TextView(getContext());
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
||||
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
textView.setTextColor(0xff3e90cf);
|
||||
//textView.setTextColor(0xff3e90cf);
|
||||
//
|
||||
textView.setTextColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
//
|
||||
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
||||
addView(textView);
|
||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)textView.getLayoutParams();
|
||||
|
@ -9,6 +9,7 @@
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.widget.ImageView;
|
||||
@ -32,28 +33,54 @@ public class PhotoEditToolCell extends FrameLayoutFixed {
|
||||
LayoutParams layoutParams = (LayoutParams) iconImage.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.bottomMargin = AndroidUtilities.dp(20);
|
||||
layoutParams.bottomMargin = AndroidUtilities.dp(12);
|
||||
iconImage.setLayoutParams(layoutParams);
|
||||
|
||||
nameTextView = new TextView(context);
|
||||
nameTextView.setGravity(Gravity.CENTER);
|
||||
nameTextView.setTextColor(0xffffffff);
|
||||
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
||||
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
|
||||
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
nameTextView.setMaxLines(1);
|
||||
nameTextView.setSingleLine(true);
|
||||
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
addView(nameTextView);
|
||||
layoutParams = (LayoutParams) nameTextView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = AndroidUtilities.dp(20);
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
|
||||
layoutParams.leftMargin = AndroidUtilities.dp(4);
|
||||
layoutParams.rightMargin = AndroidUtilities.dp(4);
|
||||
nameTextView.setLayoutParams(layoutParams);
|
||||
|
||||
valueTextView = new TextView(context);
|
||||
valueTextView.setTextColor(0xff6cc3ff);
|
||||
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
|
||||
valueTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
addView(valueTextView);
|
||||
layoutParams = (LayoutParams) valueTextView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
layoutParams.leftMargin = AndroidUtilities.dp(57);
|
||||
layoutParams.topMargin = AndroidUtilities.dp(3);
|
||||
valueTextView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(86), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
|
||||
}
|
||||
|
||||
public void setIconAndText(int resId, String text) {
|
||||
public void setIconAndTextAndValue(int resId, String text, float value) {
|
||||
iconImage.setImageResource(resId);
|
||||
nameTextView.setText(text);
|
||||
nameTextView.setText(text.toUpperCase());
|
||||
if (value == 0) {
|
||||
valueTextView.setText("");
|
||||
} else if (value > 0) {
|
||||
valueTextView.setText("+" + (int) value);
|
||||
} else {
|
||||
valueTextView.setText("" + (int) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -23,8 +23,9 @@ import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.MediaController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.ui.Components.BackupImageView;
|
||||
import org.telegram.ui.Components.FrameLayoutFixed;
|
||||
|
||||
public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||
public class PhotoPickerAlbumsCell extends FrameLayoutFixed {
|
||||
|
||||
public static interface PhotoPickerAlbumsCellDelegate {
|
||||
public abstract void didSelectAlbum(MediaController.AlbumEntry albumEntry);
|
||||
@ -35,7 +36,7 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||
private int albumsCount;
|
||||
private PhotoPickerAlbumsCellDelegate delegate;
|
||||
|
||||
private class AlbumView extends FrameLayout {
|
||||
private class AlbumView extends FrameLayoutFixed {
|
||||
|
||||
private BackupImageView imageView;
|
||||
private TextView nameTextView;
|
||||
@ -146,7 +147,9 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||
|
||||
if (albumEntry != null) {
|
||||
AlbumView albumView = albumViews[a];
|
||||
albumView.imageView.setOrientation(0, true);
|
||||
if (albumEntry.coverPhoto != null && albumEntry.coverPhoto.path != null) {
|
||||
albumView.imageView.setOrientation(albumEntry.coverPhoto.orientation, true);
|
||||
albumView.imageView.setImage("thumb://" + albumEntry.coverPhoto.imageId + ":" + albumEntry.coverPhoto.path, null, getContext().getResources().getDrawable(R.drawable.nophotos));
|
||||
} else {
|
||||
albumView.imageView.setImageResource(R.drawable.nophotos);
|
||||
@ -167,16 +170,21 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
|
||||
itemWidth = (AndroidUtilities.displaySize.x - ((albumsCount + 1) * AndroidUtilities.dp(4))) / albumsCount;
|
||||
}
|
||||
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(4) + itemWidth, MeasureSpec.EXACTLY));
|
||||
|
||||
for (int a = 0; a < albumsCount; a++) {
|
||||
LayoutParams layoutParams = (LayoutParams) albumViews[a].getLayoutParams();
|
||||
layoutParams.topMargin = AndroidUtilities.dp(4);
|
||||
layoutParams.leftMargin = (itemWidth + AndroidUtilities.dp(4)) * a;
|
||||
layoutParams.width = itemWidth;
|
||||
layoutParams.height = itemWidth;
|
||||
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
albumViews[a].setLayoutParams(layoutParams);
|
||||
albumViews[a].measure(MeasureSpec.makeMeasureSpec(itemWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(itemWidth, MeasureSpec.EXACTLY));
|
||||
}
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
||||
if (layoutParams != null) {
|
||||
layoutParams.height = AndroidUtilities.dp(4) + itemWidth;
|
||||
setLayoutParams(layoutParams);
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ package org.telegram.ui.Cells;
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.messenger.R;
|
||||
@ -23,7 +22,6 @@ public class PhotoPickerPhotoCell extends FrameLayout {
|
||||
public BackupImageView photoImage;
|
||||
public FrameLayout checkFrame;
|
||||
public CheckBox checkBox;
|
||||
public ImageView editedImage;
|
||||
public int itemWidth;
|
||||
|
||||
public PhotoPickerPhotoCell(Context context) {
|
||||
@ -57,16 +55,6 @@ public class PhotoPickerPhotoCell extends FrameLayout {
|
||||
layoutParams.topMargin = AndroidUtilities.dp(6);
|
||||
layoutParams.rightMargin = AndroidUtilities.dp(6);
|
||||
checkBox.setLayoutParams(layoutParams);
|
||||
|
||||
editedImage = new ImageView(context);
|
||||
editedImage.setImageResource(R.drawable.photo_edit);
|
||||
editedImage.setScaleType(ImageView.ScaleType.CENTER);
|
||||
addView(editedImage);
|
||||
layoutParams = (LayoutParams) editedImage.getLayoutParams();
|
||||
layoutParams.width = AndroidUtilities.dp(42);
|
||||
layoutParams.height = AndroidUtilities.dp(42);
|
||||
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
editedImage.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
@ -39,62 +40,57 @@ public class PhotoPickerSearchCell extends LinearLayout {
|
||||
public SearchButton(Context context) {
|
||||
super(context);
|
||||
|
||||
setBackgroundColor(0xff292929);
|
||||
setBackgroundColor(0xff1a1a1a);
|
||||
|
||||
selector = new View(context);
|
||||
selector.setBackgroundResource(R.drawable.list_selector);
|
||||
addView(selector);
|
||||
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) selector.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.height = LayoutParams.MATCH_PARENT;
|
||||
selector.setLayoutParams(layoutParams1);
|
||||
|
||||
LinearLayout linearLayout = new LinearLayout(context);
|
||||
linearLayout.setOrientation(HORIZONTAL);
|
||||
addView(linearLayout);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) linearLayout.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.gravity = Gravity.CENTER;
|
||||
linearLayout.setLayoutParams(layoutParams1);
|
||||
|
||||
imageView = new ImageView(context);
|
||||
linearLayout.addView(imageView);
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) imageView.getLayoutParams();
|
||||
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
||||
addView(imageView);
|
||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) imageView.getLayoutParams();
|
||||
layoutParams.height = AndroidUtilities.dp(48);
|
||||
layoutParams.width = AndroidUtilities.dp(48);
|
||||
layoutParams1.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
|
||||
FrameLayout frameLayout = new FrameLayout(context);
|
||||
frameLayout.setPadding(AndroidUtilities.dp(4), 0, 0, 0);
|
||||
linearLayout.addView(frameLayout);
|
||||
layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
|
||||
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
frameLayout.setLayoutParams(layoutParams);
|
||||
|
||||
textView1 = new TextView(context);
|
||||
textView1.setGravity(Gravity.CENTER_VERTICAL);
|
||||
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
|
||||
textView1.setPadding(0, 0, AndroidUtilities.dp(8), 0);
|
||||
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||
textView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
textView1.setTextColor(0xffffffff);
|
||||
frameLayout.addView(textView1);
|
||||
textView1.setSingleLine(true);
|
||||
textView1.setEllipsize(TextUtils.TruncateAt.END);
|
||||
addView(textView1);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) textView1.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
layoutParams1.rightMargin = AndroidUtilities.dp(4);
|
||||
layoutParams1.leftMargin = AndroidUtilities.dp(51);
|
||||
layoutParams1.topMargin = AndroidUtilities.dp(8);
|
||||
textView1.setLayoutParams(layoutParams1);
|
||||
|
||||
textView2 = new TextView(context);
|
||||
textView2.setGravity(Gravity.CENTER_VERTICAL);
|
||||
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 9);
|
||||
textView2.setPadding(0, AndroidUtilities.dp(24), AndroidUtilities.dp(8), 0);
|
||||
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
|
||||
textView2.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
textView2.setTextColor(0xff464646);
|
||||
frameLayout.addView(textView2);
|
||||
textView2.setTextColor(0xff666666);
|
||||
textView2.setSingleLine(true);
|
||||
textView2.setEllipsize(TextUtils.TruncateAt.END);
|
||||
addView(textView2);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) textView2.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
layoutParams1.leftMargin = AndroidUtilities.dp(51);
|
||||
layoutParams1.rightMargin = AndroidUtilities.dp(4);
|
||||
layoutParams1.topMargin = AndroidUtilities.dp(26);
|
||||
textView2.setLayoutParams(layoutParams1);
|
||||
}
|
||||
|
||||
@ -115,7 +111,8 @@ public class PhotoPickerSearchCell extends LinearLayout {
|
||||
|
||||
SearchButton searchButton = new SearchButton(context);
|
||||
searchButton.textView1.setText(LocaleController.getString("SearchImages", R.string.SearchImages));
|
||||
searchButton.imageView.setImageResource(R.drawable.web_search);
|
||||
searchButton.textView2.setText(LocaleController.getString("SearchImagesInfo", R.string.SearchImagesInfo));
|
||||
searchButton.imageView.setImageResource(R.drawable.search_web);
|
||||
addView(searchButton);
|
||||
LayoutParams layoutParams = (LayoutParams) searchButton.getLayoutParams();
|
||||
layoutParams.weight = 0.5f;
|
||||
@ -144,7 +141,7 @@ public class PhotoPickerSearchCell extends LinearLayout {
|
||||
searchButton = new SearchButton(context);
|
||||
searchButton.textView1.setText(LocaleController.getString("SearchGifs", R.string.SearchGifs));
|
||||
searchButton.textView2.setText("GIPHY");
|
||||
searchButton.imageView.setImageResource(R.drawable.gif_search);
|
||||
searchButton.imageView.setImageResource(R.drawable.search_gif);
|
||||
addView(searchButton);
|
||||
layoutParams = (LayoutParams) searchButton.getLayoutParams();
|
||||
layoutParams.weight = 0.5f;
|
||||
|
@ -249,6 +249,12 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
MediaController.getInstance().removeLoadingFileObserver(this);
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked, boolean animated) {
|
||||
if (checkBox.getVisibility() != VISIBLE) {
|
||||
checkBox.setVisibility(VISIBLE);
|
||||
@ -262,30 +268,40 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
|
||||
loaded = false;
|
||||
loading = false;
|
||||
|
||||
int idx = -1;
|
||||
String name = FileLoader.getDocumentFileName(document.messageOwner.media.document);
|
||||
placeholderImabeView.setVisibility(VISIBLE);
|
||||
extTextView.setVisibility(VISIBLE);
|
||||
placeholderImabeView.setImageResource(getThumbForNameOrMime(name, document.messageOwner.media.document.mime_type));
|
||||
nameTextView.setText(name);
|
||||
extTextView.setText((idx = name.lastIndexOf(".")) == -1 ? "" : name.substring(idx + 1).toLowerCase());
|
||||
if (document.messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty) {
|
||||
if (document != null && document.messageOwner.media != null) {
|
||||
int idx = -1;
|
||||
String name = FileLoader.getDocumentFileName(document.messageOwner.media.document);
|
||||
placeholderImabeView.setVisibility(VISIBLE);
|
||||
extTextView.setVisibility(VISIBLE);
|
||||
placeholderImabeView.setImageResource(getThumbForNameOrMime(name, document.messageOwner.media.document.mime_type));
|
||||
nameTextView.setText(name);
|
||||
extTextView.setText((idx = name.lastIndexOf(".")) == -1 ? "" : name.substring(idx + 1).toLowerCase());
|
||||
if (document.messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty) {
|
||||
thumbImageView.setVisibility(GONE);
|
||||
thumbImageView.setImageBitmap(null);
|
||||
} else {
|
||||
thumbImageView.setVisibility(VISIBLE);
|
||||
thumbImageView.setImage(document.messageOwner.media.document.thumb.location, "40_40", (Drawable) null);
|
||||
}
|
||||
long date = (long) document.messageOwner.date * 1000;
|
||||
dateTextView.setText(String.format("%s, %s", Utilities.formatFileSize(document.messageOwner.media.document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(new Date(date)), LocaleController.formatterDay.format(new Date(date)))));
|
||||
} else {
|
||||
nameTextView.setText("");
|
||||
extTextView.setText("");
|
||||
dateTextView.setText("");
|
||||
placeholderImabeView.setVisibility(VISIBLE);
|
||||
extTextView.setVisibility(VISIBLE);
|
||||
thumbImageView.setVisibility(GONE);
|
||||
thumbImageView.setImageBitmap(null);
|
||||
} else {
|
||||
thumbImageView.setVisibility(VISIBLE);
|
||||
thumbImageView.setImage(document.messageOwner.media.document.thumb.location, "40_40", (Drawable) null);
|
||||
}
|
||||
long date = (long) document.messageOwner.date * 1000;
|
||||
dateTextView.setText(String.format("%s, %s", Utilities.formatFileSize(document.messageOwner.media.document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(new Date(date)), LocaleController.formatterDay.format(new Date(date)))));
|
||||
|
||||
setWillNotDraw(!needDivider);
|
||||
progressView.setProgress(0, false);
|
||||
|
||||
updateFileExistIcon();
|
||||
}
|
||||
|
||||
public void updateFileExistIcon() {
|
||||
if (message != null) {
|
||||
if (message != null && message.messageOwner.media != null) {
|
||||
String fileName = null;
|
||||
File cacheFile = null;
|
||||
if (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0 || !(new File(message.messageOwner.attachPath).exists())) {
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 2.x
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2015.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.LocaleController;
|
||||
|
||||
public class SharedMediaSectionCell extends FrameLayout {
|
||||
|
||||
private TextView textView;
|
||||
|
||||
public SharedMediaSectionCell(Context context) {
|
||||
super(context);
|
||||
|
||||
textView = new TextView(getContext());
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
textView.setTextColor(0xff222222);
|
||||
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
||||
addView(textView);
|
||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)textView.getLayoutParams();
|
||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.leftMargin = AndroidUtilities.dp(13);
|
||||
layoutParams.rightMargin = AndroidUtilities.dp(13);
|
||||
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
|
||||
textView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40), MeasureSpec.EXACTLY));
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
textView.setText(text);
|
||||
}
|
||||
}
|
@ -0,0 +1,255 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 2.0.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2014.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Cells;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.MessageObject;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLoader;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.ui.Components.BackupImageView;
|
||||
import org.telegram.ui.Components.CheckBox;
|
||||
import org.telegram.ui.Components.FrameLayoutFixed;
|
||||
import org.telegram.ui.PhotoViewer;
|
||||
|
||||
public class SharedPhotoVideoCell extends FrameLayoutFixed {
|
||||
|
||||
private PhotoVideoView[] photoVideoViews;
|
||||
private MessageObject[] messageObjects;
|
||||
private int[] indeces;
|
||||
private SharedPhotoVideoCellDelegate delegate;
|
||||
private int itemsCount;
|
||||
private boolean isFirst;
|
||||
|
||||
public static interface SharedPhotoVideoCellDelegate {
|
||||
public abstract void didClickItem(SharedPhotoVideoCell cell, int index, MessageObject messageObject, int a);
|
||||
public abstract boolean didLongClickItem(SharedPhotoVideoCell cell, int index, MessageObject messageObject, int a);
|
||||
}
|
||||
|
||||
private class PhotoVideoView extends FrameLayoutFixed {
|
||||
|
||||
private BackupImageView imageView;
|
||||
private TextView videoTextView;
|
||||
private LinearLayout videoInfoContainer;
|
||||
private View selector;
|
||||
private CheckBox checkBox;
|
||||
|
||||
public PhotoVideoView(Context context) {
|
||||
super(context);
|
||||
|
||||
imageView = new BackupImageView(context);
|
||||
imageView.imageReceiver.setNeedsQualityThumb(true);
|
||||
imageView.imageReceiver.setShouldGenerateQualityThumb(true);
|
||||
addView(imageView);
|
||||
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
|
||||
videoInfoContainer = new LinearLayout(context);
|
||||
videoInfoContainer.setOrientation(LinearLayout.HORIZONTAL);
|
||||
videoInfoContainer.setBackgroundResource(R.drawable.phototime);
|
||||
videoInfoContainer.setPadding(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(3), 0);
|
||||
videoInfoContainer.setGravity(Gravity.CENTER_VERTICAL);
|
||||
addView(videoInfoContainer);
|
||||
layoutParams = (LayoutParams) videoInfoContainer.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = AndroidUtilities.dp(16);
|
||||
layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
|
||||
videoInfoContainer.setLayoutParams(layoutParams);
|
||||
|
||||
ImageView imageView1 = new ImageView(context);
|
||||
imageView1.setImageResource(R.drawable.ic_video);
|
||||
videoInfoContainer.addView(imageView1);
|
||||
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) imageView1.getLayoutParams();
|
||||
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
imageView1.setLayoutParams(layoutParams1);
|
||||
|
||||
videoTextView = new TextView(context);
|
||||
videoTextView.setTextColor(0xffffffff);
|
||||
videoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
||||
videoTextView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
videoInfoContainer.addView(videoTextView);
|
||||
layoutParams1 = (LinearLayout.LayoutParams) videoTextView.getLayoutParams();
|
||||
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.leftMargin = AndroidUtilities.dp(4);
|
||||
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
|
||||
layoutParams1.bottomMargin = AndroidUtilities.dp(1);
|
||||
videoTextView.setLayoutParams(layoutParams1);
|
||||
|
||||
selector = new View(context);
|
||||
selector.setBackgroundResource(R.drawable.list_selector);
|
||||
addView(selector);
|
||||
layoutParams = (LayoutParams) selector.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||
selector.setLayoutParams(layoutParams);
|
||||
|
||||
checkBox = new CheckBox(context, R.drawable.round_check2);
|
||||
checkBox.setVisibility(GONE);
|
||||
addView(checkBox);
|
||||
layoutParams = (LayoutParams) checkBox.getLayoutParams();
|
||||
layoutParams.width = AndroidUtilities.dp(22);
|
||||
layoutParams.height = AndroidUtilities.dp(22);
|
||||
layoutParams.gravity = Gravity.RIGHT | Gravity.TOP;
|
||||
layoutParams.topMargin = AndroidUtilities.dp(6);
|
||||
layoutParams.rightMargin = AndroidUtilities.dp(6);
|
||||
checkBox.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
selector.drawableHotspotChanged(event.getX(), event.getY());
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public SharedPhotoVideoCell(Context context) {
|
||||
super(context);
|
||||
|
||||
messageObjects = new MessageObject[6];
|
||||
photoVideoViews = new PhotoVideoView[6];
|
||||
indeces = new int[6];
|
||||
for (int a = 0; a < 6; a++) {
|
||||
photoVideoViews[a] = new PhotoVideoView(context);
|
||||
addView(photoVideoViews[a]);
|
||||
photoVideoViews[a].setVisibility(GONE);
|
||||
photoVideoViews[a].setTag(a);
|
||||
photoVideoViews[a].setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (delegate != null) {
|
||||
int a = (Integer) v.getTag();
|
||||
delegate.didClickItem(SharedPhotoVideoCell.this, indeces[a], messageObjects[a], a);
|
||||
}
|
||||
}
|
||||
});
|
||||
photoVideoViews[a].setOnLongClickListener(new OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (delegate != null) {
|
||||
int a = (Integer) v.getTag();
|
||||
return delegate.didLongClickItem(SharedPhotoVideoCell.this, indeces[a], messageObjects[a], a);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void setDelegate(SharedPhotoVideoCellDelegate delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public void setItemsCount(int count) {
|
||||
for (int a = 0; a < photoVideoViews.length; a++) {
|
||||
photoVideoViews[a].setVisibility(a < count ? VISIBLE : GONE);
|
||||
}
|
||||
itemsCount = count;
|
||||
}
|
||||
|
||||
public BackupImageView getImageView(int a) {
|
||||
if (a >= itemsCount) {
|
||||
return null;
|
||||
}
|
||||
return photoVideoViews[a].imageView;
|
||||
}
|
||||
|
||||
public MessageObject getMessageObject(int a) {
|
||||
if (a >= itemsCount) {
|
||||
return null;
|
||||
}
|
||||
return messageObjects[a];
|
||||
}
|
||||
|
||||
public void setIsFirst(boolean first) {
|
||||
isFirst = first;
|
||||
}
|
||||
|
||||
public void setChecked(int a, boolean checked, boolean animated) {
|
||||
if (photoVideoViews[a].checkBox.getVisibility() != VISIBLE) {
|
||||
photoVideoViews[a].checkBox.setVisibility(VISIBLE);
|
||||
}
|
||||
photoVideoViews[a].checkBox.setChecked(checked, animated);
|
||||
}
|
||||
|
||||
public void setItem(int a, int index, MessageObject messageObject) {
|
||||
messageObjects[a] = messageObject;
|
||||
indeces[a] = index;
|
||||
|
||||
if (messageObject != null) {
|
||||
photoVideoViews[a].setVisibility(VISIBLE);
|
||||
|
||||
PhotoVideoView photoVideoView = photoVideoViews[a];
|
||||
photoVideoView.imageView.imageReceiver.setParentMessageObject(messageObject);
|
||||
photoVideoView.imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(messageObject), false);
|
||||
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo && messageObject.messageOwner.media.video != null) {
|
||||
photoVideoView.videoInfoContainer.setVisibility(VISIBLE);
|
||||
int duration = messageObject.messageOwner.media.video.duration;
|
||||
int minutes = duration / 60;
|
||||
int seconds = duration - minutes * 60;
|
||||
photoVideoView.videoTextView.setText(String.format("%d:%02d", minutes, seconds));
|
||||
if (messageObject.messageOwner.media.video.thumb != null) {
|
||||
TLRPC.FileLocation location = messageObject.messageOwner.media.video.thumb.location;
|
||||
photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, location, "b", 0);
|
||||
} else {
|
||||
photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
|
||||
}
|
||||
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
|
||||
photoVideoView.videoInfoContainer.setVisibility(GONE);
|
||||
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
|
||||
photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, photoSize.location, "b", 0);
|
||||
} else {
|
||||
photoVideoView.videoInfoContainer.setVisibility(GONE);
|
||||
photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
|
||||
}
|
||||
} else {
|
||||
photoVideoViews[a].setVisibility(GONE);
|
||||
messageObjects[a] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int itemWidth;
|
||||
if (AndroidUtilities.isTablet()) {
|
||||
itemWidth = (AndroidUtilities.dp(490) - ((itemsCount + 1) * AndroidUtilities.dp(4))) / itemsCount;
|
||||
} else {
|
||||
itemWidth = (AndroidUtilities.displaySize.x - ((itemsCount + 1) * AndroidUtilities.dp(4))) / itemsCount;
|
||||
}
|
||||
|
||||
for (int a = 0; a < itemsCount; a++) {
|
||||
LayoutParams layoutParams = (LayoutParams) photoVideoViews[a].getLayoutParams();
|
||||
layoutParams.topMargin = isFirst ? 0 : AndroidUtilities.dp(4);
|
||||
layoutParams.leftMargin = (itemWidth + AndroidUtilities.dp(4)) * a + AndroidUtilities.dp(4);
|
||||
layoutParams.width = itemWidth;
|
||||
layoutParams.height = itemWidth;
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
photoVideoViews[a].setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((isFirst ? 0 : AndroidUtilities.dp(4)) + itemWidth, MeasureSpec.EXACTLY));
|
||||
}
|
||||
}
|
@ -48,7 +48,8 @@ public class TextCell extends FrameLayout {
|
||||
textView.setLayoutParams(layoutParams);
|
||||
|
||||
valueTextView = new TextView(context);
|
||||
valueTextView.setTextColor(0xff2f8cc9);
|
||||
//valueTextView.setTextColor(0xff2f8cc9);
|
||||
valueTextView.setTextColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||
valueTextView.setLines(1);
|
||||
valueTextView.setMaxLines(1);
|
||||
@ -95,6 +96,10 @@ public class TextCell extends FrameLayout {
|
||||
textView.setTextColor(color);
|
||||
}
|
||||
|
||||
public void setTextSize(int size) {
|
||||
textView.setTextSize(size);
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
textView.setText(text);
|
||||
imageView.setVisibility(GONE);
|
||||
|
@ -56,7 +56,10 @@ public class TextSettingsCell extends FrameLayout {
|
||||
textView.setLayoutParams(layoutParams);
|
||||
|
||||
valueTextView = new TextView(context);
|
||||
valueTextView.setTextColor(0xff2f8cc9);
|
||||
//valueTextView.setTextColor(0xff2f8cc9);
|
||||
//
|
||||
valueTextView.setTextColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
//
|
||||
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||
valueTextView.setLines(1);
|
||||
valueTextView.setMaxLines(1);
|
||||
|
@ -48,7 +48,9 @@ public class UserCell extends FrameLayout {
|
||||
private TLRPC.FileLocation lastAvatar = null;
|
||||
|
||||
private int statusColor = 0xffa8a8a8;
|
||||
private int statusOnlineColor = 0xff3b84c0;
|
||||
private int statusOnlineColor = AndroidUtilities.getIntDarkerColor("themeColor",0x15);//0xff3b84c0;
|
||||
|
||||
private int nameColor = 0xff000000;
|
||||
|
||||
public UserCell(Context context, int padding) {
|
||||
super(context);
|
||||
@ -67,6 +69,7 @@ public class UserCell extends FrameLayout {
|
||||
avatarDrawable = new AvatarDrawable();
|
||||
|
||||
nameTextView = new TextView(context);
|
||||
//ContactsNamesColor
|
||||
nameTextView.setTextColor(0xff212121);
|
||||
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
|
||||
nameTextView.setLines(1);
|
||||
@ -165,6 +168,10 @@ public class UserCell extends FrameLayout {
|
||||
statusOnlineColor = onlineColor;
|
||||
}
|
||||
|
||||
public void setNameColor(int color) {
|
||||
nameColor = color;
|
||||
}
|
||||
|
||||
public void update(int mask) {
|
||||
if (currentUser == null) {
|
||||
return;
|
||||
@ -214,6 +221,8 @@ public class UserCell extends FrameLayout {
|
||||
nameTextView.setText(currentName);
|
||||
} else {
|
||||
nameTextView.setText(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
|
||||
nameTextView.setTextColor(nameColor);
|
||||
nameTextView.setTextSize(AndroidUtilities.getIntDef("contactsNameSize", 17));
|
||||
}
|
||||
if (currrntStatus != null) {
|
||||
statusTextView.setText(currrntStatus);
|
||||
@ -227,7 +236,7 @@ public class UserCell extends FrameLayout {
|
||||
statusTextView.setTextColor(statusColor);
|
||||
}
|
||||
}
|
||||
|
||||
statusTextView.setTextSize(AndroidUtilities.getIntDef("contactsStatusSize", 14));
|
||||
imageView.setVisibility(currentDrawable == 0 ? GONE : VISIBLE);
|
||||
imageView.setImageResource(currentDrawable);
|
||||
avatarImageView.setImage(photo, "50_50", avatarDrawable);
|
||||
|
@ -55,7 +55,7 @@ public class ChangeChatNameActivity extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
if (fragmentView == null) {
|
||||
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
|
@ -48,7 +48,7 @@ public class ChangeNameActivity extends BaseFragment {
|
||||
private final static int done_button = 1;
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
if (fragmentView == null) {
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
actionBar.setAllowOverlayTitle(true);
|
||||
|
@ -101,7 +101,7 @@ public class ChangePhoneActivity extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
if (fragmentView == null) {
|
||||
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
@ -289,9 +289,9 @@ public class ChangePhoneActivity extends BaseFragment {
|
||||
|
||||
private int countryState = 0;
|
||||
|
||||
private ArrayList<String> countriesArray = new ArrayList<String>();
|
||||
private HashMap<String, String> countriesMap = new HashMap<String, String>();
|
||||
private HashMap<String, String> codesMap = new HashMap<String, String>();
|
||||
private ArrayList<String> countriesArray = new ArrayList<>();
|
||||
private HashMap<String, String> countriesMap = new HashMap<>();
|
||||
private HashMap<String, String> codesMap = new HashMap<>();
|
||||
|
||||
private boolean ignoreSelection = false;
|
||||
private boolean ignoreOnTextChange = false;
|
||||
@ -533,7 +533,7 @@ public class ChangePhoneActivity extends BaseFragment {
|
||||
layoutParams.gravity = Gravity.LEFT;
|
||||
textView.setLayoutParams(layoutParams);
|
||||
|
||||
HashMap<String, String> languageMap = new HashMap<String, String>();
|
||||
HashMap<String, String> languageMap = new HashMap<>();
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().getAssets().open("countries.txt")));
|
||||
String line;
|
||||
@ -544,6 +544,7 @@ public class ChangePhoneActivity extends BaseFragment {
|
||||
codesMap.put(args[0], args[2]);
|
||||
languageMap.put(args[1], args[2]);
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
@ -815,7 +816,8 @@ public class ChangePhoneActivity extends BaseFragment {
|
||||
|
||||
TextView wrongNumber = new TextView(context);
|
||||
wrongNumber.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL);
|
||||
wrongNumber.setTextColor(0xff4d83b3);
|
||||
//wrongNumber.setTextColor(0xff4d83b3);
|
||||
wrongNumber.setTextColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
wrongNumber.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||
wrongNumber.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
|
||||
wrongNumber.setPadding(0, AndroidUtilities.dp(24), 0, 0);
|
||||
@ -1013,7 +1015,7 @@ public class ChangePhoneActivity extends BaseFragment {
|
||||
destroyCodeTimer();
|
||||
UserConfig.setCurrentUser(user);
|
||||
UserConfig.saveConfig(true);
|
||||
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
||||
ArrayList<TLRPC.User> users = new ArrayList<>();
|
||||
users.add(user);
|
||||
MessagesStorage.getInstance().putUsersAndChats(users, null, true, true);
|
||||
MessagesController.getInstance().putUser(user, false);
|
||||
|
@ -35,7 +35,7 @@ import org.telegram.ui.ActionBar.BaseFragment;
|
||||
public class ChangePhoneHelpActivity extends BaseFragment {
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
if (fragmentView == null) {
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
actionBar.setAllowOverlayTitle(true);
|
||||
@ -118,7 +118,8 @@ public class ChangePhoneHelpActivity extends BaseFragment {
|
||||
textView = new TextView(getParentActivity());
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
||||
textView.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
textView.setTextColor(0xff4d83b3);
|
||||
//textView.setTextColor(0xff4d83b3);
|
||||
textView.setTextColor(AndroidUtilities.getIntColor("themeColor"));
|
||||
textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
|
||||
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
textView.setPadding(0, AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10));
|
||||
|
@ -61,7 +61,7 @@ public class ChangeUsernameActivity extends BaseFragment {
|
||||
private final static int done_button = 1;
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
public View createView(LayoutInflater inflater) {
|
||||
if (fragmentView == null) {
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
actionBar.setAllowOverlayTitle(true);
|
||||
@ -205,14 +205,19 @@ public class ChangeUsernameActivity extends BaseFragment {
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
||||
if (error.equals("USERNAME_INVALID")) {
|
||||
builder.setMessage(LocaleController.getString("UsernameInvalid", R.string.UsernameInvalid));
|
||||
} else if (error.equals("USERNAME_OCCUPIED")) {
|
||||
builder.setMessage(LocaleController.getString("UsernameInUse", R.string.UsernameInUse));
|
||||
} else if (error.equals("USERNAMES_UNAVAILABLE")) {
|
||||
builder.setMessage(LocaleController.getString("FeatureUnavailable", R.string.FeatureUnavailable));
|
||||
} else {
|
||||
builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
|
||||
switch (error) {
|
||||
case "USERNAME_INVALID":
|
||||
builder.setMessage(LocaleController.getString("UsernameInvalid", R.string.UsernameInvalid));
|
||||
break;
|
||||
case "USERNAME_OCCUPIED":
|
||||
builder.setMessage(LocaleController.getString("UsernameInUse", R.string.UsernameInUse));
|
||||
break;
|
||||
case "USERNAMES_UNAVAILABLE":
|
||||
builder.setMessage(LocaleController.getString("FeatureUnavailable", R.string.FeatureUnavailable));
|
||||
break;
|
||||
default:
|
||||
builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
|
||||
break;
|
||||
}
|
||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
||||
showAlertDialog(builder);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,9 @@ import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.Layout;
|
||||
import android.text.StaticLayout;
|
||||
import android.text.TextPaint;
|
||||
@ -51,6 +53,7 @@ public class AvatarDrawable extends Drawable {
|
||||
private boolean isProfile;
|
||||
private boolean drawBrodcast;
|
||||
private boolean drawPhoto;
|
||||
private int radius;
|
||||
|
||||
public AvatarDrawable() {
|
||||
super();
|
||||
@ -62,6 +65,7 @@ public class AvatarDrawable extends Drawable {
|
||||
|
||||
broadcastDrawable = ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.broadcast_w);
|
||||
}
|
||||
radius = 26;
|
||||
}
|
||||
|
||||
public AvatarDrawable(TLRPC.User user) {
|
||||
@ -155,6 +159,10 @@ public class AvatarDrawable extends Drawable {
|
||||
color = value;
|
||||
}
|
||||
|
||||
public void setRadius(int value) {
|
||||
radius = value;
|
||||
}
|
||||
|
||||
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast) {
|
||||
if (isProfile) {
|
||||
color = arrColorsProfiles[getColorIndex(id)];
|
||||
@ -164,6 +172,11 @@ public class AvatarDrawable extends Drawable {
|
||||
|
||||
drawBrodcast = isBroadcast;
|
||||
|
||||
if (firstName == null || firstName.length() == 0) {
|
||||
firstName = lastName;
|
||||
lastName = null;
|
||||
}
|
||||
|
||||
String text = "";
|
||||
if (firstName != null && firstName.length() > 0) {
|
||||
text += firstName.substring(0, 1);
|
||||
@ -176,8 +189,26 @@ public class AvatarDrawable extends Drawable {
|
||||
}
|
||||
lastch = lastName.substring(a, a + 1);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 16) {
|
||||
text += "\u200C" + lastch;
|
||||
} else {
|
||||
text += lastch;
|
||||
}
|
||||
} else if (firstName != null && firstName.length() > 0) {
|
||||
for (int a = firstName.length() - 1; a >= 0; a--) {
|
||||
if (firstName.charAt(a) == ' ') {
|
||||
if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
|
||||
if (Build.VERSION.SDK_INT >= 16) {
|
||||
text += "\u200C" + firstName.substring(a + 1, a + 2);
|
||||
} else {
|
||||
text += firstName.substring(a + 1, a + 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (text.length() > 0) {
|
||||
text = text.toUpperCase();
|
||||
try {
|
||||
@ -213,6 +244,9 @@ public class AvatarDrawable extends Drawable {
|
||||
canvas.save();
|
||||
canvas.translate(bounds.left, bounds.top);
|
||||
canvas.drawCircle(size / 2, size / 2, size / 2, paint);
|
||||
//Rect rect = new Rect(0, 0, size, size);
|
||||
//RectF rectF = new RectF(rect);
|
||||
//canvas.drawRoundRect( rectF, AndroidUtilities.dp(26), AndroidUtilities.dp(26), paint);
|
||||
|
||||
if (drawBrodcast && broadcastDrawable != null) {
|
||||
int x = (size - broadcastDrawable.getIntrinsicWidth()) / 2;
|
||||
|
@ -11,12 +11,14 @@ package org.telegram.ui.Components;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.ExifInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.ImageLoader;
|
||||
import org.telegram.android.MediaController;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.messenger.FileLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
@ -24,10 +26,13 @@ import org.telegram.android.NotificationCenter;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.LaunchActivity;
|
||||
import org.telegram.ui.PhotoAlbumPickerActivity;
|
||||
import org.telegram.ui.PhotoCropActivity;
|
||||
import org.telegram.ui.ActionBar.BaseFragment;
|
||||
import org.telegram.ui.PhotoViewer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoEditActivityDelegate {
|
||||
public String currentPicturePath;
|
||||
@ -68,13 +73,33 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||
}
|
||||
|
||||
public void openGallery() {
|
||||
try {
|
||||
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
photoPickerIntent.setType("image/*");
|
||||
parentFragment.startActivityForResult(photoPickerIntent, 14);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(true);
|
||||
fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
|
||||
@Override
|
||||
public void didSelectPhotos(ArrayList<String> photos) {
|
||||
if (!photos.isEmpty()) {
|
||||
Bitmap bitmap = ImageLoader.loadBitmap(photos.get(0), null, 800, 800, true);
|
||||
processBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didSelectWebPhotos(ArrayList<MediaController.SearchImage> photos) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startPhotoSelectActivity() {
|
||||
try {
|
||||
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
photoPickerIntent.setType("image/*");
|
||||
parentFragment.startActivityForResult(photoPickerIntent, 14);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
parentFragment.presentFragment(fragment);
|
||||
}
|
||||
|
||||
private void startCrop(String path, Uri uri) {
|
||||
@ -102,9 +127,42 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (requestCode == 13) {
|
||||
PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
|
||||
int orientation = 0;
|
||||
try {
|
||||
ExifInterface ei = new ExifInterface(currentPicturePath);
|
||||
int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
||||
switch(exif) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
orientation = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
orientation = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
orientation = 270;
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
final ArrayList<Object> arrayList = new ArrayList<>();
|
||||
arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation));
|
||||
PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, 1, new PhotoViewer.EmptyPhotoViewerProvider() {
|
||||
@Override
|
||||
public void sendButtonPressed(int index) {
|
||||
String path = null;
|
||||
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
|
||||
if (photoEntry.imagePath != null) {
|
||||
path = photoEntry.imagePath;
|
||||
} else if (photoEntry.path != null) {
|
||||
path = photoEntry.path;
|
||||
}
|
||||
Bitmap bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
|
||||
processBitmap(bitmap);
|
||||
}
|
||||
});
|
||||
Utilities.addMediaToGallery(currentPicturePath);
|
||||
startCrop(currentPicturePath, null);
|
||||
|
||||
currentPicturePath = null;
|
||||
} else if (requestCode == 14) {
|
||||
if (data == null || data.getData() == null) {
|
||||
|
@ -68,6 +68,10 @@ public class BackupImageView extends View {
|
||||
setImage(null, path, filter, thumb, null, null, null, 0);
|
||||
}
|
||||
|
||||
public void setOrientation(int angle, boolean center) {
|
||||
imageReceiver.setOrientation(angle, center);
|
||||
}
|
||||
|
||||
public void setImage(TLObject path, String httpUrl, String filter, Drawable thumb, Bitmap thumbBitmap, TLRPC.FileLocation thumbLocation, String thumbFilter, int size) {
|
||||
if (thumbBitmap != null) {
|
||||
thumb = new BitmapDrawable(null, thumbBitmap);
|
||||
|
@ -11,13 +11,16 @@ package org.telegram.ui.Components;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@ -29,8 +32,8 @@ import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -39,22 +42,23 @@ import org.telegram.android.Emoji;
|
||||
import org.telegram.android.LocaleController;
|
||||
import org.telegram.android.MediaController;
|
||||
import org.telegram.android.MessagesController;
|
||||
import org.telegram.android.NotificationCenter;
|
||||
import org.telegram.android.SendMessagesHelper;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.android.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.TLRPC;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.ui.ActionBar.BaseFragment;
|
||||
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
|
||||
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
|
||||
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
|
||||
import org.telegram.ui.AnimationCompat.ViewProxy;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ChatActivityEnterView implements NotificationCenter.NotificationCenterDelegate, SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate {
|
||||
public class ChatActivityEnterView extends LinearLayout implements NotificationCenter.NotificationCenterDelegate, SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate {
|
||||
|
||||
public static interface ChatActivityEnterViewDelegate {
|
||||
public abstract void onMessageSend();
|
||||
@ -66,17 +70,18 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
}
|
||||
|
||||
private EditText messsageEditText;
|
||||
private ImageButton sendButton;
|
||||
private ImageView sendButton;
|
||||
private PopupWindow emojiPopup;
|
||||
private ImageView emojiButton;
|
||||
private EmojiView emojiView;
|
||||
private TextView recordTimeText;
|
||||
private ImageButton audioSendButton;
|
||||
private View recordPanel;
|
||||
private View slideText;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private ImageView audioSendButton;
|
||||
private FrameLayout recordPanel;
|
||||
private LinearLayout slideText;
|
||||
private SizeNotifierRelativeLayout sizeNotifierRelativeLayout;
|
||||
private FrameLayout attachButton;
|
||||
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private AnimatorSetProxy runningAnimation;
|
||||
private AnimatorSetProxy runningAnimation2;
|
||||
private ObjectAnimatorProxy runningAnimationAudio;
|
||||
@ -94,11 +99,18 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
private boolean recordingAudio;
|
||||
|
||||
private Activity parentActivity;
|
||||
private BaseFragment parentFragment;
|
||||
private long dialog_id;
|
||||
private boolean ignoreTextChange;
|
||||
private ChatActivityEnterViewDelegate delegate;
|
||||
|
||||
public ChatActivityEnterView() {
|
||||
public ChatActivityEnterView(Activity context, SizeNotifierRelativeLayout parent, BaseFragment fragment, boolean isChat) {
|
||||
super(context);
|
||||
setOrientation(HORIZONTAL);
|
||||
setBackgroundResource(R.drawable.compose_panel);
|
||||
setFocusable(true);
|
||||
setFocusableInTouchMode(true);
|
||||
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStarted);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStartError);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStopped);
|
||||
@ -108,64 +120,32 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.hideEmojiKeyboard);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioRouteChanged);
|
||||
parentActivity = context;
|
||||
parentFragment = fragment;
|
||||
sizeNotifierRelativeLayout = parent;
|
||||
sizeNotifierRelativeLayout.setDelegate(this);
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
sendByEnter = preferences.getBoolean("send_by_enter", false);
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStarted);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStartError);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStopped);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordProgressChanged);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidSent);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.hideEmojiKeyboard);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioRouteChanged);
|
||||
if (mWakeLock != null) {
|
||||
try {
|
||||
mWakeLock.release();
|
||||
mWakeLock = null;
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
if (sizeNotifierRelativeLayout != null) {
|
||||
sizeNotifierRelativeLayout.delegate = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setContainerView(Activity activity, View containerView) {
|
||||
parentActivity = activity;
|
||||
|
||||
sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) containerView.findViewById(R.id.chat_layout);
|
||||
sizeNotifierRelativeLayout.delegate = this;
|
||||
|
||||
messsageEditText = (EditText) containerView.findViewById(R.id.chat_text_edit);
|
||||
messsageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
|
||||
|
||||
attachButton = (FrameLayout) containerView.findViewById(R.id.chat_attach_button);
|
||||
if (attachButton != null) {
|
||||
ViewProxy.setPivotX(attachButton, AndroidUtilities.dp(48));
|
||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messsageEditText.getLayoutParams();
|
||||
layoutParams.rightMargin = AndroidUtilities.dp(50);
|
||||
messsageEditText.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
sendButton = (ImageButton) containerView.findViewById(R.id.chat_send_button);
|
||||
sendButton.setVisibility(View.INVISIBLE);
|
||||
ViewProxy.setScaleX(sendButton, 0.1f);
|
||||
ViewProxy.setScaleY(sendButton, 0.1f);
|
||||
ViewProxy.setAlpha(sendButton, 0.0f);
|
||||
sendButton.clearAnimation();
|
||||
emojiButton = (ImageView) containerView.findViewById(R.id.chat_smile_button);
|
||||
audioSendButton = (ImageButton) containerView.findViewById(R.id.chat_audio_send_button);
|
||||
recordPanel = containerView.findViewById(R.id.record_panel);
|
||||
recordTimeText = (TextView) containerView.findViewById(R.id.recording_time_text);
|
||||
slideText = containerView.findViewById(R.id.slideText);
|
||||
TextView textView = (TextView) containerView.findViewById(R.id.slideToCancelTextView);
|
||||
textView.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
|
||||
FrameLayoutFixed frameLayout = new FrameLayoutFixed(context);
|
||||
addView(frameLayout);
|
||||
LayoutParams layoutParams = (LayoutParams) frameLayout.getLayoutParams();
|
||||
layoutParams.width = 0;
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.weight = 1;
|
||||
frameLayout.setLayoutParams(layoutParams);
|
||||
|
||||
emojiButton = new ImageView(context);
|
||||
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
|
||||
emojiButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
emojiButton.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(1), 0, 0);
|
||||
frameLayout.addView(emojiButton);
|
||||
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) emojiButton.getLayoutParams();
|
||||
layoutParams1.width = AndroidUtilities.dp(48);
|
||||
layoutParams1.height = AndroidUtilities.dp(48);
|
||||
layoutParams1.gravity = Gravity.BOTTOM;
|
||||
layoutParams1.topMargin = AndroidUtilities.dp(2);
|
||||
emojiButton.setLayoutParams(layoutParams1);
|
||||
emojiButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@ -173,6 +153,27 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
}
|
||||
});
|
||||
|
||||
messsageEditText = new EditText(context);
|
||||
messsageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
|
||||
messsageEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
messsageEditText.setInputType(messsageEditText.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||
messsageEditText.setSingleLine(false);
|
||||
messsageEditText.setMaxLines(4);
|
||||
messsageEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
||||
messsageEditText.setGravity(Gravity.BOTTOM);
|
||||
messsageEditText.setPadding(0, AndroidUtilities.dp(11), 0, AndroidUtilities.dp(12));
|
||||
messsageEditText.setBackgroundDrawable(null);
|
||||
AndroidUtilities.clearCursorDrawable(messsageEditText);
|
||||
messsageEditText.setTextColor(0xff000000);
|
||||
messsageEditText.setHintTextColor(0xffb2b2b2);
|
||||
frameLayout.addView(messsageEditText);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) messsageEditText.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.gravity = Gravity.BOTTOM;
|
||||
layoutParams1.leftMargin = AndroidUtilities.dp(52);
|
||||
layoutParams1.rightMargin = AndroidUtilities.dp(isChat ? 50 : 2);
|
||||
messsageEditText.setLayoutParams(layoutParams1);
|
||||
messsageEditText.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View view, int i, KeyEvent keyEvent) {
|
||||
@ -188,7 +189,6 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
messsageEditText.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@ -197,7 +197,6 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
||||
@ -213,18 +212,185 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
sendButton.setOnClickListener(new View.OnClickListener() {
|
||||
messsageEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
sendMessage();
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
String message = getTrimmedString(charSequence.toString());
|
||||
checkSendButton(true);
|
||||
|
||||
if (delegate != null) {
|
||||
delegate.onTextChanged(charSequence);
|
||||
}
|
||||
|
||||
if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
|
||||
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
|
||||
TLRPC.User currentUser = null;
|
||||
if ((int) dialog_id > 0) {
|
||||
currentUser = MessagesController.getInstance().getUser((int) dialog_id);
|
||||
}
|
||||
if (currentUser != null && (currentUser.id == UserConfig.getClientUserId() || currentUser.status != null && currentUser.status.expires < currentTime)) {
|
||||
return;
|
||||
}
|
||||
lastTypingTimeSend = System.currentTimeMillis();
|
||||
if (delegate != null) {
|
||||
delegate.needSendTyping();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
|
||||
sendMessage();
|
||||
}
|
||||
int i = 0;
|
||||
ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
|
||||
int j = arrayOfImageSpan.length;
|
||||
while (true) {
|
||||
if (i >= j) {
|
||||
Emoji.replaceEmoji(editable, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
return;
|
||||
}
|
||||
editable.removeSpan(arrayOfImageSpan[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isChat) {
|
||||
attachButton = new FrameLayout(context);
|
||||
attachButton.setEnabled(false);
|
||||
ViewProxy.setPivotX(attachButton, AndroidUtilities.dp(48));
|
||||
frameLayout.addView(attachButton);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) attachButton.getLayoutParams();
|
||||
layoutParams1.width = AndroidUtilities.dp(48);
|
||||
layoutParams1.height = AndroidUtilities.dp(48);
|
||||
layoutParams1.gravity = Gravity.BOTTOM | Gravity.RIGHT;
|
||||
layoutParams1.topMargin = AndroidUtilities.dp(2);
|
||||
attachButton.setLayoutParams(layoutParams1);
|
||||
}
|
||||
|
||||
recordPanel = new FrameLayoutFixed(context);
|
||||
recordPanel.setVisibility(GONE);
|
||||
recordPanel.setBackgroundColor(0xffffffff);
|
||||
frameLayout.addView(recordPanel);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) recordPanel.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams1.height = AndroidUtilities.dp(48);
|
||||
layoutParams1.gravity = Gravity.BOTTOM;
|
||||
layoutParams1.topMargin = AndroidUtilities.dp(2);
|
||||
recordPanel.setLayoutParams(layoutParams1);
|
||||
|
||||
slideText = new LinearLayout(context);
|
||||
slideText.setOrientation(HORIZONTAL);
|
||||
recordPanel.addView(slideText);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) slideText.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.gravity = Gravity.CENTER;
|
||||
layoutParams1.leftMargin = AndroidUtilities.dp(30);
|
||||
slideText.setLayoutParams(layoutParams1);
|
||||
|
||||
ImageView imageView = new ImageView(context);
|
||||
imageView.setImageResource(R.drawable.slidearrow);
|
||||
slideText.addView(imageView);
|
||||
layoutParams = (LayoutParams) imageView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
||||
layoutParams.topMargin = AndroidUtilities.dp(1);
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
|
||||
TextView textView = new TextView(context);
|
||||
textView.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
|
||||
textView.setTextColor(0xff999999);
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
||||
slideText.addView(textView);
|
||||
layoutParams = (LayoutParams) textView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
||||
layoutParams.leftMargin = AndroidUtilities.dp(6);
|
||||
textView.setLayoutParams(layoutParams);
|
||||
|
||||
LinearLayout linearLayout = new LinearLayout(context);
|
||||
linearLayout.setOrientation(HORIZONTAL);
|
||||
linearLayout.setPadding(AndroidUtilities.dp(13), 0, 0, 0);
|
||||
linearLayout.setBackgroundColor(0xffffffff);
|
||||
recordPanel.addView(linearLayout);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) linearLayout.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
|
||||
linearLayout.setLayoutParams(layoutParams1);
|
||||
|
||||
imageView = new ImageView(context);
|
||||
imageView.setImageResource(R.drawable.rec);
|
||||
linearLayout.addView(imageView);
|
||||
layoutParams = (LayoutParams) imageView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
||||
layoutParams.topMargin = AndroidUtilities.dp(1);
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
|
||||
recordTimeText = new TextView(context);
|
||||
recordTimeText.setText("00:00");
|
||||
recordTimeText.setTextColor(0xff4d4c4b);
|
||||
recordTimeText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||
linearLayout.addView(recordTimeText);
|
||||
layoutParams = (LayoutParams) recordTimeText.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
||||
layoutParams.leftMargin = AndroidUtilities.dp(6);
|
||||
recordTimeText.setLayoutParams(layoutParams);
|
||||
|
||||
FrameLayout frameLayout1 = new FrameLayout(context);
|
||||
addView(frameLayout1);
|
||||
layoutParams = (LayoutParams) frameLayout1.getLayoutParams();
|
||||
layoutParams.width = AndroidUtilities.dp(48);
|
||||
layoutParams.height = AndroidUtilities.dp(48);
|
||||
layoutParams.gravity = Gravity.BOTTOM;
|
||||
layoutParams.topMargin = AndroidUtilities.dp(2);
|
||||
frameLayout1.setLayoutParams(layoutParams);
|
||||
|
||||
audioSendButton = new ImageView(context);
|
||||
audioSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
audioSendButton.setImageResource(R.drawable.mic_button_states);
|
||||
audioSendButton.setBackgroundColor(0xffffffff);
|
||||
audioSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0);
|
||||
frameLayout1.addView(audioSendButton);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) audioSendButton.getLayoutParams();
|
||||
layoutParams1.width = AndroidUtilities.dp(48);
|
||||
layoutParams1.height = AndroidUtilities.dp(48);
|
||||
audioSendButton.setLayoutParams(layoutParams1);
|
||||
audioSendButton.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if (parentFragment != null) {
|
||||
String action = null;
|
||||
TLRPC.Chat currentChat = null;
|
||||
if ((int) dialog_id < 0) {
|
||||
currentChat = MessagesController.getInstance().getChat(-(int) dialog_id);
|
||||
if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) {
|
||||
action = "bigchat_upload_audio";
|
||||
} else {
|
||||
action = "chat_upload_audio";
|
||||
}
|
||||
} else {
|
||||
action = "pm_upload_audio";
|
||||
}
|
||||
if (!MessagesController.isFeatureEnabled(action, parentFragment)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
startedDraggingX = -1;
|
||||
MediaController.getInstance().startRecording(dialog_id);
|
||||
updateAudioRecordIntefrace();
|
||||
@ -279,60 +445,87 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
}
|
||||
});
|
||||
|
||||
messsageEditText.addTextChangedListener(new TextWatcher() {
|
||||
sendButton = new ImageView(context);
|
||||
sendButton.setVisibility(View.INVISIBLE);
|
||||
sendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
sendButton.setImageResource(R.drawable.ic_send);
|
||||
ViewProxy.setScaleX(sendButton, 0.1f);
|
||||
ViewProxy.setScaleY(sendButton, 0.1f);
|
||||
ViewProxy.setAlpha(sendButton, 0.0f);
|
||||
sendButton.clearAnimation();
|
||||
frameLayout1.addView(sendButton);
|
||||
layoutParams1 = (FrameLayout.LayoutParams) sendButton.getLayoutParams();
|
||||
layoutParams1.width = AndroidUtilities.dp(48);
|
||||
layoutParams1.height = AndroidUtilities.dp(48);
|
||||
sendButton.setLayoutParams(layoutParams1);
|
||||
sendButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
String message = getTrimmedString(charSequence.toString());
|
||||
checkSendButton(true);
|
||||
|
||||
if (delegate != null) {
|
||||
delegate.onTextChanged(charSequence);
|
||||
}
|
||||
|
||||
if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
|
||||
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
|
||||
TLRPC.User currentUser = null;
|
||||
if ((int) dialog_id > 0) {
|
||||
currentUser = MessagesController.getInstance().getUser((int) dialog_id);
|
||||
}
|
||||
if (currentUser != null && (currentUser.id == UserConfig.getClientUserId() || currentUser.status != null && currentUser.status.expires < currentTime)) {
|
||||
return;
|
||||
}
|
||||
lastTypingTimeSend = System.currentTimeMillis();
|
||||
if (delegate != null) {
|
||||
delegate.needSendTyping();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
|
||||
sendMessage();
|
||||
}
|
||||
int i = 0;
|
||||
ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
|
||||
int j = arrayOfImageSpan.length;
|
||||
while (true) {
|
||||
if (i >= j) {
|
||||
Emoji.replaceEmoji(editable, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
|
||||
return;
|
||||
}
|
||||
editable.removeSpan(arrayOfImageSpan[i]);
|
||||
i++;
|
||||
}
|
||||
public void onClick(View view) {
|
||||
sendMessage();
|
||||
}
|
||||
});
|
||||
|
||||
checkSendButton(false);
|
||||
|
||||
updateColors();
|
||||
}
|
||||
|
||||
private void updateColors() {
|
||||
Drawable send = parentActivity.getResources().getDrawable(R.drawable.ic_send_white);
|
||||
send.setColorFilter(AndroidUtilities.getIntDef("chatSendIconColor", AndroidUtilities.getIntColor("themeColor")), PorterDuff.Mode.MULTIPLY);
|
||||
sendButton.setImageDrawable(send);
|
||||
messsageEditText.setTextColor(AndroidUtilities.getIntDef("chatEditTextColor",0xff000000));
|
||||
messsageEditText.setTextSize(AndroidUtilities.getIntDef("chatEditTextSize",18));
|
||||
int color = AndroidUtilities.getIntDef("chatEditTextBGColor", 0xffffffff);
|
||||
setBackgroundColor(color);
|
||||
audioSendButton.setBackgroundColor(0x00000000);
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStarted);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStartError);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStopped);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordProgressChanged);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidSent);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.hideEmojiKeyboard);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioRouteChanged);
|
||||
if (mWakeLock != null) {
|
||||
try {
|
||||
mWakeLock.release();
|
||||
mWakeLock = null;
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
if (sizeNotifierRelativeLayout != null) {
|
||||
sizeNotifierRelativeLayout.setDelegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDialogId(long id) {
|
||||
dialog_id = id;
|
||||
}
|
||||
|
||||
private void sendMessage() {
|
||||
if (parentFragment != null) {
|
||||
String action = null;
|
||||
TLRPC.Chat currentChat = null;
|
||||
if ((int) dialog_id < 0) {
|
||||
currentChat = MessagesController.getInstance().getChat(-(int) dialog_id);
|
||||
if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) {
|
||||
action = "bigchat_message";
|
||||
} else {
|
||||
action = "chat_message";
|
||||
}
|
||||
} else {
|
||||
action = "pm_message";
|
||||
}
|
||||
if (!MessagesController.isFeatureEnabled(action, parentFragment)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (processSendingText(messsageEditText.getText().toString())) {
|
||||
messsageEditText.setText("");
|
||||
lastTypingTimeSend = 0;
|
||||
@ -699,7 +892,11 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
|
||||
}
|
||||
if (emojiPopup != null) {
|
||||
try {
|
||||
emojiPopup.dismiss();
|
||||
} catch (Exception e) {
|
||||
//don't promt
|
||||
}
|
||||
}
|
||||
if (sizeNotifierRelativeLayout != null) {
|
||||
sizeNotifierRelativeLayout.post(new Runnable() {
|
||||
@ -725,10 +922,6 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public void setDialogId(long id) {
|
||||
dialog_id = id;
|
||||
}
|
||||
|
||||
public void setFieldText(String text) {
|
||||
if (messsageEditText == null) {
|
||||
return;
|
||||
|
@ -14,7 +14,6 @@ import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.view.View;
|
||||
@ -27,9 +26,11 @@ public class ClippingImageView extends View {
|
||||
private int clipLeft;
|
||||
private int clipRight;
|
||||
private int clipTop;
|
||||
private Rect drawRect;
|
||||
private int orientation;
|
||||
private RectF drawRect;
|
||||
private Paint paint;
|
||||
private Bitmap bmp;
|
||||
private Matrix matrix;
|
||||
private onDrawListener drawListener;
|
||||
|
||||
private boolean needRadius;
|
||||
@ -48,7 +49,9 @@ public class ClippingImageView extends View {
|
||||
super(context);
|
||||
paint = new Paint();
|
||||
paint.setFilterBitmap(true);
|
||||
drawRect = new Rect();
|
||||
matrix = new Matrix();
|
||||
drawRect = new RectF();
|
||||
bitmapRect = new RectF();
|
||||
}
|
||||
|
||||
public int getClipBottom() {
|
||||
@ -85,6 +88,7 @@ public class ClippingImageView extends View {
|
||||
drawListener.onDraw();
|
||||
}
|
||||
canvas.save();
|
||||
|
||||
if (needRadius) {
|
||||
roundRect.set(0, 0, getWidth(), getHeight());
|
||||
shaderMatrix.reset();
|
||||
@ -92,10 +96,24 @@ public class ClippingImageView extends View {
|
||||
bitmapShader.setLocalMatrix(shaderMatrix);
|
||||
canvas.drawRoundRect(roundRect, radius, radius, roundPaint);
|
||||
} else {
|
||||
if (orientation == 90 || orientation == 270) {
|
||||
drawRect.set(-getHeight() / 2, -getWidth() / 2, getHeight() / 2, getWidth() / 2);
|
||||
matrix.setRectToRect(bitmapRect, drawRect, Matrix.ScaleToFit.FILL);
|
||||
matrix.postRotate(orientation, 0, 0);
|
||||
matrix.postTranslate(getWidth() / 2, getHeight() / 2);
|
||||
} else if (orientation == 180) {
|
||||
drawRect.set(-getWidth() / 2, -getHeight() / 2, getWidth() / 2, getHeight() / 2);
|
||||
matrix.setRectToRect(bitmapRect, drawRect, Matrix.ScaleToFit.FILL);
|
||||
matrix.postRotate(orientation, 0, 0);
|
||||
matrix.postTranslate(getWidth() / 2, getHeight() / 2);
|
||||
} else {
|
||||
drawRect.set(0, 0, getWidth(), getHeight());
|
||||
matrix.setRectToRect(bitmapRect, drawRect, Matrix.ScaleToFit.FILL);
|
||||
}
|
||||
|
||||
canvas.clipRect(clipLeft / scaleY, clipTop / scaleY, getWidth() - clipRight / scaleY, getHeight() - clipBottom / scaleY);
|
||||
drawRect.set(0, 0, getWidth(), getHeight());
|
||||
try {
|
||||
canvas.drawBitmap(bmp, null, drawRect, paint);
|
||||
canvas.drawBitmap(bmp, matrix, paint);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
@ -136,16 +154,21 @@ public class ClippingImageView extends View {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setOrientation(int angle) {
|
||||
orientation = angle;
|
||||
}
|
||||
|
||||
public void setImageBitmap(Bitmap bitmap) {
|
||||
bmp = bitmap;
|
||||
if (bitmap != null && needRadius) {
|
||||
roundRect = new RectF();
|
||||
shaderMatrix = new Matrix();
|
||||
bitmapRect = new RectF();
|
||||
if (bitmap != null) {
|
||||
bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
||||
roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
roundPaint.setShader(bitmapShader);
|
||||
if (needRadius) {
|
||||
roundRect = new RectF();
|
||||
shaderMatrix = new Matrix();
|
||||
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
||||
roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
roundPaint.setShader(bitmapShader);
|
||||
}
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class ColorSelectorDialog extends Dialog implements
|
||||
ColorPickerView.OnColorChangedListener,
|
||||
View.OnClickListener {
|
||||
|
||||
public final static int BOTTOM = 1;
|
||||
public final static int RIGHT = 2;
|
||||
public final static int TOP = 3;
|
||||
public final static int LEFT = 4;
|
||||
public final static int CENTER = 0;
|
||||
|
||||
private org.telegram.ui.Components.ColorSelectorView content;
|
||||
private OnColorChangedListener listener;
|
||||
private int initColor;
|
||||
private int color;
|
||||
private Button btnOld;
|
||||
private Button btnNew;
|
||||
private HistorySelectorView history;
|
||||
private int side;
|
||||
private int offset;
|
||||
|
||||
private boolean alpha;
|
||||
|
||||
public interface OnColorChangedListener
|
||||
{
|
||||
public void colorChanged(int color);
|
||||
|
||||
//void onOk(OnColorChangedListener dialog, int color);
|
||||
}
|
||||
/*
|
||||
private void onColorChanged()
|
||||
{
|
||||
if(listener != null)
|
||||
listener.colorChanged(getColor());
|
||||
}*/
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public ColorSelectorDialog(Context context, OnColorChangedListener listener, int initColor, int side, int offset, boolean alpha) {
|
||||
super(context, R.style.myBackgroundStyle);
|
||||
this.listener = listener;
|
||||
this.initColor = initColor;
|
||||
this.side = side;
|
||||
this.offset = offset;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public ColorSelectorDialog(Context context, int initColor, int side) {
|
||||
super(context, R.style.myBackgroundStyle);
|
||||
this.initColor = initColor;
|
||||
this.side = side;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.colordialog);
|
||||
|
||||
if (this.side == RIGHT) {
|
||||
getWindow().setGravity(Gravity.RIGHT);
|
||||
android.view.WindowManager.LayoutParams p = getWindow().getAttributes();
|
||||
p.x = offset;
|
||||
getWindow().setAttributes(p);
|
||||
} else if (this.side == BOTTOM ) {
|
||||
// getWindow().setGravity(Gravity.BOTTOM);
|
||||
// android.view.WindowManager.LayoutParams p = getWindow().getAttributes();
|
||||
// p.y = offset;
|
||||
// getWindow().setAttributes(p);
|
||||
}
|
||||
|
||||
btnOld = (Button)findViewById(R.id.button_old);
|
||||
btnOld.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
btnNew = (Button)findViewById(R.id.button_new);
|
||||
btnNew.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(listener != null) {
|
||||
listener.colorChanged(color);
|
||||
}
|
||||
history.selectColor(color);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
content = (ColorSelectorView)findViewById(R.id.content);
|
||||
content.setDialog(this);
|
||||
content.setOnColorChangedListener(new ColorSelectorView.OnColorChangedListener() {
|
||||
@Override
|
||||
public void colorChanged(int color) {
|
||||
colorChangedInternal(color);
|
||||
}
|
||||
});
|
||||
|
||||
history = (HistorySelectorView) findViewById(R.id.historyselector);
|
||||
history.setOnColorChangedListener(new HistorySelectorView.OnColorChangedListener() {
|
||||
@Override
|
||||
public void colorChanged(int color) {
|
||||
colorChangedInternal(color);
|
||||
content.setColor(color);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
btnOld.setBackgroundColor(initColor);
|
||||
btnOld.setTextColor(~initColor | 0xFF000000);
|
||||
|
||||
content.setColor(initColor);
|
||||
}
|
||||
|
||||
private void colorChangedInternal(int color)
|
||||
{
|
||||
btnNew.setBackgroundColor(color);
|
||||
btnNew.setTextColor(~color | 0xFF000000); //without alpha
|
||||
color = adjustAlpha(color,this.alpha);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private int adjustAlpha(int color, boolean b) {
|
||||
int alpha = (b) ? Color.alpha(color) : 0xff;
|
||||
int red = Color.red(color);
|
||||
int green = Color.green(color);
|
||||
int blue = Color.blue(color);
|
||||
return Color.argb(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
public void setColor(int color)
|
||||
{
|
||||
content.setColor(color);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
|
||||
if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
|
||||
System.out.println("TOuch outside the dialog ******************** ");
|
||||
this.dismiss();
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public void setOnColorChangedListener(OnColorChangedListener mlistener){
|
||||
listener = mlistener;
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.button_new) {
|
||||
if (listener != null) {
|
||||
listener.onColorChanged(color);
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
}*/
|
||||
|
||||
public void onClick(View v) {
|
||||
if(listener != null) {
|
||||
listener.colorChanged(color);
|
||||
}
|
||||
history.selectColor(color);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorChanged(int color) {
|
||||
if(listener != null)
|
||||
listener.colorChanged(getColor());
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.TabContentFactory;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class ColorSelectorView extends LinearLayout {
|
||||
private static final String HSV_TAG = "HSV";
|
||||
private static final String RGB_TAG = "RGB";
|
||||
private static final String HEX_TAG = "HEX";
|
||||
|
||||
private org.telegram.ui.Components.RgbSelectorView rgbSelector;
|
||||
private org.telegram.ui.Components.HsvSelectorView hsvSelector;
|
||||
private org.telegram.ui.Components.HexSelectorView hexSelector;
|
||||
private TabHost tabs;
|
||||
|
||||
private int maxHeight = 0;
|
||||
private int maxWidth = 0;
|
||||
|
||||
private int color;
|
||||
|
||||
private OnColorChangedListener listener;
|
||||
|
||||
public ColorSelectorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public ColorSelectorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
setColor(color, null);
|
||||
}
|
||||
|
||||
public void setDialog(Dialog d) {
|
||||
hexSelector.setDialog(d);
|
||||
}
|
||||
|
||||
private void setColor(int color, View sender) {
|
||||
if (this.color == color)
|
||||
return;
|
||||
this.color = color;
|
||||
if (sender != hsvSelector)
|
||||
hsvSelector.setColor(color);
|
||||
if (sender != rgbSelector)
|
||||
rgbSelector.setColor(color);
|
||||
if (sender != hexSelector)
|
||||
hexSelector.setColor(color);
|
||||
onColorChanged();
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View contentView = inflater.inflate(R.layout.color_colorselectview,
|
||||
null);
|
||||
|
||||
addView(contentView, new LayoutParams(LayoutParams.FILL_PARENT,
|
||||
LayoutParams.FILL_PARENT));
|
||||
|
||||
hsvSelector = new HsvSelectorView(getContext());
|
||||
hsvSelector.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
|
||||
LayoutParams.FILL_PARENT));
|
||||
hsvSelector
|
||||
.setOnColorChangedListener(new HsvSelectorView.OnColorChangedListener() {
|
||||
@Override
|
||||
public void colorChanged(int color) {
|
||||
setColor(color);
|
||||
}
|
||||
});
|
||||
rgbSelector = new RgbSelectorView(getContext());
|
||||
rgbSelector.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
|
||||
LayoutParams.FILL_PARENT));
|
||||
rgbSelector
|
||||
.setOnColorChangedListener(new RgbSelectorView.OnColorChangedListener() {
|
||||
@Override
|
||||
public void colorChanged(int color) {
|
||||
setColor(color);
|
||||
}
|
||||
});
|
||||
hexSelector = new HexSelectorView(getContext());
|
||||
hexSelector.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
|
||||
LayoutParams.FILL_PARENT));
|
||||
hexSelector
|
||||
.setOnColorChangedListener(new HexSelectorView.OnColorChangedListener() {
|
||||
@Override
|
||||
public void colorChanged(int color) {
|
||||
setColor(color);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
tabs = (TabHost) contentView
|
||||
.findViewById(R.id.colorview_tabColors);
|
||||
//tabs.getTabWidget().setDividerDrawable(new ColorDrawable(0xBDBDBD));
|
||||
|
||||
tabs.setup();
|
||||
ColorTabContentFactory factory = new ColorTabContentFactory();
|
||||
//TabSpec hsvTab = tabs.newTabSpec(HSV_TAG).setIndicator("HSV", getContext().getResources().getDrawable(R.drawable.hsv32))
|
||||
// .setContent(factory);
|
||||
//View tabview = createTabView(tabs.getContext(), HEX_TAG);
|
||||
TabSpec hsvTab = tabs.newTabSpec(HSV_TAG).setIndicator(createTabView(tabs.getContext(), HSV_TAG))
|
||||
.setContent(factory);
|
||||
//TabSpec rgbTab = tabs.newTabSpec(RGB_TAG).setIndicator("RGB", getContext().getResources().getDrawable(R.drawable.rgb32))
|
||||
// .setContent(factory);
|
||||
TabSpec rgbTab = tabs.newTabSpec(RGB_TAG).setIndicator(createTabView(tabs.getContext(), RGB_TAG))
|
||||
.setContent(factory);
|
||||
//TabSpec hexTab = tabs.newTabSpec(HEX_TAG).setIndicator("HEX", getContext().getResources().getDrawable(R.drawable.hex32))
|
||||
//.setContent(factory);
|
||||
|
||||
TabSpec hexTab = tabs.newTabSpec(HEX_TAG).setIndicator(createTabView(tabs.getContext(), HEX_TAG))
|
||||
.setContent(factory);
|
||||
tabs.addTab(hsvTab);
|
||||
tabs.addTab(rgbTab);
|
||||
tabs.addTab(hexTab);
|
||||
}
|
||||
|
||||
private static View createTabView(final Context context, final String text) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
|
||||
TextView tv = (TextView) view.findViewById(R.id.tabsText);
|
||||
tv.setText(text);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
class ColorTabContentFactory implements TabContentFactory {
|
||||
@Override
|
||||
public View createTabContent(String tag) {
|
||||
if (HSV_TAG.equals(tag)) {
|
||||
return hsvSelector;
|
||||
}
|
||||
if (RGB_TAG.equals(tag)) {
|
||||
return rgbSelector;
|
||||
}
|
||||
if (HEX_TAG.equals(tag)) {
|
||||
return hexSelector;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void onColorChanged()
|
||||
{
|
||||
if(listener != null)
|
||||
listener.colorChanged(getColor());
|
||||
}
|
||||
|
||||
public void setOnColorChangedListener(OnColorChangedListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public interface OnColorChangedListener
|
||||
{
|
||||
public void colorChanged(int color);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
if(HSV_TAG.equals(tabs.getCurrentTabTag()))
|
||||
{
|
||||
maxHeight = getMeasuredHeight();
|
||||
maxWidth = getMeasuredWidth();
|
||||
}
|
||||
setMeasuredDimension(maxWidth, maxHeight);
|
||||
}
|
||||
}
|
@ -158,6 +158,13 @@ public class EmojiView extends LinearLayout {
|
||||
if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
|
||||
pager.setCurrentItem(1);
|
||||
}
|
||||
|
||||
updateColors(tabs);
|
||||
}
|
||||
|
||||
private void updateColors(PagerSlidingTabStrip tabs) {
|
||||
setBackgroundColor(AndroidUtilities.getIntDef("chatEmojiViewBGColor",0xff222222));
|
||||
tabs.setIndicatorColor(AndroidUtilities.getIntDef("chatEmojiViewTabColor",AndroidUtilities.getIntDarkerColor("themeColor",0x15)));//0xff33b5e5
|
||||
}
|
||||
|
||||
private void saveRecents() {
|
||||
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 2.x
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2015.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.telegram.messenger.FileLog;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class ForegroundDetector implements Application.ActivityLifecycleCallbacks {
|
||||
|
||||
public interface Listener {
|
||||
public void onBecameForeground();
|
||||
public void onBecameBackground();
|
||||
}
|
||||
|
||||
private int refs;
|
||||
private boolean wasInBackground = true;
|
||||
private long enterBackgroundTime = 0;
|
||||
private CopyOnWriteArrayList<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||
private static ForegroundDetector Instance = null;
|
||||
|
||||
public static ForegroundDetector getInstance() {
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public ForegroundDetector(Application application) {
|
||||
Instance = this;
|
||||
application.registerActivityLifecycleCallbacks(this);
|
||||
}
|
||||
|
||||
public boolean isForeground() {
|
||||
return refs > 0;
|
||||
}
|
||||
|
||||
public boolean isBackground() {
|
||||
return refs == 0;
|
||||
}
|
||||
|
||||
public void addListener(Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(Listener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWasInBackground(boolean reset) {
|
||||
if (reset && Build.VERSION.SDK_INT >= 21 && (System.currentTimeMillis() - enterBackgroundTime < 200)) {
|
||||
wasInBackground = false;
|
||||
}
|
||||
return wasInBackground;
|
||||
}
|
||||
|
||||
public void resetBackgroundVar() {
|
||||
wasInBackground = false;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
}
|
||||
}
|
@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class HexSelectorView extends LinearLayout {
|
||||
|
||||
private EditText edit;
|
||||
private int color;
|
||||
private TextView txtError;
|
||||
private Button btnSave;
|
||||
private Dialog dialog;
|
||||
|
||||
private OnColorChangedListener listener;
|
||||
|
||||
public HexSelectorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HexSelectorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
public void setDialog(Dialog d) {
|
||||
this.dialog = d;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View content = inflater.inflate(R.layout.color_hexview, null);
|
||||
addView(content, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
||||
|
||||
txtError = (TextView)content.findViewById(R.id.color_hex_txtError);
|
||||
|
||||
edit = (EditText)content.findViewById(R.id.color_hex_edit);
|
||||
edit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
if (dialog != null) dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
edit.setOnKeyListener(new OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
Log.d("HexSelector", "onKey: keyCode" + keyCode + " event: " + event);
|
||||
validateColorInTextView();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
edit.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {
|
||||
}
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
validateColorInTextView();
|
||||
}
|
||||
});
|
||||
edit.setOnEditorActionListener(new OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
|
||||
validateColorInTextView();
|
||||
InputMethodManager in = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
in.hideSoftInputFromWindow(edit.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
btnSave = (Button)content.findViewById(R.id.color_hex_btnSave);
|
||||
btnSave.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
validateColorInTextView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void validateColorInTextView() {
|
||||
try
|
||||
{
|
||||
String hex = edit.getText().toString().toUpperCase().trim();
|
||||
Log.d("HexSelector", "String parsing: " + hex);
|
||||
// String prefix = "";
|
||||
if(hex.startsWith("0x"))
|
||||
{
|
||||
hex = hex.substring(2);
|
||||
// prefix = "0x";
|
||||
}
|
||||
if(hex.startsWith("#"))
|
||||
{
|
||||
hex = hex.substring(1);
|
||||
// prefix = "#";
|
||||
}
|
||||
/*
|
||||
if(hex.length() == 6)
|
||||
{
|
||||
hex = "FF" + hex;
|
||||
}*/
|
||||
if(hex.length() != 8)
|
||||
throw new Exception();
|
||||
color = (int) Long.parseLong(hex, 16);
|
||||
txtError.setVisibility(GONE);
|
||||
onColorChanged();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.d("HexSelector", "String parsing died");
|
||||
e.printStackTrace();
|
||||
txtError.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(int color)
|
||||
{
|
||||
if(color == this.color)return;
|
||||
this.color = color;
|
||||
//if (!edit.hasFocus()) {
|
||||
edit.setText(padLeft(Integer.toHexString(color).toUpperCase(), '0', 8));
|
||||
//}
|
||||
txtError.setVisibility(GONE);
|
||||
}
|
||||
|
||||
private String padLeft(String string, char padChar, int size)
|
||||
{
|
||||
if(string.length() >= size)
|
||||
return string;
|
||||
StringBuilder result = new StringBuilder();
|
||||
for(int i=string.length(); i<size; i++)
|
||||
result.append(padChar);
|
||||
result.append(string);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private void onColorChanged()
|
||||
{
|
||||
Log.d("HexSelector", "String parsing succeeded. changing to " + color);
|
||||
if(listener != null)
|
||||
listener.colorChanged(getColor());
|
||||
}
|
||||
|
||||
public void setOnColorChangedListener(OnColorChangedListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public interface OnColorChangedListener
|
||||
{
|
||||
public void colorChanged(int color);
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class HistorySelectorView extends LinearLayout {
|
||||
private static final String PREFS_NAME = "RECENT_COLORS";
|
||||
private static final String HISTORY = "HISTORY";
|
||||
|
||||
private static final int MAX_COLORS = 30;
|
||||
|
||||
JSONArray colors;
|
||||
OnColorChangedListener listener;
|
||||
int color;
|
||||
|
||||
public HistorySelectorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HistorySelectorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View content = inflater.inflate(R.layout.color_historyview, null);
|
||||
addView(content, new LayoutParams(LayoutParams.FILL_PARENT , LayoutParams.FILL_PARENT));
|
||||
|
||||
readColors();
|
||||
|
||||
makeColorList();
|
||||
}
|
||||
|
||||
private void makeColorList() {
|
||||
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
LinearLayout colorlist = (LinearLayout)findViewById(R.id.colorlist);
|
||||
|
||||
if (colors == null || colors.length() <= 0) {
|
||||
View nocolors = findViewById(R.id.nocolors);
|
||||
nocolors.setVisibility(View.VISIBLE);
|
||||
colorlist.setVisibility(View.GONE);
|
||||
findViewById(R.id.colorlistscroll).setVisibility(View.GONE); //have to remove it's parent container too
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (int i=colors.length()-1; i>=0; i--) {
|
||||
final int color = colors.getInt(i);
|
||||
ViewGroup boxgroup = (ViewGroup)inflater.inflate(R.layout.color_historyview_item, colorlist, false);
|
||||
TextView box = (TextView)boxgroup.findViewById(R.id.colorbox);
|
||||
box.setBackgroundColor(color);
|
||||
//box.setText("#"+Integer.toHexString(color));
|
||||
colorlist.addView(boxgroup );
|
||||
box.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
setColor(color);
|
||||
onColorChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void readColors() {
|
||||
SharedPreferences prefs = getContext().getSharedPreferences(PREFS_NAME, 0);
|
||||
try {
|
||||
colors = new JSONArray(prefs.getString(HISTORY, ""));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void selectColor(int color) {
|
||||
try {
|
||||
SharedPreferences prefs = getContext().getSharedPreferences(PREFS_NAME, 0);
|
||||
if (colors == null) colors = new JSONArray();
|
||||
boolean dontadd = false;
|
||||
for (int i=0; i < colors.length(); i++) {
|
||||
if (colors.getInt(i) == color) { //reusing a recent color! shit.
|
||||
dontadd = true;
|
||||
colors = moveValueToFront(colors, i, color);
|
||||
}
|
||||
}
|
||||
if (!dontadd) colors.put(color);
|
||||
if (colors.length() > MAX_COLORS) {
|
||||
JSONArray newcolors = new JSONArray();
|
||||
for (int i=colors.length()-MAX_COLORS; i < colors.length(); i++) {
|
||||
newcolors.put(colors.getInt(i));
|
||||
}
|
||||
colors = newcolors;
|
||||
}
|
||||
Editor edit = prefs.edit();
|
||||
edit.putString(HISTORY, colors.toString());
|
||||
edit.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public JSONArray moveValueToFront(JSONArray array, int index, int color) throws JSONException {
|
||||
LinkedList<Integer> list = new LinkedList<Integer>();
|
||||
for (int i=0; i < array.length(); i++) {
|
||||
list.add(array.getInt(i));
|
||||
}
|
||||
|
||||
list.add(color);
|
||||
list.remove(index);
|
||||
|
||||
array = new JSONArray();
|
||||
for (int i : list) {
|
||||
array.put(i);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
private void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
private void onColorChanged()
|
||||
{
|
||||
if(listener != null)
|
||||
listener.colorChanged(getColor());
|
||||
}
|
||||
|
||||
public void setOnColorChangedListener(OnColorChangedListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public interface OnColorChangedListener
|
||||
{
|
||||
public void colorChanged(int color);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.Shader.TileMode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class HsvAlphaSelectorView extends LinearLayout {
|
||||
|
||||
private Drawable seekSelector;
|
||||
private ImageView imgSeekSelector;
|
||||
private int minOffset = 0;
|
||||
private ImageView imgAlpha;
|
||||
|
||||
private int alpha = 0;
|
||||
private int color = Color.WHITE;
|
||||
|
||||
private boolean dirty = true;
|
||||
|
||||
private OnAlphaChangedListener listener;
|
||||
|
||||
public HsvAlphaSelectorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HsvAlphaSelectorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setMinContentOffset(int minOffset) {
|
||||
this.minOffset = minOffset;
|
||||
LayoutParams params = new LayoutParams(imgAlpha.getLayoutParams());
|
||||
params.setMargins(0, getOffset(), 0, getSelectorOffset());
|
||||
imgAlpha.setLayoutParams(params);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
seekSelector = getContext().getResources().getDrawable(
|
||||
R.drawable.color_seekselector);
|
||||
buildUI();
|
||||
}
|
||||
|
||||
private void buildUI() {
|
||||
setOrientation(LinearLayout.HORIZONTAL);
|
||||
setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
setWillNotDraw(false);
|
||||
|
||||
imgSeekSelector = new ImageView(getContext());
|
||||
imgSeekSelector.setImageDrawable(seekSelector);
|
||||
LayoutParams paramsSeek = new LayoutParams(seekSelector
|
||||
.getIntrinsicWidth(), seekSelector.getIntrinsicHeight());
|
||||
addView(imgSeekSelector, paramsSeek);
|
||||
|
||||
imgAlpha = new ImageView(getContext());
|
||||
imgAlpha.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.transparentbackrepeat));
|
||||
imgAlpha.setScaleType(ScaleType.FIT_XY);
|
||||
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
|
||||
LayoutParams.FILL_PARENT);
|
||||
params.setMargins(0, getOffset(), 0, getSelectorOffset());
|
||||
addView(imgAlpha, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if(dirty)
|
||||
{
|
||||
dirty = false;
|
||||
setAlphaImage();
|
||||
}
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
super.onLayout(changed, l, t, r, b);
|
||||
placeSelector();
|
||||
}
|
||||
|
||||
private void placeSelector()
|
||||
{
|
||||
int alphaY = (int)(((float)(255 - alpha) / 255.f) * imgAlpha.getHeight());
|
||||
|
||||
int halfHeight = getSelectorOffset();
|
||||
int vertOffset = imgAlpha.getTop();
|
||||
|
||||
imgSeekSelector.layout(0, alphaY + vertOffset - halfHeight, imgSeekSelector.getWidth(), alphaY + vertOffset - halfHeight + imgSeekSelector.getHeight());
|
||||
}
|
||||
|
||||
private int getSelectorOffset()
|
||||
{
|
||||
return (int) Math.ceil(imgSeekSelector.getHeight() / 2.f);
|
||||
}
|
||||
|
||||
private int getOffset() {
|
||||
return Math.max(minOffset, (int) Math.ceil((double) seekSelector
|
||||
.getIntrinsicHeight() / 2));
|
||||
}
|
||||
|
||||
private boolean down = false;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if(event.getAction() == MotionEvent.ACTION_DOWN)
|
||||
{
|
||||
down = true;
|
||||
setPosition((int)event.getY());
|
||||
return true;
|
||||
}
|
||||
if(event.getAction() == MotionEvent.ACTION_UP)
|
||||
{
|
||||
down = false;
|
||||
return true;
|
||||
}
|
||||
if(down && event.getAction() == MotionEvent.ACTION_MOVE)
|
||||
{
|
||||
setPosition((int)event.getY());
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void setPosition(int y)
|
||||
{
|
||||
int alphaY = y - imgAlpha.getTop();
|
||||
alpha = 255 - Math.min(255, Math.max(0, (int) (((float) alphaY / imgAlpha.getHeight()) * 255.f)));
|
||||
|
||||
placeSelector();
|
||||
|
||||
onAlphaChanged();
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha)
|
||||
{
|
||||
if(this.alpha == alpha)
|
||||
return;
|
||||
this.alpha = alpha;
|
||||
placeSelector();
|
||||
}
|
||||
|
||||
public float getAlpha()
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public void setColor(int color)
|
||||
{
|
||||
if(this.color == color)
|
||||
return;
|
||||
this.color = color;
|
||||
setAlphaImage();
|
||||
}
|
||||
|
||||
private void setAlphaImage()
|
||||
{
|
||||
if(imgAlpha.getHeight() <= 0)
|
||||
{
|
||||
dirty = true;
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
Paint paint = new Paint();
|
||||
Shader shader;
|
||||
Bitmap drawCache = null;
|
||||
if (drawCache == null) {
|
||||
|
||||
int colorFullAlpha = color | 0xFF000000;
|
||||
int colorNoAlpha = color & 0x00FFFFFF;
|
||||
|
||||
shader = new LinearGradient(0, imgAlpha.getHeight(), 0, 0,
|
||||
colorNoAlpha, colorFullAlpha, TileMode.CLAMP);
|
||||
|
||||
paint.setShader(shader);
|
||||
|
||||
drawCache = Bitmap.createBitmap(imgAlpha.getWidth(), imgAlpha.getHeight(),
|
||||
Bitmap.Config.ARGB_8888);
|
||||
Canvas cacheCanvas = new Canvas(drawCache);
|
||||
cacheCanvas.drawRect(0.f, 0.f, imgAlpha.getWidth(), imgAlpha.getHeight(),
|
||||
paint);
|
||||
|
||||
imgAlpha.setImageBitmap(drawCache);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnAlphaChangedListener(OnAlphaChangedListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private void onAlphaChanged()
|
||||
{
|
||||
if(listener != null)
|
||||
listener.alphaChanged(this, alpha);
|
||||
}
|
||||
|
||||
public interface OnAlphaChangedListener
|
||||
{
|
||||
public void alphaChanged(HsvAlphaSelectorView sender, int alpha);
|
||||
}
|
||||
}
|
@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ComposeShader;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.Shader.TileMode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class HsvColorValueView extends FrameLayout {
|
||||
private Paint paint;
|
||||
private Shader outerShader;
|
||||
private Shader innerShader;
|
||||
private float hue = 0;
|
||||
|
||||
private Bitmap drawCache = null;
|
||||
private Drawable colorSelector;
|
||||
private ImageView selectorView;
|
||||
|
||||
private int lastMeasuredSize = -1;
|
||||
|
||||
private float saturation = 0;
|
||||
private float value = 1;
|
||||
|
||||
private OnSaturationOrValueChanged listener;
|
||||
|
||||
public HsvColorValueView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HsvColorValueView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public HsvColorValueView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
colorSelector = getContext().getResources().getDrawable(
|
||||
R.drawable.color_selector);
|
||||
selectorView = new ImageView(getContext());
|
||||
selectorView.setImageDrawable(colorSelector);
|
||||
addView(selectorView, new LayoutParams(colorSelector.getIntrinsicWidth(), colorSelector.getIntrinsicHeight()));
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
lastMeasuredSize = Math.min(getMeasuredHeight(), getMeasuredWidth());
|
||||
setMeasuredDimension(lastMeasuredSize, lastMeasuredSize);
|
||||
if (drawCache != null
|
||||
&& drawCache.getHeight() != getBackgroundSize(lastMeasuredSize))
|
||||
{
|
||||
drawCache.recycle();
|
||||
drawCache = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getBackgroundOffset() {
|
||||
return (int) Math
|
||||
.ceil((double) (colorSelector.getIntrinsicHeight() / 2.f));
|
||||
}
|
||||
|
||||
private int getBackgroundSize(int availableSize) {
|
||||
int offset = getBackgroundOffset();
|
||||
return availableSize - 2 * offset;
|
||||
}
|
||||
|
||||
public int getBackgroundSize()
|
||||
{
|
||||
ensureCache();
|
||||
if (drawCache != null) return drawCache.getHeight();
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void ensureCache()
|
||||
{
|
||||
if (paint == null) {
|
||||
paint = new Paint();
|
||||
}
|
||||
int baseSize = getHeight();
|
||||
if(baseSize <= 0)
|
||||
baseSize = getMeasuredHeight();
|
||||
if(baseSize <= 0)
|
||||
baseSize = lastMeasuredSize;
|
||||
int backgroundSize = getBackgroundSize(baseSize);
|
||||
if (drawCache == null && backgroundSize > 0) {
|
||||
outerShader = new LinearGradient(0.f, 0.f, 0.f, backgroundSize,
|
||||
0xffffffff, 0xff000000, TileMode.CLAMP);
|
||||
|
||||
float[] tmp00 = new float[3];
|
||||
tmp00[1] = tmp00[2] = 1.f;
|
||||
tmp00[0] = hue;
|
||||
int rgb = Color.HSVToColor(tmp00);
|
||||
|
||||
innerShader = new LinearGradient(0.f, 0.f, backgroundSize, 0.f,
|
||||
0xffffffff, rgb, TileMode.CLAMP);
|
||||
ComposeShader shader = new ComposeShader(outerShader, innerShader,
|
||||
PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
paint.setShader(shader);
|
||||
|
||||
drawCache = Bitmap.createBitmap(backgroundSize, backgroundSize,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
Canvas cacheCanvas = new Canvas(drawCache);
|
||||
cacheCanvas.drawRect(0.f, 0.f, backgroundSize, backgroundSize,
|
||||
paint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
ensureCache();
|
||||
canvas.drawBitmap(drawCache, getBackgroundOffset(), getBackgroundOffset(), paint);
|
||||
}
|
||||
|
||||
private boolean down = false;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if(event.getAction() == MotionEvent.ACTION_DOWN)
|
||||
{
|
||||
down = true;
|
||||
return true;
|
||||
}
|
||||
if(event.getAction() == MotionEvent.ACTION_UP)
|
||||
{
|
||||
down = false;
|
||||
setSelectorPosition((int)event.getX() - getBackgroundOffset(), (int)event.getY() - getBackgroundOffset(), true);
|
||||
return true;
|
||||
}
|
||||
if(event.getAction() == MotionEvent.ACTION_MOVE && down)
|
||||
{
|
||||
setSelectorPosition((int)event.getX() - getBackgroundOffset(), (int)event.getY() - getBackgroundOffset(), false);
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void setSatAndValueFromPos(int x, int y, boolean up)
|
||||
{
|
||||
int offset = getBackgroundOffset();
|
||||
|
||||
saturation = ((x - offset) / (float)getBackgroundSize());
|
||||
value = 1.f - ((y - offset) / (float)getBackgroundSize());
|
||||
|
||||
onSaturationOrValueChanged(up);
|
||||
}
|
||||
|
||||
private void setSelectorPosition(int x, int y, boolean up)
|
||||
{
|
||||
setSatAndValueFromPos(x, y, up);
|
||||
placeSelector();
|
||||
}
|
||||
|
||||
private void placeSelector()
|
||||
{
|
||||
int offset = getBackgroundOffset();
|
||||
int halfSize = (int) Math.ceil(selectorView.getHeight() / 2.f);
|
||||
|
||||
int x = (int)(getBackgroundSize() * saturation);
|
||||
int y = (int)(getBackgroundSize() * (1.f - value));
|
||||
|
||||
int left = Math.max(0, Math.min(getBackgroundSize(), x)) + offset - halfSize;
|
||||
int top = Math.max(0, Math.min(getBackgroundSize(), y)) + offset - halfSize;
|
||||
|
||||
selectorView.layout(left, top, left + selectorView.getWidth(), top + selectorView.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right,
|
||||
int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
placeSelector();
|
||||
}
|
||||
|
||||
private void setPosFromSatAndValue()
|
||||
{
|
||||
if(drawCache != null)
|
||||
placeSelector();
|
||||
}
|
||||
|
||||
public void setHue(float hue) {
|
||||
this.hue = hue;
|
||||
drawCache = null;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setSaturation(float sat)
|
||||
{
|
||||
saturation = sat;
|
||||
setPosFromSatAndValue();
|
||||
}
|
||||
|
||||
public float getSaturation()
|
||||
{
|
||||
return saturation;
|
||||
}
|
||||
|
||||
public void setValue(float value)
|
||||
{
|
||||
this.value = value;
|
||||
setPosFromSatAndValue();
|
||||
}
|
||||
|
||||
public float getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setOnSaturationOrValueChanged(OnSaturationOrValueChanged listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private void onSaturationOrValueChanged(boolean up)
|
||||
{
|
||||
if(listener != null)
|
||||
listener.saturationOrValueChanged(this, saturation, value, up);
|
||||
}
|
||||
|
||||
public interface OnSaturationOrValueChanged
|
||||
{
|
||||
public void saturationOrValueChanged(HsvColorValueView sender, float saturation, float value, boolean up);
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class HsvHueSelectorView extends LinearLayout {
|
||||
|
||||
private Drawable seekSelector;
|
||||
private ImageView imgSeekSelector;
|
||||
private int minOffset = 0;
|
||||
private ImageView imgHue;
|
||||
|
||||
private float hue = 0;
|
||||
|
||||
private OnHueChangedListener listener;
|
||||
|
||||
public HsvHueSelectorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HsvHueSelectorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setMinContentOffset(int minOffset) {
|
||||
this.minOffset = minOffset;
|
||||
LayoutParams params = new LayoutParams(imgHue.getLayoutParams());
|
||||
params.setMargins(0, getOffset(), 0, getSelectorOffset());
|
||||
imgHue.setLayoutParams(params);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
seekSelector = getContext().getResources().getDrawable(
|
||||
R.drawable.color_seekselector);
|
||||
buildUI();
|
||||
}
|
||||
|
||||
private void buildUI() {
|
||||
setOrientation(LinearLayout.HORIZONTAL);
|
||||
setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
|
||||
imgSeekSelector = new ImageView(getContext());
|
||||
imgSeekSelector.setImageDrawable(seekSelector);
|
||||
LayoutParams paramsSeek = new LayoutParams(seekSelector
|
||||
.getIntrinsicWidth(), seekSelector.getIntrinsicHeight());
|
||||
addView(imgSeekSelector, paramsSeek);
|
||||
|
||||
imgHue = new ImageView(getContext());
|
||||
imgHue.setImageDrawable(getContext().getResources().getDrawable(
|
||||
R.drawable.color_hue));
|
||||
imgHue.setScaleType(ScaleType.FIT_XY);
|
||||
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
|
||||
LayoutParams.FILL_PARENT);
|
||||
params.setMargins(0, getOffset(), 0, getSelectorOffset());
|
||||
addView(imgHue, params);
|
||||
|
||||
}
|
||||
|
||||
private int getOffset() {
|
||||
return Math.max(minOffset, getSelectorOffset());
|
||||
}
|
||||
|
||||
private int getSelectorOffset() {
|
||||
return (int) Math.ceil(seekSelector.getIntrinsicHeight() / 2.f);
|
||||
}
|
||||
|
||||
private boolean down = false;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
down = true;
|
||||
setPosition((int) event.getY());
|
||||
return true;
|
||||
}
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
down = false;
|
||||
return true;
|
||||
}
|
||||
if (down && event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
setPosition((int) event.getY());
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void setPosition(int y) {
|
||||
int hueY = y - getOffset();
|
||||
|
||||
hue = Math.max(Math.min(
|
||||
360.f - (((float) hueY / imgHue.getHeight()) * 360.f), 360.f),
|
||||
0.f);
|
||||
|
||||
placeSelector();
|
||||
|
||||
onHueChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
super.onLayout(changed, l, t, r, b);
|
||||
placeSelector();
|
||||
}
|
||||
|
||||
private void placeSelector() {
|
||||
int hueY = (int) ((((360.f - hue) / 360.f)) * imgHue.getHeight());
|
||||
imgSeekSelector.layout(0, hueY + getOffset() - getSelectorOffset(), imgSeekSelector
|
||||
.getWidth(), hueY + getOffset() - getSelectorOffset() + imgSeekSelector.getHeight());
|
||||
}
|
||||
|
||||
public void setHue(float hue) {
|
||||
if(this.hue == hue)
|
||||
return;
|
||||
this.hue = hue;
|
||||
placeSelector();
|
||||
}
|
||||
|
||||
public float getHue() {
|
||||
return hue;
|
||||
}
|
||||
|
||||
public void setOnHueChangedListener(OnHueChangedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private void onHueChanged() {
|
||||
if (listener != null)
|
||||
listener.hueChanged(this, hue);
|
||||
}
|
||||
|
||||
public interface OnHueChangedListener {
|
||||
public void hueChanged(HsvHueSelectorView sender, float hue);
|
||||
}
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Devmil (Michael Lamers)
|
||||
* Mail: develmil@googlemail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class HsvSelectorView extends LinearLayout {
|
||||
|
||||
private HsvAlphaSelectorView alphaSelector;
|
||||
private HsvHueSelectorView hueSelector;
|
||||
private HsvColorValueView hsvColorValueView;
|
||||
|
||||
private int color;
|
||||
|
||||
private OnColorChangedListener listener;
|
||||
|
||||
public HsvSelectorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HsvSelectorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
buildUI();
|
||||
}
|
||||
|
||||
private void buildUI() {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View hsvView = inflater.inflate(R.layout.color_hsvview, null);
|
||||
this.addView(hsvView, new LayoutParams(LayoutParams.FILL_PARENT,
|
||||
LayoutParams.FILL_PARENT));
|
||||
|
||||
alphaSelector = (HsvAlphaSelectorView) hsvView
|
||||
.findViewById(R.id.color_hsv_alpha);
|
||||
hsvColorValueView = (HsvColorValueView) hsvView
|
||||
.findViewById(R.id.color_hsv_value);
|
||||
hueSelector = (HsvHueSelectorView) hsvView.findViewById(R.id.color_hsv_hue);
|
||||
|
||||
alphaSelector.setOnAlphaChangedListener(new HsvAlphaSelectorView.OnAlphaChangedListener() {
|
||||
@Override
|
||||
public void alphaChanged(HsvAlphaSelectorView sender, int alpha) {
|
||||
internalSetColor(getCurrentColor(true), true);
|
||||
}
|
||||
});
|
||||
|
||||
hsvColorValueView.setOnSaturationOrValueChanged(new HsvColorValueView.OnSaturationOrValueChanged() {
|
||||
@Override
|
||||
public void saturationOrValueChanged(HsvColorValueView sender,
|
||||
float saturation, float value, boolean up) {
|
||||
alphaSelector.setColor(getCurrentColor(false));
|
||||
internalSetColor(getCurrentColor(true), up);
|
||||
}
|
||||
});
|
||||
hueSelector.setOnHueChangedListener(new HsvHueSelectorView.OnHueChangedListener() {
|
||||
@Override
|
||||
public void hueChanged(HsvHueSelectorView sender, float hue) {
|
||||
hsvColorValueView.setHue(hue);
|
||||
alphaSelector.setColor(getCurrentColor(false));
|
||||
internalSetColor(getCurrentColor(true), true);
|
||||
}
|
||||
});
|
||||
|
||||
setColor(Color.BLACK);
|
||||
}
|
||||
|
||||
private int getCurrentColor(boolean includeAlpha)
|
||||
{
|
||||
float[] hsv = new float[3];
|
||||
hsv[0] = hueSelector.getHue();
|
||||
hsv[1] = hsvColorValueView.getSaturation();
|
||||
hsv[2] = hsvColorValueView.getValue();
|
||||
int alpha = includeAlpha ? (int)alphaSelector.getAlpha() : 255;
|
||||
return Color.HSVToColor(alpha, hsv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
LayoutParams paramsAlpha = new LayoutParams(alphaSelector.getLayoutParams());
|
||||
LayoutParams paramsHue = new LayoutParams(hueSelector.getLayoutParams());
|
||||
|
||||
paramsAlpha.height = hsvColorValueView.getHeight();
|
||||
paramsHue.height = hsvColorValueView.getHeight();
|
||||
|
||||
hueSelector.setMinContentOffset(hsvColorValueView.getBackgroundOffset());
|
||||
alphaSelector.setMinContentOffset(hsvColorValueView.getBackgroundOffset());
|
||||
|
||||
alphaSelector.setLayoutParams(paramsAlpha);
|
||||
hueSelector.setLayoutParams(paramsHue);
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
private void internalSetColor(int color, boolean fire)
|
||||
{
|
||||
this.color = color;
|
||||
if(fire)
|
||||
onColorChanged();
|
||||
}
|
||||
|
||||
public void setColor(int color)
|
||||
{
|
||||
int alpha = Color.alpha(color);
|
||||
alphaSelector.setAlpha(alpha);
|
||||
int colorWithoutAlpha = color | 0xFF000000;
|
||||
float[] hsv = new float[3];
|
||||
Color.colorToHSV(colorWithoutAlpha, hsv);
|
||||
hueSelector.setHue(hsv[0]);
|
||||
hsvColorValueView.setHue(hsv[0]);
|
||||
hsvColorValueView.setSaturation(hsv[1]);
|
||||
hsvColorValueView.setValue(hsv[2]);
|
||||
alphaSelector.setColor(color);
|
||||
internalSetColor(color, this.color != color);
|
||||
}
|
||||
|
||||
private void onColorChanged()
|
||||
{
|
||||
if(listener != null)
|
||||
listener.colorChanged(color);
|
||||
}
|
||||
|
||||
public void setOnColorChangedListener(OnColorChangedListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public interface OnColorChangedListener
|
||||
{
|
||||
public void colorChanged(int color);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 1.7.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2014.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.LocaleController;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.ui.Adapters.BaseSectionsAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LetterSectionsListView extends ListView implements AbsListView.OnScrollListener {
|
||||
|
||||
private ArrayList<View> headers = new ArrayList<>();
|
||||
private ArrayList<View> headersCache = new ArrayList<>();
|
||||
private OnScrollListener mOnScrollListener;
|
||||
private BaseSectionsAdapter mAdapter;
|
||||
private int currentFirst = -1;
|
||||
private int currentVisible = -1;
|
||||
private int startSection;
|
||||
private int sectionsCount;
|
||||
|
||||
public LetterSectionsListView(Context context) {
|
||||
super(context);
|
||||
super.setOnScrollListener(this);
|
||||
}
|
||||
|
||||
public LetterSectionsListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
super.setOnScrollListener(this);
|
||||
}
|
||||
|
||||
public LetterSectionsListView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
super.setOnScrollListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdapter(ListAdapter adapter) {
|
||||
if (mAdapter == adapter) {
|
||||
return;
|
||||
}
|
||||
headers.clear();
|
||||
headersCache.clear();
|
||||
if (adapter instanceof BaseSectionsAdapter) {
|
||||
mAdapter = (BaseSectionsAdapter) adapter;
|
||||
} else {
|
||||
mAdapter = null;
|
||||
}
|
||||
super.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
if (mOnScrollListener != null) {
|
||||
mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
|
||||
}
|
||||
if (mAdapter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
headersCache.addAll(headers);
|
||||
headers.clear();
|
||||
|
||||
if (mAdapter.getCount() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentFirst != firstVisibleItem || currentVisible != visibleItemCount) {
|
||||
currentFirst = firstVisibleItem;
|
||||
currentVisible = visibleItemCount;
|
||||
|
||||
sectionsCount = 1;
|
||||
startSection = mAdapter.getSectionForPosition(firstVisibleItem);
|
||||
int itemNum = firstVisibleItem + mAdapter.getCountForSection(startSection) - mAdapter.getPositionInSectionForPosition(firstVisibleItem);
|
||||
while (true) {
|
||||
if (itemNum >= firstVisibleItem + visibleItemCount) {
|
||||
break;
|
||||
}
|
||||
itemNum += mAdapter.getCountForSection(startSection + sectionsCount);
|
||||
sectionsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
int itemNum = firstVisibleItem;
|
||||
for (int a = startSection; a < startSection + sectionsCount; a++) {
|
||||
View header = null;
|
||||
if (!headersCache.isEmpty()) {
|
||||
header = headersCache.get(0);
|
||||
headersCache.remove(0);
|
||||
}
|
||||
header = getSectionHeaderView(a, header);
|
||||
headers.add(header);
|
||||
int count = mAdapter.getCountForSection(a);
|
||||
if (a == startSection) {
|
||||
int pos = mAdapter.getPositionInSectionForPosition(itemNum);
|
||||
if (pos == count - 1) {
|
||||
header.setTag(-header.getHeight());
|
||||
} else if (pos == count - 2) {
|
||||
View child = getChildAt(itemNum - firstVisibleItem);
|
||||
int headerTop = 0;
|
||||
if (child != null) {
|
||||
headerTop = child.getTop();
|
||||
} else {
|
||||
headerTop = -AndroidUtilities.dp(100);
|
||||
}
|
||||
if (headerTop < 0) {
|
||||
header.setTag(headerTop);
|
||||
} else {
|
||||
header.setTag(0);
|
||||
}
|
||||
} else {
|
||||
header.setTag(0);
|
||||
}
|
||||
itemNum += count - mAdapter.getPositionInSectionForPosition(firstVisibleItem);
|
||||
} else {
|
||||
View child = getChildAt(itemNum - firstVisibleItem);
|
||||
if (child != null) {
|
||||
header.setTag(child.getTop());
|
||||
} else {
|
||||
header.setTag(-AndroidUtilities.dp(100));
|
||||
}
|
||||
itemNum += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
if (mOnScrollListener != null) {
|
||||
mOnScrollListener.onScrollStateChanged(view, scrollState);
|
||||
}
|
||||
}
|
||||
|
||||
private View getSectionHeaderView(int section, View oldView) {
|
||||
boolean shouldLayout = oldView == null;
|
||||
View view = mAdapter.getSectionHeaderView(section, oldView, this);
|
||||
if (shouldLayout) {
|
||||
ensurePinnedHeaderLayout(view, false);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
if (mAdapter == null || headers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (View header : headers) {
|
||||
ensurePinnedHeaderLayout(header, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensurePinnedHeaderLayout(View header, boolean forceLayout) {
|
||||
if (header.isLayoutRequested() || forceLayout) {
|
||||
ViewGroup.LayoutParams layoutParams = header.getLayoutParams();
|
||||
int heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
|
||||
int widthSpec = MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY);
|
||||
try {
|
||||
header.measure(widthSpec, heightSpec);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
if (mAdapter == null || headers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (View header : headers) {
|
||||
int saveCount = canvas.save();
|
||||
int top = (Integer)header.getTag();
|
||||
canvas.translate(LocaleController.isRTL ? getWidth() - header.getWidth() : 0, top);
|
||||
canvas.clipRect(0, 0, getWidth(), header.getMeasuredHeight());
|
||||
if (top < 0) {
|
||||
canvas.saveLayerAlpha(0, top, header.getWidth(), top + canvas.getHeight(), (int)(255 * (1.0f + (float)top / (float)header.getMeasuredHeight())), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
|
||||
}
|
||||
header.draw(canvas);
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnScrollListener(OnScrollListener l) {
|
||||
mOnScrollListener = l;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(LetterSectionsListView.OnItemClickListener listener) {
|
||||
super.setOnItemClickListener(listener);
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
@ -39,6 +40,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@ -73,7 +75,7 @@ public class NumberPicker extends LinearLayout {
|
||||
private OnScrollListener mOnScrollListener;
|
||||
private Formatter mFormatter;
|
||||
private long mLongPressUpdateInterval = DEFAULT_LONG_PRESS_UPDATE_INTERVAL;
|
||||
private final SparseArray<String> mSelectorIndexToStringCache = new SparseArray<String>();
|
||||
private final SparseArray<String> mSelectorIndexToStringCache = new SparseArray<>();
|
||||
private final int[] mSelectorIndices = new int[SELECTOR_WHEEL_ITEM_COUNT];
|
||||
private Paint mSelectorWheelPaint;
|
||||
private Drawable mVirtualButtonPressedDrawable;
|
||||
@ -123,7 +125,9 @@ public class NumberPicker extends LinearLayout {
|
||||
|
||||
private void init() {
|
||||
mSolidColor = 0;
|
||||
mSelectionDivider = getResources().getDrawable(R.drawable.numberpicker_selection_divider);
|
||||
//mSelectionDivider = getResources().getDrawable(R.drawable.numberpicker_selection_divider);
|
||||
mSelectionDivider = getResources().getDrawable(R.drawable.numberpicker_selection_divider_white);
|
||||
mSelectionDivider.setColorFilter(AndroidUtilities.getIntColor("themeColor"), PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
|
||||
mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,598 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 2.x
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2015.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.messenger.FileLog;
|
||||
|
||||
public class PhotoCropView extends FrameLayout {
|
||||
|
||||
public static interface PhotoCropViewDelegate {
|
||||
public abstract void needMoveImageTo(float x, float y, float s, boolean animated);
|
||||
}
|
||||
|
||||
private boolean freeformCrop = true;
|
||||
private Paint rectPaint;
|
||||
private Paint circlePaint;
|
||||
private Paint halfPaint;
|
||||
private Paint shadowPaint;
|
||||
private float rectSizeX = 600;
|
||||
private float rectSizeY = 600;
|
||||
private int draggingState = 0;
|
||||
private int orientation;
|
||||
private float oldX = 0, oldY = 0;
|
||||
private int bitmapWidth = 1, bitmapHeight = 1, bitmapX, bitmapY;
|
||||
private float rectX = -1, rectY = -1;
|
||||
private Bitmap bitmapToEdit;
|
||||
private float bitmapGlobalScale = 1;
|
||||
private float bitmapGlobalX = 0;
|
||||
private float bitmapGlobalY = 0;
|
||||
private PhotoCropViewDelegate delegate;
|
||||
|
||||
private RectF animationStartValues;
|
||||
private RectF animationEndValues;
|
||||
private Runnable animationRunnable;
|
||||
|
||||
public PhotoCropView(Context context) {
|
||||
super(context);
|
||||
|
||||
rectPaint = new Paint();
|
||||
rectPaint.setColor(0xb2ffffff);
|
||||
rectPaint.setStrokeWidth(AndroidUtilities.dp(2));
|
||||
rectPaint.setStyle(Paint.Style.STROKE);
|
||||
circlePaint = new Paint();
|
||||
circlePaint.setColor(0xffffffff);
|
||||
halfPaint = new Paint();
|
||||
halfPaint.setColor(0x7f000000);
|
||||
shadowPaint = new Paint();
|
||||
shadowPaint.setColor(0x1a000000);
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
|
||||
public void setBitmap(Bitmap bitmap, int rotation, boolean freeform) {
|
||||
bitmapToEdit = bitmap;
|
||||
rectSizeX = 600;
|
||||
rectSizeY = 600;
|
||||
draggingState = 0;
|
||||
oldX = 0;
|
||||
oldY = 0;
|
||||
bitmapWidth = 1;
|
||||
bitmapHeight = 1;
|
||||
rectX = -1;
|
||||
rectY = -1;
|
||||
freeformCrop = freeform;
|
||||
orientation = rotation;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
public boolean onTouch(MotionEvent motionEvent) {
|
||||
if (motionEvent == null) {
|
||||
draggingState = 0;
|
||||
return false;
|
||||
}
|
||||
float x = motionEvent.getX();
|
||||
float y = motionEvent.getY();
|
||||
int cornerSide = AndroidUtilities.dp(20);
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide < y && rectY + cornerSide > y) {
|
||||
draggingState = 1;
|
||||
} else if (rectX - cornerSide + rectSizeX < x && rectX + cornerSide + rectSizeX > x && rectY - cornerSide < y && rectY + cornerSide > y) {
|
||||
draggingState = 2;
|
||||
} else if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide + rectSizeY < y && rectY + cornerSide + rectSizeY > y) {
|
||||
draggingState = 3;
|
||||
} else if (rectX - cornerSide + rectSizeX < x && rectX + cornerSide + rectSizeX > x && rectY - cornerSide + rectSizeY < y && rectY + cornerSide + rectSizeY > y) {
|
||||
draggingState = 4;
|
||||
} else {
|
||||
if (freeformCrop) {
|
||||
if (rectX + cornerSide < x && rectX - cornerSide + rectSizeX > x && rectY - cornerSide < y && rectY + cornerSide > y) {
|
||||
draggingState = 5;
|
||||
} else if (rectY + cornerSide < y && rectY - cornerSide + rectSizeY > y && rectX - cornerSide + rectSizeX < x && rectX + cornerSide + rectSizeX > x) {
|
||||
draggingState = 6;
|
||||
} else if (rectY + cornerSide < y && rectY - cornerSide + rectSizeY > y && rectX - cornerSide < x && rectX + cornerSide > x) {
|
||||
draggingState = 7;
|
||||
} else if (rectX + cornerSide < x && rectX - cornerSide + rectSizeX > x && rectY - cornerSide + rectSizeY < y && rectY + cornerSide + rectSizeY > y) {
|
||||
draggingState = 8;
|
||||
}
|
||||
} else {
|
||||
draggingState = 0;
|
||||
}
|
||||
}
|
||||
if (draggingState != 0) {
|
||||
cancelAnimationRunnable();
|
||||
PhotoCropView.this.requestDisallowInterceptTouchEvent(true);
|
||||
}
|
||||
oldX = x;
|
||||
oldY = y;
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (draggingState != 0) {
|
||||
draggingState = 0;
|
||||
startAnimationRunnable();
|
||||
return true;
|
||||
}
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && draggingState != 0) {
|
||||
float diffX = x - oldX;
|
||||
float diffY = y - oldY;
|
||||
float bitmapScaledWidth = bitmapWidth * bitmapGlobalScale;
|
||||
float bitmapScaledHeight = bitmapHeight * bitmapGlobalScale;
|
||||
float bitmapStartX = (getWidth() - AndroidUtilities.dp(28) - bitmapScaledWidth) / 2 + bitmapGlobalX + AndroidUtilities.dp(14);
|
||||
float bitmapStartY = (getHeight() - AndroidUtilities.dp(28) - bitmapScaledHeight) / 2 + bitmapGlobalY + AndroidUtilities.dp(14);
|
||||
float bitmapEndX = bitmapStartX + bitmapScaledWidth;
|
||||
float bitmapEndY = bitmapStartY + bitmapScaledHeight;
|
||||
|
||||
float minSide = AndroidUtilities.getPixelsInCM(0.9f, true);
|
||||
|
||||
if (draggingState == 1 || draggingState == 5) {
|
||||
if (draggingState != 5) {
|
||||
if (rectSizeX - diffX < minSide) {
|
||||
diffX = rectSizeX - minSide;
|
||||
}
|
||||
if (rectX + diffX < bitmapX) {
|
||||
diffX = bitmapX - rectX;
|
||||
}
|
||||
if (rectX + diffX < bitmapStartX) {
|
||||
bitmapGlobalX -= bitmapStartX - rectX - diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
}
|
||||
if (!freeformCrop) {
|
||||
if (rectY + diffX < bitmapY) {
|
||||
diffX = bitmapY - rectY;
|
||||
}
|
||||
if (rectY + diffX < bitmapStartY) {
|
||||
bitmapGlobalY -= bitmapStartY - rectY - diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
rectX += diffX;
|
||||
rectY += diffX;
|
||||
rectSizeX -= diffX;
|
||||
rectSizeY -= diffX;
|
||||
} else {
|
||||
if (rectSizeY - diffY < minSide) {
|
||||
diffY = rectSizeY - minSide;
|
||||
}
|
||||
if (rectY + diffY < bitmapY) {
|
||||
diffY = bitmapY - rectY;
|
||||
}
|
||||
if (rectY + diffY < bitmapStartY) {
|
||||
bitmapGlobalY -= bitmapStartY - rectY - diffY;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
if (draggingState != 5) {
|
||||
rectX += diffX;
|
||||
rectSizeX -= diffX;
|
||||
}
|
||||
rectY += diffY;
|
||||
rectSizeY -= diffY;
|
||||
}
|
||||
} else if (draggingState == 2 || draggingState == 6) {
|
||||
if (rectSizeX + diffX < minSide) {
|
||||
diffX = -(rectSizeX - minSide);
|
||||
}
|
||||
if (rectX + rectSizeX + diffX > bitmapX + bitmapWidth) {
|
||||
diffX = bitmapX + bitmapWidth - rectX - rectSizeX;
|
||||
}
|
||||
if (rectX + rectSizeX + diffX > bitmapEndX) {
|
||||
bitmapGlobalX -= bitmapEndX - rectX - rectSizeX - diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
if (!freeformCrop) {
|
||||
if (rectY - diffX < bitmapY) {
|
||||
diffX = rectY - bitmapY;
|
||||
}
|
||||
if (rectY - diffX < bitmapStartY) {
|
||||
bitmapGlobalY -= bitmapStartY - rectY + diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
rectY -= diffX;
|
||||
rectSizeX += diffX;
|
||||
rectSizeY += diffX;
|
||||
} else {
|
||||
if (draggingState != 6) {
|
||||
if (rectSizeY - diffY < minSide) {
|
||||
diffY = rectSizeY - minSide;
|
||||
}
|
||||
if (rectY + diffY < bitmapY) {
|
||||
diffY = bitmapY - rectY;
|
||||
}
|
||||
if (rectY + diffY < bitmapStartY) {
|
||||
bitmapGlobalY -= bitmapStartY - rectY - diffY;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
rectY += diffY;
|
||||
rectSizeY -= diffY;
|
||||
}
|
||||
rectSizeX += diffX;
|
||||
}
|
||||
} else if (draggingState == 3 || draggingState == 7) {
|
||||
if (rectSizeX - diffX < minSide) {
|
||||
diffX = rectSizeX - minSide;
|
||||
}
|
||||
if (rectX + diffX < bitmapX) {
|
||||
diffX = bitmapX - rectX;
|
||||
}
|
||||
if (rectX + diffX < bitmapStartX) {
|
||||
bitmapGlobalX -= bitmapStartX - rectX - diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
if (!freeformCrop) {
|
||||
if (rectY + rectSizeX - diffX > bitmapY + bitmapHeight) {
|
||||
diffX = rectY + rectSizeX - bitmapY - bitmapHeight;
|
||||
}
|
||||
if (rectY + rectSizeX - diffX > bitmapEndY) {
|
||||
bitmapGlobalY -= bitmapEndY - rectY - rectSizeX + diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
rectX += diffX;
|
||||
rectSizeX -= diffX;
|
||||
rectSizeY -= diffX;
|
||||
} else {
|
||||
if (draggingState != 7) {
|
||||
if (rectY + rectSizeY + diffY > bitmapY + bitmapHeight) {
|
||||
diffY = bitmapY + bitmapHeight - rectY - rectSizeY;
|
||||
}
|
||||
if (rectY + rectSizeY + diffY > bitmapEndY) {
|
||||
bitmapGlobalY -= bitmapEndY - rectY - rectSizeY - diffY;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
rectSizeY += diffY;
|
||||
if (rectSizeY < minSide) {
|
||||
rectSizeY = minSide;
|
||||
}
|
||||
}
|
||||
rectX += diffX;
|
||||
rectSizeX -= diffX;
|
||||
}
|
||||
} else if (draggingState == 4 || draggingState == 8) {
|
||||
if (draggingState != 8) {
|
||||
if (rectX + rectSizeX + diffX > bitmapX + bitmapWidth) {
|
||||
diffX = bitmapX + bitmapWidth - rectX - rectSizeX;
|
||||
}
|
||||
if (rectX + rectSizeX + diffX > bitmapEndX) {
|
||||
bitmapGlobalX -= bitmapEndX - rectX - rectSizeX - diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
}
|
||||
if (!freeformCrop) {
|
||||
if (rectY + rectSizeX + diffX > bitmapY + bitmapHeight) {
|
||||
diffX = bitmapY + bitmapHeight - rectY - rectSizeX;
|
||||
}
|
||||
if (rectY + rectSizeX + diffX > bitmapEndY) {
|
||||
bitmapGlobalY -= bitmapEndY - rectY - rectSizeX - diffX;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
rectSizeX += diffX;
|
||||
rectSizeY += diffX;
|
||||
} else {
|
||||
if (rectY + rectSizeY + diffY > bitmapY + bitmapHeight) {
|
||||
diffY = bitmapY + bitmapHeight - rectY - rectSizeY;
|
||||
}
|
||||
if (rectY + rectSizeY + diffY > bitmapEndY) {
|
||||
bitmapGlobalY -= bitmapEndY - rectY - rectSizeY - diffY;
|
||||
delegate.needMoveImageTo(bitmapGlobalX, bitmapGlobalY, bitmapGlobalScale, false);
|
||||
}
|
||||
if (draggingState != 8) {
|
||||
rectSizeX += diffX;
|
||||
}
|
||||
rectSizeY += diffY;
|
||||
}
|
||||
if (rectSizeX < minSide) {
|
||||
rectSizeX = minSide;
|
||||
}
|
||||
if (rectSizeY < minSide) {
|
||||
rectSizeY = minSide;
|
||||
}
|
||||
}
|
||||
|
||||
oldX = x;
|
||||
oldY = y;
|
||||
invalidate();
|
||||
}
|
||||
return draggingState != 0;
|
||||
}
|
||||
|
||||
public float getRectX() {
|
||||
return rectX - AndroidUtilities.dp(14);
|
||||
}
|
||||
|
||||
public float getRectY() {
|
||||
return rectY - AndroidUtilities.dp(14);
|
||||
}
|
||||
|
||||
public float getRectSizeX() {
|
||||
return rectSizeX;
|
||||
}
|
||||
|
||||
public float getRectSizeY() {
|
||||
return rectSizeY;
|
||||
}
|
||||
|
||||
public float getBitmapX() {
|
||||
return bitmapX - AndroidUtilities.dp(14);
|
||||
}
|
||||
|
||||
public float getBitmapY() {
|
||||
return bitmapY - AndroidUtilities.dp(14);
|
||||
}
|
||||
|
||||
public float getLimitX() {
|
||||
return rectX - ((int) Math.max(0, Math.ceil((getWidth() - AndroidUtilities.dp(28) - bitmapWidth * bitmapGlobalScale) / 2)) + AndroidUtilities.dp(14));
|
||||
}
|
||||
|
||||
public float getLimitY() {
|
||||
return rectY - ((int) Math.max(0, Math.ceil((getHeight() - AndroidUtilities.dp(28) - bitmapHeight * bitmapGlobalScale) / 2)) + AndroidUtilities.dp(14));
|
||||
}
|
||||
|
||||
public float getLimitWidth() {
|
||||
return getWidth() - AndroidUtilities.dp(14) - rectX - (int) Math.max(0, Math.ceil((getWidth() - AndroidUtilities.dp(28) - bitmapWidth * bitmapGlobalScale) / 2)) - rectSizeX;
|
||||
}
|
||||
|
||||
public float getLimitHeight() {
|
||||
return getHeight() - AndroidUtilities.dp(14) - rectY - (int) Math.max(0, Math.ceil((getHeight() - AndroidUtilities.dp(28) - bitmapHeight * bitmapGlobalScale) / 2)) - rectSizeY;
|
||||
}
|
||||
|
||||
private Bitmap createBitmap(int x, int y, int w, int h) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setFilterBitmap(true);
|
||||
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setTranslate(-bitmapToEdit.getWidth() / 2, -bitmapToEdit.getHeight() / 2);
|
||||
matrix.postRotate(orientation);
|
||||
if (orientation == 90 || orientation == 270) {
|
||||
matrix.postTranslate(bitmapToEdit.getHeight() / 2 - x, bitmapToEdit.getWidth() / 2 - y);
|
||||
} else {
|
||||
matrix.postTranslate(bitmapToEdit.getWidth() / 2 - x, bitmapToEdit.getHeight() / 2 - y);
|
||||
}
|
||||
canvas.drawBitmap(bitmapToEdit, matrix, paint);
|
||||
try {
|
||||
canvas.setBitmap(null);
|
||||
} catch (Exception e) {
|
||||
//don't promt, this will crash on 2.x
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
float bitmapScaledWidth = bitmapWidth * bitmapGlobalScale;
|
||||
float bitmapScaledHeight = bitmapHeight * bitmapGlobalScale;
|
||||
float bitmapStartX = (getWidth() - AndroidUtilities.dp(28) - bitmapScaledWidth) / 2 + bitmapGlobalX + AndroidUtilities.dp(14);
|
||||
float bitmapStartY = (getHeight() - AndroidUtilities.dp(28) - bitmapScaledHeight) / 2 + bitmapGlobalY + AndroidUtilities.dp(14);
|
||||
|
||||
float percX = (rectX - bitmapStartX) / bitmapScaledWidth;
|
||||
float percY = (rectY - bitmapStartY) / bitmapScaledHeight;
|
||||
float percSizeX = rectSizeX / bitmapScaledWidth;
|
||||
float percSizeY = rectSizeY / bitmapScaledHeight;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
if (orientation == 90 || orientation == 270) {
|
||||
width = bitmapToEdit.getHeight();
|
||||
height = bitmapToEdit.getWidth();
|
||||
} else {
|
||||
width = bitmapToEdit.getWidth();
|
||||
height = bitmapToEdit.getHeight();
|
||||
}
|
||||
|
||||
int x = (int) (percX * width);
|
||||
int y = (int) (percY * height);
|
||||
int sizeX = (int) (percSizeX * width);
|
||||
int sizeY = (int) (percSizeY * height);
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
}
|
||||
if (x + sizeX > width) {
|
||||
sizeX = width - x;
|
||||
}
|
||||
if (y + sizeY > height) {
|
||||
sizeY = height - y;
|
||||
}
|
||||
try {
|
||||
return createBitmap(x, y, sizeX, sizeY);
|
||||
} catch (Throwable e) {
|
||||
FileLog.e("tmessags", e);
|
||||
System.gc();
|
||||
try {
|
||||
return createBitmap(x, y, sizeX, sizeY);
|
||||
} catch (Throwable e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
canvas.drawRect(0, 0, getWidth(), rectY, halfPaint);
|
||||
canvas.drawRect(0, rectY, rectX, rectY + rectSizeY, halfPaint);
|
||||
canvas.drawRect(rectX + rectSizeX, rectY, getWidth(), rectY + rectSizeY, halfPaint);
|
||||
canvas.drawRect(0, rectY + rectSizeY, getWidth(), getHeight(), halfPaint);
|
||||
|
||||
int side = AndroidUtilities.dp(1);
|
||||
canvas.drawRect(rectX - side * 2, rectY - side * 2, rectX - side * 2 + AndroidUtilities.dp(20), rectY, circlePaint);
|
||||
canvas.drawRect(rectX - side * 2, rectY - side * 2, rectX, rectY - side * 2 + AndroidUtilities.dp(20), circlePaint);
|
||||
|
||||
canvas.drawRect(rectX + rectSizeX + side * 2 - AndroidUtilities.dp(20), rectY - side * 2, rectX + rectSizeX + side * 2, rectY, circlePaint);
|
||||
canvas.drawRect(rectX + rectSizeX, rectY - side * 2, rectX + rectSizeX + side * 2, rectY - side * 2 + AndroidUtilities.dp(20), circlePaint);
|
||||
|
||||
canvas.drawRect(rectX - side * 2, rectY + rectSizeY + side * 2 - AndroidUtilities.dp(20), rectX, rectY + rectSizeY + side * 2, circlePaint);
|
||||
canvas.drawRect(rectX - side * 2, rectY + rectSizeY, rectX - side * 2 + AndroidUtilities.dp(20), rectY + rectSizeY + side * 2, circlePaint);
|
||||
|
||||
canvas.drawRect(rectX + rectSizeX + side * 2 - AndroidUtilities.dp(20), rectY + rectSizeY, rectX + rectSizeX + side * 2, rectY + rectSizeY + side * 2, circlePaint);
|
||||
canvas.drawRect(rectX + rectSizeX, rectY + rectSizeY + side * 2 - AndroidUtilities.dp(20), rectX + rectSizeX + side * 2, rectY + rectSizeY + side * 2, circlePaint);
|
||||
|
||||
for (int a = 1; a < 3; a++) {
|
||||
canvas.drawRect(rectX + rectSizeX / 3 * a - side, rectY, rectX + side * 2 + rectSizeX / 3 * a, rectY + rectSizeY, shadowPaint);
|
||||
canvas.drawRect(rectX, rectY + rectSizeY / 3 * a - side, rectX + rectSizeX, rectY + rectSizeY / 3 * a + side * 2, shadowPaint);
|
||||
}
|
||||
|
||||
for (int a = 1; a < 3; a++) {
|
||||
canvas.drawRect(rectX + rectSizeX / 3 * a, rectY, rectX + side + rectSizeX / 3 * a, rectY + rectSizeY, circlePaint);
|
||||
canvas.drawRect(rectX, rectY + rectSizeY / 3 * a, rectX + rectSizeX, rectY + rectSizeY / 3 * a + side, circlePaint);
|
||||
}
|
||||
|
||||
canvas.drawRect(rectX, rectY, rectX + rectSizeX, rectY + rectSizeY, rectPaint);
|
||||
}
|
||||
|
||||
public void setBitmapParams(float scale, float x, float y) {
|
||||
bitmapGlobalScale = scale;
|
||||
bitmapGlobalX = x;
|
||||
bitmapGlobalY = y;
|
||||
}
|
||||
|
||||
public void startAnimationRunnable() {
|
||||
if (animationRunnable != null) {
|
||||
return;
|
||||
}
|
||||
animationRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (animationRunnable == this) {
|
||||
animationRunnable = null;
|
||||
animateToFill();
|
||||
}
|
||||
}
|
||||
};
|
||||
AndroidUtilities.runOnUIThread(animationRunnable, 1500);
|
||||
}
|
||||
|
||||
public void cancelAnimationRunnable() {
|
||||
if (animationRunnable != null) {
|
||||
AndroidUtilities.cancelRunOnUIThread(animationRunnable);
|
||||
animationRunnable = null;
|
||||
animationStartValues = null;
|
||||
animationEndValues = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAnimationProgress(float animationProgress) {
|
||||
if (animationStartValues != null) {
|
||||
if (animationProgress == 1) {
|
||||
rectX = animationEndValues.left;
|
||||
rectY = animationEndValues.top;
|
||||
rectSizeX = animationEndValues.right;
|
||||
rectSizeY = animationEndValues.bottom;
|
||||
animationStartValues = null;
|
||||
animationEndValues = null;
|
||||
} else {
|
||||
rectX = animationStartValues.left + (animationEndValues.left - animationStartValues.left) * animationProgress;
|
||||
rectY = animationStartValues.top + (animationEndValues.top - animationStartValues.top) * animationProgress;
|
||||
rectSizeX = animationStartValues.right + (animationEndValues.right - animationStartValues.right) * animationProgress;
|
||||
rectSizeY = animationStartValues.bottom + (animationEndValues.bottom - animationStartValues.bottom) * animationProgress;
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void animateToFill() {
|
||||
float scaleToX = bitmapWidth / rectSizeX;
|
||||
float scaleToY = bitmapHeight / rectSizeY;
|
||||
float scaleTo = scaleToX > scaleToY ? scaleToY : scaleToX;
|
||||
if (scaleTo > 1 && scaleTo * bitmapGlobalScale > 3) {
|
||||
scaleTo = 3 / bitmapGlobalScale;
|
||||
} else if (scaleTo < 1 && scaleTo * bitmapGlobalScale < 1) {
|
||||
scaleTo = 1 / bitmapGlobalScale;
|
||||
}
|
||||
float newSizeX = rectSizeX * scaleTo;
|
||||
float newSizeY = rectSizeY * scaleTo;
|
||||
float newX = (getWidth() - AndroidUtilities.dp(28) - newSizeX) / 2 + AndroidUtilities.dp(14);
|
||||
float newY = (getHeight() - AndroidUtilities.dp(28) - newSizeY) / 2 + AndroidUtilities.dp(14);
|
||||
animationStartValues = new RectF(rectX, rectY, rectSizeX, rectSizeY);
|
||||
animationEndValues = new RectF(newX, newY, newSizeX, newSizeY);
|
||||
|
||||
float newBitmapGlobalX = newX + getWidth() / 2 * (scaleTo - 1) + (bitmapGlobalX - rectX) * scaleTo;
|
||||
float newBitmapGlobalY = newY + getHeight() / 2 * (scaleTo - 1) + (bitmapGlobalY - rectY) * scaleTo;
|
||||
|
||||
delegate.needMoveImageTo(newBitmapGlobalX, newBitmapGlobalY, bitmapGlobalScale * scaleTo, true);
|
||||
}
|
||||
|
||||
public void setDelegate(PhotoCropViewDelegate delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
|
||||
if (bitmapToEdit == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int viewWidth = getWidth() - AndroidUtilities.dp(28);
|
||||
int viewHeight = getHeight() - AndroidUtilities.dp(28);
|
||||
|
||||
float bitmapW;
|
||||
float bitmapH;
|
||||
if (orientation == 90 || orientation == 270) {
|
||||
bitmapW = bitmapToEdit.getHeight();
|
||||
bitmapH = bitmapToEdit.getWidth();
|
||||
} else {
|
||||
bitmapW = bitmapToEdit.getWidth();
|
||||
bitmapH = bitmapToEdit.getHeight();
|
||||
}
|
||||
float scaleX = viewWidth / bitmapW;
|
||||
float scaleY = viewHeight / bitmapH;
|
||||
if (scaleX > scaleY) {
|
||||
bitmapH = viewHeight;
|
||||
bitmapW = (int) Math.ceil(bitmapW * scaleY);
|
||||
} else {
|
||||
bitmapW = viewWidth;
|
||||
bitmapH = (int) Math.ceil(bitmapH * scaleX);
|
||||
}
|
||||
|
||||
float percX = (rectX - bitmapX) / bitmapWidth;
|
||||
float percY = (rectY - bitmapY) / bitmapHeight;
|
||||
float percSizeX = rectSizeX / bitmapWidth;
|
||||
float percSizeY = rectSizeY / bitmapHeight;
|
||||
bitmapWidth = (int) bitmapW;
|
||||
bitmapHeight = (int) bitmapH;
|
||||
|
||||
bitmapX = (int) Math.ceil((viewWidth - bitmapWidth) / 2 + AndroidUtilities.dp(14));
|
||||
bitmapY = (int) Math.ceil((viewHeight - bitmapHeight) / 2 + AndroidUtilities.dp(14));
|
||||
|
||||
if (rectX == -1 && rectY == -1) {
|
||||
if (freeformCrop) {
|
||||
rectY = bitmapY;
|
||||
rectX = bitmapX;
|
||||
rectSizeX = bitmapWidth;
|
||||
rectSizeY = bitmapHeight;
|
||||
} else {
|
||||
if (bitmapWidth > bitmapHeight) {
|
||||
rectY = bitmapY;
|
||||
rectX = (viewWidth - bitmapHeight) / 2 + AndroidUtilities.dp(14);
|
||||
rectSizeX = bitmapHeight;
|
||||
rectSizeY = bitmapHeight;
|
||||
} else {
|
||||
rectX = bitmapX;
|
||||
rectY = (viewHeight - bitmapWidth) / 2 + AndroidUtilities.dp(14);
|
||||
rectSizeX = bitmapWidth;
|
||||
rectSizeY = bitmapWidth;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rectX = percX * bitmapWidth + bitmapX;
|
||||
rectY = percY * bitmapHeight + bitmapY;
|
||||
rectSizeX = percSizeX * bitmapWidth;
|
||||
rectSizeY = percSizeY * bitmapHeight;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 2.x
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2015.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import org.telegram.android.AndroidUtilities;
|
||||
|
||||
public class PhotoEditorSeekBar extends View {
|
||||
|
||||
private Paint innerPaint = new Paint();
|
||||
private Paint outerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private int thumbSize = AndroidUtilities.dp(16);
|
||||
private int thumbDX = 0;
|
||||
private float progress = 0;
|
||||
private boolean pressed = false;
|
||||
private int minValue;
|
||||
private int maxValue;
|
||||
private PhotoEditorSeekBarDelegate delegate;
|
||||
|
||||
public abstract interface PhotoEditorSeekBarDelegate {
|
||||
public void onProgressChanged();
|
||||
}
|
||||
|
||||
public PhotoEditorSeekBar(Context context) {
|
||||
super(context);
|
||||
|
||||
innerPaint.setColor(0x99383838);
|
||||
outerPaint.setColor(0xff53aeef);
|
||||
}
|
||||
|
||||
public void setDelegate(PhotoEditorSeekBarDelegate delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event == null) {
|
||||
return false;
|
||||
}
|
||||
float x = event.getX();
|
||||
float y = event.getY();
|
||||
float thumbX = (int)((getMeasuredWidth() - thumbSize) * progress);
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
int additionWidth = (getMeasuredHeight() - thumbSize) / 2;
|
||||
if (thumbX - additionWidth <= x && x <= thumbX + thumbSize + additionWidth && y >= 0 && y <= getMeasuredHeight()) {
|
||||
pressed = true;
|
||||
thumbDX = (int)(x - thumbX);
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
} else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||
if (pressed) {
|
||||
pressed = false;
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (pressed) {
|
||||
thumbX = (int)(x - thumbDX);
|
||||
if (thumbX < 0) {
|
||||
thumbX = 0;
|
||||
} else if (thumbX > getMeasuredWidth() - thumbSize) {
|
||||
thumbX = getMeasuredWidth() - thumbSize;
|
||||
}
|
||||
progress = thumbX / (getMeasuredWidth() - thumbSize);
|
||||
if (delegate != null) {
|
||||
delegate.onProgressChanged();
|
||||
}
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
setProgress(progress, true);
|
||||
}
|
||||
|
||||
public void setProgress(int progress, boolean notify) {
|
||||
if (progress < minValue) {
|
||||
progress = minValue;
|
||||
} else if (progress > maxValue) {
|
||||
progress = maxValue;
|
||||
}
|
||||
this.progress = (progress - minValue) / (float) (maxValue - minValue);
|
||||
invalidate();
|
||||
if (notify && delegate != null) {
|
||||
delegate.onProgressChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return (int) (minValue + progress * (maxValue - minValue));
|
||||
}
|
||||
|
||||
public void setMinMax(int min, int max) {
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int y = (getMeasuredHeight() - thumbSize) / 2;
|
||||
int thumbX = (int)((getMeasuredWidth() - thumbSize) * progress);
|
||||
canvas.drawRect(thumbSize / 2, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), getMeasuredWidth() - thumbSize / 2, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), innerPaint);
|
||||
if (minValue == 0) {
|
||||
canvas.drawRect(thumbSize / 2, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), thumbX, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), outerPaint);
|
||||
} else {
|
||||
if (progress > 0.5f) {
|
||||
canvas.drawRect(getMeasuredWidth() / 2 - AndroidUtilities.dp(1), (getMeasuredHeight() - thumbSize) / 2, getMeasuredWidth() / 2, (getMeasuredHeight() + thumbSize) / 2, outerPaint);
|
||||
canvas.drawRect(getMeasuredWidth() / 2, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), thumbX, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), outerPaint);
|
||||
} else {
|
||||
canvas.drawRect(getMeasuredWidth() / 2, (getMeasuredHeight() - thumbSize) / 2, getMeasuredWidth() / 2 + AndroidUtilities.dp(1), (getMeasuredHeight() + thumbSize) / 2, outerPaint);
|
||||
canvas.drawRect(thumbX, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), getMeasuredWidth() / 2, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), outerPaint);
|
||||
}
|
||||
}
|
||||
canvas.drawCircle(thumbX + thumbSize / 2, y + thumbSize / 2, thumbSize / 2, outerPaint);
|
||||
}
|
||||
}
|
@ -0,0 +1,417 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 2.x
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2015.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.util.SizeF;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public class PhotoFilterLinearBlurControl extends FrameLayout {
|
||||
|
||||
private final static float LinearBlurInsetProximity = 20;
|
||||
private final static float LinearBlurMinimumFalloff = 0.1f;
|
||||
private final static float LinearBlurMinimumDifference = 0.02f;
|
||||
private final static float LinearBlurViewCenterInset = 30.0f;
|
||||
private final static float LinearBlurViewRadiusInset = 30.0f;
|
||||
|
||||
private enum LinearBlurViewActiveControl {
|
||||
TGLinearBlurViewActiveControlNone,
|
||||
TGLinearBlurViewActiveControlCenter,
|
||||
TGLinearBlurViewActiveControlInnerRadius,
|
||||
TGLinearBlurViewActiveControlOuterRadius,
|
||||
TGLinearBlurViewActiveControlWholeArea,
|
||||
TGLinearBlurViewActiveControlRotation
|
||||
}
|
||||
|
||||
private LinearBlurViewActiveControl activeControl;
|
||||
private PointF startCenterPoint = new PointF();
|
||||
private PointF startDistance = new PointF();
|
||||
private PointF startRadius = new PointF();
|
||||
private boolean isTracking;
|
||||
private SizeF actualAreaSize;
|
||||
private PointF centerPoint;
|
||||
private float falloff;
|
||||
private float size;
|
||||
private float angle;
|
||||
|
||||
//@property (nonatomic, copy) void (^valueChanged)(CGPoint centerPoint, CGFloat falloff, CGFloat size, CGFloat angle);
|
||||
//@property (nonatomic, copy) void(^interactionEnded)(void);
|
||||
//UILongPressGestureRecognizer *_pressGestureRecognizer;
|
||||
//UIPanGestureRecognizer *_panGestureRecognizer;
|
||||
//UIPinchGestureRecognizer *_pinchGestureRecognizer;
|
||||
|
||||
public PhotoFilterLinearBlurControl(Context context) {
|
||||
super(context);
|
||||
|
||||
setWillNotDraw(false);
|
||||
|
||||
centerPoint = new PointF(0.5f, 0.5f);
|
||||
falloff = 0.15f;
|
||||
size = 0.35f;
|
||||
|
||||
/*_pressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handlePress:)];
|
||||
_pressGestureRecognizer.delegate = self;
|
||||
_pressGestureRecognizer.minimumPressDuration = 0.1f;
|
||||
[self addGestureRecognizer:_pressGestureRecognizer];
|
||||
|
||||
_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
|
||||
_panGestureRecognizer.delegate = self;
|
||||
[self addGestureRecognizer:_panGestureRecognizer];
|
||||
|
||||
_pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
|
||||
_pinchGestureRecognizer.delegate = self;
|
||||
[self addGestureRecognizer:_pinchGestureRecognizer];*/
|
||||
}
|
||||
|
||||
|
||||
private void handlePress() {
|
||||
/*switch (gestureRecognizer.state) {
|
||||
case UIGestureRecognizerStateBegan:
|
||||
[self setSelected:true animated:true];
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateEnded:
|
||||
case UIGestureRecognizerStateCancelled:
|
||||
case UIGestureRecognizerStateFailed:
|
||||
[self setSelected:false animated:true];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
private void handlePan() {
|
||||
/*CGPoint location = [gestureRecognizer locationInView:self];
|
||||
CGPoint centerPoint = [self _actualCenterPoint];
|
||||
CGPoint delta = CGPointMake(location.x - centerPoint.x, location.y - centerPoint.y);
|
||||
CGFloat radialDistance = sqrtf(delta.x * delta.x + delta.y * delta.y);
|
||||
CGFloat distance = fabsf(delta.x * cosf(self.angle + (CGFloat)M_PI_2) + delta.y * sinf(self.angle + (CGFloat)M_PI_2));
|
||||
|
||||
CGFloat shorterSide = (self.actualAreaSize.width > self.actualAreaSize.height) ? self.actualAreaSize.height : self.actualAreaSize.width;
|
||||
|
||||
CGFloat innerRadius = shorterSide * self.falloff;
|
||||
CGFloat outerRadius = shorterSide * self.size;
|
||||
|
||||
switch (gestureRecognizer.state) {
|
||||
case UIGestureRecognizerStateBegan:
|
||||
{
|
||||
bool close = fabsf(outerRadius - innerRadius) < TGLinearBlurInsetProximity;
|
||||
CGFloat innerRadiusOuterInset = close ? 0 : TGLinearBlurViewRadiusInset;
|
||||
CGFloat outerRadiusInnerInset = close ? 0 : TGLinearBlurViewRadiusInset;
|
||||
|
||||
if (radialDistance < TGLinearBlurViewCenterInset)
|
||||
{
|
||||
_activeControl = TGLinearBlurViewActiveControlCenter;
|
||||
_startCenterPoint = centerPoint;
|
||||
}
|
||||
else if (distance > innerRadius - TGLinearBlurViewRadiusInset && distance < innerRadius + innerRadiusOuterInset)
|
||||
{
|
||||
_activeControl = TGLinearBlurViewActiveControlInnerRadius;
|
||||
_startDistance = distance;
|
||||
_startRadius = innerRadius;
|
||||
}
|
||||
else if (distance > outerRadius - outerRadiusInnerInset && distance < outerRadius + TGLinearBlurViewRadiusInset)
|
||||
{
|
||||
_activeControl = TGLinearBlurViewActiveControlOuterRadius;
|
||||
_startDistance = distance;
|
||||
_startRadius = outerRadius;
|
||||
}
|
||||
else if (distance <= innerRadius - TGLinearBlurViewRadiusInset || distance >= outerRadius + TGLinearBlurViewRadiusInset)
|
||||
{
|
||||
_activeControl = TGLinearBlurViewActiveControlRotation;
|
||||
}
|
||||
|
||||
[self setSelected:true animated:true];
|
||||
}
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateChanged:
|
||||
{
|
||||
switch (_activeControl)
|
||||
{
|
||||
case TGLinearBlurViewActiveControlCenter:
|
||||
{
|
||||
CGPoint translation = [gestureRecognizer translationInView:self];
|
||||
|
||||
CGRect actualArea = CGRectMake((self.frame.size.width - self.actualAreaSize.width) / 2, (self.frame.size.height - self.actualAreaSize.height) / 2, self.actualAreaSize.width, self.actualAreaSize.height);
|
||||
|
||||
CGPoint newPoint = CGPointMake(MAX(CGRectGetMinX(actualArea), MIN(CGRectGetMaxX(actualArea), _startCenterPoint.x + translation.x)),
|
||||
MAX(CGRectGetMinY(actualArea), MIN(CGRectGetMaxY(actualArea), _startCenterPoint.y + translation.y)));
|
||||
|
||||
CGPoint offset = CGPointMake(0, (self.actualAreaSize.width - self.actualAreaSize.height) / 2);
|
||||
CGPoint actualPoint = CGPointMake(newPoint.x - actualArea.origin.x, newPoint.y - actualArea.origin.y);
|
||||
self.centerPoint = CGPointMake((actualPoint.x + offset.x) / self.actualAreaSize.width, (actualPoint.y + offset.y) / self.actualAreaSize.width);
|
||||
}
|
||||
break;
|
||||
|
||||
case TGLinearBlurViewActiveControlInnerRadius:
|
||||
{
|
||||
CGFloat delta = distance - _startDistance;
|
||||
self.falloff = MIN(MAX(TGLinearBlurMinimumFalloff, (_startRadius + delta) / shorterSide), self.size - TGLinearBlurMinimumDifference);
|
||||
}
|
||||
break;
|
||||
|
||||
case TGLinearBlurViewActiveControlOuterRadius:
|
||||
{
|
||||
CGFloat delta = distance - _startDistance;
|
||||
self.size = MAX(self.falloff + TGLinearBlurMinimumDifference, (_startRadius + delta) / shorterSide);
|
||||
}
|
||||
break;
|
||||
|
||||
case TGLinearBlurViewActiveControlRotation:
|
||||
{
|
||||
CGPoint translation = [gestureRecognizer translationInView:self];
|
||||
bool clockwise = false;
|
||||
|
||||
bool right = location.x > centerPoint.x;
|
||||
bool bottom = location.y > centerPoint.y;
|
||||
|
||||
if (!right && !bottom)
|
||||
{
|
||||
if (fabsf(translation.y) > fabsf(translation.x))
|
||||
{
|
||||
if (translation.y < 0)
|
||||
clockwise = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (translation.x > 0)
|
||||
clockwise = true;
|
||||
}
|
||||
}
|
||||
else if (right && !bottom)
|
||||
{
|
||||
if (fabsf(translation.y) > fabsf(translation.x))
|
||||
{
|
||||
if (translation.y > 0)
|
||||
clockwise = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (translation.x > 0)
|
||||
clockwise = true;
|
||||
}
|
||||
}
|
||||
else if (right && bottom)
|
||||
{
|
||||
if (fabsf(translation.y) > fabsf(translation.x))
|
||||
{
|
||||
if (translation.y > 0)
|
||||
clockwise = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (translation.x < 0)
|
||||
clockwise = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fabsf(translation.y) > fabsf(translation.x))
|
||||
{
|
||||
if (translation.y < 0)
|
||||
clockwise = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (translation.x < 0)
|
||||
clockwise = true;
|
||||
}
|
||||
}
|
||||
|
||||
CGFloat delta = sqrtf(translation.x * translation.x + translation.y * translation.y);
|
||||
|
||||
CGFloat angleInDegrees = TGRadiansToDegrees(_angle);
|
||||
CGFloat newAngleInDegrees = angleInDegrees + delta * (clockwise * 2 - 1) / (CGFloat)M_PI / 1.15f;
|
||||
|
||||
_angle = TGDegreesToRadians(newAngleInDegrees);
|
||||
|
||||
[gestureRecognizer setTranslation:CGPointZero inView:self];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
[self setNeedsDisplay];
|
||||
|
||||
if (self.valueChanged != nil)
|
||||
self.valueChanged(self.centerPoint, self.falloff, self.size, self.angle);
|
||||
}
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateEnded:
|
||||
case UIGestureRecognizerStateCancelled:
|
||||
case UIGestureRecognizerStateFailed:
|
||||
{
|
||||
_activeControl = TGLinearBlurViewActiveControlNone;
|
||||
|
||||
[self setSelected:false animated:true];
|
||||
|
||||
if (self.interactionEnded != nil)
|
||||
self.interactionEnded();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
private void handlePinch() {
|
||||
/*switch (gestureRecognizer.state) {
|
||||
case UIGestureRecognizerStateBegan: {
|
||||
_activeControl = TGLinearBlurViewActiveControlWholeArea;
|
||||
[self setSelected:true animated:true];
|
||||
}
|
||||
case UIGestureRecognizerStateChanged: {
|
||||
CGFloat scale = gestureRecognizer.scale;
|
||||
|
||||
self.falloff = MAX(TGLinearBlurMinimumFalloff, self.falloff * scale);
|
||||
self.size = MAX(self.falloff + TGLinearBlurMinimumDifference, self.size * scale);
|
||||
|
||||
gestureRecognizer.scale = 1.0f;
|
||||
|
||||
[self setNeedsDisplay];
|
||||
|
||||
if (self.valueChanged != nil)
|
||||
self.valueChanged(self.centerPoint, self.falloff, self.size, self.angle);
|
||||
}
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateEnded: {
|
||||
_activeControl = TGLinearBlurViewActiveControlNone;
|
||||
[self setSelected:false animated:true];
|
||||
}
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateCancelled:
|
||||
case UIGestureRecognizerStateFailed: {
|
||||
_activeControl = TGLinearBlurViewActiveControlNone;
|
||||
[self setSelected:false animated:true];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
/*- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
|
||||
{
|
||||
if (gestureRecognizer == _pressGestureRecognizer || gestureRecognizer == _panGestureRecognizer)
|
||||
{
|
||||
CGPoint location = [gestureRecognizer locationInView:self];
|
||||
CGPoint centerPoint = [self _actualCenterPoint];
|
||||
CGPoint delta = CGPointMake(location.x - centerPoint.x, location.y - centerPoint.y);
|
||||
CGFloat radialDistance = sqrtf(delta.x * delta.x + delta.y * delta.y);
|
||||
CGFloat distance = fabsf(delta.x * cosf(self.angle + (CGFloat)M_PI_2) + delta.y * sinf(self.angle + (CGFloat)M_PI_2));
|
||||
|
||||
CGFloat innerRadius = [self _actualInnerRadius];
|
||||
CGFloat outerRadius = [self _actualOuterRadius];
|
||||
|
||||
bool close = fabsf(outerRadius - innerRadius) < TGLinearBlurInsetProximity;
|
||||
CGFloat innerRadiusOuterInset = close ? 0 : TGLinearBlurViewRadiusInset;
|
||||
CGFloat outerRadiusInnerInset = close ? 0 : TGLinearBlurViewRadiusInset;
|
||||
|
||||
if (radialDistance < TGLinearBlurViewCenterInset && gestureRecognizer == _panGestureRecognizer)
|
||||
return true;
|
||||
else if (distance > innerRadius - TGLinearBlurViewRadiusInset && distance < innerRadius + innerRadiusOuterInset)
|
||||
return true;
|
||||
else if (distance > outerRadius - outerRadiusInnerInset && distance < outerRadius + TGLinearBlurViewRadiusInset)
|
||||
return true;
|
||||
else if ((distance <= innerRadius - TGLinearBlurViewRadiusInset) || distance >= outerRadius + TGLinearBlurViewRadiusInset)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
|
||||
{
|
||||
if (gestureRecognizer == _pressGestureRecognizer || otherGestureRecognizer == _pressGestureRecognizer)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}*/
|
||||
|
||||
private void setSelected(boolean selected, boolean animated) {
|
||||
/*if (animated) {
|
||||
[UIView animateWithDuration:0.16f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^
|
||||
{
|
||||
self.alpha = selected ? 0.6f : 1.0f;
|
||||
} completion:nil];
|
||||
} else {
|
||||
self.alpha = selected ? 0.6f : 1.0f;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
/*PointF centerPoint = getActualCenterPoint();
|
||||
float innerRadius = getActualInnerRadius();
|
||||
float outerRadius = getActualOuterRadius();
|
||||
|
||||
CGContextTranslateCTM(context, centerPoint.x, centerPoint.y);
|
||||
CGContextRotateCTM(context, self.angle);
|
||||
|
||||
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
|
||||
CGContextSetShadowWithColor(context, CGSizeZero, 2.5f, [UIColor colorWithWhite:0.0f alpha:0.3f].CGColor);
|
||||
|
||||
float space = 6.0f;
|
||||
float length = 12.0f;
|
||||
float thickness = 1.5f;
|
||||
for (int i = 0; i < 30; i++) {
|
||||
CGContextAddRect(context, CGRectMake(i * (length + space), -innerRadius, length, thickness));
|
||||
CGContextAddRect(context, CGRectMake(-i * (length + space) - space - length, -innerRadius, length, thickness));
|
||||
|
||||
CGContextAddRect(context, CGRectMake(i * (length + space), innerRadius, length, thickness));
|
||||
CGContextAddRect(context, CGRectMake(-i * (length + space) - space - length, innerRadius, length, thickness));
|
||||
}
|
||||
|
||||
length = 6.0f;
|
||||
thickness = 1.5f;
|
||||
for (int i = 0; i < 64; i++) {
|
||||
CGContextAddRect(context, CGRectMake(i * (length + space), -outerRadius, length, thickness));
|
||||
CGContextAddRect(context, CGRectMake(-i * (length + space) - space - length, -outerRadius, length, thickness));
|
||||
|
||||
CGContextAddRect(context, CGRectMake(i * (length + space), outerRadius, length, thickness));
|
||||
CGContextAddRect(context, CGRectMake(-i * (length + space) - space - length, outerRadius, length, thickness));
|
||||
}
|
||||
|
||||
CGContextFillPath(context);
|
||||
|
||||
CGContextFillEllipseInRect(context, CGRectMake(-16 / 2, - 16 / 2, 16, 16));*/
|
||||
}
|
||||
|
||||
private PointF getActualCenterPoint() {
|
||||
RectF actualArea = new RectF((getWidth() - actualAreaSize.getWidth()) / 2, (getHeight() - actualAreaSize.getHeight()) / 2, actualAreaSize.getWidth(), actualAreaSize.getHeight());
|
||||
PointF offset = new PointF(0, (actualAreaSize.getWidth() - actualAreaSize.getHeight()) / 2);
|
||||
return new PointF(actualArea.left - offset.x + centerPoint.x * actualAreaSize.getWidth(), actualArea.top - offset.y + centerPoint.y * actualAreaSize.getWidth());
|
||||
}
|
||||
|
||||
private float getActualInnerRadius() {
|
||||
float shorterSide = (actualAreaSize.getWidth() > actualAreaSize.getHeight()) ? actualAreaSize.getHeight() : actualAreaSize.getWidth();
|
||||
return shorterSide * falloff;
|
||||
}
|
||||
|
||||
private float getActualOuterRadius() {
|
||||
float shorterSide = (actualAreaSize.getWidth() > actualAreaSize.getHeight()) ? actualAreaSize.getHeight() : actualAreaSize.getWidth();
|
||||
return shorterSide * size;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 2.x
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2015.
|
||||
*/
|
||||
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
public class PhotoFilterRadialBlurControl {
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -20,52 +20,43 @@ import org.telegram.android.AndroidUtilities;
|
||||
import org.telegram.android.LocaleController;
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class PhotoPickerBottomLayout extends LinearLayout {
|
||||
public class PhotoPickerBottomLayout extends FrameLayout {
|
||||
|
||||
public FrameLayout doneButton;
|
||||
public LinearLayout doneButton;
|
||||
public TextView cancelButton;
|
||||
public TextView doneButtonTextView;
|
||||
public TextView doneButtonBadgeTextView;
|
||||
|
||||
public PhotoPickerBottomLayout(Context context) {
|
||||
super(context);
|
||||
setBackgroundColor(0xff333333);
|
||||
setOrientation(HORIZONTAL);
|
||||
setBackgroundColor(0xff1a1a1a);
|
||||
|
||||
cancelButton = new TextView(context);
|
||||
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||
cancelButton.setTextColor(0xffffffff);
|
||||
cancelButton.setGravity(Gravity.CENTER);
|
||||
cancelButton.setBackgroundResource(R.drawable.bar_selector_picker);
|
||||
cancelButton.setPadding(AndroidUtilities.dp(3), 0, 0, 0);
|
||||
cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
|
||||
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
|
||||
cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
addView(cancelButton);
|
||||
LayoutParams layoutParams = (LayoutParams) cancelButton.getLayoutParams();
|
||||
layoutParams.width = 0;
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.weight = 1;
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
cancelButton.setLayoutParams(layoutParams);
|
||||
|
||||
doneButton = new FrameLayout(context);
|
||||
doneButton = new LinearLayout(context);
|
||||
doneButton.setOrientation(LinearLayout.HORIZONTAL);
|
||||
doneButton.setBackgroundResource(R.drawable.bar_selector_picker);
|
||||
doneButton.setPadding(0, 0, AndroidUtilities.dp(3), 0);
|
||||
doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
|
||||
addView(doneButton);
|
||||
layoutParams = (LayoutParams) doneButton.getLayoutParams();
|
||||
layoutParams.width = 0;
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.weight = 1;
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
|
||||
doneButton.setLayoutParams(layoutParams);
|
||||
|
||||
LinearLayout linearLayout = new LinearLayout(context);
|
||||
linearLayout.setOrientation(HORIZONTAL);
|
||||
doneButton.addView(linearLayout);
|
||||
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) linearLayout.getLayoutParams();
|
||||
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.gravity = Gravity.CENTER;
|
||||
linearLayout.setLayoutParams(layoutParams1);
|
||||
|
||||
doneButtonBadgeTextView = new TextView(context);
|
||||
doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
|
||||
@ -74,28 +65,27 @@ public class PhotoPickerBottomLayout extends LinearLayout {
|
||||
doneButtonBadgeTextView.setBackgroundResource(R.drawable.photobadge);
|
||||
doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23));
|
||||
doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1));
|
||||
linearLayout.addView(doneButtonBadgeTextView);
|
||||
layoutParams = (LayoutParams) doneButtonBadgeTextView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = AndroidUtilities.dp(23);
|
||||
layoutParams.rightMargin = AndroidUtilities.dp(10);
|
||||
doneButtonBadgeTextView.setLayoutParams(layoutParams);
|
||||
doneButton.addView(doneButtonBadgeTextView);
|
||||
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) doneButtonBadgeTextView.getLayoutParams();
|
||||
layoutParams1.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.height = AndroidUtilities.dp(23);
|
||||
layoutParams1.rightMargin = AndroidUtilities.dp(10);
|
||||
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
|
||||
doneButtonBadgeTextView.setLayoutParams(layoutParams1);
|
||||
|
||||
doneButtonTextView = new TextView(context);
|
||||
doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
||||
doneButtonTextView.setTextColor(0xffffffff);
|
||||
doneButtonTextView.setGravity(Gravity.CENTER);
|
||||
doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
|
||||
doneButtonTextView.setBackgroundResource(R.drawable.bar_selector_picker);
|
||||
doneButtonTextView.setPadding(AndroidUtilities.dp(3), 0, 0, 0);
|
||||
doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
|
||||
doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
linearLayout.addView(doneButtonTextView);
|
||||
layoutParams = (LayoutParams) doneButtonTextView.getLayoutParams();
|
||||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
||||
layoutParams.height = LayoutParams.WRAP_CONTENT;
|
||||
doneButtonTextView.setLayoutParams(layoutParams);
|
||||
doneButton.addView(doneButtonTextView);
|
||||
layoutParams1 = (LinearLayout.LayoutParams) doneButtonTextView.getLayoutParams();
|
||||
layoutParams1.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
|
||||
layoutParams1.height = LayoutParams.WRAP_CONTENT;
|
||||
doneButtonTextView.setLayoutParams(layoutParams1);
|
||||
}
|
||||
|
||||
public void updateSelectedCount(int count, boolean disable) {
|
||||
@ -103,12 +93,10 @@ public class PhotoPickerBottomLayout extends LinearLayout {
|
||||
doneButtonBadgeTextView.setVisibility(View.GONE);
|
||||
|
||||
if (disable) {
|
||||
doneButtonTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.selectphoto_small_grey, 0, 0, 0);
|
||||
doneButtonTextView.setTextColor(0xff999999);
|
||||
doneButton.setEnabled(false);
|
||||
} else {
|
||||
doneButtonTextView.setTextColor(0xffffffff);
|
||||
doneButtonTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.selectphoto_small_active, 0, 0, 0);
|
||||
}
|
||||
} else {
|
||||
doneButtonTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user