Java Code Examples for android.view.ViewGroup#removeViews()

The following examples show how to use android.view.ViewGroup#removeViews() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private void destroyView(View rootView) {
  try {
    if (rootView instanceof ViewGroup) {
      ViewGroup cViewGroup = ((ViewGroup) rootView);
      for (int index = 0; index < cViewGroup.getChildCount(); index++) {
        destroyView(cViewGroup.getChildAt(index));
      }

      cViewGroup.removeViews(0, ((ViewGroup) rootView).getChildCount());
      // Ensure that the viewgroup's status to be normal
      WXReflectionUtils.setValue(rootView, "mChildrenCount", 0);

    }
    if(rootView instanceof Destroyable){
      ((Destroyable)rootView).destroy();
    }
  } catch (Exception e) {
    WXLogUtils.e("WXSDKInstance destroyView Exception: ", e);
  }
}
 
Example 2
Source File: WXSDKInstance.java    From weex-uikit with MIT License 6 votes vote down vote up
private void destroyView(View rootView) {
  try {
    if (rootView instanceof ViewGroup) {
      ViewGroup cViewGroup = ((ViewGroup) rootView);
      for (int index = 0; index < cViewGroup.getChildCount(); index++) {
        destroyView(cViewGroup.getChildAt(index));
      }

      cViewGroup.removeViews(0, ((ViewGroup) rootView).getChildCount());
      // Ensure that the viewgroup's status to be normal
      WXReflectionUtils.setValue(rootView, "mChildrenCount", 0);

    }
    if(rootView instanceof Destroyable){
      ((Destroyable)rootView).destroy();
    }
  } catch (Exception e) {
    WXLogUtils.e("WXSDKInstance destroyView Exception: ", e);
  }
}
 
Example 3
Source File: WXSDKInstance.java    From weex with Apache License 2.0 6 votes vote down vote up
private void destroyView(View rootView) {
  try {
    if (rootView instanceof ViewGroup) {
      ViewGroup cViewGroup = ((ViewGroup) rootView);
      for (int index = 0; index < cViewGroup.getChildCount(); index++) {
        destroyView(cViewGroup.getChildAt(index));
      }

      cViewGroup.removeViews(0, ((ViewGroup) rootView).getChildCount());
      // Ensure that the viewgroup's status to be normal
      WXReflectionUtils.setValue(rootView, "mChildrenCount", 0);

    }
  } catch (Exception e) {
    WXLogUtils.e("WXSDKInstance destroyView Exception: " + WXLogUtils.getStackTrace(e));
  }
}
 
Example 4
Source File: Anvil.java    From anvil with MIT License 6 votes vote down vote up
public static void unmount(View v, boolean removeChildren) {
    Mount m = mounts.get(v);
    if (m != null) {
        mounts.remove(v);
        if (v instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) v;

            int childCount = viewGroup.getChildCount();
            for (int i = 0; i < childCount; i++) {
                unmount(viewGroup.getChildAt(i));
            }
            if (removeChildren) {
                viewGroup.removeViews(0, childCount);
            }
        }
    }
}
 
Example 5
Source File: NoteViewHolder.java    From science-journal with Apache License 2.0 5 votes vote down vote up
public static void loadSnapshotsIntoList(
    ViewGroup valuesList, Label label, AppAccount appAccount) {
  Context context = valuesList.getContext();
  SnapshotLabelValue snapshotLabelValue = label.getSnapshotLabelValue();

  valuesList.setVisibility(View.VISIBLE);
  // Make sure it has the correct number of views, re-using as many as possible.
  int childCount = valuesList.getChildCount();
  int snapshotsCount = snapshotLabelValue.getSnapshotsCount();
  if (childCount < snapshotsCount) {
    for (int i = 0; i < snapshotsCount - childCount; i++) {
      LayoutInflater.from(context).inflate(R.layout.snapshot_value_details, valuesList);
    }
  } else if (childCount > snapshotsCount) {
    valuesList.removeViews(0, childCount - snapshotsCount);
  }

  SensorAppearanceProvider sensorAppearanceProvider =
      AppSingleton.getInstance(context).getSensorAppearanceProvider(appAccount);

  String valueFormat = context.getResources().getString(R.string.data_with_units);
  for (int i = 0; i < snapshotsCount; i++) {
    GoosciSnapshotValue.SnapshotLabelValue.SensorSnapshot snapshot =
        snapshotLabelValue.getSnapshots(i);
    ViewGroup snapshotLayout = (ViewGroup) valuesList.getChildAt(i);

    GoosciSensorAppearance.BasicSensorAppearance appearance =
        snapshot.getSensor().getRememberedAppearance();
    TextView sensorName = (TextView) snapshotLayout.findViewById(R.id.sensor_name);
    sensorName.setCompoundDrawablesRelative(null, null, null, null);
    sensorName.setText(appearance.getName());
    String value =
        BuiltInSensorAppearance.formatValue(
            snapshot.getValue(), appearance.getPointsAfterDecimal());
    ((TextView) snapshotLayout.findViewById(R.id.sensor_value))
        .setText(String.format(valueFormat, value, appearance.getUnits()));

    loadLargeDrawable(appearance, sensorAppearanceProvider, snapshotLayout, snapshot.getValue());
  }
}
 
Example 6
Source File: ColorPickerPreferenceWidget.java    From memoir with Apache License 2.0 4 votes vote down vote up
static void setPreviewColor(View preferenceView, int color, boolean isEnabled) {
    if (preferenceView != null && preferenceView instanceof ViewGroup) {
        Context context = preferenceView.getContext();
        ViewGroup widgetFrameView = ((ViewGroup) preferenceView.findViewById(android.R.id.widget_frame));

        if (widgetFrameView != null) {

            ColorPickerPreferenceWidget widgetView = null;

            // find already created preview image
            int count = widgetFrameView.getChildCount();
            for (int i = 0; i < count; i++) {
                View view = widgetFrameView.getChildAt(i);
                if (view instanceof ColorPickerPreferenceWidget && IMAGE_VIEW_TAG.equals(view.getTag())) {
                    widgetView = (ColorPickerPreferenceWidget) view;
                    break;
                }
            }
            if (widgetView == null) {
                // remove already created preview image and create new one
                if (count > 0) 
                    widgetFrameView.removeViews(0, count);
                widgetView = new ColorPickerPreferenceWidget(context);
                widgetView.setTag(IMAGE_VIEW_TAG);
                widgetFrameView.setVisibility(View.VISIBLE);
                widgetFrameView.setPadding(
                        widgetFrameView.getPaddingLeft(),
                        widgetFrameView.getPaddingTop(),
                        (int) (Util.getDisplayDensity(context) * 8),
                        widgetFrameView.getPaddingBottom()
                );
                widgetFrameView.addView(widgetView);
            }

            // determine and set colors
            int borderColor = Color.WHITE;
            if (!isEnabled) {
                color = reduceBrightness(color, 1);
                borderColor = reduceBrightness(borderColor, 1);
            }
            widgetView.setColor(color, borderColor);
        }
    }
}