Example usage for android.content Intent addFlags

List of usage examples for android.content Intent addFlags

Introduction

In this page you can find the example usage for android.content Intent addFlags.

Prototype

public @NonNull Intent addFlags(@Flags int flags) 

Source Link

Document

Add additional flags to the intent (or with existing flags value).

Usage

From source file:fr.gotorennes.AbstractMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.accueil:
        goToRennes.trackEvent("Menu", "Accueil");
        Intent intentAccueil = new Intent(getApplicationContext(), GoToRennesActivity.class);
        intentAccueil.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intentAccueil);//w  w w  .  j  a va  2  s . c o  m
        return true;
    case R.id.quitter:
        goToRennes.trackEvent("Menu", "Quitter");
        logout();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:eu.thecoder4.gpl.pleftdroid.EventDetailActivity.java

private void goMainActivity() {
    Intent ipd = new Intent(this, PleftDroidActivity.class);
    ipd.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(ipd);//  w  w w. jav a  2s. c  o m
}

From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java

protected void startBackgroundService() {
    if (!isServiceRunning) {
        log.info("Starting bg service");
        Activity activity = getActivity();
        Intent locationServiceIntent = new Intent(activity, LocationService.class);
        locationServiceIntent.putExtra("config", config);
        locationServiceIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
        // start service to keep service running even if no clients are bound to it
        activity.startService(locationServiceIntent);
        isServiceRunning = true;//w  w  w.ja v  a 2 s.  co  m
    }
}

From source file:de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.java

private void _open(String url, String contentType, String packageId, String activity,
        CallbackContext callbackContext, Bundle viewerOptions) throws JSONException {
    clearTempFiles();/*  ww w.  j av  a  2 s .co m*/

    File file = getAccessibleFile(url);

    if (file != null && file.exists() && file.isFile()) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            Uri path = Uri.fromFile(file);

            // @see http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent
            intent.addCategory(Intent.CATEGORY_EMBED);
            intent.setDataAndType(path, contentType);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(this.getClass().getName(), viewerOptions);
            //activity needs fully qualified name here
            intent.setComponent(new ComponentName(packageId, packageId + "." + activity));

            this.callbackContext = callbackContext;
            this.cordova.startActivityForResult(this, intent, REQUEST_CODE_OPEN);

            // send shown event
            JSONObject successObj = new JSONObject();
            successObj.put(Result.STATUS, PluginResult.Status.OK.ordinal());
            PluginResult result = new PluginResult(PluginResult.Status.OK, successObj);
            // need to keep callback for close event
            result.setKeepCallback(true);
            callbackContext.sendPluginResult(result);
        } catch (android.content.ActivityNotFoundException e) {
            JSONObject errorObj = new JSONObject();
            errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal());
            errorObj.put(Result.MESSAGE, "Activity not found: " + e.getMessage());
            callbackContext.error(errorObj);
        }
    } else {
        JSONObject errorObj = new JSONObject();
        errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal());
        errorObj.put(Result.MESSAGE, "File not found");
        callbackContext.error(errorObj);
    }
}

From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java

@SuppressLint({ "NewApi", "SimpleDateFormat" })
public VerticalSingleItemView(final DataMgr dataMgr, final Context context, final String uid, final View menu,
        final VerticalItemViewCtrl itemViewCtrl) {
    this.dataMgr = dataMgr;
    this.context = context;
    this.item = dataMgr.getItemByUid(uid, ITEM_PROJECTION);
    this.fontSize = new SettingFontSize(dataMgr).getData();
    this.theme = new SettingTheme(dataMgr).getData();
    this.showTop = false;
    this.showBottom = false;
    this.menu = menu;
    this.itemViewCtrl = itemViewCtrl;
    this.imageClickTime = 0;

    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.view = inflater.inflate(R.layout.single_item_view, null);
    // Disable hardware acceleration on Android 3.0-4.1 devices.
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
            && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }/* w  w w  .  j ava  2 s . c  o m*/

    lastItemView = view.findViewById(R.id.LastItemView);
    nextItemView = view.findViewById(R.id.NextItemView);
    itemScrollView = (OverScrollView) view.findViewById(R.id.ItemScrollView);
    itemScrollView.setTopScrollView(lastItemView);
    itemScrollView.setBottomScrollView(nextItemView);
    itemScrollView.setOnScrollChangeListener(this);
    itemScrollView.setOnTouchListener(this);

    final View btnShowOriginal = view.findViewById(R.id.BtnShowOriginal);
    btnShowOriginal.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            boolean ret = false;
            final TextView txt = (TextView) view.findViewById(R.id.BtnText);
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                txt.setTextColor(0xFF787878);
                ret = true;
                break;
            case MotionEvent.ACTION_MOVE:
                ret = true;
                break;
            case MotionEvent.ACTION_CANCEL:
                txt.setTextColor(0xBB787878);
                ret = false;
                break;
            case MotionEvent.ACTION_UP:
                txt.setTextColor(0xBB787878);
                final SettingBrowserChoice setting = new SettingBrowserChoice(dataMgr);
                if (setting.getData() == SettingBrowserChoice.BROWSER_CHOICE_EXTERNAL) {
                    final Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setData(Uri.parse(item.getHref()));
                    context.startActivity(intent);
                } else if (VerticalSingleItemView.this.listener != null) {
                    VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), false);
                }
                break;
            default:
            }
            return ret;
        }
    });

    final View btnShowMobilized = view.findViewById(R.id.BtnShowMobilized);
    btnShowMobilized.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            boolean ret = false;
            final TextView txt = (TextView) view.findViewById(R.id.BtnText);
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                txt.setTextColor(0xFF787878);
                ret = true;
                break;
            case MotionEvent.ACTION_MOVE:
                ret = true;
                break;
            case MotionEvent.ACTION_CANCEL:
                txt.setTextColor(0xBB787878);
                ret = false;
                break;
            case MotionEvent.ACTION_UP:
                txt.setTextColor(0xBB787878);
                if (VerticalSingleItemView.this.listener != null) {
                    VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), true);
                }
                ret = true;
                break;
            default:
            }
            return ret;
        }
    });

    {
        final ListItemItem lastItem = itemViewCtrl.getLastItem(item.getUid());
        final TextView txt = (TextView) lastItemView.findViewById(R.id.LastItemTitle);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
        if (lastItem == null) {
            lastUid = null;
            menu.findViewById(R.id.BtnPrevious).setEnabled(false);
            final ImageView img = (ImageView) lastItemView.findViewById(R.id.LastItemArrow);
            img.setImageResource(R.drawable.no_more_circle);
            txt.setText(R.string.TxtNoPreviousItem);
        } else {
            lastUid = lastItem.getId();
            final View btnLast = menu.findViewById(R.id.BtnPrevious);
            btnLast.setEnabled(true);
            btnLast.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View view) {
                    if (listener != null) {
                        listener.showLastItem();
                    }
                }
            });
            txt.setText(lastItem.getTitle());
        }
    }

    {
        final ListItemItem nextItem = itemViewCtrl.getNextItem(item.getUid());
        final TextView txt = (TextView) nextItemView.findViewById(R.id.NextItemTitle);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
        if (nextItem == null) {
            nextUid = null;
            menu.findViewById(R.id.BtnNext).setEnabled(false);
            final ImageView img = (ImageView) nextItemView.findViewById(R.id.NextItemArrow);
            img.setImageResource(R.drawable.no_more_circle);
            txt.setText(R.string.TxtNoNextItem);
        } else {
            nextUid = nextItem.getId();
            final View btnNext = menu.findViewById(R.id.BtnNext);
            btnNext.setEnabled(true);
            btnNext.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View view) {
                    if (listener != null) {
                        listener.showNextItem();
                    }
                }
            });
            txt.setText(nextItem.getTitle());
        }
    }

    final TextView title = (TextView) view.findViewById(R.id.ItemTitle);
    title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 3);
    title.setText(item.getTitle());
    final TextView info = (TextView) view.findViewById(R.id.ItemInfo);
    info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5);
    final StringBuilder infoText = new StringBuilder();
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    sdf.setTimeZone(TimeZone.getDefault());
    infoText.append(sdf.format(Utils.timestampToDate(item.getTimestamp())));
    if (item.getAuthor() != null && item.getAuthor().length() > 0) {
        infoText.append(" | By ");
        infoText.append(item.getAuthor());
    }
    if (item.getSourceTitle() != null && item.getSourceTitle().length() > 0) {
        infoText.append(" (");
        infoText.append(item.getSourceTitle());
        infoText.append(")");
    }
    info.setText(infoText);

    webView = (WebView) view.findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setBackgroundColor(context.getResources()
            .getColor(theme == SettingTheme.THEME_NORMAL ? R.color.NormalBackground : R.color.DarkBackground));
    webView.setFocusable(false);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            if (VerticalSingleItemView.this.imageClickTime > System.currentTimeMillis() - 1000) {
                return true;
            }
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse(url));
            context.startActivity(intent);
            return true;
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(final WebView view, final String url, final String message,
                final JsResult result) {
            if (VerticalSingleItemView.this.listener != null) {
                if (message.endsWith(".erss")) {
                    VerticalSingleItemView.this.listener
                            .onImageViewRequired(item.getStoragePath() + "/" + message);
                } else {
                    VerticalSingleItemView.this.listener.onImageViewRequired(message);
                }
            }
            VerticalSingleItemView.this.imageClickTime = System.currentTimeMillis();
            result.cancel();
            return true;
        }
    });

    updateButtonStar();
    updateButtonSharing();
    updateButtonOpenLink();

    if (!item.getState().isRead()) {
        dataMgr.markItemAsReadWithTransactionByUid(uid);
        NetworkMgr.getInstance().startImmediateItemStateSyncing();
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        getActivity().finish();/*from  w w w. j  a va 2 s.c om*/
        return true;
    }

    case R.id.AddLog: {
        try {
            addMessageDialog = new Dialog(getActivity());
            addMessageDialog.setContentView(R.layout.add_message);
            addMessageDialog.setTitle("Add Message to Event Log");
            ((Button) addMessageDialog.findViewById(R.id.SaveButton))
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AddLogMessage(((EditText) addMessageDialog.findViewById(R.id.LogMessage)).getText()
                                    .toString());
                            addMessageDialog.dismiss();
                        }
                    });

            addMessageDialog.show();
            return true;
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventFragmentUpdate", "AddLog", e);
            return false;
        }
    }

    case R.id.escalate: {
        try {
            Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

            // Add data to the intent, the receiving app will decide what to do with it.
            intent.putExtra(Intent.EXTRA_SUBJECT, "Escalation of Zenoss Event on " + Title.getText());
            String EventDetails = Summary.getText() + "\r\r\n" + LastTime.getText() + "\r\r\n" + "Count: "
                    + EventCount.getText();

            intent.putExtra(Intent.EXTRA_TEXT, EventDetails);

            startActivity(Intent.createChooser(intent, "How would you like to escalate this event?"));
            return true;
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventFragmentUpdate", "escalate", e);
            return false;
        }
    }

    default: {
        return false;
    }
    }
}

From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java

private void sendMissingKey(Account account, final String authToken, byte[] saltPwdCheck) {
    Intent intent = KeyPasswordActivity.createKeyPasswortActivity(mContext, account, authToken, saltPwdCheck);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.notif_key)
            .setContentTitle(String.format(mContext.getText(R.string.notif_missing_key).toString()))
            .setContentText(account.name).setAutoCancel(false).setOnlyAlertOnce(true)
            .setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(account.name, Constants.NOTIF_MISSING_KEY, mBuilder.build());
}

From source file:com.meetingninja.csse.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SessionManager.getInstance().init(MainActivity.this);
    session = SessionManager.getInstance();

    // Check if logged in
    if (!session.isLoggedIn()) {
        Log.v(TAG, "User is not logged in");
        Intent login = new Intent(this, LoginActivity.class);
        // Bring login to front
        login.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        // User cannot go back to this activity
        // login.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        // Show no animation when launching login page
        login.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(login);/*from  w w  w . ja  v  a2  s.  co m*/
        finish(); // close main activity
    } else { // Else continue
        Log.v(TAG, "UserID " + session.getUserID() + " is logged in");
        setContentView(R.layout.activity_main);
        setupActionBar();
        setupViews();

        // on first time display view for first nav item
        selectItem(session.getPage());

        // Check to see if data has been cached in the local database
        if (savedInstanceState != null) {
            isDataCached = savedInstanceState.getBoolean(KEY_SQL_CACHE, false);
        }
        if (!isDataCached && session.needsSync()) {
            ApplicationController.getInstance().loadUsers();
            isDataCached = true;
            session.setSynced();
        }

        // Track the usage of the application with Parse SDK
        ParseAnalytics.trackAppOpened(getIntent());
        ParseUser parseUser = ParseUser.getCurrentUser();
        if (parseUser != null) {
            ParseInstallation installation = ParseInstallation.getCurrentInstallation();
            installation.put("user", parseUser);
            installation.put("userId", parseUser.getObjectId());
            installation.saveEventually();
        }
    }

}

From source file:com.zhihuigu.sosoOffice.RegisterThirdActivity.java

@Override
public void onClick(View v) {
    if (v == backBtn) {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);//from  w  w  w  .  j  a  va 2 s  .  c  o m
        finish();
    } else if (v == submitBtn) {
        if (textValidate()) {
            new Thread(runnable).start();
        }
    } else if (v == linearGetImage) {
        int height = MyApplication.getInstance(this).getScreenHeight();
        if (photo_tag) {
            shareBtn3.setVisibility(View.VISIBLE);
            if (height == 1280) {
                chazhi = 670;
            } else if (height == 800) {
                chazhi = 340;
            } else if (height == 960) {
                chazhi = 500;
            } else if (height == 854) {
                chazhi = 400;
            } else if (height == 480) {
                chazhi = 175;
            }
        } else {
            shareBtn3.setVisibility(View.GONE);
            if (height == 1280) {
                chazhi = 800;
            } else if (height == 800) {
                chazhi = 440;
            } else if (height == 960) {
                chazhi = 600;
            } else if (height == 854) {
                chazhi = 492;
            } else if (height == 480) {
                chazhi = 240;
            }
        }
        CommonUtils.hideSoftKeyboard(this);//
        new Thread(runnableForShowDialog).start();

    } else if (v == shareBtn1) {
        dismiss();
        Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        fileName = CommonUtils.getFileName();
        MyApplication.getInstance(this).setFileName(fileName);
        File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD);
        if (!file.exists()) {
            file.mkdirs();
        }
        if (CommonUtils.isHasSdcard()) {
            openCamera.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName)));
        }
        startActivityForResult(openCamera, REQUEST_CODE_TAKE_PICTURE);
    } else if (v == shareBtn2) {
        dismiss();
        Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
        getAlbum.setType(IMAGE_TYPE);
        startActivityForResult(getAlbum, IMAGE_CODE);
    } else if (v == shareBtn3) {
        dismiss();
        //         Intent intent = new Intent(this,ImagePreViewActivity.class);
        //         intent.putExtra("path", path);
        //         startActivityForResult(intent, 6);
        ArrayList<String> al = new ArrayList<String>();
        al.clear();
        al.add(path);
        Intent it = new Intent(this, ImageSwitcher.class);
        it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        it.putStringArrayListExtra("pathes", al);
        it.putExtra("index", 0);
        startActivity(it);
    } else if (v == cancleBtn) {
        dismiss();
    }
    super.onClick(v);
}