Example usage for android.support.v4.app Fragment getClass

List of usage examples for android.support.v4.app Fragment getClass

Introduction

In this page you can find the example usage for android.support.v4.app Fragment getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:edu.vuum.mocca.ui.tags.TagsActivityBase.java

/**
 * Logic required to open the appropriate Create TagsData Fragment/Activity
 * combination to display properly on the phone or tablet.
 *///  w w w  .  ja  va2 s . c  o m
public void openCreateTagsFragment() {
    Log.d(LOG_TAG, "openCreateTagsFragment");
    if (determineDualPane()) {

        Fragment test = getSupportFragmentManager().findFragmentById(R.id.details);

        // Log.d(LOG_TAG, "open view class:" + test.getClass());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (test != null && test.getClass() != CreateTagsFragment.class) {
            CreateTagsFragment details = CreateTagsFragment.newInstance();

            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        } else {
            // Check what fragment is shown, replace if needed.
            CreateTagsFragment details = (CreateTagsFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.details);
            if (details == null) {
                // Make new fragment to show this selection.
                details = CreateTagsFragment.newInstance();

            }
            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = newCreateTagsIntent(this);
        startActivity(intent);
    }
}

From source file:de.unipassau.isl.evs.ssh.app.activity.AppMainActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    final Fragment currentFragment = getCurrentFragment();
    if (currentFragment != null) {
        outState.putString(KEY_LAST_FRAGMENT, currentFragment.getClass().getName());
    }/*from w ww . j  av  a 2  s  . com*/
}

From source file:com.google.android.apps.muzei.settings.SettingsActivity.java

private void setupAppBar() {
    mAppBar = (Toolbar) findViewById(R.id.app_bar);
    mAppBar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*from   w  ww  .  jav  a2s  .  c  om*/
        public void onClick(View view) {
            onNavigateUp();
        }
    });

    final LayoutInflater inflater = LayoutInflater.from(this);
    Spinner sectionSpinner = (Spinner) findViewById(R.id.section_spinner);
    sectionSpinner.setAdapter(new BaseAdapter() {
        @Override
        public int getCount() {
            return SECTION_LABELS.length;
        }

        @Override
        public Object getItem(int position) {
            return SECTION_LABELS[position];
        }

        @Override
        public long getItemId(int position) {
            return position + 1;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.settings_ab_spinner_list_item, parent, false);
            }
            ((TextView) convertView.findViewById(android.R.id.text1))
                    .setText(getString(SECTION_LABELS[position]));
            return convertView;
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.settings_ab_spinner_list_item_dropdown, parent, false);
            }
            ((TextView) convertView.findViewById(android.R.id.text1))
                    .setText(getString(SECTION_LABELS[position]));
            return convertView;
        }
    });

    sectionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> spinner, View view, int position, long id) {
            Class<? extends Fragment> fragmentClass = SECTION_FRAGMENTS[position];
            Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_container);
            if (currentFragment != null && fragmentClass.equals(currentFragment.getClass())) {
                return;
            }

            inflateMenuFromFragment(0);

            try {
                Fragment newFragment = fragmentClass.newInstance();
                getSupportFragmentManager().beginTransaction()
                        .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                        .setTransitionStyle(R.style.Muzei_SimpleFadeFragmentAnimation)
                        .replace(R.id.content_container, newFragment).commitAllowingStateLoss();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> spinner) {
        }
    });

    sectionSpinner.setSelection(mStartSection);

    inflateMenuFromFragment(0);
    mAppBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_get_more_sources:
                try {
                    Intent playStoreIntent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/search?q=Muzei&c=apps"))
                                    .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                    preferPackageForIntent(SettingsActivity.this, playStoreIntent, PLAY_STORE_PACKAGE_NAME);
                    startActivity(playStoreIntent);
                } catch (ActivityNotFoundException activityNotFoundException1) {
                    Toast.makeText(SettingsActivity.this, R.string.play_store_not_found, Toast.LENGTH_LONG)
                            .show();
                }
                return true;

            case R.id.action_about:
                startActivity(new Intent(SettingsActivity.this, AboutActivity.class));
                return true;
            }

            Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_container);
            if (currentFragment != null && currentFragment instanceof SettingsActivityMenuListener) {
                ((SettingsActivityMenuListener) currentFragment).onSettingsActivityMenuItemClick(item);
            }

            return false;
        }
    });
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryActivityBase.java

/**
 * Logic required to open the appropriate View StoryData Fragment/Activity
 * combination to display properly on the phone or tablet.
 *///  w  ww . j  a  v a  2 s.c  om
public void openViewStoryFragment(long index) {
    Log.d(LOG_TAG, "openStoryViewFragment(" + index + ")");
    if (determineDualPane()) {

        Fragment test = getSupportFragmentManager().findFragmentById(R.id.details);

        // Log.d(LOG_TAG, "open view class:" + test.getClass());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (test != null && test.getClass() != StoryViewFragment.class) {
            StoryViewFragment details = StoryViewFragment.newInstance(index);

            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.
            ft.replace(R.id.details, details);

        } else {
            // Check what fragment is shown, replace if needed.
            StoryViewFragment details = (StoryViewFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.details);
            if (details == null || details.getUniqueKey() != index) {
                // Make new fragment to show this selection.
                details = StoryViewFragment.newInstance(index);

            }
            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = newStoryViewIntent(this, index);
        startActivity(intent);
    }
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryActivityBase.java

/**
 * Logic required to open the appropriate Edit StoryData Fragment/Activity
 * combination to display properly on the phone or tablet.
 *//*from w  w w.  ja v a 2  s.  co  m*/
public void openEditStoryFragment(final long index) {
    Log.d(LOG_TAG, "openEditStoryFragment(" + index + ")");
    if (determineDualPane()) {

        Fragment test = getSupportFragmentManager().findFragmentById(R.id.details);

        // Log.d(LOG_TAG, "open view class:" + test.getClass());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (test != null && test.getClass() != EditStoryFragment.class) {
            EditStoryFragment editor = EditStoryFragment.newInstance(index);

            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, editor);

        } else {
            // Check what fragment is shown, replace if needed.
            EditStoryFragment editor = (EditStoryFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.details);
            if (editor == null || editor.getUniqueKey() != index) {
                // Make new fragment to show this selection.
                editor = EditStoryFragment.newInstance(index);

            }
            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, editor);

        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = newEditStoryIntent(this, index);
        startActivity(intent);
    }
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryActivityBase.java

/**
 * Logic required to open the appropriate Create StoryData Fragment/Activity
 * combination to display properly on the phone or tablet.
 *//* w  w  w.j a  va  2  s  .c  o m*/
public void openCreateStoryFragment() {
    Log.d(LOG_TAG, "openCreateStoryFragment");
    if (determineDualPane()) {

        Fragment test = getSupportFragmentManager().findFragmentById(R.id.details);

        // Log.d(LOG_TAG, "open view class:" + test.getClass());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (test != null && test.getClass() != CreateStoryFragment.class) {
            CreateStoryFragment details = CreateStoryFragment.newInstance();

            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        } else {
            // Check what fragment is shown, replace if needed.
            CreateStoryFragment details = (CreateStoryFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.details);
            if (details == null) {
                // Make new fragment to show this selection.
                details = CreateStoryFragment.newInstance();

            }
            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = newCreateStoryIntent(this);
        startActivity(intent);
    }
}

From source file:com.auth0.lock.passwordless.LockPasswordlessActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Log.d(TAG, "onNewIntent username: " + username + " intent: " + intent);

    AppLinkIntentParser linkParser = new AppLinkIntentParser(intent);
    if (username != null && linkParser.isValidAppLinkIntent()) {
        String passcode = linkParser.getCodeFromAppLinkIntent();
        performLogin(new LoginRequestEvent(username, passcode));
    } else {//from   ww w  .j  a  v a  2  s .c  o m
        Fragment fragment = new InvalidLinkFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.com_auth0_container, fragment)
                .addToBackStack(fragment.getClass().getName()).commit();
    }
}

From source file:com.microsoft.azure.engagement.MainActivity.java

/**
 * Method that replaces the current fragment
 *
 * @param item          The new menu item selected
 * @param fragmentClass The new fragment class
 *///from  w  ww  .  j a v a  2  s  .com
private final void replaceFragment(MenuItem item, @NonNull Class<? extends Fragment> fragmentClass) {
    // Hide the in-app layout if it's visible
    hideNotificationOverlay();

    updateSelection(item);

    try {
        final Fragment fragment = fragmentClass.newInstance();

        if (getSupportActionBar() != null) {
            getSupportActionBar().setTitle(item.getTitle());
            getSupportActionBar().setDisplayShowTitleEnabled(fragment instanceof HomeFragment == false);
        }

        final String backStateName = fragment.getClass().getName();

        final FragmentManager fragmentManager = getSupportFragmentManager();
        final boolean fragmentPopped = fragmentManager.popBackStackImmediate(backStateName, 0);

        if (fragmentPopped == false) {
            //fragment not in back stack, create it.
            final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.fragmentPlaceHolder, fragment);
            fragmentTransaction.addToBackStack(backStateName);
            fragmentTransaction.commit();
        }
    } catch (Exception exception) {
        Log.e(MainActivity.TAG,
                "Unable to instantiate the fragment with class '" + fragmentClass.getSimpleName() + "'");
    }
}

From source file:com.tomeokin.lspush.ui.widget.dialog.BaseDialogFragment.java

@SuppressWarnings("unchecked")
protected <T> T getDialogListener(Class<T> listenerInterface) {
    final Fragment targetFragment = getTargetFragment();
    if (targetFragment != null && listenerInterface.isAssignableFrom(targetFragment.getClass())) {
        return (T) targetFragment;
    } else if (getActivity() != null && listenerInterface.isAssignableFrom(getActivity().getClass())) {
        return (T) getActivity();
    }//from w  w w  . j av a  2 s  .co m
    return null;
}

From source file:org.ohmage.activity.test.ResponseHistoryTest.java

private GoogleMap getFragmentMapView() {
    Fragment fragment = ((ResponseHistoryActivity) solo.getCurrentActivity()).getCurrentFragment();
    assertEquals(ResponseMapFragment.class, fragment.getClass());
    ResponseMapFragment mapFragment = (ResponseMapFragment) fragment;
    return mapFragment.getMap();
}