Skip to content

Commit

Permalink
Deprecate handling of "up" and HasParent interface
Browse files Browse the repository at this point in the history
In practice, handling "up" is rarely wanted and the current
implementation complicates internal semantics and pollutes clients' Path
class hierarchies. We may revisit the idea later.
  • Loading branch information
loganj committed Feb 22, 2015
1 parent 7d2b4c3 commit 471283c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 64 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Version 0.9 *(TBD)*

* Listener is now called Dispatcher, and can be set on a Flow after construction.

* Deprecated "up" navigation. We may revisit with a better implementation later.

* Updated sample app to demonstrate all of the above.

Version 0.8 *(2014-09-17)*
Expand Down
25 changes: 12 additions & 13 deletions flow-sample/src/main/java/com/example/flow/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.view.Menu;
import android.view.MenuItem;
import com.example.flow.pathview.HandlesBack;
import com.example.flow.pathview.HandlesUp;
import com.example.flow.util.FlowBundler;
import flow.Flow;
import flow.HasParent;
Expand All @@ -36,7 +35,6 @@
public class MainActivity extends Activity implements Flow.Dispatcher {
private PathContainerView container;
private HandlesBack containerAsBackTarget;
private HandlesUp containerAsUpTarget;

private Flow flow;

Expand Down Expand Up @@ -69,7 +67,6 @@ protected void onCreate(Bundle savedInstanceState) {

container = (PathContainerView) findViewById(R.id.container);
containerAsBackTarget = (HandlesBack) container;
containerAsUpTarget = (HandlesUp) container;
}

@Override protected void onResume() {
Expand Down Expand Up @@ -111,7 +108,8 @@ protected void onCreate(Bundle savedInstanceState) {

@Override public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
return containerAsUpTarget.onUpPressed();
onBackPressed();
return true;
} else {
return super.onOptionsItemSelected(item);
}
Expand All @@ -123,18 +121,19 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Override public void dispatch(Traversal traversal, TraversalCallback callback) {
@Override public void dispatch(Traversal traversal, final TraversalCallback callback) {
Path path = traversal.destination.current();
container.dispatch(traversal, callback);

setTitle(path.getClass().getSimpleName());

ActionBar actionBar = getActionBar();
boolean hasUp = path instanceof HasParent;
actionBar.setDisplayHomeAsUpEnabled(hasUp);
actionBar.setHomeButtonEnabled(hasUp);

invalidateOptionsMenu();
boolean canGoBack = traversal.destination.size() > 1;
actionBar.setDisplayHomeAsUpEnabled(canGoBack);
actionBar.setHomeButtonEnabled(canGoBack);
container.dispatch(traversal, new TraversalCallback() {
@Override public void onTraversalCompleted() {
invalidateOptionsMenu();
callback.onTraversalCompleted();
}
});
}

private FlowBundler getFlowBundler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,9 @@
import flow.Flow;

/**
* Support for {@link HandlesUp} and {@link HandlesBack}.
* Support for {@link HandlesBack}.
*/
public class UpAndBack {
public static boolean onUpPressed(View childView) {
if (childView instanceof HandlesUp) {
if (((HandlesUp) childView).onUpPressed()) {
return true;
}
}
// Try to go up. If up isn't supported, go back.
return Flow.get(childView).goUp() || onBackPressed(childView);
}
public class BackSupport {

public static boolean onBackPressed(View childView) {
if (childView instanceof HandlesBack) {
Expand All @@ -42,6 +33,6 @@ public static boolean onBackPressed(View childView) {
return Flow.get(childView).goBack();
}

private UpAndBack() {
private BackSupport() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/** A FrameLayout that can show screens for a {@link flow.Flow}. */
public class FramePathContainerView extends FrameLayout
implements HandlesBack, HandlesUp, PathContainerView {
implements HandlesBack, PathContainerView {
private final PathContainer container;
private boolean disabled;

Expand Down Expand Up @@ -69,12 +69,8 @@ protected FramePathContainerView(Context context, AttributeSet attrs, PathContai
});
}

@Override public boolean onUpPressed() {
return UpAndBack.onUpPressed(getCurrentChild());
}

@Override public boolean onBackPressed() {
return UpAndBack.onBackPressed(getCurrentChild());
return BackSupport.onBackPressed(getCurrentChild());
}

@Override public ViewGroup getCurrentChild() {
Expand Down
22 changes: 0 additions & 22 deletions flow-sample/src/main/java/com/example/flow/pathview/HandlesUp.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import com.example.flow.R;
import com.example.flow.pathview.FramePathContainerView;
import com.example.flow.pathview.HandlesBack;
import com.example.flow.pathview.HandlesUp;
import com.example.flow.pathview.UpAndBack;
import com.example.flow.pathview.BackSupport;
import flow.Flow;
import flow.Path;
import flow.PathContainerView;
Expand All @@ -21,7 +20,7 @@
* the explanation in {@link com.example.flow.MainActivity#onCreate}.
*/
public class TabletMasterDetailRoot extends LinearLayout
implements HandlesBack, HandlesUp, PathContainerView {
implements HandlesBack, PathContainerView {
private FramePathContainerView masterContainer;
private FramePathContainerView detailContainer;

Expand Down Expand Up @@ -78,11 +77,7 @@ class CountdownCallback implements Flow.TraversalCallback {
masterContainer.dispatch(traversal, callback);
}

@Override public boolean onUpPressed() {
return UpAndBack.onUpPressed(detailContainer);
}

@Override public boolean onBackPressed() {
return UpAndBack.onBackPressed(detailContainer);
return BackSupport.onBackPressed(detailContainer);
}
}
5 changes: 4 additions & 1 deletion flow/src/main/java/flow/Backstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ public Builder buildUpon() {
return backstack.toString();
}

public static Backstack fromUpChain(Path path) {
/**
* @deprecated Applications should implement this themselves, if necessary.
*/
@Deprecated public static Backstack fromUpChain(Path path) {
LinkedList<Path> newBackstack = new LinkedList<>();

Path current = path;
Expand Down
3 changes: 2 additions & 1 deletion flow/src/main/java/flow/Flow.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ public void replaceTo(final Path path) {
* Go up one screen.
*
* @return false if going up is not possible.
* @deprecated Applications should handle "up" themselves, if necessary.
*/
public boolean goUp() {
@Deprecated public boolean goUp() {
boolean canGoUp = false;
if (backstack.current() instanceof HasParent || (pendingTraversal != null
&& pendingTraversal.state != TraversalState.FINISHED)) {
Expand Down
4 changes: 3 additions & 1 deletion flow/src/main/java/flow/HasParent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
/**
* Describes the parent of a specific screen which is used to support the up affordance.
* Implementing screens are required to be able to return an instance of their parent.
*
* @deprecated Up handling is deprecated, left to applications to implement if needed.
*/
public interface HasParent {
@Deprecated public interface HasParent {
Path getParent();
}

0 comments on commit 471283c

Please sign in to comment.