package com.marshalchen.common.demoofui.slider; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.marshalchen.common.uimodule.slider.Animations.DescriptionAnimation; import com.marshalchen.common.uimodule.slider.Indicators.PagerIndicator; import com.marshalchen.common.uimodule.slider.SliderTypes.BaseSliderView; import com.marshalchen.common.uimodule.slider.SliderTypes.TextSliderView; import com.marshalchen.common.demoofui.R; import com.marshalchen.common.uimodule.slider.SliderLayout; import java.util.HashMap; public class SliderActivity extends ActionBarActivity implements BaseSliderView.OnSliderClickListener{ private SliderLayout mDemoSlider; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slider_activity_main); mDemoSlider = (SliderLayout)findViewById(R.id.slider); HashMap<String,String> url_maps = new HashMap<String, String>(); url_maps.put("Hannibal", "http://static2.hypable.com/wp-content/uploads/2013/12/hannibal-season-2-release-date.jpg"); url_maps.put("Big Bang Theory", "http://tvfiles.alphacoders.com/100/hdclearart-10.png"); url_maps.put("House of Cards", "http://cdn3.nflximg.net/images/3093/2043093.jpg"); url_maps.put("Game of Thrones", "http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg"); HashMap<String,Integer> file_maps = new HashMap<String, Integer>(); file_maps.put("Hannibal",R.drawable.slider_hannibal); file_maps.put("Big Bang Theory",R.drawable.slider_bigbang); file_maps.put("House of Cards",R.drawable.slider_house); file_maps.put("Game of Thrones", R.drawable.slider_game_of_thrones); for(String name : file_maps.keySet()){ TextSliderView textSliderView = new TextSliderView(this); // initialize a SliderLayout textSliderView .description(name) .image(file_maps.get(name)) .setScaleType(BaseSliderView.ScaleType.Fit) .setOnSliderClickListener(this); //add your extra information textSliderView.getBundle() .putString("extra",name); mDemoSlider.addSlider(textSliderView); } mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion); mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom); mDemoSlider.setCustomAnimation(new DescriptionAnimation()); mDemoSlider.setDuration(4000); ListView l = (ListView)findViewById(R.id.transformers); l.setAdapter(new TransformerAdapter(this)); l.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mDemoSlider.setPresetTransformer(((TextView) view).getText().toString()); Toast.makeText(SliderActivity.this, ((TextView) view).getText().toString(), Toast.LENGTH_SHORT).show(); } }); } @Override public void onSliderClick(BaseSliderView slider) { Toast.makeText(this,slider.getBundle().get("extra") + "",Toast.LENGTH_SHORT).show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.slider,menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case R.id.action_custom_indicator: mDemoSlider.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator)); break; case R.id.action_custom_child_animation: mDemoSlider.setCustomAnimation(new ChildAnimationExample()); break; case R.id.action_restore_default: mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom); mDemoSlider.setCustomAnimation(new DescriptionAnimation()); break; case R.id.action_github: Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/daimajia/AndroidImageSlider")); startActivity(browserIntent); break; } return super.onOptionsItemSelected(item); } }