com.orhanobut.hawk.Hawk Java Examples

The following examples show how to use com.orhanobut.hawk.Hawk. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppDelegate.java    From AndroidSchool with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    sContext = this;

    Hawk.init(this)
            .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
            .setStorage(HawkBuilder.newSharedPrefStorage(this))
            .setLogLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE)
            .build();

    RealmConfiguration configuration = new RealmConfiguration.Builder(this)
            .rxFactory(new RealmObservableFactory())
            .build();
    Realm.setDefaultConfiguration(configuration);

    ApiFactory.recreate();
    RepositoryProvider.init();
}
 
Example #2
Source File: AppDelegate.java    From AndroidSchool with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    sContext = this;

    Hawk.init(this)
            .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
            .setStorage(HawkBuilder.newSharedPrefStorage(this))
            .setLogLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE)
            .build();

    RealmConfiguration configuration = new RealmConfiguration.Builder(this)
            .rxFactory(new RealmObservableFactory())
            .build();
    Realm.setDefaultConfiguration(configuration);

    ApiFactory.recreate();
    RepositoryProvider.init();
}
 
Example #3
Source File: WordTaskActivity.java    From Duolingo-Clone with MIT License 6 votes vote down vote up
@Override
public void onBackPressed() {

    new MaterialDialog.Builder(this)
            .title("Are you sure about that?")
            .content("All progress in this lesson will be lost.")
            .positiveText("QUIT")
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

                    progressBarValue = 0;

                    Hawk.put("progressBarValue", progressBarValue);

                    finish();
                }
            })
            .negativeText("CANCEL")
            .show();
}
 
Example #4
Source File: AppDelegate.java    From AndroidSchool with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Hawk.init(this)
            .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
            .setStorage(HawkBuilder.newSharedPrefStorage(this))
            .setLogLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE)
            .build();

    RealmConfiguration configuration = new RealmConfiguration.Builder(this)
            .rxFactory(new RealmObservableFactory())
            .build();
    Realm.setDefaultConfiguration(configuration);

    sAppComponent = DaggerAppComponent.builder()
            .dataModule(new DataModule())
            .build();
}
 
Example #5
Source File: Benchmark.java    From Iron with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadWrite500Contacts() throws Exception {
    final List<Person> contacts = TestDataGenerator.genPersonList(500);
    Iron.init(getTargetContext());
    //Iron.setCache(Cache.MEMORY);
    Iron.chest("keys").destroy();
    Iron.chest().destroy();
    //Iron.setEncryptionExtension(new IronEncryption());
    long ironTime = runTest(new IronReadWriteContactsTest(), contacts, REPEAT_COUNT);

    assertFalse(Iron.chest().<List<Person>>read("contacts1").isEmpty());

    Hawk.init(getTargetContext());
    Hawk.clear();
    long hawkTime = runTest(new HawkReadWriteContactsTest(), contacts, REPEAT_COUNT);

    final List<PersonArg> contactsArg = TestDataGenerator.genPersonArgList(500);
    Iron.init(getTargetContext());
    Iron.chest().destroy();
    long ironArg = runTest(new IronReadWriteContactsArgTest(), contactsArg, REPEAT_COUNT);

    printResults("Read/write 500 contacts", ironTime, hawkTime, ironArg);
}
 
Example #6
Source File: LessonCompletedActivity.java    From Duolingo-Clone with MIT License 6 votes vote down vote up
private void initData() {

        Hawk.init(this).build();

        repository = Injection.provideRepository();

        dailyGoal = Hawk.get("dailyGoal");

        continueButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(LessonCompletedActivity.this, LessonListActivity.class);
                startActivity(intent);
            }
        });

        setupProgressBar();
        setupWeekBar();
    }
 
Example #7
Source File: FirebaseDatabaseHelper.java    From Duolingo-Clone with MIT License 6 votes vote down vote up
@Override
public void setLessonComplete(String lesson, boolean completeness) {

    if (Injection.providesAuthHelper().getAuthInstance().getCurrentUser() != null) {

        String userID = Injection.providesAuthHelper().getAuthInstance().getCurrentUser().getUid();

        String language = Hawk.get("currentLanguage");

        myRef.child("user")
                .child(userID)
                .child("course")
                .child(language)
                .child("lessons")
                .child(lesson)
                .setValue(completeness)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {

                        Log.d(TAG, "User has completed this lesson");
                    }
                });
    }
}
 
Example #8
Source File: MainActivity.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
@CallSuper
@Override
public void updateUiElements() {
    super.updateUiElements();
    //TODO: MUST BE FIXED
    toolbar.setPopupTheme(getPopupToolbarStyle());
    toolbar.setBackgroundColor(getPrimaryColor());

    /**** SWIPE TO REFRESH ****/

    setStatusBarColor();
    setNavBarColor();

    fab.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
    fab.setVisibility(Hawk.get(getString(R.string.preference_show_fab), false) ? View.VISIBLE : View.GONE);
    mainLayout.setBackgroundColor(getBackgroundColor());

    setScrollViewColor(navigationDrawerView);
    setAllScrollbarsColor();

    navigationDrawerView.setTheme(getPrimaryColor(), getBackgroundColor(), getTextColor(), getIconColor());

    // TODO Calvin: This performs a NO-OP. Find out what this is used for
    setRecentApp(getString(R.string.app_name));
}
 
Example #9
Source File: CPHelper.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
private static Observable<Album> getHiddenAlbums(Context context, ArrayList<String> excludedAlbums) {

        boolean includeVideo = Prefs.showVideos();
        return Observable.create(subscriber -> {
            try {

                ArrayList<String> lastHidden = Hawk.get("h", new ArrayList<>());
                for (String s : lastHidden)
                    checkAndAddFolder(new File(s), subscriber, includeVideo);

                lastHidden.addAll(excludedAlbums);

                for (File storage : StorageHelper.getStorageRoots(context))
                    fetchRecursivelyHiddenFolder(storage, subscriber, lastHidden, includeVideo);
                subscriber.onComplete();
            } catch (Exception err) {
                subscriber.onError(err);
            }
        });
    }
 
Example #10
Source File: AppDelegate.java    From AndroidSchool with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    sContext = this;

    Hawk.init(this)
            .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
            .setStorage(HawkBuilder.newSharedPrefStorage(this))
            .setLogLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE)
            .build();

    RealmConfiguration configuration = new RealmConfiguration.Builder(this)
            .rxFactory(new RealmObservableFactory())
            .build();
    Realm.setDefaultConfiguration(configuration);

    ApiFactory.recreate();
    RepositoryProvider.init();
}
 
Example #11
Source File: SelectAlbumBuilder.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
private void toggleExplorerMode(boolean enabled) {
    folders = new ArrayList<>();
    exploreMode = enabled;

    if (exploreMode) {
        displayContentFolder(Environment.getExternalStorageDirectory());
        imgExploreMode.setIcon(theme.getIcon(CommunityMaterial.Icon.cmd_folder));
        exploreModePanel.setVisibility(View.VISIBLE);
    } else {
        currentFolderPath.setText(R.string.local_folder);

        for (String al : Hawk.get("albums", new ArrayList<String>()))
            folders.add(new File(al));
        /*for (Album album : ((App) getActivity().getApplicationContext()).getAlbums().albums) {
            folders.add(new File(album.getPath()));
        }*/
        imgExploreMode.setIcon(theme.getIcon(CommunityMaterial.Icon.cmd_compass_outline));
        exploreModePanel.setVisibility(View.GONE);
    }
    adapter.notifyDataSetChanged();
}
 
Example #12
Source File: ThemedActivity.java    From Liz with GNU General Public License v3.0 5 votes vote down vote up
public void updateTheme(){
    themeHelper.updateTheme();
    coloredNavBar = Hawk.get(getString(R.string.preference_colored_nav_bar), false);
    obscuredStatusBar = Hawk.get(getString(R.string.preference_translucent_status_bar), true);
    applyThemeSingleImgAct = Hawk.get("apply_theme_img_act", true);
    customIconColor = Hawk.get(getString(R.string.preference_custom_icon_color), false);
}
 
Example #13
Source File: StorageHelper.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the stored tree URIs.
 *
 * @param context context
 * @return The tree URIs.
 */
private static Uri getTreeUri(Context context) {
    String uriString = Hawk.get(context.getString(R.string.preference_internal_uri_extsdcard_photos), null);

    if (uriString == null) return null;
    return Uri.parse(uriString);
}
 
Example #14
Source File: BillingCache.java    From RxIAPv3 with Apache License 2.0 5 votes vote down vote up
public List<PurchaseDataModel> getProducts() {
    List<PurchaseDataModel> toReturn = new ArrayList<>();
    for(String id : productIds){
        toReturn.add((PurchaseDataModel) Hawk.get(id));
    }
    return toReturn;
}
 
Example #15
Source File: FirebaseDatabaseHelper.java    From Duolingo-Clone with MIT License 5 votes vote down vote up
@Override
public void setLessonCompleteDate(String lesson) {

    if (Injection.providesAuthHelper().getAuthInstance().getCurrentUser() != null) {

        String userID = Injection.providesAuthHelper().getAuthInstance().getCurrentUser().getUid();

        String language = Hawk.get("currentLanguage");

        Date date = Calendar.getInstance().getTime();

        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/YYYY", Locale.US);
        String completedDate = dateFormat.format(date);

        myRef.child("user")
                .child(userID)
                .child("course")
                .child(language)
                .child("lessons")
                .child(lesson.toLowerCase())
                .child("completed_date")
                .setValue(completedDate)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {

                        Log.d(TAG, "User's data has been updated");
                    }
                });
    }
}
 
Example #16
Source File: FirebaseDatabaseHelper.java    From Duolingo-Clone with MIT License 5 votes vote down vote up
@Override
public void getDailyGoal(){

    if (Injection.providesAuthHelper().getAuthInstance().getCurrentUser() != null) {

        String userID = Injection.providesAuthHelper().getAuthInstance().getCurrentUser().getUid();

        myRef.child("user")
                .child(userID)
                .child("daily_goal")
                .addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {

                        int dailyGoal;

                        if (dataSnapshot.getValue() != null) {

                            dailyGoal = dataSnapshot.getValue(Integer.class);

                        } else {

                            dailyGoal = 20;
                        }

                        Hawk.put("dailyGoal", dailyGoal);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });
    }
}
 
Example #17
Source File: FirebaseDatabaseHelper.java    From Duolingo-Clone with MIT License 5 votes vote down vote up
@Override
public void getLessonCompleted() {

    if (Injection.providesAuthHelper().getAuthInstance().getCurrentUser() != null) {

        String userID = Injection.providesAuthHelper().getAuthInstance().getCurrentUser().getUid();

        String language = Hawk.get("currentLanguage");

        myRef.child("user")
                .child(userID)
                .child("course")
                .child(language)
                .child("lessons")
                .addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {

                        for (DataSnapshot ds : dataSnapshot.getChildren()) {

                            Hawk.put(ds.getKey().toString(), ds.getValue());
                        }
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });
    }
}
 
Example #18
Source File: ThemeHelper.java    From Android-AudioRecorder-App with Apache License 2.0 5 votes vote down vote up
public void updateTheme() {
  this.primaryColor = Hawk.get(context.getString(R.string.preference_primary_color),
      getColor(R.color.av_color5));
  this.accentColor = Hawk.get(context.getString(R.string.preference_accent_color),
      getColor(R.color.av_color5));
  this.layerColor = Hawk.get(context.getString(R.string.preference_layer_colors),
      ColorPalette.getColors(context, ContextCompat.getColor(context, R.color.av_color5)));
  baseTheme = Theme.fromValue(Hawk.get(context.getString(R.string.preference_base_theme), 1));
}
 
Example #19
Source File: AudioRecordService.java    From Android-AudioRecorder-App with Apache License 2.0 5 votes vote down vote up
private void startRecording() {
  boolean prefHighQuality =
      Hawk.get(getApplicationContext().getString(R.string.pref_high_quality_key), false);
  audioRecorder.startRecord(
      prefHighQuality ? Constants.RECORDER_SAMPLE_RATE_HIGH : Constants.RECORDER_SAMPLE_RATE_LOW);
  handler.startDbmThread();
  audioRecorder.subscribeTimer(this::updateNotification);
}
 
Example #20
Source File: Benchmark.java    From Paper with Apache License 2.0 5 votes vote down vote up
@Test
public void testRead500Contacts() throws Exception {
    final List<Person> contacts = TestDataGenerator.genPersonList(500);
    Paper.init(getTargetContext());
    Paper.book().destroy();
    runTest(new PaperWriteContactsTest(), contacts, REPEAT_COUNT); //Prepare
    long paperTime = runTest(new PaperReadContactsTest(), contacts, REPEAT_COUNT);

    Hawk.init(getTargetContext());
    Hawk.clear();
    runTest(new HawkWriteContactsTest(), contacts, REPEAT_COUNT); //Prepare
    long hawkTime = runTest(new HawkReadContactsTest(), contacts, REPEAT_COUNT);

    printResults("Read 500 contacts", paperTime, hawkTime);
}
 
Example #21
Source File: MainActivity.java    From hawk with Apache License 2.0 5 votes vote down vote up
private void timeHawkDelete() {
  long startTime = System.currentTimeMillis();

  Hawk.delete("key");

  long endTime = System.currentTimeMillis();
  System.out.println("Hawk.count: " + (endTime - startTime) + "ms");
}
 
Example #22
Source File: MainActivity.java    From hawk with Apache License 2.0 5 votes vote down vote up
private void timeHawkContains() {
  long startTime = System.currentTimeMillis();

  Hawk.contains("key");

  long endTime = System.currentTimeMillis();
  System.out.println("Hawk.count: " + (endTime - startTime) + "ms");
}
 
Example #23
Source File: CommonApplication.java    From Lay-s with MIT License 5 votes vote down vote up
private void initStorage() {
    Hawk
            .init(this)
            .setEncryptionMethod(HawkBuilder.EncryptionMethod.NO_ENCRYPTION)
            .setStorage(HawkBuilder.newSharedPrefStorage(this))
            .setLogLevel(appDebug ? LogLevel.FULL : LogLevel.NONE)
            .build();
}
 
Example #24
Source File: ThemeHelper.java    From Liz with GNU General Public License v3.0 5 votes vote down vote up
public void updateTheme(){
	this.primaryColor = Hawk.get(context.getString(R.string.preference_primary_color),
			getColor(R.color.md_indigo_500));
	this.accentColor = Hawk.get(context.getString(R.string.preference_accent_color),
			getColor(R.color.md_light_blue_500));
	baseTheme = Theme.fromValue(Hawk.get(context.getString(R.string.preference_base_theme), 1));
}
 
Example #25
Source File: SecurityApp.java    From android-security with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Hawk.init(this).build();
    SQLiteDatabase.loadLibs(this);

    int times = Hawk.get(PREF_TIMES, 0) + 1;
    Log.d(TAG, "Psss! Let me tell a secret: you opened this app " + times + " times.");
    Hawk.put(PREF_TIMES, times);
}
 
Example #26
Source File: AudioRecorderApp.java    From Android-AudioRecorder-App with Apache License 2.0 5 votes vote down vote up
@Override public void onCreate() {
  super.onCreate();
  if (LeakCanary.isInAnalyzerProcess(this)) {
    return;
  }
  LeakCanary.install(this);
  Hawk.init(getApplicationContext()).build();
  DaggerApplicationComponent.builder().application(this).build().inject(this);
}
 
Example #27
Source File: ThemeHelper.java    From Liz with GNU General Public License v3.0 4 votes vote down vote up
public static int getAccentColor(Context context) {
	return Hawk.get(context.getString(R.string.preference_accent_color),
			ContextCompat.getColor(context, R.color.md_light_blue_500));
}
 
Example #28
Source File: ThemeHelper.java    From Liz with GNU General Public License v3.0 4 votes vote down vote up
public void setBaseTheme(Theme baseTheme) {
	this.baseTheme = baseTheme;
	Hawk.put(context.getString(R.string.preference_base_theme), getBaseTheme().getValue());
}
 
Example #29
Source File: Benchmark.java    From Iron with Apache License 2.0 4 votes vote down vote up
@Override
public void run(int i, List<Person> extra) {
    String key = "contacts" + i;
    Hawk.<List<Person>>get(key);
}
 
Example #30
Source File: PreferenceUtils.java    From AndroidSchool with Apache License 2.0 4 votes vote down vote up
@NonNull
public static String getToken() {
    return Hawk.get(TOKEN_KEY, "");
}