Is seekBar
defined in the global scope?
Here is an example using buttons, textView, seekBar, Color, resources (ids and strings) and LinerLayout.
Need to consider that for this test the name of my temporal sketch was sketch_180627b . This is important as you will need to change this to the name of your sketch in the code below. This will allow you to access resources defined as XML. Folder structure and files shown below.
Kf
C:\Users\C\AppData\Local\Temp\untitled3773019319882703841sketches>tree /f
Folder PATH listing for volume Windows8_OS
Volume serial number is 4E33-E988
C:.
└───sketch_180627b
│ AndroidManifest.xml
│ AppLifeCycle.pde
│ sketch.properties
│ sketch_180627b.pde
│
├───code
│ sketch.properties
│
└───res
└───values
ids.xml
strings.xml
FILE: ids.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="button_text_change" />
</resources>
FILE: strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="string_button_text_change">Random Msg!</string>
</resources>
FILE: sketch_180627b.pde
//REFERENCE: https://discourse.processing.org/t/android-seekbar-slider/1245/2
//REFERENCE: https://forum.processing.org/two/discussion/26349/android-input-box
//REFERENCE: https://forum.processing.org/two/discussion/26515/scrollable-image-with-scrollview
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.app.Activity;
import android.content.Context;
import android.widget.FrameLayout;
import android.widget.Toast;
import android.os.Looper;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.R;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.LinearLayout;
import android.graphics.Color;
import processing.android.CompatUtils;
final String MSGS[]={"Today is fun", "Yesterday is sunny", "Tomorrow is a new day", "See you soon", "Hey, what's up?"};
final int UNKNOWN_ID=-1;
final color BGCOLOR=color(10, 10, 250);
final int MAX_ALPHA=256;
final int MAX_RED=256;
Activity act;
Context mC;
FrameLayout fl;
//SeekBar seekBar;
int tvId=UNKNOWN_ID;
int btTvId=UNKNOWN_ID;
int btToastId=UNKNOWN_ID;
int btSliderId=UNKNOWN_ID;
int sliderId=UNKNOWN_ID;
color beginLGcolor=color(255, 0, 0, 255);
color endLGcolor=color(255, 0, 0, 0);
float cProgressValueNorm=0;
void settings() {
size(displayWidth, displayHeight>>1, P2D);
}
void draw() {
background(BGCOLOR);
rectLinearGradient(width*0.25, height*0.25, width*0.75, height*0.75, beginLGcolor, endLGcolor);
}
void rectLinearGradient(float x0, float y0, float x1, float y1, color c1, color c2) {
if (x0>x1) {
println("Nothing done as x0, x1 are not valid");
return;
}
if (y0>y1) {
println("Nothing done as y0, y1 are not valid");
return;
}
pushStyle();
strokeWeight(1);
float deltaRow=y1-y0;
for (float row=y0; row<y1; row++) {
stroke(lerpColor(c1, c2, (row-y0)/deltaRow));
line(x0, row, x1, row);
}
popStyle();
}
void mouseReleased() {
println(tvId, btTvId, btToastId, btSliderId, sliderId);
}
@ Override
public void onStart() {
super.onStart();
act = this.getActivity();
mC= act.getApplicationContext();
// OOOOOOOOOOOOOOOO---------------------------OOOOOOOOOOOOOOOO
// OOOOOOOOOOOOOOOO---------------------------OOOOOOOOOOOOOOOO
act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
TextView tv = new TextView(this.getActivity());
tv.setTextSize(24);
tv.setTextColor(Color.rgb(20, 0, 0));
tv.setText ("No message yet!");
tv.setGravity(Gravity.RIGHT);
tvId=CompatUtils.getUniqueViewId();
tv.setId(tvId);
Button textSwitchButton= new Button(act);
textSwitchButton.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
textSwitchButton.setTextSize(10);
textSwitchButton.setText (processing.test.sketch_180627b.R.string.string_button_text_change); //https://developer.android.com/guide/topics/resources/string-resource#String
btTvId=processing.test.sketch_180627b.R.id.button_text_change; //CompatUtils.getUniqueViewId(); //com.example.sketch_180627b.
textSwitchButton.setId(btTvId);
textSwitchButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View V) {
//Code here
act.runOnUiThread(
new Runnable() {
public void run() {
TextView tvx = (TextView)act.findViewById(tvId);
if (tvx!=null) {
String msg=MSGS[int(random(MSGS.length))];
tvx.setText(msg);
} else {
println("TV view was not found!");
}
}
}
);
}
}
);
Button toastButton= new Button(act);
//https://stackoverflow.com/questions/5191099/how-to-set-relativelayout-layout-params-in-code-not-in-xml
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
toastButton.setLayoutParams(params);
//toastButton.setGravity(Gravity.CENTER_HORIZONTAL);
toastButton.setTextSize(10);
toastButton.setText ("Toast!");
btToastId=CompatUtils.getUniqueViewId();
toastButton.setId(btToastId);
toastButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View V) {
//Code here
Toast.makeText(mC, "Hello World!", Toast.LENGTH_SHORT).show();
}
}
);
Button sliderControlButton= new Button(act);
sliderControlButton.setTextSize(10);
sliderControlButton.setTextColor(Color.rgb(0, 0, 0));
sliderControlButton.setText ("Toggle Slider");
//sliderControlButton.setX(width*0.60);
//sliderControlButton.setY(200);
btSliderId=CompatUtils.getUniqueViewId();
sliderControlButton.setId(btSliderId);
sliderControlButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View V) {
//Code here
act.runOnUiThread(
new Runnable() {
public void run() {
SeekBar bar = (SeekBar)act.findViewById(sliderId);
if (bar!=null) {
if (bar.getVisibility()!=View.VISIBLE)bar.setVisibility(View.VISIBLE);
else bar.setVisibility(View.INVISIBLE);
} else {
println("Slider view was not found!");
}
}
}
);
}
}
);
SeekBar seekBar = new SeekBar(mC);
//seekBar.setLayoutParams (
// new RelativeLayout.LayoutParams (
// RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT
// )
// );
seekBar.setPadding(100, 100, 200, 0);
sliderId=CompatUtils.getUniqueViewId();
seekBar.setId(sliderId);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
//Value compute on onProgressChanged()
act.runOnUiThread(
new Runnable() {
public void run() {
Button but = (Button)act.findViewById(btSliderId);
if (but!=null) {
but.setTextColor(Color.rgb(cProgressValueNorm*MAX_RED, 0, 0));
}
}
}
);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
println(progress, seekBar.getMax());
cProgressValueNorm = progress/float(seekBar.getMax());
float aFactor=cProgressValueNorm * MAX_ALPHA;
endLGcolor=color(255, 0, 0, aFactor);
}
}
);
LinearLayout layoutContainer=new LinearLayout(act);
layoutContainer.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
layoutContainer.setOrientation(LinearLayout.VERTICAL);
layoutContainer.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
layoutContainer.addView(tv);
layoutContainer.addView(textSwitchButton);
layoutContainer.addView(toastButton, params);
layoutContainer.addView(sliderControlButton);
layoutContainer.addView(seekBar);
fl = (FrameLayout)act.findViewById(R.id.content);
fl.addView(layoutContainer);
}