Search in sources :

Example 36 with ActivityNotFoundException

use of android.content.ActivityNotFoundException 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 37 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project WordPress-Android by wordpress-mobile.

the class ReaderLinkMovementMethod method onTouchEvent.

@Override
public boolean onTouchEvent(@NonNull TextView textView, @NonNull Spannable buffer, @NonNull MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        x -= textView.getTotalPaddingLeft();
        y -= textView.getTotalPaddingTop();
        x += textView.getScrollX();
        y += textView.getScrollY();
        Layout layout = textView.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);
        ImageSpan[] images = buffer.getSpans(off, off, ImageSpan.class);
        if (images != null && images.length > 0) {
            EnumSet<PhotoViewerOption> options = EnumSet.noneOf(PhotoViewerOption.class);
            if (mIsPrivate) {
                options.add(ReaderActivityLauncher.PhotoViewerOption.IS_PRIVATE_IMAGE);
            }
            String imageUrl = StringUtils.notNullStr(images[0].getSource());
            ReaderActivityLauncher.showReaderPhotoViewer(textView.getContext(), imageUrl, null, textView, options, (int) event.getX(), (int) event.getY());
            return true;
        }
    }
    try {
        return super.onTouchEvent(textView, buffer, event);
    } catch (ActivityNotFoundException e) {
        AppLog.e(AppLog.T.UTILS, e);
        return false;
    }
}
Also used : PhotoViewerOption(org.wordpress.android.ui.reader.ReaderActivityLauncher.PhotoViewerOption) Layout(android.text.Layout) ActivityNotFoundException(android.content.ActivityNotFoundException) ImageSpan(android.text.style.ImageSpan)

Example 38 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project platform_frameworks_base by android.

the class PlatLogoActivity method onAttachedToWindow.

@Override
public void onAttachedToWindow() {
    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float dp = dm.density;
    final int size = (int) (Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600 * dp) - 100 * dp);
    final ImageView im = new ImageView(this);
    final int pad = (int) (40 * dp);
    im.setPadding(pad, pad, pad, pad);
    im.setTranslationZ(20);
    im.setScaleX(0.5f);
    im.setScaleY(0.5f);
    im.setAlpha(0f);
    im.setBackground(new RippleDrawable(ColorStateList.valueOf(0xFFFFFFFF), getDrawable(com.android.internal.R.drawable.platlogo), null));
    //        im.setOutlineProvider(new ViewOutlineProvider() {
    //            @Override
    //            public void getOutline(View view, Outline outline) {
    //                outline.setOval(0, 0, view.getWidth(), view.getHeight());
    //            }
    //        });
    im.setClickable(true);
    im.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            im.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    if (mTapCount < 5)
                        return false;
                    if (REVEAL_THE_NAME) {
                        final Drawable overlay = getDrawable(com.android.internal.R.drawable.platlogo_m);
                        overlay.setBounds(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
                        im.getOverlay().clear();
                        im.getOverlay().add(overlay);
                        overlay.setAlpha(0);
                        ObjectAnimator.ofInt(overlay, "alpha", 0, 255).setDuration(500).start();
                    }
                    final ContentResolver cr = getContentResolver();
                    if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0) == 0) {
                        // For posterity: the moment this user unlocked the easter egg
                        try {
                            Settings.System.putLong(cr, Settings.System.EGG_MODE, System.currentTimeMillis());
                        } catch (RuntimeException e) {
                            Log.e("PlatLogoActivity", "Can't write settings", e);
                        }
                    }
                    im.post(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                startActivity(new Intent(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).addCategory("com.android.internal.category.PLATLOGO"));
                            } catch (ActivityNotFoundException ex) {
                                Log.e("PlatLogoActivity", "No more eggs.");
                            }
                            if (FINISH)
                                finish();
                        }
                    });
                    return true;
                }
            });
            mTapCount++;
        }
    });
    // Enable hardware keyboard input for TV compatibility.
    im.setFocusable(true);
    im.requestFocus();
    im.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode != KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                ++mKeyCount;
                if (mKeyCount > 2) {
                    if (mTapCount > 5) {
                        im.performLongClick();
                    } else {
                        im.performClick();
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    });
    mLayout.addView(im, new FrameLayout.LayoutParams(size, size, Gravity.CENTER));
    im.animate().scaleX(1f).scaleY(1f).alpha(1f).setInterpolator(mInterpolator).setDuration(500).setStartDelay(800).start();
}
Also used : Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) Intent(android.content.Intent) DisplayMetrics(android.util.DisplayMetrics) ImageView(android.widget.ImageView) View(android.view.View) Paint(android.graphics.Paint) RippleDrawable(android.graphics.drawable.RippleDrawable) ContentResolver(android.content.ContentResolver) KeyEvent(android.view.KeyEvent) ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView)

Example 39 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project platform_frameworks_base by android.

the class SearchView method onVoiceClicked.

private void onVoiceClicked() {
    // guard against possible race conditions
    if (mSearchable == null) {
        return;
    }
    SearchableInfo searchable = mSearchable;
    try {
        if (searchable.getVoiceSearchLaunchWebSearch()) {
            Intent webSearchIntent = createVoiceWebSearchIntent(mVoiceWebSearchIntent, searchable);
            getContext().startActivity(webSearchIntent);
        } else if (searchable.getVoiceSearchLaunchRecognizer()) {
            Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent, searchable);
            getContext().startActivity(appSearchIntent);
        }
    } catch (ActivityNotFoundException e) {
        // Should not happen, since we check the availability of
        // voice search before showing the button. But just in case...
        Log.w(LOG_TAG, "Could not find voice search activity");
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) SearchableInfo(android.app.SearchableInfo) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RecognizerIntent(android.speech.RecognizerIntent)

Example 40 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project platform_frameworks_base by android.

the class SearchManager method startGlobalSearch.

/**
     * Starts the global search activity.
     */
/* package */
void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
    ComponentName globalSearchActivity = getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search, if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", mContext.getPackageName());
    }
    intent.putExtra(APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        if (DBG)
            Log.d(TAG, "Starting global search: " + intent.toUri(0));
        mContext.startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Bundle(android.os.Bundle) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)406 Intent (android.content.Intent)365 Uri (android.net.Uri)49 PendingIntent (android.app.PendingIntent)39 View (android.view.View)39 ResolveInfo (android.content.pm.ResolveInfo)38 RecognizerIntent (android.speech.RecognizerIntent)35 PackageManager (android.content.pm.PackageManager)30 UserHandle (android.os.UserHandle)28 ComponentName (android.content.ComponentName)26 ImageView (android.widget.ImageView)24 Bundle (android.os.Bundle)23 TextView (android.widget.TextView)23 Test (org.junit.Test)23 RemoteException (android.os.RemoteException)22 Activity (android.app.Activity)21 SearchManager (android.app.SearchManager)20 DialogInterface (android.content.DialogInterface)17 SearchableInfo (android.app.SearchableInfo)15 File (java.io.File)15