Fixed screen orientation lock on tablets, more bug fixes

https://github.com/DrKLO/Telegram/pull/453
This commit is contained in:
DrKLO 2014-06-13 22:26:05 +04:00
parent fc14e8b4f7
commit 19ba20cdab
8 changed files with 117 additions and 77 deletions

View File

@ -81,7 +81,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 252
versionName "1.5.1"
versionCode 253
versionName "1.5.2"
}
}

View File

@ -4529,7 +4529,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
notification.ledOnMS = 1000;
notification.ledOffMS = 1000;
if (needVibrate) {
notification.defaults = Notification.DEFAULT_VIBRATE;
notification.vibrate = new long[]{0, 100, 0, 100};
} else {
notification.vibrate = new long[]{0, 0};

View File

@ -15,6 +15,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Point;
@ -166,19 +167,47 @@ public class Utilities {
WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
if (manager != null && manager.getDefaultDisplay() != null) {
int rotation = manager.getDefaultDisplay().getRotation();
int orientation = activity.getResources().getConfiguration().orientation;
if (rotation == Surface.ROTATION_270) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
} else if (rotation == Surface.ROTATION_90) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_90) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (rotation == Surface.ROTATION_0) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}
}

View File

@ -2859,7 +2859,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
public void createMenu(View v, boolean single) {
if (actionBarLayer.isActionModeShowed()) {
if (getParentActivity() == null || actionBarLayer.isActionModeShowed()) {
return;
}

View File

@ -101,6 +101,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private boolean overlayViewVisible = true;
private int animationInProgress = 0;
private PlaceProviderObject showAfterAnimation;
private PlaceProviderObject hideAfterAnimation;
private boolean disableShowCheck = false;
private Animation.AnimationListener animationListener;
@ -327,6 +329,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (setToImage != -1) {
setImageIndex(setToImage, true);
} else {
imagesArrLocations.add(0, currentFileLocation);
setImageIndex(0, true);
}
if (fromCache) {
@ -1147,15 +1150,20 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
if (!init) {
if (android.os.Build.VERSION.SDK_INT >= 11 && currentPlaceObject != null) {
if (android.os.Build.VERSION.SDK_INT >= 11 && currentPlaceObject != null) {
if (animationInProgress == 0) {
currentPlaceObject.imageReceiver.setVisible(true, true);
} else {
showAfterAnimation = currentPlaceObject;
}
}
currentPlaceObject = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation, currentIndex);
if (!init) {
if (android.os.Build.VERSION.SDK_INT >= 11 && currentPlaceObject != null) {
if (android.os.Build.VERSION.SDK_INT >= 11 && currentPlaceObject != null) {
if (animationInProgress == 0) {
currentPlaceObject.imageReceiver.setVisible(false, true);
} else {
hideAfterAnimation = currentPlaceObject;
}
}
@ -1343,6 +1351,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
disableShowCheck = true;
animationInProgress = 1;
onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
isVisible = true;
backgroundDrawable.setAlpha(255);
@ -1352,8 +1361,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if(android.os.Build.VERSION.SDK_INT >= 11) {
Utilities.lockOrientation(parentActivity);
animationInProgress = 1;
animatingImageView.setVisibility(View.VISIBLE);
animatingImageView.setImageBitmap(object.thumb);
@ -1419,6 +1426,12 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
containerView.invalidate();
animatingImageView.setVisibility(View.GONE);
Utilities.unlockOrientation(parentActivity);
if (showAfterAnimation != null) {
showAfterAnimation.imageReceiver.setVisible(true, true);
}
if (hideAfterAnimation != null) {
hideAfterAnimation.imageReceiver.setVisible(false, true);
}
}
});
animatorSet.start();
@ -1437,6 +1450,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
});
} else {
animationInProgress = 0;
containerView.invalidate();
AnimationSet animationSet = new AnimationSet(true);
AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);

View File

@ -40,9 +40,21 @@ import java.util.ArrayList;
public class ActionBarActivity extends Activity {
private class FrameLayoutAnimationListener extends FrameLayout {
public FrameLayoutAnimationListener(Context context) {
super(context);
}
@Override
protected void onAnimationEnd() {
super.onAnimationEnd();
ActionBarActivity.this.onAnimationEnd();
}
}
protected ActionBar actionBar;
private FrameLayout containerView;
private FrameLayout containerViewBack;
private FrameLayoutAnimationListener containerView;
private FrameLayoutAnimationListener containerViewBack;
protected FrameLayout contentView;
private View shadowView;
@ -116,10 +128,10 @@ public class ActionBarActivity extends Activity {
contentView = new FrameLayoutTouch(this);
setContentView(contentView, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
containerViewBack = new FrameLayout(this);
containerViewBack = new FrameLayoutAnimationListener(this);
contentView.addView(containerViewBack);
containerView = new FrameLayout(this);
containerView = new FrameLayoutAnimationListener(this);
contentView.addView(containerView);
shadowView = new FrameLayout(this);
@ -172,7 +184,6 @@ public class ActionBarActivity extends Activity {
lastFragment.onResume();
actionBar.setCurrentActionBarLayer(lastFragment.actionBarLayer);
onShowFragment();
}
}
@ -198,7 +209,7 @@ public class ActionBarActivity extends Activity {
lastFragment.setParentActivity(null);
fragmentsStack.remove(fragmentsStack.size() - 1);
FrameLayout temp = containerView;
FrameLayoutAnimationListener temp = containerView;
containerView = containerViewBack;
containerViewBack = temp;
ViewGroup parent = (ViewGroup)containerView.getParent();
@ -391,6 +402,7 @@ public class ActionBarActivity extends Activity {
public boolean checkTransitionAnimation() {
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 400) {
transitionAnimationInProgress = false;
onAnimationEnd();
}
return transitionAnimationInProgress;
}
@ -465,6 +477,7 @@ public class ActionBarActivity extends Activity {
}
}
}
containerViewBack.setVisibility(View.GONE);
}
public boolean presentFragment(BaseFragment fragment) {
@ -485,13 +498,10 @@ public class ActionBarActivity extends Activity {
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);
containerViewBack.addView(fragmentView);
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
@ -502,7 +512,19 @@ public class ActionBarActivity extends Activity {
if (fragmentView.getBackground() == null) {
fragmentView.setBackgroundColor(0xffffffff);
}
onShowFragment();
FrameLayoutAnimationListener temp = containerView;
containerView = containerViewBack;
containerViewBack = temp;
containerView.setVisibility(View.VISIBLE);
ViewGroup parent = (ViewGroup)containerView.getParent();
parent.removeView(containerView);
parent.addView(containerView, 1);
if (!needAnimation) {
presentFragmentInternalRemoveOld(removeLast, currentFragment);
}
if (needAnimation) {
transitionAnimationStartTime = System.currentTimeMillis();
transitionAnimationInProgress = true;
@ -514,23 +536,7 @@ public class ActionBarActivity extends Activity {
}
};
openAnimation.reset();
openAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
onOpenAnimationEnd(true);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
fragmentView.startAnimation(openAnimation);
containerView.startAnimation(openAnimation);
} else {
fragment.onOpenAnimationEnd();
}
@ -551,6 +557,10 @@ public class ActionBarActivity extends Activity {
fragment.onFragmentDestroy();
fragment.setParentActivity(null);
fragmentsStack.remove(fragment);
containerViewBack.setVisibility(View.GONE);
ViewGroup parent = (ViewGroup)containerView.getParent();
parent.removeView(containerViewBack);
parent.addView(containerViewBack, 0);
}
public void closeLastFragment(boolean animated) {
@ -563,13 +573,15 @@ public class ActionBarActivity extends Activity {
boolean needAnimation = animated && closeAnimation != 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);
}
FrameLayoutAnimationListener temp = containerView;
containerView = containerViewBack;
containerViewBack = temp;
containerView.setVisibility(View.VISIBLE);
previousFragment.setParentActivity(this);
View fragmentView = previousFragment.createView(getLayoutInflater(), null);
containerView.addView(fragmentView, 0);
containerView.addView(fragmentView);
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
@ -579,35 +591,22 @@ public class ActionBarActivity extends Activity {
if (fragmentView.getBackground() == null) {
fragmentView.setBackgroundColor(0xffffffff);
}
onShowFragment();
if (!needAnimation) {
closeLastFragmentInternalRemoveOld(currentFragment);
}
if (needAnimation) {
transitionAnimationStartTime = System.currentTimeMillis();
transitionAnimationInProgress = true;
closeAnimation.reset();
closeAnimation.setFillAfter(true);
onCloseAnimationEndRunnable = new Runnable() {
@Override
public void run() {
closeLastFragmentInternalRemoveOld(currentFragment);
}
};
closeAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
onCloseAnimationEnd(true);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
currentFragment.fragmentView.startAnimation(closeAnimation);
containerViewBack.startAnimation(closeAnimation);
}
}
@ -625,7 +624,6 @@ public class ActionBarActivity extends Activity {
if (fragmentView.getBackground() == null) {
fragmentView.setBackgroundColor(0xffffffff);
}
onShowFragment();
}
public void removeFragmentFromStack(BaseFragment fragment) {
@ -645,10 +643,6 @@ public class ActionBarActivity extends Activity {
}
protected void onShowFragment() {
}
public void showActionBar() {
actionBar.setVisibility(View.VISIBLE);
needLayout();
@ -725,6 +719,11 @@ public class ActionBarActivity extends Activity {
}
}
private void onAnimationEnd() {
onCloseAnimationEnd(false);
onOpenAnimationEnd(false);
}
@Override
public void startActivityForResult(final Intent intent, final int requestCode) {
if (transitionAnimationInProgress) {

View File

@ -128,13 +128,12 @@ public class ActionBarMenuItem extends ImageView {
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
popupLayout.measure(MeasureSpec.makeMeasureSpec(Utilities.dp(1000), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(Utilities.dp(1000), MeasureSpec.AT_MOST));
}
popupWindow.setFocusable(true);
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);
popupWindow.setFocusable(true);
} else {
popupWindow.showAsDropDown(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0);
popupWindow.setFocusable(true);
}
}

View File

@ -100,8 +100,8 @@
<string name="EncryptedPlaceholderTitleIncoming">%s convidou você para uma conversa secreta.</string>
<string name="EncryptedPlaceholderTitleOutgoing">Você convidou %s para uma conversa secreta.</string>
<string name="EncryptedDescriptionTitle">Conversas secretas:</string>
<string name="EncryptedDescription1">Utilizam criptografia ponta a ponta</string>
<string name="EncryptedDescription2">Não deixam rasto em nossos servidores</string>
<string name="EncryptedDescription1">Utilizam criptografia ponto a ponto</string>
<string name="EncryptedDescription2">Não deixam rastro em nossos servidores</string>
<string name="EncryptedDescription3">Têm temporizador para a autodestruição das mensagens</string>
<string name="EncryptedDescription4">Não permitem o reencaminhamento</string>
<string name="OneNewMessage">%1$d nova mensagem</string>