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:com.grottworkshop.gwsindiaink.TypefaceHelper.java

/**
 * Set the typeface to the all text views belong to the activity.
 * Note that we use decor view of the activity so that the typeface will also be applied to action bar.
 * @param activity the activity.// w  w  w .j a  va2  s. c  o  m
 * @param typefaceName typeface name.
 * @param style the typeface style.
 */
public void setTypeface(Activity activity, String typefaceName, int style) {
    setTypeface((ViewGroup) activity.getWindow().getDecorView(), typefaceName, style);
}

From source file:com.arta.lib.widget.crouton.Manager.java

@TargetApi(19)
private void handleTranslucentActionBar(ViewGroup.MarginLayoutParams params, Activity activity) {
    // Translucent status is only available as of Android 4.4 Kit Kat.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final int flags = activity.getWindow().getAttributes().flags;
        final int translucentStatusFlag = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        /* Checks whether translucent status is enabled for this window.
        * If true, sets the top margin to show the crouton just below the action bar. */
        if ((flags & translucentStatusFlag) == translucentStatusFlag) {
            final int actionBarContainerId = Resources.getSystem().getIdentifier("action_bar_container", "id",
                    "android");
            final View actionBarContainer = activity.findViewById(actionBarContainerId);
            // The action bar is present: the app is using a Holo theme.
            if (actionBarContainer != null) {
                final ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
                marginParams.topMargin = actionBarContainer.getBottom();
            }/*w  w  w .  j a va 2 s. com*/
        }
    }
}

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

@ReactMethod
public void setColor(final int color, final boolean animated, final Promise res) {
    final Activity activity = getCurrentActivity();
    if (activity == null) {
        res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
        return;//from  w ww .j  a  v a 2  s  .com
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        UiThreadUtil.runOnUiThread(new Runnable() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void run() {
                if (animated) {
                    int curColor = activity.getWindow().getStatusBarColor();
                    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), curColor, color);

                    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animator) {
                            activity.getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
                        }
                    });
                    colorAnimation.setDuration(300).setStartDelay(0);
                    colorAnimation.start();
                } else {
                    activity.getWindow().setStatusBarColor(color);
                }
                res.resolve(null);
            }
        });
    } else {
        res.resolve(null);
    }
}

From source file:com.google.samples.apps.topeka.fragment.SignInFragment.java

private void performSignInWithTransition(View v) {
    final Activity activity = getActivity();
    if (v == null || ApiLevelHelper.isLowerThan(Build.VERSION_CODES.LOLLIPOP)) {
        // Don't run a transition if the passed view is null
        CategorySelectionActivity.start(activity, mPlayer);
        activity.finish();// w  ww .  j a  va 2s.c  o  m
        return;
    }

    if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) {
        activity.getWindow().getSharedElementExitTransition().addListener(new TransitionListenerAdapter() {
            @Override
            public void onTransitionEnd(Transition transition) {
                activity.finish();
            }
        });

        final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, true,
                new Pair<>(v, activity.getString(R.string.transition_avatar)));
        @SuppressWarnings("unchecked")
        ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
                pairs);
        CategorySelectionActivity.start(activity, mPlayer, activityOptions);
    }
}

From source file:com.alibaba.weex.WXPageActivity.java

private void loadWXfromLocal(boolean reload) {
    if (reload && mInstance != null) {
        mInstance.destroy();//  www  .j  a v  a 2s .c  o  m
        mInstance = null;
    }
    if (mInstance == null) {
        RenderContainer renderContainer = new RenderContainer(this);

        mInstance = new WXSDKInstance(this);
        mInstance.setRenderContainer(renderContainer);
        mInstance.registerRenderListener(this);
        mInstance.setNestedInstanceInterceptor(this);
        mInstance.setTrackComponent(true);
    }
    mContainer.post(new Runnable() {
        @Override
        public void run() {
            Activity ctx = WXPageActivity.this;
            Rect outRect = new Rect();
            ctx.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
            mConfigMap.put("bundleUrl", mUri.toString());
            String path = "file".equals(mUri.getScheme()) ? assembleFilePath(mUri) : mUri.toString();
            mInstance.render(TAG, WXFileUtils.loadAsset(path, WXPageActivity.this), mConfigMap, null,
                    WXRenderStrategy.APPEND_ASYNC);
        }
    });
}

From source file:com.tomeokin.lspush.biz.home.CollectionListAdapter.java

public CollectionListAdapter(Activity activity, @Nullable List<Collection> colList,
        @Nullable Callback callback) {
    final Resources resources = activity.getResources();
    mMaxHeight = resources.getDimension(R.dimen.list_item_max_content)
            - resources.getDimension(R.dimen.row_vertical_padding);
    final View content = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    mMaxWidth = content.getWidth() - 2 * resources.getDimension(R.dimen.page_vertical_margin);

    if (colList != null) {
        setColList(colList);//from   w  w w  .  java2s. c o m
    }
    setCallback(callback);
}

From source file:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();/*from w w  w  . j  ava 2 s  .  c  om*/

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this, 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:mobi.cangol.mobile.navigation.SlidingMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();//from  w  ww  .  jav  a 2 s.  c  o m

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this.getRootView(), 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Set color to nav and status bar//  w w w.j a v a2 s  .  c o  m
 * @param activity
 * @param v
 */
public static void setColor(@NonNull Activity activity, int color, View v) {
    if (activity.getWindow() == null) {
        return;
    }
    if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) {
        activity.getWindow().setStatusBarColor(color);
        v.setBackgroundColor(color);
        activity.getWindow().setNavigationBarColor(color);
    } else {
        activity.getWindow().setStatusBarColor(color);
        v.setBackgroundColor(color);
        activity.getWindow().setNavigationBarColor(color);
    }
}

From source file:com.hx.hxchat.activity.ContactlistFragment.java

void hideSoftKeyboard(Activity activity) {
    if (activity.getWindow()
            .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
        if (activity.getCurrentFocus() != null)
            inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
    }//  w w w .  j  av a 2 s  . c o  m
}