Search in sources :

Example 26 with FragmentManager

use of android.app.FragmentManager in project AndroidDynamicLoader by mmin18.

the class FragmentLoader method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if ("com.dianping.intent.action.LOAD_FRAGMENT".equals(getIntent().getAction())) {
        // we need to setup environment before super.onCreate
        try {
            String path = getIntent().getStringExtra("path");
            InputStream ins = MyApplication.instance().getAssets().open(path);
            byte[] bytes = new byte[ins.available()];
            ins.read(bytes);
            ins.close();
            File f = new File(MyApplication.instance().getFilesDir(), "dex");
            f.mkdir();
            f = new File(f, "FL_" + Integer.toHexString(path.hashCode()) + ".apk");
            FileOutputStream fos = new FileOutputStream(f);
            fos.write(bytes);
            fos.close();
            File fo = new File(MyApplication.instance().getFilesDir(), "dexout");
            fo.mkdir();
            DexClassLoader dcl = new DexClassLoader(f.getAbsolutePath(), fo.getAbsolutePath(), null, super.getClassLoader());
            cl = dcl;
            try {
                AssetManager am = (AssetManager) AssetManager.class.newInstance();
                am.getClass().getMethod("addAssetPath", String.class).invoke(am, f.getAbsolutePath());
                asm = am;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            Resources superRes = super.getResources();
            res = new Resources(asm, superRes.getDisplayMetrics(), superRes.getConfiguration());
            thm = res.newTheme();
            thm.setTo(super.getTheme());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    super.onCreate(savedInstanceState);
    FrameLayout rootView = new FrameLayout(this);
    rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    rootView.setId(android.R.id.primary);
    setContentView(rootView);
    if (savedInstanceState != null)
        return;
    if ("com.dianping.intent.action.LOAD_FRAGMENT".equals(getIntent().getAction())) {
        try {
            String fragmentClass = getIntent().getStringExtra("class");
            Fragment f = (Fragment) getClassLoader().loadClass(fragmentClass).newInstance();
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(android.R.id.primary, f);
            ft.commit();
        } catch (Exception e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
        }
    } else {
        Fragment f = new ListApkFragment();
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(android.R.id.primary, f);
        ft.commit();
    }
}
Also used : AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) ViewGroup(android.view.ViewGroup) DexClassLoader(dalvik.system.DexClassLoader) Fragment(android.app.Fragment) FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction) FileOutputStream(java.io.FileOutputStream) FrameLayout(android.widget.FrameLayout) Resources(android.content.res.Resources) File(java.io.File)

Example 27 with FragmentManager

use of android.app.FragmentManager in project qksms by moezbhatti.

the class MainActivity method beginMmsSetup.

private void beginMmsSetup() {
    if (!mPrefs.getBoolean(MMS_SETUP_DONT_ASK_AGAIN, false) && TextUtils.isEmpty(mPrefs.getString(SettingsFragment.MMSC_URL, "")) && TextUtils.isEmpty(mPrefs.getString(SettingsFragment.MMS_PROXY, "")) && TextUtils.isEmpty(mPrefs.getString(SettingsFragment.MMS_PORT, ""))) {
        // Launch the MMS setup fragment here. This is a series of dialogs that will guide the
        // user through the MMS setup process.
        FragmentManager manager = getFragmentManager();
        if (manager.findFragmentByTag(MMSSetupFragment.TAG) == null) {
            MMSSetupFragment f = new MMSSetupFragment();
            Bundle args = new Bundle();
            args.putBoolean(MMSSetupFragment.ARG_ASK_FIRST, true);
            args.putString(MMSSetupFragment.ARG_DONT_ASK_AGAIN_PREF, MMS_SETUP_DONT_ASK_AGAIN);
            f.setArguments(args);
            getFragmentManager().beginTransaction().add(f, MMSSetupFragment.TAG).commit();
        }
    }
}
Also used : FragmentManager(android.app.FragmentManager) Bundle(android.os.Bundle) MMSSetupFragment(com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment)

Example 28 with FragmentManager

use of android.app.FragmentManager in project qksms by moezbhatti.

the class ComposeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.title_compose);
    FragmentManager fm = getFragmentManager();
    mComposeFragment = (ComposeFragment) fm.findFragmentByTag(ComposeFragment.TAG);
    if (mComposeFragment == null) {
        mComposeFragment = new ComposeFragment();
    }
    fm.beginTransaction().replace(R.id.content_frame, mComposeFragment, ComposeFragment.TAG).commit();
}
Also used : FragmentManager(android.app.FragmentManager)

Example 29 with FragmentManager

use of android.app.FragmentManager in project FadingActionBar by ManuelPeinado.

the class NavigationDrawerActivity method selectItem.

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new SampleFragment();
    Bundle args = new Bundle();
    args.putInt(SampleFragment.ARG_IMAGE_RES, mCityImages[position]);
    args.putInt(SampleFragment.ARG_ACTION_BG_RES, R.drawable.ab_background);
    fragment.setArguments(args);
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mCityNames[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}
Also used : FragmentManager(android.app.FragmentManager) Bundle(android.os.Bundle) Fragment(android.app.Fragment)

Example 30 with FragmentManager

use of android.app.FragmentManager in project NimbusBase_Android_Tutorial by NimbusBase.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Singleton.CONTEXT = getApplicationContext();
    Singleton.base();
    final FragmentManager fragmentManager = this.getFragmentManager();
    final IndexFragment indexFragment = (IndexFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG_INDEX);
    if (indexFragment == null) {
        final IndexFragment newIndexFragment = new IndexFragment();
        fragmentManager.beginTransaction().replace(android.R.id.content, newIndexFragment, FRAGMENT_TAG_INDEX).commit();
    }
}
Also used : FragmentManager(android.app.FragmentManager)

Aggregations

FragmentManager (android.app.FragmentManager)177 FragmentTransaction (android.app.FragmentTransaction)84 Fragment (android.app.Fragment)51 Bundle (android.os.Bundle)22 DocumentInfo (com.android.documentsui.model.DocumentInfo)20 DialogFragment (android.app.DialogFragment)15 RootInfo (com.android.documentsui.model.RootInfo)15 ActionBar (android.support.v7.app.ActionBar)12 Intent (android.content.Intent)11 File (java.io.File)6 MediaRouter (android.media.MediaRouter)5 Uri (android.net.Uri)5 StorageManager (android.os.storage.StorageManager)5 VolumeInfo (android.os.storage.VolumeInfo)5 MenuItem (android.view.MenuItem)5 IOException (java.io.IOException)5 Toolbar (android.support.v7.widget.Toolbar)4 View (android.view.View)4 DialogInterface (android.content.DialogInterface)3 ViewGroup (android.view.ViewGroup)3