Android Open Source - robotronic Example Simple






From Project

Back to project page robotronic.

License

The source code is released under:

Copyright (C) 2011 by Drew Schrauf Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the So...

If you think the Android project robotronic 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.drewschrauf.example.robotronic;
//from w  ww  . j  a  v a2s  . co  m
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.drewschrauf.robotronic.activities.RobotronicActivity;
import com.drewschrauf.robotronic.threads.ThreadHandler;

public class ExampleSimple extends RobotronicActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set the layout
    setContentView(R.layout.simple);
  }

  @Override
  protected void onStart() {
    super.onStart();

    // get the image
    ImageView image = (ImageView) findViewById(R.id.image);
    getThreadHandler()
        .makeImageDownloader(
            "https://raw.github.com/drewschrauf/robotronic/master/src/com/drewschrauf/example/robotronic/smiley.jpg",
            image);

    // get the text
    final TextView text = (TextView) findViewById(R.id.text);
    getThreadHandler()
        .makeDataDownloader(
            "https://raw.github.com/drewschrauf/robotronic/master/src/com/drewschrauf/example/robotronic/example.json",
            new Handler() {

              /**
               * Define a handler to deal with the retrieved data
               */
              @Override
              public void handleMessage(Message msg) {

                // check the return code (msg.what) to see if it
                // isData or isError
                if (ThreadHandler.isData(msg.what)) {

                  // parse the data (msg.obj) as a String
                  try {
                    JSONObject feed = new JSONObject(
                        (String) msg.obj);
                    text.setText(feed.getString("text"));
                  } catch (JSONException e) {
                    Toast.makeText(ExampleSimple.this,
                        "Error parsing result",
                        Toast.LENGTH_LONG).show();
                  }
                } else {

                  // deal with any errors that arose while
                  // retrieving data
                  Toast.makeText(ExampleSimple.this,
                      "Error retriving text",
                      Toast.LENGTH_LONG).show();
                }
              }
            });
  }
}




Java Source Code List

com.drewschrauf.example.robotronic.ExampleHome.java
com.drewschrauf.example.robotronic.ExampleListItem.java
com.drewschrauf.example.robotronic.ExampleList.java
com.drewschrauf.example.robotronic.ExampleSimple.java
com.drewschrauf.robotronic.activities.RobotronicActivity.java
com.drewschrauf.robotronic.activities.RobotronicListActivity.java
com.drewschrauf.robotronic.database.DatabaseHandler.java
com.drewschrauf.robotronic.database.DatabaseHelper.java
com.drewschrauf.robotronic.threads.BinaryFetchThread.java
com.drewschrauf.robotronic.threads.CacheCleaner.java
com.drewschrauf.robotronic.threads.DataFetchThread.java
com.drewschrauf.robotronic.threads.ParsingException.java
com.drewschrauf.robotronic.threads.RobotronicProperties.java
com.drewschrauf.robotronic.threads.RobotronicThread.java
com.drewschrauf.robotronic.threads.RobotronicUtilities.java
com.drewschrauf.robotronic.threads.ThreadHandler.java