Android Open Source - AndroidPlugin Plugin Client Fragment 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

/*
 * Copyright (C) 2014 achellies/*  w  ww  .  java2  s .  c  o m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.limemobile.app.plugin;

import java.util.List;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;

import com.limemobile.app.plugin.internal.PluginClientInfo;
import com.limemobile.app.plugin.internal.PluginClientManager;

public class PluginClientFragmentActivity extends FragmentActivity implements
    IPluginActivity {
  protected Activity mContext;

  protected FragmentActivity mProxyActivity;

  protected PluginClientInfo mPluginPackage;

  @Override
  public void setDelegate(Activity proxyActivity,
      PluginClientInfo pluginPackage) {
    mProxyActivity = (FragmentActivity) proxyActivity;
    mPluginPackage = pluginPackage;
    mContext = mProxyActivity;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    if (mProxyActivity == null) {
      mContext = this;
      super.onCreate(savedInstanceState);
    }
  }

  @Override
  public void setContentView(View view) {
    if (mProxyActivity == null) {
      super.setContentView(view);
    } else {
      mProxyActivity.setContentView(view);
    }
  }

  @Override
  public void setContentView(View view, LayoutParams params) {
    if (mProxyActivity == null) {
      super.setContentView(view, params);
    } else {
      mProxyActivity.setContentView(view, params);
    }
  }

  @Override
  public void setContentView(int layoutResID) {
    if (mProxyActivity == null) {
      super.setContentView(layoutResID);
    } else {
      mProxyActivity.setContentView(layoutResID);
    }
  }

  @Override
  public void addContentView(View view, LayoutParams params) {
    if (mProxyActivity == null) {
      super.addContentView(view, params);
    } else {
      mProxyActivity.addContentView(view, params);
    }
  }

  @Override
  public View findViewById(int id) {
    if (mProxyActivity == null) {
      return super.findViewById(id);
    } else {
      return mProxyActivity.findViewById(id);
    }
  }

  @Override
  public Intent getIntent() {
    if (mProxyActivity == null) {
      return super.getIntent();
    } else {
      return mProxyActivity.getIntent();
    }
  }

  @Override
  public ClassLoader getClassLoader() {
    if (mProxyActivity == null) {
      return super.getClassLoader();
    } else {
      return mProxyActivity.getClassLoader();
    }
  }

  @Override
  public Resources getResources() {
    if (mProxyActivity == null) {
      return super.getResources();
    } else {
      return mProxyActivity.getResources();
    }
  }

  @Override
  public String getPackageName() {
    if (mProxyActivity == null) {
      return super.getPackageName();
    } else {
      return mPluginPackage.mPackageName;
    }
  }

  @Override
  public LayoutInflater getLayoutInflater() {
    if (mProxyActivity == null) {
      return super.getLayoutInflater();
    } else {
      return mProxyActivity.getLayoutInflater();
    }
  }

  @Override
  public MenuInflater getMenuInflater() {
    if (mProxyActivity == null) {
      return super.getMenuInflater();
    } else {
      return mProxyActivity.getMenuInflater();
    }
  }

  @Override
  public SharedPreferences getSharedPreferences(String name, int mode) {
    if (mProxyActivity == null) {
      return super.getSharedPreferences(name, mode);
    } else {
      return mProxyActivity.getSharedPreferences(name, mode);
    }
  }

  @Override
  public Context getApplicationContext() {
    if (mProxyActivity == null) {
      return super.getApplicationContext();
    } else {
      return mProxyActivity.getApplicationContext();
    }
  }

  @Override
  public WindowManager getWindowManager() {
    if (mProxyActivity == null) {
      return super.getWindowManager();
    } else {
      return mProxyActivity.getWindowManager();
    }
  }

  @Override
  public Window getWindow() {
    if (mProxyActivity == null) {
      return super.getWindow();
    } else {
      return mProxyActivity.getWindow();
    }
  }

  @Override
  public Object getSystemService(String name) {
    if (mProxyActivity == null) {
      return super.getSystemService(name);
    } else {
      return mProxyActivity.getSystemService(name);
    }
  }

  @Override
  public void finish() {
    if (mProxyActivity == null) {
      super.finish();
    } else {
      mProxyActivity.finish();
    }
  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (mProxyActivity == null) {
      super.onActivityResult(requestCode, resultCode, data);
    }
  }

  @Override
  public void onBackPressed() {
    if (mProxyActivity == null) {
      super.onBackPressed();
    }
  }

  @Override
  public void onStart() {
    if (mProxyActivity == null) {
      super.onStart();
    }
  }

  @Override
  public void onRestart() {
    if (mProxyActivity == null) {
      super.onRestart();
    }
  }

  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    if (mProxyActivity == null) {
      super.onRestoreInstanceState(savedInstanceState);
    }
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    if (mProxyActivity == null) {
      super.onSaveInstanceState(outState);
    }
  }

  public void onNewIntent(Intent intent) {
    if (mProxyActivity == null) {
      super.onNewIntent(intent);
    }
  }

  @Override
  public void onResume() {
    if (mProxyActivity == null) {
      super.onResume();
    }
  }

  @Override
  public void onPause() {
    if (mProxyActivity == null) {
      super.onPause();
    }
  }

  @Override
  public void onStop() {
    if (mProxyActivity == null) {
      super.onStop();
    }
  }

  @Override
  public void onDestroy() {
    if (mProxyActivity == null) {
      super.onDestroy();
    }
  }

  public boolean onTouchEvent(MotionEvent event) {
    if (mProxyActivity == null) {
      return super.onTouchEvent(event);
    }
    return false;
  }

  public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (mProxyActivity == null) {
      return super.onKeyUp(keyCode, event);
    }
    return false;
  }

  public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
    if (mProxyActivity == null) {
      super.onWindowAttributesChanged(params);
    }
  }

  public void onWindowFocusChanged(boolean hasFocus) {
    if (mProxyActivity == null) {
      super.onWindowFocusChanged(hasFocus);
    }
  }

  public boolean onCreateOptionsMenu(Menu menu) {
    if (mProxyActivity == null) {
      return super.onCreateOptionsMenu(menu);
    }
    return true;
  }

  public boolean onOptionsItemSelected(MenuItem item) {
    if (mProxyActivity == null) {
      return onOptionsItemSelected(item);
    }
    return false;
  }

  @Override
  public void unbindService(ServiceConnection conn) {
    if (mProxyActivity == null) {
      super.unbindService(conn);
      return;
    }
    mProxyActivity.unbindService(conn);
  }

  @Override
  public void startActivityForResult(Intent intent, int requestCode) {
    if (mProxyActivity == null) {
      super.startActivityForResult(intent, requestCode);
      return;
    }

    List<ResolveInfo> resolveInfos = mContext.getPackageManager()
        .queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
      super.startActivityForResult(intent, requestCode);
    } else {
      intent.setPackage(mPluginPackage.mPackageName);
      PluginClientManager.sharedInstance(mContext)
          .startActivityForResult(mContext, intent, requestCode);
    }
  }

  @Override
  public void startActivityForResult(Intent intent, int requestCode,
      Bundle options) {
    if (mProxyActivity == null) {
      super.startActivityForResult(intent, requestCode, options);
      return;
    }

    List<ResolveInfo> resolveInfos = mContext.getPackageManager()
        .queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
      super.startActivityForResult(intent, requestCode, options);
    } else {
      intent.setPackage(mPluginPackage.mPackageName);
      PluginClientManager.sharedInstance(mContext)
          .startActivityForResult(mContext, intent, requestCode,
              options);
    }
  }

  @Override
  public void startActivity(Intent intent) {
    if (mProxyActivity == null) {
      super.startActivity(intent);
    }

    List<ResolveInfo> resolveInfos = mContext.getPackageManager()
        .queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
      super.startActivity(intent);
    } else {
      intent.setPackage(mPluginPackage.mPackageName);
      PluginClientManager.sharedInstance(mContext).startActivity(
          mContext, intent);
    }
  }

  @Override
  public void startActivity(Intent intent, Bundle options) {
    if (mProxyActivity == null) {
      super.startActivity(intent, options);
    }

    List<ResolveInfo> resolveInfos = mContext.getPackageManager()
        .queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
      super.startActivity(intent, options);
    } else {
      intent.setPackage(mPluginPackage.mPackageName);
      PluginClientManager.sharedInstance(mContext).startActivity(
          mContext, intent, options);
    }
  }

  @Override
  public ComponentName startService(Intent service) {
    if (mProxyActivity == null) {
      return super.startService(service);
    }
    List<ResolveInfo> resolveInfos = mContext
        .getPackageManager()
        .queryIntentServices(service, PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
      return super.startService(service);
    } else {
      service.setPackage(mPluginPackage.mPackageName);
      return PluginClientManager.sharedInstance(mContext).startService(
          mContext, service);
    }
  }

  @Override
  public boolean stopService(Intent service) {
    if (mProxyActivity == null) {
      return super.stopService(service);
    }
    List<ResolveInfo> resolveInfos = mContext
        .getPackageManager()
        .queryIntentServices(service, PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && !resolveInfos.isEmpty()) {
      return super.stopService(service);
    } else {
      service.setPackage(mPluginPackage.mPackageName);
      return PluginClientManager.sharedInstance(mContext).stopService(
          mContext, service);
    }
  }

  @Override
  public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    if (mProxyActivity == null) {
      return super.bindService(service, conn, flags);
    } else {
      return mProxyActivity.bindService(service, conn, flags);
    }
  }

  // ------------------------------------------------------------------------
  // methods override from FragmentActivity
  // ------------------------------------------------------------------------

  @Override
  public FragmentManager getSupportFragmentManager() {
    if (mProxyActivity == null) {
      return super.getSupportFragmentManager();
    }
    return mProxyActivity.getSupportFragmentManager();
  }

  @Override
  public LoaderManager getSupportLoaderManager() {
    if (mProxyActivity == null) {
      return super.getSupportLoaderManager();
    }
    return mProxyActivity.getSupportLoaderManager();
  }

}




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