本文整理匯總了Java中android.arch.lifecycle.LifecycleOwner類的典型用法代碼示例。如果您正苦於以下問題:Java LifecycleOwner類的具體用法?Java LifecycleOwner怎麽用?Java LifecycleOwner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LifecycleOwner類屬於android.arch.lifecycle包,在下文中一共展示了LifecycleOwner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getHamburgerPowerMenu
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
public static PowerMenu getHamburgerPowerMenu(Context context, LifecycleOwner lifecycleOwner, OnMenuItemClickListener onMenuItemClickListener) {
return new PowerMenu.Builder(context)
.addItem(new PowerMenuItem("Novel", true))
.addItem(new PowerMenuItem("Poetry", false))
.addItem(new PowerMenuItem("Art", false))
.addItem(new PowerMenuItem("Journals", false))
.addItem(new PowerMenuItem("Travel", false))
.setLifecycleOwner(lifecycleOwner)
.setAnimation(MenuAnimation.SHOWUP_TOP_LEFT)
.setMenuRadius(10f)
.setMenuShadow(10f)
.setTextColor(context.getResources().getColor(R.color.md_grey_800))
.setSelectedTextColor(Color.WHITE)
.setMenuColor(Color.WHITE)
.setSelectedMenuColor(context.getResources().getColor(R.color.colorPrimary))
.setOnMenuItemClickListener(onMenuItemClickListener)
.build();
}
示例2: getWritePowerMenu
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
public static CustomPowerMenu getWritePowerMenu(Context context, LifecycleOwner lifecycleOwner, OnMenuItemClickListener onMenuItemClickListener) {
ColorDrawable drawable = new ColorDrawable(context.getResources().getColor(R.color.md_blue_grey_300));
return new CustomPowerMenu.Builder<>(context, new CenterMenuAdapter())
.addItem("Novel")
.addItem("Poetry")
.addItem("Art")
.addItem("Journals")
.addItem("Travel")
.setLifecycleOwner(lifecycleOwner)
.setAnimation(MenuAnimation.FADE)
.setMenuRadius(10f)
.setMenuShadow(10f)
.setDivider(drawable)
.setDividerHeight(1)
.setOnMenuItemClickListener(onMenuItemClickListener)
.build();
}
示例3: playInfinite
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
public static void playInfinite(final LifecycleOwner lifecycleOwner, final Context context, final String mp3) {
playObservable(lifecycleOwner, context, mp3)
.subscribe(
new Consumer<Boolean>() {
@Override
public void accept(Boolean $) throws Exception {
play(lifecycleOwner, context, mp3);
}
},
new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
}
});
}
示例4: ClaimItemAdapter
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
public ClaimItemAdapter(
final Context context,
final LifecycleOwner owner,
final LiveData<List<ClaimItem>> liveItems) {
this.layoutInflater = LayoutInflater.from(context);
this.itemPresenter = new ItemPresenter(context);
liveItems.observe(owner, new Observer<List<ClaimItem>>() {
public void onChanged(final List<ClaimItem> claimItems) {
ClaimItemAdapter.this.items = (claimItems != null)
? claimItems
: Collections.<ClaimItem>emptyList();
ClaimItemAdapter.this.notifyDataSetChanged();
}
});
}
示例5: AllowanceOverviewPresenter
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
public AllowanceOverviewPresenter(
final LifecycleOwner lifecycleOwner,
final int allowance) {
ClaimApplication.getClaimDatabase()
.claimItemDao()
.selectAll()
.observe(lifecycleOwner, new Observer<List<ClaimItem>>() {
@Override
public void onChanged(final List<ClaimItem> claimItems) {
updateSpendStatsCommand.exec(claimItems);
}
});
this.allowance.set(allowance);
}
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:17,代碼來源:AllowanceOverviewPresenter.java
示例6: ClaimItemAdapter
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
public ClaimItemAdapter(
final Context context,
final LifecycleOwner owner,
final LiveData<List<ClaimItem>> liveItems) {
this.layoutInflater = LayoutInflater.from(context);
this.itemPresenter = new ItemPresenter(context);
liveItems.observe(owner, new Observer<List<ClaimItem>>() {
@Override
public void onChanged(final List<ClaimItem> claimItems) {
if (!items.isEmpty()) {
updateCommand.exec(Pair.create(items, claimItems));
} else {
createDisplayListCommand.exec(claimItems);
}
}
});
}
示例7: observe
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
@MainThread
public void observe(LifecycleOwner owner, final Observer<T> observer) {
if (hasActiveObservers()) {
Log.w(TAG, "Multiple observers registered but only one will be notified of changes.");
}
// Observe the internal MutableLiveData
super.observe(owner, new Observer<T>() {
@Override
public void onChanged(@Nullable T t) {
if (mPending.compareAndSet(true, false)) {
observer.onChanged(t);
}
}
});
}
示例8: givenUseCaseWhenExecuteThenRespondErrorCallback
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
@Test
public void givenUseCaseWhenExecuteThenRespondErrorCallback() throws Exception{
HandledException mockHandledException = mock(HandledException.class);
when(mockUseCase.lifecycleOwner()).thenReturn(mock(LifecycleOwner.class));
when(mockUseCase.run(anyString())).thenThrow(mock(Exception.class));
when(mockUseCase.canRespond()).thenReturn(true);
when(mockExceptionController.handle(any(Exception.class))).thenReturn(mockHandledException);
when(mockUseCase.exceptionController()).thenReturn(mockExceptionController);
when(mockUseCase.canRun()).thenReturn(true);
boolean added = useCaseExecutor.execute(mockArgs, mockUseCase, mockSuccessCallback, mockExceptionCallback);
verify(mockTasks, times(1)).addUseCase(mockUseCase);
assertThat(added, equalTo(true));
verify(mockUseCase, times(1)).run(mockArgs);
verify(mockTasks, times(1)).removeUseCase(mockUseCase);
verifyZeroInteractions(mockSuccessCallback);
verify(mockExceptionCallback, times(1)).onException(errorArgCaptor.capture());
assertThat(errorArgCaptor.getValue(), equalTo(mockHandledException));
}
示例9: testLifecycle
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
private void testLifecycle(ActivityController<? extends LifecycleOwner> controller) {
LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(controller.get());
TestObserver<Lifecycle.Event> testObserver = provider.lifecycle().test();
controller.create();
controller.start();
controller.resume();
controller.pause();
controller.stop();
controller.destroy();
testObserver.assertValues(
Lifecycle.Event.ON_CREATE,
Lifecycle.Event.ON_START,
Lifecycle.Event.ON_RESUME,
Lifecycle.Event.ON_PAUSE,
Lifecycle.Event.ON_STOP,
Lifecycle.Event.ON_DESTROY
);
}
示例10: testBindUntilEvent
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
private void testBindUntilEvent(ActivityController<? extends LifecycleOwner> controller) {
LifecycleProvider<Lifecycle.Event> activity = AndroidLifecycle.createLifecycleProvider(controller.get());
TestObserver<Object> testObserver = observable.compose(activity.bindUntilEvent(Lifecycle.Event.ON_STOP)).test();
controller.create();
testObserver.assertNotComplete();
controller.start();
testObserver.assertNotComplete();
controller.resume();
testObserver.assertNotComplete();
controller.pause();
testObserver.assertNotComplete();
controller.stop();
testObserver.assertComplete();
}
示例11: testLifecycle
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
private void testLifecycle(LifecycleOwner owner) {
Fragment fragment = (Fragment) owner;
ActivityController<?> controller = startFragment(fragment);
TestObserver<Lifecycle.Event> testObserver = AndroidLifecycle.createLifecycleProvider(owner).lifecycle().test();
controller.start();
controller.resume();
controller.pause();
controller.stop();
controller.destroy();
testObserver.assertValues(
Lifecycle.Event.ON_CREATE,
Lifecycle.Event.ON_START,
Lifecycle.Event.ON_RESUME,
Lifecycle.Event.ON_PAUSE,
Lifecycle.Event.ON_STOP,
Lifecycle.Event.ON_DESTROY
);
}
示例12: testBindUntilEvent
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
private void testBindUntilEvent(LifecycleOwner owner) {
Fragment fragment = (Fragment) owner;
ActivityController<?> controller = startFragment(fragment);
TestObserver<Object> testObserver = observable.compose(AndroidLifecycle.createLifecycleProvider(owner).bindUntilEvent(Lifecycle.Event.ON_STOP)).test();
testObserver.assertNotComplete();
controller.start();
testObserver.assertNotComplete();
controller.resume();
testObserver.assertNotComplete();
controller.pause();
testObserver.assertNotComplete();
controller.stop();
testObserver.assertComplete();
}
示例13: loadTodo
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
private void loadTodo(int tID) {
todosViewModel.findByID(tID).observe((LifecycleOwner) this, new Observer<Todo>() {
@Override
public void onChanged(@Nullable Todo todo) {
thistodo = todo;
edit_title.setText(thistodo.getTitle());
edit_desc.setText(thistodo.getDesc());
edit_priority.setProgress(thistodo.getPriority());
deadline = todo.getDeadline_date();
if(deadline != null)
edit_deadline.setText(todo.getDeadline_date().toString());
edit_cost.setText(String.valueOf(thistodo.getCost()));
edit_time.setText(String.valueOf(thistodo.getTime()));
Log.w("projectID", String.valueOf(thistodo.getProject()));
loadParentProject(todo.getProject());
}
});
}
示例14: onCreateView
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_todo_feed, container, false);
recyclerView = v.findViewById(R.id.recyclerView);
recyclerViewAdapter = new RecyclerViewAdapter<Todo>(new ArrayList<Todo>(),this, this);
recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity().getBaseContext()));
recyclerView.setAdapter(recyclerViewAdapter);
viewModel = ViewModelProviders.of(this).get(todosViewModel.class);
viewModel.getAll().observe((LifecycleOwner) getActivity(), new Observer<List<Todo>>() {
@Override
public void onChanged(@Nullable List<Todo> todos) {
recyclerViewAdapter.addItems(todos);
}
});
return v;
}
示例15: loadProject
import android.arch.lifecycle.LifecycleOwner; //導入依賴的package包/類
private void loadProject(int pID) {
projectsViewModel.findByID(pID).observe((LifecycleOwner) this, new Observer<Project>() {
@Override
public void onChanged(@Nullable Project project) {
getSupportActionBar().setTitle(project.getTitle());
getSupportActionBar().setSubtitle(project.getDesc());
thisprojecta = project;
edit_title.setText(project.getTitle());
edit_desc.setText(project.getDesc());
edit_priority.setProgress(project.getPriority());
deadline = project.getDead_line();
if(deadline != null)
edit_deadline.setText(project.getDead_line().toString());
}
});
}