Example usage for android.app Dialog Dialog

List of usage examples for android.app Dialog Dialog

Introduction

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

Prototype

public Dialog(@NonNull Context context, @StyleRes int themeResId) 

Source Link

Document

Creates a dialog window that uses a custom dialog style.

Usage

From source file:mobi.monaca.framework.plugin.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/* w w w.  j  ava  2s.c  o m*/
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            ImageButton back = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setImageResource(R.drawable.childbroswer_icon_arrow_left);
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setImageResource(R.drawable.childbroswer_icon_arrow_right);
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            close.setImageResource(R.drawable.childbroswer_icon_close);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            //TODO check LocalFileBootloader
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.dhaval.mobile.plugin.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject /*from  w  w  w.  j  a  v  a  2 s.  com*/
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
        showAddressBar = options.optBoolean("showAddressBar", true);
    }

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         * 
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    ctx.getContext().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(ctx.getContext(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(ctx.getContext());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(ctx.getContext());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            ImageButton back = new ImageButton(ctx.getContext());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(ctx.getContext());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(ctx.getContext());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });
            if (!showAddressBar) {
                edittext.setVisibility(EditText.INVISIBLE);
            }

            // Close button
            ImageButton close = new ImageButton(ctx.getContext());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(ctx.getContext());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:com.franmontiel.fullscreendialog.FullScreenDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    initBuilderArguments();//ww  w .  j a v a2s . c  o m

    Dialog dialog = new Dialog(getActivity(), getTheme()) {
        @Override
        public void onBackPressed() {
            onDiscardButtonClick();
        }
    };
    if (!fullScreen)
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    return dialog;
}

From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

/**
 * ?=item ?/*from   w  w w. jav a  2 s  .c om*/
 *
 * @param mContext
 * @return
 */
private Dialog showConfirmOrCancelDialog(final Context mContext) {
    View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_double_choice, null);
    final Dialog dialog = new Dialog(mContext, R.style.mystyle);
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.tv_cancel:
                if (onDialogClickLisenter != null)
                    onDialogClickLisenter.viewClick(StringConstant.tv_cancel);
                dismiss();
                break;
            case R.id.tv_confirm:
                if (onDialogClickLisenter != null)
                    onDialogClickLisenter.viewClick(StringConstant.tv_confirm);
                dismiss();
                break;
            default:
                break;
            }
        }
    };
    TextView tv_cancel = (TextView) convertView.findViewById(R.id.tv_cancel);
    TextView tv_confirm = (TextView) convertView.findViewById(R.id.tv_confirm);
    TextView tv_title = (TextView) convertView.findViewById(R.id.tv_title);
    TextView tv_content = (TextView) convertView.findViewById(R.id.tv_content);

    if (onDialogClickLisenter != null) {
        onDialogClickLisenter.controlView(tv_confirm, tv_cancel, tv_title, tv_content);
    }
    tv_cancel.setOnClickListener(listener);
    tv_confirm.setOnClickListener(listener);
    dialog.setContentView(convertView);
    dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style);
    return dialog;
}

From source file:dev.dworks.apps.asecure.MainActivity.java

private void showLoginDialog() {
    final SharedPreferences.Editor editor = mSharedPreferences.edit();
    final boolean passwordSet = !TextUtils.isEmpty(password);
    final String setPassword = password;

    LayoutInflater layoutInflater = LayoutInflater.from(this);
    final View loginView = layoutInflater.inflate(R.layout.dialog_login, null);
    TextView header = (TextView) loginView.findViewById(R.id.login_header);
    final EditText password = (EditText) loginView.findViewById(R.id.password);
    final EditText password_repeat = (EditText) loginView.findViewById(R.id.password_repeat);

    final Button login = (Button) loginView.findViewById(R.id.login_button);
    //Button cancel = (Button) loginView.findViewById(R.id.cancel_button);

    if (!passwordSet) {
        password_repeat.setVisibility(View.VISIBLE);
        header.setVisibility(View.VISIBLE);
    } else {/*from w w  w. ja  v  a2 s  .co m*/
        password.setVisibility(View.GONE);
        password_repeat.setVisibility(View.VISIBLE);
        password_repeat.setHint(R.string.login_pwd);
    }
    header.setText(!passwordSet ? getString(R.string.login_message) : getString(R.string.msg_login));

    final Dialog dialog = new Dialog(this, R.style.Theme_Asecure_DailogLogin);
    dialog.setContentView(loginView);
    dialog.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    dialog.show();

    password_repeat.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == R.id.login_button || actionId == EditorInfo.IME_NULL
                    || actionId == EditorInfo.IME_ACTION_DONE) {
                login.performClick();
                return true;
            }
            return false;
        }
    });
    login.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (passwordSet) {
                final String passwordString = password_repeat.getText().toString();
                if (TextUtils.isEmpty(passwordString) || passwordString.compareTo(setPassword) != 0) {
                    password_repeat.startAnimation(shake);
                    password_repeat.setError(getString(R.string.msg_wrong_password));
                    return;
                }
            } else {
                final String passwordString = password_repeat.getText().toString();
                final String passwordRepeatString = password_repeat.getText().toString();
                if (TextUtils.isEmpty(passwordString)) {
                    password.startAnimation(shake);
                    password.setError(getString(R.string.msg_pwd_empty));
                    return;
                }
                if (TextUtils.isEmpty(passwordRepeatString)) {
                    password_repeat.startAnimation(shake);
                    password_repeat.setError(getString(R.string.msg_pwd_empty));
                    return;
                } else if (passwordString.compareTo(passwordRepeatString) != 0) {
                    password_repeat.startAnimation(shake);
                    password_repeat.setError(getString(R.string.msg_pwd_dont_match));
                    return;
                }
                editor.putString("LoginPasswordPref", password.getText().toString());
                editor.commit();
            }
            dialog.dismiss();
        }
    });

    /*        cancel.setOnClickListener(new OnClickListener(){
            
             @Override
             public void onClick(View arg0) {
    dialog.dismiss();
    finish();
             }});*/
}

From source file:com.king.base.BaseActivity.java

protected void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,
        final boolean isCancel) {
    dismissDialog();/*from w ww .j av a  2s. co  m*/
    dialog = new Dialog(context, resId);
    dialog.setContentView(contentView);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && isCancel) {
                dismissDialog();
            }
            return true;

        }
    });
    setDialogWindow(dialog, widthRatio);
    dialog.show();

}

From source file:com.insthub.O2OMobile.Activity.F9_SettingActivity.java

private void showDialog() {
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.photo_dialog, null);
    mDialog = new Dialog(this, R.style.dialog);
    mDialog.setContentView(view);//w  w  w.  j a  v  a2 s  . c  o  m

    mDialog.setCanceledOnTouchOutside(true);
    mDialog.show();
    LinearLayout requsetCameraLayout = (LinearLayout) view.findViewById(R.id.register_camera);
    LinearLayout requestPhotoLayout = (LinearLayout) view.findViewById(R.id.register_photo);

    requsetCameraLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDialog.dismiss();
            if (mFileDir == null) {
                mFileDir = new File(O2OMobileAppConst.FILEPATH + "img/");
                if (!mFileDir.exists()) {
                    mFileDir.mkdirs();
                }
            }
            mFileName = O2OMobileAppConst.FILEPATH + "img/" + "temp.jpg";
            mFile = new File(mFileName);
            Uri imageuri = Uri.fromFile(mFile);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageuri);
            intent.putExtra("return-data", false);
            startActivityForResult(intent, REQUEST_CAMERA);
        }
    });

    requestPhotoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDialog.dismiss();
            Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(picture, REQUEST_PHOTO);

        }
    });
}

From source file:com.thingsee.tracker.MainActivity.java

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;/* w w  w .j  a v  a 2  s . c  o m*/

    TileProvider wmsTileProvider = TileProviderFactory.getKapsiWmsTileProvider();
    mMap.addTileOverlay(new TileOverlayOptions().tileProvider(wmsTileProvider).fadeIn(true));

    initGoogleMap();

    trackerList = (HorizontalScrollView) this.findViewById(R.id.tracker_scroll_area);
    mTrackerItemLayout = (LinearLayout) findViewById(R.id.trackers);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mainari, 16));
    Marker mark = mMap.addMarker(new MarkerOptions().position(mainari));

    ImageView locateButton = (ImageView) findViewById(R.id.app_icon);

    //set the ontouch listener
    locateButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                if (onChildOnMapView) {
                    onUpPressed();
                } else {
                    userZoomAndPanOnMap = false;
                    zoomToBoundingBox();
                }
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    ImageView settingsButton = (ImageView) findViewById(R.id.header_settings_icon);

    //set the ontouch listener
    settingsButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                //overlay is black with transparency of 0x77 (119)
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                final Dialog verificationQuery = new Dialog(mContext,
                        android.R.style.Theme_Translucent_NoTitleBar);
                verificationQuery.requestWindowFeature(Window.FEATURE_NO_TITLE);
                verificationQuery.setCancelable(false);
                verificationQuery.setContentView(R.layout.request_admin_code);
                ClearTextView ok = (ClearTextView) verificationQuery.findViewById(R.id.ok);
                ok.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                        EditText code = (EditText) verificationQuery.findViewById(R.id.verification_code);
                        if (code.getText().toString().equalsIgnoreCase("password")) {
                            Intent intent = new Intent(MainActivity.this, MenuActivity.class);
                            startActivity(intent);
                        }
                    }
                });
                ClearTextView cancel = (ClearTextView) verificationQuery.findViewById(R.id.cancel);
                cancel.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                    }
                });
                verificationQuery.show();
                verificationQuery.getWindow().setDimAmount(0.5f);
                verificationQuery.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng position) {
            if (onChildOnMapView) {
                if (trackerModelWithMarker != null) {
                    trackerModelWithMarker.getMarker().showInfoWindow();
                }
            }
        }
    });

    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (trackersActive) {
                LatLng latlng = marker.getPosition();
                userZoomAndPanOnMap = false;
                if ((latlng.latitude == mainari.latitude) && (latlng.longitude == mainari.longitude)) {
                    if (onChildOnMapView) {
                        if (trackerModelWithMarker != null) {
                            trackerModelWithMarker.getMarker().showInfoWindow();
                        }
                    }
                } else {
                    if (!onChildOnMapView) {
                        trackerModelWithMarker = null;
                        // Zoom to marker tapped
                        zoomToMarker(latlng);
                        //Remove other markers
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    focusOnChildOnMap(trackerModel.getSerialNumber());
                                    trackerModelWithMarker = trackerModel;
                                    trackerModelWithMarker.getMarker().showInfoWindow();
                                }
                            }
                        }
                    } else {
                        trackerModelWithMarker.getMarker().showInfoWindow();
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    onBackPressed();
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
    });
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker arg0) {

            // Getting view from the layout file info_window_layout
            View v = null;

            for (String key : trackers.keySet()) {
                TrackerModel trackerModel = trackers.get(key);
                if (trackerModel.getLatestLatLng() != null) {
                    if ((trackerModel.getLatestLatLng().latitude == arg0.getPosition().latitude)
                            && (trackerModel.getLatestLatLng().longitude == arg0.getPosition().longitude)) {
                        v = getLayoutInflater().inflate(R.layout.info_window, null);
                        trackerModelWithMarker = trackerModel;
                        TextView trackerAccuracy = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_accuracy);
                        if (trackerModelWithMarker.getAccuracy() != -1) {
                            trackerAccuracy
                                    .setText(String.format(mResources.getString(R.string.tracker_accuracy),
                                            trackerModelWithMarker.getAccuracy()));
                        } else {
                            trackerAccuracy.setText(
                                    String.format(mResources.getString(R.string.tracker_accuracy), 0.0f));
                        }
                        TextView trackerDistanceTs = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_update_timestamp);
                        if (trackerModelWithMarker.getLastLocationUpdate() != 0) {
                            String timeStampText = Utilities.getSmartTimeStampString(mContext, mResources,
                                    trackerModelWithMarker.getLastLocationUpdate());
                            trackerDistanceTs.setText(
                                    mResources.getString(R.string.tracker_timestamp) + " " + timeStampText);
                        } else {
                            trackerDistanceTs.setText(mResources.getString(R.string.tracker_timestamp) + " - ");
                        }
                        trackerInfoWindow = v;
                    }
                }
            }
            // Returning the view containing InfoWindow contents
            return v;
        }
    });
    IntentFilter statusIntentFilter = new IntentFilter(CommonConstants.BROADCAST_ACTION);
    statusIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    mFetchCloudDataStateReceiver = new FetchCloudDataStateReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(mFetchCloudDataStateReceiver, statusIntentFilter);

    mapLoaded = true;
    if (splashReady) {
        mSplashHandler.postDelayed(splashScreenOffFromDisplay, 0);
    }
}

From source file:com.cloudexplorers.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 * /* w ww  .  j av  a 2  s .  c o  m*/
 * @param url
 *          The url to load.
 * @param jsonObject
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         * 
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            ImageButton back = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input...
                                                        // Makes the text
                                                        // NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);

            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setPluginsEnabled(true);

            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container
            // layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:edu.sfsu.csc780.chathub.ui.ChannelActivity.java

public void openBottomSheet() {
    View view = getLayoutInflater().inflate(R.layout.bottom_sheet_modal, null);
    final Dialog mBottomSheetDialog = new Dialog(ChannelActivity.this, R.style.MaterialDialogSheet);
    mBottomSheetDialog.setContentView(view);
    mBottomSheetDialog.setCancelable(true);
    mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
    mBottomSheetDialog.show();//from   w w  w  .  j a v a 2 s .  c o  m

    mImageButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.shareImageButton);
    mImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pickImage();
            mBottomSheetDialog.hide();
        }
    });

    mPhotoButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.cameraButton);
    mPhotoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dispatchTakePhotoIntent();
            mBottomSheetDialog.hide();
        }
    });

    mLocationButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.locationButton);
    mLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            loadMap();
            mBottomSheetDialog.hide();
        }
    });

    mProgress = new ProgressDialog(this);
    mStorage = FirebaseStorage.getInstance().getReference();
    mAudioButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.voiceButton);
    mAudioButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                startRecording();

                Context context = getApplicationContext();
                CharSequence text = "Recording Started!";
                int duration = Toast.LENGTH_SHORT;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();

            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                stopRecording();
                mBottomSheetDialog.hide();

                Context context = getApplicationContext();
                CharSequence text = "Recording Stopped!";
                int duration = Toast.LENGTH_SHORT;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();

            }

            return false;
        }
    });
    mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
    mFileName += "/recorded_audio.3gp";

    mStickerButton = (BadgedStickersButton) mBottomSheetDialog.findViewById(R.id.stickerButton);
    StickersFragment stickersFragment = (StickersFragment) getSupportFragmentManager()
            .findFragmentById(R.id.frame);
    if (stickersFragment == null) {
        stickersFragment = new StickersFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.frame, stickersFragment).commit();
    }
    stickersFragment.setOnStickerSelectedListener(stickerSelectedListener);
    View stickersFrame = findViewById(R.id.frame);
    View chatContentGroup = findViewById(R.id.chat_content);
    StickersKeyboardLayout stickersLayout = (StickersKeyboardLayout) findViewById(R.id.sizeNotifierLayout);
    stickersKeyboardController = new StickersKeyboardController.Builder(this)
            .setStickersKeyboardLayout(stickersLayout).setStickersFragment(stickersFragment)
            .setStickersFrame(stickersFrame).setContentContainer(chatContentGroup)
            .setStickersButton(mStickerButton).setChatEdit(mMessageEditText).build();

    mDrawButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.drawButton);
    mDrawButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(ChannelActivity.this, DrawingActivity.class));
            mBottomSheetDialog.hide();
        }
    });
}