Example usage for android.widget SeekBar setOnSeekBarChangeListener

List of usage examples for android.widget SeekBar setOnSeekBarChangeListener

Introduction

In this page you can find the example usage for android.widget SeekBar setOnSeekBarChangeListener.

Prototype

public void setOnSeekBarChangeListener(OnSeekBarChangeListener l) 

Source Link

Document

Sets a listener to receive notifications of changes to the SeekBar's progress level.

Usage

From source file:com.example.haber.ui.activity.CallActivity.java

private void addListener() {
    ipHistoriesArray = callHistories.toArray(new String[callHistories.size()]);
    arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ipHistoriesArray);
    autoCallAdress.setAdapter(arrayAdapter);
    try {//w ww . ja  va 2  s .  com
        addCallHistory();
    } catch (Exception e) {
        ExceptionUtil.handlerException(e);
    }

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            String bw = callBWs[progress];
            tvBW.setText(bw);
            currentDefaultBW = Integer.parseInt(bw);
            save(CALL_BW, currentDefaultBW);
            LogUtil.i(TAG, currentDefaultBW);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

From source file:co.edu.uniajc.vtf.content.SettingsFragment.java

@Override
public void onActivityCreated(Bundle state) {
    super.onActivityCreated(state);
    SessionManager loSession = new SessionManager(this.getActivity());

    Button loSessionLogout = (Button) this.getView().findViewById(R.id.btnSessionLogout);
    loSessionLogout.setText("Salir : " + loSession.getNames());
    loSessionLogout.setOnClickListener(new OnClickListener() {
        @Override/*from  w  w  w  .  ja v  a  2  s .c o  m*/
        public void onClick(View v) {
            SettingsFragment.this.startLogout();
        }

    });

    Button loSaveSettings = (Button) this.getView().findViewById(R.id.btnSaveSettings);
    loSaveSettings.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            SettingsFragment.this.SaveSettings();
        }

    });

    Spinner loLanguage = (Spinner) this.getView().findViewById(R.id.spnLanguage);
    loLanguage.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ciSelectedLanguageId = position;
        }

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

        }

    });

    Spinner loCity = (Spinner) this.getView().findViewById(R.id.spnCities);
    loCity.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ciSelectedCityId = position;
        }

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

        }

    });

    SeekBar loSeekDistance = (SeekBar) this.getView().findViewById(R.id.seekDistance);
    loSeekDistance.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            TextView loDistance = (TextView) SettingsFragment.this.getView()
                    .findViewById(R.id.txtDistanceValue);
            loDistance.setText(progress + " Kms");
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

    });
    this.coController = new SettingsController(this);
    this.coController.getLanguagesAsync();
    this.showProgressDialog();
}

From source file:com.esri.arcgisruntime.sample.blendrenderer.ParametersDialogFragment.java

/**
 * Builds parameter dialog with values pulled through from MainActivity.
 *
 * @param savedInstanceState/*from   ww  w  . j a  v a  2  s  . c  o  m*/
 * @return create parameter dialog box
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    Bundle blendParameters = getArguments();
    if (blendParameters != null) {
        mAltitude = blendParameters.getInt("altitude");
        mAzimuth = blendParameters.getInt("azimuth");
        mSlopeType = (SlopeType) blendParameters.getSerializable("slope_type");
        mColorRampType = (ColorRamp.PresetType) blendParameters.getSerializable("color_ramp_type");
    }

    final AlertDialog.Builder paramDialog = new AlertDialog.Builder(getContext());
    @SuppressLint("InflateParams")
    View dialogView = inflater.inflate(R.layout.dialog_box, null);
    paramDialog.setView(dialogView);
    paramDialog.setTitle(R.string.dialog_title);
    paramDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });
    paramDialog.setPositiveButton("Render", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            ParametersListener activity = (ParametersListener) getActivity();
            activity.returnParameters(mAltitude, mAzimuth, mSlopeType, mColorRampType);
        }
    });

    mCurrAltitudeTextView = (TextView) dialogView.findViewById(R.id.curr_altitude_text);
    SeekBar altitudeSeekBar = (SeekBar) dialogView.findViewById(R.id.altitude_seek_bar);
    altitudeSeekBar.setMax(90); //altitude is restricted to 0 - 90
    //set initial altitude value
    updateAltitudeSeekBar(altitudeSeekBar);
    altitudeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAltitude = progress;
            updateAltitudeSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    mCurrAzimuthTextView = (TextView) dialogView.findViewById(R.id.curr_azimuth_text);
    SeekBar azimuthSeekBar = (SeekBar) dialogView.findViewById(R.id.azimuth_seek_bar);
    azimuthSeekBar.setMax(360); //azimuth measured in degrees 0 - 360
    //set initial azimuth value
    updateAzimuthSeekBar(azimuthSeekBar);
    azimuthSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAzimuth = progress;
            updateAzimuthSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    List<String> slopeTypeArray = new ArrayList<>();
    slopeTypeArray.add("None"); //ordinals:0
    slopeTypeArray.add("Degree"); //1
    slopeTypeArray.add("Percent rise"); //2
    slopeTypeArray.add("Scaled"); //3

    ArrayAdapter<String> slopeTypeSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_view,
            slopeTypeArray);

    Spinner slopeTypeSpinner = (Spinner) dialogView.findViewById(R.id.slope_type_spinner);
    slopeTypeSpinner.setAdapter(slopeTypeSpinnerAdapter);
    slopeTypeSpinner.setSelection(mSlopeType.ordinal());
    slopeTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mSlopeType = SlopeType.NONE;
                break;
            case 1:
                mSlopeType = SlopeType.DEGREE;
                break;
            case 2:
                mSlopeType = SlopeType.PERCENT_RISE;
                break;
            case 3:
                mSlopeType = SlopeType.SCALED;
                break;
            }
        }

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

    List<String> colorRampTypeArray = new ArrayList<>();
    colorRampTypeArray.add("None"); //ordinals:0
    colorRampTypeArray.add("Elevation"); //1
    colorRampTypeArray.add("DEM screen"); //2
    colorRampTypeArray.add("DEM light"); //3

    ArrayAdapter<String> colorRampSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_view,
            colorRampTypeArray);

    Spinner colorRampSpinner = (Spinner) dialogView.findViewById(R.id.color_ramp_spinner);
    colorRampSpinner.setAdapter(colorRampSpinnerAdapter);
    colorRampSpinner.setSelection(mColorRampType.ordinal());
    colorRampSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mColorRampType = ColorRamp.PresetType.NONE;
                break;
            case 1:
                mColorRampType = ColorRamp.PresetType.ELEVATION;
                break;
            case 2:
                mColorRampType = ColorRamp.PresetType.DEM_SCREEN;
                break;
            case 3:
                mColorRampType = ColorRamp.PresetType.DEM_LIGHT;
                break;
            }
        }

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

    return paramDialog.create();
}

From source file:ca.mudar.parkcatcher.ui.fragments.NumberSeekBarFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    ((ParkingApp) getActivity().getApplicationContext()).updateUiLanguage();

    LayoutInflater factory = LayoutInflater.from(getActivity());
    final View view = factory.inflate(R.layout.fragment_number_seekbar, null);
    final SeekBar seekbar = (SeekBar) view.findViewById(R.id.seekbar_duration);
    final TextView vDurationValue = (TextView) view.findViewById(R.id.duration_value);

    seekbar.setMax(Const.DURATION_MAX - Const.DURATION_MIN);

    int currentDuration = mListener.getParkingDuration();
    seekbar.setProgress(currentDuration - Const.DURATION_MIN);
    setDurationText(vDurationValue, currentDuration - Const.DURATION_MIN);

    seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override//from   w w w .  j a  v a 2 s. com
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            setDurationText(vDurationValue, progress);
        }
    });

    return new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.dialog_title_duration))
            .setView(view).setPositiveButton(R.string.dialog_set, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    onDurationSet(seekbar);
                }
            }).setNegativeButton(R.string.dialog_cancel, null).create();
}

From source file:moe.yukinoneko.gcomic.module.gallery.GalleryActivity.java

@Override
public void init() {
    mDecorView = getWindow().getDecorView();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams();
        lp.setMargins(0, 0, 0, Utils.getNavigationBarHeight(this));
    }/*from w ww  .  j  a  v a 2  s. c  o m*/

    mHandler = new Handler();
    mPreviousRunnable = new Runnable() {
        @Override
        public void run() {
            if (mCurChapterPosition < mChapters.size() - 1) {
                mLastChapterPosition = mCurChapterPosition;
                mCurChapterPosition += 1;
                fetchChapterContent(mChapters.get(mCurChapterPosition).chapterId);
            } else {
                galleryPager.setCurrentItem(1);
                galleryPager.setLocked(false);
                seekBar.setEnabled(true);
                showMessageSnackbar(R.string.already_first);
            }
        }
    };
    mNextRunnable = new Runnable() {
        @Override
        public void run() {
            if (mCurChapterPosition > 0) {
                mLastChapterPosition = mCurChapterPosition;
                mCurChapterPosition -= 1;
                fetchChapterContent(mChapters.get(mCurChapterPosition).chapterId);
            } else {
                galleryPager.setCurrentItem(mPagerAdapter.getCount() - 2);
                galleryPager.setLocked(false);
                seekBar.setEnabled(true);
                showMessageSnackbar(R.string.already_last);
            }
        }
    };

    galleryPager.setLocked(true);
    galleryPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            seekBar.setProgress(position - 1);

            intCurPage = position;
            if (intCurPage > mPagerAdapter.getCount() - 2) {
                intCurPage = mPagerAdapter.getCount() - 2;
            } else if (intCurPage < 1) {
                intCurPage = 1;
            }
            curPage.setText(String.valueOf(intCurPage));

            if (position == 0) {
                galleryPager.setLocked(true);
                seekBar.setEnabled(false);
                mHandler.postDelayed(mPreviousRunnable, 1000);
            } else if (position == mPagerAdapter.getCount() - 1) {
                galleryPager.setLocked(true);
                seekBar.setEnabled(false);
                mHandler.postDelayed(mNextRunnable, 1000);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    mPagerAdapter = new GalleryPagerAdapter(getSupportFragmentManager());
    galleryPager.setAdapter(mPagerAdapter);

    seekBar.setEnabled(false);
    seekBar.setKeyProgressIncrement(1);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        int progress = 0;

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            progress = i;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            galleryPager.setCurrentItem(progress + 1, false);
        }
    });

    loadErrorLayout.setBackgroundColor(0xFF444444);
    loadErrorTips.setTextColor(0x80FFFFFF);

    Intent intent = getIntent();

    mComicId = intent.getIntExtra(GALLERY_CMOIC_ID, -1);
    firstLetter = intent.getStringExtra(GALLERY_CMOIC_FIRST_LETTER);
    mChapters = intent.getParcelableArrayListExtra(GALLERY_CHAPTER_LIST);
    mCurChapterPosition = intent.getIntExtra(GALLERY_CHAPTER_POSITION, -1);
    mLastChapterPosition = mCurChapterPosition;
    mHistoryBrowsePosition = intent.getIntExtra(GALLERY_BROWSE_POSITION, 1);
    mToolbar.setTitle(mChapters.get(mCurChapterPosition).chapterTitle);

    galleryPager.setCurrentItem(1, false);

    fetchChapterContent(mChapters.get(mCurChapterPosition).chapterId);
}

From source file:layout.BeaconTabFragment.java

/**
 * Setting up the advertising interval component with a seek bar which can be set to values from
 * 100 to 1024. There is also a tracking TextView which shows the numeric representation of the
 * advertising interval.//from w  w w  .ja v a2  s . c  o m
 *
 * @param v container for the advertising interval component. This is usually the main container
 *          in the tab. It has to be added to the activity before calling this method.
 */
private void setUpAdvertisingInterval(View v) {
    if (advInterval != null) {

        v.findViewById(R.id.adv_int_info).setVisibility(View.VISIBLE);
        final TextView advIntervalView = (TextView) v.findViewById(R.id.adv_interval);
        advIntervalView.setText(advInterval);
        SeekBar advInterSeekBar = (SeekBar) v.findViewById(R.id.adv_interval_seek_bar);
        advInterSeekBar.setMax(1024 - 100);
        int progress = Integer.parseInt(advInterval) - 100;
        advInterSeekBar.setProgress(progress);
        advInterSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                int progress = seekBar.getProgress() + 100;
                advIntervalView.setText(Integer.toString(progress));
                advIntervalChanged = true;
                advInterval = advIntervalView.getText().toString();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }
}

From source file:com.yoval.community.chatapp.DistanceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_distance);

    displayLocationSettingsRequest(getApplicationContext());

    if (googleServicesAvalaible()) {

        //Toast.makeText(this, "Perfect", Toast.LENGTH_LONG).show();
        initMap();/* w w w.j  av a 2  s . c  o m*/
    } else {
        Toast.makeText(this, "Play services problem", Toast.LENGTH_LONG).show();
    }

    //Check for WIfi services enabled
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (!wifi.isWifiEnabled()) {
        showWifiRequest();
    }

    CustomizedLocationListener locationListener = new CustomizedLocationListener(getApplicationContext());
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.MAPS_RECEIVE) != PackageManager.PERMISSION_GRANTED) {

        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5 * 60 * 1000, 10,
                locationListener);
    }

    if (FirebaseAuth.getInstance().getCurrentUser() == null) {
        // Start sign in/sign up activity
        startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_REQUEST_CODE);
    } else {
        // User is already signed in. Therefore, display
        // a welcome Toast
        Toast.makeText(this,
                R.string.Bienvenue + " " + FirebaseAuth.getInstance().getCurrentUser().getDisplayName(),
                Toast.LENGTH_LONG).show();
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarDistance);
    setSupportActionBar(toolbar);

    SeekBar distanceBar = (SeekBar) findViewById(R.id.seekBarDistance); // make seekbar object
    distanceBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub
            TextView textViewDistance = (TextView) findViewById(R.id.textViewDistance);
            textViewDistance.setText(progress + " Km");
            radius = progress;
            SaveUserInformations(radius);
            updateZoomMap();

        }
    });

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.distNext);

    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            goToDetailView();
        }
    });

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}

From source file:uk.org.ngo.squeezer.dialog.AlarmSettingsDialog.java

@NonNull
@Override/*w  w  w  . j av a 2 s. c o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    @SuppressLint({ "InflateParams" }) // OK, as view is passed to AlertDialog.Builder.setView()
    final View view = getActivity().getLayoutInflater().inflate(R.layout.alarm_settings_dialog, null);

    final TextView alarmVolumeHint = (TextView) view.findViewById(R.id.alarm_volume_hint);
    final TextView alarmSnoozeHint = (TextView) view.findViewById(R.id.alarm_snooze_hint);
    final TextView alarmTimeoutHint = (TextView) view.findViewById(R.id.alarm_timeout_hint);
    final TextView alarmFadeHint = (TextView) view.findViewById(R.id.alarm_fade_hint);

    final SeekBar alarmVolume = (SeekBar) view.findViewById(R.id.alarm_volume_seekbar);
    final SeekBar alarmSnooze = (SeekBar) view.findViewById(R.id.alarm_snooze_seekbar);
    final SeekBar alarmTimeout = (SeekBar) view.findViewById(R.id.alarm_timeout_seekbar);

    final CompoundButton alarmFadeToggle = (CompoundButton) view.findViewById(R.id.alarm_fade);

    alarmVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            alarmVolumeHint.setText(String.format("%d%%", progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    alarmSnooze.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            alarmSnoozeHint.setText(
                    getResources().getQuantityString(R.plurals.alarm_snooze_hint_text, progress, progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    alarmTimeout.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (progress == 0) {
                alarmTimeoutHint.setText(R.string.alarm_timeout_hint_text_zero);
            } else {
                alarmTimeoutHint.setText(getResources().getQuantityString(R.plurals.alarm_timeout_hint_text,
                        progress, progress));
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    alarmFadeToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            alarmFadeHint.setText(isChecked ? R.string.alarm_fade_on_text : R.string.alarm_fade_off_text);
        }
    });

    alarmVolume.setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_DEFAULT_VOLUME)));
    alarmSnooze
            .setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_SNOOZE_SECONDS)) / 60);
    alarmTimeout
            .setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_TIMEOUT_SECONDS)) / 60);
    alarmFadeToggle.setChecked("1".equals(mHostActivity.getPlayerPref(Player.Pref.ALARM_FADE_SECONDS)));

    Builder builder = new Builder(getActivity());
    builder.setView(view);
    builder.setTitle(getResources().getString(R.string.alarms_settings_dialog_title,
            mHostActivity.getPlayer().getName()));
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mHostActivity.onPositiveClick(alarmVolume.getProgress(), alarmSnooze.getProgress() * 60,
                    alarmTimeout.getProgress() * 60, alarmFadeToggle.isChecked());
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    return builder.create();
}

From source file:de.ktran.anno1404warenrechner.views.PopulationNumberDialog.java

@SuppressLint({ "SetTextI18n", "InflateParams" })
@NonNull/* w  w w  . ja v a2s  . com*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    TypedArray attributes = getContext().obtainStyledAttributes(theme, R.styleable.SimpleNumberPicker);

    LayoutInflater inflater = getActivity().getLayoutInflater();

    View view;
    if (populationType instanceof PopulationType) {
        view = inflater.inflate(R.layout.number_picker, null);
    } else {
        view = inflater.inflate(R.layout.house_number_picker, null);
        seekBar = (SeekBar) view.findViewById(R.id.houseNumberPickerPopLimit);
        advancementText = (TextView) view.findViewById(R.id.houseNumberPickerPopLimitDesc);

        if (seekBar == null || advancementText == null)
            throw new IllegalStateException("Not all views could be found.");
        if (populationType == PopulationType.Civilization.OCCIDENTAL) {
            seekBar.setMax(3);
            seekBar.setProgress(3);

            setAdvancementText(3, PopulationType.Civilization.OCCIDENTAL);
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    setAdvancementText(progress, PopulationType.Civilization.OCCIDENTAL);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
        } else if (populationType == PopulationType.Civilization.ORIENTAL) {
            seekBar.setMax(1);
            seekBar.setProgress(1);

            setAdvancementText(1, PopulationType.Civilization.ORIENTAL);
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    setAdvancementText(progress, PopulationType.Civilization.ORIENTAL);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
        }
    }

    // Init number
    int color = attributes.getColor(R.styleable.SimpleNumberPicker_snpKeyColor,
            ContextCompat.getColor(getContext(), android.R.color.secondary_text_light));
    numberTextView = (TextView) view.findViewById(R.id.tv_hex_number);
    numberTextView.setTextColor(color);
    if (null != savedInstanceState && savedInstanceState.containsKey(ARG_SAVED_VALUE))
        numberTextView.setText(savedInstanceState.getString(ARG_SAVED_VALUE));
    else if (forceHouse)
        numberTextView.setText("");
    // Init backspace
    color = attributes.getColor(R.styleable.SimpleNumberPicker_snpBackspaceColor,
            ContextCompat.getColor(getContext(), android.R.color.secondary_text_light));
    backspaceButton = (ImageButton) view.findViewById(R.id.key_backspace);
    backspaceButton.setImageDrawable(
            ThemeUtil.makeSelector(getContext(), R.drawable.snp_ic_backspace_black_24dp, color));
    backspaceButton.setOnClickListener(v -> {
        if (numberTextView.getText().length() == 1 && forceHouse)
            return;

        CharSequence number = numberTextView.getText().subSequence(0, numberTextView.getText().length() - 1);
        if (1 == number.length() && '-' == number.charAt(0))
            number = "";
        numberTextView.setText(number);
        onNumberChanged();
    });
    backspaceButton.setOnLongClickListener(v -> {
        numberTextView.setText("");
        onNumberChanged();
        return true;
    });

    // Create dialog
    dialog = new AlertDialog.Builder(getContext(), theme).setView(view)
            .setPositiveButton(android.R.string.ok, (dialog12, which) -> {
                String result = numberTextView.getText().toString();
                if (result.isEmpty())
                    result = "0";
                result = result.replace(',', '.');
                result = result.replace("", "-");
                if (result.equals("-"))
                    result = "0";
                final int number = Integer.parseInt(result);

                handleDialogFinish(number);
                dismiss();
            }).setNegativeButton(android.R.string.cancel, (dialog1, which) -> dismiss()).create();

    // Init dialog
    color = attributes.getColor(R.styleable.SimpleNumberPicker_snpDialogBackground,
            ContextCompat.getColor(getContext(), android.R.color.white));
    if (dialog.getWindow() != null) {
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(color));
    }

    // Init keys
    View.OnClickListener listener = v -> {
        int key = (int) v.getTag();
        String id = numberTextView.getText() + Integer.toString(key);
        numberTextView.setText(id);
        onNumberChanged();
    };

    color = attributes.getColor(R.styleable.SimpleNumberPicker_snpKeyColor,
            ThemeUtil.getThemeAccentColor(getContext()));
    TypedArray ids = getResources().obtainTypedArray(R.array.snp_key_ids);
    for (int i = 0; i < NB_KEYS; i++) {
        TextView key = (TextView) view.findViewById(ids.getResourceId(i, -1));
        key.setTag(i);
        key.setOnClickListener(listener);
        key.setTextColor(color);
    }

    // Init sign
    TextView sign = (TextView) view.findViewById(R.id.key_house);
    if (!this.forceHouse) {
        sign.setTextColor(color);
        sign.setOnClickListener(v -> {
            String number = numberTextView.getText().toString();
            if (number.startsWith("")) {
                numberTextView.setText(number.substring(1));
            } else {
                numberTextView.setText("" + number);
            }
            onNumberChanged();
        });
    } else {
        sign.setVisibility(View.GONE);
    }

    ids.recycle();
    attributes.recycle();

    return dialog;
}

From source file:com.jaguarlandrover.hvacdemo.MainActivity.java

private void configureSeekBar(SeekBar seekBar) {
    seekBar.setMax(MAX_FAN_SPEED);//w  ww . ja  v a 2  s  .  co  m
    seekBar.setOnSeekBarChangeListener(mFanSpeedSeekBarListener = new SeekBar.OnSeekBarChangeListener() {
        /* USER INTERFACE CALLBACK */
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            Log.d(TAG, Util.getMethodName());

            if (fromUser) {
                HVACManager.invokeService(getServiceIdentifiersFromViewId(seekBar.getId()),
                        Integer.toString(progress));

                if (progress == 0) {
                    setAirflowDirectionButtons(0);
                    HVACManager.invokeService(HVACServiceIdentifier.AIRFLOW_DIRECTION.value(),
                            Integer.toString(0));
                }
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}