diff --git a/.gitignore b/.gitignore index 5349d5dd609c25d9252ecb8128245df92bff8e35..74f672124d8248b1e4894af1b7e4088fa8f208db 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,12 @@ tags TAGS.LST ID +src/org/sflphone/views/paralloidviews/ +src/org/sflphone/views/paralloid + AndroidUnusedResources1.6.2.jar -/jni/pjproject-android/build +jni/pjproject-android/build jni/pjproject-android/pjsip/build/.pjsua2-lib-arm-unknown-linux-androideabi.depend jni/pjproject-android/pjsip/build/.pjsua2-test-arm-unknown-linux-androideabi.depend .classpath diff --git a/res/layout/frag_history_detail.xml b/res/layout/frag_history_detail.xml index e35588bbd6ea9e6b686d318d7e8f087bf285edcc..e20c288eef5568e899ccd8956f9a443541b7954f 100644 --- a/res/layout/frag_history_detail.xml +++ b/res/layout/frag_history_detail.xml @@ -1,97 +1,69 @@ -<org.sflphone.views.parallaxscrollview.ParallaxScrollView xmlns:tools="http://schemas.android.com/tools" - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/scroll_view" - android:layout_width="match_parent" - android:layout_height="match_parent" > +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/frame" + android:layout_width="match_parent" + android:layout_height="match_parent"> <!-- Background --> - <RelativeLayout - android:id="@+id/iv" - android:layout_width="match_parent" - android:layout_height="@dimen/header_history_detail" > - - <ImageView - android:id="@+id/contact_photo" - android:layout_width="100dp" - android:layout_height="100dp" - android:layout_centerHorizontal="true" - android:layout_marginTop="30dp" /> + android:id="@+id/iv" + android:layout_width="match_parent" + android:layout_height="@dimen/header_history_detail" + android:layout_alignParentTop="true"> - <LinearLayout - android:id="@+id/contact_name_holder" - android:layout_width="0dp" - android:layout_height="50dp" - android:layout_alignParentBottom="true" - android:layout_alignParentLeft="true" - android:layout_alignParentRight="true" - android:background="#AAFFFFFF" - android:orientation="vertical" - android:padding="5dp" > - <TextView - android:id="@+id/history_call_name" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:gravity="center" - android:singleLine="true" - android:textSize="18sp" /> - </LinearLayout> - </RelativeLayout> + <ImageView + android:id="@+id/contact_photo" + android:layout_width="100dp" + android:layout_height="100dp" + android:layout_centerHorizontal="true" + android:layout_marginTop="30dp"/> - <!-- Foreground --> + <LinearLayout + android:id="@+id/contact_name_holder" + android:layout_width="0dp" + android:layout_height="50dp" + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentRight="true" + android:background="#AAFFFFFF" + android:orientation="vertical" + android:padding="5dp"> - <org.sflphone.views.parallaxscrollview.AnotherView - android:id="@+id/anotherView" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical" > + <TextView + android:id="@+id/history_call_name" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:singleLine="true" + android:textSize="18sp"/> + </LinearLayout> <LinearLayout - android:id="@+id/llMainHolder" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginTop="@dimen/header_history_detail" - android:orientation="vertical" > + android:id="@+id/contact_name_holder" + android:layout_width="0dp" + android:layout_height="50dp" + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentRight="true" + android:background="#AAFFFFFF" + android:orientation="vertical" + android:padding="5dp"> - <RelativeLayout - android:id="@+id/call_main_action" - android:layout_width="match_parent" - android:layout_height="?android:attr/listPreferredItemHeight" - android:background="@drawable/item_generic_selector" > + </LinearLayout> + </RelativeLayout> - <TextView - android:id="@+id/history_entry_number" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:layout_centerVertical="true" - android:layout_marginLeft="10dp" - android:singleLine="true" - android:textSize="18sp" /> - </RelativeLayout> - <View - android:layout_width="match_parent" - android:layout_height="1dp" - android:background="@drawable/divider" /> + <!-- Foreground --> - <LinearLayout - android:id="@+id/llMain" - android:layout_width="match_parent" - android:layout_height="wrap_content" > + <ListView + android:id="@+id/lvMain" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:dividerHeight="2dp" + android:layout_below="@+id/iv" + android:fillViewport="true" + android:drawSelectorOnTop="true"> + </ListView> - <ListView - android:id="@+id/lvMain" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@color/white" - android:dividerHeight="2dp" - android:drawSelectorOnTop="true" > - </ListView> - </LinearLayout> - </LinearLayout> - </org.sflphone.views.parallaxscrollview.AnotherView> -</org.sflphone.views.parallaxscrollview.ParallaxScrollView> \ No newline at end of file +</RelativeLayout> \ No newline at end of file diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index ec3ab258cb873c451f128a6c8a884d5e63485a17..0f1ccc6768b4e52ca6e4197ecd110c591b915332 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -104,12 +104,8 @@ as that of the covered work. <string name="me">Moi</string> <string name="action_call_attended_transfer">Transfert</string> <string name="action_call_unattended_transfer">Transfert Direct</string> - <string name="action_call_general_transfer">Transfert</string> <string name="action_call_conference">Conférence</string> <string name="action_call_hold">Attente</string> - <string name="action_call_unhold">Reprendre</string> - <string name="action_call_record">Enregistrer</string> - <string name="action_call_stop_record">Arrêter l\'enregistrement</string> <string name="action_settings">Paramètres</string> <string name="copyright">Copyright \u00A9 2004–2014 Savoir-Faire Linux Inc.</string> <string name="web_site">Site web</string> diff --git a/src/org/sflphone/fragments/DetailsHistoryEntryFragment.java b/src/org/sflphone/fragments/DetailsHistoryEntryFragment.java index 45b171540c67ad37395d181d65fa50b4ae750326..ee5b144260d13267bfc709c4cde1762b2584741d 100644 --- a/src/org/sflphone/fragments/DetailsHistoryEntryFragment.java +++ b/src/org/sflphone/fragments/DetailsHistoryEntryFragment.java @@ -36,6 +36,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.NavigableMap; +import android.util.Log; +import android.widget.*; import org.sflphone.R; import org.sflphone.adapters.ContactPictureTask; import org.sflphone.history.HistoryCall; @@ -43,7 +45,6 @@ import org.sflphone.model.Account; import org.sflphone.history.HistoryEntry; import org.sflphone.model.SipCall; import org.sflphone.service.ISipService; -import org.sflphone.views.parallaxscrollview.AnotherView; import android.app.Activity; import android.app.Fragment; @@ -55,14 +56,10 @@ import android.view.View; import android.view.View.MeasureSpec; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ListAdapter; -import android.widget.ListView; -import android.widget.RelativeLayout; -import android.widget.TextView; +import org.sflphone.views.paralloid.ParallaxController; +import org.sflphone.views.paralloid.Parallaxor; +import org.sflphone.views.paralloidviews.ParallaxListView; +import org.sflphone.views.paralloidviews.ParallaxScrollView; public class DetailsHistoryEntryFragment extends Fragment { @@ -73,8 +70,7 @@ public class DetailsHistoryEntryFragment extends Fragment { ContactPictureTask tasker; private ListView lvMain; - private LinearLayout llMain, llMainHolder; - private AnotherView anotherView; + private LinearLayout llMain; private RelativeLayout iv; private Callbacks mCallbacks = sDummyCallbacks; @@ -95,7 +91,7 @@ public class DetailsHistoryEntryFragment extends Fragment { public interface Callbacks { public ISipService getService(); - + public void onCall(SipCall call); } @@ -130,19 +126,17 @@ public class DetailsHistoryEntryFragment extends Fragment { View inflatedView = inflater.inflate(R.layout.frag_history_detail, parent, false); llMain = (LinearLayout) inflatedView.findViewById(R.id.llMain); - llMainHolder = (LinearLayout) inflatedView.findViewById(R.id.llMainHolder); + /*llMainHolder = (LinearLayout) inflatedView.findViewById(R.id.llMainHolder);*/ lvMain = (ListView) inflatedView.findViewById(R.id.lvMain); lvMain.setAdapter(mAdapter); iv = (RelativeLayout) inflatedView.findViewById(R.id.iv); ((TextView) iv.findViewById(R.id.history_call_name)).setText(toDisplay.getContact().getmDisplayName()); - tasker = new ContactPictureTask(getActivity(), (ImageView) iv.findViewById(R.id.contact_photo), toDisplay.getContact()); + tasker = new ContactPictureTask(getActivity(), (ImageView) inflatedView.findViewById(R.id.contact_photo), toDisplay.getContact()); tasker.run(); - anotherView = (AnotherView) inflatedView.findViewById(R.id.anotherView); - - ((TextView) anotherView.findViewById(R.id.history_entry_number)).setText(getString(R.string.detail_hist_call_number, toDisplay.getNumber())); - anotherView.findViewById(R.id.call_main_action).setOnClickListener(new OnClickListener() { +// ((TextView) iv.findViewById(R.id.history_entry_number)).setText(getString(R.string.detail_hist_call_number, toDisplay.getNumber())); + iv.findViewById(R.id.history_call_name).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -150,9 +144,7 @@ public class DetailsHistoryEntryFragment extends Fragment { SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); HashMap<String, String> details = (HashMap<String, String>) mCallbacks.getService().getAccountDetails(toDisplay.getAccountID()); - ArrayList<HashMap<String, String>> creds; - - creds = (ArrayList<HashMap<String, String>>) mCallbacks.getService().getCredentials(toDisplay.getAccountID()); + ArrayList<HashMap<String, String>> creds = (ArrayList<HashMap<String, String>>) mCallbacks.getService().getCredentials(toDisplay.getAccountID()); callBuilder.startCallCreation().setAccount(new Account(toDisplay.getAccountID(), details, creds)) .setCallType(SipCall.direction.CALL_TYPE_OUTGOING); @@ -170,22 +162,20 @@ public class DetailsHistoryEntryFragment extends Fragment { } }); - lvMain.post(new Runnable() { - + /*lvMain.post(new Runnable() { @Override public void run() { - - // Adjusts llMain's height to match ListView's height setListViewHeight(lvMain, llMain); - - // LayoutParams to set the top margin of LinearLayout holding - // the content. - // topMargin = iv.getHeight() - tvTitle.getHeight() - LinearLayout.LayoutParams p = (LinearLayout.LayoutParams) llMainHolder.getLayoutParams(); - // p.topMargin = iv.getHeight() - tvTitle.getHeight(); - llMainHolder.setLayoutParams(p); } - }); + });*/ + + /* ParallaxScrollView parSV = (ParallaxScrollView) inflatedView.findViewById(R.id.scroll_view);*/ + + if (lvMain instanceof Parallaxor) { + ((Parallaxor) lvMain).parallaxViewBy(inflatedView.findViewById(R.id.iv), 0.5f); + } + + return inflatedView; } @@ -218,11 +208,11 @@ public class DetailsHistoryEntryFragment extends Fragment { // totalHeight -= iv.getMeasuredHeight(); - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) llMain.getLayoutParams(); + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) llMain.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); llMain.setLayoutParams(params); - anotherView.requestLayout(); + } private class DetailHistoryAdapter extends BaseAdapter implements ListAdapter { @@ -310,9 +300,11 @@ public class DetailsHistoryEntryFragment extends Fragment { return convertView; } - /********************* + /** + * ****************** * ViewHolder Pattern - *********************/ + * ******************* + */ public class HistoryCallView { protected TextView historyCallState; protected TextView formatted_date; diff --git a/src/org/sflphone/views/parallaxscrollview/AnotherView.java b/src/org/sflphone/views/parallaxscrollview/AnotherView.java deleted file mode 100644 index 1b43d3caa012a8c2f55d75377343cf2791621ca9..0000000000000000000000000000000000000000 --- a/src/org/sflphone/views/parallaxscrollview/AnotherView.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.sflphone.views.parallaxscrollview; - -import android.content.Context; -import android.graphics.Canvas; -import android.util.AttributeSet; -import android.widget.LinearLayout; - -public class AnotherView extends LinearLayout{ - - private ScrollCallbacks mCallbacks; - - public AnotherView(Context context, AttributeSet attrs) - { - super(context, attrs); - } - - @Override - protected void onScrollChanged(int l, int t, int oldl, int oldt) - { - super.onScrollChanged(l, t, oldl, oldt); - if (mCallbacks != null) - { - mCallbacks.onScrollChanged(l, t, oldl, oldt); - } - } - - @Override - public int computeVerticalScrollRange() - { - return super.computeVerticalScrollRange(); - } - - public void setCallbacks(ScrollCallbacks listener) - { - mCallbacks = listener; - } - - @Override - public void draw(Canvas canvas) - { - super.draw(canvas); - } - - static interface ScrollCallbacks - { - public void onScrollChanged(int l, int t, int oldl, int oldt); - } - -} diff --git a/src/org/sflphone/views/parallaxscrollview/ObservableScrollView.java b/src/org/sflphone/views/parallaxscrollview/ObservableScrollView.java deleted file mode 100644 index 921121adcfda087551646a0bc2023b470fa2bcab..0000000000000000000000000000000000000000 --- a/src/org/sflphone/views/parallaxscrollview/ObservableScrollView.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.sflphone.views.parallaxscrollview; - -import android.content.Context; -import android.graphics.Canvas; -import android.util.AttributeSet; -import android.widget.ScrollView; - -public class ObservableScrollView extends ScrollView -{ - private ScrollCallbacks mCallbacks; - - public ObservableScrollView(Context context, AttributeSet attrs) - { - super(context, attrs); - } - - @Override - protected void onScrollChanged(int l, int t, int oldl, int oldt) - { - super.onScrollChanged(l, t, oldl, oldt); - if (mCallbacks != null) - { - mCallbacks.onScrollChanged(l, t, oldl, oldt); - } - } - - @Override - public int computeVerticalScrollRange() - { - return super.computeVerticalScrollRange(); - } - - public void setCallbacks(ScrollCallbacks listener) - { - mCallbacks = listener; - } - - @Override - public void draw(Canvas canvas) - { - super.draw(canvas); - } - - static interface ScrollCallbacks - { - public void onScrollChanged(int l, int t, int oldl, int oldt); - } -} \ No newline at end of file diff --git a/src/org/sflphone/views/parallaxscrollview/ParallaxScrollView.java b/src/org/sflphone/views/parallaxscrollview/ParallaxScrollView.java deleted file mode 100644 index 4102d10be11011adef4bc3525d08de403a59ef8c..0000000000000000000000000000000000000000 --- a/src/org/sflphone/views/parallaxscrollview/ParallaxScrollView.java +++ /dev/null @@ -1,396 +0,0 @@ -package org.sflphone.views.parallaxscrollview; - -import org.sflphone.R; -import org.sflphone.views.parallaxscrollview.ObservableScrollView.ScrollCallbacks; - -import android.content.Context; -import android.content.res.TypedArray; -import android.util.AttributeSet; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.ScrollView; - -/** - * A custom ScrollView that can accept a scroll listener. - */ -public class ParallaxScrollView extends ViewGroup -{ - private static final int DEFAULT_CHILD_GRAVITY = Gravity.CENTER_HORIZONTAL; - - private static final String TAG = "ParallaxScrollView"; - - private static float PARALLAX_OFFSET_DEFAULT = 0.2f; - - /** - * By how much should the background move to the foreground - */ - private float mParallaxOffset = PARALLAX_OFFSET_DEFAULT; - - private View mBackground; - private ObservableScrollView mScrollView; - private final ScrollCallbacks mScrollCallbacks = new ScrollCallbacks() - { - @Override - public void onScrollChanged(int l, int t, int oldl, int oldt) - { - requestLayout(); - } - }; - - // Layout stuff - - private int mBackgroundRight; - private int mBackgroundBottom; - /** - * Height of the Foreground ScrollView Content - */ - private int mScrollContentHeight = 0; - /** - * Height of the ScrollView, should be the same as this view - */ - private int mScrollViewHeight = 0; - /** - * The multipler by how much to move the background to the foreground - */ - private float mScrollDiff = 0f; - - public ParallaxScrollView(Context context, AttributeSet attrs, int defStyle) - { - super(context, attrs, defStyle); - - TypedArray a = context.getTheme().obtainStyledAttributes(attrs, - R.styleable.ParallaxScrollView, 0, 0); - - try - { - setParallaxOffset(a.getFloat(R.styleable.ParallaxScrollView_parallexOffset, - PARALLAX_OFFSET_DEFAULT)); - } - catch (Exception e) - { - } - finally - { - a.recycle(); - } - } - - public ParallaxScrollView(Context context, AttributeSet attrs) - { - this(context, attrs, 0); - } - - public ParallaxScrollView(Context context) - { - this(context, null); - } - - @Override - public void addView(View child) - { - if (getChildCount() > 1) - throw new IllegalStateException("ParallaxScrollView can host only two direct children"); - - super.addView(child); - } - - @Override - public void addView(View child, int index) - { - if (getChildCount() > 1) - throw new IllegalStateException("ParallaxScrollView can host only two direct children"); - super.addView(child, index); - } - - @Override - public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) - { - if (getChildCount() > 1) - throw new IllegalStateException("ParallaxScrollView can host only two direct children"); - super.addView(child, index, params); - } - - @Override - public void addView(View child, int width, int height) - { - if (getChildCount() > 1) - throw new IllegalStateException("ParallaxScrollView can host only two direct children"); - super.addView(child, width, height); - } - - @Override - public void addView(View child, android.view.ViewGroup.LayoutParams params) - { - if (getChildCount() > 1) - throw new IllegalStateException("ParallaxScrollView can host only two direct children"); - super.addView(child, params); - } - - /** - * Set the offset - * - * @param offset - * a number greater than 0.0 - */ - public void setParallaxOffset(float offset) - { - // Make sure we only get to .05 of a floating number - offset = (float) Math.rint(offset * 100) / 100; - if (offset > 0.0) - mParallaxOffset = offset; - else - mParallaxOffset = PARALLAX_OFFSET_DEFAULT; - - requestLayout(); - } - - /** - * Get the current offset - * - * @return - */ - public float getParallaxOffset() - { - return mParallaxOffset; - } - - /** - * Sort the views out after they have been inflated from a layout - */ - @Override - protected void onFinishInflate() - { - super.onFinishInflate(); - - if (getChildCount() > 2) - { - throw new IllegalStateException("ParallaxScrollView can host only two direct children"); - } - organiseViews(); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) - { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - - if (mScrollView != null) - { - measureChild(mScrollView, MeasureSpec.makeMeasureSpec( - MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST), - MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), - MeasureSpec.AT_MOST)); - - mScrollContentHeight = mScrollView.getChildAt(0).getMeasuredHeight(); - mScrollViewHeight = mScrollView.getMeasuredHeight(); - - } - if (mBackground != null) - { - int minHeight = 0; - minHeight = (int) (mScrollViewHeight + mParallaxOffset - * (mScrollContentHeight - mScrollViewHeight)); - minHeight = Math.max(minHeight, MeasureSpec.getSize(heightMeasureSpec)); - - measureChild(mBackground, MeasureSpec.makeMeasureSpec( - MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(minHeight, MeasureSpec.EXACTLY)); - - mBackgroundRight = getLeft() + mBackground.getMeasuredWidth(); - mBackgroundBottom = getTop() + mBackground.getMeasuredHeight(); - - mScrollDiff = (float) (mBackground.getMeasuredHeight() - mScrollViewHeight) - / (float) (mScrollContentHeight - mScrollViewHeight); - } - - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) - { - final int parentLeft = getPaddingLeft(); - final int parentRight = right - left - getPaddingRight(); - final int parentTop = getPaddingTop(); - final int parentBottom = bottom - top - getPaddingBottom(); - if (mScrollView != null && mScrollView.getVisibility() != GONE) - { - final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mScrollView - .getLayoutParams(); - - final int width = mScrollView.getMeasuredWidth(); - final int height = mScrollView.getMeasuredHeight(); - - int childLeft; - int childTop; - - int gravity = lp.gravity; - if (gravity == -1) - { - gravity = DEFAULT_CHILD_GRAVITY; - } - - final int horizontalGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; - final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; - - switch (horizontalGravity) - { - case Gravity.LEFT: - childLeft = parentLeft + lp.leftMargin; - break; - case Gravity.CENTER_HORIZONTAL: - childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - - lp.rightMargin; - break; - case Gravity.RIGHT: - childLeft = parentRight - width - lp.rightMargin; - break; - default: - childLeft = parentLeft + lp.leftMargin; - } - - switch (verticalGravity) - { - case Gravity.TOP: - childTop = parentTop + lp.topMargin; - break; - case Gravity.CENTER_VERTICAL: - childTop = parentTop + (parentBottom - parentTop - height) / 2 + lp.topMargin - - lp.bottomMargin; - break; - case Gravity.BOTTOM: - childTop = parentBottom - height - lp.bottomMargin; - break; - default: - childTop = parentTop + lp.topMargin; - } - - mScrollView.layout(childLeft, childTop, childLeft + width, childTop + height); - - } - - if (mBackground != null) - { - final int scrollYCenterOffset = mScrollView.getScrollY(); - final int offset = (int) (scrollYCenterOffset * mScrollDiff); - // Log.d(TAG, "Layout Scroll Y: " + scrollYCenterOffset + - // " ScrollDiff: " + mScrollDiff - // + " Background Offset:" + offset); - mBackground.layout(getLeft(), offset, mBackgroundRight, offset + mBackgroundBottom); - } - } - - /** - * {@inheritDoc} - */ - @Override - public LayoutParams generateLayoutParams(AttributeSet attrs) - { - return new FrameLayout.LayoutParams(getContext(), attrs); - } - - @Override - protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) - { - return new FrameLayout.LayoutParams(p); - } - - @Override - protected LayoutParams generateDefaultLayoutParams() - { - return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, - Gravity.CENTER_HORIZONTAL); - } - - /** - * {@inheritDoc} - */ - @Override - protected boolean checkLayoutParams(ViewGroup.LayoutParams p) - { - return p instanceof FrameLayout.LayoutParams; - } - - /** - * Take the direct children and sort them - */ - private void organiseViews() - { - if (getChildCount() <= 0) return; - - if (getChildCount() == 1) - { - // Get the only child - final View forground = getChildAt(0); - organiseBackgroundView(null); - organiseForgroundView(forground); - } - else if (getChildCount() == 2) - { - final View background = getChildAt(0); - final View foreground = getChildAt(1); - - organiseBackgroundView(background); - organiseForgroundView(foreground); - } - else - { - throw new IllegalStateException("ParallaxScrollView can host only two direct children"); - } - } - - private void organiseBackgroundView(final View background) - { - mBackground = background; - } - - private void organiseForgroundView(final View forground) - { - final int insertPos = getChildCount() - 1; - - // See if its a observable scroll view? - if (forground instanceof ObservableScrollView) - { - // Attach the callback to it. - mScrollView = (ObservableScrollView) forground; - } - else if (forground instanceof ViewGroup && !(forground instanceof ScrollView)) - { - // See if it is a view group but not a scroll view and wrap it - // with an observable ScrollView - mScrollView = new ObservableScrollView(getContext(), null); - removeView(forground); - mScrollView.addView(forground); - addView(mScrollView, insertPos); - } - else if (forground instanceof ScrollView) - { - final View child; - if (((ScrollView) forground).getChildCount() > 0) - child = ((ScrollView) forground).getChildAt(0); - else - child = null; - - mScrollView = new ObservableScrollView(getContext(), null); - removeView(forground); - if (child != null) mScrollView.addView(child); - addView(mScrollView, insertPos); - } - else if (forground instanceof View) - { - mScrollView = new ObservableScrollView(getContext(), null); - removeView(forground); - mScrollView.addView(forground); - addView(mScrollView, insertPos); - - } - if (mScrollView != null) - { - mScrollView.setLayoutParams(forground.getLayoutParams()); - mScrollView.setCallbacks(mScrollCallbacks); - mScrollView.setFillViewport(true); - } - } - -} \ No newline at end of file