Example usage for java.lang.ref WeakReference WeakReference

List of usage examples for java.lang.ref WeakReference WeakReference

Introduction

In this page you can find the example usage for java.lang.ref WeakReference WeakReference.

Prototype

public WeakReference(T referent) 

Source Link

Document

Creates a new weak reference that refers to the given object.

Usage

From source file:co.carlosandresjimenez.android.gotit.TabLayoutOnPageChangeListener.java

public TabLayoutOnPageChangeListener(TabLayout tabLayout) {
    mTabLayoutRef = new WeakReference<>(tabLayout);
}

From source file:com.example.pagergallerysample.PagerGalleryAdapter.java

public PagerGalleryAdapter(Context context) {
    super();//from   ww  w  .j a  v  a  2s  . c om
    mContext = new WeakReference<Context>(context);
    mInflater = LayoutInflater.from(mContext.get());
}

From source file:com.flc.app3.utils.FragmentPagerItemAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    Object item = super.instantiateItem(container, position);
    if (item instanceof Fragment) {
        holder.put(position, new WeakReference<Fragment>((Fragment) item));
    }/*w w  w  .  j a  va 2  s . c  om*/
    return item;
}

From source file:com.almende.eve.test.TestDelete.java

/**
 * Test agents./*from  w w  w .  j a  v a  2  s  . c o m*/
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws URISyntaxException
 *             the URI syntax exception
 * @throws InterruptedException
 *             the interrupted exception
 */
@Test
public void testDelete() throws IOException, URISyntaxException, InterruptedException {

    HttpTransportConfig transportConfig = new HttpTransportConfig();
    transportConfig.setServletUrl("http://localhost:8080/agents/");

    transportConfig.setServletLauncher("JettyLauncher");
    ObjectNode jettyParms = JOM.createObjectNode();
    jettyParms.put("port", 8080);
    transportConfig.set("jetty", jettyParms);

    AgentConfig config = new AgentConfig("example");
    config.addTransport(transportConfig);

    ExampleAgent agent = new ExampleAgent();
    agent.setConfig(config);

    transportConfig = null;
    config = null;

    WeakReference<Agent> test = new WeakReference<Agent>(agent);
    agent.destroy();
    agent = null;

    System.gc();
    System.gc();
    try {
        Thread.sleep(1000);
    } catch (final InterruptedException e) {
    }
    System.gc();
    System.gc();

    assertNull(test.get());

    //      LOG.warning("Sleeping for profiler connection.");
    //      try {
    //         Thread.sleep(20000);
    //      } catch (final InterruptedException e) {}
}

From source file:com.activiti.android.ui.fragments.common.RefreshHelper.java

public RefreshHelper(Activity activity, final RefreshFragment fragment, View rootView) {
    if (rootView == null) {
        return;//  www  . j a va2s . c  o  m
    }
    fragmentRef = new WeakReference<>(fragment);
    swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.ptr_layout);

    if (AccessibilityUtils.isEnabled(activity)) {
        swipeLayout.setEnabled(false);
        swipeLayout.setRefreshing(false);
    } else {
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorSchemeResources(R.color.alfresco_lime, R.color.alfresco_soil,
                R.color.alfresco_tangerine, R.color.alfresco_sky);
    }
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterComposingActionBarView.java

public MessageCenterComposingActionBarView(final Context activityContext, final MessageCenterComposingItem item,
        final MessageAdapter.OnListviewItemActionListener listener) {
    super(activityContext);
    this.listenerRef = new WeakReference<MessageAdapter.OnListviewItemActionListener>(listener);

    LayoutInflater inflater = LayoutInflater.from(activityContext);
    inflater.inflate(R.layout.apptentive_message_center_composing_actionbar, this);

    View closeButton = findViewById(R.id.cancel_composing);
    closeButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            MessageAdapter.OnListviewItemActionListener locallistener = listenerRef.get();
            if (locallistener == null) {
                return;
            }//  w  ww.jav  a 2  s.  c om
            if (showConfirmation) {
                CloseConfirmationDialog editNameDialog = new CloseConfirmationDialog();
                Bundle bundle = new Bundle();
                bundle.putString("STR_2", item.str_2);
                bundle.putString("STR_3", item.str_3);
                bundle.putString("STR_4", item.str_4);
                editNameDialog.setArguments(bundle);
                editNameDialog.show(((ApptentiveInternalActivity) activityContext).getSupportFragmentManager(),
                        "CloseConfirmationDialog");
            } else {
                locallistener.onCancelComposing();
            }
        }
    });

    TextView composing = (TextView) findViewById(R.id.composing);

    if (item.str_1 != null) {
        composing.setText(item.str_1);
    }

    sendButton = (ImageButton) findViewById(R.id.btn_send_message);
    if (item.button_1 != null) {
        sendButton.setContentDescription(item.button_1);
    }
    sendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            MessageAdapter.OnListviewItemActionListener locallistener = listenerRef.get();
            if (locallistener == null) {
                return;
            }
            locallistener.onFinishComposing();
        }
    });

    sendButton.setEnabled(false);
    sendButton.setColorFilter(Util.getThemeColorFromAttrOrRes(activityContext,
            R.attr.apptentive_material_disabled_icon, R.color.apptentive_material_dark_disabled_icon));

    attachButton = (ImageButton) findViewById(R.id.btn_attach_image);
    // Android devices can't take screenshots until Android OS version 4+
    boolean canTakeScreenshot = Util.getMajorOsVersion() >= 4;
    if (canTakeScreenshot) {
        attachButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                MessageAdapter.OnListviewItemActionListener locallistener = listenerRef.get();
                if (locallistener == null) {
                    return;
                }
                locallistener.onAttachImage();
            }
        });
    } else {
        attachButton.setVisibility(GONE);
    }
}

From source file:com.esminis.server.library.permission.PermissionRequester.java

public Observable<Void> request(Activity activity, final String permission) {
    final WeakReference<Activity> activityReference = new WeakReference<>(activity);
    return Observable.create(new Observable.OnSubscribe<Void>() {
        @Override/* w  w  w.  j  a  v  a 2s .co  m*/
        public void call(Subscriber<? super Void> subscriber) {
            final Activity activity = activityReference.get();
            if (activity == null) {
                subscriber.onError(new PermissionRequestFailed(PermissionRequestFailed.ACTIVITY_NOT_AVAILABLE));
            } else if (permission == null) {
                subscriber.onError(
                        new PermissionRequestFailed(PermissionRequestFailed.DENIED_INVALID_PERMISSION));
            } else if (hasPermission(activity, permission)) {
                subscriber.onNext(null);
                subscriber.onCompleted();
            } else {
                synchronized (lock) {
                    if (subscriberInProgress != null) {
                        subscriber.onError(new PermissionRequestFailed(
                                PermissionRequestFailed.DENIED_ANOTHER_REQUEST_IN_PROGRESS));
                        return;
                    }
                    showExplanation = ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
                    subscriberInProgress = subscriber;
                }
                ActivityCompat.requestPermissions(activity, new String[] { permission },
                        REQUEST_CODE_PERMISSION);
            }
        }
    }).subscribeOn(AndroidSchedulers.mainThread()).observeOn(AndroidSchedulers.mainThread());
}

From source file:com.cyberocw.habittodosecretary.file.AttachmentTask.java

public AttachmentTask(Context ctx, Fragment fragment, Uri uri, String fileName,
        OnAttachingFileListener mOnAttachingFileListener) {
    mCtx = ctx;//from ww  w .j  av  a 2  s  . c  om
    if (fragment != null)
        mFragmentWeakReference = new WeakReference<>(fragment);
    else
        mFragmentWeakReference = null;
    this.uri = uri;
    this.fileName = TextUtils.isEmpty(fileName) ? "" : fileName;
    this.mOnAttachingFileListener = mOnAttachingFileListener;
}

From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java

public UpdateWidgetsTask(Context context, Map<Integer, String> map) {
    mContext = new WeakReference<>(context);
    mMap = map;
}

From source file:com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController.java

/**
 * Initializes this instance.
 */
private void init() {
    originatedThread_ = new WeakReference<>(Thread.currentThread());
}