How to enable Annotation Processor in Android Studio 2.3

Close the project and find the option under File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors

Exit from Android Studio and edit the file /.idea/compiler.xml.
You should find:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
    <component name="CompilerConfiguration">
        ...
        <annotationProcessing>
            <profile default="true" name="Default" enabled="false">
                <processorPath useClasspath="true" />
            </profile>
        </annotationProcessing>
    </component>
</project>

You should set enabled to true and the boring message disappears!

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
    <component name="CompilerConfiguration">
        ...
        <annotationProcessing>
            <!-- This is the line where to set enabled to true  -->
            <profile default="true" name="Default" enabled="true">
                <processorPath useClasspath="true" />
            </profile>
        </annotationProcessing>
    </component>
</project>

References
https://stackoverflow.com/questions/42692525/how-to-enable-annotation-processor-in-android-studio-2-3

Publish a Message From Android on MQTT

AndroidManifest.xml

    <!-- Permissions the Application Requires -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!--<uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

And register our MQTT Android Service in our app before the closing tag by adding this line:

 <service android:name="org.eclipse.paho.android.service.MqttService" />

Java

public class MqttManager {

    MqttAndroidClient mqtt=null;

    public void publishTest() throws MqttException {

        try
        {
            String clientId= MqttClient.generateClientId();
            mqtt=new MqttAndroidClient(CachePupli.context,"tcp://192.168.1.2:1883",clientId);
            MqttConnectOptions connectOptions=new MqttConnectOptions();
            connectOptions.setAutomaticReconnect(true);
            connectOptions.setCleanSession(true);
            IMqttToken token= mqtt.connect(connectOptions);
            token.setActionCallback(onConnect);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }


    private IMqttActionListener onConnect=new IMqttActionListener() {
        @Override
        public void onSuccess(IMqttToken asyncActionToken) {

            MqttMessage message=new MqttMessage("Hello World".getBytes());
            try {
                mqtt.publish("test",message);
            } catch (MqttException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(IMqttToken asyncActionToken, Throwable exception) {

        }
    };
}

References
https://www.eclipse.org/paho/clients/android/
https://wildanmsyah.wordpress.com/2017/05/11/mqtt-android-client-tutorial/

Share Multiple Images or Files on Android

Yes but you’ll need to use Intent.ACTION_SEND_MULTIPLE instead of Intent.ACTION_SEND .

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/jpeg"); /* This example is sharing jpeg images. */

ArrayList<Uri> files = new ArrayList<Uri>();

for(String path : filesToSend /* List of the files you want to send */) {
    File file = new File(path);
    Uri uri = Uri.fromFile(file);
    files.add(uri);
}

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);

My Own Solution

    private fun shareSelectedFiles() {

        val files = ArrayList<Uri>()

        CachePupli.selectedMediaList.forEach { s: String ->
            val uri = Uri.parse("file:///$s")
            files.add(uri)
        }

        val intent = Intent(Intent.ACTION_SEND_MULTIPLE)
        intent.setType(FileHelper().getMimeType(files.get(0).path))
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files)

        val clipData = ClipData.newUri(contentResolver, "Share", files.get(0));

        if (files.size > 1) {
            var i = 1

            while (i < files.size) {
                clipData.addItem(ClipData.Item(files.get(i)))
                i++
            }
        }

        intent.clipData = clipData
        startActivityForResult(Intent.createChooser(intent, "Share"), 10001)
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

        // after sharing multiple files
        if (requestCode == 10001) {
            CachePupli.selectMediaMode = false
            EventBus.getDefault().post(ChangeSelectionModeStatusEvent(false))
        }

        super.onActivityResult(requestCode, resultCode, data)
    }

References
https://stackoverflow.com/questions/15577438/how-can-i-share-multiple-files-via-an-intent

Create PopupMenu with Icons using PopupWindow

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:layoutDirection="rtl"
    android:orientation="vertical"
    android:textDirection="rtl">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="10dp"
        android:paddingEnd="40dp"
        android:paddingTop="10dp">

        <android.support.v7.widget.AppCompatImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginStart="4dp"
            app:srcCompat="@drawable/ic_share_gray_24dp" />


        <android.support.v7.widget.AppCompatTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:gravity="center_vertical"
            android:text="@string/share" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="10dp"
        android:paddingEnd="40dp"
        android:paddingTop="10dp">

        <android.support.v7.widget.AppCompatImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginStart="4dp"
            app:srcCompat="@drawable/ic_delete_gray_24dp" />


        <android.support.v7.widget.AppCompatTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:gravity="center_vertical"
            android:text="@string/delete" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="10dp"
        android:paddingEnd="40dp"
        android:paddingTop="10dp">

        <android.support.v7.widget.AppCompatImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginStart="4dp"
            app:srcCompat="@drawable/ic_create_new_folder_gray_24dp" />


        <android.support.v7.widget.AppCompatTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:gravity="center_vertical"
            android:text="@string/move_to_folder" />

    </LinearLayout>

</LinearLayout>
    fun imageButtonMoreVert_OnClick(v: View) {
        val view = layoutInflater.inflate(R.layout.gallery_selection_menu, null)

        val popup = PopupWindow(this)
        popup.contentView = view
        popup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        popup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        popup.setFocusable(true);

        val location = IntArray(2)
        imageButtonMoreVert.getLocationOnScreen(location)
        val p = Point(location.get(0), location.get(1))

        val OFFSET_X = -20
        val OFFSET_Y = 50

        popup.showAtLocation(view, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
    }

References
https://stackoverflow.com/questions/15454995/popupmenu-with-icons
https://androidresearch.wordpress.com/2012/05/06/how-to-create-popups-in-android/

Use Android SDK Documentation offline in Android Studio

Find your configuration files

Windows: %USERPROFILE%\.<CONFIGURATION_FOLDER>/
Mac: ~/Library/Preferences/<CONFIGURATION_FOLDER>/
Linux: ~/.<CONFIGURATION_FOLDER>/

File is located at “Android Studio Configuration folder”/config/options/jdk.table.xml

find javadocPath

...
<jdk version="2">
  <name value="Android API 25 Platform" />
  <type value="Android SDK" />
  <homePath value="$USER_HOME$/android-sdk" />
  <roots>
      ...
    <javadocPath>
      <root type="composite">
        <root type="simple" url="http://developer.android.com/reference/" />
      </root>
    </javadocPath>
      ...
  <root type="simple" url="file:///home/mauricio/android-sdk/docs/reference" />
  <!-- if it's Windows -->
  <root type="simple" url="file://C:/android-sdk/docs/reference" />

References
https://stackoverflow.com/questions/42893969/how-to-use-android-sdk-documentation-offline