Skip to content

Commit

Permalink
ADD: added bubbles and gradient to banner
Browse files Browse the repository at this point in the history
  • Loading branch information
bxute committed Apr 20, 2018
1 parent 916c1ce commit 69c8aac
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 46 deletions.
18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 27
defaultConfig {
applicationId "app.kiti.com.kitiapp"
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -20,19 +20,19 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.firebase:firebase-auth:15.0.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
implementation 'com.google.android.gms:play-services-ads:12.0.1'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.google.firebase:firebase-database:15.0.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.android.support:cardview-v7:27.1.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.kiti.com.kitiapp.banner;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -14,9 +13,7 @@

import app.kiti.com.kitiapp.R;
import app.kiti.com.kitiapp.custom.joke.CustomViewPager;
import app.kiti.com.kitiapp.custom.joke.JokePagerAdapter;
import app.kiti.com.kitiapp.custom.joke.SlideController;
import app.kiti.com.kitiapp.utils.ReadingTimeCalculater;
import butterknife.BindView;
import butterknife.ButterKnife;

Expand All @@ -29,6 +26,8 @@ public class AutoSlideBannerView extends FrameLayout implements SlideController.
private static final double SCROLL_DELAY_FACTOR = 10;
@BindView(R.id.viewPager)
CustomViewPager viewPager;
@BindView(R.id.bubble_view)
BubbleView bubbleView;

private Context mContext;

Expand Down Expand Up @@ -62,6 +61,7 @@ private void init(Context context) {

viewPager.setAdapter(bannerPagerAdapter);
viewPager.setScrollDurationFactor(SCROLL_DELAY_FACTOR);
viewPager.setPageTransformer(false,new PageTransformer());
slideController = new SlideController();
slideController.setSlideEventListener(this);
disableUserSwipeControl(viewPager);
Expand All @@ -75,14 +75,19 @@ public void setImageUrls(ArrayList<String> imageUrls) {
int[] times = getScrollingTimes(imageUrls.size());
slideController.setIntervalOfTick(1000);
slideController.setTimeIntervals(times);

//init bubbles
bubbleView.setBubbleCount(imageUrls.size());
bubbleView.init();

// we can now start sliding
slideController.start();

}

private int[] getScrollingTimes(int size) {
int[] times = new int[size];
for(int i=0;i<size;i++){
for (int i = 0; i < size; i++) {
times[i] = DEFAULT_IMAGE_SLIDE_DURATION;
}
return times;
Expand All @@ -96,11 +101,13 @@ public void cancelSliding() {
@Override
public void changeSlideTo(int slideNumber) {
viewPager.setCurrentItem(slideNumber);
//change bubble
bubbleView.setSelectionIndex(slideNumber);
}

@Override
public void progressChangedTo(long timeLeftInMillis, long progressPercent) {
// in future, use this to change bubbles
// in future, use this to change bubbles
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class BannerPagerAdapter extends PagerAdapter {
private Context mContext;
private ArrayList<String> imageUrls;
private int size;

public BannerPagerAdapter(Context context) {
mContext = context;
Expand All @@ -30,16 +31,19 @@ public BannerPagerAdapter(Context context) {

public void setImageUrls(ArrayList<String> imageUrls) {
this.imageUrls = imageUrls;
this.size = imageUrls.size();
notifyDataSetChanged();
}

@Override
public Object instantiateItem(ViewGroup container, int position) {

View view = LayoutInflater.from(mContext).inflate(R.layout.banner_image_view, container, false);
ImageView bannerIv = view.findViewById(R.id.bannerIv);
loadImage(bannerIv, imageUrls.get(position));
container.addView(view);
return view;

}

@Override
Expand All @@ -49,7 +53,7 @@ public void destroyItem(ViewGroup collection, int position, Object view) {

@Override
public int getCount() {
return imageUrls.size();
return size;
}

@Override
Expand Down
110 changes: 110 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/banner/BubbleView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package app.kiti.com.kitiapp.banner;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import app.kiti.com.kitiapp.R;
import app.kiti.com.kitiapp.utils.FontManager;
import app.kiti.com.kitiapp.utils.PixelUtils;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
* Created by Ankit on 4/20/2018.
*/

public class BubbleView extends FrameLayout {

@BindView(R.id.container)
LinearLayout container;
private Context mContext;
private int mBubbleCount;

public static final String bubble_text = "\uF111";
private int mLastSelection = 0;

public BubbleView(@NonNull Context context) {
super(context);
init(context);
}

public BubbleView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}

public BubbleView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}

private void init(Context context) {
this.mContext = context;
View view = LayoutInflater.from(mContext).inflate(R.layout.bubble_view, this);
ButterKnife.bind(this, view);

}

public void setBubbleCount(int bubbleCount) {
this.mBubbleCount = bubbleCount;
}

public void setSelectionIndex(int index) {

resetLastSelection();
TextView target = (TextView) container.getChildAt(index);
target.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
this.mLastSelection = index;

}

private void resetLastSelection() {
TextView target = (TextView) container.getChildAt(mLastSelection);
target.setTextColor(Color.parseColor("#ffffff"));
}

public void init() {

if (mBubbleCount > 1) {
addBubbles();
} else {
throw new IllegalArgumentException("There should be atleast two bubble!");
}

setSelectionIndex(0);

}

private void addBubbles() {

for (int i = 0; i < mBubbleCount; i++) {

TextView textView = new TextView(mContext);
textView.setText(bubble_text);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 8);
textView.setTextColor(Color.parseColor("#ffffff"));
int padding = PixelUtils.dpToPx(2);
textView.setPadding(padding, padding, padding, padding);
textView.setTypeface(FontManager.getInstance().getTypeFace());
container.addView(
textView,
i,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
);

}
}

}
27 changes: 27 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/banner/PageTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app.kiti.com.kitiapp.banner;

import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
* Created by Ankit on 4/20/2018.
*/

public class PageTransformer implements ViewPager.PageTransformer {
@Override
public void transformPage(@NonNull View view, float position) {

view.setTranslationX(view.getWidth() * -position);

if (position <= -1.0F || position >= 1.0F) {
view.setAlpha(0.0F);
} else if (position == 0.0F) {
view.setAlpha(1.0F);
} else {
// position is between -1.0F & 0.0F OR 0.0F & 1.0F
view.setAlpha(1.0F - Math.abs(position));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ private String getTime(long timeLeftInMillis) {
int min = inSecond / 60;
int sec = inSecond % 60;
if (inSecond > 60) {
return String.format("%d Min %d Sec",min , sec );
}else{
return String.format("%d Sec",inSecond);
return String.format("%d Min %d Sec", min, sec);
} else {
return String.format("%d Sec", inSecond);
}
}

Expand All @@ -143,4 +143,9 @@ public boolean onTouch(View v, MotionEvent event) {
});
}

public void startSliding() {
if (slideController != null) {
slideController.start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class JokePagerAdapter extends PagerAdapter {

private Context mContext;
private ArrayList<String> jokes;
int size;

public JokePagerAdapter(Context context) {
mContext = context;
Expand All @@ -27,11 +28,13 @@ public JokePagerAdapter(Context context) {

public void setJokes(ArrayList<String> jokes) {
this.jokes = jokes;
this.size = jokes.size();
notifyDataSetChanged();
}

@Override
public Object instantiateItem(ViewGroup container, int position) {

View view = LayoutInflater.from(mContext).inflate(R.layout.joke_text_view, container, false);
TextView jokeTv = view.findViewById(R.id.joke_tv);
jokeTv.setText(jokes.get(position));
Expand All @@ -46,7 +49,7 @@ public void destroyItem(ViewGroup collection, int position, Object view) {

@Override
public int getCount() {
return jokes.size();
return size;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import app.kiti.com.kitiapp.R;
import app.kiti.com.kitiapp.activity.OptionsActivity;
import app.kiti.com.kitiapp.banner.AutoSlideBannerView;
import app.kiti.com.kitiapp.banner.BubbleView;
import app.kiti.com.kitiapp.custom.joke.AutoSlideJokeView;
import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -101,19 +102,8 @@ private void addBannerImages() {
ArrayList<String> imageUrls = new ArrayList<>();
imageUrls.add("https://www.chitramala.in/wp-content/uploads/2014/09/kajal-agarwal-success-secret.jpg");
imageUrls.add("http://imgcdn.raagalahari.com/dec2012/hd/special-chabbis-heroine-kajal-aggarwal/special-chabbis-heroine-kajal-aggarwal6.jpg");
imageUrls.add("http://www.indiancinemagallery.com/gallery/kajal-agarwal/Kajal-Agarwal-stills-from-Jilla-movie-(4)3824.JPG");
imageUrls.add("https://www.chitramala.in/wp-content/uploads/2014/09/kajal-agarwal-success-secret.jpg");
imageUrls.add("http://imgcdn.raagalahari.com/dec2012/hd/special-chabbis-heroine-kajal-aggarwal/special-chabbis-heroine-kajal-aggarwal6.jpg");
imageUrls.add("http://www.indiancinemagallery.com/gallery/kajal-agarwal/Kajal-Agarwal-stills-from-Jilla-movie-(4)3824.JPG");
imageUrls.add("https://www.chitramala.in/wp-content/uploads/2014/09/kajal-agarwal-success-secret.jpg");
imageUrls.add("http://imgcdn.raagalahari.com/dec2012/hd/special-chabbis-heroine-kajal-aggarwal/special-chabbis-heroine-kajal-aggarwal6.jpg");
imageUrls.add("http://www.indiancinemagallery.com/gallery/kajal-agarwal/Kajal-Agarwal-stills-from-Jilla-movie-(4)3824.JPG");
imageUrls.add("https://www.chitramala.in/wp-content/uploads/2014/09/kajal-agarwal-success-secret.jpg");
imageUrls.add("http://imgcdn.raagalahari.com/dec2012/hd/special-chabbis-heroine-kajal-aggarwal/special-chabbis-heroine-kajal-aggarwal6.jpg");
imageUrls.add("http://www.indiancinemagallery.com/gallery/kajal-agarwal/Kajal-Agarwal-stills-from-Jilla-movie-(4)3824.JPG");
imageUrls.add("https://www.chitramala.in/wp-content/uploads/2014/09/kajal-agarwal-success-secret.jpg");
imageUrls.add("http://imgcdn.raagalahari.com/dec2012/hd/special-chabbis-heroine-kajal-aggarwal/special-chabbis-heroine-kajal-aggarwal6.jpg");
imageUrls.add("http://www.indiancinemagallery.com/gallery/kajal-agarwal/Kajal-Agarwal-stills-from-Jilla-movie-(4)3824.JPG");

bannerSlider.setImageUrls(imageUrls);

Expand Down
Loading

0 comments on commit 69c8aac

Please sign in to comment.