Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Saturday, 16 January 2016

how to use onclick and ontouch listener both for diffrent functionality


There is code for different functionality on onclick and also different functionality for start and stop event of ontouch .

public class MyFragment extends BaseFragment implements View.OnTouchListener {

    @Override
    public boolean onTouch(final View v, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                prev_timestamp = System.currentTimeMillis();

            case MotionEvent.ACTION_UP:
                current_timestamp = System.currentTimeMillis();
                upcount++;
                if (current_timestamp - prev_timestamp < 250) {

                    if (upcount == 2) {
                        upcount = 0;
                        Log.d(TAG, "click event");
//here code for onClick event
                    } else {

                        new AsyncTask<Void, Void, Void>() {

                            @Override
                            protected Void doInBackground(Void... params) {
                                try {
                                    Thread.sleep(500);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void aVoid) {
                                if (upcount != 0) {
                                    TOUCH_END=false;
                                    Log.d(TAG, "touch start");
   //here code for onTouchStart event
                                }
                                super.onPostExecute(aVoid);
                            }
                        }.execute();

                    }
                } else {
                    upcount = 0;
                    Log.d(TAG, "touch end");
                    //here code for onTouchEnd event
                }

            case MotionEvent.ACTION_CANCEL:
                //here code for cancel event if you want

        }
        return true;
    }
}

Wednesday, 16 September 2015

Android 5 Programming by Example

This Book Is For If you have a great idea for a mobile app, and some familiarity with Java, or a similar procedural programming language, then all you need is this book to turn your idea into a reality.What You Will Learn Set up an effective development environment to create Android apps from scratch Control the layout structure and design and edit code to control screen events Respond to user interaction using Java and XML with your app Keep your users up to date with Android's new notification framework Implement Google APIs such as maps and other Google Services Create apps for televisions, cars, and wearables and build home-screen app widgets Add audio and video playback to your apps using the AudioManager and MediaPlayer classes Program the two new Lollipop widgets, CardView and RecyclerView Compile your apps, distribute them on the Google Play store, and build in a variety of ways to monetize them In DetailAndroid is a mobile operating system that runs on a staggering number of smart phones and tablets. Android offers developers the ability to build rich and innovative applications written using the Java programming language.Beginning with detailed instructions on how to install and configure the Android SDK, Studio, and Virtual Device Manager, the book moves on to creating a simple, but working, "Hello World" app that can be run on a real device or emulator.The book then moves on to layouts and the visual design of Lollipop apps. A new app is begun to demonstrate this and expanded as we move further, and, once material design has been introduced, the book moves on to the Java coding aspect and how to write code that responds to user interactions via callback methods such as touchscreen gesture listeners.