-
-
Notifications
You must be signed in to change notification settings - Fork 24
ADFA-2128: Handle IllegalArgumentException when previewing NavigationView #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f893e52
fix(ADFA-2128): Show error when navigation view is not a child of Dra…
dara-abijo-adfa ed7220a
feat(ADFA-2128): Add support for DrawerLayout in layout editor
dara-abijo-adfa 1dab1c3
fix(ADFA-2128): Add missing resource
dara-abijo-adfa 41debd7
Minor fixes
dara-abijo-adfa 7b703c7
Merge branch 'stage' into ADFA-2128
dara-abijo-adfa b9bae53
Merge branch 'stage' into ADFA-2128
dara-abijo-adfa f8f7d53
Merge branch 'stage' into ADFA-2128
dara-abijo-adfa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
81 changes: 48 additions & 33 deletions
81
...appdevforall/codeonthego/layouteditor/editor/palette/containers/NavigationViewDesign.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,42 +1,57 @@ | ||
| package org.appdevforall.codeonthego.layouteditor.editor.palette.containers; | ||
|
|
||
| import com.google.android.material.navigation.NavigationView; | ||
| import android.content.Context; | ||
| import android.graphics.Canvas; | ||
| import com.google.android.material.navigation.NavigationView; | ||
| import org.appdevforall.codeonthego.layouteditor.utils.Constants; | ||
| import org.appdevforall.codeonthego.layouteditor.utils.Utils; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class NavigationViewDesign extends NavigationView { | ||
|
|
||
| private boolean drawStrokeEnabled; | ||
| private boolean isBlueprint; | ||
|
|
||
| public NavigationViewDesign(Context context) { | ||
| super(context); | ||
| } | ||
|
|
||
| @Override | ||
| protected void dispatchDraw(Canvas canvas) { | ||
| super.dispatchDraw(canvas); | ||
|
|
||
| if (drawStrokeEnabled) | ||
| Utils.drawDashPathStroke( | ||
| this, canvas, isBlueprint ? Constants.BLUEPRINT_DASH_COLOR : Constants.DESIGN_DASH_COLOR); | ||
| } | ||
|
|
||
| public void setStrokeEnabled(boolean enabled) { | ||
| drawStrokeEnabled = enabled; | ||
| invalidate(); | ||
| } | ||
|
|
||
| @Override | ||
| public void draw(Canvas canvas) { | ||
| if (isBlueprint) Utils.drawDashPathStroke(this, canvas, Constants.BLUEPRINT_DASH_COLOR); | ||
| else super.draw(canvas); | ||
| } | ||
|
|
||
| public void setBlueprint(boolean isBlueprint) { | ||
| this.isBlueprint = isBlueprint; | ||
| invalidate(); | ||
| } | ||
|
|
||
| private boolean drawStrokeEnabled; | ||
| private boolean isBlueprint; | ||
|
|
||
| private final Logger logger = LoggerFactory.getLogger(NavigationViewDesign.class); | ||
|
|
||
| public NavigationViewDesign(Context context) { | ||
| super(context); | ||
| } | ||
|
|
||
| @Override | ||
| public void draw(Canvas canvas) { | ||
| if (isBlueprint) | ||
| Utils.drawDashPathStroke(this, canvas, Constants.BLUEPRINT_DASH_COLOR); | ||
| else | ||
| super.draw(canvas); | ||
| } | ||
|
|
||
| public void setBlueprint(boolean isBlueprint) { | ||
| this.isBlueprint = isBlueprint; | ||
| invalidate(); | ||
| } | ||
|
|
||
| public void setStrokeEnabled(boolean enabled) { | ||
| drawStrokeEnabled = enabled; | ||
| invalidate(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void dispatchDraw(Canvas canvas) { | ||
| super.dispatchDraw(canvas); | ||
|
|
||
| if (drawStrokeEnabled) | ||
| Utils.drawDashPathStroke( | ||
| this, canvas, isBlueprint ? Constants.BLUEPRINT_DASH_COLOR : Constants.DESIGN_DASH_COLOR); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onAttachedToWindow() { | ||
| try { | ||
| super.onAttachedToWindow(); | ||
| } catch (IllegalArgumentException e) { | ||
| logger.error("NavigationView should be placed in a DrawerLayout", e); | ||
| } | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
...va/org/appdevforall/codeonthego/layouteditor/editor/palette/layouts/DrawerLayoutDesign.kt
This file contains hidden or 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,56 @@ | ||
| package org.appdevforall.codeonthego.layouteditor.editor.palette.layouts | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.Canvas | ||
| import androidx.drawerlayout.widget.DrawerLayout | ||
| import org.appdevforall.codeonthego.layouteditor.utils.Constants | ||
| import org.appdevforall.codeonthego.layouteditor.utils.Utils | ||
| import org.slf4j.Logger | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
| class DrawerLayoutDesign( | ||
| context: Context, | ||
| ) : DrawerLayout(context) { | ||
| private var drawStrokeEnabled = false | ||
| private var isBlueprint = false | ||
|
|
||
| private val logger: Logger = LoggerFactory.getLogger(DrawerLayoutDesign::class.java) | ||
|
|
||
| override fun dispatchDraw(canvas: Canvas) { | ||
| super.dispatchDraw(canvas) | ||
|
|
||
| if (drawStrokeEnabled) { | ||
| Utils.drawDashPathStroke( | ||
| this, | ||
| canvas, | ||
| if (isBlueprint) Constants.BLUEPRINT_DASH_COLOR else Constants.DESIGN_DASH_COLOR, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| override fun draw(canvas: Canvas) { | ||
| if (isBlueprint) { | ||
| Utils.drawDashPathStroke(this, canvas, Constants.BLUEPRINT_DASH_COLOR) | ||
| } else { | ||
| super.draw(canvas) | ||
| } | ||
|
dara-abijo-adfa marked this conversation as resolved.
|
||
| } | ||
|
|
||
| fun setStrokeEnabled(enabled: Boolean) { | ||
| drawStrokeEnabled = enabled | ||
| invalidate() | ||
| } | ||
|
|
||
| fun setBlueprint(isBlueprint: Boolean) { | ||
| this.isBlueprint = isBlueprint | ||
| invalidate() | ||
| } | ||
|
|
||
| override fun onAttachedToWindow() { | ||
| try { | ||
| super.onAttachedToWindow() | ||
| } catch (e: Exception) { | ||
| logger.error("Error in previewing DrawerLayoutDesign", e) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.