/** This method builds a card with a thumbnail with a resource URL */ private void init_card_thumb_resourceURL() { // Create a Card Card card = new Card(getActivity()); // Create a CardHeader CardHeader header = new CardHeader(getActivity()); // Set the header title header.setTitle(getString(R.string.demo_header_basetitle)); card.addCardHeader(header); // Create thumbnail CardThumbnail thumb = new CardThumbnail(getActivity()); // Set URL resource thumb.setUrlResource( "https://lh5.googleusercontent.com/-N8bz9q4Kz0I/AAAAAAAAAAI/AAAAAAAAAAs/Icl2bQMyK7c/s265-c-k-no/photo.jpg"); // Error Resource ID thumb.setErrorResource(R.drawable.ic_error_loadingorangesmall); // Add thumbnail to a card card.addCardThumbnail(thumb); // Set card in the cardView CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_thumb_url); cardView.setCard(card); }
private void init() { CardHeader header = new CardHeader(getContext(), R.layout.carddemo_gdrive_header_inner); header.setTitle(headerTitle); header.setOtherButtonVisible(true); // Add a callback header.setOtherButtonClickListener( new CardHeader.OnClickCardHeaderOtherButtonListener() { @Override public void onButtonItemClick(Card card, View view) { Toast.makeText(getActivity(), "Click on Other Button", Toast.LENGTH_SHORT).show(); } }); // Use this code to set your drawable header.setOtherButtonDrawable(R.drawable.card_menu_button_expand); addCardHeader(header); GdriveGridThumb thumbnail = new GdriveGridThumb(getContext()); thumbnail.setDrawableResource(R.drawable.ic_action_folder_closed); addCardThumbnail(thumbnail); setOnClickListener( new OnCardClickListener() { @Override public void onClick(Card card, View view) { Toast.makeText(getContext(), "Click Listener card=" + headerTitle, Toast.LENGTH_SHORT) .show(); } }); setSwipeable(true); }
/** This method builds a card with a thumbnail with a resource ID */ private void init_card_thumb_resourceId() { // Create a Card Card card = new Card(getActivity()); // Create a CardHeader CardHeader header = new CardHeader(getActivity()); // Set the header title header.setTitle(getString(R.string.demo_header_basetitle)); // Add header to a card card.addCardHeader(header); // Create thumbnail CardThumbnail thumb = new CardThumbnail(getActivity()); // Set ID resource thumb.setDrawableResource(R.drawable.carddemo_ic_gmaps_large); // Add thumbnail to a card card.addCardThumbnail(thumb); // Set card in the cardView CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_thumb_id); cardView.setCard(card); }
@Override protected CardHeader initCardHeader() { // Add Header CardHeader header = new CardHeader(getContext(), R.layout.carddemo_googlenowweather_inner_header); // Add a popup menu. This method set OverFlow button to visible header.setPopupMenu( R.menu.popup_item, new CardHeader.OnClickCardHeaderPopupMenuListener() { @Override public void onMenuItemClick(BaseCard card, MenuItem item) { switch (item.getItemId()) { case R.id.action_add: // Example: add an item WeatherObject w1 = new WeatherObject(GoogleNowWeatherCard.this); w1.city = "Madrid"; w1.temperature = 24; w1.weatherIcon = R.drawable.ic_action_sun; w1.setObjectId(w1.city); mLinearListAdapter.add(w1); break; case R.id.action_remove: // Example: remove an item mLinearListAdapter.remove(mLinearListAdapter.getItem(0)); break; } } }); header.setTitle("Weather"); // should use R.string. return header; }
private void init() { CardHeader header = new CardHeader(getContext()); header.setButtonOverflowVisible(true); header.setTitle(headerTitle); header.setPopupMenu( R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() { @Override public void onMenuItemClick(BaseCard card, MenuItem item) { Toast.makeText(getContext(), "Item " + item.getTitle(), Toast.LENGTH_SHORT).show(); } }); addCardHeader(header); GplayGridThumb thumbnail = new GplayGridThumb(getContext()); if (resourceIdThumbnail > -1) thumbnail.setDrawableResource(resourceIdThumbnail); else thumbnail.setDrawableResource(R.drawable.ic_ic_launcher_web); addCardThumbnail(thumbnail); setOnClickListener( new OnCardClickListener() { @Override public void onClick(Card card, View view) { // Do something } }); }
/** Adds Popup menu */ protected void addPopup() { if (mCardHeader.getPopupMenu() > -1 && mImageButtonOverflow != null) { // Add a PopupMenu and its listener mImageButtonOverflow.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getContext(), mImageButtonOverflow); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(mCardHeader.getPopupMenu(), popup.getMenu()); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (mCardHeader.getPopupMenu() > 0 && mCardHeader.getPopupMenuListener() != null) { // This individual card has it unique menu mCardHeader .getPopupMenuListener() .onMenuItemClick(mCardHeader.getParentCard(), item); } return false; } }); popup.show(); } }); } else { if (mImageButtonOverflow != null) mImageButtonOverflow.setVisibility(GONE); } }
/** Sets the inner view. */ protected void setupInnerView() { if (mFrameInner != null) { // Check if view can be recycled // It can happen in a listView to improve performances or while refreshing a card if (!isRecycle() || isForceReplaceInnerLayout()) { if (isForceReplaceInnerLayout() && mFrameInner != null && mInternalInnerView != null) mFrameInner.removeView(mInternalInnerView); // Inflate inner view mInternalInnerView = mCardHeader.getInnerView(getContext(), mFrameInner); } else { // View can be recycled. // Only setup Inner Elements if (mCardHeader.getInnerLayout() > -1) mCardHeader.setupInnerViewElements(mFrameInner, mInternalInnerView); } } }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); int listImages[] = new int[] { R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher }; ArrayList<Card> cards = new ArrayList<Card>(); for (int i = 0; i < 5; i++) { // Create a Card Card card = new Card(this); // Create a CardHeader CardHeader header = new CardHeader(this); // Add Header to card header.setTitle("Angry bird: " + i); card.setTitle("sample title"); card.addCardHeader(header); CardThumbnail thumb = new CardThumbnail(this); thumb.setDrawableResource(listImages[i]); card.addCardThumbnail(thumb); cards.add(card); } CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(this, cards); CardListView listView = (CardListView) this.findViewById(R.id.myList); if (listView != null) { listView.setAdapter(mCardArrayAdapter); } }
/** Sets Buttons visibility */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") protected void setupButtons() { if (mCardHeader.isButtonOverflowVisible()) { visibilityButtonHelper(VISIBLE, GONE, GONE); // Add popup addPopup(); } else { if (mCardHeader.isButtonExpandVisible()) { visibilityButtonHelper(GONE, VISIBLE, GONE); } else { if (mCardHeader.isOtherButtonVisible() && mImageButtonOther != null) { visibilityButtonHelper(GONE, GONE, VISIBLE); // Check if button is not null if (mImageButtonOther != null) { if (mCardHeader.getOtherButtonDrawable() > 0) { if (Build.VERSION.SDK_INT >= 16) { mImageButtonOther.setBackground( getResources().getDrawable(mCardHeader.getOtherButtonDrawable())); } else { mImageButtonOther.setBackgroundDrawable( getResources().getDrawable(mCardHeader.getOtherButtonDrawable())); } } addOtherListener(); } } else { visibilityButtonHelper(GONE, GONE, GONE); } } } }
/** This method builds a standard header with a custom expand/collpase */ private Card init_standard_header_with_expandcollapse_button_custom_area(String titleHeader) { // Create a Card Card card = new Card(getActivity()); // Create a CardHeader CardHeader header = new CardHeader(getActivity()); // Set the header title header.setTitle(titleHeader); // Set visible the expand/collapse button header.setButtonExpandVisible(true); // Add Header to card card.addCardHeader(header); // This provides a simple (and useless) expand area CustomExpandCard expand = new CustomExpandCard(getActivity()); // Add Expand Area to Card card.addCardExpand(expand); return card; }
/** Sets listener for OtherButtonAction */ protected void addOtherListener() { if (mCardHeader.getOtherButtonClickListener() != null) { if (mImageButtonOther != null) { mImageButtonOther.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (mCardHeader.getOtherButtonClickListener() != null) mCardHeader .getOtherButtonClickListener() .onButtonItemClick(mCardHeader.getParentCard(), v); } }); } } else { if (mImageButtonOther != null) { mImageButtonOther.setClickable(false); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Start service to listen for shaking startService(new Intent(MainActivity.this, Background_service.class)); int cnt = getNumDots(); // cnt = 0; if (cnt == 0) { try { FileOutputStream fos = openFileOutput("Dots.txt", Context.MODE_PRIVATE); fos.write((".").getBytes()); fos.close(); } catch (Exception e) { } this.setContentView(R.layout.login); } else if (cnt == 1) { try { FileOutputStream fos = openFileOutput("Dots.txt", Context.MODE_PRIVATE); fos.write(("..").getBytes()); fos.close(); } catch (Exception e) { } this.setContentView(R.layout.instructions); } else if (cnt == 2) { try { FileOutputStream fos = openFileOutput("Dots.txt", Context.MODE_PRIVATE); fos.write(("...").getBytes()); fos.close(); } catch (Exception e) { } this.setContentView(R.layout.s1); } else if (cnt == 3) { try { FileOutputStream fos = openFileOutput("Dots.txt", Context.MODE_PRIVATE); fos.write(("....").getBytes()); fos.close(); } catch (Exception e) { } this.setContentView(R.layout.s2); } else if (cnt == 4) { try { FileOutputStream fos = openFileOutput("Dots.txt", Context.MODE_PRIVATE); fos.write((".....").getBytes()); fos.close(); } catch (Exception e) { } this.setContentView(R.layout.s3); } else if (cnt == 5) { try { FileOutputStream fos = openFileOutput("Dots.txt", Context.MODE_PRIVATE); fos.write(("......").getBytes()); fos.close(); } catch (Exception e) { } this.setContentView(R.layout.s4); } else { setContentView(R.layout.activity_main); showBalance = (TextView) findViewById(R.id.textView); showBalance.setText(dollar("$" + String.valueOf(getTotalTimes() * getAps()))); startNotification(); int listImages[] = new int[] { R.drawable.two, R.drawable.one, R.drawable.three, R.drawable.four, R.drawable.five }; ArrayList<Card> cards = new ArrayList<Card>(); /* for (int i = 0; i<5; i++) { Card card = new Card(this); CardHeader header = new CardHeader(this); header.setTitle("Angry bird: " + i); card.setTitle("sample title"); card.addCardHeader(header); CardThumbnail thumb = new CardThumbnail(this); thumb.setDrawableResource(listImages[i]); card.addCardThumbnail(thumb); cards.add(card); }*/ Card card = new Card(this); CardHeader header = new CardHeader(this); header.setTitle("Shannon Baker: $15"); card.setTitle("Perfect Attendance for a week!"); card.addCardHeader(header); CardThumbnail thumb = new CardThumbnail(this); thumb.setDrawableResource(listImages[1]); card.addCardThumbnail(thumb); cards.add(card); card = new Card(this); header = new CardHeader(this); header.setTitle("Russel Heritage: $20"); card.setTitle("10 Selfies in ten days!"); card.addCardHeader(header); thumb = new CardThumbnail(this); thumb.setDrawableResource(listImages[0]); card.addCardThumbnail(thumb); cards.add(card); card = new Card(this); header = new CardHeader(this); header.setTitle("Melody Li: $5"); card.setTitle("Discovered every place in her house!"); card.addCardHeader(header); thumb = new CardThumbnail(this); thumb.setDrawableResource(listImages[2]); card.addCardThumbnail(thumb); cards.add(card); card = new Card(this); header = new CardHeader(this); header.setTitle("Bisma Imran: $10"); card.setTitle("Brought lunch from home all week!"); card.addCardHeader(header); thumb = new CardThumbnail(this); thumb.setDrawableResource(listImages[3]); card.addCardThumbnail(thumb); cards.add(card); card = new Card(this); header = new CardHeader(this); header.setTitle("Adit Patel: $7"); card.setTitle("Went to practice every day this month!"); card.addCardHeader(header); thumb = new CardThumbnail(this); thumb.setDrawableResource(listImages[4]); card.addCardThumbnail(thumb); cards.add(card); CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(this, cards); CardListView listView = (CardListView) this.findViewById(R.id.myList); if (listView != null) { listView.setAdapter(mCardArrayAdapter); } // showBalance.setText("$124.00"); } }