This file contains hidden or 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 MyService extends Service{ | |
| @Override | |
| public int onStartCommand(Intent intent, int flags, int startId) { | |
| boolean containsCommand = MyIntentBuilder | |
| .containsCommand(intent); | |
| d(TAG, | |
| String.format( | |
| "Service in [%s] state. cmdId: [%d]. startId: [%d]", | |
| mServiceIsStarted ? "STARTED" : "NOT STARTED", | |
| containsCommand ? |
This file contains hidden or 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
| @TargetApi(26) | |
| public static class O { | |
| public static final String CHANNEL_ID = | |
| String.valueOf(getRandomNumber()); | |
| public static void createNotification(Service context) { | |
| String channelId = createChannel(context); | |
| Notification notification = | |
| buildNotification(context, channelId); |
This file contains hidden or 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
| @TargetApi(25) | |
| public static class PreO { | |
| public static void createNotification(Service context) { | |
| // Create Pending Intents. | |
| PendingIntent piLaunchMainActivity = | |
| getLaunchActivityPI(context); | |
| PendingIntent piStopService = getStopServicePI(context); | |
| // Action to stop the service. |
This file contains hidden or 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 MyIntentBuilder{ | |
| public static MyIntentBuilder getInstance(Context context) { | |
| return new MyIntentBuilder(context); | |
| } | |
| public MyIntentBuilder(Context context) { | |
| this.mContext = context; | |
| } | |
| public MyIntentBuilder setMessage(String message) { |
This file contains hidden or 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
| dependencies { | |
| implementation fileTree(include: ['*.jar'], dir: 'libs') | |
| // Support lib | |
| implementation 'com.android.support:appcompat-v7:27.0.2' | |
| // Lifecycles | |
| implementation "android.arch.lifecycle:runtime:1.0.3" | |
| annotationProcessor "android.arch.lifecycle:compiler:1.0.0" | |
| implementation "android.arch.lifecycle:common-java8:1.0.0" |
This file contains hidden or 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 CounterLiveData extends MutableLiveData<Long> { | |
| public String toString() { | |
| return String.format("count=%d", getValue()); | |
| } | |
| public Long get() { | |
| return getValue() == null ? 0L : getValue(); | |
| } | |
| public void set(Long value) { |
This file contains hidden or 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 StateViewModel extends AndroidViewModel { | |
| private final ScheduledExecutorService myExecutor; | |
| private String mData; // This value doesn't change after it is initialized | |
| private CounterLiveData mCounter = new CounterLiveData(); // This value changes over time | |
| public StateViewModel(Application context) { | |
| super(context); | |
| myExecutor = Executors.newSingleThreadScheduledExecutor(); | |
| myExecutor.scheduleWithFixedDelay(this::recurringTask, 0, 1, TimeUnit.SECONDS); | |
| Log.d(Tags.viewmodel.name(), "ViewModel constructor: created executor"); |
This file contains hidden or 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 MainActivity extends AppCompatActivity { | |
| private TextView dataTextView; | |
| private TextView counterTextView; | |
| private StateViewModel stateViewModel; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| dataTextView = findViewById(R.id.data_textview); |
This file contains hidden or 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
| private void initializeSeekBar() { | |
| mSeekBarAudio.setOnSeekBarChangeListener( | |
| new SeekBar.OnSeekBarChangeListener() { | |
| int userSelectedPosition = 0; | |
| @Override | |
| public void onStartTrackingTouch(SeekBar seekBar) { | |
| mUserIsSeeking = true; | |
| } |
This file contains hidden or 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 interface PlayerAdapter { | |
| void loadMedia(int resourceId); | |
| void release(); | |
| boolean isPlaying(); | |
| void play(); |