#CardFragment
Explore tagged Tumblr posts
jacob-cs · 8 years ago
Text
Android wear 개발방법(Creating Cards)
original source : http://www.androiddocs.com/training/wearables/ui/cards.html
Creating Cards
The Wearable UI Library provides implementations of cards specifically designed for wearable devices. This library contains the CardFrame class, which wraps views inside a card-styled frame. CardFrame can only contain one direct child, 어떤 fragment가 cardFrame안에 들어갈지는 layout manager를 통해 결정한다.  
You can add cards to your app in two ways:
Use or extend the CardFragment class.
Add a card inside a CardScrollView in your layout.
Note: This lesson shows you how to add cards to Android Wear activities. Android notifications on wearable devices are also displayed as cards. For more information, see Adding Wearable Features to Notifications. 
Create a Card Fragment
To add a CardFragment to your app:
In your layout, assign an ID to the element that contains the card
Create a CardFragment instance in your activity
Use the fragment manager to add the CardFragment instance to its container
<android.support.wearable.view.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@drawable/robot_background" android:layout_height="match_parent" android:layout_width="match_parent">    <FrameLayout        android:id="@+id/frame_layout"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:layout_box="bottom">    </FrameLayout> </android.support.wearable.view.BoxInsetLayout>
The following code adds the CardFragment instance to the activity in Figure 1:
protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_wear_activity2);    FragmentManager fragmentManager = getFragmentManager();    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();    CardFragment cardFragment = CardFragment.create(getString(R.string.cftitle),                                                    getString(R.string.cfdesc),                                                    R.drawable.p);    fragmentTransaction.add(R.id.frame_layout, cardFragment);    fragmentTransaction.commit(); }
To create a card with a custom layout using CardFragment, extend this class and override its onCreateContentView method.
Add a CardFrame to Your Layout
You can also add a card directly to your layout definition,
<android.support.wearable.view.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@drawable/robot_background" android:layout_height="match_parent" android:layout_width="match_parent">    <android.support.wearable.view.CardScrollView        android:id="@+id/card_scroll_view"        android:layout_height="match_parent"        android:layout_width="match_parent"        app:layout_box="bottom">        <android.support.wearable.view.CardFrame            android:layout_height="wrap_content"            android:layout_width="fill_parent">            <LinearLayout                android:layout_height="wrap_content"                android:layout_width="match_parent"                android:orientation="vertical"                android:paddingLeft="5dp">                <TextView                    android:fontFamily="sans-serif-light"                    android:layout_height="wrap_content"                    android:layout_width="match_parent"                    android:text="@string/custom_card"                    android:textColor="@color/black"                    android:textSize="20sp"/>                <TextView                    android:fontFamily="sans-serif-light"                    android:layout_height="wrap_content"                    android:layout_width="match_parent"                    android:text="@string/description"                    android:textColor="@color/black"                    android:textSize="14sp"/>            </LinearLayout>        </android.support.wearable.view.CardFrame>    </android.support.wearable.view.CardScrollView> </android.support.wearable.view.BoxInsetLayout>
@Override protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_wear_activity2);    CardScrollView cardScrollView =        (CardScrollView) findViewById(R.id.card_scroll_view);    cardScrollView.setCardGravity(Gravity.BOTTOM); }
0 notes
jacob-cs · 8 years ago
Text
android wear 개발방법(2d picker)
original source : http://www.androiddocs.com/training/wearables/ui/2d-picker.html
Creating a 2D Picker
that allows users to scroll vertically and horizontally through pages of data.
To implement this pattern, you add a GridViewPager element to the layout of your activity and implement an adapter that provides a set of pages by extending the FragmentGridPagerAdapter class.
Add a Page Grid
Add a GridViewPager element to your layout definition as follows:
<android.support.wearable.view.GridViewPager    xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/pager"    android:layout_width="match_parent"    android:layout_height="match_parent" />
Implement a Page Adapter
public class SampleGridPagerAdapter extends FragmentGridPagerAdapter {    private final Context mContext;    public SampleGridPagerAdapter(Context ctx, FragmentManager fm) {        super(fm);        mContext = ctx;    }    static final int[] BG_IMAGES = new int[] {            R.drawable.debug_background_1, ...            R.drawable.debug_background_5    };    // A simple container for static data in each page    private static class Page {        // static resources        int titleRes;        int textRes;        int iconRes;        ...    }    // Create a static set of pages in a 2D array    private final Page[][] PAGES = { ... };    // Override methods in FragmentGridPagerAdapter    ... }
// Obtain the UI fragment at the specified position @Override public Fragment getFragment(int row, int col) {    Page page = PAGES[row][col];    String title =        page.titleRes != 0 ? mContext.getString(page.titleRes) : null;    String text =        page.textRes != 0 ? mContext.getString(page.textRes) : null;    CardFragment fragment = CardFragment.create(title, text, page.iconRes);    // Advanced settings (card gravity, card expansion/scrolling)    fragment.setCardGravity(page.cardGravity);    fragment.setExpansionEnabled(page.expansionEnabled);    fragment.setExpansionDirection(page.expansionDirection);    fragment.setExpansionFactor(page.expansionFactor);    return fragment; } // Obtain the background image for the page at the specified position @Override public ImageReference getBackground(int row, int column) {    return ImageReference.forDrawable(BG_IMAGES[row % BG_IMAGES.length]); }
// Obtain the number of pages (vertical) @Override public int getRowCount() {    return PAGES.length; } // Obtain the number of pages (horizontal) @Override public int getColumnCount(int rowNum) {    return PAGES[rowNum].length; }
Assign an adapter instance to the page grid
In your activity
public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        ...        final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);        pager.setAdapter(new SampleGridPagerAdapter(this, getFragmentManager()));    } }
0 notes