Example usage for android.widget RelativeLayout removeView

List of usage examples for android.widget RelativeLayout removeView

Introduction

In this page you can find the example usage for android.widget RelativeLayout removeView.

Prototype

@Override
public void removeView(View view) 

Source Link

Document

Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.

Usage

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private void removeOutOfBoundsAnnotations() {
    RelativeLayout relativeLayout = (RelativeLayout) findViewById(
            R.id.supersede_feedbacklibrary_annotate_image_layout);
    if (relativeLayout != null) {
        List<View> toRemove = new ArrayList<>();
        int newBitmapWidth = annotateImageView.getBitmapWidth();
        int newBitmapHeight = annotateImageView.getBitmapHeight();
        float fraction = 0.5f;
        for (int i = 0; i < relativeLayout.getChildCount(); ++i) {
            View child = relativeLayout.getChildAt(i);
            if (child instanceof StickerAnnotationView || child instanceof TextAnnotationView) {
                // A fraction the sticker should be visible, if not the sticker will be removed
                float deleteThresholdX = child.getWidth() * fraction;
                float deleteThresholdY = child.getHeight() * fraction;
                float x = child.getX();
                float y = child.getY();

                boolean xOk = true;
                boolean yOk = true;
                if (x < 0) {
                    xOk = Math.abs(x) < deleteThresholdX;
                } else if (x > 0 && !(x < 0)) {
                    xOk = x + deleteThresholdX < newBitmapWidth;
                }//from  w w  w.j  a va 2 s  .  c om
                if (y < 0) {
                    yOk = Math.abs(y) < deleteThresholdY;
                } else if (y > 0 && !(y < 0)) {
                    yOk = y + deleteThresholdY < newBitmapHeight;
                }

                if (!(xOk && yOk)) {
                    toRemove.add(child);
                }
            }
        }

        for (int i = 0; i < toRemove.size(); ++i) {
            relativeLayout.removeView(toRemove.get(i));
        }
        toRemove.clear();

        textAnnotationCounter = 1;
        for (int i = 0; i < relativeLayout.getChildCount(); ++i) {
            View child = relativeLayout.getChildAt(i);
            if (child instanceof TextAnnotationView) {
                String newAnnotationNumber = Integer.toString(textAnnotationCounter);
                ((TextAnnotationImageView) child).getAnnotationNumberView().setText(newAnnotationNumber);
                textAnnotationCounter++;
            }
            if (textAnnotationCounter > textAnnotationCounterMaximum) {
                break;
            }
        }
    }
}

From source file:com.plusot.senselib.SenseMain.java

private void releaseMap() {
    if (map != null) {
        map.setVisibility(View.GONE);
        RelativeLayout view = (RelativeLayout) findViewById(R.id.main_rootlayout);
        view.removeView(map);
        map.removeAllViews();//from   w ww . j  a v  a 2s .c  om
        map = null;
        adjustViews();
    }

}

From source file:com.plusot.senselib.SenseMain.java

@SuppressLint("Wakelock")
@SuppressWarnings("deprecation")
public void updateSetting(SharedPreferences prefs, PreferenceKey key, boolean firstTime) {
    switch (key) {
    case AUTOSWITCH:
        if (key.getInt() > 1800000) {
            PreferenceKey.CLICKSWITCH.set(true);
        }/*w  w w.ja v a2s . c  o m*/
        break;
    case CLICKSWITCH:
        clickSwitch = key.isTrue();
        break;
    case DIM:
        if (wakeLock != null && wakeLock.isHeld()) {
            wakeLock.release();
            wakeLock = null;
        }
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        allowHandWake = false;
        switch (PreferenceKey.getDimmable()) {
        case SCREENOFF_WAKE:
            allowHandWake = true;
        case SCREENOFF_FULL:
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Globals.TAG + "_WakeLock");
            wakeLock.acquire();
            break;
        case NODIM:
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            break;
        case DIM:
        default:
            allowHandWake = true;
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, Globals.TAG + "_WakeLock");
            wakeLock.acquire();
            break;
        }
        break;
    case DISPLAYNAME:
        UserInfo.UserData user = UserInfo.getUserData();
        if (user == null)
            return;
        key.getString(user.name);
        break;
    case HASMAP:
        new SleepAndWake(new SleepAndWake.Listener() {

            @Override
            public void onWake() {
                if (PreferenceKey.HASMAP.isTrue()) {
                    addMap();
                    adjustViews();
                } else {
                    releaseMap();
                    if (!visible)
                        toggleValuesVisible();
                }
            }
        }, 500);

        break;
    case HTTPPOST:
        HttpSender.isHttpPost = key.isTrue();
        break;
    case STOPSTATE:
        PreferenceKey.getStopState();
        break;
    case STORAGE:
        Value.fileTypes = PreferenceKey.getStorageFiles();
        break;
    case TESTING:
        PreferenceKey.isTesting();
        break;
    case WHEELSIZE:
    case WHEELCIRC:
        PreferenceKey.getWheelCirc();

        break;
    case XTRAVALUES:
        key.isTrue();
        break;
    case IMEI:
        UserInfo.resetDeviceId();
        break;
    case TILESOURCE:
        key.get();
        if (!firstTime) {
            if (map != null) {
                RelativeLayout view = (RelativeLayout) findViewById(R.id.main_rootlayout);
                view.removeView(map);
                map.removeAllViews();
                map.setOnTouchListener((ClickableOverlay.Listener) null);
                map = null;
            }

            addMap();
            //ToastHelper.showToastLong(R.string.change_tilesource);
        }
        break;
    case BLE_DEVICE:
        key.get();
        break;
    default:
        key.get();
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

@Override
public void onGUICreate() {
    this.clearViews();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());

    // change shutter icon
    isRecording = false;//from w w  w  . ja  v  a  2 s  . c o m
    prefs.edit().putBoolean("videorecording", false).commit();

    ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START);

    onPreferenceCreate((PreferenceFragment) null);

    setupVideoSize(prefs);

    List<View> specialView = new ArrayList<View>();
    RelativeLayout specialLayout = (RelativeLayout) ApplicationScreen.instance
            .findViewById(R.id.specialPluginsLayout2);
    for (int i = 0; i < specialLayout.getChildCount(); i++)
        specialView.add(specialLayout.getChildAt(i));

    for (int j = 0; j < specialView.size(); j++) {
        View view = specialView.get(j);
        int view_id = view.getId();
        if (view_id == this.mRecordingTimeView.getId() || view_id == this.modeSwitcher.getId()) {
            if (view.getParent() != null)
                ((ViewGroup) view.getParent()).removeView(view);

            specialLayout.removeView(view);
        }
    }

    {
        final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);

        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

        ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.specialPluginsLayout3))
                .removeView(this.modeSwitcher);
        ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.specialPluginsLayout3))
                .addView(this.modeSwitcher, params);

        this.modeSwitcher.setLayoutParams(params);
    }

    // Calculate right sizes for plugin's controls
    DisplayMetrics metrics = new DisplayMetrics();
    ApplicationScreen.instance.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    float fScreenDensity = metrics.density;

    int iIndicatorSize = (int) (ApplicationScreen.getMainContext().getResources()
            .getInteger(R.integer.infoControlHeight) * fScreenDensity);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(iIndicatorSize, iIndicatorSize);
    int topMargin = ApplicationScreen.instance.findViewById(R.id.paramsLayout).getHeight()
            + (int) ApplicationScreen.getAppResources().getDimension(R.dimen.viewfinderViewsMarginTop);
    params.setMargins((int) (2 * ApplicationScreen.getGUIManager().getScreenDensity()), topMargin, 0, 0);

    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

    ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.specialPluginsLayout2))
            .addView(this.mRecordingTimeView, params);

    this.mRecordingTimeView.setLayoutParams(params);

    LayoutInflater inflator = ApplicationScreen.instance.getLayoutInflater();
    buttonsLayout = inflator.inflate(R.layout.plugin_capture_video_layout, null, false);
    buttonsLayout.setVisibility(View.VISIBLE);

    timeLapseButton = (RotateImageView) buttonsLayout.findViewById(R.id.buttonTimeLapse);
    pauseVideoButton = (RotateImageView) ApplicationScreen.instance.findViewById(R.id.buttonVideoPause);
    stopVideoButton = (RotateImageView) ApplicationScreen.instance.findViewById(R.id.buttonVideoStop);

    snapshotSupported = CameraController.isVideoSnapshotSupported();
    takePictureButton = (RotateImageView) buttonsLayout.findViewById(R.id.buttonCaptureImage);

    timeLapseButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            TimeLapseDialog();
        }
    });

    pauseVideoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pauseVideoRecording();
        }
    });

    stopVideoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onShutterClick();
        }
    });

    if (snapshotSupported) {
        takePictureButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                takePicture();
            }

        });
    }

    for (int j = 0; j < specialView.size(); j++) {
        View view = specialView.get(j);
        int view_id = view.getId();
        if (view_id == this.buttonsLayout.getId()) {
            if (view.getParent() != null)
                ((ViewGroup) view.getParent()).removeView(view);

            specialLayout.removeView(view);
        }
    }

    params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.height = (int) ApplicationScreen.getAppResources().getDimension(R.dimen.videobuttons_size);

    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.specialPluginsLayout2))
            .addView(this.buttonsLayout, params);

    this.buttonsLayout.setLayoutParams(params);

    if (snapshotSupported) {
        takePictureButton.setOrientation(ApplicationScreen.getGUIManager().getLayoutOrientation());
        takePictureButton.invalidate();
        // takePictureButton.requestLayout();
        displayTakePicture = true;
    } else {
        takePictureButton.setVisibility(View.GONE);
        displayTakePicture = false;
    }

    timeLapseButton.setOrientation(ApplicationScreen.getGUIManager().getLayoutOrientation());

    if (this.modeDRO() || CameraController.isRemoteCamera()) {
        takePictureButton.setVisibility(View.GONE);
        timeLapseButton.setVisibility(View.GONE);
    }

    if (prefs.getBoolean("videoStartStandardPref", false)) {
        DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    PluginManager.getInstance().onPause(true);
                    Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
                    ApplicationScreen.instance.startActivity(intent);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    // No button clicked
                    break;
                default:
                    break;
                }
            }
        };

        AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationScreen.instance);
        builder.setMessage("You selected to start standard camera. Start camera?")
                .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener)
                .show();
    }

    rotatorLayout = inflator.inflate(R.layout.plugin_capture_video_lanscaperotate_layout, null, false);
    rotatorLayout.setVisibility(View.VISIBLE);
    initRotateNotification(videoOrientation);

    List<View> specialViewRotator = new ArrayList<View>();
    RelativeLayout specialLayoutRotator = (RelativeLayout) ApplicationScreen.instance
            .findViewById(R.id.specialPluginsLayout);
    for (int i = 0; i < specialLayoutRotator.getChildCount(); i++)
        specialViewRotator.add(specialLayoutRotator.getChildAt(i));

    for (int j = 0; j < specialViewRotator.size(); j++) {
        View view = specialViewRotator.get(j);
        int view_id = view.getId();
        int layout_id = this.rotatorLayout.getId();
        if (view_id == layout_id) {
            if (view.getParent() != null)
                ((ViewGroup) view.getParent()).removeView(view);

            specialLayoutRotator.removeView(view);
        }
    }

    RelativeLayout.LayoutParams paramsRotator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    paramsRotator.height = (int) ApplicationScreen.getAppResources().getDimension(R.dimen.gui_element_2size);

    paramsRotator.addRule(RelativeLayout.CENTER_IN_PARENT);

    ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.specialPluginsLayout))
            .addView(this.rotatorLayout, paramsRotator);
}

From source file:com.acceleratedio.pac_n_zoom.AnimActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_anm);
    orgnlImageView = (ImageView) findViewById(R.id.imageView);
    orgnlImageView.setMaxHeight(800);/*from  www  .ja v  a  2  s.c o m*/
    orgnlImageView.setMaxWidth(600);
    crt_ctx = this;

    BitmapFactory.Options bmp_opt = new BitmapFactory.Options();
    bmp_opt.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT;

    // - Now we need to set the GUI ImageView data with data read from the picked file.
    DcodRszdBmpFil dcodRszdBmpFil = new DcodRszdBmpFil();
    Bitmap bmp = dcodRszdBmpFil.DcodRszdBmpFil(SelectImageActivity.orgFil, bmp_opt);

    // Now we need to set the GUI ImageView data with the orginal file selection.
    orgnlImageView.setImageBitmap(bmp);
    orgnl_iv_wdth = bmp.getWidth();
    orgnl_iv_hght = bmp.getHeight();
    final RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo);
    scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener());

    orgnlImageView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getPointerCount() > 1 || flgInScale) {

                scaleGestureDetector.onTouchEvent(event);
                return true;
            }

            int end_hrz;
            int end_vrt;
            final int pointerIndex;

            switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                bgn_hrz = (int) MotionEventCompat.getX(event, pointerIndex);
                bgn_vrt = (int) MotionEventCompat.getY(event, pointerIndex);

                String log_str = "Beginning coordinates: Horz = " + String.valueOf(bgn_hrz) + "; Vert = "
                        + String.valueOf(bgn_vrt);

                Log.d("OnTouchListener", log_str);
                orlp = (RelativeLayout.LayoutParams) orgnlImageView.getLayoutParams();
                bgn_top = (int) orlp.topMargin;
                bgn_lft = (int) orlp.leftMargin;

                // To prevent an initial jump of the magnifier, aposX and aPosY must
                // have the values from the magnifier frame
                if (aPosX == 0)
                    aPosX = orgnlImageView.getX();
                if (aPosY == 0)
                    aPosY = orgnlImageView.getY();
                break;

            case MotionEvent.ACTION_MOVE:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                float crt_hrz = MotionEventCompat.getX(event, pointerIndex);
                float crt_vrt = MotionEventCompat.getY(event, pointerIndex);
                final float dx = crt_hrz - bgn_hrz;
                final float dy = crt_vrt - bgn_vrt;
                aPosX += dx;
                aPosY += dy;
                orgnlImageView.setX(aPosX);
                orgnlImageView.setY(aPosY);

                log_str = "Current Position: Horz = " + String.valueOf(crt_hrz) + "; Vert = "
                        + String.valueOf(crt_vrt);

                Log.d("OnTouchListener", log_str);

                break;

            case MotionEvent.ACTION_UP:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                end_hrz = (int) MotionEventCompat.getX(event, pointerIndex);
                end_vrt = (int) MotionEventCompat.getY(event, pointerIndex);
            }

            rel_anm_lo.invalidate();
            return true;
        }
    });

    sav_anm_btn = (Button) findViewById(R.id.sav_btn);

    sav_anm_btn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View vw) {

            onClickFlg = 1;
            RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo);
            rel_anm_lo.removeView(vw);
            Bitmap tnBmp = getWrtBmp("thumbnail", rel_anm_lo, 40);
            tnBmp.recycle();
            int vw_nmbr = anmViews.size();

            for (int vw_mbr = 1; vw_mbr < vw_nmbr; vw_mbr += 1) {

                anim_view = anmViews.get(vw_mbr);

                if (anim_view != null) {

                    Animation crt_anm = anim_view.getAnimation();

                    if (crt_anm != null)
                        crt_anm.cancel();

                    anim_view.setAnimation(null);
                    rel_anm_lo.removeView(anim_view);

                    // Garbage collect the bitmap
                    Drawable drawable = anim_view.getDrawable();

                    if (drawable instanceof BitmapDrawable) {
                        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
                        Bitmap anim_bmp = bitmapDrawable.getBitmap();
                        anim_bmp.recycle();
                    }
                }
            }

            Bitmap orgnlImageBmp = getWrtBmp("bgimg", rel_anm_lo, 90);
            orgnlImageWdth = Integer.toString(orgnlImageBmp.getWidth());
            orgnlImageHght = Integer.toString(orgnlImageBmp.getHeight());
            anmViews.clear();
            unbindDrawables(rel_anm_lo);
            ((RelativeLayout) rel_anm_lo).removeAllViews();
            orgnlImageBmp.recycle();
            crt_ctx = null;
            orgnlImageView = null;

            Intent intent = new Intent(AnimActivity.this, com.acceleratedio.pac_n_zoom.SaveAnmActivity.class);

            startActivity(intent);
        }
    });

    progress = ProgressDialog.show(crt_ctx, "Loading the animation", "dialog message", true);
    GetRequest get_svg_img = new GetRequest();
    get_svg_img.execute("");
}