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:nf.frex.android.FrexActivity.java

private void prepareColorsDialog(final Dialog dialog) {

    //Log.d(TAG, "prepareColorsDialog() entered");

    getColorSchemes();//from   w w w. j  a v a 2  s.co m

    //Log.d(TAG, "prepareColorsDialog: new bitmaps are being created");
    Bitmap[] colorSchemeIcons = new Bitmap[colorSchemes.getSize()];
    for (int i = 0; i < colorSchemeIcons.length; i++) {
        ColorScheme colorScheme = colorSchemes.getValue(i);
        colorSchemeIcons[i] = colorScheme.getGradientIcon();
    }

    int checkedIndex = Registries.colorSchemes.getIndex(view.getColorSchemeId());
    //Log.d(TAG, "prepareColorsDialog: checkedIndex = " + checkedIndex);
    final Spinner colorTableSpinner = (Spinner) dialog.findViewById(R.id.color_table_spinner);
    colorTableSpinner.setAdapter(new ImageArrayAdapter(this, 0, colorSchemeIcons));
    colorTableSpinner.setSelection(checkedIndex, false);
    colorTableSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) {
            view.setColorSchemeId(Registries.colorSchemes.getId(position));
            view.setColorScheme(Registries.colorSchemes.getValue(position));
            view.recomputeColors();
        }

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

    final SeekBar colorFactorSeekBar = (SeekBar) dialog.findViewById(R.id.color_gain_seek_bar);
    final double colorFactorMin = -3.0;
    final double colorFactorMax = 2.0;
    final SeekBarConfigurer colorFactorSeekBarConfigurer = SeekBarConfigurer.create(colorFactorSeekBar,
            colorFactorMin, colorFactorMax, true, view.getColorGain());
    colorFactorSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            view.setColorGain((float) colorFactorSeekBarConfigurer.getValue());
            view.recomputeColors();
        }
    });

    final SeekBar colorBiasSeekBar = (SeekBar) dialog.findViewById(R.id.color_offset_seek_bar);
    final double colorBiasMin = 0;
    final double colorBiasMax = 1024;
    final SeekBarConfigurer colorBiasSeekBarConfigurer = SeekBarConfigurer.create(colorBiasSeekBar,
            colorBiasMin, colorBiasMax, false, view.getColorOffset());
    colorBiasSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            view.setColorOffset((float) colorBiasSeekBarConfigurer.getValue());
            view.recomputeColors();
        }
    });

    final CheckBox colorRepeatCheckBox = (CheckBox) dialog.findViewById(R.id.color_repeat);
    colorRepeatCheckBox.setChecked(view.isColorRepeat());
    colorRepeatCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            view.setColorRepeat(isChecked);
            view.recomputeColors();
        }
    });

    Button randomButton = (Button) dialog.findViewById(R.id.random_button);
    randomButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            colorTableSpinner.setSelection((int) (Math.random() * colorSchemes.getSize()));
            colorFactorSeekBarConfigurer.setRandomValue();
            colorBiasSeekBarConfigurer.setRandomValue();
            view.recomputeColors();
        }
    });

    Button getPalFromImgButton = (Button) dialog.findViewById(R.id.get_pal_from_img_button);
    getPalFromImgButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            dialog.dismiss();
            startActivityForResult(photoPickerIntent, SELECT_PICTURE_REQUEST_CODE);
        }
    });

    //Log.d(TAG, "prepareColorsDialog() exited");
}

From source file:com.android.music.MediaPlaybackActivity.java

/** Called when the activity is first created. */
@Override/*from  ww w  . jav  a2 s .co  m*/
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mAlbumArtWorker = new Worker("album art worker");
    mAlbumArtHandler = new AlbumArtHandler(mAlbumArtWorker.getLooper());

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.audio_player);

    mCurrentTime = (TextView) findViewById(R.id.currenttime);
    mTotalTime = (TextView) findViewById(R.id.totaltime);
    mProgress = (ProgressBar) findViewById(android.R.id.progress);
    mAlbum = (ImageView) findViewById(R.id.album);
    mArtistName = (TextView) findViewById(R.id.artistname);
    mAlbumName = (TextView) findViewById(R.id.albumname);
    mTrackName = (TextView) findViewById(R.id.trackname);

    View v = (View) mArtistName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    v = (View) mAlbumName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    v = (View) mTrackName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    mPrevButton = (RepeatingImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(mPrevListener);
    mPrevButton.setRepeatListener(mRewListener, 260);
    mPauseButton = (ImageButton) findViewById(R.id.pause);
    mPauseButton.requestFocus();
    mPauseButton.setOnClickListener(mPauseListener);
    mNextButton = (RepeatingImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(mNextListener);
    mNextButton.setRepeatListener(mFfwdListener, 260);
    seekmethod = 1;

    mDeviceHasDpad = (getResources().getConfiguration().navigation == Configuration.NAVIGATION_DPAD);

    mQueueButton = (ImageButton) findViewById(R.id.curplaylist);
    mQueueButton.setOnClickListener(mQueueListener);
    mShuffleButton = ((ImageButton) findViewById(R.id.shuffle));
    mShuffleButton.setOnClickListener(mShuffleListener);
    mRepeatButton = ((ImageButton) findViewById(R.id.repeat));
    mRepeatButton.setOnClickListener(mRepeatListener);

    if (mProgress instanceof SeekBar) {
        SeekBar seeker = (SeekBar) mProgress;
        seeker.setOnSeekBarChangeListener(mSeekListener);
    }
    mProgress.setMax(1000);

    mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();

    badSymptoms = new BadSymptoms(this);
}

From source file:systems.byteswap.publicstream.MainActivity.java

/** add all callbacks to the corresponding GUI elements:
 * -) Play the live stream// www.  j av  a  2s .co m
 * -) Play/Pause button
 * -) Seekbar
 */
public void addGUIListener() {
    //add a click listener to the "Live" button
    Button buttonLive = (Button) findViewById(R.id.buttonLive);
    buttonLive.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mService.setUseHWAcceleration(useHWAccel);
            mService.onCommand(MediaService.ACTION_LOAD, ORFParser.ORF_LIVE_URL);
            TextView text = (TextView) findViewById(R.id.textViewCurrentStream);
            if (dataFragment != null)
                dataFragment.setTextPlayButton("LIVE");
            text.setText("LIVE");
            handler.removeCallbacks(mRunnableSeek);
            handler.postDelayed(mRunnableSeek, 1000);
            updateGUIElementsVisibility();
        }
    });

    //add a click listener to the "Play/Pause" button
    final ImageButton buttonPlayPause = (ImageButton) findViewById(R.id.buttonPause);
    buttonPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mService != null) {
                mService.setUseHWAcceleration(useHWAccel);
                mService.onCommand(MediaService.ACTION_PLAY_PAUSE, "");
            }
            handler.removeCallbacks(mRunnableSeek);
            handler.postDelayed(mRunnableSeek, 1000);
            updateGUIElementsVisibility();
        }
    });
    updateGUIElementsVisibility();

    SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setMax(1000);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (mService != null) {
                mService.onCommand(MediaService.ACTION_SETTIME,
                        String.valueOf((float) seekBar.getProgress() / 1000));
                updateGUIElementsVisibility();
            }
        }
    });
}

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

private void setupSliderDialog(PrefsListItemWrapper item, final Dialog dialog) {
    final PrefsListItemWrapperValue valueWrapper = (PrefsListItemWrapperValue) item;
    dialog.setContentView(R.layout.prefs_layout_dialog_pct);
    TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
    SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);

    if (valueWrapper.ID == R.string.battery_charge_min_pct_header
            || valueWrapper.ID == R.string.prefs_disk_max_pct_header
            || valueWrapper.ID == R.string.prefs_cpu_time_max_header
            || valueWrapper.ID == R.string.prefs_cpu_other_load_suspension_header
            || valueWrapper.ID == R.string.prefs_memory_max_idle_header) {
        Double seekBarDefault = valueWrapper.status / 10;
        slider.setProgress(seekBarDefault.intValue());
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                final String progressString = NumberFormat.getPercentInstance().format(progress / 10.0);
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }/*from   w  w  w .j a v a  2s.  com*/

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, seekBarDefault.intValue(), false);
    } else if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) {
        if (!getHostInfo()) {
            if (Logging.WARNING)
                Log.w(Logging.TAG, "onItemClick missing hostInfo");
            return;
        }
        slider.setMax(hostinfo.p_ncpus <= 1 ? 0 : hostinfo.p_ncpus - 1);
        final int statusValue;
        slider.setProgress((statusValue = valueWrapper.status.intValue()) <= 0 ? 0
                : statusValue - 1 > slider.getMax() ? slider.getMax() : statusValue - 1);
        Log.d(Logging.TAG, String.format("statusValue == %,d", statusValue));
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                final String progressString = NumberFormat.getIntegerInstance()
                        .format(progress <= 0 ? 1 : progress + 1); // do not allow 0 cpus
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, statusValue - 1, false);
    } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) {
        slider.setMax(5);
        slider.setProgress(valueWrapper.status.intValue());
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                String progressString = NumberFormat.getIntegerInstance().format(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) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, valueWrapper.status.intValue(), false);
    }

    setupDialogButtons(item, dialog);
}

From source file:github.daneren2005.dsub.fragments.NowPlayingFragment.java

protected void startTimer() {
    View dialogView = context.getLayoutInflater().inflate(R.layout.start_timer, null);

    // Setup length label
    final TextView lengthBox = (TextView) dialogView.findViewById(R.id.timer_length_label);
    final SharedPreferences prefs = Util.getPreferences(context);
    String lengthString = prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "5");
    int length = Integer.parseInt(lengthString);
    lengthBox.setText(Util.formatDuration(length));

    // Setup length slider
    final SeekBar lengthBar = (SeekBar) dialogView.findViewById(R.id.timer_length_bar);
    lengthBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override/*from   w w  w . j  a v a  2 s. c  o m*/
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                int length = getMinutes(progress);
                lengthBox.setText(Util.formatDuration(length));
                seekBar.setProgress(progress);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    lengthBar.setProgress(length - 1);

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.menu_set_timer).setView(dialogView)
            .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    int length = getMinutes(lengthBar.getProgress());

                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, Integer.toString(length));
                    editor.commit();

                    getDownloadService().setSleepTimerDuration(length);
                    getDownloadService().startSleepTimer();
                    context.supportInvalidateOptionsMenu();
                }
            }).setNegativeButton(R.string.common_cancel, null);
    AlertDialog dialog = builder.create();
    dialog.show();
}

From source file:edu.ttu.spm.cheapride.MainActivity.java

public void initTimeSeekBar() {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
    String formattedDate = df.format(c.getTime());
    int hours = c.get(Calendar.HOUR_OF_DAY);
    int mins = c.get(Calendar.MINUTE);

    //seekBar.getTickMark();
    //seekBar.setProgress();

    seekBar = (SeekBar) findViewById(R.id.seek_Bar);
    textView_seekBar.setText("Selected Time :  " + showDate + "    " + convertTime(seekBar.getProgress()));

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        Calendar c = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
        String formattedDate = df.format(c.getTime());
        int progress_value;

        @Override//  ww  w.  j  a  v  a  2 s.c  om
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progress_value = progress;
            textView_seekBar.setText("Selected Time :  " + showDate + "    " + convertTime(progress));
            //textView_seekBar.setTextSize(20);

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            textView_seekBar.setText("Selected Time :  " + showDate + "    " + convertTime(progress_value));
            //textView_seekBar.setTextSize(20);
            mMap.clear();

            mRideCostComparisonTask = new UserSetputTime(convertTime(progress_value));
            mRideCostComparisonTask.execute((Void) null);

        }
    });
}

From source file:com.lofland.housebot.BotController.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.housebot);/* w ww .j  a va 2s  .co m*/
    Log.d(TAG, "onCreate");

    /*
     * TODO: If you need to maintain and pass around context:
     * http://stackoverflow.com/questions/987072/using-application-context-everywhere
     */

    // Display start up toast:
    // http://developer.android.com/guide/topics/ui/notifiers/toasts.html
    Context context = getApplicationContext();
    CharSequence text = "ex Nehilo!";
    int duration = Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, text, duration);
    // Display said toast
    toast.show();

    /*
     *  Turn on WiFi if it is off
     *  http://stackoverflow.com/questions/8863509/how-to-programmatically-turn-off-wifi-on-android-device
     */
    WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(true);

    // Prevent keyboard from popping up as soon as app launches: (it works!)
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    /*
     * Keep the screen on, because as long as we are talking to the robot, this needs to be up http://stackoverflow.com/questions/9335908/how-to- prevent-the-screen-of
     * -an-android-device-to-turn-off-during-the-execution
     */
    this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    /*
     * One or more of these three lines sets the screen to minimum brightness, Which should extend battery drain, and be less distracting on the robot.
     */
    final WindowManager.LayoutParams winParams = this.getWindow().getAttributes();
    winParams.screenBrightness = 0.01f;
    winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;

    // The "Connect" screen has a "Name" and "Address box"
    // I'm not really sure what one puts in these, and if you leave them
    // empty it works fine.
    // So not 110% sure what to do with these. Can the text just be: ""?
    // Just comment these out, and run the command with nulls?
    // mName = (EditText) findViewById(R.id.name_edit);
    // mAddress = (EditText) findViewById(R.id.address_edit);
    // The NXT Remote Control app pops up a list of seen NXTs, so maybe I
    // need to implement that instead.

    // Text to speech
    tts = new TextToSpeech(this, this);

    btnSpeak = (Button) findViewById(R.id.btnSpeak);

    txtText = (EditText) findViewById(R.id.txtSpeakText);

    // Now we need a Robot object before we an use any Roboty values!
    // We can pass defaults in or use the ones it provides
    myRobot = new Robot(INITIALTRAVELSPEED, INITIALROTATESPEED, DEFAULTVIEWANGLE);
    // We may have to pass this robot around a bit. ;)

    // Status Lines
    TextView distanceText = (TextView) findViewById(R.id.distanceText);
    distanceText.setText("???");
    TextView distanceLeftText = (TextView) findViewById(R.id.distanceLeftText);
    distanceLeftText.setText("???");
    TextView distanceRightText = (TextView) findViewById(R.id.distanceRightText);
    distanceRightText.setText("???");
    TextView headingText = (TextView) findViewById(R.id.headingText);
    headingText.setText("???");
    TextView actionText = (TextView) findViewById(R.id.isDoingText);
    actionText.setText("None");

    // Travel speed slider bar
    SeekBar travelSpeedBar = (SeekBar) findViewById(R.id.travelSpeed_seekBar);
    travelSpeedBar.setProgress(myRobot.getTravelSpeed());
    travelSpeedBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            myRobot.setTravelSpeed(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

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

    // View angle slider bar
    SeekBar viewAngleBar = (SeekBar) findViewById(R.id.viewAngle_seekBar);
    viewAngleBar.setProgress(myRobot.getViewAngle());
    viewAngleBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            myRobot.setViewAngle(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Log.d(TAG, "View Angle Slider ");
            /*
             * If this gets sent every few milliseconds with the normal output, then there is no need to send a specific command every time it changes!
             */
            // sendCommandToRobot(Command.VIEWANGLE);
        }
    });

    // Rotation speed slider bar speedSP_seekBar
    SeekBar rotateSpeedBar = (SeekBar) findViewById(R.id.rotateSpeed_seekBar);
    rotateSpeedBar.setProgress(myRobot.getRotateSpeed());
    rotateSpeedBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            myRobot.setRotateSpeed(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

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

    /*
     * This is where we find the four direction buttons defined So we could define ALL buttons this way, set up an ENUM with all options, and call the same function for ALL
     * options!
     * 
     * Just be sure the "release" only stops the robot on these, and not every button on the screen.
     * 
     * Maybe see how the code I stole this form does it?
     */
    Button buttonUp = (Button) findViewById(R.id.forward_button);
    buttonUp.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.FORWARD));
    Button buttonDown = (Button) findViewById(R.id.reverse_button);
    buttonDown.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.REVERSE));
    Button buttonLeft = (Button) findViewById(R.id.left_button);
    buttonLeft.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.LEFT));
    Button buttonRight = (Button) findViewById(R.id.right_button);
    buttonRight.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.RIGHT));

    // button on click event
    btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            speakOut();
        }

    });

    /*
     * This causes the typed text to be spoken when the Enter key is pressed.
     */
    txtText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                // Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                speakOut();
                return true;
            }
            return false;
        }
    });

    // Connect button
    connectToggleButton = (ToggleButton) findViewById(R.id.connectToggleButton);
    connectToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // The toggle is enabled
                Log.d(TAG, "Connect button Toggled On!");
                myRobot.setConnectRequested(true);
            } else {
                // The toggle is disabled
                Log.d(TAG, "Connect button Toggled OFF.");
                myRobot.setConnectRequested(false);
            }
        }
    });

    if (nxtStatusMessageHandler == null)
        nxtStatusMessageHandler = new StatusMessageHandler();

    mStatusThread = new StatusThread(context, nxtStatusMessageHandler);
    mStatusThread.start();

    // Start the web service!
    Log.d(TAG, "Start web service here:");
    // Initiate message handler for web service
    if (robotWebServerMessageHandler == null)
        robotWebServerMessageHandler = new WebServerMessageHandler(this); // Has to include "this" to send context, see WebServerMessageHandler for explanation

    robotWebServer = new WebServer(context, PORT, robotWebServerMessageHandler, myRobot);

    try {
        robotWebServer.start();
    } catch (IOException e) {
        Log.d(TAG, "robotWebServer failed to start");
        //e.printStackTrace();
    }

    // TODO:
    /*
     * See this reference on how to rebuild this handler in onCreate if it is gone: http://stackoverflow.com/questions/18221593/android-handler-changing-weakreference
     */
    // TODO - Should I stop this thread in Destroy or some such place?

    Log.d(TAG, "Web service was started.");

}

From source file:universe.constellation.orion.viewer.OrionViewerActivity.java

public void initZoomScreen() {
    //zoom screen

    final Spinner sp = (Spinner) findMyViewById(R.id.zoom_spinner);

    final EditText zoomText = (EditText) findMyViewById(R.id.zoom_picker_message);

    final SeekBar zoomSeek = (SeekBar) findMyViewById(R.id.zoom_picker_seeker);

    if (zoomSeek != null) {
        zoomSeek.setMax(300);//  ww w. j a  v a2 s  . c  o  m
        zoomSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (zoomInternal != 1) {
                    zoomText.setText("" + progress);
                    if (sp.getSelectedItemPosition() != 0) {
                        int oldInternal = zoomInternal;
                        zoomInternal = 2;
                        sp.setSelection(0);
                        zoomInternal = oldInternal;
                    }
                }
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

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

    getSubscriptionManager().addDocListeners(new DocumentViewAdapter() {
        @Override
        public void documentOpened(Controller controller) {
            updateZoom();
        }
    });

    final ImageButton zplus = (ImageButton) findMyViewById(R.id.zoom_picker_plus);
    zplus.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            zoomSeek.incrementProgressBy(1);
        }
    });

    final ImageButton zminus = (ImageButton) findMyViewById(R.id.zoom_picker_minus);
    zminus.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (zoomSeek.getProgress() != 0) {
                zoomSeek.incrementProgressBy(-1);
            }
        }
    });

    ImageButton closeZoomPeeker = (ImageButton) findMyViewById(R.id.zoom_picker_close);
    closeZoomPeeker.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //main menu
            onAnimatorCancel();
            //updateZoom();
        }
    });

    ImageButton zoom_preview = (ImageButton) findMyViewById(R.id.zoom_preview);
    zoom_preview.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            onApplyAction();
            int index = sp.getSelectedItemPosition();
            controller.changeZoom(index == 0 ? (int) (Float.parseFloat(zoomText.getText().toString()) * 100)
                    : -1 * (index - 1));
            updateZoom();
        }
    });

    sp.setAdapter(new MyArrayAdapter());
    sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            boolean disable = position != 0;
            int oldZoomInternal = zoomInternal;
            if (zoomInternal != 2) {
                zoomInternal = 1;
                if (disable) {
                    zoomText.setText((String) parent.getAdapter().getItem(position));
                } else {
                    zoomText.setText("" + ((int) (controller.getCurrentPageZoom() * 10000)) / 100f);
                    zoomSeek.setProgress((int) (controller.getCurrentPageZoom() * 100));
                }
                zoomInternal = oldZoomInternal;
            }

            zminus.setVisibility(disable ? View.GONE : View.VISIBLE);
            zplus.setVisibility(disable ? View.GONE : View.VISIBLE);

            zoomText.setFocusable(!disable);
            zoomText.setFocusableInTouchMode(!disable);

            final LinearLayout parent1 = (LinearLayout) zoomText.getParent();

            parent1.post(new Runnable() {
                @Override
                public void run() {
                    parent1.requestLayout();
                }
            });
        }

        public void onNothingSelected(AdapterView<?> parent) {
            //To change body of implemented methods use File | Settings | File Templates.
        }
    });

    //by width
    sp.setSelection(1);

}

From source file:com.android.app.MediaPlaybackActivity.java

/**
 * Called when the activity is first created.
 *//* w  ww.  j a va 2 s  . c o m*/
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mAlbumArtWorker = new Worker("album art worker");
    mAlbumArtHandler = new AlbumArtHandler(mAlbumArtWorker.getLooper());

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.audio_player);

    mCurrentTime = (TextView) findViewById(R.id.currenttime);
    mTotalTime = (TextView) findViewById(R.id.totaltime);
    mProgress = (SeekBar) findViewById(R.id.seekbar_playback);
    mAlbum = (ImageView) findViewById(R.id.album);
    mArtistName = (TextView) findViewById(R.id.artistname);
    mAlbumName = (TextView) findViewById(R.id.albumname);
    mTrackName = (TextView) findViewById(R.id.trackname);

    View v = (View) mArtistName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    v = (View) mAlbumName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    v = (View) mTrackName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    mPrevButton = (RepeatingImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(mPrevListener);
    mPrevButton.setRepeatListener(mRewListener, 260);
    mPauseButton = (ImageButton) findViewById(R.id.pause);
    mPauseButton.requestFocus();
    mPauseButton.setOnClickListener(mPauseListener);
    mNextButton = (RepeatingImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(mNextListener);
    mNextButton.setRepeatListener(mFfwdListener, 260);
    seekmethod = 1;

    mDeviceHasDpad = (getResources().getConfiguration().navigation == Configuration.NAVIGATION_DPAD);

    mQueueButton = (ImageButton) findViewById(R.id.curplaylist);
    mQueueButton.setOnClickListener(mQueueListener);
    mShuffleButton = ((ImageButton) findViewById(R.id.shuffle));
    mShuffleButton.setOnClickListener(mShuffleListener);
    mRepeatButton = ((ImageView) findViewById(R.id.repeat));
    mRepeatButton.setOnClickListener(mRepeatListener);

    mIndicator_left = (ImageView) findViewById(R.id.indicator_circle_1);
    mIndicator_right = (ImageView) findViewById(R.id.indicator_circle_2);
    mIndicator_right.setEnabled(false);
    mTitleBack = (ImageButton) findViewById(R.id.title_back);
    mTitleBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    mTitlePlaylist = (ImageButton) findViewById(R.id.title_playlist);
    mTitlePlaylist.setOnClickListener(mQueueListener);
    mTitlePlaying = (TextView) findViewById(R.id.title_playing);

    playlistPlayback = (ImageView) findViewById(R.id.playlist_iv_playback);
    playlistPlayback.setOnClickListener(mShowPlaylistListener);

    if (mProgress instanceof SeekBar) {
        SeekBar seeker = (SeekBar) mProgress;
        seeker.setOnSeekBarChangeListener(mSeekListener);
    }
    mProgress.setMax(1000);

    mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();

    mViewPager = (ViewPager) findViewById(R.id.vp_play_container);
    initViewPagerContent();
    //        mViewPager.setPageTransformer(true, new PlayPageTransformer());
    //        mPagerIndicator.create(mViewPagerContent.size());
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                mIndicator_left.setEnabled(true);
                mIndicator_right.setEnabled(false);
            } else if (position == 1) {
                mIndicator_left.setEnabled(false);
                mIndicator_right.setEnabled(true);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    mViewPager.setAdapter(mPagerAdapter);
}

From source file:org.musicmod.android.app.MusicPlaybackActivity.java

private void configureActivity() {

    setContentView(R.layout.music_playback);

    ActionBarCompat mActionBar = getActionBarCompat();

    mActionBar.setCustomView(R.layout.actionbar_music_playback);
    mActionBar.setDisplayShowCustomEnabled(true);
    mActionBar.setDisplayShowTitleEnabled(false);

    View mCustomView = mActionBar.getCustomView();

    mProgress = (ProgressBar) mCustomView.findViewById(android.R.id.progress);
    mTouchPaintView = (TouchPaintView) mCustomView.findViewById(R.id.touch_paint);
    mTouchPaintView.setEventListener(mTouchPaintEventListener);

    mTrackName = (TextView) mCustomView.findViewById(R.id.track_name);
    mTrackDetail = (TextView) mCustomView.findViewById(R.id.track_detail);

    mCurrentTime = (TextView) mCustomView.findViewById(R.id.current_time);
    mTotalTime = (TextView) mCustomView.findViewById(R.id.total_time);

    /*//from   w  ww  . ja  va 2s. co m
    mAlbum.setOnClickListener(mQueueListener);
    mAlbum.setOnLongClickListener(mSearchAlbumArtListener);
     */

    mPrevButton = (RepeatingImageButton) findViewById(R.id.prev);
    mPrevButton.setBackgroundDrawable(
            new ButtonStateDrawable(new Drawable[] { getResources().getDrawable(R.drawable.btn_mp_playback) }));
    mPrevButton.setOnClickListener(mPrevListener);
    mPrevButton.setRepeatListener(mRewListener, 260);

    mPauseButton = (ImageButton) findViewById(R.id.pause);
    mPauseButton.setBackgroundDrawable(
            new ButtonStateDrawable(new Drawable[] { getResources().getDrawable(R.drawable.btn_mp_playback) }));
    mPauseButton.requestFocus();
    mPauseButton.setOnClickListener(mPauseListener);

    mNextButton = (RepeatingImageButton) findViewById(R.id.next);
    mNextButton.setBackgroundDrawable(
            new ButtonStateDrawable(new Drawable[] { getResources().getDrawable(R.drawable.btn_mp_playback) }));
    mNextButton.setOnClickListener(mNextListener);
    mNextButton.setRepeatListener(mFfwdListener, 260);

    mDeviceHasDpad = (getResources().getConfiguration().navigation == Configuration.NAVIGATION_DPAD);

    mVisualizerViewFftSpectrum = new VisualizerViewFftSpectrum(this);
    mVisualizerViewWaveForm = new VisualizerViewWaveForm(this);
    mVisualizerView = (FrameLayout) findViewById(R.id.visualizer_view);

    if (mProgress instanceof SeekBar) {
        SeekBar seeker = (SeekBar) mProgress;
        seeker.setOnSeekBarChangeListener(mSeekListener);
    }
    mProgress.setMax(1000);

    if (findViewById(R.id.albumart_frame) != null) {
        getSupportFragmentManager().beginTransaction().replace(R.id.albumart_frame, new AlbumArtFragment())
                .commit();
    }

    mQueueFragment = new TrackFragment();
    Bundle bundle = new Bundle();
    bundle.putString(INTENT_KEY_TYPE, MediaStore.Audio.Playlists.CONTENT_TYPE);
    bundle.putLong(MediaStore.Audio.Playlists._ID, PLAYLIST_QUEUE);
    mQueueFragment.setArguments(bundle);

    mAdapter = new PagerAdapter(getSupportFragmentManager());
    mAdapter.addFragment(new LyricsAndQueueFragment());
    mAdapter.addFragment(mQueueFragment);

    mViewPager = (ViewPager) findViewById(R.id.playback_frame);
    mViewPager.setAdapter(mAdapter);

}