Skip to content

Commit

Permalink
add background color + placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
wailbabou committed Oct 11, 2018
1 parent 8f7396f commit f8da5ce
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void startSlider(){
.setColorInactive(Color.GRAY) // bottom indicator inactive color
.setImageUrls(imgs) // arraylist of image urls
.setCurrentImage(1) // the selected image ( starting from 0 )
.setBackgroundColor(Color.BLACK)
.start(this,99);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class OConfig {
private ArrayList<Uri> imagesURIs = new ArrayList<>() ;
private int colorActive,colorInactive;
private int currentImg=0;

private int backGroundColor=-99;
private int placeholder=-99;

public ArrayList<String> getImagesUrls() {
return imagesUrls;
Expand Down Expand Up @@ -51,4 +52,20 @@ public int getCurrentImg() {
public void setCurrentImg(int currentImg) {
this.currentImg = currentImg;
}

public int getBackGroundColor() {
return backGroundColor;
}

public void setBackGroundColor(int backGroundColor) {
this.backGroundColor = backGroundColor;
}

public int getPlaceholder() {
return placeholder;
}

public void setPlaceholder(int placeholder) {
this.placeholder = placeholder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public OImageSlider setCurrentImage(int position){
constants.setCurrentImg(position);
return this;
}
public OImageSlider setPlaceholder(int placeholder){
constants.setPlaceholder(placeholder);
return this;
}
public OImageSlider setBackgroundColor(int color){
constants.setBackGroundColor(color);
return this;
}
public void start(Context context,int requestCode){
Intent ii = new Intent(context,OSliderActivity.class);
ii.putExtra("data",new Gson().toJson(constants));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ public class OSingleFragment extends Fragment {
private PhotoView picture;
private String imgUrl;
private Uri imgUri;
private int placeholder = R.drawable.placeholder;

public OSingleFragment(){
}

@SuppressLint("ValidFragment")
public OSingleFragment(String url){
public OSingleFragment(String url,int placeholder){
imgUrl=url;
if(placeholder!=-99)
this.placeholder = placeholder;
}
@SuppressLint("ValidFragment")
public OSingleFragment(Uri uri){
public OSingleFragment(Uri uri,int placeholder){
imgUri=uri;
if(placeholder!=-99)
this.placeholder = placeholder;
}
@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


Expand All @@ -23,8 +24,9 @@ public class OSliderActivity extends AppCompatActivity {

private ViewPager viewPager;
private LinearLayout dotsLayout;
private RelativeLayout relativeLayout;
private TextView[] dots;
OConfig constants;
private OConfig constants;


@Override
Expand All @@ -37,16 +39,25 @@ protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_o_slider);
constants = new Gson().fromJson(getIntent().getStringExtra("data"),OConfig.class);

viewPager = findViewById(R.id.view_pager);
dotsLayout = findViewById(R.id.layoutDots);
initViews();

setupViewPager(viewPager);
viewPager.addOnPageChangeListener(viewPagerPageChangeListener);


viewPager.setCurrentItem(constants.getCurrentImg());
addBottomDots(constants.getCurrentImg());


}
public void initViews(){
viewPager = findViewById(R.id.view_pager);
dotsLayout = findViewById(R.id.layoutDots);
relativeLayout = findViewById(R.id.rel);

if(constants.getBackGroundColor()!=-99){
relativeLayout.setBackgroundColor(constants.getBackGroundColor());
}

}


Expand Down Expand Up @@ -74,11 +85,11 @@ private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
if(constants.getImagesUrls().size()>0){
for(int i=0 ; i<constants.getImagesUrls().size();i++){
adapter.addFrag(new OSingleFragment(constants.getImagesUrls().get(i)));
adapter.addFrag(new OSingleFragment(constants.getImagesUrls().get(i),constants.getPlaceholder()));
}
}else if (constants.getImagesURIs().size()>0){
for(int i=0 ; i<constants.getImagesURIs().size();i++){
adapter.addFrag(new OSingleFragment(constants.getImagesURIs().get(i)));
adapter.addFrag(new OSingleFragment(constants.getImagesURIs().get(i),constants.getPlaceholder()));
}
}
viewPager.setAdapter(adapter);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions imagesliderLib/src/main/res/layout/activity_o_slider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
<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:id="@+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:layout_height="match_parent" />

<LinearLayout
android:id="@+id/layoutDots"
Expand Down

0 comments on commit f8da5ce

Please sign in to comment.