Example usage for android.app Activity hasWindowFocus

List of usage examples for android.app Activity hasWindowFocus

Introduction

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

Prototype

public boolean hasWindowFocus() 

Source Link

Document

Returns true if this activity's main window currently has window focus.

Usage

From source file:org.chromium.BackgroundPlugin.java

private void show(final CallbackContext callbackContext) {
    Activity activity = cordova.getActivity();

    if (!activity.hasWindowFocus()) {
        BackgroundActivity.launchForeground(activity, false);
    }//w  w  w  . jav a  2  s .  c o  m
    callbackContext.success();
}

From source file:com.yerdy.services.Yerdy.java

/**
 * Resumes Yerdy tracking of current application, should be called from activity onResume(), also confirms application is in focus
 * //w w  w  .j  av a 2  s . c  o m
 * <pre>{@code
 *&#064;Override
 *protected void onResume() { 
 *  super.onResume();
 *  Yerdy.getInstance().onResume(this);
 *}</pre>
 * 
 * @param activity current activity
 * @category Application Life Cycle
 */
public void onResume(Activity activity) {
    boolean hasFocus = activity.hasWindowFocus();
    boolean finishing = activity.isFinishing();
    if (hasFocus && !finishing)
        activate(activity, true);
}

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

public static void settingPermission(@NonNull Activity activity) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(activity)) {
        MaterialDialog.Builder builder = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.writesetting).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override//from   ww w  .ja v  a  2s. c  om
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, WRITESETTINGS);
                            } else {
                                Toast.makeText(activity, "No app found to handle settings write permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setSettings(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            builder.show();
        }
    }
}

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

public static void widgetPermission(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(activity)) {
        MaterialDialog.Builder dialog = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.draw_over_permissions_message).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override//w  w w .  j ava  2s.c  om
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, OVERLAY_REQ);
                            } else {
                                Toast.makeText(activity,
                                        "No app found to handle floating widget enable permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setWidgetTrack(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            dialog.show();
        }
    }
}