Search in sources :

Example 1 with DLIntent

use of com.ryg.dynamicload.internal.DLIntent in project dynamic-load-apk by singwhatiwanna.

the class MainActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    PluginItem item = mPluginItems.get(position);
    DLPluginManager pluginManager = DLPluginManager.getInstance(this);
    pluginManager.startPluginActivity(this, new DLIntent(item.packageInfo.packageName));
}
Also used : DLPluginManager(com.ryg.dynamicload.internal.DLPluginManager) DLIntent(com.ryg.dynamicload.internal.DLIntent)

Example 2 with DLIntent

use of com.ryg.dynamicload.internal.DLIntent in project dynamic-load-apk by singwhatiwanna.

the class MainActivity method generateContentView.

private View generateContentView(final Context context) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setBackgroundColor(Color.parseColor("#F79AB5"));
    Button button = new Button(context);
    button.setText("Start TestActivity");
    layout.addView(button, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DLIntent intent = new DLIntent(getPackageName(), TestFragmentActivity.class);
            // 传递Parcelable类型的数据
            intent.putExtra("person", new Person("plugin-a", 22));
            intent.putExtra("dl_extra", "from DL framework");
            startPluginActivityForResult(intent, 0);
        }
    });
    Button button2 = new Button(context);
    button2.setText("Start Service");
    layout.addView(button2, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button2.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            DLIntent intent = new DLIntent(getPackageName(), TestService.class);
            startPluginService(intent);
        }
    });
    Button button3 = new Button(context);
    button3.setText("bind Service");
    layout.addView(button3, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mConnecton == null) {
                mConnecton = new ServiceConnection() {

                    public void onServiceDisconnected(ComponentName name) {
                    }

                    public void onServiceConnected(ComponentName name, IBinder binder) {
                        int sum = ((ITestServiceInterface) binder).sum(5, 5);
                        Log.e("MainActivity", "onServiceConnected sum(5 + 5) = " + sum);
                    }
                };
            }
            DLIntent intent = new DLIntent(getPackageName(), TestService.class);
            bindPluginService(intent, mConnecton, Context.BIND_AUTO_CREATE);
        }
    });
    Button button4 = new Button(context);
    button4.setText("unbind Service");
    layout.addView(button4, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button4.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (mConnecton != null) {
                DLIntent intent = new DLIntent(getPackageName(), TestService.class);
                unBindPluginService(intent, mConnecton);
                mConnecton = null;
            }
        }
    });
    return layout;
}
Also used : ServiceConnection(android.content.ServiceConnection) LayoutParams(android.view.ViewGroup.LayoutParams) View(android.view.View) IBinder(android.os.IBinder) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) ComponentName(android.content.ComponentName) ITestServiceInterface(com.ryg.dynamicload.service.ITestServiceInterface) DLIntent(com.ryg.dynamicload.internal.DLIntent) LinearLayout(android.widget.LinearLayout)

Example 3 with DLIntent

use of com.ryg.dynamicload.internal.DLIntent in project dynamic-load-apk by singwhatiwanna.

the class TestFragment method onClick.

@Override
public void onClick(View v) {
    if (v == button1) {
        Context context = getActivity();
        DLIntent dlIntent = new DLIntent(mPluginPackageName, MainActivity.class);
        DLPluginManager.getInstance(context).startPluginActivity(context, dlIntent);
    }
}
Also used : Context(android.content.Context) DLIntent(com.ryg.dynamicload.internal.DLIntent)

Example 4 with DLIntent

use of com.ryg.dynamicload.internal.DLIntent in project dynamic-load-apk by singwhatiwanna.

the class MainActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    PluginItem item = mPluginItems.get(position);
    DLPluginManager pluginManager = DLPluginManager.getInstance(this);
    pluginManager.startPluginActivity(this, new DLIntent(item.packageInfo.packageName, item.launcherActivityName));
    //如果存在Service则调用起Service
    if (item.launcherServiceName != null) {
        //startService
        DLIntent intent = new DLIntent(item.packageInfo.packageName, item.launcherServiceName);
    //startService
    //	        pluginManager.startPluginService(this, intent); 
    //bindService
    //	        pluginManager.bindPluginService(this, intent, mConnection = new ServiceConnection() {
    //                public void onServiceDisconnected(ComponentName name) {
    //                }
    //                
    //                public void onServiceConnected(ComponentName name, IBinder binder) {
    //                    int sum = ((ITestServiceInterface)binder).sum(5, 5);
    //                    Log.e("MainActivity", "onServiceConnected sum(5 + 5) = " + sum);
    //                }
    //            }, Context.BIND_AUTO_CREATE);
    }
}
Also used : DLPluginManager(com.ryg.dynamicload.internal.DLPluginManager) DLIntent(com.ryg.dynamicload.internal.DLIntent)

Example 5 with DLIntent

use of com.ryg.dynamicload.internal.DLIntent in project dynamic-load-apk by singwhatiwanna.

the class TestFragmentActivity method onClick.

@Override
public void onClick(View v) {
    if (v == mShowFragmentButton) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.add(R.id.fragment_container, new TestFragment().setPluginPackageName(getPackageName()));
        transaction.addToBackStack("TestFragment#1");
        transaction.commit();
    } else if (v == mStartPluginB) {
        int result = startPluginActivity(new DLIntent("com.ryg.dynamicload.sample.mainpluginb", ".MainActivity"));
        if (result != DLPluginManager.START_RESULT_SUCCESS) {
            Toast.makeText(this, "start Activity failed", Toast.LENGTH_SHORT).show();
        }
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) DLIntent(com.ryg.dynamicload.internal.DLIntent)

Aggregations

DLIntent (com.ryg.dynamicload.internal.DLIntent)5 DLPluginManager (com.ryg.dynamicload.internal.DLPluginManager)2 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 ServiceConnection (android.content.ServiceConnection)1 IBinder (android.os.IBinder)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 Button (android.widget.Button)1 LinearLayout (android.widget.LinearLayout)1 ITestServiceInterface (com.ryg.dynamicload.service.ITestServiceInterface)1