Android Open Source - OpenSynth View Pager Adapter






From Project

Back to project page OpenSynth.

License

The source code is released under:

Apache License

If you think the Android project OpenSynth listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.indigo_lab.android.opensynth;
/*from   w ww  .j  av  a  2 s  .  c o m*/
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import com.indigo_lab.android.opensynth.view.ArpeggioView;
import com.indigo_lab.android.opensynth.view.FilterEnvelopeView;
import com.indigo_lab.android.opensynth.view.FilterView;
import com.indigo_lab.android.opensynth.view.ModulationView;
import com.indigo_lab.android.opensynth.view.OscillatorDetailView;
import com.indigo_lab.android.opensynth.view.OscillatorView;
import com.indigo_lab.android.opensynth.view.VolumeEnvelopeView;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

public class ViewPagerAdapter extends PagerAdapter {
    @SuppressWarnings("unchecked")
    private static final Class<? extends View>[] VIEW_CLASSES = new Class[] {
        OscillatorView.class,
        OscillatorDetailView.class,
        ModulationView.class,
        VolumeEnvelopeView.class,
        FilterView.class,
        FilterEnvelopeView.class,
        ArpeggioView.class,
    };

    private Context mContext;
 
    public ViewPagerAdapter(Context context) {
        super();
        mContext = context;
    }
 
    @Override
    public int getCount() {
        return VIEW_CLASSES.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((View)object);
    }

    private View createViewFrom(Class<? extends View> clz) throws NoSuchMethodException,
        IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Constructor<? extends View> constructor = clz.getConstructor(Context.class);
        return constructor.newInstance(mContext);
    }

    @Override
    public Object instantiateItem(View collection, int position) {
        Class<? extends View> clz = VIEW_CLASSES[position];
        try {
            View v = createViewFrom(clz);
            ((ViewPager) collection).addView(v, 0);
            return v;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("could not create view from " + clz.getSimpleName());
        }
    }

    @Override
    public void destroyItem(View collection, int position, Object view) {
        ((ViewPager) collection).removeView((View)view);
    }
}




Java Source Code List

com.google.synthesizer.android.widgets.piano.BlackPianoKey.java
com.google.synthesizer.android.widgets.piano.NotePianoKey.java
com.google.synthesizer.android.widgets.piano.OctavePianoKey.java
com.google.synthesizer.android.widgets.piano.PianoKey.java
com.google.synthesizer.android.widgets.piano.PianoViewListener.java
com.google.synthesizer.android.widgets.piano.PianoView.java
com.google.synthesizer.android.widgets.piano.WhitePianoKey.java
com.google.synthesizer.core.midi.MidiListener.java
com.google.synthesizer.core.music.Note.java
com.indigo_lab.android.opensynth.OpenSynthActivity.java
com.indigo_lab.android.opensynth.ViewPagerAdapter.java
com.indigo_lab.android.opensynth.view.ArpeggioView.java
com.indigo_lab.android.opensynth.view.ControllerView.java
com.indigo_lab.android.opensynth.view.EnvelopeView.java
com.indigo_lab.android.opensynth.view.FilterEnvelopeView.java
com.indigo_lab.android.opensynth.view.FilterView.java
com.indigo_lab.android.opensynth.view.ImageRadioButton.java
com.indigo_lab.android.opensynth.view.ModulationView.java
com.indigo_lab.android.opensynth.view.OscillatorDetailView.java
com.indigo_lab.android.opensynth.view.OscillatorView.java
com.indigo_lab.android.opensynth.view.RadioButton.java
com.indigo_lab.android.opensynth.view.VolumeEnvelopeView.java
org.thebends.synth.Arpeggio.java
org.thebends.synth.Controller.java
org.thebends.synth.Envelope.java
org.thebends.synth.FilterCutoff.java
org.thebends.synth.Filter.java
org.thebends.synth.FixedParameter.java
org.thebends.synth.KeyStack.java
org.thebends.synth.KeyboardOscillator.java
org.thebends.synth.LFO.java
org.thebends.synth.LagProcessor.java
org.thebends.synth.LowPassFilter.java
org.thebends.synth.MutableParameter.java
org.thebends.synth.Oscillator.java
org.thebends.synth.Parameter.java
org.thebends.synth.ResonantFilter.java
org.thebends.synth.SynthJni.java
org.thebends.synth.SynthTrack.java
org.thebends.synth.Volume.java