Example usage for android.view ViewGroup removeView

List of usage examples for android.view ViewGroup removeView

Introduction

In this page you can find the example usage for android.view ViewGroup 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:com.gigabytedevelopersinc.app.calculator.Calculator.java

private void removeCling(int id) {
    setPagingEnabled(true);//from   w  ww  . jav a2  s. c  o m
    clingActive = false;

    final View cling = findViewById(id);
    if (cling != null) {
        final ViewGroup parent = (ViewGroup) cling.getParent();
        parent.post(new Runnable() {
            @Override
            public void run() {
                parent.removeView(cling);
            }
        });
    }
}

From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java

private void switchAccountViews() {
    Spinner accountSpinner = mAccountSpinner.getSpinner();
    Spinner transferAccountSpinner = mTransferAccountSpinner.getSpinner();
    ViewGroup accountParent = (ViewGroup) findViewById(R.id.AccountRow);
    ViewGroup transferAccountRow = (ViewGroup) findViewById(R.id.TransferAccountRow);
    TableLayout table = (TableLayout) findViewById(R.id.Table);
    View amountRow = table.findViewById(R.id.AmountRow);
    View transferAmountRow = table.findViewById(R.id.TransferAmountRow);
    table.removeView(amountRow);//w ww. j  av  a  2  s  .  com
    table.removeView(transferAmountRow);
    if (mType == INCOME) {
        accountParent.removeView(accountSpinner);
        transferAccountRow.removeView(transferAccountSpinner);
        accountParent.addView(transferAccountSpinner);
        transferAccountRow.addView(accountSpinner);
        table.addView(transferAmountRow, 2);
        table.addView(amountRow, 4);
    } else {
        accountParent.removeView(transferAccountSpinner);
        transferAccountRow.removeView(accountSpinner);
        accountParent.addView(accountSpinner);
        transferAccountRow.addView(transferAccountSpinner);
        table.addView(amountRow, 2);
        table.addView(transferAmountRow, 4);
    }
    linkAccountLabels();
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//from   w  w w . j  a va 2  s.c  o  m
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.announceForAccessibility(accessibilityText);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*from w  w  w  .  java2  s . co m*/
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (Build.VERSION.SDK_INT >= 16) {
                mAlertView.announceForAccessibility(accessibilityText);
            }

            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

public void testSetSelectedPositionDetached() throws Throwable {

    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.horizontal_linear);
    intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 50);
    initActivity(intent);//from  ww w. j a  v  a 2  s  . co m
    mOrientation = BaseGridView.HORIZONTAL;
    mNumRows = 1;

    final int focusToIndex = 49;
    final ViewGroup parent = (ViewGroup) mGridView.getParent();
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.removeView(mGridView);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            mGridView.setSelectedPositionSmooth(focusToIndex);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.addView(mGridView);
            mGridView.requestFocus();
        }
    });
    waitForTransientStateGone(null);
    waitForScrollIdle();
    assertEquals(mGridView.getSelectedPosition(), focusToIndex);
    assertTrue(mGridView.getLayoutManager().findViewByPosition(focusToIndex).hasFocus());

    final int focusToIndex2 = 0;
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.removeView(mGridView);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            mGridView.setSelectedPosition(focusToIndex2);
        }
    });
    runTestOnUiThread(new Runnable() {
        public void run() {
            parent.addView(mGridView);
            mGridView.requestFocus();
        }
    });
    assertEquals(mGridView.getSelectedPosition(), focusToIndex2);
    waitForTransientStateGone(null);
    waitForScrollIdle();
    assertTrue(mGridView.getLayoutManager().findViewByPosition(focusToIndex2).hasFocus());
}

From source file:com.aliyun.homeshell.Folder.java

public void deleteFolderAndContents() {
    ArrayList<ShortcutInfo> list = new ArrayList<ShortcutInfo>();
    //clear listeners
    mInfo.unbind();//  ww w .  j  a v  a  2s  .c o  m

    //Delete remain items.
    for (ShortcutInfo itemInfo : mInfo.contents) {
        mInfo.remove(itemInfo);
        list.add(itemInfo);
        LauncherModel.deleteItemFromDatabase(mLauncher, itemInfo);
    }

    //remove the foldericon from pagedview
    ViewGroup parent = (ViewGroup) mFolderIcon.getParent();
    parent.removeView(mFolderIcon);

    //delete the folderinfo from appscustomize
    mLauncher.getAppsCustomize().removeFolder(mInfo);
    LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);

    //move the remain item from the folder to pagedview
    mLauncher.getAppsCustomize().moveFolderItems(list);
}

From source file:org.appspot.apprtc.CallActivity.java

void sendToBack(View child) {
    final ViewGroup parent = (ViewGroup) child.getParent();
    if (null != parent) {
        parent.removeView(child);
        parent.addView(child, 0);//from w  ww. j av  a2 s . c  om
    }
}

From source file:org.appspot.apprtc.CallActivity.java

void bringToFront(View child) {
    final ViewGroup parent = (ViewGroup) child.getParent();
    if (null != parent) {
        parent.removeView(child);
        parent.addView(child, screenshareFrontIndex);
    }//from   w w w .  j ava  2s. com
}

From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java

private Cookie checkAntiDDOS(final CloudflareException exception, final HttpHost proxy, CancellableTask task,
        final Activity activity) {
    synchronized (lock) {
        if (processing)
            return null;
        processing = true;/*from ww w .j  a v a 2s  .  co  m*/
    }
    processing2 = true;
    currentCookie = null;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieSyncManager.createInstance(activity);
        CookieManager.getInstance().removeAllCookie();
    } else {
        CompatibilityImpl.clearCookies(CookieManager.getInstance());
    }

    final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView();
    final WebViewClient client = new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public void onPageFinished(WebView webView, String url) {
            super.onPageFinished(webView, url);
            Logger.d(TAG, "Got Page: " + url);
            String value = null;
            try {
                String[] cookies = CookieManager.getInstance().getCookie(url).split("[;]");
                for (String cookie : cookies) {
                    if ((cookie != null) && (!cookie.trim().equals(""))
                            && (cookie.startsWith(" " + exception.getRequiredCookieName() + "="))) {
                        value = cookie.substring(exception.getRequiredCookieName().length() + 2);
                    }
                }
            } catch (NullPointerException e) {
                Logger.e(TAG, e);
            }
            if (value != null) {
                BasicClientCookieHC4 cf_cookie = new BasicClientCookieHC4(exception.getRequiredCookieName(),
                        value);
                cf_cookie.setDomain("." + Uri.parse(url).getHost());
                cf_cookie.setPath("/");
                currentCookie = cf_cookie;
                Logger.d(TAG, "Cookie found: " + value);
                processing2 = false;
            } else {
                Logger.d(TAG, "Cookie is not found");
            }
        }
    };

    activity.runOnUiThread(new Runnable() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void run() {
            webView = new WebView(activity);
            webView.setVisibility(View.GONE);
            layout.addView(webView);
            webView.setWebViewClient(client);
            webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING);
            webView.getSettings().setJavaScriptEnabled(true);
            webViewContext = webView.getContext();
            if (proxy != null)
                WebViewProxy.setProxy(webViewContext, proxy.getHostName(), proxy.getPort());
            webView.loadUrl(exception.getCheckUrl());
        }
    });

    long startTime = System.currentTimeMillis();
    while (processing2) {
        long time = System.currentTimeMillis() - startTime;
        if ((task != null && task.isCancelled()) || time > TIMEOUT) {
            processing2 = false;
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                layout.removeView(webView);
                webView.stopLoading();
                webView.clearCache(true);
                webView.destroy();
                webView = null;
            } finally {
                if (proxy != null)
                    WebViewProxy.setProxy(webViewContext, null, 0);
                processing = false;
            }
        }
    });

    return currentCookie;
}

From source file:nya.miku.wishmaster.http.cloudflare.InterceptingAntiDDOS.java

/**  anti-DDOS , ? ? ??  webview  httpclient (? ?? ? ?-?  API >= 11) */
Cookie check(final CloudflareException exception, final ExtendedHttpClient httpClient,
        final CancellableTask task, final Activity activity) {
    synchronized (lock) {
        if (processing)
            return null;
        processing = true;// w  w w .j ava  2s . co  m
    }
    processing2 = true;
    currentCookie = null;

    final HttpRequestModel rqModel = HttpRequestModel.builder().setGET().build();
    final CookieStore cookieStore = httpClient.getCookieStore();
    CloudflareChecker.removeCookie(cookieStore, exception.getRequiredCookieName());
    final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView();
    final WebViewClient client = new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            HttpResponseModel responseModel = null;
            try {
                responseModel = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, null, task);
                for (int i = 0; i < 3 && responseModel.statusCode == 400; ++i) {
                    Logger.d(TAG, "HTTP 400");
                    responseModel.release();
                    responseModel = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, null, task);
                }
                for (Cookie cookie : cookieStore.getCookies()) {
                    if (CloudflareChecker.isClearanceCookie(cookie, url, exception.getRequiredCookieName())) {
                        Logger.d(TAG, "Cookie found: " + cookie.getValue());
                        currentCookie = cookie;
                        processing2 = false;
                        return new WebResourceResponse("text/html", "UTF-8",
                                new ByteArrayInputStream("cookie received".getBytes()));
                    }
                }
                BufOutputStream output = new BufOutputStream();
                IOUtils.copyStream(responseModel.stream, output);
                return new WebResourceResponse(null, null, output.toInputStream());
            } catch (Exception e) {
                Logger.e(TAG, e);
            } finally {
                if (responseModel != null)
                    responseModel.release();
            }
            return new WebResourceResponse("text/html", "UTF-8",
                    new ByteArrayInputStream("something wrong".getBytes()));
        }
    };

    activity.runOnUiThread(new Runnable() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void run() {
            webView = new WebView(activity);
            webView.setVisibility(View.GONE);
            layout.addView(webView);
            webView.setWebViewClient(client);
            webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl(exception.getCheckUrl());
        }
    });

    long startTime = System.currentTimeMillis();
    while (processing2) {
        long time = System.currentTimeMillis() - startTime;
        if ((task != null && task.isCancelled()) || time > CloudflareChecker.TIMEOUT) {
            processing2 = false;
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                layout.removeView(webView);
                webView.stopLoading();
                webView.clearCache(true);
                webView.destroy();
                webView = null;
            } finally {
                processing = false;
            }
        }
    });
    return currentCookie;
}