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.
Related
(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.
}
I am trying to make a program to get the names of all installed applications. In my Activity, I have a method called getApplicationNames that should return this information:
private ArrayList<String> getApplicationNames(Context context){
ArrayList<String> nameOfRunningApps = new ArrayList<>();
List<ApplicationInfo> runningApplications = context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
for(ApplicationInfo applicationInfo: runningApplications){
nameOfRunningApps.add(applicationInfo.name);
}
return nameOfRunningApps;
}
Now I want to call this method in onCreate():
ArrayList<String> installedProgramNames = getApplicationNames(??);
How do I make an instance of Context in order to call this method? Is this even possible?
Since Activity is basically extending Context in the hierarchy, you can easily achieve your requirement as follows inside onCreate():
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ArrayList<String> installedProgramNames = getApplicationNames(this);
...
}
In Android the Activity class extends Context (see the heirarchy diagram at the top of the documentation page), so you can pass a self-reference to your activity into getApplicationNames via the this keyword, i.e.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<String> installedProgramNames = getApplicationNames(this);
}
This is also true for other variations of Activity such as AppCompatActivity from the support libraries.
Using the application context will do the job.
ArrayList<String> installedProgramNames = getApplicationNames(getApplicationContext());
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.
How can I pass a json variable to my html page in Android, using PhoneGap?
My code:
public class Activity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
String json = readFile();
// I would pass json to menu.html
super.loadUrl("file:///android_asset/www/menu.html");
}
};
Thanks a lot.
Maybe you can use the localStorage to pass your json.
window.localstorage.setItem("Json", json);
and when you want to get this json
string json = window.localstorage.getItem("Json");
You should only be doing this if you are writing a Cordova (PhoneGap) plugin. If this is the case, you should be extending CordovaPlugin, not DroidGap. Then you will be able to return data to the JavaScript via a PluginResult object or the convenience method callbackContext.success(json) Have a look at the Plugin Development Guide, specifically the page on developing for Android.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
myclass = new MyClass(this, appView);
appView.addJavascriptInterface(this, "MyTeam");
super.loadUrl("file:///android_asset/www/menu.html");
}
and
public class MyClass {
private WebView mAppView;
private DroidGap mGap;
public MyClass(DroidGap gap, WebView view){
mAppView = view;
mGap = gap;
}
}
I have an activity group and it starts 2 activities. When the user presses a button on one of the activities, the activity group populates an ArrayList.
I am wondering if there is a way to allow both of my activities to access this ArrayList.
Here's what I have at the moment:
public class ExampleGroup extends ActivityGroup {
public static ExampleGroup group;
ArrayList<String> strs = new ArrayList<String>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
group = this;
View exampleView = getLocalActivityManager().startActivity(
"Example",
new Intent(this, Example.class).addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
setContentView(exampleView);
}
public void populateArrayList(){
//code to do it
}
}
public class Example extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
ExampleGroup.group.populateArrayList();
ArrayList<String> strs2 = ExampleGroup.group.strs;
Log.i("ArrayList contents", strs2);
}
}
The arraylist returns null. Is there something I am missing, or is there a better way to do it?
Yes essentially you're wanting to share a model object between two activities, and this has much to do with the structure of your program. See this post for more details on how that can be done:
Where should I put global methods and variables in an Android app?