Example usage for android.graphics.drawable AnimationDrawable setOneShot

List of usage examples for android.graphics.drawable AnimationDrawable setOneShot

Introduction

In this page you can find the example usage for android.graphics.drawable AnimationDrawable setOneShot.

Prototype

public void setOneShot(boolean oneShot) 

Source Link

Document

Sets whether the animation should play once or repeat.

Usage

From source file:Main.java

public static AnimationDrawable startAnimDrawable(ImageView img) {
    AnimationDrawable animDrawble = (AnimationDrawable) img.getBackground();
    animDrawble.setOneShot(false);
    animDrawble.start();//w w w. j  a v  a 2s.  c o m
    return animDrawble;
}

From source file:com.adkdevelopment.simpleflashlightadfree.ui.EmergencyFragment.java

/**
 * Starts emergency sound from assets/* w ww .jav  a 2 s.c  o m*/
 */
public void emergencySignal() {

    try {
        if (mMediaPlayer != null && mMediaPlayer.isPlaying() && status == FlashlightService.STATUS_OFF) {
            mMediaPlayer.stop();
            mMediaPlayer.reset();
            mMediaPlayer.release();
            mMediaPlayer = null;

            mLinearLayout.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorBackground));
        } else if (status == FlashlightService.STATUS_BLINK) {

            final AnimationDrawable drawable = new AnimationDrawable();
            final Handler handler = new Handler();

            drawable.addFrame(new ColorDrawable(Color.RED), 400);
            drawable.addFrame(new ColorDrawable(Color.BLUE), 400);
            drawable.setOneShot(false);

            mLinearLayout.setBackground(drawable);
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    drawable.start();
                }
            }, 100);

            mMediaPlayer = new MediaPlayer();
            AssetFileDescriptor descriptor = getActivity().getAssets().openFd("sews.mp3");
            mMediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),
                    descriptor.getLength());
            descriptor.close();

            mMediaPlayer.prepare();
            mMediaPlayer.setVolume(1f, 1f);
            mMediaPlayer.setLooping(true);
            mMediaPlayer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader./*from  w w  w  .j a  v  a  2  s  .  co  m*/
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}

From source file:com.example.search.car.pools.welcome.java

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    Fragment fragment = null;//from   w  w w.jav a 2s .com
    if ((v.equals(l_1) || (v.equals(sp_city)))) {
        String[] city = { "Delhi/NCR", "Bengaluru", "Kolkata", "Mumbai", "Pune", "Ahmedabad" };
        dialog("City", city, sp_city);
    } else if ((v.equals(l_2) || (v.equals(sp_category)))) {
        String[] category = { "All", "Carpool", "Cab", "Rideshare" };
        dialog("Category", category, sp_category);
    } else if ((v.equals(l_3) || (v.equals(sp_search_for)))) {
        String[] search_for = { "Seeker", "Provider", "Both" };
        dialog(" Search For", search_for, sp_search_for);
    } else if (v.equals(close)) {
        promptsView.dismiss();
    } else if (v.equals(rlCities)) {
        layout = "Cities";
        fragment = new Cities();
        frag_tag = "Cities";
        set_fragment(fragment);
        mDrawerLayout.closeDrawer(mDrawerList);
        // getActionBar().setTitle("Cities");
        svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city1);
        iv_cities.setImageDrawable(svg_cities.createPictureDrawable());
        rlCities.setBackgroundColor(Color.parseColor("#00ca98"));
        l_cities.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu));

        svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard);
        iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable());
        rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50"));
        l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue));
        svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search);
        iv_search.setImageDrawable(svg_search.createPictureDrawable());
        rlSearch.setBackgroundColor(Color.parseColor("#2C3E50"));
        l_search.setBackground(getResources().getDrawable(R.drawable.search_blue));
    } else if (v.equals(rlDashboard)) {
        if (task.getString("user_id", null) != null) {
            //            layout = "Dashboard";
            //            fragment = new dashboard();
            //            frag_tag = "Dashboard";
            //            // getActionBar().setTitle("My Profile");
            //            set_fragment(fragment);
            //            mDrawerLayout.closeDrawer(mDrawerList);
            //            svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard1);
            //            iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable());
            //            rlDashboard.setBackgroundColor(Color.parseColor("#00ca98"));
            //            l_dashboard.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu));
            //
            //            svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city);
            //            iv_cities.setImageDrawable(svg_cities.createPictureDrawable());
            //            rlCities.setBackgroundColor(Color.parseColor("#2C3E50"));
            //            l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue));
            //            svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search);
            //            iv_search.setImageDrawable(svg_search.createPictureDrawable());
            //            rlSearch.setBackgroundColor(Color.parseColor("#2C3E50"));
            //            l_search.setBackground(getResources().getDrawable(R.drawable.search_blue));
            Intent i = new Intent(welcome.this, dashboard_main.class);
            i.putExtra("edit", "1");
            startActivity(i);
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {
            Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show();
            mDrawerLayout.closeDrawer(mDrawerList);
        }
    } else if (v.equals(rlSearch)) {
        layout = "Search";
        frag_tag = "Search";
        fragment = new Search();
        set_fragment(fragment);
        mDrawerLayout.closeDrawer(mDrawerList);
        // getActionBar().setTitle("Search");

        svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1);
        iv_search.setImageDrawable(svg_search.createPictureDrawable());
        rlSearch.setBackgroundColor(Color.parseColor("#00ca98"));
        l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu));

        svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard);
        iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable());
        rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50"));
        l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue));
        svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city);
        iv_cities.setImageDrawable(svg_cities.createPictureDrawable());
        rlCities.setBackgroundColor(Color.parseColor("#2C3E50"));
        l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue));
    } else if (v.equals(rlProfile_login) || v.equals(profile_login)) {
        if (task.getString("user_id", null) == null) {
            Intent i = new Intent(getBaseContext(), user_login.class);
            i.putExtra("frag_id", frag_id);
            startActivity(i);
        }
        mDrawerLayout.closeDrawer(mDrawerList);
    }
    //      else if (v.equals(rlEditProfile)) {
    //         if (task.getString("user_id", null) != null) {
    //            Intent i = new Intent(welcome.this, dashboard_main.class);
    //            i.putExtra("edit", "3");
    //            startActivity(i);
    //         } else {
    //            Toast.makeText(welcome.this, "Please Login First", Toast.LENGTH_SHORT).show();
    //         }
    //         mDrawerLayout.closeDrawer(mDrawerList);
    //      } 
    else if (v.equals(login) || v.equals(rlLogin)) {
        if (task.getString("user_id", null) != null && login.getText().toString().contentEquals("Logout")) {
            SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit();
            editor.clear();
            editor.commit();
            login.setText("Login");
            rlDashboard.setVisibility(View.GONE);
            //            rlEditProfile.setVisibility(View.GONE);

            if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) {
                // highlight search menu on slider during on resume
                // change fragment to search
                FragmentManager fm = getFragmentManager();
                FragmentTransaction fragmentTransaction = fm.beginTransaction();
                fragmentTransaction.replace(R.id.content_frame, new Search());
                fragmentTransaction.commit();
                svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1);
                iv_search.setImageDrawable(svg_search.createPictureDrawable());
                rlSearch.setBackgroundColor(Color.parseColor("#00ca98"));
                l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu));
            }

            iv_login.setImageDrawable(svg_login.createPictureDrawable());
            rlProfile.setVisibility(View.GONE);
            rlProfile_login.setVisibility(View.VISIBLE);
            if (frag_id == 6) {
                Intent i_user = new Intent(getBaseContext(), user_login.class);
                i_user.putExtra("frag_id", frag_id);
                startActivity(i_user);
            }
        } else {
            Intent i = new Intent(getBaseContext(), user_login.class);
            i.putExtra("frag_id", frag_id);
            startActivity(i);
        }
        mDrawerLayout.closeDrawer(mDrawerList);
    } else if (v.equals(b_search)) {
        if (sp_city.getText().toString().toUpperCase().equals("SELECT CITY")) {
            Toast.makeText(welcome.this, "First Select the City", Toast.LENGTH_LONG).show();
        } else {
            Intent i = new Intent(welcome.this, search_result.class);
            i.putExtra("city", sp_city.getText().toString());
            i.putExtra("category", sp_category.getText().toString());
            i.putExtra("search_for", sp_search_for.getText().toString());
            i.putExtra("from", et_from.getText().toString());
            i.putExtra("to", et_to.getText().toString());
            i.putExtra("frag_id", 1);
            i.putExtra("company_id", 0);

            startActivity(i);
            promptsView.dismiss();
        }
    } else if (v.equals(l_nav_search) || v.equals(ib_search)) {
        final int DELAY = 200;
        // ColorDrawable f = new
        // ColorDrawable(Color.parseColor("#0087ca"));
        // ColorDrawable f1 = new
        // ColorDrawable(Color.parseColor("#3398ca"));
        AnimationDrawable a = new AnimationDrawable();
        a.addFrame(d1, DELAY);
        a.addFrame(d2, DELAY);
        a.setOneShot(true);
        l_nav_search.setBackground(a);
        a.start();
        showSearchDialog();
    } else if (v.equals(l_handle) || v.equals(ib_handle)) {
        final int DELAY = 200;
        // ColorDrawable f = new
        // ColorDrawable(Color.parseColor("#0087ca"));
        // ColorDrawable f1 = new
        // ColorDrawable(Color.parseColor("#3398ca"));

        AnimationDrawable a = new AnimationDrawable();
        a.addFrame(d1, DELAY);
        a.addFrame(d2, DELAY);
        a.setOneShot(true);
        l_handle.setBackground(a);
        a.start();
        if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {
            mDrawerLayout.openDrawer(mDrawerList);
        }
    } else if (v.equals(l_menu) || v.equals(ib_menu)) {
        final int DELAY = 200;
        // for light background
        // ColorDrawable f = new
        // ColorDrawable(Color.parseColor("#0087ca"));
        // ColorDrawable f1 = new
        // ColorDrawable(Color.parseColor("#3398ca"));
        AnimationDrawable a = new AnimationDrawable();
        a.addFrame(d1, DELAY);
        a.addFrame(d2, DELAY);
        a.setOneShot(true);
        l_menu.setBackground(a);
        a.start();

        final PopupMenu popup = new PopupMenu(welcome.this, v);
        popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());

        bedMenuItem = popup.getMenu().findItem(R.id.menu_login);
        final SharedPreferences task = getSharedPreferences("user", MODE_PRIVATE);
        popup.getMenu().findItem(R.id.menu_add_new_list).setVisible(!(task.getString("user_id", null) == null));
        popup.getMenu().findItem(R.id.menu_dashboard).setVisible(!(task.getString("user_id", null) == null));

        if (task.getString("user_id", null) != null) {
            bedMenuItem.setTitle("Logout");
            login.setText("Logout");
            iv_login.setImageDrawable(svg_logout.createPictureDrawable());
            rlProfile.setVisibility(View.VISIBLE);
            rlProfile_login.setVisibility(View.GONE);
            rlDashboard.setVisibility(View.VISIBLE);
            //            rlEditProfile.setVisibility(View.VISIBLE);
            set_data();
        } else {
            bedMenuItem.setTitle("Login/Register");
            login.setText("Login");
            iv_login.setImageDrawable(svg_login.createPictureDrawable());
            rlDashboard.setVisibility(View.GONE);
            //            rlEditProfile.setVisibility(View.GONE);
            rlProfile.setVisibility(View.GONE);
            rlProfile_login.setVisibility(View.VISIBLE);
        }

        if (task.getString("user_id", null) != null) {
            popup.getMenu().findItem(R.id.menu_login).setTitle("Logout");
        } else {
            popup.getMenu().findItem(R.id.menu_login).setTitle("Login/Register");
        }
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // TODO Auto-generated method stub
                int id = item.getItemId();
                Intent i;
                switch (id) {
                case R.id.menu_add_new_list:
                    if (task.getString("user_id", null) != null) {
                        i = new Intent(welcome.this, create_activity.class);
                        startActivity(i);
                    } else {
                        Toast.makeText(welcome.this, "Login first", Toast.LENGTH_SHORT).show();
                    }

                    return true;
                case R.id.menu_dashboard:
                    if (task.getString("user_id", null) != null) {
                        i = new Intent(welcome.this, dashboard_main.class);
                        i.putExtra("edit", "12344");
                        startActivity(i);
                    } else {
                        Toast.makeText(welcome.this, "Please Login first", Toast.LENGTH_LONG).show();
                    }
                    return true;
                case R.id.menu_login:
                    if (bedMenuItem.getTitle().equals("Logout")) {
                        SharedPreferences.Editor editor = getSharedPreferences("user", MODE_PRIVATE).edit();
                        editor.clear();
                        editor.commit();
                        // bedMenuItem.setTitle("Login/Register");
                        login.setText("Login");
                        rlDashboard.setVisibility(View.GONE);
                        //                     rlEditProfile.setVisibility(View.GONE);

                        if (layout.contentEquals("Dashboard") || frag_tag.contentEquals("Dashboard")) {
                            // highlight search menu on slider during on
                            // resume
                            // change fragment to search
                            FragmentManager fm = getFragmentManager();
                            FragmentTransaction fragmentTransaction = fm.beginTransaction();
                            fragmentTransaction.replace(R.id.content_frame, new Search());
                            fragmentTransaction.commit();
                            SVG svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(),
                                    R.raw.search1);
                            iv_search.setImageDrawable(svg_search.createPictureDrawable());
                            rlSearch.setBackgroundColor(Color.parseColor("#00ca98"));
                            l_search.setBackground(
                                    getResources().getDrawable(R.drawable.white_circle_side_menu));
                        }

                        iv_login.setImageDrawable(svg_login.createPictureDrawable());
                        rlProfile.setVisibility(View.GONE);
                        rlProfile_login.setVisibility(View.VISIBLE);
                        if (frag_id == 6) {
                            Intent i_user = new Intent(getBaseContext(), user_login.class);
                            i_user.putExtra("frag_id", frag_id);
                            startActivity(i_user);
                        }
                    } else {
                        i = new Intent(getBaseContext(), user_login.class);
                        i.putExtra("frag_id", frag_id);
                        startActivity(i);
                    }
                    return true;
                }
                return false;
            }
        });
        popup.show();
        // } else {
        // openOptionsMenu();
        // }
    }

}