1cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 2cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckpackage com.example.renderthread; 3cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 4cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.app.Activity; 5cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.content.Intent; 6cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.Bundle; 7cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.Handler; 8ff941dcd815021bb20d6504eb486acb1e50592c3John Reckimport android.util.Log; 9e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckimport android.view.RenderNodeAnimator; 10cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.view.View; 11cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.widget.AdapterView; 12cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.widget.AdapterView.OnItemClickListener; 13cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.widget.ListView; 14cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.widget.SimpleAdapter; 15cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 16cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport java.util.ArrayList; 17cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport java.util.HashMap; 18cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport java.util.Map; 19cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 20cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckpublic class MainActivity extends Activity implements OnItemClickListener { 21cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 22cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck static final int DURATION = 400; 23cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 24cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck static final String KEY_NAME = "name"; 25cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck static final String KEY_CLASS = "clazz"; 26cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 27cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck static Map<String,?> make(String name) { 28cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck Map<String,Object> ret = new HashMap<String,Object>(); 29cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck ret.put(KEY_NAME, name); 30cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck return ret; 31cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 32cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 33cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck @SuppressWarnings("serial") 34cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck static final ArrayList<Map<String,?>> SAMPLES = new ArrayList<Map<String,?>>() {{ 35cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck for (int i = 1; i < 25; i++) { 36cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck add(make("List Item: " + i)); 37cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 38cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck }}; 39cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 40cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck Handler mHandler = new Handler(); 41cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 42cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck @Override 43cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck protected void onCreate(Bundle savedInstanceState) { 44cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck super.onCreate(savedInstanceState); 45cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck setContentView(R.layout.activity_main); 46cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck ListView lv = (ListView) findViewById(android.R.id.list); 47cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck lv.setDrawSelectorOnTop(true); 48cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck lv.setAdapter(new SimpleAdapter(this, SAMPLES, 49cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck R.layout.item_layout, new String[] { KEY_NAME }, 50cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck new int[] { android.R.id.text1 })); 51cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck lv.setOnItemClickListener(this); 52cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck getActionBar().setTitle("MainActivity"); 53cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 54cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 55cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck @Override 56cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck protected void onResume() { 57cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck super.onResume(); 58cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck ListView lv = (ListView) findViewById(android.R.id.list); 59cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck for (int i = 0; i < lv.getChildCount(); i++) { 60cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck lv.getChildAt(i).animate().translationY(0).setDuration(DURATION); 61cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 62cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 63cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 64cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck @Override 65cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck public void onItemClick(final AdapterView<?> adapterView, View clickedView, 66cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck int clickedPosition, long clickedId) { 67cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck int topPosition = adapterView.getFirstVisiblePosition(); 68cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck int dy = adapterView.getHeight(); 69cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck for (int i = 0; i < adapterView.getChildCount(); i++) { 70cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck int pos = topPosition + i; 71cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck View child = adapterView.getChildAt(i); 72cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck float delta = (pos - clickedPosition) * 1.1f; 73cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck if (delta == 0) delta = -1; 74e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck RenderNodeAnimator animator = new RenderNodeAnimator( 75ff941dcd815021bb20d6504eb486acb1e50592c3John Reck RenderNodeAnimator.TRANSLATION_Y, dy * delta); 76e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck animator.setDuration(DURATION); 77ff941dcd815021bb20d6504eb486acb1e50592c3John Reck if (child == clickedView) logTranslationY(clickedView); 7880fe183c34d862839546ed214e5f69a427cc73d8Ji-Hwan Lee animator.setTarget(child); 7980fe183c34d862839546ed214e5f69a427cc73d8Ji-Hwan Lee animator.start(); 80ff941dcd815021bb20d6504eb486acb1e50592c3John Reck if (child == clickedView) logTranslationY(clickedView); 81cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 82cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck //mHandler.postDelayed(mLaunchActivity, (long) (DURATION * .4)); 83cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck mLaunchActivity.run(); 84cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 85cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 86ff941dcd815021bb20d6504eb486acb1e50592c3John Reck private void logTranslationY(View v) { 87ff941dcd815021bb20d6504eb486acb1e50592c3John Reck Log.d("RTTest", "View has translationY: " + v.getTranslationY()); 88ff941dcd815021bb20d6504eb486acb1e50592c3John Reck } 89ff941dcd815021bb20d6504eb486acb1e50592c3John Reck 90cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck private Runnable mLaunchActivity = new Runnable() { 91cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 92cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck @Override 93cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck public void run() { 94cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck startActivity(new Intent(MainActivity.this, SubActivity.class)); 95cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck overridePendingTransition(0, 0); 96cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 97cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck }; 98cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 99cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck} 100