Android Open Source - android-002 Test Front End Activity






From Project

Back to project page android-002.

License

The source code is released under:

Apache License

If you think the Android project android-002 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 course.labs.notificationslab;
/*w  w w . ja  v  a  2  s. c o  m*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TestFrontEndActivity extends Activity {

  private final static long DAWN_OF_TIME = 0;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_front_end);

    Button ageTweetsButton = (Button) findViewById(R.id.age_tweets_button);
    ageTweetsButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        setFileAge(DAWN_OF_TIME);
      }

    });

    Button rejuvTweetsButton = (Button) findViewById(R.id.rejuv_tweets_button);
    rejuvTweetsButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        setFileAge(System.currentTimeMillis());
      }

    });

    Button startMainActivityButton = (Button) findViewById(R.id.start_main_button);
    startMainActivityButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        startActivity(new Intent(TestFrontEndActivity.this,
            MainActivity.class));
      }
    });

    createTweetFileIfMissing();
  }

  private void createTweetFileIfMissing() {

    String fname = TestFrontEndActivity.this.getFilesDir() + "/"
        + MainActivity.TWEET_FILENAME;

    File file = new File(fname);
    if (!file.exists()) {

      PrintWriter out = null;
      BufferedReader in = null;

      try {
        out = new PrintWriter(new BufferedWriter(
            new OutputStreamWriter(openFileOutput(
                MainActivity.TWEET_FILENAME,
                Context.MODE_PRIVATE))));

        for (int resId : DownloaderTask.txtFeeds) {
          in = new BufferedReader(new InputStreamReader(
              getResources().openRawResource(resId)));

          String line;
          StringBuffer buffer = new StringBuffer();

          while ((line = in.readLine()) != null) {
            buffer.append(line);
          }
          
          out.println(buffer);
          
        }
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (Resources.NotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        try {
          if (null != in) {
            in.close();
          }
          if (null != out) {
            out.close();
          }
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }

  private void setFileAge(long timestamp) {
    String fname = TestFrontEndActivity.this.getFilesDir() + "/"
        + MainActivity.TWEET_FILENAME;
    File file = new File(fname);
    if (file.exists()) {
      file.setLastModified(timestamp);
    }
  }

}




Java Source Code List

com.michaelfitzmaurice.android.modernart.MainActivity.java
com.michaelfitzmaurice.dailyselfie.AlarmReceiver.java
com.michaelfitzmaurice.dailyselfie.AlarmTimeInterval.java
com.michaelfitzmaurice.dailyselfie.Alarms.java
com.michaelfitzmaurice.dailyselfie.SelfieDetailActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListViewAdapter.java
com.michaelfitzmaurice.dailyselfie.SelfieRecord.java
com.michaelfitzmaurice.dailyselfie.settings.ReminderIntervalDialogPreference.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsActivity.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsFragment.java
course.labs.contentproviderlab.MockLocationProvider.java
course.labs.contentproviderlab.PlaceDownloaderTask.java
course.labs.contentproviderlab.PlaceRecord.java
course.labs.contentproviderlab.PlaceViewActivity.java
course.labs.contentproviderlab.PlaceViewAdapter.java
course.labs.contentproviderlab.provider.PlaceBadgeContentProvider.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.graphicslab.BubbleActivity.java
course.labs.locationlab.MockLocationProvider.java
course.labs.locationlab.PlaceDownloaderTask.java
course.labs.locationlab.PlaceRecord.java
course.labs.locationlab.PlaceViewActivity.java
course.labs.locationlab.PlaceViewAdapter.java
course.labs.notificationslab.DownloaderTask.java
course.labs.notificationslab.FeedFragment.java
course.labs.notificationslab.FriendsFragment.java
course.labs.notificationslab.MainActivity.java
course.labs.notificationslab.SelectionListener.java
course.labs.notificationslab.TestFrontEndActivity.java