Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeEclipse
titleExample Register Initialization
public void setupViewsAndListeners() {
	Register myRegister = initRegister("View Permission For Register in OpenMRS", R.id.myRegisterContainer, R.id.btn_my_register, onRegisterStartListener,
        new RegisterCountView[]{
           new RegisterCountView(R.id.txt_my_count_type_1, "mybindType1", "", "B1", CountMethod.AUTO),
           new RegisterCountView(R.id.txt_my_count_type_2, "mybindType2", "", "B2", CountMethod.AUTO),
        });
}

// You can override count for a badge like below in method updateRegisterCounts
protected void updateRegisterCounts(HomeContext homeContext) {
    if (householdRegistermyRegister.isAllowed()){ // TODO automate and call automatically without need to call resetCount
        householdRegistermyRegister.resetRegisterCounts();

        int count1 = myRegister.getCountView(R.id.txt_my_count_type_1).getCurrentCount();
        int count2 = myRegister.getCountView(R.id.txt_my_count_type_2).getCurrentCount();

		// Actual count to display should be count1+count2 so override
        householdRegistermyRegister.overrideRegisterCount(R.id.txt_my_count_type_2, count1+count2, "B2");
    }
}


A complete example would be

Code Block
languagejava
themeEclipse
titleExample Home Activity
public class MyHomeActivity extends NativeHomeActivity {
    Activity activity=this;

// keep a reference to register for custom tasks
    private Register myRegister;

    private final String TAG = getClass().getName();

    @Override
    public int smartRegistersHomeLayout() {
        return R.layout.smart_registers_home;
    }

    @Override
    protected void onCreation() {
        super.onCreation();

        navigationController = new ImmunizationNavigationController(this);//todo refactor and maybe remove this method
    }

    @Override
    public void setupViewsAndListeners() {
		myRegister = initRegister("View Permission For Register in OpenMRS", R.id.myRegisterContainer, R.id.btn_my_register, onRegisterStartListener,
        	new RegisterCountView[]{
           		new RegisterCountView(R.id.txt_my_count_type_1, "mybindType1", "", "B1", CountMethod.AUTO),
           		new RegisterCountView(R.id.txt_my_count_type_2, "mybindType2", "", "B2", CountMethod.AUTO),
        	});
	}

    @Override
	// You can override count for a badge like below in method updateRegisterCounts
	protected void updateRegisterCounts(HomeContext homeContext) {
    	if (myRegister.isAllowed()){ // TODO automate and call automatically without need to call resetCount
    	    myRegister.resetRegisterCounts();
	
    	    int count1 = myRegister.getCountView(R.id.txt_my_count_type_1).getCurrentCount();
    	    int count2 = myRegister.getCountView(R.id.txt_my_count_type_2).getCurrentCount();
	
			// Actual count to display should be count1+count2 so override
    	    myRegister.overrideRegisterCount(R.id.txt_my_count_type_2, count1+count2, "B2");
    	}
	}

    private View.OnClickListener onRegisterStartListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btn_my_register:
                    activity.startActivity(new Intent(activity, MyRegisterActivity.class));
                    break;
                case R.id.btn_register2:
                    // for other registers
                    break;
            }
        }
    };

	// on click listener for non register buttons
    private View.OnClickListener onButtonsClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btn_non_register_function1:
                    // start activity 1
                    break;

                case R.id.btn_non_register_function2:
					// start activity 2
                    activity.startActivity(new Intent(activity, MyActivity2.class));
                    break;
            }
        }
    };
}