static final int CONST_TAB = 0x00000001; static final int CONST_FILTER = 0x000100; // 关注 static final int TAB_FOLLOW = CONST_TAB << 0; // 发现 static final int TAB_DISCOVER = CONST_TAB << 1; // 视频 static final int TAB_VIDEO = CONST_TAB << 2; // 2-全部 static final int MODEL_ALL = CONST_FILTER << 1; // 2-玩乐 static final int MODEL_PLAY = CONST_FILTER << 2; // 2-文创 static final int MODEL_CULTURAL = CONST_FILTER << 3; // 2-家居 static final int MODEL_HOME = CONST_FILTER << 4; // 2-汽车 static final int MODEL_CAR = CONST_FILTER << 5;
2. 通过 |= 加入多个状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 给当前状态添加指定的状态标记 static int addFlag(int model, int flag) { return model | flag; }
// 发现-全部 static final int FILTER_FOLLOW_DISCOVER_ALL = TAB_FOLLOW | MODEL_ALL; // 发现-玩乐 static final int FILTER_FOLLOW_DISCOVER_PLAY = TAB_FOLLOW | MODEL_PLAY; // 发现-文创 static final int FILTER_FOLLOW_DISCOVER_CULTURAL = TAB_FOLLOW | MODEL_CULTURAL; // 发现-家居 static final int FILTER_FOLLOW_DISCOVER_HOME = TAB_FOLLOW | MODEL_HOME; // 发现-汽车 static final int FILTER_FOLLOW_DISCOVER_CAR = TAB_FOLLOW | MODEL_HOME;
int model = FILTER_FOLLOW_DISCOVER_ALL; checkFlag(model, FILTER_FOLLOW_DISCOVER_PLAY);//false checkFlag(model, TAB_FOLLOW);//true checkFlag(model, TAB_DISCOVER);//false checkFlag(model, MODEL_ALL);//true
4. (m & ~STATUS)扣除该状态
1 2 3 4 5 6 7 8 9
// 从当前状态中移除指定的状态标记 static int removeFlag(int model, int flag) { return model & ~flag; }
int model = FILTER_FOLLOW_DISCOVER_ALL; model = removeFlag(model, MODEL_ALL);// 移除all状态 checkFlag(model, MODEL_ALL);//检查MODEL_ALL状态,false checkFlag(model, TAB_FOLLOW);//检查TAB_FOLLOW状态,true