From 2c61da0001b57fe7a39229021123a1fe82e3e4b4 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Wed, 4 Jun 2014 20:00:42 +0400 Subject: [PATCH] Fixed app startup on Android 2.x, crash fixes --- TMessagesProj/build.gradle | 2 +- .../java/org/telegram/ui/ChatActivity.java | 3 + .../org/telegram/ui/ChatProfileActivity.java | 1 + .../ui/ChatProfileChangeNameActivity.java | 1 + .../org/telegram/ui/ContactAddActivity.java | 1 + .../org/telegram/ui/ContactsActivity.java | 6 +- .../telegram/ui/CountrySelectActivity.java | 6 +- .../telegram/ui/DocumentSelectActivity.java | 1 + .../org/telegram/ui/IdenticonActivity.java | 1 + .../telegram/ui/LanguageSelectActivity.java | 6 +- .../java/org/telegram/ui/LaunchActivity.java | 23 +-- .../java/org/telegram/ui/MediaActivity.java | 1 + .../org/telegram/ui/MessagesActivity.java | 6 +- .../org/telegram/ui/SettingsActivity.java | 1 + .../org/telegram/ui/SettingsBlockedUsers.java | 1 + .../ui/SettingsChangeNameActivity.java | 1 + .../ui/SettingsWallpapersActivity.java | 1 + .../org/telegram/ui/UserProfileActivity.java | 1 + .../ui/Views/ActionBar/ActionBarActivity.java | 18 +- .../ui/Views/ActionBar/ActionBarLayer.java | 6 + .../ui/Views/ActionBar/ActionBarMenu.java | 2 +- .../ui/Views/ActionBar/ActionBarMenuItem.java | 11 +- .../Views/ActionBar/ActionBarPopupWindow.java | 158 ++++++++++++++++++ .../ui/Views/ActionBar/BaseFragment.java | 13 +- TMessagesProj/src/main/res/values/styles.xml | 1 + 25 files changed, 215 insertions(+), 57 deletions(-) create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarPopupWindow.java diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index e8d01a7a9..fadcebab7 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 234 + versionCode 236 versionName "1.4.15" } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 828b84774..f8dc297bd 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -2655,6 +2655,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa @Override public void onResume() { + super.onResume(); + showActionBar(); checkActionBarMenu(); @@ -2741,6 +2743,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa @Override public void onPause() { + super.onPause(); actionBarLayer.hideActionMode(); hideEmojiPopup(); paused = true; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java index 8442c93d3..5902e5d34 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java @@ -371,6 +371,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen @Override public void onResume() { + super.onResume(); if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java index 325623e44..f3532402d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java @@ -103,6 +103,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment { @Override public void onResume() { + super.onResume(); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); boolean animations = preferences.getBoolean("view_animations", true); if (!animations) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java index 0a563725e..5c8622281 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java @@ -177,6 +177,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent @Override public void onResume() { + super.onResume(); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); boolean animations = preferences.getBoolean("view_animations", true); if (!animations) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java index a43e285b3..9d2de23eb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java @@ -358,16 +358,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter @Override public void onResume() { + super.onResume(); if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } } - @Override - public void onPause() { - actionBarLayer.closeSearchField(); - } - @Override public void didReceivedNotification(int id, Object... args) { if (id == MessagesController.contactsDidLoaded) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java index 8b359ae36..372326e42 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java @@ -245,16 +245,12 @@ public class CountrySelectActivity extends BaseFragment { @Override public void onResume() { + super.onResume(); if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } } - @Override - public void onPause() { - actionBarLayer.closeSearchField(); - } - public void search(final String query) { if (query == null) { searchResult = null; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java index 081236207..fabf713f3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java @@ -194,6 +194,7 @@ public class DocumentSelectActivity extends BaseFragment { @Override public void onResume() { + super.onResume(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java index 4cd4fc8ee..3994d5eb2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java @@ -84,6 +84,7 @@ public class IdenticonActivity extends BaseFragment { @Override public void onResume() { + super.onResume(); fixLayout(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java index ecc09a7e3..639cf7950 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java @@ -197,16 +197,12 @@ public class LanguageSelectActivity extends BaseFragment { @Override public void onResume() { + super.onResume(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } } - @Override - public void onPause() { - actionBarLayer.closeSearchField(); - } - public void search(final String query) { if (query == null) { searchResult = null; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index d38ba878d..a72180714 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -120,13 +120,9 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen if (fragmentsStack.isEmpty()) { if (!UserConfig.clientActivated) { - LoginActivity fragment = new LoginActivity(); - fragment.onFragmentCreate(); - fragmentsStack.add(fragment); + addFragmentToStack(new LoginActivity()); } else { - MessagesActivity fragment = new MessagesActivity(null); - fragment.onFragmentCreate(); - fragmentsStack.add(fragment); + addFragmentToStack(new MessagesActivity(null)); } try { @@ -137,37 +133,32 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen if (fragmentName.equals("chat")) { if (args != null) { ChatActivity chat = new ChatActivity(args); - if (chat.onFragmentCreate()) { - fragmentsStack.add(chat); + if (addFragmentToStack(chat)) { chat.restoreSelfArgs(savedInstanceState); } } } else if (fragmentName.equals("settings")) { SettingsActivity settings = new SettingsActivity(); - settings.onFragmentCreate(); + addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); - fragmentsStack.add(settings); } else if (fragmentName.equals("group")) { if (args != null) { GroupCreateFinalActivity group = new GroupCreateFinalActivity(args); - if (group.onFragmentCreate()) { + if (addFragmentToStack(group)) { group.restoreSelfArgs(savedInstanceState); - fragmentsStack.add(group); } } } else if (fragmentName.equals("chat_profile")) { if (args != null) { ChatProfileActivity profile = new ChatProfileActivity(args); - if (profile.onFragmentCreate()) { + if (addFragmentToStack(profile)) { profile.restoreSelfArgs(savedInstanceState); - fragmentsStack.add(profile); } } } else if (fragmentName.equals("wallpapers")) { SettingsWallpapersActivity settings = new SettingsWallpapersActivity(); - settings.onFragmentCreate(); + addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); - fragmentsStack.add(settings); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java index a228e3563..b9e49ec92 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java @@ -253,6 +253,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No @Override public void onResume() { + super.onResume(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java index 0c5255599..4363df095 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java @@ -378,17 +378,13 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter @Override public void onResume() { + super.onResume(); showActionBar(); if (messagesListViewAdapter != null) { messagesListViewAdapter.notifyDataSetChanged(); } } - @Override - public void onPause() { - actionBarLayer.closeSearchField(); - } - @Override @SuppressWarnings("unchecked") public void didReceivedNotification(int id, Object... args) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index 386947721..2beefee03 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -546,6 +546,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter @Override public void onResume() { + super.onResume(); showActionBar(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java index c21d4e37b..b69726386 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java @@ -252,6 +252,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe @Override public void onResume() { + super.onResume(); if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java index fa711f6f2..e45734fc7 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java @@ -115,6 +115,7 @@ public class SettingsChangeNameActivity extends BaseFragment { @Override public void onResume() { + super.onResume(); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); boolean animations = preferences.getBoolean("view_animations", true); if (!animations) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java index 2ddaf7dfb..e1c7cb9c5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java @@ -424,6 +424,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica @Override public void onResume() { + super.onResume(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java index 64f891371..a4c2052d3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java @@ -436,6 +436,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen @Override public void onResume() { + super.onResume(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java index 952f59556..1e9eeeca3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java @@ -33,10 +33,6 @@ import android.widget.FrameLayout; import org.telegram.messenger.FileLog; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; -import org.telegram.ui.ChatActivity; -import org.telegram.ui.GroupCreateFinalActivity; -import org.telegram.ui.SettingsActivity; -import org.telegram.ui.SettingsWallpapersActivity; import java.util.ArrayList; @@ -315,7 +311,7 @@ public class ActionBarActivity extends Activity { @Override public void onBackPressed() { - if (startedTracking || checkTransitionAnimation()) { + if (startedTracking || checkTransitionAnimation() || fragmentsStack.isEmpty()) { return; } if (actionBar.currentLayer != null && actionBar.currentLayer.isSearchFieldVisible) { @@ -488,6 +484,15 @@ public class ActionBarActivity extends Activity { return true; } + public boolean addFragmentToStack(BaseFragment fragment) { + if (!fragment.onFragmentCreate()) { + return false; + } + fragment.setParentActivity(this); + fragmentsStack.add(fragment); + return true; + } + private void closeLastFragmentInternalRemoveOld(BaseFragment fragment) { fragment.onPause(); fragment.onFragmentDestroy(); @@ -566,9 +571,6 @@ public class ActionBarActivity extends Activity { } public void removeFragmentFromStack(BaseFragment fragment) { -// if (!fragmentsStack.isEmpty() && fragmentsStack.get(fragmentsStack.size() - 1) == fragment) { -// return; -// } fragment.onFragmentDestroy(); fragment.setParentActivity(null); fragmentsStack.remove(fragment); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java index f9008ba9d..81cfda904 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java @@ -437,4 +437,10 @@ public class ActionBarLayer extends FrameLayout { menu.onMenuButtonPressed(); } } + + protected void onPause() { + if (menu != null) { + menu.hideAllPopupMenus(); + } + } } \ No newline at end of file diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java index 36224c714..00266e217 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java @@ -87,7 +87,7 @@ public class ActionBarMenu extends LinearLayout { return menuItem; } - public void onDestroy() { + public void hideAllPopupMenus() { for (int a = 0; a < getChildCount(); a++) { View view = getChildAt(a); if (view instanceof ActionBarMenuItem) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java index f2970e98c..af5a6b033 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java @@ -23,7 +23,6 @@ import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.PopupWindow; import android.widget.TextView; import org.telegram.messenger.R; @@ -41,7 +40,7 @@ public class ActionBarMenuItem extends ImageView { private LinearLayout popupLayout; private ActionBarMenu parentMenu; - private PopupWindow popupWindow; + private ActionBarPopupWindow popupWindow; private ActionBar parentActionBar; private EditText searchField; private boolean isSearchField = false; @@ -120,12 +119,12 @@ public class ActionBarMenuItem extends ImageView { return; } if (popupWindow == null) { - popupWindow = new PopupWindow(popupLayout, FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); + popupWindow = new ActionBarPopupWindow(popupLayout, FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setOutsideTouchable(true); popupWindow.setClippingEnabled(true); - popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); + popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED); popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); } if (popupLayout.getMeasuredWidth() == 0) { @@ -177,7 +176,6 @@ public class ActionBarMenuItem extends ImageView { searchField.setTextSize(18); searchField.setTextColor(0xffffffff); searchField.setSingleLine(true); - searchField.setTextIsSelectable(false); searchField.setBackgroundResource(R.drawable.search_light_states); searchField.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0); searchField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS); @@ -220,10 +218,11 @@ public class ActionBarMenuItem extends ImageView { mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.set(searchField, R.drawable.search_carret); } catch (Exception e) { - e.printStackTrace(); + //nothing to do } if (Build.VERSION.SDK_INT >= 11) { searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH); + searchField.setTextIsSelectable(false); } else { searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarPopupWindow.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarPopupWindow.java new file mode 100644 index 000000000..a011316d1 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarPopupWindow.java @@ -0,0 +1,158 @@ +/* + * This is the source code of Telegram for Android v. 1.4.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. + */ + +//Thanks to https://github.com/JakeWharton/ActionBarSherlock/ + +package org.telegram.ui.Views.ActionBar; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewTreeObserver; +import android.widget.PopupWindow; + +import java.lang.reflect.Field; + +public class ActionBarPopupWindow extends PopupWindow { + private static final Field superListenerField; + static { + Field f = null; + try { + f = PopupWindow.class.getDeclaredField("mOnScrollChangedListener"); + f.setAccessible(true); + } catch (NoSuchFieldException e) { + /* ignored */ + } + superListenerField = f; + } + + private static final ViewTreeObserver.OnScrollChangedListener NOP = new ViewTreeObserver.OnScrollChangedListener() { + @Override + public void onScrollChanged() { + /* do nothing */ + } + }; + + private ViewTreeObserver.OnScrollChangedListener mSuperScrollListener; + private ViewTreeObserver mViewTreeObserver; + + public ActionBarPopupWindow() { + super(); + init(); + } + + public ActionBarPopupWindow(Context context) { + super(context); + init(); + } + + public ActionBarPopupWindow(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public ActionBarPopupWindow(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(); + } + + public ActionBarPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + public ActionBarPopupWindow(int width, int height) { + super(width, height); + init(); + } + + public ActionBarPopupWindow(View contentView) { + super(contentView); + init(); + } + + public ActionBarPopupWindow(View contentView, int width, int height, boolean focusable) { + super(contentView, width, height, focusable); + init(); + } + + public ActionBarPopupWindow(View contentView, int width, int height) { + super(contentView, width, height); + init(); + } + + private void init() { + if (superListenerField != null) { + try { + mSuperScrollListener = (ViewTreeObserver.OnScrollChangedListener) superListenerField.get(this); + superListenerField.set(this, NOP); + } catch (Exception e) { + mSuperScrollListener = null; + } + } + } + + 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); + } + mViewTreeObserver = null; + } + } + + 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; + if (vto != mViewTreeObserver) { + if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) { + mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener); + } + if ((mViewTreeObserver = vto) != null) { + vto.addOnScrollChangedListener(mSuperScrollListener); + } + } + } + } + + @Override + public void showAsDropDown(View anchor, int xoff, int yoff) { + super.showAsDropDown(anchor, xoff, yoff); + registerListener(anchor); + } + + @Override + public void update(View anchor, int xoff, int yoff, int width, int height) { + super.update(anchor, xoff, yoff, width, height); + registerListener(anchor); + } + + @Override + public void update(View anchor, int width, int height) { + super.update(anchor, width, height); + registerListener(anchor); + } + + @Override + public void showAtLocation(View parent, int gravity, int x, int y) { + super.showAtLocation(parent, gravity, x, y); + unregisterListener(); + } + + @Override + public void dismiss() { + super.dismiss(); + unregisterListener(); + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java index 238a81aaa..cc5776932 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java @@ -51,11 +51,11 @@ public class BaseFragment { } fragmentView = null; } + if (actionBarLayer != null) { + actionBarLayer.onDestroy(); + actionBarLayer = null; + } if (parentActivity != null) { - if (actionBarLayer != null) { - actionBarLayer.onDestroy(); - actionBarLayer = null; - } actionBarLayer = parentActivity.getInternalActionBar().createLayer(); } } @@ -92,7 +92,10 @@ public class BaseFragment { } public void onPause() { - + if (actionBarLayer != null) { + actionBarLayer.onPause(); + actionBarLayer.closeSearchField(); + } } public void onConfigurationChanged(android.content.res.Configuration newConfig) { diff --git a/TMessagesProj/src/main/res/values/styles.xml b/TMessagesProj/src/main/res/values/styles.xml index c70a0edf3..8d83da71d 100644 --- a/TMessagesProj/src/main/res/values/styles.xml +++ b/TMessagesProj/src/main/res/values/styles.xml @@ -8,6 +8,7 @@ @android:color/white @android:color/white @drawable/shadow + true