Search in sources :

Example 16 with Fragment

use of android.app.Fragment in project k-9 by k9mail.

the class CryptoInfoDialog method onCreateDialog.

// inflating without root element is fine for creating a dialog
@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Builder b = new AlertDialog.Builder(getActivity());
    dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.message_crypto_info_dialog, null);
    topIconFrame = dialogView.findViewById(R.id.crypto_info_top_frame);
    topIcon_1 = (ImageView) topIconFrame.findViewById(R.id.crypto_info_top_icon_1);
    topIcon_2 = (ImageView) topIconFrame.findViewById(R.id.crypto_info_top_icon_2);
    topIcon_3 = (ImageView) topIconFrame.findViewById(R.id.crypto_info_top_icon_3);
    topText = (TextView) dialogView.findViewById(R.id.crypto_info_top_text);
    bottomIconFrame = dialogView.findViewById(R.id.crypto_info_bottom_frame);
    bottomIcon_1 = (ImageView) bottomIconFrame.findViewById(R.id.crypto_info_bottom_icon_1);
    bottomIcon_2 = (ImageView) bottomIconFrame.findViewById(R.id.crypto_info_bottom_icon_2);
    bottomText = (TextView) dialogView.findViewById(R.id.crypto_info_bottom_text);
    MessageCryptoDisplayStatus displayStatus = MessageCryptoDisplayStatus.valueOf(getArguments().getString(ARG_DISPLAY_STATUS));
    setMessageForDisplayStatus(displayStatus);
    b.setView(dialogView);
    b.setPositiveButton(R.string.crypto_info_ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dismiss();
        }
    });
    if (displayStatus.hasAssociatedKey()) {
        b.setNeutralButton(R.string.crypto_info_view_key, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Fragment frag = getTargetFragment();
                if (!(frag instanceof OnClickShowCryptoKeyListener)) {
                    throw new AssertionError("Displaying activity must implement OnClickShowCryptoKeyListener!");
                }
                ((OnClickShowCryptoKeyListener) frag).onClickShowCryptoKey();
            }
        });
    }
    return b.create();
}
Also used : DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) MessageCryptoDisplayStatus(com.fsck.k9.view.MessageCryptoDisplayStatus) OnClickListener(android.content.DialogInterface.OnClickListener) Fragment(android.app.Fragment) DialogFragment(android.app.DialogFragment) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 17 with Fragment

use of android.app.Fragment in project superCleanMaster by joyoyao.

the class DialogUtil method removeDialog.

/**
	 * 描述:移除Fragment.
	 * 
	 * @param context
	 *            the context
	 */
public static void removeDialog(Context context) {
    try {
        FragmentActivity activity = (FragmentActivity) context;
        FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
        // 指定一个系统转场动画
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        Fragment prev = activity.getFragmentManager().findFragmentByTag(mDialogTag);
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);
        ft.commit();
    } catch (Exception e) {
        // 可能有Activity已经被销毁的异常
        e.printStackTrace();
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) FragmentTransaction(android.app.FragmentTransaction) Fragment(android.app.Fragment)

Example 18 with Fragment

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

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    int error = 0;
    // must be load at the first start
    do {
        site = intent.getParcelableExtra("_site");
        if (site == null) {
            // #201
            error = 201;
            break;
        }
        fragmentName = intent.getStringExtra("_fragment");
        if (TextUtils.isEmpty(fragmentName)) {
            // #202
            error = 202;
            break;
        }
        String code = intent.getStringExtra("_code");
        if (TextUtils.isEmpty(code)) {
            loaded = true;
            break;
        }
        file = site.getFile(code);
        if (file == null) {
            // #205
            error = 205;
            break;
        }
        classLoader = MyClassLoader.getClassLoader(site, file);
        loaded = classLoader != null;
        if (!loaded) {
            // #210
            error = 210;
            break;
        }
    } while (false);
    super.onCreate(savedInstanceState);
    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 (!loaded) {
        TextView text = new TextView(this);
        text.setText("无法载入页面" + (error == 0 ? "" : " #" + error));
        text.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
        rootView.addView(text);
        return;
    }
    // the fragment will be restored by framework
    if (savedInstanceState != null)
        return;
    Fragment fragment = null;
    try {
        fragment = (Fragment) getClassLoader().loadClass(fragmentName).newInstance();
    } catch (Exception e) {
        loaded = false;
        classLoader = null;
        // #211
        error = 211;
        TextView text = new TextView(this);
        text.setText("无法载入页面 #" + error);
        text.append("\n" + e);
        text.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
        rootView.addView(text);
        return;
    }
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(android.R.id.primary, fragment);
    ft.commit();
}
Also used : ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) Fragment(android.app.Fragment) FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView)

Example 19 with Fragment

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

the class FragmentDeveloper method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    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) {
        Fragment f = new SampleFragment();
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(android.R.id.primary, f);
        ft.commit();
    }
}
Also used : FragmentManager(android.app.FragmentManager) SampleFragment(com.dianping.example.fragment.SampleFragment) FragmentTransaction(android.app.FragmentTransaction) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) Fragment(android.app.Fragment) SampleFragment(com.dianping.example.fragment.SampleFragment)

Example 20 with Fragment

use of android.app.Fragment 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)

Aggregations

Fragment (android.app.Fragment)183 FragmentTransaction (android.app.FragmentTransaction)65 DialogFragment (android.app.DialogFragment)42 FragmentManager (android.app.FragmentManager)34 Bundle (android.os.Bundle)18 PreferenceFragment (android.support.v14.preference.PreferenceFragment)12 Intent (android.content.Intent)11 View (android.view.View)11 BizFragment (org.aisen.weibo.sina.ui.fragment.base.BizFragment)8 TextView (android.widget.TextView)6 ABaseFragment (org.aisen.android.ui.fragment.ABaseFragment)6 Uri (android.net.Uri)5 PreferenceFragment (android.preference.PreferenceFragment)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 ViewGroup (android.view.ViewGroup)3 FrameLayout (android.widget.FrameLayout)3 Method (java.lang.reflect.Method)3 APagingFragment (org.aisen.android.ui.fragment.APagingFragment)3