Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use CS hidden string in XML Layout? #34

Closed
Narvelan opened this issue Mar 14, 2018 · 7 comments
Closed

Can I use CS hidden string in XML Layout? #34

Narvelan opened this issue Mar 14, 2018 · 7 comments
Assignees

Comments

@Narvelan
Copy link

Narvelan commented Mar 14, 2018

When I write link to hidden string res in xml layout files
android:text="@string/glass"
The text remains encrypted, somehow we can use this strings in xml to show text decrypted?
Or only decrypt it in java code and after use settext

@efraespada
Copy link
Member

@Narvelan I think it's possible by extending TextView class and decrypt values before show them on view. It could be a good improvement 👌​👌​

@efraespada efraespada self-assigned this Mar 15, 2018
@Narvelan
Copy link
Author

@efraespada It's will be perfect! If you can do this =)

I try to create widget extends AppCompatTextView, but don't know get resId to setText)

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

import com.stringcare.library.SC;

public final class MyTextView extends AppCompatTextView {

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        SC.init(context);
        setText(SC.getString( ?? ));
    }
}

@Narvelan
Copy link
Author

I did it

    public final class MyTextView extends AppCompatTextView {
        public MyTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            SC.init(context);
            String text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
            if (text != null) {
                setText(SC.getString(Integer.parseInt(text.substring(1))));
            }
        }
}

@efraespada
Copy link
Member

Perfect @Narvelan! You're great! 😄
Would you like to include it on library?

@Narvelan
Copy link
Author

Narvelan commented Apr 2, 2018

Don't now how to do it) In my project it's java file (MyTextView.java) in widget folder with code

package ru.myapp.widgets;

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

import com.stringcare.library.SC;

    public final class MyTextView extends AppCompatTextView {

        public MyTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            SC.init(context);
            String text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
            if (text != null) {
                setText(SC.getString(Integer.parseInt(text.substring(1))));
            }
        }
}

And in my layout files I use it like:

<ru.myapp.widgets.MyTextView
                    android:text="@string/myHiddenString"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />

@efraespada
Copy link
Member

Okay @Narvelan, then I'll add it to library with your permission 🙂

@efraespada
Copy link
Member

Hi @Narvelan, I released v0.9 with your improvement. I added a ContextListener for avoiding init the library with the TextView's Context. Thanks!

Documentation Usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants