List of usage examples for android.graphics.drawable AnimationDrawable start
@Override public void start()
From source file:com.adkdevelopment.simpleflashlightadfree.ui.EmergencyFragment.java
/** * Starts emergency sound from assets//w w w. j a v a 2 s . c o m */ public void emergencySignal() { try { if (mMediaPlayer != null && mMediaPlayer.isPlaying() && status == FlashlightService.STATUS_OFF) { mMediaPlayer.stop(); mMediaPlayer.reset(); mMediaPlayer.release(); mMediaPlayer = null; mLinearLayout.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorBackground)); } else if (status == FlashlightService.STATUS_BLINK) { final AnimationDrawable drawable = new AnimationDrawable(); final Handler handler = new Handler(); drawable.addFrame(new ColorDrawable(Color.RED), 400); drawable.addFrame(new ColorDrawable(Color.BLUE), 400); drawable.setOneShot(false); mLinearLayout.setBackground(drawable); handler.postDelayed(new Runnable() { @Override public void run() { drawable.start(); } }, 100); mMediaPlayer = new MediaPlayer(); AssetFileDescriptor descriptor = getActivity().getAssets().openFd("sews.mp3"); mMediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); mMediaPlayer.prepare(); mMediaPlayer.setVolume(1f, 1f); mMediaPlayer.setLooping(true); mMediaPlayer.start(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:android.support.v7.app.MediaRouteButton.java
private void refreshRoute() { if (mAttachedToWindow) { final MediaRouter.RouteInfo route = mRouter.getSelectedRoute(); final boolean isRemote = !route.isDefaultOrBluetooth() && route.matchesSelector(mSelector); final boolean isConnecting = isRemote && route.isConnecting(); boolean needsRefresh = false; if (mRemoteActive != isRemote) { mRemoteActive = isRemote;// ww w. ja va 2 s . com needsRefresh = true; } if (mIsConnecting != isConnecting) { mIsConnecting = isConnecting; needsRefresh = true; } if (needsRefresh) { refreshDrawableState(); if (mRemoteIndicator.getCurrent() instanceof AnimationDrawable) { AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent(); if (!curDrawable.isRunning()) { curDrawable.start(); } } } } }
From source file:com.example.linkagescroll.widget.PagerSlidingTabStrip.java
private void setChooseTab(int position) { int childCount = tabsContainer.getChildCount(); if (pager.getAdapter() instanceof IconTabProvider) { ImageButton tab;/*from ww w . j av a 2 s .c o m*/ for (int i = 0; i < childCount; ++i) { tab = (ImageButton) tabsContainer.getChildAt(i); if (i == position) { tab.setImageResource(((IconTabProvider) pager.getAdapter()).getPageIconResId(i)); Drawable drawable = tab.getDrawable(); if (drawable instanceof AnimationDrawable) { AnimationDrawable animationDrawable = (AnimationDrawable) drawable; animationDrawable.start(); } } else { tab.setImageResource(((IconTabProvider) pager.getAdapter()).getUnselectPageIconResId(i)); } } } else { for (int i = 0; i < childCount; ++i) { TextView tab; tab = (TextView) tabsContainer.getChildAt(i); if (i == position) { tab.setTextColor(tabTextSelectColor); } else { tab.setTextColor(tabTextColor); } } } }
From source file:com.tdispatch.passenger.core.TDFragment.java
protected void lockUI(Boolean lockUI) { View v = mFragmentView.findViewById(R.id.tdfragment_busy_overlay_container); if (v != null) { AnimationDrawable busyAnim = (AnimationDrawable) ((ImageView) mFragmentView .findViewById(R.id.tdfragment_busy)).getBackground(); if (lockUI) { // // hide soft menu // InputMethodManager imm = (InputMethodManager)mContext.getSystemService( Context.INPUT_METHOD_SERVICE); // imm.hideSoftInputFromWindow(v.getWindowToken(), 0); if (getOverlayBackgroundResourceId() != null) { v.setBackgroundResource(getOverlayBackgroundResourceId()); }//from w ww. j a v a2 s . com busyAnim.start(); v.setVisibility(View.VISIBLE); } else { v.setVisibility(View.GONE); busyAnim.stop(); } } else { WebnetLog.d("No lockUI overlay"); } }
From source file:androidx.mediarouter.app.MediaRouteButton.java
/** * Sets a drawable to use as the remote route indicator. *//*from w ww . j ava2 s.c o m*/ public void setRemoteIndicatorDrawable(Drawable d) { if (mRemoteIndicatorLoader != null) { mRemoteIndicatorLoader.cancel(false); } if (mRemoteIndicator != null) { mRemoteIndicator.setCallback(null); unscheduleDrawable(mRemoteIndicator); } if (d != null) { if (mButtonTint != null) { d = DrawableCompat.wrap(d.mutate()); DrawableCompat.setTintList(d, mButtonTint); } d.setCallback(this); d.setState(getDrawableState()); d.setVisible(getVisibility() == VISIBLE, false); } mRemoteIndicator = d; refreshDrawableState(); if (mAttachedToWindow && mRemoteIndicator != null && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) { AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent(); if (mIsConnecting) { if (!curDrawable.isRunning()) { curDrawable.start(); } } else if (mRemoteActive) { if (curDrawable.isRunning()) { curDrawable.stop(); } curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1); } } }
From source file:edu.chl.dat255.sofiase.readyforapet.viewcontroller.PetActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.petactivity); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //Receiving the new or saved pet if (CreatePetActivity.getPet() != null) { dog = (Dog) CreatePetActivity.getPet(); } else {//from w ww . ja va2s . c om try { dog = (Dog) Pet.load("pet_file.dat", PetActivity.this); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } //Getting the petMood petMood = dog.getPetMood(); //Getting the pet name petName = dog.getName(); //Connecting variables to xml objects play = (Button) findViewById(R.id.play); walk = (Button) findViewById(R.id.walk); eat = (Button) findViewById(R.id.eat); sleep = (Button) findViewById(R.id.sleep); showPetAge = (TextView) findViewById(R.id.petage); petResponse = (TextView) findViewById(R.id.petresponse); dogBiscuit = (ImageView) findViewById(R.id.dogbiscuit); dogPicture = (ImageView) findViewById(R.id.dogpicture); dogBiscuit.setVisibility(View.GONE); dogPicture.setVisibility(View.VISIBLE); //Initializing the background music try { afd = getAssets().openFd("readyforapetsong6.m4v"); player = new MediaPlayer(); player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); player.setLooping(true); player.prepare(); player.start(); } catch (IOException e) { e.printStackTrace(); } //Making it possible to turn off music with a checkbox addListenerOnMusic(); musicCheckBox.setChecked(true); //Getting the age of the pet if it has not already died petAge = (int) (petMood.getCurrentHour() - dog.getBirthHour()) / 24; //Setting textview with welcome message petResponse.setText("Hello, my name is " + petName + "!"); petResponse.setVisibility(View.VISIBLE); uiHandler.postDelayed(makeTextGone, 2500); //Setting textview with current age of the pet showPetAge.setText(petName + " is " + petAge + " days old."); petResponse.setVisibility(View.VISIBLE); //Changing the picture and enabling/disabling buttons depending on mood changePicture(); //Decreasing the moodBar depending on how much time has passed since last eat, walk, play and sleep petMood.setFoodMood(petMood.getFoodMood() + petMood.moodBarDecrease(petMood.getLastEatHour(), petMood.getCurrentHour())); petMood.setWalkMood(petMood.getWalkMood() + petMood.moodBarDecrease(petMood.getLastWalkHour(), petMood.getCurrentHour())); petMood.setPlayMood(petMood.getPlayMood() + petMood.moodBarDecrease(petMood.getLastPlayHour(), petMood.getCurrentHour())); petMood.setSleepMood(petMood.getSleepMood() + petMood.moodBarDecrease(petMood.getLastSleepHour(), petMood.getCurrentHour())); moodBar = (ProgressBar) findViewById(R.id.moodbar); moodBar.setProgress(petMood.getSumMood()); eat.setOnClickListener(new OnClickListener() { /** * Making the dog feel less hungry if it is hungry and else give the message i'm full. * Also shows a picture of a dogbisquit when eating. * * @param v - View */ @Override public void onClick(View v) { petResponse = (TextView) findViewById(R.id.petresponse); //Disabling buttons when eating if (petMood.getFoodMood() < 5) { play.setEnabled(false); eat.setEnabled(false); walk.setEnabled(false); sleep.setEnabled(false); new Handler().postDelayed(new Runnable() { @Override public void run() { eat.setEnabled(true); walk.setEnabled(true); play.setEnabled(true); sleep.setEnabled(true); changePicture(); } }, 10000); //Getting the pet response of eating petResponse.setText(dog.eat()); petResponse.setVisibility(View.VISIBLE); uiHandler.postDelayed(makeTextGone, 10000); dogBiscuit.setVisibility(View.VISIBLE); dogBiscuit.setBackgroundResource(R.anim.animation); //Starting animation eating dogbisquit final AnimationDrawable anim = (AnimationDrawable) dogBiscuit.getBackground(); anim.start(); uiHandler.postDelayed(makeTextGone, 10000); } else { petResponse.setText(dog.eat()); petResponse.setVisibility(View.VISIBLE); uiHandler.postDelayed(makeTextGone, 5000); } //Updating the moodbar moodBar = (ProgressBar) findViewById(R.id.moodbar); moodBar.setProgress(petMood.getSumMood()); } }); play.setOnClickListener(new OnClickListener() { /** * Sends the user to PlayActivity if the pet is not too hungry. * * @param v - View */ @Override public void onClick(View v) { //Continuing to playActivity only of the dog has not died and is not too hungry if ((petMood.getPlayMood() < 5 && petMood.getFoodMood() >= 3) && dog.isAlive()) { //Opening PlayActivity and receives a requestCode when resuming this activity PetActivity.this.startActivityForResult(new Intent(PetActivity.this, PlayActivity.class), 0); } else { petResponse.setText(dog.play(0)); petResponse.setVisibility(View.VISIBLE); uiHandler.postDelayed(makeTextGone, 2000); } changePicture(); } }); walk.setOnClickListener(new OnClickListener() { /** * Sends the user to WalkActivity if the pet wants to walk. * When resuming PetActivity a result is received that tells how far the pet walked. * * @param v - View */ @Override public void onClick(View v) { petResponse = (TextView) findViewById(R.id.petresponse); // Moving to the WalkActivity class if foodMood is high enough and petMood is below 5. if (((petMood.getFoodMood() < 3 && petMood.getWalkMood() < 5) || petMood.getWalkMood() == 5)) { petResponse.setText(dog.walk(0)); petResponse.setVisibility(View.VISIBLE); uiHandler.postDelayed(makeTextGone, 2000); } else if (dog.isAlive()) { //Opening PlayActivity and receives a requestCode when resuming this activity PetActivity.this.startActivityForResult(new Intent(PetActivity.this, WalkActivity.class), 1); } else { petResponse.setText(dog.walk(0)); petResponse.setVisibility(View.VISIBLE); uiHandler.postDelayed(makeTextGone, 2000); } changePicture(); } }); sleep.setOnClickListener(new OnClickListener() { /** * Sending the user to SleepActivity if sleepMood is below 5. * When resuming PetActivity a result is received that tells how much the pet has slept. * * @param v - View */ @Override public void onClick(View v) { if (dog.isAlive() && petMood.getSleepMood() < 5) { //Opening PlayActivity if the dog is alive and receives a requestCode when resuming this activity PetActivity.this.startActivityForResult(new Intent(PetActivity.this, SleepActivity.class), 2); } else { //Set the pet's response if it is either dead or not sleepy petResponse = (TextView) findViewById(R.id.petresponse); petResponse.setText(dog.sleep(0)); petResponse.setVisibility(View.VISIBLE); uiHandler.postDelayed(makeTextGone, 2000); } changePicture(); } }); }
From source file:androidx.mediarouter.app.MediaRouteButton.java
void refreshRoute() { final MediaRouter.RouteInfo route = mRouter.getSelectedRoute(); final boolean isRemote = !route.isDefaultOrBluetooth() && route.matchesSelector(mSelector); final boolean isConnecting = isRemote && route.isConnecting(); boolean needsRefresh = false; if (mRemoteActive != isRemote) { mRemoteActive = isRemote;/*from ww w . j ava2s. c o m*/ needsRefresh = true; } if (mIsConnecting != isConnecting) { mIsConnecting = isConnecting; needsRefresh = true; } if (needsRefresh) { updateContentDescription(); refreshDrawableState(); } if (mAttachedToWindow) { setEnabled(mRouter.isRouteAvailable(mSelector, MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE)); } if (mRemoteIndicator != null && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) { AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent(); if (mAttachedToWindow) { if ((needsRefresh || isConnecting) && !curDrawable.isRunning()) { curDrawable.start(); } } else if (isRemote && !isConnecting) { // When the route is already connected before the view is attached, show the last // frame of the connected animation immediately. if (curDrawable.isRunning()) { curDrawable.stop(); } curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1); } } }
From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingCursorAdapter.java
/** * Show the imageView and start its animation drawable. *///from ww w . j a va2 s.co m private void startAnimation(final ImageView imageView) { if (imageView.getVisibility() != View.VISIBLE) { Log.v(TAG, "startAnimation"); imageView.setVisibility(View.VISIBLE); final AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable(); // On some devices, directly calling start() on the animation does not work. // We have to wait until the ImageView is visible before starting the animation. imageView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { if (!animationDrawable.isRunning()) { imageView.post(() -> { animationDrawable.setVisible(true, false); animationDrawable.start(); }); } imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } }
From source file:metrocasas.projectsgt.MainActivity.java
public void upLoadFiles() { bandera = true;/*from w w w . j a v a 2 s. c om*/ ImageView img = (ImageView) findViewById(R.id.image_load); assert img != null; img.setBackgroundResource(R.drawable.load_files); // Get the background, which has been compiled to an AnimationDrawable object. AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); // Start the animation (looped playback by default). frameAnimation.start(); if (!title.getText().toString().equals("")) { q.setVisibility(View.GONE); p.setVisibility(View.VISIBLE); if (audioFile != null) { archivos.add(audioFile); } else { audio = ""; } if (!archivos.isEmpty()) { try { for (File i : archivos) { AmazonS3 s3Client = new AmazonS3Client(amazonCognito()); TransferUtility transferUtility = new TransferUtility(s3Client, this); TransferObserver transferObserver = transferUtility.upload(BUCKET_NAME, "projects/" + i.getName(), i); transferObserver.setTransferListener(new TransferListener() { @Override public void onStateChanged(int id, TransferState state) { if (state == TransferState.COMPLETED) { if (bandera) { ingresarDatos(); limpiarCampos(); bandera = false; } } } @Override public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { } @Override public void onError(int id, Exception ex) { Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_SHORT).show(); } }); } } catch (Exception e) { ingresarDatos(); limpiarCampos(); } } else { ingresarDatos(); limpiarCampos(); } } else { Toast.makeText(this, "Debe ingresar por lo menos el ttulo", Toast.LENGTH_LONG).show(); q.scrollTo(0, 0); title.setFocusableInTouchMode(true); title.setFocusable(true); title.requestFocus(); } }
From source file:com.groundupworks.partyphotobooth.fragments.CaptureFragment.java
/** * Initiates the capture sequence with count down. *///from w ww .jav a 2 s . c o m private void initiateCountdownCapture() { if (mCamera != null) { mStartButton.setEnabled(false); // Start auto-focus. mCamera.autoFocus(null); // Start animation. Take picture when count down animation completes. final AnimationDrawable countdownAnimation = (AnimationDrawable) mStartButton.getBackground(); countdownAnimation .setCallback(new TakePictureAnimationDrawableCallback(countdownAnimation, mStartButton)); mStartButton.post(new Runnable() { @Override public void run() { countdownAnimation.start(); } }); } }