auick action widget (tested/buds fixed)
This commit is contained in:
parent
8f6e25dda5
commit
e0b192d5a2
10 changed files with 105 additions and 112 deletions
8
OsmAnd/res/drawable/quick_action_controls_background.xml
Normal file
8
OsmAnd/res/drawable/quick_action_controls_background.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape android:shape="rectangle"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<solid android:color="@color/dashboard_background" />
|
||||
<corners android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp"/>
|
||||
|
||||
</shape>
|
|
@ -1,40 +1,39 @@
|
|||
<?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="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:background="@drawable/bg_card_light"
|
||||
android:layout_margin="8dp">
|
||||
android:orientation="vertical"
|
||||
android:clickable="true">
|
||||
|
||||
<net.osmand.plus.widgets.WrapContentViewPager
|
||||
android:layout_marginTop="2dp"
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="200dp" />
|
||||
|
||||
<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">
|
||||
android:background="@drawable/quick_action_controls_background"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnPrev"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="16dp"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/dots"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:layout_height="match_parent"/>
|
||||
android:orientation="horizontal" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnNext"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="4dp"
|
||||
android:layout_width="4dp"
|
||||
android:layout_marginRight="2dp"
|
||||
|
|
|
@ -1,36 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout 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"
|
||||
android:background="@color/color_white"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
grid:layout_columnWeight="1">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<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" />
|
||||
android:layout_marginTop="24dp"
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
<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:layout_marginTop="12dp"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:textSize="@dimen/default_sub_text_size"
|
||||
tools:text="Add marker" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/dividerRight"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="right"
|
||||
android:background="@color/dashboard_background"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/dividerBot"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/dashboard_background"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</FrameLayout>
|
|
@ -1,16 +1,11 @@
|
|||
<?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_width="match_parent"
|
||||
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">
|
||||
|
||||
|
||||
</android.support.v7.widget.GridLayout>
|
||||
grid:alignmentMode="alignMargins"
|
||||
grid:columnCount="3"/>
|
|
@ -99,6 +99,7 @@
|
|||
|
||||
<color name="icon_color">#727272</color>
|
||||
<color name="icon_color_light">#ccc</color>
|
||||
<color name="icon_color_dark">#ff4f4f4f</color>
|
||||
|
||||
<color name="on_map_icon_color">#505050</color>
|
||||
|
||||
|
|
|
@ -89,6 +89,9 @@ import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
|
|||
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionFactory;
|
||||
import net.osmand.plus.quickaction.QuickActionsWidget;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
|
|
|
@ -20,7 +20,7 @@ public class QuickActionFactory {
|
|||
return json;
|
||||
}
|
||||
|
||||
public List<QuickAction> parseActiveActionsList(String json) {
|
||||
public static List<QuickAction> parseActiveActionsList(String json) {
|
||||
|
||||
Type type = new TypeToken<List<QuickAction>>(){}.getType();
|
||||
ArrayList<QuickAction> quickActions = new Gson().fromJson(json, type);
|
||||
|
|
|
@ -109,7 +109,8 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
}
|
||||
});
|
||||
|
||||
dots = (RadioGroup) findViewById(R.id.radioGroup);
|
||||
dots = (LinearLayout) findViewById(R.id.dots);
|
||||
dots.removeAllViews();
|
||||
|
||||
if (pageCount > 1) {
|
||||
|
||||
|
@ -118,20 +119,23 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
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));
|
||||
dot.setImageDrawable(i == 0
|
||||
? getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.dashboard_blue)
|
||||
: getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light));
|
||||
|
||||
dots.addView(new RadioButton(context));
|
||||
dots.addView(dot);
|
||||
}
|
||||
}
|
||||
|
||||
controls = (LinearLayout) findViewById(R.id.controls);
|
||||
controls.setVisibility(pageCount > 1 ? VISIBLE : GONE);
|
||||
|
||||
updateControls(viewPager.getCurrentItem());
|
||||
}
|
||||
|
||||
private void updateControls(int position) {
|
||||
|
||||
next.setEnabled(viewPager.getAdapter().getCount() > position);
|
||||
next.setEnabled(viewPager.getAdapter().getCount() > position + 1);
|
||||
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));
|
||||
|
@ -141,12 +145,10 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
? 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.dashboard_blue)
|
||||
: getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light));
|
||||
}
|
||||
}
|
||||
|
@ -154,26 +156,28 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
private View createPageView(ViewGroup container, int position){
|
||||
|
||||
LayoutInflater li = getLayoutInflater();
|
||||
GridLayout gridLayout = (GridLayout) li
|
||||
.inflate(R.layout.quick_action_widget_page, container, false);
|
||||
View page = li.inflate(R.layout.quick_action_widget_page, container, false);
|
||||
GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid);
|
||||
|
||||
final int maxItems = position > 0
|
||||
? ELEMENT_PER_PAGE
|
||||
: (actions.size() > (ELEMENT_PER_PAGE / 2)
|
||||
? ELEMENT_PER_PAGE
|
||||
: (ELEMENT_PER_PAGE / 2));
|
||||
// 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++){
|
||||
final int maxItems = actions.size() == 1 ? 1 : ELEMENT_PER_PAGE;
|
||||
|
||||
for (int i = 0; i < maxItems; i++){
|
||||
|
||||
View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false);
|
||||
|
||||
if (i * (position + 1) < actions.size()) {
|
||||
if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
|
||||
|
||||
final QuickAction action = actions.get(i * (position + 1));
|
||||
final QuickAction action = actions.get(i + (position * ELEMENT_PER_PAGE));
|
||||
|
||||
((ImageView) view.findViewById(R.id.imageView))
|
||||
.setImageDrawable(getIconsCache()
|
||||
.getIcon(action.getIconRes(), R.color.icon_color));
|
||||
.getIcon(action.getIconRes(), R.color.icon_color_dark));
|
||||
|
||||
((TextView) view.findViewById(R.id.title))
|
||||
.setText(action.getNameRes());
|
||||
|
@ -187,6 +191,9 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
});
|
||||
}
|
||||
|
||||
view.findViewById(R.id.dividerBot).setVisibility(i < ELEMENT_PER_PAGE / 2 ? VISIBLE : GONE);
|
||||
view.findViewById(R.id.dividerRight).setVisibility(((i + 1) % 3) == 0 ? GONE : VISIBLE);
|
||||
|
||||
gridLayout.addView(view);
|
||||
}
|
||||
|
||||
|
@ -221,7 +228,7 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
}
|
||||
|
||||
private int countPage(){
|
||||
return (int) Math.ceil((actions.size()) / 6);
|
||||
return (int) Math.ceil((actions.size()) / (double) 6);
|
||||
}
|
||||
|
||||
private LayoutInflater getLayoutInflater(){
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
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