Common plug-ins for Android Studio

Keywords: Android ButterKnife Gradle Fragment

1. Import third-party jar packages and open source libraries

Import local jar

Copy the jar file to libs, right-click on the jar file and select add as a library to import. The compile of build.gradle in the module will increase.

compile files('libs/butterknife-6.1.0.jar')

If builder.gradle already has

compile fileTree(include: ['*.jar'], dir: 'libs')

No more add s, just Sync gradle.

Add remote open source libraries

You can download the open source library and enter the module's build.gradle file. Add the following image to it:

Additions are usually described in readme.md of open source libraries.

Add local open source libraries

Download the open source library, place it in the same directory as the app directory, then edit the set. gradle file and add ": Open Source Library folder name". For example, the open source library folder of volley is placed under the same level directory of app, and then set. gradle is edited. The content is changed to:

include ':app', ":volley"

Then go back to the build.gradle file in your app directory and add it under dependencies {} node:

compile project(':volley')

Then you can refer to the open source library (actually called Module) stored locally in your code.

2. Common plug-ins

Common Plug-ins

  • Butterknife Zelezny
  • Parcelable Code Generator
  • Prettify
  • ADB Idea
  • GsonFormat
  • Android Drawable Importer
  • Android Code Generator
  • Android Material Design Icon Generator
Butterknife Zelezny 
  • Function: View Injection Framework Focusing on Android System
  • Download: Android ButterKnife Zelezny
  • Installation: Setting - > Preferences - > Plugins - > Browse repositories, find Butterknife Zelezny, or install it from disk after downloading
  • Use:
  1. Ensure that the latest Bufferknife jar file is imported into the classpath
  2. Right-click the layout reference in the code, then select Generate or press alt+Insert directly, and select Generate ButterKnife Injections
  3. Select the component that needs annotation in the open dialog box, or set a ViewHolder for the Adapter
  4. Clicking Confirm generates annotation code for components
  • Characteristic
  • Support View Injection in Activity
class ExampleActivity extends Activity {
    @InjectView(R.id.title) TextView title;
    @InjectView(R.id.subtitle) TextView subtitle;
    @InjectView(R.id.footer) TextView footer;

    @Override 
    public void onCreate(Bundle savedInstanceState) {    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_activity);
        ButterKnife.inject(this);
        // TODO Use "injected" views...
    }
}
  • Support View Injection in View
public class FancyFragment extends Fragment {
    @InjectView(R.id.button1) Button button1;
    @InjectView(R.id.button2) Button button2;

    @Override
    View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fancy_fragment, container, false);
        ButterKnife.inject(this, view);
        // TODO Use "injected" views...

        return view;
    }
}
  • Support injection in ViewHolder
public class MyAdapter extends BaseAdapter {
    @Override 
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = inflater.inflate(R.layout.whatever, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }
        holder.name.setText("John Doe");
        // etc...
        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.title) TextView name;
        @InjectView(R.id.job_title) TextView jobTitle;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
  • Support for View Event Callback Function Injection
View: @OnLongClick and @OnFocusChanged 
TextView: @OnEditorAction 
AdapterView: @OnItemClick and @OnItemLongClick 
CompoundButton: @OnCheckedChanged
  • Sample code:
// With Button parameter
@OnClick(R.id.submit)
public void sayHi(Button button) {
    button.setText("Hello!");
}

// Without parameters
@OnClick(R.id.submit)
public void submit() {
    // TODO submit data to server...
}

// Injecting multiple View events at the same time
@OnClick({ R.id.door1, R.id.door2, R.id.door3 })
public void pickDoor(DoorView door) {
    if (door.hasPrizeBehind()) {
        Toast.makeText(this, "You win!", LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "Try again", LENGTH_SHORT).show();
    }
}
  • Use screenshots:

Parcelable Code Generator 
  • Function: Parcelable interface is a unique serialization method for Android, which is more efficient than Serializable interface. It can also be used in IPC, but the implementation is slightly more complex. The plug-in can help implement the code for fields and methods required by the Parcelable interface
  • Download: Parcelable Code Generator
  • Installation: Setting - > Preferences - > Plugins - > Browse repositories, find Parcelable Code Generator, or install it from disk after downloading
  • Use:
    1. Create a new entity class and define attributes
    2. Right-click Generator or press Alt+Insert directly, select Parcelable, select the required attributes, and click OK to generate the corresponding code.

    Prettify

  • Function: Generate View declarations from layout files (without annotations)
  • Download: Android Studio Prettify
  • Installation: Setting - > Preferences - > Plugins - > Browse repositories, find Prettify, or install it from disk after downloading
  • Characteristic:
    1. Generation of view variable for setContentView of inflate activity
    2. Add the Extract String resource shortcut key to the context menu
    3. Annotation of view's cast check
    4. Variable Generation of field and method in views
    5. Relevant layout files for internal classes
    6. Search for id of layout in xml file
  • Using screenshots

ADB Idea 
  • Function: This plug-in can easily complete the following operations without manually entering ADB commands
  • Unloading application
  • Killing application process
  • Startup application
  • restart app
  • Clear application data
  • Clear application data and restart application
  • Download: ADB Idea
  • Installation: Setting - > Preferences - > Plugins - > Browse repositories, find ADB Idea, or install it from disk after downloading
  • Use: Select the appropriate menu item in Tools - > Android - > ADB Idea for operation.

    GsonFormat

  • Function: According to JSONObject format string, automatically generate entity class parameters
  • Installation: Setting - > Preferences - > Plugins - > Browse repositories, find Gson, or install it from disk after downloading
  • Use: Use Generate shortcuts in entity classes for reference JSon Entity Class Quick Generation Plug-in GsonFormat uses
  • Simple Entity Classes

  • Complex entity classes

Posted by Irvin Amoraal on Fri, 19 Apr 2019 14:21:32 -0700