Example usage for android.app Dialog setOnDismissListener

List of usage examples for android.app Dialog setOnDismissListener

Introduction

In this page you can find the example usage for android.app Dialog setOnDismissListener.

Prototype

public void setOnDismissListener(@Nullable OnDismissListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is dismissed.

Usage

From source file:com.gb.cwsup.activity.order.WaitSureOrderActivity.java

private void showErrorDialog(String string) {
    Builder builder = new AlertDialog.Builder(this).setTitle("??")
            .setMessage("???????")
            .setPositiveButton("", null);
    Dialog dialog = builder.create();
    dialog.show();//from   w  ww.  j av  a2s.c  o m

    dialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface arg0) {
            WaitSureOrderActivity.this.finish();
        }
    });
}

From source file:com.android.nobadgift.DashboardActivity.java

private void displayConfirmationDialog() {
    try {/* w  w w .jav a  2s .  co  m*/
        Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.custom_dialog);
        dialog.setTitle("Successfully Scanned!");
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.setOnDismissListener(new OnDismissListener() {
            public void onDismiss(DialogInterface dialog) {
                displayInfoDialog();
            }
        });
        TextView text = (TextView) dialog.findViewById(R.id.dialogText);
        text.setText("\"" + itemName + "\"");
        ImageView image = (ImageView) dialog.findViewById(R.id.dialogImage);
        image.setImageBitmap(retrievedImage);
        dialog.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:pulseanddecibels.jp.yamatenki.activity.SplashActivity.java

private void displayUserLicenseAgreement() {
    final Dialog dialog = new Dialog(SplashActivity.this);
    //        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_license_agreement);
    dialog.setTitle(getString(R.string.text_license_agreement_title));
    dialog.setCanceledOnTouchOutside(false);
    Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.yama_brown));
    dialog.getWindow().setBackgroundDrawable(d);
    dialog.show();/*from w  w w .  j av  a 2s.c  o m*/
    licenseAgreementDialogOpen = true;
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (!agreeButtonPressed) {
                licenseAgreementDialogOpen = false;
                settings.setAgreedToLicense(false);
                if (!databaseTaskRunning) {
                    finish();
                }
            }
        }
    });
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            licenseAgreementDialogOpen = false;
            settings.setAgreedToLicense(false);
            if (!databaseTaskRunning) {
                finish();
            }
        }
    });

    final Button agreeButton = (Button) dialog.findViewById(R.id.agree_button);
    agreeButton.setEnabled(false);
    agreeButton.setAlpha(.5f);
    agreeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            settings.setAgreedToLicense(true);
            agreeButtonPressed = true;
            dialog.dismiss();
            if (!databaseTaskRunning) {
                startMainActivity();
            }
        }
    });

    final CheckBox agreementCheckbox = (CheckBox) dialog.findViewById(R.id.agreement_checkbox);
    agreementCheckbox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CheckBox checkbox = (CheckBox) v;
            if (checkbox.isChecked()) {
                agreeButton.setAlpha(1.0f);
                agreeButton.setEnabled(true);
            } else {
                agreeButton.setAlpha(.5f);
                agreeButton.setEnabled(false);
            }
        }
    });

    TextView agreementLabel = (TextView) dialog.findViewById(R.id.agreement_label);
    agreementLabel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            agreementCheckbox.setChecked(!agreementCheckbox.isChecked());
            if (agreementCheckbox.isChecked()) {
                agreeButton.setAlpha(1.0f);
                agreeButton.setEnabled(true);
            } else {
                agreeButton.setAlpha(.5f);
                agreeButton.setEnabled(false);
            }
        }
    });
}

From source file:uk.co.armedpineapple.cth.SDLActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    commandHandler = new CommandHandler(this);
    // The volume buttons should change the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Make sure that external media is mounted.
    if (Files.canAccessExternalStorage()) {

        final SharedPreferences preferences = app.getPreferences();

        if (app.configuration == null) {
            try {
                app.configuration = Configuration.loadFromPreferences(this, preferences);
            } catch (StorageUnavailableException e) {
                Log.e(LOG_TAG, "Can't get storage.");

                // Create an alert dialog warning that external storage isn't
                // mounted. The application will have to exit at this point.

                DialogFactory.createExternalStorageWarningDialog(this, true).show();
            }/*from   w w  w  .  j a v  a2s  .  c om*/
        }

        currentVersion = preferences.getInt("last_version", 0) - 1;

        try {
            currentVersion = (getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);

        } catch (NameNotFoundException e) {
            BugSenseHandler.sendException(e);
        }

        // Check to see if the game files have been copied yet, or whether the
        // application has been updated
        if (!preferences.getBoolean("scripts_copied", false)
                || preferences.getInt("last_version", 0) < currentVersion) {

            Log.d(LOG_TAG, "This is a new installation");

            // Show the recent changes dialog
            Dialog recentChangesDialog = DialogFactory.createRecentChangesDialog(this);
            recentChangesDialog.setOnDismissListener(new OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface arg0) {
                    installFiles(preferences);
                }

            });
            recentChangesDialog.show();

        } else {

            // Continue to load the application otherwise
            loadApplication();
        }

    } else {
        Log.e(LOG_TAG, "Can't get storage.");

        // Create an alert dialog warning that external storage isn't
        // mounted. The application will have to exit at this point.

        DialogFactory.createExternalStorageWarningDialog(this, true).show();
    }
}

From source file:com.google.android.apps.santatracker.launch.TvStartupActivity.java

private void showGooglePlayServicesAvailabilityErrorDialog(final int connectionStatusCode) {

    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(connectionStatusCode, this, 0);
    dialog.show();/*from  ww  w  .j a  v a 2  s  . com*/
    dialog.setOnDismissListener(new Dialog.OnDismissListener() {

        public void onDismiss(DialogInterface dialog) {
            finish();
        }
    });

}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Utility method to display an alert dialog. Use instead of AlertDialog to
 * get the right styling./*  w  w  w  . j  ava  2s. c  o m*/
 * 
 * @param context
 * @param message
 */
public static void displayAlert(final Launcher context, String message) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.alert);

    final TextView alertTextView = (TextView) dialog.findViewById(R.id.alertText);
    alertTextView.setText(message);
    Button alertButton = (Button) dialog.findViewById(R.id.alertButton);
    alertButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
        }

    });
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
}

From source file:com.sonymobile.dronecontrol.activity.MainActivity.java

private void loadLicense() {
    View view = getLayoutInflater().inflate(R.layout.licenses, null);

    Dialog dialog = new AlertDialog.Builder(this).setPositiveButton(R.string.settings_button_ok, null)
            .setView(view).setTitle(getString(R.string.settings_item_licenses)).create();

    final WebView webView = (WebView) view.findViewById(R.id.license_view);
    final ProgressBar webProgress = (ProgressBar) view.findViewById(R.id.license_progress);
    webProgress.setVisibility(View.VISIBLE);

    dialog.setOnDismissListener(new OnDismissListener() {
        @Override/*from w  w w . ja va2s  .co m*/
        public void onDismiss(DialogInterface dialog) {
            webView.stopLoading();
        }
    });

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onScaleChanged(WebView view, float oldScale, float newScale) {
            super.onScaleChanged(view, oldScale, newScale);
            webProgress.setVisibility(View.GONE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webProgress.setVisibility(View.GONE);
        }
    });

    webView.loadUrl("file:///android_asset/licenses.html");
    dialog.show();
}

From source file:org.rm3l.maoni.ui.MaoniActivity.java

private void initScreenCaptureView(@NonNull final Intent intent) {
    final ImageButton screenshotThumb = (ImageButton) findViewById(R.id.maoni_screenshot);

    final TextView touchToPreviewTextView = (TextView) findViewById(R.id.maoni_screenshot_touch_to_preview);
    if (touchToPreviewTextView != null && intent.hasExtra(SCREENSHOT_TOUCH_TO_PREVIEW_HINT)) {
        touchToPreviewTextView.setText(intent.getCharSequenceExtra(SCREENSHOT_TOUCH_TO_PREVIEW_HINT));
    }/*  www .j a va2s .  com*/

    final View screenshotContentView = findViewById(R.id.maoni_include_screenshot_content);
    if (!TextUtils.isEmpty(mScreenshotFilePath)) {
        final File file = new File(mScreenshotFilePath.toString());
        if (file.exists()) {
            if (mIncludeScreenshot != null) {
                mIncludeScreenshot.setVisibility(View.VISIBLE);
            }
            if (screenshotContentView != null) {
                screenshotContentView.setVisibility(View.VISIBLE);
            }
            if (screenshotThumb != null) {
                //Thumbnail - load with smaller resolution so as to reduce memory footprint
                screenshotThumb.setImageBitmap(
                        ViewUtils.decodeSampledBitmapFromFilePath(file.getAbsolutePath(), 100, 100));
            }

            // Hook up clicks on the thumbnail views.
            if (screenshotThumb != null) {
                screenshotThumb.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        final Dialog imagePreviewDialog = new Dialog(MaoniActivity.this);

                        imagePreviewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                        imagePreviewDialog.getWindow()
                                .setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

                        imagePreviewDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialogInterface) {
                                //nothing;
                            }
                        });

                        imagePreviewDialog.setContentView(R.layout.maoni_screenshot_preview);

                        final View.OnClickListener clickListener = new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                imagePreviewDialog.dismiss();
                            }
                        };

                        final ImageView imageView = (ImageView) imagePreviewDialog
                                .findViewById(R.id.maoni_screenshot_preview_image);
                        imageView.setImageURI(Uri.fromFile(file));

                        final DrawableView drawableView = (DrawableView) imagePreviewDialog
                                .findViewById(R.id.maoni_screenshot_preview_image_drawable_view);
                        final DrawableViewConfig config = new DrawableViewConfig();
                        // If the view is bigger than canvas, with this the user will see the bounds
                        config.setShowCanvasBounds(true);
                        config.setStrokeWidth(57.0f);
                        config.setMinZoom(1.0f);
                        config.setMaxZoom(1.0f);
                        config.setStrokeColor(mHighlightColor);
                        final View decorView = getWindow().getDecorView();
                        config.setCanvasWidth(decorView.getWidth());
                        config.setCanvasHeight(decorView.getHeight());
                        drawableView.setConfig(config);
                        drawableView.bringToFront();

                        imagePreviewDialog.findViewById(R.id.maoni_screenshot_preview_pick_highlight_color)
                                .setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        config.setStrokeColor(mHighlightColor);
                                    }
                                });
                        imagePreviewDialog.findViewById(R.id.maoni_screenshot_preview_pick_blackout_color)
                                .setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        config.setStrokeColor(mBlackoutColor);
                                    }
                                });
                        imagePreviewDialog.findViewById(R.id.maoni_screenshot_preview_close)
                                .setOnClickListener(clickListener);

                        imagePreviewDialog.findViewById(R.id.maoni_screenshot_preview_undo)
                                .setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        drawableView.undo();
                                    }
                                });

                        imagePreviewDialog.findViewById(R.id.maoni_screenshot_preview_save)
                                .setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        ViewUtils.exportViewToFile(MaoniActivity.this,
                                                imagePreviewDialog.findViewById(
                                                        R.id.maoni_screenshot_preview_image_view_updated),
                                                new File(mScreenshotFilePath.toString()));
                                        initScreenCaptureView(intent);
                                        imagePreviewDialog.dismiss();
                                    }
                                });

                        imagePreviewDialog.setCancelable(true);
                        imagePreviewDialog.setCanceledOnTouchOutside(false);

                        imagePreviewDialog.show();
                    }
                });
            }
        } else {
            if (mIncludeScreenshot != null) {
                mIncludeScreenshot.setVisibility(View.GONE);
            }
            if (screenshotContentView != null) {
                screenshotContentView.setVisibility(View.GONE);
            }
        }
    } else {
        if (mIncludeScreenshot != null) {
            mIncludeScreenshot.setVisibility(View.GONE);
        }
        if (screenshotContentView != null) {
            screenshotContentView.setVisibility(View.GONE);
        }
    }
}

From source file:de.j4velin.mapsmeasure.Map.java

@SuppressLint("NewApi")
@Override/*from  ww w .  j  a va  2  s . c  o m*/
public void onCreate(final Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
    } catch (final BadParcelableException bpe) {
        bpe.printStackTrace();
    }
    setContentView(R.layout.activity_map);

    formatter_no_dec.setMaximumFractionDigits(0);
    formatter_two_dec.setMaximumFractionDigits(2);

    final SharedPreferences prefs = getSharedPreferences("settings", Context.MODE_PRIVATE);

    // use metric a the default everywhere, except in the US
    metric = prefs.getBoolean("metric", !Locale.getDefault().equals(Locale.US));

    final View topCenterOverlay = findViewById(R.id.topCenterOverlay);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    final View menuButton = findViewById(R.id.menu);
    if (menuButton != null) {
        menuButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                mDrawerLayout.openDrawer(GravityCompat.START);
            }
        });
    }

    if (mDrawerLayout != null) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

        mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

            private boolean menuButtonVisible = true;

            @Override
            public void onDrawerStateChanged(int newState) {

            }

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onDrawerSlide(final View drawerView, final float slideOffset) {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setAlpha(1 - slideOffset);
                if (menuButtonVisible && menuButton != null && slideOffset > 0) {
                    menuButton.setVisibility(View.INVISIBLE);
                    menuButtonVisible = false;
                }
            }

            @Override
            public void onDrawerOpened(final View drawerView) {
                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onDrawerClosed(final View drawerView) {
                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setVisibility(View.VISIBLE);
                if (menuButton != null) {
                    menuButton.setVisibility(View.VISIBLE);
                    menuButtonVisible = true;
                }
            }
        });
    }

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (mMap == null) {
        Dialog d = GooglePlayServicesUtil
                .getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this), this, 0);
        d.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        });
        d.show();
        return;
    }

    marker = BitmapDescriptorFactory.fromResource(R.drawable.marker);
    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(final Marker click) {
            addPoint(click.getPosition());
            return true;
        }
    });

    mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
        @Override
        public boolean onMyLocationButtonClick() {
            if (mMap.getMyLocation() != null) {
                LatLng myLocation = new LatLng(mMap.getMyLocation().getLatitude(),
                        mMap.getMyLocation().getLongitude());
                double distance = SphericalUtil.computeDistanceBetween(myLocation,
                        mMap.getCameraPosition().target);

                // Only if the distance is less than 50cm we are on our location, add the marker
                if (distance < 0.5) {
                    Toast.makeText(Map.this, R.string.marker_on_current_location, Toast.LENGTH_SHORT).show();
                    addPoint(myLocation);
                }
            }
            return false;
        }
    });

    // check if open with csv file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        try {
            Util.loadFromFile(getIntent().getData(), this);
            if (!trace.isEmpty())
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(trace.peek(), 16));
        } catch (IOException e) {
            Toast.makeText(this,
                    getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }

    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(final Bundle bundle) {
                    Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
                    if (l != null && mMap.getCameraPosition().zoom <= 2) {
                        mMap.moveCamera(CameraUpdateFactory
                                .newLatLngZoom(new LatLng(l.getLatitude(), l.getLongitude()), 16));
                    }
                    mGoogleApiClient.disconnect();
                }

                @Override
                public void onConnectionSuspended(int cause) {

                }
            }).build();
    mGoogleApiClient.connect();

    valueTv = (TextView) findViewById(R.id.distance);
    updateValueText();
    valueTv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (type == MeasureType.DISTANCE)
                changeType(MeasureType.AREA);
            // only switch to elevation mode is an internet connection is
            // available and user has access to this feature
            else if (type == MeasureType.AREA && Util.checkInternetConnection(Map.this) && PRO_VERSION)
                changeType(MeasureType.ELEVATION);
            else
                changeType(MeasureType.DISTANCE);
        }
    });

    View delete = findViewById(R.id.delete);
    delete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            removeLast();
        }
    });
    delete.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Map.this);
            builder.setMessage(getString(R.string.delete_all, trace.size()));
            builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    clear();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.create().show();
            return true;
        }
    });

    mMap.setOnMapClickListener(new OnMapClickListener() {
        @Override
        public void onMapClick(final LatLng center) {
            addPoint(center);
        }
    });

    // Drawer stuff
    ListView drawerList = (ListView) findViewById(R.id.left_drawer);
    drawerListAdapert = new DrawerListAdapter(this);
    drawerList.setAdapter(drawerListAdapert);
    drawerList.setDivider(null);
    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, int position, long id) {
            switch (position) {
            case 0: // Search before Android 5.0
                Dialogs.getSearchDialog(Map.this).show();
                closeDrawer();
                break;
            case 2: // Units
                Dialogs.getUnits(Map.this, distance, SphericalUtil.computeArea(trace)).show();
                closeDrawer();
                break;
            case 3: // distance
                changeType(MeasureType.DISTANCE);
                break;
            case 4: // area
                changeType(MeasureType.AREA);
                break;
            case 5: // elevation
                if (PRO_VERSION) {
                    changeType(MeasureType.ELEVATION);
                } else {
                    Dialogs.getElevationAccessDialog(Map.this, mService).show();
                }
                break;
            case 7: // map
                changeView(GoogleMap.MAP_TYPE_NORMAL);
                break;
            case 8: // satellite
                changeView(GoogleMap.MAP_TYPE_HYBRID);
                break;
            case 9: // terrain
                changeView(GoogleMap.MAP_TYPE_TERRAIN);
                break;
            case 11: // save
                Dialogs.getSaveNShare(Map.this, trace).show();
                closeDrawer();
                break;
            case 12: // more apps
                try {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:j4velin"))
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (ActivityNotFoundException anf) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/developer?id=j4velin"))
                                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;
            case 13: // about
                Dialogs.getAbout(Map.this).show();
                closeDrawer();
                break;
            default:
                break;
            }
        }
    });

    changeView(prefs.getInt("mapView", GoogleMap.MAP_TYPE_NORMAL));
    changeType(MeasureType.DISTANCE);

    // KitKat translucent decor enabled? -> Add some margin/padding to the
    // drawer and the map
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {

        int statusbar = Util.getStatusBarHeight(this);

        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) topCenterOverlay.getLayoutParams();
        lp.setMargins(0, statusbar + 10, 0, 0);
        topCenterOverlay.setLayoutParams(lp);

        // on most devices and in most orientations, the navigation bar
        // should be at the bottom and therefore reduces the available
        // display height
        int navBarHeight = Util.getNavigationBarHeight(this);

        DisplayMetrics total, available;
        total = new DisplayMetrics();
        available = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(available);
        API17Wrapper.getRealMetrics(getWindowManager().getDefaultDisplay(), total);

        boolean navBarOnRight = getResources()
                .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE
                && (total.widthPixels - available.widthPixels > 0);

        if (navBarOnRight) {
            // in landscape on phones, the navigation bar might be at the
            // right side, reducing the available display width
            mMap.setPadding(mDrawerLayout == null ? Util.dpToPx(this, 200) : 0, statusbar, navBarHeight, 0);
            drawerList.setPadding(0, statusbar + 10, 0, 0);
            if (menuButton != null)
                menuButton.setPadding(0, 0, 0, 0);
        } else {
            mMap.setPadding(0, statusbar, 0, navBarHeight);
            drawerList.setPadding(0, statusbar + 10, 0, 0);
            drawerListAdapert.setMarginBottom(navBarHeight);
            if (menuButton != null)
                menuButton.setPadding(0, 0, 0, navBarHeight);
        }
    }

    mMap.setMyLocationEnabled(true);

    PRO_VERSION |= prefs.getBoolean("pro", false);
    if (!PRO_VERSION) {
        bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND")
                .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE);
    }
}

From source file:com.near.chimerarevo.fragments.CommentsFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void loadDisqusOAuth() {
    if (getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE)
            .getString(Constants.KEY_REFRESH_TOKEN, "").length() > 1) {

        RequestBody formBody = new FormEncodingBuilder().add("grant_type", "refresh_token")
                .add("client_id", Constants.DISQUS_API_KEY).add("client_secret", Constants.DISQUS_API_SECRET)
                .add("refresh_token",
                        getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE)
                                .getString(Constants.KEY_REFRESH_TOKEN, ""))
                .build();//w w  w. j  a  v  a 2s .c  o m

        Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody).tag(FRAGMENT_TAG)
                .build();

        if (mDialog == null)
            mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login);
        else
            mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login);

        mDialog.show();
        OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback());

        return;
    }

    final Dialog dialog = new Dialog(getActivity());

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.webview_layout);
    dialog.setCancelable(true);

    dialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            isDialogOpen = false;
            mFab.show();
        }
    });
    dialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface arg0) {
            isDialogOpen = false;
            mFab.show();
        }
    });

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
        CookieManager.getInstance().removeAllCookies(null);
    else {
        CookieSyncManager.createInstance(getActivity());
        CookieManager.getInstance().removeAllCookie();
    }

    WebView wv = (WebView) dialog.findViewById(R.id.webview);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setSaveFormData(false);
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            dialog.findViewById(R.id.progressContainer).setVisibility(View.GONE);
            dialog.findViewById(R.id.webViewContainer).setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            dialog.findViewById(R.id.progressContainer).setVisibility(View.VISIBLE);
            dialog.findViewById(R.id.webViewContainer).setVisibility(View.GONE);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            boolean state = super.shouldOverrideUrlLoading(view, url);
            if (url.contains(Constants.SITE_URL)) {
                String code = url.split("code=")[1];

                RequestBody formBody = new FormEncodingBuilder().add("grant_type", "authorization_code")
                        .add("client_id", Constants.DISQUS_API_KEY)
                        .add("client_secret", Constants.DISQUS_API_SECRET)
                        .add("redirect_uri", Constants.SITE_URL).add("code", code).build();

                Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody)
                        .tag(FRAGMENT_TAG).build();

                if (mDialog == null)
                    mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login);
                else
                    mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login);

                dialog.dismiss();
                mDialog.show();

                OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback());
            }
            return state;
        }

        @Override
        public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

    });
    wv.loadUrl(URLUtils.getDisqusAuthUrl());

    isDialogOpen = true;
    mFab.hide();
    dialog.show();
}