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:org.huxizhijian.sdk.util.StatusBarUtil.java

/**
 * DrawerLayout ???//from  w  w  w . j  a v a 2  s .  c om
 *
 * @param activity       ?activity
 * @param drawerLayout   DrawerLayout
 * @param color          ??
 * @param statusBarAlpha ???
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
        int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // ????
    //  statusBarView 
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
        contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
    } else {
        StatusBarView statusBarView = createStatusBarView(activity, color);
        contentLayout.addView(statusBarView, 0);
    }
    // ? LinearLayout ,padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(contentLayout.getPaddingLeft(),
                getStatusBarHeight(activity) + contentLayout.getPaddingTop(), contentLayout.getPaddingRight(),
                contentLayout.getPaddingBottom());
    }
    // 
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);

    addTranslucentView(activity, statusBarAlpha);
}

From source file:io.github.prefanatic.cleantap.ui.animation.InfoAndCheckinAnimation.java

public static void setupSharedElementTransitionsFab(@NonNull Activity activity, @Nullable View target,
        int dialogCornerRadius) {
    ArcMotion arcMotion = new ArcMotion();
    arcMotion.setMinimumHorizontalAngle(50f);
    arcMotion.setMinimumVerticalAngle(50f);
    int color = ContextCompat.getColor(activity, R.color.colorAccent);
    Interpolator easeInOut = AnimationUtils.loadInterpolator(activity, android.R.interpolator.fast_out_slow_in);
    MorphFabToDialog sharedEnter = new MorphFabToDialog(color, dialogCornerRadius);
    sharedEnter.setPathMotion(arcMotion);
    sharedEnter.setInterpolator(easeInOut);
    MorphDialogToFab sharedReturn = new MorphDialogToFab(color);
    sharedReturn.setPathMotion(arcMotion);
    sharedReturn.setInterpolator(easeInOut);
    if (target != null) {
        sharedEnter.addTarget(target);/*w  ww  .j a  v a 2 s .  com*/
        sharedReturn.addTarget(target);
    }
    activity.getWindow().setSharedElementEnterTransition(sharedEnter);
    activity.getWindow().setSharedElementReturnTransition(sharedReturn);
}

From source file:net.wequick.small.ApkBundleLauncher.java

/**
 * Apply plugin activity info with plugin's AndroidManifest.xml
 * @param activity//from  w ww  .j  a v a  2  s  .  c o  m
 * @param ai
 */
private static void applyActivityInfo(Activity activity, ActivityInfo ai) {
    // Apply window attributes
    Window window = activity.getWindow();
    window.setSoftInputMode(ai.softInputMode);
    activity.setRequestedOrientation(ai.screenOrientation);
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static void updateFullscreenStatus(Activity pActivity, View pContentView, boolean pUseFullscreen) {
    T.UI();//w  w w  .j  ava 2s.co  m
    if (pActivity.getWindow() != null) {
        if (pUseFullscreen) {
            pActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            pActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        } else {
            pActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            pActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        pContentView.requestLayout();
    }
}

From source file:org.devgeeks.privacyscreen.PrivacyScreenPlugin.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    Activity activity = this.cordova.getActivity();
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}

From source file:com.aaplab.android.roboboost.VisibleInjectionContext.java

public VisibleInjectionContext(Activity activity) {
    this.rootView = activity.getWindow().getDecorView();
}

From source file:com.nick.scalpel.core.binding.ViewFinder.java

@Override
public void wire(Activity activity, Field field) {
    wire(activity.getWindow().getDecorView(), activity, field);
}

From source file:com.bt.heliniumstudentapp.MainActivity.java

protected static void setStatusBar(Activity context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        context.getWindow().setStatusBarColor(Color.TRANSPARENT);

        if (context == mainContext)
            drawerDL.setStatusBarBackgroundColor(ContextCompat.getColor(context, darkPrimaryColor));
        else//  www . ja va  2 s .  c  o m
            context.getWindow().setStatusBarColor(ContextCompat.getColor(context, darkPrimaryColor));

        context.setTaskDescription(new ActivityManager.TaskDescription(context.getString(R.string.app_name),
                BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher),
                ContextCompat.getColor(context, primaryColor)));

    }
}

From source file:dev.nick.accessories.injection.processors.ViewProcessor.java

protected Object parseField(Object container, Field field) {
    BindView bindView = field.getAnnotation(BindView.class);
    int id = checkId(bindView.value());
    View rootView;//from w  w w . j  av a 2 s .  c o  m
    boolean isProvider = container instanceof BindView.RootViewProvider;
    if (isProvider) {
        BindView.RootViewProvider provider = (BindView.RootViewProvider) container;
        rootView = provider.getRootView();
    } else if (container instanceof Activity) {
        Activity activity = (Activity) container;
        rootView = activity.getWindow().getDecorView();
    } else if (container instanceof Fragment) {
        Fragment fragment = (Fragment) container;
        rootView = fragment.getView();
    } else if (container instanceof android.support.v4.app.Fragment) {
        android.support.v4.app.Fragment fragmentV4 = (android.support.v4.app.Fragment) container;
        rootView = fragmentV4.getView();
    } else if (container instanceof View) {
        rootView = (View) container;
    } else if (container instanceof RecyclerView.ViewHolder) {
        RecyclerView.ViewHolder holder = (RecyclerView.ViewHolder) container;
        rootView = holder.itemView;
    } else {
        throw new IllegalArgumentException("You should impl BindView.RootViewProvider for no-component class");
    }
    Preconditions.checkNotNull(rootView, "No root view detected.");
    return rootView.findViewById(id);
}

From source file:br.com.hotforms.FacebookHash.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 *///from   ww  w.  jav  a 2s .  c o m
@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {
    Log.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();

    if ("getHash".equals(action)) {
        try {
            String packageName = activity.getClass().getPackage().getName();
            PackageManager packageManager = activity.getPackageManager();
            PackageInfo info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String hash = Base64.encodeToString(md.digest(), Base64.DEFAULT);

                String result = String.format("{ FacebookHash : \"%s\", PackageName : \"%s\"}", hash.trim(),
                        packageName);
                callbackContext.success(result);
            }
        } catch (NameNotFoundException e) {
            callbackContext.error(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            callbackContext.error(e.getMessage());
        }
        return true;
    }

    return false;
}