0

I am have been tring to get my app to just display a string from another class forever!

Here is part of the main class I have that has a sensor manager, I want to be able to shake it and display the string from my Jconnect class. From my RandomBook Class shouldnt I be able to create and instance of Jconnect and just called the method returning a string and pass the string to setText()? 
RandomBook Class:


package com.example.bp;






import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Random;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;





import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;



public class RandomBook extends Activity implements SensorEventListener {
    private float mLastX, mLastY, mLastZ;
    private boolean mInitialized;
    private SensorManager mSensorManager;

    private Sensor mAccelerometer;
    private final float NOISE = (float) 2.0;
    int category;


    public static Random rand = new Random();
    public static Element randomBook;
    public static Document doc;
    public static Elements first_page_image_links;
    public static Elements other_page_image_links;
    public static String links;
    public  static String[] stringSplit;
    public static Document parsedDoc;
    public  static String bookImage;
    public static String bookTitle;
     JConnect test= new JConnect();

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_random_book);

        mInitialized = false;
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
        Intent getIntentMainAct= getIntent();
        int id = getIntentMainAct.getIntExtra("id", 0);




    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_random_book, menu);
        return true;
    }


    @Override
    public void onAccuracyChanged(Sensor arg0, int arg1) {
        // 

    }


    @Override
    public void onSensorChanged(SensorEvent event) {

        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];
        if (!mInitialized) {
        mLastX = x;
        mLastY = y;
        mLastZ = z;

        mInitialized = true;
        } else {
        float deltaX = Math.abs(mLastX - x);
        float deltaY = Math.abs(mLastY - y);
        float deltaZ = Math.abs(mLastZ - z);
        if (deltaX < NOISE) deltaX = (float)0.0;
        if (deltaY < NOISE) deltaY = (float)0.0;
        if (deltaZ < NOISE) deltaZ = (float)0.0;
        mLastX = x;
        mLastY = y;
        mLastZ = z;

        if (deltaY > deltaX || deltaY< deltaX){


    TextView nn= (TextView) findViewById(R.id.TextView1);
    nn.setText(test.connectURL());

        }


        }

    }   


        protected void onResume() {
            super.onResume();
            mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
            }

        protected void onPause() {
            super.onPause();
            mSensorManager.unregisterListener(this);
            finish();
            }






            }

Here Is my Jconnect class:

package com.example.bp;

import java.io.IOException;
import java.util.Random;

import junit.framework.Test;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.w3c.dom.Text;


import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;

public class JConnect extends Activity {

    public static Random rand = new Random();
    public static Element randomBook;
    public static Document doc;
    public static Elements first_page_image_links;
    public static Elements other_page_image_links;
    public static String links;
    public  static String[] stringSplit;
    public static Document parsedDoc;
    public  static String bookImage;
    public static String bookTitle;
    static String splitString;
    private Element pagelink;



     public String connectURL()
        {
         Thread thread = new Thread()
         {
             @Override
             public void run() {
                 try {

                     doc = Jsoup.connect("http://www.amazon.com/s/ref=lp_283155_nr_n_25?rh=n%3A283155%2Cn%3A!1000%2Cn%3A25&bbn=1000&ie=UTF8&qid=1359169912&rnid=1000").get();
                     first_page_image_links=pagelink.getElementsByClass("image"); 
                     int size=first_page_image_links.size();
                     int randomInt=rand.nextInt(size)+1;
                     randomBook=first_page_image_links.get(randomInt);
                     links = randomBook.select("a[href]").toString();
                        stringSplit= links.split("\"");
                     parsedDoc = Jsoup.connect(stringSplit[0]).get();
//                       parsePageImage();
                 } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
             }
         };

         thread.start();




        return parsedDoc.toString();


        }

Edited by ret801

1
Contributor
2
Replies
13
Views
5 Years
Discussion Span
Last Post by ret801
0

By the way in my Jconnect class I parsed links and randomly return a link

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.