GithubHelp home page GithubHelp logo

progresslayout's Introduction

ProgressLayout

Custom Progress Layout for Android

Build Status Join the chat at https://gitter.im/iammert/ProgressLayout

Here is the youtube link

XML Definition

 <co.mobiwise.library.ProgressLayout
        android:id="@+id/progressLayout"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        app:maxProgress="100"
        app:autoProgress="true"
        app:emptyColor="#152430"
        android:layout_centerVertical="true"/>

Attributes to use

<co.mobiwise.library.ProgressLayout
...
app:maxProgress="100"
app:autoProgress="true"
app:emptyColor="#152430"
app:loadedColor="#11FFFFFF"
...
/>

Use

ProgressLayout progressLayout = (ProgressLayout) findViewById(R.id.progressLayout);
//Start it
progressLayout.start();
//pause it
progressLayout.stop();
//cancel it
progressLayout.cancel();

Methods

progressLayout.setMaxProgress(120);
progressLayout.setCurrentProgress(64);
boolean isPlaying = progressLayout.isPlaying();
//If you dont want to auto progress and handle it yourself
progressLayout.setAutoProgress(false);

Listener

progressLayout.setProgressLayoutListener(new ProgressLayout.ProgressLayoutListener() {
    @Override
    public void onProgressCompleted() {
        //TODO completed
    }

    @Override
    public void onProgressChanged(int seconds) {
        //TODO progress seconds changed.
    }
});

Gradle

Add it to your project build.gradle

 repositories {
     // ...
     maven { url "https://jitpack.io" }
 }

Add it to your app module build gradle.

dependencies {
     compile 'com.github.iammert:ProgressLayout:a2ac196500'
}

Design

I inspired from this design which is designed by Anatoly Nesterov

License

Copyright 2015 Mert Şimşek.

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.

progresslayout's People

Contributors

iammert avatar ppamorim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

progresslayout's Issues

Setting currentProgress on xml

Is it possible to set the currentProgress on xml? I'm using your library with data-binding and I have to have an attribute to bind my current progress to

Travis CI

Would me amazing to implement a CI to validate the code, what do you think about?

support round corners

this library can be support round corners of views? for example using shape or selector for makeing round corners

Cannot set progress during initialization

image

final CircularProgressButton circularButton1 = findViewById(R.id.circularButton1);
circularButton1.setIndeterminateProgressMode(true);
circularButton1.setProgress(50);

Progress Not showing when i declare progress layout as static

Hello
I used your library with with view pager. when audio is playing and swipe then its working perfect but when u again swipe on previous progress will be continue. please help me.
My Code Is As below

DisplayPictureDetail.DpFragmentPagerAdapter dpFragmentPagerAdapter;
ViewPager viewPager;
@SuppressLint("StaticFieldLeak")
Toolbar mToolbar;
private static ArrayList DpDetailArl;
int selectedPosition = 0, pos;
static String Title, CatType, downloadUrl;
@SuppressLint("StaticFieldLeak")
static RelativeLayout mRowDetailLayout;

static int currentDuration = 0, mIntFavCounter;
static Activity activity;
DatabaseHandler db;
static MediaPlayer mediaPlayer;
FloatingActionButton mFabRingtone, mFabNotification, mFabAlarm;
SparkButton mImgFavCounter;
TextView mRowtxtFav;
int CurrentId, CurrentDownloadCount;
static CategoryModel currentTrack = null;
static boolean isPlaying = false;
static ProgressLayout progressLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_pager);
    activity = DisplayPictureDetail.this;
    if (Connectivity.getInstance(DisplayPictureDetail.this).isOnline()) {
        Log.d("RESULT", "------------------DP DETAIL Page Start------------------");

        viewPager = (ViewPager) findViewById(R.id.pager);
        mImgFavCounter = (SparkButton) findViewById(R.id.heart_button);
        mRowtxtFav = (TextView) findViewById(R.id.mRowtxtFav);
        mToolbar = (Toolbar) findViewById(R.id.mToolbar);
      
        setSupportActionBar(mToolbar);
        mediaPlayer = new MediaPlayer();
        db = new DatabaseHandler(activity);
        if (mToolbar != null) {
            mToolbar.setTitleTextColor(Color.WHITE);
            mToolbar.setSubtitleTextColor(Color.WHITE);
            mToolbar.setBackgroundColor(Color.TRANSPARENT);
            getSupportActionBar().setTitle("Title");
        }

        Bundle extra = getIntent().getBundleExtra("extra");
        if (extra != null) {
            DpDetailArl = (ArrayList<CategoryModel>) extra.getSerializable("objects");
            pos = getIntent().getIntExtra("position", 0);
        }

        if (DpDetailArl != null) {
            dpFragmentPagerAdapter = new DpFragmentPagerAdapter(getSupportFragmentManager());
            viewPager.setAdapter(dpFragmentPagerAdapter);
            dpFragmentPagerAdapter.notifyDataSetChanged();
        } else {
            Toast.makeText(activity, "No Data Found..", Toast.LENGTH_SHORT).show();
        }
        setCurrentItem(pos);

        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                if (mediaPlayer.isPlaying()) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    isPlaying = false;
                }
            }

            @Override
            public void onPageSelected(int position) {
                displayMetaInfo(position);
                GradientDrawable gd1 = Config.generateGradiantRandom(DisplayPictureDetail.this);
                viewPager.setBackground(gd1);
                mRowDetailLayout.setBackground(gd1);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
                

    } else {

// new AlertDialog(DisplayPictureDetail.this, getString(R.string.alert_title), getString(R.string.inernet_alert_message),
// getString(R.string.alert_pos_btn), new NavigationMainActivity());
}
}

private void setCurrentItem(int position) {
    viewPager.setCurrentItem(position, false);
    displayMetaInfo(position);
    selectedPosition = position;
}

private void displayMetaInfo(int position) {
    CategoryModel image = DpDetailArl.get(position);
    downloadUrl = image.getUrl();
    CurrentId = image.getId();
    CurrentDownloadCount = image.getDownloads();
      
}

public void onBackPressed() {
    super.onBackPressed();
    if (mediaPlayer != null) {
        mediaPlayer.stop();

    }
}

public void onPause() {
    super.onPause();
    if (mediaPlayer.isPlaying()) {
        mediaPlayer.pause();
    }
}

public void onStop() {
    super.onStop();
    if (mediaPlayer.isPlaying()) {
        mediaPlayer.stop();
        mediaPlayer.reset();
    }
}

public void onDestroy() {
    super.onDestroy();
    if (mediaPlayer.isPlaying()) {
        mediaPlayer.stop();
        mediaPlayer.reset();
    }
}

public class DpFragmentPagerAdapter extends FragmentPagerAdapter {

    public DpFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public int getCount() {
        return DpDetailArl.size();
    }

    @Override
    public Fragment getItem(int position) {
        SwipeFragment fragment = new SwipeFragment();
        return SwipeFragment.newInstance(position);
    }
}

public static class SwipeFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View swipeView = inflater.inflate(R.layout.display_picture_detail, container, false);

        Bundle args = getArguments();
        final int position = args.getInt("position");

        final DatabaseHandler db = new DatabaseHandler(getActivity());
        final ImageView ivIcon;
        final int SECOND_MS = 1000;
        final Handler mHandler = new Handler();

        final Runnable mRunnable = new Runnable() {
            @Override
            public void run() {
                currentDuration += 1;
                mHandler.postDelayed(this, SECOND_MS);
            }
        };
        final CategoryModel track = DpDetailArl.get(position);
        mRowDetailLayout = (RelativeLayout) swipeView.findViewById(R.id.mRowDetailLayout);
        progressLayout = (ProgressLayout) swipeView.findViewById(R.id.progressLayout);
        ivIcon = (ImageView) swipeView.findViewById(R.id.ivIcon);

        progressLayout.setMaxProgress(DpDetailArl.get(position).getDurationInSec());

        Title = DpDetailArl.get(position).getName();
        CatType = DpDetailArl.get(position).getCat_type();

        ivIcon.setBackgroundResource(R.drawable.ic_play_white);

        if (currentTrack != null && currentTrack == track) {
            ivIcon.setBackgroundResource(isPlaying ? R.drawable.ic_pause_white : R.drawable.ic_play_white);
            progressLayout.setCurrentProgress(currentDuration);
            if (isPlaying) progressLayout.start();
        } else {
            progressLayout.cancel();
        }
        ivIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String AUDIO_PATH = DpDetailArl.get(position).getUrl();

                if (track != currentTrack) {
                    currentTrack = track;
                    mHandler.removeCallbacks(mRunnable);
                    currentDuration = 0;
                }
                if (!progressLayout.isPlaying()) {
                    isPlaying = true;
                    try {
                        mediaPlayer.reset();
                        if (mediaPlayer != null) {
                            mediaPlayer.setDataSource(AUDIO_PATH);
                            mediaPlayer.prepare();
                            mediaPlayer.start();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    progressLayout.start();
                    mHandler.postDelayed(mRunnable, 0);
                    ivIcon.setBackgroundResource(R.drawable.ic_pause_white);
                    int UpdateViewCount = DpDetailArl.get(position).getViews() + 1;
                    Functions.updateDpCounter(activity, Config.KEY_ID, String.valueOf(DpDetailArl.get(position).getId()),
                            Config.KEY_VIEWS, String.valueOf(UpdateViewCount), Config.VIEWS_COUNTER_UPDATE_URL);

                } else {

                    isPlaying = false;
                    mediaPlayer.stop();

                    progressLayout.setCurrentProgress(0);
                    progressLayout.cancel();
                    mHandler.removeCallbacks(mRunnable);
                    ivIcon.setBackgroundResource(R.drawable.ic_play_white);

// ivIcon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

                }
            }
        });
        progressLayout.setProgressLayoutListener(new ProgressLayoutListener() {
            @Override
            public void onProgressCompleted() {
                progressLayout.stop();
               ivIcon.setBackgroundResource(R.drawable.ic_play_white);
            }

            @Override
            public void onProgressChanged(int seconds) {
                Log.d("Result", "Pogress Mili:-" + seconds);
            }
        });


        return swipeView;
    }


    static SwipeFragment newInstance(int position) {
        SwipeFragment swipeFragment = new SwipeFragment();
        Bundle args = new Bundle();
        args.putInt("position", position);
        swipeFragment.setArguments(args);
        return swipeFragment;
    }

}

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.