Android Open Source - AndroidPlugin Main Activity






From Project

Back to project page AndroidPlugin.

License

The source code is released under:

MIT License

If you think the Android project AndroidPlugin listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package androidx.plmgrdemo;
//from w  w  w  .j  a  v  a  2s . co m
import java.io.File;
import java.util.Collection;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import androidx.pluginmgr.PlugInfo;
import androidx.pluginmgr.PluginManager;

public class MainActivity extends Activity {
    // private EditText pluginDirTxt;
    // private Button pluginLoader;
    private ListView pluglistView;
    //
    private PluginManager plugMgr;

    private static final String sdcard = Environment
            .getExternalStorageDirectory().getPath();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final EditText pluginDirTxt = (EditText) findViewById(R.id.pluginDirTxt);
        Button pluginLoader = (Button) findViewById(R.id.pluginLoader);
        pluglistView = (ListView) findViewById(R.id.pluglist);

        plugMgr = PluginManager.getInstance(this);

        String pluginSrcDir = sdcard + "/Download";
        pluginDirTxt.setText(pluginSrcDir);

        pluglistView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                plugItemClick(position);
            }
        });

        final Context context = this;
        pluginLoader.setOnClickListener(new View.OnClickListener() {
            private volatile boolean plugLoading = false;

            @Override
            public void onClick(View v) {
                final String dirText = pluginDirTxt.getText().toString().trim();
                if (TextUtils.isEmpty(dirText)) {
                    Toast.makeText(context, getString(R.string.pl_dir),
                            Toast.LENGTH_LONG).show();
                    return;
                }
                if (plugLoading) {
                    Toast.makeText(context, getString(R.string.loading),
                            Toast.LENGTH_LONG).show();
                    return;
                }
                String strDialogTitle = getString(R.string.dialod_loading_title);
                String strDialogBody = getString(R.string.dialod_loading_body);
                final ProgressDialog dialogLoading = ProgressDialog.show(
                        context, strDialogTitle, strDialogBody, true);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        plugLoading = true;
                        try {
                            Collection<PlugInfo> plugs = plugMgr
                                    .loadPlugin(new File(dirText));
                            setPlugins(plugs);
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            dialogLoading.dismiss();
                        }
                        plugLoading = false;
                    }
                }).start();
            }
        });
    }

    private void plugItemClick(int position) {
        PlugInfo plug = (PlugInfo) pluglistView.getItemAtPosition(position);
        plugMgr.startMainActivity(this, plug.getPackageName());
    }

    private void setPlugins(final Collection<PlugInfo> plugs) {
        if (plugs == null || plugs.isEmpty()) {
            return;
        }
        final ListAdapter adapter = new PlugListViewAdapter(this, plugs);
        runOnUiThread(new Runnable() {
            public void run() {
                pluglistView.setAdapter(adapter);
            }
        });
    }
}




Java Source Code List

android.widget.ViewStub.java
androidx.plmgrdemo.MainActivity.java
androidx.plmgrdemo.PlugListViewAdapter.java
androidx.pluginmgr.ActivityClassGenerator.java
androidx.pluginmgr.ActivityOverider.java
androidx.pluginmgr.FileUtil.java
androidx.pluginmgr.FrameworkClassLoader.java
androidx.pluginmgr.LayoutInflaterWrapper.java
androidx.pluginmgr.PlugInfo.java
androidx.pluginmgr.PluginActivityLifeCycleCallback.java
androidx.pluginmgr.PluginClassLoader.java
androidx.pluginmgr.PluginContextWrapper.java
androidx.pluginmgr.PluginManager.java
androidx.pluginmgr.PluginManifestUtil.java
androidx.pluginmgr.ReflectionUtils.java
androidx.pluginmgr.XmlManifestReader.java
com.limemobile.app.demo.pluginclienta.ClientABindService.java
com.limemobile.app.demo.pluginclienta.ClientAStartedService.java
com.limemobile.app.demo.pluginclienta.MainActivity.java
com.limemobile.app.demo.pluginclienta.TestButton.java
com.limemobile.app.demo.pluginclienta.TestFragmentActivity.java
com.limemobile.app.demo.pluginclienta.TestFragment.java
com.limemobile.app.demo.pluginclientb.ClientBStartedService.java
com.limemobile.app.demo.pluginclientb.MainActivity.java
com.limemobile.app.demo.pluginhost.HostBindService.java
com.limemobile.app.demo.pluginhost.HostStartedService.java
com.limemobile.app.demo.pluginhost.MainActivity.java
com.limemobile.app.demo.pluginhost.MyApplication.java
com.limemobile.app.demo.pluginhost.TestHostClass.java
com.limemobile.app.plugin.IPluginActivity.java
com.limemobile.app.plugin.IPluginContentProvider.java
com.limemobile.app.plugin.IPluginService.java
com.limemobile.app.plugin.PluginClientActivity.java
com.limemobile.app.plugin.PluginClientFragmentActivity.java
com.limemobile.app.plugin.PluginClientService.java
com.limemobile.app.plugin.PluginHostApplication.java
com.limemobile.app.plugin.PluginHostContentProvider.java
com.limemobile.app.plugin.PluginHostDelegateActivity.java
com.limemobile.app.plugin.PluginHostDelegateContentProvider.java
com.limemobile.app.plugin.PluginHostDelegateFragmentActivity.java
com.limemobile.app.plugin.PluginHostDelegateService.java
com.limemobile.app.plugin.internal.IPluginActivityDelegate.java
com.limemobile.app.plugin.internal.IPluginContentProviderDelegate.java
com.limemobile.app.plugin.internal.IPluginServiceDelegate.java
com.limemobile.app.plugin.internal.PluginClientDexClassLoader.java
com.limemobile.app.plugin.internal.PluginClientInfo.java
com.limemobile.app.plugin.internal.PluginClientManager.java
com.limemobile.app.plugin.internal.PluginDelegateActivityImpl.java
com.limemobile.app.plugin.internal.PluginDelegateContentProviderImpl.java
com.limemobile.app.plugin.internal.PluginDelegateServiceImpl.java
com.limemobile.app.plugin.internal.ReflectFieldAccessor.java