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
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| staticMethod(); | |
| } | |
| public static void staticMethod() { | |
| Context context = ApplicationBase.getContext(); | |
| } |
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
| package pk.minitodo.base; | |
| /** | |
| * Created by PK on 11.10.2015. | |
| */ | |
| import android.content.Context; | |
| import android.content.res.Resources; | |
| import android.support.v7.widget.CardView; | |
| import android.support.v7.widget.RecyclerView; | |
| import android.view.LayoutInflater; |
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
| // check if Realm db exist | |
| RealmConfiguration config = getConfig(); | |
| if (new File(config.getPath()).exists()) { | |
| // exists | |
| } else { | |
| // don't exists | |
| } | |
| // check if Realm is closed | |
| if(realm.isClosed()) { |
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 BaseActivity implements FragmentManager.OnBackStackChangedListener { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| ButterKnife.bind(this); | |
| getSupportFragmentManager().addOnBackStackChangedListener(this); |
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 static boolean isNetworkAvailable() { | |
| // ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); | |
| ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |
| NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); | |
| return activeNetworkInfo != null && activeNetworkInfo.isConnected(); | |
| } |
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
| DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); | |
| float dpHeight = displayMetrics.heightPixels / displayMetrics.density; | |
| float dpWidth = displayMetrics.widthPixels / displayMetrics.density; | |
| // variant, API 17+ | |
| Display display = context.getWindowManager().getDefaultDisplay(); | |
| DisplayMetrics realMetrics = new DisplayMetrics(); | |
| display.getRealMetrics(realMetrics); | |
| float realWidth = realMetrics.widthPixels / realMetrics.density; | |
| float realHeight = realMetrics.heightPixels / realMetrics.density; |
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
| // packageName = "com.example.yourapp" | |
| public Boolean isAppRunning(String packageName) { | |
| ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); // this = context | |
| List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses(); | |
| for(int i = 0; i < procInfos.size(); i++) { | |
| if(procInfos.get(i).processName.equals(packageName)) { | |
| // Toast.makeText(getApplicationContext(), "App " + packageName + " is running", Toast.LENGTH_LONG).show(); | |
| return 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
| try { | |
| SSLContext.getInstance("TLSv1.2"); | |
| ProviderInstaller.installIfNeeded(this); | |
| } catch (GooglePlayServicesRepairableException e) { | |
| // Thrown when Google Play Services is not installed, up-to-date, or enabled | |
| // Show dialog to allow users to install, update, or otherwise enable Google Play services. | |
| GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), (Activity) context, 0); | |
| } catch (GooglePlayServicesNotAvailableException e) { | |
| Log.e("SecurityException", "Google Play Services not available."); | |
| } catch (Exception e) { |
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
| content.postDelayed(new Runnable() { | |
| @Override | |
| public void run() { | |
| if ((Build.VERSION.SDK_INT >= 17 && LWQSettingsActivity.this.isDestroyed()) || LWQSettingsActivity.this.isFinishing()) { | |
| return; | |
| } | |
| requestNewInterstitial(); | |
| } | |
| }, 1000); |
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
| // https://github.com/ReactiveX/RxJava/issues/1323#issuecomment-45149897 | |
| // thank you, akarnokd ! | |
| public class ThrottleNotFirst { | |
| public static void main(String[] args) throws Exception { | |
| for (int firstWait = 0; firstWait < 2; firstWait++) { | |
| PublishSubject<String> source = PublishSubject.create(); | |
| PublishSubject<Observable<String>> immediates = PublishSubject.create(); |
OlderNewer