quick action widget night mode
This commit is contained in:
parent
dc31eda502
commit
a5b10d9957
4 changed files with 46 additions and 15 deletions
|
@ -2,7 +2,7 @@
|
|||
<shape android:shape="rectangle"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<solid android:color="@color/dashboard_background" />
|
||||
<solid android:color="?attr/dashboard_divider" />
|
||||
<corners android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp"/>
|
||||
|
||||
</shape>
|
|
@ -6,6 +6,7 @@
|
|||
android:background="@drawable/quick_action_background">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
android:layout_height="24dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="24dp"
|
||||
android:tint="?attr/primary_icon_color"
|
||||
android:scaleType="centerInside"/>
|
||||
|
||||
<TextView
|
||||
|
@ -45,7 +46,7 @@
|
|||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="right"
|
||||
android:background="@color/dashboard_background"
|
||||
android:background="?attr/dashboard_divider"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<View
|
||||
|
@ -53,7 +54,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/dashboard_background"
|
||||
android:background="?attr/dashboard_divider"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</FrameLayout>
|
|
@ -2,8 +2,11 @@ package net.osmand.plus.quickaction;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.view.ContextThemeWrapper;
|
||||
import android.support.v7.widget.GridLayout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -19,6 +22,7 @@ import android.widget.TextView;
|
|||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -38,20 +42,18 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
private ViewPager viewPager;
|
||||
private LinearLayout dots;
|
||||
private LinearLayout controls;
|
||||
private View container;
|
||||
|
||||
public QuickActionsWidget(Context context) {
|
||||
super(context);
|
||||
inflate(context, R.layout.quick_action_widget, this);
|
||||
}
|
||||
|
||||
public QuickActionsWidget(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
inflate(context, R.layout.quick_action_widget, this);
|
||||
}
|
||||
|
||||
public QuickActionsWidget(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
inflate(context, R.layout.quick_action_widget, this);
|
||||
}
|
||||
|
||||
public void setActions(List<QuickAction> actions){
|
||||
|
@ -59,6 +61,7 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
this.actions = actions;
|
||||
this.actions.add(new QuickActionFactory.NewAction());
|
||||
|
||||
removeAllViews();
|
||||
setupLayout(getContext(), countPage());
|
||||
}
|
||||
|
||||
|
@ -68,9 +71,20 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
|
||||
private void setupLayout(Context context, int pageCount){
|
||||
|
||||
boolean light = ((OsmandApplication) context.getApplicationContext()).getSettings().isLightContent();
|
||||
|
||||
inflate(new ContextThemeWrapper(context, light
|
||||
? R.style.OsmandLightTheme
|
||||
: R.style.OsmandDarkTheme), R.layout.quick_action_widget, this);
|
||||
|
||||
container = findViewById(R.id.container);
|
||||
viewPager = (ViewPager) findViewById(R.id.viewPager);
|
||||
viewPager.setAdapter(new ViewsPagerAdapter());
|
||||
|
||||
container.setBackgroundResource(light
|
||||
? R.drawable.bg_card_light
|
||||
: R.drawable.bg_card_dark);
|
||||
|
||||
viewPager.getLayoutParams().height = actions.size() > ELEMENT_PER_PAGE / 2
|
||||
? (int) getResources().getDimension(R.dimen.quick_action_widget_height_big)
|
||||
: (int) getResources().getDimension(R.dimen.quick_action_widget_height_small);
|
||||
|
@ -122,6 +136,8 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
|
||||
if (pageCount > 1) {
|
||||
|
||||
int color = light ? R.color.icon_color_light : R.color.white_50_transparent;
|
||||
|
||||
for (int i = 0; i < pageCount; i++) {
|
||||
|
||||
ImageView dot = (ImageView) getLayoutInflater()
|
||||
|
@ -129,7 +145,7 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
|
||||
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));
|
||||
: getIconsCache().getIcon(R.drawable.ic_dot_position, color));
|
||||
|
||||
dots.addView(dot);
|
||||
}
|
||||
|
@ -143,27 +159,37 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
|
||||
private void updateControls(int position) {
|
||||
|
||||
boolean light = ((OsmandApplication) getContext().getApplicationContext()).getSettings().isLightContent();
|
||||
|
||||
int colorEnabled = light ? R.color.icon_color : R.color.color_white;
|
||||
int colorDisabled = light ? R.color.icon_color_light : R.color.white_50_transparent;
|
||||
|
||||
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));
|
||||
? getIconsCache().getIcon(R.drawable.ic_arrow_forward, colorEnabled)
|
||||
: getIconsCache().getIcon(R.drawable.ic_arrow_forward, colorDisabled));
|
||||
|
||||
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));
|
||||
? getIconsCache().getIcon(R.drawable.ic_arrow_back, colorEnabled)
|
||||
: getIconsCache().getIcon(R.drawable.ic_arrow_back, colorDisabled));
|
||||
|
||||
for (int i = 0; i < dots.getChildCount(); i++){
|
||||
|
||||
((ImageView) dots.getChildAt(i)).setImageDrawable(i == position
|
||||
? getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.dashboard_blue)
|
||||
: getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light));
|
||||
: getIconsCache().getIcon(R.drawable.ic_dot_position, colorDisabled));
|
||||
}
|
||||
}
|
||||
|
||||
private View createPageView(ViewGroup container, int position){
|
||||
|
||||
LayoutInflater li = getLayoutInflater();
|
||||
boolean light = ((OsmandApplication) getContext().getApplicationContext()).getSettings().isLightContent();
|
||||
|
||||
LayoutInflater li = getLayoutInflater(light
|
||||
? R.style.OsmandLightTheme
|
||||
: R.style.OsmandDarkTheme);
|
||||
|
||||
View page = li.inflate(R.layout.quick_action_widget_page, container, false);
|
||||
GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid);
|
||||
|
||||
|
@ -179,8 +205,7 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
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_dark));
|
||||
.setImageResource(action.getIconRes());
|
||||
|
||||
((TextView) view.findViewById(R.id.title))
|
||||
.setText(action.getName(getContext()));
|
||||
|
@ -243,6 +268,10 @@ public class QuickActionsWidget extends LinearLayout {
|
|||
return (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
private LayoutInflater getLayoutInflater(@StyleRes int style){
|
||||
return (LayoutInflater) new ContextThemeWrapper(getContext(), style).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
private OsmandApplication getApplication(){
|
||||
return (OsmandApplication)(getContext().getApplicationContext());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue