Home

Awesome

LongPressPopup

<img src="sample.gif" title="sample" /> <br /> You can try the demo app on google play store. <br /> https://play.google.com/store/apps/details?id=rm.com.longpresspopupsample <br /> <br /> Or see the full video demo on YouTube. <br /> https://youtu.be/oSETieldmyw <br /> <br />

A library that let you implement a behaviour similar to the Instagram's <br /> long-press to show detail, with the option to put every kind of views inside it, <br /> (even web views, lists, pagers and so on) show tooltips on drag over <br /> and handle the release of the finger over Views <br />

[Changelog] (CHANGELOG.md)<br />

Download

Gradle:

compile 'com.rm:longpresspopup:1.0.1'
<br /> <b>Min SDK version: 10 (Android 2.3.3) </b> <br />

Usage

Basic

Here's a basic example <br />

public class ActivityMain extends AppCompatActivity {
        
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            Button btn = (Button) findViewById(R.id.btn_popup);
            
            // Create a foo TextView
            TextView textView = new TextView(this);
            textView.setText("Hello, Foo!");
            
            LongPressPopup popup = new LongPressPopupBuilder(this)// A Context object for the builder constructor
                    .setTarget(btn)// The View which will open the popup if long pressed
                    .setPopupView(textView)// The View to show when long pressed 
                    .build();// This will give you a LongPressPopup object
                    
            // You can also chain it to the .build() mehod call above without declaring the "popup" variable before 
            popup.register();// From this moment, the touch events are registered and, if long pressed, will show the given view inside the popup, call unregister() to stop
        }
}
<img src="sample_short.gif" title="sample" />

Advanced

Here's a complete example with all the options <br />

public class ActivityMain extends AppCompatActivity implements PopupInflaterListener,
            PopupStateListener, PopupOnHoverListener, View.OnClickListener {

    private static final String TAG = ActivityMain.class.getSimpleName();
     
    private TextView mTxtPopup;   
        
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Button btn = (Button) findViewById(R.id.btn_popup);
        
        LongPressPopup popup = new LongPressPopupBuilder(this)
                        .setTarget(btn)
                        //.setPopupView(textView)// Not using this time
                        .setPopupView(R.layout.popup_layout, this)
                        .setLongPressDuration(750)
                        .setDismissOnLongPressStop(false)
                        .setDismissOnTouchOutside(false)
                        .setDismissOnBackPressed(false)
                        .setCancelTouchOnDragOutsideView(true)
                        .setLongPressReleaseListener(this)
                        .setOnHoverListener(this)
                        .setPopupListener(this)
                        .setTag("PopupFoo")
                        .setAnimationType(LongPressPopup.ANIMATION_TYPE_FROM_CENTER)
                        .build();
                
        // You can also chain it to the .build() mehod call above without declaring the "popup" variable before 
        popup.register();
    }
    
    
    // Popup inflater listener
    @Override
    public void onViewInflated(@Nullable String popupTag, View root) {
        mTxtPopup = (TextView) root.findViewById(R.id.txt_popup);
    }
    
    
    // Touch released on a View listener
    @Override
    public void onClick(View view) {
        if (mTxtPopup != null && view.getId() == mTxtPopup.getId()) {
            Toast.makeText(ActivityMain.this, "TextView Clicked!", Toast.LENGTH_SHORT).show();
        }
    }
    
    
    // PopupStateListener
    @Override
    public void onPopupShow(@Nullable String popupTag) {
        if(mTxtPopup != null) {
            mTxtPopup.setText("FooBar!");
        }
    }
    
    @Override
    public void onPopupDismiss(@Nullable String popupTag) {
        Toast.makeText(this, "Popup dismissed!", Toast.LENGTH_SHORT).show();
    }
    
    
    // Hover state listener
    @Override
    public void onHoverChanged(View view, boolean isHovered) {
        Log.e(TAG, "Hover change: " + isHovered + " on View " + view.getClass().getSimpleName());
    }
}

<br /> <br /> And here are the functions you can use to customize the Popup and it's behaviour from the LongPressPopupBuilder class: <br />

<br /><br />

Also, the LongPressPopup class gives some utility methods, like <br />

<br />

Known Bugs

<br /><br />

License

Copyright 2017 Riccardo Moro.

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.