Add text button to the notification
This commit is contained in:
parent
d2c56bb451
commit
939eeb3a77
4 changed files with 82 additions and 0 deletions
|
@ -437,6 +437,21 @@
|
|||
android:visibility="gone"
|
||||
tools:text="New version of OsmAnd+ with 50% discount"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/widget_top_bar_text_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textColor="?attr/wikivoyage_active_color"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:visibility="gone"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Some button"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
|
|
|
@ -214,6 +214,21 @@
|
|||
android:visibility="gone"
|
||||
tools:text="New version of OsmAnd+ with 50% discount"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/widget_top_bar_text_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textColor="?attr/wikivoyage_active_color"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:visibility="gone"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Some button"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.os.AsyncTask;
|
|||
import android.provider.Settings.Secure;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
|
@ -200,6 +201,11 @@ public class DiscountHelper {
|
|||
toolbarController.setBackBtnIconIds(iconId, iconId);
|
||||
toolbarController.setBackBtnIconClrs(data.iconColor, data.iconColor);
|
||||
toolbarController.setStatusBarColor(data.statusBarColor);
|
||||
if (!TextUtils.isEmpty(data.textBtnTitle)) {
|
||||
toolbarController.setTextBtnVisible(true);
|
||||
toolbarController.setTextBtnTitle(data.textBtnTitle);
|
||||
toolbarController.setTextBtnTitleClrs(data.textBtnTitleColor, data.textBtnTitleColor);
|
||||
}
|
||||
if (!Algorithms.isEmpty(data.url)) {
|
||||
View.OnClickListener clickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -212,6 +218,7 @@ public class DiscountHelper {
|
|||
};
|
||||
toolbarController.setOnBackButtonClickListener(clickListener);
|
||||
toolbarController.setOnTitleClickListener(clickListener);
|
||||
toolbarController.setOnTextBtnClickListener(clickListener);
|
||||
}
|
||||
toolbarController.setOnCloseButtonClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -296,6 +303,7 @@ public class DiscountHelper {
|
|||
String description;
|
||||
String iconId;
|
||||
String url;
|
||||
String textBtnTitle;
|
||||
|
||||
@ColorInt
|
||||
int iconColor = -1;
|
||||
|
@ -307,6 +315,8 @@ public class DiscountHelper {
|
|||
int descrColor = -1;
|
||||
@ColorInt
|
||||
int statusBarColor = -1;
|
||||
@ColorInt
|
||||
int textBtnTitleColor = -1;
|
||||
|
||||
static ControllerData parse(OsmandApplication app, JSONObject obj) throws JSONException {
|
||||
ControllerData res = new ControllerData();
|
||||
|
@ -314,11 +324,13 @@ public class DiscountHelper {
|
|||
res.description = obj.getString("description");
|
||||
res.iconId = obj.getString("icon");
|
||||
res.url = parseUrl(app, obj.getString("url"));
|
||||
res.textBtnTitle = obj.optString("button_title");
|
||||
res.iconColor = parseColor("icon_color", obj);
|
||||
res.bgColor = parseColor("bg_color", obj);
|
||||
res.titleColor = parseColor("title_color", obj);
|
||||
res.descrColor = parseColor("description_color", obj);
|
||||
res.statusBarColor = parseColor("status_bar_color", obj);
|
||||
res.textBtnTitleColor = parseColor("button_title_color", obj);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -274,6 +274,7 @@ public class MapInfoWidgetsFactory {
|
|||
|
||||
boolean refreshBtnVisible = false;
|
||||
boolean saveViewVisible = false;
|
||||
boolean textBtnVisible = false;
|
||||
protected boolean topBarSwitchVisible = false;
|
||||
protected boolean topBarSwitchChecked = false;
|
||||
|
||||
|
@ -293,6 +294,10 @@ public class MapInfoWidgetsFactory {
|
|||
int descrTextClrLight = -1;
|
||||
@ColorInt
|
||||
int descrTextClrDark = -1;
|
||||
@ColorInt
|
||||
int textBtnTitleClrLight = -1;
|
||||
@ColorInt
|
||||
int textBtnTitleClrDark = -1;
|
||||
|
||||
boolean singleLineTitle = true;
|
||||
|
||||
|
@ -300,6 +305,7 @@ public class MapInfoWidgetsFactory {
|
|||
|
||||
String title = "";
|
||||
String description = null;
|
||||
String textBtnTitle = null;
|
||||
|
||||
int saveViewTextId = -1;
|
||||
|
||||
|
@ -308,6 +314,7 @@ public class MapInfoWidgetsFactory {
|
|||
OnClickListener onCloseButtonClickListener;
|
||||
OnClickListener onRefreshButtonClickListener;
|
||||
OnClickListener onSaveViewClickListener;
|
||||
OnClickListener onTextBtnClickListener;
|
||||
OnCheckedChangeListener onSwitchCheckedChangeListener;
|
||||
|
||||
Runnable onCloseToolbarListener;
|
||||
|
@ -412,6 +419,14 @@ public class MapInfoWidgetsFactory {
|
|||
this.saveViewTextId = id;
|
||||
}
|
||||
|
||||
public void setTextBtnVisible(boolean visible) {
|
||||
this.textBtnVisible = visible;
|
||||
}
|
||||
|
||||
public void setTextBtnTitle(String title) {
|
||||
this.textBtnTitle = title;
|
||||
}
|
||||
|
||||
public void setTopBarSwitchVisible(boolean visible) {
|
||||
this.topBarSwitchVisible = visible;
|
||||
}
|
||||
|
@ -440,6 +455,11 @@ public class MapInfoWidgetsFactory {
|
|||
this.descrTextClrDark = descrTextClrDark;
|
||||
}
|
||||
|
||||
public void setTextBtnTitleClrs(int textBtnTitleClrLight, int textBtnTitleClrDark) {
|
||||
this.textBtnTitleClrLight = textBtnTitleClrLight;
|
||||
this.textBtnTitleClrDark = textBtnTitleClrDark;
|
||||
}
|
||||
|
||||
public void setOnBackButtonClickListener(OnClickListener onBackButtonClickListener) {
|
||||
this.onBackButtonClickListener = onBackButtonClickListener;
|
||||
}
|
||||
|
@ -456,6 +476,10 @@ public class MapInfoWidgetsFactory {
|
|||
this.onSaveViewClickListener = onSaveViewClickListener;
|
||||
}
|
||||
|
||||
public void setOnTextBtnClickListener(OnClickListener onTextBtnClickListener) {
|
||||
this.onTextBtnClickListener = onTextBtnClickListener;
|
||||
}
|
||||
|
||||
public void setOnSwitchCheckedChangeListener(OnCheckedChangeListener onSwitchCheckedChangeListener) {
|
||||
this.onSwitchCheckedChangeListener = onSwitchCheckedChangeListener;
|
||||
}
|
||||
|
@ -519,6 +543,7 @@ public class MapInfoWidgetsFactory {
|
|||
private ImageButton refreshButton;
|
||||
private ImageButton closeButton;
|
||||
private TextView saveView;
|
||||
private TextView textBtn;
|
||||
private SwitchCompat topBarSwitch;
|
||||
private View shadowView;
|
||||
private boolean nightMode;
|
||||
|
@ -535,6 +560,7 @@ public class MapInfoWidgetsFactory {
|
|||
closeButton = (ImageButton) map.findViewById(R.id.widget_top_bar_close_button);
|
||||
titleView = (TextView) map.findViewById(R.id.widget_top_bar_title);
|
||||
saveView = (TextView) map.findViewById(R.id.widget_top_bar_save);
|
||||
textBtn = (TextView) map.findViewById(R.id.widget_top_bar_text_btn);
|
||||
descrView = (TextView) map.findViewById(R.id.widget_top_bar_description);
|
||||
topBarSwitch = (SwitchCompat) map.findViewById(R.id.widget_top_bar_switch);
|
||||
shadowView = map.findViewById(R.id.widget_top_bar_shadow);
|
||||
|
@ -653,6 +679,7 @@ public class MapInfoWidgetsFactory {
|
|||
closeButton.setOnClickListener(controller.onCloseButtonClickListener);
|
||||
refreshButton.setOnClickListener(controller.onRefreshButtonClickListener);
|
||||
saveView.setOnClickListener(controller.onSaveViewClickListener);
|
||||
textBtn.setOnClickListener(controller.onTextBtnClickListener);
|
||||
topBarSwitch.setOnCheckedChangeListener(controller.onSwitchCheckedChangeListener);
|
||||
}
|
||||
|
||||
|
@ -690,6 +717,7 @@ public class MapInfoWidgetsFactory {
|
|||
int titleTextClrId = nightMode ? controller.titleTextClrDarkId : controller.titleTextClrLightId;
|
||||
int descrTextClr = nightMode ? controller.descrTextClrDark : controller.descrTextClrLight;
|
||||
int descrTextClrId = nightMode ? controller.descrTextClrDarkId : controller.descrTextClrLightId;
|
||||
int textBtnTitleClr = nightMode ? controller.textBtnTitleClrDark : controller.textBtnTitleClrLight;
|
||||
|
||||
if (bg != null) {
|
||||
topBarLayout.setBackgroundDrawable(bg);
|
||||
|
@ -720,6 +748,9 @@ public class MapInfoWidgetsFactory {
|
|||
titleView.setTextColor(titleColor);
|
||||
descrView.setTextColor(descrColor);
|
||||
saveView.setTextColor(titleColor);
|
||||
if (textBtnTitleClr != -1) {
|
||||
textBtn.setTextColor(textBtnTitleClr);
|
||||
}
|
||||
|
||||
titleView.setSingleLine(controller.singleLineTitle);
|
||||
|
||||
|
@ -748,6 +779,15 @@ public class MapInfoWidgetsFactory {
|
|||
} else if (saveView.getVisibility() == View.VISIBLE) {
|
||||
saveView.setVisibility(View.GONE);
|
||||
}
|
||||
if (controller.textBtnVisible) {
|
||||
textBtn.setText(controller.textBtnTitle);
|
||||
textBtn.setContentDescription(controller.textBtnTitle);
|
||||
if (textBtn.getVisibility() == View.GONE) {
|
||||
textBtn.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (textBtn.getVisibility() == View.VISIBLE) {
|
||||
textBtn.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateColors() {
|
||||
|
|
Loading…
Reference in a new issue