DrKLO 8 years ago
parent
commit
0b0d485093
  1. 4
      TMessagesProj/build.gradle
  2. 4
      TMessagesProj/jni/Android.mk
  3. BIN
      TMessagesProj/libs/armeabi-v7a/libtmessages.so
  4. BIN
      TMessagesProj/libs/armeabi/libtmessages.so
  5. BIN
      TMessagesProj/libs/x86/libtmessages.so
  6. 3
      TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java
  7. 28
      TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java
  8. 23
      TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java
  9. 13
      TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java
  10. 97
      TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java
  11. 2
      TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java
  12. 37
      TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java
  13. 85
      TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java
  14. 3
      TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java
  15. 78
      TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java
  16. 79
      TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java
  17. 83
      TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java
  18. 43
      TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarPopupWindow.java
  19. 383
      TMessagesProj/src/main/java/org/telegram/ui/Views/ColorPickerView.java
  20. 41
      TMessagesProj/src/main/res/layout-ar/settings_row_color_layout.xml
  21. 14
      TMessagesProj/src/main/res/layout/settings_color_dialog_layout.xml
  22. 33
      TMessagesProj/src/main/res/layout/settings_row_color_layout.xml
  23. 1
      TMessagesProj/src/main/res/values-ar/strings.xml
  24. 1
      TMessagesProj/src/main/res/values-de/strings.xml
  25. 1
      TMessagesProj/src/main/res/values-es/strings.xml
  26. 1
      TMessagesProj/src/main/res/values-it/strings.xml
  27. 1
      TMessagesProj/src/main/res/values-nl/strings.xml
  28. 1
      TMessagesProj/src/main/res/values-pt-rBR/strings.xml
  29. 1
      TMessagesProj/src/main/res/values-pt-rPT/strings.xml
  30. 1
      TMessagesProj/src/main/res/values/strings.xml
  31. 263
      Tools/EmojiTextureMaker.m

4
TMessagesProj/build.gradle

@ -81,7 +81,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 258
versionName "1.5.5"
versionCode 260
versionName "1.5.6"
}
}

4
TMessagesProj/jni/Android.mk

@ -3,10 +3,10 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE := tmessages
LOCAL_CFLAGS := -w -std=gnu99 -O3 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLOG_DISABLED
LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLOG_DISABLED
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
LOCAL_CPPFLAGS := -DBSD=1 -ffast-math -O3 -funroll-loops
LOCAL_CPPFLAGS := -DBSD=1 -ffast-math -O2 -funroll-loops
#LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := \

BIN
TMessagesProj/libs/armeabi-v7a/libtmessages.so

Binary file not shown.

BIN
TMessagesProj/libs/armeabi/libtmessages.so

Binary file not shown.

BIN
TMessagesProj/libs/x86/libtmessages.so

Binary file not shown.

3
TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java

@ -2584,10 +2584,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
public void tcpConnectionConnected(TcpConnection connection) {
Datacenter datacenter = datacenterWithId(connection.getDatacenterId());
if (datacenter.authKey != null) {
processRequestQueue(connection.transportRequestClass, connection.getDatacenterId());
if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
sendingPushPing = false;
lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 10000;
} else {
processRequestQueue(connection.transportRequestClass, connection.getDatacenterId());
}
}
}

28
TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java

@ -44,18 +44,22 @@ public class FileLog {
return;
}
dateFormat = FastDateFormat.getInstance("dd_MM_yyyy_HH_mm_ss", Locale.US);
File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);
if (sdCard == null) {
return;
}
File dir = new File(sdCard.getAbsolutePath() + "/logs");
if (dir == null) {
return;
}
dir.mkdirs();
currentFile = new File(dir, dateFormat.format(System.currentTimeMillis()) + ".txt");
if (currentFile == null) {
return;
try {
File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);
if (sdCard == null) {
return;
}
File dir = new File(sdCard.getAbsolutePath() + "/logs");
if (dir == null) {
return;
}
dir.mkdirs();
currentFile = new File(dir, dateFormat.format(System.currentTimeMillis()) + ".txt");
if (currentFile == null) {
return;
}
} catch (Exception e) {
e.printStackTrace();
}
try {
currentFile.createNewFile();

23
TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java

@ -12,7 +12,6 @@ import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import org.json.JSONObject;
import org.telegram.ui.ApplicationLoader;
@ -20,7 +19,6 @@ import org.telegram.ui.ApplicationLoader;
public class GcmBroadcastReceiver extends BroadcastReceiver {
public static final int NOTIFICATION_ID = 1;
private static PowerManager.WakeLock wakeLock = null;
private static final Integer sync = 1;
@Override
@ -28,27 +26,6 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
FileLog.d("tmessages", "GCM received intent: " + intent);
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
synchronized (sync) {
try {
if (wakeLock == null) {
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
}
if (!wakeLock.isHeld()) {
wakeLock.acquire(5000);
}
} catch (Exception e) {
try {
if (wakeLock != null) {
wakeLock.release();
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
FileLog.e("tmessages", e);
}
}
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {

13
TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java

@ -4452,6 +4452,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
boolean needVibrate = false;
String choosenSoundPath = null;
int ledColor = 0xff00ff00;
if (chat_id != 0) {
choosenSoundPath = preferences.getString("sound_chat_path_" + chat_id, null);
@ -4461,6 +4462,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath);
}
needVibrate = preferences.getBoolean("EnableVibrateGroup", true);
ledColor = preferences.getInt("GroupLed", 0xff00ff00);
} else if (user_id != 0) {
choosenSoundPath = preferences.getString("sound_path_" + user_id, null);
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
@ -4469,6 +4471,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
}
needVibrate = preferences.getBoolean("EnableVibrateAll", true);
ledColor = preferences.getInt("MessagesLed", 0xff00ff00);
}
if (preferences.contains("color_" + dialog_id)) {
ledColor = preferences.getInt("color_" + dialog_id, 0);
}
if (!needVibrate && vibrate_override == 1) {
@ -4478,6 +4484,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
String name = Utilities.formatName(user.first_name, user.last_name);
if ((int)dialog_id == 0) {
name = LocaleController.getString("AppName", R.string.AppName);
}
String msgShort = msg.replace(name + ": ", "").replace(name + " ", "");
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
@ -4511,7 +4520,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
mBuilder.setContentIntent(contentIntent);
mNotificationManager.cancel(1);
Notification notification = mBuilder.build();
notification.ledARGB = 0xff00ff00;
if (ledColor != 0) {
notification.ledARGB = ledColor;
}
notification.ledOnMS = 1000;
notification.ledOffMS = 1000;
if (needVibrate) {

97
TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java

@ -16,80 +16,20 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class NativeLoader {
private static final long sizes[] = new long[] {
922256, //armeabi
991908, //armeabi-v7a
1713204, //x86
795280, //armeabi
844452, //armeabi-v7a
1242164, //x86
0, //mips
};
private static volatile boolean nativeLoaded = false;
public static void cleanNativeLog(Context context) {
try {
File sdCard = context.getFilesDir();
if (sdCard == null) {
return;
}
File file = new File(sdCard, "nativeer.log");
if (file == null || !file.exists()) {
return;
}
file.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
private static OutputStreamWriter streamWriter = null;
private static FileOutputStream stream = null;
private static void closeStream() {
try {
if (stream != null) {
streamWriter.close();
stream.close();
stream = null;
streamWriter = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeNativeError(Context context, String info, Throwable throwable) {
try {
if (stream == null) {
File sdCard = context.getFilesDir();
if (sdCard == null) {
return;
}
File file = new File(sdCard, "nativeer.log");
if (file == null) {
return;
}
stream = new FileOutputStream(file);
streamWriter = new OutputStreamWriter(stream);
}
streamWriter.write(info + "\n");
streamWriter.write(throwable + "\n");
StackTraceElement[] stack = throwable.getStackTrace();
for (StackTraceElement el : stack) {
streamWriter.write(el + "\n");
}
streamWriter.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
private static File getNativeLibraryDir(Context context) {
File f = null;
if (context != null) {
@ -133,12 +73,10 @@ public class NativeLoader {
nativeLoaded = true;
} catch (Error e) {
FileLog.e("tmessages", e);
writeNativeError(context, "after zip", e);
}
return true;
} catch (Exception e) {
FileLog.e("tmessages", e);
writeNativeError(context, "zip", e);
} finally {
if (stream != null) {
try {
@ -163,8 +101,6 @@ public class NativeLoader {
return;
}
cleanNativeLog(context);
try {
String folder = null;
long libSize = 0;
@ -193,12 +129,17 @@ public class NativeLoader {
}
} catch (Exception e) {
FileLog.e("tmessages", e);
writeNativeError(context, "arch", e);
folder = "armeabi";
libSize = sizes[0];
libSize2 = sizes[1];
}
String javaArch = System.getProperty("os.arch");
if (javaArch != null && javaArch.contains("686")) {
folder = "x86";
libSize = sizes[2];
}
File destFile = getNativeLibraryDir(context);
if (destFile != null) {
destFile = new File(destFile, "libtmessages.so");
@ -207,27 +148,23 @@ public class NativeLoader {
try {
System.loadLibrary("tmessages");
nativeLoaded = true;
closeStream();
return;
} catch (Error e) {
FileLog.e("tmessages", e);
writeNativeError(context, "normal", e);
}
}
}
File destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages.so");
if (destLocalFile.exists()) {
if (destLocalFile != null && destLocalFile.exists()) {
if (destLocalFile.length() == libSize) {
try {
FileLog.d("tmessages", "Load local lib");
System.load(destLocalFile.getAbsolutePath());
nativeLoaded = true;
closeStream();
return;
} catch (Error e) {
FileLog.e("tmessages", e);
writeNativeError(context, "local", e);
}
} else {
destLocalFile.delete();
@ -236,21 +173,23 @@ public class NativeLoader {
FileLog.e("tmessages", "Library not found, arch = " + folder);
if (!loadFromZip(context, destLocalFile, folder) && folder.equals("armeabi-v7a")) {
folder = "armeabi";
loadFromZip(context, destLocalFile, folder);
if (!loadFromZip(context, destLocalFile, folder)) {
folder = "x86";
destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages86.so");
if (!loadFromZip(context, destLocalFile, folder)) {
destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessagesarm.so");
folder = "armeabi";
loadFromZip(context, destLocalFile, folder);
}
}
} catch (Throwable e) {
e.printStackTrace();
writeNativeError(context, "", e);
}
try {
System.loadLibrary("tmessages");
nativeLoaded = true;
closeStream();
} catch (Error e) {
writeNativeError(context, "last chance", e);
FileLog.e("tmessages", e);
}
}

2
TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java

@ -19,9 +19,11 @@ public class ScreenReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
FileLog.e("tmessages", "screen off");
ApplicationLoader.lastPauseTime = System.currentTimeMillis();
ApplicationLoader.isScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
FileLog.e("tmessages", "screen on");
ApplicationLoader.resetLastPauseTime();
ApplicationLoader.isScreenOn = true;
}
}

37
TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java

@ -39,7 +39,6 @@ import net.hockeyapp.android.UpdateManager;
import org.telegram.ui.ApplicationLoader;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -47,7 +46,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
@ -997,41 +995,6 @@ public class Utilities {
public boolean includeDeviceData() {
return true;
}
@Override
public String getDescription() {
String description = "";
try {
File sdCard = ApplicationLoader.applicationContext.getFilesDir();
if (sdCard == null) {
return description;
}
File file = new File(sdCard, "nativeer.log");
if (file == null || !file.exists()) {
return description;
}
FileInputStream inputStream = new FileInputStream(file);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
log.append("\n");
}
bufferedReader.close();
inputStream.close();
description = log.toString();
NativeLoader.cleanNativeLog(ApplicationLoader.applicationContext);
} catch (Exception e) {
e.printStackTrace();
}
return description;
}
});
}

85
TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java

@ -47,6 +47,7 @@ import org.telegram.ui.Views.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.AvatarUpdater;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import org.telegram.ui.Views.ColorPickerView;
import java.util.ArrayList;
import java.util.Collections;
@ -71,10 +72,12 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
private int settingsSectionRow;
private int settingsNotificationsRow;
private int settingsVibrateRow;
private int settingsLedRow;
private int settingsSoundRow;
private int sharedMediaSectionRow;
private int sharedMediaRow;
private int membersSectionRow;
private int membersEndRow;
private int addMemberRow;
private int leaveGroupRow;
private int rowCount = 0;
@ -140,18 +143,21 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
settingsSectionRow = rowCount++;
settingsNotificationsRow = rowCount++;
settingsVibrateRow = rowCount++;
settingsLedRow = rowCount++;
settingsSoundRow = rowCount++;
sharedMediaSectionRow = rowCount++;
sharedMediaRow = rowCount++;
if (info != null && !(info instanceof TLRPC.TL_chatParticipantsForbidden)) {
membersSectionRow = rowCount++;
rowCount += info.participants.size();
membersEndRow = rowCount;
if (info.participants.size() < 200) {
addMemberRow = rowCount++;
} else {
addMemberRow = -1;
}
} else {
membersEndRow = -1;
addMemberRow = -1;
membersSectionRow = -1;
}
@ -197,7 +203,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i > membersSectionRow && i < addMemberRow) {
if (i > membersSectionRow && i < membersEndRow) {
if (getParentActivity() == null) {
return false;
}
@ -268,7 +274,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
presentFragment(new MediaActivity(args));
} else if (i == addMemberRow) {
openAddMenu();
} else if (i > membersSectionRow && i < addMemberRow) {
} else if (i > membersSectionRow && i < membersEndRow) {
int user_id = info.participants.get(sortedUsers.get(i - membersSectionRow - 1)).user_id;
if (user_id == UserConfig.getClientUserId()) {
return;
@ -304,6 +310,56 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == settingsLedRow) {
if (getParentActivity() == null) {
return;
}
LayoutInflater li = (LayoutInflater)getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_color_dialog_layout, null, false);
final ColorPickerView colorPickerView = (ColorPickerView)view.findViewById(R.id.color_picker);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (preferences.contains("color_" + (-chat_id))) {
colorPickerView.setOldCenterColor(preferences.getInt("color_" + (-chat_id), 0xff00ff00));
} else {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("color_" + (-chat_id), colorPickerView.getColor());
editor.commit();
listView.invalidateViews();
}
});
builder.setNeutralButton(LocaleController.getString("Disabled", R.string.Disabled), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("color_" + (-chat_id), 0);
editor.commit();
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.remove("color_" + (-chat_id));
editor.commit();
listView.invalidateViews();
}
});
showAlertDialog(builder);
}
}
});
@ -588,7 +644,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
@Override
public boolean isEnabled(int i) {
return i == settingsNotificationsRow || i == settingsSoundRow || i == sharedMediaRow || i > membersSectionRow && i <= addMemberRow || i == settingsVibrateRow;
return i == settingsNotificationsRow || i == settingsSoundRow || i == sharedMediaRow || i == addMemberRow || i > membersSectionRow && i < membersEndRow || i == settingsVibrateRow || i == settingsLedRow;
}
@Override
@ -830,6 +886,23 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
textView.setText(LocaleController.getString("Sound", R.string.Sound));
divider.setVisibility(View.INVISIBLE);
}
} else if (type == 7) {
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_row_color_layout, viewGroup, false);
}
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
View colorView = view.findViewById(R.id.settings_color);
View divider = view.findViewById(R.id.settings_row_divider);
textView.setText(LocaleController.getString("LedColor", R.string.LedColor));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (preferences.contains("color_" + (-chat_id))) {
colorView.setBackgroundColor(preferences.getInt("color_" + (-chat_id), 0xff00ff00));
} else {
colorView.setBackgroundColor(preferences.getInt("GroupLed", 0xff00ff00));
}
divider.setVisibility(View.VISIBLE);
}
return view;
}
@ -848,15 +921,17 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
return 4;
} else if (i == leaveGroupRow) {
return 5;
} else if (i > membersSectionRow && i < addMemberRow) {
} else if (i > membersSectionRow && i < membersEndRow) {
return 3;
} else if (i == settingsLedRow) {
return 7;
}
return 0;
}
@Override
public int getViewTypeCount() {
return 7;
return 8;
}
@Override

3
TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java

@ -100,6 +100,9 @@ public class PhotoCropActivity extends BaseFragment {
} else {
draggingState = 0;
}
if (draggingState != 0) {
PhotoCropView.this.requestDisallowInterceptTouchEvent(true);
}
oldX = x;
oldY = y;
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

78
TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java

@ -39,6 +39,7 @@ import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import org.telegram.ui.Views.ColorPickerView;
public class SettingsNotificationsActivity extends BaseFragment {
private ListView listView;
@ -50,11 +51,13 @@ public class SettingsNotificationsActivity extends BaseFragment {
private int messagePreviewRow;
private int messageVibrateRow;
private int messageSoundRow;
private int messageLedRow;
private int groupSectionRow;
private int groupAlertRow;
private int groupPreviewRow;
private int groupVibrateRow;
private int groupSoundRow;
private int groupLedRow;
private int inappSectionRow;
private int inappSoundRow;
private int inappVibrateRow;
@ -74,11 +77,13 @@ public class SettingsNotificationsActivity extends BaseFragment {
messageAlertRow = rowCount++;
messagePreviewRow = rowCount++;
messageVibrateRow = rowCount++;
messageLedRow = rowCount++;
messageSoundRow = rowCount++;
groupSectionRow = rowCount++;
groupAlertRow = rowCount++;
groupPreviewRow = rowCount++;
groupVibrateRow = rowCount++;
groupLedRow = rowCount++;
groupSoundRow = rowCount++;
inappSectionRow = rowCount++;
inappSoundRow = rowCount++;
@ -110,12 +115,12 @@ public class SettingsNotificationsActivity extends BaseFragment {
});
fragmentView = inflater.inflate(R.layout.settings_layout, container, false);
ListAdapter listAdapter = new ListAdapter(getParentActivity());
final ListAdapter listAdapter = new ListAdapter(getParentActivity());
listView = (ListView)fragmentView.findViewById(R.id.listView);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == messageAlertRow || i == groupAlertRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
@ -289,6 +294,54 @@ public class SettingsNotificationsActivity extends BaseFragment {
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
} else if (i == messageLedRow || i == groupLedRow) {
if (getParentActivity() == null) {
return;
}
LayoutInflater li = (LayoutInflater)getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_color_dialog_layout, null, false);
final ColorPickerView colorPickerView = (ColorPickerView)view.findViewById(R.id.color_picker);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messageLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
} else if (i == groupLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageLedRow) {
editor.putInt("MessagesLed", colorPickerView.getColor());
} else if (i == groupLedRow) {
editor.putInt("GroupLed", colorPickerView.getColor());
}
editor.commit();
listView.invalidateViews();
}
});
builder.setNeutralButton(LocaleController.getString("Disabled", R.string.Disabled), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageLedRow) {
editor.putInt("MessagesLed", 0);
} else if (i == groupLedRow) {
editor.putInt("GroupLed", 0);
}
editor.commit();
listView.invalidateViews();
}
});
showAlertDialog(builder);
}
}
});
@ -501,8 +554,23 @@ public class SettingsNotificationsActivity extends BaseFragment {
textViewDetail.setText(LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom));
divider.setVisibility(View.INVISIBLE);
}
} else if (type == 3) {
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_row_color_layout, viewGroup, false);
}
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
View colorView = view.findViewById(R.id.settings_color);
View divider = view.findViewById(R.id.settings_row_divider);
textView.setText(LocaleController.getString("LedColor", R.string.LedColor));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messageLedRow) {
colorView.setBackgroundColor(preferences.getInt("MessagesLed", 0xff00ff00));
} else if (i == groupLedRow) {
colorView.setBackgroundColor(preferences.getInt("GroupLed", 0xff00ff00));
}
divider.setVisibility(View.VISIBLE);
}
return view;
}
@ -516,6 +584,8 @@ public class SettingsNotificationsActivity extends BaseFragment {
i == contactJoinedRow ||
i == pebbleAlertRow || i == notificationsServiceRow) {
return 1;
} else if (i == messageLedRow || i == groupLedRow) {
return 3;
} else {
return 2;
}
@ -523,7 +593,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
@Override
public int getViewTypeCount() {
return 3;
return 4;
}
@Override

79
TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java

@ -48,6 +48,7 @@ import org.telegram.ui.Views.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import org.telegram.ui.Views.ColorPickerView;
import org.telegram.ui.Views.IdenticonView;
import java.util.ArrayList;
@ -79,6 +80,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
private int settingsSoundRow;
private int sharedMediaSectionRow;
private int sharedMediaRow;
private int settingsLedRow;
private int rowCount = 0;
public UserProfileActivity(Bundle args) {
@ -126,6 +128,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
settingsNotificationsRow = rowCount++;
settingsVibrateRow = rowCount++;
settingsLedRow = rowCount++;
settingsSoundRow = rowCount++;
sharedMediaSectionRow = rowCount++;
sharedMediaRow = rowCount++;
@ -373,6 +376,57 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == settingsLedRow) {
if (getParentActivity() == null) {
return;
}
LayoutInflater li = (LayoutInflater)getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_color_dialog_layout, null, false);
final ColorPickerView colorPickerView = (ColorPickerView)view.findViewById(R.id.color_picker);
final String key = dialog_id == 0 ? "color_" + user_id : "color_" + dialog_id;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (preferences.contains(key)) {
colorPickerView.setOldCenterColor(preferences.getInt(key, 0xff00ff00));
} else {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt(key, colorPickerView.getColor());
editor.commit();
listView.invalidateViews();
}
});
builder.setNeutralButton(LocaleController.getString("Disabled", R.string.Disabled), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt(key, 0);
editor.commit();
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.remove(key);
editor.commit();
listView.invalidateViews();
}
});
showAlertDialog(builder);
}
}
});
@ -589,7 +643,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
@Override
public boolean isEnabled(int i) {
return i == phoneRow || i == settingsTimerRow || i == settingsKeyRow || i == settingsNotificationsRow || i == sharedMediaRow || i == settingsSoundRow || i == settingsVibrateRow;
return i == phoneRow || i == settingsTimerRow || i == settingsKeyRow || i == settingsNotificationsRow || i == sharedMediaRow || i == settingsSoundRow || i == settingsVibrateRow || i == settingsLedRow;
}
@Override
@ -846,8 +900,25 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
textView.setText(LocaleController.getString("Sound", R.string.Sound));
divider.setVisibility(View.INVISIBLE);
}
}
} else if (type == 6) {
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_row_color_layout, viewGroup, false);
}
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
View colorView = view.findViewById(R.id.settings_color);
View divider = view.findViewById(R.id.settings_row_divider);
textView.setText(LocaleController.getString("LedColor", R.string.LedColor));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
String key = dialog_id == 0 ? "color_" + user_id : "color_" + dialog_id;
if (preferences.contains(key)) {
colorView.setBackgroundColor(preferences.getInt(key, 0xff00ff00));
} else {
colorView.setBackgroundColor(preferences.getInt("MessagesLed", 0xff00ff00));
}
divider.setVisibility(View.VISIBLE);
}
return view;
}
@ -865,13 +936,15 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
return 4;
} else if (i == settingsSoundRow) {
return 5;
} else if (i == settingsLedRow) {
return 6;
}
return 0;
}
@Override
public int getViewTypeCount() {
return 6;
return 7;
}
@Override

83
TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java

@ -9,13 +9,14 @@
package org.telegram.ui.Views.ActionBar;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.Rect;
import android.os.Build;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
@ -38,13 +39,16 @@ public class ActionBarMenuItem extends ImageView {
public abstract void onTextChanged(EditText editText);
}
private LinearLayout popupLayout;
private ActionBarPopupWindow.ActionBarPopupWindowLayout popupLayout;
private ActionBarMenu parentMenu;
private ActionBarPopupWindow popupWindow;
private ActionBar parentActionBar;
private EditText searchField;
private boolean isSearchField = false;
private ActionBarMenuItemSearchListener listener;
private Rect rect = null;
private int[] location = null;
private View selectedMenuView = null;
public ActionBarMenuItem(Context context, ActionBarMenu menu, ActionBar actionBar, int background) {
super(context);
@ -65,11 +69,82 @@ public class ActionBarMenuItem extends ImageView {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) {
if (event.getY() > getHeight()) {
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
toggleSubMenu();
return true;
}
} else if (popupWindow != null && popupWindow.isShowing()) {
getLocationOnScreen(location);
float x = event.getX() + location[0];
float y = event.getY() + location[1];
popupLayout.getLocationOnScreen(location);
x -= location[0];
y -= location[1];
selectedMenuView = null;
for (int a = 0; a < popupLayout.getChildCount(); a++) {
View child = popupLayout.getChildAt(a);
child.getHitRect(rect);
if ((Integer)child.getTag() < 100) {
if (!rect.contains((int)x, (int)y)) {
child.setSelected(false);
} else {
child.setSelected(true);
selectedMenuView = child;
}
}
}
}
} else if (popupWindow != null && popupWindow.isShowing() && event.getActionMasked() == MotionEvent.ACTION_UP) {
if (selectedMenuView != null) {
selectedMenuView.setSelected(false);
parentMenu.onItemClick((Integer) selectedMenuView.getTag());
}
popupWindow.dismiss();
} else {
if (selectedMenuView != null) {
selectedMenuView.setSelected(false);
selectedMenuView = null;
}
}
return super.onTouchEvent(event);
}
public void addSubItem(int id, String text, int icon) {
if (popupLayout == null) {
popupLayout = new LinearLayout(getContext());
rect = new Rect();
location = new int[2];
popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
popupLayout.setOrientation(LinearLayout.VERTICAL);
popupLayout.setBackgroundResource(R.drawable.popup_fixed);
popupLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (popupWindow != null && popupWindow.isShowing()) {
v.getHitRect(rect);
if (!rect.contains((int)event.getX(), (int)event.getY())) {
popupWindow.dismiss();
}
}
}
return false;
}
});
popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
@Override
public void onDispatchKeyEvent(KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
}
}
});
}
if (popupLayout.getChildCount() != 0) {
View delimeter = new View(getContext());
@ -121,7 +196,7 @@ public class ActionBarMenuItem extends ImageView {
}
if (popupWindow == null) {
popupWindow = new ActionBarPopupWindow(popupLayout, FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
popupWindow.setClippingEnabled(true);
popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);

43
TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarPopupWindow.java

@ -12,8 +12,10 @@ package org.telegram.ui.Views.ActionBar;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import java.lang.reflect.Field;
@ -41,6 +43,39 @@ public class ActionBarPopupWindow extends PopupWindow {
private ViewTreeObserver.OnScrollChangedListener mSuperScrollListener;
private ViewTreeObserver mViewTreeObserver;
public static interface OnDispatchKeyEventListener {
public void onDispatchKeyEvent(KeyEvent keyEvent);
}
public static class ActionBarPopupWindowLayout extends LinearLayout {
private OnDispatchKeyEventListener mOnDispatchKeyEventListener;
public ActionBarPopupWindowLayout(Context context) {
super(context);
}
public ActionBarPopupWindowLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ActionBarPopupWindowLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setDispatchKeyEventListener(OnDispatchKeyEventListener listener) {
mOnDispatchKeyEventListener = listener;
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (mOnDispatchKeyEventListener != null) {
mOnDispatchKeyEventListener.onDispatchKeyEvent(event);
}
return super.dispatchKeyEvent(event);
}
}
public ActionBarPopupWindow() {
super();
init();
@ -98,7 +133,6 @@ public class ActionBarPopupWindow extends PopupWindow {
}
private void unregisterListener() {
// Don't do anything if we haven't managed to patch the super listener
if (mSuperScrollListener != null && mViewTreeObserver != null) {
if (mViewTreeObserver.isAlive()) {
mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
@ -108,13 +142,8 @@ public class ActionBarPopupWindow extends PopupWindow {
}
private void registerListener(View anchor) {
// Don't do anything if we haven't managed to patch the super listener.
// And don't bother attaching the listener if the anchor view isn't
// attached. This means we'll only have to deal with the real VTO owned
// by the ViewRoot.
if (mSuperScrollListener != null) {
ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver()
: null;
ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
if (vto != mViewTreeObserver) {
if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);

383
TMessagesProj/src/main/java/org/telegram/ui/Views/ColorPickerView.java

@ -0,0 +1,383 @@
/*
* Copyright 2012 Lars Werkman
*
* 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.Views;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import org.telegram.messenger.Utilities;
public class ColorPickerView extends View {
private static final String STATE_PARENT = "parent";
private static final String STATE_ANGLE = "angle";
private static final String STATE_OLD_COLOR = "color";
private static final String STATE_SHOW_OLD_COLOR = "showColor";
private static final int[] COLORS = new int[] { 0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00, 0xFFFFFF00, 0xFFFF0000 };
private Paint mColorWheelPaint;
private Paint mPointerHaloPaint;
private Paint mPointerColor;
private int mColorWheelThickness;
private int mColorWheelRadius;
private int mPreferredColorWheelRadius;
private int mColorCenterRadius;
private int mPreferredColorCenterRadius;
private int mColorCenterHaloRadius;
private int mPreferredColorCenterHaloRadius;
private int mColorPointerRadius;
private int mColorPointerHaloRadius;
private RectF mColorWheelRectangle = new RectF();
private RectF mCenterRectangle = new RectF();
private boolean mUserIsMovingPointer = false;
private int mCenterOldColor;
private boolean mShowCenterOldColor;
private int mCenterNewColor;
private float mTranslationOffset;
private float mSlopX;
private float mSlopY;
private float mAngle;
private Paint mCenterOldPaint;
private Paint mCenterNewPaint;
private Paint mCenterHaloPaint;
private float[] mHSV = new float[3];
private OnColorChangedListener onColorChangedListener;
private OnColorSelectedListener onColorSelectedListener;
private int oldChangedListenerColor;
private int oldSelectedListenerColor;
public ColorPickerView(Context context) {
super(context);
init(null, 0);
}
public ColorPickerView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, 0);
}
public ColorPickerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs, defStyle);
}
public interface OnColorChangedListener {
public void onColorChanged(int color);
}
public interface OnColorSelectedListener {
public void onColorSelected(int color);
}
public void setOnColorChangedListener(OnColorChangedListener listener) {
this.onColorChangedListener = listener;
}
public void setOnColorSelectedListener(OnColorSelectedListener listener) {
this.onColorSelectedListener = listener;
}
private void init(AttributeSet attrs, int defStyle) {
mColorWheelThickness = Utilities.dp(8);
mColorWheelRadius = Utilities.dp(124);
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = Utilities.dp(54);
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = Utilities.dp(60);
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = Utilities.dp(14);
mColorPointerHaloRadius = Utilities.dp(18);
mAngle = (float) (-Math.PI / 2);
Shader s = new SweepGradient(0, 0, COLORS, null);
mColorWheelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mColorWheelPaint.setShader(s);
mColorWheelPaint.setStyle(Paint.Style.STROKE);
mColorWheelPaint.setStrokeWidth(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}
@Override
protected void onDraw(Canvas canvas) {
canvas.translate(mTranslationOffset, mTranslationOffset);
canvas.drawOval(mColorWheelRectangle, mColorWheelPaint);
float[] pointerPosition = calculatePointerPosition(mAngle);
canvas.drawCircle(pointerPosition[0], pointerPosition[1], mColorPointerHaloRadius, mPointerHaloPaint);
canvas.drawCircle(pointerPosition[0], pointerPosition[1], mColorPointerRadius, mPointerColor);
canvas.drawCircle(0, 0, mColorCenterHaloRadius, mCenterHaloPaint);
if (mShowCenterOldColor) {
canvas.drawArc(mCenterRectangle, 90, 180, true, mCenterOldPaint);
canvas.drawArc(mCenterRectangle, 270, 180, true, mCenterNewPaint);
} else {
canvas.drawArc(mCenterRectangle, 0, 360, true, mCenterNewPaint);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int intrinsicSize = 2 * (mPreferredColorWheelRadius + mColorPointerHaloRadius);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int width;
int height;
if (widthMode == MeasureSpec.EXACTLY) {
width = widthSize;
} else if (widthMode == MeasureSpec.AT_MOST) {
width = Math.min(intrinsicSize, widthSize);
} else {
width = intrinsicSize;
}
if (heightMode == MeasureSpec.EXACTLY) {
height = heightSize;
} else if (heightMode == MeasureSpec.AT_MOST) {
height = Math.min(intrinsicSize, heightSize);
} else {
height = intrinsicSize;
}
int min = Math.min(width, height);
setMeasuredDimension(min, min);
mTranslationOffset = min * 0.5f;
mColorWheelRadius = min / 2 - mColorWheelThickness - mColorPointerHaloRadius;
mColorWheelRectangle.set(-mColorWheelRadius, -mColorWheelRadius, mColorWheelRadius, mColorWheelRadius);
mColorCenterRadius = (int) ((float) mPreferredColorCenterRadius * ((float) mColorWheelRadius / (float) mPreferredColorWheelRadius));
mColorCenterHaloRadius = (int) ((float) mPreferredColorCenterHaloRadius * ((float) mColorWheelRadius / (float) mPreferredColorWheelRadius));
mCenterRectangle.set(-mColorCenterRadius, -mColorCenterRadius, mColorCenterRadius, mColorCenterRadius);
}
private int ave(int s, int d, float p) {
return s + java.lang.Math.round(p * (d - s));
}
private int calculateColor(float angle) {
float unit = (float) (angle / (2 * Math.PI));
if (unit < 0) {