Android – Warning:Conflict with dependency ‘com.google.code.findbugs:jsr305’ solution

When I tried to add these library dependencies:

    compile 'com.trello:rxlifecycle:0.7.0'
    compile 'com.trello:rxlifecycle-android:0.7.0'

I received following error:

Warning:Conflict with dependency ‘com.google.code.findbugs:jsr305’. Resolved versions for app (3.0.1) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Execution failed for task ‘:app:prepareDebugAndroidTestDependencies’.
> Dependency Error. See console for details.
Information:BUILD FAILED

Then I googled and found this solution:
In your apps build.gradle add the following within android { }:

configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}

How to use lambda in Android Studio?

First of all, add following to build.gradle(app) file:

android {
    defaultConfig {
       ...
        jackOptions {
            enabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

After that you can use lambda in your application:

        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(v-> Toast.makeText(getApplicationContext(), "Hello Lambda", Toast.LENGTH_LONG).show());

instead of this:

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Hello Lambda", Toast.LENGTH_LONG).show();
            }
        });

Android – RecyclerView adapter example

public class PeopleAdapter extends RecyclerView.Adapter<PeopleAdapter.ViewHolder> {

    List<Person> people;

    public PeopleAdapter(List<Person> people) {
        this.people = people;
    }

    @Override
    public PeopleAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listitem_person, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView name;
        TextView number;

        ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);
            number = (TextView) itemView.findViewById(R.id.number);
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Person person = people.get(position);
        holder.name.setText(person.getName());
        holder.number.setText(person.getNumber()+"");
    }

    @Override
    public int getItemCount() {
        return people.size();
    }

}

Android – what is android:supportsRtl=”true” for?

android:supportsRtl="true"

I always thought what is this for? Now I found what for. It is for supporting Arabic, Urdu, Hebrew languages. Because those languages are written from right to left. If you set supportsRtl true, your layout will be mirrored from right to left. So you do not have to create special layout for it. If you set false, your layout remain same no matter what language is used.

This is supported from API 17 – Android 4.2.

Android – How to load NavigationView menu item icon from URL using Picasso

    // this set prevents collecting targets by garbage collector
    final Set<Target> targets = new HashSet<>();

    private void loadMenuIcon(final MenuItem menuItem, String url) {

        Target target = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
                BitmapDrawable mBitmapDrawable = new BitmapDrawable(getResources(), bitmap);
                menuItem.setIcon(mBitmapDrawable);
            }

            @Override
            public void onBitmapFailed(Drawable drawable) {}

            @Override
            public void onPrepareLoad(Drawable drawable) {}
        };

        targets.add(target);

        Picasso.with(this).load(url).into(target);

    }

Usage:

            Menu menu = navigationView.getMenu();
            MenuItem item = menu.add(0, id, i, name);
            loadMenuIcon(item, url);

Android Studio 2.2

%d1%81%d0%bd%d0%b8%d0%bc%d0%be%d0%ba-%d1%8d%d0%ba%d1%80%d0%b0%d0%bd%d0%b0-2016-09-21-%d0%b2-1-16-51

New version of Android Studio published. Following improvements are made:

– New layout editor
– Constraint layout support
– Sample code search
– Instant Run improvement
– APK analyzer
– build cache
– Virtual sensors in emulator
– Espresso Test recorder
– GPU debugger

Happy Android coding =)