Example usage for android.app Activity getWindow

List of usage examples for android.app Activity getWindow

Introduction

In this page you can find the example usage for android.app Activity getWindow.

Prototype

public Window getWindow() 

Source Link

Document

Retrieve the current android.view.Window for the activity.

Usage

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;//from w  ww .ja va  2s.c  o  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;
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void requestAdjustResize(Activity activity, int classGuid) {
    if (activity == null || isTablet()) {
        return;//from w  w w . j a v a 2  s. c  om
    }
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    adjustOwnerClassGuid = classGuid;
}

From source file:app.newbee.lib.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;/*  ww  w .  j ava2 s.  co  m*/
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.ijiaban.yinxiang.MainActivity.java

/**
 * Changes the color of the action bar and status bar
 * @param color ARGB Color to apply//from   w ww .  ja  v a 2  s  . c om
 */
@SuppressLint("NewApi")
private void setColor(int color) {
    View mainView = findViewById(R.id.rootView);
    if (mainView == null) {
        Log.e("MainActivity:setColor()", "WARNING: Did not find root view.");
    } else {
        mainView.setBackgroundColor(color);
    }

    /*
    Set the action bar colour to the average colour of the generated image and
    the status bar colour for Android Version >= 5.0 accordingly.
    */
    try {
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
    } catch (NullPointerException nullError) {
        Log.e("MainActivity:generateImageTask()", nullError.toString());
    } catch (NoSuchMethodError methodError) {
        Log.e("MainActivity:generateImageTask()", methodError.toString());
    }

    Log.d("MainActivity:generateImageTask()", "Changing status bar & action bar colour.");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Get the window through a reference to the activity.
        Activity parent = (Activity) mContext;
        Window window = parent.getWindow();
        // Set the status bar colour of this window.
        int statusColor = ColorUtilities.getDarkenedColor(color);
        window.setStatusBarColor(statusColor);
    }
}

From source file:com.adityarathi.muo.utils.Common.java

/**
 * Returns the view container for the ActionBar.
 * @return//from   ww  w .  ja v  a  2 s  .  c  om
 */
public View getActionBarView(Activity activity) {
    Window window = activity.getWindow();
    View view = window.getDecorView();
    int resId = getResources().getIdentifier("action_bar_container", "id", "android");

    return view.findViewById(resId);
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void removeAdjustResize(Activity activity, int classGuid) {
    if (activity == null || isTablet()) {
        return;/*  w w  w  .java2s.c  o m*/
    }
    if (adjustOwnerClassGuid == classGuid) {
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    }
}

From source file:com.facebook.react.modules.statusbar.StatusBarModule.java

@ReactMethod
public void setTranslucent(final boolean translucent, final Promise res) {
    final Activity activity = getCurrentActivity();
    if (activity == null) {
        res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
        return;//from   w  ww .  ja v a2s  . c  om
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        UiThreadUtil.runOnUiThread(new Runnable() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void run() {
                // If the status bar is translucent hook into the window insets calculations
                // and consume all the top insets so no padding will be added under the status bar.
                View decorView = activity.getWindow().getDecorView();
                if (translucent) {
                    decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                        @Override
                        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                            WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                            return defaultInsets.replaceSystemWindowInsets(
                                    defaultInsets.getSystemWindowInsetLeft(), 0,
                                    defaultInsets.getSystemWindowInsetRight(),
                                    defaultInsets.getSystemWindowInsetBottom());
                        }
                    });
                } else {
                    decorView.setOnApplyWindowInsetsListener(null);
                }

                ViewCompat.requestApplyInsets(decorView);
                res.resolve(null);
            }
        });
    }
}

From source file:com.facebook.litho.LayoutState.java

private static boolean canCollectDisplayListsSync(Activity activity) {
    // If we have no window or the hierarchy has never been drawn before we cannot guarantee that
    // a valid GL context exists. In this case just bail.
    final Window window = activity.getWindow();
    if (window == null) {
        return false;
    }// w  w w  .  ja v a 2 s . c om

    final View decorView = window.getDecorView();
    if (decorView == null || decorView.getDrawingTime() == 0) {
        return false;
    }

    return true;
}

From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;/*w  w  w . j  av a2  s  .  c o m*/
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.mojtaba.materialdatetimepicker.date.DatePickerDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    if (savedInstanceState != null) {
        mPersianCalendar.setPersianDate(savedInstanceState.getInt(KEY_SELECTED_YEAR),
                savedInstanceState.getInt(KEY_SELECTED_MONTH), savedInstanceState.getInt(KEY_SELECTED_DAY));
    }//ww  w  .j a v a2 s.  c  o m
}