dagger.android.support.AndroidSupportInjection Java Examples

The following examples show how to use dagger.android.support.AndroidSupportInjection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LiveDataFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    AndroidSupportInjection.inject(this);
    super.onCreate(savedInstanceState);

    Log.e(TAG, "onCreate: " + " the map is: " + viewOnSelectListenerMap.get(this.getClass()));

    // set top level adapter
    setAdapter(mRowsAdapter);

    // retrive appropriate listener from listener map and set on it
    setOnItemViewClickedListener(viewOnClickListenerMap.get(this.getClass()));
    setOnItemViewSelectedListener(viewOnSelectListenerMap.get(this.getClass()));
    setOnSearchClickedListener(onClickListener.get(this.getClass()));

    // register broadcast receiver
    DownloadCompleteBroadcastReceiver.getInstance().registerListener(this);

    // tweak the ui
    setHeadersState(HEADERS_ENABLED);
    setHeadersTransitionOnBackEnabled(true);
    setTitle(getString(R.string.livedata));

    // enable transition
    prepareEntranceTransition();
}
 
Example #2
Source File: AppInjector.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
private static void handleActivity(Activity activity) {
    if (activity instanceof HasSupportFragmentInjector || activity instanceof Injectable) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #3
Source File: TestAppInjector.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
private static void handleActivity(Activity activity) {
    if (activity instanceof HasSupportFragmentInjector || activity instanceof Injectable) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #4
Source File: LiveDataFragment.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    AndroidSupportInjection.inject(this);
    super.onCreate(savedInstanceState);

    Log.e(TAG, "onCreate: " + " the map is: " + viewOnSelectListenerMap.get(this.getClass()));

    // set top level adapter
    setAdapter(mRowsAdapter);

    // retrive appropriate listener from listener map and set on it
    setOnItemViewClickedListener(viewOnClickListenerMap.get(this.getClass()));
    setOnItemViewSelectedListener(viewOnSelectListenerMap.get(this.getClass()));
    setOnSearchClickedListener(onClickListener.get(this.getClass()));

    // register broadcast receiver
    DownloadCompleteBroadcastReceiver.getInstance().registerListener(this);

    // tweak the ui
    setHeadersState(HEADERS_ENABLED);
    setHeadersTransitionOnBackEnabled(true);
    setTitle(getString(R.string.livedata));

    // enable transition
    prepareEntranceTransition();
}
 
Example #5
Source File: ConditionalAlbumListFragment.java    From PainlessMusicPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidSupportInjection.inject(this);

    mAnimTime = getResources().getInteger(R.integer.shortest_anim_time);
    mRequestManager = Glide.with(this);

    final Activity activity = getActivity();
    if (activity == null) {
        throw new IllegalStateException("Activity is null");
    }

    mAdapter = new ConditionalAlbumsRecyclerAdapter(activity, mRequestManager);
    mAdapter.setOnAlbumClickListener(this::onListItemClick);
    mModel.setRecyclerAdpter(mAdapter);
}
 
Example #6
Source File: AppInjector.java    From mcumgr-android with Apache License 2.0 6 votes vote down vote up
private static void handleActivity(@NonNull final Activity activity) {
    if (activity instanceof Injectable || activity instanceof HasAndroidInjector) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((AppCompatActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentPreCreated(@NonNull final FragmentManager fm,
                                                             @NonNull final Fragment f,
                                                             final Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #7
Source File: AppInjector.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
private static void handleActivity(Activity activity) {
    if (activity instanceof BaseActivity) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof FragmentInjectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #8
Source File: AppInjector.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void handleActivity(final Activity activity) {
	if (activity instanceof Injectable || activity instanceof HasAndroidInjector) {
		AndroidInjection.inject(activity);
	}
	if (activity instanceof AppCompatActivity) {
		((AppCompatActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(
				new FragmentManager.FragmentLifecycleCallbacks() {
					@Override
					public void onFragmentCreated(@NonNull final FragmentManager fm, @NonNull final Fragment f, final Bundle savedInstanceState) {
						if (f instanceof Injectable) {
							AndroidSupportInjection.inject(f);
						}
					}
				}, true);
	}
}
 
Example #9
Source File: AppInjector.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
/**
 * The strategy for automated dependency injection is:
 *
 *   If this activity has implemented HasSupportFragmentInjector interfacea which means it has
 *   to return the DispatchInjector through overriding public AndroidInjector<Fragment>
 *   fragmentInjector() method to return the @Inject DispatchInjector. Then this activity must
 *   be processed with the AndroidInjection by calling the AndroidInjection.inject method.
 *
 *   If the activity is extended from the FragmentActivity, then we will set up the dependency
 *   injection for all the fragments by instrumenting the AndroidInjection.inject method at
 *   the beginning of fragment's creation. Since the fragment takes the main responsibility on
 *   UI rendering.
 *
 * @param activity activity to be processed.
 */
private static void handleActivity(Activity activity) {

    // TODO: an injectable for activity separately
    if (activity instanceof HasSupportFragmentInjector) {

        // When the activity has implemented the HasSupportFragmentInjector interface, android
        // injector will inject into it, so the activity can be injected with the dispatch
        // injector specific for fragment. Then this dispatch injector will be returned through
        // the override method and contribute to android injector factory for fragment
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                    Bundle savedInstanceState) {
                                if (f instanceof Injectable) {

                                    // The injector only contains the provision method for the
                                    // field in the fragment.
                                    // But for activity, there will be a module providing the
                                    // binding method which will be bound to the fragment's
                                    // subcomponent's builder (Android injector builder) and
                                    // then be cast to AndroidInjector.Factory
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #10
Source File: SearchFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    AndroidSupportInjection.inject(this);
    super.onCreate(savedInstanceState);
    setBadgeDrawable(ResourcesCompat.getDrawable(getActivity().getResources(),
            R.drawable.ic_add_row_circle_black_24dp, getActivity().getTheme()));

    setTitle("Search Using Live Data");
    setSearchResultProvider(this);
    setOnItemViewClickedListener(viewOnClickListenerMap.get(this.getClass()));
}
 
Example #11
Source File: TransactionsFragment.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    AndroidSupportInjection.inject(this);
    View view = inflater.inflate(R.layout.fragment_transactions, container, false);
    toolbar(view);
    setToolbarTitle(R.string.toolbar_header_transactions);
    initViewModel(view);

    return view;
}
 
Example #12
Source File: RateUsDialog.java    From android-mvvm-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    DialogRateUsBinding binding = DataBindingUtil.inflate(inflater, R.layout.dialog_rate_us, container, false);
    View view = binding.getRoot();

    AndroidSupportInjection.inject(this);
    mRateUsViewModel = ViewModelProviders.of(this,factory).get(RateUsViewModel.class);
    binding.setViewModel(mRateUsViewModel);

    mRateUsViewModel.setNavigator(this);

    return view;
}
 
Example #13
Source File: FragmentDelegateImpl.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(Context context) {
    //如果要使用eventbus请将此方法返回true
    if (iFragment.useEventBus()) {
        //注册到事件主线
        EventBus.getDefault().register(mFragment);
    }
    if (iFragment.injectable()) {
        //Dagger.Android 依赖注入
        AndroidSupportInjection.inject(mFragment);
    }
}
 
Example #14
Source File: AppInjector.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
/**
 * The strategy for automated dependency injection is:
 *
 *   If this activity has implemented HasSupportFragmentInjector interfacea which means it has
 *   to return the DispatchInjector through overriding public AndroidInjector<Fragment>
 *   fragmentInjector() method to return the @Inject DispatchInjector. Then this activity must
 *   be processed with the AndroidInjection by calling the AndroidInjection.inject method.
 *
 *   If the activity is extended from the FragmentActivity, then we will set up the dependency
 *   injection for all the fragments by instrumenting the AndroidInjection.inject method at
 *   the beginning of fragment's creation. Since the fragment takes the main responsibility on
 *   UI rendering.
 *
 * @param activity activity to be processed.
 */
private static void handleActivity(Activity activity) {

    // TODO: an injectable for activity separately
    if (activity instanceof HasSupportFragmentInjector) {

        // When the activity has implemented the HasSupportFragmentInjector interface, android
        // injector will inject into it, so the activity can be injected with the dispatch
        // injector specific for fragment. Then this dispatch injector will be returned through
        // the override method and contribute to android injector factory for fragment
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                    Bundle savedInstanceState) {
                                if (f instanceof Injectable) {

                                    // The injector only contains the provision method for the
                                    // field in the fragment.
                                    // But for activity, there will be a module providing the
                                    // binding method which will be bound to the fragment's
                                    // subcomponent's builder (Android injector builder) and
                                    // then be cast to AndroidInjector.Factory
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #15
Source File: SearchFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    AndroidSupportInjection.inject(this);
    super.onCreate(savedInstanceState);
    setBadgeDrawable(ResourcesCompat.getDrawable(getActivity().getResources(),
            R.drawable.ic_add_row_circle_black_24dp, getActivity().getTheme()));

    setTitle("Search Using Live Data");
    setSearchResultProvider(this);
    setOnItemViewClickedListener(viewOnClickListenerMap.get(this.getClass()));
}
 
Example #16
Source File: DemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void safeInject() {
  try {
    AndroidSupportInjection.inject(this);
  } catch (Exception e) {
    // Ignore exception, not all DemoFragment subclasses need to inject
  }
}
 
Example #17
Source File: ArtistAlbumsFragment.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Bundle args = getArguments();
    if (args == null) {
        throw new IllegalStateException("Arguments must not be null");
    }
    artistId = args.getLong(EXTRA_ARTIST_ID);
    AndroidSupportInjection.inject(this);
}
 
Example #18
Source File: GenreAlbumsFragment.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Bundle args = getArguments();
    if (args == null) {
        throw new IllegalStateException("Arguments must not be null");
    }
    genreId = args.getLong(EXTRA_GENRE_ID);
    AndroidSupportInjection.inject(this);
}
 
Example #19
Source File: ThemeSwitcherDialogFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onAttach(Context context) {
  AndroidSupportInjection.inject(this);
  super.onAttach(context);
}
 
Example #20
Source File: PlaybackStatusFragment.java    From PainlessMusicPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidSupportInjection.inject(this);
}
 
Example #21
Source File: EffectsFragment.java    From PainlessMusicPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidSupportInjection.inject(this);
    audioEffects.addObserver(mAudioEffectsObserver);
}
 
Example #22
Source File: LobbyFragment.java    From DaggerAndroidSampleApp with Apache License 2.0 4 votes vote down vote up
@Override
public void onAttach(Context context) {
    AndroidSupportInjection.inject(this);
    super.onAttach(context);
}
 
Example #23
Source File: BaseFragment.java    From Moneycim with MIT License 4 votes vote down vote up
@Override
public void onAttach(Context context) {
    AndroidSupportInjection.inject(this);
    super.onAttach(context);
}
 
Example #24
Source File: BaseFragment.java    From android-mvvm-architecture with Apache License 2.0 4 votes vote down vote up
private void performDependencyInjection() {
    AndroidSupportInjection.inject(this);
}
 
Example #25
Source File: BaseFragment.java    From Android-AudioRecorder-App with Apache License 2.0 4 votes vote down vote up
@Override public void onAttach(Context context) {
  super.onAttach(context);
  AndroidSupportInjection.inject(this);
}
 
Example #26
Source File: RecentAlbumsFragment.java    From PainlessMusicPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidSupportInjection.inject(this);
}
 
Example #27
Source File: LocationPreferencesActivity.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidSupportInjection.inject(this);
}
 
Example #28
Source File: BaseDialogFragment.java    From Awesome-WanAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    AndroidSupportInjection.inject(this);
}
 
Example #29
Source File: RecordsFragment.java    From android-auto-call-recorder with MIT License 4 votes vote down vote up
@Override
public void onAttach(Context context) {
    AndroidSupportInjection.inject(this);
    super.onAttach(context);
}
 
Example #30
Source File: RecordsDialog.java    From android-auto-call-recorder with MIT License 4 votes vote down vote up
@Override
public void onAttach(Context context) {
    AndroidSupportInjection.inject(this);
    super.onAttach(context);
}