I want to change specific paragraphs direction through code with spans in android text view
Here is what i tried :
I tried adding LTR or RTL unicode
but this approach changes the text length which i cant do since its a book reader kind of app
/**
* Unicode "Left-To-Right Embedding" (LRE) character.
*/
private static final char LTR = '\u202A';
/**
* Unicode "Right-To-Left Embedding" (RLE) character.
*/
private static final char RTL = '\u202B';
/**
* Unicode "Left-To-Right Mark" (LRM) character.
*/
private static final char INSIDE_LTR = '\u200E';
/**
* Unicode "Right-To-Left Mark" (RLM) character.
*/
private static final char INSIDE_RTL = '\u200F';
I also tried changing the text direction through
android:textDirection
The issue is this changes all paragrapghs directon according to the following
public static final int TEXT_DIRECTION_ANY_RTL = 2;
public static final int TEXT_DIRECTION_FIRST_STRONG = 1;
public static final int TEXT_DIRECTION_FIRST_STRONG_LTR = 6;
public static final int TEXT_DIRECTION_FIRST_STRONG_RTL = 7;
public static final int TEXT_DIRECTION_INHERIT = 0;
public static final int TEXT_DIRECTION_LOCALE = 5;
public static final int TEXT_DIRECTION_LTR = 3;
public static final int TEXT_DIRECTION_RTL = 4;
I also tried LocaleSpan
but it had no effect on text direction
i want to do it like spans set from X to y To be LTR or RTL ,
any idea ?
Related
I am very new to both java and opencv especially android. From reading, I know that camera2 API support higher resolution compared to camera1 API, which is useful for my project.
I am trying to understand face-detection sample from open cv. I know that there are javacameraview and javacamera2view classes.
so far, I understand that the activity using javacameraview. however, I don't know where the javacameraview initially called. no decalaration at all.
I believe it is called in camerabridgeviewbase. but I cannot find any initialization of javacameraview.
The main goal is to replace javacameraview with javacamera2view. or use camera2 API directly.
I understand that there are some limitation in camera2 API but that is not the main problem now.
Here is the CameraBridgeViewBase initialisation
private static final String TAG = "CameraBridge";
protected static final int MAX_UNSPECIFIED = -1;
private static final int STOPPED = 0;
private static final int STARTED = 1;
private int mState = STOPPED;
private Bitmap mCacheBitmap;
private CvCameraViewListener2 mListener;
private boolean mSurfaceExist;
private final Object mSyncObject = new Object();
protected int mFrameWidth;
protected int mFrameHeight;
protected int mMaxHeight;
protected int mMaxWidth;
protected float mScale = 1;
protected int mPreviewFormat = RGBA;
protected int mCameraIndex = CAMERA_ID_ANY;
protected boolean mEnabled;
protected boolean mCameraPermissionGranted = false;
protected FpsMeter mFpsMeter = null;
public static final int CAMERA_ID_ANY = -1;
public static final int CAMERA_ID_BACK = 99;
public static final int CAMERA_ID_FRONT = 98;
public static final int RGBA = 1;
public static final int GRAY = 2;
cheers
Well iam looking in the wrong place. It is controlled in the layout. Just replace JavaCameraView with JavaCamera2View. And done. Camera2 implemented.
I have a Util class which is capable of creating color codes(decimal).
public class ColorUtils {
private static final String RED = "ff0000";
private static final String GREEN = "00ff00";
private static final String BLUE = "0000ff";
private static final String WHITE = "ffffff";
private static final int RADIX = 16;
public static int getColorShade(String deepShade, String lightShade, float percentage) {
if (percentage > 100) {
throw new RuntimeException("Percentage can not be more than 100");
}
int deepShadeCode = Integer.parseInt(deepShade, RADIX);
int lightShadeCode = Integer.parseInt(lightShade, RADIX);
int shadeDifference = deepShadeCode - lightShadeCode;
int shadeOffset = (int) (shadeDifference * percentage)/100;
return lightShadeCode + shadeOffset;
}
public static int getColorShade(String deepShade, float percentage) {
return getColorShade(deepShade, WHITE, percentage);
}
public static int getRedColorShade(float percentage) {
return getColorShade(RED, percentage);
}
public static int getGreenColorShade(float percentage) {
return getColorShade(GREEN, percentage);
}
public static int getBlueColorShade(float percentage) {
return getColorShade(BLUE, percentage);
}
public static int getWhite() {
return Integer.parseInt(WHITE, RADIX);
}
}
Is there any way to convert it to Android color?
All I could find out is ContextCompat.getColor(this,R.color.yourcolor)
but this will take resource id in second arguments, I don't want to make color pallets in color.xml. Is there a work around?
Don't know how you create the color, but if it can extract red, green, blue, then try this:
#ColorInt int color = Color.rgb(getRedColorShade(percentage), getGreenColorShade(percentage), getBlueColorShade(percentage));
Ref here, this time it's pretty sure that this method is added from API level 1 and can be used instead of valueOf
I have a custom view I've created that draws a circle, places a single text character in the middle, and sets the font to a custom icon font. It looks like this
The code for it looks like this
public class IconView extends TextView
{
public static final String ICON_PROJECTOR = "A";
public static final String ICON_BLURAY = "F";
public static final String ICON_TUNER = "H";
public static final String ICON_CALL = "W";
public static final String ICON_HANG_UP = "X";
public static final String ICON_SLIDERS = "l";
public static final String ICON_KEYPAD = "t";
public static final String ICON_UP = "!";
public static final String ICON_DOWN = "#";
public static final String ICON_LEFT = "#";
public static final String ICON_RIGHT = "$";
public static final String ICON_UP_ALT = "%";
public static final String ICON_DOWN_ALT = "^";
public static final String ICON_LEFT_ALT = "&";
public static final String ICON_RIGHT_ALT = "*";
public static final String ICON_MENU_BACK = "<";
public static final String ICON_MENU_FWD = ">";
private int bgColor;
public IconView(Context context, AttributeSet attrs)
{
super(context, attrs);
Typeface iconTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/hav.ttf");
this.setTypeface(iconTypeface);
}
public void setIcon(String icon)
{
this.setText(icon);
}
public void setColor(int color)
{
bgColor=color;
}
#Override
protected void onDraw(Canvas canvas)
{
int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
this.setLayoutParams(new LinearLayout.LayoutParams(size,size));
this.setGravity(Gravity.CENTER);
//Draw Background
Rect rect = canvas.getClipBounds();
Paint paint = new Paint();
paint.setColor(bgColor);
paint.setAntiAlias(true);
canvas.drawCircle(rect.centerX(), rect.centerY(), rect.width() / 2, paint);
//Set Text Color
this.setTextColor(0xFFFFFFFF);
super.onDraw(canvas);
}
}
It runs and looks beautiful. Unfortunately, when it's running the entire application lags and my memory usage looks like this . I'm pretty sure that means something's leaking, and since I'm very new to this I don't know what in my onDraw method is causing it. If I comment out everything in onDraw but super() then I get just the icon with the font, no circle, and the memory problems go away entirely. I get a nice solid even line for memory and the app is snappy and responsive.
So what's wrong with my circle code, how can I fix it, or what should I replace it with?
Thanks for any help, I appreciate it!
I have checked the suggested question here, but when I checked the documentation regarding the method getNetworkInfo()here, there was no documentation regarding the possible integer values this method could handle. For an example, if I passed 0 to the getNetworkInfo() this means I am checking he mobile network, and if it is 1, I am checking the status of the WiFi.
Is there any other possible values? Why they are not in the documentation?
From the docs: http://developer.android.com/reference/android/net/ConnectivityManager.html
public static final int TYPE_NONE = -1;
public static final int TYPE_MOBILE = 0;
public static final int TYPE_WIFI = 1;
public static final int TYPE_MOBILE_MMS = 2;
public static final int TYPE_MOBILE_SUPL = 3;
public static final int TYPE_MOBILE_DUN = 4;
public static final int TYPE_MOBILE_HIPRI = 5;
public static final int TYPE_WIMAX = 6;
public static final int TYPE_BLUETOOTH = 7;
public static final int TYPE_DUMMY = 8;
public static final int TYPE_ETHERNET = 9;
public static final int TYPE_MOBILE_FOTA = 10;
public static final int TYPE_MOBILE_IMS = 11;
public static final int TYPE_MOBILE_CBS = 12;
public static final int TYPE_WIFI_P2P = 13;
public static final int TYPE_MOBILE_IA = 14;
I am trying to do resampling in android using this library https://github.com/intervigilium/libresample/blob/master/src/net/sourceforge/resample/Resample.java#L6
but I dont know exactly what to fill in the Parameters
I want to Resample an audio file
File mySound = new File("/mySound.wav");
to 44,100 kHz
how do i do it with this library: Library Code shown below..
package net.sourceforge.resample;
public class Resample {
public static final int DEFAULT_BUFFER_SIZE = 4096;
public static final int MAX_CHANNELS = 2;
public static final int CHANNEL_MONO = 0;
public static final int CHANNEL_LEFT = 0;
public static final int CHANNEL_RIGHT = 1;
private static final String RESAMPLE_LIB = "resample";
static {
System.loadLibrary(RESAMPLE_LIB);
}
public static native void downmix(short outputBuffer[], short inputLeft[], short inputRight[], int numSamples);
public static native int resample(double factor, short inputBuffer[], short outputBuffer[], int numSamples);
public static native void initialize(int inputRate, int outputRate, int bufferSize, int channels);
public static native double getFactor();
public static native int process(short inputBuffer[], short outputBuffer[], int channel, boolean isLast);
public static native void close();
}