Search in sources :

Example 76 with FrameLayout

use of android.widget.FrameLayout 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 77 with FrameLayout

use of android.widget.FrameLayout 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 78 with FrameLayout

use of android.widget.FrameLayout 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 79 with FrameLayout

use of android.widget.FrameLayout in project nmid-headline by miao1007.

the class PlatformListPage method initPageView.

private void initPageView() {
    flPage = new FrameLayout(getContext());
    flPage.setOnClickListener(this);
    flPage.setBackgroundDrawable(new ColorDrawable(0x55000000));
    // container of the platform gridview
    llPage = new LinearLayout(getContext()) {

        public boolean onTouchEvent(MotionEvent event) {
            return true;
        }
    };
    llPage.setOrientation(LinearLayout.VERTICAL);
    llPage.setBackgroundDrawable(new ColorDrawable(0xffffffff));
    FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    lpLl.gravity = Gravity.BOTTOM;
    llPage.setLayoutParams(lpLl);
    flPage.addView(llPage);
    // gridview
    grid = new PlatformGridView(getContext());
    grid.setEditPageBackground(getBackgroundView());
    LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    grid.setLayoutParams(lpWg);
    llPage.addView(grid);
    // cancel button
    btnCancel = new Button(getContext());
    btnCancel.setTextColor(0xff3a65ff);
    btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    int resId = getStringRes(getContext(), "cancel");
    if (resId > 0) {
        btnCancel.setText(resId);
    }
    btnCancel.setPadding(0, 0, 0, com.mob.tools.utils.R.dipToPx(getContext(), 5));
    resId = getBitmapRes(getContext(), "classic_platform_corners_bg");
    if (resId > 0) {
        btnCancel.setBackgroundResource(resId);
    } else {
        btnCancel.setBackgroundDrawable(new ColorDrawable(0xffffffff));
    }
    LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, com.mob.tools.utils.R.dipToPx(getContext(), 45));
    int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10);
    lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10);
    btnCancel.setLayoutParams(lpBtn);
    llPage.addView(btnCancel);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout) MotionEvent(android.view.MotionEvent)

Example 80 with FrameLayout

use of android.widget.FrameLayout in project openkit-android by OpenKit.

the class WebDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            sendCancelToListener();
        }
    });
    spinner = new ProgressDialog(getContext());
    spinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
    spinner.setMessage(getContext().getString(R.string.com_facebook_loading));
    spinner.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            sendCancelToListener();
            WebDialog.this.dismiss();
        }
    });
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    contentFrameLayout = new FrameLayout(getContext());
    // First calculate how big the frame layout should be
    calculateSize();
    getWindow().setGravity(Gravity.CENTER);
    // resize the dialog if the soft keyboard comes up
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    /* Create the 'x' image, but don't add to the contentFrameLayout layout yet
         * at this point, we only need to know its drawable width and height
         * to place the webview
         */
    createCrossImage();
    /* Now we know 'x' drawable width and height,
         * layout the webview and add it the contentFrameLayout layout
         */
    int crossWidth = crossImageView.getDrawable().getIntrinsicWidth();
    setUpWebView(crossWidth / 2 + 1);
    /* Finally add the 'x' image to the contentFrameLayout layout and
        * add contentFrameLayout to the Dialog view
        */
    contentFrameLayout.addView(crossImageView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    setContentView(contentFrameLayout);
}
Also used : DialogInterface(android.content.DialogInterface) FrameLayout(android.widget.FrameLayout) ProgressDialog(android.app.ProgressDialog) SuppressLint(android.annotation.SuppressLint)

Aggregations

FrameLayout (android.widget.FrameLayout)634 View (android.view.View)244 TextView (android.widget.TextView)143 ViewGroup (android.view.ViewGroup)128 ImageView (android.widget.ImageView)95 LinearLayout (android.widget.LinearLayout)89 ListView (android.widget.ListView)54 AdapterView (android.widget.AdapterView)49 Button (android.widget.Button)44 LayoutInflater (android.view.LayoutInflater)42 Bitmap (android.graphics.Bitmap)41 LayoutParams (android.view.ViewGroup.LayoutParams)37 AbsListView (android.widget.AbsListView)37 Context (android.content.Context)35 Intent (android.content.Intent)28 Activity (android.app.Activity)25 TextureView (android.view.TextureView)25 ColorDrawable (android.graphics.drawable.ColorDrawable)23 FileOutputStream (java.io.FileOutputStream)23 Drawable (android.graphics.drawable.Drawable)20