Fixed app startup on Android 2.x, crash fixes

This commit is contained in:
DrKLO 2014-06-04 20:00:42 +04:00
parent c1896e97c3
commit 2c61da0001
25 changed files with 215 additions and 57 deletions

View file

@ -82,7 +82,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 234 versionCode 236
versionName "1.4.15" versionName "1.4.15"
} }
} }

View file

@ -2655,6 +2655,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
showActionBar(); showActionBar();
checkActionBarMenu(); checkActionBarMenu();
@ -2741,6 +2743,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
@Override @Override
public void onPause() { public void onPause() {
super.onPause();
actionBarLayer.hideActionMode(); actionBarLayer.hideActionMode();
hideEmojiPopup(); hideEmojiPopup();
paused = true; paused = true;

View file

@ -371,6 +371,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listViewAdapter != null) { if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged(); listViewAdapter.notifyDataSetChanged();
} }

View file

@ -103,6 +103,7 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) { if (!animations) {

View file

@ -177,6 +177,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) { if (!animations) {

View file

@ -358,16 +358,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listViewAdapter != null) { if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged(); listViewAdapter.notifyDataSetChanged();
} }
} }
@Override
public void onPause() {
actionBarLayer.closeSearchField();
}
@Override @Override
public void didReceivedNotification(int id, Object... args) { public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.contactsDidLoaded) { if (id == MessagesController.contactsDidLoaded) {

View file

@ -245,16 +245,12 @@ public class CountrySelectActivity extends BaseFragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listViewAdapter != null) { if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged(); listViewAdapter.notifyDataSetChanged();
} }
} }
@Override
public void onPause() {
actionBarLayer.closeSearchField();
}
public void search(final String query) { public void search(final String query) {
if (query == null) { if (query == null) {
searchResult = null; searchResult = null;

View file

@ -194,6 +194,7 @@ public class DocumentSelectActivity extends BaseFragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }

View file

@ -84,6 +84,7 @@ public class IdenticonActivity extends BaseFragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
fixLayout(); fixLayout();
} }

View file

@ -197,16 +197,12 @@ public class LanguageSelectActivity extends BaseFragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
} }
@Override
public void onPause() {
actionBarLayer.closeSearchField();
}
public void search(final String query) { public void search(final String query) {
if (query == null) { if (query == null) {
searchResult = null; searchResult = null;

View file

@ -120,13 +120,9 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
if (fragmentsStack.isEmpty()) { if (fragmentsStack.isEmpty()) {
if (!UserConfig.clientActivated) { if (!UserConfig.clientActivated) {
LoginActivity fragment = new LoginActivity(); addFragmentToStack(new LoginActivity());
fragment.onFragmentCreate();
fragmentsStack.add(fragment);
} else { } else {
MessagesActivity fragment = new MessagesActivity(null); addFragmentToStack(new MessagesActivity(null));
fragment.onFragmentCreate();
fragmentsStack.add(fragment);
} }
try { try {
@ -137,37 +133,32 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
if (fragmentName.equals("chat")) { if (fragmentName.equals("chat")) {
if (args != null) { if (args != null) {
ChatActivity chat = new ChatActivity(args); ChatActivity chat = new ChatActivity(args);
if (chat.onFragmentCreate()) { if (addFragmentToStack(chat)) {
fragmentsStack.add(chat);
chat.restoreSelfArgs(savedInstanceState); chat.restoreSelfArgs(savedInstanceState);
} }
} }
} else if (fragmentName.equals("settings")) { } else if (fragmentName.equals("settings")) {
SettingsActivity settings = new SettingsActivity(); SettingsActivity settings = new SettingsActivity();
settings.onFragmentCreate(); addFragmentToStack(settings);
settings.restoreSelfArgs(savedInstanceState); settings.restoreSelfArgs(savedInstanceState);
fragmentsStack.add(settings);
} else if (fragmentName.equals("group")) { } else if (fragmentName.equals("group")) {
if (args != null) { if (args != null) {
GroupCreateFinalActivity group = new GroupCreateFinalActivity(args); GroupCreateFinalActivity group = new GroupCreateFinalActivity(args);
if (group.onFragmentCreate()) { if (addFragmentToStack(group)) {
group.restoreSelfArgs(savedInstanceState); group.restoreSelfArgs(savedInstanceState);
fragmentsStack.add(group);
} }
} }
} else if (fragmentName.equals("chat_profile")) { } else if (fragmentName.equals("chat_profile")) {
if (args != null) { if (args != null) {
ChatProfileActivity profile = new ChatProfileActivity(args); ChatProfileActivity profile = new ChatProfileActivity(args);
if (profile.onFragmentCreate()) { if (addFragmentToStack(profile)) {
profile.restoreSelfArgs(savedInstanceState); profile.restoreSelfArgs(savedInstanceState);
fragmentsStack.add(profile);
} }
} }
} else if (fragmentName.equals("wallpapers")) { } else if (fragmentName.equals("wallpapers")) {
SettingsWallpapersActivity settings = new SettingsWallpapersActivity(); SettingsWallpapersActivity settings = new SettingsWallpapersActivity();
settings.onFragmentCreate(); addFragmentToStack(settings);
settings.restoreSelfArgs(savedInstanceState); settings.restoreSelfArgs(savedInstanceState);
fragmentsStack.add(settings);
} }
} }
} }

View file

@ -253,6 +253,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }

View file

@ -378,17 +378,13 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
showActionBar(); showActionBar();
if (messagesListViewAdapter != null) { if (messagesListViewAdapter != null) {
messagesListViewAdapter.notifyDataSetChanged(); messagesListViewAdapter.notifyDataSetChanged();
} }
} }
@Override
public void onPause() {
actionBarLayer.closeSearchField();
}
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void didReceivedNotification(int id, Object... args) { public void didReceivedNotification(int id, Object... args) {

View file

@ -546,6 +546,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
showActionBar(); showActionBar();
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();

View file

@ -252,6 +252,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listViewAdapter != null) { if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged(); listViewAdapter.notifyDataSetChanged();
} }

View file

@ -115,6 +115,7 @@ public class SettingsChangeNameActivity extends BaseFragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) { if (!animations) {

View file

@ -424,6 +424,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }

View file

@ -436,6 +436,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
@Override @Override
public void onResume() { public void onResume() {
super.onResume();
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }

View file

@ -33,10 +33,6 @@ import android.widget.FrameLayout;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.Utilities; 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; import java.util.ArrayList;
@ -315,7 +311,7 @@ public class ActionBarActivity extends Activity {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (startedTracking || checkTransitionAnimation()) { if (startedTracking || checkTransitionAnimation() || fragmentsStack.isEmpty()) {
return; return;
} }
if (actionBar.currentLayer != null && actionBar.currentLayer.isSearchFieldVisible) { if (actionBar.currentLayer != null && actionBar.currentLayer.isSearchFieldVisible) {
@ -488,6 +484,15 @@ public class ActionBarActivity extends Activity {
return true; 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) { private void closeLastFragmentInternalRemoveOld(BaseFragment fragment) {
fragment.onPause(); fragment.onPause();
fragment.onFragmentDestroy(); fragment.onFragmentDestroy();
@ -566,9 +571,6 @@ public class ActionBarActivity extends Activity {
} }
public void removeFragmentFromStack(BaseFragment fragment) { public void removeFragmentFromStack(BaseFragment fragment) {
// if (!fragmentsStack.isEmpty() && fragmentsStack.get(fragmentsStack.size() - 1) == fragment) {
// return;
// }
fragment.onFragmentDestroy(); fragment.onFragmentDestroy();
fragment.setParentActivity(null); fragment.setParentActivity(null);
fragmentsStack.remove(fragment); fragmentsStack.remove(fragment);

View file

@ -437,4 +437,10 @@ public class ActionBarLayer extends FrameLayout {
menu.onMenuButtonPressed(); menu.onMenuButtonPressed();
} }
} }
protected void onPause() {
if (menu != null) {
menu.hideAllPopupMenus();
}
}
} }

View file

@ -87,7 +87,7 @@ public class ActionBarMenu extends LinearLayout {
return menuItem; return menuItem;
} }
public void onDestroy() { public void hideAllPopupMenus() {
for (int a = 0; a < getChildCount(); a++) { for (int a = 0; a < getChildCount(); a++) {
View view = getChildAt(a); View view = getChildAt(a);
if (view instanceof ActionBarMenuItem) { if (view instanceof ActionBarMenuItem) {

View file

@ -23,7 +23,6 @@ import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.R; import org.telegram.messenger.R;
@ -41,7 +40,7 @@ public class ActionBarMenuItem extends ImageView {
private LinearLayout popupLayout; private LinearLayout popupLayout;
private ActionBarMenu parentMenu; private ActionBarMenu parentMenu;
private PopupWindow popupWindow; private ActionBarPopupWindow popupWindow;
private ActionBar parentActionBar; private ActionBar parentActionBar;
private EditText searchField; private EditText searchField;
private boolean isSearchField = false; private boolean isSearchField = false;
@ -120,12 +119,12 @@ public class ActionBarMenuItem extends ImageView {
return; return;
} }
if (popupWindow == null) { 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.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true); popupWindow.setOutsideTouchable(true);
popupWindow.setClippingEnabled(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); popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
} }
if (popupLayout.getMeasuredWidth() == 0) { if (popupLayout.getMeasuredWidth() == 0) {
@ -177,7 +176,6 @@ public class ActionBarMenuItem extends ImageView {
searchField.setTextSize(18); searchField.setTextSize(18);
searchField.setTextColor(0xffffffff); searchField.setTextColor(0xffffffff);
searchField.setSingleLine(true); searchField.setSingleLine(true);
searchField.setTextIsSelectable(false);
searchField.setBackgroundResource(R.drawable.search_light_states); searchField.setBackgroundResource(R.drawable.search_light_states);
searchField.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0); searchField.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0);
searchField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS); searchField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
@ -220,10 +218,11 @@ public class ActionBarMenuItem extends ImageView {
mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.setAccessible(true);
mCursorDrawableRes.set(searchField, R.drawable.search_carret); mCursorDrawableRes.set(searchField, R.drawable.search_carret);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); //nothing to do
} }
if (Build.VERSION.SDK_INT >= 11) { if (Build.VERSION.SDK_INT >= 11) {
searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH); searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH);
searchField.setTextIsSelectable(false);
} else { } else {
searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
} }

View file

@ -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();
}
}

View file

@ -51,11 +51,11 @@ public class BaseFragment {
} }
fragmentView = null; fragmentView = null;
} }
if (actionBarLayer != null) {
actionBarLayer.onDestroy();
actionBarLayer = null;
}
if (parentActivity != null) { if (parentActivity != null) {
if (actionBarLayer != null) {
actionBarLayer.onDestroy();
actionBarLayer = null;
}
actionBarLayer = parentActivity.getInternalActionBar().createLayer(); actionBarLayer = parentActivity.getInternalActionBar().createLayer();
} }
} }
@ -92,7 +92,10 @@ public class BaseFragment {
} }
public void onPause() { public void onPause() {
if (actionBarLayer != null) {
actionBarLayer.onPause();
actionBarLayer.closeSearchField();
}
} }
public void onConfigurationChanged(android.content.res.Configuration newConfig) { public void onConfigurationChanged(android.content.res.Configuration newConfig) {

View file

@ -8,6 +8,7 @@
<item name="android:colorBackground">@android:color/white</item> <item name="android:colorBackground">@android:color/white</item>
<item name="android:windowBackground">@android:color/white</item> <item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@drawable/shadow</item> <item name="android:windowContentOverlay">@drawable/shadow</item>
<item name="android:windowNoTitle">true</item>
</style> </style>
<style name="Theme.TMessages" parent="@android:style/Theme.Holo.Light"> <style name="Theme.TMessages" parent="@android:style/Theme.Holo.Light">