Search in sources :

Example 51 with Parcelable

use of android.os.Parcelable in project Android-AccountChooser by frakbot.

the class ChooseTypeAndAccountActivity method onActivityResult.

// Called when the choose account type activity (for adding an account) returns.
// If it was a success read the account and set it in the result. In all cases
// return the result and finish this activity.
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        if (data != null && data.getExtras() != null)
            data.getExtras().keySet();
        Bundle extras = data != null ? data.getExtras() : null;
        Log.v(TAG, "ChooseTypeAndAccountActivity.onActivityResult(reqCode=" + requestCode + ", resCode=" + resultCode + ", extras=" + extras + ")");
    }
    // we got our result, so clear the fact that we had a pending request
    mPendingRequest = REQUEST_NULL;
    if (resultCode == RESULT_CANCELED) {
        // finish this activity
        if (mAccounts.isEmpty()) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
        return;
    }
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CHOOSE_TYPE) {
            if (data != null) {
                String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
                if (accountType != null) {
                    runAddAccountForAuthenticator(accountType);
                    return;
                }
            }
            Log.d(TAG, "ChooseTypeAndAccountActivity.onActivityResult: unable to find account " + "type, pretending the request was canceled");
        } else if (requestCode == REQUEST_ADD_ACCOUNT) {
            String accountName = null;
            String accountType = null;
            if (data != null) {
                accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
                accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
            }
            if (accountName == null || accountType == null) {
                Account[] currentAccounts = AccountManager.get(this).getAccounts();
                Set<Account> preExistingAccounts = new HashSet<Account>();
                for (Parcelable accountParcel : mExistingAccounts) {
                    preExistingAccounts.add((Account) accountParcel);
                }
                for (Account account : currentAccounts) {
                    if (!preExistingAccounts.contains(account)) {
                        accountName = account.name;
                        accountType = account.type;
                        break;
                    }
                }
            }
            if (accountName != null || accountType != null) {
                setResultAndFinish(accountName, accountType);
                return;
            }
        }
        Log.d(TAG, "ChooseTypeAndAccountActivity.onActivityResult: unable to find added " + "account, pretending the request was canceled");
    }
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "ChooseTypeAndAccountActivity.onActivityResult: canceled");
    }
    setResult(Activity.RESULT_CANCELED);
    finish();
}
Also used : Account(android.accounts.Account) Set(java.util.Set) HashSet(java.util.HashSet) Bundle(android.os.Bundle) Parcelable(android.os.Parcelable)

Example 52 with Parcelable

use of android.os.Parcelable in project FBReaderJ by geometer.

the class ProcessHyperlinkAction method run.

@Override
protected void run(Object... params) {
    final ZLTextRegion region = Reader.getTextView().getOutlinedRegion();
    if (region == null) {
        return;
    }
    final ZLTextRegion.Soul soul = region.getSoul();
    if (soul instanceof ZLTextHyperlinkRegionSoul) {
        Reader.getTextView().hideOutline();
        Reader.getViewWidget().repaint();
        final ZLTextHyperlink hyperlink = ((ZLTextHyperlinkRegionSoul) soul).Hyperlink;
        switch(hyperlink.Type) {
            case FBHyperlinkType.EXTERNAL:
                openInBrowser(hyperlink.Id);
                break;
            case FBHyperlinkType.INTERNAL:
            case FBHyperlinkType.FOOTNOTE:
                {
                    final AutoTextSnippet snippet = Reader.getFootnoteData(hyperlink.Id);
                    if (snippet == null) {
                        break;
                    }
                    Reader.Collection.markHyperlinkAsVisited(Reader.getCurrentBook(), hyperlink.Id);
                    final boolean showToast;
                    switch(Reader.MiscOptions.ShowFootnoteToast.getValue()) {
                        default:
                        case never:
                            showToast = false;
                            break;
                        case footnotesOnly:
                            showToast = hyperlink.Type == FBHyperlinkType.FOOTNOTE;
                            break;
                        case footnotesAndSuperscripts:
                            showToast = hyperlink.Type == FBHyperlinkType.FOOTNOTE || region.isVerticallyAligned();
                            break;
                        case allInternalLinks:
                            showToast = true;
                            break;
                    }
                    if (showToast) {
                        final SuperActivityToast toast;
                        if (snippet.IsEndOfText) {
                            toast = new SuperActivityToast(BaseActivity, SuperToast.Type.STANDARD);
                        } else {
                            toast = new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON);
                            toast.setButtonIcon(android.R.drawable.ic_menu_more, ZLResource.resource("toast").getResource("more").getValue());
                            toast.setOnClickWrapper(new OnClickWrapper("ftnt", new SuperToast.OnClickListener() {

                                @Override
                                public void onClick(View view, Parcelable token) {
                                    Reader.getTextView().hideOutline();
                                    Reader.tryOpenFootnote(hyperlink.Id);
                                }
                            }));
                        }
                        toast.setText(snippet.getText());
                        toast.setDuration(Reader.MiscOptions.FootnoteToastDuration.getValue().Value);
                        toast.setOnDismissWrapper(new OnDismissWrapper("ftnt", new SuperToast.OnDismissListener() {

                            @Override
                            public void onDismiss(View view) {
                                Reader.getTextView().hideOutline();
                                Reader.getViewWidget().repaint();
                            }
                        }));
                        Reader.getTextView().outlineRegion(region);
                        BaseActivity.showToast(toast);
                    } else {
                        Reader.tryOpenFootnote(hyperlink.Id);
                    }
                    break;
                }
        }
    } else if (soul instanceof ZLTextImageRegionSoul) {
        Reader.getTextView().hideOutline();
        Reader.getViewWidget().repaint();
        final String url = ((ZLTextImageRegionSoul) soul).ImageElement.URL;
        if (url != null) {
            try {
                final Intent intent = new Intent();
                intent.setClass(BaseActivity, ImageViewActivity.class);
                intent.putExtra(ImageViewActivity.URL_KEY, url);
                intent.putExtra(ImageViewActivity.BACKGROUND_COLOR_KEY, Reader.ImageOptions.ImageViewBackground.getValue().intValue());
                OrientationUtil.startActivity(BaseActivity, intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else if (soul instanceof ZLTextWordRegionSoul) {
        DictionaryUtil.openTextInDictionary(BaseActivity, ((ZLTextWordRegionSoul) soul).Word.getString(), true, region.getTop(), region.getBottom(), new Runnable() {

            public void run() {
                BaseActivity.outlineRegion(soul);
            }
        });
    }
}
Also used : SuperToast(com.github.johnpersano.supertoasts.SuperToast) ImageViewActivity(org.geometerplus.android.fbreader.image.ImageViewActivity) SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast) Parcelable(android.os.Parcelable) Intent(android.content.Intent) View(android.view.View) AutoTextSnippet(org.geometerplus.fbreader.util.AutoTextSnippet) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickWrapper(com.github.johnpersano.supertoasts.util.OnClickWrapper) OnDismissWrapper(com.github.johnpersano.supertoasts.util.OnDismissWrapper)

Example 53 with Parcelable

use of android.os.Parcelable in project MaterialViewPager by florent37.

the class MaterialViewPager method onSaveInstanceState.

@Override
protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);
    //end
    ss.settings = this.settings;
    ss.yOffset = MaterialViewPagerHelper.getAnimator(getContext()).lastYOffset;
    return ss;
}
Also used : Parcelable(android.os.Parcelable)

Example 54 with Parcelable

use of android.os.Parcelable in project FBReaderJ by geometer.

the class Dictan method onActivityResult.

void onActivityResult(final FBReaderMainActivity fbreader, int resultCode, final Intent data) {
    if (data == null) {
        fbreader.hideDictionarySelection();
        return;
    }
    final int errorCode = data.getIntExtra("error.code", -1);
    if (resultCode != FBReaderMainActivity.RESULT_OK || errorCode != -1) {
        showError(fbreader, errorCode, data);
        return;
    }
    String text = data.getStringExtra("article.text");
    if (text == null) {
        showError(fbreader, -1, data);
        return;
    }
    // a hack for obsolete (before 5.0 beta) dictan versions
    final int index = text.indexOf("\000");
    if (index >= 0) {
        text = text.substring(0, index);
    }
    final boolean hasExtraData;
    if (text.length() == MAX_LENGTH_FOR_TOAST) {
        text = trimArticle(text);
        hasExtraData = true;
    } else {
        hasExtraData = data.getBooleanExtra("article.resources.contains", false);
    }
    final SuperActivityToast toast;
    if (hasExtraData) {
        toast = new SuperActivityToast(fbreader, SuperToast.Type.BUTTON);
        toast.setButtonIcon(android.R.drawable.ic_menu_more, ZLResource.resource("toast").getResource("more").getValue());
        toast.setOnClickWrapper(new OnClickWrapper("dict", new SuperToast.OnClickListener() {

            @Override
            public void onClick(View view, Parcelable token) {
                final String word = data.getStringExtra("article.word");
                final Intent intent = getActionIntent(word);
                try {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    fbreader.startActivity(intent);
                    fbreader.overridePendingTransition(0, 0);
                } catch (ActivityNotFoundException e) {
                // ignore
                }
            }
        }));
    } else {
        toast = new SuperActivityToast(fbreader, SuperToast.Type.STANDARD);
    }
    toast.setText(text);
    toast.setDuration(DictionaryUtil.TranslationToastDurationOption.getValue().Value);
    InternalUtil.showToast(toast, fbreader);
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickWrapper(com.github.johnpersano.supertoasts.util.OnClickWrapper) SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast) Parcelable(android.os.Parcelable) Intent(android.content.Intent) View(android.view.View)

Example 55 with Parcelable

use of android.os.Parcelable in project WeChatLuckyMoney by geeeeeeeeek.

the class HongbaoService method watchNotifications.

private boolean watchNotifications(AccessibilityEvent event) {
    // Not a notification
    if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
        return false;
    // Not a hongbao
    String tip = event.getText().toString();
    if (!tip.contains(WECHAT_NOTIFICATION_TIP))
        return true;
    Parcelable parcelable = event.getParcelableData();
    if (parcelable instanceof Notification) {
        Notification notification = (Notification) parcelable;
        try {
            /* 清除signature,避免进入会话后误判 */
            signature.cleanSignature();
            notification.contentIntent.send();
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }
    }
    return true;
}
Also used : Parcelable(android.os.Parcelable) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Aggregations

Parcelable (android.os.Parcelable)826 Bundle (android.os.Bundle)99 View (android.view.View)85 Intent (android.content.Intent)58 SparseArray (android.util.SparseArray)38 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)26 MenuItem (android.view.MenuItem)23 ImageView (android.widget.ImageView)23 TextView (android.widget.TextView)17 MenuItem (com.actionbarsherlock.view.MenuItem)14 SuppressLint (android.annotation.SuppressLint)13 Dialog (android.app.Dialog)13 MediumTest (android.support.test.filters.MediumTest)13 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)12 Paint (android.graphics.Paint)12 MenuView (com.android.internal.view.menu.MenuView)12 RemoteException (android.os.RemoteException)11 Bitmap (android.graphics.Bitmap)10 ShortcutIconResource (android.content.Intent.ShortcutIconResource)9