Code Monkey home page Code Monkey logo

freedtouch's Introduction

FreeDTouch

A 3D Touch API for Android

Android Arsenal

How do I use it?

build.gradle

compile 'io.github.developersofcydonia:freedtouch:1.0.0'

MainActivity.java

FreeDTouch.OnForceTouchListener onForceTouchListener = new FreeDTouch.OnForceTouchListener() {
    @Override
    public void onPeek(View popup, View v, MotionEvent e) {
        Log.d(TAG, "onPeek");
        Toast.makeText(MainActivity.this, "PEEK", Toast.LENGTH_SHORT).show();
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(20);
        
        // To find views inside your popup, use popup.findViewById(...).
        // E.g. -> TextView textView = (TextView) popup.findViewById(R.id.textview);
    }
    
    @Override
    public void onPop(View popup, View v, MotionEvent e) {
        Log.d(TAG, "onPop");
        Toast.makeText(MainActivity.this, "POP", Toast.LENGTH_SHORT).show();
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(20);
    }
    
    @Override
    public void onClick(View popup, View v, MotionEvent e) {
        Log.d(TAG, "onClick");
        Toast.makeText(MainActivity.this, "Click", Toast.LENGTH_SHORT).show();
    }
    
    @Override
    public void onCancel(View popup, View v, MotionEvent e) {
        Log.d(TAG, "onCancel");
        Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
    }
};

Button button = (Button) findViewById(R.id.button);
View popupContainer = findViewById(R.id.popup_container);

FreeDTouch.setup(button, onForceTouchListner)
        .addPopup(popupContainer, R.layout.popup_example)
        .start();

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Wrap your layout in a RelativeLayout -->
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/button"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="PushMe" />

    </RelativeLayout>

    <!-- Create a popup container -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/popup_container">
    </FrameLayout>
</RelativeLayout>

popup_example.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="72dp"
    android:background="#eee">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="#212121"
        android:textSize="82sp"
        android:gravity="center"
        android:text="Hey!"/>

</RelativeLayout>

freedtouch's People

Contributors

eliseomartelli avatar

Watchers

James Cloos avatar Pham Thanh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.