diff --git a/app/build.gradle b/app/build.gradle index fe0a5c9..8e45b9f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,5 +25,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.1.0' + compile 'com.android.support:design:25.1.0' + compile 'com.android.support:recyclerview-v7:25.1.0' testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4bb1fd6..0937fd6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,6 +15,8 @@ + + \ No newline at end of file diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/Adapter.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/Adapter.java new file mode 100644 index 0000000..e4f02bd --- /dev/null +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/Adapter.java @@ -0,0 +1,93 @@ +package com.sdsmdg.hareshkh.lectureassignment; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Toast; + +import java.util.List; + +/** + * Created by shyam on 31-Jan-17. + */ + +public class Adapter extends RecyclerView.Adapter { + int moviesCount; + Context context; + ItemViewHolder itemViewHolder; + List moviesList; + + public Adapter(Context context, List moviesList){ + this.context = context; + moviesCount = moviesList.size(); + this.moviesList = moviesList; + } + + @Override + public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item,parent,false); + itemViewHolder = new ItemViewHolder(view); + return itemViewHolder; + } + + @Override + public void onBindViewHolder(ItemViewHolder holder, final int position) { + holder.movieName.setText(moviesList.get(position).getMovieName()); + holder.movieReleaseDate.setText(moviesList.get(position).getMovieReleaseDate()); + holder.moviePoster.setImageBitmap(decodeSampledBitmapFromResource(context.getResources(),moviesList.get(position).getMoviePoster(),55,90)); + + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(context,"You clicked on Movie Number " + (position+1),Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public int getItemCount() { + return moviesCount; + } + + public static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) { + + final int height = options.outHeight; + final int width = options.outWidth; + int inSampleSize = 1; + + if (height > reqHeight || width > reqWidth) { + + final int halfHeight = height / 2; + final int halfWidth = width / 2; + + // Calculate the largest inSampleSize value that is a power of 2 and keeps both + // height and width larger than the requested height and width. + while ((halfHeight / inSampleSize) >= reqHeight + && (halfWidth / inSampleSize) >= reqWidth) { + inSampleSize *= 2; + } + } + return inSampleSize; + } + + public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, + int reqWidth, int reqHeight) { + + // First decode with inJustDecodeBounds=true to check dimensions + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeResource(res, resId, options); + + // Calculate inSampleSize + options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); + + // Decode bitmap with inSampleSize set + options.inJustDecodeBounds = false; + return BitmapFactory.decodeResource(res, resId, options); + } +} diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/CustomViewActivity.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/CustomViewActivity.java new file mode 100644 index 0000000..95d5b82 --- /dev/null +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/CustomViewActivity.java @@ -0,0 +1,40 @@ +package com.sdsmdg.hareshkh.lectureassignment; + +import android.graphics.Color; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.SeekBar; + +public class CustomViewActivity extends AppCompatActivity{ + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_custom_view); + + final View view = findViewById(R.id.activity_custom_view); + SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar); + + + seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + ProgressRectangle progressRectangle = (ProgressRectangle) findViewById(R.id.progressRectangle); + progressRectangle.draw(progress); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + Snackbar.make(view,"Hello!",Snackbar.LENGTH_SHORT).show(); + } + }); + } +} diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ItemViewHolder.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ItemViewHolder.java new file mode 100644 index 0000000..51185e6 --- /dev/null +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ItemViewHolder.java @@ -0,0 +1,23 @@ +package com.sdsmdg.hareshkh.lectureassignment; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +/** + * Created by shyam on 31-Jan-17. + */ + +public class ItemViewHolder extends RecyclerView.ViewHolder { + ImageView moviePoster; + TextView movieName; + TextView movieReleaseDate; + + ItemViewHolder(View itemView){ + super(itemView); + moviePoster = (ImageView) itemView.findViewById(R.id.movie_poster); + movieName = (TextView) itemView.findViewById(R.id.movie_name); + movieReleaseDate = (TextView) itemView.findViewById(R.id.movie_releaseDate); + } +} diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MainActivity.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MainActivity.java index a42b22d..3c05052 100644 --- a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MainActivity.java +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MainActivity.java @@ -1,13 +1,56 @@ package com.sdsmdg.hareshkh.lectureassignment; +import android.content.Intent; +import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +import java.util.ArrayList; +import java.util.List; public class MainActivity extends AppCompatActivity { + List listOfMovies = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + RecyclerView listOfMoviesRecyclerView = (RecyclerView) findViewById(R.id.listOfMovies); + listOfMovies.add(0,new MoviesModel(R.drawable.the_secret_life_of_pets,"The Secret Life of Pets", "18-06-2016")); + listOfMovies.add(1,new MoviesModel(R.drawable.suicide_squad,"Suicide Squad", "02-08-2016")); + listOfMovies.add(2,new MoviesModel(R.drawable.la_la_land,"La La Land", "01-12-2016")); + listOfMovies.add(3,new MoviesModel(R.drawable.assassins_creed,"Assassin's Creed","21-12-2016")); + listOfMovies.add(4,new MoviesModel(R.drawable.finding_dory,"Finding Dory","16-06-2016")); + listOfMovies.add(5,new MoviesModel(R.drawable.jurassic_world,"Jurassic World","09-06-2015")); + listOfMovies.add(6,new MoviesModel(R.drawable.moana,"Moana","23-11-2016")); + listOfMovies.add(7,new MoviesModel(R.drawable.interstellar,"Interstellar","05-11-2014")); + listOfMovies.add(8,new MoviesModel(R.drawable.captain_america_civil_war,"Captain America: Civil War","27-04-2016")); + listOfMovies.add(9,new MoviesModel(R.drawable.mad_max_fury_road,"Mad Max:Fury Road","13-05-2015")); + listOfMovies.add(10,new MoviesModel(R.drawable.arrival,"Arrival","10-11-2016")); + listOfMovies.add(11,new MoviesModel(R.drawable.passengers,"Passengers","21-12-2016")); + listOfMovies.add(12,new MoviesModel(R.drawable.inferno,"Inferno","13-10-2016")); + listOfMovies.add(13,new MoviesModel(R.drawable.the_magnificient_seven,"The Magnificient Seven","14-09-2016")); + listOfMovies.add(14,new MoviesModel(R.drawable.split,"Split","19-01-2017")); + + Adapter adapter = new Adapter(this,listOfMovies); + LinearLayoutManager linearLayout = new LinearLayoutManager(this); + listOfMoviesRecyclerView.setAdapter(adapter); + listOfMoviesRecyclerView.setHasFixedSize(true); + listOfMoviesRecyclerView.setLayoutManager(linearLayout); + + FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.floatingActionButtonToCustomActivity); + floatingActionButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MainActivity.this, CustomViewActivity.class); + startActivity(intent); + } + }); } + + } diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MoviesModel.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MoviesModel.java new file mode 100644 index 0000000..d0302e2 --- /dev/null +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MoviesModel.java @@ -0,0 +1,41 @@ +package com.sdsmdg.hareshkh.lectureassignment; + +/** + * Created by shyam on 31-Jan-17. + */ + +public class MoviesModel{ + int moviePoster; + String movieName; + String movieReleaseDate; + + MoviesModel(int moviePoster, String movieName, String movieReleaseDate){ + this.movieName = movieName; + this.movieReleaseDate = movieReleaseDate; + this.moviePoster = moviePoster; + } + + public String getMovieName() { + return movieName; + } + + public void setMovieName(String movieName) { + this.movieName = movieName; + } + + public String getMovieReleaseDate() { + return movieReleaseDate; + } + + public void setMovieReleaseDate(String movieReleaseDate) { + this.movieReleaseDate = movieReleaseDate; + } + + public int getMoviePoster() { + return moviePoster; + } + + public void setMoviePoster(int moviePoster) { + this.moviePoster = moviePoster; + } +} diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangle.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangle.java new file mode 100644 index 0000000..2ef1949 --- /dev/null +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangle.java @@ -0,0 +1,55 @@ +package com.sdsmdg.hareshkh.lectureassignment; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.View; + +/** + * Created by shyam on 04-Feb-17. + */ + +public class ProgressRectangle extends View { + + public ProgressRectangle(Context context){ + super(context); + } + + Canvas canvas; + Paint paintBackground; + Paint paintProgress; + int progressColor; + int backgroundColor; + int progress = 0; + + public ProgressRectangle (Context context, AttributeSet attributeSet){ + super(context,attributeSet); + + TypedArray array = context.obtainStyledAttributes(attributeSet,R.styleable.ProgressRectangle); + progressColor = array.getColor(R.styleable.ProgressRectangle_progressColor,Color.rgb(255,140,0)); + backgroundColor = array.getColor(R.styleable.ProgressRectangle_backgroundColor,Color.GRAY); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + this.canvas = canvas; + paintBackground = new Paint(); + paintBackground.setStyle(Paint.Style.FILL); + paintBackground.setColor(backgroundColor); + paintProgress = new Paint(); + paintProgress.setColor(progressColor); + paintProgress.setStyle(Paint.Style.FILL); + canvas.drawRect(progress*canvas.getWidth()/100,550,canvas.getWidth(),650,paintBackground); + canvas.drawRect(0,550,progress*canvas.getWidth()/100,650,paintProgress); + } + + public void draw(int progress){ + this.progress = progress; + invalidate(); + } + +} diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangleBehavior.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangleBehavior.java new file mode 100644 index 0000000..03fb13f --- /dev/null +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangleBehavior.java @@ -0,0 +1,29 @@ +package com.sdsmdg.hareshkh.lectureassignment; + +import android.content.Context; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.Snackbar; +import android.util.AttributeSet; +import android.view.View; + +/** + * Created by shyam on 06-Feb-17. + */ + +public class ProgressRectangleBehavior extends CoordinatorLayout.Behavior{ + public ProgressRectangleBehavior(Context context, AttributeSet attributeSet){ + super(context,attributeSet); + } + + @Override + public boolean layoutDependsOn(CoordinatorLayout parent, ProgressRectangle child, View dependency) { + return dependency instanceof Snackbar.SnackbarLayout; + } + + @Override + public boolean onDependentViewChanged(CoordinatorLayout parent, ProgressRectangle child, View dependency) { + float translationY = Math.min(0, dependency.getTranslationY()-dependency.getHeight()); + child.setTranslationY(translationY); + return true; + } +} diff --git a/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/SeekbarBehaviour.java b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/SeekbarBehaviour.java new file mode 100644 index 0000000..2d29b66 --- /dev/null +++ b/app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/SeekbarBehaviour.java @@ -0,0 +1,31 @@ +package com.sdsmdg.hareshkh.lectureassignment; + +import android.content.Context; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.Snackbar; +import android.util.AttributeSet; +import android.view.View; +import android.widget.SeekBar; + +/** + * Created by shyam on 05-Feb-17. + */ + +public class SeekbarBehaviour extends CoordinatorLayout.Behavior { + + public SeekbarBehaviour(Context context, AttributeSet attributeSet){ + super(context,attributeSet); + } + + @Override + public boolean layoutDependsOn(CoordinatorLayout parent, SeekBar child, View dependency) { + return dependency instanceof Snackbar.SnackbarLayout; + } + + @Override + public boolean onDependentViewChanged(CoordinatorLayout parent, SeekBar child, View dependency) { + float translationY = Math.min(0, dependency.getTranslationY()-dependency.getHeight()); + child.setTranslationY(translationY); + return true; + } +} diff --git a/app/src/main/res/drawable/arrival.jpg b/app/src/main/res/drawable/arrival.jpg new file mode 100644 index 0000000..323d300 Binary files /dev/null and b/app/src/main/res/drawable/arrival.jpg differ diff --git a/app/src/main/res/drawable/assassins_creed.jpg b/app/src/main/res/drawable/assassins_creed.jpg new file mode 100644 index 0000000..a8d43f5 Binary files /dev/null and b/app/src/main/res/drawable/assassins_creed.jpg differ diff --git a/app/src/main/res/drawable/captain_america_civil_war.jpg b/app/src/main/res/drawable/captain_america_civil_war.jpg new file mode 100644 index 0000000..a20fec7 Binary files /dev/null and b/app/src/main/res/drawable/captain_america_civil_war.jpg differ diff --git a/app/src/main/res/drawable/finding_dory.jpg b/app/src/main/res/drawable/finding_dory.jpg new file mode 100644 index 0000000..f571b16 Binary files /dev/null and b/app/src/main/res/drawable/finding_dory.jpg differ diff --git a/app/src/main/res/drawable/inferno.jpg b/app/src/main/res/drawable/inferno.jpg new file mode 100644 index 0000000..0d2e513 Binary files /dev/null and b/app/src/main/res/drawable/inferno.jpg differ diff --git a/app/src/main/res/drawable/interstellar.jpg b/app/src/main/res/drawable/interstellar.jpg new file mode 100644 index 0000000..bef3295 Binary files /dev/null and b/app/src/main/res/drawable/interstellar.jpg differ diff --git a/app/src/main/res/drawable/jurassic_world.jpg b/app/src/main/res/drawable/jurassic_world.jpg new file mode 100644 index 0000000..c12e17e Binary files /dev/null and b/app/src/main/res/drawable/jurassic_world.jpg differ diff --git a/app/src/main/res/drawable/la_la_land.jpg b/app/src/main/res/drawable/la_la_land.jpg new file mode 100644 index 0000000..6ebcbbe Binary files /dev/null and b/app/src/main/res/drawable/la_la_land.jpg differ diff --git a/app/src/main/res/drawable/mad_max_fury_road.jpg b/app/src/main/res/drawable/mad_max_fury_road.jpg new file mode 100644 index 0000000..934d90b Binary files /dev/null and b/app/src/main/res/drawable/mad_max_fury_road.jpg differ diff --git a/app/src/main/res/drawable/moana.jpg b/app/src/main/res/drawable/moana.jpg new file mode 100644 index 0000000..d331510 Binary files /dev/null and b/app/src/main/res/drawable/moana.jpg differ diff --git a/app/src/main/res/drawable/passengers.jpg b/app/src/main/res/drawable/passengers.jpg new file mode 100644 index 0000000..bc7d93f Binary files /dev/null and b/app/src/main/res/drawable/passengers.jpg differ diff --git a/app/src/main/res/drawable/right_arrow.xml b/app/src/main/res/drawable/right_arrow.xml new file mode 100644 index 0000000..00f17fa --- /dev/null +++ b/app/src/main/res/drawable/right_arrow.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/split.jpg b/app/src/main/res/drawable/split.jpg new file mode 100644 index 0000000..6768330 Binary files /dev/null and b/app/src/main/res/drawable/split.jpg differ diff --git a/app/src/main/res/drawable/suicide_squad.jpg b/app/src/main/res/drawable/suicide_squad.jpg new file mode 100644 index 0000000..70bbfd7 Binary files /dev/null and b/app/src/main/res/drawable/suicide_squad.jpg differ diff --git a/app/src/main/res/drawable/the_magnificient_seven.jpg b/app/src/main/res/drawable/the_magnificient_seven.jpg new file mode 100644 index 0000000..68fd622 Binary files /dev/null and b/app/src/main/res/drawable/the_magnificient_seven.jpg differ diff --git a/app/src/main/res/drawable/the_secret_life_of_pets.jpg b/app/src/main/res/drawable/the_secret_life_of_pets.jpg new file mode 100644 index 0000000..265ed10 Binary files /dev/null and b/app/src/main/res/drawable/the_secret_life_of_pets.jpg differ diff --git a/app/src/main/res/layout/activity_custom_view.xml b/app/src/main/res/layout/activity_custom_view.xml new file mode 100644 index 0000000..e1201aa --- /dev/null +++ b/app/src/main/res/layout/activity_custom_view.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 809dd02..eb70da9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -10,8 +10,19 @@ android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.sdsmdg.hareshkh.lectureassignment.MainActivity"> - + + + + android:layout_alignParentBottom="true" + android:layout_alignParentEnd="true" + android:src = "@drawable/right_arrow" + /> + diff --git a/app/src/main/res/layout/recyclerview_item.xml b/app/src/main/res/layout/recyclerview_item.xml new file mode 100644 index 0000000..d4e2658 --- /dev/null +++ b/app/src/main/res/layout/recyclerview_item.xml @@ -0,0 +1,39 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/ProgressRectangleAttributes.xml b/app/src/main/res/values/ProgressRectangleAttributes.xml new file mode 100644 index 0000000..3425410 --- /dev/null +++ b/app/src/main/res/values/ProgressRectangleAttributes.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 223979f..19d5212 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - LectureAssignment + Movies List diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..27bfaa4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -5,7 +5,7 @@ @color/colorPrimary @color/colorPrimaryDark - @color/colorAccent + #FF8C00 diff --git a/gradle.properties b/gradle.properties index aac7c9b..869e8ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx1536m +org.gradle.jvmargs=-Xmx1024m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit