Commit 288fceeb authored by DrKLO's avatar DrKLO

UI improvements

parent 2f23635e
...@@ -564,18 +564,30 @@ public class FileLoader { ...@@ -564,18 +564,30 @@ public class FileLoader {
if (message == null) { if (message == null) {
return new File(""); return new File("");
} }
if (message.media instanceof TLRPC.TL_messageMediaVideo) { if (message instanceof TLRPC.TL_messageService) {
return getPathToAttach(message.media.video); if (message.action.photo != null) {
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) { ArrayList<TLRPC.PhotoSize> sizes = message.action.photo.sizes;
return getPathToAttach(message.media.document); if (sizes.size() > 0) {
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) { TLRPC.PhotoSize sizeFull = getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize());
return getPathToAttach(message.media.audio); if (sizeFull != null) {
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) { return getPathToAttach(sizeFull);
ArrayList<TLRPC.PhotoSize> sizes = message.media.photo.sizes; }
if (sizes.size() > 0) { }
TLRPC.PhotoSize sizeFull = getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize()); }
if (sizeFull != null) { } else {
return getPathToAttach(sizeFull); if (message.media instanceof TLRPC.TL_messageMediaVideo) {
return getPathToAttach(message.media.video);
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
return getPathToAttach(message.media.document);
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
return getPathToAttach(message.media.audio);
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
ArrayList<TLRPC.PhotoSize> sizes = message.media.photo.sizes;
if (sizes.size() > 0) {
TLRPC.PhotoSize sizeFull = getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize());
if (sizeFull != null) {
return getPathToAttach(sizeFull);
}
} }
} }
} }
......
...@@ -10,10 +10,43 @@ package org.telegram.ui.Cells; ...@@ -10,10 +10,43 @@ package org.telegram.ui.Cells;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration;
public class BaseCell extends View { public class BaseCell extends View {
private final class CheckForTap implements Runnable {
public void run() {
if (pendingCheckForLongPress == null) {
pendingCheckForLongPress = new CheckForLongPress();
}
pendingCheckForLongPress.currentPressCount = ++pressCount;
postDelayed(pendingCheckForLongPress, ViewConfiguration.getLongPressTimeout() - ViewConfiguration.getTapTimeout());
}
}
class CheckForLongPress implements Runnable {
public int currentPressCount;
public void run() {
if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
checkingForLongPress = false;
MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
onTouchEvent(event);
event.recycle();
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
onLongPress();
}
}
}
private boolean checkingForLongPress = false;
private CheckForLongPress pendingCheckForLongPress = null;
private int pressCount = 0;
private CheckForTap pendingCheckForTap = null;
public BaseCell(Context context) { public BaseCell(Context context) {
super(context); super(context);
} }
...@@ -25,4 +58,29 @@ public class BaseCell extends View { ...@@ -25,4 +58,29 @@ public class BaseCell extends View {
protected void setDrawableBounds(Drawable drawable, int x, int y, int w, int h) { protected void setDrawableBounds(Drawable drawable, int x, int y, int w, int h) {
drawable.setBounds(x, y, x + w, y + h); drawable.setBounds(x, y, x + w, y + h);
} }
protected void startCheckLongPress() {
if (checkingForLongPress) {
return;
}
checkingForLongPress = true;
if (pendingCheckForTap == null) {
pendingCheckForTap = new CheckForTap();
}
postDelayed(pendingCheckForTap, ViewConfiguration.getTapTimeout());
}
protected void cancelCheckLongPress() {
checkingForLongPress = false;
if (pendingCheckForLongPress != null) {
removeCallbacks(pendingCheckForLongPress);
}
if (pendingCheckForTap != null) {
removeCallbacks(pendingCheckForTap);
}
}
protected void onLongPress() {
}
} }
...@@ -17,10 +17,8 @@ import android.text.Layout; ...@@ -17,10 +17,8 @@ import android.text.Layout;
import android.text.StaticLayout; import android.text.StaticLayout;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SoundEffectConstants; import android.view.SoundEffectConstants;
import android.view.ViewConfiguration;
import org.telegram.android.AndroidUtilities; import org.telegram.android.AndroidUtilities;
import org.telegram.android.ContactsController; import org.telegram.android.ContactsController;
...@@ -108,45 +106,13 @@ public class ChatBaseCell extends BaseCell { ...@@ -108,45 +106,13 @@ public class ChatBaseCell extends BaseCell {
private TLRPC.User currentForwardUser; private TLRPC.User currentForwardUser;
private String currentForwardNameString; private String currentForwardNameString;
public ChatBaseCellDelegate delegate; protected ChatBaseCellDelegate delegate;
protected int namesOffset = 0; protected int namesOffset = 0;
private boolean checkingForLongPress = false;
private int pressCount = 0;
private CheckForLongPress pendingCheckForLongPress = null;
private CheckForTap pendingCheckForTap = null;
private int last_send_state = 0; private int last_send_state = 0;
private int last_delete_date = 0; private int last_delete_date = 0;
private final class CheckForTap implements Runnable {
public void run() {
if (pendingCheckForLongPress == null) {
pendingCheckForLongPress = new CheckForLongPress();
}
pendingCheckForLongPress.currentPressCount = ++pressCount;
postDelayed(pendingCheckForLongPress, ViewConfiguration.getLongPressTimeout() - ViewConfiguration.getTapTimeout());
}
}
class CheckForLongPress implements Runnable {
public int currentPressCount;
public void run() {
if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
if (delegate != null) {
checkingForLongPress = false;
MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
onTouchEvent(event);
event.recycle();
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
delegate.didLongPressed(ChatBaseCell.this);
}
}
}
}
public ChatBaseCell(Context context) { public ChatBaseCell(Context context) {
super(context); super(context);
if (backgroundDrawableIn == null) { if (backgroundDrawableIn == null) {
...@@ -203,6 +169,10 @@ public class ChatBaseCell extends BaseCell { ...@@ -203,6 +169,10 @@ public class ChatBaseCell extends BaseCell {
invalidate(); invalidate();
} }
public void setDelegate(ChatBaseCellDelegate delegate) {
this.delegate = delegate;
}
public void setCheckPressed(boolean value, boolean pressed) { public void setCheckPressed(boolean value, boolean pressed) {
isCheckPressed = value; isCheckPressed = value;
isPressed = pressed; isPressed = pressed;
...@@ -345,27 +315,6 @@ public class ChatBaseCell extends BaseCell { ...@@ -345,27 +315,6 @@ public class ChatBaseCell extends BaseCell {
return backgroundWidth - AndroidUtilities.dp(8); return backgroundWidth - AndroidUtilities.dp(8);
} }
protected void startCheckLongPress() {
if (checkingForLongPress) {
return;
}
checkingForLongPress = true;
if (pendingCheckForTap == null) {
pendingCheckForTap = new CheckForTap();
}
postDelayed(pendingCheckForTap, ViewConfiguration.getTapTimeout());
}
protected void cancelCheckLongPress() {
checkingForLongPress = false;
if (pendingCheckForLongPress != null) {
removeCallbacks(pendingCheckForLongPress);
}
if (pendingCheckForTap != null) {
removeCallbacks(pendingCheckForTap);
}
}
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
boolean result = false; boolean result = false;
...@@ -462,6 +411,13 @@ public class ChatBaseCell extends BaseCell { ...@@ -462,6 +411,13 @@ public class ChatBaseCell extends BaseCell {
} }
@Override
protected void onLongPress() {
if (delegate != null) {
delegate.didLongPressed(this);
}
}
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
if (currentMessageObject == null) { if (currentMessageObject == null) {
......
...@@ -93,7 +93,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -93,7 +93,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private int nameWidth = 0; private int nameWidth = 0;
private String currentNameString; private String currentNameString;
public ChatMediaCellDelegate mediaDelegate = null; private ChatMediaCellDelegate mediaDelegate = null;
private float currentProgress = 0; private float currentProgress = 0;
private RectF progressRect = new RectF(); private RectF progressRect = new RectF();
...@@ -165,6 +165,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -165,6 +165,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} }
} }
public void setMediaDelegate(ChatMediaCellDelegate delegate) {
this.mediaDelegate = delegate;
}
@Override @Override
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
......
...@@ -661,12 +661,11 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -661,12 +661,11 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
actionBarLayout.presentFragment(fragment, false, true, true); actionBarLayout.presentFragment(fragment, false, true, true);
} }
Bundle args2 = new Bundle(); if (!fragment.openVideoEditor(videoPath, true, actionBarLayout)) {
args2.putString("videoPath", videoPath); if (!AndroidUtilities.isTablet()) {
VideoEditorActivity fragment2 = new VideoEditorActivity(args2); actionBarLayout.presentFragment(fragment, true);
fragment2.setDelegate(fragment); }
presentFragment(fragment2, true, true); } else if (!AndroidUtilities.isTablet()) {
if (!AndroidUtilities.isTablet()) {
actionBarLayout.addFragmentToStack(fragment, actionBarLayout.fragmentsStack.size() - 1); actionBarLayout.addFragmentToStack(fragment, actionBarLayout.fragmentsStack.size() - 1);
} }
} else { } else {
......
...@@ -207,7 +207,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> { ...@@ -207,7 +207,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
v = list.poll(); v = list.poll();
} }
View child = mAdapter.getView(mRightViewIndex, v, this); View child = mAdapter.getView(mRightViewIndex, v, this);
child.setTag(1, type); child.setTag(type);
addAndMeasureChild(child, -1); addAndMeasureChild(child, -1);
rightEdge += child.getMeasuredWidth(); rightEdge += child.getMeasuredWidth();
...@@ -234,7 +234,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> { ...@@ -234,7 +234,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
v = list.poll(); v = list.poll();
} }
View child = mAdapter.getView(mLeftViewIndex, v, this); View child = mAdapter.getView(mLeftViewIndex, v, this);
child.setTag(1, type); child.setTag(type);
addAndMeasureChild(child, 0); addAndMeasureChild(child, 0);
leftEdge -= child.getMeasuredWidth(); leftEdge -= child.getMeasuredWidth();
...@@ -248,7 +248,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> { ...@@ -248,7 +248,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
while (child != null && child.getRight() + dx <= 0) { while (child != null && child.getRight() + dx <= 0) {
mDisplayOffset += child.getMeasuredWidth(); mDisplayOffset += child.getMeasuredWidth();
int type = (Integer) child.getTag(1); int type = (Integer) child.getTag();
LinkedList<View> list = mRemovedViewQueue.get(type); LinkedList<View> list = mRemovedViewQueue.get(type);
if (list == null) { if (list == null) {
list = new LinkedList<View>(); list = new LinkedList<View>();
...@@ -263,7 +263,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> { ...@@ -263,7 +263,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
child = getChildAt(getChildCount() - 1); child = getChildAt(getChildCount() - 1);
while (child != null && child.getLeft() + dx >= getWidth()) { while (child != null && child.getLeft() + dx >= getWidth()) {
int type = (Integer) child.getTag(1); int type = (Integer) child.getTag();
LinkedList<View> list = mRemovedViewQueue.get(type); LinkedList<View> list = mRemovedViewQueue.get(type);
if (list == null) { if (list == null) {
list = new LinkedList<View>(); list = new LinkedList<View>();
......
/*
* 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.widget.FrameLayout;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
public class MessageActionLayout extends FrameLayout {
public TightTextView messageTextView;
public MessageActionLayout(android.content.Context context) {
super(context);
}
public MessageActionLayout(android.content.Context context, android.util.AttributeSet attrs) {
super(context, attrs);
}
public MessageActionLayout(android.content.Context context, android.util.AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(messageTextView.linesMaxWidth + AndroidUtilities.dp(14), getMeasuredHeight());
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
messageTextView = (TightTextView)findViewById(R.id.chat_message_text);
}
}
/*
* 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.Context;
import android.text.Layout;
import android.util.AttributeSet;
import android.widget.TextView;
import org.telegram.messenger.FileLog;
public class TightTextView extends TextView {
private boolean hasMaxWidth;
public int maxWidth;
public int lastLineWidth = 0;
public int linesMaxWidth = 0;
public int lines = 0;
public TightTextView(Context context) {
this(context, null, 0);
}
public TightTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TightTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
Layout layout = getLayout();
lines = layout.getLineCount();
float lastLeft = layout.getLineLeft(lines - 1);
float lastLine = layout.getLineWidth(lines - 1);
int lastLineWidthWithLeft;
int linesMaxWidthWithLeft;
boolean hasNonRTL = false;
linesMaxWidth = lastLineWidth = (int)Math.ceil(lastLine);
linesMaxWidthWithLeft = lastLineWidthWithLeft = (int)Math.ceil(lastLine + lastLeft);
if (lastLeft == 0) {
hasNonRTL = true;
}
if (hasMaxWidth) {
int specModeW = MeasureSpec.getMode(widthMeasureSpec);
if (specModeW != MeasureSpec.EXACTLY) {
if (lines > 1) {
float textRealMaxWidth = 0, textRealMaxWidthWithLeft = 0;
for (int n = 0; n < lines; ++n) {
float lineWidth;
float lineLeft;
try {
lineWidth = layout.getLineWidth(n);
lineLeft = layout.getLineLeft(n);
} catch (Exception e) {
FileLog.e("tmessages", e);
return;
}
if (lineLeft == 0) {
hasNonRTL = true;
}
textRealMaxWidth = Math.max(textRealMaxWidth, lineWidth);
textRealMaxWidthWithLeft = Math.max(textRealMaxWidthWithLeft, lineWidth + lineLeft);
linesMaxWidth = Math.max(linesMaxWidth, (int)Math.ceil(lineWidth));
linesMaxWidthWithLeft = Math.max(linesMaxWidthWithLeft, (int)Math.ceil(lineWidth + lineLeft));
}
if (hasNonRTL) {
textRealMaxWidth = textRealMaxWidthWithLeft;
lastLineWidth = lastLineWidthWithLeft;
linesMaxWidth = linesMaxWidthWithLeft;
} else {
lastLineWidth = linesMaxWidth;
}
int w = (int)Math.ceil(textRealMaxWidth);
if (w < getMeasuredWidth()) {
super.onMeasure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.AT_MOST), heightMeasureSpec);
}
} else {
super.onMeasure(MeasureSpec.makeMeasureSpec(Math.min(maxWidth, linesMaxWidth), MeasureSpec.AT_MOST), heightMeasureSpec);
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
try {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} catch (Exception e2) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
FileLog.e("tmessages", e2);
}
}
}
@Override
public void setMaxWidth(int maxpixels) {
super.setMaxWidth(maxpixels);
hasMaxWidth = true;
maxWidth = maxpixels;
}
@Override
public void setMaxEms(int maxems) {
super.setMaxEms(maxems);
hasMaxWidth = true;
}
}
/*
* This is the source code of Telegram for Android v. 1.7.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;
import android.text.TextPaint;
import android.text.style.URLSpan;
public class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="5dp"
android:gravity="center"
android:layout_gravity="top">
<org.telegram.ui.Views.MessageActionLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:id="@+id/message_action_layout">
<org.telegram.ui.Views.TightTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:id="@+id/chat_message_text"
android:textColor="#ffffff"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:ellipsize="none"
android:gravity="center"
android:maxLines="10"
android:maxWidth="380dp"
android:layout_gravity="center"/>
</org.telegram.ui.Views.MessageActionLayout>
<org.telegram.ui.Views.BackupImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginTop="5dp"
android:id="@+id/chat_photo_image"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:gravity="center"
android:layout_gravity="top">
<org.telegram.ui.Views.MessageActionLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:id="@+id/message_action_layout">
<org.telegram.ui.Views.TightTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:id="@+id/chat_message_text"
android:textColor="#ffffff"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:ellipsize="none"
android:gravity="center"
android:maxLines="10"
android:layout_gravity="center"/>
</org.telegram.ui.Views.MessageActionLayout>
</LinearLayout>
\ 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