In my app i have to apply resize using seekbar to selected image onclick but problem is that only last applied stickerview can be resized and if i want to resize the previous stickerview then also last sticker is being resized.
Can anyone help me with this problem
holder.icon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (a == 1) {
canvas.setBackgroundResource(mThumbIds[position]);
dialog.dismiss();
a = 0;
}
if (a1 == 1) {
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setSpacing(1);
final GalleryImageAdapter galleryImageAdapter= new GalleryImageAdapter(getApplicationContext(),position);
gallery.setAdapter(galleryImageAdapter);
gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
if(x ==1)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds[position]);
if(x ==2)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds1[position]);
if(x ==3)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds2[position]);
canvas.addView(iv_sticker1);
}
});
a1 = 0;
}
if (a2 == 1) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
iv_sticker1.setImageDrawable(getResources().getDrawable(mThumbIds2[position]));
canvas.addView(iv_sticker1);
iv_sticker1.setOwnerId(2);
dialog.dismiss();
a2 = 0;
}
if (a3 == 1) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
iv_sticker1.setImageDrawable(getResources().getDrawable(mThumbIds3[position]));
canvas.addView(iv_sticker1);
dialog.dismiss();
a3 = 0;
}
}
});
And this is my resize program
final SeekBar sk1 = (SeekBar) findViewById(R.id.seekBar1);
sk1.setMax(500);
sk1.setOnSeekBarChangeListener(new SeekBar.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
iv_sticker1.getMainView();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(progress, progress);
iv_sticker1.setLayoutParams(params);
iv_sticker1.setMinimumWidth(progress);
iv_sticker1.setMinimumHeight(progress);
}
});
Now whenever i do this only last iv_sticker1 get selected.How can i apply resize to selected image on click?
Related
Here is my MainActivity Where I want to send the chosen GIF To the Wallpaper Service class using Uri :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(i, 0);
}
});
Button btn1;
btn1 = findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0){
Uri uri = data.getData();
Intent i = new Intent(MainActivity.this,one.class);
i.putExtra("ayush",uri.toString());
startActivity(i);
////////////////
}
}
}
And here is my Second Activity where I want to Receive the Gif data and put it on the movie decode stream. Please Suggest me some ways. Please suggest me some ways to do it.
public void onDestroy() {
super.onDestroy();
}
#Override
public Engine onCreateEngine() {
// TODO Auto-generated method stub
try {
//Movie movie=Movie.decodeStream(getResources().getMovie(R.drawable.endless_staircase));
Movie movie = getResources().getMovie(Intent.getIntent(Uri.parse(//I want to use the get intent extra here )));
return new GIFWallpaperEngine(movie);
} catch (Exception e) {
// TODO: handle exception
Log.d("GIF", "Could Not load Asset");
return null;
}
}
private class GIFWallpaperEngine extends Engine {
private final int frameDuration = 20;
private SurfaceHolder holder;
private Movie movie;
private boolean visible;
private Handler handler;
int mWhen;
long mStart;
float mScaleX, mScaleY;
public GIFWallpaperEngine(Movie movie) {
this.movie = movie;
handler = new Handler();
mWhen = -1;
}
#Override
public void onCreate(SurfaceHolder surfaceHolder) {
// TODO Auto-generated method stub
super.onCreate(surfaceHolder);//tick();
this.holder = surfaceHolder;
}
private void draw() {
tick();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
canvas.save();
canvas.scale(mScaleX, mScaleY);
if (canvas != null) {
movie.draw(canvas, 0, 0);
}
canvas.restore();
// holder.unlockCanvasAndPost(canvas);
//movie.setTime(((int)(SystemClock.uptimeMillis()-SystemClock.uptimeMillis())%(movie.duration())));
//movie.setTime((int)((System.currentTimeMillis()%movie.duration())));
movie.setTime(mWhen);
} finally {
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
handler.removeCallbacks(drawGIF);
if (visible) handler.postDelayed(drawGIF, 1000L / 25L);
}
void tick() {
int dur = movie.duration();
if (mWhen == -1L) {
mWhen = 0;
mStart = SystemClock.uptimeMillis();
} else {
long mDiff = SystemClock.uptimeMillis() - mStart;
mWhen = (int) (mDiff % dur);
}
}
#Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub
super.onSurfaceChanged(holder, format, width, height);
mScaleX = width / (1f * movie.width());
mScaleY = height / (1f * movie.height());
draw();
}
private Runnable drawGIF = new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
draw();
}
};
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
handler.removeCallbacks(drawGIF);
}
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
//super.onVisibilityChanged(visible);
this.visible = visible;
if (visible) {
handler.post(drawGIF);
} else {
handler.removeCallbacks(drawGIF);
}
}
}
}
Please Suggest me Some Ways to do it.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to create a progress barProgressBar screenshot like given image where the star image should reduce based on time(every second). So,Please guide me how to do? I am using the handler for countdown timer
timeString* we are getting it from different class
String timestring = getIntent().getStringExtra("ageintent");
timereceived = Integer.parseInt(timestring);
seekbar.setMax(timereceived);
seekbar.setClickable(false);
timereceived--;
time.setText(String.valueOf(timereceived));
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
handler = new Handler();
run = new Runnable() {
#Override
public void run() {
int seconds = Integer.parseInt(timeseconds.getText().toString());
int timechange = Integer.parseInt(time.getText().toString());
seekbar.setProgress(seconds);
seconds--;
timeseconds.setText(String.valueOf(seconds));
if (seconds == 0 && timechange == 0) {
Toast.makeText(Naughty_Step.this, "Your punishment is completed", Toast.LENGTH_SHORT).show();
soundplayer.start();
timereceived--;
} else if (seconds == 0) {
timeseconds.setText("59");
timechange--;
seekbar.setProgress(seconds);
time.setText(String.valueOf(timechange));
// int min= Integer.parseInt(time.getText().toString());
// seekbar.setProgress(min);
handler.postDelayed(this, 1000);
} else {
handler.postDelayed(this, 1000);
}
}
};
handler.postDelayed(run, 1000);
}
Try below -
SeekBar seekBar1 = (SeekBar)findViewById(R.id.seekBar1);
drw = getResources().getDrawable(R.drawable.ic_launcher);
seekBar1.setOnSeekBarChangeListener(new yourListener());
private class yourListener implements SeekBar.OnSeekBarChangeListener {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
iSize = 100 - progress;
tv.setText(String.valueOf(new Integer(progress)));
drw = resize(drw);
seekBar.setThumb(drw);
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
}
//Reduce size of seekbar
private Drawable resize(Drawable image) {
Bitmap b = ((BitmapDrawable)image).getBitmap();
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, iSize, iSize, false);
return new BitmapDrawable(getResources(), bitmapResized);
}
Add this as inner class of your activity or fragment need progressbar reduce.
class CounterClass extends CountDownTimer {
int totalDuration;
public CounterClass(long millisInFeature, long countDownInterval) {
// TODO Auto-generated constructor stub
super(millisInFeature , countDownInterval);
this.totalDuration =millisInFeature
}
#Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
int progress =((millisUntilFinished * 100 / totalDuration))
progressbar.setProgress(progress);
}
#Override
public void onFinish() {
// TODO Auto-generated method stub
}
oncreate() or event start
(new CounterClass(30000,1000)).start();
In my SMS app, I have a dialog that opens when the user clicks on an attached image to expand it.
Everything worked fine until I decided to add animations. This dialog has 3 buttons (one close ImageButton in the top right corner and two buttons in a bottom bar of the dialog). When the user clicks on the image, the buttons anime out/in. This all works fine except the buttons are still clickable even after they're hidden.
Before Animations:
After Animations:
My code for the dialog below:
// Declare these here to increase scope. (Listeners)
private static boolean ContainerChanged;
private static boolean ActionsHidden;
private static boolean AnimStarted;
private static boolean closeAnimFinished;
private static boolean barAnimFinished;
private void showExpandedImageDialog(Uri imgUri)
{
// Initialize Dialog
final Dialog dialog = new Dialog(ActivitySend.this, R.style.FullHeightDialog);
dialog.setContentView(R.layout.dialog_attachment_image_send);
// Initialize Views
final RelativeLayout Container = (RelativeLayout) dialog.findViewById(R.id.Container);
final LinearLayout actions = (LinearLayout) dialog.findViewById(R.id.Actions);
final ImageButton btnClose = (ImageButton) dialog.findViewById(R.id.btnClose);
Button btnReplace = (Button) dialog.findViewById(R.id.btnReplace);
Button btnRemove = (Button) dialog.findViewById(R.id.btnRemove);
ImageView image = (ImageView) dialog.findViewById(R.id.Image);
// Load Image & Make Zoomable
PhotoViewAttacher mAttacher = new PhotoViewAttacher(image);
image.setImageURI(imgUri);
mAttacher.update();
// Get animations ready
final Animation fiCloseAnim = AnimationUtils.loadAnimation(ActivitySend.this, R.anim.fade_in);
fiCloseAnim.setFillEnabled(true);
fiCloseAnim.setFillAfter(true);
final Animation foCloseAnim = AnimationUtils.loadAnimation(ActivitySend.this, R.anim.fade_out);
foCloseAnim.setFillEnabled(true);
foCloseAnim.setFillAfter(true);
final Animation dBarAnim = AnimationUtils.loadAnimation(ActivitySend.this, R.anim.slide_down);
dBarAnim.setFillEnabled(true);
dBarAnim.setFillAfter(true);
final Animation uBarAnim = AnimationUtils.loadAnimation(ActivitySend.this, R.anim.slide_up);
uBarAnim.setFillEnabled(true);
uBarAnim.setFillAfter(true);
// Reset static variables
ActionsHidden = false;
AnimStarted = false;
closeAnimFinished = false;
barAnimFinished = false;
// Initialize listeners
AnimationListener closeAnimListener = new AnimationListener()
{
#Override
public void onAnimationEnd(Animation animation)
{
closeAnimFinished = true;
if (closeAnimFinished && barAnimFinished)
{
AnimStarted = false;
closeAnimFinished = false;
barAnimFinished = false;
if (ActionsHidden)
{
actions.setVisibility(View.VISIBLE);
btnClose.setVisibility(View.VISIBLE);
}
else
{
actions.setVisibility(View.GONE);
btnClose.setVisibility(View.GONE);
}
ActionsHidden = !ActionsHidden;
}
}
#Override
public void onAnimationRepeat(Animation animation)
{
// Nothing
}
#Override
public void onAnimationStart(Animation animation)
{
AnimStarted = true;
}
};
AnimationListener barAnimListener = new AnimationListener()
{
#Override
public void onAnimationEnd(Animation animation)
{
barAnimFinished = true;
if (closeAnimFinished && barAnimFinished)
{
AnimStarted = false;
closeAnimFinished = false;
barAnimFinished = false;
if (ActionsHidden)
{
actions.setVisibility(View.VISIBLE);
btnClose.setVisibility(View.VISIBLE);
}
else
{
actions.setVisibility(View.GONE);
btnClose.setVisibility(View.GONE);
}
ActionsHidden = !ActionsHidden;
}
}
#Override
public void onAnimationRepeat(Animation animation)
{
// Nothing
}
#Override
public void onAnimationStart(Animation animation)
{
AnimStarted = true;
}
};
// Set listeners
fiCloseAnim.setAnimationListener(closeAnimListener);
foCloseAnim.setAnimationListener(closeAnimListener);
dBarAnim.setAnimationListener(barAnimListener);
uBarAnim.setAnimationListener(barAnimListener);
// Actions Appear/Disappear onTap (Animate)
mAttacher.setOnPhotoTapListener(new OnPhotoTapListener()
{
#Override
public void onPhotoTap(View view, float x, float y)
{
if (!AnimStarted && ActionsHidden)
{
actions.startAnimation(uBarAnim);
btnClose.startAnimation(fiCloseAnim);
}
else if (!AnimStarted)
{
actions.startAnimation(dBarAnim);
btnClose.startAnimation(foCloseAnim);
}
}
});
// Make dialog square
ContainerChanged = false;
ViewTreeObserver vto = Container.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
{
public boolean onPreDraw()
{
// Set boolean to save processing power
if (!ContainerChanged)
{
int width = Container.getMeasuredWidth();
Container.getLayoutParams().height = width;
ContainerChanged = true;
}
return true;
}
});
// Set button listeners
btnClose.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
dialog.dismiss();
}
});
btnReplace.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
}
});
btnRemove.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
}
});
// Show dialog
dialog.show();
}
Everything works perfectly if I remove the animations and only use view.setVisibility(View.GONE) but I really like the animations...
Any ideas on what I could do to fix this?
I could probably use view.setClickable(false); but I'm sure there's a better solution than that.
You can do it like this:
Let your activity implement AnimationListener. Then there will be an overridden method public void onAnimationEnd(Animation arg0), write setClickable(false) or setEnabled(false) in this method for all three of your buttons, enable them again when you are starting your animation....hope you got me..
I want to get value from seekbar in my application every time I touch it. The value that I declared in seekbar will be added in my url but each time I touch the seekbar it gives me a looping and the url will loop and loaded as amount seekbar on progressChanged. This is my code:
int period = 0;
SeekTime.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) {
// TODO Auto-generated method stub
if (SeekTime.getProgress() <= 3){
SeekTime.setProgress(0);
period=7;
}
if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
SeekTime.setProgress(5);
period =30;
}
if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
SeekTime.setProgress(10);
period = 90;
}
if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
SeekTime.setProgress(15);
period = 180;
}
if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
SeekTime.setProgress(20);
period = 270;
}
if (SeekTime.getProgress() >23){
SeekTime.setProgress(25);
period = 360;
}
new LoadData(URL+period).execute();
I think that the problem that you get is because when you call SeekTime.setProgress() the progress is being changed - it calls onProgressChange() again.
What you should do is to check, if the progress change have been done by user. You have fromUser variable that allows you to control that.
int period = 0;
SeekTime.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) {
// TODO Auto-generated method stub
if(fromUser) {
if (SeekTime.getProgress() <= 3){
SeekTime.setProgress(0);
period=7;
}
if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
SeekTime.setProgress(5);
period =30;
}
if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
SeekTime.setProgress(10);
period = 90;
}
if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
SeekTime.setProgress(15);
period = 180;
}
if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
SeekTime.setProgress(20);
period = 270;
}
if (SeekTime.getProgress() >23){
SeekTime.setProgress(25);
period = 360;
}
new LoadData(URL+period).execute();
}
}
i uses seekBar to pass value increase/decrease by user... i put the initial value of barValue=50. when user drag seekbar lesser than current value.. the a,b decreases by 0.00001.
Problem i face. its only do the IF condition onced. after seekBar updated.. no changes on a and b.
public static double a,b;
public static int barValue;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
a= location.getLatitude();
b= location.getLongitude();
bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this); // set seekbar listener.
barValue = 50;
bar.setProgress(barValue);
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
if (progress > barValue)
{
a += seekBar.getProgress()/10000;
b += seekBar.getProgress()/10000;
getSensorManager().enableMockLocation(a, b);
}
else if(progress < barValue)
{
a -= seekBar.getProgress()/10000;
b -= seekBar.getProgress()/10000;
getSensorManager().enableMockLocation(a, b);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
seekBar.setSecondaryProgress(seekBar.getProgress());
barValue = seekBar.getProgress();
}