Example usage for android.app Activity getIntent

List of usage examples for android.app Activity getIntent

Introduction

In this page you can find the example usage for android.app Activity getIntent.

Prototype

public Intent getIntent() 

Source Link

Document

Return the intent that started this activity.

Usage

From source file:im.vector.VectorApp.java

/**
 * Restart an activity to manage language update
 *
 * @param activity the activity to restart
 *///w  w  w .  j  a  va  2  s .  c  o  m
private void restartActivity(Activity activity) {
    // avoid restarting activities when it is not required
    // some of them has no text
    if (!(activity instanceof VectorMediasPickerActivity) && !(activity instanceof VectorCallViewActivity)
            && !(activity instanceof JitsiCallActivity) && !(activity instanceof WidgetActivity)) {
        activity.startActivity(activity.getIntent());
        activity.finish();
    }
}

From source file:com.android.messaging.ui.conversation.ConversationFragment.java

private void clearScrollToMessagePosition() {
    final Activity activity = getActivity();
    if (activity == null) {
        return;/*from   w w  w . j a v a 2s  . c  o  m*/
    }

    final Intent intent = activity.getIntent();
    if (intent == null) {
        return;
    }
    intent.putExtra(UIIntents.UI_INTENT_EXTRA_MESSAGE_POSITION, -1);
}

From source file:com.android.messaging.ui.conversation.ConversationFragment.java

private int getScrollToMessagePosition() {
    final Activity activity = getActivity();
    if (activity == null) {
        return -1;
    }/*from  ww w . ja v  a 2 s.  com*/

    final Intent intent = activity.getIntent();
    if (intent == null) {
        return -1;
    }

    return intent.getIntExtra(UIIntents.UI_INTENT_EXTRA_MESSAGE_POSITION, -1);
}

From source file:com.smartnsoft.droid4me.app.ActivityController.java

/**
 * Indicates whether a redirection is required before letting the activity continue its life cycle. It launches the redirected {@link Activity} if a
 * redirection is need, and provide to its {@link Intent} the initial activity {@link Intent} trough the extra {@link Parcelable}
 * {@link ActivityController#CALLING_INTENT} key.
 * //from  w  ww.  j  a v a  2s .c o  m
 * <p>
 * If the provided {@code activity} implements the {@link ActivityController.EscapeToRedirector} interface or exposes the
 * {@link ActivityController.EscapeToRedirectorAnnotation} annotation, the method returns {@code false}.
 * </p>
 * 
 * <p>
 * Note that this method does not need to be marked as {@code synchronized}, because it is supposed to be invoked systematically from the UI thread.
 * </p>
 * 
 * @param activity
 *          the activity which is being proved against the {@link ActivityController.Redirector}
 * @return {@code true} if and only if the given activity should be paused (or ended) and if another activity should be launched instead through the
 *         {@link Activity#startActivity(Intent)} method
 * @see ActivityController#extractCallingIntent(Activity)
 * @see ActivityController.Redirector#getRedirection(Activity)
 * @see ActivityController.EscapeToRedirector
 * @see ActivityController.EscapeToRedirectorAnnotation
 */
public boolean needsRedirection(Activity activity) {
    if (redirector == null) {
        return false;
    }
    if (activity instanceof ActivityController.EscapeToRedirector || activity.getClass()
            .getAnnotation(ActivityController.EscapeToRedirectorAnnotation.class) != null) {
        if (log.isDebugEnabled()) {
            log.debug("The Activity with class '" + activity.getClass().getName()
                    + "' is escaped regarding the Redirector");
        }
        return false;
    }
    final Intent intent = redirector.getRedirection(activity);
    if (intent == null) {
        return false;
    }
    if (log.isDebugEnabled()) {
        log.debug("A redirection is needed");
    }

    // We redirect to the right Activity
    {
        // We consider the parent activity in case it is embedded (like in an ActivityGroup)
        final Intent formerIntent = activity.getParent() != null ? activity.getParent().getIntent()
                : activity.getIntent();
        intent.putExtra(ActivityController.CALLING_INTENT, formerIntent);
        // Disables the fact that the new started activity should belong to the tasks history and from the recent tasks
        // intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        // intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        activity.startActivity(intent);
    }

    // We now finish the redirected Activity
    activity.finish();

    return true;
}

From source file:org.mariotaku.twidere.util.Utils.java

public static void restartActivity(final Activity activity) {
    if (activity == null)
        return;//from   ww  w . j ava  2 s. c om
    final int enter_anim = android.R.anim.fade_in;
    final int exit_anim = android.R.anim.fade_out;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        ActivityAccessor.overridePendingTransition(activity, enter_anim, exit_anim);
    } else {
        activity.getWindow().setWindowAnimations(0);
    }
    activity.finish();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        ActivityAccessor.overridePendingTransition(activity, enter_anim, exit_anim);
    } else {
        activity.getWindow().setWindowAnimations(0);
    }
    activity.startActivity(activity.getIntent());
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void restartActivity(final Activity activity, final boolean animation) {
    if (activity == null)
        return;/* w w  w. jav a2  s.  co m*/
    final int enter_anim = animation ? android.R.anim.fade_in : 0;
    final int exit_anim = animation ? android.R.anim.fade_out : 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        OverridePendingTransitionAccessor.overridePendingTransition(activity, enter_anim, exit_anim);
    } else {
        activity.getWindow().setWindowAnimations(0);
    }
    activity.finish();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        OverridePendingTransitionAccessor.overridePendingTransition(activity, enter_anim, exit_anim);
    } else {
        activity.getWindow().setWindowAnimations(0);
    }
    activity.startActivity(activity.getIntent());
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void restartActivity(final Activity activity) {
    if (activity == null)
        return;//from  www .  ja va 2s .  com
    final int enter_anim = android.R.anim.fade_in;
    final int exit_anim = android.R.anim.fade_out;
    activity.finish();
    activity.overridePendingTransition(enter_anim, exit_anim);
    activity.startActivity(activity.getIntent());
    activity.overridePendingTransition(enter_anim, exit_anim);
}

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

private void displayTextSizeSelection(final Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    LayoutInflater inflater = activity.getLayoutInflater();

    View layout = inflater.inflate(R.layout.text_size_selection, null);
    builder.setTitle(R.string.font_size);
    builder.setView(layout);/*from   w  w w  .ja v a2  s. c  om*/

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.show();

    LinearLayout linearLayout = layout.findViewById(R.id.text_selection_group_view);

    int childCount = linearLayout.getChildCount();

    String scaleText = VectorApp.getFontScale();

    for (int i = 0; i < childCount; i++) {
        View v = linearLayout.getChildAt(i);

        if (v instanceof CheckedTextView) {
            final CheckedTextView checkedTextView = (CheckedTextView) v;
            checkedTextView.setChecked(TextUtils.equals(checkedTextView.getText(), scaleText));

            checkedTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    VectorApp.updateFontScale(checkedTextView.getText().toString());
                    activity.startActivity(activity.getIntent());
                    activity.finish();
                }
            });
        }
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public static void initPushContent(String message, String image, String messageType, String category,
        Context context) {//from w ww . jav a 2s.c o m
    com.codename1.push.PushContent.reset();

    int iMessageType = 1;
    try {
        iMessageType = Integer.parseInt(messageType);
    } catch (Throwable t) {
    }

    String actionId = null;
    String reply = null;
    boolean cancel = true;
    if (context instanceof Activity) {
        Activity activity = (Activity) context;
        Bundle extras = activity.getIntent().getExtras();
        if (extras != null) {
            actionId = extras.getString("pushActionId");
            extras.remove("pushActionId");

            if (actionId != null && RemoteInputWrapper.isSupported()) {
                Bundle textExtras = RemoteInputWrapper.getResultsFromIntent(activity.getIntent());
                if (textExtras != null) {
                    CharSequence cs = textExtras.getCharSequence(actionId + "$Result");
                    if (cs != null) {
                        reply = cs.toString();
                    }
                }

            }
        }

    }
    if (cancel) {
        PushNotificationService.cancelNotification(context);
    }
    com.codename1.push.PushContent.setType(iMessageType);
    com.codename1.push.PushContent.setCategory(category);
    if (actionId != null) {
        com.codename1.push.PushContent.setActionId(actionId);
    }
    if (reply != null) {
        com.codename1.push.PushContent.setTextResponse(reply);
    }
    switch (iMessageType) {
    case 1:
    case 5:
        com.codename1.push.PushContent.setBody(message);
        break;
    case 2:
        com.codename1.push.PushContent.setMetaData(message);
        break;
    case 3: {
        String[] parts = message.split(";");
        com.codename1.push.PushContent.setMetaData(parts[1]);
        com.codename1.push.PushContent.setBody(parts[0]);
        break;
    }
    case 4: {
        String[] parts = message.split(";");
        com.codename1.push.PushContent.setTitle(parts[0]);
        com.codename1.push.PushContent.setBody(parts[1]);
        break;
    }
    case 101: {
        com.codename1.push.PushContent.setBody(message.substring(message.indexOf(" ") + 1));
        com.codename1.push.PushContent.setType(1);
        break;
    }
    case 102: {
        String[] parts = message.split(";");
        com.codename1.push.PushContent.setTitle(parts[1]);
        com.codename1.push.PushContent.setBody(parts[2]);
        com.codename1.push.PushContent.setType(2);
        break;
    }
    }
}