If you think the Android project Android-Universal-Image-Loader 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
*//www.java2s.com
* 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.universalimageloader.sample.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.sample.Constants;
import com.nostra13.universalimageloader.sample.R;
import com.nostra13.universalimageloader.sample.fragment.ImageGalleryFragment;
import com.nostra13.universalimageloader.sample.fragment.ImageGridFragment;
import com.nostra13.universalimageloader.sample.fragment.ImageListFragment;
import com.nostra13.universalimageloader.sample.fragment.ImagePagerFragment;
import com.nostra13.universalimageloader.utils.L;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
*/publicclass HomeActivity extends Activity {
privatestaticfinal String TEST_FILE_NAME = "Universal Image Loader @#&=+-_.,!()~'%20.png";
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_home);
File testImageOnSdCard = newFile("/mnt/sdcard", TEST_FILE_NAME);
if (!testImageOnSdCard.exists()) {
copyTestImageToSdCard(testImageOnSdCard);
}
}
publicvoid onImageListClick(View view) {
Intent intent = new Intent(this, SimpleImageActivity.class);
intent.putExtra(Constants.Extra.FRAGMENT_INDEX, ImageListFragment.INDEX);
startActivity(intent);
}
publicvoid onImageGridClick(View view) {
Intent intent = new Intent(this, SimpleImageActivity.class);
intent.putExtra(Constants.Extra.FRAGMENT_INDEX, ImageGridFragment.INDEX);
startActivity(intent);
}
publicvoid onImagePagerClick(View view) {
Intent intent = new Intent(this, SimpleImageActivity.class);
intent.putExtra(Constants.Extra.FRAGMENT_INDEX, ImagePagerFragment.INDEX);
startActivity(intent);
}
publicvoid onImageGalleryClick(View view) {
Intent intent = new Intent(this, SimpleImageActivity.class);
intent.putExtra(Constants.Extra.FRAGMENT_INDEX, ImageGalleryFragment.INDEX);
startActivity(intent);
}
publicvoid onFragmentsClick(View view) {
Intent intent = new Intent(this, ComplexImageActivity.class);
startActivity(intent);
}
@Override
publicvoid onBackPressed() {
ImageLoader.getInstance().stop();
super.onBackPressed();
}
@Override
publicboolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
publicboolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_clear_memory_cache:
ImageLoader.getInstance().clearMemoryCache();
return true;
case R.id.item_clear_disc_cache:
ImageLoader.getInstance().clearDiskCache();
return true;
default:
return false;
}
}
privatevoid copyTestImageToSdCard(finalFile testImageOnSdCard) {
new Thread(new Runnable() {
@Override
publicvoid run() {
try {
InputStream is = getAssets().open(TEST_FILE_NAME);
FileOutputStream fos = new FileOutputStream(testImageOnSdCard);
byte[] buffer = newbyte[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();
}
}