public class Show extends Activity {
public int begir;
public int onvan_no;
private int imgViewCount = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
//ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
final int[] image = {
R.drawable.image_1,
R.drawable.image_2,
R.drawable.image_3,
R.drawable.image_4,
R.drawable.image_5,
R.drawable.image_6,
R.drawable.image_7,
R.drawable.image_8,
R.drawable.image_9,
R.drawable.image_10
};
Bundle extras = getIntent().getExtras();
if (extras != null) {
onvan_no=extras.getInt("onvan");
}
final ImageView tvk = (ImageView) findViewById(R.id.image);
tvk.setImageResource(image[onvan_no]);
//دکمه ذخیره------------------------
Button pm = (Button) findViewById(R.id.save);
pm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + "/wallpaper");
if(!dir.exists()) {
dir.mkdirs(); // build directory
}
Toast. makeText( getApplicationContext(),
"در پوشه wallpaper ذخیره شد",
Toast.LENGTH_LONG).show();
Bitmap img= BitmapFactory.decodeResource(getApplication().getResources(), image[imgViewCount]);
FileOutputStream out = null;
try {
String img_name = "/sdcard/wallpaper/image_w_( " + String.valueOf(image[imgViewCount]+1) + " ).png";
out = new FileOutputStream(img_name);
img.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}}});
//دکمه بعدی---------------------
Button km = (Button) findViewById(R.id.next);
km.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Bundle extr = getIntent().getExtras();
if (extr != null) {
}
if (imgViewCount == -1) {
imgViewCount = onvan_no+1;
}
else{
imgViewCount++;
}
if (image.length > imgViewCount) {
tvk.setImageResource(image[imgViewCount]);
}
if (image.length == imgViewCount) {
Toast. makeText( getApplicationContext(),
"تصویر آخر",
Toast.LENGTH_LONG).show();
}
}});
//دکمه قبلی----------------------
Button mm = (Button) findViewById(R.id.prev);
mm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Bundle extr = getIntent().getExtras();
if (extr != null) {
}
if (image.length!=imgViewCount) {
if (imgViewCount == -1) {
imgViewCount = onvan_no-1;
}
else{
imgViewCount--;
}
if (image.length>imgViewCount) {
tvk.setImageResource(image[imgViewCount]);
}
if (onvan_no == 0) {
Toast. makeText( getApplicationContext(),
"تصویر اول",
Toast.LENGTH_LONG).show();
}
}
}});