Skip to content

Commit 2e30c4f

Browse files
author
Hasan Badran
committed
code improve
1 parent 53653c3 commit 2e30c4f

File tree

16 files changed

+289
-2
lines changed

16 files changed

+289
-2
lines changed

.idea/caches/build_file_checksums.ser

594 Bytes
Binary file not shown.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/net/cryptobrewery/syntaxviewexample/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
4545
syntax_view.checkMyCode();
4646

4747
//on text change listener
48-
syntax_view.code.addTextChangedListener(new TextWatcher() {
48+
syntax_view.getCode().addTextChangedListener(new TextWatcher() {
4949
@Override
5050
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
5151
}

colorview/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

colorview/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 26
5+
6+
7+
8+
defaultConfig {
9+
minSdkVersion 16
10+
targetSdkVersion 26
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
}
26+
27+
dependencies {
28+
implementation fileTree(dir: 'libs', include: ['*.jar'])
29+
30+
implementation 'com.android.support:appcompat-v7:26.1.0'
31+
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
32+
testImplementation 'junit:junit:4.12'
33+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
34+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35+
implementation 'com.android.support:recyclerview-v7:26.1.0'
36+
implementation 'com.android.support:cardview-v7:26.1.0'
37+
}

colorview/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.cryptobrewery.colorview;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("net.cryptobrewery.colorview.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="net.cryptobrewery.colorview">
4+
5+
<application>
6+
<activity android:name=".ColorView"></activity>
7+
</application>
8+
9+
</manifest>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package net.cryptobrewery.colorview;
2+
3+
import android.graphics.Color;
4+
import android.support.v7.widget.CardView;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
/**
11+
* Created by Hasan Badran on 8/12/2018.
12+
*/
13+
14+
public class ColorAdapter extends RecyclerView.Adapter<ColorAdapter.ViewHolder>{
15+
private String[] colors;
16+
private onCardColorClick listener;
17+
private int height,width;
18+
public ColorAdapter(String[] colors) {
19+
this.colors = colors;
20+
}
21+
22+
public ColorAdapter(String[] colors, onCardColorClick listener) {
23+
this.colors = colors;
24+
this.listener = listener;
25+
}
26+
27+
public ColorAdapter(String[] colors, onCardColorClick listener, int height, int width) {
28+
this.colors = colors;
29+
this.listener = listener;
30+
this.height = height;
31+
this.width = width;
32+
}
33+
34+
public ColorAdapter(String[] colors, int height, int width) {
35+
this.colors = colors;
36+
this.height = height;
37+
this.width = width;
38+
}
39+
40+
@Override
41+
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
42+
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.color_item_box,parent,false));
43+
}
44+
45+
@Override
46+
public void onBindViewHolder(ViewHolder holder, int position) {
47+
48+
49+
holder.colorCard.setCardBackgroundColor(Color.parseColor(colors[position]));
50+
}
51+
52+
@Override
53+
public int getItemCount() {
54+
return colors.length;
55+
}
56+
class ViewHolder extends RecyclerView.ViewHolder{
57+
private CardView colorCard;
58+
private ViewHolder(View itemView) {
59+
super(itemView);
60+
colorCard = itemView.findViewById(R.id.color_rec_view);
61+
if(listener !=null){
62+
itemView.setOnClickListener(new View.OnClickListener() {
63+
@Override
64+
public void onClick(View view) {
65+
listener.ClickCallBack();
66+
}
67+
});
68+
}
69+
}
70+
}
71+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package net.cryptobrewery.colorview;
2+
3+
import android.content.Context;
4+
import android.support.v7.widget.LinearLayoutManager;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.util.AttributeSet;
7+
import android.view.View;
8+
import android.widget.RelativeLayout;
9+
10+
public class ColorView extends RelativeLayout {
11+
private RecyclerView colorRecyclerView;
12+
private Context ctx;
13+
14+
15+
public ColorView(Context context) {
16+
super(context);
17+
this.ctx = context;
18+
init();
19+
}
20+
21+
public ColorView(Context context, AttributeSet attrs) {
22+
super(context, attrs);
23+
init();
24+
25+
}
26+
27+
private void init() {
28+
inflate(ctx,R.layout.colorview,this);
29+
colorRecyclerView = findViewById(R.id.color_rec_view);
30+
LinearLayoutManager llm = new LinearLayoutManager(ctx);
31+
llm.setOrientation(LinearLayoutManager.HORIZONTAL);
32+
colorRecyclerView.setLayoutManager(llm);
33+
ColorAdapter adapter = new ColorAdapter(new String[]{"#99aafc","#831949","#941920"});
34+
colorRecyclerView.setAdapter(adapter);
35+
colorRecyclerView.hasFixedSize();
36+
colorRecyclerView.forceLayout();
37+
}
38+
}

0 commit comments

Comments
 (0)