如何在上次保存的照片的第一张(上方)显示?
我想在自定义图库中首先显示上次保存的照片
我正在使用通用图片加载程序库
java文件
我能够获得所有图像,但无法获得最后一张图像
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.pmb.lovephotoframe.R;
import java.io.File;
import java.util.ArrayList;
public class CustomGallery extends ActionBarActivity {
ArrayList<String> f = new ArrayList<String>();// list of file paths
File[] listFile;
String applicationname = "Love Photo Frame";
ImageView backmain, backhome;
DisplayImageOptions options;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_gallery);
getSupportActionBar().setTitle("Greeting Cards");
final android.support.v7.app.ActionBar actionBar1 = getSupportActionBar();
final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.custom_gallry_actionbar);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ed145b")));
applicationname = "Love Photo Frame";
// getFromSdcard();
initImageLoader(getApplicationContext());
options = new DisplayImageOptions.Builder()
.showImageOnLoading(Color.TRANSPARENT)
.showImageForEmptyUri(Color.GREEN).showImageOnFail(Color.BLACK)
.cacheInMemory(true).cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565).build();
GridView imagegrid = (GridView) findViewById(R.id.gridView1);
CustomAdapter adapter = new CustomAdapter(this, getfromcard());
imagegrid.setAdapter(adapter);
DisplayImage.grid = imagegrid;
imagegrid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent i = new Intent(getApplicationContext(), DisplayImage.class);
CustomAdapter c = new CustomAdapter(getApplicationContext(), getfromcard());
i.putExtra("imageID", c.getItem(position));
startActivity(i);
finish();
}
});
backmain = (ImageView) findViewById(R.id.back_main);
backhome = (ImageView) findViewById(R.id.back_home);
backmain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent b1 = new Intent(getApplicationContext(), MainActivity.class);
b1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(b1);
}
});
backhome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent b1 = new Intent(getApplicationContext(), MainActivity.class);
b1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(b1);
}
});
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent b1 = new Intent(getApplicationContext(), MainActivity.class);
b1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(b1);
}
@SuppressWarnings("deprecation")
public static void initImageLoader(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context).threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO).build();
ImageLoader.getInstance().init(config);
}
public ArrayList<String> getfromcard() {
Toast.makeText(getApplicationContext(), "Method Called", Toast.LENGTH_LONG).show();
File file = new File(
android.os.Environment.getExternalStorageDirectory(),
applicationname);
File[] sortedByDate = file.listFiles();
if (sortedByDate != null && sortedByDate.length > 1) {
Arrays.sort(sortedByDate, new Comparator<File>() {
@Override
public int compare(File object1, File object2) {
return (int) ((object1.lastModified() > object2.lastModified()) ? object1.lastModified() : object2.lastModified());
}
});
sortedByDate = file.listFiles();
for (int i = 0; i < sortedByDate.length; i++) {
f1.add(sortedByDate[i].getAbsolutePath());
}
}
return f1;
}
/*
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.custom_gallery, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}*/
}