// Path: app/src/main/java/com/reddyetwo/hashmypass/app/TwikApplication.java
// public class TwikApplication extends Application {
// 
//     public static final String LOG_TAG = "TWIK";
//     private char[] mCachedMasterKey;
//     private boolean mTutorialDismissed = false;
//     private static TwikApplication mInstance;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mInstance = this;
//         LeakCanary.install(this);
//     }
// 
//     /**
//      * Return the Singleton instance of the {@link android.app.Application}
//      * @return the Singleton instance of the {@link android.app.Application}
//      */
//     public static TwikApplication getInstance() {
//         return mInstance;
//     }
// 
//     /**
//      * Get the tutorial dismissed flag.
//      *
//      * @return true if the tutorial has been dismissed, false otherwise.
//      */
//     public boolean getTutorialDismissed() {
//         return mTutorialDismissed;
//     }
// 
//     /**
//      * Set the tutorial dismissed flag. Once the tutorial has been dismissed, it is never shown again.
//      *
//      * @param tutorialDismissed the flag value
//      */
//     public void setTutorialDismissed(boolean tutorialDismissed) {
//         mTutorialDismissed = tutorialDismissed;
//     }
// 
//     /**
//      * Get the cached master key
//      *
//      * @return the cached master key
//      */
//     public char[] getCachedMasterKey() {
//         if (mCachedMasterKey == null || Preferences.getRememberMasterKeyMins(this) == 0) {
//             mCachedMasterKey = new char[]{};
//         }
//         return mCachedMasterKey;
//     }
// 
//     /**
//      * Wipe the cached master key
//      */
//     public void wipeCachedMasterKey() {
//         if (mCachedMasterKey != null) {
//             Arrays.fill(mCachedMasterKey, ' ');
//             mCachedMasterKey = null;
//         }
//     }
// 
//     /**
//      * Save master key to cache if enabled by user
//      *
//      * @param masterKey the master key
//      */
//     public void cacheMasterKey(char[] masterKey) {
//         if (Preferences.getRememberMasterKeyMins(this) > 0) {
//             mCachedMasterKey = Arrays.copyOf(masterKey, masterKey.length);
//         }
//     }
// }


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import com.reddyetwo.hashmypass.app.TwikApplication;
import java.io.FileInputStream;
/*
 * Copyright 2014 Red Dye No. 2
 *
 * This file is part of Twik.
 *
 * Twik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Twik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Twik.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.reddyetwo.hashmypass.app.data;




/**
 * Class to get/add/delete/update {@link com.reddyetwo.hashmypass.app.data.Favicon} from storage
 */
public class FaviconSettings {

    private static final String FILE_NAME = "favicon-%d.png";
    private static final int FAVICON_QUALITY = 100;

    private FaviconSettings() {

    }

    /**
     * Get the favicon of a site
     *
     * @param context the {@link android.content.Context} instance
     * @param site    the site
     * @return the {@link com.reddyetwo.hashmypass.app.data.Favicon} instance
     */
    public static Favicon getFavicon(Context context, String site) {
        DataOpenHelper helper = new DataOpenHelper(context);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor =
                db.query(DataOpenHelper.FAVICONS_TABLE_NAME, new String[]{DataOpenHelper.COLUMN_ID},
                        DataOpenHelper.COLUMN_FAVICONS_SITE + "= ?", new String[]{site}, null, null,
                        null);

        Favicon favicon = null;
        if (cursor.moveToFirst()) {
            long id = cursor.getLong(cursor.getColumnIndex(DataOpenHelper.COLUMN_ID));
            try {
                String filename = String.format(FILE_NAME, id);
                FileInputStream fis = context.openFileInput(filename);
                Bitmap icon = BitmapFactory.decodeStream(fis);
                favicon = new Favicon(id, site, icon);
            } catch (FileNotFoundException e) {
                // Favicon not found in storage
// Path: app/src/main/java/com/reddyetwo/hashmypass/app/TwikApplication.java
// public class TwikApplication extends Application {
// 
//     public static final String LOG_TAG = "TWIK";
//     private char[] mCachedMasterKey;
//     private boolean mTutorialDismissed = false;
//     private static TwikApplication mInstance;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mInstance = this;
//         LeakCanary.install(this);
//     }
// 
//     /**
//      * Return the Singleton instance of the {@link android.app.Application}
//      * @return the Singleton instance of the {@link android.app.Application}
//      */
//     public static TwikApplication getInstance() {
//         return mInstance;
//     }
// 
//     /**
//      * Get the tutorial dismissed flag.
//      *
//      * @return true if the tutorial has been dismissed, false otherwise.
//      */
//     public boolean getTutorialDismissed() {
//         return mTutorialDismissed;
//     }
// 
//     /**
//      * Set the tutorial dismissed flag. Once the tutorial has been dismissed, it is never shown again.
//      *
//      * @param tutorialDismissed the flag value
//      */
//     public void setTutorialDismissed(boolean tutorialDismissed) {
//         mTutorialDismissed = tutorialDismissed;
//     }
// 
//     /**
//      * Get the cached master key
//      *
//      * @return the cached master key
//      */
//     public char[] getCachedMasterKey() {
//         if (mCachedMasterKey == null || Preferences.getRememberMasterKeyMins(this) == 0) {
//             mCachedMasterKey = new char[]{};
//         }
//         return mCachedMasterKey;
//     }
// 
//     /**
//      * Wipe the cached master key
//      */
//     public void wipeCachedMasterKey() {
//         if (mCachedMasterKey != null) {
//             Arrays.fill(mCachedMasterKey, ' ');
//             mCachedMasterKey = null;
//         }
//     }
// 
//     /**
//      * Save master key to cache if enabled by user
//      *
//      * @param masterKey the master key
//      */
//     public void cacheMasterKey(char[] masterKey) {
//         if (Preferences.getRememberMasterKeyMins(this) > 0) {
//             mCachedMasterKey = Arrays.copyOf(masterKey, masterKey.length);
//         }
//     }
// }


// Path: app/src/main/java/com/reddyetwo/hashmypass/app/data/FaviconSettings.java
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import com.reddyetwo.hashmypass.app.TwikApplication;
import java.io.FileInputStream;

/*
 * Copyright 2014 Red Dye No. 2
 *
 * This file is part of Twik.
 *
 * Twik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Twik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Twik.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.reddyetwo.hashmypass.app.data;




/**
 * Class to get/add/delete/update {@link com.reddyetwo.hashmypass.app.data.Favicon} from storage
 */
public class FaviconSettings {

    private static final String FILE_NAME = "favicon-%d.png";
    private static final int FAVICON_QUALITY = 100;

    private FaviconSettings() {

    }

    /**
     * Get the favicon of a site
     *
     * @param context the {@link android.content.Context} instance
     * @param site    the site
     * @return the {@link com.reddyetwo.hashmypass.app.data.Favicon} instance
     */
    public static Favicon getFavicon(Context context, String site) {
        DataOpenHelper helper = new DataOpenHelper(context);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor =
                db.query(DataOpenHelper.FAVICONS_TABLE_NAME, new String[]{DataOpenHelper.COLUMN_ID},
                        DataOpenHelper.COLUMN_FAVICONS_SITE + "= ?", new String[]{site}, null, null,
                        null);

        Favicon favicon = null;
        if (cursor.moveToFirst()) {
            long id = cursor.getLong(cursor.getColumnIndex(DataOpenHelper.COLUMN_ID));
            try {
                String filename = String.format(FILE_NAME, id);
                FileInputStream fis = context.openFileInput(filename);
                Bitmap icon = BitmapFactory.decodeStream(fis);
                favicon = new Favicon(id, site, icon);
            } catch (FileNotFoundException e) {
                // Favicon not found in storage
                Log.d(TwikApplication.LOG_TAG, "Favicon file not found: " + e);