Skip to content

Commit

Permalink
code improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasan Badran committed Dec 26, 2018
1 parent 53653c3 commit 2e30c4f
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 2 deletions.
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
syntax_view.checkMyCode();

//on text change listener
syntax_view.code.addTextChangedListener(new TextWatcher() {
syntax_view.getCode().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
Expand Down
1 change: 1 addition & 0 deletions colorview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions colorview/build.gradle
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'
}
21 changes: 21 additions & 0 deletions colorview/proguard-rules.pro
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
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());
}
}
9 changes: 9 additions & 0 deletions colorview/src/main/AndroidManifest.xml
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>
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 colorview/src/main/java/net/cryptobrewery/colorview/ColorView.java
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();
}
}
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();
}
8 changes: 8 additions & 0 deletions colorview/src/main/res/layout/color_item_box.xml
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>
14 changes: 14 additions & 0 deletions colorview/src/main/res/layout/colorview.xml
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>
3 changes: 3 additions & 0 deletions colorview/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">colorView</string>
</resources>
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.regex.Pattern;

public class SyntaxView extends RelativeLayout {
public MaterialEditText code;
private MaterialEditText code;
int oldLength, newLength;
private SyntaxHighlighter keywords = new SyntaxHighlighter(
Pattern.compile(
Expand Down Expand Up @@ -369,5 +369,9 @@ public char getLastDifference(String a,String b){
public void setAutoIndent(boolean val){
this.autoIndent = val;
}

public MaterialEditText getCode() {
return code;
}
}

0 comments on commit 2e30c4f

Please sign in to comment.