Android Open Source - passwords-by-harry Data Service






From Project

Back to project page passwords-by-harry.

License

The source code is released under:

Apache License

If you think the Android project passwords-by-harry listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2013. Harry Henry Gebel
 *//from   w  w w  . j  a  va 2s  . c o m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.harryfrommarydelde.passwordsbyharry;

import android.app.Activity;
import android.content.Intent;
import android.os.Binder;
import android.widget.Toast;

import com.dropbox.sync.android.DbxAccount;
import com.dropbox.sync.android.DbxAccountManager;

/**
 * Stores and retrieves encrypted data
 */
public class DataService extends NonstopBoundService {
    private static final int REQUEST_LINK_TO_DROPBOX = 0;
    private static final String APP_KEY = "hh8pqygb5ok4s1u";
    private static final String APP_SECRET = "7pxqzq6zvw4x1mo";
    private DbxAccount account;

    private final DataBinder dataBinder = new DataBinder();

    public DataService() {
        // we should rarely by killed, but if we are
        // it is okay to force the user to re-enter
        // their password
        super(START_NOT_STICKY);

    }

    public class DataBinder extends Binder {
        /**
         * @return true if there is a data file, even if it is empty. Also link account if it
         * exists
         */
        public boolean dataExists() {
            DbxAccountManager accountManager;

            // check if link to Dropbox account exists
            accountManager = DbxAccountManager.getInstance(
                    getApplicationContext(), APP_KEY, APP_SECRET);
            if (accountManager.hasLinkedAccount()) {
                account = accountManager.getLinkedAccount();
                return true;
            }
            else
                return false;
        }

        /**
         * Link a Dropbox account to app
         * @param activity activity to launch after account is linked
         */
        public void linkAccount(Activity activity) {
            DbxAccountManager accountManager;

            // check start link to Dropbox account
            accountManager = DbxAccountManager.getInstance(
                    getApplicationContext(), APP_KEY, APP_SECRET);
            accountManager.startLink(activity, REQUEST_LINK_TO_DROPBOX);

            if (accountManager.hasLinkedAccount())
                Toast.makeText(getApplicationContext(), "Account linked", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(
                        getApplicationContext(),
                        "No account linked",
                        Toast.LENGTH_LONG).show();
        }

        /**
         * @return true if the user is logged in
         * **/
        public boolean isLoggedIn() {
            return false;
        }
    }

    public DataBinder onNonstopBind(Intent intent) {
        return dataBinder;
    }
}




Java Source Code List

com.github.harryfrommarydelde.passwordsbyharry.AccountListActivity.java
com.github.harryfrommarydelde.passwordsbyharry.ChangeMasterPasswordActivity.java
com.github.harryfrommarydelde.passwordsbyharry.DataServiceConnectedActivity.java
com.github.harryfrommarydelde.passwordsbyharry.DataService.java
com.github.harryfrommarydelde.passwordsbyharry.LoginActivity.java
com.github.harryfrommarydelde.passwordsbyharry.NonstopBoundService.java
com.github.harryfrommarydelde.passwordsbyharry.SettingsActivity.java
com.github.harryfrommarydelde.pbhsupport.DropboxSupport.java