From 3fecce964594ebc32af5bdd98f170ffceb0df0fa Mon Sep 17 00:00:00 2001 From: DrKLO Date: Wed, 4 Jun 2014 03:31:48 +0400 Subject: [PATCH] Implemented own ActionBar and Fragments, swipe back navigation, https://github.com/DrKLO/Telegram/issues/424 --- TMessagesProj/build.gradle | 4 +- TMessagesProj/src/main/AndroidManifest.xml | 13 - .../telegram/messenger/LocaleController.java | 13 + .../telegram/messenger/MessagesStorage.java | 6 + .../org/telegram/messenger/Utilities.java | 2 +- .../org/telegram/ui/ApplicationLoader.java | 17 - .../org/telegram/ui/Cells/ChatBaseCell.java | 25 - .../org/telegram/ui/Cells/ChatMediaCell.java | 1 - .../org/telegram/ui/Cells/DialogCell.java | 2 +- .../java/org/telegram/ui/ChatActivity.java | 1274 +++++++---------- .../org/telegram/ui/ChatProfileActivity.java | 203 +-- .../ui/ChatProfileChangeNameActivity.java | 119 +- .../org/telegram/ui/ContactAddActivity.java | 132 +- .../org/telegram/ui/ContactsActivity.java | 364 ++--- .../telegram/ui/CountrySelectActivity.java | 387 +++-- .../telegram/ui/DocumentSelectActivity.java | 129 +- .../org/telegram/ui/GroupCreateActivity.java | 134 +- .../telegram/ui/GroupCreateFinalActivity.java | 184 +-- .../org/telegram/ui/IdenticonActivity.java | 128 +- .../java/org/telegram/ui/IntroActivity.java | 3 +- .../telegram/ui/LanguageSelectActivity.java | 272 +--- .../java/org/telegram/ui/LaunchActivity.java | 543 ++----- .../org/telegram/ui/LocationActivity.java | 382 +++-- .../java/org/telegram/ui/LoginActivity.java | 221 ++- .../telegram/ui/LoginActivityPhoneView.java | 16 +- .../java/org/telegram/ui/MediaActivity.java | 140 +- .../org/telegram/ui/MessagesActivity.java | 393 ++--- .../org/telegram/ui/PhotoCropActivity.java | 102 +- .../org/telegram/ui/SettingsActivity.java | 165 +-- .../org/telegram/ui/SettingsBlockedUsers.java | 128 +- .../ui/SettingsChangeNameActivity.java | 118 +- .../ui/SettingsNotificationsActivity.java | 112 +- .../ui/SettingsWallpapersActivity.java | 73 +- .../org/telegram/ui/UserProfileActivity.java | 390 ++--- .../ui/Views/ActionBar/ActionBar.java | 208 +++ .../ui/Views/ActionBar/ActionBarActivity.java | 623 ++++++++ .../ui/Views/ActionBar/ActionBarLayer.java | 433 ++++++ .../ui/Views/ActionBar/ActionBarMenu.java | 143 ++ .../ui/Views/ActionBar/ActionBarMenuItem.java | 259 ++++ .../ui/Views/ActionBar/BaseFragment.java | 166 +++ .../org/telegram/ui/Views/AvatarUpdater.java | 23 +- .../telegram/ui/Views/BackupImageView.java | 5 +- .../org/telegram/ui/Views/BaseFragment.java | 196 --- .../ui/Views/OnSwipeTouchListener.java | 149 -- TMessagesProj/src/main/res/anim/no_anim.xml | 6 - .../src/main/res/anim/no_anim_show.xml | 6 - .../src/main/res/anim/slide_left.xml | 7 - .../src/main/res/anim/slide_left_away.xml | 7 - .../src/main/res/anim/slide_right.xml | 7 - .../src/main/res/anim/slide_right_away.xml | 7 - .../main/res/drawable-hdpi/editheader.9.png | Bin 0 -> 134 bytes .../src/main/res/drawable-hdpi/header.9.png | Bin 136 -> 0 bytes .../main/res/drawable-hdpi/search_light.9.png | Bin 0 -> 105 bytes .../drawable-hdpi/search_light_selected.9.png | Bin 0 -> 112 bytes .../main/res/drawable-ldpi/editheader.9.png | Bin 0 -> 106 bytes .../src/main/res/drawable-ldpi/header.9.png | Bin 108 -> 0 bytes .../main/res/drawable-mdpi/editheader.9.png | Bin 0 -> 118 bytes .../src/main/res/drawable-mdpi/header.9.png | Bin 119 -> 0 bytes .../main/res/drawable-mdpi/search_light.9.png | Bin 0 -> 100 bytes .../drawable-mdpi/search_light_selected.9.png | Bin 0 -> 109 bytes .../main/res/drawable-xhdpi/editheader.9.png | Bin 0 -> 152 bytes .../src/main/res/drawable-xhdpi/header.9.png | Bin 148 -> 0 bytes .../res/drawable-xhdpi/search_light.9.png | Bin 0 -> 126 bytes .../search_light_selected.9.png | Bin 0 -> 126 bytes .../main/res/drawable-xxhdpi/editheader.9.png | Bin 0 -> 200 bytes .../src/main/res/drawable-xxhdpi/header.9.png | Bin 189 -> 0 bytes .../src/main/res/drawable/ab_icon_fixed2.xml | 5 - .../main/res/drawable/search_light_states.xml | 8 + .../main/res/layout-ar/contacts_layout.xml | 7 +- .../res/layout-ar/location_view_layout.xml | 86 +- .../main/res/layout/application_layout.xml | 15 - .../src/main/res/layout/contacts_layout.xml | 7 +- .../res/layout/location_attach_layout.xml | 41 +- .../main/res/layout/location_view_layout.xml | 82 +- .../main/res/layout/updating_state_layout.xml | 1 - TMessagesProj/src/main/res/values/colors.xml | 1 + TMessagesProj/src/main/res/values/strings.xml | 2 +- TMessagesProj/src/main/res/values/styles.xml | 50 +- 78 files changed, 4063 insertions(+), 4682 deletions(-) create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java delete mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/BaseFragment.java delete mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Views/OnSwipeTouchListener.java delete mode 100644 TMessagesProj/src/main/res/anim/no_anim.xml delete mode 100644 TMessagesProj/src/main/res/anim/no_anim_show.xml delete mode 100644 TMessagesProj/src/main/res/anim/slide_left.xml delete mode 100644 TMessagesProj/src/main/res/anim/slide_left_away.xml delete mode 100644 TMessagesProj/src/main/res/anim/slide_right.xml delete mode 100644 TMessagesProj/src/main/res/anim/slide_right_away.xml create mode 100644 TMessagesProj/src/main/res/drawable-hdpi/editheader.9.png delete mode 100644 TMessagesProj/src/main/res/drawable-hdpi/header.9.png create mode 100755 TMessagesProj/src/main/res/drawable-hdpi/search_light.9.png create mode 100755 TMessagesProj/src/main/res/drawable-hdpi/search_light_selected.9.png create mode 100644 TMessagesProj/src/main/res/drawable-ldpi/editheader.9.png delete mode 100644 TMessagesProj/src/main/res/drawable-ldpi/header.9.png create mode 100644 TMessagesProj/src/main/res/drawable-mdpi/editheader.9.png delete mode 100644 TMessagesProj/src/main/res/drawable-mdpi/header.9.png create mode 100755 TMessagesProj/src/main/res/drawable-mdpi/search_light.9.png create mode 100755 TMessagesProj/src/main/res/drawable-mdpi/search_light_selected.9.png create mode 100644 TMessagesProj/src/main/res/drawable-xhdpi/editheader.9.png delete mode 100644 TMessagesProj/src/main/res/drawable-xhdpi/header.9.png create mode 100755 TMessagesProj/src/main/res/drawable-xhdpi/search_light.9.png create mode 100755 TMessagesProj/src/main/res/drawable-xhdpi/search_light_selected.9.png create mode 100644 TMessagesProj/src/main/res/drawable-xxhdpi/editheader.9.png delete mode 100644 TMessagesProj/src/main/res/drawable-xxhdpi/header.9.png delete mode 100644 TMessagesProj/src/main/res/drawable/ab_icon_fixed2.xml create mode 100755 TMessagesProj/src/main/res/drawable/search_light_states.xml delete mode 100644 TMessagesProj/src/main/res/layout/application_layout.xml diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 55ccd56a..e8d01a7a 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 233 - versionName "1.4.14" + versionCode 234 + versionName "1.4.15" } } diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml index 7b88baab..158676b0 100644 --- a/TMessagesProj/src/main/AndroidManifest.xml +++ b/TMessagesProj/src/main/AndroidManifest.xml @@ -95,19 +95,6 @@ - - - - fragmentsStack = new ArrayList(); - public static void postInitApplication() { if (applicationInited) { return; @@ -149,17 +143,6 @@ public class ApplicationLoader extends Application { java.lang.System.setProperty("java.net.preferIPv4Stack", "true"); java.lang.System.setProperty("java.net.preferIPv6Addresses", "false"); - try { - ViewConfiguration config = ViewConfiguration.get(this); - Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); - if(menuKeyField != null) { - menuKeyField.setAccessible(true); - menuKeyField.setBoolean(config, false); - } - } catch (Exception e) { - e.printStackTrace(); - } - startPushService(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java index 6b5e5877..4cf0e9c9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java @@ -30,7 +30,6 @@ import org.telegram.messenger.R; import org.telegram.messenger.Utilities; import org.telegram.objects.MessageObject; import org.telegram.ui.Views.ImageReceiver; -import org.telegram.ui.Views.OnSwipeTouchListener; import java.lang.ref.WeakReference; @@ -41,8 +40,6 @@ public class ChatBaseCell extends BaseCell { public abstract void didPressedCancelSendButton(ChatBaseCell cell); public abstract void didLongPressed(ChatBaseCell cell); public abstract boolean canPerformActions(); - public boolean onSwipeLeft(); - public boolean onSwipeRight(); } public boolean isChat = false; @@ -118,7 +115,6 @@ public class ChatBaseCell extends BaseCell { private int pressCount = 0; private CheckForLongPress pendingCheckForLongPress = null; private CheckForTap pendingCheckForTap = null; - private OnSwipeTouchListener onSwipeTouchListener; private final class CheckForTap implements Runnable { public void run() { @@ -153,23 +149,6 @@ public class ChatBaseCell extends BaseCell { media = isMedia; avatarImage = new ImageReceiver(); avatarImage.parentView = new WeakReference(this); - onSwipeTouchListener = new OnSwipeTouchListener() { - public void onSwipeRight() { - if (delegate != null && delegate.onSwipeRight()) { - MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0); - onTouchEvent(event); - event.recycle(); - } - } - - public void onSwipeLeft() { - if (delegate != null && delegate.onSwipeLeft()) { - MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0); - onTouchEvent(event); - event.recycle(); - } - } - }; } @Override @@ -384,10 +363,6 @@ public class ChatBaseCell extends BaseCell { } } - protected void checkSwipes(MotionEvent event) { - onSwipeTouchListener.onTouch(this, event); - } - @Override public boolean onTouchEvent(MotionEvent event) { boolean result = false; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java index dfa978ac..5ac68412 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -135,7 +135,6 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD boolean result = false; int side = Utilities.dp(44); - checkSwipes(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { if (delegate == null || delegate.canPerformActions()) { if (buttonState != -1 && x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java index 69496365..88dcaac0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java @@ -482,7 +482,7 @@ public class DialogCell extends BaseCell { messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageText)), messagePaint.getFontMetricsInt(), Utilities.dp(20)); } else { if (message.messageOwner.message != null) { - messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageOwner.message.replace("\n", " "))), messagePaint.getFontMetricsInt(), Utilities.dp(20)); + messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageOwner.message.replace("\n", " ").replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), Utilities.dp(20)); } } } else { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 8e0f3851..d1c81f25 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -20,33 +20,26 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.Bitmap; -import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; import android.media.MediaPlayer; import android.media.ThumbnailUtils; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.PowerManager; import android.provider.MediaStore; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; -import android.support.v7.view.ActionMode; import android.text.Editable; import android.text.Html; +import android.text.TextUtils; import android.text.TextWatcher; import android.text.style.ImageSpan; import android.util.TypedValue; -import android.view.Display; +import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.MotionEvent; -import android.view.SubMenu; import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -64,6 +57,7 @@ import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.ProgressBar; import android.widget.RelativeLayout; @@ -90,12 +84,14 @@ import org.telegram.ui.Cells.ChatAudioCell; import org.telegram.ui.Cells.ChatBaseCell; import org.telegram.ui.Cells.ChatMediaCell; import org.telegram.ui.Cells.ChatMessageCell; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +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.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.EmojiView; import org.telegram.ui.Views.LayoutListView; import org.telegram.ui.Views.MessageActionLayout; -import org.telegram.ui.Views.OnSwipeTouchListener; import org.telegram.ui.Views.SizeNotifierRelativeLayout; import org.telegram.ui.Views.TimerButton; @@ -107,6 +103,9 @@ import java.util.HashMap; import java.util.concurrent.Semaphore; public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate, NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, DocumentSelectActivity.DocumentSelectActivityDelegate { + + private View timeItem; + private View menuItem; private LayoutListView chatListView; private BackupImageView avatarImageView; private TLRPC.Chat currentChat; @@ -137,14 +136,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa private MessageObject forwaringMessage; private TextView secretViewStatusTextView; private TimerButton timerButton; - private Point displaySize = new Point(); + private TextView selectedMessagesCountTextView; private boolean paused = true; private boolean readWhenResume = false; private boolean sendByEnter = false; private int readWithDate = 0; private int readWithMid = 0; - private boolean swipeOpening = false; - public boolean scrollToTopOnResume = false; + private boolean scrollToTopOnResume = false; private boolean scrollToTopUnReadOnResume = false; private boolean isCustomTheme = false; private int downloadPhotos = 0; @@ -170,7 +168,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa private long lastTypingTimeSend = 0; private int minDate = 0; private int progressTag = 0; - private boolean invalidateAfterAnimation = false; boolean first = true; private int unread_to_load = 0; private int first_unread_id = 0; @@ -211,105 +208,16 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa private final static int attach_location = 10; private final static int chat_menu_avatar = 11; - ActionMode mActionMode = null; - private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { - @Override - public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { - menu.clear(); - MenuInflater inflater = actionMode.getMenuInflater(); - if (currentEncryptedChat == null) { - menu.add(Menu.NONE, copy, Menu.NONE, LocaleController.getString("Copy", R.string.Copy)).setIcon(R.drawable.ic_ab_fwd_copy); - menu.add(Menu.NONE, forward, Menu.NONE, LocaleController.getString("Forward", R.string.Forward)).setIcon(R.drawable.ic_ab_fwd_forward); - menu.add(Menu.NONE, delete, Menu.NONE, LocaleController.getString("Delete", R.string.Delete)).setIcon(R.drawable.ic_ab_fwd_delete); - } else { - menu.add(Menu.NONE, copy, Menu.NONE, LocaleController.getString("Copy", R.string.Copy)).setIcon(R.drawable.ic_ab_fwd_copy); - menu.add(Menu.NONE, delete, Menu.NONE, LocaleController.getString("Delete", R.string.Delete)).setIcon(R.drawable.ic_ab_fwd_delete); - } - menu.findItem(copy).setVisible(selectedMessagesCanCopyIds.size() != 0); - return true; - } - - @Override - public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { - return false; - } - - @Override - public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { - switch (menuItem.getItemId()) { - case copy: { - String str = ""; - ArrayList ids = new ArrayList(selectedMessagesCanCopyIds.keySet()); - if (currentEncryptedChat == null) { - Collections.sort(ids); - } else { - Collections.sort(ids, Collections.reverseOrder()); - } - for (Integer id : ids) { - MessageObject messageObject = selectedMessagesCanCopyIds.get(id); - if (str.length() != 0) { - str += "\n"; - } - str += messageObject.messageOwner.message; - } - if (str.length() != 0) { - if(android.os.Build.VERSION.SDK_INT < 11) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); - clipboard.setText(str); - } else { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); - android.content.ClipData clip = android.content.ClipData.newPlainText("label", str); - clipboard.setPrimaryClip(clip); - } - } - break; - } - case delete: { - ArrayList ids = new ArrayList(selectedMessagesIds.keySet()); - ArrayList random_ids = null; - if (currentEncryptedChat != null) { - random_ids = new ArrayList(); - for (HashMap.Entry entry : selectedMessagesIds.entrySet()) { - MessageObject msg = entry.getValue(); - if (msg.messageOwner.random_id != 0 && msg.type != 10) { - random_ids.add(msg.messageOwner.random_id); - } - } - } - MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat); - break; - } - case forward: { - MessagesActivity fragment = new MessagesActivity(); - fragment.selectAlertString = R.string.ForwardMessagesTo; - fragment.selectAlertStringDesc = "ForwardMessagesTo"; - fragment.animationType = 1; - Bundle args = new Bundle(); - args.putBoolean("onlySelect", true); - args.putBoolean("serverOnly", true); - fragment.setArguments(args); - fragment.delegate = ChatActivity.this; - ((LaunchActivity)parentActivity).presentFragment(fragment, "select_chat", false); - break; - } - } - actionMode.finish(); - return false; - } - - @Override - public void onDestroyActionMode(ActionMode actionMode) { - mActionMode = null; - updateVisibleRows(); - } - }; + public ChatActivity(Bundle args) { + super(args); + } @Override public boolean onFragmentCreate() { - super.onFragmentCreate(); - final int chatId = getArguments().getInt("chat_id", 0); - final int userId = getArguments().getInt("user_id", 0); - final int encId = getArguments().getInt("enc_id", 0); + final int chatId = arguments.getInt("chat_id", 0); + final int userId = arguments.getInt("user_id", 0); + final int encId = arguments.getInt("enc_id", 0); + scrollToTopOnResume = arguments.getBoolean("scrollToTopOnResume", false); if (chatId != 0) { currentChat = MessagesController.getInstance().chats.get(chatId); @@ -436,6 +344,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa NotificationCenter.getInstance().addObserver(this, MediaController.screenshotTook); NotificationCenter.getInstance().addObserver(this, 997); + super.onFragmentCreate(); + loading = true; MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); @@ -511,7 +421,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } try { if (prevOrientation != -10) { - parentActivity.setRequestedOrientation(prevOrientation); + getParentActivity().setRequestedOrientation(prevOrientation); prevOrientation = -10; } } catch (Exception e) { @@ -520,21 +430,207 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa MediaController.getInstance().stopAudio(); } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - Display display = parentActivity.getWindowManager().getDefaultDisplay(); - if(android.os.Build.VERSION.SDK_INT < 13) { - displaySize.set(display.getWidth(), display.getHeight()); - } else { - display.getSize(displaySize); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } else if (id == -2) { + selectedMessagesIds.clear(); + selectedMessagesCanCopyIds.clear(); + actionBarLayer.hideActionMode(); + updateVisibleRows(); + } else if (id == attach_photo) { + try { + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + File image = Utilities.generatePicturePath(); + if (image != null) { + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); + currentPicturePath = image.getAbsolutePath(); + } + getParentActivity().startActivityForResult(takePictureIntent, 0); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else if (id == attach_gallery) { + try { + Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); + photoPickerIntent.setType("image/*"); + getParentActivity().startActivityForResult(photoPickerIntent, 1); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else if (id == attach_video) { + try { + Intent pickIntent = new Intent(); + pickIntent.setType("video/*"); + pickIntent.setAction(Intent.ACTION_GET_CONTENT); + pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long)(1024 * 1024 * 1000)); + Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); + File video = Utilities.generateVideoPath(); + if (video != null) { + if(android.os.Build.VERSION.SDK_INT > 16) { + takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video)); + } + takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long)(1024 * 1024 * 1000)); + currentPicturePath = video.getAbsolutePath(); + } + Intent chooserIntent = Intent.createChooser(pickIntent, ""); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent }); + + getParentActivity().startActivityForResult(chooserIntent, 2); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else if (id == attach_location) { + if (!isGoogleMapsInstalled()) { + return; + } + LocationActivity fragment = new LocationActivity(); + presentFragment(fragment); + } else if (id == attach_document) { + DocumentSelectActivity fragment = new DocumentSelectActivity(); + fragment.setDelegate(ChatActivity.this); + presentFragment(fragment); + } else if (id == chat_menu_avatar) { + if (currentUser != null) { + Bundle args = new Bundle(); + args.putInt("user_id", currentUser.id); + if (currentEncryptedChat != null) { + args.putLong("dialog_id", dialog_id); + } + presentFragment(new UserProfileActivity(args)); + } else if (currentChat != null) { + if (info != null) { + if (info instanceof TLRPC.TL_chatParticipantsForbidden) { + return; + } + NotificationCenter.getInstance().addToMemCache(5, info); + } + if (currentChat.participants_count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) { + return; + } + Bundle args = new Bundle(); + args.putInt("chat_id", currentChat.id); + presentFragment(new ChatProfileActivity(args)); + } + } else if (id == copy) { + String str = ""; + ArrayList ids = new ArrayList(selectedMessagesCanCopyIds.keySet()); + if (currentEncryptedChat == null) { + Collections.sort(ids); + } else { + Collections.sort(ids, Collections.reverseOrder()); + } + for (Integer messageId : ids) { + MessageObject messageObject = selectedMessagesCanCopyIds.get(messageId); + if (str.length() != 0) { + str += "\n"; + } + str += messageObject.messageOwner.message; + } + if (str.length() != 0) { + if(android.os.Build.VERSION.SDK_INT < 11) { + android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(str); + } else { + android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipData clip = android.content.ClipData.newPlainText("label", str); + clipboard.setPrimaryClip(clip); + } + } + } else if (id == delete) { + ArrayList ids = new ArrayList(selectedMessagesIds.keySet()); + ArrayList random_ids = null; + if (currentEncryptedChat != null) { + random_ids = new ArrayList(); + for (HashMap.Entry entry : selectedMessagesIds.entrySet()) { + MessageObject msg = entry.getValue(); + if (msg.messageOwner.random_id != 0 && msg.type != 10) { + random_ids.add(msg.messageOwner.random_id); + } + } + } + MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat); + } else if (id == forward) { + Bundle args = new Bundle(); + args.putBoolean("onlySelect", true); + args.putBoolean("serverOnly", true); + args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo)); + MessagesActivity fragment = new MessagesActivity(args); + fragment.setDelegate(ChatActivity.this); + presentFragment(fragment); + } + } + }); + updateSubtitle(); + + if (currentEncryptedChat != null) { + actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4)); + } + + ActionBarMenu menu = actionBarLayer.createMenu(); + + if (currentEncryptedChat != null) { + timeItem = menu.addItemResource(chat_enc_timer, R.layout.chat_header_enc_layout); + } + + ActionBarMenuItem item = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach); + item.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto), R.drawable.ic_attach_photo); + item.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery), R.drawable.ic_attach_gallery); + item.addSubItem(attach_video, LocaleController.getString("ChatVideo", R.string.ChatVideo), R.drawable.ic_attach_video); + item.addSubItem(attach_document, LocaleController.getString("ChatDocument", R.string.ChatDocument), R.drawable.ic_ab_doc); + item.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation), R.drawable.ic_attach_location); + menuItem = item; + + + ActionBarMenu actionMode = actionBarLayer.createActionMode(); + actionMode.addItem(-2, R.drawable.ic_ab_done_gray); + + FrameLayout layout = new FrameLayout(actionMode.getContext()); + layout.setBackgroundColor(0xffe5e5e5); + actionMode.addView(layout); + LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)layout.getLayoutParams(); + layoutParams.width = Utilities.dp(1); + layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT; + layoutParams.topMargin = Utilities.dp(12); + layoutParams.bottomMargin = Utilities.dp(12); + layoutParams.gravity = Gravity.CENTER_VERTICAL; + layout.setLayoutParams(layoutParams); + + selectedMessagesCountTextView = new TextView(actionMode.getContext()); + selectedMessagesCountTextView.setTextSize(18); + selectedMessagesCountTextView.setTextColor(0xff000000); + selectedMessagesCountTextView.setSingleLine(true); + selectedMessagesCountTextView.setLines(1); + selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END); + selectedMessagesCountTextView.setPadding(Utilities.dp(6), 0, 0, 0); + selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL); + actionMode.addView(selectedMessagesCountTextView); + layoutParams = (LinearLayout.LayoutParams)selectedMessagesCountTextView.getLayoutParams(); + layoutParams.weight = 1; + layoutParams.width = 0; + layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT; + selectedMessagesCountTextView.setLayoutParams(layoutParams); + + if (currentEncryptedChat == null) { + actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy); + actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward); + actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete); + } else { + actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy); + actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete); + } + actionMode.getItem(copy).setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE); + + View avatarLayout = menu.addItemResource(chat_menu_avatar, R.layout.chat_header_layout); + avatarImageView = (BackupImageView)avatarLayout.findViewById(R.id.chat_avatar_image); + avatarImageView.processDetach = false; + checkActionBarMenu(); + fragmentView = inflater.inflate(R.layout.chat_layout, container, false); sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout)fragmentView.findViewById(R.id.chat_layout); @@ -544,7 +640,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages)); chatListView = (LayoutListView)fragmentView.findViewById(R.id.chat_list_view); - chatListView.setAdapter(chatAdapter = new ChatAdapter(parentActivity)); + chatListView.setAdapter(chatAdapter = new ChatAdapter(getParentActivity())); topPanel = fragmentView.findViewById(R.id.top_panel); topPlaneClose = (ImageView)fragmentView.findViewById(R.id.top_plane_close); topPanelText = (TextView)fragmentView.findViewById(R.id.top_panel_text); @@ -636,7 +732,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa chatListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapter, View view, int position, long id) { - if (mActionMode == null) { + if (!actionBarLayer.isActionModeShowed()) { createMenu(view, false); } return true; @@ -896,7 +992,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @@ -915,7 +1011,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa chatListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { processRowSelect(view); return; } @@ -923,25 +1019,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } }); - chatListView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - ChatActivity.this.onSwipeRight(); - } - - public void onSwipeLeft() { - ChatActivity.this.onSwipeLeft(); - } - }); - - emptyView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - ChatActivity.this.onSwipeRight(); - } - - public void onSwipeLeft() { - ChatActivity.this.onSwipeLeft(); - } - }); if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) || currentUser != null && (currentUser instanceof TLRPC.TL_userDeleted || currentUser instanceof TLRPC.TL_userEmpty)) { bottomOverlayChat.setVisibility(View.VISIBLE); @@ -968,38 +1045,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa return src; } - private boolean onSwipeLeft() { - if (swipeOpening) { - return false; - } - try { - if (visibleDialog != null) { - visibleDialog.dismiss(); - visibleDialog = null; - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - if (avatarImageView != null) { - swipeOpening = true; - avatarImageView.performClick(); - } - return true; - } - - private boolean onSwipeRight() { - try { - if (visibleDialog != null) { - visibleDialog.dismiss(); - visibleDialog = null; - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - finishFragment(true); - return true; - } - private void checkSendButton() { String message = getTrimmedString(messsageEditText.getText().toString()); if (message.length() > 0) { @@ -1012,13 +1057,10 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void updateAudioRecordIntefrace() { - if (parentActivity == null) { - return; - } if (recordingAudio) { try { if (mWakeLock == null) { - PowerManager pm = (PowerManager) parentActivity.getSystemService(Context.POWER_SERVICE); + PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock"); mWakeLock.acquire(); } @@ -1026,13 +1068,25 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa FileLog.e("tmessages", e); } try { - prevOrientation = parentActivity.getRequestedOrientation(); - if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - } else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - } else { - parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); + prevOrientation = getParentActivity().getRequestedOrientation(); + WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE); + if (manager != null && manager.getDefaultDisplay() != null) { + int rotation = manager.getDefaultDisplay().getRotation(); + if (rotation == Surface.ROTATION_270) { + if (Build.VERSION.SDK_INT >= 9) { + getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); + } else { + getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + } else if (rotation == Surface.ROTATION_90) { + getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } else if (rotation == Surface.ROTATION_0) { + getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + if (Build.VERSION.SDK_INT >= 9) { + getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); + } + } } } catch (Exception e) { FileLog.e("tmessages", e); @@ -1077,7 +1131,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } try { if (prevOrientation != -10) { - parentActivity.setRequestedOrientation(prevOrientation); + getParentActivity().setRequestedOrientation(prevOrientation); prevOrientation = -10; } } catch (Exception e) { @@ -1181,22 +1235,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } } - @Override - public void onAnimationEnd() { - super.onAnimationEnd(); - if (invalidateAfterAnimation) { - if (chatListView != null) { - updateVisibleRows(); - } - } - } - - @Override - public void willBeHidden() { - super.willBeHidden(); - paused = true; - } - private void updateSecretStatus() { if (bottomOverlay == null) { return; @@ -1223,12 +1261,97 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } if (hideKeyboard) { hideEmojiPopup(); - if (parentActivity != null) { - Utilities.hideKeyboard(parentActivity.getCurrentFocus()); + Utilities.hideKeyboard(getParentActivity().getCurrentFocus()); + } + checkActionBarMenu(); + } + + private void checkActionBarMenu() { + if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat) || + currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) || + currentUser != null && (currentUser instanceof TLRPC.TL_userDeleted || currentUser instanceof TLRPC.TL_userEmpty)) { + + if (menuItem != null) { + menuItem.setVisibility(View.GONE); + } + + if (timeItem != null) { + timeItem.setVisibility(View.GONE); + } + } else { + if (menuItem != null) { + menuItem.setVisibility(View.VISIBLE); + } + + if (timeItem != null) { + timeItem.setVisibility(View.VISIBLE); } } - if (parentActivity != null) { - parentActivity.supportInvalidateOptionsMenu(); + + if (timeItem != null) { + timerButton = (TimerButton)timeItem.findViewById(R.id.chat_timer); + timerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); + builder.setItems(new CharSequence[]{ + LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever), + LocaleController.getString("ShortMessageLifetime2s", R.string.ShortMessageLifetime2s), + LocaleController.getString("ShortMessageLifetime5s", R.string.ShortMessageLifetime5s), + LocaleController.getString("ShortMessageLifetime1m", R.string.ShortMessageLifetime1m), + LocaleController.getString("ShortMessageLifetime1h", R.string.ShortMessageLifetime1h), + LocaleController.getString("ShortMessageLifetime1d", R.string.ShortMessageLifetime1d), + LocaleController.getString("ShortMessageLifetime1w", R.string.ShortMessageLifetime1w) + + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + int oldValue = currentEncryptedChat.ttl; + if (which == 0) { + currentEncryptedChat.ttl = 0; + } else if (which == 1) { + currentEncryptedChat.ttl = 2; + } else if (which == 2) { + currentEncryptedChat.ttl = 5; + } else if (which == 3) { + currentEncryptedChat.ttl = 60; + } else if (which == 4) { + currentEncryptedChat.ttl = 60 * 60; + } else if (which == 5) { + currentEncryptedChat.ttl = 60 * 60 * 24; + } else if (which == 6) { + currentEncryptedChat.ttl = 60 * 60 * 24 * 7; + } + if (oldValue != currentEncryptedChat.ttl) { + MessagesController.getInstance().sendTTLMessage(currentEncryptedChat); + MessagesStorage.getInstance().updateEncryptedChat(currentEncryptedChat); + } + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + visibleDialog = builder.show(); + visibleDialog.setCanceledOnTouchOutside(true); + } + }); + timerButton.setTime(currentEncryptedChat.ttl); + } + + if (avatarImageView != null) { + TLRPC.FileLocation photo = null; + int placeHolderId = 0; + if (currentUser != null) { + if (currentUser.photo != null) { + photo = currentUser.photo.photo_small; + } + placeHolderId = Utilities.getUserAvatarForId(currentUser.id); + } else if (currentChat != null) { + if (currentChat.photo != null) { + photo = currentChat.photo.photo_small; + } + placeHolderId = Utilities.getGroupAvatarForId(currentChat.id); + } + avatarImageView.setImage(photo, "50_50", placeHolderId); } } @@ -1372,8 +1495,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa selectedMessagesCanCopyIds.put(messageObject.messageOwner.id, messageObject); } } - if (mActionMode != null && mActionMode.getMenu() != null) { - mActionMode.getMenu().findItem(copy).setVisible(selectedMessagesCanCopyIds.size() != 0); + if (actionBarLayer.isActionModeShowed()) { + if (selectedMessagesIds.isEmpty()) { + actionBarLayer.hideActionMode(); + } + actionBarLayer.createActionMode().getItem(copy).setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE); } } @@ -1399,58 +1525,26 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void updateActionModeTitle() { - if (mActionMode == null) { + if (!actionBarLayer.isActionModeShowed()) { return; } - if (selectedMessagesIds.isEmpty()) { - mActionMode.finish(); - } else { - mActionMode.setTitle(LocaleController.formatString("Selected", R.string.Selected, selectedMessagesIds.size())); + if (!selectedMessagesIds.isEmpty()) { + selectedMessagesCountTextView.setText(LocaleController.formatString("Selected", R.string.Selected, selectedMessagesIds.size())); } } private void updateSubtitle() { - if (isFinish) { - return; - } - - if (paused || getActivity() == null) { - return; - } - - ActionBar actionBar = parentActivity.getSupportActionBar(); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (currentChat != null) { - actionBar.setTitle(currentChat.title); - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } + actionBarLayer.setTitle(currentChat.title); } else if (currentUser != null) { if (currentUser.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(currentUser.id) == null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().loadingContacts)) { if (currentUser.phone != null && currentUser.phone.length() != 0) { - actionBar.setTitle(PhoneFormat.getInstance().format("+" + currentUser.phone)); + actionBarLayer.setTitle(PhoneFormat.getInstance().format("+" + currentUser.phone)); } else { - actionBar.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name)); + actionBarLayer.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name)); } } else { - actionBar.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name)); - } - - if (title != null) { - if (currentEncryptedChat != null) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); - title.setCompoundDrawablePadding(Utilities.dp(4)); - } else { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } + actionBarLayer.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name)); } } @@ -1460,14 +1554,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa setTypingAnimation(false); if (currentChat != null) { if (currentChat instanceof TLRPC.TL_chatForbidden) { - actionBar.setSubtitle(LocaleController.getString("YouWereKicked", R.string.YouWereKicked)); + actionBarLayer.setSubtitle(LocaleController.getString("YouWereKicked", R.string.YouWereKicked)); } else if (currentChat.left) { - actionBar.setSubtitle(LocaleController.getString("YouLeft", R.string.YouLeft)); + actionBarLayer.setSubtitle(LocaleController.getString("YouLeft", R.string.YouLeft)); } else { if (onlineCount > 0 && currentChat.participants_count != 0) { - actionBar.setSubtitle(String.format("%d %s, %d %s", currentChat.participants_count, LocaleController.getString("Members", R.string.Members), onlineCount, LocaleController.getString("Online", R.string.Online))); + actionBarLayer.setSubtitle(String.format("%d %s, %d %s", currentChat.participants_count, LocaleController.getString("Members", R.string.Members), onlineCount, LocaleController.getString("Online", R.string.Online))); } else { - actionBar.setSubtitle(String.format("%d %s", currentChat.participants_count, LocaleController.getString("Members", R.string.Members))); + actionBarLayer.setSubtitle(String.format("%d %s", currentChat.participants_count, LocaleController.getString("Members", R.string.Members))); } } } else if (currentUser != null) { @@ -1475,11 +1569,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (user != null) { currentUser = user; } - actionBar.setSubtitle(LocaleController.formatUserStatus(currentUser)); + actionBarLayer.setSubtitle(LocaleController.formatUserStatus(currentUser)); } } else { lastPrintString = printString; - actionBar.setSubtitle(printString); + actionBarLayer.setSubtitle(printString); setTypingAnimation(true); } } @@ -1516,7 +1610,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa @Override public void onSizeChanged(int height) { Rect localRect = new Rect(); - parentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect); + getParentActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect); WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE); if (manager == null || manager.getDefaultDisplay() == null) { @@ -1527,15 +1621,15 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (height > Utilities.dp(50)) { if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { keyboardHeightLand = height; - parentActivity.getSharedPreferences("emoji", 0).edit().putInt("kbd_height_land3", keyboardHeightLand).commit(); + ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height_land3", keyboardHeightLand).commit(); } else { keyboardHeight = height; - parentActivity.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit(); + ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit(); } } if (emojiPopup != null && emojiPopup.isShowing()) { - WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE); + WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE); final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams)emojiPopup.getContentView().getLayoutParams(); layoutParams.width = contentView.getWidth(); if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { @@ -1977,12 +2071,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } } } else if (id == 999) { - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - chatListView.invalidateViews(); - } + if (chatListView != null) { + chatListView.invalidateViews(); } if (emojiView != null) { emojiView.invalidateViews(); @@ -1995,13 +2085,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_NAME) != 0) { checkAndUpdateAvatar(); - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - updateVisibleRows(); - } - } + updateVisibleRows(); } if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) { CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id); @@ -2185,13 +2269,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } } if (updated) { - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - updateVisibleRows(); - } - } + updateVisibleRows(); } } else if (id == MessagesController.messagesDeleted) { ArrayList markAsDeletedMessages = (ArrayList)args[0]; @@ -2249,13 +2327,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa messagesDict.put(newMsgId, obj); obj.messageOwner.id = newMsgId; obj.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SENT; - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - updateVisibleRows(); - } - } + updateVisibleRows(); if (obj.messageOwner.attachPath != null && obj.messageOwner.attachPath.length() != 0) { progressBarMap.remove(obj.messageOwner.attachPath); } @@ -2268,26 +2340,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa progressBarMap.remove(obj.messageOwner.attachPath); } obj.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SENT; - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - updateVisibleRows(); - } - } + updateVisibleRows(); } } else if (id == MessagesController.messageSendError) { Integer msgId = (Integer)args[0]; MessageObject obj = messagesDict.get(msgId); if (obj != null) { obj.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SEND_ERROR; - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - updateVisibleRows(); - } - } + updateVisibleRows(); if (obj.messageOwner.attachPath != null && obj.messageOwner.attachPath.length() != 0) { progressBarMap.remove(obj.messageOwner.attachPath); } @@ -2321,25 +2381,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa String location = (String)args[0]; if (loadingFile.containsKey(location)) { loadingFile.remove(location); - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - updateVisibleRows(); - } - } + updateVisibleRows(); } } else if (id == FileLoader.FileDidLoaded) { String location = (String)args[0]; if (loadingFile.containsKey(location)) { loadingFile.remove(location); - if (animationInProgress) { - invalidateAfterAnimation = true; - } else { - if (chatListView != null) { - updateVisibleRows(); - } - } + updateVisibleRows(); } } else if (id == FileLoader.FileLoadProgressChanged) { String location = (String)args[0]; @@ -2375,9 +2423,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa obj.messageOwner.unread = false; } } - if (chatListView != null) { - updateVisibleRows(); - } + updateVisibleRows(); } } else if (id == MediaController.audioDidReset) { Integer mid = (Integer)args[0]; @@ -2436,11 +2482,10 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } maxDate = Integer.MIN_VALUE; minDate = 0; + selectedMessagesIds.clear(); + selectedMessagesCanCopyIds.clear(); + actionBarLayer.hideActionMode(); chatAdapter.notifyDataSetChanged(); - if (mActionMode != null) { - mActionMode.finish(); - mActionMode = null; - } } else if (id == MediaController.recordStartError || id == MediaController.recordStopped) { if (recordingAudio) { recordingAudio = false; @@ -2500,14 +2545,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa topPanel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (parentActivity == null) { - return; - } - ContactAddActivity fragment = new ContactAddActivity(); Bundle args = new Bundle(); args.putInt("user_id", currentUser.id); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "add_contact_" + currentUser.id, false); + presentFragment(new ContactAddActivity(args)); } }); } @@ -2538,7 +2578,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void createEmojiPopup() { - emojiView = new EmojiView(parentActivity); + emojiView = new EmojiView(getParentActivity()); emojiView.setListener(new EmojiView.Listener() { public void onBackspace() { messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67)); @@ -2556,10 +2596,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void showEmojiPopup(boolean show) { - if (parentActivity == null) { - return; - } - InputMethodManager localInputMethodManager = (InputMethodManager)parentActivity.getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager localInputMethodManager = (InputMethodManager)ApplicationLoader.applicationContext.getSystemService(Context.INPUT_METHOD_SERVICE); if (show) { if (emojiPopup == null) { createEmojiPopup(); @@ -2568,10 +2605,10 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE); int rotation = manager.getDefaultDisplay().getRotation(); if (keyboardHeight <= 0) { - keyboardHeight = parentActivity.getSharedPreferences("emoji", 0).getInt("kbd_height", Utilities.dp(200)); + keyboardHeight = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height", Utilities.dp(200)); } if (keyboardHeightLand <= 0) { - keyboardHeightLand = parentActivity.getSharedPreferences("emoji", 0).getInt("kbd_height_land3", Utilities.dp(200)); + keyboardHeightLand = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height_land3", Utilities.dp(200)); } if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { currentHeight = keyboardHeightLand; @@ -2581,7 +2618,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY)); emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(contentView.getWidth(), View.MeasureSpec.EXACTLY)); - emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), 83, 0, 0); + emojiPopup.showAtLocation(getParentActivity().getWindow().getDecorView(), 83, 0, 0); if (!keyboardVisible) { contentView.setPadding(0, 0, 0, currentHeight); emojiButton.setImageResource(R.drawable.ic_msg_panel_hide); @@ -2613,29 +2650,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - updateSubtitle(); - ((LaunchActivity)parentActivity).fixBackButton(); - } - @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (!firstStart && chatAdapter != null) { + showActionBar(); + + checkActionBarMenu(); + if (chatAdapter != null) { chatAdapter.notifyDataSetChanged(); } MessagesController.getInstance().openned_dialog_id = dialog_id; @@ -2652,8 +2672,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa scrollToTopUnReadOnResume = false; scrollToTopOnResume = false; } - firstStart = false; - swipeOpening = false; if (emojiView != null) { emojiView.loadRecents(); } @@ -2662,11 +2680,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa readWhenResume = false; MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, readWithMid, 0, readWithDate, true); } - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); + fixLayout(); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); String lastMessageText = preferences.getString("dialog_" + dialog_id, null); @@ -2695,40 +2709,36 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } } + @Override + public void onBeginSlide() { + hideEmojiPopup(); + } + private void setTypingAnimation(boolean start) { - TextView subtitle = (TextView)parentActivity.findViewById(R.id.action_bar_subtitle); - if (subtitle == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_subtitle", "id", "android"); - subtitle = (TextView)parentActivity.findViewById(subtitleId); + if (actionBarLayer == null) { + return; } - if (subtitle != null) { - if (start) { - try { - if (currentChat != null) { - subtitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.typing_dots_chat, 0, 0, 0); - } else { - subtitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.typing_dots, 0, 0, 0); - } - subtitle.setCompoundDrawablePadding(Utilities.dp(4)); - AnimationDrawable mAnim = (AnimationDrawable)subtitle.getCompoundDrawables()[0]; - mAnim.setAlpha(200); - mAnim.start(); - } catch (Exception e) { - FileLog.e("tmessages", e); + if (start) { + try { + if (currentChat != null) { + actionBarLayer.setSubTitleIcon(R.drawable.typing_dots_chat, Utilities.dp(4)); + } else { + actionBarLayer.setSubTitleIcon(R.drawable.typing_dots, Utilities.dp(4)); } - } else { - subtitle.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + AnimationDrawable mAnim = (AnimationDrawable)actionBarLayer.getSubTitleIcon(); + mAnim.setAlpha(200); + mAnim.start(); + } catch (Exception e) { + FileLog.e("tmessages", e); } + } else { + actionBarLayer.setSubTitleIcon(0, 0); } } @Override public void onPause() { - super.onPause(); - if (mActionMode != null) { - mActionMode.finish(); - mActionMode = null; - } + actionBarLayer.hideActionMode(); hideEmojiPopup(); paused = true; MessagesController.getInstance().openned_dialog_id = 0; @@ -2772,214 +2782,32 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void fixLayout() { - if (chatListView != null) { - ViewTreeObserver obs = chatListView.getViewTreeObserver(); - obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - if (parentActivity == null) { - chatListView.getViewTreeObserver().removeOnPreDrawListener(this); - return false; - } - WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE); - Display display = manager.getDefaultDisplay(); - int rotation = Surface.ROTATION_0; - if (display != null) { - rotation = display.getRotation(); - } - int height; - int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight(); - - if (currentActionBarHeight != Utilities.dp(48) && currentActionBarHeight != Utilities.dp(40)) { - height = currentActionBarHeight; - } else { - height = Utilities.dp(48); - if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { - height = Utilities.dp(40); - } - } - - if (avatarImageView != null) { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) avatarImageView.getLayoutParams(); - params.width = height; - params.height = height; - avatarImageView.setLayoutParams(params); - } - - chatListView.getViewTreeObserver().removeOnPreDrawListener(this); - - if (currentEncryptedChat != null) { - TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView) parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); - title.setCompoundDrawablePadding(Utilities.dp(4)); - } - } - - return false; + ViewTreeObserver obs = chatListView.getViewTreeObserver(); + obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + int height = Utilities.dp(48); + if (getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + height = Utilities.dp(40); + selectedMessagesCountTextView.setTextSize(16); + } else { + selectedMessagesCountTextView.setTextSize(18); } - }); - } + if (avatarImageView != null) { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) avatarImageView.getLayoutParams(); + params.width = height; + params.height = height; + avatarImageView.setLayoutParams(params); + } + chatListView.getViewTreeObserver().removeOnPreDrawListener(this); + return false; + } + }); } @Override public void onConfigurationChanged(android.content.res.Configuration newConfig) { - super.onConfigurationChanged(newConfig); fixLayout(); - - if (parentActivity != null) { - Display display = parentActivity.getWindowManager().getDefaultDisplay(); - if(android.os.Build.VERSION.SDK_INT < 13) { - displaySize.set(display.getWidth(), display.getHeight()); - } else { - display.getSize(displaySize); - } - } - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - menu.clear(); - - SupportMenuItem timeItem = null; - - if (currentEncryptedChat != null) { - timeItem = (SupportMenuItem)menu.add(Menu.NONE, chat_enc_timer, Menu.NONE, null); - timeItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - timeItem.setActionView(R.layout.chat_header_enc_layout); - } - - SubMenu subMenu = menu.addSubMenu(Menu.NONE, chat_menu_attach, Menu.NONE, LocaleController.getString("Attach", R.string.Attach)).setIcon(R.drawable.ic_ab_attach); - SupportMenuItem menuItem = (SupportMenuItem)subMenu.getItem(); - menuItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - - subMenu.add(Menu.NONE, attach_photo, Menu.NONE, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto)).setIcon(R.drawable.ic_attach_photo); - subMenu.add(Menu.NONE, attach_gallery, Menu.NONE, LocaleController.getString("ChatGallery", R.string.ChatGallery)).setIcon(R.drawable.ic_attach_gallery); - subMenu.add(Menu.NONE, attach_video, Menu.NONE, LocaleController.getString("ChatVideo", R.string.ChatVideo)).setIcon(R.drawable.ic_attach_video); - subMenu.add(Menu.NONE, attach_document, Menu.NONE, LocaleController.getString("ChatDocument", R.string.ChatDocument)).setIcon(R.drawable.ic_ab_doc); - subMenu.add(Menu.NONE, attach_location, Menu.NONE, LocaleController.getString("ChatLocation", R.string.ChatLocation)).setIcon(R.drawable.ic_attach_location); - - SupportMenuItem avatarItem = (SupportMenuItem)menu.add(Menu.NONE, chat_menu_avatar, Menu.NONE, null); - avatarItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - avatarItem.setActionView(R.layout.chat_header_layout); - - if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat) || - currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) || - currentUser != null && (currentUser instanceof TLRPC.TL_userDeleted || currentUser instanceof TLRPC.TL_userEmpty)) { - - if (menuItem != null) { - menuItem.setVisible(false); - } - - if (timeItem != null) { - timeItem.setVisible(false); - } - } - - if (timeItem != null && timeItem.getActionView() != null) { - timerButton = (TimerButton)timeItem.getActionView().findViewById(R.id.chat_timer); - timerButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); - builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); - builder.setItems(new CharSequence[]{ - LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever), - LocaleController.getString("ShortMessageLifetime2s", R.string.ShortMessageLifetime2s), - LocaleController.getString("ShortMessageLifetime5s", R.string.ShortMessageLifetime5s), - LocaleController.getString("ShortMessageLifetime1m", R.string.ShortMessageLifetime1m), - LocaleController.getString("ShortMessageLifetime1h", R.string.ShortMessageLifetime1h), - LocaleController.getString("ShortMessageLifetime1d", R.string.ShortMessageLifetime1d), - LocaleController.getString("ShortMessageLifetime1w", R.string.ShortMessageLifetime1w) - - }, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - int oldValue = currentEncryptedChat.ttl; - if (which == 0) { - currentEncryptedChat.ttl = 0; - } else if (which == 1) { - currentEncryptedChat.ttl = 2; - } else if (which == 2) { - currentEncryptedChat.ttl = 5; - } else if (which == 3) { - currentEncryptedChat.ttl = 60; - } else if (which == 4) { - currentEncryptedChat.ttl = 60 * 60; - } else if (which == 5) { - currentEncryptedChat.ttl = 60 * 60 * 24; - } else if (which == 6) { - currentEncryptedChat.ttl = 60 * 60 * 24 * 7; - } - if (oldValue != currentEncryptedChat.ttl) { - MessagesController.getInstance().sendTTLMessage(currentEncryptedChat); - MessagesStorage.getInstance().updateEncryptedChat(currentEncryptedChat); - } - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - visibleDialog = builder.show(); - visibleDialog.setCanceledOnTouchOutside(true); - } - }); - timerButton.setTime(currentEncryptedChat.ttl); - } - - View avatarLayout = avatarItem.getActionView(); - avatarImageView = (BackupImageView)avatarLayout.findViewById(R.id.chat_avatar_image); - - avatarImageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (parentActivity == null) { - return; - } - if (currentUser != null) { - UserProfileActivity fragment = new UserProfileActivity(); - Bundle args = new Bundle(); - args.putInt("user_id", currentUser.id); - if (currentEncryptedChat != null) { - args.putLong("dialog_id", dialog_id); - } - fragment.setArguments(args); - ((LaunchActivity) parentActivity).presentFragment(fragment, "user_" + currentUser.id, swipeOpening); - } else if (currentChat != null) { - if (info != null) { - if (info instanceof TLRPC.TL_chatParticipantsForbidden) { - return; - } - NotificationCenter.getInstance().addToMemCache(5, info); - } - if (currentChat.participants_count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) { - return; - } - ChatProfileActivity fragment = new ChatProfileActivity(); - Bundle args = new Bundle(); - args.putInt("chat_id", currentChat.id); - fragment.setArguments(args); - ((LaunchActivity) parentActivity).presentFragment(fragment, "chat_" + currentChat.id, swipeOpening); - } - } - }); - - TLRPC.FileLocation photo = null; - int placeHolderId = 0; - if (currentUser != null) { - if (currentUser.photo != null) { - photo = currentUser.photo.photo_small; - } - placeHolderId = Utilities.getUserAvatarForId(currentUser.id); - } else if (currentChat != null) { - if (currentChat.photo != null) { - photo = currentChat.photo.photo_small; - } - placeHolderId = Utilities.getGroupAvatarForId(currentChat.id); - } - avatarImageView.setImage(photo, "50_50", placeHolderId); } private View getRowParentView(View v) { @@ -3001,13 +2829,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } public void createMenu(View v, boolean single) { - if (mActionMode != null || parentActivity == null || getActivity() == null || isFinish || swipeOpening) { + if (actionBarLayer.isActionModeShowed()) { return; } - selectedMessagesCanCopyIds.clear(); selectedObject = null; forwaringMessage = null; + selectedMessagesCanCopyIds.clear(); selectedMessagesIds.clear(); View parentView = getRowParentView(v); if (parentView == null) { @@ -3024,7 +2852,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (single || type < 2) { if (type >= 0) { selectedObject = message; - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = null; @@ -3102,11 +2930,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (i == 0) { String fileName = selectedObject.getFileName(); if (selectedObject.type == 3) { - MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 1, null); + MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 1, null); } else if (selectedObject.type == 1) { - MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 0, null); + MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 0, null); } else if (selectedObject.type == 8 || selectedObject.type == 9) { - MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 2, selectedObject.messageOwner.media.document.file_name); + MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 2, selectedObject.messageOwner.media.document.file_name); } } else if (i == 1) { processSelectedOption(2); @@ -3125,11 +2953,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (i == 1) { String fileName = selectedObject.getFileName(); if (selectedObject.type == 3) { - MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 1, null); + MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 1, null); } else if (selectedObject.type == 1) { - MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 0, null); + MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 0, null); } else if (selectedObject.type == 8 || selectedObject.type == 9) { - MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, parentActivity, 2, selectedObject.messageOwner.media.document.file_name); + MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 2, selectedObject.messageOwner.media.document.file_name); } } else if (i == 2) { processSelectedOption(2); @@ -3156,13 +2984,10 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } } if (locFile != null) { - if (parentActivity == null) { - return; - } if (LocaleController.getInstance().applyLanguageFile(locFile)) { - ((LaunchActivity)parentActivity).presentFragment(new LanguageSelectActivity(), "settings_lang", false); - } else if (parentActivity != null) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + presentFragment(new LanguageSelectActivity()); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); @@ -3195,8 +3020,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } return; } + actionBarLayer.showActionMode(); addToSelectedMessages(message); - mActionMode = parentActivity.startSupportActionMode(mActionModeCallback); updateActionModeTitle(); updateVisibleRows(); } @@ -3264,30 +3089,24 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } } else if (option == 2) { if (selectedObject != null) { - if (parentActivity == null) { - return; - } forwaringMessage = selectedObject; selectedObject = null; - MessagesActivity fragment = new MessagesActivity(); - fragment.selectAlertString = R.string.ForwardMessagesTo; - fragment.selectAlertStringDesc = "ForwardMessagesTo"; - fragment.animationType = 1; Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putBoolean("serverOnly", true); - fragment.setArguments(args); - fragment.delegate = this; - ((LaunchActivity)parentActivity).presentFragment(fragment, "select_chat", false); + args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo)); + MessagesActivity fragment = new MessagesActivity(args); + fragment.setDelegate(this); + presentFragment(fragment); } } else if (option == 3) { if (selectedObject != null) { if(android.os.Build.VERSION.SDK_INT < 11) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); + android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(selectedObject.messageText); } else { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedObject.messageText); clipboard.setPrimaryClip(clip); } @@ -3342,29 +3161,17 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (did != dialog_id) { int lower_part = (int)did; if (lower_part != 0) { - ActionBarActivity inflaterActivity = parentActivity; - if (inflaterActivity == null) { - inflaterActivity = (ActionBarActivity)getActivity(); - } activity.removeSelfFromStack(); - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); + + Bundle args = new Bundle(); + args.putBoolean("scrollToTopOnResume", scrollToTopOnResume); if (lower_part > 0) { - bundle.putInt("user_id", lower_part); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - ActionBarActivity act = (ActionBarActivity)getActivity(); - if (inflaterActivity != null) { - ((LaunchActivity)inflaterActivity).presentFragment(fragment, "chat" + Math.random(), false); - } + args.putInt("user_id", lower_part); } else if (lower_part < 0) { - bundle.putInt("chat_id", -lower_part); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - if (inflaterActivity != null) { - ((LaunchActivity)inflaterActivity).presentFragment(fragment, "chat" + Math.random(), false); - } + args.putInt("chat_id", -lower_part); } + presentFragment(new ChatActivity(args)); + removeSelfFromStack(); if (forwaringMessage != null) { if (forwaringMessage.messageOwner.id > 0) { @@ -3379,6 +3186,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa MessagesController.getInstance().sendMessage(selectedMessagesIds.get(id), did); } } + selectedMessagesCanCopyIds.clear(); selectedMessagesIds.clear(); } } else { @@ -3400,6 +3208,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa for (Integer id : ids) { MessagesController.getInstance().sendMessage(selectedMessagesIds.get(id), did); } + selectedMessagesCanCopyIds.clear(); selectedMessagesIds.clear(); } chatListView.setSelection(messages.size() + 1); @@ -3410,86 +3219,15 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa @Override public boolean onBackPressed() { - if (emojiPopup != null && emojiPopup.isShowing()) { + if (actionBarLayer.isActionModeShowed()) { + selectedMessagesIds.clear(); + selectedMessagesCanCopyIds.clear(); + actionBarLayer.hideActionMode(); + updateVisibleRows(); + return false; + } else if (emojiPopup != null && emojiPopup.isShowing()) { hideEmojiPopup(); return false; - } else { - return true; - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - case attach_photo: { - try { - Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - File image = Utilities.generatePicturePath(); - if (image != null) { - takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); - currentPicturePath = image.getAbsolutePath(); - } - parentActivity.startActivityForResult(takePictureIntent, 0); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - break; - } - case attach_gallery: { - try { - Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); - photoPickerIntent.setType("image/*"); - parentActivity.startActivityForResult(photoPickerIntent, 1); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - break; - } - case attach_video: { - try { - Intent pickIntent = new Intent(); - pickIntent.setType("video/*"); - pickIntent.setAction(Intent.ACTION_GET_CONTENT); - pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long)(1024 * 1024 * 1000)); - Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); - File video = Utilities.generateVideoPath(); - if (video != null) { - if(android.os.Build.VERSION.SDK_INT > 16) { - takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video)); - } - takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long)(1024 * 1024 * 1000)); - currentPicturePath = video.getAbsolutePath(); - } - Intent chooserIntent = Intent.createChooser(pickIntent, ""); - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent }); - - parentActivity.startActivityForResult(chooserIntent, 2); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - break; - } - case attach_location: { - if (!isGoogleMapsInstalled() || parentActivity == null) { - return true; - } - LocationActivity fragment = new LocationActivity(); - ((LaunchActivity)parentActivity).presentFragment(fragment, "location", false); - break; - } - case attach_document: { - if (parentActivity == null) { - return true; - } - DocumentSelectActivity fragment = new DocumentSelectActivity(); - fragment.delegate = this; - ((LaunchActivity)parentActivity).presentFragment(fragment, "document", false); - break; - } } return true; } @@ -3499,7 +3237,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ApplicationInfo info = ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 ); return true; } catch(PackageManager.NameNotFoundException e) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage("Install Google Maps?"); builder.setCancelable(true); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @@ -3507,7 +3245,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa public void onClick(DialogInterface dialogInterface, int i) { try { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")); - startActivity(intent); + getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -3535,7 +3273,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa boolean disableSelection = false; boolean selected = false; - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { if (selectedMessagesIds.containsKey(holder.message.messageOwner.id)) { view.setBackgroundColor(0x6633b5e5); selected = true; @@ -3552,7 +3290,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa boolean disableSelection = false; boolean selected = false; - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { if (selectedMessagesIds.containsKey(cell.getMessageObject().messageOwner.id)) { view.setBackgroundColor(0x6633b5e5); selected = true; @@ -3621,7 +3359,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void alertUserOpenError(MessageObject message) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(R.string.OK, null); if (message.type == 3) { @@ -3746,7 +3484,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa boolean selected = false; boolean disableSelection = false; - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { if (selectedMessagesIds.containsKey(message.messageOwner.id)) { view.setBackgroundColor(0x6633b5e5); selected = true; @@ -3763,11 +3501,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa @Override public void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user) { if (user != null && user.id != UserConfig.clientUserId) { - UserProfileActivity fragment = new UserProfileActivity(); Bundle args = new Bundle(); args.putInt("user_id", user.id); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "user_" + user.id, false); + presentFragment(new UserProfileActivity(args)); } } @@ -3786,17 +3522,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa @Override public boolean canPerformActions() { - return mActionMode == null; - } - - @Override - public boolean onSwipeLeft() { - return ChatActivity.this.onSwipeLeft(); - } - - @Override - public boolean onSwipeRight() { - return ChatActivity.this.onSwipeRight(); + return !actionBarLayer.isActionModeShowed(); } }; if (view instanceof ChatMediaCell) { @@ -3812,8 +3538,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } if (message.type == 1) { NotificationCenter.getInstance().addToMemCache(51, message); - Intent intent = new Intent(parentActivity, GalleryImageViewer.class); - startActivity(intent); + Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class); + getParentActivity().startActivity(intent); } else if (message.type == 3) { try { File f = null; @@ -3825,7 +3551,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(f), "video/mp4"); - startActivity(intent); + getParentActivity().startActivity(intent); } catch (Exception e) { alertUserOpenError(message); } @@ -3834,8 +3560,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa return; } NotificationCenter.getInstance().addToMemCache(0, message); - LocationActivity fragment = new LocationActivity(); - ((LaunchActivity)parentActivity).presentFragment(fragment, "location_view", false); + presentFragment(new LocationActivity()); } } }; @@ -3951,7 +3676,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } if (type == 11 || type == 10) { - int width = displaySize.x - Utilities.dp(30); + int width = Utilities.displaySize.x - Utilities.dp(30); messageTextView.setText(message.messageText); messageTextView.setMaxWidth(width); @@ -4202,15 +3927,15 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa int width; if (currentChat != null && type != 8) { if (actionView.getVisibility() == View.VISIBLE) { - width = displaySize.x - Utilities.dp(290); + width = Utilities.displaySize.x - Utilities.dp(290); } else { - width = displaySize.x - Utilities.dp(270); + width = Utilities.displaySize.x - Utilities.dp(270); } } else { if (actionView.getVisibility() == View.VISIBLE) { - width = displaySize.x - Utilities.dp(240); + width = Utilities.displaySize.x - Utilities.dp(240); } else { - width = displaySize.x - Utilities.dp(220); + width = Utilities.displaySize.x - Utilities.dp(220); } } nameTextView.setMaxWidth(width); @@ -4270,16 +3995,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa addContactButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { processRowSelect(view); return; } - ContactAddActivity fragment = new ContactAddActivity(); Bundle args = new Bundle(); args.putInt("user_id", message.messageOwner.media.user_id); args.putString("phone", message.messageOwner.media.phone_number); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "add_contact_" + message.messageOwner.media.user_id, false); + presentFragment(new ContactAddActivity(args)); } }); @@ -4299,7 +4022,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (message.type == 8 || message.type == 9) { processOnClick(view); } else if (message.type == 12 || message.type == 13) { - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { processRowSelect(view); return; } @@ -4309,16 +4032,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa user = MessagesController.getInstance().users.get(message.messageOwner.media.user_id); } if (user != null) { - UserProfileActivity fragment = new UserProfileActivity(); Bundle args = new Bundle(); args.putInt("user_id", message.messageOwner.media.user_id); - fragment.setArguments(args); - ((LaunchActivity) parentActivity).presentFragment(fragment, "user_" + message.messageOwner.media.user_id, false); + presentFragment(new UserProfileActivity(args)); } else { - if (parentActivity == null || message.messageOwner.media.phone_number == null || message.messageOwner.media.phone_number.length() == 0) { + if (message.messageOwner.media.phone_number == null || message.messageOwner.media.phone_number.length() == 0) { return; } - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { @@ -4326,24 +4047,17 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa try { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + message.messageOwner.media.phone_number)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == 0) { - ActionBarActivity inflaterActivity = parentActivity; - if (inflaterActivity == null) { - inflaterActivity = (ActionBarActivity)getActivity(); - } - if (inflaterActivity == null) { - return; - } int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager)inflaterActivity.getSystemService(Context.CLIPBOARD_SERVICE); + android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(message.messageOwner.media.phone_number); } else { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager)inflaterActivity.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", message.messageOwner.media.phone_number); clipboard.setPrimaryClip(clip); } @@ -4395,16 +4109,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa avatarImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { processRowSelect(view); return; } if (message != null) { - UserProfileActivity fragment = new UserProfileActivity(); Bundle args = new Bundle(); args.putInt("user_id", message.messageOwner.from_id); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "user_" + message.messageOwner.from_id, false); + presentFragment(new UserProfileActivity(args)); } } }); @@ -4456,15 +4168,15 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void processOnClick(View view) { - if (mActionMode != null) { + if (actionBarLayer.isActionModeShowed()) { processRowSelect(view); return; } if (message != null) { if (message.type == 11) { NotificationCenter.getInstance().addToMemCache(51, message); - Intent intent = new Intent(parentActivity, GalleryImageViewer.class); - startActivity(intent); + Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class); + getParentActivity().startActivity(intent); } else if (message.type == 8 || message.type == 9) { File f = null; String fileName = message.getFileName(); @@ -4495,13 +4207,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } if (realMimeType != null) { try { - startActivity(intent); + getParentActivity().startActivity(intent); } catch (Exception e) { intent.setDataAndType(Uri.fromFile(f), "text/plain"); - startActivity(intent); + getParentActivity().startActivity(intent); } } else { - startActivity(intent); + getParentActivity().startActivity(intent); } } catch (Exception e) { alertUserOpenError(message); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java index 299df030..8442c93d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java @@ -20,13 +20,8 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.provider.Settings; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v7.app.ActionBar; import android.text.Html; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -45,10 +40,11 @@ import org.telegram.messenger.R; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; import org.telegram.ui.Cells.ChatOrUserCell; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.AvatarUpdater; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.BaseFragment; import java.util.ArrayList; import java.util.Collections; @@ -79,6 +75,12 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen private int leaveGroupRow; private int rowCount = 0; + private static final int done_button = 1; + + public ChatProfileActivity(Bundle args) { + super(args); + } + @Override public boolean onFragmentCreate() { super.onFragmentCreate(); @@ -140,19 +142,31 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen avatarUpdater.clear(); } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("GroupInfo", R.string.GroupInfo)); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } else if (id == done_button) { + openAddMenu(); + } + } + }); + ActionBarMenu menu = actionBarLayer.createMenu(); + View item = menu.addItemResource(done_button, R.layout.group_profile_add_member_layout); + TextView textView = (TextView)item.findViewById(R.id.done_button); + if (textView != null) { + textView.setText(LocaleController.getString("AddMember", R.string.AddMember)); + } + fragmentView = inflater.inflate(R.layout.chat_profile_layout, container, false); listView = (ListView)fragmentView.findViewById(R.id.listView); - listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity)); + listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity())); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { @@ -166,7 +180,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } selectedUser = user; - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] {LocaleController.getString("KickFromGroup", R.string.KickFromGroup)}; builder.setItems(items, new DialogInterface.OnClickListener() { @@ -188,16 +202,13 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, final int i, long l) { - if (parentActivity == null) { - return; - } if (i == settingsSoundRow) { try { Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); - SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Uri currentSound = null; String defaultPath = null; @@ -216,16 +227,14 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); - parentActivity.startActivityForResult(tmpIntent, 3); + getParentActivity().startActivityForResult(tmpIntent, 3); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == sharedMediaRow) { - MediaActivity fragment = new MediaActivity(); - Bundle bundle = new Bundle(); - bundle.putLong("dialog_id", -chat_id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "media_chat_" + chat_id, false); + Bundle args = new Bundle(); + args.putLong("dialog_id", -chat_id); + presentFragment(new MediaActivity(args)); } else if (i == addMemberRow) { openAddMenu(); } else if (i > membersSectionRow && i < addMemberRow) { @@ -233,13 +242,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen if (user_id == UserConfig.clientUserId) { return; } - UserProfileActivity fragment = new UserProfileActivity(); Bundle args = new Bundle(); args.putInt("user_id", user_id); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "user_" + user_id, false); + presentFragment(new UserProfileActivity(args)); } else if (i == settingsVibrateRow || i == settingsNotificationsRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems(new CharSequence[] { LocaleController.getString("Default", R.string.Default), @@ -266,12 +273,6 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } } }); - - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -293,19 +294,19 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen if (requestCode == 3) { Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); String name = null; - if (ringtone != null && parentActivity != null) { - Ringtone rng = RingtoneManager.getRingtone(parentActivity, ringtone); + if (ringtone != null) { + Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone); if (rng != null) { if(ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) { name = LocaleController.getString("Default", R.string.Default); } else { - name = rng.getTitle(parentActivity); + name = rng.getTitle(getParentActivity()); } rng.stop(); } } - SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (name != null && ringtone != null) { @@ -321,6 +322,20 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } } + @Override + public void saveSelfArgs(Bundle args) { + if (avatarUpdater != null && avatarUpdater.currentPicturePath != null) { + args.putString("path", avatarUpdater.currentPicturePath); + } + } + + @Override + public void restoreSelfArgs(Bundle args) { + if (avatarUpdater != null) { + avatarUpdater.currentPicturePath = args.getString("path"); + } + } + public void didReceivedNotification(int id, Object... args) { if (id == MessagesController.updateInterfaces) { int mask = (Integer)args[0]; @@ -354,55 +369,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("GroupInfo", R.string.GroupInfo)); - actionBar.setSubtitle(null); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - ((LaunchActivity)parentActivity).fixBackButton(); - } - @Override public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - } - return true; } private void updateVisibleRows(int mask) { @@ -467,14 +438,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen private void processPhotoMenu(int action) { if (action == 0) { - if (parentActivity == null) { - return; - } TLRPC.Chat chat = MessagesController.getInstance().chats.get(chat_id); if (chat.photo != null && chat.photo.photo_big != null) { NotificationCenter.getInstance().addToMemCache(53, chat.photo.photo_big); - Intent intent = new Intent(parentActivity, GalleryImageViewer.class); - startActivity(intent); + Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class); + getParentActivity().startActivity(intent); } } else if (action == 1) { avatarUpdater.openCamera(); @@ -486,25 +454,22 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } private void openAddMenu() { - ContactsActivity fragment = new ContactsActivity(); - fragment.animationType = 1; - Bundle bundle = new Bundle(); - bundle.putBoolean("onlyUsers", true); - bundle.putBoolean("destroyAfterSelect", true); - bundle.putBoolean("usersAsSections", true); - bundle.putBoolean("returnAsResult", true); - fragment.selectAlertString = R.string.AddToTheGroup; - fragment.selectAlertStringDesc = "AddToTheGroup"; - fragment.delegate = this; + Bundle args = new Bundle(); + args.putBoolean("onlyUsers", true); + args.putBoolean("destroyAfterSelect", true); + args.putBoolean("usersAsSections", true); + args.putBoolean("returnAsResult", true); + args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup)); + ContactsActivity fragment = new ContactsActivity(args); + fragment.setDelegate(this); if (info != null) { HashMap users = new HashMap(); for (TLRPC.TL_chatParticipant p : info.participants) { users.put(p.user_id, null); } - NotificationCenter.getInstance().addToMemCache(7, users); + fragment.setIgnoreUsers(users); } - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "contacts_block", false); + presentFragment(fragment); } private void kickUser(TLRPC.TL_chatParticipant user) { @@ -519,25 +484,6 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - SupportMenuItem item = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, LocaleController.getString("AddMember", R.string.AddMember)); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - LayoutInflater li = (LayoutInflater)ApplicationLoader.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - item.setActionView(R.layout.group_profile_add_member_layout); - - TextView textView = (TextView)item.getActionView().findViewById(R.id.done_button); - if (textView != null) { - textView.setText(LocaleController.getString("AddMember", R.string.AddMember)); - textView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - openAddMenu(); - } - }); - } - } - private class ListAdapter extends BaseAdapter { private Context mContext; @@ -591,11 +537,9 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ChatProfileChangeNameActivity fragment = new ChatProfileChangeNameActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("chat_id", chat_id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat_name_" + chat_id, false); + Bundle args = new Bundle(); + args.putInt("chat_id", chat_id); + presentFragment(new ChatProfileChangeNameActivity(args)); } }); @@ -603,7 +547,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; int type; TLRPC.Chat chat = MessagesController.getInstance().chats.get(chat_id); @@ -647,6 +591,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen onlineText = (TextView)view.findViewById(R.id.settings_online); } avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image); + avatarImage.processDetach = false; TextView textView = (TextView)view.findViewById(R.id.settings_name); Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf"); textView.setTypeface(typeface); @@ -753,7 +698,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java index c4f26ad6..325623e4 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileChangeNameActivity.java @@ -11,13 +11,10 @@ package org.telegram.ui; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v7.app.ActionBar; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.EditText; @@ -28,7 +25,7 @@ import org.telegram.messenger.TLRPC; import org.telegram.messenger.MessagesController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; public class ChatProfileChangeNameActivity extends BaseFragment { private EditText firstNameField; @@ -36,8 +33,8 @@ public class ChatProfileChangeNameActivity extends BaseFragment { private int chat_id; private View doneButton; - public ChatProfileChangeNameActivity() { - animationType = 1; + public ChatProfileChangeNameActivity(Bundle args) { + super(args); } @Override @@ -48,18 +45,32 @@ public class ChatProfileChangeNameActivity extends BaseFragment { } @Override - public void onFragmentDestroy() { - super.onFragmentDestroy(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setCustomView(R.layout.settings_do_action_layout); + + Button cancelButton = (Button)actionBarLayer.findViewById(R.id.cancel_button); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + finishFragment(); + } + }); + doneButton = actionBarLayer.findViewById(R.id.done_button); + doneButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (firstNameField.getText().length() != 0) { + saveName(); + finishFragment(); + } + } + }); + + cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); + TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); + textView.setText(LocaleController.getString("Done", R.string.Done)); + fragmentView = inflater.inflate(R.layout.chat_profile_change_name_layout, container, false); TLRPC.Chat currentChat = MessagesController.getInstance().chats.get(chat_id); @@ -90,54 +101,8 @@ public class ChatProfileChangeNameActivity extends BaseFragment { return fragmentView; } - @Override - public boolean canApplyUpdateStatus() { - return false; - } - - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(false); - - actionBar.setCustomView(R.layout.settings_do_action_layout); - Button cancelButton = (Button)actionBar.getCustomView().findViewById(R.id.cancel_button); - cancelButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finishFragment(); - } - }); - doneButton = actionBar.getCustomView().findViewById(R.id.done_button); - doneButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (firstNameField.getText().length() != 0) { - saveName(); - finishFragment(); - } - } - }); - - cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); - TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); - textView.setText(LocaleController.getString("Done", R.string.Done)); - } - @Override public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).updateActionBar(); - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); boolean animations = preferences.getBoolean("view_animations", true); if (!animations) { @@ -147,31 +112,9 @@ public class ChatProfileChangeNameActivity extends BaseFragment { } @Override - public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { - if (nextAnim != 0) { - Animation anim = AnimationUtils.loadAnimation(getActivity(), nextAnim); - - anim.setAnimationListener(new Animation.AnimationListener() { - - public void onAnimationStart(Animation animation) { - ChatProfileChangeNameActivity.this.onAnimationStart(); - } - - public void onAnimationRepeat(Animation animation) { - - } - - public void onAnimationEnd(Animation animation) { - ChatProfileChangeNameActivity.this.onAnimationEnd(); - firstNameField.requestFocus(); - Utilities.showKeyboard(firstNameField); - } - }); - - return anim; - } else { - return super.onCreateAnimation(transit, enter, nextAnim); - } + public void onOpenAnimationEnd() { + firstNameField.requestFocus(); + Utilities.showKeyboard(firstNameField); } private void saveName() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java index 491ff34b..0a563725 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactAddActivity.java @@ -12,29 +12,25 @@ import android.app.Activity; import android.content.SharedPreferences; import android.graphics.Typeface; import android.os.Bundle; -import android.support.v7.app.ActionBar; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import org.telegram.PhoneFormat.PhoneFormat; +import org.telegram.messenger.ContactsController; import org.telegram.messenger.LocaleController; import org.telegram.messenger.TLRPC; -import org.telegram.messenger.ConnectionsManager; -import org.telegram.messenger.ContactsController; import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; public class ContactAddActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { private int user_id; @@ -46,14 +42,17 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent private TextView onlineText; private TextView phoneText; + public ContactAddActivity(Bundle args) { + super(args); + } + @Override public boolean onFragmentCreate() { - super.onFragmentCreate(); NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces); user_id = getArguments().getInt("user_id", 0); phone = getArguments().getString("phone"); TLRPC.User user = MessagesController.getInstance().users.get(user_id); - return user != null; + return user != null && super.onFragmentCreate(); } @Override @@ -63,8 +62,35 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setCustomView(R.layout.settings_do_action_layout); + Button cancelButton = (Button)actionBarLayer.findViewById(R.id.cancel_button); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + finishFragment(); + } + }); + doneButton = actionBarLayer.findViewById(R.id.done_button); + doneButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (firstNameField.getText().length() != 0) { + TLRPC.User user = MessagesController.getInstance().users.get(user_id); + user.first_name = firstNameField.getText().toString(); + user.last_name = lastNameField.getText().toString(); + ContactsController.getInstance().addContact(user); + finishFragment(); + NotificationCenter.getInstance().postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_NAME); + } + } + }); + + cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); + TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); + textView.setText(LocaleController.getString("Done", R.string.Done)); + fragmentView = inflater.inflate(R.layout.contact_add_layout, container, false); TLRPC.User user = MessagesController.getInstance().users.get(user_id); @@ -149,68 +175,8 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent } } - @Override - public boolean canApplyUpdateStatus() { - return false; - } - - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(false); - actionBar.setDisplayShowTitleEnabled(false); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - - actionBar.setCustomView(R.layout.settings_do_action_layout); - Button cancelButton = (Button)actionBar.getCustomView().findViewById(R.id.cancel_button); - cancelButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finishFragment(); - } - }); - doneButton = actionBar.getCustomView().findViewById(R.id.done_button); - doneButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (firstNameField.getText().length() != 0) { - TLRPC.User user = MessagesController.getInstance().users.get(user_id); - user.first_name = firstNameField.getText().toString(); - user.last_name = lastNameField.getText().toString(); - ContactsController.getInstance().addContact(user); - finishFragment(); - NotificationCenter.getInstance().postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_NAME); - } - } - }); - - cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); - TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); - textView.setText(LocaleController.getString("Done", R.string.Done)); - } - @Override public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).updateActionBar(); - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); boolean animations = preferences.getBoolean("view_animations", true); if (!animations) { @@ -220,30 +186,8 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent } @Override - public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { - if (nextAnim != 0) { - Animation anim = AnimationUtils.loadAnimation(getActivity(), nextAnim); - - anim.setAnimationListener(new Animation.AnimationListener() { - - public void onAnimationStart(Animation animation) { - ContactAddActivity.this.onAnimationStart(); - } - - public void onAnimationRepeat(Animation animation) { - - } - - public void onAnimationEnd(Animation animation) { - ContactAddActivity.this.onAnimationEnd(); - firstNameField.requestFocus(); - Utilities.showKeyboard(firstNameField); - } - }); - - return anim; - } else { - return super.onCreateAnimation(transit, enter, nextAnim); - } + public void onOpenAnimationEnd() { + firstNameField.requestFocus(); + Utilities.showKeyboard(firstNameField); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java index cee664fb..a43e285b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java @@ -15,19 +15,12 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBar; -import android.support.v7.widget.SearchView; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; -import android.widget.ImageView; +import android.widget.EditText; import android.widget.TextView; import org.telegram.messenger.LocaleController; @@ -45,13 +38,13 @@ import org.telegram.messenger.Utilities; import org.telegram.ui.Adapters.ContactsActivityAdapter; import org.telegram.ui.Adapters.ContactsActivitySearchAdapter; import org.telegram.ui.Cells.ChatOrUserCell; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; +import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.PinnedHeaderListView; import org.telegram.ui.Views.SectionedBaseAdapter; -import java.lang.reflect.Field; - import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; @@ -68,21 +61,22 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter private boolean returnAsResult; private boolean createSecretChat; private boolean creatingChat = false; - public int selectAlertString = 0; - public String selectAlertStringDesc = null; - private SearchView searchView; + private String selectAlertString = null; private TextView emptyTextView; private HashMap ignoreUsers; - private SupportMenuItem searchItem; private String inviteText; private boolean updatingInviteText = false; - public ContactsActivityDelegate delegate; + private ContactsActivityDelegate delegate; public static interface ContactsActivityDelegate { public abstract void didSelectContact(TLRPC.User user); } + public ContactsActivity(Bundle args) { + super(args); + } + @SuppressWarnings("unchecked") @Override public boolean onFragmentCreate() { @@ -90,18 +84,15 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter NotificationCenter.getInstance().addObserver(this, MessagesController.contactsDidLoaded); NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces); NotificationCenter.getInstance().addObserver(this, MessagesController.encryptedChatCreated); - if (getArguments() != null) { + if (arguments != null) { onlyUsers = getArguments().getBoolean("onlyUsers", false); destroyAfterSelect = getArguments().getBoolean("destroyAfterSelect", false); usersAsSections = getArguments().getBoolean("usersAsSections", false); returnAsResult = getArguments().getBoolean("returnAsResult", false); createSecretChat = getArguments().getBoolean("createSecretChat", false); - if (destroyAfterSelect) { - ignoreUsers = (HashMap)NotificationCenter.getInstance().getFromMemCache(7); - } + selectAlertString = arguments.getString("selectAlertString"); } - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); inviteText = preferences.getString("invitetext", null); int time = preferences.getInt("invitetexttime", 0); @@ -121,25 +112,77 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter delegate = null; } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public void willBeHidden() { - if (searchItem != null) { - if (searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + if (destroyAfterSelect) { + actionBarLayer.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact)); + } else { + actionBarLayer.setTitle(LocaleController.getString("Contacts", R.string.Contacts)); + } + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { + @Override + public void onSearchExpand() { + searching = true; + } + + @Override + public void onSearchCollapse() { + searchListViewAdapter.searchDialogs(null); + searching = false; + searchWas = false; + ViewGroup group = (ViewGroup) listView.getParent(); + listView.setAdapter(listViewAdapter); + if (!LocaleController.isRTL) { + listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom()); + } else { + listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); + } + if (android.os.Build.VERSION.SDK_INT >= 11) { + listView.setFastScrollAlwaysVisible(true); + } + listView.setFastScrollEnabled(true); + listView.setVerticalScrollBarEnabled(false); + + emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); + } + + @Override + public void onTextChanged(EditText editText) { + if (searchListViewAdapter == null) { + return; + } + String text = editText.getText().toString(); + if (text.length() != 0) { + searchWas = true; + if (listView != null) { + listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); + listView.setAdapter(searchListViewAdapter); + if(android.os.Build.VERSION.SDK_INT >= 11) { + listView.setFastScrollAlwaysVisible(false); + } + listView.setFastScrollEnabled(false); + listView.setVerticalScrollBarEnabled(true); + } + if (emptyTextView != null) { + emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); + } + } + searchListViewAdapter.searchDialogs(text); + } + }); searching = false; searchWas = false; @@ -148,13 +191,13 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter emptyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); - searchListViewAdapter = new ContactsActivitySearchAdapter(parentActivity, ignoreUsers); + searchListViewAdapter = new ContactsActivitySearchAdapter(getParentActivity(), ignoreUsers); listView = (PinnedHeaderListView)fragmentView.findViewById(R.id.listView); listView.setEmptyView(emptyTextView); listView.setVerticalScrollBarEnabled(false); - listViewAdapter = new ContactsActivityAdapter(parentActivity, onlyUsers, usersAsSections, ignoreUsers); + listViewAdapter = new ContactsActivityAdapter(getParentActivity(), onlyUsers, usersAsSections, ignoreUsers); listView.setAdapter(listViewAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -172,13 +215,11 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } else { if (createSecretChat) { creatingChat = true; - MessagesController.getInstance().startSecretChat(parentActivity, user); + MessagesController.getInstance().startSecretChat(getParentActivity(), user); } else { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", user.id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), destroyAfterSelect, false); + Bundle args = new Bundle(); + args.putInt("user_id", user.id); + presentFragment(new ChatActivity(args), true); } } } else { @@ -205,7 +246,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, inviteText != null ? inviteText : LocaleController.getString("InviteText", R.string.InviteText)); - startActivity(intent); + getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -232,13 +273,11 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } else { if (createSecretChat) { creatingChat = true; - MessagesController.getInstance().startSecretChat(parentActivity, user); + MessagesController.getInstance().startSecretChat(getParentActivity(), user); } else { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", user.id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), destroyAfterSelect, false); + Bundle args = new Bundle(); + args.putInt("user_id", user.id); + presentFragment(new ChatActivity(args), true); } } } else { @@ -251,7 +290,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter if (usePhone == null) { return; } - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); final String arg1 = usePhone; @@ -261,7 +300,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter try { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null)); intent.putExtra("sms_body", LocaleController.getString("InviteText", R.string.InviteText)); - startActivity(intent); + getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -274,32 +313,11 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } }); - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - if (searchItem != null) { - if (searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - } - }); - emptyTextView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - if (searchItem != null) { - if (searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - } - }); - listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { - Utilities.hideKeyboard(searchView); + Utilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @@ -317,10 +335,10 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } private void didSelectResult(final TLRPC.User user, boolean useAlert) { - if (useAlert && selectAlertString != 0) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + if (useAlert && selectAlertString != null) { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); - builder.setMessage(LocaleController.formatString(selectAlertStringDesc, selectAlertString, Utilities.formatName(user.first_name, user.last_name))); + builder.setMessage(LocaleController.formatStringSimple(selectAlertString, Utilities.formatName(user.first_name, user.last_name))); builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { @@ -335,183 +353,19 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter delegate = null; } finishFragment(); - if (searchItem != null) { - if (searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setSubtitle(null); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - - if (destroyAfterSelect) { - actionBar.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact)); - } else { - actionBar.setTitle(LocaleController.getString("Contacts", R.string.Contacts)); - } - - ((LaunchActivity)parentActivity).fixBackButton(); - } - @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - if (!firstStart && listViewAdapter != null) { + if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } - firstStart = false; - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); } @Override public void onPause() { - super.onPause(); - if (searchItem != null && searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - if (searchItem != null) { - if (searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - finishFragment(); - break; - } - return true; - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - super.onCreateOptionsMenu(menu, inflater); - - searchItem = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, LocaleController.getString("Search", R.string.Search)).setIcon(R.drawable.ic_ab_search); - searchItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS|SupportMenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - searchItem.setActionView(searchView = new SearchView(parentActivity)); - - TextView textView = (TextView) searchView.findViewById(R.id.search_src_text); - if (textView != null) { - textView.setTextColor(0xffffffff); - try { - Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); - mCursorDrawableRes.setAccessible(true); - mCursorDrawableRes.set(textView, R.drawable.search_carret); - } catch (Exception e) { - e.printStackTrace(); - } - } - - ImageView img = (ImageView) searchView.findViewById(R.id.search_close_btn); - if (img != null) { - img.setImageResource(R.drawable.ic_msg_btn_cross_custom); - } - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - Utilities.hideKeyboard(searchView); - return true; - } - - @Override - public boolean onQueryTextChange(String s) { - if (searchListViewAdapter == null) { - return true; - } - if (s.length() != 0) { - searchWas = true; - if (listView != null) { - listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); - listView.setAdapter(searchListViewAdapter); - if(android.os.Build.VERSION.SDK_INT >= 11) { - listView.setFastScrollAlwaysVisible(false); - } - listView.setFastScrollEnabled(false); - listView.setVerticalScrollBarEnabled(true); - } - if (emptyTextView != null) { - emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); - } - } - searchListViewAdapter.searchDialogs(s); - return true; - } - }); - - searchItem.setSupportOnActionExpandListener(new MenuItemCompat.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem menuItem) { - if (parentActivity != null) { - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setIcon(R.drawable.ic_ab_search); - } - searching = true; - return true; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem menuItem) { - if (parentActivity == null) { - return true; - } - searchView.setQuery("", false); - searchListViewAdapter.searchDialogs(null); - searching = false; - searchWas = false; - ViewGroup group = (ViewGroup) listView.getParent(); - listView.setAdapter(listViewAdapter); - if (!LocaleController.isRTL) { - listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom()); - } else { - listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); - } - if (android.os.Build.VERSION.SDK_INT >= 11) { - listView.setFastScrollAlwaysVisible(true); - } - listView.setFastScrollEnabled(true); - listView.setVerticalScrollBarEnabled(false); - ((LaunchActivity)parentActivity).updateActionBar(); - - emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); - return true; - } - }); + actionBarLayer.closeSearchField(); } @Override @@ -528,11 +382,9 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } else if (id == MessagesController.encryptedChatCreated) { if (createSecretChat && creatingChat) { TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat)args[0]; - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("enc_id", encryptedChat.id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), true, false); + Bundle args2 = new Bundle(); + args2.putInt("enc_id", encryptedChat.id); + presentFragment(new ChatActivity(args2), true); } } } @@ -580,4 +432,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } } } + + public void setDelegate(ContactsActivityDelegate delegate) { + this.delegate = delegate; + } + + public void setIgnoreUsers(HashMap users) { + ignoreUsers = users; + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java index 6495937d..8b359ae3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java @@ -9,34 +9,29 @@ package org.telegram.ui; import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; -import android.support.v7.widget.SearchView; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.BaseAdapter; -import android.widget.ImageView; +import android.widget.EditText; import android.widget.TextView; import org.telegram.messenger.FileLog; import org.telegram.messenger.LocaleController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; +import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.PinnedHeaderListView; import org.telegram.ui.Views.SectionedBaseAdapter; import java.io.BufferedReader; +import java.io.InputStream; import java.io.InputStreamReader; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -44,9 +39,12 @@ import java.util.HashMap; import java.util.Timer; import java.util.TimerTask; -public class CountrySelectActivity extends ActionBarActivity { - private SupportMenuItem searchItem; - private SearchView searchView; +public class CountrySelectActivity extends BaseFragment { + + public static interface CountrySelectActivityDelegate { + public abstract void didSelectCountry(String name); + } + private SectionedBaseAdapter listViewAdapter; private PinnedHeaderListView listView; private boolean searchWas; @@ -55,6 +53,7 @@ public class CountrySelectActivity extends ActionBarActivity { private TextView emptyTextView; private HashMap> countries = new HashMap>(); private ArrayList sortedCountries = new ArrayList(); + private CountrySelectActivityDelegate delegate; private Timer searchTimer; public ArrayList searchResult; @@ -66,14 +65,10 @@ public class CountrySelectActivity extends ActionBarActivity { } @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - searching = false; - searchWas = false; - + public boolean onFragmentCreate() { try { - BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().getAssets().open("countries.txt"))); + InputStream stream = ApplicationLoader.applicationContext.getResources().getAssets().open("countries.txt"); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); String line; while ((line = reader.readLine()) != null) { String[] args = line.split(";"); @@ -90,6 +85,8 @@ public class CountrySelectActivity extends ActionBarActivity { } arr.add(c); } + reader.close();//TODO + stream.close(); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -110,218 +107,152 @@ public class CountrySelectActivity extends ActionBarActivity { }); } - setContentView(R.layout.country_select_layout); - - emptyTextView = (TextView)findViewById(R.id.searchEmptyView); - searchListViewAdapter = new SearchAdapter(this); - - listView = (PinnedHeaderListView)findViewById(R.id.listView); - listView.setEmptyView(emptyTextView); - listView.setVerticalScrollBarEnabled(false); - - listView.setAdapter(listViewAdapter = new ListAdapter(this)); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int i, long l) { - if (searching && searchWas) { - if (i < searchResult.size()) { - Country c = searchResult.get(i); - Intent intent = new Intent(); - intent.putExtra("country", c.name); - setResult(RESULT_OK, intent); - finish(); - } - } else { - int section = listViewAdapter.getSectionForPosition(i); - int row = listViewAdapter.getPositionInSectionForPosition(i); - if (section < sortedCountries.size()) { - String n = sortedCountries.get(section); - ArrayList arr = countries.get(n); - if (row < arr.size()) { - Country c = arr.get(row); - Intent intent = new Intent(); - intent.putExtra("country", c.name); - setResult(RESULT_OK, intent); - finish(); - } - } - } - } - }); - - listView.setOnScrollListener(new AbsListView.OnScrollListener() { - @Override - public void onScrollStateChanged(AbsListView absListView, int i) { - if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { - Utilities.hideKeyboard(searchView); - } - } - - @Override - public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - } - }); - - getWindow().setBackgroundDrawableResource(R.drawable.transparent); - } - - public void applySelfActionBar() { - ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setSubtitle(null); - actionBar.setTitle(getString(R.string.ChooseCountry)); - fixBackButton(); + return super.onFragmentCreate(); } @Override - protected void onResume() { - super.onResume(); - applySelfActionBar(); + public void onFragmentDestroy() { + super.onFragmentDestroy(); + } + + @Override + public View createView(LayoutInflater inflater, ViewGroup container) { + if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry)); + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { + @Override + public void onSearchExpand() { + searching = true; + } + + @Override + public void onSearchCollapse() { + search(null); + searching = false; + searchWas = false; + ViewGroup group = (ViewGroup) listView.getParent(); + listView.setAdapter(listViewAdapter); + if (!LocaleController.isRTL) { + listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom()); + } else { + listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); + } + if (android.os.Build.VERSION.SDK_INT >= 11) { + listView.setFastScrollAlwaysVisible(true); + } + listView.setFastScrollEnabled(true); + listView.setVerticalScrollBarEnabled(false); + + emptyTextView.setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry)); + } + + @Override + public void onTextChanged(EditText editText) { + String text = editText.getText().toString(); + search(text); + if (text.length() != 0) { + searchWas = true; + if (listView != null) { + listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); + listView.setAdapter(searchListViewAdapter); + if(android.os.Build.VERSION.SDK_INT >= 11) { + listView.setFastScrollAlwaysVisible(false); + } + listView.setFastScrollEnabled(false); + listView.setVerticalScrollBarEnabled(true); + } + if (emptyTextView != null) { + emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); + } + } + } + }); + + searching = false; + searchWas = false; + + fragmentView = inflater.inflate(R.layout.country_select_layout, container, false); + + emptyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); + searchListViewAdapter = new SearchAdapter(getParentActivity()); + + listView = (PinnedHeaderListView)fragmentView.findViewById(R.id.listView); + listView.setEmptyView(emptyTextView); + listView.setVerticalScrollBarEnabled(false); + + listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity())); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + if (searching && searchWas) { + if (i < searchResult.size()) { + Country c = searchResult.get(i); + if (delegate != null) { + delegate.didSelectCountry(c.name); + } + finishFragment(); + } + } else { + int section = listViewAdapter.getSectionForPosition(i); + int row = listViewAdapter.getPositionInSectionForPosition(i); + if (section < sortedCountries.size()) { + String n = sortedCountries.get(section); + ArrayList arr = countries.get(n); + if (row < arr.size()) { + Country c = arr.get(row); + if (delegate != null) { + delegate.didSelectCountry(c.name); + } + finishFragment(); + } + } + } + } + }); + + listView.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView absListView, int i) { + if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { + Utilities.hideKeyboard(getParentActivity().getCurrentFocus()); + } + } + + @Override + public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + } + }); + } else { + ViewGroup parent = (ViewGroup)fragmentView.getParent(); + if (parent != null) { + parent.removeView(fragmentView); + } + } + return fragmentView; + } + + @Override + public void onResume() { + if (listViewAdapter != null) { + listViewAdapter.notifyDataSetChanged(); + } } @Override public void onPause() { - super.onPause(); - if (searchItem != null && searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - if (searchItem != null) { - if (searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - finish(); - break; - } - return true; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - searchItem = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, LocaleController.getString("Search", R.string.Search)).setIcon(R.drawable.ic_ab_search); - searchItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS|SupportMenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - searchItem.setActionView(searchView = new SearchView(this)); - - TextView textView = (TextView) searchView.findViewById(R.id.search_src_text); - if (textView != null) { - textView.setTextColor(0xffffffff); - try { - Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); - mCursorDrawableRes.setAccessible(true); - mCursorDrawableRes.set(textView, R.drawable.search_carret); - } catch (Exception e) { - e.printStackTrace(); - } - } - - ImageView img = (ImageView) searchView.findViewById(R.id.search_close_btn); - if (img != null) { - img.setImageResource(R.drawable.ic_msg_btn_cross_custom); - } - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - Utilities.hideKeyboard(searchView); - return true; - } - - @Override - public boolean onQueryTextChange(String s) { - search(s); - if (s.length() != 0) { - searchWas = true; - if (listView != null) { - listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); - listView.setAdapter(searchListViewAdapter); - if(android.os.Build.VERSION.SDK_INT >= 11) { - listView.setFastScrollAlwaysVisible(false); - } - listView.setFastScrollEnabled(false); - listView.setVerticalScrollBarEnabled(true); - } - if (emptyTextView != null) { - emptyTextView.setText(getString(R.string.NoResult)); - } - } - return true; - } - }); - - searchItem.setSupportOnActionExpandListener(new MenuItemCompat.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem menuItem) { - getSupportActionBar().setIcon(R.drawable.ic_ab_search); - searching = true; - return true; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem menuItem) { - searchView.setQuery("", false); - search(null); - searching = false; - searchWas = false; - ViewGroup group = (ViewGroup) listView.getParent(); - listView.setAdapter(listViewAdapter); - if (!LocaleController.isRTL) { - listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom()); - } else { - listView.setPadding(Utilities.dp(30), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); - } - if (android.os.Build.VERSION.SDK_INT >= 11) { - listView.setFastScrollAlwaysVisible(true); - } - listView.setFastScrollEnabled(true); - listView.setVerticalScrollBarEnabled(false); - applySelfActionBar(); - - emptyTextView.setText(getString(R.string.ChooseCountry)); - return true; - } - }); - return super.onCreateOptionsMenu(menu); - } - - public void fixBackButton() { - if(android.os.Build.VERSION.SDK_INT == 19) { - //workaround for back button dissapear - try { - Class firstClass = getSupportActionBar().getClass(); - Class aClass = firstClass.getSuperclass(); - if (aClass == android.support.v7.app.ActionBar.class) { - - } else { - Field field = aClass.getDeclaredField("mActionBar"); - field.setAccessible(true); - android.app.ActionBar bar = (android.app.ActionBar)field.get(getSupportActionBar()); - - field = bar.getClass().getDeclaredField("mActionView"); - field.setAccessible(true); - View v = (View)field.get(bar); - aClass = v.getClass(); - - field = aClass.getDeclaredField("mHomeLayout"); - field.setAccessible(true); - v = (View)field.get(v); - v.setVisibility(View.VISIBLE); - } - } catch (Exception e) { - e.printStackTrace(); - } - } + actionBarLayer.closeSearchField(); } public void search(final String query) { @@ -379,6 +310,10 @@ public class CountrySelectActivity extends ActionBarActivity { }); } + public void setCountrySelectActivityDelegate(CountrySelectActivityDelegate delegate) { + this.delegate = delegate; + } + private void updateSearchResults(final ArrayList arrCounties) { Utilities.RunOnUIThread(new Runnable() { @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java index 9d7cab97..08123620 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java @@ -14,12 +14,9 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Build; -import android.os.Bundle; import android.os.Environment; import android.os.StatFs; -import android.support.v7.app.ActionBar; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -32,9 +29,9 @@ import org.telegram.messenger.FileLog; import org.telegram.messenger.LocaleController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.BaseFragment; import java.io.BufferedReader; import java.io.File; @@ -58,7 +55,7 @@ public class DocumentSelectActivity extends BaseFragment { private boolean receiverRegistered = false; private ArrayList history = new ArrayList(); private long sizeLimit = 1024 * 1024 * 1024; - public DocumentSelectActivityDelegate delegate; + private DocumentSelectActivityDelegate delegate; private class ListItem { int icon; @@ -99,17 +96,11 @@ public class DocumentSelectActivity extends BaseFragment { } }; - @Override - public boolean onFragmentCreate() { - super.onFragmentCreate(); - return true; - } - @Override public void onFragmentDestroy() { try { if (receiverRegistered) { - parentActivity.unregisterReceiver(receiver); + getParentActivity().unregisterReceiver(receiver); } } catch (Exception e) { FileLog.e("tmessages", e); @@ -118,13 +109,7 @@ public class DocumentSelectActivity extends BaseFragment { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (!receiverRegistered) { receiverRegistered = true; IntentFilter filter = new IntentFilter(); @@ -138,12 +123,23 @@ public class DocumentSelectActivity extends BaseFragment { filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE); filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); filter.addDataScheme("file"); - parentActivity.registerReceiver(receiver, filter); + getParentActivity().registerReceiver(receiver, filter); } if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile)); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } + } + }); + fragmentView = inflater.inflate(R.layout.document_select_layout, container, false); - listAdapter = new ListAdapter(parentActivity); + listAdapter = new ListAdapter(getParentActivity()); emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); listView = (ListView)fragmentView.findViewById(R.id.listView); listView.setEmptyView(emptyView); @@ -158,22 +154,21 @@ public class DocumentSelectActivity extends BaseFragment { he.scrollItem = listView.getFirstVisiblePosition(); he.scrollOffset = listView.getChildAt(0).getTop(); he.dir = currentDir; - ActionBar actionBar = parentActivity.getSupportActionBar(); - he.title = actionBar.getTitle().toString(); + he.title = actionBarLayer.getTitle().toString(); if (!listFiles(file)){ return; } history.add(he); - actionBar.setTitle(item.title); + actionBarLayer.setTitle(item.title); listView.setSelection(0); } else { if (!file.canRead()) { - showErrorBox(getString(R.string.AccessError)); + showErrorBox(LocaleController.getString("AccessError", R.string.AccessError)); return; } if (sizeLimit != 0) { if (file.length() > sizeLimit) { - showErrorBox(getString(R.string.FileUploadLimit, Utilities.formatFileSize(sizeLimit))); + showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, Utilities.formatFileSize(sizeLimit))); return; } } @@ -187,11 +182,6 @@ public class DocumentSelectActivity extends BaseFragment { } }); - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); listRoots(); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); @@ -202,66 +192,18 @@ public class DocumentSelectActivity extends BaseFragment { return fragmentView; } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setSubtitle(null); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile)); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - if (!firstStart && listAdapter != null) { + if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } - firstStart = false; - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - } - return true; } @Override public boolean onBackPressed() { if (history.size() > 0){ HistoryEntry he = history.remove(history.size() - 1); - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setTitle(he.title); + actionBarLayer.setTitle(he.title); if (he.dir != null) { listFiles(he.dir); } else { @@ -273,6 +215,10 @@ public class DocumentSelectActivity extends BaseFragment { return super.onBackPressed(); } + public void setDelegate(DocumentSelectActivityDelegate delegate) { + this.delegate = delegate; + } + private boolean listFiles(File dir) { if (!dir.canRead()) { if (dir.getAbsolutePath().startsWith(Environment.getExternalStorageDirectory().toString()) @@ -292,7 +238,7 @@ public class DocumentSelectActivity extends BaseFragment { return true; } } - showErrorBox(getString(R.string.AccessError)); + showErrorBox(LocaleController.getString("AccessError", R.string.AccessError)); return false; } emptyView.setText(LocaleController.getString("NoFiles", R.string.NoFiles)); @@ -304,7 +250,7 @@ public class DocumentSelectActivity extends BaseFragment { return false; } if (files == null) { - showErrorBox(getString(R.string.UnknownError)); + showErrorBox(LocaleController.getString("UnknownError", R.string.UnknownError)); return false; } currentDir = dir; @@ -344,7 +290,7 @@ public class DocumentSelectActivity extends BaseFragment { } private void showErrorBox(String error){ - new AlertDialog.Builder(parentActivity) + new AlertDialog.Builder(getParentActivity()) .setTitle(LocaleController.getString("AppName", R.string.AppName)) .setMessage(error) .setPositiveButton(R.string.OK, null) @@ -356,7 +302,11 @@ public class DocumentSelectActivity extends BaseFragment { items.clear(); String extStorage = Environment.getExternalStorageDirectory().getAbsolutePath(); ListItem ext = new ListItem(); - ext.title = getString(Build.VERSION.SDK_INT < 9 || Environment.isExternalStorageRemovable() ? R.string.SdCard : R.string.InternalStorage); + if (Build.VERSION.SDK_INT < 9 || Environment.isExternalStorageRemovable()) { + ext.title = LocaleController.getString("SdCard", R.string.SdCard); + } else { + ext.title = LocaleController.getString("InternalStorage", R.string.InternalStorage); + } ext.icon = Build.VERSION.SDK_INT < 9 || Environment.isExternalStorageRemovable() ? R.drawable.ic_external_storage : R.drawable.ic_storage; ext.subtitle = getRootSubtitle(extStorage); ext.file = Environment.getExternalStorageDirectory(); @@ -386,9 +336,12 @@ public class DocumentSelectActivity extends BaseFragment { result.removeAll(aliases.get(extDevice)); for (String path : result) { try { - boolean isSd = path.toLowerCase().contains("sd"); ListItem item = new ListItem(); - item.title = getString(isSd ? R.string.SdCard : R.string.ExternalStorage); + if (path.toLowerCase().contains("sd")) { + ext.title = LocaleController.getString("SdCard", R.string.SdCard); + } else { + ext.title = LocaleController.getString("ExternalStorage", R.string.ExternalStorage); + } item.icon = R.drawable.ic_external_storage; item.subtitle = getRootSubtitle(path); item.file = new File(path); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java index 96ecd514..0dc953a8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java @@ -17,8 +17,6 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v7.app.ActionBar; import android.text.Editable; import android.text.Spannable; import android.text.SpannableString; @@ -26,9 +24,6 @@ import android.text.SpannableStringBuilder; import android.text.TextWatcher; import android.text.style.ImageSpan; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; @@ -48,8 +43,10 @@ import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.PinnedHeaderListView; import org.telegram.ui.Views.SectionedBaseAdapter; @@ -105,17 +102,14 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen private CharSequence changeString; private int beforeChangeIndex; - public GroupCreateActivity() { - animationType = 1; - } + private final static int done_button = 1; @Override public boolean onFragmentCreate() { - super.onFragmentCreate(); NotificationCenter.getInstance().addObserver(this, MessagesController.contactsDidLoaded); NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces); NotificationCenter.getInstance().addObserver(this, MessagesController.chatDidCreated); - return true; + return super.onFragmentCreate(); } @Override @@ -127,14 +121,33 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup)); + actionBarLayer.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } else if (id == done_button) { + if (!selectedContacts.isEmpty()) { + ArrayList result = new ArrayList(); + result.addAll(selectedContacts.keySet()); + Bundle args = new Bundle(); + args.putIntegerArrayList("result", result); + presentFragment(new GroupCreateFinalActivity(args)); + } + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout); + TextView doneTextView = (TextView)doneItem.findViewById(R.id.done_button); + doneTextView.setText(LocaleController.getString("Next", R.string.Next)); searching = false; searchWas = false; @@ -186,10 +199,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen selectedContacts.remove(sp.uid); } } - if (parentActivity != null) { - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); - } + actionBarLayer.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); listView.invalidateViews(); } else { search = true; @@ -222,7 +232,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen listView.setEmptyView(emptyTextView); listView.setVerticalScrollBarEnabled(false); - listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity)); + listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity())); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { @@ -255,10 +265,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen span.uid = user.id; ignoreChange = false; } - if (parentActivity != null) { - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); - } + actionBarLayer.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); if (searching || searchWas) { searching = false; searchWas = false; @@ -302,44 +309,8 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen return fragmentView; } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup)); - actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - - @Override - public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - public XImageSpan createAndPutChipForUser(TLRPC.User user) { - LayoutInflater lf = (LayoutInflater)parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); + LayoutInflater lf = (LayoutInflater)ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); View textView = lf.inflate(R.layout.group_create_bubble, null); TextView text = (TextView)textView.findViewById(R.id.bubble_text_view); String name = Utilities.formatName(user.first_name, user.last_name); @@ -451,41 +422,6 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen }); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - } - return true; - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - SupportMenuItem doneItem = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, null); - doneItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - doneItem.setActionView(R.layout.group_create_done_layout); - - TextView doneTextView = (TextView)doneItem.getActionView().findViewById(R.id.done_button); - doneTextView.setText(LocaleController.getString("Next", R.string.Next)); - doneTextView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (!selectedContacts.isEmpty()) { - ArrayList result = new ArrayList(); - result.addAll(selectedContacts.keySet()); - Bundle args = new Bundle(); - args.putIntegerArrayList("result", result); - GroupCreateFinalActivity fragment = new GroupCreateFinalActivity(); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "group_craate_final", false); - } - } - }); - } - @Override public void didReceivedNotification(int id, Object... args) { if (id == MessagesController.contactsDidLoaded) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java index 86a986c2..957247d2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java @@ -14,12 +14,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v7.app.ActionBar; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; @@ -36,9 +31,11 @@ import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; import org.telegram.ui.Cells.ChatOrUserCell; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.AvatarUpdater; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.PinnedHeaderListView; import org.telegram.ui.Views.SectionedBaseAdapter; @@ -58,10 +55,15 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati private ProgressDialog progressDialog = null; private String nameToSet = null; + private final static int done_button = 1; + + public GroupCreateFinalActivity(Bundle args) { + super(args); + } + @SuppressWarnings("unchecked") @Override public boolean onFragmentCreate() { - super.onFragmentCreate(); NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces); NotificationCenter.getInstance().addObserver(this, MessagesController.chatDidCreated); NotificationCenter.getInstance().addObserver(this, MessagesController.chatDidFailCreate); @@ -101,7 +103,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati return false; } } - return true; + return super.onFragmentCreate(); } @Override @@ -114,14 +116,59 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup)); + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } else if (id == done_button) { + if (donePressed) { + return; + } + if (nameTextView.getText().length() == 0) { + return; + } + donePressed = true; + + if (avatarUpdater.uploadingAvatar != null) { + createAfterUpload = true; + } else { + progressDialog = new ProgressDialog(getParentActivity()); + progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); + progressDialog.setCanceledOnTouchOutside(false); + progressDialog.setCancelable(false); + + final long reqId = MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, uploadedAvatar); + + progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ConnectionsManager.getInstance().cancelRpc(reqId, true); + donePressed = false; + try { + dialog.dismiss(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + }); + progressDialog.show(); + } + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout); + + TextView doneTextView = (TextView)doneItem.findViewById(R.id.done_button); + doneTextView.setText(LocaleController.getString("Done", R.string.Done)); + fragmentView = inflater.inflate(R.layout.group_create_final_layout, container, false); final ImageButton button2 = (ImageButton)fragmentView.findViewById(R.id.settings_change_avatar_button); @@ -129,7 +176,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati @Override public void onClick(View view) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; @@ -166,7 +213,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati nameToSet = null; } listView = (PinnedHeaderListView)fragmentView.findViewById(R.id.listView); - listView.setAdapter(new ListAdapter(parentActivity)); + listView.setAdapter(new ListAdapter(getParentActivity())); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -176,42 +223,6 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati return fragmentView; } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setSubtitle(null); - actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup)); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - - @Override - public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - @Override public void didUploadedPhoto(final TLRPC.InputFile file, final TLRPC.PhotoSize small, final TLRPC.PhotoSize big) { Utilities.RunOnUIThread(new Runnable() { @@ -228,17 +239,6 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati }); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - } - return true; - } - @Override public void onActivityResultFragment(int requestCode, int resultCode, Intent data) { avatarUpdater.onActivityResult(requestCode, resultCode, data); @@ -272,53 +272,6 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati } } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - SupportMenuItem doneItem = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, null); - doneItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - doneItem.setActionView(R.layout.group_create_done_layout); - - TextView doneTextView = (TextView)doneItem.getActionView().findViewById(R.id.done_button); - doneTextView.setText(LocaleController.getString("Done", R.string.Done)); - doneTextView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (donePressed || parentActivity == null) { - return; - } - if (nameTextView.getText().length() == 0) { - return; - } - donePressed = true; - - if (avatarUpdater.uploadingAvatar != null) { - createAfterUpload = true; - } else { - progressDialog = new ProgressDialog(parentActivity); - progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); - progressDialog.setCanceledOnTouchOutside(false); - progressDialog.setCancelable(false); - - final long reqId = MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, uploadedAvatar); - - progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ConnectionsManager.getInstance().cancelRpc(reqId, true); - donePressed = false; - try { - dialog.dismiss(); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - }); - progressDialog.show(); - } - } - }); - } - @Override public void didReceivedNotification(int id, final Object... args) { if (id == MessagesController.updateInterfaces) { @@ -335,7 +288,6 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati } } donePressed = false; - FileLog.e("tmessages", "did fail create chat"); } else if (id == MessagesController.chatDidCreated) { Utilities.RunOnUIThread(new Runnable() { @Override @@ -347,11 +299,9 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati FileLog.e("tmessages", e); } } - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("chat_id", (Integer)args[0]); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), true, false); + Bundle args2 = new Bundle(); + args2.putInt("chat_id", (Integer)args[0]); + presentFragment(new ChatActivity(args2)); } }); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java index b50a4a56..4cd4fc8e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java @@ -10,10 +10,8 @@ package org.telegram.ui; import android.content.Context; import android.os.Bundle; -import android.support.v7.app.ActionBar; import android.text.Html; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -27,12 +25,17 @@ import org.telegram.messenger.TLRPC; import org.telegram.messenger.MessagesController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.IdenticonView; public class IdenticonActivity extends BaseFragment { private int chat_id; + public IdenticonActivity(Bundle args) { + super(args); + } + @Override public boolean onFragmentCreate() { chat_id = getArguments().getInt("chat_id"); @@ -40,19 +43,21 @@ public class IdenticonActivity extends BaseFragment { } @Override - public void onFragmentDestroy() { - super.onFragmentDestroy(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey)); + actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4)); + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } + } + }); + fragmentView = inflater.inflate(R.layout.identicon_layout, container, false); IdenticonView identiconView = (IdenticonView) fragmentView.findViewById(R.id.identicon_view); TextView textView = (TextView)fragmentView.findViewById(R.id.identicon_text); @@ -71,32 +76,6 @@ public class IdenticonActivity extends BaseFragment { return fragmentView; } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setSubtitle(null); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey)); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); - title.setCompoundDrawablePadding(Utilities.dp(4)); - } - } - @Override public void onConfigurationChanged(android.content.res.Configuration newConfig) { super.onConfigurationChanged(newConfig); @@ -105,62 +84,29 @@ public class IdenticonActivity extends BaseFragment { @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); fixLayout(); } private void fixLayout() { - final View v = getView(); - if (v != null) { - ViewTreeObserver obs = v.getViewTreeObserver(); - obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - LinearLayout layout = (LinearLayout)fragmentView; - WindowManager manager = (WindowManager)parentActivity.getSystemService(Context.WINDOW_SERVICE); - int rotation = manager.getDefaultDisplay().getRotation(); + ViewTreeObserver obs = fragmentView.getViewTreeObserver(); + obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + LinearLayout layout = (LinearLayout)fragmentView; + WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE); + int rotation = manager.getDefaultDisplay().getRotation(); - if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { - layout.setOrientation(LinearLayout.HORIZONTAL); - } else { - layout.setOrientation(LinearLayout.VERTICAL); - } - - v.setPadding(v.getPaddingLeft(), 0, v.getPaddingRight(), v.getPaddingBottom()); - v.getViewTreeObserver().removeOnPreDrawListener(this); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = ApplicationLoader.applicationContext.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); - title.setCompoundDrawablePadding(Utilities.dp(4)); - } - - return false; + if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { + layout.setOrientation(LinearLayout.HORIZONTAL); + } else { + layout.setOrientation(LinearLayout.VERTICAL); } - }); - } - } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - } - return true; + fragmentView.setPadding(fragmentView.getPaddingLeft(), 0, fragmentView.getPaddingRight(), fragmentView.getPaddingBottom()); + fragmentView.getViewTreeObserver().removeOnPreDrawListener(this); + + return false; + } + }); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java index 39297969..d7ce4ebd 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/IntroActivity.java @@ -194,7 +194,8 @@ public class IntroActivity extends ActionBarActivity { return; } startPressed = true; - Intent intent2 = new Intent(IntroActivity.this, LoginActivity.class); + Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class); + intent2.putExtra("fromIntro", true); startActivity(intent2); finish(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java index d05d51b3..ecc09a7e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java @@ -11,21 +11,13 @@ package org.telegram.ui; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBar; -import android.support.v7.widget.SearchView; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.BaseAdapter; -import android.widget.ImageView; +import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; @@ -33,17 +25,16 @@ import org.telegram.messenger.FileLog; import org.telegram.messenger.LocaleController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; +import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; +import org.telegram.ui.Views.ActionBar.BaseFragment; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; public class LanguageSelectActivity extends BaseFragment { - private SupportMenuItem searchItem; - private SearchView searchView; private BaseAdapter listAdapter; private ListView listView; private boolean searchWas; @@ -55,39 +46,71 @@ public class LanguageSelectActivity extends BaseFragment { public ArrayList searchResult; @Override - public boolean onFragmentCreate() { - super.onFragmentCreate(); - return true; - } - - @Override - public void onFragmentDestroy() { - super.onFragmentDestroy(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("Language", R.string.Language)); + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { + @Override + public void onSearchExpand() { + searching = true; + } + + @Override + public void onSearchCollapse() { + search(null); + searching = false; + searchWas = false; + if (listView != null) { + emptyTextView.setVisibility(View.GONE); + listView.setAdapter(listAdapter); + } + } + + @Override + public void onTextChanged(EditText editText) { + String text = editText.getText().toString(); + search(text); + if (text.length() != 0) { + searchWas = true; + if (listView != null) { + listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); + listView.setAdapter(searchListViewAdapter); + if(android.os.Build.VERSION.SDK_INT >= 11) { + listView.setFastScrollAlwaysVisible(false); + } + listView.setFastScrollEnabled(false); + listView.setVerticalScrollBarEnabled(true); + } + if (emptyTextView != null) { + emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); + } + } + } + }); + fragmentView = inflater.inflate(R.layout.language_select_layout, container, false); - listAdapter = new ListAdapter(parentActivity); + listAdapter = new ListAdapter(getParentActivity()); listView = (ListView)fragmentView.findViewById(R.id.listView); listView.setAdapter(listAdapter); emptyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); listView.setEmptyView(emptyTextView); - searchListViewAdapter = new SearchAdapter(parentActivity); + searchListViewAdapter = new SearchAdapter(getParentActivity()); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { - if (parentActivity == null) { - return; - } LocaleController.LocaleInfo localeInfo = null; if (searching && searchWas) { if (i >= 0 && i < searchResult.size()) { @@ -99,26 +122,8 @@ public class LanguageSelectActivity extends BaseFragment { } } if (localeInfo != null) { - boolean isRTL = LocaleController.isRTL; LocaleController.getInstance().applyLanguage(localeInfo, true); - if (isRTL != LocaleController.isRTL) { - for (BaseFragment fragment : ApplicationLoader.fragmentsStack) { - if (fragment == LanguageSelectActivity.this) { - continue; - } - if (fragment.fragmentView != null) { - ViewGroup parent = (ViewGroup)fragment.fragmentView.getParent(); - if (parent != null) { - parent.removeView(fragment.fragmentView); - } - fragment.fragmentView = null; - } - fragment.parentActivity = parentActivity; - } - } - } - if (searchItem != null && searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); + getParentActivity().rebuildAllFragmentViews(); } finishFragment(); } @@ -127,9 +132,6 @@ public class LanguageSelectActivity extends BaseFragment { listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { - if (parentActivity == null) { - return false; - } LocaleController.LocaleInfo localeInfo = null; if (searching && searchWas) { if (i >= 0 && i < searchResult.size()) { @@ -144,7 +146,7 @@ public class LanguageSelectActivity extends BaseFragment { return false; } final LocaleController.LocaleInfo finalLocaleInfo = localeInfo; - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), new DialogInterface.OnClickListener() { @@ -160,10 +162,6 @@ public class LanguageSelectActivity extends BaseFragment { if (searchListViewAdapter != null) { searchListViewAdapter.notifyDataSetChanged(); } - applySelfActionBar(); - if (searchItem != null && searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } } } }); @@ -173,17 +171,11 @@ public class LanguageSelectActivity extends BaseFragment { } }); - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); - listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { - Utilities.hideKeyboard(searchView); + Utilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @@ -203,150 +195,16 @@ public class LanguageSelectActivity extends BaseFragment { return fragmentView; } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setSubtitle(null); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - actionBar.setTitle(LocaleController.getString("Language", R.string.Language)); - ((LaunchActivity)parentActivity).fixBackButton(); - } - @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - if (!firstStart && listAdapter != null) { + if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } - firstStart = false; - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); } @Override public void onPause() { - super.onPause(); - if (searchItem != null && searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - if (searchItem != null && searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - finishFragment(); - break; - } - return true; - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - searchItem = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, LocaleController.getString("Search", R.string.Search)).setIcon(R.drawable.ic_ab_search); - searchItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS|SupportMenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - searchItem.setActionView(searchView = new SearchView(parentActivity)); - - TextView textView = (TextView) searchView.findViewById(R.id.search_src_text); - if (textView != null) { - textView.setTextColor(0xffffffff); - try { - Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); - mCursorDrawableRes.setAccessible(true); - mCursorDrawableRes.set(textView, R.drawable.search_carret); - } catch (Exception e) { - e.printStackTrace(); - } - } - - ImageView img = (ImageView) searchView.findViewById(R.id.search_close_btn); - if (img != null) { - img.setImageResource(R.drawable.ic_msg_btn_cross_custom); - } - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - Utilities.hideKeyboard(searchView); - return true; - } - - @Override - public boolean onQueryTextChange(String s) { - search(s); - if (s.length() != 0) { - searchWas = true; - if (listView != null) { - listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); - listView.setAdapter(searchListViewAdapter); - if(android.os.Build.VERSION.SDK_INT >= 11) { - listView.setFastScrollAlwaysVisible(false); - } - listView.setFastScrollEnabled(false); - listView.setVerticalScrollBarEnabled(true); - } - if (emptyTextView != null) { - emptyTextView.setText(getString(R.string.NoResult)); - } - } - return true; - } - }); - - searchItem.setSupportOnActionExpandListener(new MenuItemCompat.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem menuItem) { - if (parentActivity != null) { - parentActivity.getSupportActionBar().setIcon(R.drawable.ic_ab_search); - } - searching = true; - return true; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem menuItem) { - searchView.setQuery("", false); - search(null); - searching = false; - searchWas = false; - if (listView != null) { - emptyTextView.setVisibility(View.GONE); - listView.setAdapter(listAdapter); - } - ((LaunchActivity)parentActivity).fixBackButton(); - return true; - } - }); - - super.onCreateOptionsMenu(menu, inflater); + actionBarLayer.closeSearchField(); } public void search(final String query) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index 9142e011..d38ba878 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -8,26 +8,19 @@ package org.telegram.ui; -import android.app.Activity; import android.app.NotificationManager; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.database.Cursor; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.Parcelable; import android.provider.ContactsContract; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; import android.view.Surface; import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; import android.view.WindowManager; import android.widget.EditText; import android.widget.TextView; @@ -36,6 +29,7 @@ import android.widget.Toast; import org.telegram.PhoneFormat.PhoneFormat; import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.FileLog; +import org.telegram.messenger.LocaleController; import org.telegram.messenger.MediaController; import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; @@ -44,14 +38,13 @@ import org.telegram.messenger.TLRPC; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; import org.telegram.objects.MessageObject; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.ActionBarActivity; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.NotificationView; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Map; @@ -70,35 +63,33 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen private View backStatusButton; private View statusBackground; private TextView statusText; - private View containerView; @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); ApplicationLoader.postInitApplication(); - this.setTheme(R.style.Theme_TMessages); - getWindow().setBackgroundDrawableResource(R.drawable.transparent); - if (!UserConfig.clientActivated) { Intent intent = getIntent(); if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) { + super.onCreateFinish(savedInstanceState); finish(); return; } - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", MODE_PRIVATE); - Map state = preferences.getAll(); - if (state.isEmpty()) { - Intent intent2 = new Intent(this, IntroActivity.class); - startActivity(intent2); - } else { - Intent intent2 = new Intent(this, LoginActivity.class); - startActivity(intent2); + if (intent != null && !intent.getBooleanExtra("fromIntro", false)) { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", MODE_PRIVATE); + Map state = preferences.getAll(); + if (state.isEmpty()) { + Intent intent2 = new Intent(this, IntroActivity.class); + startActivity(intent2); + super.onCreateFinish(savedInstanceState); + finish(); + return; + } } - finish(); - return; } + super.onCreate(savedInstanceState); + int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { Utilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId); @@ -106,43 +97,37 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen NotificationCenter.getInstance().postNotificationName(702, this); currentConnectionState = ConnectionsManager.getInstance().connectionState; - for (BaseFragment fragment : ApplicationLoader.fragmentsStack) { - if (fragment.fragmentView != null) { - ViewGroup parent = (ViewGroup)fragment.fragmentView.getParent(); - if (parent != null) { - parent.removeView(fragment.fragmentView); - } - fragment.fragmentView = null; - } - fragment.parentActivity = this; - } - setContentView(R.layout.application_layout); + NotificationCenter.getInstance().addObserver(this, 1234); NotificationCenter.getInstance().addObserver(this, 658); NotificationCenter.getInstance().addObserver(this, 701); NotificationCenter.getInstance().addObserver(this, 702); NotificationCenter.getInstance().addObserver(this, 703); NotificationCenter.getInstance().addObserver(this, GalleryImageViewer.needShowAllMedia); - getSupportActionBar().setLogo(R.drawable.ab_icon_fixed2); statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null); statusBackground = statusView.findViewById(R.id.back_button_background); backStatusButton = statusView.findViewById(R.id.back_button); - containerView = findViewById(R.id.container); statusText = (TextView)statusView.findViewById(R.id.status_text); statusBackground.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (ApplicationLoader.fragmentsStack.size() > 1) { + if (fragmentsStack.size() > 1) { onBackPressed(); } } }); - if (ApplicationLoader.fragmentsStack.isEmpty()) { - MessagesActivity fragment = new MessagesActivity(); - fragment.onFragmentCreate(); - ApplicationLoader.fragmentsStack.add(fragment); + if (fragmentsStack.isEmpty()) { + if (!UserConfig.clientActivated) { + LoginActivity fragment = new LoginActivity(); + fragment.onFragmentCreate(); + fragmentsStack.add(fragment); + } else { + MessagesActivity fragment = new MessagesActivity(null); + fragment.onFragmentCreate(); + fragmentsStack.add(fragment); + } try { if (savedInstanceState != null) { @@ -151,10 +136,9 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen Bundle args = savedInstanceState.getBundle("args"); if (fragmentName.equals("chat")) { if (args != null) { - ChatActivity chat = new ChatActivity(); - chat.setArguments(args); + ChatActivity chat = new ChatActivity(args); if (chat.onFragmentCreate()) { - ApplicationLoader.fragmentsStack.add(chat); + fragmentsStack.add(chat); chat.restoreSelfArgs(savedInstanceState); } } @@ -162,21 +146,28 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen SettingsActivity settings = new SettingsActivity(); settings.onFragmentCreate(); settings.restoreSelfArgs(savedInstanceState); - ApplicationLoader.fragmentsStack.add(settings); + fragmentsStack.add(settings); } else if (fragmentName.equals("group")) { if (args != null) { - GroupCreateFinalActivity group = new GroupCreateFinalActivity(); - group.setArguments(args); + GroupCreateFinalActivity group = new GroupCreateFinalActivity(args); if (group.onFragmentCreate()) { group.restoreSelfArgs(savedInstanceState); - ApplicationLoader.fragmentsStack.add(group); + fragmentsStack.add(group); + } + } + } else if (fragmentName.equals("chat_profile")) { + if (args != null) { + ChatProfileActivity profile = new ChatProfileActivity(args); + if (profile.onFragmentCreate()) { + profile.restoreSelfArgs(savedInstanceState); + fragmentsStack.add(profile); } } } else if (fragmentName.equals("wallpapers")) { SettingsWallpapersActivity settings = new SettingsWallpapersActivity(); settings.onFragmentCreate(); settings.restoreSelfArgs(savedInstanceState); - ApplicationLoader.fragmentsStack.add(settings); + fragmentsStack.add(settings); } } } @@ -188,35 +179,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen handleIntent(getIntent(), false, savedInstanceState != null); } - @SuppressWarnings("unchecked") - private void prepareForHideShowActionBar() { - try { - Class firstClass = getSupportActionBar().getClass(); - Class aClass = firstClass.getSuperclass(); - if (aClass == android.support.v7.app.ActionBar.class) { - Method method = firstClass.getDeclaredMethod("setShowHideAnimationEnabled", boolean.class); - method.invoke(getSupportActionBar(), false); - } else { - Field field = aClass.getDeclaredField("mActionBar"); - field.setAccessible(true); - Method method = field.get(getSupportActionBar()).getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class); - method.invoke(field.get(getSupportActionBar()), false); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void showActionBar() { - prepareForHideShowActionBar(); - getSupportActionBar().show(); - } - - public void hideActionBar() { - prepareForHideShowActionBar(); - getSupportActionBar().hide(); - } - private void handleIntent(Intent intent, boolean isNew, boolean restore) { boolean pushOpened = false; @@ -483,61 +445,44 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen if (push_user_id == UserConfig.clientUserId) { open_settings = 1; } else { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", push_user_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { + Bundle args = new Bundle(); + args.putInt("user_id", push_user_id); + ChatActivity fragment = new ChatActivity(args); + if (presentFragment(fragment, false, true)) { pushOpened = true; - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); } } } else if (push_chat_id != 0) { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("chat_id", push_chat_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { + Bundle args = new Bundle(); + args.putInt("chat_id", push_chat_id); + ChatActivity fragment = new ChatActivity(args); + if (presentFragment(fragment, false, true)) { pushOpened = true; - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); } - } else if (push_enc_id != 0) { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("enc_id", push_enc_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { + } else if (push_enc_id != 0) { + Bundle args = new Bundle(); + args.putInt("enc_id", push_enc_id); + ChatActivity fragment = new ChatActivity(args); + if (presentFragment(fragment, false, true)) { pushOpened = true; - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); } } if (videoPath != null || photoPath != null || sendingText != null || documentPath != null || documentsPathArray != null || imagesPathArray != null || contactsToSend != null) { - MessagesActivity fragment = new MessagesActivity(); - fragment.selectAlertString = R.string.ForwardMessagesTo; - fragment.selectAlertStringDesc = "ForwardMessagesTo"; - fragment.animationType = 1; + NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); Bundle args = new Bundle(); args.putBoolean("onlySelect", true); - fragment.setArguments(args); - fragment.delegate = this; - ApplicationLoader.fragmentsStack.add(fragment); - fragment.onFragmentCreate(); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()).commitAllowingStateLoss(); + args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo)); + MessagesActivity fragment = new MessagesActivity(args); + fragment.setDelegate(this); + presentFragment(fragment, false, true); pushOpened = true; } if (open_settings != 0) { - SettingsActivity fragment = new SettingsActivity(); - ApplicationLoader.fragmentsStack.add(fragment); - fragment.onFragmentCreate(); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings").commitAllowingStateLoss(); + presentFragment(new SettingsActivity(), false, true); pushOpened = true; } if (!pushOpened && !isNew) { - BaseFragment fragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()).commitAllowingStateLoss(); + showLastFragment(); } getIntent().setAction(null); @@ -554,30 +499,20 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen if (dialog_id != 0) { int lower_part = (int)dialog_id; - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); + Bundle args = new Bundle(); + args.putBoolean("scrollToTopOnResume", true); + NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); if (lower_part != 0) { if (lower_part > 0) { - NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - bundle.putInt("user_id", lower_part); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - presentFragment(fragment, "chat" + Math.random(), true, false); + args.putInt("user_id", lower_part); } else if (lower_part < 0) { - NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - bundle.putInt("chat_id", -lower_part); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - presentFragment(fragment, "chat" + Math.random(), true, false); + args.putInt("chat_id", -lower_part); } } else { - NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - int chat_id = (int)(dialog_id >> 32); - bundle.putInt("enc_id", chat_id); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - presentFragment(fragment, "chat" + Math.random(), true, false); + args.putInt("enc_id", (int)(dialog_id >> 32)); } + ChatActivity fragment = new ChatActivity(args); + presentFragment(fragment, true); if (photoPath != null) { fragment.processSendingPhoto(null, photoPath); } @@ -618,8 +553,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (ApplicationLoader.fragmentsStack.size() != 0) { - BaseFragment fragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); + if (fragmentsStack.size() != 0) { + BaseFragment fragment = fragmentsStack.get(fragmentsStack.size() - 1); fragment.onActivityResultFragment(requestCode, resultCode, data); } } @@ -640,7 +575,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen @Override protected void onDestroy() { super.onDestroy(); - processOnFinish(); + onFinish(); } @Override @@ -649,11 +584,9 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen if (notificationView == null && getLayoutInflater() != null) { notificationView = (NotificationView) getLayoutInflater().inflate(R.layout.notification_layout, null); } - fixLayout(); Utilities.checkForCrashes(this); Utilities.checkForUpdates(this); ApplicationLoader.resetLastPauseTime(); - supportInvalidateOptionsMenu(); updateActionBar(); try { NotificationManager mNotificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); @@ -664,7 +597,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen } } - private void processOnFinish() { + @Override + protected void onFinish() { if (finished) { return; } @@ -686,40 +620,20 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen public void onConfigurationChanged(android.content.res.Configuration newConfig) { super.onConfigurationChanged(newConfig); Utilities.checkDisplaySize(); - fixLayout(); } - private void fixLayout() { - if (containerView != null) { - ViewTreeObserver obs = containerView.getViewTreeObserver(); - obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); - int rotation = manager.getDefaultDisplay().getRotation(); + @Override + public void needLayout() { + super.needLayout(); + if (notificationView != null) { + WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); + int rotation = manager.getDefaultDisplay().getRotation(); - int height; - int currentActionBarHeight = getSupportActionBar().getHeight(); - if (currentActionBarHeight != Utilities.dp(48) && currentActionBarHeight != Utilities.dp(40)) { - height = currentActionBarHeight; - } else { - height = Utilities.dp(48); - if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { - height = Utilities.dp(40); - } - } - - if (notificationView != null) { - notificationView.applyOrientationPaddings(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height); - } - - if (Build.VERSION.SDK_INT < 16) { - containerView.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } else { - containerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } - } - }); + int height = Utilities.dp(48); + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + height = Utilities.dp(40); + } + notificationView.applyOrientationPaddings(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90, height); } } @@ -727,22 +641,20 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen @SuppressWarnings("unchecked") public void didReceivedNotification(int id, Object... args) { if (id == 1234) { - for (BaseFragment fragment : ApplicationLoader.fragmentsStack) { + for (BaseFragment fragment : fragmentsStack) { fragment.onFragmentDestroy(); } - ApplicationLoader.fragmentsStack.clear(); + fragmentsStack.clear(); Intent intent2 = new Intent(this, IntroActivity.class); startActivity(intent2); - processOnFinish(); + onFinish(); finish(); } else if (id == GalleryImageViewer.needShowAllMedia) { long dialog_id = (Long)args[0]; - MediaActivity fragment = new MediaActivity(); - Bundle bundle = new Bundle(); if (dialog_id != 0) { - bundle.putLong("dialog_id", dialog_id); - fragment.setArguments(bundle); - presentFragment(fragment, "media_" + dialog_id, false); + Bundle args2 = new Bundle(); + args2.putLong("dialog_id", dialog_id); + presentFragment(new MediaActivity(args2), false, true); } } else if (id == 658) { Integer push_user_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_user_id", 0); @@ -751,46 +663,19 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen if (push_user_id != 0) { NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", push_user_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { - if (ApplicationLoader.fragmentsStack.size() > 0) { - BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - lastFragment.willBeHidden(); - } - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); - } + Bundle args2 = new Bundle(); + args2.putInt("user_id", push_user_id); + presentFragment(new ChatActivity(args2), false, true); } else if (push_chat_id != 0) { NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("chat_id", push_chat_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { - if (ApplicationLoader.fragmentsStack.size() > 0) { - BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - lastFragment.willBeHidden(); - } - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); - } - } else if (push_enc_id != 0) { + Bundle args2 = new Bundle(); + args2.putInt("chat_id", push_chat_id); + presentFragment(new ChatActivity(args2), false, true); + } else if (push_enc_id != 0) { NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("enc_id", push_enc_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { - if (ApplicationLoader.fragmentsStack.size() > 0) { - BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - lastFragment.willBeHidden(); - } - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); - } + Bundle args2 = new Bundle(); + args2.putInt("enc_id", push_enc_id); + presentFragment(new ChatActivity(args2), false, true); } } else if (id == 701) { if (notificationView != null) { @@ -799,7 +684,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen } } else if (id == 702) { if (args[0] != this) { - processOnFinish(); + onFinish(); } } else if (id == 703) { int state = (Integer)args[0]; @@ -811,207 +696,33 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen } } - public void fixBackButton() { - if(android.os.Build.VERSION.SDK_INT == 19) { - //workaround for back button dissapear - try { - Class firstClass = getSupportActionBar().getClass(); - Class aClass = firstClass.getSuperclass(); - if (aClass == android.support.v7.app.ActionBar.class) { - - } else { - Field field = aClass.getDeclaredField("mActionBar"); - field.setAccessible(true); - android.app.ActionBar bar = (android.app.ActionBar)field.get(getSupportActionBar()); - - field = bar.getClass().getDeclaredField("mActionView"); - field.setAccessible(true); - View v = (View)field.get(bar); - aClass = v.getClass(); - - field = aClass.getDeclaredField("mHomeLayout"); - field.setAccessible(true); - v = (View)field.get(v); - v.setVisibility(View.VISIBLE); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - public void updateActionBar() { - ActionBar actionBar = getSupportActionBar(); - if (actionBar == null) { - return; - } - BaseFragment currentFragment = null; - if (!ApplicationLoader.fragmentsStack.isEmpty()) { - currentFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - } - boolean canApplyLoading = true; - if (currentFragment != null && (currentConnectionState == 0 || !currentFragment.canApplyUpdateStatus() || statusView == null)) { - currentFragment.applySelfActionBar(); - canApplyLoading = false; - } - if (canApplyLoading) { - if (statusView != null) { - statusView.setVisibility(View.VISIBLE); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(false); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setSubtitle(null); - - if (ApplicationLoader.fragmentsStack.size() > 1) { - backStatusButton.setVisibility(View.VISIBLE); - statusBackground.setEnabled(true); - } else { - backStatusButton.setVisibility(View.GONE); - statusBackground.setEnabled(false); - } - - if (currentConnectionState == 1) { - statusText.setText(getString(R.string.WaitingForNetwork)); - } else if (currentConnectionState == 2) { - statusText.setText(getString(R.string.Connecting)); - } else if (currentConnectionState == 3) { - statusText.setText(getString(R.string.Updating)); - } - if (actionBar.getCustomView() != statusView) { - actionBar.setCustomView(statusView); - } - - try { - if (statusView.getLayoutParams() instanceof android.support.v7.app.ActionBar.LayoutParams) { - android.support.v7.app.ActionBar.LayoutParams statusParams = (android.support.v7.app.ActionBar.LayoutParams)statusView.getLayoutParams(); - statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST)); - statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54)); - if (statusParams.height == 0) { - statusParams.height = actionBar.getHeight(); - } - if (statusParams.width <= 0) { - statusParams.width = Utilities.dp(100); - } - statusParams.topMargin = 0; - statusParams.leftMargin = 0; - statusView.setLayoutParams(statusParams); - } else if (statusView.getLayoutParams() instanceof android.app.ActionBar.LayoutParams) { - android.app.ActionBar.LayoutParams statusParams = (android.app.ActionBar.LayoutParams)statusView.getLayoutParams(); - statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST)); - statusParams.width = (statusText.getMeasuredWidth() + Utilities.dp(54)); - if (statusParams.height == 0) { - statusParams.height = actionBar.getHeight(); - } - if (statusParams.width <= 0) { - statusParams.width = Utilities.dp(100); - } - statusParams.topMargin = 0; - statusParams.leftMargin = 0; - statusView.setLayoutParams(statusParams); - } - } catch (Exception e) { - e.printStackTrace(); - } + if (currentConnectionState != 0 && statusView != null) { + onShowFragment(); + if (currentConnectionState == 1) { + statusText.setText(getString(R.string.WaitingForNetwork)); + } else if (currentConnectionState == 2) { + statusText.setText(getString(R.string.Connecting)); + } else if (currentConnectionState == 3) { + statusText.setText(getString(R.string.Updating)); } - } - } - public void presentFragment(BaseFragment fragment, String tag, boolean bySwipe) { - presentFragment(fragment, tag, false, bySwipe); - } - - public void presentFragment(BaseFragment fragment, String tag, boolean removeLast, boolean bySwipe) { - if (getCurrentFocus() != null) { - Utilities.hideKeyboard(getCurrentFocus()); + statusText.measure(View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST)); + actionBar.setBackOverlay(statusView, (statusText.getMeasuredWidth() + Utilities.dp(54))); + } else { + actionBar.setBackOverlay(null, 0); } - if (!fragment.onFragmentCreate()) { - return; - } - BaseFragment current = null; - if (!ApplicationLoader.fragmentsStack.isEmpty()) { - current = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - } - if (current != null) { - current.willBeHidden(); - } - FragmentManager fm = getSupportFragmentManager(); - FragmentTransaction fTrans = fm.beginTransaction(); - if (removeLast && current != null) { - ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1); - current.onFragmentDestroy(); - } - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - boolean animations = preferences.getBoolean("view_animations", true); - if (animations) { - if (bySwipe) { - fTrans.setCustomAnimations(R.anim.slide_left, R.anim.no_anim); - } else { - fTrans.setCustomAnimations(R.anim.scale_in, R.anim.no_anim); - } - } - try { - fTrans.replace(R.id.container, fragment, tag); - fTrans.commitAllowingStateLoss(); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - ApplicationLoader.fragmentsStack.add(fragment); - } - - public void removeFromStack(BaseFragment fragment) { - ApplicationLoader.fragmentsStack.remove(fragment); - fragment.onFragmentDestroy(); - } - - public void finishFragment(boolean bySwipe) { - if (getCurrentFocus() != null) { - Utilities.hideKeyboard(getCurrentFocus()); - } - if (ApplicationLoader.fragmentsStack.size() < 2) { - for (BaseFragment fragment : ApplicationLoader.fragmentsStack) { - fragment.onFragmentDestroy(); - } - ApplicationLoader.fragmentsStack.clear(); - MessagesActivity fragment = new MessagesActivity(); - fragment.onFragmentCreate(); - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chats").commitAllowingStateLoss(); - return; - } - BaseFragment fragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - fragment.onFragmentDestroy(); - BaseFragment prev = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 2); - FragmentManager fm = getSupportFragmentManager(); - FragmentTransaction fTrans = fm.beginTransaction(); - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - boolean animations = preferences.getBoolean("view_animations", true); - if (animations) { - if (bySwipe) { - fTrans.setCustomAnimations(R.anim.no_anim_show, R.anim.slide_right_away); - } else { - fTrans.setCustomAnimations(R.anim.no_anim_show, R.anim.scale_out); - } - } - fTrans.replace(R.id.container, prev, prev.getTag()); - fTrans.commitAllowingStateLoss(); - ApplicationLoader.fragmentsStack.remove(ApplicationLoader.fragmentsStack.size() - 1); } @Override - public void onBackPressed() { - if (ApplicationLoader.fragmentsStack.size() == 1) { - ApplicationLoader.fragmentsStack.get(0).onFragmentDestroy(); - ApplicationLoader.fragmentsStack.clear(); - processOnFinish(); - finish(); - return; - } - if (!ApplicationLoader.fragmentsStack.isEmpty()) { - BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); - if (lastFragment.onBackPressed()) { - finishFragment(false); + protected void onShowFragment() { + if (statusView != null) { + if (fragmentsStack.size() > 1) { + backStatusButton.setVisibility(View.VISIBLE); + statusBackground.setEnabled(true); + } else { + backStatusButton.setVisibility(View.GONE); + statusBackground.setEnabled(false); } } } @@ -1020,8 +731,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen protected void onSaveInstanceState(Bundle outState) { try { super.onSaveInstanceState(outState); - if (!ApplicationLoader.fragmentsStack.isEmpty()) { - BaseFragment lastFragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); + if (!fragmentsStack.isEmpty()) { + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1); Bundle args = lastFragment.getArguments(); if (lastFragment instanceof ChatActivity && args != null) { outState.putBundle("args", args); @@ -1033,6 +744,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen outState.putString("fragment", "group"); } else if (lastFragment instanceof SettingsWallpapersActivity) { outState.putString("fragment", "wallpapers"); + } else if (lastFragment instanceof ChatProfileActivity && args != null) { + outState.putString("fragment", "chat_profile"); } lastFragment.saveSelfArgs(outState); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java index b487659d..813d93ba 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java @@ -9,13 +9,7 @@ package org.telegram.ui; import android.location.Location; -import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v7.app.ActionBar; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -23,13 +17,15 @@ import android.widget.TextView; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.MapView; +import com.google.android.gms.maps.MapsInitializer; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; +import org.telegram.messenger.FileLog; import org.telegram.messenger.LocaleController; import org.telegram.messenger.TLRPC; import org.telegram.objects.MessageObject; @@ -37,8 +33,11 @@ import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +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.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; public class LocationActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { private GoogleMap googleMap; @@ -49,116 +48,15 @@ public class LocationActivity extends BaseFragment implements NotificationCenter private MessageObject messageObject; private BackupImageView avatarImageView; private TextView nameTextView; - private View bottomView; - private TextView sendButton; private boolean userLocationMoved = false; private boolean firstWas = false; + private MapView mapView; private final static int map_to_my_location = 1; private final static int map_list_menu_map = 2; private final static int map_list_menu_satellite = 3; private final static int map_list_menu_hybrid = 4; - public SupportMapFragment mapFragment = new SupportMapFragment() { - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - googleMap = getMap(); - if (googleMap == null) { - return; - } - - googleMap.setMyLocationEnabled(true); - googleMap.getUiSettings().setMyLocationButtonEnabled(false); - googleMap.getUiSettings().setZoomControlsEnabled(false); - googleMap.getUiSettings().setCompassEnabled(false); - googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { - @Override - public void onMyLocationChange(Location location) { - positionMarker(location); - } - }); - myLocation = googleMap.getMyLocation(); - - if (sendButton != null) { - userLocation = new Location("network"); - userLocation.setLatitude(20.659322); - userLocation.setLongitude(-11.406250); - LatLng latLng = new LatLng(20.659322, -11.406250); - userMarker = googleMap.addMarker(new MarkerOptions().position(latLng). - icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)).draggable(true)); - - sendButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - NotificationCenter.getInstance().postNotificationName(997, userLocation.getLatitude(), userLocation.getLongitude()); - finishFragment(); - } - }); - - googleMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() { - @Override - public void onMarkerDragStart(Marker marker) { - } - - @Override - public void onMarkerDrag(Marker marker) { - userLocationMoved = true; - } - - @Override - public void onMarkerDragEnd(Marker marker) { - LatLng latLng = marker.getPosition(); - userLocation.setLatitude(latLng.latitude); - userLocation.setLongitude(latLng.longitude); - } - }); - } - - if (bottomView != null) { - bottomView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (userLocation != null) { - LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); - CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8); - googleMap.animateCamera(position); - } - } - }); - } - - if (messageObject != null) { - int fromId = messageObject.messageOwner.from_id; - if (messageObject.messageOwner instanceof TLRPC.TL_messageForwarded) { - fromId = messageObject.messageOwner.fwd_from_id; - } - TLRPC.User user = MessagesController.getInstance().users.get(fromId); - if (user != null) { - TLRPC.FileLocation photo = null; - if (user.photo != null) { - photo = user.photo.photo_small; - } - avatarImageView.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id)); - nameTextView.setText(Utilities.formatName(user.first_name, user.last_name)); - } - userLocation = new Location("network"); - userLocation.setLatitude(messageObject.messageOwner.media.geo.lat); - userLocation.setLongitude(messageObject.messageOwner.media.geo._long); - LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); - userMarker = googleMap.addMarker(new MarkerOptions().position(latLng). - icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin))); - CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8); - googleMap.moveCamera(position); - } - - positionMarker(myLocation); - - ViewGroup topLayout = (ViewGroup)parentActivity.findViewById(R.id.container); - topLayout.requestTransparentRegion(topLayout); - } - }; - @Override public boolean onFragmentCreate() { super.onFragmentCreate(); @@ -175,57 +73,58 @@ public class LocationActivity extends BaseFragment implements NotificationCenter super.onFragmentDestroy(); NotificationCenter.getInstance().removeObserver(this, MessagesController.updateInterfaces); NotificationCenter.getInstance().removeObserver(this, MessagesController.closeChats); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setSubtitle(null); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - if (messageObject != null) { - actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation)); - } else { - actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation)); - } - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); + if (mapView != null) { + mapView.onDestroy(); } } @Override - public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + if (messageObject != null) { + actionBarLayer.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation)); + } else { + actionBarLayer.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation)); + } + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } else if (id == map_list_menu_map) { + if (googleMap != null) { + googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); + } + } else if (id == map_list_menu_satellite) { + if (googleMap != null) { + googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); + } + } else if (id == map_list_menu_hybrid) { + if (googleMap != null) { + googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); + } + } else if (id == map_to_my_location) { + if (myLocation != null) { + LatLng latLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude()); + if (googleMap != null) { + CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8); + googleMap.animateCamera(position); + } + } + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + menu.addItem(map_to_my_location, R.drawable.ic_ab_location); + + ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); + item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0); + item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0); + item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0); + if (messageObject != null) { fragmentView = inflater.inflate(R.layout.location_view_layout, container, false); } else { @@ -235,13 +134,108 @@ public class LocationActivity extends BaseFragment implements NotificationCenter avatarImageView = (BackupImageView)fragmentView.findViewById(R.id.location_avatar_view); nameTextView = (TextView)fragmentView.findViewById(R.id.location_name_label); distanceTextView = (TextView)fragmentView.findViewById(R.id.location_distance_label); - bottomView = fragmentView.findViewById(R.id.location_bottom_view); - sendButton = (TextView)fragmentView.findViewById(R.id.location_send_button); + View bottomView = fragmentView.findViewById(R.id.location_bottom_view); + TextView sendButton = (TextView) fragmentView.findViewById(R.id.location_send_button); if (sendButton != null) { sendButton.setText(LocaleController.getString("SendLocation", R.string.SendLocation)); } - getChildFragmentManager().beginTransaction().replace(R.id.map_view, mapFragment).commit(); + mapView = (MapView)fragmentView.findViewById(R.id.map_view); + mapView.onCreate(null); + try { + MapsInitializer.initialize(getParentActivity()); + googleMap = mapView.getMap(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + + if (googleMap != null) { + googleMap.setMyLocationEnabled(true); + googleMap.getUiSettings().setMyLocationButtonEnabled(false); + googleMap.getUiSettings().setZoomControlsEnabled(false); + googleMap.getUiSettings().setCompassEnabled(false); + googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { + @Override + public void onMyLocationChange(Location location) { + positionMarker(location); + } + }); + myLocation = googleMap.getMyLocation(); + + + if (sendButton != null) { + userLocation = new Location("network"); + userLocation.setLatitude(20.659322); + userLocation.setLongitude(-11.406250); + LatLng latLng = new LatLng(20.659322, -11.406250); + userMarker = googleMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)).draggable(true)); + + sendButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + NotificationCenter.getInstance().postNotificationName(997, userLocation.getLatitude(), userLocation.getLongitude()); + finishFragment(); + } + }); + + googleMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() { + @Override + public void onMarkerDragStart(Marker marker) { + } + + @Override + public void onMarkerDrag(Marker marker) { + userLocationMoved = true; + } + + @Override + public void onMarkerDragEnd(Marker marker) { + LatLng latLng = marker.getPosition(); + userLocation.setLatitude(latLng.latitude); + userLocation.setLongitude(latLng.longitude); + } + }); + } + + if (bottomView != null) { + bottomView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (userLocation != null) { + LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); + CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8); + googleMap.animateCamera(position); + } + } + }); + } + + if (messageObject != null) { + int fromId = messageObject.messageOwner.from_id; + if (messageObject.messageOwner instanceof TLRPC.TL_messageForwarded) { + fromId = messageObject.messageOwner.fwd_from_id; + } + TLRPC.User user = MessagesController.getInstance().users.get(fromId); + if (user != null) { + TLRPC.FileLocation photo = null; + if (user.photo != null) { + photo = user.photo.photo_small; + } + avatarImageView.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id)); + nameTextView.setText(Utilities.formatName(user.first_name, user.last_name)); + } + userLocation = new Location("network"); + userLocation.setLatitude(messageObject.messageOwner.media.geo.lat); + userLocation.setLongitude(messageObject.messageOwner.media.geo._long); + LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); + userMarker = googleMap.addMarker(new MarkerOptions().position(latLng). + icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin))); + CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8); + googleMap.moveCamera(position); + } + + positionMarker(myLocation); + } } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -269,51 +263,6 @@ public class LocationActivity extends BaseFragment implements NotificationCenter } } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - SupportMenuItem item = (SupportMenuItem)menu.add(Menu.NONE, map_to_my_location, Menu.NONE, LocaleController.getString("MyLocation", R.string.MyLocation)).setIcon(R.drawable.ic_ab_location); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - - menu.add(Menu.NONE, map_list_menu_map, Menu.NONE, LocaleController.getString("Map", R.string.Map)); - menu.add(Menu.NONE, map_list_menu_satellite, Menu.NONE, LocaleController.getString("Satellite", R.string.Satellite)); - menu.add(Menu.NONE, map_list_menu_hybrid, Menu.NONE, LocaleController.getString("Hybrid", R.string.Hybrid)); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case map_list_menu_map: - if (googleMap != null) { - googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); - } - break; - case map_list_menu_satellite: - if (googleMap != null) { - googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); - } - break; - case map_list_menu_hybrid: - if (googleMap != null) { - googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); - } - break; - case map_to_my_location: - if (myLocation != null) { - LatLng latLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude()); - if (googleMap != null) { - CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8); - googleMap.animateCamera(position); - } - } - break; - case android.R.id.home: - finishFragment(); - break; - } - return true; - } - private void positionMarker(Location location) { if (location == null) { return; @@ -343,7 +292,6 @@ public class LocationActivity extends BaseFragment implements NotificationCenter } } } - } @Override @@ -357,4 +305,28 @@ public class LocationActivity extends BaseFragment implements NotificationCenter removeSelfFromStack(); } } + + @Override + public void onPause() { + super.onPause(); + if (mapView != null) { + mapView.onPause(); + } + } + + @Override + public void onResume() { + super.onResume(); + if (mapView != null) { + mapView.onResume(); + } + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + if (mapView != null) { + mapView.onLowMemory(); + } + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java index d4ffe872..a74be4cf 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java @@ -9,55 +9,99 @@ package org.telegram.ui; import android.animation.Animator; -import android.app.Activity; import android.app.AlertDialog; -import android.content.Intent; +import android.content.Context; import android.content.SharedPreferences; -import android.graphics.Point; import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v7.app.ActionBarActivity; -import android.view.Display; -import android.view.Menu; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.animation.AccelerateDecelerateInterpolator; -import android.widget.ImageView; import android.widget.TextView; import org.telegram.messenger.FileLog; import org.telegram.messenger.LocaleController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.SlideView; import java.util.Map; import java.util.Set; -public class LoginActivity extends ActionBarActivity implements SlideView.SlideViewDelegate { +public class LoginActivity extends BaseFragment implements SlideView.SlideViewDelegate { private int currentViewNum = 0; private SlideView[] views = new SlideView[3]; + private final static int done_button = 1; + @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (currentViewNum == 0) { - if (resultCode == RESULT_OK) { - ((LoginActivityPhoneView)views[0]).selectCountry(data.getStringExtra("country")); + public boolean onFragmentCreate() { + return super.onFragmentCreate(); + } + + @Override + public void onFragmentDestroy() { + super.onFragmentDestroy(); + for (SlideView v : views) { + if (v != null) { + v.onDestroyActivity(); } } + Utilities.HideProgressDialog(getParentActivity()); } @Override - protected void onResume() { - super.onResume(); - Utilities.checkForCrashes(this); - Utilities.checkForUpdates(this); - ApplicationLoader.resetLastPauseTime(); - } + public View createView(LayoutInflater inflater, ViewGroup container) { + if (fragmentView == null) { + actionBarLayer.setDisplayUseLogoEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("AppName", R.string.AppName)); - @Override - protected void onPause() { - super.onPause(); - ApplicationLoader.lastPauseTime = System.currentTimeMillis(); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == done_button) { + onNextAction(); + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout); + TextView doneTextView = (TextView)doneItem.findViewById(R.id.done_button); + doneTextView.setText(LocaleController.getString("Done", R.string.Done)); + + fragmentView = inflater.inflate(R.layout.login_layout, container, false); + + views[0] = (SlideView)fragmentView.findViewById(R.id.login_page1); + views[1] = (SlideView)fragmentView.findViewById(R.id.login_page2); + views[2] = (SlideView)fragmentView.findViewById(R.id.login_page3); + + actionBarLayer.setTitle(views[0].getHeaderName()); + + Bundle savedInstanceState = loadCurrentState(); + if (savedInstanceState != null) { + currentViewNum = savedInstanceState.getInt("currentViewNum", 0); + } + for (int a = 0; a < views.length; a++) { + SlideView v = views[a]; + if (v != null) { + if (savedInstanceState != null) { + v.restoreStateParams(savedInstanceState); + } + v.delegate = this; + v.setVisibility(currentViewNum == a ? View.VISIBLE : View.GONE); + } + } + } else { + ViewGroup parent = (ViewGroup)fragmentView.getParent(); + if (parent != null) { + parent.removeView(fragmentView); + } + } + return fragmentView; } private void saveCurrentState() { @@ -70,7 +114,7 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV v.saveStateParams(bundle); } } - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", MODE_PRIVATE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); putBundleToEditor(bundle, editor, null); @@ -83,7 +127,7 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV private Bundle loadCurrentState() { try { Bundle bundle = new Bundle(); - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", MODE_PRIVATE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", Context.MODE_PRIVATE); Map params = preferences.getAll(); for (Map.Entry entry : params.entrySet()) { String key = entry.getKey(); @@ -116,7 +160,7 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV } private void clearCurrentState() { - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", MODE_PRIVATE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); @@ -144,125 +188,58 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV } } - public void ShowAlertDialog(final Activity activity, final String message) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (!isFinishing()) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); - builder.setMessage(message); - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); - builder.show().setCanceledOnTouchOutside(true); - } - } - }); - } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.login_layout); - ApplicationLoader.applicationContext = this.getApplicationContext(); - - getSupportActionBar().setLogo(R.drawable.ab_icon_fixed2); - getSupportActionBar().show(); - - ImageView view = (ImageView)findViewById(16908332); - if (view == null) { - view = (ImageView)findViewById(R.id.home); - } - if (view != null) { - view.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0); - } - - views[0] = (SlideView)findViewById(R.id.login_page1); - views[1] = (SlideView)findViewById(R.id.login_page2); - views[2] = (SlideView)findViewById(R.id.login_page3); - - getSupportActionBar().setTitle(views[0].getHeaderName()); - - savedInstanceState = loadCurrentState(); - if (savedInstanceState != null) { - currentViewNum = savedInstanceState.getInt("currentViewNum", 0); - } - for (int a = 0; a < views.length; a++) { - SlideView v = views[a]; - if (v != null) { - if (savedInstanceState != null) { - v.restoreStateParams(savedInstanceState); - } - v.delegate = this; - v.setVisibility(currentViewNum == a ? View.VISIBLE : View.GONE); - } - } - - getWindow().setBackgroundDrawableResource(R.drawable.transparent); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - SupportMenuItem doneItem = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, null); - doneItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - doneItem.setActionView(R.layout.group_create_done_layout); - - TextView doneTextView = (TextView)doneItem.getActionView().findViewById(R.id.done_button); - doneTextView.setText(LocaleController.getString("Done", R.string.Done)); - doneTextView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - onNextAction(); - } - }); - return super.onCreateOptionsMenu(menu); - } - - @Override - public void onBackPressed() { + public boolean onBackPressed() { if (currentViewNum == 0) { for (SlideView v : views) { if (v != null) { v.onDestroyActivity(); } } - super.onBackPressed(); + return true; } else if (currentViewNum != 1 && currentViewNum != 2) { setPage(0, true, null, true); } + return false; } @Override - public void needShowAlert(String text) { + public void needShowAlert(final String text) { if (text == null) { return; } - ShowAlertDialog(LoginActivity.this, text); + getParentActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); + builder.setMessage(text); + builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); + builder.show().setCanceledOnTouchOutside(true); + } + }); } @Override public void needShowProgress() { - Utilities.ShowProgressDialog(this, LocaleController.getString("Loading", R.string.Loading)); + Utilities.ShowProgressDialog(getParentActivity(), LocaleController.getString("Loading", R.string.Loading)); } @Override public void needHideProgress() { - Utilities.HideProgressDialog(this); + Utilities.HideProgressDialog(getParentActivity()); } public void setPage(int page, boolean animated, Bundle params, boolean back) { if(android.os.Build.VERSION.SDK_INT > 13) { - Point displaySize = new Point(); - Display display = getWindowManager().getDefaultDisplay(); - display.getSize(displaySize); - final SlideView outView = views[currentViewNum]; final SlideView newView = views[page]; currentViewNum = page; newView.setParams(params); - getSupportActionBar().setTitle(newView.getHeaderName()); + actionBarLayer.setTitle(newView.getHeaderName()); newView.onShow(); - newView.setX(back ? -displaySize.x : displaySize.x); + newView.setX(back ? -Utilities.displaySize.x : Utilities.displaySize.x); outView.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { @@ -281,7 +258,7 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV @Override public void onAnimationRepeat(Animator animator) { } - }).setDuration(300).translationX(back ? displaySize.x : -displaySize.x).start(); + }).setDuration(300).translationX(back ? Utilities.displaySize.x : -Utilities.displaySize.x).start(); newView.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { @@ -305,7 +282,7 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV currentViewNum = page; views[page].setParams(params); views[page].setVisibility(View.VISIBLE); - getSupportActionBar().setTitle(views[page].getHeaderName()); + actionBarLayer.setTitle(views[page].getHeaderName()); views[page].onShow(); } } @@ -316,27 +293,13 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV } @Override - protected void onDestroy() { - super.onDestroy(); - for (SlideView v : views) { - if (v != null) { - v.onDestroyActivity(); - } - } - Utilities.HideProgressDialog(this); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); + public void saveSelfArgs(Bundle outState) { saveCurrentState(); } @Override public void needFinishActivity() { - Intent intent2 = new Intent(this, LaunchActivity.class); - startActivity(intent2); - finish(); clearCurrentState(); + presentFragment(new MessagesActivity(null), true); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java index c46d1d4d..786cdcf3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivityPhoneView.java @@ -9,9 +9,7 @@ package org.telegram.ui; import android.content.Context; -import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.telephony.TelephonyManager; import android.text.Editable; import android.text.TextWatcher; @@ -33,6 +31,7 @@ import org.telegram.messenger.FileLog; import org.telegram.messenger.R; import org.telegram.messenger.RPCRequest; import org.telegram.messenger.Utilities; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.SlideView; import java.io.BufferedReader; @@ -82,9 +81,16 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI countryButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - ActionBarActivity activity = (ActionBarActivity)delegate; - Intent intent = new Intent(activity, CountrySelectActivity.class); - activity.startActivityForResult(intent, 1); + BaseFragment activity = (BaseFragment)delegate; + CountrySelectActivity fragment = new CountrySelectActivity(); + fragment.setCountrySelectActivityDelegate(new CountrySelectActivity.CountrySelectActivityDelegate() { + @Override + public void didSelectCountry(String name) { + selectCountry(name); + phoneField.requestFocus(); + } + }); + activity.presentFragment(fragment); } }); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java index df1c05fa..a228e356 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java @@ -13,9 +13,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.support.v7.app.ActionBar; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -34,9 +32,9 @@ import org.telegram.objects.MessageObject; import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.BaseFragment; import java.util.ArrayList; import java.util.HashMap; @@ -57,6 +55,10 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No private View progressView; private TextView emptyView; + public MediaActivity(Bundle args) { + super(args); + } + @Override public boolean onFragmentCreate() { super.onFragmentCreate(); @@ -83,14 +85,24 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("SharedMedia", R.string.SharedMedia)); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + if (Build.VERSION.SDK_INT < 11) { + listView.setAdapter(null); + listView = null; + listAdapter = null; + } + finishFragment(); + } + } + }); + fragmentView = inflater.inflate(R.layout.media_layout, container, false); emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); @@ -98,14 +110,14 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No listView = (GridView)fragmentView.findViewById(R.id.media_grid); progressView = fragmentView.findViewById(R.id.progressLayout); - listView.setAdapter(listAdapter = new ListAdapter(parentActivity)); + listView.setAdapter(listAdapter = new ListAdapter(getParentActivity())); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { NotificationCenter.getInstance().addToMemCache(54, messages); NotificationCenter.getInstance().addToMemCache(55, i); - Intent intent = new Intent(parentActivity, GalleryImageViewer.class); - startActivity(intent); + Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class); + getParentActivity().startActivity(intent); } }); if (loading && messages.isEmpty()) { @@ -130,17 +142,6 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No } } }); - - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); - emptyView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -250,44 +251,11 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("SharedMedia", R.string.SharedMedia)); - actionBar.setSubtitle(null); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - @Override public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } - if (!firstStart && listAdapter != null) { + if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } - firstStart = false; - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); fixLayout(); } @@ -303,24 +271,23 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { - if (parentActivity != null) { - WindowManager manager = (WindowManager)parentActivity.getSystemService(Activity.WINDOW_SERVICE); - int rotation = manager.getDefaultDisplay().getRotation(); + WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE); + int rotation = manager.getDefaultDisplay().getRotation(); - if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { - orientation = 1; - listView.setNumColumns(6); - itemWidth = getResources().getDisplayMetrics().widthPixels / 6 - Utilities.dp(2) * 5; - listView.setColumnWidth(itemWidth); - } else { - orientation = 0; - listView.setNumColumns(4); - itemWidth = getResources().getDisplayMetrics().widthPixels / 4 - Utilities.dp(2) * 3; - listView.setColumnWidth(itemWidth); - } - listView.setPadding(listView.getPaddingLeft(), Utilities.dp(4), listView.getPaddingRight(), listView.getPaddingBottom()); - listAdapter.notifyDataSetChanged(); + if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { + orientation = 1; + listView.setNumColumns(6); + itemWidth = getParentActivity().getResources().getDisplayMetrics().widthPixels / 6 - Utilities.dp(2) * 5; + listView.setColumnWidth(itemWidth); + } else { + orientation = 0; + listView.setNumColumns(4); + itemWidth = getParentActivity().getResources().getDisplayMetrics().widthPixels / 4 - Utilities.dp(2) * 3; + listView.setColumnWidth(itemWidth); } + listView.setPadding(listView.getPaddingLeft(), Utilities.dp(4), listView.getPaddingRight(), listView.getPaddingBottom()); + listAdapter.notifyDataSetChanged(); + if (listView != null) { listView.getViewTreeObserver().removeOnPreDrawListener(this); } @@ -331,22 +298,6 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No } } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - if (Build.VERSION.SDK_INT < 11) { - listView.setAdapter(null); - listView = null; - listAdapter = null; - } - finishFragment(); - break; - } - return true; - } - private class ListAdapter extends BaseAdapter { private Context mContext; @@ -403,13 +354,6 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No if (message.messageOwner.media != null && message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) { ArrayList sizes = message.messageOwner.media.photo.sizes; boolean set = false; -// for (TLRPC.PhotoSize size : sizes) { -// if (size.type != null && size.type.equals("m")) { -// set = true; -// imageView.setImage(size.location, null, R.drawable.photo_placeholder); -// break; -// } -// } if (!set) { if (message.imagePreview != null) { imageView.setImageBitmap(message.imagePreview); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java index 674ba104..0c525559 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java @@ -12,21 +12,13 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; -import android.support.v4.app.FragmentActivity; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBar; -import android.support.v7.widget.SearchView; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.BaseAdapter; -import android.widget.ImageView; +import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; @@ -43,9 +35,11 @@ import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.DialogCell; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; +import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; +import org.telegram.ui.Views.ActionBar.BaseFragment; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; @@ -55,11 +49,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter private MessagesAdapter messagesListViewAdapter; private TextView searchEmptyView; private View progressView; - private SupportMenuItem searchItem; private View empryView; - private SearchView searchView; - public int selectAlertString = 0; - public String selectAlertStringDesc = null; + private String selectAlertString; private boolean serverOnly = false; private static boolean dialogsLoaded = false; @@ -73,10 +64,11 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter public ArrayList searchResult; public ArrayList searchResultNames; - public MessagesActivityDelegate delegate; + private MessagesActivityDelegate delegate; private final static int messages_list_menu_new_messages = 1; private final static int messages_list_menu_new_chat = 2; + private final static int messages_list_menu_other = 6; private final static int messages_list_menu_new_secret_chat = 3; private final static int messages_list_menu_contacts = 4; private final static int messages_list_menu_settings = 5; @@ -85,6 +77,10 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter public abstract void didSelectDialog(MessagesActivity fragment, long dialog_id); } + public MessagesActivity(Bundle args) { + super(args); + } + @Override public boolean onFragmentCreate() { super.onFragmentCreate(); @@ -96,8 +92,9 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter NotificationCenter.getInstance().addObserver(this, MessagesController.contactsDidLoaded); NotificationCenter.getInstance().addObserver(this, 1234); if (getArguments() != null) { - onlySelect = getArguments().getBoolean("onlySelect", false); - serverOnly = getArguments().getBoolean("serverOnly", false); + onlySelect = arguments.getBoolean("onlySelect", false); + serverOnly = arguments.getBoolean("serverOnly", false); + selectAlertString = arguments.getString("selectAlertString"); } if (!dialogsLoaded) { MessagesController.getInstance().loadDialogs(0, 0, 100, true); @@ -121,20 +118,101 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + ActionBarMenu menu = actionBarLayer.createMenu(); + menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { + @Override + public void onSearchExpand() { + searching = true; + if (messagesListView != null) { + messagesListView.setEmptyView(searchEmptyView); + } + if (empryView != null) { + empryView.setVisibility(View.GONE); + } + } + + @Override + public void onSearchCollapse() { + searchDialogs(null); + searching = false; + searchWas = false; + if (messagesListView != null) { + messagesListView.setEmptyView(empryView); + searchEmptyView.setVisibility(View.GONE); + } + if (messagesListViewAdapter != null) { + messagesListViewAdapter.notifyDataSetChanged(); + } + } + + @Override + public void onTextChanged(EditText editText) { + String text = editText.getText().toString(); + searchDialogs(text); + if (text.length() != 0) { + searchWas = true; + if (messagesListViewAdapter != null) { + messagesListViewAdapter.notifyDataSetChanged(); + } + if (searchEmptyView != null) { + messagesListView.setEmptyView(searchEmptyView); + empryView.setVisibility(View.GONE); + } + } + } + }); + if (onlySelect) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat)); + } else { + actionBarLayer.setDisplayUseLogoEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("AppName", R.string.AppName)); + menu.addItem(messages_list_menu_new_messages, R.drawable.ic_ab_compose); + ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); + item.addSubItem(messages_list_menu_new_chat, LocaleController.getString("NewGroup", R.string.NewGroup), 0); + item.addSubItem(messages_list_menu_new_secret_chat, LocaleController.getString("NewSecretChat", R.string.NewSecretChat), 0); + item.addSubItem(messages_list_menu_contacts, LocaleController.getString("Contacts", R.string.Contacts), 0); + item.addSubItem(messages_list_menu_settings, LocaleController.getString("Settings", R.string.Settings), 0); + } + + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == messages_list_menu_settings) { + presentFragment(new SettingsActivity()); + } else if (id == messages_list_menu_contacts) { + presentFragment(new ContactsActivity(null)); + } else if (id == messages_list_menu_new_messages) { + Bundle args = new Bundle(); + args.putBoolean("onlyUsers", true); + args.putBoolean("destroyAfterSelect", true); + args.putBoolean("usersAsSections", true); + presentFragment(new ContactsActivity(args)); + } else if (id == messages_list_menu_new_secret_chat) { + Bundle args = new Bundle(); + args.putBoolean("onlyUsers", true); + args.putBoolean("destroyAfterSelect", true); + args.putBoolean("usersAsSections", true); + args.putBoolean("createSecretChat", true); + presentFragment(new ContactsActivity(args)); + } else if (id == messages_list_menu_new_chat) { + presentFragment(new GroupCreateActivity()); + } else if (id == -1) { + if (onlySelect) { + finishFragment(); + } + } + } + }); + searching = false; searchWas = false; fragmentView = inflater.inflate(R.layout.messages_list, container, false); - messagesListViewAdapter = new MessagesAdapter(parentActivity); + messagesListViewAdapter = new MessagesAdapter(getParentActivity()); messagesListView = (ListView)fragmentView.findViewById(R.id.messages_list_view); messagesListView.setAdapter(messagesListViewAdapter); @@ -199,25 +277,18 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter if (onlySelect) { didSelectResult(dialog_id, true); } else { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); + Bundle args = new Bundle(); int lower_part = (int)dialog_id; if (lower_part != 0) { if (lower_part > 0) { - bundle.putInt("user_id", lower_part); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false); + args.putInt("user_id", lower_part); } else if (lower_part < 0) { - bundle.putInt("chat_id", -lower_part); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false); + args.putInt("chat_id", -lower_part); } } else { - int id = (int)(dialog_id >> 32); - bundle.putInt("enc_id", id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false); + args.putInt("enc_id", (int)(dialog_id >> 32)); } + presentFragment(new ChatActivity(args)); } } }); @@ -242,7 +313,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter } selectedDialog = dialog.id; - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if ((int)selectedDialog < 0) { @@ -275,7 +346,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { - Utilities.hideKeyboard(searchView); + Utilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @@ -305,75 +376,17 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter return fragmentView; } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - final ActionBar actionBar = parentActivity.getSupportActionBar(); - if (onlySelect) { - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setSubtitle(null); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat)); - ((LaunchActivity)parentActivity).fixBackButton(); - } else { - ImageView view = (ImageView)parentActivity.findViewById(16908332); - if (view == null) { - view = (ImageView)parentActivity.findViewById(R.id.home); - } - if (view != null) { - view.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0); - } - actionBar.setHomeButtonEnabled(false); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(true); - actionBar.setDisplayHomeAsUpEnabled(false); - actionBar.setDisplayUseLogoEnabled(true); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setSubtitle(null); - actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); - } - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } + showActionBar(); if (messagesListViewAdapter != null) { messagesListViewAdapter.notifyDataSetChanged(); } - - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); } @Override public void onPause() { - super.onPause(); - if (searchItem != null && searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } + actionBarLayer.closeSearchField(); } @Override @@ -439,18 +452,13 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter } } - @Override - public void willBeHidden() { - if (searchItem != null) { - if (searchItem.isActionViewExpanded()) { - searchItem.collapseActionView(); - } - } + public void setDelegate(MessagesActivityDelegate delegate) { + this.delegate = delegate; } private void didSelectResult(final long dialog_id, boolean useAlert) { - if (useAlert && selectAlertString != 0) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + if (useAlert && selectAlertString != null) { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); int lower_part = (int)dialog_id; if (lower_part != 0) { @@ -459,13 +467,13 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter if (user == null) { return; } - builder.setMessage(LocaleController.formatString(selectAlertStringDesc, selectAlertString, Utilities.formatName(user.first_name, user.last_name))); + builder.setMessage(LocaleController.formatStringSimple(selectAlertString, Utilities.formatName(user.first_name, user.last_name))); } else if (lower_part < 0) { TLRPC.Chat chat = MessagesController.getInstance().chats.get(-lower_part); if (chat == null) { return; } - builder.setMessage(LocaleController.formatString(selectAlertStringDesc, selectAlertString, chat.title)); + builder.setMessage(LocaleController.formatStringSimple(selectAlertString, chat.title)); } } else { int chat_id = (int)(dialog_id >> 32); @@ -474,7 +482,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter if (user == null) { return; } - builder.setMessage(LocaleController.formatString(selectAlertStringDesc, selectAlertString, Utilities.formatName(user.first_name, user.last_name))); + builder.setMessage(LocaleController.formatStringSimple(selectAlertString, Utilities.formatName(user.first_name, user.last_name))); } builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { @Override @@ -550,167 +558,6 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter } } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (parentActivity == null) { - return; - } - searchItem = (SupportMenuItem)menu.add(Menu.NONE, 0, Menu.NONE, LocaleController.getString("Search", R.string.Search)).setIcon(R.drawable.ic_ab_search); - searchItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS|SupportMenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - searchItem.setActionView(searchView = new SearchView(parentActivity)); - if (!onlySelect) { - SupportMenuItem item = (SupportMenuItem)menu.add(Menu.NONE, messages_list_menu_new_messages, Menu.NONE, LocaleController.getString("NewMessages", R.string.NewMessages)).setIcon(R.drawable.ic_ab_compose); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - - item = (SupportMenuItem)menu.add(Menu.NONE, messages_list_menu_new_chat, Menu.NONE, LocaleController.getString("NewGroup", R.string.NewGroup)); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_NEVER); - - item = (SupportMenuItem)menu.add(Menu.NONE, messages_list_menu_new_secret_chat, Menu.NONE, LocaleController.getString("NewSecretChat", R.string.NewSecretChat)); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_NEVER); - - item = (SupportMenuItem)menu.add(Menu.NONE, messages_list_menu_contacts, Menu.NONE, LocaleController.getString("Contacts", R.string.Contacts)); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_NEVER); - - item = (SupportMenuItem)menu.add(Menu.NONE, messages_list_menu_settings, Menu.NONE, LocaleController.getString("Settings", R.string.Settings)); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_NEVER); - } - - TextView textView = (TextView) searchView.findViewById(R.id.search_src_text); - if (textView != null) { - textView.setTextColor(0xffffffff); - try { - Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); - mCursorDrawableRes.setAccessible(true); - mCursorDrawableRes.set(textView, R.drawable.search_carret); - } catch (Exception e) { - e.printStackTrace(); - } - } - - ImageView img = (ImageView) searchView.findViewById(R.id.search_close_btn); - if (img != null) { - img.setImageResource(R.drawable.ic_msg_btn_cross_custom); - } - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - Utilities.hideKeyboard(searchView); - return true; - } - - @Override - public boolean onQueryTextChange(String s) { - searchDialogs(s); - if (s.length() != 0) { - searchWas = true; - if (messagesListViewAdapter != null) { - messagesListViewAdapter.notifyDataSetChanged(); - } - if (searchEmptyView != null) { - messagesListView.setEmptyView(searchEmptyView); - empryView.setVisibility(View.GONE); - } - } - return true; - } - }); - - searchItem.setSupportOnActionExpandListener(new MenuItemCompat.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem menuItem) { - if (parentActivity != null) { - parentActivity.getSupportActionBar().setIcon(R.drawable.ic_ab_logo); - } - searching = true; - if (messagesListView != null) { - messagesListView.setEmptyView(searchEmptyView); - } - if (empryView != null) { - empryView.setVisibility(View.GONE); - } - return true; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem menuItem) { - searchView.setQuery("", false); - searchDialogs(null); - searching = false; - searchWas = false; - if (messagesListView != null) { - messagesListView.setEmptyView(empryView); - searchEmptyView.setVisibility(View.GONE); - } - if (messagesListViewAdapter != null) { - messagesListViewAdapter.notifyDataSetChanged(); - } - if (onlySelect) { - ((LaunchActivity)parentActivity).fixBackButton(); - } - return true; - } - }); - - super.onCreateOptionsMenu(menu, inflater); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - FragmentActivity inflaterActivity = parentActivity; - if (inflaterActivity == null) { - inflaterActivity = getActivity(); - } - if (inflaterActivity == null) { - return true; - } - switch (itemId) { - - case messages_list_menu_settings: { - ((LaunchActivity)inflaterActivity).presentFragment(new SettingsActivity(), "settings", false); - break; - } - case messages_list_menu_contacts: { - ((LaunchActivity)inflaterActivity).presentFragment(new ContactsActivity(), "contacts", false); - break; - } - case messages_list_menu_new_messages: { - BaseFragment fragment = new ContactsActivity(); - Bundle bundle = new Bundle(); - bundle.putBoolean("onlyUsers", true); - bundle.putBoolean("destroyAfterSelect", true); - bundle.putBoolean("usersAsSections", true); - fragment.animationType = 1; - fragment.setArguments(bundle); - ((LaunchActivity)inflaterActivity).presentFragment(fragment, "contacts_chat", false); - break; - } - case messages_list_menu_new_secret_chat: { - BaseFragment fragment = new ContactsActivity(); - Bundle bundle = new Bundle(); - bundle.putBoolean("onlyUsers", true); - bundle.putBoolean("destroyAfterSelect", true); - bundle.putBoolean("usersAsSections", true); - bundle.putBoolean("createSecretChat", true); - fragment.animationType = 1; - fragment.setArguments(bundle); - ((LaunchActivity)inflaterActivity).presentFragment(fragment, "contacts_chat", false); - break; - } - case messages_list_menu_new_chat: { - ((LaunchActivity)inflaterActivity).presentFragment(new GroupCreateActivity(), "group_create", false); - break; - } - case android.R.id.home: - if (onlySelect) { - finishFragment(); - } - break; - } - return true; - } - private class MessagesAdapter extends BaseAdapter { private Context mContext; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java index 72de0add..c5d6ff9a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java @@ -16,7 +16,6 @@ import android.graphics.Point; import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.ActionBar; import android.util.AttributeSet; import android.view.Display; import android.view.LayoutInflater; @@ -33,7 +32,7 @@ import org.telegram.messenger.FileLog; import org.telegram.messenger.LocaleController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; import java.io.File; @@ -278,14 +277,17 @@ public class PhotoCropActivity extends BaseFragment { private Bitmap imageToCrop; private BitmapDrawable drawable; - public PhotoCropActivityDelegate delegate = null; + private PhotoCropActivityDelegate delegate = null; private PhotoCropView view; private boolean sameBitmap = false; private boolean doneButtonPressed = false; + public PhotoCropActivity(Bundle args) { + super(args); + } + @Override public boolean onFragmentCreate() { - super.onFragmentCreate(); String photoPath = getArguments().getString("photoPath"); Uri photoUri = getArguments().getParcelable("photoUri"); if (photoPath == null && photoUri == null) { @@ -310,6 +312,7 @@ public class PhotoCropActivity extends BaseFragment { return false; } drawable = new BitmapDrawable(imageToCrop); + super.onFragmentCreate(); return true; } @@ -324,14 +327,37 @@ public class PhotoCropActivity extends BaseFragment { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { - fragmentView = view = new PhotoCropView(this.getActivity()); + actionBarLayer.setCustomView(R.layout.settings_do_action_layout); + Button cancelButton = (Button)actionBarLayer.findViewById(R.id.cancel_button); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + finishFragment(); + } + }); + View doneButton = actionBarLayer.findViewById(R.id.done_button); + doneButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (delegate != null && !doneButtonPressed) { + Bitmap bitmap = view.getBitmap(); + if (bitmap == imageToCrop) { + sameBitmap = true; + } + delegate.didFinishCrop(bitmap); + doneButtonPressed = true; + } + finishFragment(); + } + }); + + cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); + TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); + textView.setText(LocaleController.getString("Done", R.string.Done)); + + fragmentView = view = new PhotoCropView(getParentActivity()); fragmentView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); @@ -342,57 +368,7 @@ public class PhotoCropActivity extends BaseFragment { return fragmentView; } - @Override - public boolean canApplyUpdateStatus() { - return false; - } - - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(false); - - actionBar.setCustomView(R.layout.settings_do_action_layout); - Button cancelButton = (Button)actionBar.getCustomView().findViewById(R.id.cancel_button); - cancelButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finishFragment(); - } - }); - View doneButton = actionBar.getCustomView().findViewById(R.id.done_button); - doneButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (delegate != null && !doneButtonPressed) { - Bitmap bitmap = view.getBitmap(); - if (bitmap == imageToCrop) { - sameBitmap = true; - } - delegate.didFinishCrop(bitmap); - doneButtonPressed = true; - } - finishFragment(); - } - }); - - cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); - TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); - textView.setText(LocaleController.getString("Done", R.string.Done)); - } - - @Override - public void onResume() { - super.onResume(); - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).updateActionBar(); + public void setDelegate(PhotoCropActivityDelegate delegate) { + this.delegate = delegate; } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index 97b0beda..38694772 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -19,14 +19,11 @@ import android.content.pm.PackageInfo; import android.graphics.Typeface; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; import android.text.Html; import android.text.Spannable; import android.text.method.LinkMovementMethod; import android.util.Base64; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -55,10 +52,10 @@ import org.telegram.messenger.RPCRequest; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; import org.telegram.objects.PhotoObject; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.AvatarUpdater; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.BaseFragment; import java.io.File; import java.util.ArrayList; @@ -220,26 +217,28 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("Settings", R.string.Settings)); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } + } + }); + fragmentView = inflater.inflate(R.layout.settings_layout, container, false); - listAdapter = new ListAdapter(parentActivity); + 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, final int i, long l) { - if (parentActivity == null) { - return; - } if (i == textSizeRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize)); builder.setItems(new CharSequence[]{String.format("%d", 12), String.format("%d", 13), String.format("%d", 14), String.format("%d", 15), String.format("%d", 16), String.format("%d", 17), String.format("%d", 18), String.format("%d", 19), String.format("%d", 20), String.format("%d", 21), String.format("%d", 22), String.format("%d", 23), String.format("%d", 24)}, new DialogInterface.OnClickListener() { @Override @@ -266,19 +265,19 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter listView.invalidateViews(); } } else if (i == notificationRow) { - ((LaunchActivity)parentActivity).presentFragment(new SettingsNotificationsActivity(), "settings_notifications", false); + presentFragment(new SettingsNotificationsActivity()); } else if (i == blockedRow) { - ((LaunchActivity)parentActivity).presentFragment(new SettingsBlockedUsers(), "settings_blocked", false); + presentFragment(new SettingsBlockedUsers()); } else if (i == backgroundRow) { - ((LaunchActivity)parentActivity).presentFragment(new SettingsWallpapersActivity(), "settings_wallpapers", false); + presentFragment(new SettingsWallpapersActivity()); } else if (i == askQuestionRow) { - final TextView message = new TextView(parentActivity); + final TextView message = new TextView(getParentActivity()); message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo))); message.setTextSize(18); message.setPadding(Utilities.dp(8), Utilities.dp(5), Utilities.dp(8), Utilities.dp(6)); message.setMovementMethod(new LinkMovementMethodMy()); - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setView(message); builder.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), new DialogInterface.OnClickListener() { @Override @@ -302,7 +301,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter listView.invalidateViews(); } } else if (i == terminateSessionsRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @@ -312,18 +311,11 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { - ActionBarActivity inflaterActivity = parentActivity; - if (inflaterActivity == null) { - inflaterActivity = (ActionBarActivity)getActivity(); - } - if (inflaterActivity == null) { - return; - } if (error == null && response instanceof TLRPC.TL_boolTrue) { - Toast toast = Toast.makeText(inflaterActivity, R.string.TerminateAllSessions, Toast.LENGTH_SHORT); + Toast toast = Toast.makeText(getParentActivity(), R.string.TerminateAllSessions, Toast.LENGTH_SHORT); toast.show(); } else { - Toast toast = Toast.makeText(inflaterActivity, R.string.UnknownError, Toast.LENGTH_SHORT); + Toast toast = Toast.makeText(getParentActivity(), R.string.UnknownError, Toast.LENGTH_SHORT); toast.show(); } UserConfig.registeredForPush = false; @@ -335,9 +327,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.show().setCanceledOnTouchOutside(true); } else if (i == languageRow) { - ((LaunchActivity)parentActivity).presentFragment(new LanguageSelectActivity(), "settings_lang", false); + presentFragment(new LanguageSelectActivity()); } else if (i == switchBackendButtonRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @@ -351,14 +343,14 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } else if (i == telegramFaqRow) { try { Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl))); - parentActivity.startActivity(pickIntent); + getParentActivity().startActivity(pickIntent); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == contactsReimportRow) { } else if (i == contactsSortRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy)); builder.setItems(new CharSequence[] { LocaleController.getString("Default", R.string.Default), @@ -379,7 +371,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.show().setCanceledOnTouchOutside(true); } else if (i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems(new CharSequence[] { LocaleController.getString("Enabled", R.string.Enabled), @@ -410,12 +402,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } } }); - - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -449,11 +435,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } } if (supportUser == null) { - if (parentActivity == null) { - return; - } - final ProgressDialog progressDialog = new ProgressDialog(parentActivity); - progressDialog.setMessage(parentActivity.getString(R.string.Loading)); + final ProgressDialog progressDialog = new ProgressDialog(getParentActivity()); + progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.show(); @@ -467,9 +450,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter Utilities.RunOnUIThread(new Runnable() { @Override public void run() { - if (parentActivity == null) { - return; - } SharedPreferences.Editor editor = preferences.edit(); editor.putInt("support_id", res.user.id); SerializedData data = new SerializedData(); @@ -482,11 +462,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter FileLog.e("tmessages", e); } MessagesController.getInstance().users.put(res.user.id, res.user); - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", res.user.id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false); + Bundle args = new Bundle(); + args.putInt("user_id", res.user.id); + presentFragment(new ChatActivity(args)); } }); } else { @@ -505,11 +483,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter }, null, true, RPCRequest.RPCRequestClassGeneric); } else { MessagesController.getInstance().users.putIfAbsent(supportUser.id, supportUser); - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", supportUser.id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false); + Bundle args = new Bundle(); + args.putInt("user_id", supportUser.id); + presentFragment(new ChatActivity(args)); } } @@ -544,32 +520,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setSubtitle(null); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("Settings", R.string.Settings)); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - private void sendLogs() { try { ArrayList uris = new ArrayList(); @@ -588,7 +538,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter i.putExtra(Intent.EXTRA_EMAIL, new String[]{BuildVars.SEND_LOGS_EMAIL}); i.putExtra(Intent.EXTRA_SUBJECT, "last logs"); i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); - startActivity(Intent.createChooser(i, "Select email application.")); + getParentActivity().startActivity(Intent.createChooser(i, "Select email application.")); } catch (Exception e) { e.printStackTrace(); } @@ -596,30 +546,10 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - if (!firstStart && listAdapter != null) { + showActionBar(); + if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } - firstStart = false; - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - } - return true; } private class ListAdapter extends BaseAdapter { @@ -674,7 +604,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ((LaunchActivity)parentActivity).presentFragment(new SettingsChangeNameActivity(), "change_name", false); + presentFragment(new SettingsChangeNameActivity()); } }); @@ -682,11 +612,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (parentActivity == null) { - return; - } - - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; @@ -714,8 +640,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter if (user != null && user.photo != null && user.photo.photo_big != null) { NotificationCenter.getInstance().addToMemCache(56, user.id); NotificationCenter.getInstance().addToMemCache(53, user.photo.photo_big); - Intent intent = new Intent(parentActivity, GalleryImageViewer.class); - startActivity(intent); + Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class); + getParentActivity().startActivity(intent); } } else if (i == 0 && !full || i == 1 && full) { avatarUpdater.openCamera(); @@ -786,6 +712,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter if (user != null) { textView.setText(Utilities.formatName(user.first_name, user.last_name)); BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image); + avatarImage.processDetach = false; TLRPC.FileLocation photo = null; if (user.photo != null) { photo = user.photo.photo_small; @@ -908,7 +835,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java index 8573684f..c21d4e37 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java @@ -12,12 +12,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; -import android.support.v4.internal.view.SupportMenuItem; -import android.support.v7.app.ActionBar; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -36,8 +31,9 @@ import org.telegram.messenger.R; import org.telegram.messenger.RPCRequest; import org.telegram.messenger.Utilities; import org.telegram.ui.Cells.ChatOrUserCell; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; +import org.telegram.ui.Views.ActionBar.BaseFragment; import java.util.ArrayList; import java.util.HashMap; @@ -69,16 +65,33 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers)); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } else if (id == block_user) { + Bundle args = new Bundle(); + args.putBoolean("onlyUsers", true); + args.putBoolean("destroyAfterSelect", true); + args.putBoolean("usersAsSections", true); + args.putBoolean("returnAsResult", true); + ContactsActivity fragment = new ContactsActivity(args); + fragment.setDelegate(SettingsBlockedUsers.this); + presentFragment(fragment); + } + } + }); + + ActionBarMenu menu = actionBarLayer.createMenu(); + menu.addItem(block_user, R.drawable.plus); + fragmentView = inflater.inflate(R.layout.settings_blocked_users_layout, container, false); - listViewAdapter = new ListAdapter(parentActivity); + listViewAdapter = new ListAdapter(getParentActivity()); listView = (ListView)fragmentView.findViewById(R.id.listView); progressView = fragmentView.findViewById(R.id.progressLayout); emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); @@ -96,11 +109,9 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { if (i < blockedContacts.size()) { - UserProfileActivity fragment = new UserProfileActivity(); Bundle args = new Bundle(); args.putInt("user_id", blockedContacts.get(i).user_id); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "user_" + blockedContacts.get(i).user_id, false); + presentFragment(new UserProfileActivity(args)); } } }); @@ -113,7 +124,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe } selectedUserId = blockedContacts.get(i).user_id; - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] {LocaleController.getString("Unblock", R.string.Unblock)}; @@ -145,17 +156,6 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe return true; } }); - - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); - emptyView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -250,76 +250,11 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setSubtitle(null); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers)); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - ((LaunchActivity)parentActivity).fixBackButton(); - } - @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - if (!firstStart && listViewAdapter != null) { + if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } - firstStart = false; - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - SupportMenuItem item = (SupportMenuItem)menu.add(Menu.NONE, block_user, Menu.NONE, null).setIcon(R.drawable.plus); - item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - case block_user: - ContactsActivity fragment = new ContactsActivity(); - fragment.animationType = 1; - Bundle bundle = new Bundle(); - bundle.putBoolean("onlyUsers", true); - bundle.putBoolean("destroyAfterSelect", true); - bundle.putBoolean("usersAsSections", true); - bundle.putBoolean("returnAsResult", true); - fragment.delegate = this; - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "contacts_block", false); - break; - } - return true; } @Override @@ -400,7 +335,6 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe view = li.inflate(R.layout.settings_unblock_info_row_layout, viewGroup, false); TextView textView = (TextView)view.findViewById(R.id.info_text_view); textView.setText(LocaleController.getString("UnblockText", R.string.UnblockText)); - registerForContextMenu(view); } } return view; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java index 785f29bf..fa711f6f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsChangeNameActivity.java @@ -10,14 +10,10 @@ package org.telegram.ui; import android.app.Activity; import android.content.SharedPreferences; -import android.os.Bundle; -import android.support.v7.app.ActionBar; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.EditText; @@ -33,7 +29,7 @@ import org.telegram.messenger.R; import org.telegram.messenger.RPCRequest; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; public class SettingsChangeNameActivity extends BaseFragment { private EditText firstNameField; @@ -41,90 +37,32 @@ public class SettingsChangeNameActivity extends BaseFragment { private View headerLabelView; private View doneButton; - public SettingsChangeNameActivity() { - animationType = 1; - } - @Override - public boolean canApplyUpdateStatus() { - return false; - } - - @Override - public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(false); - actionBar.setSubtitle(null); - - actionBar.setCustomView(R.layout.settings_do_action_layout); - Button cancelButton = (Button)actionBar.getCustomView().findViewById(R.id.cancel_button); - cancelButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finishFragment(); - } - }); - doneButton = actionBar.getCustomView().findViewById(R.id.done_button); - doneButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (firstNameField.getText().length() != 0) { - saveName(); + public View createView(LayoutInflater inflater, ViewGroup container) { + if (fragmentView == null) { + actionBarLayer.setCustomView(R.layout.settings_do_action_layout); + Button cancelButton = (Button)actionBarLayer.findViewById(R.id.cancel_button); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { finishFragment(); } - } - }); - - cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); - TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); - textView.setText(LocaleController.getString("Done", R.string.Done)); - - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - boolean animations = preferences.getBoolean("view_animations", true); - if (!animations) { - firstNameField.requestFocus(); - Utilities.showKeyboard(firstNameField); - } - } - - @Override - public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { - if (nextAnim != 0) { - Animation anim = AnimationUtils.loadAnimation(getActivity(), nextAnim); - - anim.setAnimationListener(new Animation.AnimationListener() { - - public void onAnimationStart(Animation animation) { - SettingsChangeNameActivity.this.onAnimationStart(); - } - - public void onAnimationRepeat(Animation animation) { - - } - - public void onAnimationEnd(Animation animation) { - SettingsChangeNameActivity.this.onAnimationEnd(); - firstNameField.requestFocus(); - Utilities.showKeyboard(firstNameField); + }); + doneButton = actionBarLayer.findViewById(R.id.done_button); + doneButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (firstNameField.getText().length() != 0) { + saveName(); + finishFragment(); + } } }); - return anim; - } else { - return super.onCreateAnimation(transit, enter, nextAnim); - } - } + cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel)); + TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text); + textView.setText(LocaleController.getString("Done", R.string.Done)); - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (fragmentView == null) { fragmentView = inflater.inflate(R.layout.settings_change_name_layout, container, false); TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId); @@ -175,6 +113,16 @@ public class SettingsChangeNameActivity extends BaseFragment { return fragmentView; } + @Override + public void onResume() { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + boolean animations = preferences.getBoolean("view_animations", true); + if (!animations) { + firstNameField.requestFocus(); + Utilities.showKeyboard(firstNameField); + } + } + private void saveName() { TLRPC.TL_account_updateProfile req = new TLRPC.TL_account_updateProfile(); if (UserConfig.currentUser == null || lastNameField.getText() == null || firstNameField.getText() == null) { @@ -196,4 +144,10 @@ public class SettingsChangeNameActivity extends BaseFragment { } }, null, true, RPCRequest.RPCRequestClassGeneric); } + + @Override + public void onOpenAnimationEnd() { + firstNameField.requestFocus(); + Utilities.showKeyboard(firstNameField); + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java index 5e27e898..c6a28668 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java @@ -17,12 +17,8 @@ import android.content.SharedPreferences; import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; -import android.os.Bundle; import android.provider.Settings; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -41,8 +37,8 @@ import org.telegram.messenger.MessagesController; import org.telegram.messenger.R; import org.telegram.messenger.RPCRequest; import org.telegram.messenger.Utilities; -import org.telegram.ui.Views.BaseFragment; -import org.telegram.ui.Views.OnSwipeTouchListener; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.BaseFragment; public class SettingsNotificationsActivity extends BaseFragment { private ListView listView; @@ -99,24 +95,26 @@ public class SettingsNotificationsActivity extends BaseFragment { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + actionBarLayer.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } + } + }); + fragmentView = inflater.inflate(R.layout.settings_layout, container, false); - ListAdapter listAdapter = new ListAdapter(parentActivity); + 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) { - if (parentActivity == null) { - return; - } if (i == messageAlertRow || i == groupAlertRow) { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); @@ -192,7 +190,7 @@ public class SettingsNotificationsActivity extends BaseFragment { } } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); - parentActivity.startActivityForResult(tmpIntent, i); + getParentActivity().startActivityForResult(tmpIntent, i); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -209,20 +207,13 @@ public class SettingsNotificationsActivity extends BaseFragment { @Override public void run() { MessagesController.getInstance().enableJoined = true; - ActionBarActivity inflaterActivity = parentActivity; - if (inflaterActivity == null) { - inflaterActivity = (ActionBarActivity)getActivity(); - } - if (inflaterActivity == null) { - return; - } reseting = false; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); listView.invalidateViews(); - Toast toast = Toast.makeText(inflaterActivity, R.string.ResetNotificationsText, Toast.LENGTH_SHORT); + Toast toast = Toast.makeText(getParentActivity(), R.string.ResetNotificationsText, Toast.LENGTH_SHORT); toast.show(); } }); @@ -274,7 +265,7 @@ public class SettingsNotificationsActivity extends BaseFragment { listView.invalidateViews(); ApplicationLoader.startPushService(); } else { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @@ -293,12 +284,6 @@ public class SettingsNotificationsActivity extends BaseFragment { } } }); - - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -313,13 +298,13 @@ public class SettingsNotificationsActivity extends BaseFragment { if (resultCode == Activity.RESULT_OK) { Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); String name = null; - if (ringtone != null && parentActivity != null) { - Ringtone rng = RingtoneManager.getRingtone(parentActivity, ringtone); + if (ringtone != null) { + Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone); if (rng != null) { if(ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) { name = LocaleController.getString("Default", R.string.Default); } else { - name = rng.getTitle(parentActivity); + name = rng.getTitle(getParentActivity()); } rng.stop(); } @@ -350,61 +335,6 @@ public class SettingsNotificationsActivity extends BaseFragment { } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setSubtitle(null); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - - @Override - public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - } - - @Override - public void onConfigurationChanged(android.content.res.Configuration newConfig) { - super.onConfigurationChanged(newConfig); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - } - return true; - } - private class ListAdapter extends BaseAdapter { private Context mContext; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java index 9c1304f9..2ddaf7df 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java @@ -43,7 +43,7 @@ import org.telegram.messenger.RPCRequest; import org.telegram.messenger.Utilities; import org.telegram.objects.PhotoObject; import org.telegram.ui.Views.BackupImageView; -import org.telegram.ui.Views.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.HorizontalListView; import java.io.File; @@ -94,10 +94,10 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false); - listAdapter = new ListAdapter(parentActivity); + listAdapter = new ListAdapter(getParentActivity()); progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress); backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image); @@ -107,16 +107,13 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { if (i == 0) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)}; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - if (parentActivity == null) { - return; - } if (i == 0) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = Utilities.generatePicturePath(); @@ -124,11 +121,11 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); currentPicturePath = image.getAbsolutePath(); } - parentActivity.startActivityForResult(takePictureIntent, 10); + getParentActivity().startActivityForResult(takePictureIntent, 10); } else if (i == 1) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); - parentActivity.startActivityForResult(photoPickerIntent, 11); + getParentActivity().startActivityForResult(photoPickerIntent, 11); } } }); @@ -404,52 +401,34 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica } private void fixLayout() { - final View view = getView(); - if (view != null) { - ViewTreeObserver obs = view.getViewTreeObserver(); - obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - view.getViewTreeObserver().removeOnPreDrawListener(this); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - if (listView != null) { - listView.post(new Runnable() { - @Override - public void run() { - listView.scrollTo(0); - } - }); - } - return false; + ViewTreeObserver obs = fragmentView.getViewTreeObserver(); + obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + fragmentView.getViewTreeObserver().removeOnPreDrawListener(this); + if (listAdapter != null) { + listAdapter.notifyDataSetChanged(); } - }); - } - } - - @Override - public boolean canApplyUpdateStatus() { - return false; + if (listView != null) { + listView.post(new Runnable() { + @Override + public void run() { + listView.scrollTo(0); + } + }); + } + return false; + } + }); } @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - if (!firstStart && listAdapter != null) { + if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } - - ((LaunchActivity) parentActivity).hideActionBar(); - + hideActionBar(); processSelectedBackground(); - fixLayout(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java index b7c5cc11..64f89137 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java @@ -20,15 +20,9 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.provider.Settings; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.ViewTreeObserver; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageButton; @@ -48,10 +42,12 @@ import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; import org.telegram.messenger.RPCRequest; import org.telegram.messenger.Utilities; +import org.telegram.ui.Views.ActionBar.ActionBarLayer; +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.BaseFragment; +import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.IdenticonView; -import org.telegram.ui.Views.OnSwipeTouchListener; import java.util.ArrayList; @@ -84,21 +80,24 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen private int sharedMediaRow; private int rowCount = 0; + public UserProfileActivity(Bundle args) { + super(args); + } + @Override public boolean onFragmentCreate() { - super.onFragmentCreate(); NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces); NotificationCenter.getInstance().addObserver(this, MessagesController.contactsDidLoaded); NotificationCenter.getInstance().addObserver(this, MessagesController.mediaCountDidLoaded); NotificationCenter.getInstance().addObserver(this, MessagesController.encryptedChatCreated); NotificationCenter.getInstance().addObserver(this, MessagesController.encryptedChatUpdated); - user_id = getArguments().getInt("user_id", 0); - dialog_id = getArguments().getLong("dialog_id", 0); + user_id = arguments.getInt("user_id", 0); + dialog_id = arguments.getLong("dialog_id", 0); if (dialog_id != 0) { currentEncryptedChat = MessagesController.getInstance().encryptedChats.get((int)(dialog_id >> 32)); } updateRowsIds(); - return MessagesController.getInstance().users.get(user_id) != null; + return MessagesController.getInstance().users.get(user_id) != null && super.onFragmentCreate(); } @Override @@ -132,16 +131,78 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setDisplayHomeAsUpEnabled(true); + if (dialog_id != 0) { + actionBarLayer.setTitle(LocaleController.getString("SecretTitle", R.string.SecretTitle)); + actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4)); + } else { + actionBarLayer.setTitle(LocaleController.getString("ContactInfo", R.string.ContactInfo)); + } + actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { + @Override + public void onItemClick(int id) { + if (id == -1) { + finishFragment(); + } else if (id == block_contact) { + TLRPC.User user = MessagesController.getInstance().users.get(user_id); + if (user == null) { + return; + } + TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block(); + req.id = MessagesController.getInputUser(user); + TLRPC.TL_contactBlocked blocked = new TLRPC.TL_contactBlocked(); + blocked.user_id = user_id; + blocked.date = (int)(System.currentTimeMillis() / 1000); + ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { + @Override + public void run(TLObject response, TLRPC.TL_error error) { + + } + }, null, true, RPCRequest.RPCRequestClassGeneric); + } else if (id == add_contact) { + TLRPC.User user = MessagesController.getInstance().users.get(user_id); + Bundle args = new Bundle(); + args.putInt("user_id", user.id); + presentFragment(new ContactAddActivity(args)); + } else if (id == share_contact) { + Bundle args = new Bundle(); + args.putBoolean("onlySelect", true); + args.putBoolean("serverOnly", true); + MessagesActivity fragment = new MessagesActivity(args); + fragment.setDelegate(UserProfileActivity.this); + presentFragment(fragment); + } else if (id == edit_contact) { + Bundle args = new Bundle(); + args.putInt("user_id", user_id); + presentFragment(new ContactAddActivity(args)); + } else if (id == delete_contact) { + final TLRPC.User user = MessagesController.getInstance().users.get(user_id); + if (user == null) { + return; + } + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); + builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); + builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + ArrayList arrayList = new ArrayList(); + arrayList.add(user); + ContactsController.getInstance().deleteContact(arrayList); + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + builder.show().setCanceledOnTouchOutside(true); + } + } + }); + + createActionBarMenu(); + fragmentView = inflater.inflate(R.layout.user_profile_layout, container, false); - listAdapter = new ListAdapter(parentActivity); + listAdapter = new ListAdapter(getParentActivity()); TextView textView = (TextView)fragmentView.findViewById(R.id.start_secret_button_text); textView.setText(LocaleController.getString("StartEncryptedChat", R.string.StartEncryptedChat)); @@ -151,7 +212,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen @Override public void onClick(View view) { creatingChat = true; - MessagesController.getInstance().startSecretChat(parentActivity, MessagesController.getInstance().users.get(user_id)); + MessagesController.getInstance().startSecretChat(getParentActivity(), MessagesController.getInstance().users.get(user_id)); } }); if (dialog_id == 0) { @@ -165,11 +226,8 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, final int i, long l) { - if (parentActivity == null) { - return; - } if (i == settingsVibrateRow || i == settingsNotificationsRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems(new CharSequence[] { LocaleController.getString("Default", R.string.Default), @@ -207,7 +265,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); - SharedPreferences preferences = parentActivity.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Uri currentSound = null; String defaultPath = null; @@ -226,28 +284,24 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); - parentActivity.startActivityForResult(tmpIntent, 12); + getParentActivity().startActivityForResult(tmpIntent, 12); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == sharedMediaRow) { - MediaActivity fragment = new MediaActivity(); - Bundle bundle = new Bundle(); + Bundle args = new Bundle(); if (dialog_id != 0) { - bundle.putLong("dialog_id", dialog_id); + args.putLong("dialog_id", dialog_id); } else { - bundle.putLong("dialog_id", user_id); + args.putLong("dialog_id", user_id); } - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "media_user_" + user_id, false); + presentFragment(new MediaActivity(args)); } else if (i == settingsKeyRow) { - IdenticonActivity fragment = new IdenticonActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("chat_id", (int)(dialog_id >> 32)); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "key_" + dialog_id, false); + Bundle args = new Bundle(); + args.putInt("chat_id", (int)(dialog_id >> 32)); + presentFragment(new IdenticonActivity(args)); } else if (i == settingsTimerRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); builder.setItems(new CharSequence[]{ LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever), @@ -296,12 +350,6 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } else { MessagesController.getInstance().getMediaCount(user_id, classGuid, true); } - - listView.setOnTouchListener(new OnSwipeTouchListener() { - public void onSwipeRight() { - finishFragment(true); - } - }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -325,7 +373,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen if(ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) { name = LocaleController.getString("Default", R.string.Default); } else { - name = rng.getTitle(parentActivity); + name = rng.getTitle(getParentActivity()); } rng.stop(); } @@ -357,9 +405,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } } } else if (id == MessagesController.contactsDidLoaded) { - if (parentActivity != null) { - parentActivity.supportInvalidateOptionsMenu(); - } + createActionBarMenu(); } else if (id == MessagesController.mediaCountDidLoaded) { long uid = (Long)args[0]; if (uid > 0 && user_id == uid && dialog_id == 0 || dialog_id != 0 && dialog_id == uid) { @@ -372,11 +418,9 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen if (creatingChat) { NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat)args[0]; - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("enc_id", encryptedChat.id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), true, false); + Bundle args2 = new Bundle(); + args2.putInt("enc_id", encryptedChat.id); + presentFragment(new ChatActivity(args2), true); } } else if (id == MessagesController.encryptedChatUpdated) { TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)args[0]; @@ -390,220 +434,57 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } } - @Override - public void applySelfActionBar() { - if (parentActivity == null) { - return; - } - ActionBar actionBar = parentActivity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setSubtitle(null); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayUseLogoEnabled(false); - actionBar.setDisplayShowCustomEnabled(false); - actionBar.setCustomView(null); - if (dialog_id != 0) { - actionBar.setTitle(LocaleController.getString("SecretTitle", R.string.SecretTitle)); - } else { - actionBar.setTitle(LocaleController.getString("ContactInfo", R.string.ContactInfo)); - } - - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - if (dialog_id != 0) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); - title.setCompoundDrawablePadding(Utilities.dp(4)); - } else { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - title.setCompoundDrawablePadding(0); - } - } - } - @Override public void onResume() { - super.onResume(); - if (isFinish) { - return; - } - if (getActivity() == null) { - return; - } - if (!firstStart && listAdapter != null) { + if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } - firstStart = false; - ((LaunchActivity)parentActivity).showActionBar(); - ((LaunchActivity)parentActivity).updateActionBar(); - fixLayout(); } - @Override - public void onConfigurationChanged(android.content.res.Configuration newConfig) { - super.onConfigurationChanged(newConfig); - fixLayout(); - } + private void createActionBarMenu() { + ActionBarMenu menu = actionBarLayer.createMenu(); + menu.clearItems(); - private void fixLayout() { - if (listView != null) { - ViewTreeObserver obs = listView.getViewTreeObserver(); - obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - listView.getViewTreeObserver().removeOnPreDrawListener(this); - if (dialog_id != 0) { - TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title); - if (title == null) { - final int subtitleId = ApplicationLoader.applicationContext.getResources().getIdentifier("action_bar_title", "id", "android"); - title = (TextView)parentActivity.findViewById(subtitleId); - } - if (title != null) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); - title.setCompoundDrawablePadding(Utilities.dp(4)); - } - } - return false; - } - }); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: - finishFragment(); - break; - case block_contact: { - TLRPC.User user = MessagesController.getInstance().users.get(user_id); - if (user == null) { - break; - } - TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block(); - req.id = MessagesController.getInputUser(user); - TLRPC.TL_contactBlocked blocked = new TLRPC.TL_contactBlocked(); - blocked.user_id = user_id; - blocked.date = (int)(System.currentTimeMillis() / 1000); - ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - - } - }, null, true, RPCRequest.RPCRequestClassGeneric); - break; - } - case add_contact: { - TLRPC.User user = MessagesController.getInstance().users.get(user_id); - ContactAddActivity fragment = new ContactAddActivity(); - Bundle args = new Bundle(); - args.putInt("user_id", user.id); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "add_contact_" + user.id, false); - break; - } - case share_contact: { - MessagesActivity fragment = new MessagesActivity(); - Bundle args = new Bundle(); - args.putBoolean("onlySelect", true); - args.putBoolean("serverOnly", true); - fragment.setArguments(args); - fragment.delegate = this; - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat_select", false); - break; - } - case edit_contact: { - ContactAddActivity fragment = new ContactAddActivity(); - Bundle args = new Bundle(); - args.putInt("user_id", user_id); - fragment.setArguments(args); - ((LaunchActivity)parentActivity).presentFragment(fragment, "add_contact_" + user_id, false); - break; - } - case delete_contact: { - final TLRPC.User user = MessagesController.getInstance().users.get(user_id); - if (user == null) { - break; - } - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); - builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); - builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - ArrayList arrayList = new ArrayList(); - arrayList.add(user); - ContactsController.getInstance().deleteContact(arrayList); - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - builder.show().setCanceledOnTouchOutside(true); - break; - } - } - return true; - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (ContactsController.getInstance().contactsDict.get(user_id) == null) { TLRPC.User user = MessagesController.getInstance().users.get(user_id); if (user == null) { return; } + ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); if (user.phone != null && user.phone.length() != 0) { - menu.add(Menu.NONE, add_contact, Menu.NONE, LocaleController.getString("AddContact", R.string.AddContact)); - menu.add(Menu.NONE, block_contact, Menu.NONE, LocaleController.getString("BlockContact", R.string.BlockContact)); + item.addSubItem(add_contact, LocaleController.getString("AddContact", R.string.AddContact), 0); + item.addSubItem(block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0); } else { - menu.add(Menu.NONE, block_contact, Menu.NONE, LocaleController.getString("BlockContact", R.string.BlockContact)); + item.addSubItem(block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0); } } else { - menu.add(Menu.NONE, share_contact, Menu.NONE, LocaleController.getString("ShareContact", R.string.ShareContact)); - menu.add(Menu.NONE, block_contact, Menu.NONE, LocaleController.getString("BlockContact", R.string.BlockContact)); - menu.add(Menu.NONE, edit_contact, Menu.NONE, LocaleController.getString("EditContact", R.string.EditContact)); - menu.add(Menu.NONE, delete_contact, Menu.NONE, LocaleController.getString("DeleteContact", R.string.DeleteContact)); + ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); + item.addSubItem(share_contact, LocaleController.getString("ShareContact", R.string.ShareContact), 0); + item.addSubItem(block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0); + item.addSubItem(edit_contact, LocaleController.getString("EditContact", R.string.EditContact), 0); + item.addSubItem(delete_contact, LocaleController.getString("DeleteContact", R.string.DeleteContact), 0); } } @Override public void didSelectDialog(MessagesActivity messageFragment, long dialog_id) { if (dialog_id != 0) { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); + Bundle args = new Bundle(); + args.putBoolean("scrollToTopOnResume", true); + NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); int lower_part = (int)dialog_id; if (lower_part != 0) { if (lower_part > 0) { - NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - bundle.putInt("user_id", lower_part); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), true, false); - removeSelfFromStack(); - messageFragment.removeSelfFromStack(); + args.putInt("user_id", lower_part); } else if (lower_part < 0) { - NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - bundle.putInt("chat_id", -lower_part); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), true, false); - messageFragment.removeSelfFromStack(); - removeSelfFromStack(); + args.putInt("chat_id", -lower_part); } } else { - NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - int id = (int)(dialog_id >> 32); - bundle.putInt("enc_id", id); - fragment.setArguments(bundle); - fragment.scrollToTopOnResume = true; - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false); - messageFragment.removeSelfFromStack(); - removeSelfFromStack(); + args.putInt("enc_id", (int)(dialog_id >> 32)); } + presentFragment(new ChatActivity(args), true); + messageFragment.removeSelfFromStack(); + removeSelfFromStack(); TLRPC.User user = MessagesController.getInstance().users.get(user_id); MessagesController.getInstance().sendMessage(user, dialog_id); } @@ -659,6 +540,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen onlineText = (TextView)view.findViewById(R.id.settings_online); avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image); + avatarImage.processDetach = false; avatarImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -666,8 +548,8 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen if (user.photo != null && user.photo.photo_big != null) { NotificationCenter.getInstance().addToMemCache(56, user_id); NotificationCenter.getInstance().addToMemCache(53, user.photo.photo_big); - Intent intent = new Intent(parentActivity, GalleryImageViewer.class); - startActivity(intent); + Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class); + getParentActivity().startActivity(intent); } } }); @@ -714,7 +596,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } selectedPhone = user.phone; - AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() { @Override @@ -723,24 +605,17 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen try { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + selectedPhone)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == 0) { - ActionBarActivity inflaterActivity = parentActivity; - if (inflaterActivity == null) { - inflaterActivity = (ActionBarActivity)getActivity(); - } - if (inflaterActivity == null) { - return; - } int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager)inflaterActivity.getSystemService(Context.CLIPBOARD_SERVICE); + android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(selectedPhone); } else { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager)inflaterActivity.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedPhone); clipboard.setPrimaryClip(clip); } @@ -755,19 +630,14 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (parentActivity == null) { - return; - } TLRPC.User user = MessagesController.getInstance().users.get(user_id); if (user == null || user instanceof TLRPC.TL_userEmpty) { return; } NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", user_id); - fragment.setArguments(bundle); - ((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), true, false); + Bundle args = new Bundle(); + args.putInt("user_id", user_id); + presentFragment(new ChatActivity(args), true); } }); TextView textView = (TextView)view.findViewById(R.id.settings_row_text); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java new file mode 100644 index 00000000..3cdcdb64 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBar.java @@ -0,0 +1,208 @@ +/* + * 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. + */ + +package org.telegram.ui.Views.ActionBar; + +import android.animation.Animator; +import android.animation.ObjectAnimator; +import android.content.Context; +import android.content.res.Configuration; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import org.telegram.messenger.R; +import org.telegram.messenger.Utilities; + +import java.util.ArrayList; + +public class ActionBar extends FrameLayout { + + private static Drawable logoDrawable; + protected ActionBarLayer currentLayer = null; + private ActionBarLayer previousLayer = null; + private View currentBackOverlay; + private View shadowView = null; + private int currentBackOverlayWidth; + + public ActionBar(Context context) { + super(context); + createComponents(); + } + + public ActionBar(Context context, AttributeSet attrs) { + super(context, attrs); + createComponents(); + } + + public ActionBar(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + createComponents(); + } + + public void createComponents() { + shadowView = new View(getContext()); + addView(shadowView); + shadowView.setVisibility(INVISIBLE); + ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams(); + layoutParams.width = Utilities.dp(2); + layoutParams.height = LayoutParams.MATCH_PARENT; + shadowView.setLayoutParams(layoutParams); + shadowView.setBackgroundResource(R.drawable.shadow); + } + + public ActionBarLayer createLayer() { + return new ActionBarLayer(getContext(), this); + } + + public void detachActionBarLayer(ActionBarLayer layer) { + if (layer == null) { + return; + } + removeView(layer); + if (currentLayer == layer) { + currentLayer = null; + } + } + + public void setCurrentActionBarLayer(ActionBarLayer layer) { + if (layer == null || layer.getParent() != null) { + return; + } + if (currentLayer != null) { + removeView(currentLayer); + } + currentLayer = layer; + addView(layer); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)layer.getLayoutParams(); + layoutParams.width = LayoutParams.MATCH_PARENT; + layoutParams.height = LayoutParams.MATCH_PARENT; + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + layer.setLayoutParams(layoutParams); + updateBackOverlay(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY)); + if(android.os.Build.VERSION.SDK_INT >= 11) { + layer.setAlpha(1); + } + } + + public void setBackOverlay(View view, int width) { + if (currentBackOverlay != null) { + removeView(currentBackOverlay); + } + if (view != null) { + addView(view); + } + currentBackOverlayWidth = width; + currentBackOverlay = view; + updateBackOverlay(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY)); + } + + private void updateBackOverlay(int widthMeasureSpec, int heightMeasureSpec) { + if (currentLayer != null) { + currentLayer.setBackLayoutVisible(currentBackOverlay == null ? VISIBLE : INVISIBLE); + } + if (currentBackOverlay != null) { + ViewGroup.LayoutParams layoutParams = currentBackOverlay.getLayoutParams(); + if (currentLayer != null) { + currentLayer.measure(widthMeasureSpec, heightMeasureSpec); + layoutParams.width = Math.min(currentBackOverlayWidth, currentLayer.getBackLayoutWidth()); + } else { + layoutParams.width = LayoutParams.WRAP_CONTENT; + } + if (layoutParams.width != 0) { + layoutParams.height = LayoutParams.MATCH_PARENT; + currentBackOverlay.setLayoutParams(layoutParams); + } + } + } + + public void prepareForMoving(ActionBarLayer layer) { + if (currentLayer == null || layer == null) { + return; + } + previousLayer = layer; + ViewGroup parent = (ViewGroup) previousLayer.getParent(); + if (parent != null) { + parent.removeView(previousLayer); + } + this.addView(previousLayer, 0); + ViewGroup.LayoutParams layoutParams = layer.getLayoutParams(); + layoutParams.width = LayoutParams.MATCH_PARENT; + layoutParams.height = LayoutParams.MATCH_PARENT; + layer.setLayoutParams(layoutParams); + currentLayer.setBackgroundDrawable(getBackground()); + shadowView.setX(-Utilities.dp(2)); + shadowView.setVisibility(VISIBLE); + } + + public void stopMoving(boolean backAnimation) { + if (currentLayer == null) { + return; + } + currentLayer.setBackgroundDrawable(null); + currentLayer.setX(0); + if (!backAnimation) { + removeView(currentLayer); + currentLayer = previousLayer; + currentLayer.setAlpha(1); + } else { + removeView(previousLayer); + previousLayer = null; + } + shadowView.setVisibility(INVISIBLE); + } + + public void moveActionBarByX(int dx) { + if (currentLayer == null) { + return; + } + currentLayer.setX(dx); + shadowView.setX(dx - Utilities.dp(2)); + if (dx != 0) { + if (previousLayer != null) { + previousLayer.setAlpha(Math.min(1, (float) dx / (float) currentLayer.getMeasuredWidth())); + } + } else { + if (previousLayer != null) { + previousLayer.setAlpha(0); + } + currentLayer.setAlpha(1); + } + } + + public void setupAnimations(ArrayList animators, boolean back) { + if (back) { + animators.add(ObjectAnimator.ofFloat(currentLayer, "x", 0)); + animators.add(ObjectAnimator.ofFloat(shadowView, "x", -Utilities.dp(2))); + animators.add(ObjectAnimator.ofFloat(previousLayer, "alpha", 0)); + } else { + animators.add(ObjectAnimator.ofFloat(currentLayer, "x", getMeasuredWidth())); + animators.add(ObjectAnimator.ofFloat(shadowView, "x", getMeasuredWidth() - Utilities.dp(2))); + animators.add(ObjectAnimator.ofFloat(previousLayer, "alpha", 1.0f)); + } + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + updateBackOverlay(widthMeasureSpec, heightMeasureSpec); + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Utilities.dp(40), MeasureSpec.EXACTLY)); + } else { + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Utilities.dp(48), MeasureSpec.EXACTLY)); + } + } + + public void onMenuButtonPressed() { + if (currentLayer != null) { + currentLayer.onMenuButtonPressed(); + } + } +} 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 new file mode 100644 index 00000000..952f5955 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java @@ -0,0 +1,623 @@ +/* + * 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. + */ + +package org.telegram.ui.Views.ActionBar; + +import android.animation.Animator; +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.app.Activity; +import android.content.pm.ActivityInfo; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; +import android.view.ActionMode; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.Surface; +import android.view.VelocityTracker; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.WindowManager; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +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; + +public class ActionBarActivity extends Activity { + + protected ActionBar actionBar; + private FrameLayout containerView; + private FrameLayout containerViewBack; + private FrameLayout contentView; + private View shadowView; + + private Animation openAnimation; + private Animation closeAnimation; + + private boolean startedTracking = false; + private int startedTrackingX; + private int prevOrientation = -10; + private boolean animationInProgress = false; + private VelocityTracker velocityTracker = null; + private boolean beginTrackingSent = false; + private boolean transitionAnimationInProgress = false; + private long transitionAnimationStartTime; + private boolean inActionMode = false; + + public static ArrayList fragmentsStack = new ArrayList(); + + protected void onCreateFinish(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + try { + openAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_in); + closeAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_out); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + + setTheme(R.style.Theme_TMessages); + getWindow().setBackgroundDrawableResource(R.drawable.transparent); + + contentView = new FrameLayout(this); + setContentView(contentView, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); + + containerViewBack = new FrameLayout(this); + contentView.addView(containerViewBack); + + containerView = new FrameLayout(this); + contentView.addView(containerView); + + shadowView = new FrameLayout(this); + contentView.addView(shadowView); + shadowView.setBackgroundResource(R.drawable.shadow); + ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams(); + layoutParams.width = Utilities.dp(2); + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + shadowView.setLayoutParams(layoutParams); + shadowView.setVisibility(View.INVISIBLE); + + actionBar = new ActionBar(this); + actionBar.setBackgroundResource(R.color.header); + contentView.addView(actionBar); + layoutParams = actionBar.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + actionBar.setLayoutParams(layoutParams); + + for (BaseFragment fragment : fragmentsStack) { + fragment.setParentActivity(this); + } + + needLayout(); + } + + @Override + public void onConfigurationChanged(android.content.res.Configuration newConfig) { + super.onConfigurationChanged(newConfig); + fixLayout(); + if (!fragmentsStack.isEmpty()) { + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1); + lastFragment.onConfigurationChanged(newConfig); + } + } + + @Override + protected void onResume() { + super.onResume(); + fixLayout(); + if (!fragmentsStack.isEmpty()) { + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1); + lastFragment.onResume(); + + actionBar.setCurrentActionBarLayer(lastFragment.actionBarLayer); + onShowFragment(); + } + } + + @Override + protected void onPause() { + super.onPause(); + if (!fragmentsStack.isEmpty()) { + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1); + lastFragment.onPause(); + } + } + + private void onSlideAnimationEnd(boolean backAnimation) { + containerView.setX(0); + containerViewBack.setX(0); + actionBar.stopMoving(backAnimation); + shadowView.setVisibility(View.INVISIBLE); + shadowView.setX(-Utilities.dp(2)); + if (!backAnimation) { + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1); + lastFragment.onPause(); + lastFragment.onFragmentDestroy(); + lastFragment.setParentActivity(null); + fragmentsStack.remove(fragmentsStack.size() - 1); + + FrameLayout temp = containerView; + containerView = containerViewBack; + containerViewBack = temp; + ViewGroup parent = (ViewGroup)containerView.getParent(); + parent.removeView(containerView); + parent.addView(containerView, 1); + lastFragment = fragmentsStack.get(fragmentsStack.size() - 1); + lastFragment.onResume(); + } else { + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2); + lastFragment.onPause(); + if (lastFragment.fragmentView != null) { + ViewGroup parent = (ViewGroup) lastFragment.fragmentView.getParent(); + if (parent != null) { + parent.removeView(lastFragment.fragmentView); + } + } + } + containerViewBack.setVisibility(View.GONE); + try { + if (prevOrientation != -10) { + setRequestedOrientation(prevOrientation); + prevOrientation = -10; + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + startedTracking = false; + animationInProgress = false; + } + + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + if(android.os.Build.VERSION.SDK_INT >= 11 && !checkTransitionAnimation() && !inActionMode) { + if (ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && ev.getX() <= Utilities.dp(6) && fragmentsStack.size() > 1) { + startedTracking = true; + startedTrackingX = (int) ev.getX(); + shadowView.setVisibility(View.VISIBLE); + shadowView.setX(-Utilities.dp(2)); + containerViewBack.setVisibility(View.VISIBLE); + beginTrackingSent = false; + + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2); + actionBar.prepareForMoving(lastFragment.actionBarLayer); + View fragmentView = lastFragment.createView(getLayoutInflater(), null); + ViewGroup parentView = (ViewGroup)fragmentView.getParent(); + if (parentView != null) { + parentView.removeView(fragmentView); + } + containerViewBack.addView(fragmentView); + ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + fragmentView.setLayoutParams(layoutParams); + if (fragmentView.getBackground() == null) { + fragmentView.setBackgroundColor(0xffffffff); + } + lastFragment.onResume(); + + try { + prevOrientation = getRequestedOrientation(); + WindowManager manager = (WindowManager)getSystemService(Activity.WINDOW_SERVICE); + if (manager != null && manager.getDefaultDisplay() != null) { + int rotation = manager.getDefaultDisplay().getRotation(); + if (rotation == Surface.ROTATION_270) { + if (Build.VERSION.SDK_INT >= 9) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + } else if (rotation == Surface.ROTATION_90) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } else if (rotation == Surface.ROTATION_0) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + if (Build.VERSION.SDK_INT >= 9) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); + } + } + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + if (velocityTracker == null) { + velocityTracker = VelocityTracker.obtain(); + } else { + velocityTracker.clear(); + } + } else if (startedTracking && !animationInProgress) { + if (ev.getAction() == MotionEvent.ACTION_MOVE) { + if (!beginTrackingSent) { + if (getCurrentFocus() != null) { + Utilities.hideKeyboard(getCurrentFocus()); + } + BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1); + currentFragment.onBeginSlide(); + beginTrackingSent = true; + } + velocityTracker.addMovement(ev); + int dx = Math.max(0, (int) (ev.getX() - startedTrackingX)); + actionBar.moveActionBarByX(dx); + containerView.setX(dx); + shadowView.setX(dx - Utilities.dp(2)); + } else if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { + velocityTracker.computeCurrentVelocity(1000); + float x = containerView.getX(); + ArrayList animators = new ArrayList(); + final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && velocityTracker.getXVelocity() < 6000; + float distToMove = 0; + if (!backAnimation) { + distToMove = containerView.getMeasuredWidth() - x; + animators.add(ObjectAnimator.ofFloat(containerView, "x", containerView.getMeasuredWidth())); + animators.add(ObjectAnimator.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - Utilities.dp(2))); + } else { + distToMove = x; + animators.add(ObjectAnimator.ofFloat(containerView, "x", 0)); + animators.add(ObjectAnimator.ofFloat(shadowView, "x", -Utilities.dp(2))); + } + actionBar.setupAnimations(animators, backAnimation); + + AnimatorSet animatorSet = new AnimatorSet(); + animatorSet.playTogether(animators); + animatorSet.setDuration((int)(200.0f / containerView.getMeasuredWidth() * distToMove)); + animatorSet.start(); + animationInProgress = true; + animatorSet.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animator) { + + } + + @Override + public void onAnimationEnd(Animator animator) { + onSlideAnimationEnd(backAnimation); + } + + @Override + public void onAnimationCancel(Animator animator) { + onSlideAnimationEnd(backAnimation); + } + + @Override + public void onAnimationRepeat(Animator animator) { + + } + }); + velocityTracker.recycle(); + velocityTracker = null; + } + } + return startedTracking || super.dispatchTouchEvent(ev); + } + return super.dispatchTouchEvent(ev); + } + + @Override + public void onBackPressed() { + if (startedTracking || checkTransitionAnimation()) { + return; + } + if (actionBar.currentLayer != null && actionBar.currentLayer.isSearchFieldVisible) { + actionBar.currentLayer.closeSearchField(); + return; + } + BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1); + if (lastFragment.onBackPressed()) { + if (fragmentsStack.size() == 1) { + fragmentsStack.get(0).onFragmentDestroy(); + fragmentsStack.clear(); + onFinish(); + finish(); + } else if (!fragmentsStack.isEmpty()) { + closeLastFragment(); + } + } + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + for (BaseFragment fragment : fragmentsStack) { + fragment.onLowMemory(); + } + } + + public boolean checkTransitionAnimation() { + if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 400) { + transitionAnimationInProgress = false; + } + return transitionAnimationInProgress; + } + + private void fixLayout() { + if (contentView != null) { + ViewTreeObserver obs = contentView.getViewTreeObserver(); + obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + needLayout(); + + if (Build.VERSION.SDK_INT < 16) { + contentView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } else { + contentView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + } + }); + } + } + + public void needLayout() { + WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); + int rotation = manager.getDefaultDisplay().getRotation(); + + int height = 0; + if (actionBar.getVisibility() == View.VISIBLE) { + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + height = Utilities.dp(40); + } else { + height = Utilities.dp(48); + } + } + + if (containerView != null) { + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) containerView.getLayoutParams(); + if (layoutParams.topMargin != height) { + layoutParams.setMargins(0, height, 0, 0); + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + containerView.setLayoutParams(layoutParams); + } + } + if (containerViewBack != null) { + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) containerViewBack.getLayoutParams(); + if (layoutParams.topMargin != height) { + layoutParams.setMargins(0, height, 0, 0); + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + containerViewBack.setLayoutParams(layoutParams); + } + } + } + + public ActionBar getInternalActionBar() { + return actionBar; + } + + private void presentFragmentInternalRemoveOld(boolean removeLast, BaseFragment fragment) { + if (fragment == null) { + return; + } + fragment.onPause(); + if (removeLast) { + fragment.onFragmentDestroy(); + fragment.setParentActivity(null); + fragmentsStack.remove(fragment); + } else { + if (fragment.fragmentView != null) { + ViewGroup parent = (ViewGroup) fragment.fragmentView.getParent(); + if (parent != null) { + parent.removeView(fragment.fragmentView); + } + } + } + } + + public boolean presentFragment(BaseFragment fragment) { + return presentFragment(fragment, false, false); + } + + public boolean presentFragment(BaseFragment fragment, boolean removeLast) { + return presentFragment(fragment, removeLast, false); + } + + public boolean presentFragment(final BaseFragment fragment, final boolean removeLast, boolean forceWithoutAnimation) { + if (!fragment.onFragmentCreate() || checkTransitionAnimation()) { + return false; + } + if (getCurrentFocus() != null) { + Utilities.hideKeyboard(getCurrentFocus()); + } + boolean needAnimation = openAnimation != null && !forceWithoutAnimation && getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true); + + final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null; + if (!needAnimation) { + presentFragmentInternalRemoveOld(removeLast, currentFragment); + } + + fragment.setParentActivity(this); + View fragmentView = fragment.createView(getLayoutInflater(), null); + containerView.addView(fragmentView); + ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + fragmentView.setLayoutParams(layoutParams); + fragmentsStack.add(fragment); + fragment.onResume(); + actionBar.setCurrentActionBarLayer(fragment.actionBarLayer); + if (fragmentView.getBackground() == null) { + fragmentView.setBackgroundColor(0xffffffff); + } + onShowFragment(); + if (needAnimation) { + transitionAnimationStartTime = System.currentTimeMillis(); + transitionAnimationInProgress = true; + openAnimation.reset(); + openAnimation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + transitionAnimationInProgress = false; + transitionAnimationStartTime = 0; + fragment.onOpenAnimationEnd(); + presentFragmentInternalRemoveOld(removeLast, currentFragment); + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + fragmentView.startAnimation(openAnimation); + } else { + fragment.onOpenAnimationEnd(); + } + return true; + } + + private void closeLastFragmentInternalRemoveOld(BaseFragment fragment) { + fragment.onPause(); + fragment.onFragmentDestroy(); + fragment.setParentActivity(null); + fragmentsStack.remove(fragment); + } + + public void closeLastFragment() { + if (fragmentsStack.size() <= 1 || checkTransitionAnimation()) { + return; + } + if (getCurrentFocus() != null) { + Utilities.hideKeyboard(getCurrentFocus()); + } + boolean needAnimation = openAnimation != null && getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true); + final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1); + BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 2); + if (!needAnimation) { + closeLastFragmentInternalRemoveOld(currentFragment); + } + + previousFragment.setParentActivity(this); + View fragmentView = previousFragment.createView(getLayoutInflater(), null); + containerView.addView(fragmentView, 0); + ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + fragmentView.setLayoutParams(layoutParams); + previousFragment.onResume(); + actionBar.setCurrentActionBarLayer(previousFragment.actionBarLayer); + if (fragmentView.getBackground() == null) { + fragmentView.setBackgroundColor(0xffffffff); + } + onShowFragment(); + if (needAnimation) { + transitionAnimationStartTime = System.currentTimeMillis(); + transitionAnimationInProgress = true; + closeAnimation.reset(); + closeAnimation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + transitionAnimationInProgress = false; + transitionAnimationStartTime = 0; + closeLastFragmentInternalRemoveOld(currentFragment); + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + currentFragment.fragmentView.startAnimation(closeAnimation); + } + } + + public void showLastFragment() { + BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1); + previousFragment.setParentActivity(this); + View fragmentView = previousFragment.createView(getLayoutInflater(), null); + containerView.addView(fragmentView); + ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + fragmentView.setLayoutParams(layoutParams); + previousFragment.onResume(); + actionBar.setCurrentActionBarLayer(previousFragment.actionBarLayer); + if (fragmentView.getBackground() == null) { + fragmentView.setBackgroundColor(0xffffffff); + } + onShowFragment(); + } + + public void removeFragmentFromStack(BaseFragment fragment) { +// if (!fragmentsStack.isEmpty() && fragmentsStack.get(fragmentsStack.size() - 1) == fragment) { +// return; +// } + fragment.onFragmentDestroy(); + fragment.setParentActivity(null); + fragmentsStack.remove(fragment); + } + + public void rebuildAllFragmentViews() { + for (int a = 0; a < fragmentsStack.size() - 1; a++) { + fragmentsStack.get(a).setParentActivity(null); + fragmentsStack.get(a).setParentActivity(this); + } + } + + protected void onFinish() { + + } + + protected void onShowFragment() { + + } + + public void showActionBar() { + actionBar.setVisibility(View.VISIBLE); + needLayout(); + } + + public void hideActionBar() { + actionBar.setVisibility(View.GONE); + needLayout(); + } + + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_MENU && !checkTransitionAnimation() && !startedTracking) { + actionBar.onMenuButtonPressed(); + return true; + } + return super.onKeyUp(keyCode, event); + } + + @Override + public void onActionModeStarted(ActionMode mode) { + super.onActionModeStarted(mode); + hideActionBar(); + inActionMode = true; + } + + @Override + public void onActionModeFinished(ActionMode mode) { + super.onActionModeFinished(mode); + showActionBar(); + inActionMode = false; + } +} 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 new file mode 100644 index 00000000..a2dcb81d --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java @@ -0,0 +1,433 @@ +/* + * 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. + */ + +package org.telegram.ui.Views.ActionBar; + +import android.content.Context; +import android.content.res.Configuration; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +import org.telegram.messenger.R; +import org.telegram.messenger.Utilities; + +public class ActionBarLayer extends FrameLayout { + + public interface ActionBarMenuOnItemClick { + public abstract void onItemClick(int id); + } + + private FrameLayout backButtonFrameLayout; + private ImageView logoImageView; + private ImageView backButtonImageView; + private TextView titleTextView; + private TextView subTitleTextView; + private ActionBarMenu menu; + private ActionBarMenu actionMode; + private ActionBar parentActionBar; + private boolean oldUseLogo; + private boolean oldUseBack; + protected boolean isSearchFieldVisible; + public ActionBarMenuOnItemClick actionBarMenuOnItemClick; + + public ActionBarLayer(Context context, ActionBar actionBar) { + super(context); + parentActionBar = actionBar; + backButtonFrameLayout = new FrameLayout(context); + addView(backButtonFrameLayout); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)backButtonFrameLayout.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.FILL_PARENT; + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + backButtonFrameLayout.setBackgroundResource(R.drawable.bar_selector); + backButtonFrameLayout.setLayoutParams(layoutParams); + backButtonFrameLayout.setPadding(0, 0, Utilities.dp(4), 0); + backButtonFrameLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + if (isSearchFieldVisible) { + closeSearchField(); + return; + } + if (actionBarMenuOnItemClick != null) { + actionBarMenuOnItemClick.onItemClick(-1); + } + } + }); + backButtonFrameLayout.setEnabled(false); + } + + public ActionBarLayer(Context context) { + super(context); + } + + public ActionBarLayer(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ActionBarLayer(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + private void positionBackImage(int height) { + if (backButtonImageView != null) { + LayoutParams layoutParams = (LayoutParams)backButtonImageView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + layoutParams.setMargins(Utilities.dp(3), (height - backButtonImageView.getDrawable().getIntrinsicHeight()) / 2, 0, 0); + backButtonImageView.setLayoutParams(layoutParams); + } + } + + private void positionLogoImage(int height) { + if (logoImageView != null) { + LayoutParams layoutParams = (LayoutParams) logoImageView.getLayoutParams(); + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + layoutParams.width = (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f); + layoutParams.height = (int)(logoImageView.getDrawable().getIntrinsicHeight() / 1.3f); + layoutParams.setMargins(Utilities.dp(12), (height - layoutParams.height) / 2, 0, 0); + } else { + layoutParams.width = logoImageView.getDrawable().getIntrinsicWidth(); + layoutParams.height = logoImageView.getDrawable().getIntrinsicHeight(); + layoutParams.setMargins(Utilities.dp(12), (height - layoutParams.width) / 2, 0, 0); + } + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + logoImageView.setLayoutParams(layoutParams); + } + } + + private void positionTitle(int width, int height) { + int offset = Utilities.dp(2); + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + offset = Utilities.dp(1); + } + int maxTextWidth = 0; + + LayoutParams layoutParams = null; + + if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) { + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + titleTextView.setTextSize(16); + } else { + titleTextView.setTextSize(18); + } + + layoutParams = (LayoutParams) titleTextView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + titleTextView.setLayoutParams(layoutParams); + titleTextView.measure(width, height); + maxTextWidth = titleTextView.getMeasuredWidth(); + } + if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) { + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + subTitleTextView.setTextSize(12); + } else { + subTitleTextView.setTextSize(14); + } + + layoutParams = (LayoutParams) subTitleTextView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + subTitleTextView.setLayoutParams(layoutParams); + subTitleTextView.measure(width, height); + maxTextWidth = Math.max(maxTextWidth, subTitleTextView.getMeasuredWidth()); + } + + int x = 0; + if (logoImageView == null || logoImageView.getVisibility() == GONE) { + x = Utilities.dp(16); + } else { + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + x = Utilities.dp(22) + (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f); + } else { + x = Utilities.dp(22) + logoImageView.getDrawable().getIntrinsicWidth(); + } + } + + if (menu != null) { + maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - Utilities.dp(16)); + } + + if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) { + layoutParams = (LayoutParams) titleTextView.getLayoutParams(); + layoutParams.width = LayoutParams.MATCH_PARENT; + layoutParams.height = titleTextView.getMeasuredHeight(); + int y = (height - titleTextView.getMeasuredHeight()) / 2; + if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) { + y = (height / 2 - titleTextView.getMeasuredHeight()) / 2 + offset; + } + layoutParams.setMargins(x, y, 0, 0); + titleTextView.setLayoutParams(layoutParams); + } + if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) { + layoutParams = (LayoutParams) subTitleTextView.getLayoutParams(); + layoutParams.width = LayoutParams.MATCH_PARENT; + layoutParams.height = subTitleTextView.getMeasuredHeight(); + layoutParams.setMargins(x, height / 2 + (height / 2 - subTitleTextView.getMeasuredHeight()) / 2 - offset, 0, 0); + subTitleTextView.setLayoutParams(layoutParams); + } + + ViewGroup.LayoutParams layoutParams1 = backButtonFrameLayout.getLayoutParams(); + layoutParams1.width = x + maxTextWidth + (isSearchFieldVisible ? 0 : Utilities.dp(6)); + backButtonFrameLayout.setLayoutParams(layoutParams1); + } + + public void positionMenu(int width, int height) { + if (menu == null) { + return; + } + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams(); + layoutParams.width = isSearchFieldVisible ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT; + layoutParams.leftMargin = isSearchFieldVisible ? Utilities.dp(26) + logoImageView.getDrawable().getIntrinsicWidth() : 0; + menu.setLayoutParams(layoutParams); + menu.measure(width, height); + } + + public void setDisplayUseLogoEnabled(boolean value) { + if (value && logoImageView == null) { + logoImageView = new ImageView(getContext()); + logoImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); + logoImageView.setImageResource(R.drawable.ic_ab_logo); + backButtonFrameLayout.addView(logoImageView); + positionLogoImage(getMeasuredHeight()); + } else if (logoImageView != null) { + logoImageView.setVisibility(value ? VISIBLE : GONE); + } + } + + public void setDisplayHomeAsUpEnabled(boolean value) { + if (value && backButtonImageView == null) { + backButtonImageView = new ImageView(getContext()); + backButtonImageView.setImageResource(R.drawable.ic_ab_back); + backButtonFrameLayout.addView(backButtonImageView); + positionBackImage(getMeasuredHeight()); + } + if (backButtonImageView != null) { + backButtonImageView.setVisibility(value ? VISIBLE : GONE); + backButtonFrameLayout.setEnabled(value); + } + } + + public void setSubtitle(CharSequence value) { + if (value != null && subTitleTextView == null) { + subTitleTextView = new TextView(getContext()); + backButtonFrameLayout.addView(subTitleTextView); + subTitleTextView.setTextColor(0xffd7e8f7); + subTitleTextView.setSingleLine(true); + subTitleTextView.setLines(1); + subTitleTextView.setMaxLines(1); + subTitleTextView.setEllipsize(TextUtils.TruncateAt.END); + } + if (subTitleTextView != null) { + subTitleTextView.setVisibility(value != null ? VISIBLE : GONE); + subTitleTextView.setText(value); + positionTitle(getMeasuredWidth(), getMeasuredHeight()); + } + } + + public void setSubTitleIcon(int resourceId, int padding) { + if (resourceId != 0 && subTitleTextView == null) { + subTitleTextView = new TextView(getContext()); + backButtonFrameLayout.addView(subTitleTextView); + subTitleTextView.setTextColor(0xffd7e8f7); + subTitleTextView.setSingleLine(true); + subTitleTextView.setLines(1); + subTitleTextView.setMaxLines(1); + subTitleTextView.setEllipsize(TextUtils.TruncateAt.END); + positionTitle(getMeasuredWidth(), getMeasuredHeight()); + } + if (subTitleTextView != null) { + subTitleTextView.setCompoundDrawablesWithIntrinsicBounds(resourceId, 0, 0, 0); + subTitleTextView.setCompoundDrawablePadding(padding); + } + } + + public void setTitle(CharSequence value) { + if (value != null && titleTextView == null) { + titleTextView = new TextView(getContext()); + titleTextView.setSingleLine(true); + titleTextView.setEllipsize(TextUtils.TruncateAt.END); + backButtonFrameLayout.addView(titleTextView); + titleTextView.setTextColor(0xffffffff); + } + if (titleTextView != null) { + titleTextView.setVisibility(value != null ? VISIBLE : GONE); + titleTextView.setText(value); + positionTitle(getMeasuredWidth(), getMeasuredHeight()); + } + } + + public void setTitleIcon(int resourceId, int padding) { + if (resourceId != 0 && titleTextView == null) { + titleTextView = new TextView(getContext()); + backButtonFrameLayout.addView(titleTextView); + titleTextView.setTextColor(0xffffffff); + titleTextView.setSingleLine(true); + titleTextView.setLines(1); + titleTextView.setMaxLines(1); + titleTextView.setEllipsize(TextUtils.TruncateAt.END); + positionTitle(getMeasuredWidth(), getMeasuredHeight()); + } + titleTextView.setCompoundDrawablesWithIntrinsicBounds(resourceId, 0, 0, 0); + titleTextView.setCompoundDrawablePadding(padding); + } + + public Drawable getSubTitleIcon() { + return subTitleTextView.getCompoundDrawables()[0]; + } + + public CharSequence getTitle() { + if (titleTextView == null) { + return null; + } + return titleTextView.getText(); + } + + public ActionBarMenu createMenu() { + if (menu != null) { + return menu; + } + menu = new ActionBarMenu(getContext(), parentActionBar, this); + addView(menu); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams(); + layoutParams.height = LayoutParams.FILL_PARENT; + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.gravity = Gravity.RIGHT; + menu.setLayoutParams(layoutParams); + return menu; + } + + public void onDestroy() { + parentActionBar.detachActionBarLayer(this); + } + + public void setActionBarMenuOnItemClick(ActionBarMenuOnItemClick listener) { + actionBarMenuOnItemClick = listener; + } + + public void setCustomView(int resourceId) { + LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = li.inflate(resourceId, null); + addView(view); + } + + public void setBackLayoutVisible(int visibility) { + backButtonFrameLayout.setVisibility(visibility); + } + + public int getBackLayoutWidth() { + if (menu != null) { + return getMeasuredWidth() - menu.getMeasuredWidth(); + } + return getMeasuredWidth(); + } + + public ActionBarMenu createActionMode() { + if (actionMode != null) { + return actionMode; + } + actionMode = new ActionBarMenu(getContext(), parentActionBar, this); + actionMode.setBackgroundResource(R.drawable.editheader); + addView(actionMode); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)actionMode.getLayoutParams(); + layoutParams.height = LayoutParams.FILL_PARENT; + layoutParams.width = LayoutParams.FILL_PARENT; + layoutParams.gravity = Gravity.RIGHT; + actionMode.setLayoutParams(layoutParams); + actionMode.setVisibility(GONE); + return actionMode; + } + + public void showActionMode() { + if (actionMode == null) { + return; + } + actionMode.setVisibility(VISIBLE); + if (backButtonFrameLayout != null) { + backButtonFrameLayout.setVisibility(INVISIBLE); + } + if (menu != null) { + menu.setVisibility(INVISIBLE); + } + } + + public void hideActionMode() { + if (actionMode == null) { + return; + } + actionMode.setVisibility(GONE); + if (backButtonFrameLayout != null) { + backButtonFrameLayout.setVisibility(VISIBLE); + } + if (menu != null) { + menu.setVisibility(VISIBLE); + } + } + + public boolean isActionModeShowed() { + return actionMode != null && actionMode.getVisibility() == VISIBLE; + } + + protected void onSearchFieldVisibilityChanged(boolean visible) { + isSearchFieldVisible = visible; + if (titleTextView != null) { + titleTextView.setVisibility(visible ? GONE : VISIBLE); + } + if (subTitleTextView != null) { + subTitleTextView.setVisibility(visible ? GONE : VISIBLE); + } + backButtonFrameLayout.setPadding(0, 0, visible ? 0 : Utilities.dp(4), 0); + if (visible) { + oldUseLogo = logoImageView != null && logoImageView.getVisibility() == VISIBLE; + setDisplayUseLogoEnabled(true); + } else { + setDisplayUseLogoEnabled(oldUseLogo); + } + if (visible) { + oldUseBack = backButtonImageView != null && backButtonImageView.getVisibility() == VISIBLE; + setDisplayHomeAsUpEnabled(true); + } else { + setDisplayHomeAsUpEnabled(oldUseBack); + } + logoImageView.setImageResource(visible ? R.drawable.ic_ab_search : R.drawable.ic_ab_logo); + } + + public void closeSearchField() { + if (!isSearchFieldVisible || menu == null) { + return; + } + menu.closeSearchField(); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + positionLogoImage(MeasureSpec.getSize(heightMeasureSpec)); + positionBackImage(MeasureSpec.getSize(heightMeasureSpec)); + positionMenu(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec)); + positionTitle(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec)); + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + + public void onMenuButtonPressed() { + if (menu != null) { + menu.onMenuButtonPressed(); + } + } +} \ 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 new file mode 100644 index 00000000..36224c71 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenu.java @@ -0,0 +1,143 @@ +/* + * 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. + */ + +package org.telegram.ui.Views.ActionBar; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; + +import org.telegram.messenger.R; +import org.telegram.messenger.Utilities; + +public class ActionBarMenu extends LinearLayout { + + private ActionBar parentActionBar; + private ActionBarLayer parentActionBarLayer; + + public ActionBarMenu(Context context, ActionBar actionBar, ActionBarLayer layer) { + super(context); + setOrientation(LinearLayout.HORIZONTAL); + parentActionBar = actionBar; + parentActionBarLayer = layer; + } + + public ActionBarMenu(Context context) { + super(context); + } + + public ActionBarMenu(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ActionBarMenu(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public View addItemResource(int id, int resourceId) { + LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = li.inflate(resourceId, null); + view.setTag(id); + addView(view); + LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams(); + layoutParams.height = FrameLayout.LayoutParams.FILL_PARENT; + view.setBackgroundResource(R.drawable.bar_selector); + view.setLayoutParams(layoutParams); + view.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + onItemClick((Integer)view.getTag()); + } + }); + return view; + } + + public ActionBarMenuItem addItem(int id, int icon) { + ActionBarMenuItem menuItem = new ActionBarMenuItem(getContext(), this, parentActionBar); + menuItem.setTag(id); + menuItem.setScaleType(ImageView.ScaleType.CENTER); + menuItem.setImageResource(icon); + addView(menuItem); + LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)menuItem.getLayoutParams(); + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.width = Utilities.dp(56); + menuItem.setLayoutParams(layoutParams); + menuItem.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + ActionBarMenuItem item = (ActionBarMenuItem)view; + if (item.hasSubMenu()) { + item.toggleSubMenu(); + } else if (item.isSearchField()) { + parentActionBarLayer.onSearchFieldVisibilityChanged(item.toggleSearch()); + } else { + onItemClick((Integer)view.getTag()); + } + } + }); + return menuItem; + } + + public void onDestroy() { + for (int a = 0; a < getChildCount(); a++) { + View view = getChildAt(a); + if (view instanceof ActionBarMenuItem) { + ((ActionBarMenuItem)view).closeSubMenu(); + } + } + } + + public void onItemClick(int id) { + if (parentActionBarLayer.actionBarMenuOnItemClick != null) { + parentActionBarLayer.actionBarMenuOnItemClick.onItemClick(id); + } + } + + public void clearItems() { + for (int a = 0; a < getChildCount(); a++) { + View view = getChildAt(a); + removeView(view); + } + } + + public void onMenuButtonPressed() { + for (int a = 0; a < getChildCount(); a++) { + View view = getChildAt(a); + if (view instanceof ActionBarMenuItem) { + ActionBarMenuItem item = (ActionBarMenuItem)view; + if (item.hasSubMenu()) { + item.toggleSubMenu(); + } + } + } + } + + public void closeSearchField() { + for (int a = 0; a < getChildCount(); a++) { + View view = getChildAt(a); + if (view instanceof ActionBarMenuItem) { + ActionBarMenuItem item = (ActionBarMenuItem)view; + if (item.isSearchField()) { + parentActionBarLayer.onSearchFieldVisibilityChanged(item.toggleSearch()); + } + } + } + } + + public ActionBarMenuItem getItem(int id) { + View v = findViewWithTag(id); + if (v instanceof ActionBarMenuItem) { + return (ActionBarMenuItem)v; + } + return null; + } +} 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 new file mode 100644 index 00000000..f2970e98 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarMenuItem.java @@ -0,0 +1,259 @@ +/* + * 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. + */ + +package org.telegram.ui.Views.ActionBar; + +import android.content.Context; +import android.graphics.drawable.BitmapDrawable; +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.View; +import android.view.WindowManager; +import android.view.inputmethod.EditorInfo; +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; +import org.telegram.messenger.Utilities; + +import java.lang.reflect.Field; + +public class ActionBarMenuItem extends ImageView { + + public static interface ActionBarMenuItemSearchListener { + public abstract void onSearchExpand(); + public abstract void onSearchCollapse(); + public abstract void onTextChanged(EditText editText); + } + + private LinearLayout popupLayout; + private ActionBarMenu parentMenu; + private PopupWindow popupWindow; + private ActionBar parentActionBar; + private EditText searchField; + private boolean isSearchField = false; + private ActionBarMenuItemSearchListener listener; + + public ActionBarMenuItem(Context context, ActionBarMenu menu, ActionBar actionBar) { + super(context); + setBackgroundResource(R.drawable.bar_selector); + parentMenu = menu; + parentActionBar = actionBar; + } + + public ActionBarMenuItem(Context context) { + super(context); + } + + public ActionBarMenuItem(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ActionBarMenuItem(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public void addSubItem(int id, String text, int icon) { + if (popupLayout == null) { + popupLayout = new LinearLayout(getContext()); + popupLayout.setOrientation(LinearLayout.VERTICAL); + popupLayout.setBackgroundResource(R.drawable.popup_fixed); + } + if (popupLayout.getChildCount() != 0) { + View delimeter = new View(getContext()); + delimeter.setBackgroundColor(0xffdcdcdc); + popupLayout.addView(delimeter); + LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)delimeter.getLayoutParams(); + layoutParams.width = Utilities.dp(196); + layoutParams.height = Utilities.density >= 3 ? 2 : 1; + delimeter.setLayoutParams(layoutParams); + } + TextView textView = new TextView(getContext()); + textView.setTextColor(0xff000000); + textView.setBackgroundResource(R.drawable.list_selector); + textView.setGravity(Gravity.CENTER_VERTICAL); + textView.setPadding(Utilities.dp(16), 0, Utilities.dp(16), 0); + textView.setTextSize(18); + textView.setMinWidth(Utilities.dp(196)); + textView.setTag(id); + textView.setText(text); + if (icon != 0) { + textView.setCompoundDrawablePadding(Utilities.dp(12)); + textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null); + } + popupLayout.addView(textView); + LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)textView.getLayoutParams(); + layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT; + layoutParams.height = Utilities.dp(48); + textView.setLayoutParams(layoutParams); + textView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + parentMenu.onItemClick((Integer) view.getTag()); + if (popupWindow != null && popupWindow.isShowing()) { + popupWindow.dismiss(); + } + } + }); + } + + public boolean hasSubMenu() { + return popupLayout != null; + } + + public void toggleSubMenu() { + if (popupWindow != null && popupWindow.isShowing()) { + popupWindow.dismiss(); + return; + } + if (popupWindow == null) { + popupWindow = new PopupWindow(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.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); + } + if (popupLayout.getMeasuredWidth() == 0) { + popupWindow.showAsDropDown(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0); + popupWindow.update(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0, -1, -1); + } else { + popupWindow.showAsDropDown(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0); + } + } + + public boolean toggleSearch() { + if (searchField == null) { + return false; + } + if (searchField.getVisibility() == VISIBLE) { + searchField.setVisibility(GONE); + setVisibility(VISIBLE); + Utilities.hideKeyboard(searchField); + if (listener != null) { + listener.onSearchCollapse(); + } + return false; + } else { + searchField.setVisibility(VISIBLE); + setVisibility(GONE); + searchField.setText(""); + searchField.requestFocus(); + Utilities.showKeyboard(searchField); + if (listener != null) { + listener.onSearchExpand(); + } + return true; + } + } + + public void closeSubMenu() { + if (popupWindow != null && popupWindow.isShowing()) { + popupWindow.dismiss(); + } + } + + public EditText getSearchField() { + return searchField; + } + + public ActionBarMenuItem setIsSearchField(boolean value) { + if (value && searchField == null) { + searchField = new EditText(getContext()); + 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); + searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_SEARCH || event != null && event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { + Utilities.hideKeyboard(searchField); + } + return false; + } + }); + searchField.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (listener != null) { + listener.onTextChanged(searchField); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + /* + ImageView img = (ImageView) searchView.findViewById(R.id.search_close_btn); + if (img != null) { + img.setImageResource(R.drawable.ic_msg_btn_cross_custom); + } + */ + try { + Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); + mCursorDrawableRes.setAccessible(true); + mCursorDrawableRes.set(searchField, R.drawable.search_carret); + } catch (Exception e) { + e.printStackTrace(); + } + if (Build.VERSION.SDK_INT >= 11) { + searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH); + } else { + searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH); + } + parentMenu.addView(searchField, 0); + LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)searchField.getLayoutParams(); + layoutParams.weight = 1; + layoutParams.width = 0; + layoutParams.gravity = Gravity.CENTER_VERTICAL; + layoutParams.height = Utilities.dp(36); + layoutParams.rightMargin = Utilities.dp(4); + searchField.setLayoutParams(layoutParams); + searchField.setVisibility(GONE); + } + isSearchField = value; + return this; + } + + public boolean isSearchField() { + return isSearchField; + } + + public void setActionBarMenuItemSearchListener(ActionBarMenuItemSearchListener listener) { + this.listener = listener; + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + if (popupWindow != null && popupWindow.isShowing()) { + popupWindow.update(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0, -1, -1); + } + } +} 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 new file mode 100644 index 00000000..238a81aa --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java @@ -0,0 +1,166 @@ +/* + * This is the source code of Telegram for Android v. 1.3.2. + * 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. + */ + +package org.telegram.ui.Views.ActionBar; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import org.telegram.messenger.ConnectionsManager; + +public class BaseFragment { + private boolean isFinished = false; + protected View fragmentView; + private ActionBarActivity parentActivity; + protected ActionBarLayer actionBarLayer; + protected int classGuid = 0; + protected Bundle arguments; + + public BaseFragment() { + classGuid = ConnectionsManager.getInstance().generateClassGuid(); + } + + public BaseFragment(Bundle args) { + arguments = args; + classGuid = ConnectionsManager.getInstance().generateClassGuid(); + } + + public View createView(LayoutInflater inflater, ViewGroup container) { + return null; + } + + public Bundle getArguments() { + return arguments; + } + + public void setParentActivity(ActionBarActivity activity) { + if (parentActivity != activity) { + parentActivity = activity; + if (fragmentView != null) { + ViewGroup parent = (ViewGroup) fragmentView.getParent(); + if (parent != null) { + parent.removeView(fragmentView); + } + fragmentView = null; + } + if (parentActivity != null) { + if (actionBarLayer != null) { + actionBarLayer.onDestroy(); + actionBarLayer = null; + } + actionBarLayer = parentActivity.getInternalActionBar().createLayer(); + } + } + } + + public void finishFragment() { + if (isFinished || parentActivity == null) { + return; + } + parentActivity.closeLastFragment(); + } + + public void removeSelfFromStack() { + if (isFinished || parentActivity == null) { + return; + } + parentActivity.removeFragmentFromStack(this); + } + + public boolean onFragmentCreate() { + return true; + } + + public void onFragmentDestroy() { + ConnectionsManager.getInstance().cancelRpcsForClassGuid(classGuid); + isFinished = true; + if (actionBarLayer != null) { + actionBarLayer.setEnabled(false); + } + } + + public void onResume() { + + } + + public void onPause() { + + } + + public void onConfigurationChanged(android.content.res.Configuration newConfig) { + + } + + public boolean onBackPressed() { + return true; + } + + public void onActivityResultFragment(int requestCode, int resultCode, Intent data) { + + } + + public void saveSelfArgs(Bundle args) { + + } + + public void restoreSelfArgs(Bundle args) { + + } + + public void presentFragment(BaseFragment fragment) { + if (parentActivity == null) { + return; + } + parentActivity.presentFragment(fragment); + } + + public void presentFragment(BaseFragment fragment, boolean removeLast) { + if (parentActivity == null) { + return; + } + parentActivity.presentFragment(fragment, removeLast); + } + + public void presentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation) { + if (parentActivity == null) { + return; + } + parentActivity.presentFragment(fragment, removeLast, forceWithoutAnimation); + } + + public ActionBarActivity getParentActivity() { + return parentActivity; + } + + public void showActionBar() { + if (parentActivity != null) { + parentActivity.showActionBar(); + } + } + + public void hideActionBar() { + if (parentActivity != null) { + parentActivity.hideActionBar(); + } + } + + public void onBeginSlide() { + + } + + public void onOpenAnimationEnd() { + + } + + public void onLowMemory() { + + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java index e3bdab82..91c5ca97 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java @@ -23,6 +23,7 @@ import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; import org.telegram.ui.LaunchActivity; import org.telegram.ui.PhotoCropActivity; +import org.telegram.ui.Views.ActionBar.BaseFragment; import java.io.File; @@ -58,7 +59,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); currentPicturePath = image.getAbsolutePath(); } - parentFragment.parentActivity.startActivityForResult(takePictureIntent, 13); + parentFragment.getParentActivity().startActivityForResult(takePictureIntent, 13); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -68,7 +69,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); - parentFragment.parentActivity.startActivityForResult(photoPickerIntent, 14); + parentFragment.getParentActivity().startActivityForResult(photoPickerIntent, 14); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -76,23 +77,19 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg private void startCrop(String path, Uri uri) { try { - LaunchActivity activity = (LaunchActivity)parentFragment.parentActivity; - if (activity == null) { - activity = (LaunchActivity)parentFragment.getActivity(); - } + LaunchActivity activity = (LaunchActivity)parentFragment.getParentActivity(); if (activity == null) { return; } - Bundle params = new Bundle(); + Bundle args = new Bundle(); if (path != null) { - params.putString("photoPath", path); + args.putString("photoPath", path); } else if (uri != null) { - params.putParcelable("photoUri", uri); + args.putParcelable("photoUri", uri); } - PhotoCropActivity photoCropActivity = new PhotoCropActivity(); - photoCropActivity.delegate = this; - photoCropActivity.setArguments(params); - activity.presentFragment(photoCropActivity, "crop", false); + PhotoCropActivity photoCropActivity = new PhotoCropActivity(args); + photoCropActivity.setDelegate(this); + activity.presentFragment(photoCropActivity); } catch (Exception e) { FileLog.e("tmessages", e); Bitmap bitmap = FileLoader.loadBitmap(path, uri, 800, 800); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java index 980efc9f..641a8b0d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/BackupImageView.java @@ -24,6 +24,7 @@ import org.telegram.messenger.Utilities; public class BackupImageView extends ImageView { boolean makeRequest = true; public String currentPath; + public boolean processDetach = true; private boolean isPlaceholder; private boolean ignoreLayout = true; @@ -179,7 +180,9 @@ public class BackupImageView extends ImageView { @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); - recycleBitmap(null); + if (processDetach) { + recycleBitmap(null); + } } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/BaseFragment.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/BaseFragment.java deleted file mode 100644 index 4ab44f30..00000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/BaseFragment.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 1.3.2. - * 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. - */ - -package org.telegram.ui.Views; - -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v7.app.ActionBarActivity; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; - -import org.telegram.messenger.ConnectionsManager; -import org.telegram.ui.LaunchActivity; -import org.telegram.ui.ApplicationLoader; - -public class BaseFragment extends Fragment { - public int animationType = 0; - public boolean isFinish = false; - public View fragmentView; - public ActionBarActivity parentActivity; - public int classGuid = 0; - public boolean firstStart = true; - public boolean animationInProgress = false; - private long currentAnimationDuration = 0; - private boolean removeParentOnDestroy = false; - private boolean removeParentOnAnimationEnd = true; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - parentActivity = (ActionBarActivity)getActivity(); - } - - public void willBeHidden() { - - } - - public void finishFragment() { - finishFragment(false); - } - - public void finishFragment(boolean bySwipe) { - if (isFinish || animationInProgress) { - return; - } - isFinish = true; - if (parentActivity == null) { - ApplicationLoader.fragmentsStack.remove(this); - onFragmentDestroy(); - return; - } - ((LaunchActivity)parentActivity).finishFragment(bySwipe); - if (getActivity() == null) { - if (fragmentView != null) { - ViewGroup parent = (ViewGroup)fragmentView.getParent(); - if (parent != null) { - parent.removeView(fragmentView); - } - fragmentView = null; - } - parentActivity = null; - } else { - removeParentOnDestroy = true; - } - } - - public void removeSelfFromStack() { - if (isFinish) { - return; - } - isFinish = true; - if (parentActivity == null) { - ApplicationLoader.fragmentsStack.remove(this); - onFragmentDestroy(); - return; - } - ((LaunchActivity)parentActivity).removeFromStack(this); - if (getActivity() == null) { - if (fragmentView != null) { - ViewGroup parent = (ViewGroup)fragmentView.getParent(); - if (parent != null) { - parent.removeView(fragmentView); - } - fragmentView = null; - } - parentActivity = null; - } else { - removeParentOnDestroy = true; - } - } - - public boolean onFragmentCreate() { - classGuid = ConnectionsManager.getInstance().generateClassGuid(); - return true; - } - - public void onFragmentDestroy() { - ConnectionsManager.getInstance().cancelRpcsForClassGuid(classGuid); - removeParentOnDestroy = true; - isFinish = true; - } - - public void onAnimationStart() { - animationInProgress = true; - if (fragmentView != null) { - fragmentView.postDelayed(new Runnable() { - @Override - public void run() { - if (animationInProgress) { - onAnimationEnd(); - } - } - }, currentAnimationDuration); - } - } - - public void onAnimationEnd() { - animationInProgress = false; - } - - public boolean onBackPressed() { - return true; - } - - @Override - public void onDestroy() { - super.onDestroy(); - if (removeParentOnDestroy) { - if (fragmentView != null) { - ViewGroup parent = (ViewGroup)fragmentView.getParent(); - if (parent != null) { - parent.removeView(fragmentView); - } - fragmentView = null; - } - parentActivity = null; - } - } - - @Override - public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { - if (nextAnim != 0) { - Animation anim = AnimationUtils.loadAnimation(getActivity(), nextAnim); - currentAnimationDuration = anim.getDuration(); - - anim.setAnimationListener(new Animation.AnimationListener() { - - public void onAnimationStart(Animation animation) { - BaseFragment.this.onAnimationStart(); - } - - public void onAnimationRepeat(Animation animation) { - - } - - public void onAnimationEnd(Animation animation) { - if (animationInProgress) { - BaseFragment.this.onAnimationEnd(); - } - } - }); - - return anim; - } else { - return super.onCreateAnimation(transit, enter, nextAnim); - } - } - - public boolean canApplyUpdateStatus() { - return true; - } - - public void applySelfActionBar() { - - } - - public void onActivityResultFragment(int requestCode, int resultCode, Intent data) { - - } - - public void saveSelfArgs(Bundle args) { - - } - - public void restoreSelfArgs(Bundle args) { - - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/OnSwipeTouchListener.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/OnSwipeTouchListener.java deleted file mode 100644 index 2feebb33..00000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/OnSwipeTouchListener.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 1.3.2. - * 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. - */ - -package org.telegram.ui.Views; - -import android.view.MotionEvent; -import android.view.View; -import android.view.View.OnTouchListener; -import android.widget.GridView; -import android.widget.ListView; - -public class OnSwipeTouchListener implements OnTouchListener { - private float downX, downY; - private boolean discard = false; - - public boolean onTouch(View v, MotionEvent event) { - switch(event.getAction()){ - case MotionEvent.ACTION_DOWN: { - downX = event.getX(); - downY = event.getY(); - discard = false; - return !(v instanceof ListView || v instanceof GridView); - } - case MotionEvent.ACTION_MOVE: { - float upX = event.getX(); - float upY = event.getY(); - - float deltaX = downX - upX; - float deltaY = downY - upY; - if (Math.abs(deltaY) > 40) { - discard = true; - } - - if(!discard && Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > 90) { - if(deltaX < 0) { - onSwipeRight(); - return true; - } - if(deltaX > 0) { - onSwipeLeft(); - return true; - } - } - - break; - } - case MotionEvent.ACTION_UP: { - onTouchUp(event); - return false; - } - } - return false; - } - - - /*private final GestureDetector gestureDetector = new GestureDetector(new GestureListener()); - - public boolean onTouch(final View view, final MotionEvent motionEvent) { - return gestureDetector.onTouchEvent(motionEvent); - } - - private final class GestureListener extends SimpleOnGestureListener { - - private static final int SWIPE_THRESHOLD = 100; - private static final int SWIPE_VELOCITY_THRESHOLD = 100; - private long lastTime = 0; - - @Override - public boolean onDown(MotionEvent e) { - return true; - } - - - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - boolean result = false; - try { - int mask = e1.getActionMasked(); - Log.e("tmessages", "event1" + e1); - Log.e("tmessages", "event2" + e2); - float diffY = e2.getY() - e1.getY(); - float diffX = e2.getX() - e1.getX(); - float velocityX = 0; - if (lastTime != 0) - if (Math.abs(diffX) > Math.abs(diffY)) { - if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { - if (diffX > 0) { - onSwipeRight(); - } else { - onSwipeLeft(); - } - } - } - } catch (Exception exception) { - exception.printStackTrace(); - } - return result; - } - - - -// @Override -// public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { -// boolean result = false; -// try { -// float diffY = e2.getY() - e1.getY(); -// float diffX = e2.getX() - e1.getX(); -// if (Math.abs(diffX) > Math.abs(diffY)) { -// if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { -// if (diffX > 0) { -// onSwipeRight(); -// } else { -// onSwipeLeft(); -// } -// } -// } else { -// if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { -// if (diffY > 0) { -// onSwipeBottom(); -// } else { -// onSwipeTop(); -// } -// } -// } -// } catch (Exception exception) { -// exception.printStackTrace(); -// } -// return result; -// } - } -*/ - public void onTouchUp(MotionEvent event) { - - } - - public void onSwipeRight() { - - } - - public void onSwipeLeft() { - - } -} diff --git a/TMessagesProj/src/main/res/anim/no_anim.xml b/TMessagesProj/src/main/res/anim/no_anim.xml deleted file mode 100644 index a964bf5d..00000000 --- a/TMessagesProj/src/main/res/anim/no_anim.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/anim/no_anim_show.xml b/TMessagesProj/src/main/res/anim/no_anim_show.xml deleted file mode 100644 index ebad7944..00000000 --- a/TMessagesProj/src/main/res/anim/no_anim_show.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/anim/slide_left.xml b/TMessagesProj/src/main/res/anim/slide_left.xml deleted file mode 100644 index 785709ab..00000000 --- a/TMessagesProj/src/main/res/anim/slide_left.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/anim/slide_left_away.xml b/TMessagesProj/src/main/res/anim/slide_left_away.xml deleted file mode 100644 index 42f29db9..00000000 --- a/TMessagesProj/src/main/res/anim/slide_left_away.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/anim/slide_right.xml b/TMessagesProj/src/main/res/anim/slide_right.xml deleted file mode 100644 index 5ae3a889..00000000 --- a/TMessagesProj/src/main/res/anim/slide_right.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/anim/slide_right_away.xml b/TMessagesProj/src/main/res/anim/slide_right_away.xml deleted file mode 100644 index 5d88854b..00000000 --- a/TMessagesProj/src/main/res/anim/slide_right_away.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/drawable-hdpi/editheader.9.png b/TMessagesProj/src/main/res/drawable-hdpi/editheader.9.png new file mode 100644 index 0000000000000000000000000000000000000000..00240da6448b71dcf398b8bd4ae1065f0fa1a70e GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^LO|@q!3HFw9NHEDDPK<)$B>F!Z*OemJYc}X;_!CL zP1~Sn6RgcW9URpJcC_o4?zMX~OXu6OO*2`W_caT#Ff}?T2ylR?1@oQ${bMTWF}A+T gzgJ?uocl`7AIBq-7e2f49B43ur>mdKI;Vst09kG=u>b%7 literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-hdpi/header.9.png b/TMessagesProj/src/main/res/drawable-hdpi/header.9.png deleted file mode 100644 index 8277f4c2f619238bd6f2f53db7217102cb868e91..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 136 zcmeAS@N?(olHy`uVBq!ia0vp^fgTe~DWM4fXoxKn diff --git a/TMessagesProj/src/main/res/drawable-hdpi/search_light.9.png b/TMessagesProj/src/main/res/drawable-hdpi/search_light.9.png new file mode 100755 index 0000000000000000000000000000000000000000..36e71d85d08310865a37a38a5876dc78d4372af9 GIT binary patch literal 105 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~k!3HF)wbmE`DFaUz#}JM4$v^)8w`Z37Am6po z+v)2g(?*7d*QRRDn?J5#Tv6p96EC#Ua9@Rb%R>f+&Xuw+O+F;e0P1D%boFyt=akR{ E0I7Z;-v9sr literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-hdpi/search_light_selected.9.png b/TMessagesProj/src/main/res/drawable-hdpi/search_light_selected.9.png new file mode 100755 index 0000000000000000000000000000000000000000..9bde7fbdce15a1c2873eb0779ffc0617fd9b15c4 GIT binary patch literal 112 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~k!3HF)wbmE`DRWO3#}JM4$q6$m+Zg$O@E^Uw z81lZJ?bE^f8J_14%!p_Ru>Zp|qw<;kM2WLbT|5rH?EgED6zpZtm|hnx*$^-bXas|& LtDnm{r-UW|n`+uXo8G5=nhE&{2PH<@WZ(%Tri-}=f z<14QJ{aP}i7OM(E9x_a^mdKI;Vst E0NKbPEC2ui literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-ldpi/header.9.png b/TMessagesProj/src/main/res/drawable-ldpi/header.9.png deleted file mode 100644 index 1bbb98f89f62ca8ec2dde0607d1c8af8ac9ffc5c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^AhsF@8<6}P!}S438GE`ohE&{2PH<@WZ(+dHGUeRw ze*VKIf8;|gRuzOiTyZF{wIt}ogSp0E?d^JEru|oMkYrH(!+J<|wfGC5b_P#ZKbLh* G2~7Zr+$22! diff --git a/TMessagesProj/src/main/res/drawable-mdpi/editheader.9.png b/TMessagesProj/src/main/res/drawable-mdpi/editheader.9.png new file mode 100644 index 0000000000000000000000000000000000000000..e7f67fe0776718379fc7ee02bc7e11903d6a815c GIT binary patch literal 118 zcmeAS@N?(olHy`uVBq!ia0vp^d_Zi(!3HFAKD=TFQnsEhjv*Ddk`o+Q|8pjoTvcJ( zq3G=X_(id?c7Of3-12t+Qx`O5V7O8ja%cOF S6X8IE7(8A5T-G@yGywp~jVJX0 literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-mdpi/header.9.png b/TMessagesProj/src/main/res/drawable-mdpi/header.9.png deleted file mode 100644 index cb162a036961bbe62002a4c6bdffd6ddcbb5e643..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 119 zcmeAS@N?(olHy`uVBq!ia0vp^JV0#3!3HEVSgovpl%1!GV@SoVEt`mrVp3OWu(*tYT>W@HfhtG!C@Uj!>q8-u5-pUXO@geCyVL>!s` literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-mdpi/search_light_selected.9.png b/TMessagesProj/src/main/res/drawable-mdpi/search_light_selected.9.png new file mode 100755 index 0000000000000000000000000000000000000000..1767c169eef03f3370b0f8e40f531dd481a9b82d GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^JV4CO!3HF4Hmy+sQYM}*jv*44lYjjGZ_jMS*7QH1 z$CppT@G}o{phONw%V+tnLd~`l!OqNzXB@V%srV-z^vGhE?K{(iZ(fQrP(OpGtDnm{ Hr-UW|vZo$& literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/editheader.9.png b/TMessagesProj/src/main/res/drawable-xhdpi/editheader.9.png new file mode 100644 index 0000000000000000000000000000000000000000..50261891c46a30b6d4ab6a2c26196b0277d5db1d GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^Qb3%F!Z*OhnZ7|?rad>~^ zjbx|g96iyFLlImr;(mS0Z|vXUCsw`r)|}R6hySfYEKH3K3IZJ1s0`y1qEDDF7@m8h ivx0AL!JTTGZ@!*E&aMliUz7l?V(@hJb6Mw<&;$Ts05K*2 literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/header.9.png b/TMessagesProj/src/main/res/drawable-xhdpi/header.9.png deleted file mode 100644 index e001523f6a396b6ef5f9f11bafc5b38352acb026..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^VnCe4!3HEl*p=S^sc26Z$B>F!Z*MvBGAQ!6I^IcS z;9t!kznWq7U1mnsw~3Q~p4{EnxNYlRkG%XdqBCPmdKI;Vst0DAs11ONa4 diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/search_light.9.png b/TMessagesProj/src/main/res/drawable-xhdpi/search_light.9.png new file mode 100755 index 0000000000000000000000000000000000000000..4e9ae43c250a365c3894e04aace0602a506b199b GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^qCm{e!3HEJoIX|yq+C5+978nDC;#~W-=0~Khvol7 z1H)I2CW)>m8aUV+8udAXlQhooEaFu)>JVsC;_i|1;&qn1z`CMwWxmD@8>XG@5j{z4 Z4Ch(42+t_Fa};PGgQu&X%Q~loCICWDCD8x? literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/search_light_selected.9.png b/TMessagesProj/src/main/res/drawable-xhdpi/search_light_selected.9.png new file mode 100755 index 0000000000000000000000000000000000000000..1743da6b4e1fde0f22e32216039e718a0cb1c7b5 GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^qCm{e!3HEJoIX|yq+C5+978nDC;#~W-=0~Khvol7 z1H)I2CW)>m8aUV)4xTaopEyItdE!^$Tn)$h3#7aBEDrH5l{lPKbU~WStl#0CqS)dY aj0`i|)DAxoJGT#LAcLo?pUXO@geCyp{V3}I literal 0 HcmV?d00001 diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/editheader.9.png b/TMessagesProj/src/main/res/drawable-xxhdpi/editheader.9.png new file mode 100644 index 0000000000000000000000000000000000000000..a58727f986031d008f874415d0d03cb6aa8cd9ca GIT binary patch literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^YCt@RgAGV(rtLTjr20Kw978H@y}h%OmqCGt*`X|{ z%q^+!Lf|Kn1tRGux8^fV-{fcWF3mPlO^OEubl7zcPzUrS&g(mH;L^dY*ArJJBqYf5 dWv=JXVK7fA2(?FJmRh2GUtl_UBZv9s%xEk4RCH?)Ci#`*B0&fOT8%3buKJ%V}E2i`PSU$)) cd=kiHez0}Bg4u#CKS8E?y85}Sb4q9e09kt}YybcN diff --git a/TMessagesProj/src/main/res/drawable/ab_icon_fixed2.xml b/TMessagesProj/src/main/res/drawable/ab_icon_fixed2.xml deleted file mode 100644 index 640f8a6b..00000000 --- a/TMessagesProj/src/main/res/drawable/ab_icon_fixed2.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/drawable/search_light_states.xml b/TMessagesProj/src/main/res/drawable/search_light_states.xml new file mode 100755 index 00000000..11282d4c --- /dev/null +++ b/TMessagesProj/src/main/res/drawable/search_light_states.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/TMessagesProj/src/main/res/layout-ar/contacts_layout.xml b/TMessagesProj/src/main/res/layout-ar/contacts_layout.xml index c2e0c196..eccbfa38 100644 --- a/TMessagesProj/src/main/res/layout-ar/contacts_layout.xml +++ b/TMessagesProj/src/main/res/layout-ar/contacts_layout.xml @@ -1,6 +1,7 @@ - + - + - - + + + android:layout_width="64dp" + android:layout_height="64dp" + android:contentDescription="" + android:id="@+id/location_avatar_view" + android:layout_marginRight="12dp" + android:layout_marginTop="16dp" + android:layout_gravity="top|right"/> - + + + - + \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/application_layout.xml b/TMessagesProj/src/main/res/layout/application_layout.xml deleted file mode 100644 index b3a57e07..00000000 --- a/TMessagesProj/src/main/res/layout/application_layout.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/contacts_layout.xml b/TMessagesProj/src/main/res/layout/contacts_layout.xml index 7f6c72a8..8b281bc3 100644 --- a/TMessagesProj/src/main/res/layout/contacts_layout.xml +++ b/TMessagesProj/src/main/res/layout/contacts_layout.xml @@ -1,6 +1,7 @@ - + - + - + - + \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/location_view_layout.xml b/TMessagesProj/src/main/res/layout/location_view_layout.xml index d339fb85..9eda596f 100644 --- a/TMessagesProj/src/main/res/layout/location_view_layout.xml +++ b/TMessagesProj/src/main/res/layout/location_view_layout.xml @@ -1,49 +1,57 @@ - + - - + + + android:layout_width="64dp" + android:layout_height="64dp" + android:contentDescription="" + android:id="@+id/location_avatar_view" + android:layout_marginLeft="12dp" + android:layout_marginTop="16dp" + android:layout_gravity="top"/> - + + + - + \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/updating_state_layout.xml b/TMessagesProj/src/main/res/layout/updating_state_layout.xml index 715e3ab2..da95e9a6 100644 --- a/TMessagesProj/src/main/res/layout/updating_state_layout.xml +++ b/TMessagesProj/src/main/res/layout/updating_state_layout.xml @@ -14,7 +14,6 @@ android:indeterminateDuration="1200" android:indeterminateOnly="true" android:layout_gravity="center_vertical|left" - android:visibility="visible" android:layout_marginLeft="12dp"/> #ff000000 #ffffffff #dcdcdc + #ff54759e \ No newline at end of file diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index c673551e..bdcda8d9 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -269,7 +269,7 @@ If google play services are enough for you to receive notifications, you can disable Notifications Service. However we recommend you to leave it enabled to keep app running in background and receive instant notifications. Sort By Import Contacts - via WiFi only + Via WiFi only First name Last name diff --git a/TMessagesProj/src/main/res/values/styles.xml b/TMessagesProj/src/main/res/values/styles.xml index 707e57a9..c70a0edf 100644 --- a/TMessagesProj/src/main/res/values/styles.xml +++ b/TMessagesProj/src/main/res/values/styles.xml @@ -3,21 +3,16 @@ - - - - - - - -