Android Open Source - TheNewBoston Internal Data






From Project

Back to project page TheNewBoston.

License

The source code is released under:

Eclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECI...

If you think the Android project TheNewBoston 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.homelysoft.thenewboston;
//from  w w w . j  a  v  a  2s.  co  m
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class InternalData extends Activity implements OnClickListener {

  EditText sharedData;
  TextView dataDisplay;
  Button save, load;
  FileOutputStream fos;
  String fileName = "internal_string";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.shared_prefs);
    bridgeXML();
    setOnClickListeners();
  }

  private void bridgeXML() {
    sharedData = (EditText) findViewById(R.id.et_prefs);
    dataDisplay = (TextView) findViewById(R.id.tv_prefs_status);
    save = (Button) findViewById(R.id.b_pref_save);
    load = (Button) findViewById(R.id.b_pref_load);
  }

  private void setOnClickListeners() {
    save.setOnClickListener(this);
    load.setOnClickListener(this);
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()) {
    case R.id.b_pref_save:
      String data = sharedData.getText().toString();
      /*
       * Saving data via File File f=new File(fileName); try { fos=new
       * FileOutputStream(f); //write something here fos.close(); } catch
       * (FileNotFoundException e) { e.printStackTrace(); } catch
       * (IOException e) { e.printStackTrace(); }
       */
      try {
        fos = openFileOutput(fileName, Context.MODE_PRIVATE);
        fos.write(data.getBytes());
        fos.close();
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
      break;
    case R.id.b_pref_load:
      dataDisplay.setText("Yes, you tapped load button");
      new loadStuff().execute(fileName);
      break;
    }

  }

  public class loadStuff extends AsyncTask<String, Integer, String> {
    
    ProgressDialog dialog;
    
    @Override
    protected void onPreExecute() {
      dialog=new ProgressDialog(InternalData.this);
      dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
      dialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
      String collected = null;
      FileInputStream fis = null;
            
      try {
        fis = openFileInput(fileName);
        byte[] dataArray = new byte[fis.available()];
        dialog.setMax(fis.available());
        while (fis.read(dataArray) != -1) {
          publishProgress(dataArray.length);
          try {
            Thread.sleep(100);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
        collected = new String(dataArray);
        dialog.dismiss();
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        try {
          fis.close();
          return collected;
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return null;
    }

    @Override
    protected void onProgressUpdate(Integer... progress) {
      dialog.incrementProgressBy(progress[0]);

    }

    protected void onPostExecute(String result) {
      dataDisplay.setText(result);
    }

  }

}




Java Source Code List

com.homelysoft.thenewboston.AboutUs.java
com.homelysoft.thenewboston.Accelerate.java
com.homelysoft.thenewboston.Data.java
com.homelysoft.thenewboston.Email.java
com.homelysoft.thenewboston.ExternalData.java
com.homelysoft.thenewboston.Flipper.java
com.homelysoft.thenewboston.Home.java
com.homelysoft.thenewboston.HotOrNot.java
com.homelysoft.thenewboston.InternalData.java
com.homelysoft.thenewboston.OpenedClass.java
com.homelysoft.thenewboston.OurViewClient.java
com.homelysoft.thenewboston.Photo.java
com.homelysoft.thenewboston.Preferences.java
com.homelysoft.thenewboston.SQLView.java
com.homelysoft.thenewboston.SQLite.java
com.homelysoft.thenewboston.SharedPrefs.java
com.homelysoft.thenewboston.Slider.java
com.homelysoft.thenewboston.SoundPoolPlay.java
com.homelysoft.thenewboston.Splash.java
com.homelysoft.thenewboston.StartingPoint.java
com.homelysoft.thenewboston.Tabs.java
com.homelysoft.thenewboston.TextPlay.java
com.homelysoft.thenewboston.gfx.GFXSurface.java
com.homelysoft.thenewboston.gfx.GFX.java
com.homelysoft.thenewboston.gfx.MyBringBack.java
com.homelysoft.thenewboston.vect.Vector.java