quick action widget (need to test)
This commit is contained in:
parent
17c5a349c8
commit
a3ce4d673b
13 changed files with 446 additions and 53 deletions
|
@ -4,13 +4,13 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingTop="24dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dialog_add_action_title"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
|
@ -20,6 +20,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dialog_add_action_subhead"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
|
@ -27,7 +28,6 @@
|
|||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_marginRight="24dp"
|
||||
android:layout_weight="1"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -35,13 +35,14 @@
|
|||
|
||||
<Button
|
||||
android:id="@+id/btnDismiss"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/btn_dismiss"
|
||||
android:layout_gravity="right"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:textColor="@color/dashboard_blue"
|
||||
android:background="@color/color_transparent"
|
||||
android:textAllCaps="true"/>
|
||||
</LinearLayout>
|
|
@ -6,6 +6,9 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="48dp"
|
||||
android:paddingRight="24dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_card_light"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<net.osmand.plus.widgets.WrapContentViewPager
|
||||
android:layout_marginTop="2dp"
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/controls"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:background="@color/dashboard_background"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="2dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnPrev"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="16dp"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:paddingRight="16dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/dots"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnNext"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
7
OsmAnd/res/layout/quick_action_widget_dot.xml
Normal file
7
OsmAnd/res/layout/quick_action_widget_dot.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="4dp"
|
||||
android:layout_width="4dp"
|
||||
android:layout_marginRight="2dp"
|
||||
android:layout_marginLeft="2dp"/>
|
|
@ -1,6 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
xmlns:grid="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/color_white"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
grid:layout_columnWeight="1">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_action_flag_dark" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Add marker" />
|
||||
|
||||
</LinearLayout>
|
110
OsmAnd/res/layout/quick_action_widget_page.xml
Normal file
110
OsmAnd/res/layout/quick_action_widget_page.xml
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.GridLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:grid="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/grid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:horizontalSpacing="1dp"
|
||||
android:verticalSpacing="1dp"
|
||||
android:background="@color/dashboard_background"
|
||||
grid:orientation="horizontal"
|
||||
grid:alignmentMode="alignBounds"
|
||||
grid:columnCount="3">
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:grid="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
grid:layout_columnWeight="1">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_action_flag_dark" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Add marker" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:grid="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
grid:layout_columnWeight="1">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_action_flag_dark" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Add marker" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:grid="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
grid:layout_columnWeight="1">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_action_flag_dark" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Add marker" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.GridLayout>
|
|
@ -2467,6 +2467,7 @@ If you need help with OsmAnd application, please contact our support team: suppo
|
|||
<string name="quick_action_item_action">Action %d</string>
|
||||
<string name="quick_action_item_screen">Screen %d</string>
|
||||
<string name="quick_action_add_marker">Add marker</string>
|
||||
<string name="quick_action_new_action">Add action</string>
|
||||
<string name="quick_action_add_favorite">Add favorite</string>
|
||||
<string name="dialog_add_action_title">Add Action</string>
|
||||
<string name="dialog_add_action_subhead">Create item</string>
|
||||
|
|
|
@ -28,12 +28,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
|||
|
||||
public static final String TAG = AddQuickActionDialog.class.getSimpleName();
|
||||
|
||||
public interface QuickActionSelectionListener {
|
||||
|
||||
void onActionSelected(QuickAction action);
|
||||
}
|
||||
|
||||
protected QuickActionSelectionListener selectionListener;
|
||||
protected QuickAction.QuickActionSelectionListener selectionListener;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
|
@ -9,6 +9,11 @@ import java.util.HashMap;
|
|||
|
||||
public class QuickAction {
|
||||
|
||||
public interface QuickActionSelectionListener {
|
||||
|
||||
void onActionSelected(QuickAction action);
|
||||
}
|
||||
|
||||
protected int id;
|
||||
protected @StringRes int nameRes;
|
||||
protected @DrawableRes int iconRes;
|
||||
|
|
|
@ -40,7 +40,11 @@ public class QuickActionFactory {
|
|||
|
||||
public QuickAction produceAction(QuickAction quickAction){
|
||||
|
||||
if (quickAction.id == MarkerAction.ID) {
|
||||
if (quickAction.id == NewAction.ID) {
|
||||
|
||||
return new NewAction(quickAction);
|
||||
|
||||
} else if (quickAction.id == MarkerAction.ID) {
|
||||
|
||||
return new MarkerAction(quickAction);
|
||||
|
||||
|
@ -51,10 +55,37 @@ public class QuickActionFactory {
|
|||
} else return quickAction;
|
||||
}
|
||||
|
||||
public static class MarkerAction extends QuickAction {
|
||||
public static class NewAction extends QuickAction {
|
||||
|
||||
public static final int ID = 1;
|
||||
|
||||
protected NewAction(){
|
||||
id = ID;
|
||||
nameRes = R.string.quick_action_new_action;
|
||||
iconRes = R.drawable.ic_action_plus;
|
||||
}
|
||||
|
||||
public NewAction(QuickAction quickAction) {
|
||||
super(quickAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
//TODO do some action
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawUI(ViewGroup parent) {
|
||||
|
||||
//TODO inflate view & fill with params
|
||||
}
|
||||
}
|
||||
|
||||
public static class MarkerAction extends QuickAction {
|
||||
|
||||
public static final int ID = 2;
|
||||
|
||||
private MarkerAction(){
|
||||
id = ID;
|
||||
nameRes = R.string.quick_action_add_marker;
|
||||
|
@ -80,7 +111,7 @@ public class QuickActionFactory {
|
|||
|
||||
public static class FavoriteAction extends QuickAction {
|
||||
|
||||
public static final int ID = 2;
|
||||
public static final int ID = 3;
|
||||
|
||||
public FavoriteAction() {
|
||||
id = ID;
|
||||
|
|
|
@ -36,7 +36,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
|||
* Created by okorsun on 20.12.16.
|
||||
*/
|
||||
|
||||
public class QuickActionListFragment extends BaseOsmAndFragment implements AddQuickActionDialog.QuickActionSelectionListener {
|
||||
public class QuickActionListFragment extends BaseOsmAndFragment implements QuickAction.QuickActionSelectionListener {
|
||||
public static final String TAG = QuickActionListFragment.class.getSimpleName();
|
||||
|
||||
RecyclerView quickActionRV;
|
||||
|
|
|
@ -3,13 +3,20 @@ package net.osmand.plus.quickaction;
|
|||
import android.content.Context;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.GridLayout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -17,78 +24,186 @@ import java.util.List;
|
|||
|
||||
public class QuickActionsWidget extends LinearLayout {
|
||||
|
||||
private static final int ELEMENT_PER_PAGE = 6;
|
||||
|
||||
private QuickAction.QuickActionSelectionListener selectionListener;
|
||||
|
||||
private List<QuickAction> actions;
|
||||
|
||||
private ImageButton next;
|
||||
private ImageButton prev;
|
||||
|
||||
private ViewPager viewPager;
|
||||
private LinearLayout dots;
|
||||
private LinearLayout controls;
|
||||
|
||||
public QuickActionsWidget(Context context) {
|
||||
super(context);
|
||||
setup();
|
||||
inflate(context, R.layout.quick_action_widget, this);
|
||||
}
|
||||
|
||||
public QuickActionsWidget(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setup();
|
||||
inflate(context, R.layout.quick_action_widget, this);
|
||||
}
|
||||
|
||||
public QuickActionsWidget(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
setup();
|
||||
inflate(context, R.layout.quick_action_widget, this);
|
||||
}
|
||||
|
||||
public void setActions(List<QuickAction> actions){
|
||||
|
||||
this.actions = actions;
|
||||
this.actions.add(new QuickActionFactory.NewAction());
|
||||
|
||||
setupLayout(getContext(), countPage());
|
||||
}
|
||||
|
||||
private void setup(){
|
||||
inflate(getContext(), R.layout.quick_action_widget, this);
|
||||
|
||||
// viewPager = (ViewPager) findViewById(R.id.viewPager);
|
||||
// viewPager.setAdapter(new ViewsPagerAdapter());
|
||||
//
|
||||
// next = (ImageButton) findViewById(R.id.btnNext);
|
||||
// prev = (ImageButton) findViewById(R.id.btnPrev);
|
||||
//
|
||||
// next.setOnClickListener(new OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
//
|
||||
// if (viewPager.getAdapter().getCount() > viewPager.getCurrentItem() + 1) {
|
||||
// viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// prev.setOnClickListener(new OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
//
|
||||
// if (viewPager.getCurrentItem() - 1 >= 0) {
|
||||
// viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
public void setSelectionListener(QuickAction.QuickActionSelectionListener selectionListener) {
|
||||
this.selectionListener = selectionListener;
|
||||
}
|
||||
|
||||
private View createPageView(ViewGroup container){
|
||||
//TODO setup it
|
||||
return getLayoutInflater().inflate(R.layout.quick_action_widget_item, container, false);
|
||||
private void setupLayout(Context context, int pageCount){
|
||||
|
||||
viewPager = (ViewPager) findViewById(R.id.viewPager);
|
||||
viewPager.setAdapter(new ViewsPagerAdapter());
|
||||
|
||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
updateControls(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
next = (ImageButton) findViewById(R.id.btnNext);
|
||||
prev = (ImageButton) findViewById(R.id.btnPrev);
|
||||
|
||||
next.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
if (viewPager.getAdapter().getCount() > viewPager.getCurrentItem() + 1) {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
prev.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
if (viewPager.getCurrentItem() - 1 >= 0) {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dots = (RadioGroup) findViewById(R.id.radioGroup);
|
||||
|
||||
if (pageCount > 1) {
|
||||
|
||||
for (int i = 0; i < pageCount; i++) {
|
||||
|
||||
ImageView dot = (ImageView) getLayoutInflater()
|
||||
.inflate(R.layout.quick_action_widget_dot, dots, false);
|
||||
|
||||
dot.setImageDrawable(getIconsCache().getIcon(
|
||||
R.drawable.ic_dot_position, R.color.icon_color_light));
|
||||
|
||||
dots.addView(new RadioButton(context));
|
||||
}
|
||||
}
|
||||
|
||||
controls = (LinearLayout) findViewById(R.id.controls);
|
||||
controls.setVisibility(pageCount > 1 ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
private void updateControls(int position) {
|
||||
|
||||
next.setEnabled(viewPager.getAdapter().getCount() > position);
|
||||
next.setImageDrawable(next.isEnabled()
|
||||
? getIconsCache().getIcon(R.drawable.ic_arrow_forward, R.color.icon_color)
|
||||
: getIconsCache().getIcon(R.drawable.ic_arrow_forward, R.color.icon_color_light));
|
||||
|
||||
prev.setEnabled(position > 0);
|
||||
prev.setImageDrawable(prev.isEnabled()
|
||||
? getIconsCache().getIcon(R.drawable.ic_arrow_back, R.color.icon_color)
|
||||
: getIconsCache().getIcon(R.drawable.ic_arrow_back, R.color.icon_color_light));
|
||||
|
||||
dots.removeAllViews();
|
||||
|
||||
for (int i = 0; i < dots.getChildCount(); i++){
|
||||
|
||||
((ImageView) dots.getChildAt(i)).setImageDrawable(i == position
|
||||
? getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light)
|
||||
: getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light));
|
||||
}
|
||||
}
|
||||
|
||||
private View createPageView(ViewGroup container, int position){
|
||||
|
||||
LayoutInflater li = getLayoutInflater();
|
||||
GridLayout gridLayout = (GridLayout) li
|
||||
.inflate(R.layout.quick_action_widget_page, container, false);
|
||||
|
||||
final int maxItems = position > 0
|
||||
? ELEMENT_PER_PAGE
|
||||
: (actions.size() > (ELEMENT_PER_PAGE / 2)
|
||||
? ELEMENT_PER_PAGE
|
||||
: (ELEMENT_PER_PAGE / 2));
|
||||
|
||||
for (int i = position == 0 ? 0 : 1; i > ELEMENT_PER_PAGE; i++){
|
||||
|
||||
View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false);
|
||||
|
||||
if (i * (position + 1) < actions.size()) {
|
||||
|
||||
final QuickAction action = actions.get(i * (position + 1));
|
||||
|
||||
((ImageView) view.findViewById(R.id.imageView))
|
||||
.setImageDrawable(getIconsCache()
|
||||
.getIcon(action.getIconRes(), R.color.icon_color));
|
||||
|
||||
((TextView) view.findViewById(R.id.title))
|
||||
.setText(action.getNameRes());
|
||||
|
||||
view.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
if (selectionListener != null) selectionListener.onActionSelected(action);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
gridLayout.addView(view);
|
||||
}
|
||||
|
||||
return gridLayout;
|
||||
}
|
||||
|
||||
private class ViewsPagerAdapter extends PagerAdapter {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return (int) Math.ceil(actions.size() / 6);
|
||||
return countPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
|
||||
View view = createPageView(container);
|
||||
View view = createPageView(container, position);
|
||||
container.addView(view, 0);
|
||||
|
||||
return view;
|
||||
|
@ -105,7 +220,19 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
}
|
||||
}
|
||||
|
||||
private int countPage(){
|
||||
return (int) Math.ceil((actions.size()) / 6);
|
||||
}
|
||||
|
||||
private LayoutInflater getLayoutInflater(){
|
||||
return (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
private OsmandApplication getApplication(){
|
||||
return (OsmandApplication)(getContext().getApplicationContext());
|
||||
}
|
||||
|
||||
private IconsCache getIconsCache(){
|
||||
return getApplication().getIconsCache();
|
||||
}
|
||||
}
|
||||
|
|
40
OsmAnd/src/net/osmand/plus/widgets/WrapContentViewPager.java
Normal file
40
OsmAnd/src/net/osmand/plus/widgets/WrapContentViewPager.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package net.osmand.plus.widgets;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class WrapContentViewPager extends ViewPager {
|
||||
|
||||
private int mCurrentPagePosition = 0;
|
||||
|
||||
public WrapContentViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public WrapContentViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
try {
|
||||
View child = getChildAt(mCurrentPagePosition);
|
||||
if (child != null) {
|
||||
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||
int h = child.getMeasuredHeight();
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
public void reMeasureCurrentPage(int position) {
|
||||
mCurrentPagePosition = position;
|
||||
requestLayout();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue