Better sliding drawer to match content height + change default account onthego

This commit is contained in:
Sylvain Berfini 2012-07-27 13:56:21 +02:00
parent b18c0e0e81
commit 995d9ea594
4 changed files with 117 additions and 49 deletions

View file

@ -1,20 +1,26 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="horizontal" android:layout_width="match_parent"
android:gravity="center" android:layout_height="fill_parent"> android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView <ImageView
android:id="@+id/State" android:id="@+id/State"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"/>
android:layout_weight="1"/>
<TextView <TextView
android:id="@+id/Identity" android:id="@+id/Identity"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:layout_weight="4"/> android:layout_weight="4"/>
<CheckBox
android:id="@+id/Default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>

View file

@ -10,17 +10,16 @@
android:id="@+id/statusBar" android:id="@+id/statusBar"
linphone:direction="topToBottom" linphone:direction="topToBottom"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp" android:layout_height="wrap_content"
linphone:handle="@+id/handle" linphone:handle="@+id/handle"
linphone:content="@+id/content"> linphone:content="@+id/content">
<RelativeLayout <ListView
android:id="@id/content" android:id="@id/content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:background="@android:color/black"> android:stackFromBottom="true"
android:background="@android:color/black"/>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@id/handle" android:id="@id/handle"

View file

@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.List;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
@ -29,20 +29,21 @@ import org.linphone.ui.SlidingDrawer;
import org.linphone.ui.SlidingDrawer.OnDrawerOpenListener; import org.linphone.ui.SlidingDrawer.OnDrawerOpenListener;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Adapter; import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.SimpleAdapter;
import android.widget.TextView; import android.widget.TextView;
/** /**
@ -53,7 +54,7 @@ public class StatusFragment extends Fragment {
private Handler refreshHandler = new Handler(); private Handler refreshHandler = new Handler();
private TextView statusText, exit; private TextView statusText, exit;
private ImageView statusLed, callQuality, encryption; private ImageView statusLed, callQuality, encryption;
private RelativeLayout sliderContent; private ListView sliderContent;
private SlidingDrawer drawer; private SlidingDrawer drawer;
private Runnable mCallQualityUpdater; private Runnable mCallQualityUpdater;
private boolean isInCall, isAttached = false; private boolean isInCall, isAttached = false;
@ -75,7 +76,7 @@ public class StatusFragment extends Fragment {
populateSliderContent(); populateSliderContent();
} }
}); });
sliderContent = (RelativeLayout) view.findViewById(R.id.content); sliderContent = (ListView) view.findViewById(R.id.content);
exit = (TextView) view.findViewById(R.id.exit); exit = (TextView) view.findViewById(R.id.exit);
exit.setOnClickListener(new OnClickListener() { exit.setOnClickListener(new OnClickListener() {
@Override @Override
@ -121,25 +122,9 @@ public class StatusFragment extends Fragment {
} }
private void populateSliderContent() { private void populateSliderContent() {
sliderContent.removeAllViews(); sliderContent.setDividerHeight(0);
AccountsListAdapter adapter = new AccountsListAdapter(LinphoneManager.getLc().getProxyConfigList());
ListView accounts = new ListView(getActivity()); sliderContent.setAdapter(adapter);
accounts.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
accounts.setDividerHeight(0);
ArrayList<HashMap<String,String>> hashMapAccountsStateList = new ArrayList<HashMap<String,String>>();
for (LinphoneProxyConfig lpc : LinphoneManager.getLc().getProxyConfigList()) {
HashMap<String, String> entitiesHashMap = new HashMap<String, String>();
entitiesHashMap.put("Identity", lpc.getIdentity().split("sip:")[1]);
entitiesHashMap.put("State", Integer.toString(getStatusIconResource(lpc.getState())));
hashMapAccountsStateList.add(entitiesHashMap);
}
Adapter adapterForList = new SimpleAdapter(getActivity(), hashMapAccountsStateList, R.layout.accounts,
new String[] {"Identity", "State" },
new int[] { R.id.Identity, R.id.State });
accounts.setAdapter((ListAdapter) adapterForList);
sliderContent.addView(accounts);
} }
public void registrationStateChanged(final RegistrationState state) { public void registrationStateChanged(final RegistrationState state) {
@ -294,4 +279,78 @@ public class StatusFragment extends Fragment {
exit.setVisibility(View.VISIBLE); exit.setVisibility(View.VISIBLE);
} }
} }
class AccountsListAdapter extends BaseAdapter {
private LinphoneProxyConfig[] accounts;
private SharedPreferences prefs;
private List<CheckBox> checkboxes;
AccountsListAdapter(LinphoneProxyConfig[] lpcs) {
accounts = lpcs;
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
checkboxes = new ArrayList<CheckBox>();
}
private OnCheckedChangeListener defaultListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(getString(R.string.pref_default_account), (Integer) buttonView.getTag());
editor.commit();
sliderContent.invalidate();
for (CheckBox cb : checkboxes) {
cb.setChecked(false);
cb.setEnabled(true);
}
buttonView.setChecked(true);
buttonView.setEnabled(false);
}
}
};
public int getCount() {
return accounts.length;
}
public Object getItem(int position) {
return accounts[position];
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView != null) {
view = convertView;
} else {
view = LayoutInflater.from(getActivity()).inflate(R.layout.accounts, parent, false);
}
LinphoneProxyConfig lpc = (LinphoneProxyConfig) getItem(position);
ImageView status = (ImageView) view.findViewById(R.id.State);
status.setImageResource(getStatusIconResource(lpc.getState()));
TextView identity = (TextView) view.findViewById(R.id.Identity);
identity.setText(lpc.getIdentity().split("sip:")[1]);
CheckBox isDefault = (CheckBox) view.findViewById(R.id.Default);
checkboxes.add(isDefault);
isDefault.setTag(position);
isDefault.setChecked(false);
isDefault.setEnabled(true);
if (prefs.getInt(getString(R.string.pref_default_account), 0) == position) {
isDefault.setChecked(true);
isDefault.setEnabled(false);
}
isDefault.setOnCheckedChangeListener(defaultListener);
return view;
}
}
} }

View file

@ -257,7 +257,7 @@ public class SlidingDrawer extends ViewGroup {
- mTopOffset; - mTopOffset;
mContent.measure(MeasureSpec.makeMeasureSpec(widthSpecSize, mContent.measure(MeasureSpec.makeMeasureSpec(widthSpecSize,
MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height,
MeasureSpec.EXACTLY)); MeasureSpec.AT_MOST));
} else { } else {
int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset; int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
mContent.measure(MeasureSpec.makeMeasureSpec(width, mContent.measure(MeasureSpec.makeMeasureSpec(width,
@ -267,6 +267,10 @@ public class SlidingDrawer extends ViewGroup {
setMeasuredDimension(widthSpecSize, heightSpecSize); setMeasuredDimension(widthSpecSize, heightSpecSize);
} }
private int getCustomBottom() {
return mContent.getBottom() + mHandleHeight;
}
@Override @Override
protected void dispatchDraw(Canvas canvas) { protected void dispatchDraw(Canvas canvas) {
@ -282,7 +286,7 @@ public class SlidingDrawer extends ViewGroup {
if (isVertical) { if (isVertical) {
if (mInvert) { if (mInvert) {
canvas.drawBitmap(cache, 0, handle.getTop() canvas.drawBitmap(cache, 0, handle.getTop()
- (getBottom() - getTop()) + mHandleHeight, - (getCustomBottom() - getTop()) + mHandleHeight,
null); null);
} else { } else {
canvas.drawBitmap(cache, 0, handle.getBottom(), null); canvas.drawBitmap(cache, 0, handle.getBottom(), null);
@ -340,7 +344,7 @@ public class SlidingDrawer extends ViewGroup {
handleLeft = (width - handleWidth) / 2; handleLeft = (width - handleWidth) / 2;
if (mInvert) { if (mInvert) {
Log.d(LOG_TAG, "content.layout(1)"); Log.d(LOG_TAG, "content.layout(1)");
handleTop = mExpanded ? height - mBottomOffset - handleHeight handleTop = mExpanded ? getCustomBottom() - mBottomOffset - handleHeight
: mTopOffset; : mTopOffset;
content.layout(0, mTopOffset, content.getMeasuredWidth(), content.layout(0, mTopOffset, content.getMeasuredWidth(),
mTopOffset + content.getMeasuredHeight()); mTopOffset + content.getMeasuredHeight());
@ -483,7 +487,7 @@ public class SlidingDrawer extends ViewGroup {
boolean c4; boolean c4;
if (mInvert) { if (mInvert) {
c1 = (mExpanded && (getBottom() - handleBottom) < mTapThreshold c1 = (mExpanded && (getCustomBottom() - handleBottom) < mTapThreshold
+ mBottomOffset); + mBottomOffset);
c2 = (!mExpanded && handleTop < mTopOffset c2 = (!mExpanded && handleTop < mTopOffset
+ mHandleHeight - mTapThreshold); + mHandleHeight - mTapThreshold);
@ -495,7 +499,7 @@ public class SlidingDrawer extends ViewGroup {
c1 = (mExpanded && handleTop < mTapThreshold c1 = (mExpanded && handleTop < mTapThreshold
+ mTopOffset); + mTopOffset);
c2 = (!mExpanded && handleTop > mBottomOffset c2 = (!mExpanded && handleTop > mBottomOffset
+ getBottom() - getTop() - mHandleHeight + getCustomBottom() - getTop() - mHandleHeight
- mTapThreshold); - mTapThreshold);
c3 = (mExpanded && handleLeft < mTapThreshold c3 = (mExpanded && handleLeft < mTapThreshold
+ mTopOffset); + mTopOffset);
@ -556,7 +560,7 @@ public class SlidingDrawer extends ViewGroup {
boolean c3; boolean c3;
if (mExpanded) { if (mExpanded) {
int bottom = mVertical ? getBottom() : getRight(); int bottom = mVertical ? getCustomBottom() + mHandleHeight : getRight();
int handleHeight = mVertical ? mHandleHeight : mHandleWidth; int handleHeight = mVertical ? mHandleHeight : mHandleWidth;
Log.d(LOG_TAG, "position: " + position + ", velocity: " + velocity Log.d(LOG_TAG, "position: " + position + ", velocity: " + velocity
@ -688,7 +692,7 @@ public class SlidingDrawer extends ViewGroup {
if (mVertical) { if (mVertical) {
if (position == EXPANDED_FULL_OPEN) { if (position == EXPANDED_FULL_OPEN) {
if (mInvert) if (mInvert)
handle.offsetTopAndBottom(mBottomOffset + getBottom() handle.offsetTopAndBottom(mBottomOffset + getCustomBottom()
- getTop() - mHandleHeight); - getTop() - mHandleHeight);
else else
handle.offsetTopAndBottom(mTopOffset - handle.getTop()); handle.offsetTopAndBottom(mTopOffset - handle.getTop());
@ -697,7 +701,7 @@ public class SlidingDrawer extends ViewGroup {
if (mInvert) { if (mInvert) {
handle.offsetTopAndBottom(mTopOffset - handle.getTop()); handle.offsetTopAndBottom(mTopOffset - handle.getTop());
} else { } else {
handle.offsetTopAndBottom(mBottomOffset + getBottom() handle.offsetTopAndBottom(mBottomOffset + getCustomBottom()
- getTop() - mHandleHeight - handle.getTop()); - getTop() - mHandleHeight - handle.getTop());
} }
invalidate(); invalidate();
@ -706,9 +710,9 @@ public class SlidingDrawer extends ViewGroup {
int deltaY = position - top; int deltaY = position - top;
if (position < mTopOffset) { if (position < mTopOffset) {
deltaY = mTopOffset - top; deltaY = mTopOffset - top;
} else if (deltaY > mBottomOffset + getBottom() - getTop() } else if (deltaY > mBottomOffset + getCustomBottom() - getTop()
- mHandleHeight - top) { - mHandleHeight - top) {
deltaY = mBottomOffset + getBottom() - getTop() deltaY = mBottomOffset + getCustomBottom() - getTop()
- mHandleHeight - top; - mHandleHeight - top;
} }
@ -785,7 +789,7 @@ public class SlidingDrawer extends ViewGroup {
int height = getBottom() - getTop() - handleHeight - mTopOffset; int height = getBottom() - getTop() - handleHeight - mTopOffset;
content.measure(MeasureSpec.makeMeasureSpec(getRight() content.measure(MeasureSpec.makeMeasureSpec(getRight()
- getLeft(), MeasureSpec.EXACTLY), MeasureSpec - getLeft(), MeasureSpec.EXACTLY), MeasureSpec
.makeMeasureSpec(height, MeasureSpec.EXACTLY)); .makeMeasureSpec(height, MeasureSpec.AT_MOST));
Log.d(LOG_TAG, "content.layout(2)"); Log.d(LOG_TAG, "content.layout(2)");