Fresco Library Not Loading Any Images - java

So due to memory issue I thought about using Facebook's Fresco library.
So this is what I did,
First I added the following dependencies,
compile 'com.facebook.fresco:fresco:1.3.0'
compile 'com.facebook.fresco:animated-gif:1.3.0'
Then I initialized it in application class,
Fresco.initialize(getApplicationContext());
Then I added SimpleDraweeView to layout file,
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/imageMessage"
android:layout_width="180dp"
android:layout_height="180dp"
/>
Then I added the code in my activity,
SimpleDraweeView gif = (SimpleDraweeView) row.findViewById(R.id.imageMessage);
ImageRequest request = ImageRequestBuilder.newBuilderWithSource (Uri.parse(url.get(position)))
.setProgressiveRenderingEnabled (true)
.build ();
DraweeController controller = Fresco.newDraweeControllerBuilder ()
.setImageRequest (request)
.setAutoPlayAnimations (true)
.build ();
gif.setController (controller);
But it's not loading images, I also tried different urls but same result, So what I'm missing...

i was facing same issue but not with gif. below is the code which load images, don't forget to initialize fresco.
Fresco.initialize(context);
SimpleDraweeView iv_image = (SimpleDraweeView)itemView.findViewById(R.id.iv_image);
iv_image.setImageURI(Uri.parse("your image url here"));
`
and here is xml
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/iv_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/iv_car"
fresco:viewAspectRatio="1.22"/>

Related

How do I set videopath for UDP stream using vitamio?

I'm trying to get a UDP stream from a GoPro camera.
https://github.com/KonradIT/GoProStream
I'm redoing this python code in android studio using vitamio.
But for some reason, as soon as I set the path, it crashes
_myVideoView.setVideoPath("udp://#10.5.5.100:8554");
But if I remove it, the app can launch but of course there is no video.
If someone encountered the same issue and found a solution, that would help me.
_myVideoView.setVideoPath("udp://#10.5.5.100:8554");
_myVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
_myVideoView.setBufferSize(2048);
_myVideoView.requestFocus();
_myVideoView.setMediaController(new MediaController(this));
_myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
_myVideoView.start();
I have done that for onCreate :
if(!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)){
return;
}
Vitamio.initialize(this);
the videoview :
<io.vov.vitamio.widget.VideoView
android:id="#+id/VideoView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="50dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="50dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageButtonLeft"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/WebView"
tools:visibility="visible" />
and the build graddle :
implementation project(path: ':vitamio')
ps : I've tried to put the compile line in graddle, but it can't find the method compile and the implement line seem to work just fine.
ps2 : I just tried but even http link from YouTube doesn't work, I've definitely made a mistake but dunno where
Found the solution...
I was just importing the project but I didn't build it beforehand
So there was no way it could work.
But I gave up later for other reasons and I would recommend lib vlc instead of vitamio for displaying video from udp streams.

creating android library from fragment [duplicate]

This question already has answers here:
how to get a fragment added in an XML layout
(5 answers)
Closed last year.
i'm having a fragment that i want to use it as a library in other projects.
i created a library module and copy-paste all my fragment code and resources to library mode and then to use that library module i'm writing the following code in activity's xml
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainerView"
android:name="com.dhirunand.meter.MeterFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
and in java file
MeterFragment meterFragment = new MeterFragment();
String selectedNumber = meterFragment.getSelectedNumber();
visually library mudule is working fine but i'm not able to fetch data from the library module
project github url https://github.com/dhirunand/meter--number-picker
when you are using new MeterFragment() line then you are creating NEW fragment, not using one attached to FragmentContainerView. this NEW one isn't visible on screen, its just created in memory, not shown (as you haven't posted attaching code), so getSelectedNumber() will return default value instead this set in MeterFragment attached to FragmentContainerView
you should obtain this "real" existing and visible instance from XML by
FragmentContainerView fcv = (FragmentContainerView) findViewById(R.id.fragmentContainerView);
MeterFragment meterFragment = (MeterFragment) fcv.getFragment();

Image doesn't load from Firebase storage using Glide

I am trying to get an image from firebase storage in android studio but I am stuck and cannot understand the problem. The picture just doesnt load on the ImageView.
I followed the documentation that is on official site, but it didnt help, I also searched different question here but nothing helped me unfortunatly.
I have the user-permession for Internet in the manifest already
<uses-permission android:name="android.permission.INTERNET" />
This is the ImageView
<ImageView
android:id="#+id/picProfile"
android:layout_width="100dp"
android:layout_height="100dp"
....
/>
This is how the picture looks in storage
This is my code (Java)
StorageReference firebaseStorage=FirebaseStorage.getInstance().getReference("profile_pictures/2022_01_08_18_53_17.png");
Glide.with(getView().getContext())
.load(firebaseStorage)
.into(picProfile);
Also if I try to use this part of the code, the picture (sample_01)on the ImageView will be seen:
.placeholder(R.drawable.sample_01)
The question is what I should do for make the Glide show the picture from storage?
Thank you
UPDATE
I of course implemented the class
#GlideModule
public class MyAppGlideModule extends AppGlideModule {
#Override
public void registerComponents(Context context, Glide glide, Registry registry) {
// Register FirebaseImageLoader to handle StorageReference
registry.append(StorageReference.class, InputStream.class,
new FirebaseImageLoader.Factory());
}
}
and also in gradle the following
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation 'com.firebaseui:firebase-ui-storage:3.3.0'

Get admob Id remotely

I have an application I made using android studio. As of the moment, the admob ids are defined in the strings.xml file. However, I want to make the app get the admob ids from either my server or from firebase as I want to be able to change them remotely should any problems occur. How would I go about doing this?
Either you can load Ads From Firebase Using Remote Config
or you Can Use the Firebase database. Refer this Sample Project from my Github
Load Ads From Firebse
You can do it programmatically.
Layout
From your layout file, add AdView:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
Retrieving Ad Unit Id
You need to do network calls either on your splash screen or main activity to retrieve your Ad Unit Id/s
You can use Retrofit for doing such http request calls from your web server
If you choose Firebase, you can use their
Firebase Realtime Database
Setting Ad Unit Id
In Java
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); // Set ad unit id
In Kotlin
val adView = AdView(this)
adView.adSize = AdSize.BANNER
adView.adUnitId = "ca-app-pub-3940256099942544/6300978111" // Set ad unit id
Additional
Depending on your persistent storage implementation, here's a one liner way of saving the Ad Unit Id using SharedPreferences
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("MY_AD_UNIT_ID", "YOUR_AD_UNIT_VALUE").apply();
Here's how you will retrieve it
PreferenceManager.getDefaultSharedPreferences(context).getString("MY_AD_UNIT_ID", "DEFAULT_STRING_IF_NOTHING_WAS_FOUND");
Where context is your Context.
Read more:
https://developers.google.com/admob/android/banner
There is a new API that allows you to manage Firebase projects and get configuration data from them. This would be the most logical place to look up such configuration data programmatically.
I checked the projects.get and projects.getAdminConfig, but haven't been able to find the ID you're looking for yet.
If that ID is indeed missing, it might be worth it to file a feature request.

Android Java: Buttons and TextViews not showing up when added via Java (to existing XML layout)

OK, I'm tearing my hair out.
I have a simple default relative layout XML for my main activity, and defined a LinearLayout in the XML as well. In my Java code, I added a LinearLayout row, orientation horizontal, and added it to the XML Linearlayout (which I found by ID). When I then added Buttons or Textviews to that layour row, they showed up perfectly.
However, when I attempted to do the same thing in another activity, I can't get the TextViews or Buttons to show up at all. I originally had a background image and tried adding my Buttons and TextViews directly to the root RelativeLayout (foundById), with plans to move them around by .setX and .setY, but I took away the background and reverted to referencing a specific Linearlayout like my main Activity (for testing purposes, to remove any anomalies)and it still won't show them. I have re-arranged and tested forever and can not see what I'm missing.
Here's my current XML (stripped down for testing):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_open_template"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.mystuff.stupidapp.OpenTemplateActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/openTemplateMain">
</LinearLayout>
</RelativeLayout>
...and here's the current code (also stripped down):
public class OpenTemplateActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_template);
final Resources res = getResources();
Intent intent = getIntent();
String fileName = intent.getStringExtra(MainActivity.EXTRA_FILENAME);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenHeight = displaymetrics.heightPixels;
int screenWidth = displaymetrics.widthPixels;
LinearLayout.LayoutParams rowLayoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
LinearLayout llMain = new LinearLayout(this);
llMain.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout llMainParent = (LinearLayout) findViewById(R.id.openTemplateMain);
llMainParent.addView(llMain);
Button bTest = new Button(this);
bTest.setText("TESTB");
llMain.addView(bTest);
//other code below unrelated.
}
}
Ideas, anyone? Please?
Answering my own question for those with a similar issue:
Turns out the APK was stuck, but only with code. Meaning any changes to the XML template (adding/removing Text or buttons or backgrounds) would reflect on the test device when I hit Play or Debug. But any changes to the code would NOT be reflected. I noticed this when I changed the tags in my debug logging and they were not reflected in the logs. I also noticed a Toast-like popup saying something about the app being dismissed manually and to re-run via IDE, but it didn't stay around long enough for a good look.
Clearing the cache and data, the uninstalling the app, then re-launching via the IDE play, fixed the issue. Code changes are now being reflected as expected, and code-created views are being shown as well.
You can prevent this or something similar from happening in the future by disabling the instant run feature in Android Studio: https://stackoverflow.com/a/35169716/3662251
Instant run basically incrementally compiles your code and only pushes the changes to the device. Unfortunately in its current state inconsistencies between code and runtime happen quite often and can lead to many wasted hours of bug hunting when that bug was actually introduced by instant run.

Categories

Resources