List of usage examples for android.widget SeekBar SeekBar
public SeekBar(Context context)
From source file:com.googlecode.android_scripting.facade.ui.SeekBarDialogTask.java
@Override public void onCreate() { super.onCreate(); mSeekBar = new SeekBar(getActivity()); mSeekBar.setMax(mMax);//from ww w . j av a 2 s .c o m mSeekBar.setProgress(mProgress); mSeekBar.setPadding(10, 0, 10, 3); mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar arg0) { } public void onStartTrackingTouch(SeekBar arg0) { } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { EventFacade eventFacade = getEventFacade(); if (eventFacade != null) { JSONObject result = new JSONObject(); try { result.put("which", "seekbar"); result.put("progress", mSeekBar.getProgress()); result.put("fromuser", fromUser); eventFacade.postEvent("dialog", result); } catch (JSONException e) { Log.e(e); } } } }); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (mTitle != null) { builder.setTitle(mTitle); } if (mMessage != null) { builder.setMessage(mMessage); } builder.setView(mSeekBar); configureButtons(builder, getActivity()); addOnCancelListener(builder, getActivity()); mDialog = builder.show(); mShowLatch.countDown(); }
From source file:uwp.cs.edu.parkingtracker.parking.ParkDialogFragment.java
/** * Called after onAttach as part of the fragment lifecycle. * * @param savedInstanceState/*from w ww .j av a2 s .c o m*/ * @return */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder votePopup = new AlertDialog.Builder(getActivity()); votePopup.setTitle("How full is this zone?"); LinearLayout linear = new LinearLayout(getActivity()); linear.setOrientation(LinearLayout.VERTICAL); SeekBar fullnessSlider = new SeekBar(getActivity()); fullnessSlider.setMax(4); fullnessSlider.setPadding(50, 70, 50, -10); final TextView result = new TextView(getActivity()); result.setPadding(20, 10, 10, 10); result.setText("0 %"); linear.addView(fullnessSlider); linear.addView(result); votePopup.setView(linear); fullnessSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int fullness, boolean fromUser) { fullnessValue = fullness; result.setText(fullness * 25 + "%"); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); votePopup.setPositiveButton("Send", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatabaseExchange.sendVote(zID, fullnessValue * 25); dismiss(); } }); votePopup.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }); return votePopup.create(); }
From source file:org.musicmod.android.dialog.SleepTimerDialog.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(new LinearLayout(this)); DisplayMetrics dm = new DisplayMetrics(); dm = getResources().getDisplayMetrics(); action = getIntent().getAction();// ww w .j av a2 s .c om mSleepTimerDialog = new AlertDialog.Builder(this).create(); mSleepTimerDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC); mRemained = (int) MusicUtils.getSleepTimerRemained() / 1000 / 60; LinearLayout mContainer = new LinearLayout(this); mContainer.setOrientation(LinearLayout.VERTICAL); mContainer.setPadding((int) dm.density * 8, 0, (int) dm.density * 8, 0); mTimeView = new TextView(this); mContainer.addView(mTimeView); mSetTime = new SeekBar(this); mSetTime.setMax(120); mContainer.addView(mSetTime); if (mRemained > 0) { mSetTime.setProgress(mRemained); } else { mSetTime.setProgress(30); } mSetTime.setOnSeekBarChangeListener(this); mProgress = mSetTime.getProgress(); mTimerTime = mProgress; if (mTimerTime >= 1) { mPrompt = SleepTimerDialog.this.getResources().getQuantityString(R.plurals.NNNminutes, mTimerTime, mTimerTime); } else { mPrompt = SleepTimerDialog.this.getResources().getString(R.string.disabled); } mTimeView.setText(mPrompt); if (INTENT_SLEEP_TIMER.equals(action)) { mSleepTimerDialog.setIcon(android.R.drawable.ic_dialog_info); mSleepTimerDialog.setTitle(R.string.set_time); mSleepTimerDialog.setView(mContainer); mSleepTimerDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.ok), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mTimerTime >= 1) { long milliseconds = mTimerTime * 60 * 1000; boolean gentle = new PreferencesEditor(getApplicationContext()) .getBooleanPref(KEY_GENTLE_SLEEPTIMER, true); MusicUtils.startSleepTimer(milliseconds, gentle); } else { MusicUtils.stopSleepTimer(); } finish(); } }); mSleepTimerDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); mSleepTimerDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); } else { Toast.makeText(this, R.string.error_bad_parameters, Toast.LENGTH_SHORT).show(); finish(); } }
From source file:org.yammp.dialog.SleepTimerDialog.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mUtils = ((YAMMPApplication) getApplication()).getMediaUtils(); setContentView(new LinearLayout(this)); DisplayMetrics dm = new DisplayMetrics(); dm = getResources().getDisplayMetrics(); action = getIntent().getAction();//from w w w.j a va 2 s . c om mSleepTimerDialog = new AlertDialog.Builder(this).create(); mSleepTimerDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC); mRemained = (int) mUtils.getSleepTimerRemained() / 1000 / 60; LinearLayout mContainer = new LinearLayout(this); mContainer.setOrientation(LinearLayout.VERTICAL); mContainer.setPadding((int) dm.density * 8, 0, (int) dm.density * 8, 0); mTimeView = new TextView(this); mContainer.addView(mTimeView); mSetTime = new SeekBar(this); mSetTime.setMax(120); mContainer.addView(mSetTime); if (mRemained > 0) { mSetTime.setProgress(mRemained); } else { mSetTime.setProgress(30); } mSetTime.setOnSeekBarChangeListener(this); mProgress = mSetTime.getProgress(); mTimerTime = mProgress; if (mTimerTime >= 1) { mPrompt = SleepTimerDialog.this.getResources().getQuantityString(R.plurals.NNNminutes, mTimerTime, mTimerTime); } else { mPrompt = SleepTimerDialog.this.getResources().getString(R.string.disabled); } mTimeView.setText(mPrompt); if (INTENT_SLEEP_TIMER.equals(action)) { mSleepTimerDialog.setIcon(android.R.drawable.ic_dialog_info); mSleepTimerDialog.setTitle(R.string.set_time); mSleepTimerDialog.setView(mContainer); mSleepTimerDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.ok), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mTimerTime >= 1) { long milliseconds = mTimerTime * 60 * 1000; boolean gentle = new PreferencesEditor(getApplicationContext()) .getBooleanPref(KEY_GENTLE_SLEEPTIMER, true); mUtils.startSleepTimer(milliseconds, gentle); } else { mUtils.stopSleepTimer(); } finish(); } }); mSleepTimerDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); mSleepTimerDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); } else { Toast.makeText(this, R.string.error_bad_parameters, Toast.LENGTH_SHORT).show(); finish(); } }
From source file:com.mishiranu.dashchan.content.service.AudioPlayerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = new ContextThemeWrapper(this, Preferences.getThemeResource()); setVolumeControlStream(AudioManager.STREAM_MUSIC); float density = ResourceUtils.obtainDensity(this); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view); linearLayout.setPadding(padding, padding, padding, C.API_LOLLIPOP ? (int) (8f * density) : padding); textView = new TextView(context, null, android.R.attr.textAppearanceListItem); linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); textView.setPadding(0, 0, 0, 0);/*w w w .ja v a 2s . co m*/ textView.setEllipsize(TextUtils.TruncateAt.END); textView.setSingleLine(true); LinearLayout horizontal = new LinearLayout(context); horizontal.setOrientation(LinearLayout.HORIZONTAL); horizontal.setGravity(Gravity.CENTER_VERTICAL); horizontal.setPadding(0, (int) (16f * density), 0, 0); linearLayout.addView(horizontal, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); seekBar = new SeekBar(context); horizontal.addView(seekBar, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); seekBar.setPadding((int) (8f * density), 0, (int) (16f * density), 0); seekBar.setOnSeekBarChangeListener(this); button = new ImageButton(context); horizontal.addView(button, (int) (48f * density), (int) (48f * density)); button.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.listChoiceBackgroundIndicator, 0)); setPlayState(false); button.setOnClickListener(this); alertDialog = new AlertDialog.Builder(context).setView(linearLayout).setOnCancelListener(this) .setPositiveButton(R.string.action_stop, this).show(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AudioPlayerService.ACTION_TOGGLE); intentFilter.addAction(AudioPlayerService.ACTION_CANCEL); LocalBroadcastManager.getInstance(this).registerReceiver(audioPlayerReceiver, intentFilter); bindService(new Intent(this, AudioPlayerService.class), this, 0); }
From source file:org.mdc.chess.SeekBarPreference.java
@Override protected View onCreateView(ViewGroup parent) { TextView name = new TextView(getContext()); name.setText(getTitle());// w w w . j a v a 2 s .c o m //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large); TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large); name.setGravity(Gravity.START); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.START; lp.weight = 1.0f; name.setLayoutParams(lp); currValBox = new TextView(getContext()); currValBox.setTextSize(12); currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC); currValBox.setPadding(2, 5, 0, 0); currValBox.setText(valToString()); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.CENTER; currValBox.setLayoutParams(lp); LinearLayout row1 = new LinearLayout(getContext()); row1.setOrientation(LinearLayout.HORIZONTAL); row1.addView(name); row1.addView(currValBox); final SeekBar bar = new SeekBar(getContext()); bar.setMax(maxValue); bar.setProgress(currVal); bar.setOnSeekBarChangeListener(this); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.END; bar.setLayoutParams(lp); CharSequence summaryCharSeq = getSummary(); boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0); TextView summary = null; if (haveSummary) { summary = new TextView(getContext()); summary.setText(getSummary()); // summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large); summary.setGravity(Gravity.START); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.START; lp.weight = 1.0f; summary.setLayoutParams(lp); } LinearLayout layout = new LinearLayout(getContext()); layout.setPadding(25, 5, 25, 5); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(row1); layout.addView(bar); if (summary != null) { layout.addView(summary); } layout.setId(android.R.id.widget_frame); currValBox.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null); final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext()); builder.setView(content); String title = ""; String key = getKey(); if (key.equals("strength")) { title = getContext().getString(R.string.edit_strength); } else if (key.equals("bookRandom")) { title = getContext().getString(R.string.edit_randomization); } builder.setTitle(title); final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number); valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", ".")); final Runnable selectValue = new Runnable() { public void run() { try { String txt = valueView.getText().toString(); int value = (int) (Double.parseDouble(txt) * 10 + 0.5); if (value < 0) value = 0; if (value > maxValue) value = maxValue; onProgressChanged(bar, value, false); } catch (NumberFormatException ignored) { } } }; valueView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { selectValue.run(); return true; } return false; } }); builder.setPositiveButton("Ok", new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { selectValue.run(); } }); builder.setNegativeButton("Cancel", null); builder.create().show(); } }); return layout; }
From source file:widgets.Graphical_Binary.java
public Graphical_Binary(tracerengine Trac, Activity context, String address, final String name, int id, int dev_id, String state_key, String url, String usage, String parameters, String model_id, int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params) throws JSONException { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.context = context; this.address = address; this.url = url; this.state_key = state_key; this.usage = usage; this.update = update; this.myself = this; this.session_type = session_type; this.stateS = getResources().getText(R.string.State).toString(); this.place_id = place_id; this.place_type = place_type; this.params = params; mytag = "Graphical_Binary(" + dev_id + ")"; //get parameters try {/*from w w w. j av a 2s.c o m*/ JSONObject jparam = new JSONObject(parameters.replaceAll(""", "\"")); value0 = jparam.getString("value0"); value1 = jparam.getString("value1"); } catch (Exception e) { value0 = "0"; value1 = "1"; } if (usage.equals("light")) { this.Value_0 = getResources().getText(R.string.light_stat_0).toString(); this.Value_1 = getResources().getText(R.string.light_stat_1).toString(); } else if (usage.equals("shutter")) { this.Value_0 = getResources().getText(R.string.shutter_stat_0).toString(); this.Value_1 = getResources().getText(R.string.shutter_stat_1).toString(); } else { this.Value_0 = value0; this.Value_1 = value1; } String[] model = model_id.split("\\."); type = model[0]; Tracer.d(mytag, "model_id = <" + model_id + "> type = <" + type + "> value0 = " + value0 + " value1 = " + value1); //state state = new TextView(context); state.setTextColor(Color.BLACK); animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(1000); //first seekbar on/off seekBarOnOff = new SeekBar(context); seekBarOnOff.setProgress(0); seekBarOnOff.setMax(40); Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.bgseekbaronoff); seekBarOnOff.setLayoutParams(new LayoutParams(bMap.getWidth(), bMap.getHeight())); seekBarOnOff.setProgressDrawable(getResources().getDrawable(R.drawable.bgseekbaronoff)); seekBarOnOff.setThumb(getResources().getDrawable(R.drawable.buttonseekbar)); seekBarOnOff.setThumbOffset(0); seekBarOnOff.setOnSeekBarChangeListener(this); seekBarOnOff.setTag("0"); super.LL_infoPan.addView(state); super.LL_featurePan.addView(seekBarOnOff); login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); handler = new Handler() { @Override public void handleMessage(Message msg) { if (activate) { Tracer.d(mytag, "Handler receives a request to die "); if (realtime) { Tracer.get_engine().unsubscribe(session); session = null; realtime = false; } //That seems to be a zombie //removeView(background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } else { try { Bundle b = msg.getData(); if ((b != null) && (b.getString("message") != null)) { if (b.getString("message").equals(value0)) { //state.setText(stateS+value0); state.setText(stateS + Value_0); new SBAnim(seekBarOnOff.getProgress(), 0).execute(); } else if (b.getString("message").equals(value1)) { //state.setText(stateS+value1); state.setText(stateS + Value_1); new SBAnim(seekBarOnOff.getProgress(), 40).execute(); } state.setAnimation(animation); } else { if (msg.what == 2) { Toast.makeText(getContext(), "Command Failed", Toast.LENGTH_SHORT).show(); } else if (msg.what == 9999) { //state_engine send us a signal to notify value changed if (session == null) return; String new_val = session.getValue(); Tracer.d(mytag, "Handler receives a new value <" + new_val + ">"); if (new_val.equals(value0)) { state.setText(stateS + Value_0); new SBAnim(seekBarOnOff.getProgress(), 0).execute(); } else if (new_val.equals(value1)) { state.setText(stateS + Value_1); new SBAnim(seekBarOnOff.getProgress(), 40).execute(); } else { state.setText(stateS + new_val); new SBAnim(seekBarOnOff.getProgress(), 0).execute(); } } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "state engine disappeared ===> Harakiri !"); session = null; realtime = false; //removeView(background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } } catch (Exception e) { Tracer.e(mytag, "Handler error for device " + name); e.printStackTrace(); } } } }; //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (Tracer.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ //updateTimer(); //Don't use anymore cyclic refresh.... }
From source file:widgets.Graphical_Range.java
public Graphical_Range(tracerengine Trac, Activity context, String address, String name, int id, int dev_id, String state_key, String url, String usage, String parameters, String model_id, int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params) throws JSONException { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.address = address; this.url = url; this.dev_id = dev_id; this.id = id; this.state_key = state_key; this.usage = usage; this.update = update; this.wname = name; this.myself = this; this.session_type = session_type; this.place_id = place_id; this.place_type = place_type; this.context = context; stateThread = 1;/*from ww w . j av a 2s . c o m*/ this.stateS = getResources().getText(R.string.State).toString(); mytag = "Graphical_Range(" + dev_id + ")"; this.params = params; login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); //get parameters JSONObject jparam = new JSONObject(parameters.replaceAll(""", "\"")); command = jparam.getString("command"); valueMin = jparam.getInt("valueMin"); valueMax = jparam.getInt("valueMax"); range = valueMax - valueMin; scale = 100 / range; try { test_unite = jparam.getString("unit"); } catch (JSONException e) { test_unite = "%"; } if (test_unite == null || test_unite.length() == 0) { test_unite = "%"; } String[] model = model_id.split("\\."); type = model[0]; //linearlayout horizontal body bodyPanHorizontal = new LinearLayout(context); bodyPanHorizontal.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.CENTER_VERTICAL)); bodyPanHorizontal.setOrientation(LinearLayout.HORIZONTAL); //right panel with different info and seekbars rightPan = new FrameLayout(context); rightPan.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); rightPan.setPadding(0, 0, 10, 0); // panel leftPan = new LinearLayout(context); leftPan.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.BOTTOM)); leftPan.setOrientation(LinearLayout.VERTICAL); leftPan.setGravity(Gravity.CENTER_VERTICAL); leftPan.setPadding(4, 5, 0, 0); state = new TextView(context); state.setTextColor(Color.BLACK); state.setPadding(20, 0, 0, 0); animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(1000); //first seekbar variator seekBarVaria = new SeekBar(context); seekBarVaria.setProgress(0); seekBarVaria.setMax(valueMax - valueMin); seekBarVaria.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); seekBarVaria.setProgressDrawable(getResources().getDrawable(R.drawable.bgseekbarvaria)); seekBarVaria.setThumb(getResources().getDrawable(R.drawable.buttonseekbar)); seekBarVaria.setThumbOffset(-3); seekBarVaria.setOnSeekBarChangeListener(this); seekBarVaria.setPadding(0, 0, 15, 7); leftPan.addView(state); leftPan.addView(seekBarVaria); rightPan.addView(leftPan); bodyPanHorizontal.addView(rightPan); super.LL_topPan.removeView(super.LL_featurePan); super.LL_infoPan.addView(bodyPanHorizontal); handler = new Handler() { @Override public void handleMessage(Message msg) { /// Deprecated method to die ///////////////////////////////////////// if (activate) { Tracer.d(mytag, "Handler receives a request to die "); //That seems to be a zombie removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself /////////////////////////////////////////////////////////////////// } else { int new_val = 0; if (msg.what == 9999) { //state_engine send us a signal to notify value changed if (session == null) return; try { Tracer.d(mytag, "Handler receives a new value from cache_engine <" + session.getValue() + ">"); new_val = Integer.parseInt(session.getValue()); } catch (Exception e) { new_val = 0; } //#1649 //Value min and max should be the limit of the widget if (new_val <= valueMin) { state.setText(stateS + valueMin + " " + test_unite); } else if (new_val > valueMin && new_val < valueMax) { state.setText(stateS + new_val + " " + test_unite); } else if (new_val >= valueMax) { state.setText(stateS + valueMax + " " + test_unite); } state.setAnimation(animation); new SBAnim(seekBarVaria.getProgress(), new_val - valueMin).execute(); } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "state engine disappeared ===> Harakiri !"); session = null; realtime = false; removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } } }; //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (Tracer.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ }
From source file:org.musicmod.android.dialog.EqualizerDialog.java
private void setupEqualizerFxAndUI(int audioSessionId) { // Create the Equalizer object (an AudioEffect subclass) and attach it // to our media player, with a default priority (0). mEqualizer = new EqualizerWrapper(0, audioSessionId); if (mEqualizer == null) { finish();/* ww w . j ava 2s. c o m*/ return; } mEqualizer.setEnabled(false); short bands = mEqualizer.getNumberOfBands(); final short minEQLevel = mEqualizer.getBandLevelRange()[0]; final short maxEQLevel = mEqualizer.getBandLevelRange()[1]; mLinearLayout.removeAllViews(); for (short i = 0; i < bands; i++) { final short band = i; TextView freqTextView = new TextView(this); freqTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); freqTextView.setGravity(Gravity.CENTER_HORIZONTAL); if (mEqualizer.getCenterFreq(band) / 1000 < 1000) { freqTextView.setText((mEqualizer.getCenterFreq(band) / 1000) + " Hz"); } else { freqTextView.setText(((float) mEqualizer.getCenterFreq(band) / 1000 / 1000) + " KHz"); } mLinearLayout.addView(freqTextView); LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); TextView minDbTextView = new TextView(this); minDbTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); minDbTextView.setText((minEQLevel / 100) + " dB"); TextView maxDbTextView = new TextView(this); maxDbTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); maxDbTextView.setText((maxEQLevel / 100) + " dB"); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.weight = 1; SeekBar bar = new SeekBar(this); bar.setLayoutParams(layoutParams); bar.setMax(maxEQLevel - minEQLevel); bar.setProgress(mPrefs.getEqualizerSetting(band, (short) ((maxEQLevel + minEQLevel) / 2)) - minEQLevel); mEqualizer.setBandLevel(band, mPrefs.getEqualizerSetting(band, (short) ((maxEQLevel + minEQLevel) / 2))); bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mEqualizer.setBandLevel(band, (short) (minEQLevel + progress)); mPrefs.setEqualizerSetting(band, (short) (minEQLevel + progress)); reloadEqualizer(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); row.addView(minDbTextView); row.addView(bar); row.addView(maxDbTextView); mLinearLayout.addView(row); } }
From source file:oyagev.projects.android.ArduCopter.BluetoothChat.java
private void addControl(String name, String type, int commandValue) { Log.d(TAG, "Adding cmd: " + commandValue); LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); View view = new TextView(this); //hidden view for command value TextView cmdView = new TextView(this); cmdView.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); cmdView.setVisibility(View.INVISIBLE); cmdView.setText(String.valueOf(commandValue)); cmdView.setTag("cmd"); //Setup the control if (type.equals("Button")) { view = new Button(this); ((Button) view).setText(name); ((Button) view).setOnClickListener(new OnClickListener() { @Override// www . j a v a 2 s . c om public void onClick(View v) { TextView cmd = (TextView) ((LinearLayout) v.getParent()).findViewWithTag("cmd"); dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), new byte[] { 1 }); } }); } else if (type.equals("Edit")) { view = new EditText(this); ((EditText) view).setText(name); } else if (type.equals("Label")) { view = new TextView(this); ((TextView) view).setText(name); } else if (type.equals("Scrollbar")) { view = new LinearLayout(this); TextView text = new TextView(this); text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); text.setText(name); text.setTag("seek_text"); SeekBar bar = new SeekBar(this); bar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); ((LinearLayout) view).setOrientation(LinearLayout.VERTICAL); ((LinearLayout) view).addView(text); ((LinearLayout) view).addView(bar); bar.setOnSeekBarChangeListener(new 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) { TextView cmd = (TextView) ((LinearLayout) ((LinearLayout) seekBar.getParent()).getParent()) .findViewWithTag("cmd"); ByteBuffer buffer = ByteBuffer.allocate(2); buffer.putShort((short) progress); dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), buffer.array()); } }); } else if (type.equals("Input String")) { view = new LinearLayout(this); TextView text = new TextView(this); text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); text.setText(name); text.setTag("inp_text"); TextView inp = new TextView(this); inp.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); //((LinearLayout)view).setOrientation(LinearLayout.VERTICAL); ((LinearLayout) view).addView(text); ((LinearLayout) view).addView(inp); ycomm.registerCallback((byte) commandValue, new CallbackView(getApplicationContext(), inp) { @Override public void run(byte type, byte command, byte[] data, byte data_langth) { // TODO Auto-generated method stub String str = new String(data); ((TextView) this.view).setText(str); } }); } else { return; } view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); row.addView(cmdView); row.addView(view); ((LinearLayout) findViewById(R.id.controls_layout)).addView(row); }