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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="horizontal"
android:gravity="center" android:layout_height="fill_parent">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="@+id/State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/Identity"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@android:color/white"
android:layout_weight="4"/>
<CheckBox
android:id="@+id/Default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -10,17 +10,16 @@
android:id="@+id/statusBar"
linphone:direction="topToBottom"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_height="wrap_content"
linphone:handle="@+id/handle"
linphone:content="@+id/content">
<RelativeLayout
<ListView
android:id="@id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
</RelativeLayout>
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:background="@android:color/black"/>
<RelativeLayout
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.
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore;
@ -29,20 +29,21 @@ import org.linphone.ui.SlidingDrawer;
import org.linphone.ui.SlidingDrawer.OnDrawerOpenListener;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
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.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.SimpleAdapter;
import android.widget.TextView;
/**
@ -53,7 +54,7 @@ public class StatusFragment extends Fragment {
private Handler refreshHandler = new Handler();
private TextView statusText, exit;
private ImageView statusLed, callQuality, encryption;
private RelativeLayout sliderContent;
private ListView sliderContent;
private SlidingDrawer drawer;
private Runnable mCallQualityUpdater;
private boolean isInCall, isAttached = false;
@ -75,7 +76,7 @@ public class StatusFragment extends Fragment {
populateSliderContent();
}
});
sliderContent = (RelativeLayout) view.findViewById(R.id.content);
sliderContent = (ListView) view.findViewById(R.id.content);
exit = (TextView) view.findViewById(R.id.exit);
exit.setOnClickListener(new OnClickListener() {
@Override
@ -121,25 +122,9 @@ public class StatusFragment extends Fragment {
}
private void populateSliderContent() {
sliderContent.removeAllViews();
ListView accounts = new ListView(getActivity());
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);
sliderContent.setDividerHeight(0);
AccountsListAdapter adapter = new AccountsListAdapter(LinphoneManager.getLc().getProxyConfigList());
sliderContent.setAdapter(adapter);
}
public void registrationStateChanged(final RegistrationState state) {
@ -294,4 +279,78 @@ public class StatusFragment extends Fragment {
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;
mContent.measure(MeasureSpec.makeMeasureSpec(widthSpecSize,
MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height,
MeasureSpec.EXACTLY));
MeasureSpec.AT_MOST));
} else {
int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
mContent.measure(MeasureSpec.makeMeasureSpec(width,
@ -267,6 +267,10 @@ public class SlidingDrawer extends ViewGroup {
setMeasuredDimension(widthSpecSize, heightSpecSize);
}
private int getCustomBottom() {
return mContent.getBottom() + mHandleHeight;
}
@Override
protected void dispatchDraw(Canvas canvas) {
@ -282,7 +286,7 @@ public class SlidingDrawer extends ViewGroup {
if (isVertical) {
if (mInvert) {
canvas.drawBitmap(cache, 0, handle.getTop()
- (getBottom() - getTop()) + mHandleHeight,
- (getCustomBottom() - getTop()) + mHandleHeight,
null);
} else {
canvas.drawBitmap(cache, 0, handle.getBottom(), null);
@ -340,7 +344,7 @@ public class SlidingDrawer extends ViewGroup {
handleLeft = (width - handleWidth) / 2;
if (mInvert) {
Log.d(LOG_TAG, "content.layout(1)");
handleTop = mExpanded ? height - mBottomOffset - handleHeight
handleTop = mExpanded ? getCustomBottom() - mBottomOffset - handleHeight
: mTopOffset;
content.layout(0, mTopOffset, content.getMeasuredWidth(),
mTopOffset + content.getMeasuredHeight());
@ -483,7 +487,7 @@ public class SlidingDrawer extends ViewGroup {
boolean c4;
if (mInvert) {
c1 = (mExpanded && (getBottom() - handleBottom) < mTapThreshold
c1 = (mExpanded && (getCustomBottom() - handleBottom) < mTapThreshold
+ mBottomOffset);
c2 = (!mExpanded && handleTop < mTopOffset
+ mHandleHeight - mTapThreshold);
@ -495,7 +499,7 @@ public class SlidingDrawer extends ViewGroup {
c1 = (mExpanded && handleTop < mTapThreshold
+ mTopOffset);
c2 = (!mExpanded && handleTop > mBottomOffset
+ getBottom() - getTop() - mHandleHeight
+ getCustomBottom() - getTop() - mHandleHeight
- mTapThreshold);
c3 = (mExpanded && handleLeft < mTapThreshold
+ mTopOffset);
@ -556,7 +560,7 @@ public class SlidingDrawer extends ViewGroup {
boolean c3;
if (mExpanded) {
int bottom = mVertical ? getBottom() : getRight();
int bottom = mVertical ? getCustomBottom() + mHandleHeight : getRight();
int handleHeight = mVertical ? mHandleHeight : mHandleWidth;
Log.d(LOG_TAG, "position: " + position + ", velocity: " + velocity
@ -688,7 +692,7 @@ public class SlidingDrawer extends ViewGroup {
if (mVertical) {
if (position == EXPANDED_FULL_OPEN) {
if (mInvert)
handle.offsetTopAndBottom(mBottomOffset + getBottom()
handle.offsetTopAndBottom(mBottomOffset + getCustomBottom()
- getTop() - mHandleHeight);
else
handle.offsetTopAndBottom(mTopOffset - handle.getTop());
@ -697,7 +701,7 @@ public class SlidingDrawer extends ViewGroup {
if (mInvert) {
handle.offsetTopAndBottom(mTopOffset - handle.getTop());
} else {
handle.offsetTopAndBottom(mBottomOffset + getBottom()
handle.offsetTopAndBottom(mBottomOffset + getCustomBottom()
- getTop() - mHandleHeight - handle.getTop());
}
invalidate();
@ -706,9 +710,9 @@ public class SlidingDrawer extends ViewGroup {
int deltaY = position - top;
if (position < mTopOffset) {
deltaY = mTopOffset - top;
} else if (deltaY > mBottomOffset + getBottom() - getTop()
} else if (deltaY > mBottomOffset + getCustomBottom() - getTop()
- mHandleHeight - top) {
deltaY = mBottomOffset + getBottom() - getTop()
deltaY = mBottomOffset + getCustomBottom() - getTop()
- mHandleHeight - top;
}
@ -785,7 +789,7 @@ public class SlidingDrawer extends ViewGroup {
int height = getBottom() - getTop() - handleHeight - mTopOffset;
content.measure(MeasureSpec.makeMeasureSpec(getRight()
- getLeft(), MeasureSpec.EXACTLY), MeasureSpec
.makeMeasureSpec(height, MeasureSpec.EXACTLY));
.makeMeasureSpec(height, MeasureSpec.AT_MOST));
Log.d(LOG_TAG, "content.layout(2)");