This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.myapplication | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.view.MotionEvent | |
import android.view.View | |
import com.example.myapplication.views.StarView | |
import kotlinx.android.synthetic.main.activity_main.* | |
class MainActivity : AppCompatActivity() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
struct Star { | |
let radius: CGFloat | |
init(radius: CGFloat) { | |
self.radius = radius |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void activeStateChanged(boolean newActive) { | |
if (newActive == mActive) { | |
return; | |
} | |
// immediately set active state, so we'd never dispatch anything to inactive | |
// owner | |
mActive = newActive; | |
boolean wasInactive = LiveData.this.mActiveCount == 0; | |
LiveData.this.mActiveCount += mActive ? 1 : -1; | |
if (wasInactive && mActive) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestrictTo(LIBRARY_GROUP) | |
public class SupportActivity extends Activity implements LifecycleOwner { | |
// ... | |
@Override | |
@SuppressWarnings("RestrictedApi") | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ReportFragment.injectIfNeededIn(this); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SupportActivity extends Activity implements LifecycleOwner { | |
... | |
private LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this); | |
... | |
@Override | |
protected void onSaveInstanceState(Bundle outState) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LifecycleBoundObserver extends ObserverWrapper implements GenericLifecycleObserver { | |
@NonNull final LifecycleOwner mOwner; | |
LifecycleBoundObserver(@NonNull LifecycleOwner owner, Observer<T> observer) { | |
super(observer); | |
mOwner = owner; | |
} | |
@Override | |
boolean shouldBeActive() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void setValue(T value) { | |
assertMainThread("setValue"); | |
mVersion++; | |
mData = value; | |
dispatchingValue(null); | |
} | |
private void dispatchingValue(@Nullable ObserverWrapper initiator) { | |
if (mDispatchingValue) { | |
mDispatchInvalidated = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@MainThread | |
public void observe(@NonNull LifecycleOwner owner, @NonNull Observer<T> observer) { | |
if (owner.getLifecycle().getCurrentState() == DESTROYED) { | |
// ignore | |
return; | |
} | |
LifecycleBoundObserver wrapper = new LifecycleBoundObserver(owner, observer); | |
ObserverWrapper existing = mObservers.putIfAbsent(observer, wrapper); | |
if (existing != null && !existing.isAttachedTo(owner)) { | |
throw new IllegalArgumentException("Cannot add the same observer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NameViewModel extends ViewModel { | |
private MutableLiveData<String> mCurrentName; | |
public MutableLiveData<String> getCurrentName() { | |
if (mCurrentName == null) { | |
mCurrentName = new MutableLiveData<String>(); | |
} | |
return mCurrentName; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onDestroy() { | |
mCalled = true; | |
// Use mStateSaved instead of isStateSaved() since we're past onStop() | |
if (mViewModelStore != null && !mHost.mFragmentManager.mStateSaved) { | |
mViewModelStore.clear(); | |
} | |
} |
NewerOlder