Android Open Source - coursera-android-pos Download Base






From Project

Back to project page coursera-android-pos.

License

The source code is released under:

MIT License

If you think the Android project coursera-android-pos 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 edu.vuum.mocca;
/*w w  w  .j  a  v a2  s  . c o  m*/
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

/**
 * This class is used as a base for the two ThreadedDownloads
 * Assignment Activities.  It instantiates the UI and handles
 * displaying images and getting text from the EditText object by
 * making displayBitmap() and getUrlString() available to subclasses.
 * 
 * This design creates a separation of concerns, where this class
 * handles UI functionality, while subclasses handle any
 * service-related functionality that downloads images.
 * 
 * DownloadBase, which extends Activity and overrides its primitive
 * operation onCreate(), is an example of the Template Method
 * Pattern. More generically, any object that extends Activity and
 * overrides its primitive methods such as onStart() or onPause() is
 * also an example of the Template Method Pattern.
 */
public class DownloadBase extends Activity {
    /**
     * Used for debugging.
     */
    private final String TAG = this.getClass().getSimpleName(); 

    /**
     * This object is the reference to the text box that allows the user to
     * input a URL to an image for downloading.
     */
    private EditText mEditText;

    /**
     * This object is a reference to the container of an image in the
     * UI.  When we finish downloading, we update this to display the
     * image we just stored on the file system.
     */
    private ImageView mImageView;

    /**
     * The original bitmap (used for resetting the image).
     */
    private Bitmap mDefaultBitmap;
    
    /**
     * Store the current bitmap for testing purposes.
     */
    public Bitmap mCurrentBitmap;
    
    /**
     * Display the given file in the ImageView.  Use
     * BitmapFactory.decodeFile().  Store the bitmap used to update
     * the file to make testing easier.
     */
    void displayBitmap (String pathname) {
      mCurrentBitmap = BitmapFactory.decodeFile(pathname);
      
      mImageView.setImageBitmap(mCurrentBitmap);
    }
    
    /**
     * Gets the URL from the EditText.
     */
    String getUrlString () {
      return mEditText.getText().toString();
    }
    
    /**
     * Resets image to the default image stored with the program and
     * reset the image default URL.
     */
    public void resetImage(View view) {
      mImageView.setImageBitmap(mDefaultBitmap);
      mCurrentBitmap = mDefaultBitmap;
        mEditText.setText(getResources().getString(R.string.default_url));
        Log.d(TAG, "reset Image");
    }
    
    /**
     * This hook method is called when the Activity is initially
     * created.  It's where we setup the UI for the activity and
     * initialize any objects that need to exist while the activity
     * exists.
     */
    @Override
        public void onCreate(Bundle savedInstanceState) {
        Log.d(getClass().getSimpleName(), "onCreate");
        super.onCreate(savedInstanceState);
        
        // Use the Android framework to create a User Interface for
        // this activity.  The interface that should be created is
        // defined in activity_download.xml in the res/layout folder.
        setContentView(R.layout.activity_download);
        
        // Once the UI is created, get a reference to the instantiated
        // EditText and ImageView objects by providing their ids to
        // the Android framework.
        mEditText = (EditText) findViewById(R.id.url);
        mImageView = (ImageView) findViewById(R.id.imageView1);
        
        // Store whatever image is originally displayed in the
        // ImageView as a local Bitmap object so that we can quickly
        // reset the image when a button is pressed.
        mCurrentBitmap =
            ((BitmapDrawable)(mImageView.getDrawable())).getBitmap();
        mDefaultBitmap = mCurrentBitmap;
    }
}




Java Source Code List

.BuggyLongTest.java
.Main.java
.PingPongWrong.java
.SimpleAtomicLongTest.java
.SimpleAtomicLong.java
edu.vuum.mocca.AndroidPlatformStrategy.java
edu.vuum.mocca.AndroidPlatformStrategy.java
edu.vuum.mocca.AndroidPlatformStrategy.java
edu.vuum.mocca.BuggyLongTest.java
edu.vuum.mocca.BuggyLongTest.java
edu.vuum.mocca.ConsolePlatformStrategy.java
edu.vuum.mocca.ConsolePlatformStrategy.java
edu.vuum.mocca.ConsolePlatformStrategy.java
edu.vuum.mocca.DownloadActivity.java
edu.vuum.mocca.DownloadActivity.java
edu.vuum.mocca.DownloadBase.java
edu.vuum.mocca.DownloadIntentService.java
edu.vuum.mocca.DownloadService.java
edu.vuum.mocca.DownloadUtils.java
edu.vuum.mocca.Main.java
edu.vuum.mocca.Main.java
edu.vuum.mocca.Main.java
edu.vuum.mocca.Options.java
edu.vuum.mocca.Options.java
edu.vuum.mocca.Options.java
edu.vuum.mocca.PingPongActivity.java
edu.vuum.mocca.PingPongActivity.java
edu.vuum.mocca.PingPongRight.java
edu.vuum.mocca.PingPongRight.java
edu.vuum.mocca.PingPongRight.java
edu.vuum.mocca.PlatformStrategyFactory.java
edu.vuum.mocca.PlatformStrategyFactory.java
edu.vuum.mocca.PlatformStrategyFactory.java
edu.vuum.mocca.PlatformStrategy.java
edu.vuum.mocca.PlatformStrategy.java
edu.vuum.mocca.PlatformStrategy.java
edu.vuum.mocca.PlayPingPong.java
edu.vuum.mocca.PlayPingPong.java
edu.vuum.mocca.PlayPingPong.java
edu.vuum.mocca.SimpleAtomicLongMultithreadedTest.java
edu.vuum.mocca.SimpleAtomicLongMultithreadedTest.java
edu.vuum.mocca.SimpleAtomicLongMultithreadedTest.java
edu.vuum.mocca.SimpleAtomicLongSingleThreadedTest.java
edu.vuum.mocca.SimpleAtomicLongSingleThreadedTest.java
edu.vuum.mocca.SimpleAtomicLongSingleThreadedTest.java
edu.vuum.mocca.SimpleAtomicLongTests.java
edu.vuum.mocca.SimpleAtomicLongTests.java
edu.vuum.mocca.SimpleAtomicLongTests.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.ThreadPoolDownloadService.java
edu.vuum.mocca.ThreadedDownloads.java
edu.vuum.mocca.provider.MoocSchema.java
edu.vuum.mocca.storage.MoocResolver.java
edu.vuum.mocca.storage.StorageUtilities.java
edu.vuum.mocca.storage.StoryCreator.java
edu.vuum.mocca.storage.StoryData.java
edu.vuum.mocca.ui.CreateStoryActivity.java
edu.vuum.mocca.ui.EditStoryActivity.java
edu.vuum.mocca.ui.ListStoryActivity.java
edu.vuum.mocca.ui.LoginActivity.java
edu.vuum.mocca.ui.SoundRecordActivity.java
edu.vuum.mocca.ui.StoryActivityBase.java
edu.vuum.mocca.ui.StoryDataArrayAdaptor.java
edu.vuum.mocca.ui.ViewStoryActivity.java
edu.vuum.mooca.BuggyBlockingQueue.java
edu.vuum.mooca.BuggyBlockingQueue.java
edu.vuum.mooca.BuggyBlockingQueue.java
edu.vuum.mooca.SynchronizedQueueImpl.java
edu.vuum.mooca.SynchronizedQueueImpl.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java.java