private static List<CommanderItem> readCommanders(Context context,String commandType){
  List<CommanderItem> result=new ArrayList<>();
  SharedPreferences sp=getSharedPreferences(context);
  int counter=0;
  String keyPrefix=KEY_COMMANDER + commandType;
  while (true) {
    String key=keyPrefix + String.format("%02d",counter);
    String content=sp.getString(key,null);
    if (content == null) {
      break;
    }
    String[] ds=content.split(",");
    CommanderItem item=null;
    if (ds.length == 7) {
      item=new CommanderItem(ds[0],ds[1],ds[2],ds[3],ds[4],Boolean.parseBoolean(ds[5]),Boolean.parseBoolean(ds[6]));
    }
 else     if (ds.length == 9) {
      item=new ExpanderCommanderItem(ds[0],ds[1],ds[2],ds[3],ds[4],Boolean.parseBoolean(ds[5]),Boolean.parseBoolean(ds[6]),Integer.parseInt(ds[7]),McpGpioExpander.fromString(ds[8]));
    }
    if (item != null) {
      result.add(item);
    }
    counter++;
  }
  return result;
}

private static List < CommanderItem > readCommanders ( Context context , String commandType ) { List < CommanderItem > result = new ArrayList < > ( ) ; SharedPreferences sp = getSharedPreferences ( context ) ; int counter = 0 ; String keyPrefix = KEY_COMMANDER + commandType ; while ( true ) { String key = keyPrefix + String . format ( "%02d" , counter ) ; String content = sp . getString ( key , null ) ; if ( content == null ) { break ; } String [ ] ds = content . split ( "," ) ; CommanderItem item = null ; if ( ds . length == 7 ) { item = new CommanderItem ( ds [ 0 ] , ds [ 1 ] , ds [ 2 ] , ds [ 3 ] , ds [ 4 ] , Boolean . parseBoolean ( ds [ 5 ] ) , Boolean . parseBoolean ( ds [ 6 ] ) ) ; } else if ( ds . length == 9 ) { item = new ExpanderCommanderItem ( ds [ 0 ] , ds [ 1 ] , ds [ 2 ] , ds [ 3 ] , ds [ 4 ] , Boolean . parseBoolean ( ds [ 5 ] ) , Boolean . parseBoolean ( ds [ 6 ] ) , Integer . parseInt ( ds [ 7 ] ) , McpGpioExpander . fromString ( ds [ 8 ] ) ) ; } if ( item != null ) { result . add ( item ) ; } counter ++ ; } return result ; }
read user define command blocks
