Skip to content
Merged
Show file tree
Hide file tree
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 Jan 31, 2017
8ad67af
included recyclerview dependency
dakshitagrawal Jan 31, 2017
b3ed57b
MainActivity.java file containing recyclerview
dakshitagrawal Jan 31, 2017
9eeffe5
activity_main.xml file containing recyclerview
dakshitagrawal Jan 31, 2017
a433e1f
changed the appbar title
dakshitagrawal Jan 31, 2017
bb154e0
contains all posters used in app
dakshitagrawal Jan 31, 2017
2acc7eb
created a model for movies
dakshitagrawal Jan 31, 2017
63aced2
created a layout for recyclerview item
dakshitagrawal Jan 31, 2017
75e83c3
code for the item viewholder
dakshitagrawal Jan 31, 2017
7460c78
wrote code for recycler view adapter
dakshitagrawal Jan 31, 2017
e9aeb7b
added design dependency
dakshitagrawal Feb 5, 2017
b9f9ac3
added second activity
dakshitagrawal Feb 5, 2017
5497387
added FAB listener to main activity
dakshitagrawal Feb 5, 2017
a9c9cdf
added FAB
dakshitagrawal Feb 5, 2017
3d7d331
changed accent color
dakshitagrawal Feb 5, 2017
f561951
added new activity for custom views
dakshitagrawal Feb 5, 2017
e0737fd
added custom view code
dakshitagrawal Feb 5, 2017
c055755
added right_arrow drawable
dakshitagrawal Feb 5, 2017
88d781a
added custom behaviour of snackbar to seekbar
dakshitagrawal Feb 5, 2017
df44a1a
layout of custom view activity
dakshitagrawal Feb 5, 2017
02ca934
attributes file for the progress rectangle custom view
dakshitagrawal Feb 5, 2017
7bc5cde
added custom behavior to progress rectangle view
dakshitagrawal Feb 5, 2017
b9c0afd
updated layout for custom view activity
dakshitagrawal Feb 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CustomViewActivity">
</activity>
</application>

</manifest>
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);
}
}
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();
}
});
}
}
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);
}
}
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"));

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.

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);
}
});
}


}
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;
}
}
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();
}

}
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;
}
}
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;
}
}
Binary file added app/src/main/res/drawable/arrival.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/assassins_creed.jpg
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.
Binary file added app/src/main/res/drawable/finding_dory.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/inferno.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/interstellar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/jurassic_world.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/la_la_land.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/mad_max_fury_road.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/moana.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/passengers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading