static analysis fixes
This commit is contained in:
parent
02dc340466
commit
a0062bf1a8
|
|
@ -15,15 +15,17 @@ import rx.subjects.BehaviorSubject;
|
|||
* Created by Gavriil Sitnikov on 02/11/2015.
|
||||
* TODO: fill description
|
||||
*/
|
||||
public class HeadsetStateObserver {
|
||||
public final class HeadsetStateObserver {
|
||||
|
||||
@Nullable
|
||||
private static HeadsetStateObserver instance;
|
||||
|
||||
@NonNull
|
||||
public static synchronized HeadsetStateObserver getInstance(@NonNull Context context) {
|
||||
if (instance == null) {
|
||||
instance = new HeadsetStateObserver(context);
|
||||
public static HeadsetStateObserver getInstance(@NonNull final Context context) {
|
||||
synchronized (HeadsetStateObserver.class) {
|
||||
if (instance == null) {
|
||||
instance = new HeadsetStateObserver(context);
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
|
@ -32,27 +34,17 @@ public class HeadsetStateObserver {
|
|||
private final BehaviorSubject<Boolean> isPluggedInSubject;
|
||||
private final Observable<Boolean> isPluggedInObservable;
|
||||
|
||||
@Nullable
|
||||
private IsPluggedInReceiver isPluggedInReceiver;
|
||||
|
||||
private HeadsetStateObserver(@NonNull Context context) {
|
||||
private HeadsetStateObserver(@NonNull final Context context) {
|
||||
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
isPluggedInSubject = BehaviorSubject.create();
|
||||
final IsPluggedInReceiver isPluggedInReceiver = new IsPluggedInReceiver();
|
||||
isPluggedInObservable = isPluggedInSubject
|
||||
.distinctUntilChanged()
|
||||
.doOnSubscribe(() -> {
|
||||
isPluggedInReceiver = new IsPluggedInReceiver();
|
||||
context.registerReceiver(isPluggedInReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
|
||||
isPluggedInSubject.onNext(isPluggedIn());
|
||||
})
|
||||
.doOnUnsubscribe(() -> {
|
||||
if (isPluggedInReceiver == null) {
|
||||
throw new IllegalStateException("IsPluggedInReceiver is null on unsubscribe");
|
||||
}
|
||||
|
||||
context.unregisterReceiver(isPluggedInReceiver);
|
||||
isPluggedInReceiver = null;
|
||||
})
|
||||
.doOnUnsubscribe(() -> context.unregisterReceiver(isPluggedInReceiver))
|
||||
.replay(1)
|
||||
.refCount();
|
||||
}
|
||||
|
|
@ -69,7 +61,7 @@ public class HeadsetStateObserver {
|
|||
private class IsPluggedInReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
|
||||
isPluggedInSubject.onNext(intent.getExtras().getInt("state") != 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import android.os.Handler;
|
|||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
|
|
@ -39,15 +38,17 @@ import rx.subjects.BehaviorSubject;
|
|||
* Created by Gavriil Sitnikov on 02/11/2015.
|
||||
* TODO: fill description
|
||||
*/
|
||||
public class VolumeController {
|
||||
public final class VolumeController {
|
||||
|
||||
@Nullable
|
||||
private static VolumeController instance;
|
||||
|
||||
@NonNull
|
||||
public static synchronized VolumeController getInstance(@NonNull Context context) {
|
||||
if (instance == null) {
|
||||
instance = new VolumeController(context);
|
||||
public static VolumeController getInstance(@NonNull final Context context) {
|
||||
synchronized (VolumeController.class) {
|
||||
if (instance == null) {
|
||||
instance = new VolumeController(context);
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
|
@ -57,8 +58,6 @@ public class VolumeController {
|
|||
private final BehaviorSubject<Integer> volumeSubject;
|
||||
private final Observable<Integer> volumeObservable;
|
||||
|
||||
@Nullable
|
||||
private VolumeObserver volumeObserver;
|
||||
@Nullable
|
||||
private SeekBar seekBar;
|
||||
@Nullable
|
||||
|
|
@ -68,26 +67,19 @@ public class VolumeController {
|
|||
@Nullable
|
||||
private Subscription seekBarSubscription;
|
||||
|
||||
private VolumeController(@NonNull Context context) {
|
||||
private VolumeController(@NonNull final Context context) {
|
||||
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
volumeSubject = BehaviorSubject.create();
|
||||
final VolumeObserver volumeObserver = new VolumeObserver();
|
||||
volumeObservable = volumeSubject
|
||||
.distinctUntilChanged()
|
||||
.doOnSubscribe(() -> {
|
||||
volumeObserver = new VolumeObserver();
|
||||
context.getContentResolver()
|
||||
.registerContentObserver(Settings.System.CONTENT_URI, true, volumeObserver);
|
||||
updateVolume();
|
||||
})
|
||||
.doOnUnsubscribe(() -> {
|
||||
if (volumeObserver == null) {
|
||||
throw new IllegalStateException("VolumeObserver is null on unsubscribe");
|
||||
}
|
||||
context.getContentResolver()
|
||||
.unregisterContentObserver(volumeObserver);
|
||||
volumeObserver = null;
|
||||
})
|
||||
.doOnUnsubscribe(() -> context.getContentResolver().unregisterContentObserver(volumeObserver))
|
||||
.replay(1)
|
||||
.refCount();
|
||||
}
|
||||
|
|
@ -96,7 +88,7 @@ public class VolumeController {
|
|||
volumeSubject.onNext(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
|
||||
}
|
||||
|
||||
public void setVolume(int value) {
|
||||
public void setVolume(final int value) {
|
||||
if (value < 0 || value > maxVolume) {
|
||||
throw new IllegalStateException("Volume: " + value + " out of bounds [0," + maxVolume + "]");
|
||||
}
|
||||
|
|
@ -114,7 +106,7 @@ public class VolumeController {
|
|||
return volumeObservable;
|
||||
}
|
||||
|
||||
public void attachSeekBar(@NonNull SeekBar seekBar) {
|
||||
public void attachSeekBar(@NonNull final SeekBar seekBar) {
|
||||
if (this.seekBar != null) {
|
||||
throw new IllegalArgumentException("Attached SeekBar is not null");
|
||||
}
|
||||
|
|
@ -124,16 +116,18 @@ public class VolumeController {
|
|||
this.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
|
||||
setVolume(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
public void onStartTrackingTouch(final SeekBar seekBar) {
|
||||
//ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
public void onStopTrackingTouch(final SeekBar seekBar) {
|
||||
//ignored
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -143,7 +137,21 @@ public class VolumeController {
|
|||
.subscribe(seekBar::setProgress);
|
||||
}
|
||||
|
||||
public void attachVolumeButtons(@NonNull ImageView volumeDown, @NonNull ImageView volumeUp) {
|
||||
public void detachSeekBar(@NonNull final SeekBar seekBar) {
|
||||
if (this.seekBar != seekBar) {
|
||||
throw new IllegalArgumentException("Wrong SeekBar: " + seekBar + " != " + this.seekBar);
|
||||
}
|
||||
if (seekBarSubscription == null) {
|
||||
throw new IllegalStateException("SeekBarSubscription is null on detach of SeekBar");
|
||||
}
|
||||
|
||||
this.seekBar.setOnSeekBarChangeListener(null);
|
||||
seekBarSubscription.unsubscribe();
|
||||
seekBarSubscription = null;
|
||||
this.seekBar = null;
|
||||
}
|
||||
|
||||
public void attachVolumeButtons(@NonNull final ImageView volumeDown, @NonNull final ImageView volumeUp) {
|
||||
if (this.volumeDown != null && this.volumeUp != null) {
|
||||
throw new IllegalArgumentException("Attached volume buttons is not null");
|
||||
}
|
||||
|
|
@ -161,26 +169,9 @@ public class VolumeController {
|
|||
setVolume(getVolume() - 1);
|
||||
}
|
||||
});
|
||||
seekBarSubscription = observeVolume()
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(seekBar::setProgress);
|
||||
}
|
||||
|
||||
public void detachSeekBar(@NonNull SeekBar seekBar) {
|
||||
if (this.seekBar != seekBar) {
|
||||
throw new IllegalArgumentException("Wrong SeekBar: " + seekBar + " != " + this.seekBar);
|
||||
}
|
||||
if (seekBarSubscription == null) {
|
||||
throw new IllegalStateException("SeekBarSubscription is null on detach of SeekBar");
|
||||
}
|
||||
|
||||
this.seekBar.setOnSeekBarChangeListener(null);
|
||||
seekBarSubscription.unsubscribe();
|
||||
seekBarSubscription = null;
|
||||
this.seekBar = null;
|
||||
}
|
||||
|
||||
public void detachVolumeButtons(@NonNull ImageView volumeDownImageView, @NonNull ImageView volumeUpImageView) {
|
||||
public void detachVolumeButtons(@NonNull final ImageView volumeDownImageView, @NonNull final ImageView volumeUpImageView) {
|
||||
if (this.volumeDown != volumeDownImageView && this.volumeUp != volumeUpImageView) {
|
||||
throw new IllegalArgumentException("Wrong SeekBar: " + seekBar + " != " + this.seekBar);
|
||||
}
|
||||
|
|
@ -196,7 +187,7 @@ public class VolumeController {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
public void onChange(final boolean selfChange) {
|
||||
updateVolume();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.roboswag.components.navigation;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
|
@ -29,6 +30,8 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import rx.functions.Func1;
|
||||
|
||||
/**
|
||||
* Created by Gavriil Sitnikov on 21/10/2015.
|
||||
* TODO: fill description
|
||||
|
|
@ -39,7 +42,7 @@ public abstract class AbstractBaseActivity extends AppCompatActivity
|
|||
|
||||
private static final String TOP_FRAGMENT_TAG_MARK = "TOP_FRAGMENT";
|
||||
|
||||
private boolean isPaused = false;
|
||||
private boolean isPaused;
|
||||
|
||||
/* Returns id of main fragments container where navigation-node fragments should be */
|
||||
protected int getFragmentContainerId() {
|
||||
|
|
@ -48,19 +51,19 @@ public abstract class AbstractBaseActivity extends AppCompatActivity
|
|||
|
||||
/* Returns if last fragment in stack is top (added by setFragment) like fragment from sidebar menu */
|
||||
public boolean isCurrentFragmentTop() {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
if (fragmentManager.getBackStackEntryCount() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String topFragmentTag = fragmentManager
|
||||
final String topFragmentTag = fragmentManager
|
||||
.getBackStackEntryAt(fragmentManager.getBackStackEntryCount() - 1)
|
||||
.getName();
|
||||
return topFragmentTag != null && topFragmentTag.contains(TOP_FRAGMENT_TAG_MARK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected void onCreate(final @Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
||||
}
|
||||
|
|
@ -78,33 +81,44 @@ public abstract class AbstractBaseActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentStarted(@NonNull AbstractBaseFragment fragment) {
|
||||
public void onFragmentStarted(@NonNull final AbstractBaseFragment fragment) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/* Raises when back stack changes */
|
||||
@Override
|
||||
public void onBackStackChanged() {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/* Setting fragment of special class as first in stack */
|
||||
public Fragment setFirstFragment(Class<?> fragmentClass) {
|
||||
public <T extends AbstractBaseFragment> T setFirstFragment(@NonNull final Class<T> fragmentClass) {
|
||||
return setFirstFragment(fragmentClass, null);
|
||||
}
|
||||
|
||||
/* Setting fragment of special class as first in stack with args */
|
||||
public Fragment setFirstFragment(Class<?> fragmentClass, Bundle args) {
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends AbstractBaseFragment> T setFirstFragment(@NonNull final Class<T> fragmentClass,
|
||||
@Nullable final Bundle args) {
|
||||
if (isPaused) {
|
||||
//TODO: log
|
||||
return null;
|
||||
}
|
||||
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
if (fragmentManager.getBackStackEntryCount() > 0) {
|
||||
fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
}
|
||||
|
||||
Fragment fragment = Fragment.instantiate(this, fragmentClass.getName(), args);
|
||||
final T fragment;
|
||||
try {
|
||||
fragment = (T) Fragment.instantiate(this, fragmentClass.getName(), args);
|
||||
} catch (Exception ex) {
|
||||
//TODO: log
|
||||
return null;
|
||||
}
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(getFragmentContainerId(), fragment, null)
|
||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
|
|
@ -112,91 +126,79 @@ public abstract class AbstractBaseActivity extends AppCompatActivity
|
|||
return fragment;
|
||||
}
|
||||
|
||||
private Fragment addFragmentToStack(Class<?> fragmentClass, Bundle args, String backStackTag) {
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends AbstractBaseFragment> T addFragmentToStack(@NonNull final Class<T> fragmentClass,
|
||||
@Nullable final Bundle args,
|
||||
@Nullable final String backStackTag) {
|
||||
if (isPaused) {
|
||||
//TODO: log
|
||||
return null;
|
||||
}
|
||||
|
||||
Fragment fragment = Fragment.instantiate(this, fragmentClass.getName(), args);
|
||||
final T fragment;
|
||||
try {
|
||||
fragment = (T) Fragment.instantiate(this, fragmentClass.getName(), args);
|
||||
} catch (Exception ex) {
|
||||
//TODO: log
|
||||
return null;
|
||||
}
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(getFragmentContainerId(), fragment, backStackTag)
|
||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
.addToBackStack(backStackTag)
|
||||
.commit();
|
||||
return fragment;
|
||||
return (T) fragment;
|
||||
}
|
||||
|
||||
/* Setting fragment of special class as top */
|
||||
public Fragment setFragment(Class fragmentClass) {
|
||||
public <T extends AbstractBaseFragment> T setFragment(@NonNull final Class<T> fragmentClass) {
|
||||
return setFragment(fragmentClass, null);
|
||||
}
|
||||
|
||||
/* Setting fragment of special class as top with args */
|
||||
public Fragment setFragment(Class fragmentClass, Bundle args) {
|
||||
public <T extends AbstractBaseFragment> T setFragment(@NonNull final Class<T> fragmentClass, @Nullable final Bundle args) {
|
||||
return addFragmentToStack(fragmentClass, args, fragmentClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK);
|
||||
}
|
||||
|
||||
/* Pushing fragment of special class to fragments stack */
|
||||
public Fragment pushFragment(Class fragmentClass) {
|
||||
public <T extends AbstractBaseFragment> T pushFragment(@NonNull final Class<T> fragmentClass) {
|
||||
return pushFragment(fragmentClass, null);
|
||||
}
|
||||
|
||||
/* Pushing fragment of special class with args to fragments stack */
|
||||
public Fragment pushFragment(Class fragmentClass, Bundle args) {
|
||||
public <T extends AbstractBaseFragment> T pushFragment(@NonNull final Class<T> fragmentClass, @Nullable final Bundle args) {
|
||||
return addFragmentToStack(fragmentClass, args, fragmentClass.getName());
|
||||
}
|
||||
|
||||
/* Raises when device back button pressed */
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
boolean backPressResult = false;
|
||||
if (fragmentManager.getFragments() != null) {
|
||||
for (Fragment fragment : fragmentManager.getFragments()) {
|
||||
if (fragment != null && fragment.isResumed() && fragment instanceof AbstractBaseFragment) {
|
||||
backPressResult = backPressResult || ((AbstractBaseFragment) fragment).onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!backPressResult) {
|
||||
if (!tryForeachChild(AbstractBaseFragment::onBackPressed)) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
if (tryHomeOnChildren(fragmentManager)) {
|
||||
if (tryForeachChild(AbstractBaseFragment::onHomePressed)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int stackSize = fragmentManager.getBackStackEntryCount();
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
final int stackSize = fragmentManager.getBackStackEntryCount();
|
||||
|
||||
switch (stackSize) {
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
fragmentManager.popBackStack();
|
||||
getSupportFragmentManager().popBackStack();
|
||||
return true;
|
||||
default:
|
||||
String lastFragmentName = fragmentManager.getBackStackEntryAt(stackSize - 1).getName();
|
||||
for (int i = stackSize - 2; i >= 0; i--) {
|
||||
String currentFragmentName = fragmentManager.getBackStackEntryAt(i).getName();
|
||||
if (currentFragmentName == null || !currentFragmentName.equals(lastFragmentName)) {
|
||||
fragmentManager.popBackStackImmediate(currentFragmentName, 0);
|
||||
break;
|
||||
} else if (i == 0) {
|
||||
fragmentManager.popBackStackImmediate(currentFragmentName, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
} else {
|
||||
lastFragmentName = currentFragmentName;
|
||||
}
|
||||
}
|
||||
findTopFragmentAndPopBackStackToIt(fragmentManager, stackSize);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
|
|
@ -204,26 +206,45 @@ public abstract class AbstractBaseActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
|
||||
private boolean tryHomeOnChildren(@NonNull FragmentManager fragmentManager) {
|
||||
boolean homePressResult = false;
|
||||
if (fragmentManager.getFragments() != null) {
|
||||
for (Fragment fragment : fragmentManager.getFragments()) {
|
||||
if (fragment != null
|
||||
&& fragment.isResumed()
|
||||
&& fragment instanceof AbstractBaseFragment) {
|
||||
homePressResult = homePressResult || ((AbstractBaseFragment) fragment).onHomePressed();
|
||||
}
|
||||
private void findTopFragmentAndPopBackStackToIt(@NonNull final FragmentManager fragmentManager, final int stackSize) {
|
||||
String lastFragmentName = fragmentManager.getBackStackEntryAt(stackSize - 1).getName();
|
||||
for (int i = stackSize - 2; i >= 0; i--) {
|
||||
final String currentFragmentName = fragmentManager.getBackStackEntryAt(i).getName();
|
||||
if (currentFragmentName == null || !currentFragmentName.equals(lastFragmentName)) {
|
||||
fragmentManager.popBackStackImmediate(currentFragmentName, 0);
|
||||
break;
|
||||
} else if (i == 0) {
|
||||
fragmentManager.popBackStackImmediate(currentFragmentName, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
} else {
|
||||
lastFragmentName = currentFragmentName;
|
||||
}
|
||||
}
|
||||
return homePressResult;
|
||||
}
|
||||
|
||||
private boolean tryForeachChild(final Func1<AbstractBaseFragment, Boolean> actionOnChild) {
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
if (fragmentManager.getFragments() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean result = false;
|
||||
for (@Nullable final Fragment fragment : fragmentManager.getFragments()) {
|
||||
if (fragment != null
|
||||
&& fragment.isResumed()
|
||||
&& fragment instanceof AbstractBaseFragment) {
|
||||
result = result || actionOnChild.call((AbstractBaseFragment) fragment);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Hides device keyboard */
|
||||
public void hideSoftInput() {
|
||||
if (getCurrentFocus() != null) {
|
||||
InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
final InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
|
||||
View mainFragmentContainer = findViewById(getFragmentContainerId());
|
||||
final View mainFragmentContainer = findViewById(getFragmentContainerId());
|
||||
if (mainFragmentContainer != null) {
|
||||
mainFragmentContainer.requestFocus();
|
||||
}
|
||||
|
|
@ -231,9 +252,9 @@ public abstract class AbstractBaseActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
/* Shows device keyboard */
|
||||
public void showSoftInput(View view) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
|
||||
public void showSoftInput(@NonNull final View view) {
|
||||
final InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
|
||||
import rx.functions.Func1;
|
||||
|
|
@ -54,7 +52,7 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (view == null) {
|
||||
throw new IllegalStateException("Background fragments are deprecated - view shouldn't be null");
|
||||
|
|
@ -63,10 +61,11 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
}
|
||||
|
||||
@NonNull
|
||||
protected abstract TViewController createViewController(@NonNull View view, @Nullable Bundle savedInstanceState);
|
||||
protected abstract TViewController createViewController(@NonNull final View view, @Nullable final Bundle savedInstanceState);
|
||||
|
||||
@Override
|
||||
public void onFragmentStarted(@NonNull AbstractBaseFragment fragment) {
|
||||
public void onFragmentStarted(@NonNull final AbstractBaseFragment fragment) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
@ -79,14 +78,14 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
onStart(viewController, getBaseActivity());
|
||||
}
|
||||
|
||||
protected void onStart(@NonNull TViewController viewController, @NonNull AbstractBaseActivity baseActivity) {
|
||||
Fragment parentFragment = getParentFragment();
|
||||
if (parentFragment != null) {
|
||||
protected void onStart(@NonNull final TViewController viewController, @NonNull final AbstractBaseActivity baseActivity) {
|
||||
final Fragment parentFragment = getParentFragment();
|
||||
if (parentFragment == null) {
|
||||
baseActivity.onFragmentStarted(this);
|
||||
} else {
|
||||
if (parentFragment instanceof OnFragmentStartedListener) {
|
||||
((OnFragmentStartedListener) parentFragment).onFragmentStarted(this);
|
||||
}
|
||||
} else {
|
||||
baseActivity.onFragmentStarted(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,23 +99,19 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
onResume(viewController, getBaseActivity());
|
||||
}
|
||||
|
||||
protected void onResume(@NonNull TViewController viewController, @NonNull AbstractBaseActivity baseActivity) {
|
||||
protected void onResume(@NonNull final TViewController viewController, @NonNull final AbstractBaseActivity baseActivity) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
private boolean tryForeachChild(Func1<AbstractBaseFragment, Boolean> actionOnChild) {
|
||||
FragmentManager fragmentManager = getChildFragmentManager();
|
||||
boolean result = false;
|
||||
private boolean tryForeachChild(final Func1<AbstractBaseFragment, Boolean> actionOnChild) {
|
||||
final FragmentManager fragmentManager = getChildFragmentManager();
|
||||
|
||||
if (fragmentManager.getFragments() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Fragment fragment : fragmentManager.getFragments()) {
|
||||
boolean result = false;
|
||||
for (@Nullable final Fragment fragment : fragmentManager.getFragments()) {
|
||||
if (fragment != null
|
||||
&& fragment.isResumed()
|
||||
&& fragment instanceof AbstractBaseFragment) {
|
||||
|
|
@ -146,7 +141,8 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
super.onPause();
|
||||
}
|
||||
|
||||
protected void onPause(@NonNull TViewController viewController, @NonNull AbstractBaseActivity baseActivity) {
|
||||
protected void onPause(@NonNull final TViewController viewController, @NonNull final AbstractBaseActivity baseActivity) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
@ -159,7 +155,8 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
super.onStop();
|
||||
}
|
||||
|
||||
protected void onStop(@NonNull TViewController viewController, @NonNull AbstractBaseActivity baseActivity) {
|
||||
protected void onStop(@NonNull final TViewController viewController, @NonNull final AbstractBaseActivity baseActivity) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
@ -173,7 +170,7 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
this.viewController = null;
|
||||
}
|
||||
|
||||
protected void onDestroyView(@NonNull TViewController viewController) {
|
||||
protected void onDestroyView(@NonNull final TViewController viewController) {
|
||||
viewController.onDestroy();
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +190,7 @@ public abstract class AbstractBaseFragment<TViewController extends AbstractBaseF
|
|||
return context;
|
||||
}
|
||||
|
||||
public ViewController(@NonNull View view) {
|
||||
public ViewController(@NonNull final View view) {
|
||||
context = view.getContext();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ public class ServiceBinder<TService extends Service> extends Binder {
|
|||
@NonNull
|
||||
private final TService service;
|
||||
|
||||
public ServiceBinder(@NonNull TService service) {
|
||||
public ServiceBinder(@NonNull final TService service) {
|
||||
super();
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,15 +32,17 @@ import rx.subjects.BehaviorSubject;
|
|||
* Created by Gavriil Sitnikov on 02/11/2015.
|
||||
* TODO: fill description
|
||||
*/
|
||||
public class IsCallingObserver {
|
||||
public final class IsCallingObserver {
|
||||
|
||||
@Nullable
|
||||
private static IsCallingObserver instance;
|
||||
|
||||
@NonNull
|
||||
public static synchronized IsCallingObserver getInstance(@NonNull Context context) {
|
||||
if (instance == null) {
|
||||
instance = new IsCallingObserver(context);
|
||||
public static IsCallingObserver getInstance(@NonNull final Context context) {
|
||||
synchronized (IsCallingObserver.class) {
|
||||
if (instance == null) {
|
||||
instance = new IsCallingObserver(context);
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
|
@ -48,11 +50,11 @@ public class IsCallingObserver {
|
|||
private final BehaviorSubject<Boolean> isCallingSubject = BehaviorSubject.create();
|
||||
private final Observable<Boolean> isCallingObservable;
|
||||
|
||||
private IsCallingObserver(@NonNull Context context) {
|
||||
TelephonyManager phoneStateManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
private IsCallingObserver(@NonNull final Context context) {
|
||||
final TelephonyManager phoneStateManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
phoneStateManager.listen(new PhoneStateListener() {
|
||||
@Override
|
||||
public void onCallStateChanged(int state, String incomingNumber) {
|
||||
public void onCallStateChanged(final int state, final String incomingNumber) {
|
||||
super.onCallStateChanged(state, incomingNumber);
|
||||
isCallingSubject.onNext(isCallingState(state));
|
||||
}
|
||||
|
|
@ -64,7 +66,7 @@ public class IsCallingObserver {
|
|||
.refCount();
|
||||
}
|
||||
|
||||
private boolean isCallingState(int state) {
|
||||
private boolean isCallingState(final int state) {
|
||||
return state != TelephonyManager.CALL_STATE_IDLE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import com.facebook.common.util.UriUtil;
|
|||
public final class FrescoUtils {
|
||||
|
||||
@NonNull
|
||||
public static Uri getResourceUri(@DrawableRes int resourceId) {
|
||||
public static Uri getResourceUri(@DrawableRes final int resourceId) {
|
||||
return new Uri.Builder().scheme(UriUtil.LOCAL_RESOURCE_SCHEME).path(String.valueOf(resourceId)).build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.io.IOException;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Gavriil Sitnikov on 18/07/2014.
|
||||
|
|
@ -41,30 +42,32 @@ import java.util.List;
|
|||
*/
|
||||
public final class Typefaces {
|
||||
|
||||
private static final HashMap<String, Typeface> TYPEFACES = new HashMap<>();
|
||||
private static final Map<String, Typeface> TYPEFACES_MAP = new HashMap<>();
|
||||
|
||||
/* Returns typeface by name from assets 'fonts' folder */
|
||||
@NonNull
|
||||
public static synchronized Typeface getByName(@NonNull Context context, @NonNull String name) {
|
||||
Typeface result = TYPEFACES.get(name);
|
||||
if (result == null) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
try {
|
||||
List<String> fonts = Arrays.asList(assetManager.list("fonts"));
|
||||
if (fonts.contains(name + ".ttf")) {
|
||||
result = Typeface.createFromAsset(assetManager, "fonts/" + name + ".ttf");
|
||||
} else if (fonts.contains(name + ".otf")) {
|
||||
result = Typeface.createFromAsset(assetManager, "fonts/" + name + ".otf");
|
||||
} else {
|
||||
throw new IllegalStateException("Can't find .otf or .ttf file in folder 'fonts' with name: " + name);
|
||||
public static Typeface getByName(@NonNull final Context context, @NonNull final String name) {
|
||||
synchronized (TYPEFACES_MAP) {
|
||||
Typeface result = TYPEFACES_MAP.get(name);
|
||||
if (result == null) {
|
||||
final AssetManager assetManager = context.getAssets();
|
||||
try {
|
||||
final List<String> fonts = Arrays.asList(assetManager.list("fonts"));
|
||||
if (fonts.contains(name + ".ttf")) {
|
||||
result = Typeface.createFromAsset(assetManager, "fonts/" + name + ".ttf");
|
||||
} else if (fonts.contains(name + ".otf")) {
|
||||
result = Typeface.createFromAsset(assetManager, "fonts/" + name + ".otf");
|
||||
} else {
|
||||
throw new IllegalStateException("Can't find .otf or .ttf file in folder 'fonts' with name: " + name);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Typefaces files should be in folder named 'fonts'", e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Typefaces files should be in folder named 'fonts'");
|
||||
TYPEFACES_MAP.put(name, result);
|
||||
}
|
||||
TYPEFACES.put(name, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static <TTypefacedText extends TextView & TypefacedText> void initialize(final TTypefacedText typefacedText,
|
||||
|
|
|
|||
|
|
@ -10,11 +10,14 @@ import android.view.ViewGroup;
|
|||
* Created by Gavriil Sitnikov on 13/11/2015.
|
||||
* TODO: fill description
|
||||
*/
|
||||
public class UiUtils {
|
||||
public final class UiUtils {
|
||||
|
||||
@NonNull
|
||||
public static View inflate(@LayoutRes int layoutId, @NonNull ViewGroup parent) {
|
||||
public static View inflate(@LayoutRes final int layoutId, @NonNull final ViewGroup parent) {
|
||||
return LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
|
||||
}
|
||||
|
||||
private UiUtils() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@ import org.roboswag.components.utils.Typefaces;
|
|||
*/
|
||||
public class TypefacedEditText extends EditText implements TypefacedText {
|
||||
|
||||
public TypefacedEditText(Context context) {
|
||||
public TypefacedEditText(final Context context) {
|
||||
super(context);
|
||||
Typefaces.initialize(this, context, null);
|
||||
}
|
||||
|
||||
public TypefacedEditText(Context context, AttributeSet attrs) {
|
||||
public TypefacedEditText(final Context context, final AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
Typefaces.initialize(this, context, attrs);
|
||||
}
|
||||
|
||||
public TypefacedEditText(Context context, AttributeSet attrs, int defStyle) {
|
||||
public TypefacedEditText(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
Typefaces.initialize(this, context, attrs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@ import org.roboswag.components.utils.Typefaces;
|
|||
*/
|
||||
public class TypefacedTextView extends TextView implements TypefacedText {
|
||||
|
||||
public TypefacedTextView(Context context) {
|
||||
public TypefacedTextView(final Context context) {
|
||||
super(context);
|
||||
Typefaces.initialize(this, context, null);
|
||||
}
|
||||
|
||||
public TypefacedTextView(Context context, AttributeSet attrs) {
|
||||
public TypefacedTextView(final Context context, final AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
Typefaces.initialize(this, context, attrs);
|
||||
}
|
||||
|
||||
public TypefacedTextView(Context context, AttributeSet attrs, int defStyle) {
|
||||
public TypefacedTextView(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
Typefaces.initialize(this, context, attrs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue