使用dagger2注入自定义类对话框

时间:2017-08-09 14:20:42

标签: progressdialog inject

我有匕首的问题,我试图了解它是如何工作的。我有一个自定义类,扩展了对话框类,所以我想在所有活动或片段中注入这个类,只是为了显示隐藏我的对话框。

这是我的自定义类。

public class Loader extends Dialog {

    public static AVLoadingIndicatorView avi;
    public static TextView title;

    @Inject
    public Loader(@ApplicationContext  Context context) {
        super(context, R.style.TransparentProgressDialog);
        this.setContentView(R.layout.loader);
        avi = (AVLoadingIndicatorView) findViewById(R.id.load);
        title = (TextView) findViewById(R.id.title);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    public void setTitle(String t){
        title.setText(t);
    }
}

注意:这个类需要在构造函数中使用像parm这样的上下文,并使用库来显示一个很酷的进度。

enter code here
My module class is this.

    @Provides
    @ApplicationContext
    Context provideContext() {
        return mApplication;
    }

    @Provides
    public Loader provideLoader(@ApplicationContext Context context){
        return new Loader(context);
    }

我的组件。

enter code here
@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {

     @ApplicationContext
     Context context();

     Application application();
     PreferencesHelper getPreferences();
     Loader loader();


     void inject(MyFirebaseInstanceIDService myFirebaseInstanceIDService);
     void inject(SplashActivity splashActivity);
     void inject(SignUpActivity signUpActivity);
}

最后,我注入了我的活动。

enter code here
public class SignUpActivity extends AppCompatActivity{

    SignUpContract.Presenter presenter;

    @Inject
    PreferencesHelper preferences;

    @Inject
    Loader loader;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);
        ButterKnife.bind(this);


        ((MyApplication) getApplicationContext()).getComponent().inject(this);

        loader.setTitle(getString(R.string.dialog_processing));

        loader.show();

    }
}

我感谢任何帮助,以了解更多有关匕首的信息。感谢

 Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

0 个答案:

没有答案
相关问题