Example usage for android.app Dialog findViewById

List of usage examples for android.app Dialog findViewById

Introduction

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

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

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

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

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

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

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

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

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

                startRecording();

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

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

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

                stopRecording();
                mBottomSheetDialog.hide();

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

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

            }

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

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

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

From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java

private void createMapLayerSelectionDialog() {
    if (layersAndVisibility == null) {
        getLayersAndVisibility();// w  w w  .j  a v a  2  s . c om
    }

    final Dialog dialog = dialogInterface.getDialog(getActivity(), R.layout.dialog_select_map_layers,
            R.string.choose_map_layers);
    Button okButton = (Button) dialog.findViewById(R.id.select_map_layers_update_map_button);
    final List<CheckBoxRow> rows = new ArrayList<>();
    final LinearLayout mapLayerLayout = (LinearLayout) dialog.findViewById(R.id.map_layers_checkbox_layout);
    final Button cancelButton = (Button) dialog.findViewById(R.id.select_map_layers_cancel_button);
    LayerAndVisibility[] layers = new Gson().fromJson(layersAndVisibility.toString(),
            LayerAndVisibility[].class);
    for (LayerAndVisibility layer : layers) {
        if (layer.name.equals("Grunnkart") || layer.name.contains("OpenLayers_Control")) {
            continue;
        }
        boolean isActive;
        isActive = layer.isVisible;

        CheckBoxRow row = rowsInterface.getCheckBoxRow(getActivity(), layer.name, false, isActive);
        rows.add(row);
        View mapLayerRow = row.getView();
        mapLayerLayout.addView(mapLayerRow);
    }

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            List<String> layersList = new ArrayList<>();
            layersList.add("Grunnkart");

            for (int i = 0; i < mapLayerLayout.getChildCount(); i++) {
                if (rows.get(i).isChecked()) {
                    layersList.add(rows.get(i).getText());
                }
            }

            user.setActiveLayers(layersList);
            user.writeToSharedPref(getActivity());
            dialog.dismiss();

            if (layersList.contains(getString(R.string.fishing_facility_name))
                    && !user.getIsFishingFacilityAuthenticated()) {
                dialogInterface.getHyperlinkAlertDialog(getActivity(),
                        getString(R.string.about_fishing_facility_title),
                        getString(R.string.about_fishing_facility_details)).show();
            }

            JSONArray json = new JSONArray(layersList);
            browser.loadUrl("javascript:toggleLayers(" + json + ")");

            getLayersAndVisibility();
        }
    });

    cancelButton.setOnClickListener(onClickListenerInterface.getDismissDialogListener(dialog));

    dialog.show();
}

From source file:fr.cph.chicago.activity.MainActivity.java

private void displayUpdatePanel() {
    try {//  w  w  w.  j a  v a  2  s.  c  o m
        String versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        String versionNamePreferences = sharedPref.getString("version.name", null);
        if (versionNamePreferences == null || !versionNamePreferences.equals(versionName)) {
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("version.name", versionName);
            editor.commit();

            final Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.update);
            dialog.setTitle("Update");

            InputStreamReader is = new InputStreamReader(
                    ChicagoTracker.getAppContext().getAssets().open("update.txt"));
            BufferedReader br = new BufferedReader(is);
            String read = br.readLine();
            StringBuilder sb = new StringBuilder();
            while (read != null) {
                sb.append(read + "\n");
                read = br.readLine();
            }

            TextView text = (TextView) dialog.findViewById(R.id.updateText);
            text.setText(sb.toString());

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            Display display = getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int width = size.x;
            int newWidth = width - (width * 20 / 100);
            int height = size.y;
            int newHeight = height - (height * 20 / 100);

            dialog.getWindow().setLayout(newWidth, newHeight);

            dialog.show();
        }

    } catch (NameNotFoundException e) {
        Log.w(TAG, e.getMessage(), e);
    } catch (IOException e) {
        Log.w(TAG, e.getMessage(), e);
    }
}

From source file:liqui.droid.activity.Base.java

/**
 * Open about dialog.//from   w w w.ja va2s  .c o  m
 */
public void openAboutDialog() {
    Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.dlg_about);

    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        String versionName = packageInfo.versionName;
        dialog.setTitle(getResources().getString(R.string.app_name) + " v" + versionName);
    } catch (PackageManager.NameNotFoundException e) {
        dialog.setTitle(getResources().getString(R.string.app_name));
    }

    Button btnByEmail = (Button) dialog.findViewById(R.id.btn_by_email);
    btnByEmail.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_EMAIL,
                    new String[] { getResources().getString(R.string.my_email) });
            sendIntent.setType("message/rfc822");
            startActivity(Intent.createChooser(sendIntent, "Select email application."));
        }
    });

    dialog.show();
}

From source file:com.hp.map.CustomerMapActivity.java

public void menuDialog() {
    final Dialog dialog = new Dialog(this);
    LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = li.inflate(R.layout.menu_dialog, null, false);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(v);//ww w  .  j a v a 2s  . com

    dialog.setTitle("Danh mc chnh");

    Display display = getWindowManager().getDefaultDisplay();

    dialog.getWindow().setLayout(2 * display.getWidth() / 3, LayoutParams.FILL_PARENT);
    dialog.getWindow().getAttributes().gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;

    lv = (ListView) dialog.findViewById(R.id.menu_list_view);

    lv.setAdapter(
            new DialogArrayAdapter(context, android.R.layout.simple_list_item_1, DetailListData.MENU_LIST));
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            DetailsList selectedValue = (DetailsList) lv.getAdapter().getItem(arg2);
            if (selectedValue.activityClass != null) {
                //if sigout
                if (selectedValue.activityClass == LoginActivity.class) {
                    //LoginActivity.threadLooper.quit();
                }
                startActivity(new Intent(context, selectedValue.activityClass));
            }
        }
    });

    dialog.show();

    //      ImageView iv = (ImageView)dialog.findViewById(R.id.menu_list_view);
    //      iv.setImageResource(1);
}

From source file:edu.berkeley.boinc.PrefsFragment.java

private void setupSelectionListDialog(final PrefsListItemWrapper item, final Dialog dialog)
        throws RemoteException {
    dialog.setContentView(R.layout.prefs_layout_dialog_selection);

    if (item.ID == R.string.prefs_client_log_flags_header) {
        final ArrayList<SelectionDialogOption> options = new ArrayList<SelectionDialogOption>();
        String[] array = getResources().getStringArray(R.array.prefs_client_log_flags);
        for (String option : array)
            options.add(new SelectionDialogOption(option));
        ListView lv = (ListView) dialog.findViewById(R.id.selection);
        new PrefsSelectionDialogListAdapter(getActivity(), lv, R.id.selection, options);

        // setup confirm button action
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override//from   ww  w  . j av a 2 s  .  com
            public void onClick(View v) {
                ArrayList<String> selectedOptions = new ArrayList<String>();
                for (SelectionDialogOption option : options)
                    if (option.selected)
                        selectedOptions.add(option.name);
                if (Logging.DEBUG)
                    Log.d(Logging.TAG, selectedOptions.size() + " log flags selected");
                new SetCcConfigAsync().execute(formatOptionsToCcConfig(selectedOptions));
                dialog.dismiss();
            }
        });
    } else if (item.ID == R.string.prefs_power_source_header) {
        final ArrayList<SelectionDialogOption> options = new ArrayList<SelectionDialogOption>();
        options.add(new SelectionDialogOption(R.string.prefs_power_source_ac,
                BOINCActivity.monitor.getPowerSourceAc()));
        options.add(new SelectionDialogOption(R.string.prefs_power_source_usb,
                BOINCActivity.monitor.getPowerSourceUsb()));
        options.add(new SelectionDialogOption(R.string.prefs_power_source_wireless,
                BOINCActivity.monitor.getPowerSourceWireless()));
        options.add(new SelectionDialogOption(R.string.prefs_power_source_battery, clientPrefs.run_on_batteries,
                true));
        ListView lv = (ListView) dialog.findViewById(R.id.selection);
        new PrefsSelectionDialogListAdapter(getActivity(), lv, R.id.selection, options);

        // setup confirm button action
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    for (SelectionDialogOption option : options) {
                        switch (option.ID) {
                        case R.string.prefs_power_source_ac:
                            BOINCActivity.monitor.setPowerSourceAc(option.selected);
                            break;
                        case R.string.prefs_power_source_usb:
                            BOINCActivity.monitor.setPowerSourceUsb(option.selected);
                            break;
                        case R.string.prefs_power_source_wireless:
                            BOINCActivity.monitor.setPowerSourceWireless(option.selected);
                            break;
                        case R.string.prefs_power_source_battery:
                            clientPrefs.run_on_batteries = option.selected;
                            new WriteClientPrefsAsync().execute(clientPrefs); //async task triggers layout update
                            break;
                        }
                        ;
                    }
                    dialog.dismiss();
                } catch (RemoteException e) {
                }
            }
        });
    }

    // generic cancel button
    Button cancel = (Button) dialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}

From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java

private void notifyUserOfProximityAlert() {
    Handler mainHandler = new Handler(getActivity().getMainLooper());

    Runnable myRunnable = new Runnable() {
        @Override//w  w w.jav  a  2s  . c  o m
        public void run() {
            final Dialog dialog = dialogInterface.getDialog(getActivity(),
                    R.layout.dialog_proximity_alert_warning, R.string.proximity_alert_warning);

            Button okButton = (Button) dialog.findViewById(R.id.proximity_alert_warning_ok_button);
            Button showOnMapButton = (Button) dialog
                    .findViewById(R.id.proximity_alert_warning_show_on_map_button);
            Button dismissAlertButton = (Button) dialog
                    .findViewById(R.id.proximity_alert_warning_dismiss_button);

            long[] pattern = { 0, 500, 200, 200, 300, 200, 200 };

            vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
            vibrator.vibrate(pattern, 0);

            mediaPlayer = MediaPlayer.create(getActivity(), R.raw.proximity_warning_sound);

            if (mediaPlayer == null) {
                return;
            }

            mediaPlayer.setLooping(true);
            mediaPlayer.start();

            okButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alarmFiring = false;
                    vibrator.cancel();
                    vibrator = null;
                    proximityAlertWatcher.cancel(true);
                    proximityAlertWatcher = null;
                    mediaPlayer.stop();
                    mediaPlayer.release();

                    dialog.dismiss();
                    runScheduledAlarm(getResources().getInteger(R.integer.sixty),
                            getResources().getInteger(R.integer.proximity_alert_interval_time_seconds));
                }
            });

            showOnMapButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alarmFiring = false;
                    vibrator.cancel();
                    vibrator = null;
                    proximityAlertWatcher.cancel(true);
                    proximityAlertWatcher = null;
                    mediaPlayer.stop();
                    mediaPlayer.release();

                    browser.loadUrl("javascript:zoomToUserPosition()");

                    dialog.dismiss();
                    runScheduledAlarm(getResources().getInteger(R.integer.sixty),
                            getResources().getInteger(R.integer.proximity_alert_interval_time_seconds));

                }
            });

            dismissAlertButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alarmFiring = false;
                    vibrator.cancel();
                    vibrator = null;
                    proximityAlertWatcher.cancel(true);
                    proximityAlertWatcher = null;
                    mediaPlayer.stop();
                    mediaPlayer.release();

                    dialog.dismiss();
                }
            });

            dialog.show();
        } // This is your code
    };
    mainHandler.post(myRunnable);
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_add_bluetooth_device) {
        addBluetoothDevice();//from   ww w  .j ava  2  s.co  m
        return true;
    }

    if (id == R.id.action_connect) {
        disconnectMenuItem.setEnabled(true);
        connectMenuItem.setEnabled(false);
        addMenuItem.setEnabled(false);
        connectAllShimmerImus();
        connectBioHarness();
    }

    if (id == R.id.action_disconnect) {
        disconnectDevices();
    }

    if (id == R.id.action_settings) {
        showSettings();
    }

    if (id == R.id.action_start_streaming) {
        this.isFirstSelfReportRequest = true;
        startSession();
        //showQuestionnaire(true);
    }

    if (id == R.id.action_stop_streaming) {
        this.isSessionStarted = false;
        this.stopTimestamp = System.currentTimeMillis();
        stopAllStreamingOfAllShimmerImus();
        stopStreamingBioHarness();
        stopStreamingInternalSensorData();

        if (intervalConfigured) {
            stopTimerThread();
        } else {
            feedbackNotification();
            showQuestionnaire();
        }

        this.directoryName = null;
        this.startStreamMenuItem.setEnabled(true);
        this.stopStreamMenuItem.setEnabled(false);
        this.disconnectMenuItem.setEnabled(true);
    }

    if (id == R.id.action_info) {
        Dialog dialog = new Dialog(this);
        dialog.setTitle(getString(R.string.action_info));
        dialog.setContentView(R.layout.info_popup);

        TextView infoSessionStatus = (TextView) dialog.findViewById(R.id.textViewInfoSessionStatus);
        if (isSessionStarted) {
            infoSessionStatus.setText(getString(R.string.info_started));
        }

        if (shimmerImuService != null) {
            int shimmerImuCount = shimmerImuService.shimmerImuMap.values().size();

            TextView infoShimmerImoConnectionStatus = (TextView) dialog
                    .findViewById(R.id.textViewInfoShimmerImoConnectionStatus);
            infoShimmerImoConnectionStatus.setText(getString(R.string.info_number_connected, shimmerImuCount));
        }

        if (bioHarnessService != null) {
            if (bioHarnessService.isBioHarnessConnected()) {
                TextView infoBioHarnessConnectionStatus = (TextView) dialog
                        .findViewById(R.id.textViewInfoBioHarnessConnectionStatus);
                infoBioHarnessConnectionStatus.setText(getString(R.string.info_number_connected, 1));
            }
        }

        infoGpsConnectionStatus = (TextView) dialog.findViewById(R.id.textViewInfoGpsConnectionStatus);
        if (gpsStatusText == null) {
            gpsStatusText = getString(R.string.info_not_connected);
        }
        infoGpsConnectionStatus.setText(gpsStatusText);

        TextView infoVersionName = (TextView) dialog.findViewById(R.id.textViewInfoVersionName);
        try {
            PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            infoVersionName.setText(packageInfo.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Could not read package info", e);
            infoVersionName.setText(R.string.info_could_not_read);
        }
        dialog.show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:edu.berkeley.boinc.PrefsActivity.java

public void onItemClick(View view) {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    Object item = view.getTag();//from  w w w  .j  a  v a 2s  .co m

    if (item instanceof PrefsListItemWrapperValue) {
        final PrefsListItemWrapperValue valueWrapper = (PrefsListItemWrapperValue) item;
        if (Logging.DEBUG)
            Log.d(Logging.TAG, "PrefsActivity onItemClick Value " + valueWrapper.ID);

        if (valueWrapper.isPct) {
            // show dialog with slider
            dialog.setContentView(R.layout.prefs_layout_dialog_pct);
            // setup slider
            TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
            sliderProgress.setText(valueWrapper.status.intValue() + " " + getString(R.string.prefs_unit_pct));
            Double seekBarDefault = valueWrapper.status / 10;
            SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);
            slider.setProgress(seekBarDefault.intValue());
            slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    String progressString = (progress * 10) + " " + getString(R.string.prefs_unit_pct);
                    TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                    sliderProgress.setText(progressString);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
        } else if (valueWrapper.isNumber) {
            if (!getHostInfo()) {
                if (Logging.WARNING)
                    Log.w(Logging.TAG, "onItemClick missing hostInfo");
                return;
            }

            // show dialog with slider
            dialog.setContentView(R.layout.prefs_layout_dialog_pct);
            TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
            sliderProgress.setText("" + valueWrapper.status.intValue());
            SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);

            // slider setup depending on actual preference
            if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) {
                slider.setMax(hostinfo.p_ncpus);
                slider.setProgress(valueWrapper.status.intValue());
                slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (progress == 0)
                            progress = 1; // do not allow 0 cpus
                        String progressString = String.valueOf(progress);
                        TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                        sliderProgress.setText(progressString);
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }
                });
            } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) {
                slider.setMax(5);
                slider.setProgress(valueWrapper.status.intValue());
                slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        String progressString = String.valueOf(progress);
                        TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                        sliderProgress.setText(progressString);
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }
                });
            }
        } else {
            // show dialog with edit text
            dialog.setContentView(R.layout.prefs_layout_dialog);
        }
        // show preference name
        ((TextView) dialog.findViewById(R.id.pref)).setText(valueWrapper.ID);

        // setup buttons
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                double value = 0.0;
                Boolean clientPref = true;
                if (valueWrapper.isPct) {
                    SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);
                    value = slider.getProgress() * 10;
                } else if (valueWrapper.isNumber) {
                    SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);
                    int sbProgress = slider.getProgress();
                    if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) {
                        if (sbProgress == 0)
                            sbProgress = 1;
                        value = numberCpuCoresToPct(sbProgress);
                    } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) {
                        appPrefs.setLogLevel(sbProgress);
                        updateValuePref(valueWrapper.ID, (double) sbProgress);
                        clientPref = false; // avoid writing client prefs via rpc
                        updateLayout();
                    }
                } else {
                    EditText edit = (EditText) dialog.findViewById(R.id.Input);
                    String input = edit.getText().toString();
                    Double valueTmp = parseInputValueToDouble(input);
                    if (valueTmp == null)
                        return;
                    value = valueTmp;
                }
                if (clientPref)
                    writeClientValuePreference(valueWrapper.ID, value);
                dialog.dismiss();
            }
        });
        Button cancel = (Button) dialog.findViewById(R.id.cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();

    } else {
        // instance of PrefsListItemWrapper, i.e. client log flags
        PrefsListItemWrapper wrapper = (PrefsListItemWrapper) item;
        if (Logging.DEBUG)
            Log.d(Logging.TAG, "PrefsActivity onItemClick super " + wrapper.ID);

        dialog.setContentView(R.layout.prefs_layout_dialog_selection);
        final ArrayList<ClientLogOption> options = new ArrayList<ClientLogOption>();
        String[] array = getResources().getStringArray(R.array.prefs_client_log_flags);
        for (String option : array)
            options.add(new ClientLogOption(option));
        ListView lv = (ListView) dialog.findViewById(R.id.selection);
        new PrefsLogOptionsListAdapter(this, lv, R.id.selection, options);

        // setup buttons
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<String> selectedOptions = new ArrayList<String>();
                for (ClientLogOption option : options)
                    if (option.selected)
                        selectedOptions.add(option.name);
                if (Logging.DEBUG)
                    Log.d(Logging.TAG, selectedOptions.size() + " log flags selected");
                new SetCcConfigAsync().execute(formatOptionsToCcConfig(selectedOptions));
                dialog.dismiss();
            }
        });
        Button cancel = (Button) dialog.findViewById(R.id.cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }
}

From source file:com.appolis.move.AcMoveDetails.java

/**
 * /*from   ww w.j  a  va  2s .c o  m*/
 * @param mContext
 * @param newClass
 * @param strMessages
 */
public void showPopUp(final Context mContext, final Class<?> newClass, final String strMessages) {
    String message;
    if (strMessages.equals(GlobalParams.BLANK)) {
        message = GlobalParams.WRONG_USER;
    } else {
        message = strMessages;
    }

    final Dialog dialog = new Dialog(mContext, R.style.Dialog_NoTitle);
    dialog.setContentView(R.layout.dialogwarning);
    // set the custom dialog components - text, image and button      
    TextView text2 = (TextView) dialog.findViewById(R.id.tvScantitle2);
    text2.setText(message);

    LanguagePreferences langPref = new LanguagePreferences(mContext);
    Button dialogButtonOk = (Button) dialog.findViewById(R.id.dialogButtonOK);
    dialogButtonOk.setText(langPref.getPreferencesString(GlobalParams.OK, GlobalParams.OK));

    dialogButtonOk.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            scanFlag = GlobalParams.FLAG_ACTIVE;
        }
    });
    dialog.show();
}