Example usage for android.content Intent FLAG_ACTIVITY_NO_HISTORY

List of usage examples for android.content Intent FLAG_ACTIVITY_NO_HISTORY

Introduction

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

Prototype

int FLAG_ACTIVITY_NO_HISTORY

To view the source code for android.content Intent FLAG_ACTIVITY_NO_HISTORY.

Click Source Link

Document

If set, the new activity is not kept in the history stack.

Usage

From source file:com.trellmor.berrytubechat.ChatActivity.java

private void loadPreferences() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    try {//from w w w  . j av a 2s. c  o m
        mScrollback = Integer.parseInt(settings.getString(MainActivity.KEY_SCROLLBACK, "100"));
    } catch (NumberFormatException e) {
        mScrollback = 100;
    }

    if (mScrollback <= 0)
        mScrollback = 100;

    if (mBinder != null)
        mBinder.getService().setChatMsgBufferSize(mScrollback);

    try {
        mFlair = Integer.parseInt(settings.getString(MainActivity.KEY_FLAIR, "0"));
    } catch (NumberFormatException e) {
        mFlair = 0;
    }

    if (settings.getBoolean(MainActivity.KEY_SQUEE, false)) {
        mNotification = new NotificationCompat.Builder(this);
        mNotification.setSmallIcon(R.drawable.ic_stat_notify_chat);
        mNotification.setLights(0xFF0000FF, 100, 2000);
        mNotification.setAutoCancel(true);

        Intent intent = new Intent(this, ChatActivity.class);
        intent.putExtra(MainActivity.KEY_USERNAME, mUsername);
        intent.putExtra(MainActivity.KEY_PASSWORD, mPassword);
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);

        mNotification.setContentIntent(
                PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        String squee = settings.getString(MainActivity.KEY_SQUEE_RINGTONE, "");
        if (!"".equals(squee)) {
            mNotification.setSound(Uri.parse(squee), AudioManager.STREAM_NOTIFICATION);
        }
        if (settings.getBoolean(MainActivity.KEY_SQUEE_VIBRATE, false)) {
            mNotification.setVibrate(new long[] { 0, 100 });
        }
    } else {
        mNotification = null;
    }

    boolean showVideo = settings.getBoolean(MainActivity.KEY_VIDEO, false);
    if (showVideo != mShowVideo) {
        // If the value has changed, act on it
        if (showVideo) {
            if (!mFirstPrefLoad) {
                Toast.makeText(this, R.string.toast_video_enabled, Toast.LENGTH_LONG).show();
            }
        } else {
            mBinder.getService().disableVideoMessages();
            setTextVideoVisible(false);
        }
    }
    mShowVideo = showVideo;

    mShowDrinkCount = settings.getBoolean(MainActivity.KEY_DRINKCOUNT, true);
    mPopupPoll = settings.getBoolean(MainActivity.KEY_POPUP_POLL, false);
    updateDrinkCount();

    mFirstPrefLoad = false;
}

From source file:com.nkahoang.screenstandby.Main.java

private void openVideoClip() {
    Builder watchDialog = new AlertDialog.Builder(this).setCancelable(true);
    watchDialog.setTitle("Select a video clip:");
    watchDialog.setIcon(android.R.drawable.ic_menu_slideshow);
    watchDialog.setItems(clipsName, new android.content.DialogInterface.OnClickListener() {
        @Override/*from   w w  w. j a  v a  2 s . com*/
        public void onClick(DialogInterface dialog, int which) {
            if (which >= 0) {
                Intent youtubeIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.youtube.com/watch?v=" + clipsUrl[which]));
                youtubeIntent
                        .addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                startActivity(youtubeIntent);
            }
        }
    });
    watchDialog.setNegativeButton("Dismiss", null);
    watchDialog.show();
}

From source file:fm.smart.r1.ItemActivity.java

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it//  w w  w .ja v a  2  s  . c o  m
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (LoginActivity.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.getId());
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = new AddItemResult(Main.lookup.addItemToGoal(Main.transport,
                            Main.default_study_goal_id, item.getId(), null));

                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default goal

                        ItemActivity.add_sentence_goal_result = new AddSentenceResult(
                                Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id,
                                        item.getId(), sentence_id, null));

                        result = ItemActivity.add_sentence_goal_result;
                        if (ItemActivity.add_sentence_goal_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.getId(), Main.default_study_goal_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this, item.getId().toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:com.paranoid.gerrit.PatchSetViewerFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    String tab = null;/*from   www.j av  a2 s  .c  o  m*/
    switch (item.getOrder()) {
    case OWNER:
        tab = CardsFragment.KEY_OWNER;
        break;
    case REVIEWER:
        tab = CardsFragment.KEY_REVIEWER;
    }
    committerObject.setState(tab);
    Intent intent = new Intent(mParent, ReviewTab.class);
    intent.putExtra(CardsFragment.KEY_DEVELOPER, committerObject);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(intent);
    return true;
}

From source file:io.github.hidroh.materialistic.AppUtils.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void openPlayStore(Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(PLAY_STORE_URL));
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    } else {//from  w w  w  .j a va 2 s .  co m
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    }
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, R.string.no_playstore, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.untappedkegg.rally.home.ActivityMain.java

private void sendFeedback() {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();

    final String emailMsg = String.format(
            "App Version: %s\nAndroid: %s : %s\nDevice: %s \nPlease leave the above lines for debugging purposes. Thank you!\n\n",
            BuildConfig.VERSION_NAME, Build.VERSION.SDK_INT, Build.VERSION.RELEASE,
            /*Build.FINGERPRINT,*/ Build.MODEL);

    // Google+/*from  www.  j  a  v  a2 s . c om*/
    ArrayList<Person> recipients = new ArrayList<Person>();
    recipients.add(PlusShare.createPerson("109961307643513437237", BuildConfig.DEV_NAME));
    targetedShareIntents
            .add(new PlusShare.Builder(this).setType("text/plain").setRecipients(recipients).getIntent());

    // Email
    try {
        targetedShareIntents.add(
                CommonIntents.getShareIntent("email", "Feedback: " + getString(R.string.app_name), emailMsg)
                        .putExtra(Intent.EXTRA_EMAIL, "UntappedKegg@gmail.com"));
    } catch (Exception e) {
    }

    try {
        targetedShareIntents.add(
                CommonIntents.getShareIntent("gmail", "Feedback: " + getString(R.string.app_name), emailMsg)
                        .putExtra(Intent.EXTRA_EMAIL, "UntappedKegg@gmail.com"));
    } catch (Exception e) {
    }

    // Twitter
    Intent twitterIntent = CommonIntents.getShareIntent("twitter", "Untapped Rally", "@UntappedKegg ");
    if (twitterIntent != null)
        targetedShareIntents.add(twitterIntent);

    // Market
    try {
        final String mPackageName = getPackageName();
        final String installer = getPackageManager().getInstallerPackageName(mPackageName);
        Intent marketIntent = null;

        if (AppState.MARKET_GOOGLE.equalsIgnoreCase(installer)) {
            marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(AppState.APP_LINK_GOOGLE + mPackageName));
            marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
                    | Intent.FLAG_ACTIVITY_NEW_TASK);

        } else if (AppState.MARKET_AMAZON.equalsIgnoreCase(installer)) {
            marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(AppState.APP_LINK_AMAZON + mPackageName));
            marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        if (marketIntent != null)
            targetedShareIntents.add(marketIntent);

    } catch (Exception e) {
    }

    Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Send Feedback via:");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));
    startActivity(chooserIntent);

}

From source file:com.nkahoang.screenstandby.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_toggle: {
        Intent intentToggle = new Intent("com.nkahoang.screenstandby.action.TOGGLE");
        Main.this.sendBroadcast(intentToggle);
        break;/*from   w w w .  j  a  va  2  s. c o m*/
    }
    case R.id.menu_exit: {
        this.finish();
        break;
    }
    case R.id.menu_debuginfo:
        Logger.ShowLog(Main.this);
        break;
    case R.id.menu_rate:
        Intent marketIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=com.nkahoang.screenstandby"));
        marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        startActivity(marketIntent);
        break;
    case R.id.menu_watch_youtube:
        openVideoClip();
        break;
    case R.id.menu_troubleshooting:
        Intent intentTroubleshooting = new Intent(Main.this, TroubleshootingActivity.class);
        startActivity(intentTroubleshooting);
        break;
    case R.id.menu_manual:
        Intent intentManual = new Intent(Main.this, ManualBrightnessChangerActivity.class);
        startActivity(intentManual);
        break;
    case R.id.menu_setting:
        openSettings();
        break;
    case R.id.menu_devmessage:
        ChangeLogHandler.ShowChangelog(this);
        break;
    /*
    case R.id.menu_changedpi:
    Intent dpiintent = new Intent(Main.this,
         XTopDPIChanger.class);
    startActivity(dpiintent);
    break;*/
    }
    return true;
}

From source file:com.xortech.sender.SenderMain.java

/**
 * METHOD TO ASK USER TO DISABLE "DON'T KEEP ACTIVITIES" IN DEVELOPER OPTIONS
 *//*from w  w w .  j a  v a2 s  . c o  m*/
public void showDeveloperOptionsScreen() {

    new AlertDialog.Builder(this).setTitle("Developer Options Detected!").setMessage(
            "In order for Sender to work properly, please uncheck the \"Don't keep activities\" option.")
            .setNegativeButton(android.R.string.no, null)
            .setPositiveButton(android.R.string.yes, new OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {
                    Intent intent = new Intent(
                            android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    startActivity(intent);
                    finish();
                }
            }).create().show();
}

From source file:com.necisstudio.highlightgoal.MainActivity.java

void drawermenu(int id) {
    if (id == R.id.rate) {
        Uri uri = Uri.parse("market://details?id=com.necisstudio.highlightgoal");
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
                | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        try {//from  ww w.java  2 s . c o m
            startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=com.necisstudio.highlightgoal")));
        }

    } else if (id == R.id.feedback) {
        Intent send = new Intent(Intent.ACTION_SENDTO);
        String uriText = "mailto:" + Uri.encode("report@necistudio.com") + "?subject="
                + Uri.encode("Feedback for Highlight Goal") + "&body=" + Uri.encode("");
        Uri uri = Uri.parse(uriText);
        send.setData(uri);
        startActivity(Intent.createChooser(send, "Send mail..."));
    } else if (id == R.id.latest) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(0);
        txtTitle.setText("Latest");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightLatestFragment.newInstance(""),
                KlasementLigaFragment.newInstance("inggris"), ScheduleLigaLatestFragment.newInstance(""));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);
        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Schedule");
    } else if (id == R.id.inggris) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(R.mipmap.premier);
        txtTitle.setText("Premier League");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightFragment.newInstance("inggris"),
                KlasementLigaFragment.newInstance("inggris"), ScheduleLigaFragment.newInstance("inggris"));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);

        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Standings");
        tabHost.getTabAt(2).setText("Schedule");

    } else if (id == R.id.europa) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(R.mipmap.europa);
        txtTitle.setText("Europa League");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightFragment.newInstance("europa"),
                new TeamEuropaFragment(), ScheduleLigaFragment.newInstance("europa"));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);

        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Standings");
        tabHost.getTabAt(2).setText("Schedule");
    } else if (id == R.id.champion) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(R.mipmap.champion);
        txtTitle.setText("Champions League");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightFragment.newInstance("champions"),
                new TeamChampionsFragment(), ScheduleLigaFragment.newInstance("champions"));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);

        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Standings");
        tabHost.getTabAt(2).setText("Schedule");
    } else if (id == R.id.seria) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(R.mipmap.seria);
        txtTitle.setText("Seri A");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightFragment.newInstance("italia"),
                KlasementLigaFragment.newInstance("italia"), ScheduleLigaFragment.newInstance("italia"));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);

        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Standings");
        tabHost.getTabAt(2).setText("Schedule");
    } else if (id == R.id.jerman) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(R.mipmap.bundes);
        txtTitle.setText("Bundesliga");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightFragment.newInstance("jerman"),
                KlasementLigaFragment.newInstance("jerman"), ScheduleLigaFragment.newInstance("jerman"));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);

        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Standings");
        tabHost.getTabAt(2).setText("Schedule");
    } else if (id == R.id.spain) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(R.mipmap.bbva);
        txtTitle.setText("BBVA League");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightFragment.newInstance("spain"),
                KlasementLigaFragment.newInstance("spain"), ScheduleLigaFragment.newInstance("spain"));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);

        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Standings");
        tabHost.getTabAt(2).setText("Schedule");
    } else if (id == R.id.france) {
        ApplicationConfig.status = id;
        iddrawer = id;
        imgLogo.setImageResource(R.mipmap.ligue);
        txtTitle.setText("League 1");
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(HighlightFragment.newInstance("france"),
                KlasementLigaFragment.newInstance("france"), ScheduleLigaFragment.newInstance("france"));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        pager.setOffscreenPageLimit(3);

        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Standings");
        tabHost.getTabAt(2).setText("Schedule");
    } else if (id == R.id.about) {
        Intent intent = new Intent(MainActivity.this, ActivityAbout.class);
        startActivity(intent);
    } else if (id == R.id.license) {
        Intent intent = new Intent(MainActivity.this, ActivityLicense.class);
        startActivity(intent);
    }
}

From source file:com.groksolutions.grok.mobile.instance.InstanceListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (isMenuVisible() && item.getItemId() == R.id.menu_add_annotation) {
        // Get instance from context menu position
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        InstanceAnomalyChartData instance = (InstanceAnomalyChartData) getListAdapter().getItem(info.position);

        // Get timestamp from the selected bar on the anomaly chart
        AnomalyChartView view = (AnomalyChartView) info.targetView.findViewById(R.id.anomaly_chart_view);
        long selectedTimestamp = view.getSelectedTimestamp();
        if (selectedTimestamp == -1) {
            // Should not happen
            Log.w(TAG, "Failed to get annotation timestamp from chart view. Using current time instead");
            return true;
        }// w ww  .  ja  v  a2 s.co  m

        // Open "Add  Annotation" activity
        Intent addAnnotation = new Intent(getActivity(), AddAnnotationActivity.class);
        addAnnotation.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        addAnnotation.putExtra(AddAnnotationActivity.EXTRA_INSTANCE_ID, instance.getId());
        addAnnotation.putExtra(AddAnnotationActivity.EXTRA_TIMESTAMP, selectedTimestamp);
        getActivity().startActivity(addAnnotation);
    }

    return super.onContextItemSelected(item);
}