firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.63k stars 1.83k forks source link

InflateException, Error inflating class TextView #1183

Closed genericjohndoe closed 6 years ago

genericjohndoe commented 6 years ago

Step 1: Are you in the right place?

yes

Step 2: Describe your environment

Step 3: Describe the problem:

I recieved the following error upon start up Unable to start activity ComponentInfo{com.udacity.gradle.builditbigger/com.firebase.ui.auth.KickoffActivity}: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class TextView

Steps to reproduce:

  1. Start the app, the app should fail upon start up

Observed Results:

03-09 16:04:12.294 18290-18290/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.udacity.gradle.builditbigger, PID: 18290 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.udacity.gradle.builditbigger/com.firebase.ui.auth.KickoffActivity}: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class TextView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3003) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6823) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) Caused by: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class TextView Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class TextView Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x7f040077 a=4 r=0x7f06002c} at android.content.res.TypedArray.getColorStateList(TypedArray.java:545) at android.widget.TextView.<init>(TextView.java:1137) at android.widget.TextView.<init>(TextView.java:1038) at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:75) at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103) at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024) at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) at android.view.LayoutInflater.rInflate(LayoutInflater.java:865) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828) at android.view.LayoutInflater.inflate(LayoutInflater.java:525) at android.view.LayoutInflater.inflate(LayoutInflater.java:427) at android.view.LayoutInflater.inflate(LayoutInflater.java:378) at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:383) at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323) at android.support.v7.app.AppCompatDelegateImplV9.onPostCreate(AppCompatDelegateImplV9.java:170) at android.support.v7.app.AppCompatActivity.onPostCreate(AppCompatActivity.java:97) at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1207) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2975) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6823) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) 03-09 16:04:13.142 18330-18330/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.udacity.gradle.builditbigger, PID: 18330 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.udacity.gradle.builditbigger/com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity}: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x7f040077 a=4 r=0x7f06002c} at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3003) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6823) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x7f040077 a=4 r=0x7f06002c} at android.content.res.TypedArray.getColorStateList(TypedArray.java:545) at android.widget.TextView.<init>(TextView.java:1137) at android.widget.TextView.<init>(TextView.java:1038) at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:75) at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71) at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:67) at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753) at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261) at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243) at android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621) at android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631) at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity.onCreate(AuthMethodPickerActivity.java:84) at android.app.Activity.performCreate(Activity.java:6977) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064)  at android.app.ActivityThread.-wrap14(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6823)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) 

Expected Results:

Relevant Code:

   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Constants.FIREBASEDATABASE = FirebaseDatabase.getInstance();
        Constants.FIREBASEDATABASE.setPersistenceEnabled(true);
        Constants.DATABASE = Constants.FIREBASEDATABASE.getReference();
        mFirebaseAuth = FirebaseAuth.getInstance();
        mAuthStateListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                user = firebaseAuth.getCurrentUser();
                if (user != null) { // User is signed in
                    configureApp(user);
                } else { //user isn't signed in, prompts user to sign in
                    startActivityForResult(
                            AuthUI.getInstance()
                                    .createSignInIntentBuilder()
                                    .setIsSmartLockEnabled(false)
                                    .setAvailableProviders(
                                            Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
                                                    new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
                                    .build(),
                            RC_SIGN_IN);
                }
            }
        };
    }
samtstern commented 6 years ago

@genericjohndoe can you show app/build.gradle?

genericjohndoe commented 6 years ago
apply plugin: 'com.android.application'
/*apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'*/

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.udacity.gradle.builditbigger"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resConfigs "auto"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dataBinding {
        enabled = true
    }
}

configurations.all {
    resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.1.0'
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //circular imageview
    compile 'de.hdodenhof:circleimageview:2.2.0'
    //dialog boxes
    compile 'com.afollestad.material-dialogs:core:0.9.4.7'
    //chips library
    compile project(path: ':chipslibrary')
    //Firebase
    compile 'com.google.firebase:firebase-storage:11.8.0'
    compile 'com.google.firebase:firebase-database:11.8.0'
    compile 'com.google.firebase:firebase-auth:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
    compile 'com.firebaseui:firebase-ui-auth:3.2.2'
    compile 'com.google.android.gms:play-services-auth:11.8.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
    //support library
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:appcompat-v7:27.1.0'
    compile 'com.android.support:support-v4:27.1.0'
    compile 'com.android.support:design:27.1.0'
    //lifecycle aware objects
    implementation "android.arch.lifecycle:runtime:1.1.0"
    annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
    implementation "android.arch.lifecycle:common-java8:1.1.0"
    //testing
    compile 'com.google.code.findbugs:jsr305:3.0.1'
    testCompile 'junit:junit:4.12'
    //glide
    compile 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
    //splash screen
    compile 'agency.tango.android:material-intro-screen:0.0.5'
    //floating action menu
    compile 'com.github.clans:fab:1.6.4'
    //video playback
    compile 'com.google.android.exoplayer:exoplayer:r2.5.1'
    compile 'com.google.android.exoplayer:extension-mediasession:r2.5.1'
    // ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:1.1.0"
    annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
    // Room
    implementation "android.arch.persistence.room:runtime:1.0.0"
    annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
    //kapt "android.arch.persistence.room:compiler:1.0.0"
    //vid chat
    compile 'co.netguru.videochatguru:videochatguru:0.1.2@aar'
    implementation 'org.webrtc:google-webrtc:1.0.+'
    //socialtextview
    compile 'com.hendraanggrian:socialview-core:0.17'
    compile 'com.hendraanggrian:socialview-commons:0.17'
    //gif support
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.10'
    //multidex
    compile 'com.android.support:multidex:1.0.3'

}

apply plugin: 'com.google.gms.google-services'

@samtstern

genericjohndoe commented 6 years ago

@samtstern the error is on line 29 in xml according to the error message. I tried moving around the elements in the xml docs for the layouts down. each time the app failed, but the line number didn't change, why?

samtstern commented 6 years ago

@genericjohndoe I apologize for my lack of response, I am pretty stumped on the cause of this issue and have not been able to think of a next step. But I'll try to take another look.

SUPERCILEX commented 6 years ago

@genericjohndoe Could you please try removing the configurations.all block? That's not how you should be setting dependencies... 😕

genericjohndoe commented 6 years ago

@SUPERCILEX i removed the configurations.all block, it didnt solve my problem but the project builds without error

genericjohndoe commented 6 years ago

@samtstern so i've traced the error to:

 public static Intent createIntent(Context context, FlowParameters flowParams) {
        return HelperActivityBase.createBaseIntent(
                context, AuthMethodPickerActivity.class, flowParams);
    }

When the intent is returned from HelperActivityBase.createBaseIntent(), that's when the application terminates. I'm not sure what to do from there though.... None of the methods of the AuthMethodPickerActivity or the HelperActivityBase classes are being called (including onCreate(), which means setContentView() isn't being called). What could explain the error received when layouts aren't being inflated yet?

I logged every method starting from the KickOffActivity class (The beginning of methods, the end of methods, before and after super() (if applicable), a log statement was put in every conditional block as well. The last log statement observed was the one I put in the HelperActivityBase.createBaseIntent() method, which was right before the return statement. Note: this was after AuthMethodPickerActivity.createIntent() was called....

SUPERCILEX commented 6 years ago

Hmmm, yeah, I'm stumped too. Thanks a ton for your investigation! However, creating an intent basically just tells Android what "component" aka activity, broadcast receiver etc to use for an action. If you put a breakpoint in the KickoffActivity's onCreate super call, that's where all the magic will happen. So this AppCompat line is causing the problem:

subDecor = (ViewGroup) inflater.inflate(
                        R.layout.abc_dialog_title_material, null);

That doesn't make any sense since it's a standard layout call. If I had to guess, one of your dependencies is destroying AppCompat somehow... the best advice I can offer is ripping everything apart with only FirebaseUI left over, then slowly adding back your dependencies until AppCompat breaks. Once that happens, you can send the 😡 emoji to the maintainer of that library. 😆 (Just kidding, don't do that 😉)

pavel-zolotov commented 6 years ago

I have the same issue. The most interesting thing is that one of my dependencies in build.gradle is probably the same. It is the implementation of com.github.pchmn:MaterialChipsInput library imported as a module and named as chipslibrary in your case. No doubt, it causes the problem, because if you delete it, the problem will disappear. Does anyone have an idea why it happens? How can one library cause an error in another?

samtstern commented 6 years ago

@pavel-zolotov thanks for the input! Sounds like that library is the issue? And it's compiled from a module (compile project(path: ':chipslibrary')) which means it's going to be tricky to root out the issue.

samtstern commented 6 years ago

@genericjohndoe do you get this issue if you remove that library?

genericjohndoe commented 6 years ago

@samtstern I ended up removing the firebase UI library. i set up my own login/sign in UI. things seem to work fine now

samtstern commented 6 years ago

@genericjohndoe well that's one way to solve it :cry: but I wish you didn't have to! We'll keep trying to fix it, good luck with your app!

pavel-zolotov commented 6 years ago

I have spent a ton of hours until I came up with a solution. The problem was caused by a conflict of dependencies, that use both of chipslibrary and firebase-ui-auth. Most probably there are different versions of one of the support libs. So I solved the problem by using implementation project(':chipslibrary') with implementation 'com.android.support:appcompat-v7:27.1.0' in my build.gradle instead of compile project(':chipslibrary') and compile 'com.android.support:appcompat-v7:27.1.0'

SUPERCILEX commented 6 years ago

@samtstern I don't think we'll be able to do anything about this problem on our side aside from telling developers to use aars instead of jars.

samtstern commented 6 years ago

Thanks for following up @pavel-zolotov! And @SUPERCILEX I agree, it's unfortunate but we can't do much here. Closing the issue to reflect that.

gurureddydev commented 6 months ago

FATAL EXCEPTION: main Process: com.guru.androidtv, PID: 30155 android.view.InflateException: Binary XML file line #42 in com.guru.androidtv:layout/lb_playback_transport_controls_row: Binary XML file line #42 in com.guru.androidtv:layout/lb_playback_transport_controls_row: Error inflating class Caused by: android.view.InflateException: Binary XML file line #42 in com.guru.androidtv:layout/lb_playback_transport_controls_row: Error inflating class Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:863) at android.view.LayoutInflater.createView(LayoutInflater.java:785) at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:939) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:959) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1013) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:970) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1132) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1093) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1135) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1093) at android.view.LayoutInflater.inflate(LayoutInflater.java:692) at android.view.LayoutInflater.inflate(LayoutInflater.java:542) at androidx.leanback.widget.PlaybackTransportRowPresenter.createRowViewHolder(PlaybackTransportRowPresenter.java:687) at androidx.leanback.widget.RowPresenter.onCreateViewHolder(RowPresenter.java:330) at androidx.leanback.widget.ItemBridgeAdapter.onCreateViewHolder(ItemBridgeAdapter.java:363) at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7788) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6873) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6757) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6753) at androidx.leanback.widget.GridLayoutManager.getViewForPosition(GridLayoutManager.java:1152) at androidx.leanback.widget.GridLayoutManager$2.createItem(GridLayoutManager.java:1683) at androidx.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:115) at androidx.leanback.widget.Grid.appendOneColumnVisibleItems(Grid.java:400) at androidx.leanback.widget.GridLayoutManager.appendOneColumnVisibleItems(GridLayoutManager.java:1899) at androidx.leanback.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:2333) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4645) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4348) at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4919) at android.view.View.layout(View.java:23336) at android.view.ViewGroup.layout(ViewGroup.java:6505) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:23336) at android.view.ViewGroup.layout(ViewGroup.java:6505) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:23336) at android.view.ViewGroup.layout(ViewGroup.java:6505) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:23336) at android.view.ViewGroup.layout(ViewGroup.java:6505) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 2024-03-09 09:46:49.251 30155-30155 AndroidRuntime com.guru.androidtv E at android.view.View.layout(View.java:23336) at android.view.ViewGroup.layout(ViewGroup.java:6505) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1841) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) at android.view.View.layout(View.java:23336) at android.view.ViewGroup.layout(ViewGroup.java:6505) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at com.android.internal.policy.DecorView.onLayout(DecorView.java:867) at android.view.View.layout(View.java:23336) at android.view.ViewGroup.layout(ViewGroup.java:6505) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3956) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3358) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2322) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9155) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1232) at android.view.Choreographer.doCallbacks(Choreographer.java:1029) at android.view.Choreographer.doFrame(Choreographer.java:934) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1217) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:238) at android.os.Looper.loop(Looper.java:349) at android.app.ActivityThread.main(ActivityThread.java:8262) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 68: TypedValue{t=0x2/d=0x7f04009b a=-1} at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:783) at android.view.View.(View.java:5588) at android.view.ViewGroup.(ViewGroup.java:706) at android.widget.LinearLayout.(LinearLayout.java:254) at android.widget.LinearLayout.(LinearLayout.java:250) at android.widget.LinearLayout.(LinearLayout.java:246) ... 75 more

gurureddydev commented 6 months ago

package com.guru.androidtv.player

import android.net.Uri import android.os.Bundle import androidx.leanback.app.VideoSupportFragment import androidx.leanback.app.VideoSupportFragmentGlueHost

class VideoFragment : VideoSupportFragment() {

private lateinit var transportGlue: CustomTransportControlGlue

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    transportGlue = CustomTransportControlGlue(
        context = requireContext(),
        playerAdapter = BasicMediaPlayerAdapter(requireContext())
    )

    transportGlue.host = VideoSupportFragmentGlueHost(this)

    transportGlue.subtitle = "Leanback artist"
    transportGlue.title = "Leanback team at work"
    val uriPath =
        "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
    transportGlue.playerAdapter.setDataSource(Uri.parse(uriPath))
}

}

package com.guru.androidtv.player

import android.content.Context import androidx.leanback.media.PlaybackTransportControlGlue import androidx.leanback.widget.Action import androidx.leanback.widget.ArrayObjectAdapter import androidx.leanback.widget.PlaybackControlsRow

class CustomTransportControlGlue(context: Context, playerAdapter: BasicMediaPlayerAdapter) : PlaybackTransportControlGlue(context, playerAdapter) {

private val forwardAction = PlaybackControlsRow.FastForwardAction(context)
private val rewindAction = PlaybackControlsRow.RewindAction(context)
private val nextAction = PlaybackControlsRow.SkipNextAction(context)
private val previousAction = PlaybackControlsRow.SkipPreviousAction(context)

init {
    isSeekEnabled = true
}

override fun onCreatePrimaryActions(primaryActionsAdapter: ArrayObjectAdapter) {
    primaryActionsAdapter.add(previousAction)
    primaryActionsAdapter.add(rewindAction)
    super.onCreatePrimaryActions(primaryActionsAdapter)
    primaryActionsAdapter.add(forwardAction)
    primaryActionsAdapter.add(nextAction)
}

override fun onActionClicked(action: Action) {
    when(action){
        forwardAction -> playerAdapter.fastForward()
        rewindAction -> playerAdapter.rewind()
        else -> super.onActionClicked(action)
    }
   onUpdateProgress()
}

}

package com.guru.androidtv.player

import android.content.Context import androidx.leanback.media.MediaPlayerAdapter import androidx.leanback.media.PlaybackBannerControlGlue.ACTION_ import androidx.leanback.media.PlaybackBannerControlGlue.ACTION_FAST_FORWARD import androidx.leanback.media.PlaybackBannerControlGlue.ACTION_PLAY_PAUSE import androidx.leanback.media.PlaybackBannerControlGlue.ACTION_REWIND import androidx.leanback.media.PlaybackBannerControlGlue.ACTION_SKIP_TO_NEXT import androidx.leanback.media.PlaybackBannerControlGlue.ACTION_SKIP_TO_PREVIOUS

class BasicMediaPlayerAdapter(context: Context) : MediaPlayerAdapter(context) {

val playList = ArrayList<String>()
var playListPosition = 0
override fun next() {
    super.next()
}

override fun previous() {
    super.previous()
}

override fun fastForward() {
    seekTo(currentPosition + 10_000)
}

override fun rewind() {
    seekTo(currentPosition - 10_000)
}

override fun getSupportedActions(): Long {
    return (ACTION_SKIP_TO_PREVIOUS xor ACTION_REWIND xor ACTION_PLAY_PAUSE xor ACTION_FAST_FORWARD xor ACTION_SKIP_TO_NEXT).toLong()
}

fun loadMovies() {

}

}