Created
July 10, 2018 11:23
-
-
Save xsahil03x/e58b5eb0597c966f907c87aae871f256 to your computer and use it in GitHub Desktop.
On Boarding Screen With Videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#E6EAEE" | |
tools:context=".OnBoardingActivity"> | |
<android.support.v4.view.ViewPager | |
android:id="@+id/vp_tutorial" | |
android:layout_width="620dp" | |
android:layout_height="350dp" | |
android:background="@color/colorAccent" | |
android:layout_centerInParent="true" /> | |
<LinearLayout | |
android:id="@+id/dots" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_alignParentBottom="true" | |
android:layout_below="@id/vp_tutorial" | |
android:layout_centerInParent="true" | |
android:orientation="horizontal" /> | |
<ImageButton | |
android:id="@+id/btnBack" | |
android:layout_width="50dp" | |
android:layout_height="50dp" | |
android:layout_alignParentEnd="true" | |
android:layout_alignTop="@+id/btnNext" | |
android:layout_marginEnd="325dp" | |
android:onClick="setBack" | |
app:srcCompat="@color/colorAccent" /> | |
<ImageButton | |
android:id="@+id/btnNext" | |
android:layout_width="50dp" | |
android:layout_height="50dp" | |
android:layout_alignParentBottom="true" | |
android:layout_alignParentStart="true" | |
android:layout_marginBottom="25dp" | |
android:layout_marginStart="315dp" | |
android:onClick="setNext" | |
app:srcCompat="@color/colorAccent" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<VideoView | |
android:id="@+id/vp_item" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_centerInParent="true" | |
/> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.magarex.moviemania; | |
import android.content.SharedPreferences; | |
import android.os.Bundle; | |
import android.preference.PreferenceManager; | |
import android.support.v4.view.ViewPager; | |
import android.support.v7.app.AppCompatActivity; | |
import android.text.Html; | |
import android.view.View; | |
import android.widget.ImageButton; | |
import android.widget.LinearLayout; | |
import android.widget.TextView; | |
import com.magarex.moviemania.Adapter.SliderAdapter; | |
public class OnBoardingActivity extends AppCompatActivity { | |
public static final String COMPLETED_ONBOARDING = "completed_onboarding"; | |
private ViewPager vp_tutorial; | |
private LinearLayout dots; | |
private ImageButton btnNext, btnBack; | |
private int mCurrentPage; | |
ViewPager.OnPageChangeListener viewListener = new ViewPager.OnPageChangeListener() { | |
@Override | |
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | |
} | |
@Override | |
public void onPageSelected(int position) { | |
mCurrentPage = position; | |
addDotIndicator(position); | |
if (position == 0) { | |
btnBack.setEnabled(false); | |
btnBack.setVisibility(View.INVISIBLE); | |
btnNext.setEnabled(true); | |
} else if (position == 1) { | |
btnBack.setEnabled(true); | |
btnBack.setVisibility(View.VISIBLE); | |
btnNext.setEnabled(true); | |
} else if (position == 2) { | |
btnBack.setEnabled(true); | |
btnBack.setVisibility(View.VISIBLE); | |
btnNext.setEnabled(true); | |
} | |
} | |
@Override | |
public void onPageScrollStateChanged(int state) { | |
} | |
}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_on_boarding); | |
vp_tutorial = findViewById(R.id.vp_tutorial); | |
dots = findViewById(R.id.dots); | |
btnBack = findViewById(R.id.btnBack); | |
btnNext = findViewById(R.id.btnNext); | |
SliderAdapter mAdapter = new SliderAdapter(OnBoardingActivity.this); | |
vp_tutorial.setAdapter(mAdapter); | |
addDotIndicator(0); | |
vp_tutorial.addOnPageChangeListener(viewListener); | |
} | |
public void setNext(View view) { | |
if (mCurrentPage == 1) { | |
SharedPreferences.Editor sharedPreferencesEditor = | |
PreferenceManager.getDefaultSharedPreferences(OnBoardingActivity.this).edit(); | |
sharedPreferencesEditor.putBoolean(COMPLETED_ONBOARDING, true); | |
sharedPreferencesEditor.apply(); | |
finish(); | |
} else | |
vp_tutorial.setCurrentItem(mCurrentPage + 1, true); | |
} | |
public void setBack(View view) { | |
vp_tutorial.setCurrentItem(mCurrentPage - 1, true); | |
} | |
public void addDotIndicator(int position) { | |
TextView[] mDots = new TextView[2]; | |
dots.removeAllViews(); | |
for (int i = 0; i < mDots.length; i++) { | |
mDots[i] = new TextView(OnBoardingActivity.this); | |
mDots[i].setText(Html.fromHtml("•")); | |
mDots[i].setTextSize(35); | |
mDots[i].setTextColor(getResources().getColor(R.color.shimmer_background_color)); | |
dots.addView(mDots[i]); | |
} | |
mDots[position].setTextColor(getResources().getColor(R.color.colorAccent)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.magarex.moviemania.Adapter; | |
import android.content.Context; | |
import android.net.Uri; | |
import android.support.annotation.NonNull; | |
import android.support.v4.view.PagerAdapter; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.MediaController; | |
import android.widget.RelativeLayout; | |
import android.widget.VideoView; | |
import com.magarex.moviemania.R; | |
public class SliderAdapter extends PagerAdapter { | |
private Context mContext; | |
private LayoutInflater mInflator; | |
private int[] videos = { | |
R.raw.sample1, | |
R.raw.sampletwo | |
}; | |
public SliderAdapter(Context context) { | |
this.mContext = context; | |
} | |
@Override | |
public int getCount() { | |
return videos.length; | |
} | |
@Override | |
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { | |
return view == object; | |
} | |
@NonNull | |
@Override | |
public Object instantiateItem(@NonNull ViewGroup container, int position) { | |
mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
View view = mInflator.inflate(R.layout.activity_on_boarding_item, container, false); | |
VideoView vp_item = view.findViewById(R.id.vp_item); | |
MediaController mediaController = new MediaController(mContext); | |
mediaController.setAnchorView(vp_item); | |
vp_item.setMediaController(mediaController); | |
vp_item.setVideoURI(Uri.parse("android.resource://" + mContext.getPackageName()+ "/" + videos[position])); | |
vp_item.start(); | |
container.addView(view); | |
return view; | |
} | |
@Override | |
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { | |
container.removeView((RelativeLayout) object); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment