Even better main/settings layout for best display on every screen + fix crazy fragments issue

This commit is contained in:
Sylvain Berfini 2012-08-08 13:29:14 +02:00
parent de116b0677
commit c17eb9046b
11 changed files with 158 additions and 162 deletions

BIN
res/drawable-hdpi/mark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B

BIN
res/drawable-mdpi/mark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

View file

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
<LinearLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="75dp"
android:paddingTop="20dp" />
<fragment
android:id="@+id/status"
android:name="org.linphone.StatusFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/status" />
</FrameLayout>
<LinearLayout
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2">
<ImageView
android:id="@+id/history"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_history"
android:scaleType="fitXY"
android:src="@drawable/history" />
<TextView
android:id="@+id/missedCalls"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/missed_calls_bg"
android:gravity="center"
android:textSize="20dp"
android:visibility="gone" />
</RelativeLayout>
<ImageView
android:id="@+id/contacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_contacts"
android:scaleType="fitXY"
android:src="@drawable/contacts" />
<ImageView
android:id="@+id/dialer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_dialer"
android:scaleType="fitXY"
android:src="@drawable/dialer" />
<ImageView
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_settings"
android:scaleType="fitXY"
android:src="@drawable/settings" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2">
<ImageView
android:id="@+id/chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_chat"
android:scaleType="fitXY"
android:src="@drawable/chat" />
<TextView
android:id="@+id/missedChats"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/missed_calls_bg"
android:gravity="center"
android:textSize="20dp"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

View file

@ -5,9 +5,65 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<!-- Hack to adjust perfectly on every screen the bottom of the fragment with the curved menu -->
<LinearLayout
android:id="@+id/mark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
</LinearLayout>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@id/mark"
android:layout_alignParentTop="true"> android:layout_alignParentTop="true">
<LinearLayout <LinearLayout
@ -15,7 +71,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingBottom="65dp"
android:paddingTop="20dp" /> android:paddingTop="20dp" />
<fragment <fragment
@ -113,6 +168,7 @@
android:gravity="center" android:gravity="center"
android:textSize="20dp" android:textSize="20dp"
android:visibility="gone" /> android:visibility="gone" />
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>

View file

@ -3,11 +3,66 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<!-- Hack to adjust perfectly on every screen the bottom of the fragment with the curved menu -->
<LinearLayout
android:id="@+id/mark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/mark"
android:visibility="invisible" />
</LinearLayout>
<ListView <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_above="@id/mark"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:paddingBottom="75dp" />
<LinearLayout <LinearLayout
android:id="@+id/menu" android:id="@+id/menu"

View file

@ -35,25 +35,25 @@
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/statebar_background"/> android:src="@drawable/statebar_background"/>
<TextView
android:id="@+id/statusText"
android:text="@string/status_not_connected"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView <ImageView
android:contentDescription="@string/content_description_led" android:contentDescription="@string/content_description_led"
android:id="@+id/statusLed" android:id="@+id/statusLed"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:src="@drawable/led_disconnected" android:src="@drawable/led_error"
android:layout_toRightOf="@id/statusText"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<TextView
android:id="@+id/statusText"
android:text="@string/status_not_connected"
android:textColor="@android:color/white"
android:paddingLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/statusLed" />
<LinearLayout <LinearLayout
android:id="@+id/moreStatusLed" android:id="@+id/moreStatusLed"
android:paddingLeft="5dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="10dp" android:layout_height="10dp"
android:orientation="horizontal" android:orientation="horizontal"
@ -79,7 +79,7 @@
<TextView <TextView
android:id="@+id/exit" android:id="@+id/exit"
android:text="EXIT" android:text="@string/menu_exit"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View file

@ -260,10 +260,10 @@
<string name="chat">Chat</string> <string name="chat">Chat</string>
<string name="call">Call</string> <string name="call">Call</string>
<string name="add_to_contacts">Add to contacts</string> <string name="add_to_contacts">Add to contacts</string>
<string name="status_connected">CONNECTED</string> <string name="status_connected">Registered</string>
<string name="status_not_connected">NOT CONNECTED</string> <string name="status_not_connected">Not Registered</string>
<string name="status_in_progress">CONNECTING</string> <string name="status_in_progress">Registration in progress</string>
<string name="status_error">ERROR</string> <string name="status_error">Registration failed</string>
<string name="addressHint">Number or address</string> <string name="addressHint">Number or address</string>

View file

@ -60,8 +60,8 @@ import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.OrientationEventListener; import android.view.OrientationEventListener;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -107,6 +107,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
FragmentManager.enableDebugLogging(true);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!LinphoneManager.isInstanciated()) { if (!LinphoneManager.isInstanciated()) {
@ -124,18 +125,19 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
} }
setContentView(R.layout.main); setContentView(R.layout.main);
instance = this;
initButtons(); initButtons();
if (LinphoneManager.isInstanciated()) { currentFragment = FragmentsAvailable.DIALER;
LinphoneManager.addListener(this); if (savedInstanceState != null) {
} return;
}
if (findViewById(R.id.fragmentContainer) != null) { if (findViewById(R.id.fragmentContainer) != null) {
dialerFragment = new DialerFragment(); dialerFragment = new DialerFragment();
dialerFragment.setArguments(getIntent().getExtras()); dialerFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, dialerFragment).commit(); .add(R.id.fragmentContainer, dialerFragment).commit();
currentFragment = FragmentsAvailable.DIALER;
} }
int missedCalls = LinphoneManager.getLc().getMissedCallsCount(); int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
@ -150,8 +152,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
LinphoneManager.getLc().setDeviceRotation(rotation); LinphoneManager.getLc().setDeviceRotation(rotation);
mAlwaysChangingPhoneAngle = rotation; mAlwaysChangingPhoneAngle = rotation;
instance = this;
} }
private void initButtons() { private void initButtons() {
@ -241,15 +241,16 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
} }
} }
try { try {
getSupportFragmentManager().popBackStack(newFragmentType.toString(), FragmentManager.POP_BACK_STACK_INCLUSIVE); getSupportFragmentManager().popBackStackImmediate(newFragmentType.toString(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (java.lang.IllegalStateException e) { } catch (java.lang.IllegalStateException e) {
} }
transaction.addToBackStack(newFragmentType.toString()); transaction.addToBackStack(newFragmentType.toString());
transaction.replace(R.id.fragmentContainer, newFragment); transaction.replace(R.id.fragmentContainer, newFragment);
transaction.commitAllowingStateLoss(); transaction.commitAllowingStateLoss();
getSupportFragmentManager().executePendingTransactions();
currentFragment = newFragmentType; currentFragment = newFragmentType;
} }
@ -266,9 +267,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
transaction.addToBackStack(newFragmentType.toString()); transaction.addToBackStack(newFragmentType.toString());
transaction.replace(R.id.fragmentContainer2, newFragment); transaction.replace(R.id.fragmentContainer2, newFragment);
transaction.commitAllowingStateLoss();
} else { } else {
if (!withoutAnimation && !getResources().getBoolean(R.bool.disable_animations) && currentFragment.shouldAnimate()) { if (!withoutAnimation && !getResources().getBoolean(R.bool.disable_animations) && currentFragment.shouldAnimate()) {
if (newFragmentType.isRightOf(currentFragment)) { if (newFragmentType.isRightOf(currentFragment)) {
@ -282,16 +280,17 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
try { try {
getSupportFragmentManager().popBackStack(newFragmentType.toString(), FragmentManager.POP_BACK_STACK_INCLUSIVE); getSupportFragmentManager().popBackStackImmediate(newFragmentType.toString(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (java.lang.IllegalStateException e) { } catch (java.lang.IllegalStateException e) {
} }
transaction.addToBackStack(newFragmentType.toString()); transaction.addToBackStack(newFragmentType.toString());
transaction.replace(R.id.fragmentContainer, newFragment); transaction.replace(R.id.fragmentContainer, newFragment);
transaction.commitAllowingStateLoss();
} }
transaction.commitAllowingStateLoss();
getSupportFragmentManager().executePendingTransactions();
currentFragment = newFragmentType; currentFragment = newFragmentType;
} }
@ -787,13 +786,14 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(resultCode, requestCode, data);
if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) { if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
if (data.getExtras().getBoolean("Exit", false)) { if (data.getExtras().getBoolean("Exit", false)) {
exit(); exit();
} else { } else {
FragmentsAvailable newFragment = (FragmentsAvailable) data.getExtras().getSerializable("FragmentToDisplay"); FragmentsAvailable newFragment = (FragmentsAvailable) data.getExtras().getSerializable("FragmentToDisplay");
changeCurrentFragment(newFragment, null, true);
selectMenu(newFragment); selectMenu(newFragment);
changeCurrentFragment(newFragment, null, true);
} }
} }
else if (requestCode == callActivity) { else if (requestCode == callActivity) {
@ -804,13 +804,14 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
resetClassicMenuLayoutAndGoBackToCallIfStillRunning(); resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
} }
} }
super.onActivityResult(resultCode, requestCode, data);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
LinphoneManager.addListener(this);
prepareContactsInBackground(); prepareContactsInBackground();
if (chatStorage != null) { if (chatStorage != null) {
@ -832,6 +833,8 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
@Override @Override
protected void onDestroy() { protected void onDestroy() {
LinphoneManager.removeListener(this);
if (chatStorage != null) { if (chatStorage != null) {
chatStorage.close(); chatStorage.close();
chatStorage = null; chatStorage = null;

View file

@ -36,7 +36,9 @@ public class NetworkManager extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false);
LinphoneManager.getInstance().connectivityChanged(cm, lNoConnectivity); if (LinphoneManager.isInstanciated()) {
LinphoneManager.getInstance().connectivityChanged(cm, lNoConnectivity);
}
} }
} }

View file

@ -175,7 +175,7 @@ public class StatusFragment extends Fragment {
private int getStatusIconResource(LinphoneCore.RegistrationState state, boolean isDefaultAccount) { private int getStatusIconResource(LinphoneCore.RegistrationState state, boolean isDefaultAccount) {
try { try {
boolean defaultAccountConnected = (isDefaultAccount && LinphoneManager.getLc().getDefaultProxyConfig().isRegistered()) || !isDefaultAccount; boolean defaultAccountConnected = (isDefaultAccount && LinphoneManager.getLcIfManagerNotDestroyedOrNull().getDefaultProxyConfig().isRegistered()) || !isDefaultAccount;
if (state == RegistrationState.RegistrationOk && defaultAccountConnected) { if (state == RegistrationState.RegistrationOk && defaultAccountConnected) {
return R.drawable.led_connected; return R.drawable.led_connected;
} else if (state == RegistrationState.RegistrationProgress) { } else if (state == RegistrationState.RegistrationProgress) {
@ -194,7 +194,7 @@ public class StatusFragment extends Fragment {
private String getStatusIconText(LinphoneCore.RegistrationState state) { private String getStatusIconText(LinphoneCore.RegistrationState state) {
try { try {
if (state == RegistrationState.RegistrationOk && LinphoneManager.getLc().getDefaultProxyConfig().isRegistered()) { if (state == RegistrationState.RegistrationOk && LinphoneManager.getLcIfManagerNotDestroyedOrNull().getDefaultProxyConfig().isRegistered()) {
return getString(R.string.status_connected); return getString(R.string.status_connected);
} else if (state == RegistrationState.RegistrationProgress) { } else if (state == RegistrationState.RegistrationProgress) {
return getString(R.string.status_in_progress); return getString(R.string.status_in_progress);