कार्ड डिज़ाइन

यह दस्तावेज़ बताता है कि ग्लास स्टाइल को कैसे फ़ॉलो करें और GDK का इस्तेमाल करते समय आम तौर पर इस्तेमाल होने वाले यूज़र इंटरफ़ेस (यूआई) के सबसे सही तरीके कैसे लागू करें.

कांच की थीम

Glass आपके Glassware पर एक मानक थीम लागू करता है, इसलिए वह बाकी उपयोगकर्ता इंटरफ़ेस के साथ संगत रहता है. थीम की ये विशेषताएं हैं:

  • रोबोटो टाइपफ़ेस का इस्तेमाल करता है
  • बिना स्टेटस बार या कार्रवाई बार वाली गतिविधियों को फ़ुल-स्क्रीन में दिखाता है
  • सॉलिड बैकग्राउंड वाला आइकॉन

Glass थीम लागू करने के लिए, अपने Android मेनिफ़ेस्ट में थीम की घोषणा न करें.

अगर आपने अपने Glassware के हिस्सों की पसंद के मुताबिक स्टाइल बनाया है और आपको बाकी सभी चीज़ों के लिए डिफ़ॉल्ट Glass थीम चाहिए, तो parent एट्रिब्यूट की मदद से Theme.DeviceDefault का इनहेरिट करें:

<resources>
    <style name="CustomTheme" parent="@android:style/Theme.DeviceDefault">
        <!-- Theme customization goes here. -->
    </style>
</resources>

थीम बनाने के बारे में ज़्यादा जानकारी के लिए, स्टाइल और थीम पर Android डेवलपर गाइड देखें.

कांच के स्टाइल वाले कार्ड

CardBuilder क्लास, प्रॉपर्टी के सेट के आधार पर बेहतर तरीके से बने कार्ड बनाती है. जहां भी हो सके, CardBuilder.Layout से मिले लेआउट का इस्तेमाल करें, ताकि Glass पर आपका कॉन्टेंट दूसरे कॉन्टेंट जैसा दिखे.

CardBuilder का इस्तेमाल करने के लिए:

  1. CardBuilder.Layout से अपनी पसंद का लेआउट देते हुए, CardBuilder का एक इंस्टेंस बनाएं.
  2. कार्ड की प्रॉपर्टी सेट करें, जैसे कि टेक्स्ट, फ़ुटनोट, और टाइमस्टैंप.
  3. कार्ड को Android View में बदलने के लिए CardBuilder.getView() पर कॉल करें या इसे RemoteViews ऑब्जेक्ट में बदलने के लिए CardBuilder.getRemoteViews() कॉल करें.
  4. View का इस्तेमाल अपनी गतिविधियों, लेआउट या CardScrollView में या RemoteViews का इस्तेमाल LiveCard में करें.

यूज़र इंटरफ़ेस (यूआई) की सामान्य सुविधाएं

CardBuilder से मिले कई लेआउट में, नीचे दिए गए सामान्य यूज़र इंटरफ़ेस की सुविधाएं काम करती हैं. हर तरह के कार्ड के साथ काम करने वाली सुविधाओं की सूची के लिए, CardBuilder.Layout में अलग-अलग लेआउट के दस्तावेज़ देखें.

एट्रिब्यूशन आइकॉन

एट्रिब्यूशन आइकॉन एक वैकल्पिक 36 × 36 पिक्सेल आइकॉन है जो कार्ड के निचले दाएं कोने में और टाइमस्टैंप के दाईं ओर दिखाई देता है. अपने ऐप्लिकेशन की पहचान करने के लिए, CardBuilder.setAttributionIcon() को कॉल करके यह आइकॉन सेट करें, खास तौर से लाइव कार्ड पर, ताकि उपयोगकर्ता उस कार्ड पर मौजूद जानकारी का तुरंत स्रोत देख सके.

स्टैक इंंडिकेटर

स्टैक इंंडिकेटर, जिसे CardBuilder.showStackIndicator() से कंट्रोल किया जाता है, वह कार्ड का कॉर्नर फ़ोल्ड है. यह कार्ड के सबसे ऊपर दाएं कोने में दिखता है. इसका इस्तेमाल, विज़ुअल इंडिकेटर के तौर पर करें. इससे पता चलता है कि आपका कार्ड ऐसे दूसरे कार्ड का बंडल है जिन पर उपयोगकर्ता सीधे टैप कर सकता है.

View view = new CardBuilder(context, CardBuilder.Layout.TEXT)
    .setText("A stack indicator can be added to the corner of a card...")
    .setAttributionIcon(R.drawable.ic_smile)
    .showStackIndicator(true)
    .getView();

लेआउट

नीचे दिए गए उदाहरणों में वे लेआउट दिखाए गए हैं जो CardBuilder का इस्तेमाल करके उपलब्ध हैं.

TEXT और TEXT_FIXED

CardBuilder.Layout.TEXT लेआउट को दिखाने पर, पूरी स्क्रीन वाला टेक्स्ट दिखता है. साथ ही, बैकग्राउंड में इमेज मोज़ेक का विकल्प भी होता है. टेक्स्ट का साइज़, उपलब्ध जगह में फ़िट होने के लिए डाइनैमिक तौर पर बदल जाता है. CardBuilder.Layout.TEXT_FIXED समान है, लेकिन इसके टेक्स्ट को छोटे आकार में ठीक करता है.

View view1 = new CardBuilder(context, CardBuilder.Layout.TEXT)
    .setText("This is the TEXT layout. The text size will adjust dynamically.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .getView();
View view2 = new CardBuilder(context, CardBuilder.Layout.TEXT)
    .setText("You can also add images to the background of a TEXT card.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .addImage(R.drawable.image1)
    .addImage(R.drawable.image2)
    .addImage(R.drawable.image3)
    .addImage(R.drawable.image4)
    .addImage(R.drawable.image5)
    .getView();
View view3 = new CardBuilder(context, CardBuilder.Layout.TEXT_FIXED)
    .setText("This is the TEXT_FIXED layout. The text size is always the same.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .getView();

COLUMNS और COLUMNS_FIXED

CardBuilder.Layout.COLUMNS लेआउट, कार्ड के बाईं ओर इमेज मोज़ेक या आइकॉन दिखाता है और दाईं ओर टेक्स्ट होता है. टेक्स्ट का साइज़ डाइनैमिक तौर पर उपलब्ध है, ताकि वह उपलब्ध जगह में फ़िट हो सके. टेक्स्ट का साइज़ ठीक रखने के लिए, CardBuilder.Layout.COLUMNS_FIXED का इस्तेमाल करें.

View view1 = new CardBuilder(context, CardBuilder.Layout.COLUMNS)
    .setText("This is the COLUMNS layout with dynamic text.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .addImage(R.drawable.image1)
    .addImage(R.drawable.image2)
    .addImage(R.drawable.image3)
    .addImage(R.drawable.image4)
    .addImage(R.drawable.image5)
    .getView();
View view2 = new CardBuilder(context, CardBuilder.Layout.COLUMNS)
    .setText("You can even put a centered icon on a COLUMNS card instead of a mosaic.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .setIcon(R.drawable.ic_wifi)
    .getView();
View view3 = new CardBuilder(context, CardBuilder.Layout.COLUMNS_FIXED)
    .setText("This is the COLUMNS_FIXED layout. The text size is always the same.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .addImage(R.drawable.image1)
    .addImage(R.drawable.image2)
    .addImage(R.drawable.image3)
    .addImage(R.drawable.image4)
    .addImage(R.drawable.image5)
    .getView();

CAPTION

CardBuilder.Layout.CAPTION लेआउट के बैकग्राउंड में इमेज मोज़ेक होता है और कार्ड के सबसे नीचे, कैप्शन का छोटा टेक्स्ट दिखता है. उदाहरण के लिए, कैप्शन के आगे आइकॉन भी दिखाया जा सकता है. उदाहरण के लिए, कार्ड के कॉन्टेंट से जुड़े व्यक्ति की पहचान.

पहली इमेज: (बैकग्राउंड इमेज, photowherewhere.co.uk, क्रॉप की गई)
View view1 = new CardBuilder(context, CardBuilder.Layout.CAPTION)
    .setText("The caption layout.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .addImage(R.drawable.beach)
    .setAttributionIcon(R.drawable.ic_smile)
    .getView();

View view2 = new CardBuilder(context, CardBuilder.Layout.CAPTION)
    .setText("The caption layout with an icon.")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .addImage(R.drawable.beach)
    .setIcon(R.drawable.ic_avatar)
    .setAttributionIcon(R.drawable.ic_smile)
    .getView();

TITLE

CardBuilder.Layout.TITLE लेआउट के बैकग्राउंड में इमेज मोज़ेक होता है. इसमें कार्ड के नीचे, बीच में एक शीर्षक और वैकल्पिक आइकॉन होता है. अक्सर इस लेआउट का इस्तेमाल, संपर्क दिखाने या टारगेट शेयर करने के लिए किया जाता है. इस लेआउट पर फ़ुटनोट और टाइमस्टैंप इस्तेमाल नहीं किए जाते.

View view = new CardBuilder(context, CardBuilder.Layout.TITLE)
    .setText("TITLE Card")
    .setIcon(R.drawable.ic_phone)
    .addImage(R.drawable.beach)
    .getView();

AUTHOR

वह मैसेज या बातचीत दिखाने के लिए CardBuilder.Layout.AUTHOR लेआउट का इस्तेमाल करें जहां फ़ोकस लेखक पर है. यह बैकग्राउंड में इमेज मोज़ेक, लेखक के अवतार के रूप में इस्तेमाल होने वाले आइकॉन, और एक ऐसा शीर्षक और उप-शीर्षक के साथ काम करता है जिसमें आप पहचान बताने वाली जानकारी जोड़ सकते हैं.

View view = new CardBuilder(context, CardBuilder.Layout.AUTHOR)
    .setText("The AUTHOR layout lets you display a message or conversation "
            + " with a focus on the author.")
    .setIcon(R.drawable.ic_avatar)
    .setHeading("Joe Lastname")
    .setSubheading("Mountain View, California")
    .setFootnote("This is the footnote")
    .setTimestamp("just now")
    .getView();

CardBuilder.Layout.MENU लेआउट, Glass के स्टैंडर्ड मेन्यू जैसा दिखता है इसमें बीच में एक आइकॉन और शीर्षक और एक वैकल्पिक फ़ुटनोट है. पुष्टि करने वाली स्क्रीन के लिए इस लेआउट का इस्तेमाल करें. उदाहरण के लिए, उपयोगकर्ता के मेन्यू आइटम चुनने के बाद, "मिटाने" से "मिटाने" में बदलने के लिए. अगर आपको वाकई कोई मेन्यू चाहिए, तो आपको उसके बजाय स्टैंडर्ड विकल्पों वाले मेन्यू का इस्तेमाल करना चाहिए.

View view = new CardBuilder(context, CardBuilder.Layout.MENU)
    .setText("MENU layout")
    .setIcon(R.drawable.ic_phone)
    .setFootnote("Optional menu description")
    .getView();

EMBED_INSIDE

CardBuilder.Layout.EMBED_INSIDE लेआउट, आपके अपने डिज़ाइन के कस्टम लेआउट एक्सएमएल को स्टैंडर्ड ग्लास कार्ड टेंप्लेट में एम्बेड करता है. इसकी मदद से, अपने ऐप्लिकेशन के लिए कस्टम यूआई डिज़ाइन किया जा सकता है. हालांकि, ज़रूरत पड़ने पर कार्ड के फ़ुटनोट, टाइमस्टैंप, एट्रिब्यूशन आइकॉन, और स्टैक इंडिकेटर को सही जगह पर रखा जा सकता है.

CardBuilder.getView() को कॉल करने के बाद, एम्बेड किए गए लेआउट में मौजूद व्यू को ऐक्सेस करने के लिए, नतीजे पर findViewById() का इस्तेमाल करें. इसी तरह, CardBuilder.getRemoteViews() को कॉल करने पर, एम्बेड किए गए लेआउट के व्यू में बदलाव किया जा सकता है. इसके लिए, उन्हें सीधे RemoteViews सेटर तरीके में पास करना होगा.

View view = new CardBuilder(context, CardBuilder.Layout.EMBED_INSIDE)
    .setEmbeddedLayout(R.layout.food_table)
    .setFootnote("Foods you tracked")
    .setTimestamp("today")
    .getView();
TextView textView1 = (TextView) view.findViewById(R.id.text_view_1);
textView1.setText("Water");
// ...and so on

ज़्यादा जानकारी वाले उदाहरण के लिए, GitHub ApiDemo प्रोजेक्ट देखें.

ALERT

CardBuilder.Layout.ALERT लेआउट में एक बड़ा सा आइकॉन होता है, जिसमें मुख्य मैसेज और फ़ुटनोट शामिल होते हैं. अपने ग्लासवेयर में अहम जानकारी वाला मैसेज, चेतावनी या गड़बड़ी दिखाने के लिए, Dialog में इस लेआउट का इस्तेमाल करें.

नीचे दिए गए उदाहरण में, AlertDialog को लागू करने की जानकारी दी गई है. साथ ही, कार्ड को खारिज किया गया है और जब उपयोगकर्ता कार्ड पर टैप करता है, तब वाई-फ़ाई की सेटिंग खुल जाती है:

  1. एक ऐसी कक्षा बनाएं जिसमें Dialog शामिल हों.
  2. CardBuilder.Layout.ALERT लेआउट के साथ CardBuilder का इस्तेमाल करके कार्ड बनाएं और फिर इस कार्ड के साथ कॉन्टेंट व्यू सेट करें.
  3. (ज़रूरी नहीं) इस कार्ड पर उपयोगकर्ता के हाथ के जेस्चर हैंडल करने के लिए, GestureDetector बनाएं.

    public class AlertDialog extends Dialog {
    
        private final DialogInterface.OnClickListener mOnClickListener;
        private final AudioManager mAudioManager;
        private final GestureDetector mGestureDetector;
    
        /**
         * Handles the tap gesture to call the dialog's
         * onClickListener if one is provided.
         */
        private final GestureDetector.BaseListener mBaseListener =
            new GestureDetector.BaseListener() {
    
            @Override
            public boolean onGesture(Gesture gesture) {
                if (gesture == Gesture.TAP) {
                    mAudioManager.playSoundEffect(Sounds.TAP);
                    if (mOnClickListener != null) {
                        // Since Glass dialogs do not have buttons,
                        // the index passed to onClick is always 0.
                        mOnClickListener.onClick(AlertDialog.this, 0);
                    }
                    return true;
                }
                return false;
            }
        };
    
        public AlertDialog(Context context, int iconResId,
                           int textResId, int footnoteResId,
                           DialogInterface.OnClickListener onClickListener) {
            super(context);
    
            mOnClickListener = onClickListener;
            mAudioManager =
                (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            mGestureDetector =
                new GestureDetector(context).setBaseListener(mBaseListener);
    
            setContentView(new CardBuilder(context, CardBuilder.Layout.ALERT)
                    .setIcon(iconResId)
                    .setText(textResId)
                    .setFootnote(footnoteResId)
                    .getView());
        }
    
        /** Overridden to let the gesture detector handle a possible tap event. */
        @Override
        public boolean onGenericMotionEvent(MotionEvent event) {
            return mGestureDetector.onMotionEvent(event)
                || super.onGenericMotionEvent(event);
        }
    }
    
  4. (ज़रूरी नहीं) अपनी गतिविधि में, उपयोगकर्ता के टैप करने पर किसी भी दूसरे फ़्लो को मैनेज करने के लिए, OnClickListener लागू करें. वाई-फ़ाई जैसी सेटिंग शुरू करने के बारे में ज़्यादा जानकारी के लिए, सेटिंग शुरू करना देखें.

  5. चेतावनी कार्ड दिखाने के लिए, AlertDialog कंस्ट्रक्टर को कॉल करें.

    public class MyActivity extends Activity {
        ...
        private final DialogInterface.OnClickListener mOnClickListener =
                new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int button) {
                            // Open WiFi Settings
                            startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                        }
                };
    
        @Override
        protected void onCreate(Bundle bundle) {
            ...
    
            new AlertDialog(context, R.drawable.ic_cloud_sad_150, R.string.alert_text,
                R.string.alert_footnote_text, mOnClickListener).show();
    
            ...
        }
    }
    

एक्सएमएल लेआउट

अगर कार्डबिल्डर क्लास आपकी ज़रूरतों को पूरा नहीं करती है, तो आप दो बुनियादी कार्ड लेआउट का इस्तेमाल कर सकते हैं.

मुख्य लेआउट

यह लेआउट, किसी कार्ड के लिए स्टैंडर्ड पैडिंग (जगह) और फ़ुटर के बारे में बताता है. खाली RelativeLayout में अपने व्यू डालें.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <RelativeLayout
        android:id="@+id/body_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/glass_card_body_height"
        android:layout_marginLeft="@dimen/glass_card_margin"
        android:layout_marginTop="@dimen/glass_card_margin"
        android:layout_marginRight="@dimen/glass_card_margin"
        tools:ignore="UselessLeaf"
        >

        <!-- Put your widgets inside this RelativeLayout. -->

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/footer_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left"
        android:layout_marginLeft="@dimen/glass_card_margin"
        android:layout_marginBottom="@dimen/glass_card_footer_margin"
        android:layout_marginRight="@dimen/glass_card_margin"
        android:orientation="horizontal"
        >

        <!-- The footer view will grow to fit as much content as possible while the
             timestamp view keeps a fixed width. If the footer text is too long, it
             will be ellipsized with a 40px margin between it and the timestamp. -->

        <TextView
            android:id="@+id/footer"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            />

        <TextView
            android:id="@+id/timestamp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/glass_card_margin"
            android:ellipsize="end"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            />

    </LinearLayout>

</FrameLayout>

बाएं कॉलम का लेआउट

यह 240 पिक्सल बाएं कॉलम और 400 पिक्सल दाएं कॉलम में दो RelativeLayout के रूप में बताया जाता है, जिनमें आप अपने व्यू डाल सकते हैं.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <RelativeLayout
        android:id="@+id/left_column"
        android:layout_width="@dimen/glass_card_left_column_width"
        android:layout_height="match_parent"
        >

        <!-- Put widgets for the left column inside this RelativeLayout. -->

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="@dimen/glass_card_body_height"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="@dimen/glass_card_two_column_margin"
        android:layout_marginRight="@dimen/glass_card_margin"
        android:layout_marginTop="@dimen/glass_card_margin"
        android:layout_toRightOf="@+id/left_column"
        tools:ignore="UselessLeaf"
        >

        <!-- Put widgets for the right column inside this RelativeLayout. -->

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/footer_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|left"
        android:layout_marginBottom="@dimen/glass_card_footer_margin"
        android:layout_marginLeft="@dimen/glass_card_two_column_margin"
        android:layout_marginRight="@dimen/glass_card_margin"
        android:layout_toRightOf="@+id/left_column"
        android:orientation="horizontal"
        >

        <!--
             The footer view will grow to fit as much content as possible while the
             timestamp view keeps a fixed width. If the footer text is too long, it
             will be ellipsized with a 40px margin between it and the timestamp.
        -->

        <TextView
            android:id="@+id/footer"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            />

        <TextView
            android:id="@+id/timestamp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/glass_card_margin"
            android:ellipsize="end"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            />

    </LinearLayout>

</RelativeLayout>

स्टैंडर्ड डाइमेंशन

इस फ़ाइल का इस्तेमाल, Glass के स्टैंडर्ड स्टाइल के हिसाब से करने के लिए, पिछले लेआउट या अपने लेआउट के साथ करें. अपने Android प्रोजेक्ट में, res/values/dimens.xml के तौर पर यह फ़ाइल बनाएं.

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <!-- The recommended margin for the top, left, and right edges of a card. -->
    <dimen name="glass_card_margin">40px</dimen>

    <!-- The recommended margin between the bottom of the card and the footer. This is
         an adjusted value so that the baseline of the text in the footer sits 40px
         from the bottom of the card, matching the other margins. -->
    <dimen name="glass_card_footer_margin">33px</dimen>

    <!-- The recommended margin for the left column of the two-column card. -->
    <dimen name="glass_card_two_column_margin">30px</dimen>

    <!-- The maximum height of the body content inside a card. -->
    <dimen name="glass_card_body_height">240px</dimen>

    <!-- The width of the left column in the two-column layout. -->
    <dimen name="glass_card_left_column_width">240px</dimen>

</resources>