예제 #1
0
 /**
  * Returns the language associated with the given deck, model and card model, for the given type.
  *
  * @param qa the part of the card for which to store the association, {@link
  *     #LANGUAGES_QA_QUESTION}, {@link #LANGUAGES_QA_ANSWER}, or {@link #LANGUAGES_QA_UNDEFINED}
  *     return the language associate with the type, as a two-characters, lowercase string, or the
  *     empty string if no association is defined
  */
 public static String getLanguage(Context context, long did, int ord, int qa) {
   openDBIfClosed(context);
   String language = "";
   Cursor cur = null;
   try {
     String query =
         "SELECT language FROM languages "
             + "WHERE did = "
             + did
             + " AND ord = "
             + ord
             + " AND qa = "
             + qa
             + " "
             + "LIMIT 1";
     cur = mMetaDb.rawQuery(query, null);
     Timber.v("getLanguage: %s", query);
     if (cur.moveToNext()) {
       language = cur.getString(0);
     }
   } catch (Exception e) {
     Timber.e(e, "Error fetching language ");
   } finally {
     if (cur != null && !cur.isClosed()) {
       cur.close();
     }
   }
   return language;
 }
  public Observable<User> createUser(String uid, String email) {
    Timber.v("Creating new user profile");
    User user = new User(email);
    user.setCreated(DateTime.now());

    return mUserManager.createUser(uid, user);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    Timber.v("onReceive: %s", intent);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (!prefs.getBoolean(SettingsFragment.PREF_TOGGLE_WITH_FLITCHIO, true)) {
      Timber.i("Toggling with Flitchio is disabled");

      return;
    }

    final int statusCode = intent.getIntExtra(EXTRA_STATUS, Status.UNKNOWN);

    switch (statusCode) {
      case Status.CONNECTED:
        Timber.i("Flitchio has connected");

        if (!ServiceUtils.isServiceRunning(context, FlitchioBindingService.class)) {
          context.startService(new Intent(context, FlitchioBindingService.class));
        }
        break;
      case Status.DISCONNECTED:
        Timber.i("Flitchio has disconnected");

        context.sendBroadcast(new Intent(FlitchioBindingService.ACTION_STOP_SERVICE));
        break;
      default:
        Timber.wtf("Invalid intent: " + intent);
    }
  }
예제 #4
0
 private void autoLaunchMain() {
   if (launchMainPending != null) {
     uiHandler.removeCallbacks(launchMainPending);
     long passingTime = System.currentTimeMillis() - entryTime;
     long expTime = SPLASH_TIME - passingTime;
     Timber.v("expTime: %s", expTime);
     uiHandler.postDelayed(launchMainPending, expTime);
   }
 }
예제 #5
0
  /**
   * Unzip the .zip file
   *
   * @param path zip file path
   * @param destinationFolder target folder
   * @return success / fail
   */
  public static boolean unzip(String path, String destinationFolder) {
    try {
      FileInputStream is = new FileInputStream(path);
      ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
      ZipEntry ze = null;
      byte[] buffer = new byte[1024];
      int count;
      while ((ze = zis.getNextEntry()) != null) {
        Timber.v("Unzipping " + ze.getName());

        /// code to search is given string exists or not in a Sentence
        String haystack = ze.getName();
        String needle1 = "_MACOSX";
        int index1 = haystack.indexOf(needle1);
        if (index1 != -1) {
          Timber.v("The string contains the substring " + needle1);
          continue;
        }

        if (ze.isDirectory()) {
          _dirChecker(destinationFolder, ze.getName());
        } else {
          FileOutputStream fout = new FileOutputStream(destinationFolder + "/" + ze.getName());
          // replace for loop with:

          while ((count = zis.read(buffer)) != -1) {
            fout.write(buffer, 0, count);
          }

          fout.close();
          zis.closeEntry();
        }
      }
      zis.close();
    } catch (Exception e) {
      e.printStackTrace();

      Timber.e("unzip", e);
      return false;
    }

    return true;
  }
  /** @see BroadcastReceiver#onReceive(Context, Intent) */
  @Override
  public void onReceive(Context context, Intent intent) {
    boolean connected = isConnected(context);
    Timber.v("Connected: " + connected);

    // Loop over listeners
    for (ConnectivityListener listener : listeners) {
      listener.onNetworkStateChanged(connected);
    }
  }
    /**
     * called when the presenter and view are ready. getView() will not be null
     *
     * @param savedInstanceState This bundle is only passed on rotation not passed on navigating
     *     back
     */
    @Override
    protected void onLoad(Bundle savedInstanceState) {
      Timber.v("onLoad");
      ButterKnife.bind(this, getView());
      userRepo
          .getMe()
          .subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe(
              new Action1<User>() {
                @Override
                public void call(User user) {
                  String firstName = user.getData().attributes().getFirstName();
                  String lastName = user.getData().attributes().getLastName();
                  //                    String email = user.getData().attributes().getEmail();
                  firstNameEditText.setText(firstName);
                  lastNameEditText.setText(lastName);
                  //                    emailEditText.setText(email);
                  photoEditView.load(user.getData().attributes(), userPhoto);
                }
              },
              new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                  Timber.e(throwable, "Unable to retrieve profile");
                  Crashlytics.logException(throwable);
                  ProfileEditView view = getView();
                  if (view != null) {
                    ToastService.get(view)
                        .bern(view.getContext().getString(R.string.error_retrieving_profile));
                  } else {
                    Timber.w("getView() null, can not notify user of failed profile retrieval.");
                  }
                }
              });

      photoEditView.setPhotoChangeListener(
          new PhotoEditView.PhotoChangeListener() {
            @Override
            public void onPhotoChanged(Bitmap bitmap, String base64PhotoData) {
              userPhoto = bitmap;
              Presenter.this.base64PhotoData = base64PhotoData;
            }
          });

      getView()
          .postDelayed(
              new Runnable() {
                @Override
                public void run() {
                  photoEditView.toggleAvatarWidget(true);
                }
              },
              300);
    }
예제 #8
0
 /**
  * Associates a language to a deck, model, and card model for a given type.
  *
  * @param qa the part of the card for which to store the association, {@link
  *     #LANGUAGES_QA_QUESTION}, {@link #LANGUAGES_QA_ANSWER}, or {@link #LANGUAGES_QA_UNDEFINED}
  * @param language the language to associate, as a two-characters, lowercase string
  */
 public static void storeLanguage(Context context, long did, int ord, int qa, String language) {
   openDBIfClosed(context);
   try {
     mMetaDb.execSQL(
         "INSERT INTO languages (did, ord, qa, language) " + " VALUES (?, ?, ?, ?);",
         new Object[] {did, ord, qa, language});
     Timber.v("Store language for deck %d", did);
   } catch (Exception e) {
     Timber.e(e, "Error storing language in MetaDB ");
   }
 }
  @Override
  public void onTimeChanged(Calendar time) {
    Timber.v("onTimeChanged()");

    int hr = time.get(Calendar.HOUR_OF_DAY) % 12;
    int min = time.get(Calendar.MINUTE);
    int sec = time.get(Calendar.SECOND);

    rotateHands(hr, min, sec);
    invalidate();
  }
예제 #10
0
 /** Open the meta-db */
 private static void openDB(Context context) {
   try {
     mMetaDb = context.openOrCreateDatabase(DATABASE_NAME, 0, null);
     if (mMetaDb.needUpgrade(DATABASE_VERSION)) {
       mMetaDb = upgradeDB(mMetaDb, DATABASE_VERSION);
     }
     Timber.v("Opening MetaDB");
   } catch (Exception e) {
     Timber.e(e, "Error opening MetaDB ");
   }
 }
  public Observable<Token> register(String email, String pass) {

    Timber.v("Creating new account " + email);

    return mUserManager
        .register(email, pass)
        .flatMap(
            token -> {
              mPreferenceHelper.storeToken(token.getAccessToken());
              Intent intent = mAuthenticationManager.generateAuthIntent(token, email, pass);
              mAuthenticationManager.completeLogin(intent);
              return Observable.just(token);
            });
  }
  public Observable<Token> authenticate(final String email, final String pass) {

    Timber.v("Authenticating " + email);

    return mUserManager
        .login(email, pass)
        .flatMap(
            token -> {
              mPreferenceHelper.storeToken(token.getAccessToken());
              Intent intent = mAuthenticationManager.generateAuthIntent(token, email, pass);
              mAuthenticationManager.completeLogin(intent);
              return Observable.just(token);
            });
  }
 @OnClick(R.id.submit_profile)
 void onSaveProfileClicked(final View v) {
   Timber.v("Attempting to save profile");
   String firstName = firstNameEditText.getText().toString();
   String lastName = lastNameEditText.getText().toString();
   //            String email = emailEditText.getText().toString();
   UserSpec spec = new UserSpec();
   final User user = new User();
   user.getData().attributes().firstName(firstName);
   user.getData().attributes().lastName(lastName);
   user.getData().attributes().base64PhotoData(base64PhotoData);
   //            user.getData().attributes().email(email);
   spec.create(new CreateUserRequest());
   spec.update(user);
   userRepo
       .update(spec)
       .subscribeOn(Schedulers.io())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           new Action1<User>() {
             @Override
             public void call(User user) {
               Timber.v("Profile saved");
               ProfileEditView view = getView();
               if (view != null) {
                 ToastService.get(view)
                     .bern(view.getContext().getString(R.string.profile_saved));
                 FTBApplication.getEventBus().post(new LoginEvent(LoginEvent.LOGIN, user));
                 Flow.get(view.getContext()).set(new HomeScreen());
               } else {
                 Timber.w("getView() null, cannot notify user of successful profile save");
               }
             }
           },
           new Action1<Throwable>() {
             @Override
             public void call(Throwable throwable) {
               Timber.e(throwable, "Unable to save profile");
               Crashlytics.logException(throwable);
               ProfileEditView view = getView();
               if (view != null) {
                 ToastService.get(view)
                     .bern(view.getContext().getString(R.string.error_saving_profile));
               } else {
                 Timber.w("getView() null, cannot notify user of failed profile save");
               }
             }
           });
 }
예제 #14
0
 public static ServiceLookup getServiceLookup(List<ServiceEvent> services) {
   ArrayList<ServiceLookup> lookups = new ArrayList<>();
   for (ServiceEvent service : services) {
     ServiceLookup lookup = ServiceLookup.get(service.getType());
     if (lookup != null && lookup.getPriority() > 0) {
       lookups.add(lookup);
     }
   }
   Timber.v("lookups for " + services + " are " + lookups);
   if (lookups.isEmpty()) {
     return null;
   }
   Collections.sort(lookups);
   return lookups.get(lookups.size() - 1);
 }
예제 #15
0
 @Override
 public Void visitString(Property<String> property, AbstractModel data) {
   try {
     String value = data.getValue(property);
     if (value == null) {
       return null;
     }
     xml.attribute(null, property.name, value);
   } catch (UnsupportedOperationException e) {
     // didn't read this value, do nothing
     Timber.v(e, e.getMessage());
   } catch (IllegalArgumentException | IOException | IllegalStateException e) {
     throw new RuntimeException(e);
   }
   return null;
 }
예제 #16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Timber.v("onCreate");

    Intent intent = new Intent(this, DiscoveryService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    setContentView(R.layout.flame_activity);
    if (savedInstanceState == null) {
      getSupportFragmentManager()
          .beginTransaction()
          .add(R.id.main, new HostListFragment())
          .commit();
    }
  }
  @Override
  public void onValidationFailed(List<ValidationError> errors) {
    for (ValidationError error : errors) {
      View view = error.getView();
      String message = error.getCollatedErrorMessage(getContext());

      // Display error messages ;)
      if (view instanceof EditText) {
        EditText editText = ((EditText) view);
        editText.setError(message);
        editText.requestFocus();
        break;
      } else {
        Timber.v("Unknown validation error:");
      }
    }
  }
예제 #18
0
 public static void buildAvailableLanguages() {
   availableTtsLocales.clear();
   Locale[] systemLocales = Locale.getAvailableLocales();
   for (Locale loc : systemLocales) {
     try {
       int retCode = mTts.isLanguageAvailable(loc);
       if (retCode >= TextToSpeech.LANG_COUNTRY_AVAILABLE) {
         availableTtsLocales.add(loc);
       } else {
         Timber.v(
             "ReadText.buildAvailableLanguages() :: %s  not available (error code %d)",
             loc.getDisplayName(), retCode);
       }
     } catch (IllegalArgumentException e) {
       Timber.e("Error checking if language " + loc.getDisplayName() + " available");
     }
   }
 }
예제 #19
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    String updateIdString = intent.getStringExtra("updateId");
    Timber.v("EditActivity.onCreate, updateid: " + updateIdString);
    /*
    				Bundle bundle = intent.getExtras();
    				for (String key : bundle.keySet()) {
    				    Object value = bundle.get(key);
    				    Log.d("ZetaRemote", String.format("%s %s (%s)", key,
    				        value.toString(), value.getClass().getName()));
    				}
    */
    updateId = Long.valueOf(updateIdString).longValue();

    setTitle("Edit Record");

    setContentView(R.layout.addedit_activity);

    nameEditText = (EditText) findViewById(R.id.nameEditText);
    serverEditText = (EditText) findViewById(R.id.serverEditText);
    urlEditText = (EditText) findViewById(R.id.urlEditText);

    addButton = (Button) findViewById(R.id.addButton);

    datasource = new DataSource(this);
    datasource.open();

    Command currentCommand = datasource.getCommandById(updateId);

    nameEditText.setText(currentCommand.getName());
    serverEditText.setText(currentCommand.getServer());
    urlEditText.setText(currentCommand.getUrl());

    addButton.setText("Update");
    addButton.setOnClickListener(this);
  }
  public Observable<Boolean> forgotPassword(final String email) {

    Timber.v("Sending Forgot Password Link");

    return mUserManager.forgotPassword(email);
  }
예제 #21
0
 public void onServiceDisconnected(ComponentName className) {
   Timber.v("service disconnected");
   mDiscoveryService = null;
 }
예제 #22
0
 public void onServiceConnected(ComponentName className, IBinder binder) {
   DiscoveryService.MyBinder b = (DiscoveryService.MyBinder) binder;
   mDiscoveryService = b.getService();
   Timber.v("service connected");
 }
 public Observable<User> getMe() {
   Timber.v("Retrieving User Profile");
   return mUserManager.getMe();
 }