Skip to content

Commit

Permalink
Merge pull request #6 from nakshay/languagefeature
Browse files Browse the repository at this point in the history
Languagefeature merge with Master branch
  • Loading branch information
nakshay authored May 11, 2017
2 parents aba2d31 + 8f1ca0a commit b0cf293
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

11 changes: 11 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## How to contribute


1. Fork TextHighlighter
1. Check out the `develop` branch
1. Make a feature branch (use `git checkout -b "new-feature"`)
1. Make your new feature or bugfix on your branch
1. From your branch, make a pull request against `nakshay/TextHighlighter/develop`
1. Wait for your change to be pulled into `nakshay/TextHighlighter/develop`
1. Merge `nakshay/TextHighlighter/develop` into your origin `develop`
1. Delete your feature branch
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

TextHighlighter is simple android API for developers to show highlighted text in android apps, also provides methods to show styled text.

##Description:
## Description:

The purpose of TextHighlighter API is provide the simplest way to highlight the text in android apps.
The API can be used with all andriod views which allows the rendering of text using ```Html.fromHtml()``` method.

##Usage
## Usage

Add below line in app ```build.gradle```

Expand All @@ -17,7 +17,7 @@ dependencies {
}
```

##Code snippets
## Code snippets

Create the object of TextHighlighter

Expand Down Expand Up @@ -88,7 +88,7 @@ String[] = getStyleForTheToken(String[] token);
```


##Note:
## Note:

Named colors may not work always, you can use Hex values insted of named colors, hence using Hex values instead of named colors is recommended.

Expand All @@ -97,7 +97,7 @@ Example:-

```highlighter.setColorForTheToken("Awesome","#D83400"); ```

##Supported tags for text styling
## Supported tags for text styling

```
<b>
Expand All @@ -111,12 +111,21 @@ Example:-
Visit [www.htmlcolorcodes](http://htmlcolorcodes.com/) for awesome colors and their Hex values.


##Screenshot
## Screenshot


![alt tag](https://raw.githubusercontent.com/akshay-naik/TextHighlighter/master/screenshot.png) ![alt tag](https://github.com/akshayrn/TextHighlighter/blob/master/TextHighlighter.png)

##License
## Current development

Please refer [Wiki](https://github.com/nakshay/TextHighlighter/wiki) section to know more about current development


## How to Contribute?

Please refer [CONTRIBUTE.md](https://github.com/nakshay/TextHighlighter/blob/languagefeature/CONTRIBUTE.md) to see contribute workflow.

## License

Copyright 2016 AKSHAY NAIK

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.github.akshay_naik.texthighlighter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.akshay_naik.texthighlighterapi.TextHighlighter;



public class MainActivity extends AppCompatActivity {

TextView mTextView;
Expand All @@ -21,23 +22,27 @@ protected void onCreate(Bundle savedInstanceState) {

TextHighlighter highlighter=new TextHighlighter();

highlighter.setDefaultColor("black");
String code="#include &lt; iostream.h > <br/> <br/> void main ( ) <br/> { <br/> &nbsp;&nbsp; int s1, s2, s3, s4, s5, sum, total = 500; <br/> &nbsp;&nbsp; float per; <br/> &nbsp;&nbsp; cout &lt;&lt; \"\\nEnter marks of 5 subjects :\"; <br/> &nbsp;&nbsp; cin >>s1>>s2>>s3>>s4>>s5; <br/> &nbsp;&nbsp; <br/> &nbsp;&nbsp; sum = s1 + s2 + s3 + s4 + s5; <br/> &nbsp;&nbsp; cout &lt;&lt; \"\\nSum :\" &lt;&lt; sum; <br/> &nbsp;&nbsp; <br/> &nbsp;&nbsp; per = ( sum * 100 ) /500; <br/> &nbsp;&nbsp; /* percentage formula*/ <br/> &nbsp;&nbsp; cout &lt;&lt; \"\\nPercentage :\" &lt;&lt; per; <br/> } <br/> <br/> Output: <br/> <br/> Enter marks of % subjects : <br/> 89 81 79 85 75 <br/> sum: 409 <br/> Percentage: 81.00000 <br/> ";

/* highlighter.setDefaultColor("black");
highlighter.setColorForTheToken("awesome","red");
highlighter.setColorForTheToken("text","purple");
highlighter.setColorForTheToken("highlighter","blue");

*/
highlighter.setStyleForTheToken("Awesome",TextHighlighter.BOLD);
highlighter.setStyleForTheToken("Text",TextHighlighter.UNDERLINE);
highlighter.setStyleForTheToken("Highlighter",TextHighlighter.ITALIC);


highlighter.setLanguage(highlighter.JAVA);
mTextView= (TextView) findViewById(R.id.mytextview);
mEditText =(EditText) findViewById(R.id.myedittext);

String highlightedText=highlighter.getHighlightedText("Awesome text highlighter");

String highlightedText=highlighter.getHighlightedText(code);
String styledText=highlighter.getStyledText(highlightedText);

mTextView.setText(Html.fromHtml(styledText));
mEditText.setText(Html.fromHtml(styledText));
mTextView.setText(Html.fromHtml(highlightedText));

}
}
6 changes: 0 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<EditText
android:id="@+id/myedittext"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textSize="30sp"
/>
</RelativeLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.3.1'


classpath 'com.android.tools.build:gradle:2.2.2'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Dec 03 16:42:48 IST 2016
#Sat Apr 29 18:32:51 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
2 changes: 1 addition & 1 deletion texthighlighterapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '25.0.0'

defaultConfig {
minSdkVersion 9
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.github.akshay_naik.texthighlighterapi;

/**
* Created by akshay on 30/04/17.
*/

class C implements Language{


//define all token in lowercase, even though text to be highlighted is in uppercase

final String[] tokens={"auto","double","int","struct","const","float","short","unsigned","break","else","long","switch","continue","for","signed",
"void","case","enum","register","typedef","default","goto","sizeof","volatile","char","extern","return","union","do","if","static",
"while"};

final String[] operators={"+","-","/","*","%","=","+=","-=","*=","/=",
"%=","&=","^=","<",">","<=",">=","==","!=","&&","||","!","&","|","~","^","<<",
">>","?",":","Sizeof","++","--","&lt;", "&lt;&lt;","printf","scanf"};

final String[] symbols={"(",")","{","}","[","]", "#include"};

final String[] comments={"/*", "*/","//"};


C()
{
for (String token:tokens) {
colorMap.put(token,"red");
}

for (String operator:operators) {
colorMap.put(operator,"#2C5A2E");
}
for (String comment:comments) {
colorMap.put(comment,"purple");
}
for (String symbol: symbols) {
colorMap.put(symbol,"blue");
}

}

@Override
public String getColor(String myToken) {
String color=colorMap.get(myToken.toLowerCase());

if(color==null) {
color=defaultColor;
}
return color;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.akshay_naik.texthighlighterapi;


/**
* Created by akshay on 30/04/17.
*/

class Cpp implements Language{


//define all token in lowercase, even though text to be highlighted is in uppercase

final String[] operators = {">", "&lt;", "&lt;&lt;", ">>","+","-","++","--","==","="};
final String[] symbols = {"#include", "//", "{", "}", "(", ")"};
final String[] comments = {"/*", "*/"};
final String[] tokens = {"iostream.h", "asm", " auto", " break", " case", " catch", " char", " class", " const",
" continue", " default", " delete", " do", " double", " else", " enum", " extern", " float",
" for", " friend", " goto", " if", " inline", " int", " long", " new", " operator",
" private", " protected", " public", " register", " return", " short",
" signed", " sizeof", " static", " struct", " switch", " template", " this",
" throw", " try", " typedef", " union", " unsigned", " virtual", " void", " volatile", " while", "cout", "cin"};

Cpp()
{
for (String token:tokens) {
colorMap.put(token,"red");
}

for (String operator:operators) {
colorMap.put(operator,"#2C5A2E");
}
for (String comment:comments) {
colorMap.put(comment,"purple");
}
for (String symbol: symbols) {
colorMap.put(symbol,"blue");
}
}

@Override
public String getColor(String myToken) {
String color=colorMap.get(myToken.toLowerCase());

if(color==null) {
color=defaultColor;
}
return color;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.akshay_naik.texthighlighterapi;

/**
* Created by akshay on 30/04/17.
*/

class Java implements Language{

//define all token in lowercase, even though text to be highlighted is in uppercase


final String[] operators={"+","-","/","*","%","=","+=","-=","*=","/=",
"%=","&=","^=","<",">","<=",">=","==","!=","&&","||","!","&","|","~","^","<<",
">>","?",":","<<=",">>=","++","--","&lt;", "&lt;&lt;","println","print",">>>","<<<"};

final String[] tokens ={"abstract","assert boolean","break","byte","case","catch","char","class",
"const","continue","default","do","double","else","enum ","extends","final","finally","float",
"for","goto","if","implements","import","instanceof","int","interface","long","native","new","package",
"private","protected","public","return","short","static","strictfp"," super","switch","synchronized",
"this","throw","throws","transient","try","void","volatile","while"};

final String[] symbols = {"import", "//", "{", "}", "(", ")"};

final String[] comments={"/*", "*/","//"};

Java() {
for (String token:tokens) {
colorMap.put(token,"red");
}

for (String operator:operators) {
colorMap.put(operator,"#2C5A2E");
}
for (String comment:comments) {
colorMap.put(comment,"purple");
}
for (String symbol: symbols) {
colorMap.put(symbol,"blue");
}
}

@Override
public String getColor(String myToken) {
String color=colorMap.get(myToken.toLowerCase());

if(color==null) {
color=defaultColor;
}
return color;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.akshay_naik.texthighlighterapi;

import java.util.HashMap;

/**
* Created by akshay on 30/04/17.
*/

interface Language {
HashMap<String,String> colorMap= new HashMap<>();
String getColor(String myToken);
String defaultColor = "black";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.akshay_naik.texthighlighterapi;

/**
* Created by akshay on 29/04/17.
*/

public interface LibraryConstant {

public interface LanguageConstant {

public static String JAVA="JAVA";
public static String C="C";
public static String CPP="C++";
}

public interface StyleConstant {

//pre-defined Styles

public static final String NORMAL="NORMAL";
public static final String BOLD="BOLD";
public static final String ITALIC="ITALIC";
public static final String UNDERLINE="UNDERLINE";
public static final String SUPERSCRIPT="SUPERSCRIPT";
public static final String SUBSCRIPT="SUBSCRIPT";


}
}
Loading

0 comments on commit b0cf293

Please sign in to comment.