-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to hide buttons/alert views (#1251)
- Loading branch information
Devota Aabel
authored
Sep 24, 2018
1 parent
d56e07d
commit 2d92c9b
Showing
13 changed files
with
639 additions
and
176 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
...igation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/FeedbackButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.content.Context; | ||
import android.support.constraint.ConstraintLayout; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.util.AttributeSet; | ||
|
||
public class FeedbackButton extends ConstraintLayout implements NavigationButton { | ||
private FloatingActionButton feedbackFab; | ||
private MultiOnClickListener multiOnClickListener; | ||
|
||
public FeedbackButton(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public FeedbackButton(Context context, AttributeSet attrs) { | ||
this(context, attrs, -1); | ||
} | ||
|
||
public FeedbackButton(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
initialize(context); | ||
} | ||
|
||
/** | ||
* Adds an onClickListener to the button | ||
* | ||
* @param onClickListener to add | ||
*/ | ||
@Override | ||
public void addOnClickListener(OnClickListener onClickListener) { | ||
multiOnClickListener.addListener(onClickListener); | ||
} | ||
|
||
/** | ||
* Removes an onClickListener from the button | ||
* | ||
* @param onClickListener to remove | ||
*/ | ||
@Override | ||
public void removeOnClickListener(OnClickListener onClickListener) { | ||
multiOnClickListener.removeListener(onClickListener); | ||
} | ||
|
||
/** | ||
* Hides the button | ||
*/ | ||
@Override | ||
public void hide() { | ||
setVisibility(GONE); | ||
} | ||
|
||
/** | ||
* Shows the button | ||
*/ | ||
@Override | ||
public void show() { | ||
setVisibility(VISIBLE); | ||
} | ||
|
||
@Override | ||
protected void onFinishInflate() { | ||
super.onFinishInflate(); | ||
bind(); | ||
} | ||
|
||
@Override | ||
protected void onAttachedToWindow() { | ||
super.onAttachedToWindow(); | ||
setupOnClickListeners(); | ||
} | ||
|
||
@Override | ||
protected void onDetachedFromWindow() { | ||
super.onDetachedFromWindow(); | ||
clearListeners(); | ||
} | ||
|
||
|
||
private void setupOnClickListeners() { | ||
multiOnClickListener = new MultiOnClickListener(); | ||
feedbackFab.setOnClickListener(multiOnClickListener); | ||
} | ||
|
||
private void clearListeners() { | ||
multiOnClickListener.clearListeners(); | ||
multiOnClickListener = null; | ||
setOnClickListener(null); | ||
} | ||
|
||
private void initialize(Context context) { | ||
inflate(context, R.layout.feedback_button_layout, this); | ||
} | ||
|
||
private void bind() { | ||
feedbackFab = findViewById(R.id.feedbackFab); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...n-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/MultiOnClickListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.view.View; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
class MultiOnClickListener implements View.OnClickListener { | ||
private Set<View.OnClickListener> onClickListeners; | ||
|
||
MultiOnClickListener() { | ||
this.onClickListeners = new HashSet<>(); | ||
} | ||
|
||
void addListener(View.OnClickListener onClickListener) { | ||
onClickListeners.add(onClickListener); | ||
} | ||
|
||
void removeListener(View.OnClickListener onClickListener) { | ||
onClickListeners.remove(onClickListener); | ||
} | ||
|
||
void clearListeners() { | ||
onClickListeners.clear(); | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
for (View.OnClickListener onClickListener : onClickListeners) { | ||
onClickListener.onClick(view); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.view.View; | ||
|
||
public interface NavigationButton { | ||
|
||
/** | ||
* Adds an onClickListener to the button | ||
* | ||
* @param onClickListener to add | ||
*/ | ||
void addOnClickListener(View.OnClickListener onClickListener); | ||
|
||
/** | ||
* Removes an onClickListener from the button | ||
* | ||
* @param onClickListener to remove | ||
*/ | ||
void removeOnClickListener(View.OnClickListener onClickListener); | ||
|
||
/** | ||
* Hides the button | ||
*/ | ||
void hide(); | ||
|
||
/** | ||
* Shows the button | ||
*/ | ||
void show(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.