i have an activity which contain this seekbar and have another view of drawing which is drawing circle in Ondraw() mathod,i dont get any solution can anyone help.
here is my code
Activity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crop);
layout = (LinearLayout) findViewById(R.id.layout);
sk = (SeekBar) findViewById(R.id.seekBar);
drawing= new DrawView(this);
sk.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
size = i + 10;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
layout.addView(drawing);
}
here is my View have this mathod
#Override
public void onDraw(Canvas canvas) {
canvas.drawBitmap(resulting, 0, 0, null);
canvas.drawPath(circlePath, circlePaint);
canvas.drawCircle(x,y,size/2,showpaint);
}
my problem is how to draw circle on realtime when seekbar is changing,if you need any further detail tell me.
Try adding an updateSize(int size) method to the drawable that calls invalidate() to redraw every time the size changes.
Related
I want to fully dim my screen brightness programmatically using seekbar I am using this code to do the operation but it does not dim the screen brightness fully.I want to remove the screen brightness completely
code:
public class Night extends AppCompatActivity {
private SeekBar brightbar;
private int brightness;
private ContentResolver contentResolver;
private android.view.Window window;
TextView txtPerc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_night);
brightbar=(SeekBar)findViewById(R.id.brightbar);
txtPerc=(TextView)findViewById(R.id.txtPercentage);
contentResolver=getContentResolver();
window=getWindow();
brightbar.setMax(255);
brightbar.setKeyProgressIncrement(1);
try{
brightness= Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS);
}catch (Exception e) {
e.printStackTrace();
}
brightbar.setProgress(brightness);
brightbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (progress<=5)
{
brightness=5;
}else {
brightness=progress;
}
float perc=(brightness/(float)255)*100;
txtPerc.setText((int)perc + "%");
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS,brightness);
WindowManager.LayoutParams layoutpars=window.getAttributes();
layoutpars.screenBrightness=brightness/(float)255;
window.setAttributes(layoutpars);
}
});
}
}
Can anyone suggest me how can I do that.
most "nightmode"/"protect your eyes" kind of apps uses a service with a View covering the whole screen.
they then set the transparency/alpha of this view according to how dark you want. the background color can be different hues or black.
take a look at this question which shows how to create a view from a service Starting a View from a Service?
hope it helps.
use bellow code it works for me
WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1F;
getWindow().setAttributes(layout);
I am just drawing a Circle with canvas, and change the radius with a SeekBar. This Code works fine on Emulator, but on my phone the remove View thing doesn't work. Means the circle gets bigger and bigger, but not smaller on my phone.
What is the problem here ?
my Code:
public class Kreis extends Activity implements OnSeekBarChangeListener {
private SeekBar seekbar;
public static int radius = 30;
private TextView textview;
private static View alterKreis;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_kreis);
this.seekbar = (SeekBar)findViewById(R.id.radiusbar);
this.textview = (TextView)findViewById(R.id.ausgabe);
seekbar.setOnSeekBarChangeListener(this);
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
radius = seekbar.getProgress();
textview.setText(radius + "");
RelativeLayout lp=new RelativeLayout(this);
Circle view = new Circle(this);
lp.removeView(view);
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
addContentView(view,params);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public class Circle extends View{
public Circle(Context context) {
super(context);
}
#Override
public void draw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.GREEN);
// if(radius>0){
canvas.drawCircle(200,200,radius,paint);
// }
}
}
}
private OnSeekBarChangeListener _onSizeChangeListener = new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
progress = progress+MIN_POINT_SIZE;
_view.getLayoutParams().height = progress;
_view.getLayoutParams().width = progress;
}
};
In the above piece of code,I want to change the width and height of _view as and when user seeks to some value from Seek bar control.But _view's attributes are not changing.Could some one look into it is there any wrong going?
Try this code in on progress changed,
LayoutParams newParams = new LayoutParams(progress,progress);
_view.setLayoutParams(newParams);
try to add:
_view.getRootView().requestLayout();
after you've update the LayoutParams dimensions.
I am trying to draw some text above the thumb of the SeekBar like in the image above. The idea is that when you move the thumb along the SeekBar text is displayed above the thumb. I am able to draw text inside the thumb but when I try and draw it outside the thumb it doesn't work. Below is my code:
public class MainActivity extends Activity {
SeekBar mybar;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mybar = (SeekBar) findViewById(R.id.seekBar1);
mybar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// add here your implementation
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// add here your implementation
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int value = seekBar.getProgress();
String valueString = value + "";
Paint paint = new Paint();
paint.setColor(Color.BLACK);
Bitmap b = Bitmap.createBitmap(600, 600,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.drawText(valueString, 100, 100, paint);
seekBar.draw(canvas);
}
});
}
}
Do I have to override the onDraw method and do it that way instead?
I am trying to change thumb of SeekBar from code. I want to change when someone click and I implement
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
seek.setThumb(getResources().getDrawable(R.drawable.red_rect));
}
#Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
}
});
At start I have default thumb and when I click it should change to red_rect, but when I click is that thumb disappear at all. Can someone help me how to solve this ?
You need to call setBounds() on Drawable after you get it from Resources:
final Drawable d = getResources().getDrawable(R.drawable.thumb);
d.setBounds(new Rect(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()));
slider.setThumb(d);
from http://www.mail-archive.com/android-developers#googlegroups.com/msg164344.html