Android Open Source - savemypics C Flickr Web Activity






From Project

Back to project page savemypics.

License

The source code is released under:

Copyright (c) 2014, KB Sriram All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. R...

If you think the Android project savemypics 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

package org.savemypics.android.authenticator;
//from   w w w.j av a  2 s  .  c o m
// Wrap a webview that finish() by returning
// oauth tokens [if it sees it]

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import org.savemypics.android.R;
import org.savemypics.android.util.CUtils;

public class CFlickrWebActivity extends Activity
{
    final static String KEY_TARGET_URL =
        "org.savemypics.android.cfwa_target_url";
    final static String KEY_CALLBACK_URL =
        "org.savemypics.android.cfwa_callback_url";
    final static String KEY_TOKEN_PARAMS =
        "org.savemypics.android.cfwa_token_params";

    @Override
    protected void onCreate(Bundle saved)
    {
        super.onCreate(saved);
        final String target = getIntent().getStringExtra(KEY_TARGET_URL);
        final String callback = getIntent().getStringExtra(KEY_CALLBACK_URL);
        if (TextUtils.isEmpty(target) ||
            TextUtils.isEmpty(callback)) {
            CUtils.LOGW(TAG, "Unexpected empty intent");
            setResult(RESULT_CANCELED);
            finish();
        }

        setContentView(R.layout.flickr_web);
        m_wv = (WebView) findViewById(R.id.flickr_webview);

        //CUtils.LOGD(TAG, "target="+target);
        //CUtils.LOGD(TAG, "callback="+callback);

        WebSettings ws = m_wv.getSettings();
        ws.setJavaScriptEnabled(true);
        ws.setUserAgentString("savemypics/1.0");

        m_wv.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading
                        (WebView view, String url) {
                        if (url.startsWith(callback)) {
                            onFinishWith(url);
                            return true;
                        }
                        else {
                            //CUtils.LOGD(TAG, "skip: "+url);
                            return false;
                        }
                    }
            });

        // Remove all cookies before starting.
        CookieSyncManager.createInstance(this);
        CookieManager cmgr = CookieManager.getInstance();
        cmgr.removeAllCookie();

        m_wv.loadUrl(target);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        // Check if the key event was the Back button and if there's history
        if ((keyCode == KeyEvent.KEYCODE_BACK) && m_wv.canGoBack()) {
            m_wv.goBack();
            return true;
        }
        else {
            return super.onKeyDown(keyCode, event);
        }
    }

    private void onFinishWith(String url)
    {
        Uri uri = Uri.parse(url);

        Intent intent = new Intent().putExtra(KEY_TOKEN_PARAMS, uri.getQuery());
        setResult(RESULT_OK, intent);
        finish();            
    }

    private WebView m_wv;
    private final static String TAG =
        CUtils.makeLogTag(CFlickrWebActivity.class);
}




Java Source Code List

android.util.Base64.java
org.savemypics.android.activity.AActivity.java
org.savemypics.android.activity.ABaseSettingsActivity.java
org.savemypics.android.activity.CAccountInfoListAdapter.java
org.savemypics.android.activity.CFlickrSettingsActivity.java
org.savemypics.android.activity.CSnapfishSettingsActivity.java
org.savemypics.android.activity.CStartActivity.java
org.savemypics.android.authenticator.AAuthenticatorActivity.java
org.savemypics.android.authenticator.CAuthenticationService.java
org.savemypics.android.authenticator.CAuthenticator.java
org.savemypics.android.authenticator.CFlickrLoginHookActivity.java
org.savemypics.android.authenticator.CFlickrWebActivity.java
org.savemypics.android.authenticator.CSelectProviderActivity.java
org.savemypics.android.authenticator.CSnapfishLoginActivity.java
org.savemypics.android.db.CAccount.java
org.savemypics.android.db.CDb.java
org.savemypics.android.db.CLocalImage.java
org.savemypics.android.db.CMap.java
org.savemypics.android.db.CRemoteImage.java
org.savemypics.android.event.AEvent.java
org.savemypics.android.event.CEventBus.java
org.savemypics.android.event.CExceptionEvent.java
org.savemypics.android.glue.ABaseGlue.java
org.savemypics.android.glue.CFlickrGlue.java
org.savemypics.android.glue.CSnapfishGlue.java
org.savemypics.android.receiver.CNetworkChangeReceiver.java
org.savemypics.android.service.CTaskQueue.java
org.savemypics.android.sync.CMediaUtils.java
org.savemypics.android.sync.CSyncAdapter.java
org.savemypics.android.sync.CSyncService.java
org.savemypics.android.sync.CSyncUtils.java
org.savemypics.android.util.CBitmapUtils.java
org.savemypics.android.util.CFileCache.java
org.savemypics.android.util.CLruCache.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.view.CMaximumWidthLayout.java
org.savemypics.android.view.CModularLayout.java
org.savemypics.android.view.CRefreshButton.java
org.savemypics.android.view.CRoundedBitmapView.java
org.savemypics.android.view.CStatusCounterView.java
org.savemypics.plugin.CIOUtils.java
org.savemypics.plugin.CPlugin.java
org.savemypics.plugin.flickr.CFlickrAlbum.java
org.savemypics.plugin.flickr.CFlickrUtils.java
org.savemypics.plugin.snapfish.CSnapfishAlbum.java
org.savemypics.plugin.snapfish.CSnapfishFeed.java
org.savemypics.plugin.snapfish.CSnapfishUser.java
org.savemypics.plugin.snapfish.CSnapfishUtils.java