Skip to content

Commit ce33df0

Browse files
author
DrKLO
committed
More Android L design
1 parent f7b14c1 commit ce33df0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+380
-230
lines changed

TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,22 @@ public static void lockOrientation(Activity activity) {
7171
if (manager != null && manager.getDefaultDisplay() != null) {
7272
int rotation = manager.getDefaultDisplay().getRotation();
7373
int orientation = activity.getResources().getConfiguration().orientation;
74+
int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8;
75+
int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9;
76+
if (Build.VERSION.SDK_INT < 9) {
77+
SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
78+
SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
79+
}
7480

7581
if (rotation == Surface.ROTATION_270) {
7682
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
7783
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
7884
} else {
79-
if (Build.VERSION.SDK_INT >= 9) {
80-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
81-
} else {
82-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
83-
}
85+
activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
8486
}
8587
} else if (rotation == Surface.ROTATION_90) {
8688
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
87-
if (Build.VERSION.SDK_INT >= 9) {
88-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
89-
} else {
90-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
91-
}
89+
activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT);
9290
} else {
9391
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
9492
}
@@ -100,17 +98,9 @@ public static void lockOrientation(Activity activity) {
10098
}
10199
} else {
102100
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
103-
if (Build.VERSION.SDK_INT >= 9) {
104-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
105-
} else {
106-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
107-
}
101+
activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
108102
} else {
109-
if (Build.VERSION.SDK_INT >= 9) {
110-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
111-
} else {
112-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
113-
}
103+
activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT);
114104
}
115105
}
116106
}
@@ -472,7 +462,7 @@ public static Point getRealScreenSize() {
472462
return size;
473463
}
474464

475-
public static void setListViewEdgeEffectColor(ListView listView, int color) {
465+
public static void setListViewEdgeEffectColor(AbsListView listView, int color) {
476466
if (Build.VERSION.SDK_INT >= 21) {
477467
try {
478468
Field field = AbsListView.class.getDeclaredField("mEdgeGlowTop");

TMessagesProj/src/main/java/org/telegram/android/ContactsController.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.concurrent.ConcurrentHashMap;
4242

4343
public class ContactsController {
44+
4445
private Account currentAccount;
4546
private boolean loadingContacts = false;
4647
private static final Object loadContactsSync = new Object();
@@ -108,6 +109,13 @@ public static ContactsController getInstance() {
108109
return localInstance;
109110
}
110111

112+
public ContactsController() {
113+
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
114+
if (preferences.getBoolean("needGetStatuses", false)) {
115+
reloadContactsStatuses();
116+
}
117+
}
118+
111119
public void cleanup() {
112120
contactsBook.clear();
113121
contactsBookSPhones.clear();
@@ -1577,6 +1585,42 @@ public void run() {
15771585
}, true, RPCRequest.RPCRequestClassGeneric);
15781586
}
15791587

1588+
public void reloadContactsStatuses() {
1589+
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
1590+
final SharedPreferences.Editor editor = preferences.edit();
1591+
editor.putBoolean("needGetStatuses", true).commit();
1592+
TLRPC.TL_contacts_getStatuses req = new TLRPC.TL_contacts_getStatuses();
1593+
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
1594+
@Override
1595+
public void run(final TLObject response, TLRPC.TL_error error) {
1596+
if (error == null) {
1597+
AndroidUtilities.runOnUIThread(new Runnable() {
1598+
@Override
1599+
public void run() {
1600+
editor.remove("needGetStatuses").commit();
1601+
TLRPC.Vector vector = (TLRPC.Vector) response;
1602+
if (!vector.objects.isEmpty()) {
1603+
ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<TLRPC.User>();
1604+
for (Object object : vector.objects) {
1605+
TLRPC.User toDbUser = new TLRPC.User();
1606+
TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;
1607+
TLRPC.User user = MessagesController.getInstance().getUser(status.user_id);
1608+
if (user != null) {
1609+
user.status = status.status;
1610+
}
1611+
toDbUser.status = status.status;
1612+
dbUsersStatus.add(toDbUser);
1613+
}
1614+
MessagesStorage.getInstance().updateUsers(dbUsersStatus, true, true, true);
1615+
}
1616+
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_STATUS);
1617+
}
1618+
});
1619+
}
1620+
}
1621+
});
1622+
}
1623+
15801624
public void loadPrivacySettings() {
15811625
if (loadingDeleteInfo == 0) {
15821626
loadingDeleteInfo = 1;
@@ -1650,6 +1694,7 @@ public ArrayList<TLRPC.PrivacyRule> getPrivacyRules() {
16501694
public void setPrivacyRules(ArrayList<TLRPC.PrivacyRule> rules) {
16511695
privacyRules = rules;
16521696
NotificationCenter.getInstance().postNotificationName(NotificationCenter.privacyRulesUpdated);
1697+
reloadContactsStatuses();
16531698
}
16541699

16551700
public static String formatName(String firstName, String lastName) {

TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,9 @@ public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxH
11171117
return b;
11181118
}
11191119

1120-
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache) throws Exception {
1120+
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway) throws Exception {
11211121
Bitmap scaledBitmap = null;
1122-
if (scaleFactor > 1) {
1122+
if (scaleFactor > 1 || scaleAnyway) {
11231123
scaledBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
11241124
} else {
11251125
scaledBitmap = bitmap;
@@ -1171,6 +1171,10 @@ private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, i
11711171
}
11721172

11731173
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache) {
1174+
return scaleAndSaveImage(bitmap, maxWidth, maxHeight, quality, cache, 0, 0);
1175+
}
1176+
1177+
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache, int minWidth, int minHeight) {
11741178
if (bitmap == null) {
11751179
return null;
11761180
}
@@ -1179,21 +1183,26 @@ public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, f
11791183
if (photoW == 0 || photoH == 0) {
11801184
return null;
11811185
}
1186+
boolean scaleAnyway = false;
11821187
float scaleFactor = Math.max(photoW / maxWidth, photoH / maxHeight);
1188+
if (scaleFactor < 1 && minWidth != 0 && minHeight != 0) {
1189+
scaleFactor = Math.max(photoW / minWidth, photoH / minHeight);
1190+
scaleAnyway = true;
1191+
}
11831192
int w = (int)(photoW / scaleFactor);
11841193
int h = (int)(photoH / scaleFactor);
11851194
if (h == 0 || w == 0) {
11861195
return null;
11871196
}
11881197

11891198
try {
1190-
return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache);
1199+
return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway);
11911200
} catch (Throwable e) {
11921201
FileLog.e("tmessages", e);
11931202
ImageLoader.getInstance().clearMemory();
11941203
System.gc();
11951204
try {
1196-
return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache);
1205+
return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway);
11971206
} catch (Throwable e2) {
11981207
FileLog.e("tmessages", e2);
11991208
return null;

TMessagesProj/src/main/java/org/telegram/android/MessagesController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,10 +1375,11 @@ public void processLoadedMessages(final TLRPC.messages_Messages messagesRes, fin
13751375
@Override
13761376
public void run() {
13771377
int lower_id = (int)dialog_id;
1378+
int high_id = (int)(dialog_id >> 32);
13781379
if (!isCache) {
13791380
MessagesStorage.getInstance().putMessages(messagesRes, dialog_id);
13801381
}
1381-
if (lower_id != 0 && isCache && messagesRes.messages.size() == 0 && (load_type == 0 || load_type == 2 || load_type == 3)) {
1382+
if (high_id != 1 && lower_id != 0 && isCache && messagesRes.messages.size() == 0 && (load_type == 0 || load_type == 2 || load_type == 3)) {
13821383
AndroidUtilities.runOnUIThread(new Runnable() {
13831384
@Override
13841385
public void run() {

TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,20 @@ public void serializeToStream(AbsSerializedData stream) {
272272
}
273273

274274
public static class TL_contactStatus extends TLObject {
275-
public static int constructor = 0xaa77b873;
275+
public static int constructor = 0xd3680c61;
276276

277277
public int user_id;
278-
public int expires;
278+
public UserStatus status;
279279

280280
public void readParams(AbsSerializedData stream) {
281281
user_id = stream.readInt32();
282-
expires = stream.readInt32();
282+
status = (UserStatus)TLClassStore.Instance().TLdeserialize(stream, stream.readInt32());
283283
}
284284

285285
public void serializeToStream(AbsSerializedData stream) {
286286
stream.writeInt32(constructor);
287287
stream.writeInt32(user_id);
288-
stream.writeInt32(expires);
288+
status.serializeToStream(stream);
289289
}
290290
}
291291

@@ -7389,6 +7389,18 @@ public void serializeToStream(AbsSerializedData stream) {
73897389
public static class TL_contacts_getStatuses extends TLObject {
73907390
public static int constructor = 0xc4a353ee;
73917391

7392+
public ArrayList<TL_contactStatus> id = new ArrayList<TL_contactStatus>();
7393+
7394+
public Class responseClass () {
7395+
return Vector.class;
7396+
}
7397+
7398+
public void parseVector(Vector vector, AbsSerializedData data) {
7399+
int size = data.readInt32();
7400+
for (int a = 0; a < size; a++) {
7401+
vector.objects.add(TLClassStore.Instance().TLdeserialize(data, data.readInt32()));
7402+
}
7403+
}
73927404

73937405
public void serializeToStream(AbsSerializedData stream) {
73947406
stream.writeInt32(constructor);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static class TPFactorizedValue {
114114
private native static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, int offset, int length);
115115

116116
public static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, boolean changeIv, int offset, int length) {
117-
aesIgeEncryption(buffer, key, changeIv ? iv : iv.clone(), encrypt, offset, length);
117+
aesIgeEncryption(buffer, key, changeIv ? iv : (byte [])iv.clone(), encrypt, offset, length);
118118
}
119119

120120
public static Integer parseInt(String value) {
@@ -640,7 +640,7 @@ public static CharSequence generateSearchName(String name, String name2, String
640640
builder.append(" ");
641641
}
642642
query.trim();
643-
builder.append(Html.fromHtml("<font color=\"#548ab6\">" + query + "</font>"));
643+
builder.append(Html.fromHtml("<font color=\"#4d83b3\">" + query + "</font>"));
644644

645645
lastIndex = end;
646646
}

TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ public void onAnimationEnd(Object animation) {
633633
currentAnimation.start();
634634
}
635635
} else {
636+
if (backgroundView != null) {
637+
ViewProxy.setAlpha(backgroundView, 1.0f);
638+
backgroundView.setVisibility(VISIBLE);
639+
}
636640
fragment.onOpenAnimationEnd();
637641
}
638642
return true;
@@ -789,6 +793,10 @@ public void showLastFragment() {
789793
if (removeActionBarExtraHeight) {
790794
previousFragment.actionBar.setOccupyStatusBar(false);
791795
}
796+
ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
797+
if (parent != null) {
798+
parent.removeView(previousFragment.actionBar);
799+
}
792800
containerView.addView(previousFragment.actionBar);
793801
}
794802
containerView.addView(fragmentView);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
264264

265265
private int getBottomOffsetY() {
266266
getLocationOnScreen(location);
267-
int diff = location[1] - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0) + getMeasuredHeight() - menuHeight;
267+
int diff = location[1] - AndroidUtilities.statusBarHeight + getMeasuredHeight() - menuHeight;
268268
int y = AndroidUtilities.dp(8) - menuHeight;
269269
if (diff < 0) {
270270
y -= diff;

TMessagesProj/src/main/java/org/telegram/ui/ActionBar/DrawerLayoutContainer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ public void onAnimationCancel(Object animator) {
218218
}
219219

220220
private void onDrawerAnimationEnd(boolean opened) {
221-
AndroidUtilities.unlockOrientation((Activity) getContext());
222221
startedTracking = false;
223222
currentAnimation = null;
224223
drawerOpened = opened;
@@ -257,7 +256,6 @@ private void prepareForDrawerOpen(MotionEvent ev) {
257256
startedTrackingX = (int) ev.getX();
258257
}
259258
beginTrackingSent = false;
260-
AndroidUtilities.lockOrientation((Activity)getContext());
261259
}
262260

263261
public boolean isDrawerOpened() {

TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsSearchAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public View getView(int i, View view, ViewGroup viewGroup) {
234234
}
235235
} else if (i > searchResult.size() && user.username != null) {
236236
try {
237-
username = Html.fromHtml(String.format("<font color=\"#548ab6\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
237+
username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
238238
} catch (Exception e) {
239239
username = user.username;
240240
FileLog.e("tmessages", e);

0 commit comments

Comments
 (0)