Open top menu








You need to remove or replaces some Special Character eg- Backslash (\n), [ , ’, and \n ,\u,\s, etc. You replaces some regular expressions are complicated things,

String str="hello, who are \u you";
 
Step 1- The (\u )escape character replace very complicated.

String value=str. replaceAll(Pattern.quote("\\u") , "new String value");
 
 
Step 2- the replace  all digit Value from String.

String str="hello, who are 24314 you ";

String something=str.replaceAll(
"[\\p{Digit}]", "");

Output:-hello who are you

Step 3- The replace  all regular expression from String.

String alphaOnly = input.replaceAll("[^a-zA-Z]+","");
String alphaAndDigits = input.replaceAll(
"[^a-zA-Z0-9]+","");
 
 Or equivalent

String alphaOnly = input.replaceAll(
"[^\\p{Alpha}]+","");
String alphaAndDigits = input.replaceAll(
"[^\\p{Alpha}\\p{Digit}]+","");









 thank you  
Read more


Android- How to get Rgb Color programmaticall.



 Get the pixel in height And width when touch on imageView.


activity_main.xml
...................................................................................................................................................................
xmlns:
android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:orientation="vertical">

            android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Android Beginner tutorial point"
       
tools:context=".MainActivity"
       
android:textSize="40dp"
       
android:textStyle="bold"
 
   
        android:id="@+id/colorAvarage"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="touched color: "/>
            android:id="@+id/image"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:src="@drawable/multicolor"
       
android:layout_marginTop="40dp"/>





...................................................................................................................................................................

 MainActivity.java
...................................................................................................................................................................



import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.TextView;

public class  MainActivit extends Activity {

    TextView touchedXY, invertedXY, imgSize, colorRGB;
    ImageView imgSource;

    @Override
   
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.color_code_activity);

        touchedXY = (TextView)findViewById(R.id.TutorialBlog);
        colorRGB = (TextView)findViewById(R.id.colorAvarage);
        imgSource = (ImageView)findViewById(R.id.image);
        imgSource.setOnTouchListener(imgOnTouchListener);

             }

        OnTouchListener imgOnTouchListener = new OnTouchListener(){

        @Override
       
public boolean onTouch(View view, MotionEvent event) {

            float eventX = event.getX();
            float eventY = event.getY();
            float[] eventXY = new float[] {eventX, eventY};

            Matrix invertMatrix = new Matrix();
            ((ImageView)view).getImageMatrix().invert(invertMatrix);

            invertMatrix.mapPoints(eventXY);
            int x = Integer.valueOf((int)eventXY[0]);
            int y = Integer.valueOf((int)eventXY[1]);

                        Drawable imgDrawable = ((ImageView)view).getDrawable();
            Bitmap bitmap = ((BitmapDrawable)imgDrawable).getBitmap();

            //Limit x, y range within bitmap

            
if(x < 0){
                x = 0;
            }else if(x > bitmap.getWidth()-1){
                x = bitmap.getWidth()-1;
            }

            if(y < 0){
                y = 0;
            }else if(y > bitmap.getHeight()-1){
                y = bitmap.getHeight()-1;
            }

            int touchedRGB = bitmap.getPixel(x, y);
            colorRGB.setText("Color Code In Hexa------->   " + "#" +    Integer.toHexString(touchedRGB));
            colorRGB.setTextColor(touchedRGB);
            touchedXY.setTextColor(touchedRGB);
            return true;
        }};

}
...................................................................................................................................................................


Read more

 Android- Explain how to get Color code from Image programmatically.

First Set Image in Bitmap :-
final Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
 
Then Get Touch X and Y coordinate from ImageView.
public boolean onTouch(View v, MotionEvent event) {

    x = (int)event.getX();

    y= (int)event.getY();

    return false;

}
 
Get the color code in Hex String touch on imageView.
Integer.toHexString(bitmap.getPixel(x, y);
 
Get the color code in Hex String touch on imageView.

activity_main.xml
.............................................................................................................................................................

xml version="1.0" encoding="utf-8"?>

<LinearLayout 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/activity_main"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Android Beginner point"

        android:textSize="25dp"

        android:textStyle="bold"

        android:id="@+id/textView" />



    <ImageView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:src="@drawable/multicolor"

        android:layout_below="@+id/textView"

        android:layout_toRightOf="@+id/textView"

        android:layout_toEndOf="@+id/textView"

        android:id="@+id/imageView" />



</LinearLayout>

.............................................................................................................................................................

MAinActivity.java
.............................................................................................................................................................
import android.graphics.Bitmap;

import android.graphics.drawable.BitmapDrawable;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.MotionEvent;

import android.view.View;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;



public class MainActivity extends AppCompatActivity {

     int x,y;

    TextView txtView;

    ColorUtils utils=new ColorUtils();

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        txtView=(TextView)findViewById(R.id.textView);

        ImageView imageView=(ImageView)findViewById(R.id.imageView);

        final Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();

         imageView.setOnTouchListener(new View.OnTouchListener() {

             @Override

             public boolean onTouch(View v, MotionEvent event) {

                 x = (int)event.getX();

                 y= (int)event.getY();

                 int pixel = bitmap.getPixel(x,y);

                 txtView.setTextColor(bitmap.getPixel( x,y));

                   Toast.makeText(getApplicationContext(),"#"+Integer.toHexString(bitmap.getPixel(x, y)),Toast.LENGTH_LONG).show();



                 return false;

             }

         });



    }

}
 .............................................................................................................................................................


 


Read more