-
Notifications
You must be signed in to change notification settings - Fork 4
Dk lecture assignments #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f8f48e3
changed the build.gradle file
dakshitagrawal 8ad67af
included recyclerview dependency
dakshitagrawal b3ed57b
MainActivity.java file containing recyclerview
dakshitagrawal 9eeffe5
activity_main.xml file containing recyclerview
dakshitagrawal a433e1f
changed the appbar title
dakshitagrawal bb154e0
contains all posters used in app
dakshitagrawal 2acc7eb
created a model for movies
dakshitagrawal 63aced2
created a layout for recyclerview item
dakshitagrawal 75e83c3
code for the item viewholder
dakshitagrawal 7460c78
wrote code for recycler view adapter
dakshitagrawal e9aeb7b
added design dependency
dakshitagrawal b9f9ac3
added second activity
dakshitagrawal 5497387
added FAB listener to main activity
dakshitagrawal a9c9cdf
added FAB
dakshitagrawal 3d7d331
changed accent color
dakshitagrawal f561951
added new activity for custom views
dakshitagrawal e0737fd
added custom view code
dakshitagrawal c055755
added right_arrow drawable
dakshitagrawal 88d781a
added custom behaviour of snackbar to seekbar
dakshitagrawal df44a1a
layout of custom view activity
dakshitagrawal 02ca934
attributes file for the progress rectangle custom view
dakshitagrawal 7bc5cde
added custom behavior to progress rectangle view
dakshitagrawal b9c0afd
updated layout for custom view activity
dakshitagrawal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/Adapter.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<ItemViewHolder> { | ||
| int moviesCount; | ||
| Context context; | ||
| ItemViewHolder itemViewHolder; | ||
| List<MoviesModel> moviesList; | ||
|
|
||
| public Adapter(Context context, List<MoviesModel> 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); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/CustomViewActivity.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| } | ||
| }); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ItemViewHolder.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MainActivity.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<MoviesModel> 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); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| } | ||
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MoviesModel.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangle.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| } | ||
|
|
||
| } |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/ProgressRectangleBehavior.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<ProgressRectangle>{ | ||
| 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; | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/SeekbarBehaviour.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<SeekBar> { | ||
|
|
||
| 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; | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use strings.xml to store the strings , it can be used elsewhere too.