Skip to content

Commit

Permalink
refactor: refactor Utility, remove NavigationScene reference
Browse files Browse the repository at this point in the history
  • Loading branch information
qii committed Dec 22, 2020
1 parent 24f1a96 commit c408f59
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.bytedance.scene;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.List;

Expand All @@ -26,4 +27,7 @@ public interface SceneParent {
void disableSupportRestore();

boolean isSupportRestore();

@Nullable
String getSceneDebugInfo(@NonNull Scene scene);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.bytedance.scene.group;

import android.app.Activity;
import android.arch.lifecycle.Lifecycle;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.*;
Expand Down Expand Up @@ -655,6 +656,26 @@ public final void unregisterChildSceneLifecycleCallbacks(@NonNull ChildSceneLife
}
}

@Override
@Nullable
public String getSceneDebugInfo(@NonNull Scene scene) {
if (scene.getParentScene() == null) {
return null;
}
if (scene.getParentScene() != this) {
throw new IllegalArgumentException("Scene parent is incorrect");
}
String tag = findTagByScene(scene);
boolean isHidden = !isShow(scene);

StringBuilder stringBuilder = new StringBuilder("tag: " + tag + " ");
if (isHidden) {
stringBuilder.append("hidden ");
}

return stringBuilder.toString();
}

/**
* @hide
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,27 @@ public void unregisterChildSceneLifecycleCallbacks(@NonNull ChildSceneLifecycleC
}
}

@Override
@Nullable
public String getSceneDebugInfo(@NonNull Scene scene) {
if (scene.getParentScene() == null) {
return null;
}
if (scene.getParentScene() != this) {
throw new IllegalArgumentException("Scene parent is incorrect");
}
Lifecycle.State state = scene.getLifecycle().getCurrentState();
String status = null;
if (state == Lifecycle.State.RESUMED) {
status = "resumed";
} else if (state == Lifecycle.State.STARTED) {
status = "paused";
} else if (state == Lifecycle.State.CREATED) {
status = "stopped";
}
return "status: " + status + " ";
}

/**
* @hide
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import com.bytedance.scene.Scene;
import com.bytedance.scene.group.GroupScene;
import com.bytedance.scene.navigation.NavigationScene;
import com.bytedance.scene.SceneParent;

import java.util.List;

Expand Down Expand Up @@ -232,55 +231,24 @@ public static String getViewHierarchy(@NonNull Scene scene) {

private static void getViewHierarchy(Scene scene, StringBuilder desc, int margin) {
desc.append(getViewMessage(scene, margin));
if (scene instanceof NavigationScene) {
if (scene instanceof SceneParent) {
margin++;
NavigationScene navigationScene = (NavigationScene) scene;
List<Scene> list = navigationScene.getSceneList();
for (int i = 0; i < list.size(); i++) {
getViewHierarchy(list.get(i), desc, margin);
}
} else if (scene instanceof GroupScene) {
margin++;
GroupScene groupScene = (GroupScene) scene;
List<Scene> list = groupScene.getSceneList();
SceneParent sceneParent = (SceneParent) scene;
List<Scene> list = sceneParent.getSceneList();
for (int i = 0; i < list.size(); i++) {
getViewHierarchy(list.get(i), desc, margin);
}
}
}

private static String getViewMessage(Scene scene, int marginOffset) {
String tag = null;
boolean isHidden = false;
String status = null;
if (scene.getParentScene() instanceof GroupScene) {
GroupScene groupScene = (GroupScene) scene.getParentScene();
tag = groupScene.findTagByScene(scene);
isHidden = !groupScene.isShow(scene);
} else if (scene.getParentScene() instanceof NavigationScene) {
Lifecycle.State state = scene.getLifecycle().getCurrentState();
if (state == Lifecycle.State.RESUMED) {
status = "resumed";
} else if (state == Lifecycle.State.STARTED) {
status = "paused";
} else if (state == Lifecycle.State.CREATED) {
status = "stopped";
}
}

Scene parentScene = scene.getParentScene();
String repeated = new String(new char[marginOffset]).replace("\0", " ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(repeated + "[" + scene.getClass().getSimpleName() + "] ");

if (tag != null) {
stringBuilder.append("tag: " + tag + " ");
if (isHidden) {
stringBuilder.append("hidden ");
}
}

if (status != null) {
stringBuilder.append("status: " + status + " ");
if (parentScene != null) {
stringBuilder.append(((SceneParent) parentScene).getSceneDebugInfo(scene));
}

String resourceId = null;
Expand All @@ -294,7 +262,6 @@ private static String getViewMessage(Scene scene, int marginOffset) {
return stringBuilder.toString();
}


public static int getColorWithAlpha(float alpha, int baseColor) {
int a = Math.min(255, Math.max(0, (int) (alpha * 255))) << 24;
int rgb = 0x00ffffff & baseColor;
Expand Down

0 comments on commit c408f59

Please sign in to comment.