Better animations between tabs
This commit is contained in:
parent
3bc93a8583
commit
1a29c5ac72
4 changed files with 75 additions and 17 deletions
|
@ -8,14 +8,14 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@drawable/champ_saisie_numero"
|
android:background="@drawable/champ_saisie_numero"
|
||||||
|
android:gravity="center_vertical"
|
||||||
android:stretchColumns="0"
|
android:stretchColumns="0"
|
||||||
android:shrinkColumns="0"
|
android:shrinkColumns="0"
|
||||||
android:layout_weight="0.9">
|
android:layout_weight="0.9">
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:gravity="center">
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/contactNameOrNumber"
|
android:id="@+id/contactNameOrNumber"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -32,17 +32,35 @@ public enum FragmentsAvailable {
|
||||||
CHAT;
|
CHAT;
|
||||||
|
|
||||||
public boolean shouldAddToBackStack() {
|
public boolean shouldAddToBackStack() {
|
||||||
return this == HISTORY_DETAIL ||
|
return true;
|
||||||
this == HISTORY ||
|
|
||||||
this == CONTACT ||
|
|
||||||
this == CONTACTS ||
|
|
||||||
this == CHATLIST ||
|
|
||||||
this == CHAT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldAnimate() {
|
public boolean shouldAnimate() {
|
||||||
return this == HISTORY_DETAIL ||
|
return true;
|
||||||
this == CONTACT ||
|
}
|
||||||
this == CHAT;
|
|
||||||
|
public boolean isRightOf(FragmentsAvailable fragment) {
|
||||||
|
switch (this) {
|
||||||
|
case HISTORY:
|
||||||
|
case HISTORY_DETAIL:
|
||||||
|
return fragment == UNKNOW;
|
||||||
|
|
||||||
|
case CONTACTS:
|
||||||
|
case CONTACT:
|
||||||
|
return HISTORY.isRightOf(fragment) || fragment == HISTORY || fragment == HISTORY_DETAIL;
|
||||||
|
|
||||||
|
case DIALER:
|
||||||
|
return CONTACTS.isRightOf(fragment) || fragment == CONTACT || fragment == CONTACTS;
|
||||||
|
|
||||||
|
case SETTINGS:
|
||||||
|
return DIALER.isRightOf(fragment) || fragment == DIALER;
|
||||||
|
|
||||||
|
case CHAT:
|
||||||
|
case CHATLIST:
|
||||||
|
return SETTINGS.isRightOf(fragment) || fragment == SETTINGS;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ import android.support.v4.app.Fragment.SavedState;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
@ -189,17 +190,20 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
|
|
||||||
if (newFragment != null) {
|
if (newFragment != null) {
|
||||||
newFragment.setArguments(extras);
|
newFragment.setArguments(extras);
|
||||||
currentFragment = newFragmentType;
|
changeFragment(newFragment, newFragmentType);
|
||||||
changeFragment(newFragment);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFragment(Fragment newFragment) {
|
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType) {
|
||||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||||
|
|
||||||
if (currentFragment.shouldAddToBackStack()) {
|
if (currentFragment.shouldAddToBackStack()) {
|
||||||
if (!getResources().getBoolean(R.bool.disable_animations) && currentFragment.shouldAnimate()) {
|
if (!getResources().getBoolean(R.bool.disable_animations) && currentFragment.shouldAnimate()) {
|
||||||
transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
|
if (newFragmentType.isRightOf(currentFragment)) {
|
||||||
|
transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
|
||||||
|
} else {
|
||||||
|
transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
transaction.addToBackStack("Add to back stack");
|
transaction.addToBackStack("Add to back stack");
|
||||||
}
|
}
|
||||||
|
@ -213,6 +217,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
transaction.replace(R.id.fragmentContainer, newFragment);
|
transaction.replace(R.id.fragmentContainer, newFragment);
|
||||||
|
|
||||||
transaction.commitAllowingStateLoss();
|
transaction.commitAllowingStateLoss();
|
||||||
|
currentFragment = newFragmentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayHistoryDetail(String sipUri, LinphoneCallLog log) {
|
public void displayHistoryDetail(String sipUri, LinphoneCallLog log) {
|
||||||
|
@ -289,7 +294,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
dialer.setSelected(true);
|
dialer.setSelected(true);
|
||||||
}
|
}
|
||||||
else if (id == R.id.settings) {
|
else if (id == R.id.settings) {
|
||||||
currentFragment = FragmentsAvailable.SETTINGS;
|
|
||||||
// if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
// if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||||
// changeCurrentFragment(FragmentsAvailable.SETTINGS, null);
|
// changeCurrentFragment(FragmentsAvailable.SETTINGS, null);
|
||||||
// settings.setSelected(true);
|
// settings.setSelected(true);
|
||||||
|
@ -297,6 +301,11 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
Intent intent = new Intent(ACTION_MAIN);
|
Intent intent = new Intent(ACTION_MAIN);
|
||||||
intent.setClass(this, PreferencesActivity.class);
|
intent.setClass(this, PreferencesActivity.class);
|
||||||
startActivityForResult(intent, SETTINGS_ACTIVITY);
|
startActivityForResult(intent, SETTINGS_ACTIVITY);
|
||||||
|
if (FragmentsAvailable.SETTINGS.isRightOf(currentFragment)) {
|
||||||
|
overridePendingTransition(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
|
||||||
|
} else {
|
||||||
|
overridePendingTransition(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
else if (id == R.id.chat) {
|
else if (id == R.id.chat) {
|
||||||
|
@ -526,6 +535,10 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
return isInCallLayout;
|
return isInCallLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FragmentsAvailable getCurrentFragment() {
|
||||||
|
return currentFragment;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
|
if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
|
||||||
|
@ -577,6 +590,15 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
displayChat(sipUri);
|
displayChat(sipUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK && currentFragment == FragmentsAvailable.DIALER) {
|
||||||
|
if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContactPicked {
|
interface ContactPicked {
|
||||||
|
|
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -87,7 +88,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements O
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra("FragmentToDisplay", newFragment);
|
intent.putExtra("FragmentToDisplay", newFragment);
|
||||||
setResult(RESULT_FIRST_USER, intent);
|
setResult(RESULT_FIRST_USER, intent);
|
||||||
finish();
|
finishWithCustomAnimation(newFragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,4 +111,21 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements O
|
||||||
missedCalls.setVisibility(View.GONE);
|
missedCalls.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void finishWithCustomAnimation(FragmentsAvailable newFragment) {
|
||||||
|
finish();
|
||||||
|
if (FragmentsAvailable.SETTINGS.isRightOf(newFragment)) {
|
||||||
|
overridePendingTransition(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
|
||||||
|
} else {
|
||||||
|
overridePendingTransition(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
finishWithCustomAnimation(LinphoneActivity.instance().getCurrentFragment());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue