Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
Merge commit '40378d0bf850b47af047322aa93b60cb7d138ae0' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Apr 26, 2014
2 parents 656f89a + 40378d0 commit 0ff8758
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 89 deletions.
36 changes: 2 additions & 34 deletions res/layout/fragment_type_simple.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,52 +97,20 @@
android:layout_below="@+id/fragment_contents"
android:layout_centerHorizontal="true" />

<ListView
<com.apb.beacon.common.NestedListView
android:id="@+id/fragment_action_list"
android:layout_height="wrap_content"
android:layout_below="@+id/b_action"
android:divider="@android:drawable/screen_background_light_transparent"
android:layout_width="match_parent" />

<ListView
<com.apb.beacon.common.NestedListView
android:id="@+id/fragment_item_list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@+id/fragment_action_list"
android:layout_marginTop="10dp" />

<!--<View-->
<!--android:layout_height="1dp"-->
<!--android:layout_below="@+id/fragment_item_list"-->
<!--android:background="@android:color/transparent"-->
<!--android:layout_width="fill_parent" />-->

<!--<Button-->
<!--android:id="@+id/b_action2"-->
<!--android:text="@string/page_button_action_text"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_below="@+id/fragment_item_list"-->
<!--android:background="@drawable/drawable_wizard_button"-->
<!--style="@style/activate_disguise_button"-->
<!--android:layout_marginTop="10dp"-->
<!--android:layout_marginBottom="10dp"-->
<!--android:layout_marginLeft="50dp"-->
<!--android:layout_marginRight="50dp"-->
<!--android:layout_centerHorizontal="true" />-->
</RelativeLayout>

</ScrollView>

<!-- <ListView
android:id="@+id/fragment_action_list"
android:layout_height="wrap_content"
android:divider="@android:drawable/screen_background_light_transparent"
android:layout_width="match_parent" />
<ListView
android:id="@+id/fragment_item_list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="10dp" />-->
</LinearLayout>
18 changes: 9 additions & 9 deletions res/layout/row_page_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
android:padding="10dp"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tv_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/page_title_text"
android:layout_toLeftOf="@+id/iv_arrow"
android:textSize="22sp" />

<ImageView
android:id="@+id/iv_arrow"
android:layout_height="30dp"
Expand All @@ -22,4 +13,13 @@
android:visibility="visible"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"/>

<TextView
android:id="@+id/tv_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/page_title_text"
android:layout_marginRight="50dp"
android:textSize="22sp" />
</RelativeLayout>
37 changes: 0 additions & 37 deletions src/main/java/com/apb/beacon/common/ListViewHelper.java

This file was deleted.

86 changes: 86 additions & 0 deletions src/main/java/com/apb/beacon/common/NestedListView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.apb.beacon.common;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
* Created by aoe on 4/27/14.
*/

public class NestedListView extends ListView implements View.OnTouchListener, AbsListView.OnScrollListener {

private int listViewTouchAction;
private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 99;

public NestedListView(Context context, AttributeSet attrs) {
super(context, attrs);
listViewTouchAction = -1;
setOnScrollListener(this);
setOnTouchListener(this);
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
scrollBy(0, -1);
}
}
}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

int newHeight = 0;
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (heightMode != MeasureSpec.EXACTLY) {
ListAdapter listAdapter = getAdapter();
if (listAdapter != null && !listAdapter.isEmpty()) {
int listPosition = 0;
for (listPosition = 0; listPosition < listAdapter.getCount()
&& listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) {
View listItem = listAdapter.getView(listPosition, null, this);
//now it will not throw a NPE if listItem is a ViewGroup instance
if (listItem instanceof ViewGroup) {
listItem.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
listItem.measure(widthMeasureSpec, heightMeasureSpec);
newHeight += listItem.getMeasuredHeight();
}
newHeight += getDividerHeight() * listPosition;
}
if ((heightMode == View.MeasureSpec.AT_MOST) && (newHeight > heightSize)) {
if (newHeight > heightSize) {
newHeight = heightSize;
}
}
} else {
newHeight = getMeasuredHeight();
}
setMeasuredDimension(getMeasuredWidth(), newHeight);
}

@Override
public boolean onTouch(View v, MotionEvent event) {
if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
scrollBy(0, 1);
}
}
return false;
}
}
17 changes: 8 additions & 9 deletions src/main/java/com/apb/beacon/fragment/SimpleFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.apb.beacon.MainActivity;
Expand All @@ -34,8 +33,8 @@
import com.apb.beacon.common.AppUtil;
import com.apb.beacon.common.ApplicationSettings;
import com.apb.beacon.common.ImageDownloader;
import com.apb.beacon.common.ListViewHelper;
import com.apb.beacon.common.MyTagHandler;
import com.apb.beacon.common.NestedListView;
import com.apb.beacon.data.PBDatabase;
import com.apb.beacon.model.Page;
import com.apb.beacon.model.PageItem;
Expand All @@ -57,8 +56,8 @@ public class SimpleFragment extends Fragment {
DisplayMetrics metrics;

TextView tvTitle, tvContent, tvIntro, tvWarning, tvStatus;
ListView lvItems;
ListView lvActions;
NestedListView lvItems;
NestedListView lvActions;
LinearLayout llWarning, llStatus;
Button bAction;

Expand Down Expand Up @@ -141,8 +140,8 @@ public void onClick(View v) {
}
});

lvItems = (ListView) view.findViewById(R.id.fragment_item_list);
lvActions = (ListView) view.findViewById(R.id.fragment_action_list);
lvItems = (NestedListView) view.findViewById(R.id.fragment_item_list);
lvActions = (NestedListView) view.findViewById(R.id.fragment_action_list);

llWarning = (LinearLayout) view.findViewById(R.id.ll_fragment_warning);
tvWarning = (TextView) view.findViewById(R.id.fragment_warning);
Expand Down Expand Up @@ -254,15 +253,15 @@ else if(pageId.equals("home-alerting")){
lvActions.setAdapter(pageActionAdapter);
pageActionAdapter.setData(currentPage.getAction());
}
ListViewHelper.getListViewSize(lvActions);


pageItemAdapter = new PageItemAdapter(activity, null);
lvItems.setAdapter(pageItemAdapter);
ListViewHelper.getListViewSize(lvItems);

pageItemAdapter.setData(currentPage.getItems());
ListViewHelper.getListViewSize(lvItems);

tvTitle.setFocusableInTouchMode(true);
tvTitle.requestFocus();

updateImages(true, currentPage.getContent());
}
Expand Down

0 comments on commit 0ff8758

Please sign in to comment.