Last active
November 19, 2015 17:10
-
-
Save frogermcs/ccfeff9b3341a59fa38c to your computer and use it in GitHub Desktop.
FlatBuffers performance in Android - sources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
RepositoryHolder holder; | |
if (convertView == null) { | |
convertView = inflater.inflate(R.layout.list_item_repo, parent, false); | |
holder = new RepositoryHolder(convertView); | |
convertView.setTag(holder); | |
} else { | |
holder = (RepositoryHolder) convertView.getTag(); | |
} | |
holder.bindItemOnPosition(getItem(position)); | |
return convertView; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
holder.bindItemOnPosition(getItem(position)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void openWithRepos(Activity openingActivity, ReposList reposList) { | |
Intent intent = new Intent(openingActivity, ReposListActivity.class); | |
intent.putExtra(KEY_REPOS, reposList.getByteBuffer().array()); | |
intent.putExtra(KEY_MODE, MODE_FLAT_AS_IS); | |
openingActivity.startActivity(intent); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void openWithReposJson(Activity openingActivity, ReposListJson reposListJson) { | |
Intent intent = new Intent(openingActivity, ReposListActivity.class); | |
intent.putExtra(KEY_REPOS, reposListJson); | |
intent.putExtra(KEY_MODE, MODE_JSON); | |
openingActivity.startActivity(intent); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class RepositoryHolder { | |
@Bind(R.id.tvTitle) | |
TextView tvTitle; | |
@Bind(R.id.tvSubtitle) | |
TextView tvSubtitle; | |
public RepositoryHolder(View view) { | |
ButterKnife.bind(this, view); | |
} | |
public void bindItemOnPosition(Repo repository) { | |
tvTitle.setText(repository.name()); | |
tvSubtitle.setText(repository.description()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class FlatRepositoryViewHolder { | |
@Bind(R.id.tvTitle) | |
TextView tvTitle; | |
@Bind(R.id.tvSubtitle) | |
TextView tvSubtitle; | |
private ReposList reposList; | |
private Repo repository; | |
public FlatRepositoryViewHolder(View view, ReposList reposList, int itemPosition) { | |
ButterKnife.bind(this, view); | |
this.reposList = reposList; | |
repository = reposList.repos(itemPosition); | |
} | |
public void bindItemOnPosition(int itemPosition) { | |
repository = reposList.repos(repository, itemPosition); | |
bindRepositoryName(repository.name()); | |
bindRepositoryDescription(repository.description()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class RepositoryHolder { | |
@Bind(R.id.tvTitle) | |
TextView tvTitle; | |
@Bind(R.id.tvSubtitle) | |
TextView tvSubtitle; | |
public RepositoryHolder(View view) { | |
ButterKnife.bind(this, view); | |
} | |
public void bindItemOnPosition(RepoJson repository) { | |
tvTitle.setText(repository.name); | |
tvSubtitle.setText(repository.description); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ByteBuffer bb = ByteBuffer.wrap(bytes); | |
ReposList reposListFlat = frogermcs.io.flatbuffs.model.flat.ReposList.getRootAsReposList(bb); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReposListJson reposListJson = new Gson().fromJson(reposStr, ReposListJson.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void setupEasyFlatAdapter() { | |
byte[] reposByteArray = getIntent().getByteArrayExtra(KEY_REPOS); | |
reposList = ReposList.getRootAsReposList(ByteBuffer.wrap(reposByteArray)); | |
FlatRepositoriesListAdapter repositoriesListAdapter = new FlatRepositoriesListAdapter(this); | |
lvRepositories.setAdapter(repositoriesListAdapter); | |
repositoriesListAdapter.setReposList(reposList); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void setupJsonAdapter() { | |
reposListJson = getIntent().getParcelableExtra(KEY_REPOS); | |
JsonRepositoriesListAdapter repositoriesListAdapter = new JsonRepositoriesListAdapter(this); | |
lvRepositories.setAdapter(repositoriesListAdapter); | |
repositoriesListAdapter.setReposList(reposListJson); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment