Quantcast
Jump to content


Recommended Posts

Posted

2020-10-14-01-banner.jpg

Samsung DeX offers a PC-like experience for your phone app. If an app is compatible with DeX, the user can run it on a PC and enjoy its full features on a big screen. Generally, no additional coding is required to make your app DeX-compatible if the best practices of Android programming are followed during development. However, you must make some features compatible with DeX mode so that the user can fully enjoy the desktop experience.

If your app is a gallery app, a game, or any kind of app where multi-touch is required, this feature needs to be made compatible with DeX mode as well. You can replace the multi-touch action with a mouse wheel up/down action for DeX mode. Today, let’s get into the details of how the mouse wheel up/down action can be used to implement the pinch zoom in/out action in a DeX-compatible app.

Get Started

First, let’s go through an example where an image can be zoomed in/out by using multi-touch. For an Android device, you can achieve this feature by detecting the pinch gesture. For DeX mode, you instead need to detect the mouse wheel up/down event to implement this feature.

To start with, develop an app in which you can zoom in/out on an image. Then, make this feature compatible with DeX by receiving the mouse wheel up/down event.

Detect the Pinch Gesture on a Touch Screen

Create a new project in Android Studio, and then add a layout in an XML file. This layout should contain an image on which you can use the pinch gesture for zooming in/out.

The ScaleGestureDetector class is used to determine the scaling transformation gestures using the supplied MotionEvents. First, a ScaleGestureDetector type variable is declared. Next, implement a scale listener, which extends the SimpleOnScaleGestureListener to listen for a subset of scaling-related events. The onScale() method responds to a scaling event. The scale factor is determined in this method and then the layout is scaled accordingly. The maximum and minimum factor values are set for the layout.

private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
    @Override
    public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
        scaleFactor *= scaleGestureDetector.getScaleFactor();
        scaleFactor = Math.max(minScaleFactor, Math.min(scaleFactor, maxScaleFactor));
        layout_main.setScaleX(scaleFactor);
        layout_main.setScaleY(scaleFactor);
        return true;
    }
} 

An instance of ScaleGestureDetector is created in the onCreate() method and the reference of the current activity and the ScaleListener instance are passed as arguments.

Next, an onTouchEvent() callback method is implemented to receive the gesture event and pass this event through to the onTouchEvent() method of the ScaleGestureDetector object.

private ScaleGestureDetector scaleGestureDetector;

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

    layout_main=findViewById(R.id.layout);
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());
}
 
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
    scaleGestureDetector.onTouchEvent(motionEvent);
    return true;
}

Detect Mouse Wheel Scroll for DeX

The MotionEvent object is used to report movement events such as mouse movement. The mouse wheel up/down event is received by the MotionEvent.ACTION_SCROLL action. This action is always delivered to the window or view under the mouse pointer.

The setOnGenericMotionListener event is set on the layout where the implementation of the zoom in/out action should be done. View.OnGenericMotionListener is invoked before the generic motion event is given to the view. The onGenericMotion(View v, MotionEvent event) method is called when a generic motion event is dispatched to a view. It returns true if the listener has consumed the event, false otherwise.

AXIS_VSCROLL is the vertical scroll axis of a motion event. For a mouse, the value is normalized to a range from -1.0 (wheel down) to 1.0 (wheel up).

layout_main=findViewById(R.id.layout);

layout_main.setOnGenericMotionListener(new View.OnGenericMotionListener() {
    @Override
    public boolean onGenericMotion(View v, MotionEvent event) {
        int action = event.getAction();
            if (action == MotionEvent.ACTION_SCROLL) {
                float wheelY = event.getAxisValue(MotionEvent.AXIS_VSCROLL);

                if (wheelY > 0.0f)
                {
                    scaleFactor=  Math.min(maxScaleFactor, scaleFactor*2);

                    Log.d("Mouse_Wheel","up");
                    // write the code to zoom in
                    layout_main.setScaleX(scaleFactor);
                    layout_main.setScaleY(scaleFactor);
                }
                else
                {
                    scaleFactor=  Math.max(minScaleFactor, scaleFactor/2);
                    Log.d("Mouse_Wheel","down");
                    // write the code to zoom out
                    layout_main.setScaleX(scaleFactor);
                    layout_main.setScaleY(scaleFactor);
                }
                return true;
            }
        return true;
   }
});

If the layout supports using the mouse wheel for scrolling, then Ctrl + Mouse wheel up/down can be used for the zoom in/out action. You can implement this by following the steps below:

1. Check the status of Ctrl key. The onKeyDown() and onKeyUp() methods are called when the Ctrl key is pressed or released, respectively.

private boolean ctrlKeyPressed;

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_CTRL_LEFT:
        case KeyEvent.KEYCODE_CTRL_RIGHT:
            ctrlKeyPressed = true;
            break;
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_CTRL_LEFT:
        case KeyEvent.KEYCODE_CTRL_RIGHT:
            ctrlKeyPressed = false;
            break;
    }
    return super.onKeyUp(keyCode, event);
}

2. Execute the zoom in/out action if the Ctrl key is pressed and the mouse wheel is scrolled.

if ((action == MotionEvent.ACTION_SCROLL)&& ctrlKeyPressed) {
    
    float wheelY = event.getAxisValue(MotionEvent.AXIS_VSCROLL);

        if (wheelY > 0.0f){}
        else {}
    return true;
}

Testing

Run the sample app in an Android phone to zoom the image in and out with the pinch in/out gesture. To check the mouse wheel zoom in/out feature, run the app in DeX mode. The source code of the sample app is attached at the end of this article. Feel free to download it and experiment on your own.

2020-10-14-01-01.jpg 2020-10-15-02-01.jpg

Conclusion

This is a basic introduction to mouse wheel interaction in Samsung DeX. There are many things you can do by enabling the mouse and mouse-wheel actions in your app. If you want to add more keyboard functionality, refer to the Android guide for Handling Keyboard Actions.

Additional Resource

Download the Source Code of Sample App

View the full blog at its source



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Similar Topics

    • By Samsung Newsroom
      Samsung Electronics, the world’s leading TV manufacturer for 18 consecutive years, will showcase its leadership in AI TV technology at the 2024 Latin America Tech Seminar. The event, held in São Paulo, Brazil, on May 28-29, will provide an in-depth look at the latest advancements in AI TV technology.
       
      ▲ (Left) Deokhwan Kim, Picture Quality Solution Lab at Samsung Electronics, explains that AI-backed features such as 8K AI Upscaling Pro are powered by a new and powerful NQ8 AI Gen3 Processor on the 2024 Neo QLED 8K.
       
      The Tech Seminar is part of a global series, following successful events in Europe and Southeast Asia earlier this year and coming after the ‘Unbox & Discover’ events held across Latin America. The event will offer a more in-depth exploration of 2024 picture and audio technology, with experts from the Visual Display division explaining the new features to media and industry professionals.
       
      Key highlights will include:
       
      Neo QLED 8K: Featuring advanced image upscaling powered by the NQ8 AI Gen3 Processor, the Neo QLED 8K uses 512 neural networks to transform content from its original quality to a stunning 8K resolution.1 This AI-driven technology analyzes and improves image details in real time, providing a premium viewing experience with exceptional clarity and detail. Gaming Features: The 2024 Neo QLED comes with advanced game optimization features, including AI Auto Game Mode,2 which provides gamers with a seamless and immersive experience tailored to their specific game type. Samsung OLED: Offering superior picture quality without light reflection, Samsung’s 2024 OLED lineup ensures vibrant colors and deeper blacks than ever before. Samsung OLED’s Glare Free technology, certified by Underwriters Laboratories Inc. (UL), ensures optimal color accuracy and clarity even in bright conditions. Music Frame: This innovative speaker doubles as a decorative frame, providing rich surround sound when connected to a Samsung TV. It integrates seamlessly into any home environment, enhancing both the visual and audio experience.  
      ▲ (Right) Kevin Cha, Picture Quality Solution Lab at Samsung Electronics, describes how the 2024 Neo QLED 8K incorporates the new and powerful NQ8 AI Gen3 Processor to support AI-backed features such as 8K AI Upscaling Pro and AI Motion Enhancer Pro.
       
      “We are thrilled to offer an exclusive deep dive into our AI TV technologies at the LATAM Tech Seminar,” said Yongjae Kim, Executive Vice President of Visual Display Business at Samsung Electronics. “This event is a unique opportunity for experts and reviewers to experience firsthand our latest products that deliver exceptional picture quality, advanced features and seamless connectivity.”
       
      For more information on Samsung’s 2024 TV and monitor lineup, please visit samsung.com.
       
      ▲ (Right) Andy Lee, Head of Picture Quality Solution Lab at Samsung Electronics, shares how the 2024 Samsung OLED features Glare Free technology to deliver a comfortable viewing experience.
       
       
      1 8K AI Upscaling Pro
      2 Available in models Q80D and above
      View the full article
    • By Samsung Newsroom
      As electric vehicles continue to increase in popularity, Samsung Electronics has unveiled the OH24B, an outdoor signage solution optimized for EV charging stations, at the Integrated Systems Europe (ISE) 2023, the largest AV systems event in the world. The 24-inch outdoor signage features high-temperature resistant liquid crystal, which is less affected by sunlight and shows great performance in bright conditions. With peak brightness levels of 1,500 nits and UL verification for outdoor visibility, the OH24B displays content clearly outdoors — even in direct sunlight.
       
      In addition, its IP66 rated dust- and waterproof features provide maximum durability, and its Advanced Magic Glass technology is IK10 rated, minimizing screen damage from physical impact or elements. The OH24B is easy to use as its high-performance System on Chip (SoC) allows content management without the use of an additional PC. On top of that, the MagicINFO solution, a cloud-based device and content management platform, remotely controls content in real time, making content monitoring and management seamless and simple.
       
      With detachable Wi-Fi and Bluetooth accessories, the OH24B creates a stable and rapid wireless network environment under any outdoor installation conditions, keeping content running no matter what time of day. Not only is the OH24B hassle-free and a high-performing signage solution, but it also offers incredible energy savings. The OH24B comes with improved energy efficiency with the industry’s lowest power consumption (up to 90W) while offering brilliant pictures in stunning clarity. Simply put, the OH24B is the perfect signage solution for EV charging stations, which need to continuously display various content, including charging information, traffic conditions and store ads.
       
      Check out the infographic below to explore the OH24B along with its breakthrough technologies developed by Samsung, boasting the top position in the global commercial display market for 13 consecutive years.
       

       

       

      View the full article
    • By Samsung Newsroom
      Since it opened in 2004, the Leeum Museum of Art has earned a reputation as a cultural space where traditional, modern and international artworks that span a range of eras and styles are brought together. After the pandemic required it to close for nineteen months, the renovated museum has now reopened with new exhibits that include advanced technological displays which provide enhanced viewing of its expansive collection.
       
      As technology continues to enter the art world in ways that haven’t been seen before, the display and creation of digital art are becoming increasingly common. Amid this climate, Samsung Electronics has partnered with the Leeum Museum of Art to promote the convergence of art and technology and allow people to experience 5,000 years of history with a curated collection in the Art Store on The Frame.
       
      Samsung Newsroom reached out to Kwang-bae Lee, a curator at the Leeum Museum of Art, to get the inside scoop on the museum’s reopening, its collections and its collaboration with Samsung.
       
       
      Transcending Time and Space With Artworks That Span Eras and Styles
      ▲ Exterior view of the Leeum Museum of Art
       
      The Samsung Foundation of Culture established the Leeum Museum of Art in Hannam-dong, Seoul, Korea in 2004 in order to preserve its cultural assets and share them with the public. It was designed by acclaimed architects, Mario Botta, Jean Nouvel and Rem Koolhaas, and is highly regarded for its architectural value and harmonious design which blends with nature. With its unfailing dedication to holding exhibitions and showcasing its expansive collection, the museum now has one of the most broadly representative and varied collections in South Korea. Today, the Leeum is known as an open museum where various artistic styles, from traditional Korean art to vibrant and modern contemporary pieces from both Korea and abroad, can coexist. The museum has also been utilizing digital technology in its exhibits for the past ten years with this technology allowing, old artworks to be displayed in new and exciting ways. In this way, the Leeum seeks to head toward the future while not forgetting about the past. The museum is currently using a variety of state-of-the-art devices for both exhibition and education purposes.
       
      ▲ The interior of the Leeum Museum of Art
       
      During the renovation period, the Leeum launched new permanent exhibits featuring both traditional and modern artworks. It also revived a special exhibition entitled “Human, 7 questions”, which is designed to offer visitors a chance to reflect on humanity as the source of art and contemplate the meaning of human existence during times of crisis. It has also installed a massive Media Wall in its lobby, allowing users to appreciate the artwork of Jennifer Steinkamp upon entering the museum.
       
      “Following the Leeum’s reopening, people seem to be paying special attention to the new collections and special exhibitions we have opened,” said Lee. “I am excited to have visitors come in and see the new and improved space for themselves as they enjoy the full experience the renovated museum offers.”
       
       
      Samsung and Leeum Usher in a New Era of Digital Art
      The partnership between Samsung Electronics and the Leeum is also playing an important role in the ongoing unification of art and technology. Thanks to the fact that works curated by the museum are included on The Frame, users can now view them not just outside of the museum, but across the world. As Korean culture continues to grow more popular and expand into new countries, the introduction of this collection on the Art Store opens new opportunities for users around the world to experience the beauty of Korean traditional art.
       
      ▲ Lidded Bowl (National Treasure), 11th-12th century (Goryeo Dynasty)
       
      Curators spent a great amount of time and effort selecting a collection that shines a light on the artistry and aesthetic of Korean art for display on The Frame. Because of this, viewers can now enjoy beautiful patterns on metal, subtly colored pottery and vibrant paintings from the comfort of their homes.
       
      “Technology allows visitors to appreciate finer details in an artwork – whether it is a picture, a text, or a voice – that they may not have noticed before,” Lee said. “As technologies continue developing, our appreciation and understanding of art will expand beyond what we could ever have imagined.”
       
      ▲ Daoist Immortals, Kim Hong Do, 1776 (Joseon Dynasty)
       
      Samsung Electronics and Leeum have been cooperating on using technology to promote art since the museum opened in 2004. Beyond digital art displays, this partnership has also demonstrated how digital archives can play an important role in preserving historical legacies.
       
      “In this era, when we have access to abundance of masterpieces, the best of art and technology have to come together to complement one another,” Lee commented. “We hope our collaboration with Samsung will eventually come to be regarded as a masterpiece in and of itself.”
       
      The collection of artworks curated by the Leeum is available in the Art Store on The Frame today.
       
      Check out some of the Leeum’s top picks for The Frame below.
       

      View the full article
    • By Samsung Newsroom
      ▲ Still Life #1 (Desert Oasis) (2018)
       
      Versatility is one of the greatest strengths of Samsung’s award-winning lifestyle TV, The Frame. Not only does it offer customization to fit any home décor and stunning QLED picture quality, but the Art Store also transforms the user’s display into a window to the world. With over 1,500 pieces to choose from, including world-renowned artworks like Vincent Van Gogh’s ‘Starry Night’ and partnerships with Magnum Photos, Etsy and a host of museums, the Art Store lets consumers embark on a premium virtual travel experience from the comfort of their home.
       
      With July bearing the curation theme of ‘Summer Vibes’, Samsung Newsroom is introducing photographer Dean West, who travels across continents to take pictures that capture things like the intensity of the desert heat, the refreshing first step into a luxury pool and the feeling of the sun on a tropical beach. West strives to give viewers an escape from reality with his art, and always finds himself coming back to landscapes that are warm and bright – or, as he describes them, “the places you’d rather be.”
       

       
      With West’s work perfectly encapsulating the theme of ‘Summer Vibes’, Newsroom spoke to the photographer about some of his top picks from the Art Store and why The Frame is the ideal platform for displaying his work.
       
      ▲ Pink Dreams #1, Miami Shores (2020)
       
       
      Showcasing Carefully Crafted Scenes With Quantum Dot Technology
      Vibrant colors are a key aspect of West’s artfully orchestrated scenes. “When photographing a scene, I always try to capture the essence or the feeling of a place,” says West. “Color is one way of communicating that. For example, when capturing my pool scenes, the feeling I’m going for is that moment when you first take off your sunglasses – when the sun bounces off the walls into the glistening pool. A colorful array of swimsuits and sunscreen-soaked skin are made visible, and color plays a beautiful role in capturing that essence.”
       
      ▲ St Pete Beach (2016)
       
      The Frame’s QLED 4K picture quality offers the perfect medium for West’s work to be showcased to thousands across the globe. Quantum Dot technology allows more than a billion colors to be displayed at 100% color volume, allowing West’s artistic intent to shine through on a bright screen with vivid and accurate color reproduction. The cutting-edge display technology analyzes every piece of each image and adjusts the contrast to give it an enhanced sense of depth and color for a stunning result every time.
       
      “The technology used provides such a harmonious viewing experience that it has to be seen to be believed,” relates West. “The display’s ability to reproduce color and light is so good that photographers and viewers from around the world can’t help but express their admiration. On top of this, The Frame gives users from all corners of the globe quality access to works that they may otherwise never have seen. This alone is something I truly respect.”
       
      West describes ‘art’ as a series of complex images that blend into a single idea. He adds, “Understanding light is at the heart of creating imagery that are vivid and bright. Any person can put themselves in the right place at the right time and capture something beautiful, but learning to blend complex images takes years to master. The keys are to be curious, do your research and make the time to create.”
       
      ▲ Eagle Rock Office, Los Angeles (2019)
       
       
      How Technology Is Making the Art World More Accessible
      Technology plays a key role in expanding access to art. It provides a multitude of platforms on which work can be displayed and accessed by a broad range of users on different devices. And The Frame is one of those devices. “We’ve already seen how wonderfully the worlds of art and tech are merging,” West remarks. “Artists have always used the best tools available to them at the time, and they will continue to do so as technology advances.”
       
      The Art Store provides access to an expansive library of artworks to appeal to every taste, mood or setting. This ever-growing collection features pieces from a wide range of eras, as well as contributions from 47 global partners and 626 artists so far.
       
      Fifteen of Dean’s pieces are available today for display on the Art Store and The Frame.
       

      View the full article
    • By Samsung Newsroom
      Over the past year and a half, our lives have changed inordinately, with social distancing measures taking over and requiring us to transform every part of our routines from the way we work to the way we shop.
       
      In light of this ‘new normal’ that we find ourselves living in, Samsung Electronics has been working non-stop to develop innovative solutions for businesses as well as users. Samsung Kiosk, a point-of-sale (POS) terminal for customers, is one such solution.
       
      Samsung Kiosk is not only equipped with a range of functionalities and operational settings to fit different business types and sizes, but also features a dedicated User Interface that allows for the easy set-up and usage of menu, payment and saving systems. With a refined design for seamless in-store integration and antibacterial coating technology, Samsung Kiosk has been developed to provide the best possible experiences to retailers as well as customers.
       
      Take a look at the infographic below to learn more about Samsung Kiosk.
       

      View the full article





×
×
  • Create New...