Trying to load pictures from url using novoda ImageLoader - android

hi I am trying to load an image from an url using novoda Direct ImageLoader method
right now I have this class
public class MainActivity extends Activity {
public class DirectLoading extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView iv=(ImageView) findViewById(R.id.imageView1);
ImageView ivv=(ImageView) findViewById(R.id.imageView2);
Bitmap b=new DirectLoader()
.download("https://upload.wikimedia.org/wikipedia/commons/a/ad/SmallStellatedDodecahedron.jpg");
Bitmap pic=new DirectLoader()
.download("http://www.coetail.com/mamitakagi1129/wp-content/themes/twentyten/images/headers/cherryblossoms.jpg");
ivv.setImageBitmap(pic);
iv.setImageBitmap(b);
}
private void guiBuilder() {
}
}
}
I should get 2 images into the 2 imageViews, but I am getting a blank screen. There is a "Hello world" string in the layout that is not displayed so I guess I do get the images but they are not displayed graphically.

As it says in readme file https://github.com/novoda/ImageLoader/blob/develop/README.md you should handle threading when using DirectLoader.download(), for example, using AsyncTask.

Related

Assign image resource in an image view with string

(1) I am using recyleview to fetch image, text & audio file from API. For text I used volley & for image use picasso, what I will use for audio file.
(2) after fetch the image & text when apply onclicklistener pass the info to another activity. Can pass only text not images.
What I need to do to solve this problem?
this is adapter part
viewHolder.textViewStory.setText(banglaItem.getStoryName());
viewHolder.textViewWritter.setText(banglaItem.getWritterName());
Picasso.get().load(banglaItem.getStoryImage()).fit().into(viewHolder.imageView);
viewHolder.linear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,AudioActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("storyName",banglaItem.getStoryName());
intent.putExtra("storyImage",banglaItem.getStoryImage());
context.startActivity(intent);
}
});
this is the new activity part
public class AudioActivity extends AppCompatActivity {
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
int resourceId = getResources().getIdentifier(imageStory,"drawable", getPackageName());
image.setImageResource(resourceId);
}
}
(1.) if you have complete url of your audio file then you can directly stream audio file using media player classes provided by android.
(2.) you are passing storyImage in next activity ,which is a url that you get from api. so you have to find same on next activity i.e
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
Picasso.get().load(imageStory).fit().into(image);
//here image story contain url that you sent through first activity. As picasso uses cache, it will load (already loaded image in first activity) very smoothly from it cache.
}

Android using ION with PhotoView Library

My application keeps crashing every time I try to use the PhotoViewAttacher on my application of the PhotoView library. I'm using ION to display images and trying to get the PhotoView library to allow me to zoom into them. My code currently is:
public class massiveImageView extends Activity {
ImageView mImageView;
PhotoViewAttacher mAttacher;
Drawable drawable;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.massive_image_view);
// Any implementation of ImageView can be used!
mImageView = (ImageView) findViewById(R.id.imageViewMassivePage);
Ion.with(this).load("https://pbs.twimg.com/profile_images/522909800191901697/FHCGSQg0.png").withBitmap().asBitmap()
.setCallback(new FutureCallback<Bitmap>() {
#Override
public void onCompleted(Exception e, Bitmap result) {
// do something with your bitmap
drawable=new BitmapDrawable(result);
mImageView.setImageDrawable(drawable);
}
});
mAttacher = new PhotoViewAttacher(mImageView);
}
}
And the error I'm getting is at this line:
mAttacher = new PhotoViewAttacher(mImageView);
Saying:
java.lang.NoClassDefFoundError: uk.co.senab.photoview.PhotoViewAttacher
Any help would be hugely appreciated.
I still don't quite understand why it doesn't work, but I was able to find an answer, where instead of adding the dependency of the library, I just found the jar file online and added that instead, now everything is working perfect.
Library Link

Android Imageview displays old bitmap after screen rotates

My app is supposed to first displays an image, when a button is pressed, another image is displayed in the image view. However, when the screen is rotated, the imageView displays the old image. How should I go about fixing this? (bits is the Bitmap loaded into imageView on create)
My code is below:
RGBToBitmap(rgb.getWindow(), bits); //this loads a new image into bits
imageView.setImageBitmap(bits);
I suppose you are setting the first image of your ImageView in the onCreate or onStart method of your Activity.
Upon rotating the screen, the onCreate and onStart methods get called again, and therefore your ImageView displays the first image again.
In order to save your Activity state, have a look at this:
http://developer.android.com/reference/android/app/Activity.html#SavingPersistentState
This could be a possible solution:
Bitmap image = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
image = (Bitmap) getLastNonConfigurationInstance();
if(bitmap == null){
image = downloadImage();
}
setImage(bitmap);
}
#Override
public Object onRetainNonConfigurationInstance() {
return bitmap;
}
You can also read into this method when ur using fragments:
Fragment.setRetainInstance
Or the Bundle: (onSaveInstanceState(Bundle) is also available in your Activity)
//Save it onSaveInstanceState:
#Override
public void onSaveInstanceState(Bundle toSave) {
super.onSaveInstanceState(toSave);
toSave.putParcelable("bitmap", bitmap);
}
//nd get it back onCreate:
#Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
if (savedState != null) bitmap = savedState.getParcelable("bitmap");
}

Display screenshot image from one activity to another activity

I am developing playing video application and taking screenshot of running video and display a screenshot in next activity, i am playing video and taking screenshot and i am not able to display screenshot in next activity please check my code and give me changes.
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.ImageView01);
// image.setBackgroundDrawable(bitmapDrawable);
String bitmap = image.toString();
System.out.println("Image getting++++++ : " + bitmap);
Intent intent = new Intent(VideoDemo.this, ScreenshotView.class);
intent.putExtra("BitmapImage", bitmap);
startActivity(intent);
public class ScreenshotView extends Activity
{ private String filename;
private ImageButton back;
private ImageView screenshot;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.screenshot);
screenshot =(ImageView)findViewById(R.id.screen);
back = (ImageButton)findViewById(R.id.backbutton);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
System.gc();
Intent i = getIntent();
Bitmap bitmap = (Bitmap) i.getParcelableExtra("BitmapImage");
screenshot.setImageBitmap(bitmap);
}
}
Here your "bitmap" object is a string.
And you are passing a string object to your next activity.
That is why, you are not able to set image in you ImageView screenshot.
Can you try the below code and lemme know whether you fixed it.
Sending Object
Here is the code to send the Object from one to other class. One Important thing to send the Object is the class should implement the Serializable class.
The below Red Colored text should be same.
//MainActivity.java
Intent i = new Intent(MainActivity.this,startActivity.class);
ObjectClassName object = new ObjectClassName();
i.putExtra("THIS", Object);
Receiving Object
// startActivity.java
Intent i = getIntent();
ObjectClassName obj = (ObjectClassName) getIntent().getSerializableExtra("THIS");//
TypeCasting needed

Droid-fu library's WebGalleryAdapter with gallery example

Any good tutorial shows how to use Droid-fu library's WebGalleryAdapter with gallery widget ???
here you can found info about droid-fu libaray
public class ImageSwitcherGallery extends Activity{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebGalleryAdapter webAdapter = new WebGalleryAdapter(ImageGallery.this);
try {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.image_switcher_1);
webAdapter.setImageUrls(loadImages());
webAdapter.setProgressDrawable(getResources().getDrawable(R.drawable.ajax_loader));
Gallery gallery = (Gallery)findViewById(R.id.gallery);
gallery.setAdapter(webAdapter);
} catch (Exception e) {
Log.e(TAG, Util.getExceptionMsg(e));
}
}
private LinkedList<String> loadImages(){
//loading images from another static object
LinkedList<ImageURL> urlList = ResultSetHandler.getImagesGalleryUrls();
LinkedList<String> list = new LinkedList<String>();
for(ImageURL imageUrl: urlList){
list.add(imageUrl.getImagePath());
}
return list;
}
//Retriving loaded image urls
}
i am only using gallery thats why it is only displaying section 2, how can i switcher object with droid-fu libaray ?
alt text http://www.freeimagehosting.net/uploads/8954c5a8a9.jpg
Have a look at this now.
Droid-fu is discontinued.

Categories

Resources