Android Open Source - sdl_tester_android Json Flipper Dialog

From Project

Back to project page sdl_tester_android.


The source code is released under:

Copyright (c) 2014, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are m...

If you think the Android project sdl_tester_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.livio.sdl.dialogs;
/*  ww w. j a v a  2s .  c o m*/
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.livio.sdl.R;
import com.livio.sdl.SdlLogMessage;
import com.livio.sdl.utils.SdlUtils;

 * This dialog shows a single JSON message, but allows the ability to flip back and forth between
 * all available messages via the arrow buttons at the bottom of the dialog.  This dialog will not
 * be updated when new messages are sent with this dialog open.  The dialog must be closed and re-opened
 * in order to refresh with new values.
 * @author Mike Burke
public class JsonFlipperDialog extends BaseAlertDialog {
  private List<SdlLogMessage> jsonMessages;
  private int currentPosition;
  private TextView text;
  private ImageButton leftButton, rightButton;
  public JsonFlipperDialog(Context context, List<SdlLogMessage> jsonMessages, int startPosition) {
    super(context, SdlUtils.makeJsonTitle(jsonMessages.get(startPosition).getCorrelationId()), R.layout.json_flipper_dialog);
    this.jsonMessages = jsonMessages;
    this.currentPosition = startPosition;
    // since refresh updates the dialog's title, this must be after createDialog() so the dialog isn't null

  protected void findViews(View parent) {
    text = (TextView) parent.findViewById(;
    // set up left button
    leftButton = (ImageButton) parent.findViewById(;
    leftButton.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        // if we can move left, do it.  if not, do nothing
        if(currentPosition > 0){
    // set up right button
    rightButton = (ImageButton) parent.findViewById(;
    rightButton.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        // if we can move right, do it.  if not, do nothing
        if(currentPosition < (jsonMessages.size()-1) ){
  // refresh the buttons & the text for this dialog
  private void refresh(){
  // refreshes the buttons with new position.  disables the buttons when we're at the edges of the list.
  private void refreshButtons(){
    boolean atStart = (currentPosition == 0);
    boolean atEnd = (currentPosition == jsonMessages.size()-1);
  // refreshes the text of the dialog - both the title and the main text.
  private void refreshText(){
    SdlLogMessage currentMessage = jsonMessages.get(currentPosition);


Java Source Code List