cn.trinea.android.common.util.ListUtils Java Examples

The following examples show how to use cn.trinea.android.common.util.ListUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From android-switch-env with Apache License 2.0 6 votes vote down vote up
private void initData() {
    Context context = getApplicationContext();
    hostMap = AppControl.getHostMap(context);
    appList = AppControl.getAppList(context);
    if (ListUtils.isEmpty(appList)) {
        return;
    }

    String[] dataArray = new String[appList.size()];
    for (int i = 0; i < appList.size(); i++) {
        App app = appList.get(i);
        if (app != null && !StringUtils.isEmpty(app.getAppName()) && !StringUtils.isEmpty(app.getPackageName())) {
            dataArray[i] = app.getAppName() + "(" + app.getPackageName() + ")";
        }
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
            dataArray);
    packageSpinner.setAdapter(adapter);
    int selectedPosi = PreferencesUtils.getInt(context, Constants.PREFERENCES_SELECTED_POSITION, 0);
    packageSpinner.setSelection(selectedPosi);
}
 
Example #2
Source File: MainActivity.java    From android-switch-env with Apache License 2.0 6 votes vote down vote up
private void reloadHost() {
    if (MapUtils.isEmpty(hostMap) || ListUtils.isEmpty(appList)) {
        return;
    }

    // init button status
    handler.sendEmptyMessage(isOnlineEnv() ? WHAT_INIT_ONLINE_ENV : WHAT_INIT_TEST_ENV);

    // init host text
    try {
        StringBuilder fileContent = FileUtils.readFile(HOSTS_PATH, "utf-8");
        handler.sendMessage(handler.obtainMessage(WHAT_GET_CONTENT_SUCCESS,
                fileContent == null ? "" : fileContent.toString()));
    } catch (Exception e) {
        e.printStackTrace();
        handler.sendMessage(handler.obtainMessage(WHAT_GET_CONTENT_FAIL, e.getMessage()));
    }
}
 
Example #3
Source File: MainActivity.java    From android-switch-env with Apache License 2.0 6 votes vote down vote up
/**
 * if exists domain line than it means test env
 * 
 * @param domainName
 * @return
 */
private boolean isOnlineEnv() {
    List<String> lineList = null;
    try {
        lineList = FileUtils.readFileToList(HOSTS_PATH, "utf-8");
    } catch (Exception e) {
        e.printStackTrace();
        handler.sendMessage(handler.obtainMessage(WHAT_GET_CONTENT_FAIL, e.getMessage()));
        return true;
    }

    Set<String> domainNameSet = hostMap.keySet();
    if (!ListUtils.isEmpty(lineList)) {
        for (String line : lineList) {
            for (String domainName : domainNameSet) {
                if (isDomainLine(line, domainName)) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
Example #4
Source File: JokePresenter.java    From orz with Apache License 2.0 5 votes vote down vote up
private void refresh(List<ContentlistEntity> contentlistEntities) {
    if (ListUtils.isEmpty(contentlistEntities)) {
        return;
    }
    mContentlistEntities = contentlistEntities;
    mView.showData(mContentlistEntities);
}
 
Example #5
Source File: JokePresenter.java    From orz with Apache License 2.0 5 votes vote down vote up
private void loadMore(List<ContentlistEntity> contentlistEntities) {
    if (ListUtils.isEmpty(contentlistEntities)) {
        return;
    }
    mContentlistEntities.addAll(contentlistEntities);
    mView.showData(mContentlistEntities);
}
 
Example #6
Source File: AppControl.java    From android-switch-env with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> getHostMap(Context context) {
    List<String> dataList;
    // read from sdcard first, then assets
    if (FileUtils.isFileExist(FITST_ADD_HOST_FILE)) {
        dataList = FileUtils.readFileToList(FITST_ADD_HOST_FILE, FILE_ENCODE);
    } else {
        dataList = ResourceUtils.geFileToListFromAssets(context, SECOND_ADD_HOST_FILE);
    }
    if (ListUtils.isEmpty(dataList)) {
        return null;
    }

    Map<String, String> hostMap = new LinkedHashMap<String, String>();
    for (String s : dataList) {
        // ignore empty or notes
        if (s == null || s.startsWith("#")) {
            continue;
        }

        int index = s.indexOf(" ");
        if (index == -1) {
            continue;
        }

        String first = s.substring(0, index), second = s.substring(index);
        if (!StringUtils.isEmpty(first) || !StringUtils.isEmpty(second)) {
            hostMap.put(first.trim(), second.trim());
        }
    }
    return hostMap;
}
 
Example #7
Source File: AppControl.java    From android-switch-env with Apache License 2.0 5 votes vote down vote up
public static List<App> getAppList(Context context) {
    List<String> dataList;
    // read from sdcard first, then assets
    if (FileUtils.isFileExist(FITST_APP_INFO_FILE)) {
        dataList = FileUtils.readFileToList(FITST_APP_INFO_FILE, FILE_ENCODE);
    } else {
        dataList = ResourceUtils.geFileToListFromAssets(context, SECOND_APP_INFO_FILE);
    }
    if (ListUtils.isEmpty(dataList)) {
        return null;
    }

    List<App> appList = new ArrayList<App>();
    for (String s : dataList) {
        // ignore empty or notes
        if (s == null || s.startsWith("#")) {
            continue;
        }

        int index = s.indexOf(" ");
        if (index == -1) {
            continue;
        }

        String packageName = s.substring(0, index), appName = s.substring(index);
        if (!StringUtils.isEmpty(packageName) || !StringUtils.isEmpty(appName)) {
            appList.add(new App(packageName.trim(), appName.trim()));
        }
    }
    return appList;
}
 
Example #8
Source File: ViewPagerDemo.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
@Override
public Fragment getItem(int arg0) {
    return ListUtils.isEmpty(fragmentList) ? null : fragmentList.get(arg0);
}