Skip to content

Latest commit

 

History

History
160 lines (117 loc) · 3.74 KB

File metadata and controls

160 lines (117 loc) · 3.74 KB

Table of Contents

  1. Naming Convention
  2. Code Folding
    1. Top Level
      1. Top Level Model Class Regions
      2. Top Level Activity Class Regions
    2. Inner Level
      1. Inner Level Model Class Regions
      2. Inner Level Activity Class Regions
  3. [Handling Clicks](#Handling Clicks)

Naming Convention

Component Class Name Layout Name
Activity UserProfileScreenActivity user_profile_screen_activity.xml
Fragment SignUpScreenFragment sign_up_screen_fragment.xml
Dialog ChangePasswordScreenConfirmationDialog change_password_screen_confirmation_dialog.xml
DialogFragment PaymentScreenApplyCouponCodeDialogFragment payment_screen_apply_coupon_code_dialog_fragment.xml
AdapterView Item - profile_screen_item_person.xml

UI Elements Naming Convention

Component Prefix Example @id Java Variable
Button btn_ btn_login btnLogin
TextView tv_ tv_email tvEmail
ProgressBar pb_ pb_loading_countries pbLoadingCountries

TODO: Add below examples to the above table.

  • Frame Layout: fl

  • Linear Layout: ll

  • Table Layout: tl

  • Table Row: tr

  • Grid Layout: gl

  • Relative Layout: rl

  • Text View: tv

  • Button: bt

  • Check Box: cb

  • Switch: sw

  • Toggle Button: tb

  • Image Button: ib

  • Image View: iv

  • Progress Bar: pb

  • Seek Bar: sb

  • Rating Bar: rb

  • Spinner: sp

  • WebView: wv

  • Edit Text: et

  • Radio Group: rg

  • List View: lv

  • Grid View: gv

  • Expandable List View: el

  • Scroll View: sv

  • Horizontal Scroll View: hs

  • Search View:* se

  • Tab Host: th

  • Video View: vv

  • Dialer Filter: df

  • Include: ic

  • Fragment: fr

  • Custom View (other): cv

Code Folding

Use regions in Java classes to support code folding.

Top Level

Top Level Model Class Regions

class Person {
  
  // region Declarations
  // endregion Declarations
  
  // region Constructors
  // endregion Constructors
  
  // region Getter Setter
  // endregion Getter Setter
  
  // region Parceable
  // endregion Parceable
  
  // region Class Methods
  // endregion Class Methods
  
  // region Instance Methods
  // endregion Instance Methods

}

Top Level Activity Class Regions

class SettingsActivity extends AppCompatActivity {
   
   // region Declarations
   // endregion Declarations
   
   // region onCreate
   // endregion onCreate
 
   // region Overrides
   // endregion Overrides
   
   // region onClick Functions
   // endregion onClick Functions
   
}

Inner Level

Handling Clicks

Don't set clicklisteners from onCreate when you can directly implement android:onClick from xml.
// Bad

@Override
protected void onCreate(Bundle savedInstanceState) {

    llLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            promptForLogout(SettingsActivity.this);
        }
    });

}

// Good

<LinearLayout
    android:id="@+id/ll_logout"
    android:onClick="logoutButtonClicked">
</LinearLayout>

public void logoutButtonClicked(View view) {
    promptForLogout(SettingsActivity.this);
}

Reference Links