Implemented own ActionBar and Fragments, swipe back navigation, https://github.com/DrKLO/Telegram/issues/424

This commit is contained in:
DrKLO 2014-06-04 03:31:48 +04:00
parent 644fc7ccea
commit 3fecce9645
78 changed files with 4063 additions and 4682 deletions

View File

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

View File

@ -95,19 +95,6 @@
<data android:mimeType="vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile"/>
</intent-filter>
</activity>
<activity
android:name="org.telegram.ui.LoginActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.telegram.ui.CountrySelectActivity"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.TMessages"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.telegram.ui.IntroActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

View File

@ -456,6 +456,19 @@ public class LocaleController {
}
}
public static String formatStringSimple(String string, Object... args) {
try {
if (getInstance().currentLocale != null) {
return String.format(getInstance().currentLocale, string, args);
} else {
return String.format(string, args);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
return "LOC_ERR: " + string;
}
}
public void onDeviceConfigurationChange(Configuration newConfig) {
if (changingConfiguration) {
return;

View File

@ -564,9 +564,11 @@ public class MessagesStorage {
}
ids += uid;
}
int totalCount = 0;
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT uid, read_state, out FROM messages WHERE mid IN(%s)", ids));
while (cursor.next()) {
int out = cursor.intValue(2);
totalCount++;
if (out != 0) {
continue;
}
@ -588,6 +590,10 @@ public class MessagesStorage {
}
cursor.dispose();
if (totalCount != messages.size()) {
FileLog.e("tmessages", "messages read mismatch!");
}
cursor = database.queryFinalized(String.format(Locale.US, "SELECT did, unread_count FROM dialogs WHERE did IN(%s)", dialogsToReload));
while (cursor.next()) {
long did = cursor.longValue(0);

View File

@ -205,7 +205,7 @@ public class Utilities {
}
public static int dp(int value) {
return (int)(density * value);
return (int)(Math.max(1, density * value));
}
public static int dpf(float value) {

View File

@ -24,7 +24,6 @@ import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.PowerManager;
import android.view.ViewConfiguration;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
@ -41,10 +40,7 @@ import org.telegram.messenger.NativeLoader;
import org.telegram.messenger.ScreenReceiver;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.BaseFragment;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.concurrent.atomic.AtomicInteger;
@ -64,8 +60,6 @@ public class ApplicationLoader extends Application {
private static volatile boolean applicationInited = false;
public static volatile boolean isScreenOn = false;
public static ArrayList<BaseFragment> fragmentsStack = new ArrayList<BaseFragment>();
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();
}

View File

@ -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<View>(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;

View File

@ -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) {

View File

@ -482,7 +482,7 @@ public class DialogCell extends BaseCell {
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#316f9f>%s:</font> <font color=#316f9f>%s</font>", name, message.messageText)), messagePaint.getFontMetricsInt(), Utilities.dp(20));
} else {
if (message.messageOwner.message != null) {
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#316f9f>%s:</font> <font color=#808080>%s</font>", name, message.messageOwner.message.replace("\n", " "))), messagePaint.getFontMetricsInt(), Utilities.dp(20));
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#316f9f>%s:</font> <font color=#808080>%s</font>", name, message.messageOwner.message.replace("\n", " ").replace("<", "&lt;").replace(">", "&gt;"))), messagePaint.getFontMetricsInt(), Utilities.dp(20));
}
}
} else {

File diff suppressed because it is too large Load Diff

View File

@ -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<Integer, TLRPC.User> users = new HashMap<Integer, TLRPC.User>();
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() {

View File

@ -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() {

View File

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

View File

@ -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<Integer, TLRPC.User> 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<Integer, TLRPC.User>)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<Integer, TLRPC.User> users) {
ignoreUsers = users;
}
}

View File

@ -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<String, ArrayList<Country>> countries = new HashMap<String, ArrayList<Country>>();
private ArrayList<String> sortedCountries = new ArrayList<String>();
private CountrySelectActivityDelegate delegate;
private Timer searchTimer;
public ArrayList<Country> 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<Country> 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<Country> 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<Country> arrCounties) {
Utilities.RunOnUIThread(new Runnable() {
@Override

View File

@ -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<HistoryEntry> history = new ArrayList<HistoryEntry>();
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);

View File

@ -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<Integer> result = new ArrayList<Integer>();
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<Integer> result = new ArrayList<Integer>();
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) {

View File

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

View File

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

View File

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

View File

@ -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<LocaleController.LocaleInfo> 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) {

View File

@ -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<String, ?> 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<String, ?> 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);
}

View File

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

View File

@ -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<String, ?> params = preferences.getAll();
for (Map.Entry<String, ?> 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);
}
}

View File

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

View File

@ -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<TLRPC.PhotoSize> 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);

View File

@ -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<TLObject> searchResult;
public ArrayList<CharSequence> 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;

View File

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

View File

@ -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<Uri> uris = new ArrayList<Uri>();
@ -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() {

View File

@ -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;

View File

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

View File

@ -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;

View File

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

View File

@ -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<TLRPC.User> arrayList = new ArrayList<TLRPC.User>();
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<TLRPC.User> arrayList = new ArrayList<TLRPC.User>();
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);

View File

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

View File

@ -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<BaseFragment> fragmentsStack = new ArrayList<BaseFragment>();
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<Animator> animators = new ArrayList<Animator>();
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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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

View File

@ -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) {
}
}

View File

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

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="150" />
</set>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="150" />
</set>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
android:duration="150"/>
</set>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%"
android:duration="150"/>
</set>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%"
android:toXDelta="0"
android:duration="150"/>
</set>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="150"/>
</set>

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 B

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/ic_ab_logo"
android:left="-6dp"/>
</layer-list>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="@drawable/search_light_selected" />
<item android:drawable="@drawable/search_light" />
</selector>

View File

@ -1,6 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.telegram.ui.Views.PinnedHeaderListView
android:layout_width="fill_parent"

View File

@ -1,51 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top">
<FrameLayout android:id="@+id/map_view"
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"/>
<FrameLayout android:layout_width="fill_parent"
android:layout_height="91dp"
android:layout_gravity="bottom"
android:background="@drawable/location_panel"
android:id="@+id/location_bottom_view">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="91dp"
android:layout_gravity="bottom"
android:background="@drawable/location_panel"
android:id="@+id/location_bottom_view">
<org.telegram.ui.Views.BackupImageView
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"/>
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"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginRight="88dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="12dp"
android:id="@+id/location_name_label"
android:layout_gravity="top|right"
android:maxLines="1"
android:gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginRight="88dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="12dp"
android:id="@+id/location_name_label"
android:layout_gravity="top|right"
android:maxLines="1"
android:gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginRight="88dp"
android:layout_marginTop="52dp"
android:layout_marginLeft="12dp"
android:textColor="#999999"
android:id="@+id/location_distance_label"
android:layout_gravity="top|right"
android:maxLines="1"
android:gravity="right"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginRight="88dp"
android:layout_marginTop="52dp"
android:layout_marginLeft="12dp"
android:textColor="#999999"
android:id="@+id/location_distance_label"
android:layout_gravity="top|right"
android:maxLines="1"
android:gravity="right"/>
</FrameLayout>
</FrameLayout>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:background="#ffffff">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"/>
</FrameLayout>

View File

@ -1,6 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.telegram.ui.Views.PinnedHeaderListView
android:layout_width="fill_parent"

View File

@ -1,25 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top">
<FrameLayout android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"/>
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"/>
<TextView android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:gravity="center"
android:textSize="18dp"
android:textColor="#316f9f"
android:background="@drawable/location_send_button_states"
android:id="@+id/location_send_button"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:gravity="center"
android:textSize="18dp"
android:textColor="#316f9f"
android:background="@drawable/location_send_button_states"
android:id="@+id/location_send_button"/>
</FrameLayout>

View File

@ -1,49 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top">
<FrameLayout android:id="@+id/map_view"
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"/>
<FrameLayout android:layout_width="fill_parent"
android:layout_height="91dp"
android:layout_gravity="bottom"
android:background="@drawable/location_panel"
android:id="@+id/location_bottom_view">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="91dp"
android:layout_gravity="bottom"
android:background="@drawable/location_panel"
android:id="@+id/location_bottom_view">
<org.telegram.ui.Views.BackupImageView
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"/>
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"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginLeft="88dp"
android:layout_marginTop="20dp"
android:layout_marginRight="12dp"
android:id="@+id/location_name_label"
android:layout_gravity="top"
android:maxLines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginLeft="88dp"
android:layout_marginTop="20dp"
android:layout_marginRight="12dp"
android:id="@+id/location_name_label"
android:layout_gravity="top"
android:maxLines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="52dp"
android:layout_marginRight="12dp"
android:textColor="#999999"
android:id="@+id/location_distance_label"
android:layout_gravity="top"
android:maxLines="1"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="52dp"
android:layout_marginRight="12dp"
android:textColor="#999999"
android:id="@+id/location_distance_label"
android:layout_gravity="top"
android:maxLines="1"/>
</FrameLayout>
</FrameLayout>

View File

@ -14,7 +14,6 @@
android:indeterminateDuration="1200"
android:indeterminateOnly="true"
android:layout_gravity="center_vertical|left"
android:visibility="visible"
android:layout_marginLeft="12dp"/>
<ImageView android:layout_height="wrap_content"

View File

@ -5,4 +5,5 @@
<color name="gallery_background_color">#ff000000</color>
<color name="settings_background_color">#ffffffff</color>
<color name="divider">#dcdcdc</color>
<color name="header">#ff54759e</color>
</resources>

View File

@ -269,7 +269,7 @@
<string name="NotificationsServiceDisableInfo">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.</string>
<string name="SortBy">Sort By</string>
<string name="ImportContacts">Import Contacts</string>
<string name="WiFiOnly">via WiFi only</string>
<string name="WiFiOnly">Via WiFi only</string>
<string name="SortFirstName">First name</string>
<string name="SortLastName">Last name</string>

View File

@ -3,21 +3,16 @@
<!--THEMES-->
<style name="Theme.TMessages.Start" parent="Theme.AppCompat.Light">
<style name="Theme.TMessages.Start" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar.Transparent.TMessages.Start</item>
<item name="android:colorBackground">@android:color/white</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@drawable/shadow</item>
<item name="actionBarStyle">@style/ActionBar.Transparent.TMessages</item>
<item name="windowActionBarOverlay">false</item>
</style>
<style name="Theme.TMessages" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/ActionBar.Transparent.TMessages</item>
<item name="android:actionOverflowButtonStyle">@style/ActionBar.Transparent.TMessages.ActionButtonOverflow</item>
<item name="android:homeAsUpIndicator">@drawable/ab_icon_up_messages</item>
<item name="android:popupMenuStyle">@style/ActionBar.Transparent.TMessages.Popup</item>
<style name="Theme.TMessages" parent="@android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:colorBackground">@android:color/white</item>
<item name="android:windowBackground">@android:color/white</item>
@ -25,17 +20,7 @@
<item name="android:listViewStyle">@style/Theme.TMessages.ListView</item>
<item name="android:listChoiceBackgroundIndicator">@drawable/list_selector</item>
<item name="android:editTextStyle">@style/Theme.TMessages.EditText</item>
<item name="android:windowContentOverlay">@drawable/shadow</item>
<item name="android:actionBarItemBackground">@drawable/bar_selector</item>
<item name="searchViewSearchIcon">@android:color/transparent</item>
<item name="actionBarStyle">@style/ActionBar.Transparent.TMessages</item>
<item name="actionOverflowButtonStyle">@style/ActionBar.Transparent.TMessages.ActionButtonOverflow</item>
<item name="homeAsUpIndicator">@drawable/ab_icon_up_messages</item>
<item name="popupMenuStyle">@style/ActionBar.Transparent.TMessages.Popup</item>
<item name="windowActionBarOverlay">false</item>
<item name="listChoiceBackgroundIndicator">@drawable/list_selector</item>
<item name="actionBarItemBackground">@drawable/bar_selector</item>
</style>
<style name="Theme.TMessages.Gallery" parent="Theme.AppCompat">
@ -60,26 +45,14 @@
<!--ACTION BAR-->
<style name="ActionBar.Transparent.TMessages" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@drawable/header</item>
<item name="android:logo">@drawable/ic_launcher</item>
<item name="android:titleTextStyle">@style/ActionBar.Transparent.TMessages.Gallery.Title</item>
<item name="android:subtitleTextStyle">@style/ActionBar.Transparent.TMessages.Gallery.Subtitle</item>
<item name="background">@drawable/header</item>
<item name="logo">@drawable/ic_launcher</item>
<item name="titleTextStyle">@style/ActionBar.Transparent.TMessages.Gallery.Title</item>
<item name="subtitleTextStyle">@style/ActionBar.Transparent.TMessages.Gallery.Subtitle</item>
</style>
<style name="ActionBar.Transparent.TMessages.Start" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@drawable/header</item>
<style name="ActionBar.Transparent.TMessages.Start" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/header</item>
<item name="android:logo">@drawable/transparent</item>
<item name="android:titleTextStyle">@style/ActionBar.Transparent.TMessages.Gallery.Title</item>
<item name="android:subtitleTextStyle">@style/ActionBar.Transparent.TMessages.Gallery.Subtitle</item>
<item name="android:title">""</item>
<item name="background">@drawable/header</item>
<item name="background">@color/header</item>
<item name="logo">@drawable/transparent</item>
<item name="title">""</item>
<item name="titleTextStyle">@style/ActionBar.Transparent.TMessages.Gallery.Title</item>
@ -101,19 +74,10 @@
<item name="android:textSize">18sp</item>
</style>
<style name="ActionBar.Transparent.TMessages.ActionButtonOverflow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/ic_ab_other</item>
</style>
<style name="ActionBar.Transparent.TMessages.Gallery.ActionButtonOverflow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/ic_ab_other_white</item>
</style>
<style name="ActionBar.Transparent.TMessages.Popup" parent="Widget.AppCompat.Light.ListPopupWindow">
<item name="android:popupBackground">@drawable/popup_fixed</item>
<item name="android:dropDownSelector">@drawable/list_selector</item>
</style>
<style name="ActionBar.Transparent.TMessages.Gallery.Title" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#ffffffff</item>
</style>