Friday, December 13, 2019

using Java, Kotlin and dagger together in project

If we are using java, kotlin and dagger together in project.

Follow this steps

kapt
Kapt is the Kotlin Annotation Processing Tool, and it’s in pretty good shape these days. If you want to be able to reference generated code from Kotlin, you need to use kapt. To do that, simply include the plugin in your build.gradle file with the line:


apply plugin: 'kotlin-kapt'







And in dependencies

kapt 'com.google.dagger:dagger-compiler:2.13'

Thursday, June 27, 2019

Block touch event in view

Add an onTouchEvent method to the view with top position then return true. True will tell the event bubbling that the event was consumed therefore prevent event from bubbling to other views.

protected boolean onTouchEvent (MotionEvent me) {
    return true;
}

For v1 you would do an import:
import android.view.View.OnTouchListener;
Then set the onTouchListener:

v1.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});

Force hide soft keyboard

InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    //Find the currently focused view, so we can grab the correct window token from it.
    View view = activity.getCurrentFocus();
    //If no view currently has focus, create a new one, just so we can grab a window token from it
    if (view == null) {
        view = new View(activity);
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

difference between “px”, “dip”, “dp” and “sp”

  1. px
    Pixels - corresponds to actual pixels on the screen.
  2. in
    Inches - based on the physical size of the screen.
    1 Inch = 2.54 centimeters
  3. mm
    Millimeters - based on the physical size of the screen.
  4. pt
    Points - 1/72 of an inch based on the physical size of the screen.
  5. dp or dip
    Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
  6. sp
    Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommended you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

Tuesday, June 18, 2019

Running adb over wifi

Easy Steps for running adb over wifi

1.  Connect Android phone and host machine to same WiFi network

2.  Connect Android phone to host machine using USB cable (to start with)

3.   Run adb tcpip 5555 from a command prompt

4.   Run adb shell "ip addr show wlan0 | grep -e wlan0$ | cut -d\" \" -f 6 | cut -d/ -f 1" to obtain the phone's IP address

5.   Disconnect USB cable and run adb connect :5555