|
| 1 | +package com.babanomania.pdfscanner; |
| 2 | + |
| 3 | +import android.content.Intent; |
| 4 | +import android.content.SharedPreferences; |
| 5 | +import android.support.design.widget.TabLayout; |
| 6 | +import android.support.v4.view.ViewPager; |
| 7 | +import android.support.v7.app.AppCompatActivity; |
| 8 | +import android.os.Bundle; |
| 9 | +import android.view.View; |
| 10 | +import android.view.Window; |
| 11 | +import android.view.WindowManager; |
| 12 | +import android.view.animation.Animation; |
| 13 | +import android.view.animation.AnimationUtils; |
| 14 | +import android.widget.Button; |
| 15 | +import android.widget.TextView; |
| 16 | + |
| 17 | +import com.babanomania.pdfscanner.intro.IntroItem; |
| 18 | +import com.babanomania.pdfscanner.intro.IntroViewPagerAdapter; |
| 19 | +import com.babanomania.pdfscanner.utils.UIUtil; |
| 20 | + |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +public class IntroActivity extends AppCompatActivity { |
| 25 | + |
| 26 | + private ViewPager screenPager; |
| 27 | + IntroViewPagerAdapter introViewPagerAdapter ; |
| 28 | + TabLayout tabIndicator; |
| 29 | + Button btnNext; |
| 30 | + int position = 0 ; |
| 31 | + Button btnGetStarted; |
| 32 | + Animation btnAnim ; |
| 33 | + TextView tvSkip; |
| 34 | + |
| 35 | + @Override |
| 36 | + protected void onCreate(Bundle savedInstanceState) { |
| 37 | + super.onCreate(savedInstanceState); |
| 38 | + |
| 39 | + // make the activity on full screen |
| 40 | + requestWindowFeature(Window.FEATURE_NO_TITLE); |
| 41 | + getWindow().setFlags( |
| 42 | + WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| 43 | + WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 44 | + ); |
| 45 | + |
| 46 | + UIUtil.setWhiteNavigationBar( findViewById(android.R.id.content), this ); |
| 47 | + |
| 48 | + setContentView(R.layout.activity_intro); |
| 49 | + |
| 50 | + // hide the action bar |
| 51 | + getSupportActionBar().hide(); |
| 52 | + |
| 53 | + // ini views |
| 54 | + btnNext = findViewById(R.id.btn_next); |
| 55 | + btnGetStarted = findViewById(R.id.btn_get_started); |
| 56 | + tabIndicator = findViewById(R.id.tab_indicator); |
| 57 | + btnAnim = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.button_animation); |
| 58 | + tvSkip = findViewById(R.id.tv_skip); |
| 59 | + |
| 60 | + // fill list screen |
| 61 | + final List<IntroItem> mList = new ArrayList<>(); |
| 62 | + mList.add(new IntroItem( getResources().getString(R.string.intro_title1), |
| 63 | + getResources().getString(R.string.intro_desc1), |
| 64 | + R.drawable.ic_intro1)); |
| 65 | + |
| 66 | + mList.add(new IntroItem( getResources().getString(R.string.intro_title2), |
| 67 | + getResources().getString(R.string.intro_desc2), |
| 68 | + R.drawable.ic_intro2)); |
| 69 | + |
| 70 | + mList.add(new IntroItem( getResources().getString(R.string.intro_title3), |
| 71 | + getResources().getString(R.string.intro_desc3), |
| 72 | + R.drawable.ic_intro3)); |
| 73 | + |
| 74 | + // setup viewpager |
| 75 | + screenPager =findViewById(R.id.screen_viewpager); |
| 76 | + introViewPagerAdapter = new IntroViewPagerAdapter(this,mList); |
| 77 | + screenPager.setAdapter(introViewPagerAdapter); |
| 78 | + |
| 79 | + // setup tablayout with viewpager |
| 80 | + tabIndicator.setupWithViewPager(screenPager); |
| 81 | + |
| 82 | + // next button click Listener |
| 83 | + btnNext.setOnClickListener(new View.OnClickListener() { |
| 84 | + @Override |
| 85 | + public void onClick(View v) { |
| 86 | + |
| 87 | + position = screenPager.getCurrentItem(); |
| 88 | + if (position < mList.size()) { |
| 89 | + position++; |
| 90 | + screenPager.setCurrentItem(position); |
| 91 | + } |
| 92 | + |
| 93 | + if (position == mList.size()-1) { // when we reach to the last screen |
| 94 | + loaddLastScreen(); |
| 95 | + } |
| 96 | + |
| 97 | + } |
| 98 | + }); |
| 99 | + |
| 100 | + // tablayout add change listener |
| 101 | + tabIndicator.addOnTabSelectedListener(new TabLayout.BaseOnTabSelectedListener() { |
| 102 | + @Override |
| 103 | + public void onTabSelected(TabLayout.Tab tab) { |
| 104 | + |
| 105 | + if (tab.getPosition() == mList.size()-1) { |
| 106 | + loaddLastScreen(); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public void onTabUnselected(TabLayout.Tab tab) {} |
| 112 | + |
| 113 | + @Override |
| 114 | + public void onTabReselected(TabLayout.Tab tab) {} |
| 115 | + }); |
| 116 | + |
| 117 | + // Get Started button click listener |
| 118 | + btnGetStarted.setOnClickListener(new View.OnClickListener() { |
| 119 | + @Override |
| 120 | + public void onClick(View v) { |
| 121 | + |
| 122 | + //open main activity |
| 123 | + Intent mainActivity = new Intent(getApplicationContext(),MainActivity.class); |
| 124 | + |
| 125 | + startActivity(mainActivity); |
| 126 | + // also we need to save a boolean value to storage so next time when the user run the app |
| 127 | + // we could know that he is already checked the intro screen activity |
| 128 | + // i'm going to use shared preferences to that process |
| 129 | + savePrefsData(); |
| 130 | + finish(); |
| 131 | + |
| 132 | + } |
| 133 | + }); |
| 134 | + |
| 135 | + // skip button click listener |
| 136 | + tvSkip.setOnClickListener(new View.OnClickListener() { |
| 137 | + @Override |
| 138 | + public void onClick(View v) { |
| 139 | + //open main activity |
| 140 | + Intent mainActivity = new Intent(getApplicationContext(),MainActivity.class); |
| 141 | + |
| 142 | + startActivity(mainActivity); |
| 143 | + // also we need to save a boolean value to storage so next time when the user run the app |
| 144 | + // we could know that he is already checked the intro screen activity |
| 145 | + // i'm going to use shared preferences to that process |
| 146 | + savePrefsData(); |
| 147 | + finish(); |
| 148 | + } |
| 149 | + }); |
| 150 | + } |
| 151 | + |
| 152 | + private void savePrefsData() { |
| 153 | + SharedPreferences pref = getApplicationContext().getSharedPreferences("myPrefs",MODE_PRIVATE); |
| 154 | + SharedPreferences.Editor editor = pref.edit(); |
| 155 | + editor.putBoolean("isIntroOpnend",true); |
| 156 | + editor.commit(); |
| 157 | + } |
| 158 | + |
| 159 | + // show the GETSTARTED Button and hide the indicator and the next button |
| 160 | + private void loaddLastScreen() { |
| 161 | + |
| 162 | + btnNext.setVisibility(View.INVISIBLE); |
| 163 | + btnGetStarted.setVisibility(View.VISIBLE); |
| 164 | + tvSkip.setVisibility(View.INVISIBLE); |
| 165 | + tabIndicator.setVisibility(View.INVISIBLE); |
| 166 | + // TODO : ADD an animation the getstarted button |
| 167 | + // setup animation |
| 168 | + btnGetStarted.setAnimation(btnAnim); |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + } |
| 173 | +} |
0 commit comments