Search in sources :

Example 26 with Fragment

use of android.app.Fragment in project cw-omnibus by commonsguy.

the class MainActivity method showPreso.

private void showPreso(RouteInfo route) {
    if (inline.getVisibility() == View.VISIBLE) {
        inline.setVisibility(View.GONE);
        prose.setText(R.string.secondary);
        Fragment f = getFragmentManager().findFragmentById(R.id.preso);
        getFragmentManager().beginTransaction().remove(f).commit();
    }
    preso = buildPreso(route.getPresentationDisplay());
    preso.show(getFragmentManager(), "preso");
}
Also used : Fragment(android.app.Fragment)

Example 27 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 28 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 29 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)

Example 30 with Fragment

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

the class SettingsFragment method onPreferenceClick.

@Override
public boolean onPreferenceClick(Preference preference) {
    String key = preference.getKey() != null ? preference.getKey() : "";
    AnalyticsManager.getInstance().sendEvent(AnalyticsManager.CATEGORY_PREFERENCE_CLICK, key, null);
    // Categories
    int resId = 0;
    switch(key) {
        case CATEGORY_APPEARANCE:
            resId = R.xml.settings_appearance;
            break;
        case CATEGORY_GENERAL:
            resId = R.xml.settings_general;
            break;
        case CATEGORY_NOTIFICATIONS:
            resId = R.xml.settings_notifications;
            break;
        case CATEGORY_MMS:
            resId = R.xml.settings_mms;
            break;
        case CATEGORY_QUICKREPLY:
            resId = R.xml.settings_quickreply;
            break;
        case CATEGORY_QUICKCOMPOSE:
            resId = R.xml.settings_quickcompose;
            break;
        case CATEGORY_ABOUT:
            resId = R.xml.settings_about;
            break;
    }
    if (resId != 0) {
        Fragment fragment = SettingsFragment.newInstance(resId);
        getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.content_frame, fragment, CATEGORY_TAG).commit();
    }
    switch(key) {
        case THEME:
            ThemeManager.showColorPickerDialog(mContext);
            break;
        case ICON:
            ThemeManager.setIcon(mContext);
            break;
        case BUBBLES:
            new BubblePreferenceDialog().setContext(mContext).show();
            break;
        case BLOCKED_FUTURE:
            BlockedNumberDialog.showDialog(mContext);
            break;
        case SHOULD_I_ANSWER:
            final String packageName = "org.mistergroup.muzutozvednout";
            if (!PackageUtils.isAppInstalled(mContext, packageName)) {
                String referrer = "referrer=utm_source%3Dqksms%26utm_medium%3Dapp%26utm_campaign%3Dqksmssettings";
                new QKDialog().setContext(mContext).setTitle(R.string.dialog_should_i_answer_title).setMessage(R.string.dialog_should_i_answer_message).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.okay, v -> {
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName + "&" + referrer)));
                    } catch (android.content.ActivityNotFoundException anfe) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName + "&" + referrer)));
                    }
                }).show();
                new Handler().postDelayed(() -> {
                    mPrefs.edit().putBoolean(SHOULD_I_ANSWER, false).commit();
                    ((CheckBoxPreference) preference).setChecked(false);
                }, 500);
            }
            break;
        case NOTIFICATION_LED_COLOR:
            mLedColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker");
            break;
        case DAY_START:
        case NIGHT_START:
            TimePickerFragment fragment = new TimePickerFragment();
            fragment.setPreference(preference);
            fragment.setOnPreferenceChangeListener(this);
            fragment.show(getFragmentManager(), "timepicker");
            break;
        case QK_RESPONSES:
            showQkResponseEditor();
            break;
        case AUTOMATICALLY_CONFIGURE_MMS:
            // Show the MMS setup dialogs. See the MMSSetupDialog class for info about what the
            // arguments mean.
            MMSSetupFragment f = new MMSSetupFragment();
            Bundle args = new Bundle();
            args.putBoolean(MMSSetupFragment.ARG_ASK_FIRST, false);
            args.putString(MMSSetupFragment.ARG_DONT_ASK_AGAIN_PREF, null);
            f.setArguments(args);
            getFragmentManager().beginTransaction().add(f, MMSSetupFragment.TAG).commit();
            break;
        case MMS_CONTACT_SUPPORT:
            // Opens an email compose intent with MMS debugging information
            MMSSetupFragment.contactSupport(getActivity());
            break;
        case CHANGELOG:
            DialogHelper.showChangelog(mContext);
            break;
        case THANKS:
            new QKDialog().setContext(mContext).setTitle(R.string.pref_about_thanks_title).setTripleLineItems(R.array.contributor_names, R.array.contributor_githubs, R.array.contributor_projects, new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    String baseUrl = ((QKTextView) view.findViewById(R.id.list_item_subtitle)).getText().toString();
                    startBrowserIntent("https://" + baseUrl);
                }
            }).show();
            break;
        case DONATE:
            DonationManager.getInstance(mContext).showDonateDialog();
            break;
        case GOOGLE_PLUS:
            startBrowserIntent(GOOGLE_PLUS_URL);
            break;
        case GITHUB:
            startBrowserIntent(GITHUB_URL);
            break;
        case CROWDIN:
            startBrowserIntent(CROWDIN_URL);
            break;
    }
    return false;
}
Also used : DateFormatter(com.moez.QKSMS.common.utils.DateFormatter) Arrays(java.util.Arrays) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) MMSSetupFragment(com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment) QKTextView(com.moez.QKSMS.ui.view.QKTextView) Uri(android.net.Uri) PendingIntent(android.app.PendingIntent) PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference) ListviewHelper(com.moez.QKSMS.common.ListviewHelper) Handler(android.os.Handler) LiveViewManager(com.moez.QKSMS.common.LiveViewManager) ColorPickerSwatch(com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch) View(android.view.View) AdapterView(android.widget.AdapterView) PreferenceManager(android.preference.PreferenceManager) DonationManager(com.moez.QKSMS.common.DonationManager) ParseException(java.text.ParseException) PackageUtils(com.moez.QKSMS.common.utils.PackageUtils) Log(android.util.Log) BlockedNumberDialog(com.moez.QKSMS.ui.dialog.BlockedNumberDialog) Set(java.util.Set) AnalyticsManager(com.moez.QKSMS.common.AnalyticsManager) ListPreference(android.preference.ListPreference) PreferenceFragment(android.preference.PreferenceFragment) EndlessJabber(com.moez.QKSMS.transaction.EndlessJabber) ListView(android.widget.ListView) DeleteOldMessagesService(com.moez.QKSMS.service.DeleteOldMessagesService) QKPreferences(com.moez.QKSMS.common.QKPreferences) BubblePreferenceDialog(com.moez.QKSMS.ui.dialog.BubblePreferenceDialog) Context(android.content.Context) QKPreference(com.moez.QKSMS.enums.QKPreference) PreferenceCategory(android.preference.PreferenceCategory) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) PackageInfo(android.content.pm.PackageInfo) QKActivity(com.moez.QKSMS.ui.base.QKActivity) Stack(java.util.Stack) KeyboardUtils(com.moez.QKSMS.common.utils.KeyboardUtils) ArrayList(java.util.ArrayList) R(com.moez.QKSMS.R) HashSet(java.util.HashSet) Calendar(java.util.Calendar) ColorPickerDialog(com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) DialogHelper(com.moez.QKSMS.common.DialogHelper) Build(android.os.Build) Fragment(android.app.Fragment) ThemeManager(com.moez.QKSMS.ui.ThemeManager) AlarmManager(android.app.AlarmManager) EndlessJabberInterface(com.mariussoft.endlessjabber.sdk.EndlessJabberInterface) NotificationManager(com.moez.QKSMS.transaction.NotificationManager) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) SmsHelper(com.moez.QKSMS.transaction.SmsHelper) Collections(java.util.Collections) Resources(android.content.res.Resources) NightModeAutoReceiver(com.moez.QKSMS.receiver.NightModeAutoReceiver) CheckBoxPreference(android.preference.CheckBoxPreference) Bundle(android.os.Bundle) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) MMSSetupFragment(com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment) PreferenceFragment(android.preference.PreferenceFragment) Fragment(android.app.Fragment) MMSSetupFragment(com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment) QKTextView(com.moez.QKSMS.ui.view.QKTextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) BubblePreferenceDialog(com.moez.QKSMS.ui.dialog.BubblePreferenceDialog) AdapterView(android.widget.AdapterView)

Aggregations

Fragment (android.app.Fragment)209 FragmentTransaction (android.app.FragmentTransaction)82 FragmentManager (android.app.FragmentManager)51 DialogFragment (android.app.DialogFragment)44 Bundle (android.os.Bundle)22 Intent (android.content.Intent)13 View (android.view.View)13 PreferenceFragment (android.support.v14.preference.PreferenceFragment)12 TextView (android.widget.TextView)8 BizFragment (org.aisen.weibo.sina.ui.fragment.base.BizFragment)8 Uri (android.net.Uri)6 ABaseFragment (org.aisen.android.ui.fragment.ABaseFragment)6 Activity (android.app.Activity)5 PreferenceFragment (android.preference.PreferenceFragment)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ViewGroup (android.view.ViewGroup)3 FrameLayout (android.widget.FrameLayout)3 ContactVcardViewerFragment (com.xabber.android.ui.fragment.ContactVcardViewerFragment)3 Method (java.lang.reflect.Method)3