mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-18 19:59:09 +00:00
PanelButton has can now have a large header or a smaller footer caption
This commit is contained in:
@@ -23,12 +23,25 @@
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/header_margin_top"
|
||||
android:textAppearance="?attr/textPanelHeader"
|
||||
android:visibility="visible"
|
||||
tools:text="@string/start_mode" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/panel_button_footer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="@dimen/header_margin_top"
|
||||
android:textAppearance="?attr/textPanelCaption"
|
||||
android:visibility="gone"
|
||||
tools:text="@string/start_mode" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/panel_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_above="@id/panel_button_footer"
|
||||
android:layout_below="@id/panel_button_header">
|
||||
|
||||
<ImageView
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/start_procedure"
|
||||
app:buttonCaption="@string/start_procedure"
|
||||
app:buttonType="typeValue"
|
||||
app:linePosition="right"/>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/start_mode"
|
||||
app:buttonCaption="@string/start_mode"
|
||||
app:buttonType="typeImage"/>
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -32,7 +32,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/gate_start_pathfinder"
|
||||
app:buttonCaption="@string/gate_start_pathfinder"
|
||||
app:buttonType="typeValue"
|
||||
app:linePosition="right"/>
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/gate_start_timing"
|
||||
app:buttonCaption="@string/gate_start_timing"
|
||||
app:buttonType="typeValue"/>
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -49,7 +49,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/race_group"
|
||||
app:buttonCaption="@string/race_group"
|
||||
app:buttonSwitch=""
|
||||
app:buttonType="typeSwitch"/>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/race_factor"
|
||||
app:buttonCaption="@string/race_factor"
|
||||
app:buttonType="typeValue"
|
||||
app:linePosition="right" />
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/course"
|
||||
app:buttonCaption="@string/course"
|
||||
app:buttonType="typeValue"
|
||||
app:linePosition="right" />
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/wind"
|
||||
app:buttonCaption="@string/wind"
|
||||
app:buttonType="typeValue" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/start_procedure"
|
||||
app:buttonCaption="@string/start_procedure"
|
||||
app:buttonType="typeValue" />
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -22,7 +22,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/start_mode"
|
||||
app:buttonCaption="@string/start_mode"
|
||||
app:buttonType="typeImage" />
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -30,7 +30,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/gate_start_pathfinder"
|
||||
app:buttonCaption="@string/gate_start_pathfinder"
|
||||
app:buttonType="typeValue" />
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -38,7 +38,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/gate_start_timing"
|
||||
app:buttonCaption="@string/gate_start_timing"
|
||||
app:buttonType="typeValue" />
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -46,7 +46,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/race_group"
|
||||
app:buttonCaption="@string/race_group"
|
||||
app:buttonSwitch=""
|
||||
app:buttonType="typeSwitch" />
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/race_factor"
|
||||
app:buttonCaption="@string/race_factor"
|
||||
app:buttonType="typeValue" />
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -63,7 +63,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/course"
|
||||
app:buttonCaption="@string/course"
|
||||
app:buttonType="typeValue" />
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.PanelButton
|
||||
@@ -71,7 +71,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:buttonHeader="@string/wind"
|
||||
app:buttonCaption="@string/wind"
|
||||
app:buttonType="typeValue" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="PanelButton">
|
||||
<attr name="buttonHeader" format="reference|string" />
|
||||
<attr name="buttonCaption" format="reference|string" />
|
||||
|
||||
<attr name="buttonType" format="enum">
|
||||
<enum name="typeValue" value="0" />
|
||||
@@ -27,6 +27,11 @@
|
||||
<enum name="right" value="2" />
|
||||
</attr>
|
||||
|
||||
<attr name="captionPosition" format="enum">
|
||||
<enum name="top" value="0" />
|
||||
<enum name="bottom" value="1" />
|
||||
</attr>
|
||||
|
||||
<attr name="showLock" format="boolean" />
|
||||
</declare-styleable>
|
||||
|
||||
|
||||
+119
-26
@@ -5,6 +5,7 @@ import android.content.DialogInterface;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
@@ -25,19 +26,67 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
public final static int LEVEL_NORMAL = 0;
|
||||
public final static int LEVEL_TOGGLED = 1;
|
||||
|
||||
public enum PanelType {
|
||||
Value(0),
|
||||
Image(1),
|
||||
Switch(2),
|
||||
Flag(3);
|
||||
|
||||
private int value;
|
||||
|
||||
PanelType(int type) {
|
||||
value = type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PanelType fromId(int id) {
|
||||
for (PanelType type : PanelType.values()) {
|
||||
if (type.value == id) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public enum CaptionPosition {
|
||||
top(0),
|
||||
bottom(1);
|
||||
|
||||
private int value;
|
||||
|
||||
CaptionPosition(int position) {
|
||||
value = position;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CaptionPosition fromId(int id) {
|
||||
for (CaptionPosition position : CaptionPosition.values()) {
|
||||
if (position.value == id) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private View mLayer;
|
||||
private View mLock;
|
||||
|
||||
private String mCaption;
|
||||
private TextView mHeader;
|
||||
private TextView mFooter;
|
||||
|
||||
private View mContent;
|
||||
private TextView mText;
|
||||
private TextView mValue;
|
||||
private ImageView mImage;
|
||||
private Switch mSwitch;
|
||||
|
||||
private ImageView mMarker;
|
||||
private View mLine;
|
||||
|
||||
private int mType;
|
||||
private PanelType mType;
|
||||
private CaptionPosition mCaptionPosition;
|
||||
|
||||
private PanelButtonClick mListener;
|
||||
private TouchEventListener mTouchEventListener;
|
||||
@@ -59,12 +108,12 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
@Override
|
||||
public void run() {
|
||||
if (mLock != null && mLock.getVisibility() == VISIBLE && isNormal()) {
|
||||
if (mType == 2 && mSwitch != null) {
|
||||
if (mType == PanelType.Switch && mSwitch != null) {
|
||||
mSwitch.setChecked(!mSwitch.isChecked());
|
||||
}
|
||||
showChangeDialog(PanelButton.this);
|
||||
} else {
|
||||
if (mType == 2) {
|
||||
if (mType == PanelType.Switch) {
|
||||
if (mListener != null && mSwitch != null) {
|
||||
mListener.onChangedSwitch(PanelButton.this, mSwitch.isChecked());
|
||||
}
|
||||
@@ -80,7 +129,7 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
mTouchEventListener = new TouchEventListener(this);
|
||||
mTouchEventListener.setClickRunnable(clickRunnable);
|
||||
|
||||
setPanelType(a.getInt(R.styleable.PanelButton_buttonType, 0));
|
||||
setPanelType(PanelType.fromId(a.getInt(R.styleable.PanelButton_buttonType, PanelType.Value.value)));
|
||||
|
||||
switch (mType) {
|
||||
default:
|
||||
@@ -91,9 +140,11 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
mContent = findViewById(R.id.panel_content);
|
||||
|
||||
mHeader = (TextView) findViewById(R.id.panel_button_header);
|
||||
setHeader(a.getString(R.styleable.PanelButton_buttonHeader));
|
||||
mFooter = (TextView) findViewById(R.id.panel_button_footer);
|
||||
setCaptionPosition(CaptionPosition.fromId(a.getInt(R.styleable.PanelButton_captionPosition, CaptionPosition.top.value)));
|
||||
setCaption(a.getString(R.styleable.PanelButton_buttonCaption));
|
||||
|
||||
mText = (TextView) findViewById(R.id.panel_value);
|
||||
mValue = (TextView) findViewById(R.id.panel_value);
|
||||
setPanelText(a.getString(R.styleable.PanelButton_buttonValue));
|
||||
|
||||
mImage = (ImageView) findViewById(R.id.panel_image);
|
||||
@@ -118,9 +169,43 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void setHeader(String header) {
|
||||
public void setCaptionPosition(CaptionPosition position) {
|
||||
mCaptionPosition = position;
|
||||
if (mHeader != null) {
|
||||
mHeader.setText(header);
|
||||
mHeader.setVisibility(GONE);
|
||||
}
|
||||
if (mFooter != null) {
|
||||
mFooter.setVisibility(GONE);
|
||||
}
|
||||
switch (mCaptionPosition) {
|
||||
case bottom:
|
||||
if (mFooter != null) {
|
||||
mFooter.setVisibility(VISIBLE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (mHeader != null) {
|
||||
mHeader.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
setCaption(mCaption);
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
mCaption = caption;
|
||||
|
||||
switch (mCaptionPosition) {
|
||||
case bottom:
|
||||
if (mFooter != null) {
|
||||
mFooter.setText(caption);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (mHeader != null) {
|
||||
mHeader.setText(caption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,15 +225,19 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
}
|
||||
}
|
||||
|
||||
public void setPanelType(int type) {
|
||||
public void setPanelType(PanelType type) {
|
||||
mType = type;
|
||||
switch (type) {
|
||||
case 2:
|
||||
mTouchEventListener.setEnabled(false);
|
||||
break;
|
||||
if (mType != null) {
|
||||
switch (mType) {
|
||||
case Switch:
|
||||
mTouchEventListener.setEnabled(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
mTouchEventListener.setEnabled(true);
|
||||
default:
|
||||
mTouchEventListener.setEnabled(true);
|
||||
}
|
||||
} else {
|
||||
mTouchEventListener.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,8 +247,8 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
|
||||
public void setPanelText(String text) {
|
||||
hideValues();
|
||||
if (mText != null) {
|
||||
mText.setText(text);
|
||||
if (mValue != null) {
|
||||
mValue.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,8 +300,8 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
}
|
||||
|
||||
private void hideValues() {
|
||||
if (mText != null) {
|
||||
mText.setVisibility(GONE);
|
||||
if (mValue != null) {
|
||||
mValue.setVisibility(GONE);
|
||||
}
|
||||
|
||||
if (mImage != null) {
|
||||
@@ -224,22 +313,26 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
}
|
||||
|
||||
switch (mType) {
|
||||
case 0:
|
||||
if (mText != null) {
|
||||
mText.setVisibility(VISIBLE);
|
||||
case Value:
|
||||
if (mValue != null) {
|
||||
mValue.setVisibility(VISIBLE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case Image:
|
||||
if (mImage != null) {
|
||||
mImage.setVisibility(VISIBLE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case Switch:
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setVisibility(VISIBLE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +352,7 @@ public class PanelButton extends FrameLayout implements DialogInterface.OnClickL
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (mType == 2) {
|
||||
if (mType == PanelType.Switch) {
|
||||
if (mListener != null & mSwitch != null) {
|
||||
mSwitch.setChecked(!mSwitch.isChecked());
|
||||
mListener.onChangedSwitch(this, mSwitch.isChecked());
|
||||
|
||||
Reference in New Issue
Block a user