Android Open Source - Android-Universal-Image-Loader-Wrapper Home Activity






From Project

Back to project page Android-Universal-Image-Loader-Wrapper.

License

The source code is released under:

Apache License

If you think the Android project Android-Universal-Image-Loader-Wrapper 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

/*******************************************************************************
 * Copyright 2011-2013 Sergey Tarasevich
 *// w  w  w .j a v a 2 s .  c om
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.nostra13.example.universalimageloader;

import static com.nostra13.example.universalimageloader.Constants.IMAGES;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;

import mobi.sherif.example.universalimageloaderwrapper.ImageLoadingViewActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.nostra13.example.universalimageloader.Constants.Extra;
import com.nostra13.universalimageloader.utils.L;

/**
 * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
 */
public class HomeActivity extends BaseActivity {

  private static final String TEST_FILE_NAME = "Universal Image Loader @#&=+-_.,!()~'%20.png";

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_home);

    File testImageOnSdCard = new File("/mnt/sdcard", TEST_FILE_NAME);
    if (!testImageOnSdCard.exists()) {
      copyTestImageToSdCard(testImageOnSdCard);
    }
  }

  public void onImageListClick(View view) {
    Intent intent = new Intent(this, ImageListActivity.class);
    intent.putExtra(Extra.IMAGES, IMAGES);
    startActivity(intent);
  }

  public void onImageGridClick(View view) {
    Intent intent = new Intent(this, ImageGridActivity.class);
    intent.putExtra(Extra.IMAGES, IMAGES);
    startActivity(intent);
  }

  public void onImagePagerClick(View view) {
    Intent intent = new Intent(this, ImagePagerActivity.class);
    intent.putExtra(Extra.IMAGES, IMAGES);
    startActivity(intent);
  }

  public void onImageGalleryClick(View view) {
    Intent intent = new Intent(this, ImageGalleryActivity.class);
    intent.putExtra(Extra.IMAGES, IMAGES);
    startActivity(intent);
  }

  public void onImageLoadingViewClick(View view) {
    Intent intent = new Intent(this, ImageLoadingViewActivity.class);
    intent.putExtra(Extra.IMAGES, IMAGES[new Random(System.currentTimeMillis()).nextInt(IMAGES.length)]);
    startActivity(intent);
  }

  @Override
  public void onBackPressed() {
    imageLoader.stop();
    super.onBackPressed();
  }

  private void copyTestImageToSdCard(final File testImageOnSdCard) {
    new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          InputStream is = getAssets().open(TEST_FILE_NAME);
          FileOutputStream fos = new FileOutputStream(testImageOnSdCard);
          byte[] buffer = new byte[8192];
          int read;
          try {
            while ((read = is.read(buffer)) != -1) {
              fos.write(buffer, 0, read);
            }
          } finally {
            fos.flush();
            fos.close();
            is.close();
          }
        } catch (IOException e) {
          L.w("Can't copy test image onto SD card");
        }
      }
    }).start();
  }
}




Java Source Code List

com.nostra13.example.universalimageloader.AbsListViewBaseActivity.java
com.nostra13.example.universalimageloader.BaseActivity.java
com.nostra13.example.universalimageloader.Constants.java
com.nostra13.example.universalimageloader.HomeActivity.java
com.nostra13.example.universalimageloader.ImageGalleryActivity.java
com.nostra13.example.universalimageloader.ImageGridActivity.java
com.nostra13.example.universalimageloader.ImageListActivity.java
com.nostra13.example.universalimageloader.ImagePagerActivity.java
com.nostra13.example.universalimageloader.UILApplication.java
com.nostra13.example.universalimageloader.widget.UILWidgetProvider.java
mobi.sherif.example.universalimageloaderwrapper.ImageLoadingViewActivity.java
mobi.sherif.util.ui.ImageLoadingView.java