Commit 92e1b050 authored by DrKLO's avatar DrKLO

Improved back swipe, new photo viewer(not finished, disabed) bug fixes

parent cdb39ac3
......@@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 238
versionCode 240
versionName "1.4.15"
}
}
......@@ -1603,7 +1603,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
}
@SuppressWarnings("unused")
ByteBufferDesc createConnectionData(ArrayList<NetworkMessage> messages, ArrayList<Integer> quickAckId, TcpConnection connection) {
Datacenter datacenter = datacenterWithId(connection.getDatacenterId());
if (datacenter.authKey == null) {
......
......@@ -433,7 +433,12 @@ public class ContactsController {
FileLog.e("tmessages", "detected account deletion!");
currentAccount = new Account(UserConfig.currentUser.phone, "org.telegram.account");
am.addAccountExplicitly(currentAccount, "", null);
performWriteContactsToPhoneBookInternal();
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
performWriteContactsToPhoneBook();
}
});
}
}
} catch (Exception e) {
......@@ -1149,7 +1154,7 @@ public class ContactsController {
sortedUsersSectionsArray = sortedSectionsArray;
}
private void performWriteContactsToPhoneBookInternal() {
private void performWriteContactsToPhoneBookInternal(ArrayList<TLRPC.TL_contact> contactsArray) {
try {
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
......@@ -1160,7 +1165,7 @@ public class ContactsController {
}
c1.close();
for (TLRPC.TL_contact u : contacts) {
for (TLRPC.TL_contact u : contactsArray) {
if (!bookContacts.containsKey(u.user_id)) {
TLRPC.User user = MessagesController.getInstance().users.get(u.user_id);
addContactToPhoneBook(user, false);
......@@ -1173,10 +1178,12 @@ public class ContactsController {
}
private void performWriteContactsToPhoneBook() {
final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<TLRPC.TL_contact>();
contactsArray.addAll(contacts);
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public void run() {
performWriteContactsToPhoneBookInternal();
performWriteContactsToPhoneBookInternal(contactsArray);
}
});
}
......
......@@ -11,9 +11,10 @@ package org.telegram.messenger;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
public class DispatchQueue extends Thread {
public Handler handler;
public volatile Handler handler = null;
private final Object handlerSyncObject = new Object();
public DispatchQueue(final String threadName) {
......@@ -47,12 +48,14 @@ public class DispatchQueue extends Thread {
public void postRunnable(Runnable runnable, int delay) {
if (handler == null) {
try {
synchronized (handlerSyncObject) {
handlerSyncObject.wait();
synchronized (handlerSyncObject) {
if (handler == null) {
try {
handlerSyncObject.wait();
} catch (Throwable t) {
t.printStackTrace();
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
......@@ -67,8 +70,8 @@ public class DispatchQueue extends Thread {
public void run() {
Looper.prepare();
handler = new Handler();
synchronized (handlerSyncObject) {
handler = new Handler();
handlerSyncObject.notify();
}
Looper.loop();
......
......@@ -3403,7 +3403,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ConnectionsManager.getInstance().connectionState = 0;
processUpdatesQueue(true);
} else if (res instanceof TLRPC.TL_updates_differenceSlice) {
//MessagesStorage.lastSeqValue = res.intermediate_state.seq;
MessagesStorage.lastDateValue = res.intermediate_state.date;
MessagesStorage.lastPtsValue = res.intermediate_state.pts;
MessagesStorage.lastQtsValue = res.intermediate_state.qts;
......@@ -3424,8 +3423,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
} else {
gettingDifference = false;
getDifference();
FileLog.e("tmessages", "get difference error, don't know what to do :(");
ConnectionsManager.getInstance().connectionState = 0;
final int stateCopy = ConnectionsManager.getInstance().connectionState;
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(703, stateCopy);
}
});
}
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
......
......@@ -8,8 +8,6 @@
package org.telegram.messenger;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.Html;
import android.util.SparseArray;
......@@ -40,8 +38,6 @@ public class MessagesStorage {
public static final int wallpapersDidLoaded = 171;
private boolean appliedDialogFix = false;
private static volatile MessagesStorage Instance = null;
public static MessagesStorage getInstance() {
MessagesStorage localInstance = Instance;
......@@ -66,22 +62,10 @@ public class MessagesStorage {
cacheFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache4.db");
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dbconfig", Context.MODE_PRIVATE);
appliedDialogFix = preferences.getBoolean("appliedDialogFix", false);
boolean createTable = false;
//cacheFile.delete();
if (!cacheFile.exists()) {
createTable = true;
try {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("appliedDialogFix", true);
appliedDialogFix = true;
editor.commit();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
try {
database = new SQLiteDatabase(cacheFile.getPath());
......@@ -202,66 +186,11 @@ public class MessagesStorage {
cacheFile.delete();
cacheFile = null;
}
try {
File old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache.db");
if (old.exists()) {
old.delete();
}
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache2.db");
if (old.exists()) {
old.delete();
}
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache3.db");
if (old.exists()) {
old.delete();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
openDatabase();
}
});
}
public void applyDialogsFix() { //server bug on 20.02.2014
if (!appliedDialogFix) {
try {
SQLiteCursor cursor = database.queryFinalized("SELECT d.did, m.data FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid WHERE m.mid < 0 AND m.date >= 1392930900 AND m.date <= 1392935700");
String dids = "";
while (cursor.next()) {
long did = cursor.longValue(0);
byte[] messageData = cursor.byteArrayValue(1);
if (messageData != null) {
SerializedData data = new SerializedData(messageData);
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (message != null) {
if (message.action != null && message.action instanceof TLRPC.TL_messageActionUserJoined) {
if (dids.length() != 0) {
dids += ",";
}
dids += "" + did;
}
}
}
}
cursor.dispose();
if (dids.length() != 0) {
database.executeFast("DELETE FROM dialogs WHERE did IN(" + dids + ")").stepThis().dispose();
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dbconfig", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("appliedDialogFix", true);
appliedDialogFix = true;
editor.commit();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
public void saveSecretParams(final int lsv, final int sg, final byte[] pbytes) {
storageQueue.postRunnable(new Runnable() {
@Override
......
......@@ -90,6 +90,10 @@ public class TcpConnection extends ConnectionContext {
connectionState = TcpConnectionState.TcpConnectionStageConnecting;
try {
Datacenter datacenter = ConnectionsManager.getInstance().datacenterWithId(datacenterId);
hostAddress = datacenter.getCurrentAddress();
hostPort = datacenter.getCurrentPort();
if(android.os.Build.VERSION.SDK_INT < 11) {
if (!ConnectionsManager.isNetworkOnline() && !tryWithNoNetworkAnyway) {
handleConnectionError(null);
......@@ -108,9 +112,7 @@ public class TcpConnection extends ConnectionContext {
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
Datacenter datacenter = ConnectionsManager.getInstance().datacenterWithId(datacenterId);
hostAddress = datacenter.getCurrentAddress();
hostPort = datacenter.getCurrentPort();
FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort));
firstPacket = true;
if (restOfTheData != null) {
......@@ -292,6 +294,7 @@ public class TcpConnection extends ConnectionContext {
}
if (client == null || client.isDisconnected()) {
BuffersStorage.getInstance().reuseFreeBuffer(buff);
return;
}
......
......@@ -39,7 +39,7 @@ import java.util.Locale;
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
public static interface ChatMediaCellDelegate {
public abstract void didPressedImage(ChatBaseCell cell);
public abstract void didPressedImage(ChatMediaCell cell, ImageReceiver imageReceiver);
}
private static Drawable placeholderInDrawable;
......@@ -196,7 +196,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (currentMessageObject.type == 1) {
if (buttonState == -1) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
mediaDelegate.didPressedImage(this, photoImage);
}
} else if (buttonState == 0) {
didPressedButton();
......@@ -217,7 +217,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
} else if (currentMessageObject.type == 4) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
mediaDelegate.didPressedImage(this, photoImage);
}
}
}
......@@ -271,7 +271,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
} else if (buttonState == 3) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this);
mediaDelegate.didPressedImage(this, photoImage);
}
}
}
......@@ -545,6 +545,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
canvas.restore();
} else {
photoImage.draw(canvas, photoImage.imageX, photoImage.imageY, photoWidth, photoHeight);
drawTime = photoImage.getVisible();
}
if (progressVisible) {
......
......@@ -191,7 +191,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
}
}
});
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
return true;
}
......@@ -269,7 +269,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
}
});
......@@ -585,7 +585,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
processPhotoMenu(action);
}
});
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
} else {
......@@ -709,7 +709,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
}
......
......@@ -307,7 +307,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
}
}
......@@ -346,7 +346,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(R.string.Cancel, null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else {
if (delegate != null) {
delegate.didSelectContact(user);
......
......@@ -200,7 +200,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
}
}
});
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
......
......@@ -93,6 +93,12 @@ public class IdenticonActivity extends BaseFragment {
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (fragmentView != null) {
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
}
if (getParentActivity() == null) {
return true;
}
LinearLayout layout = (LinearLayout)fragmentView;
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
......@@ -104,8 +110,6 @@ public class IdenticonActivity extends BaseFragment {
}
fragmentView.setPadding(fragmentView.getPaddingLeft(), 0, fragmentView.getPaddingRight(), fragmentView.getPaddingBottom());
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
......
......@@ -166,7 +166,7 @@ public class LanguageSelectActivity extends BaseFragment {
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
return true;
}
});
......
......@@ -168,6 +168,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
}
handleIntent(getIntent(), false, savedInstanceState != null);
PhotoViewer.getInstance().setParentActivity(this);
}
private void handleIntent(Intent intent, boolean isNew, boolean restore) {
......@@ -744,4 +746,22 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
FileLog.e("tmessages", e);
}
}
@Override
public void onBackPressed() {
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto();
} else {
super.onBackPressed();
}
}
@Override
public boolean onPreIme() {
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto();
return true;
}
return super.onPreIme();
}
}
......@@ -215,7 +215,7 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(text);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
}
......
......@@ -337,7 +337,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
});
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
return true;
}
});
......@@ -487,7 +487,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(R.string.Cancel, null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else {
if (delegate != null) {
delegate.didSelectDialog(MessagesActivity.this, dialog_id);
......
This diff is collapsed.
......@@ -254,7 +254,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else if (i == enableAnimationsRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
......@@ -286,7 +286,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else if (i == sendLogsRow) {
sendLogs();
} else if (i == clearLogsRow) {
......@@ -325,7 +325,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else if (i == languageRow) {
presentFragment(new LanguageSelectActivity());
} else if (i == switchBackendButtonRow) {
......@@ -339,7 +339,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else if (i == telegramFaqRow) {
try {
Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)));
......@@ -369,7 +369,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else if (i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
......@@ -398,7 +398,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
}
});
......@@ -547,7 +547,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
@Override
public void onResume() {
super.onResume();
showActionBar();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
......@@ -696,7 +695,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
}
});
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
}
......@@ -844,12 +843,14 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
public void onClick(DialogInterface dialogInterface, int i) {
NotificationCenter.getInstance().postNotificationName(1234);
MessagesController.getInstance().unregistedPush();
listView.setAdapter(null);
MessagesStorage.getInstance().cleanUp();
MessagesController.getInstance().cleanUp();
ConnectionsManager.getInstance().cleanUp();
UserConfig.clearConfig();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
}
......
......@@ -151,7 +151,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
}
}
});
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
return true;
}
......
......@@ -279,7 +279,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
}
}
......
......@@ -96,62 +96,15 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
@Override
public View createView(LayoutInflater inflater, ViewGroup container) {
if (fragmentView == null) {
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false);
listAdapter = new ListAdapter(getParentActivity());
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
listView = (HorizontalListView)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 (i == 0) {
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 (i == 0) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = Utilities.generatePicturePath();
if (image != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
getParentActivity().startActivityForResult(takePictureIntent, 10);
} else if (i == 1) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
getParentActivity().startActivityForResult(photoPickerIntent, 11);
}
}
});
builder.show().setCanceledOnTouchOutside(true);
} else {
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
selectedBackground = wallPaper.id;
listAdapter.notifyDataSetChanged();
processSelectedBackground();
}
}
});
TextView textView = (TextView)fragmentView.findViewById(R.id.done_button_text);
textView.setText(LocaleController.getString("Set", R.string.Set));
Button cancelButton = (Button)fragmentView.findViewById(R.id.cancel_button);
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel));
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 = fragmentView.findViewById(R.id.done_button);
doneButton = actionBarLayer.findViewById(R.id.done_button);
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......@@ -190,6 +143,53 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
}
});
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel));
TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text);
textView.setText(LocaleController.getString("Set", R.string.Set));
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false);
listAdapter = new ListAdapter(getParentActivity());
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
listView = (HorizontalListView)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 (i == 0) {
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 (i == 0) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = Utilities.generatePicturePath();
if (image != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
getParentActivity().startActivityForResult(takePictureIntent, 10);
} else if (i == 1) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
getParentActivity().startActivityForResult(photoPickerIntent, 11);
}
}
});
showAlertDialog(builder);
} else {
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
selectedBackground = wallPaper.id;
listAdapter.notifyDataSetChanged();
processSelectedBackground();
}
}
});
processSelectedBackground();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
......@@ -428,7 +428,6 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
hideActionBar();
processSelectedBackground();
fixLayout();
}
......
......@@ -194,7 +194,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
}
});
......@@ -222,7 +222,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
if (dialog_id == 0) {
......@@ -268,7 +268,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
} else if (i == settingsSoundRow) {
try {
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
......@@ -351,7 +351,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
}
});
......@@ -633,7 +633,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
}
});
builder.show().setCanceledOnTouchOutside(true);
showAlertDialog(builder);
}
});
}
......
......@@ -32,6 +32,7 @@ public class ActionBar extends FrameLayout {
private View currentBackOverlay;
private View shadowView = null;
private int currentBackOverlayWidth;
protected int itemsBackgroundResourceId;
public ActionBar(Context context) {
super(context);
......@@ -139,7 +140,6 @@ public class ActionBar extends FrameLayout {
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.MATCH_PARENT;
layer.setLayoutParams(layoutParams);
currentLayer.setBackgroundDrawable(getBackground());
shadowView.setX(-Utilities.dp(2));
shadowView.setVisibility(VISIBLE);
}
......@@ -148,7 +148,6 @@ public class ActionBar extends FrameLayout {
if (currentLayer == null) {
return;
}
currentLayer.setBackgroundDrawable(null);
currentLayer.setX(0);
if (!backAnimation) {
removeView(currentLayer);
......@@ -206,4 +205,8 @@ public class ActionBar extends FrameLayout {
currentLayer.onMenuButtonPressed();
}
}
public void setItemsBackground(int resourceId) {
itemsBackgroundResourceId = resourceId;
}
}
......@@ -37,7 +37,7 @@ public class ActionBarLayer extends FrameLayout {
private TextView subTitleTextView;
private ActionBarMenu menu;
private ActionBarMenu actionMode;
private ActionBar parentActionBar;
protected ActionBar parentActionBar;
private boolean oldUseLogo;
private boolean oldUseBack;
private boolean isBackLayoutHidden = false;
......@@ -53,8 +53,8 @@ public class ActionBarLayer extends FrameLayout {
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.setBackgroundResource(actionBar.itemsBackgroundResourceId);
backButtonFrameLayout.setPadding(0, 0, Utilities.dp(4), 0);
backButtonFrameLayout.setOnClickListener(new OnClickListener() {
@Override
......@@ -432,6 +432,16 @@ public class ActionBarLayer extends FrameLayout {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public void setAlpha(float alpha) {
if (menu != null) {
menu.setAlpha(alpha);
}
if (backButtonFrameLayout != null) {
backButtonFrameLayout.setAlpha(alpha);
}
}
public void onMenuButtonPressed() {
if (menu != null) {
menu.onMenuButtonPressed();
......
......@@ -16,7 +16,6 @@ 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 {
......@@ -50,7 +49,7 @@ public class ActionBarMenu extends LinearLayout {
addView(view);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams();
layoutParams.height = FrameLayout.LayoutParams.FILL_PARENT;
view.setBackgroundResource(R.drawable.bar_selector);
view.setBackgroundResource(parentActionBar.itemsBackgroundResourceId);
view.setLayoutParams(layoutParams);
view.setOnClickListener(new OnClickListener() {
@Override
......
......@@ -48,7 +48,7 @@ public class ActionBarMenuItem extends ImageView {
public ActionBarMenuItem(Context context, ActionBarMenu menu, ActionBar actionBar) {
super(context);
setBackgroundResource(R.drawable.bar_selector);
setBackgroundResource(actionBar.itemsBackgroundResourceId);
parentMenu = menu;
parentActionBar = actionBar;
}
......
......@@ -8,6 +8,8 @@
package org.telegram.ui.Views.ActionBar;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
......@@ -15,6 +17,8 @@ import android.view.View;
import android.view.ViewGroup;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
public class BaseFragment {
private boolean isFinished = false;
......@@ -23,6 +27,7 @@ public class BaseFragment {
protected ActionBarLayer actionBarLayer;
protected int classGuid = 0;
protected Bundle arguments;
private AlertDialog visibleDialog = null;
public BaseFragment() {
classGuid = ConnectionsManager.getInstance().generateClassGuid();
......@@ -54,9 +59,9 @@ public class BaseFragment {
if (parentActivity != null) {
if (actionBarLayer != null) {
actionBarLayer.onDestroy();
actionBarLayer = null;
}
actionBarLayer = parentActivity.getInternalActionBar().createLayer();
actionBarLayer.setBackgroundResource(R.color.header);
}
}
}
......@@ -96,6 +101,14 @@ public class BaseFragment {
actionBarLayer.onPause();
actionBarLayer.closeSearchField();
}
try {
if (visibleDialog != null && visibleDialog.isShowing()) {
visibleDialog.dismiss();
visibleDialog = null;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
......@@ -156,7 +169,17 @@ public class BaseFragment {
}
public void onBeginSlide() {
try {
if (visibleDialog != null && visibleDialog.isShowing()) {
visibleDialog.dismiss();
visibleDialog = null;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (actionBarLayer != null) {
actionBarLayer.onPause();
}
}
public void onOpenAnimationEnd() {
......@@ -166,4 +189,22 @@ public class BaseFragment {
public void onLowMemory() {
}
protected void showAlertDialog(AlertDialog.Builder builder) {
if (parentActivity == null || parentActivity.checkTransitionAnimation() || parentActivity.animationInProgress || parentActivity.startedTracking) {
return;
}
if (visibleDialog != null && visibleDialog.isShowing()) {
visibleDialog.dismiss();
visibleDialog = null;
}
visibleDialog = builder.show();
visibleDialog.setCanceledOnTouchOutside(true);
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
visibleDialog = null;
}
});
}
}
......@@ -10,6 +10,7 @@ package org.telegram.ui.Views;
import java.util.HashMap;
import java.util.LinkedList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Rect;
......@@ -139,6 +140,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
@SuppressLint("DrawAllocation")
@Override
protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
......@@ -308,6 +310,12 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
return handled;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
requestDisallowInterceptTouchEvent(true);
return super.onInterceptTouchEvent(ev);
}
protected boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
synchronized(HorizontalListView.this){
......
......@@ -10,6 +10,7 @@ package org.telegram.ui.Views;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
......@@ -34,6 +35,8 @@ public class ImageReceiver {
public Integer TAG = null;
public WeakReference<View> parentView = null;
public int imageX = 0, imageY = 0, imageW = 0, imageH = 0;
public Rect drawRegion = new Rect();
private boolean isVisible = true;
private boolean selfSetting = false;
public void setImage(TLRPC.FileLocation path, String filter, Drawable placeholder) {
......@@ -172,6 +175,9 @@ public class ImageReceiver {
}
public void draw(Canvas canvas, int x, int y, int w, int h) {
if (!isVisible) {
return;
}
try {
if (currentImage != null) {
int bitmapW = currentImage.getIntrinsicWidth();
......@@ -179,27 +185,29 @@ public class ImageReceiver {
float scaleW = bitmapW / (float)w;
float scaleH = bitmapH / (float)h;
if (Math.abs(scaleW - scaleH) > 0.05f) {
if (Math.abs(scaleW - scaleH) > 0.00001f) {
canvas.save();
canvas.clipRect(x, y, x + w, y + h);
if (bitmapW / scaleH > w) {
bitmapW /= scaleH;
currentImage.setBounds(x - (bitmapW - w) / 2, y, x + (bitmapW + w) / 2, y + h);
drawRegion.set(x - (bitmapW - w) / 2, y, x + (bitmapW + w) / 2, y + h);
} else {
bitmapH /= scaleW;
currentImage.setBounds(x, y - (bitmapH - h) / 2, x + w, y + (bitmapH + h) / 2);
drawRegion.set(x, y - (bitmapH - h) / 2, x + w, y + (bitmapH + h) / 2);
}
currentImage.setBounds(drawRegion);
currentImage.draw(canvas);
canvas.restore();
} else {
currentImage.setBounds(x, y, x + w, y + h);
drawRegion.set(x, y, x + w, y + h);
currentImage.setBounds(drawRegion);
currentImage.draw(canvas);
}
} else if (last_placeholder != null) {
last_placeholder.setBounds(x, y, x + w, y + h);
drawRegion.set(x, y, x + w, y + h);
last_placeholder.setBounds(drawRegion);
last_placeholder.draw(canvas);
}
} catch (Exception e) {
......@@ -211,4 +219,28 @@ public class ImageReceiver {
FileLog.e("tmessages", e);
}
}
public Bitmap getBitmap() {
if (currentImage != null && currentImage instanceof BitmapDrawable) {
return ((BitmapDrawable)currentImage).getBitmap();
} else if (isPlaceholder && last_placeholder != null && last_placeholder instanceof BitmapDrawable) {
return ((BitmapDrawable)last_placeholder).getBitmap();
}
return null;
}
public void setVisible(boolean value) {
if (isVisible == value) {
return;
}
isVisible = value;
View parent = parentView.get();
if (parent != null) {
parent.invalidate();
}
}
public boolean getVisible() {
return isVisible;
}
}
<!--
~ 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.
-->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#40ffffff" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#40ffffff" />
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#40ffffff" />
</shape>
</item>
<item android:drawable="@drawable/transparent" />
</selector>
\ No newline at end of file
......@@ -7,8 +7,7 @@
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:scaleType="centerCrop"
android:id="@+id/background_image"
android:layout_marginBottom="48dp"/>
android:id="@+id/background_image"/>
<ProgressBar
android:background="#99000000"
......@@ -27,56 +26,6 @@
android:id="@+id/listView"
android:clipToPadding="false"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:layout_marginBottom="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_gravity="bottom">
<Button
android:textSize="12dp"
android:textColor="#111111"
android:id="@+id/cancel_button"
android:background="@drawable/list_selector"
android:paddingLeft="3dp"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:textAllCaps="true"
android:layout_weight="1.0"
android:textStyle="bold"/>
<View
android:layout_gravity="center_vertical"
android:background="#c9c9c9"
android:layout_width="1px"
android:layout_height="28dp" />
<FrameLayout
android:id="@+id/done_button"
android:background="@drawable/list_selector"
android:paddingRight="3dp"
android:clickable="true"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0">
<TextView
android:textSize="12dp"
android:textColor="#111111"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:id="@+id/done_button_text"
android:drawableLeft="@drawable/ic_ab_done_gray"
android:drawablePadding="8dp"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>
android:paddingRight="40dp"/>
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment