i have made a seekbar zoom controler for my map view as follows
myZoomBar = (SeekBar)findViewById(R.id.zoombar);
SetZoomLevel();
myZoomBar.setOnSeekBarChangeListener(myZoomBarOnSeekBarChangeListener);
and
private SeekBar.OnSeekBarChangeListener myZoomBarOnSeekBarChangeListener =
new SeekBar.OnSeekBarChangeListener(){
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
SetZoomLevel();
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
};
private void SetZoomLevel()
{
int myZoomLevel = myZoomBar.getProgress()+1;
mc.setZoom(myZoomLevel);
Toast.makeText(this,
"Zoom Level : " + String.valueOf(myZoomLevel),
Toast.LENGTH_LONG).show();
};
my question is how can i set the default view level to 15? As it is right now when the map opens it is zoomed out all the way.
try below code
MaView mapView = (MapView)findViewById(R.id.my_map);
MapController mapController = mapView.getController();
mapController.setZoom(15);
Use setZoom() method of MapController class in your MapActivity .
Related
I have the following code that changes the opacity of the frame animation with the help of a seekbar, now i'm trying to control the duration of frame animation with the help of this seek bar, can anybody help me in telling that if it is possible?
The code:
ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
//Create a new AnimationDrawable
final AnimationDrawable myAnimationDrawable
= createAnimationDrawable();
//apply the new AnimationDrawable
myAnimation.setImageDrawable(myAnimationDrawable);
SeekBar setAnimationAlpha = (SeekBar)findViewById(R.id.setalpha);
Button startAnimation = (Button)findViewById(R.id.startanimation);
Button stopAnimation = (Button)findViewById(R.id.stopanimation);
startAnimation.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(!myAnimationDrawable.isRunning()){
myAnimationDrawable.start();
}
}});
stopAnimation.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(myAnimationDrawable.isRunning()){
myAnimationDrawable.stop();
}
}});
setAnimationAlpha.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
myAnimationDrawable.setAlpha(progress);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}});
}
private AnimationDrawable createAnimationDrawable(){
AnimationDrawable newAnim = new AnimationDrawable();
newAnim.addFrame(getResources().getDrawable(R.drawable.android_1), 90);
newAnim.addFrame(getResources().getDrawable(R.drawable.android_2), 90);
newAnim.addFrame(getResources().getDrawable(R.drawable.android_3), 90);
newAnim.addFrame(getResources().getDrawable(R.drawable.android_4), 90);
newAnim.addFrame(getResources().getDrawable(R.drawable.android_5), 90);
newAnim.addFrame(getResources().getDrawable(R.drawable.android_6), 90);
newAnim.addFrame(getResources().getDrawable(R.drawable.android_7), 90);
newAnim.setOneShot(false);
return newAnim;
}
}
I want to resize image by using seekbar. Seekbar is working but its not giving any good results. With the following code, the image is resized but just when you change the progress of seekbar for the first time. Please help
Seekbar listener
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progresValue,
boolean fromUser) {
// TODO Auto-generated method stub
progresValue = progress;
resizeImage(image, progresValue);
}
});
Function to resize image
public void resizeImage(Bitmap bitmap, int progress) {
Bitmap bitmapSource = bitmap;
float bHeight = bitmapSource.getHeight();
float bWidth = bitmapSource.getWidth();
float factorH = progress / (float) bHeight;
float factorW = progress / (float) bWidth;
float factorToUse = (factorH > factorW) ? factorW : factorH;
Bitmap bm = Bitmap.createScaledBitmap(bitmapSource,
(int)(bWidth * factorToUse), (int)(bHeight * factorToUse),
false);
qImage.setImageBitmap(bm);
}
final SeekBar sk1 = (SeekBar) findViewById(R.id.seekBar1);
sk1.setMax(500);
sk1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(progress,progress);
img.setLayoutParams(params);
img.setMinimumWidth(progress);
img.setMinimumHeight(progress);
}
});
Hi im having a bit of problems getting my sprite to fade back in. Im using paralell entity modifiers, scaling and fading after which the sprite gets new X and Y cordinates and fades in and scales back up. It doesnt work and i think it might have something to do with the onUpdate method.
XOsprite = new Sprite(x, y, XO, engine.getVertexBufferObjectManager()) {
#Override
public boolean onAreaTouched(final TouchEvent te, final float xVal,
final float yVal) {
XOsprite.registerEntityModifier(downOut); //kill sprite
isKilled = true;
XOsprite.registerUpdateHandler(new IUpdateHandler() {
#Override
public void reset() {
// TODO Auto-generated method stub
}
#Override
public void onUpdate(float pSecondsElapsed) {
// TODO Auto-generated method stub
totalElapsedTime += pSecondsElapsed;
if(totalElapsedTime >= 3.0f){
BaseGameActivity gameActivity = (BaseGameActivity) activity;
gameActivity.runOnUpdateThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if(isKilled){
reviveSprite();
isKilled = false;
}
}
});
}
//reset();
}
});
return true;
}
};
XOsprite.registerEntityModifier(inUp);
gameScene.attachChild(XOsprite);
gameScene.registerTouchArea(XOsprite);
return gameScene;
}
-edit- more code
public void reviveSprite(){
setSprites();
XOsprite.unregisterEntityModifier(downOut);
XOsprite.registerEntityModifier(inUp);
}
public void setSprites(){
if (rand.nextInt(2) == 0) {
XO = X;
} else {
XO = O;
}
x = rand.nextInt(MainActivity.CAM_WIDTH);
y = rand.nextInt(MainActivity.CAM_HEIGHT);
}
you are already on the UpdateThread, so no need to do this
gameActivity.runOnUpdateThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if(isKilled){
reviveSprite();
isKilled = false;
}
}
});
just do this
if(isKilled){
reviveSprite();
isKilled = false;
}
I am using a seekbar, and I want to add certain marks in the seekbar with text to use it as a scale. The selected interval points should be highlighted.
The corresponding code is here:
seekbar = (SeekBar) findViewById(R.id.seekBar1);
seekbar.setMax(max);
seekbar.setProgress(50);
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
value.setText("SeekBar value is " + progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
To make the above seek bar you first have to add a measuring scale as a background drawable. Then you'll have to make textboxes for each interval on the measuring scale.
<SeekBar
....
android:progressDrawable="#drawable/progress"
android:thumb="#drawable/thumb"
....
/>
Then
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
progress = ((int)Math.round(progress/interval))*interval;
seekBar.setProgress(progress);
if(progress==5) textBox5.setTextColor(Color.RED);
else if(progress==10) textBox10.setTextColor(Color.RED);
//......... for all the text boxes.
}
Actually, all The above solutions force to select the last progress point, which is not logic.
To make it mire accurete, Seek bar must detect which is the nearest dot and jump to it.
So below is the solution,
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progressStep = getMax() / dotsCount;
int lastDotProgress = Math.round(getProgress() / progressStep) * progressStep;
int nextDotProgress = lastDotProgress + progressStep;
int midBetweenDots = lastDotProgress + (progressStep / 2);
if (getProgress() > midBetweenDots)
seekBar.setProgress(nextDotProgress);
else
seekBar.setProgress(lastDotProgress);
}
You can use same behavior in onProgressChanged() if you want to prevent seeking between dots
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int s_size=5;
progress = ((int)Math.round(progress/s_size))*s_size;
seekBar.setProgress(progress);
textview.setText(progress + "");
}
what you want to settext get easily get from progress and
textview.settext() value
I have a seekbar for example: from 0 to 10. How can I make if I want to set seekbar to 5 as default position. So in this example seekbar should start from middle.
Use this one
android:progress="5"
Like "progress", it inherits some of it's attributes from ProgressBar. You find all the attributes at http://developer.android.com/reference/android/widget/SeekBar.html
To get Seekbar at the value of 5
In the xml layout use the max value as 10
android:max="10"
In the java for seekbar to get at progress 5
seekbar = (SeekBar) findViewById(R.id.seekBar1);
seekbar.setProgress(5);
thats it :)
I hope this code surely helps you.
Try this...
float discrete=0;
float start=0;
float end=100;
float start_pos=0;
int start_position=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start=-10; //you need to give starting value of SeekBar
end=10; //you need to give end value of SeekBar
start_pos=5; //you need to give starting position value of SeekBar
start_position=(int) (((start_pos-start)/(end-start))*100);
discrete=start_pos;
SeekBar seek=(SeekBar) findViewById(R.id.seekBar1);
seek.setProgress(start_position);
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "discrete = "+String.valueOf(discrete), Toast.LENGTH_SHORT).show();
}
#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
// To convert it as discrete value
float temp=progress;
float dis=end-start;
discrete=(start+((temp/100)*dis));
}
});
}
default value By xml :
android:progress="5"
max value by xml
android:max="10"
final Timer timer = new Timer();
seekBar_efficiency.setMax(40);
seekBar_efficiency.setProgress(35);
timer.schedule(new TimerTask() {
#Override
public void run() {
seekBar_efficiency.setProgress(20);
timer.cancel();
}
}, 200, 50);