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.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void addRemoteProfile(final String prof_act, final String prof_name, final String prof_user,
        final String prof_pass, final String prof_addr, final String prof_port, final String prof_share,
        final String msg_text) {

    // ??/*  ww w  .j  a v  a  2 s  .c  o  m*/
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);
    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Add remote profile");

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    final Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            btnGet1.setEnabled(false);
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_act, new_name;
            editaddr.selectAll();
            edituser.selectAll();
            editpass.selectAll();
            editshare.selectAll();
            editname.selectAll();
            new_name = editname.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "A";

            if (isProfileDuplicated("R", new_name)) {
                dlg_msg.setText(getString(R.string.msgs_add_remote_profile_duplicate));
            } else {
                dialog.dismiss();
                //               setFixedOrientation(false);
                int pos = profileListView.getFirstVisiblePosition();
                int topPos = 0;
                if (profileListView.getChildAt(0) != null)
                    profileListView.getChildAt(0).getTop();
                String prof_user = edituser.getText().toString();
                String prof_pass = editpass.getText().toString();
                String prof_addr = editaddr.getText().toString();
                String prof_share = editshare.getText().toString();
                String prof_port = editport.getText().toString();
                profileAdapter.add(new ProfileListItem("R", new_name, new_act, prof_user, prof_pass, prof_addr,
                        prof_port, prof_share, false));
                saveProfile(false, "", "");
                profileAdapter = createProfileList(false, ""); // create profile list

                profileListView.setSelectionFromTop(pos, topPos);
                profileAdapter.setNotifyOnChange(true);

                setRemoteDirBtnListener();
            }
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

/**
 *  ?  ? ?/*  w w w  .j a v  a 2 s.  com*/
 * @param itemPosition ? ? (?)   listView
 * @param isTablet true, ?   (??   ? ??)
 * @param coordinates   ??
 */
private void showPostPopupDialog(final int itemPosition, final boolean isTablet, final Point coordinates,
        final String refererPost) {
    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);
    final int measuredWidth = isTablet ? adapter.measureViewWidth(itemPosition) : -1; //? ??  ? 
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    final Rect activityWindowRect;
    final int dlgWindowWidth;
    final int dlgWindowHeight;
    if (isTablet) {
        activityWindowRect = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(activityWindowRect);
        dlgWindowWidth = Math.max(coordinates.x, activityWindowRect.width() - coordinates.x);
        dlgWindowHeight = Math.max(coordinates.y, activityWindowRect.height() - coordinates.y);
        tmpDlg.getWindow().setLayout(dlgWindowWidth, dlgWindowHeight);
    } else {
        activityWindowRect = null;
        dlgWindowWidth = -1;
        dlgWindowHeight = -1;
    }
    tmpDlg.show();

    Runnable next = new Runnable() {
        @SuppressLint("RtlHardcoded")
        @Override
        public void run() {
            int dlgWidth = tmpV.getWidth();
            int dlgHeight = tmpV.getHeight();
            tmpDlg.hide();
            tmpDlg.cancel();
            int newWidth = isTablet ? Math.min(measuredWidth, dlgWidth) : dlgWidth;

            View view = adapter.getView(itemPosition, null, null, newWidth, refererPost);
            view.setBackgroundColor(bgColor);
            //Logger.d(TAG, "measured: "+view.findViewById(R.id.post_frame_main).getMeasuredWidth()+
            //        "x"+view.findViewById(R.id.post_frame_main).getMeasuredHeight());

            Dialog dialog = new Dialog(activity);
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(view);
            if (isTablet) {
                view.findViewById(R.id.post_frame_main).measure(
                        MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
                int newWindowWidth = dlgWindowWidth - dlgWidth + newWidth;
                int newWindowHeight = dlgWindowHeight - dlgHeight
                        + Math.min(view.findViewById(R.id.post_frame_main).getMeasuredHeight(), dlgHeight);
                dialog.getWindow().setLayout(newWindowWidth, newWindowHeight);
                WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                if (coordinates.x > activityWindowRect.width() - coordinates.x
                        && coordinates.x + newWindowWidth > activityWindowRect.width()) {
                    params.x = activityWindowRect.width() - coordinates.x;
                    params.gravity = Gravity.RIGHT;
                } else {
                    params.x = coordinates.x;
                    params.gravity = Gravity.LEFT;
                }
                if (coordinates.y > activityWindowRect.height() - coordinates.y
                        && coordinates.y + newWindowHeight > activityWindowRect.height()) {
                    params.y = activityWindowRect.height() - coordinates.y;
                    params.gravity |= Gravity.BOTTOM;
                } else {
                    params.y = coordinates.y;
                    params.gravity |= Gravity.TOP;
                }
                dialog.getWindow().setAttributes(params);

                //     
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    CompatibilityImpl.setDimAmount(dialog.getWindow(), 0.1f);
                } else {
                    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                }
            }
            dialog.show();
            dialogs.add(dialog);
        }
    };

    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void showThreadPreviewDialog(final int position) {
    final List<PresentationItemModel> items = new ArrayList<>();
    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);/*  ww w  .  j a  v  a  2s. co m*/
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    tmpDlg.show();
    Runnable next = new Runnable() {
        @Override
        public void run() {
            final int dlgWidth = tmpV.getWidth();
            tmpDlg.hide();
            tmpDlg.cancel();
            final Dialog dialog = new Dialog(activity);

            if (presentationModel.source != null && presentationModel.source.threads != null
                    && presentationModel.source.threads.length > position
                    && presentationModel.source.threads[position].posts != null
                    && presentationModel.source.threads[position].posts.length > 0) {

                final String threadNumber = presentationModel.source.threads[position].posts[0].number;

                ClickableURLSpan.URLSpanClickListener spanClickListener = new ClickableURLSpan.URLSpanClickListener() {
                    @Override
                    public void onClick(View v, ClickableURLSpan span, String url, String referer) {
                        if (url.startsWith("#")) {
                            try {
                                UrlPageModel threadPageModel = new UrlPageModel();
                                threadPageModel.chanName = chan.getChanName();
                                threadPageModel.type = UrlPageModel.TYPE_THREADPAGE;
                                threadPageModel.boardName = tabModel.pageModel.boardName;
                                threadPageModel.threadNumber = threadNumber;
                                url = chan.buildUrl(threadPageModel) + url;
                                dialog.dismiss();
                                UrlHandler.open(chan.fixRelativeUrl(url), activity);
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        } else {
                            dialog.dismiss();
                            UrlHandler.open(chan.fixRelativeUrl(url), activity);
                        }
                    }
                };

                AndroidDateFormat.initPattern();
                String datePattern = AndroidDateFormat.getPattern();
                DateFormat dateFormat = datePattern == null
                        ? DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                        : new SimpleDateFormat(datePattern, Locale.US);
                dateFormat.setTimeZone(settings.isLocalTime() ? TimeZone.getDefault()
                        : TimeZone.getTimeZone(presentationModel.source.boardModel.timeZoneId));

                int postsCount = presentationModel.source.threads[position].postsCount;
                boolean showIndex = presentationModel.source.threads[position].posts.length <= postsCount;
                int curPostIndex = postsCount - presentationModel.source.threads[position].posts.length + 1;

                boolean openSpoilers = settings.openSpoilers();

                for (int i = 0; i < presentationModel.source.threads[position].posts.length; ++i) {
                    PresentationItemModel model = new PresentationItemModel(
                            presentationModel.source.threads[position].posts[i], chan.getChanName(),
                            presentationModel.source.pageModel.boardName,
                            presentationModel.source.pageModel.threadNumber, dateFormat, spanClickListener,
                            imageGetter, ThemeUtils.ThemeColors.getInstance(activity.getTheme()), openSpoilers,
                            floatingModels, null);
                    model.buildSpannedHeader(showIndex ? (i == 0 ? 1 : ++curPostIndex) : -1,
                            presentationModel.source.boardModel.bumpLimit,
                            presentationModel.source.boardModel.defaultUserName, null, false);
                    items.add(model);
                }
            } else {
                items.add(presentationModel.presentationList.get(position));
            }
            ListView dlgList = new ListView(activity);
            dlgList.setAdapter(new ArrayAdapter<PresentationItemModel>(activity, 0, items) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View view = adapter.getView(position, convertView, parent, dlgWidth, getItem(position));
                    view.setBackgroundColor(bgColor);
                    return view;
                }
            });
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(dlgList);
            dialog.show();
            dialogs.add(dialog);
        }
    };
    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void editRemoteProfile(String prof_act, String prof_name, String prof_user, String prof_pass,
        String prof_addr, final String prof_port, String prof_share, String msg_text, final int item_num) {

    // ??//w w w .j a v a  2 s .c om
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);

    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Edit remote profile");

    CommonDialog.setDlgBoxSizeLimit(dialog, false);

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    if (arg1 != null)
                        dlg_msg.setText((String) arg1[0]);
                    else
                        dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_user, new_pass, new_addr, new_share, new_act, new_name;

            dialog.dismiss();
            //            setFixedOrientation(false);

            new_addr = editaddr.getText().toString();
            new_user = edituser.getText().toString();
            new_pass = editpass.getText().toString();
            new_share = editshare.getText().toString();
            new_name = editname.getText().toString();
            String new_port = editport.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "I";

            int pos = profileListView.getFirstVisiblePosition();
            int topPos = 0;
            if (profileListView.getChildAt(0) != null)
                profileListView.getChildAt(0).getTop();
            ProfileListItem item = profileAdapter.getItem(item_num);

            profileAdapter.remove(item);
            profileAdapter.insert(new ProfileListItem("R", new_name, new_act, new_user, new_pass, new_addr,
                    new_port, new_share, false), item_num);

            saveProfile(false, "", "");
            //            appendProfile();
            //            profileAdapter = 
            //                  createProfileList(false); // create profile list
            profileListView.setSelectionFromTop(pos, topPos);
            profileAdapter.setNotifyOnChange(true);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();

}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void openReferencesList(final String from) {
    final List<Integer> positions = new ArrayList<>();
    int position = -1;
    for (int i = 0; i < presentationModel.presentationList.size(); ++i) {
        if (presentationModel.presentationList.get(i).sourceModel.number.equals(from)) {
            position = i;// w  ww . j  a va2  s  .  c  om
            break;
        }
    }
    if (position != -1) {
        Spanned referencesString = presentationModel.presentationList.get(position).referencesString;
        if (referencesString == null) {
            Logger.e(TAG, "null referencesString");
            return;
        }
        ClickableURLSpan[] spans = referencesString.getSpans(0, referencesString.length(),
                ClickableURLSpan.class);
        for (ClickableURLSpan span : spans) {
            String url = span.getURL();
            try {
                //url    , .. ???  PresentationItemModel ( )
                UrlPageModel model = UrlHandler.getPageModel(url);
                for (; position < presentationModel.presentationList.size(); ++position) {
                    if (presentationModel.presentationList.get(position).sourceModel.number
                            .equals(model.postNumber)) {
                        break;
                    }
                }
                if (position < presentationModel.presentationList.size())
                    positions.add(position);
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }
    }

    if (positions.size() == 0) {
        Logger.e(TAG, "no references");
        return;
    }

    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    tmpDlg.show();
    Runnable next = new Runnable() {
        @Override
        public void run() {
            final int dlgWidth = tmpV.getWidth();
            tmpDlg.hide();
            tmpDlg.cancel();

            ListView dlgList = new ListView(activity);
            dlgList.setAdapter(new ArrayAdapter<Integer>(activity, 0, positions) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    try {
                        int adapterPositon = getItem(position);
                        View view = adapter.getView(adapterPositon, convertView, parent, dlgWidth,
                                adapter.getItem(adapterPositon), from);
                        view.setBackgroundColor(bgColor);
                        return view;
                    } catch (Exception e) {
                        Logger.e(TAG, e);
                        Toast.makeText(activity, R.string.error_unknown, Toast.LENGTH_LONG).show();
                        return new View(activity);
                    }
                }
            });

            Dialog dialog = new Dialog(activity);
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(dlgList);
            dialog.show();
            dialogs.add(dialog);
        }
    };
    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

public void scanRemoteNetworkDlg(final NotifyEvent p_ntfy, String port_number) {
    //??//ww w.  ja  va  2  s .c o m
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.scan_remote_ntwk_dlg);
    final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel);
    final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_msg);
    final TextView tv_result = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_title);
    tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_press_scan_btn));
    tv_result.setVisibility(TextView.GONE);

    final String from = getLocalIpAddress();
    String subnet = from.substring(0, from.lastIndexOf("."));
    String subnet_o1, subnet_o2, subnet_o3;
    subnet_o1 = subnet.substring(0, subnet.indexOf("."));
    subnet_o2 = subnet.substring(subnet.indexOf(".") + 1, subnet.lastIndexOf("."));
    subnet_o3 = subnet.substring(subnet.lastIndexOf(".") + 1, subnet.length());
    final EditText baEt1 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o1);
    final EditText baEt2 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o2);
    final EditText baEt3 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o3);
    final EditText baEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o4);
    final EditText eaEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_end_address_o4);
    baEt1.setText(subnet_o1);
    baEt2.setText(subnet_o2);
    baEt3.setText(subnet_o3);
    baEt4.setText("1");
    baEt4.setSelection(1);
    eaEt4.setText("254");
    baEt4.requestFocus();

    final CheckBox cb_use_port_number = (CheckBox) dialog.findViewById(R.id.scan_remote_ntwk_use_port);
    final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    if (port_number.equals("")) {
        et_port_number.setEnabled(false);
        cb_use_port_number.setChecked(false);
    } else {
        et_port_number.setEnabled(true);
        et_port_number.setText(port_number);
        cb_use_port_number.setChecked(true);
    }
    cb_use_port_number.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            et_port_number.setEnabled(isChecked);
        }
    });

    final NotifyEvent ntfy_lv_click = new NotifyEvent(mContext);
    ntfy_lv_click.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            dialog.dismiss();
            p_ntfy.notifyToListener(true, o);
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
        }
    });

    final ArrayList<ScanAddressResultListItem> ipAddressList = new ArrayList<ScanAddressResultListItem>();
    //      ScanAddressResultListItem li=new ScanAddressResultListItem();
    //      li.server_name=mContext.getString(R.string.msgs_ip_address_no_address);
    //      ipAddressList.add(li);
    final ListView lv = (ListView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_list);
    final AdapterScanAddressResultList adap = new AdapterScanAddressResultList(mContext,
            R.layout.scan_address_result_list_item, ipAddressList, ntfy_lv_click);
    lv.setAdapter(adap);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);

    //SCAN?
    btn_scan.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ipAddressList.clear();
            NotifyEvent ntfy = new NotifyEvent(mContext);
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    if (ipAddressList.size() < 1) {
                        tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_not_detected));
                        tv_result.setVisibility(TextView.GONE);
                    } else {
                        tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_select_detected_host));
                        tv_result.setVisibility(TextView.VISIBLE);
                    }
                    //                   adap.clear();
                    //                   for (int i=0;i<ipAddressList.size();i++) 
                    //                      adap.add(ipAddressList.get(i));
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }

            });
            if (auditScanAddressRangeValue(dialog)) {
                tv_result.setVisibility(TextView.GONE);
                String ba1 = baEt1.getText().toString();
                String ba2 = baEt2.getText().toString();
                String ba3 = baEt3.getText().toString();
                String ba4 = baEt4.getText().toString();
                String ea4 = eaEt4.getText().toString();
                String subnet = ba1 + "." + ba2 + "." + ba3;
                int begin_addr = Integer.parseInt(ba4);
                int end_addr = Integer.parseInt(ea4);
                scanRemoteNetwork(dialog, lv, adap, ipAddressList, subnet, begin_addr, end_addr, ntfy);
            } else {
                //error
            }
        }
    });

    //CANCEL?
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            p_ntfy.notifyToListener(false, null);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    dialog.show();

}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

@SuppressLint("InlinedApi")
private void openGridGallery() {
    final int tnSize = resources.getDimensionPixelSize(R.dimen.post_thumbnail_size);

    class GridGalleryAdapter extends ArrayAdapter<Triple<AttachmentModel, String, String>>
            implements View.OnClickListener, AbsListView.OnScrollListener {
        private final GridView view;
        private boolean selectingMode = false;
        private boolean[] isSelected = null;
        private volatile boolean isBusy = false;

        public GridGalleryAdapter(GridView view, List<Triple<AttachmentModel, String, String>> list) {
            super(activity, 0, list);
            this.view = view;
            this.isSelected = new boolean[list.size()];
        }/*from w w  w.ja  v a  2  s. c  om*/

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
                if (isBusy)
                    setNonBusy();
                isBusy = false;
            } else
                isBusy = true;
        }

        private void setNonBusy() {
            if (!downloadThumbnails())
                return;
            for (int i = 0; i < view.getChildCount(); ++i) {
                View v = view.getChildAt(i);
                Object tnTag = v.findViewById(R.id.post_thumbnail_image).getTag();
                if (tnTag == null || tnTag == Boolean.FALSE)
                    fill(view.getPositionForView(v), v, false);
            }
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = new FrameLayout(activity);
                convertView.setLayoutParams(new AbsListView.LayoutParams(tnSize, tnSize));
                ImageView tnImage = new ImageView(activity);
                tnImage.setLayoutParams(new FrameLayout.LayoutParams(tnSize, tnSize, Gravity.CENTER));
                tnImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                tnImage.setId(R.id.post_thumbnail_image);
                ((FrameLayout) convertView).addView(tnImage);
            }
            convertView.setTag(getItem(position).getLeft());
            safeRegisterForContextMenu(convertView);
            convertView.setOnClickListener(this);
            fill(position, convertView, isBusy);
            if (isSelected[position]) {
                /*ImageView overlay = new ImageView(activity);
                overlay.setImageResource(android.R.drawable.checkbox_on_background);*/
                FrameLayout overlay = new FrameLayout(activity);
                overlay.setBackgroundColor(Color.argb(128, 0, 255, 0));
                if (((FrameLayout) convertView).getChildCount() < 2)
                    ((FrameLayout) convertView).addView(overlay);

            } else {
                if (((FrameLayout) convertView).getChildCount() > 1)
                    ((FrameLayout) convertView).removeViewAt(1);
            }
            return convertView;
        }

        private void safeRegisterForContextMenu(View view) {
            try {
                view.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                    @Override
                    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
                        if (presentationModel == null) {
                            Fragment currentFragment = MainApplication
                                    .getInstance().tabsSwitcher.currentFragment;
                            if (currentFragment instanceof BoardFragment) {
                                currentFragment.onCreateContextMenu(menu, v, menuInfo);
                            }
                        } else {
                            BoardFragment.this.onCreateContextMenu(menu, v, menuInfo);
                        }
                    }
                });
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }

        @Override
        public void onClick(View v) {
            if (selectingMode) {
                int position = view.getPositionForView(v);
                isSelected[position] = !isSelected[position];
                notifyDataSetChanged();
            } else {
                BoardFragment fragment = BoardFragment.this;
                if (presentationModel == null) {
                    Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment;
                    if (currentFragment instanceof BoardFragment)
                        fragment = (BoardFragment) currentFragment;
                }
                fragment.openAttachment((AttachmentModel) v.getTag());
            }
        }

        private void fill(int position, View view, boolean isBusy) {
            AttachmentModel attachment = getItem(position).getLeft();
            String attachmentHash = getItem(position).getMiddle();
            ImageView tnImage = (ImageView) view.findViewById(R.id.post_thumbnail_image);
            if (attachment.thumbnail == null || attachment.thumbnail.length() == 0) {
                tnImage.setTag(Boolean.TRUE);
                tnImage.setImageResource(Attachments.getDefaultThumbnailResId(attachment.type));
                return;
            }
            tnImage.setTag(Boolean.FALSE);
            CancellableTask imagesDownloadTask = BoardFragment.this.imagesDownloadTask;
            ExecutorService imagesDownloadExecutor = BoardFragment.this.imagesDownloadExecutor;
            if (presentationModel == null) {
                Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment;
                if (currentFragment instanceof BoardFragment) {
                    imagesDownloadTask = ((BoardFragment) currentFragment).imagesDownloadTask;
                    imagesDownloadExecutor = ((BoardFragment) currentFragment).imagesDownloadExecutor;
                }
            }
            bitmapCache.asyncGet(attachmentHash, attachment.thumbnail, tnSize, chan, localFile,
                    imagesDownloadTask, tnImage, imagesDownloadExecutor, Async.UI_HANDLER,
                    downloadThumbnails() && !isBusy,
                    downloadThumbnails() ? (isBusy ? 0 : R.drawable.thumbnail_error)
                            : Attachments.getDefaultThumbnailResId(attachment.type));
        }

        public void setSelectingMode(boolean selectingMode) {
            this.selectingMode = selectingMode;
            if (!selectingMode) {
                Arrays.fill(isSelected, false);
                notifyDataSetChanged();
            }
        }

        public void selectAll() {
            if (selectingMode) {
                Arrays.fill(isSelected, true);
                notifyDataSetChanged();
            }
        }

        public void downloadSelected(final Runnable onFinish) {
            final Dialog progressDialog = ProgressDialog.show(activity,
                    resources.getString(R.string.grid_gallery_dlg_title),
                    resources.getString(R.string.grid_gallery_dlg_message), true, false);
            Async.runAsync(new Runnable() {
                @Override
                public void run() {
                    BoardFragment fragment = BoardFragment.this;
                    if (fragment.presentationModel == null) {
                        Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment;
                        if (currentFragment instanceof BoardFragment)
                            fragment = (BoardFragment) currentFragment;
                    }
                    boolean flag = false;
                    for (int i = 0; i < isSelected.length; ++i)
                        if (isSelected[i])
                            if (!fragment.downloadFile(getItem(i).getLeft(), true))
                                flag = true;
                    final boolean toast = flag;
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (toast)
                                Toast.makeText(activity, R.string.notification_download_exists_or_in_queue,
                                        Toast.LENGTH_LONG).show();
                            progressDialog.dismiss();
                            onFinish.run();
                        }
                    });
                }
            });
        }
    }

    try {
        List<Triple<AttachmentModel, String, String>> list = presentationModel.getAttachments();
        if (list == null) {
            Toast.makeText(activity, R.string.notifacation_updating_now, Toast.LENGTH_LONG).show();
            return;
        }

        GridView grid = new GridView(activity);
        final GridGalleryAdapter gridAdapter = new GridGalleryAdapter(grid, list);
        grid.setNumColumns(GridView.AUTO_FIT);
        grid.setColumnWidth(tnSize);
        int spacing = (int) (resources.getDisplayMetrics().density * 5 + 0.5f);
        grid.setVerticalSpacing(spacing);
        grid.setHorizontalSpacing(spacing);
        grid.setPadding(spacing, spacing, spacing, spacing);
        grid.setAdapter(gridAdapter);
        grid.setOnScrollListener(gridAdapter);
        grid.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));

        final Button btnToSelecting = new Button(activity);
        btnToSelecting.setText(R.string.grid_gallery_select);
        CompatibilityUtils.setTextAppearance(btnToSelecting, android.R.style.TextAppearance_Small);
        btnToSelecting.setSingleLine();
        btnToSelecting.setVisibility(View.VISIBLE);
        btnToSelecting.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        final LinearLayout layoutSelectingButtons = new LinearLayout(activity);
        layoutSelectingButtons.setOrientation(LinearLayout.HORIZONTAL);
        layoutSelectingButtons.setWeightSum(10f);
        Button btnDownload = new Button(activity);
        btnDownload.setLayoutParams(
                new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.25f));
        btnDownload.setText(R.string.grid_gallery_download);
        CompatibilityUtils.setTextAppearance(btnDownload, android.R.style.TextAppearance_Small);
        btnDownload.setSingleLine();
        Button btnSelectAll = new Button(activity);
        btnSelectAll.setLayoutParams(
                new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.75f));
        btnSelectAll.setText(android.R.string.selectAll);
        CompatibilityUtils.setTextAppearance(btnSelectAll, android.R.style.TextAppearance_Small);
        btnSelectAll.setSingleLine();
        Button btnCancel = new Button(activity);
        btnCancel.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3f));
        btnCancel.setText(android.R.string.cancel);
        CompatibilityUtils.setTextAppearance(btnCancel, android.R.style.TextAppearance_Small);
        btnCancel.setSingleLine();
        layoutSelectingButtons.addView(btnDownload);
        layoutSelectingButtons.addView(btnSelectAll);
        layoutSelectingButtons.addView(btnCancel);
        layoutSelectingButtons.setVisibility(View.GONE);
        layoutSelectingButtons.setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

        btnToSelecting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnToSelecting.setVisibility(View.GONE);
                layoutSelectingButtons.setVisibility(View.VISIBLE);
                gridAdapter.setSelectingMode(true);
            }
        });

        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnToSelecting.setVisibility(View.VISIBLE);
                layoutSelectingButtons.setVisibility(View.GONE);
                gridAdapter.setSelectingMode(false);
            }
        });

        btnSelectAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gridAdapter.selectAll();
            }
        });

        btnDownload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gridAdapter.downloadSelected(new Runnable() {
                    @Override
                    public void run() {
                        btnToSelecting.setVisibility(View.VISIBLE);
                        layoutSelectingButtons.setVisibility(View.GONE);
                        gridAdapter.setSelectingMode(false);
                    }
                });
            }
        });

        LinearLayout dlgLayout = new LinearLayout(activity);
        dlgLayout.setOrientation(LinearLayout.VERTICAL);
        dlgLayout.addView(btnToSelecting);
        dlgLayout.addView(layoutSelectingButtons);
        dlgLayout.addView(grid);

        Dialog gridDialog = new Dialog(activity);
        gridDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        gridDialog.setContentView(dlgLayout);
        gridDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        gridDialog.show();
    } catch (OutOfMemoryError oom) {
        MainApplication.freeMemory();
        Logger.e(TAG, oom);
        Toast.makeText(activity, R.string.error_out_of_memory, Toast.LENGTH_LONG).show();
    }
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

private void showMessageInfo(final Context paramContext, String paramString1, String paramString2) {
      paramContext = new Dialog(paramContext);
      StatFs localStatFs = new StatFs("/system");
      int i = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int j = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      localStatFs = new StatFs("/data");
      int k = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int m = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      paramContext.setCancelable(true);/*from   ww w  .  jav a  2  s .  c o m*/
      paramContext.setTitle(paramString1);
      paramContext.setContentView(2130968617);
      ((TextView) paramContext.findViewById(2131558571)).setText(paramString2);
      ((TextView) paramContext.findViewById(2131558564))
              .setText("System ROM (/system): " + i + "Mb (" + j + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558565);
      paramString1.setMax(i);
      paramString1.incrementProgressBy(i - j);
      ((TextView) paramContext.findViewById(2131558566))
              .setText("Internal SD (/data): " + k + "Mb (" + m + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558567);
      paramString1.setMax(k);
      paramString1.incrementProgressBy(i - j);
      ((Button) paramContext.findViewById(2131558569)).setOnClickListener(new View.OnClickListener() {
          public void onClick(View paramAnonymousView) {
              paramContext.dismiss();
          }
      });
      Utils.showDialog(paramContext);
  }

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

private static void showMessageInfoStatic(Context paramContext, String paramString1, String paramString2) {
      paramContext = new Dialog(paramContext);
      StatFs localStatFs = new StatFs("/system");
      int i = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int j = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      localStatFs = new StatFs("/data");
      int k = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int m = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      paramContext.setCancelable(true);//from ww w  . ja  va  2  s .  c o  m
      paramContext.setTitle(paramString1);
      paramContext.setContentView(2130968617);
      ((TextView) paramContext.findViewById(2131558571)).setText(paramString2);
      ((TextView) paramContext.findViewById(2131558564))
              .setText("System ROM (/system): " + i + "Mb (" + j + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558565);
      paramString1.setMax(i);
      paramString1.incrementProgressBy(i - j);
      ((TextView) paramContext.findViewById(2131558566))
              .setText("Internal SD (/data): " + k + "Mb (" + m + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558567);
      paramString1.setMax(k);
      paramString1.incrementProgressBy(i - j);
      ((Button) paramContext.findViewById(2131558569)).setOnClickListener(new View.OnClickListener() {
          public void onClick(View paramAnonymousView) {
              this.val$dialog.dismiss();
          }
      });
      Utils.showDialog(paramContext);
  }