Last active
November 20, 2017 19:02
-
-
Save lucasr/9508647 to your computer and use it in GitHub Desktop.
Revisions
-
lucasr revised this gist
Mar 21, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ package org.lucasr.transition.samples; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,7 +25,7 @@ public Item(long id, String value) { private final List<Item> items = new ArrayList<Item>(); private int currentId = 0; public SomeAdapter(Context context) { super(); this.context = context; } -
lucasr revised this gist
Mar 13, 2014 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -47,7 +47,8 @@ public View getView(int position, View convertView, ViewGroup parent) { convertView = LayoutInflater.from(context).inflate(R.layout.text_item, parent, false); } Item item = items.get(position); ((TextView) convertView).setText(item.value + " (" + item.id + ")"); return convertView; } @@ -64,7 +65,7 @@ public boolean hasStableIds() { private Item createItem(String value) { long id = ++currentId; return new Item(id, value); } public void add(String value) { -
lucasr revised this gist
Mar 12, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; -
lucasr revised this gist
Mar 12, 2014 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:gravity="center" android:layout_margin="2dp" android:paddingLeft="64dp" android:paddingRight="64dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:background="#ffcc00"/> -
lucasr revised this gist
Mar 12, 2014 . 3 changed files with 59 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ package org.lucasr.transition.samples; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.transition.TransitionManager; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.widget.ListView; import java.util.Random; public class MainActivity extends ActionBarActivity { private ListView listView; private TransitionAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.list); adapter = new SomeAdapter(this); adapter.add("One"); adapter.add("Another"); listView.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { final int id = item.getItemId(); if (id == R.id.action_add) { TransitionManager.beginDelayedTransition(listView); adapter.add(1, "New item"); return true; } else if (id == R.id.action_remove) { TransitionManager.beginDelayedTransition(listView); adapter.remove(1); return true; } return super.onOptionsItemSelected(item); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ package org.lucasr.transition.samples; import android.content.Context; import android.transition.TransitionManager; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ <ListView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="org.lucasr.transition.samples.MainActivity"/> -
lucasr created this gist
Mar 12, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,85 @@ package com.example.android_transition_samples.app; import android.content.Context; import android.transition.TransitionManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.TextView; import java.util.ArrayList; import java.util.List; public class SomeAdapter extends BaseAdapter { private static class Item { public final long id; public final String value; public Item(long id, String value) { this.id = id; this.value = value; } } private final Context context; private final List<Item> items = new ArrayList<Item>(); private int currentId = 0; public TransitionAdapter(Context context) { super(); this.context = context; } @Override public int getCount() { return items.size(); } @Override public Object getItem(int position) { return items.get(position); } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(context).inflate(R.layout.text_item, parent, false); } ((TextView) convertView).setText(items.get(position).value); return convertView; } @Override public long getItemId(int position) { return items.get(position).id; } @Override public boolean hasStableIds() { return true; } private Item createItem(String value) { long id = ++currentId; return new Item(id, value + " (" + id + ")"); } public void add(String value) { items.add(createItem(value)); notifyDataSetChanged(); } public void add(int index, String value) { items.add(index, createItem(value)); notifyDataSetChanged(); } public void remove(int index) { items.remove(index); notifyDataSetChanged(); } }