-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hasan Badran
committed
Dec 26, 2018
1 parent
53653c3
commit 2e30c4f
Showing
16 changed files
with
289 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 @@ | ||
/build |
This file contains 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,37 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
|
||
|
||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
implementation 'com.android.support:recyclerview-v7:26.1.0' | ||
implementation 'com.android.support:cardview-v7:26.1.0' | ||
} |
This file contains 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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
colorview/src/androidTest/java/net/cryptobrewery/colorview/ExampleInstrumentedTest.java
This file contains 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,26 @@ | ||
package net.cryptobrewery.colorview; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("net.cryptobrewery.colorview.test", appContext.getPackageName()); | ||
} | ||
} |
This file contains 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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.cryptobrewery.colorview"> | ||
|
||
<application> | ||
<activity android:name=".ColorView"></activity> | ||
</application> | ||
|
||
</manifest> |
71 changes: 71 additions & 0 deletions
71
colorview/src/main/java/net/cryptobrewery/colorview/ColorAdapter.java
This file contains 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,71 @@ | ||
package net.cryptobrewery.colorview; | ||
|
||
import android.graphics.Color; | ||
import android.support.v7.widget.CardView; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* Created by Hasan Badran on 8/12/2018. | ||
*/ | ||
|
||
public class ColorAdapter extends RecyclerView.Adapter<ColorAdapter.ViewHolder>{ | ||
private String[] colors; | ||
private onCardColorClick listener; | ||
private int height,width; | ||
public ColorAdapter(String[] colors) { | ||
this.colors = colors; | ||
} | ||
|
||
public ColorAdapter(String[] colors, onCardColorClick listener) { | ||
this.colors = colors; | ||
this.listener = listener; | ||
} | ||
|
||
public ColorAdapter(String[] colors, onCardColorClick listener, int height, int width) { | ||
this.colors = colors; | ||
this.listener = listener; | ||
this.height = height; | ||
this.width = width; | ||
} | ||
|
||
public ColorAdapter(String[] colors, int height, int width) { | ||
this.colors = colors; | ||
this.height = height; | ||
this.width = width; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.color_item_box,parent,false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, int position) { | ||
|
||
|
||
holder.colorCard.setCardBackgroundColor(Color.parseColor(colors[position])); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return colors.length; | ||
} | ||
class ViewHolder extends RecyclerView.ViewHolder{ | ||
private CardView colorCard; | ||
private ViewHolder(View itemView) { | ||
super(itemView); | ||
colorCard = itemView.findViewById(R.id.color_rec_view); | ||
if(listener !=null){ | ||
itemView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
listener.ClickCallBack(); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
colorview/src/main/java/net/cryptobrewery/colorview/ColorView.java
This file contains 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,38 @@ | ||
package net.cryptobrewery.colorview; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.widget.RelativeLayout; | ||
|
||
public class ColorView extends RelativeLayout { | ||
private RecyclerView colorRecyclerView; | ||
private Context ctx; | ||
|
||
|
||
public ColorView(Context context) { | ||
super(context); | ||
this.ctx = context; | ||
init(); | ||
} | ||
|
||
public ColorView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
init(); | ||
|
||
} | ||
|
||
private void init() { | ||
inflate(ctx,R.layout.colorview,this); | ||
colorRecyclerView = findViewById(R.id.color_rec_view); | ||
LinearLayoutManager llm = new LinearLayoutManager(ctx); | ||
llm.setOrientation(LinearLayoutManager.HORIZONTAL); | ||
colorRecyclerView.setLayoutManager(llm); | ||
ColorAdapter adapter = new ColorAdapter(new String[]{"#99aafc","#831949","#941920"}); | ||
colorRecyclerView.setAdapter(adapter); | ||
colorRecyclerView.hasFixedSize(); | ||
colorRecyclerView.forceLayout(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
colorview/src/main/java/net/cryptobrewery/colorview/onCardColorClick.java
This file contains 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,9 @@ | ||
package net.cryptobrewery.colorview; | ||
|
||
/** | ||
* Created by Hasan Badran on 8/12/2018. | ||
*/ | ||
|
||
public interface onCardColorClick { | ||
void ClickCallBack(); | ||
} |
This file contains 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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/card" | ||
android:layout_width="25dp" | ||
android:layout_height="25dp"> | ||
|
||
|
||
</android.support.v7.widget.CardView> |
This file contains 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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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/root" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="net.cryptobrewery.colorview.ColorView"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/color_rec_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</RelativeLayout> |
This file contains 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,3 @@ | ||
<resources> | ||
<string name="app_name">colorView</string> | ||
</resources> |
17 changes: 17 additions & 0 deletions
17
colorview/src/test/java/net/cryptobrewery/colorview/ExampleUnitTest.java
This file contains 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,17 @@ | ||
package net.cryptobrewery.colorview; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void addition_isCorrect() throws Exception { | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
This file contains 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