├── README.md ├── android-animation-sample ├── .gitignore ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ └── vcs.xml ├── android-animation-sample.iml ├── app │ ├── .gitignore │ ├── app.iml │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── mobapphome │ │ │ └── animation │ │ │ └── sample │ │ │ ├── AboutFragment.java │ │ │ ├── MainActivity.java │ │ │ ├── SecondFragment.java │ │ │ ├── StartFragment.java │ │ │ └── UIMethods.java │ │ └── res │ │ ├── anim │ │ ├── a1_fade_in_scale.xml │ │ ├── a1_fade_out_scale.xml │ │ ├── a2_fade_in.xml │ │ ├── a2_fade_out.xml │ │ ├── a3_slide_down_fade.xml │ │ └── a3_slide_up_fade.xml │ │ ├── drawable-hdpi │ │ ├── button_info_normal.png │ │ ├── button_sound_muted.png │ │ └── button_sound_normal.png │ │ ├── drawable │ │ ├── icon_large.png │ │ ├── mah_btn_background_selector.xml │ │ ├── mah_btn_main_pressed_state.xml │ │ ├── mah_btn_main_state.xml │ │ ├── mah_btn_ripple_effect.xml │ │ └── mah_btn_text_selector.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_about.xml │ │ ├── fragment_second.xml │ │ └── fragment_start.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── raw │ │ ├── explosion.mp3 │ │ ├── space_drifter.mp3 │ │ └── whoosh.mp3 │ │ ├── values-v21 │ │ └── styles.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── imgs └── img_create │ ├── android_animation_sample_logo.ai │ ├── android_animation_sample_logo.png │ └── ic_launcher │ ├── res │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ └── mipmap-xxxhdpi │ │ └── ic_launcher.png │ └── web_hi_res_512.png └── screenshots ├── open_animation.gif └── start_animation.gif /README.md: -------------------------------------------------------------------------------- 1 | # android-open-animation 2 | ### Sample opening animation for android 3 | 4 | This application has created by [Sttar Hummatli](https://www.linkedin.com/in/hummatli) in test prosess. 5 | 6 | It contains opening animation tips. You can use it freely in your apps. 7 | 8 | Application has build on IDE `Android Studio` 9 | 10 | ### Images 11 | Start Animation        12 | Open Animation 13 | 14 | ### Contribution 15 | * Fork it 16 | * Create your feature branch (git checkout -b my-new-feature) 17 | * Commit your changes (git commit -am 'Added some feature') 18 | * Push to the branch (git push origin my-new-feature) 19 | * Create new Pull Request 20 | * Star it 21 | 22 | If you have any question about application please let me know. Write to settarxan@gmail.com. I will help. 23 | 24 | ### Developed By 25 | Sattar Hummatli - settarxan@gmail.com 26 | 27 | 28 | ### License 29 | MIT License 30 | 31 | Copyright (c) 2017 [Sattar Hummatli](https://www.linkedin.com/in/hummatli) 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all 41 | copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 49 | SOFTWARE. 50 | 51 | -------------------------------------------------------------------------------- /android-animation-sample/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/.name: -------------------------------------------------------------------------------- 1 | android-animation-sample -------------------------------------------------------------------------------- /android-animation-sample/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /android-animation-sample/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android-animation-sample/android-animation-sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /android-animation-sample/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-animation-sample/app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /android-animation-sample/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.mobapphome.animation.sample" 9 | minSdkVersion 14 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile 'com.android.support:appcompat-v7:24.2.1' 25 | } 26 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/java/com/mobapphome/animation/sample/AboutFragment.java: -------------------------------------------------------------------------------- 1 | package com.mobapphome.animation.sample; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.LinearLayout; 10 | 11 | public class AboutFragment extends Fragment implements View.OnClickListener { 12 | 13 | @Override 14 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 15 | LinearLayout lytMain = (LinearLayout) inflater.inflate(R.layout.fragment_about, container, false); 16 | lytMain.findViewById(R.id.btnBack).setOnClickListener(this); 17 | return lytMain; 18 | } 19 | 20 | @Override 21 | public void onClick(View v) { 22 | // TODO Auto-generated method stub 23 | if (v.getId() == R.id.btnBack) { 24 | try { 25 | getActivity().getSupportFragmentManager().popBackStack(); 26 | } catch (NullPointerException npe) { 27 | return; 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/java/com/mobapphome/animation/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.mobapphome.animation.sample; 2 | 3 | import java.util.List; 4 | 5 | import android.content.Context; 6 | import android.content.SharedPreferences; 7 | import android.graphics.Typeface; 8 | import android.media.AudioManager; 9 | import android.media.MediaPlayer; 10 | import android.os.Bundle; 11 | import android.support.v4.app.Fragment; 12 | import android.support.v4.app.FragmentTransaction; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.util.Log; 15 | import android.widget.TextView; 16 | 17 | public class MainActivity extends AppCompatActivity { 18 | 19 | static public final String START_FARGMENT = "startFragment"; 20 | static public final String SECOND_FARGMENT = "secondFragment"; 21 | static public final String ABOUT_FARGMENT = "aboutFragment"; 22 | 23 | final public static String PREF_KEY_SOUND = "sound"; 24 | 25 | public MediaPlayer mpFonStart; 26 | 27 | SharedPreferences prefs; 28 | private boolean soundOn = false; 29 | 30 | FragmentTransaction transactionForCommitOnPostResume = null; 31 | FragmentTransaction transactionForCommitOnPostResumeForAdd = null; 32 | 33 | public void soundOn(boolean soundOn){ 34 | this.soundOn = soundOn; 35 | if (soundOn) { 36 | setVolume(1); 37 | } else { 38 | setVolume(0); 39 | } 40 | saveSoundOnPref(); 41 | } 42 | 43 | public void setVolume(float volume){ 44 | if(mpFonStart != null) mpFonStart.setVolume(volume, volume); 45 | } 46 | 47 | public boolean getSoundOn(){ 48 | return soundOn; 49 | } 50 | 51 | 52 | static public void setFontTextView(Context context, TextView tv, String fontName) { 53 | try{ 54 | Typeface font = Typeface.createFromAsset(context.getAssets(),fontName); 55 | tv.setTypeface(font); 56 | }catch(RuntimeException r){ 57 | Log.e("test", "Error " + r.getMessage()); 58 | } 59 | } 60 | 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | 64 | super.onCreate(savedInstanceState); 65 | 66 | Log.i("test", "Main act on create called"); 67 | 68 | setContentView(R.layout.activity_main); 69 | 70 | prefs = getSharedPreferences( 71 | getApplicationContext().getPackageName(), Context.MODE_PRIVATE); 72 | soundOn = prefs.getBoolean(PREF_KEY_SOUND, false); 73 | 74 | if (savedInstanceState == null) { 75 | FragmentTransaction transaction = getSupportFragmentManager() 76 | .beginTransaction(); 77 | StartFragment fragment = StartFragment.newInstance(); 78 | 79 | transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,android.R.anim.fade_in, android.R.anim.fade_out); 80 | transaction.add(R.id.container, fragment, START_FARGMENT); 81 | transaction.commit(); 82 | } 83 | } 84 | 85 | 86 | public void startAudioFonStart(){ 87 | new Thread(new Runnable() { 88 | 89 | @Override 90 | public void run() { 91 | stopAudioFonStart(); 92 | mpFonStart = MediaPlayer.create(MainActivity.this, R.raw.space_drifter); 93 | mpFonStart.setLooping(true); 94 | mpFonStart.setAudioStreamType(AudioManager.STREAM_MUSIC); 95 | 96 | if(soundOn){ 97 | mpFonStart.setVolume(1, 1); 98 | }else{ 99 | mpFonStart.setVolume(0, 0); 100 | } 101 | mpFonStart.start(); 102 | } 103 | }).start(); 104 | } 105 | 106 | public void stopAudioFonStart(){ 107 | if(mpFonStart != null && mpFonStart.isPlaying()){ 108 | mpFonStart.stop(); 109 | } 110 | } 111 | 112 | @Override 113 | protected void onStart() { 114 | // TODO Auto-generated method stub 115 | if(soundOn){ 116 | setVolume(1); 117 | } 118 | Log.i("test", "-----Main act on start called"); 119 | super.onStart(); 120 | } 121 | 122 | 123 | @Override 124 | protected void onPostResume() { 125 | super.onPostResume(); 126 | if(transactionForCommitOnPostResume != null){ 127 | transactionForCommitOnPostResume.commit(); 128 | } 129 | transactionForCommitOnPostResume = null; 130 | Log.i("test", "On resume post 1 = transactionForCommitOnPostResume = " + transactionForCommitOnPostResume); 131 | if(transactionForCommitOnPostResumeForAdd != null){ 132 | Log.i("test", "On resume post 2"); 133 | transactionForCommitOnPostResumeForAdd.commit(); 134 | } 135 | transactionForCommitOnPostResumeForAdd = null; 136 | } 137 | 138 | public void saveSoundOnPref(){ 139 | prefs.edit().putBoolean(PREF_KEY_SOUND, soundOn).apply(); 140 | } 141 | 142 | 143 | @Override 144 | protected void onStop() { 145 | // TODO Auto-generated method stub 146 | setVolume(0); 147 | saveSoundOnPref(); 148 | Log.i("test", "----Main act on stop called"); 149 | super.onStop(); 150 | } 151 | 152 | 153 | 154 | public void replaceFragments(int conatinerId, Fragment fragment, String fragmentTag, int enter, int exit, int popEnter, int popExit){ 155 | replaceFragments(conatinerId, fragment, fragmentTag, enter, exit, popEnter, popExit, false); 156 | } 157 | 158 | public void replaceFragments(int conatinerId, Fragment fragment, String fragmentTag, int enter, int exit, int popEnter, int popExit, boolean commitOnPostResume){ 159 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 160 | transaction.setCustomAnimations(enter, exit, popEnter, popExit); 161 | transaction.replace(conatinerId, fragment, fragmentTag); 162 | transaction.addToBackStack(null); 163 | if(!commitOnPostResume) { 164 | transaction.commit(); 165 | transactionForCommitOnPostResume = null; 166 | }else{ 167 | transactionForCommitOnPostResume = transaction; 168 | } 169 | } 170 | 171 | 172 | @Override 173 | public void onBackPressed() { 174 | List fragments = getSupportFragmentManager().getFragments(); 175 | Log.i("test", "Fragment size = " + fragments.size()); 176 | for(int i = 0;i < fragments.size() ; ++i){ 177 | Fragment frag = fragments.get(i); 178 | if(frag != null){ 179 | Log.i("test", "frag " + i + " = " + fragments.get(i).getTag() + " isvisible = " + fragments.get(i).isVisible()); 180 | if(frag.isVisible()){ 181 | if(frag instanceof AboutFragment){ 182 | Log.i("test", "Current frag is About fragment"); 183 | }else if(frag instanceof StartFragment){ 184 | Log.i("test", "Current frag is Start fragment"); 185 | finish(); 186 | }else if(frag instanceof SecondFragment){ 187 | Log.i("test", "Current frag is Second fragment"); 188 | } 189 | } 190 | }else{ 191 | Log.i("test", "frag " + frag); 192 | } 193 | } 194 | 195 | super.onBackPressed(); 196 | 197 | 198 | } 199 | } -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/java/com/mobapphome/animation/sample/SecondFragment.java: -------------------------------------------------------------------------------- 1 | package com.mobapphome.animation.sample; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.LinearLayout; 10 | 11 | 12 | public class SecondFragment extends Fragment implements View.OnClickListener { 13 | 14 | 15 | public static SecondFragment newInstance() { 16 | SecondFragment myFragment = new SecondFragment(); 17 | return myFragment; 18 | } 19 | 20 | 21 | @Override 22 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 23 | 24 | LinearLayout lytMain = (LinearLayout) inflater.inflate(R.layout.fragment_second, container, false); 25 | lytMain.findViewById(R.id.btnBack).setOnClickListener(this); 26 | return lytMain; 27 | } 28 | 29 | @Override 30 | public void onClick(View v) { 31 | // TODO Auto-generated method stub 32 | if (v.getId() == R.id.btnBack) { 33 | try { 34 | getActivity().getSupportFragmentManager().popBackStack(); 35 | } catch (NullPointerException npe) { 36 | return; 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/java/com/mobapphome/animation/sample/StartFragment.java: -------------------------------------------------------------------------------- 1 | package com.mobapphome.animation.sample; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ObjectAnimator; 7 | import android.content.Context; 8 | import android.graphics.Point; 9 | import android.media.AudioManager; 10 | import android.media.MediaPlayer; 11 | import android.os.Bundle; 12 | import android.os.Vibrator; 13 | import android.support.annotation.Nullable; 14 | import android.support.v4.app.Fragment; 15 | import android.util.Log; 16 | import android.view.Display; 17 | import android.view.LayoutInflater; 18 | import android.view.MenuItem; 19 | import android.view.View; 20 | import android.view.ViewGroup; 21 | import android.view.ViewTreeObserver; 22 | import android.view.animation.AnticipateInterpolator; 23 | import android.view.animation.DecelerateInterpolator; 24 | import android.view.animation.LinearInterpolator; 25 | import android.view.animation.OvershootInterpolator; 26 | import android.widget.Button; 27 | import android.widget.ImageView; 28 | import android.widget.RelativeLayout; 29 | 30 | public class StartFragment extends Fragment implements View.OnClickListener { 31 | 32 | RelativeLayout lytMain; 33 | ImageView imgView; 34 | Button btn1; 35 | Button btn2; 36 | ImageView btnSound; 37 | ImageView btnInfo; 38 | 39 | int scrWidth; 40 | int scrHeight; 41 | 42 | float imgViewInitX; 43 | float btn1InitX; 44 | float btn2InitX; 45 | float btnSoundInitX; 46 | float btnInfoInitX; 47 | 48 | float imgViewInitY; 49 | float btn1InitY; 50 | float btn2InitY; 51 | float btnSoundInitY; 52 | float btnInfoInitY; 53 | 54 | float imgViewNewY; 55 | float btn1NewY; 56 | float btn2NewY; 57 | float btnSoundNewY; 58 | float btnInfoNewY; 59 | 60 | boolean firstTime = true; 61 | boolean startOpenAnimately = false; 62 | boolean startEnded = false; 63 | 64 | SecondFragment secondFragment; 65 | 66 | 67 | private void playWhoosh(){ 68 | new Thread(new Runnable() { 69 | 70 | @Override 71 | public void run() { 72 | 73 | MediaPlayer mp = MediaPlayer.create(lytMain.getContext(), 74 | R.raw.whoosh); 75 | mp.setAudioStreamType(AudioManager.STREAM_MUSIC); 76 | mp.start(); 77 | } 78 | }).start(); 79 | } 80 | 81 | public void enableButtons(boolean enable){ 82 | btn1.setEnabled(enable); 83 | btn2.setEnabled(enable); 84 | btnInfo.setEnabled(enable); 85 | btnSound.setEnabled(enable); 86 | } 87 | 88 | private void startAnimation(){ 89 | //set initial coordinates 90 | 91 | enableButtons(false); 92 | 93 | imgView.setX(UIMethods.mapToLocCordX((scrWidth - imgView.getWidth()) / 2, imgView)); 94 | imgView.setY(UIMethods.mapToLocCordY((scrHeight - imgView.getHeight()) / 2, imgView)); 95 | btn1.setX(UIMethods.mapToLocCordX(-btn1.getWidth(), btn1)); 96 | btn2.setX(UIMethods.mapToLocCordX(scrWidth, btn2)); 97 | btnSound.setY(UIMethods.mapToLocCordX(-btnSound.getHeight(), btnSound)); 98 | btnInfo.setY(UIMethods.mapToLocCordX(-btnInfo.getHeight(), btnInfo)); 99 | 100 | //Animation first 101 | ObjectAnimator animScaleX = ObjectAnimator.ofFloat(imgView, "scaleX", 3, 1); 102 | ObjectAnimator animScaleY = ObjectAnimator.ofFloat(imgView, "scaleY", 3, 1); 103 | ObjectAnimator animAlpha = ObjectAnimator.ofFloat(imgView, "alpha", 0, 1); 104 | 105 | AnimatorSet animSetFirst = new AnimatorSet(); 106 | animSetFirst.setDuration(500); 107 | animSetFirst.playTogether(animScaleX, animScaleY, animAlpha); 108 | animSetFirst.addListener(new AnimatorListenerAdapter() { 109 | 110 | @Override 111 | public void onAnimationStart(Animator animation) { 112 | 113 | try{ 114 | if (((MainActivity)getActivity()).getSoundOn()) { 115 | playWhoosh(); 116 | } 117 | }catch(NullPointerException npe){ 118 | return; 119 | } 120 | super.onAnimationStart(animation); 121 | } 122 | 123 | }); 124 | 125 | //Animation second 126 | ObjectAnimator animShakeX = ObjectAnimator.ofFloat(imgView, "x", imgView.getX() - 10, imgView.getX() + 10); 127 | animShakeX.setRepeatCount(17); 128 | animShakeX.setRepeatMode(ObjectAnimator.RESTART); 129 | animShakeX.setInterpolator(new LinearInterpolator()); 130 | 131 | 132 | ObjectAnimator animShakeY = ObjectAnimator.ofFloat(imgView, "y",imgView.getY() -10, imgView.getY() +10); 133 | animShakeY.setRepeatCount(16); 134 | animShakeY.setRepeatMode(ObjectAnimator.REVERSE); 135 | animShakeX.setInterpolator(new LinearInterpolator()); 136 | 137 | AnimatorSet animSetSecond = new AnimatorSet(); 138 | animSetSecond.playTogether(animShakeX, animShakeY); 139 | animSetSecond.setDuration(50); 140 | long datest = 0; 141 | animSetSecond.addListener(new AnimatorListenerAdapter() { 142 | MediaPlayer mp = null; 143 | Vibrator v = null; 144 | @Override 145 | public void onAnimationStart(Animator animation) { 146 | 147 | try{ 148 | if (((MainActivity)getActivity()).getSoundOn()) { 149 | new Thread(new Runnable() { 150 | 151 | @Override 152 | public void run() { 153 | mp = MediaPlayer.create(lytMain.getContext(), R.raw.explosion); 154 | mp.setVolume(0.3f, 0.3f); 155 | mp.setAudioStreamType(AudioManager.STREAM_MUSIC); 156 | mp.start(); 157 | v = (Vibrator) lytMain.getContext().getSystemService(Context.VIBRATOR_SERVICE); 158 | v.vibrate(5000); 159 | } 160 | }).start(); 161 | } 162 | }catch(NullPointerException npe){ 163 | return; 164 | } 165 | super.onAnimationStart(animation); 166 | } 167 | 168 | @Override 169 | public void onAnimationEnd(Animator animation) { 170 | // TODO Auto-generated method stub 171 | if (mp != null && mp.isPlaying()) mp.stop(); 172 | if (v !=null) v.cancel(); 173 | super.onAnimationEnd(animation); 174 | } 175 | }); 176 | 177 | //Animation third 178 | ObjectAnimator animThird = ObjectAnimator.ofFloat(imgView, "y", imgView.getY(), imgViewInitY); 179 | animThird.setDuration(500); 180 | animThird.setInterpolator(new OvershootInterpolator()); 181 | animThird.setStartDelay(500); 182 | animThird.addListener(new AnimatorListenerAdapter() { 183 | @Override 184 | public void onAnimationStart(Animator animation) { 185 | 186 | try{ 187 | if (((MainActivity)getActivity()).getSoundOn()) { 188 | playWhoosh(); 189 | } 190 | }catch(NullPointerException npe){ 191 | return; 192 | } 193 | super.onAnimationStart(animation); 194 | } 195 | }); 196 | 197 | 198 | //Animation forth 199 | ObjectAnimator animForth = ObjectAnimator.ofFloat(btn1, "x", btn1.getX(), btn1InitX); 200 | animForth.setDuration(300); 201 | animForth.setInterpolator(new DecelerateInterpolator()); 202 | animForth.addListener(new AnimatorListenerAdapter() { 203 | @Override 204 | public void onAnimationStart(Animator animation) { 205 | 206 | try{ 207 | if ((( MainActivity)getActivity()).getSoundOn()) { 208 | playWhoosh(); 209 | } 210 | }catch(NullPointerException npe){ 211 | return; 212 | } 213 | super.onAnimationStart(animation); 214 | } 215 | 216 | }); 217 | 218 | //Animation fifth 219 | ObjectAnimator animFifth = ObjectAnimator.ofFloat(btn2, "x", btn2.getX(), btn2InitX); 220 | animFifth.setDuration(300); 221 | animFifth.setInterpolator(new DecelerateInterpolator()); 222 | animFifth.addListener(new AnimatorListenerAdapter() { 223 | @Override 224 | public void onAnimationStart(Animator animation) { 225 | 226 | try{ 227 | if (((MainActivity)getActivity()).getSoundOn()) { 228 | playWhoosh(); 229 | } 230 | }catch(NullPointerException npe){ 231 | return; 232 | } 233 | super.onAnimationStart(animation); 234 | } 235 | 236 | }); 237 | 238 | //Animation sixth 239 | ObjectAnimator animSound = ObjectAnimator.ofFloat(btnSound, "y", btnSound.getY(), btnSoundInitY); 240 | animSound.setInterpolator(new DecelerateInterpolator()); 241 | 242 | ObjectAnimator animInfo = ObjectAnimator.ofFloat(btnInfo, "y", btnInfo.getY(), btnInfoInitY); 243 | animInfo.setInterpolator(new DecelerateInterpolator()); 244 | 245 | AnimatorSet animSixth = new AnimatorSet(); 246 | animSixth.playTogether(animSound, animInfo); 247 | animSixth.setDuration(300); 248 | animSixth.addListener(new AnimatorListenerAdapter() { 249 | //Listineri sonuncu animasiyaya atmaqda veziyyet donmain 250 | //qarshisin almaqdir. animSetAll -a atanda gecikme bas veririr 251 | @Override 252 | public void onAnimationEnd(Animator animation) { 253 | // TODO Auto-generated method stub 254 | enableButtons(true); 255 | startEnded = true; 256 | super.onAnimationStart(animation); 257 | } 258 | 259 | }); 260 | 261 | 262 | //Animation all starter 263 | AnimatorSet animSetAll = new AnimatorSet(); 264 | animSetAll.playSequentially(animSetFirst, animSetSecond, animThird, animForth, animFifth, animSixth); 265 | animSetAll.start(); 266 | 267 | } 268 | 269 | private void openAnimation() { 270 | startOpenAnimately = true; 271 | enableButtons(false); 272 | imgViewNewY = imgView.getY() - UIMethods.getRelativeTop(imgView) 273 | - imgView.getHeight(); 274 | btn1NewY = scrHeight; 275 | btn2NewY = scrHeight + btn2.getY() - btn1.getY(); 276 | btnSoundNewY = btnSound.getY() - UIMethods.getRelativeTop(btnSound) 277 | - btnSound.getHeight(); 278 | btnInfoNewY = btnInfo.getY() - UIMethods.getRelativeTop(btnInfo) 279 | - btnInfo.getHeight(); 280 | 281 | ObjectAnimator animImgViewY = ObjectAnimator.ofFloat(imgView, "y", 282 | imgView.getY(), imgViewNewY); 283 | ObjectAnimator animBtn1 = ObjectAnimator.ofFloat(btn1, "y", 284 | btn1.getY(), btn1NewY); 285 | ObjectAnimator animBtn2 = ObjectAnimator.ofFloat(btn2, "y", 286 | btn2.getY(), btn2NewY); 287 | ObjectAnimator animBtnSound = ObjectAnimator.ofFloat(btnSound, "y", 288 | btnSound.getY(), btnSoundNewY); 289 | ObjectAnimator animBtnInfo = ObjectAnimator.ofFloat(btnInfo, "y", 290 | btnInfo.getY(), btnInfoNewY); 291 | 292 | AnimatorSet animatorSet = new AnimatorSet(); 293 | animatorSet.setDuration(500); 294 | animatorSet.setInterpolator(new AnticipateInterpolator(1)); 295 | animatorSet.playTogether(animImgViewY, animBtnSound, animBtnInfo, 296 | animBtn1, animBtn2); 297 | animatorSet.addListener(new AnimatorListenerAdapter() { 298 | 299 | @Override 300 | public void onAnimationEnd(Animator arg0) { 301 | // TODO Auto-generated method stub 302 | 303 | Log.i("test", "Open animation end"); 304 | ((MainActivity) getActivity()).replaceFragments(R.id.container, 305 | secondFragment, MainActivity.SECOND_FARGMENT, R.anim.a2_fade_in, 0, 0, R.anim.a2_fade_out); 306 | enableButtons(true); 307 | } 308 | 309 | }); 310 | animatorSet.start(); 311 | 312 | } 313 | 314 | private void closeAnimation() { 315 | if(!startOpenAnimately){ 316 | return; 317 | } 318 | startOpenAnimately = false; 319 | enableButtons(false); 320 | 321 | ObjectAnimator animImgViewY = ObjectAnimator.ofFloat(imgView, "y", 322 | imgViewNewY, imgViewInitY); 323 | ObjectAnimator animBtnSound = ObjectAnimator.ofFloat(btnSound, "y", 324 | btnSoundNewY, btnSoundInitY); 325 | ObjectAnimator animBtnInfo = ObjectAnimator.ofFloat(btnInfo, "y", 326 | btnInfoNewY, btnInfoInitY); 327 | ObjectAnimator animBtn1 = ObjectAnimator.ofFloat(btn1, "y", 328 | btn1NewY, btn1InitY); 329 | ObjectAnimator animBtn2 = ObjectAnimator.ofFloat(btn2, "y", 330 | btn2NewY, btn2InitY); 331 | 332 | AnimatorSet animatorSet = new AnimatorSet(); 333 | animatorSet.setDuration(500); 334 | animatorSet.setInterpolator(new OvershootInterpolator(1)); 335 | animatorSet.playTogether(animImgViewY, animBtnSound, animBtnInfo, 336 | animBtn1, animBtn2); 337 | animatorSet.addListener(new AnimatorListenerAdapter() { 338 | @Override 339 | public void onAnimationEnd(Animator animation) { 340 | enableButtons(true); 341 | super.onAnimationEnd(animation); 342 | } 343 | }); 344 | 345 | animatorSet.start(); 346 | } 347 | 348 | @Override 349 | public void onClick(View v) { 350 | // TODO Auto-generated method stub 351 | if (v.getId() == R.id.btn1) { 352 | openAnimation(); 353 | } else if (v.getId() == R.id.btn2) { 354 | openAnimation(); 355 | } else if (v.getId() == R.id.btnSound) { 356 | 357 | try{ 358 | if (((MainActivity)getActivity()).getSoundOn()) { 359 | btnSound.setBackgroundResource(R.drawable.button_sound_muted); 360 | } else { 361 | btnSound.setBackgroundResource(R.drawable.button_sound_normal); 362 | } 363 | ((MainActivity)getActivity()).soundOn(!((MainActivity)getActivity()).getSoundOn()); 364 | }catch(NullPointerException npe){ 365 | return; 366 | } 367 | 368 | } else if (v.getId() == R.id.btnInfo) { 369 | final AboutFragment fragment = new AboutFragment(); 370 | ((MainActivity) getActivity()).replaceFragments(R.id.container, fragment, 371 | MainActivity.ABOUT_FARGMENT, R.anim.a3_slide_up_fade, R.anim.a1_fade_out_scale, R.anim.a1_fade_in_scale, R.anim.a3_slide_down_fade); 372 | } 373 | 374 | } 375 | 376 | 377 | public static StartFragment newInstance(){ 378 | StartFragment myFragment = new StartFragment(); 379 | return myFragment; 380 | } 381 | 382 | @Override 383 | public void onCreate(@Nullable Bundle savedInstanceState) { 384 | firstTime = true; 385 | secondFragment = SecondFragment.newInstance(); 386 | super.onCreate(savedInstanceState); 387 | } 388 | 389 | @Override 390 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 391 | Bundle savedInstanceState) { 392 | 393 | Log.i("test", "Start frag cretate view ---"); 394 | 395 | setHasOptionsMenu(true); 396 | lytMain = (RelativeLayout) inflater.inflate(R.layout.fragment_start,container, false); 397 | 398 | imgView = (ImageView) lytMain.findViewById(R.id.imgStart); 399 | btn1 = (Button) lytMain.findViewById(R.id.btn1); 400 | btn2 = (Button) lytMain.findViewById(R.id.btn2); 401 | btnSound = (ImageView) lytMain.findViewById(R.id.btnSound); 402 | btnInfo = (ImageView) lytMain.findViewById(R.id.btnInfo); 403 | // btnSound.bringToFront(); 404 | // btnInfo.bringToFront(); 405 | 406 | btn1.setOnClickListener(this); 407 | btn2.setOnClickListener(this); 408 | btnSound.setOnClickListener(this); 409 | btnInfo.setOnClickListener(this); 410 | 411 | 412 | try{ 413 | if (((MainActivity)getActivity()).getSoundOn()) { 414 | btnSound.setBackgroundResource(R.drawable.button_sound_normal); 415 | } else { 416 | btnSound.setBackgroundResource(R.drawable.button_sound_muted); 417 | } 418 | }catch(NullPointerException npe){ 419 | return null; 420 | } 421 | 422 | lytMain.getViewTreeObserver().addOnGlobalLayoutListener( 423 | new ViewTreeObserver.OnGlobalLayoutListener() { 424 | 425 | @Override 426 | public void onGlobalLayout() { 427 | // now we can retrieve the width and height 428 | Display display = null; 429 | try{ 430 | display = getActivity().getWindowManager() 431 | .getDefaultDisplay(); 432 | }catch(NullPointerException npe){ 433 | return; 434 | } 435 | 436 | Point size = new Point(); 437 | display.getSize(size); 438 | scrWidth = size.x; 439 | scrHeight = size.y; 440 | // Getting actual coordinates 441 | imgViewInitX = imgView.getX(); 442 | btn1InitX = btn1.getX(); 443 | btn2InitX = btn2.getX(); 444 | btnSoundInitX = btnSound.getX(); 445 | btnInfoInitX = btnInfo.getX(); 446 | 447 | imgViewInitY = imgView.getY(); 448 | btn1InitY = btn1.getY(); 449 | btn2InitY = btn2.getY(); 450 | btnSoundInitY = btnSound.getY(); 451 | btnInfoInitY = btnInfo.getY(); 452 | 453 | Log.i("test", "StartFrag First time = " + firstTime); 454 | if (firstTime) { 455 | firstTime = false; 456 | startAnimation(); 457 | } else { 458 | closeAnimation(); 459 | } 460 | 461 | // ... 462 | // do whatever you want with them 463 | // ... 464 | // this is an important step not to keep receiving 465 | // callbacks: 466 | // we should remove this listener 467 | // I use the function to remove it based on the api 468 | // level! 469 | 470 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) 471 | imgView.getViewTreeObserver() 472 | .removeOnGlobalLayoutListener(this); 473 | else 474 | imgView.getViewTreeObserver() 475 | .removeGlobalOnLayoutListener(this); 476 | } 477 | }); 478 | try{ 479 | ((MainActivity)getActivity()).startAudioFonStart(); 480 | }catch(NullPointerException npe){ 481 | return null; 482 | } 483 | return lytMain; 484 | } 485 | 486 | 487 | 488 | @Override 489 | public void onDestroyView() { 490 | 491 | try{ 492 | ((MainActivity)getActivity()).stopAudioFonStart(); 493 | }catch(NullPointerException npe){ 494 | return; 495 | } 496 | Log.i("test", "Start frag destroyed view ------"); 497 | super.onDestroyView(); 498 | } 499 | 500 | 501 | @Override 502 | public boolean onOptionsItemSelected(MenuItem item) { 503 | // TODO Auto-generated method stub 504 | int id = item.getItemId(); 505 | // if (id == R.id.action_capitaine_frag) { 506 | // return true; 507 | // } 508 | return super.onOptionsItemSelected(item); 509 | } 510 | 511 | } -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/java/com/mobapphome/animation/sample/UIMethods.java: -------------------------------------------------------------------------------- 1 | package com.mobapphome.animation.sample; 2 | 3 | import android.view.View; 4 | 5 | public class UIMethods { 6 | static public int getRelativeLeft(View myView) { 7 | if (myView.getParent() == myView.getRootView()) 8 | return myView.getLeft(); 9 | else 10 | return myView.getLeft() + getRelativeLeft((View) myView.getParent()); 11 | } 12 | 13 | static public int getRelativeTop(View myView) { 14 | if (myView.getParent() == myView.getRootView()) 15 | return myView.getTop(); 16 | else 17 | return myView.getTop() + getRelativeTop((View) myView.getParent()); 18 | } 19 | 20 | static private float getCordSysDiffY(View myView) { 21 | return getRelativeTop(myView) - myView.getY(); 22 | } 23 | 24 | static private float getCordSysDiffX(View myView) { 25 | return getRelativeLeft(myView) - myView.getX(); 26 | } 27 | 28 | static public float mapToLocCordY(float yGlobal, View myView) { 29 | return yGlobal - getCordSysDiffY(myView); 30 | } 31 | 32 | static public float mapToLocCordX(float xGlobal, View myView) { 33 | return xGlobal - getCordSysDiffX(myView); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/anim/a1_fade_in_scale.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 19 | 20 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/anim/a1_fade_out_scale.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 19 | 20 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/anim/a2_fade_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/anim/a2_fade_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/anim/a3_slide_down_fade.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/anim/a3_slide_up_fade.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable-hdpi/button_info_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummatli/android-open-animation/7e12e31438c0f259ca276998adb0cb88cba40f9e/android-animation-sample/app/src/main/res/drawable-hdpi/button_info_normal.png -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable-hdpi/button_sound_muted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummatli/android-open-animation/7e12e31438c0f259ca276998adb0cb88cba40f9e/android-animation-sample/app/src/main/res/drawable-hdpi/button_sound_muted.png -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable-hdpi/button_sound_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummatli/android-open-animation/7e12e31438c0f259ca276998adb0cb88cba40f9e/android-animation-sample/app/src/main/res/drawable-hdpi/button_sound_normal.png -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable/icon_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummatli/android-open-animation/7e12e31438c0f259ca276998adb0cb88cba40f9e/android-animation-sample/app/src/main/res/drawable/icon_large.png -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable/mah_btn_background_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable/mah_btn_main_pressed_state.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable/mah_btn_main_state.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable/mah_btn_ripple_effect.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/drawable/mah_btn_text_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 17 | 23 | 24 | -------------------------------------------------------------------------------- /android-animation-sample/app/src/main/res/layout/fragment_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 24 | 33 | 34 | 35 | 42 | 43 | 44 |