Skip to content

Commit

Permalink
Merge pull request #66 from StringCare/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
efraespada authored Dec 31, 2019
2 parents f533964 + 097c263 commit a99a32a
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 67 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ dependencies {
})
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
implementation project(path: ':library')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'commons-io:commons-io:2.5'
// implementation "com.stringcare:library:$stringcare_version"
// implementation project(path: ':library')
implementation "com.stringcare:library:$stringcare_version"
}


Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ protected void onCreate(Bundle savedInstanceState) {
final SCTextView tvAuto = findViewById(R.id.auto_tv);
findViewById(R.id.btn_change).setOnClickListener(v -> {
if (tvAuto.isHtmlEnabled()) {
tvAuto.htmlEnabled(!tvAuto.isHtmlEnabled());
} else if (tvAuto.isVisible()){
tvAuto.visible(!tvAuto.isVisible());
} else if (!tvAuto.isVisible()){
tvAuto.visible(!tvAuto.isVisible());
tvAuto.htmlEnabled(!tvAuto.isHtmlEnabled());
tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
} else if (tvAuto.isRevealingValue()) {
tvAuto.setRevealed(!tvAuto.isRevealingValue());
} else if (!tvAuto.isRevealingValue()) {
tvAuto.setRevealed(!tvAuto.isRevealingValue());
tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
}
});

boolean equals = SC.reveal(R.string.hello_world_b).equals(getString(R.string.hello_world_a));
String areEquals = "Same result: " + equals;
String areEquals = "Same result: " + equals;
((TextView) findViewById(R.id.same_value)).setText(areEquals);

String jsonObjectName = SC.reveal(R.string.asset_json_file);
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
android:padding="25dp"
android:text="@string/hello"
android:textColor="@android:color/black"
app:html="true"
app:visible="false" />
app:htmlSupport="true"
app:reveal="true" />

<Button
android:id="@+id/btn_change"
Expand Down Expand Up @@ -120,8 +120,8 @@
android:textSize="12sp"
android:text="@string/hello_world_b"
android:textColor="@android:color/black"
app:html="false"
app:visible="true" />
app:htmlSupport="false"
app:reveal="true" />

<TextView
android:layout_width="wrap_content"
Expand Down Expand Up @@ -154,9 +154,9 @@
android:textSize="12sp"
android:text="@string/hello_world_c"
android:textColor="@android:color/black"
app:html="false"
app:htmlSupport="false"
app:androidTreatment="false"
app:visible="true" />
app:reveal="true" />

<TextView
android:layout_width="wrap_content"
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
ext.kotlin_version = '1.3.50'

ext {
stringcare_version = '3.3'
stringcare_version = '3.6.1'
}

repositories {
Expand All @@ -16,9 +16,9 @@ buildscript {
}

dependencies {
// classpath "com.stringcare:plugin:$stringcare_version"
classpath files('../KotlinGradlePlugin/build/libs/plugin-3.5.jar')
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "com.stringcare:plugin:$stringcare_version"
// classpath files('../KotlinGradlePlugin/build/libs/plugin-3.5.jar')
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down
6 changes: 3 additions & 3 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ cmake_minimum_required(VERSION 3.10.2)
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
native-lib
sc-native-lib

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
../../stringcare-jni-android-library/lib/native-lib.cpp)
../../stringcare-jni-android-library/lib/sc-native-lib.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
Expand All @@ -37,7 +37,7 @@ find_library( # Sets the name of the path variable.
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
native-lib
sc-native-lib

# Links the target library to the log library
# included in the NDK.
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "3.6"
version = "3.6.1"

android {
compileSdkVersion 28
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/stringcare/library/SC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SC {
companion object {

init {
System.loadLibrary("native-lib")
System.loadLibrary("sc-native-lib")
}

val context: Context
Expand Down
96 changes: 55 additions & 41 deletions library/src/main/java/com/stringcare/library/SCTextView.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,70 @@
package com.stringcare.library;

/*
* Credits to Narvelan:
* https://github.com/StringCare/AndroidLibrary/issues/34
*/

import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.text.Html;
import android.util.AttributeSet;

import java.util.Formatter;
/*
* Credits to Narvelan:
* https://github.com/StringCare/AndroidLibrary/issues/34
*/

public class SCTextView extends AppCompatTextView {

private String text;
private Boolean isHTML;
private Boolean androidTreatment;
private Boolean visible;
private Boolean revealed;

public SCTextView(Context context) {
super(context);
isHTML = null;
visible = null;
revealed = null;
androidTreatment = null;
}

public SCTextView(Context context, AttributeSet attrs) {
super(context, attrs);
isHTML = null;
visible = null;
revealed = null;
androidTreatment = null;
loadText(attrs);
}

public SCTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
isHTML = null;
visible = null;
revealed = null;
androidTreatment = null;
loadText(attrs);
}

/**
* Defines initial vars
* Sets the initial parameters
*
* @param attrs {AttributeSet}
*/
private void loadText(final AttributeSet attrs) {
text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
String mFalse = "false";

String mResourceAndroidSchema = "http://schemas.android.com/apk/res/android";
String textName = "text";

String mResourceSchema = "http://schemas.android.com/apk/res-auto";
String htmlName = "htmlSupport";
String revealValue = "reveal";
String androidTreatmentName = "androidTreatment";

text = attrs.getAttributeValue(mResourceAndroidSchema, textName);
if (isHTML == null) {
isHTML = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "html"));
isHTML = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, htmlName));
}
if (visible == null) {
visible = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "visible"));
if (revealed == null) {
revealed = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, revealValue));
}
if (androidTreatment == null) {
androidTreatment = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "androidTreatment"));
androidTreatment = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, androidTreatmentName));
}

reloadText();
Expand All @@ -68,16 +76,16 @@ private void loadText(final AttributeSet attrs) {
private void reloadText() {
if (text != null) {
try {
final Integer val = Integer.parseInt(text.substring(1));
if (!visible) {
final int val = Integer.parseInt(text.substring(1));
if (!isRevealingValue()) {
setText(getContext().getString(val));
return;
}
SC.onContextReady(new ContextListener() {
@Override
public void contextReady() {
String value = SC.reveal(val, androidTreatment);
if (isHTML) {
String value = SC.reveal(val, usesAndroidTreatment());
if (isHtmlEnabled()) {
setText(Html.fromHtml(value));
} else {
setText(value);
Expand All @@ -91,12 +99,12 @@ public void contextReady() {
}

/**
* Enables de-obfuscation before print the value
* Reveals the value before print it
*
* @param visible {true|false}
* @param revealed {true|false}
*/
public void visible(boolean visible) {
this.visible = visible;
public void setRevealed(boolean revealed) {
this.revealed = revealed;
reloadText();
}

Expand All @@ -105,40 +113,46 @@ public void visible(boolean visible) {
*
* @param enabled {true|false}
*/
public void htmlEnabled(boolean enabled) {
public void setHtmlSupport(boolean enabled) {
isHTML = enabled;
reloadText();
}

/**
* Returns true if is the value must be print as HTML or plain text
* Enables the Android treatment
*
* @param enabled {true|false}
*/
public void setAndroidTreatment(boolean enabled) {
androidTreatment = enabled;
reloadText();
}

/**
* Returns true if is the value must be print as HTML
*
* @return Boolean
*/
public boolean isHtmlEnabled() {
return isHTML;
return Boolean.TRUE.equals(isHTML);
}

/**
* Returns true if is de-obfuscating the value before print it
* Returns true if the value must be treated as the Android system does
*
* @return Boolean
*/
public boolean isVisible() {
return visible;
public boolean usesAndroidTreatment() {
return Boolean.TRUE.equals(androidTreatment);
}

public String escapeUnicode(String input) {
StringBuilder b = new StringBuilder(input.length());
Formatter f = new Formatter(b);
for (char c : input.toCharArray()) {
if (c < 128) {
b.append(c);
} else {
f.format("\\u%04x", (int) c);
}
}
return b.toString();
/**
* Returns true if the value should be setRevealed before print it
*
* @return Boolean
*/
public boolean isRevealingValue() {
return Boolean.TRUE.equals(revealed);
}

}
29 changes: 29 additions & 0 deletions library/src/main/java/com/stringcare/library/StringExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun String.reveal(
version: Version = defaultVersion
): String = SC.reveal(this, androidTreatment, version)

// lambdas
fun String.json(
predicate: () -> Boolean = { true }
): JSONObject = SC.asset().json(this, predicate)
Expand All @@ -52,3 +53,31 @@ fun String.asyncBytes(
predicate: () -> Boolean = { true },
bytes: (bytes: ByteArray) -> Unit
) = SC.asset().asyncBytes(this, predicate, bytes)

// param
fun String.json(
predicate: Boolean = true
): JSONObject = SC.asset().json(this, predicate)

fun String.asyncJson(
predicate: Boolean = true,
json: (json: JSONObject) -> Unit
) = SC.asset().asyncJson(this, { predicate }, json)

fun String.jsonArray(
predicate: Boolean = true
): JSONArray = SC.asset().jsonArray(this, predicate)

fun String.asyncJsonArray(
predicate: Boolean = true,
json: (json: JSONArray) -> Unit
) = SC.asset().asyncJsonArray(this, { predicate }, json)

fun String.bytes(
predicate: Boolean = true
): ByteArray = SC.asset().bytes(this, predicate)

fun String.asyncBytes(
predicate: Boolean = true,
bytes: (bytes: ByteArray) -> Unit
) = SC.asset().asyncBytes(this, { predicate }, bytes)
4 changes: 2 additions & 2 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com_stringcare_library_SCTextView">
<attr name="html" format="boolean" />
<attr name="visible" format="boolean" />
<attr name="htmlSupport" format="boolean" />
<attr name="reveal" format="boolean" />
<attr name="androidTreatment" format="boolean" />
</declare-styleable>
</resources>

0 comments on commit a99a32a

Please sign in to comment.