Set android shape color programmatically

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid android:color="#666666" />

    <size
        android:width="8dp"
        android:height="8dp" />
</shape>
            <ImageView
                android:id="@+id/imageViewStep2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="4dp"
                android:layout_marginRight="4dp"
                android:background="@drawable/ic_stepper"
                android:contentDescription="@string/step_2" />
        Drawable background = imageViewStep1.getBackground();

        if (background instanceof ShapeDrawable) {
            // cast to 'ShapeDrawable'
            ShapeDrawable shapeDrawable = (ShapeDrawable) background;
            shapeDrawable.getPaint().setColor(ContextCompat.getColor(this, R.color.md_blue_500));
        } else if (background instanceof GradientDrawable) {
            // cast to 'GradientDrawable'
            GradientDrawable gradientDrawable = (GradientDrawable) background;
            gradientDrawable.setColor(ContextCompat.getColor(this, R.color.md_blue_500));
        } else if (background instanceof ColorDrawable) {
            // alpha value may need to be set again after this call
            ColorDrawable colorDrawable = (ColorDrawable) background;
            colorDrawable.setColor(ContextCompat.getColor(this, R.color.md_blue_500));
        }

References
https://stackoverflow.com/questions/17823451/set-android-shape-color-programmatically

Maximum simultaneous connections on a mosquitto broker

nano /etc/sysctl.conf
fs.file-max = 999999
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_syncookies = 1
# this gives the kernel more memory for tcp
# which you need with many (100k+) open socket connections
net.ipv4.tcp_mem = 50576   64768   98152
net.core.netdev_max_backlog = 2500
nano /etc/security/limits.conf
*       soft    nofile  262144
*       hard    nofile  262144
*       soft    nproc  262144
*       hard    nproc  262144
cat /proc/sys/net/ipv4/ip_local_port_range
cat /proc/sys/kernel/threads-max
nano .bashrc
ulimit -t unlimited
ulimit -c unlimited
ulimit -a

References
https://lists.launchpad.net/mosquitto-users/msg00163.html

Detect when there is an Internet connection available on Android

In this method just current activity receive this event
Add to android Manifest

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

In your activity, create a Broadcast Receiver:

private BroadcastReceiver networkStateReceiver=new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = manager.getActiveNetworkInfo();
        doSomethingOnNetworkChange(ni);
    }
};
@Override
public void onResume() {
    super.onResume();
    registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
}

@Override
public void onPause() {
    unregisterReceiver(networkStateReceiver);
    super.onPause();
}

References
https://stackoverflow.com/questions/6169059/android-event-for-internet-connectivity-state-change

How to root Android Huawei mate 7 gold ( MT7-TL10 )

download TWRP image then go to download folder

adb reboot bootloader

fastboot devices # just for check
fastboot flash recovery twrp_3.0.2_mate7_6.0.img
fastboot reboot

download zip file of SuperSu and put it on root folder of Phone SD card

adb reboot recovery

install zip

References
http://forum.supersu.com/topic/908/huawei-phone-general-guide-huawei-root
http://www.droidviews.com/how-to-boot-android-devices-in-fastboot-download-bootloader-or-recovery-mode/
https://android.gadgethacks.com/how-to/know-your-android-tools-what-is-fastboot-do-you-use-it-0155640/