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) 

Source Link

Document

Creates a dialog window that uses the default dialog theme.

Usage

From source file:com.nttec.everychan.http.recaptcha.Recaptcha2fallback.java

@Override
public void handle(final Activity activity, final CancellableTask task, final Callback callback) {
    try {//from   w  w  w.j av  a 2  s.c om
        final HttpClient httpClient = ((HttpChanModule) MainApplication.getInstance().getChanModule(chanName))
                .getHttpClient();
        final String usingURL = scheme + RECAPTCHA_FALLBACK_URL + publicKey
                + (sToken != null && sToken.length() > 0 ? ("&stoken=" + sToken) : "");
        String refererURL = baseUrl != null && baseUrl.length() > 0 ? baseUrl : usingURL;
        Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, refererURL) };
        String htmlChallenge;
        if (lastChallenge != null && lastChallenge.getLeft().equals(usingURL)) {
            htmlChallenge = lastChallenge.getRight();
        } else {
            htmlChallenge = HttpStreamer.getInstance().getStringFromUrl(usingURL,
                    HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient,
                    null, task, false);
        }
        lastChallenge = null;

        Matcher challengeMatcher = Pattern.compile("name=\"c\" value=\"([\\w-]+)").matcher(htmlChallenge);
        if (challengeMatcher.find()) {
            final String challenge = challengeMatcher.group(1);
            HttpResponseModel responseModel = HttpStreamer.getInstance().getFromUrl(
                    scheme + RECAPTCHA_IMAGE_URL + challenge + "&k=" + publicKey,
                    HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient,
                    null, task);
            try {
                InputStream imageStream = responseModel.stream;
                final Bitmap challengeBitmap = BitmapFactory.decodeStream(imageStream);

                final String message;
                Matcher messageMatcher = Pattern.compile("imageselect-message(?:.*?)>(.*?)</div>")
                        .matcher(htmlChallenge);
                if (messageMatcher.find())
                    message = RegexUtils.removeHtmlTags(messageMatcher.group(1));
                else
                    message = null;

                final Bitmap candidateBitmap;
                Matcher candidateMatcher = Pattern
                        .compile("fbc-imageselect-candidates(?:.*?)src=\"data:image/(?:.*?);base64,([^\"]*)\"")
                        .matcher(htmlChallenge);
                if (candidateMatcher.find()) {
                    Bitmap bmp = null;
                    try {
                        byte[] imgData = Base64.decode(candidateMatcher.group(1), Base64.DEFAULT);
                        bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length);
                    } catch (Exception e) {
                    }
                    candidateBitmap = bmp;
                } else
                    candidateBitmap = null;

                activity.runOnUiThread(new Runnable() {
                    final int maxX = 3;
                    final int maxY = 3;
                    final boolean[] isSelected = new boolean[maxX * maxY];

                    @SuppressLint("InlinedApi")
                    @Override
                    public void run() {
                        LinearLayout rootLayout = new LinearLayout(activity);
                        rootLayout.setOrientation(LinearLayout.VERTICAL);

                        if (candidateBitmap != null) {
                            ImageView candidateView = new ImageView(activity);
                            candidateView.setImageBitmap(candidateBitmap);
                            int picSize = (int) (activity.getResources().getDisplayMetrics().density * 50
                                    + 0.5f);
                            candidateView.setLayoutParams(new LinearLayout.LayoutParams(picSize, picSize));
                            candidateView.setScaleType(ImageView.ScaleType.FIT_XY);
                            rootLayout.addView(candidateView);
                        }

                        if (message != null) {
                            TextView textView = new TextView(activity);
                            textView.setText(message);
                            CompatibilityUtils.setTextAppearance(textView, android.R.style.TextAppearance);
                            textView.setLayoutParams(
                                    new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                            LinearLayout.LayoutParams.WRAP_CONTENT));
                            rootLayout.addView(textView);
                        }

                        FrameLayout frame = new FrameLayout(activity);
                        frame.setLayoutParams(
                                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));

                        final ImageView imageView = new ImageView(activity);
                        imageView.setLayoutParams(new FrameLayout.LayoutParams(
                                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
                        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                        imageView.setImageBitmap(challengeBitmap);
                        frame.addView(imageView);

                        final LinearLayout selector = new LinearLayout(activity);
                        selector.setLayoutParams(new FrameLayout.LayoutParams(
                                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
                        AppearanceUtils.callWhenLoaded(imageView, new Runnable() {
                            @Override
                            public void run() {
                                selector.setLayoutParams(new FrameLayout.LayoutParams(imageView.getWidth(),
                                        imageView.getHeight()));
                            }
                        });
                        selector.setOrientation(LinearLayout.VERTICAL);
                        selector.setWeightSum(maxY);
                        for (int y = 0; y < maxY; ++y) {
                            LinearLayout subSelector = new LinearLayout(activity);
                            subSelector.setLayoutParams(new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));
                            subSelector.setOrientation(LinearLayout.HORIZONTAL);
                            subSelector.setWeightSum(maxX);
                            for (int x = 0; x < maxX; ++x) {
                                FrameLayout switcher = new FrameLayout(activity);
                                switcher.setLayoutParams(new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.MATCH_PARENT, 1f));
                                switcher.setTag(new int[] { x, y });
                                switcher.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        int[] coord = (int[]) v.getTag();
                                        int index = coord[1] * maxX + coord[0];
                                        isSelected[index] = !isSelected[index];
                                        v.setBackgroundColor(isSelected[index] ? Color.argb(128, 0, 255, 0)
                                                : Color.TRANSPARENT);
                                    }
                                });
                                subSelector.addView(switcher);
                            }
                            selector.addView(subSelector);
                        }

                        frame.addView(selector);
                        rootLayout.addView(frame);

                        Button checkButton = new Button(activity);
                        checkButton.setLayoutParams(
                                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));
                        checkButton.setText(android.R.string.ok);
                        rootLayout.addView(checkButton);

                        ScrollView dlgView = new ScrollView(activity);
                        dlgView.addView(rootLayout);

                        final Dialog dialog = new Dialog(activity);
                        dialog.setTitle("Recaptcha");
                        dialog.setContentView(dlgView);
                        dialog.setCanceledOnTouchOutside(false);
                        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                if (!task.isCancelled()) {
                                    callback.onError("Cancelled");
                                }
                            }
                        });
                        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.WRAP_CONTENT);
                        dialog.show();

                        checkButton.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                                if (task.isCancelled())
                                    return;
                                Async.runAsync(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                                            pairs.add(new BasicNameValuePair("c", challenge));
                                            for (int i = 0; i < isSelected.length; ++i)
                                                if (isSelected[i])
                                                    pairs.add(new BasicNameValuePair("response",
                                                            Integer.toString(i)));

                                            HttpRequestModel request = HttpRequestModel.builder()
                                                    .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8"))
                                                    .setCustomHeaders(new Header[] {
                                                            new BasicHeader(HttpHeaders.REFERER, usingURL) })
                                                    .build();
                                            String response = HttpStreamer.getInstance().getStringFromUrl(
                                                    usingURL, request, httpClient, null, task, false);
                                            String hash = "";
                                            Matcher matcher = Pattern.compile(
                                                    "fbc-verification-token(?:.*?)<textarea[^>]*>([^<]*)<",
                                                    Pattern.DOTALL).matcher(response);
                                            if (matcher.find())
                                                hash = matcher.group(1);

                                            if (hash.length() > 0) {
                                                Recaptcha2solved.push(publicKey, hash);
                                                activity.runOnUiThread(new Runnable() {
                                                    @Override
                                                    public void run() {
                                                        callback.onSuccess();
                                                    }
                                                });
                                            } else {
                                                lastChallenge = Pair.of(usingURL, response);
                                                throw new RecaptchaException(
                                                        "incorrect answer (hash is empty)");
                                            }
                                        } catch (final Exception e) {
                                            Logger.e(TAG, e);
                                            if (task.isCancelled())
                                                return;
                                            handle(activity, task, callback);
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
            } finally {
                responseModel.release();
            }
        } else
            throw new Exception("can't parse recaptcha challenge answer");
    } catch (final Exception e) {
        Logger.e(TAG, e);
        if (!task.isCancelled()) {
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callback.onError(e.getMessage() != null ? e.getMessage() : e.toString());
                }
            });
        }
    }
}

From source file:gov.nasa.arc.geocam.geocam.CameraActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_SAVE_PROGRESS:
        mSaveProgressDialog = new ProgressDialog(this);
        mSaveProgressDialog.setMessage(getResources().getString(R.string.camera_saving));
        mSaveProgressDialog.setIndeterminate(true);
        mSaveProgressDialog.setCancelable(false);
        return mSaveProgressDialog;

    case DIALOG_HIDE_KEYBOARD:
        mHideKeyboardDialog = new Dialog(this);
        mHideKeyboardDialog.setTitle(getResources().getString(R.string.camera_hide_keyboard));
        return mHideKeyboardDialog;

    default:/* ww w  . ja  v  a 2  s.c  om*/
        break;
    }
    return null;
}

From source file:com.woofy.haifa.MapActivity.java

private boolean initMap() {
    if (mMap == null) {
        SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mMap = mapFrag.getMap();//from   w  w w . j ava  2s.c  om

        if (mMap != null) {
            mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

                @Override
                public View getInfoWindow(Marker marker) {

                    // Getting view from the layout file
                    LayoutInflater inflater = LayoutInflater.from(MapActivity.this);
                    View v = inflater.inflate(R.layout.info_window, null);

                    TextView locality = (TextView) v.findViewById(R.id.tv_locality);
                    locality.setText(marker.getTitle());

                    //                   TextView title = (TextView) v.findViewById(R.id.tv_lat);
                    //                   title.setText(marker.getTitle());

                    TextView address = (TextView) v.findViewById(R.id.tv_lng);
                    address.setText(marker.getSnippet());

                    ImageView img = (ImageView) v.findViewById(R.id.imageView1);
                    if (lastbitmap != null) {
                        img.setImageBitmap(lastbitmap);
                    }
                    if (pic_map.containsKey(marker.getTitle())) {
                        img.setImageBitmap(pic_map.get(marker.getTitle()));
                    }
                    if (marker.getTitle().equals("You")) {
                        img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.you_marker));
                    }

                    if (marker.getSnippet().length() < 30) {

                        //                   img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bad_dog));
                        new HttpLib.MarkerPic(marker.getTitle(), img, marker).execute();
                        //                   HttpLib.DownloadImageTask task=new HttpLib.DownloadImageTask(img,marker);
                        //                   task.execute("http://52.1.192.145/uploads/img_1434327703156_kgqsjhlevp9fj6tcs7su32gj43.jpg");
                        //                   
                        Vector<BasicNameValuePair> vec = new Vector<BasicNameValuePair>();
                        vec.add(new BasicNameValuePair("name", marker.getTitle()));
                        new HttpLib.MarkerInfoWindow(vec, marker).execute();

                    }

                    return v;
                    //                  return null;
                }

                @Override
                public View getInfoContents(Marker marker) {

                    View v = getLayoutInflater().inflate(R.layout.info_window, null);
                    TextView tvLocality = (TextView) v.findViewById(R.id.tv_locality);
                    TextView tvLat = (TextView) v.findViewById(R.id.tv_lat);
                    TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
                    TextView tvSnippet = (TextView) v.findViewById(R.id.tv_snippet);
                    //                  ImageView img = (ImageView) v.findViewById(R.id.imageView1);
                    LatLng ll = marker.getPosition();

                    tvLocality.setText(marker.getTitle());
                    //                  tvLat.setText("Dogs: " + "Woofy, Goofy");
                    //                  tvLng.setText("Click for more info");
                    //                  tvSnippet.setText(marker.getSnippet());

                    ImageView img = (ImageView) v.findViewById(R.id.imageView1);

                    if (lastbitmap != null) {
                        img.setImageBitmap(lastbitmap);
                        Log.d("Set bitmap", "Set bitmap");
                    } else {
                        new HttpLib.MarkerPic(marker.getTitle(), img, marker).execute();
                    }
                    if (marker.getSnippet().length() < 30) {

                        //                      img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bad_dog));

                        //                      HttpLib.DownloadImageTask task=new HttpLib.DownloadImageTask(img,marker);
                        //                      task.execute("http://52.1.192.145/uploads/img_1434327703156_kgqsjhlevp9fj6tcs7su32gj43.jpg");
                        //                      
                        Vector<BasicNameValuePair> vec = new Vector<BasicNameValuePair>();
                        vec.add(new BasicNameValuePair("name", marker.getTitle()));
                        new HttpLib.MarkerInfoWindow(vec, marker).execute();

                    }

                    return v;

                }
            });

            mMap.setOnMapLongClickListener(new OnMapLongClickListener() {

                @Override
                public void onMapLongClick(final LatLng point) {

                    final Dialog dialog = new Dialog(MapActivity.this);
                    dialog.setContentView(R.layout.alert_layout);
                    dialog.setCancelable(true);
                    dialog.show();

                    //                       .setMessage(R.string.really_quit)
                    Button b = (Button) dialog.findViewById(R.id.yesmeet);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            String t1 = ((EditText) dialog.findViewById(R.id.meet_name)).getText().toString();
                            //                               String t2 = ((EditText)dialog.findViewById(R.id.editText1111)).getText().toString();

                            if (meet != null)
                                meet.remove();
                            MarkerOptions options;
                            options = new MarkerOptions().title(t1).position(point)
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
                                    .anchor(.5f, .5f) //center the icon
                                    .draggable(true);

                            Marker mar = mMap.addMarker(options);

                            //                           MeetingMarkers.add(mar);
                            meet = mar;

                            dialog.dismiss();

                        }

                    });

                    Button b1 = (Button) dialog.findViewById(R.id.nomeet);
                    b1.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            dialog.dismiss();

                        }
                    });

                }
            });

            mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
                @Override
                public void onCameraChange(CameraPosition position) {
                    if (SystemClock.uptimeMillis() - show_people_last_updated > 1000) {
                        show_people_last_updated = SystemClock.uptimeMillis();
                        showPeople();
                    }
                }
            });

            mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

                @Override
                public boolean onMarkerClick(final Marker marker) {

                    lastbitmap = null;
                    marker.hideInfoWindow();
                    marker.showInfoWindow();

                    return false;
                }
            });

            mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                @Override
                public void onInfoWindowClick(Marker marker) {
                    Log.d("Open profile page", marker.getTitle());
                    Intent intent = new Intent(MapActivity.this, Profile.class);
                    intent.putExtra("name", marker.getTitle());
                    startActivity(intent);

                }
            });

            mMap.setOnMarkerDragListener(new OnMarkerDragListener() {

                @Override
                public void onMarkerDragStart(Marker marker) {
                    marker.remove();
                    MarkerOptions options;
                    options = new MarkerOptions().title(marker.getTitle()).position(marker.getPosition())
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker))
                            .anchor(.5f, .5f) //center the icon
                            .draggable(true);

                    String name = marker.getTitle();
                    if (selected_markers.contains(name)) {
                        selected_markers.remove(name);
                    } else {
                        selected_markers.add(name);
                        options.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_checked));
                    }

                    Marker addmarker = mMap.addMarker(options);
                    PersonMarkers.add(addmarker);
                }

                @Override
                public void onMarkerDragEnd(Marker marker) {

                }

                @Override
                public void onMarkerDrag(Marker arg0) {

                }
            });
        }
    }
    return (mMap != null);
}

From source file:com.example.google.playservices.placepicker.PlacePickerFragment.java

@Override
public void onCardClick(int cardActionId, String cardTag) {
    if (cardActionId == ACTION_PICK_PLACE) {
        // BEGIN_INCLUDE(intent)
        /* Use the PlacePicker Builder to construct an Intent.
        Note: This sample demonstrates a basic use case.
        The PlacePicker Builder supports additional properties such as search bounds.
         *///  w ww.  j a v  a2  s.co m
        try {
            PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
            Intent intent = intentBuilder.build(getActivity());
            // Start the Intent by requesting a result, identified by a request code.
            startActivityForResult(intent, REQUEST_PLACE_PICKER);

            // Hide the pick option in the UI to prevent users from starting the picker
            // multiple times.
            showPickAction(false);

        } catch (GooglePlayServicesRepairableException e) {
            GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), getActivity(), 0);
        } catch (GooglePlayServicesNotAvailableException e) {
            Toast.makeText(getActivity(), "Google Play Services is not available.", Toast.LENGTH_LONG).show();
        }

        // END_INCLUDE(intent)
    } else if (cardActionId == ACTION_REPORT_WAIT) {
        final Dialog dialog = new Dialog(this.getActivity());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.report);

        final NumberPicker np = (NumberPicker) dialog.findViewById(R.id.numpicker);
        np.setMaxValue(120);
        np.setMinValue(0);

        // Report
        Button dialogButtonReport = (Button) dialog.findViewById(R.id.dialogButtonReport);
        dialogButtonReport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HttpPost httppost = new HttpPost("http://powergrid.xyz/quickq/restaurantpost.php");
                httppost.setHeader("Content-type", "application/x-www-form-urlencoded");
                List<NameValuePair> nameValuePairs = new ArrayList<>(2);
                // TODO
                nameValuePairs.add(new BasicNameValuePair("placeid", globalplace.getId()));
                nameValuePairs.add(new BasicNameValuePair("waittime", String.valueOf(np.getValue())));
                try {
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                } catch (UnsupportedEncodingException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                powergridServerReportTime task = new powergridServerReportTime();
                task.execute(httppost);

                dialog.dismiss();
            }
        });

        // Cancel
        Button dialogButtonCancel = (Button) dialog.findViewById(R.id.dialogButtonCancel);
        // If button is clicked, close the custom dialog
        dialogButtonCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }
}

From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java

public void showconfirmationdialog(final int fragnumber) {
    final Dialog dialog = new Dialog(TabsActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_leaving_confirmation);
    dialog.getWindow()/*from ww  w  . jav a2 s.c  om*/
            .setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    Button yes = (Button) dialog.findViewById(R.id.yesbtn);
    yes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (fragnumber) {
            case 1:
                showpickupschool();
                break;
            case 2:
                showdrill();
                break;
            case 3:
                showservice();
                break;
            case 4:
                showinstall();
                break;
            case 5:
                showpending();
                break;

            }
            dialog.dismiss();

        }
    });
    Button no = (Button) dialog.findViewById(R.id.nobtn);
    no.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    ImageView close = (ImageView) dialog.findViewById(R.id.ivClose);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

From source file:com.eurotong.orderhelperandroid.OrderMenuActivity.java

@Override
public void onClick(View v) {
    if (v.getId() == R.id.btnGoHome) {
        GotoTableOrderView();/*from  w w  w.ja  va2 s  .c o m*/
        //finish();
    }
    if (v.getId() == R.id.btnPrint) {
        // custom dialog
        final Dialog dialog = new Dialog(context);

        dialog.setContentView(R.layout.print_command_selection);
        dialog.setTitle(R.string.msg_please_select_operation);

        // set the custom dialog components - text, image and button
        Button btnPrintBill = (Button) dialog.findViewById(R.id.btnPrintBill);
        Button btnPrintKitchen = (Button) dialog.findViewById(R.id.btnPrintKitchen);
        Button btnExit = (Button) dialog.findViewById(R.id.btnExit);
        Button btnPrintBar = (Button) dialog.findViewById(com.eurotong.orderhelperandroid.R.id.btnPrintBar);
        Button btnPrintPreview = (Button) dialog
                .findViewById(com.eurotong.orderhelperandroid.R.id.btnPrintPreview);
        if (!User.Current().HasRight(Define.UR_DEBUG_PRINT_LAYOUT)) {
            btnPrintPreview.setVisibility(View.GONE);
        }
        // if button is clicked, close the custom dialog
        btnPrintBill.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (User.Current().HasRight(Define.UR_PRINT)) {
                    DoPrintPos(_table, PrintLayout.Current(), Setting.Current().NumberOfPrints);
                    dialog.dismiss();
                }
            }
        });

        btnPrintKitchen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (User.Current().HasRight(Define.UR_PRINT_KITCHEN)) {
                    DoPrintPos(_table, PrintLayout.KitchenLayout(), Setting.Current().NumberOfPrintsKitchen);
                    dialog.dismiss();
                }
            }
        });

        btnPrintBar.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (User.Current().HasRight(Define.UR_PRINT_BAR)) {
                    DoPrintPos(_table, PrintLayout.BarLayout(), Setting.Current().NumberOfPrintsBar);
                    dialog.dismiss();
                }
            }
        });
        btnPrintPreview.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, PrintPreview.class);
                i.putExtra(Define.TABLE_NR, _table.TableNr);
                startActivity(i);
                dialog.dismiss();
            }
        });
        btnExit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }
    if (v.getId() == R.id.btnExtra) {
        // custom dialog
        final Dialog dialog = new Dialog(context);

        dialog.setContentView(R.layout.table_order_extra);
        dialog.setTitle(R.string.msg_please_select_operation);

        // set the custom dialog components - text, image and button
        Button btnViewTableDetail = (Button) dialog.findViewById(R.id.btnViewTableDetail);
        Button btnDeleteTable = (Button) dialog.findViewById(R.id.btnDeleteTable);
        Button btnExit = (Button) dialog.findViewById(com.eurotong.orderhelperandroid.R.id.btnExit);
        Button btnAddChildTable = (Button) dialog
                .findViewById(com.eurotong.orderhelperandroid.R.id.btnAddChildTable);

        // if button is clicked, close the custom dialog
        btnViewTableDetail.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, TableDetailActivity.class);
                i.putExtra(Define.TABLE_NR, _table.TableNr);
                startActivity(i);
                dialog.dismiss();
            }
        });

        btnAddChildTable.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Table table;
                if (_table.ParentTable != null) {
                    table = _table.ParentTable.CreateChildTable();
                } else {
                    table = _table.CreateChildTable();
                }
                TableHelper.TableList().add(table);
                TableHelper.SaveTablesToStorage();
                _table = table;
                InitVMMenuGroup();
                ShowCurrentOrders();
                dialog.dismiss();
            }
        });

        btnDeleteTable.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Builder confirmDeleteTableDialog = new AlertDialog.Builder(context);
                confirmDeleteTableDialog.setTitle(R.string.msg_are_you_sure_to_delete_this_order);
                confirmDeleteTableDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        TableHelper.DeleteTableByNumber(_table.TableNr);
                        TableHelper.SaveTablesToStorage();
                        dialog.dismiss();
                        finish();
                        //MyApplication.GoToHome();
                        //finish();
                        //Intent i = new Intent(context, TablesOverviewActivity.class);                        
                        //startActivity(i);
                        //dialog.dismiss();
                    }
                });
                confirmDeleteTableDialog.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //
                    }
                });
                confirmDeleteTableDialog.show();
                dialog.dismiss();
            }
        });
        btnExit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }
    //else if(v.getId()==R.id.btnSave)
    ///{
    //   SaveTableOrders();
    //   GotoTableOrderView();
    //finish(); //finish means close. want to refresh tableorder when close this view. so instead use gototableorderview()
    //}   
    //else if(v.getId()==R.id.btnAllMenu)
    //{
    //   BindingMenuList();
    //}
    else if (v.getId() == R.id.btnMenuGroup) {
        MakeMenuGroupButtons();
    }
    //else if(v.getId()==R.id.btnMenuBar)
    //{
    //   BingMenuBarList();
    //}
    if (v.getId() == R.id.btnCurrentOrders) {
        ShowCurrentOrders();
        //finish();
    } else if (v.getId() == R.id.btnCloseKeyboard) {
        //close soft keyboard
        //http://www.workingfromhere.com/blog/2011/04/27/close-hide-the-android-soft-keyboard/
        InputMethodManager imm = (InputMethodManager) getSystemService(
                MyApplication.getAppContext().INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editTextInput.getWindowToken(), 0);
        View filling = menusContainer.findViewById(R.id.hint_fill);
        if (filling != null) {
            filling.setVisibility(View.GONE);
        }
        SetEditTextInputText("");
        ShowCurrentOrders();
    }
}

From source file:com.sentaroh.android.TaskAutomation.ActivityTaskStatus.java

private void showMainDialog(String action) {

    // common ??/*from w  ww  .j  a  va 2  s . c o m*/
    mainDialog = new Dialog(context);
    mainDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mainDialog.setContentView(R.layout.task_status_dlg);

    if (util.isKeyguardEffective()) {
        Window win = mainDialog.getWindow();
        win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                //            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }
    ;

    TextView title = (TextView) mainDialog.findViewById(R.id.task_status_dlg_title);
    title.setText(getString(R.string.msgs_status_dialog_title));
    setSchedulerStatus();
    historyListView = (ListView) mainDialog.findViewById(R.id.task_status_dlg_history_listview);
    statusListView = (ListView) mainDialog.findViewById(R.id.task_status_dlg_status_listview);

    historyAdapter = new AdapterTaskStatusHistoryList(this, R.layout.task_history_list_item,
            getTaskHistoryList());
    historyListView.setAdapter(historyAdapter);
    historyListView.setSelection(historyAdapter.getCount() - 1);
    historyListView.setEnabled(true);
    historyListView.setSelected(true);
    setTaskListLongClickListener();

    statusAdapter = new AdapterTaskStatusActiveList(this, R.layout.task_status_list_item, getActiveTaskList(1));
    statusListView.setAdapter(statusAdapter);
    statusListView.setSelection(statusAdapter.getCount() - 1);
    statusListView.setEnabled(true);
    statusListView.setSelected(true);

    setCancelBtnListener();

    final Button btnStatus = (Button) mainDialog.findViewById(R.id.task_status_dlg_status_btn);
    final Button btnHistory = (Button) mainDialog.findViewById(R.id.task_status_dlg_history_btn);

    final CheckBox cb_enable_scheduler = (CheckBox) mainDialog
            .findViewById(R.id.task_status_dlg_status_enable_scheduler);

    final Button btnLog = (Button) mainDialog.findViewById(R.id.task_status_dlg_log_btn);
    final Button btnClose = (Button) mainDialog.findViewById(R.id.task_status_dlg_close_btn);

    CommonDialog.setDlgBoxSizeLimit(mainDialog, true);
    //      mainDialog.setOnKeyListener(new DialogOnKeyListener(context));

    cb_enable_scheduler.setChecked(envParms.settingEnableScheduler);
    cb_enable_scheduler.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        private boolean ignoreEvent = false;

        @Override
        public void onCheckedChanged(CompoundButton arg0, final boolean isChecked) {
            if (ignoreEvent) {
                ignoreEvent = false;
                return;
            }
            NotifyEvent ntfy = new NotifyEvent(null);
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    envParms.setSettingEnableScheduler(context, isChecked);
                    try {
                        svcServer.aidlCancelAllActiveTask();
                        svcServer.aidlResetScheduler();
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                    setSchedulerStatus();
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                    ignoreEvent = true;
                    cb_enable_scheduler.setChecked(!isChecked);
                }
            });
            String msg = "";
            if (!isChecked)
                msg = context.getString(R.string.msgs_status_dialog_enable_scheduler_confirm_msg_disable);
            else
                msg = context.getString(R.string.msgs_status_dialog_enable_scheduler_confirm_msg_enable);
            CommonDialog cd = new CommonDialog(context, getSupportFragmentManager());
            cd.showCommonDialog(true, "W", "", msg, ntfy);
        }
    });

    btnStatus.setBackgroundResource(R.drawable.button_back_ground_color_selector);
    btnHistory.setBackgroundResource(R.drawable.button_back_ground_color_selector);

    if (action.equals("History")) {
        statusListView.setVisibility(ListView.GONE);
        historyListView.setVisibility(ListView.VISIBLE);
        btnStatus.setTextColor(Color.DKGRAY);
        btnHistory.setTextColor(Color.GREEN);
        btnHistory.setClickable(false);
    } else {
        statusListView.setVisibility(ListView.VISIBLE);
        historyListView.setVisibility(ListView.GONE);
        btnStatus.setTextColor(Color.GREEN);
        btnHistory.setTextColor(Color.DKGRAY);
        btnStatus.setClickable(false);
    }

    btnStatus.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            statusListView.setVisibility(ListView.VISIBLE);
            historyListView.setVisibility(ListView.GONE);
            btnStatus.setTextColor(Color.GREEN);
            btnHistory.setTextColor(Color.DKGRAY);
            btnStatus.setClickable(false);
            btnHistory.setClickable(true);
            setSchedulerStatus();
        }
    });

    btnHistory.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            statusListView.setVisibility(ListView.GONE);
            historyListView.setVisibility(ListView.VISIBLE);
            btnStatus.setTextColor(Color.DKGRAY);
            btnHistory.setTextColor(Color.GREEN);
            btnStatus.setClickable(true);
            btnHistory.setClickable(false);
            setSchedulerStatus();
        }
    });

    if (util.isLogFileExists())
        btnLog.setEnabled(true);
    else
        btnLog.setEnabled(false);
    btnLog.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            util.resetLogReceiver();
            Intent intent = new Intent();
            intent = new Intent(android.content.Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + util.getLogFilePath()), "text/plain");
            startActivity(intent);
            setSchedulerStatus();
        }
    });

    // Close?
    btnClose.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mainDialog.dismiss();
            //            commonDlg.setFixedOrientation(false);
        }
    });
    mainDialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface arg0) {
            finish();
        }
    });
    // Cancel?
    mainDialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnClose.performClick();
        }
    });
    //      commonDlg.setFixedOrientation(true);
    mainDialog.setCancelable(true);
    mainDialog.show();

}

From source file:com.birdeye.MainActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!Prefs.usernames.isSet()) {
        Prefs.usernames.set(Twitter.getSessionManager().getActiveSession().getUserName());
    }/*from   ww w.  jav a 2  s.co  m*/

    setContentView(R.layout.main);
    ButterKnife.bind(this);

    // hideSystemUI(this);
    Chartboost.startWithAppId(MainActivity.this, "57552756f6cd4526e365b9d1",
            "239b2e3aa657ccdcdf0b9674c8750f077b5e0aed");
    Chartboost.setLoggingLevel(CBLogging.Level.ALL);
    Chartboost.setDelegate(delegate);
    Chartboost.onCreate(this);

    tv_cancel = (TextView) findViewById(R.id.tv_cancel);
    tvSetTimer = (Button) findViewById(R.id.tvSetTimer);

    if (!BillingProcessor.isIabServiceAvailable(MainActivity.this)) {
        // showToast("In-app billing service is unavailable, please upgrade Android Market/Play to version >= 3.9.16");
        onBackPressed();
    }

    bp = new BillingProcessor(this, LICENSE_KEY, MERCHANT_ID, new BillingProcessor.IBillingHandler() {
        @Override
        public void onProductPurchased(String productId, TransactionDetails details) {
            showToast("onProductPurchased: " + productId);
            // updateTextViews();
        }

        @Override
        public void onBillingError(int errorCode, Throwable error) {
            showToast("onBillingError: " + Integer.toString(errorCode));
        }

        @Override
        public void onBillingInitialized() {
            showToast("onBillingInitialized");
            readyToPurchase = true;
            //updateTextViews();
        }

        @Override
        public void onPurchaseHistoryRestored() {
            showToast("onPurchaseHistoryRestored");
            for (String sku : bp.listOwnedProducts())
                Log.d(LOG_TAG, "Owned Managed Product: " + sku);
            for (String sku : bp.listOwnedSubscriptions())
                Log.d(LOG_TAG, "Owned Subscription: " + sku);
            //updateTextViews();
            Log.i(LOG_TAG, String.format("%s is%s subscribed", SUBSCRIPTION_ID,
                    bp.isSubscribed(SUBSCRIPTION_ID) ? "" : " not"));
        }
    });

    subs = bp.getSubscriptionListingDetails(SUBSCRIPTION_ID);
    // showToast(subs != null ? subs.toString() : "Failed to load subscription details");

    if (subs == null) {
        //  showToast(subs != null ? subs.toString() : "Failed to load subscription details");
        Globals.hasPaid = false;
    } else {
        Globals.hasPaid = true;
    }

    if (Globals.hasPaid) {
        tvSetTimer.setVisibility(View.VISIBLE);

        message4.setVisibility(View.VISIBLE);
        message5.setVisibility(View.VISIBLE);
        message6.setVisibility(View.VISIBLE);
        message7.setVisibility(View.VISIBLE);
        message8.setVisibility(View.VISIBLE);
        message9.setVisibility(View.VISIBLE);
        message10.setVisibility(View.VISIBLE);
        message11.setVisibility(View.VISIBLE);
        message12.setVisibility(View.VISIBLE);
        message13.setVisibility(View.VISIBLE);
        message14.setVisibility(View.VISIBLE);
        message15.setVisibility(View.VISIBLE);
        message16.setVisibility(View.VISIBLE);
        message17.setVisibility(View.VISIBLE);
        message18.setVisibility(View.VISIBLE);
        message19.setVisibility(View.VISIBLE);
        message20.setVisibility(View.VISIBLE);
        message21.setVisibility(View.VISIBLE);
        message22.setVisibility(View.VISIBLE);
        message23.setVisibility(View.VISIBLE);
        message24.setVisibility(View.VISIBLE);
        message25.setVisibility(View.VISIBLE);

        ets = Arrays.asList(usernames, hashtags, message1, message2, message3, message4, message5, message6,
                message7, message8, message9, message10, message11, message12, message13, message14, message15,
                message16, message17, message18, message19, message20, message21, message22, message23,
                message24, message25);

    } else {
        tvSetTimer.setVisibility(View.GONE);
        message4.setVisibility(View.GONE);
        message5.setVisibility(View.GONE);
        message6.setVisibility(View.GONE);
        message7.setVisibility(View.GONE);
        message8.setVisibility(View.GONE);
        message9.setVisibility(View.GONE);
        message10.setVisibility(View.GONE);
        message11.setVisibility(View.GONE);
        message12.setVisibility(View.GONE);
        message13.setVisibility(View.GONE);
        message14.setVisibility(View.GONE);
        message15.setVisibility(View.GONE);
        message16.setVisibility(View.GONE);
        message17.setVisibility(View.GONE);
        message18.setVisibility(View.GONE);
        message19.setVisibility(View.GONE);
        message20.setVisibility(View.GONE);
        message21.setVisibility(View.GONE);
        message22.setVisibility(View.GONE);
        message23.setVisibility(View.GONE);
        message24.setVisibility(View.GONE);
        message25.setVisibility(View.GONE);
        ets = Arrays.asList(usernames, hashtags, message1, message2, message3);
    }

    tvSetTimer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            dialog.setContentView(R.layout.input_time);
            dialog.setCancelable(true);

            Button bt_set = (Button) dialog.findViewById(R.id.bt_set);
            final EditText et_time = (EditText) dialog.findViewById(R.id.et_time);

            bt_set.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (et_time.getText().toString().equalsIgnoreCase("")) {
                        Toast.makeText(MainActivity.this, "Please enter time to auto shut down",
                                Toast.LENGTH_SHORT).show();
                    }

                    else {

                        int valueTimer = Integer.parseInt(et_time.getText().toString()) * 1000;

                        initateCounter(valueTimer);
                        tv_cancel.setText("Auto ShutDown started");
                        tvSetTimer.setVisibility(View.GONE);
                        tv_cancel.setVisibility(View.VISIBLE);
                        dialog.dismiss();
                    }

                }
            });

            dialog.show();

        }
    });

    cameras.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Facing.values()));
    //noinspection ConstantConditions
    cameras.setSelection(Prefs.facing.get().ordinal());
    cameras.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Prefs.facing.set(Facing.values()[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    for (TextInputEditText et : ets) {
        DrawableCompat.setTint(et.getBackground(), ContextCompat.getColor(this, R.color.colorAccent));
        final TextInputLayout til = textLayout(et);
        til.setError(null);
        til.setErrorEnabled(false);
    }

    TextViews.setText(usernames, Prefs.usernames.get());
    TextViews.setText(hashtags, Prefs.hashtags.get());
    TextViews.setText(message1, Prefs.message1.get());
    TextViews.setText(message2, Prefs.message2.get());
    TextViews.setText(message3, Prefs.message3.get());

    TextViews.setText(message4, Prefs.message4.get());
    TextViews.setText(message5, Prefs.message5.get());
    TextViews.setText(message6, Prefs.message6.get());
    TextViews.setText(message7, Prefs.message7.get());
    TextViews.setText(message8, Prefs.message8.get());
    TextViews.setText(message9, Prefs.message9.get());
    TextViews.setText(message10, Prefs.message10.get());
    TextViews.setText(message11, Prefs.message11.get());
    TextViews.setText(message12, Prefs.message12.get());
    TextViews.setText(message13, Prefs.message13.get());
    TextViews.setText(message14, Prefs.message14.get());
    TextViews.setText(message15, Prefs.message15.get());
    TextViews.setText(message16, Prefs.message16.get());
    TextViews.setText(message17, Prefs.message17.get());
    TextViews.setText(message18, Prefs.message18.get());
    TextViews.setText(message19, Prefs.message19.get());
    TextViews.setText(message20, Prefs.message20.get());
    TextViews.setText(message21, Prefs.message21.get());
    TextViews.setText(message22, Prefs.message22.get());
    TextViews.setText(message23, Prefs.message23.get());
    TextViews.setText(message24, Prefs.message24.get());
    TextViews.setText(message25, Prefs.message25.get());

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    getWindow().setBackgroundDrawableResource(R.color.bg);

    mAdView = (AdView) findViewById(R.id.adView);
    mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));

    adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            // Check the LogCat to get your test device ID
            .addTestDevice("EB02375D2DA62FFA0F6F145AD2302B3D").build();

    // adRequest = new AdRequest.Builder().build();

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
        }

        @Override
        public void onAdClosed() {
            //   Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            //  Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdLeftApplication() {
            //  Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }
    });

    mAdView.loadAd(adRequest);
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }

        @Override
        public void onAdClosed() {
            Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdLeftApplication() {
            Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdOpened() {
            Toast.makeText(getApplicationContext(), "Ad is opened!", Toast.LENGTH_SHORT).show();
        }
    });

    if (Globals.hasPaid) {
        tv_cancel.setVisibility(View.GONE);
        mAdView.setVisibility(View.GONE);
    } else {

        // initateCounter(120000);
        startRepeatingTask();
        mAdView.setVisibility(View.VISIBLE);
    }

}