Example usage for android.widget ImageView setImageResource

List of usage examples for android.widget ImageView setImageResource

Introduction

In this page you can find the example usage for android.widget ImageView setImageResource.

Prototype

@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync")
public void setImageResource(@DrawableRes int resId) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.genesys.pokemaps.MapActivity.java

public void startPokemoonLoop() {
    new Timer().schedule(new TimerTask() {
        @Override//from   www. ja  v  a  2  s .c  o m
        public void run() {
            if (gameManager != null && (location != null)) {
                long startTime = System.currentTimeMillis();
                try {
                    // Updates our game location to match our real location.
                    gameManager.setPlayerLocation(location);

                    // Update our pokestops and add a marker on our map at its location.
                    // TODO: Add a map marker for pokestops.
                    // gameManager.updatePokestops();

                    // Cycles through our pokestops and loots them if the option is available.
                    for (PokestopLootResult lootResult : gameManager.lootPokestops()) {
                        switch (lootResult.getResult()) {
                        case SUCCESS:
                            showSnackBar("Pokestop was successfully looted. Gained "
                                    + lootResult.getExperience() + " XP");
                            Log.i(TAG, "Pokestop was successfully looted. Gained" + lootResult.getExperience()
                                    + " XP and " + lootResult.getItemsAwarded().size() + " items.");
                            Utils.vibrate(Constants.POKESTOP_VIBRATION_PATTERN, vibrator);
                            break;
                        case INVENTORY_FULL:
                            String invMsg = "Inventory too full to loot Pokestop";
                            showSnackBar(invMsg);
                            Log.i(TAG, invMsg);
                            break;
                        case IN_COOLDOWN_PERIOD:
                            String coolMsg = "Pokestop is currently in cooldown";
                            showSnackBar(coolMsg);
                            Log.i(TAG, coolMsg);
                            break;
                        default:
                            String errMsg = "Couldn't loot pokestop due to error "
                                    + lootResult.getResult().name();
                            showSnackBar(errMsg);
                            Log.i(TAG, errMsg);
                        }
                    }

                    final List<NearbyPokemon> nearbyPokemon = gameManager.getNearbyPokemon();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            for (int i = 0; i < nearbyContainer.getChildCount(); i++) {
                                View child = nearbyContainer.getChildAt(i);
                                if (child.getId() != R.id.no_nearby_text_view
                                        && child.getParent() == nearbyContainer) {
                                    nearbyContainer.removeViewAt(i--);
                                }
                            }

                            if (nearbyPokemon.size() > 0) {
                                // There are nearby Pokemon!
                                // Set our TextView visibility to gone.
                                nearbyTextView.setVisibility(View.GONE);
                                for (NearbyPokemon pokemon : nearbyPokemon) {
                                    Log.i(TAG, pokemon.getPokemonId().name() + " is nearby.");

                                    ViewGroup nearbyPokemonLayout = (ViewGroup) getLayoutInflater()
                                            .inflate(R.layout.nearby_pokemon, null);

                                    ImageView pokemonImage = (ImageView) nearbyPokemonLayout.getChildAt(1);
                                    ImageView pokemonBackground = (ImageView) nearbyPokemonLayout.getChildAt(0);

                                    int id = getResources().getIdentifier(
                                            pokemon.getPokemonId().name().toLowerCase(), "drawable",
                                            getPackageName());
                                    pokemonImage.setImageResource(id);

                                    int backgroundColor;
                                    switch (PokemonMetaRegistry.getMeta(pokemon.getPokemonId())
                                            .getPokemonClass()) {
                                    case VERY_COMMON:
                                        backgroundColor = Utils.getColor(MapActivity.this,
                                                R.color.veryCommonColor);
                                        break;
                                    case COMMON:
                                        backgroundColor = Utils.getColor(MapActivity.this, R.color.commonColor);
                                        break;
                                    case UNCOMMON:
                                        backgroundColor = Utils.getColor(MapActivity.this,
                                                R.color.uncommonColor);
                                        break;
                                    case RARE:
                                        backgroundColor = Utils.getColor(MapActivity.this, R.color.rareColor);
                                        break;
                                    case VERY_RARE:
                                        backgroundColor = Utils.getColor(MapActivity.this,
                                                R.color.veryRareColor);
                                        break;
                                    case EPIC:
                                        backgroundColor = Utils.getColor(MapActivity.this, R.color.epicColor);
                                        break;
                                    case LEGENDARY:
                                        backgroundColor = Utils.getColor(MapActivity.this,
                                                R.color.legendaryColor);
                                        break;
                                    case MYTHIC:
                                        backgroundColor = Utils.getColor(MapActivity.this, R.color.mythicColor);
                                        break;
                                    default:
                                        backgroundColor = Color.WHITE;
                                    }

                                    pokemonBackground.setColorFilter(backgroundColor);

                                    nearbyContainer.addView(nearbyPokemonLayout);
                                }
                            } else {
                                nearbyTextView.setVisibility(View.VISIBLE);
                            }
                        }
                    });

                    // Update our pokemon and add a marker on the map at its location.
                    // TODO: Add a map marker for catchable pokemon.
                    //gameManager.updateCatchablePokemon();

                    GameManager.Catch catchResult = gameManager.catchPokemon();
                    if (catchResult != null) {
                        String pokemon = PokeDictionary.getDisplayName(
                                catchResult.getCatchablePokemon().getPokemonId().getNumber(), Locale.ENGLISH);
                        String message;
                        switch (catchResult.getCatchResult().getStatus()) {
                        case CATCH_SUCCESS:
                            message = pokemon + " successfully captured";
                            Utils.vibrate(Constants.POKEMON_VIBRATION_PATTERN, vibrator);
                            break;
                        case CATCH_FLEE:
                            message = pokemon + " fled";
                            break;
                        case CATCH_MISSED:
                            message = pokemon + " missed";
                            break;
                        default:
                            message = "Unable to catch " + pokemon;
                        }
                        showSnackBar(message);
                        Log.i(TAG, message);
                    }

                    gameManager.updateGyms();

                } catch (LoginFailedException e) {
                    showSnackBar("Login failed. Credentials changed");
                } catch (RemoteServerException e) {
                    showSnackBar("Login failed. Servers may be down");
                } catch (NoSuchItemException e) {
                    showSnackBar("Not enough pokeballs to catch pokemon");
                } catch (AsyncPokemonGoException e) {
                    String username = preferences.getString(getString(R.string.username_preference_key), null);
                    String password = preferences.getString(getString(R.string.password_preference_key), null);
                    if (username != null || password != null) {
                        gameManager.loginPTC(username, password);
                    }
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                double scanTimeSeconds = (double) (System.currentTimeMillis() - startTime) / 1000;
                Log.i(TAG, "World scanning completed in " + scanTimeSeconds + " seconds.");
            }
        }
    }, 0, GAME_REFRESH_RATE);
}

From source file:com.luseen.spacenavigation.SpaceNavigationView.java

/**
 * Adding given space items to content/* www . ja v a 2 s  .co  m*/
 *
 * @param leftContent  to left content
 * @param rightContent and right content
 */
private void addSpaceItems(LinearLayout leftContent, LinearLayout rightContent) {

    /**
     * Removing all views for not being duplicated
     */
    if (leftContent.getChildCount() > 0 || rightContent.getChildCount() > 0) {
        leftContent.removeAllViews();
        rightContent.removeAllViews();
    }

    /**
     * Clear spaceItemList and badgeList for not being duplicated
     */
    spaceItemList.clear();
    badgeList.clear();

    /**
     * Getting LayoutInflater to inflate space item view from XML
     */
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for (int i = 0; i < spaceItems.size(); i++) {
        final int index = i;
        int targetWidth;
        if (spaceItems.size() > 2)
            targetWidth = contentWidth / 2;
        else
            targetWidth = contentWidth;

        RelativeLayout.LayoutParams textAndIconContainerParams = new RelativeLayout.LayoutParams(targetWidth,
                mainContentHeight);
        RelativeLayout textAndIconContainer = (RelativeLayout) inflater.inflate(R.layout.space_item_view, this,
                false);
        textAndIconContainer.setLayoutParams(textAndIconContainerParams);

        ImageView spaceItemIcon = (ImageView) textAndIconContainer.findViewById(R.id.space_icon);
        TextView spaceItemText = (TextView) textAndIconContainer.findViewById(R.id.space_text);
        RelativeLayout badgeContainer = (RelativeLayout) textAndIconContainer
                .findViewById(R.id.badge_container);
        spaceItemIcon.setImageResource(spaceItems.get(i).getItemIcon());
        spaceItemText.setText(spaceItems.get(i).getItemName());
        spaceItemText.setTextSize(TypedValue.COMPLEX_UNIT_PX, spaceItemTextSize);

        /**
         * Set custom font to space item textView
         */
        if (isCustomFont)
            spaceItemText.setTypeface(customFont);

        /**
         * Hide item icon and show only text
         */
        if (textOnly)
            Utils.changeViewVisibilityGone(spaceItemIcon);

        /**
         * Hide item text and change icon size
         */
        ViewGroup.LayoutParams iconParams = spaceItemIcon.getLayoutParams();
        if (iconOnly) {
            iconParams.height = spaceItemIconOnlySize;
            iconParams.width = spaceItemIconOnlySize;
            spaceItemIcon.setLayoutParams(iconParams);
            Utils.changeViewVisibilityGone(spaceItemText);
        } else {
            iconParams.height = spaceItemIconSize;
            iconParams.width = spaceItemIconSize;
            spaceItemIcon.setLayoutParams(iconParams);
        }

        /**
         * Adding space items to item list for future
         */
        spaceItemList.add(textAndIconContainer);

        /**
         * Adding badge items to badge list for future
         */
        badgeList.add(badgeContainer);

        /**
         * Adding sub views to left and right sides
         */
        if (spaceItems.size() == 2 && leftContent.getChildCount() == 1) {
            rightContent.addView(textAndIconContainer, textAndIconContainerParams);
        } else if (spaceItems.size() > 2 && leftContent.getChildCount() == 2) {
            rightContent.addView(textAndIconContainer, textAndIconContainerParams);
        } else {
            leftContent.addView(textAndIconContainer, textAndIconContainerParams);
        }

        /**
         * Changing current selected item tint
         */
        if (i == currentSelectedItem) {
            spaceItemText.setTextColor(activeSpaceItemColor);
            Utils.changeImageViewTint(spaceItemIcon, activeSpaceItemColor);
        } else {
            spaceItemText.setTextColor(inActiveSpaceItemColor);
            Utils.changeImageViewTint(spaceItemIcon, inActiveSpaceItemColor);
        }

        textAndIconContainer.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                updateSpaceItems(index);
            }
        });
    }

    /**
     * Restore available badges from saveInstance
     */
    restoreBadges();
}

From source file:com.csipsimple.ui.favorites.FavAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(cursor, cv);

    int type = ContactsWrapper.TYPE_CONTACT;
    if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) {
        type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE);
    }//from  w  w w  .j  a va  2 s .c o  m

    showViewForType(view, type);

    if (type == ContactsWrapper.TYPE_GROUP) {
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.header_text);
        ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
        PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view
                .findViewById(R.id.header_presence_spinner);

        // Get datas
        SipProfile acc = new SipProfile(cursor);

        final Long profileId = cv.getAsLong(BaseColumns._ID);
        final String groupName = acc.android_group;
        final String displayName = acc.display_name;
        final String wizard = acc.wizard;
        final boolean publishedEnabled = (acc.publish_enabled == 1);
        final String domain = acc.getDefaultDomain();

        // Bind datas to view
        tv.setText(displayName);
        icon.setImageResource(WizardUtils.getWizardIconRes(wizard));
        presSpinner.setProfileId(profileId);

        // Extra menu view if not already set
        ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner);

        MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled);
        MenuBuilder menuBuilder;
        if (menuViewWrapper.getTag() == null) {

            final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);

            ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext);
            mActionMenuPresenter.setReserveOverflow(true);
            menuBuilder = new MenuBuilder(context);
            menuBuilder.setCallback(newMcb);
            MenuInflater inflater = new MenuInflater(context);
            inflater.inflate(R.menu.fav_menu, menuBuilder);
            menuBuilder.addMenuPresenter(mActionMenuPresenter);
            ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper);
            UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null);
            menuViewWrapper.addView(menuView, layoutParams);
            menuViewWrapper.setTag(menuBuilder);
        } else {
            menuBuilder = (MenuBuilder) menuViewWrapper.getTag();
            menuBuilder.setCallback(newMcb);
        }
        menuBuilder.findItem(R.id.share_presence).setTitle(
                publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing);
        menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName));

    } else if (type == ContactsWrapper.TYPE_CONTACT) {
        ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor);
        ci.userData = cursor.getPosition();
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.contact_name);
        QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo);
        TextView statusText = (TextView) view.findViewById(R.id.status_text);
        ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon);

        // Bind
        if (ci.contactId != null) {
            tv.setText(ci.displayName);
            badge.assignContactUri(ci.callerInfo.contactContentUri);
            ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(),
                    ci.callerInfo, R.drawable.ic_contact_picture_holo_dark);

            statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusText.setText(ci.status);
            statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence));
        }
        View v;
        v = view.findViewById(R.id.contact_view);
        v.setTag(ci);
        v.setOnClickListener(mPrimaryActionListener);
        v = view.findViewById(R.id.secondary_action_icon);
        v.setTag(ci);
        v.setOnClickListener(mSecondaryActionListener);
    } else if (type == ContactsWrapper.TYPE_CONFIGURE) {
        // We only bind if it's the correct type
        View v = view.findViewById(R.id.configure_view);
        v.setOnClickListener(this);
        ConfigureObj cfg = new ConfigureObj();
        cfg.profileId = cv.getAsLong(BaseColumns._ID);
        v.setTag(cfg);
    }
}

From source file:com.fututel.ui.favorites.FavAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(cursor, cv);

    int type = ContactsWrapper.TYPE_CONTACT;
    if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) {
        type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE);
    }/*from  ww w . j a  v  a2  s  . c  om*/

    showViewForType(view, type);

    if (type == ContactsWrapper.TYPE_GROUP) {
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.header_text);
        ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
        PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view
                .findViewById(R.id.header_presence_spinner);

        // Get datas
        SipProfile acc = new SipProfile(cursor);

        final Long profileId = cv.getAsLong(BaseColumns._ID);
        final String groupName = acc.android_group;
        final String displayName = acc.display_name;
        final String wizard = acc.wizard;
        final boolean publishedEnabled = (acc.publish_enabled == 1);
        final String domain = acc.getDefaultDomain();

        // Bind datas to view
        tv.setText(displayName);
        icon.setImageResource(WizardUtils.getWizardIconRes(wizard));
        presSpinner.setProfileId(profileId);

        // Extra menu view if not already set
        ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner);

        MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled);
        MenuBuilder menuBuilder;
        if (menuViewWrapper.getTag() == null) {

            final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);

            ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext);
            mActionMenuPresenter.setReserveOverflow(true);
            menuBuilder = new MenuBuilder(context);
            menuBuilder.setCallback(newMcb);
            MenuInflater inflater = new MenuInflater(context);
            inflater.inflate(R.menu.fav_menu, menuBuilder);
            menuBuilder.addMenuPresenter(mActionMenuPresenter);
            ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper);
            UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null);
            menuViewWrapper.addView(menuView, layoutParams);
            menuViewWrapper.setTag(menuBuilder);
        } else {
            menuBuilder = (MenuBuilder) menuViewWrapper.getTag();
            menuBuilder.setCallback(newMcb);
        }
        menuBuilder.findItem(R.id.share_presence).setTitle(
                publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing);
        menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName));

    } else if (type == ContactsWrapper.TYPE_CONTACT) {
        ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor);
        ci.userData = cursor.getPosition();
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.contact_name);
        QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo);
        TextView statusText = (TextView) view.findViewById(R.id.status_text);
        ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon);

        // Bind
        if (ci.contactId != null) {
            tv.setText(ci.displayName);
            badge.assignContactUri(ci.callerInfo.contactContentUri);
            ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(),
                    ci.callerInfo, R.drawable.ic_contact_picture_holo_light);

            statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusText.setText(ci.status);
            statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence));
        }
        View v;
        v = view.findViewById(R.id.contact_view);
        v.setTag(ci);
        v.setOnClickListener(mPrimaryActionListener);
        v = view.findViewById(R.id.secondary_action_icon);
        v.setTag(ci);
        v.setOnClickListener(mSecondaryActionListener);
    } else if (type == ContactsWrapper.TYPE_CONFIGURE) {
        // We only bind if it's the correct type
        View v = view.findViewById(R.id.configure_view);
        v.setOnClickListener(this);
        ConfigureObj cfg = new ConfigureObj();
        cfg.profileId = cv.getAsLong(BaseColumns._ID);
        v.setTag(cfg);
    }
}

From source file:com.gelakinetic.mtgfam.activities.MainActivity.java

public void showDialogFragment(final int id) {
    // DialogFragment.show() will take care of adding the fragment
    // in a transaction. We also want to remove any currently showing
    // dialog, so make our own transaction and take care of that here.
    this.showContent();
    FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
    Fragment prev = getSupportFragmentManager().findFragmentByTag(FamiliarFragment.DIALOG_TAG);
    if (prev != null) {
        ft.remove(prev);/*from w  ww .  j  ava 2 s.  co m*/
    }

    // Create and show the dialog.
    FamiliarDialogFragment newFragment = new FamiliarDialogFragment() {

        @Override
        public void onDismiss(DialogInterface mDialog) {
            super.onDismiss(mDialog);
            if (bounceMenu) {
                getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                bounceMenu = false;
                Runnable r = new Runnable() {

                    @Override
                    public void run() {
                        long timeStarted = System.currentTimeMillis();
                        Message msg = Message.obtain();
                        msg.arg1 = OPEN;
                        bounceHandler.sendMessage(msg);
                        while (System.currentTimeMillis() < (timeStarted + 1500)) {
                            ;
                        }
                        msg = Message.obtain();
                        msg.arg1 = CLOSE;
                        bounceHandler.sendMessage(msg);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
                            }
                        });
                    }
                };

                Thread t = new Thread(r);
                t.start();
            }
        }

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            switch (id) {
            case DONATEDIALOG: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
                builder.setTitle(R.string.main_donate_dialog_title);
                builder.setNeutralButton(R.string.dialog_thanks_anyway, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

                LayoutInflater inflater = this.getActivity().getLayoutInflater();
                View dialoglayout = inflater.inflate(R.layout.about_dialog,
                        (ViewGroup) findViewById(R.id.dialog_layout_root));

                TextView text = (TextView) dialoglayout.findViewById(R.id.aboutfield);
                text.setText(ImageGetterHelper.jellyBeanHack(getString(R.string.main_donate_text)));
                text.setMovementMethod(LinkMovementMethod.getInstance());

                text.setTextSize(15);

                ImageView paypal = (ImageView) dialoglayout.findViewById(R.id.imageview1);
                paypal.setImageResource(R.drawable.paypal);
                paypal.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=SZK4TAH2XBZNC&lc=US&item_name=MTG%20Familiar&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted"));

                        startActivity(myIntent);
                    }
                });
                ((ImageView) dialoglayout.findViewById(R.id.imageview2)).setVisibility(View.GONE);

                builder.setView(dialoglayout);
                return builder.create();
            }
            case ABOUTDIALOG: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());

                // You have to catch the exception because the package stuff is all
                // run-time
                if (pInfo != null) {
                    builder.setTitle(getString(R.string.main_about) + " " + getString(R.string.app_name) + " "
                            + pInfo.versionName);
                } else {
                    builder.setTitle(getString(R.string.main_about) + " " + getString(R.string.app_name));
                }

                builder.setNeutralButton(R.string.dialog_thanks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

                LayoutInflater inflater = this.getActivity().getLayoutInflater();
                View dialoglayout = inflater.inflate(R.layout.about_dialog,
                        (ViewGroup) findViewById(R.id.dialog_layout_root));

                TextView text = (TextView) dialoglayout.findViewById(R.id.aboutfield);
                text.setText(ImageGetterHelper.jellyBeanHack(getString(R.string.main_about_text)));
                text.setMovementMethod(LinkMovementMethod.getInstance());

                builder.setView(dialoglayout);
                return builder.create();
            }
            case CHANGELOGDIALOG: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());

                if (pInfo != null) {
                    builder.setTitle(getString(R.string.main_whats_new_in_title) + " " + pInfo.versionName);
                } else {
                    builder.setTitle(R.string.main_whats_new_title);
                }

                builder.setNeutralButton(R.string.dialog_enjoy, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

                builder.setMessage(ImageGetterHelper.jellyBeanHack(getString(R.string.main_whats_new_text)));
                return builder.create();
            }
            default: {
                savedInstanceState.putInt("id", id);
                return super.onCreateDialog(savedInstanceState);
            }
            }
        }
    };
    newFragment.show(ft, FamiliarFragment.DIALOG_TAG);
}

From source file:com.example.drugsformarinemammals.General_Info_Drug.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.general_info_drug);
    isStoredInLocal = false;/*from w ww . j  a  va  2  s .c  om*/
    fiveLastScreen = false;
    helper = new Handler_Sqlite(this);
    helper.open();
    Bundle extras1 = this.getIntent().getExtras();
    if (extras1 != null) {
        infoBundle = extras1.getStringArrayList("generalInfoDrug");
        fiveLastScreen = extras1.getBoolean("fiveLastScreen");
        if (infoBundle == null)
            isStoredInLocal = true;
        if (!isStoredInLocal) {
            initializeGeneralInfoDrug();
            initializeCodesInformation();
            initializeCodes();
        } else {
            drug_name = extras1.getString("drugName");
            codes = helper.getCodes(drug_name);
            codesInformation = helper.getCodesInformation(drug_name);
        }
        //Title
        TextView drugTitle = (TextView) findViewById(R.id.drugTitle);
        drugTitle.setText(drug_name);
        drugTitle.setTypeface(Typeface.SANS_SERIF);

        //Description 
        LinearLayout borderDescription = new LinearLayout(this);
        borderDescription.setOrientation(LinearLayout.VERTICAL);
        borderDescription
                .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        borderDescription.setBackgroundResource(R.drawable.layout_border);

        TextView description = new TextView(this);
        if (isStoredInLocal)
            description.setText(helper.getDescription(drug_name));
        else
            description.setText(this.description);
        description.setTextSize(18);
        description.setTypeface(Typeface.SANS_SERIF);

        LinearLayout.LayoutParams paramsDescription = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsDescription.leftMargin = 60;
        paramsDescription.rightMargin = 60;
        paramsDescription.topMargin = 20;

        borderDescription.addView(description, borderDescription.getChildCount(), paramsDescription);

        LinearLayout layoutDescription = (LinearLayout) findViewById(R.id.layoutDescription);
        layoutDescription.addView(borderDescription, layoutDescription.getChildCount());

        //Animals
        TextView headerAnimals = (TextView) findViewById(R.id.headerAnimals);
        headerAnimals.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);

        Button cetaceansButton = (Button) findViewById(R.id.cetaceansButton);
        cetaceansButton.setText("CETACEANS");
        cetaceansButton.setTypeface(Typeface.SANS_SERIF);
        cetaceansButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                showDoseInformation(drug_name, "Cetaceans");
            }
        });

        Button pinnipedsButton = (Button) findViewById(R.id.pinnipedsButton);
        pinnipedsButton.setText("PINNIPEDS");
        pinnipedsButton.setTypeface(Typeface.SANS_SERIF);
        pinnipedsButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                SQLiteDatabase db = helper.open();
                ArrayList<String> families = new ArrayList<String>();
                if (db != null)
                    families = helper.read_animals_family(drug_name, "Pinnipeds");
                if ((families != null && families.size() == 1 && families.get(0).equals(""))
                        || (families != null && families.size() == 0))
                    showDoseInformation(drug_name, "Pinnipeds");
                else
                    showDoseInformationPinnipeds(drug_name, families);
            }
        });

        Button otherButton = (Button) findViewById(R.id.otherButton);
        otherButton.setText("OTHER MM");
        otherButton.setTypeface(Typeface.SANS_SERIF);
        otherButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                showDoseInformation(drug_name, "Other MM");
            }
        });

        //Codes & therapeutic target & anatomical target
        TextView headerATCvetCodes = (TextView) findViewById(R.id.headerATCvetCodes);
        headerATCvetCodes.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);

        //Action
        TextView headerActionAnatomical = (TextView) findViewById(R.id.headerActionAnatomical);
        headerActionAnatomical.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);

        createTextViewAnatomical();
        createBorderAnatomicalGroup();

        TextView headerActionTherapeutic = (TextView) findViewById(R.id.headerActionTherapeutic);
        headerActionTherapeutic.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);

        createTextViewTherapeutic();
        createBorderTherapeuticGroup();

        params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.leftMargin = 60;
        params.rightMargin = 60;
        params.topMargin = 20;

        Spinner codesSpinner = (Spinner) findViewById(R.id.codesSpinner);
        SpinnerAdapter adapterCodes = new SpinnerAdapter(this, R.layout.item_spinner, codes);
        adapterCodes.setDropDownViewResource(R.layout.spinner_dropdown_item);
        codesSpinner.setAdapter(adapterCodes);
        codesSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parent, View arg1, int arg2, long arg3) {
                userEntryCode = parent.getSelectedItem().toString();
                int numCodes = codesInformation.size();

                layoutAnatomicalGroup.removeView(borderAnatomicalGroup);
                createBorderAnatomicalGroup();

                boolean founded = false;
                int i = 0;
                while (!founded && i < numCodes) {
                    if (userEntryCode.equals(codesInformation.get(i).getCode())) {
                        createTextViewAnatomical();
                        anatomicalGroup.setText(codesInformation.get(i).getAnatomic_group() + "\n");
                        borderAnatomicalGroup.addView(anatomicalGroup, borderAnatomicalGroup.getChildCount(),
                                params);
                        founded = true;
                    }
                    i++;
                }

                layoutAnatomicalGroup = (LinearLayout) findViewById(R.id.layoutActionAnatomical);
                layoutAnatomicalGroup.addView(borderAnatomicalGroup, layoutAnatomicalGroup.getChildCount());
                layoutTherapeuticGroup.removeView(borderTherapeuticGroup);
                createBorderTherapeuticGroup();
                founded = false;
                i = 0;
                while (!founded && i < numCodes) {
                    if (userEntryCode.equals(codesInformation.get(i).getCode())) {
                        createTextViewTherapeutic();
                        therapeuticGroup.setText(codesInformation.get(i).getTherapeutic_group() + "\n");
                        borderTherapeuticGroup.addView(therapeuticGroup, borderTherapeuticGroup.getChildCount(),
                                params);
                        founded = true;
                    }
                    i++;
                }
                layoutTherapeuticGroup = (LinearLayout) findViewById(R.id.layoutActionTherapeutic);
                layoutTherapeuticGroup.addView(borderTherapeuticGroup, layoutTherapeuticGroup.getChildCount());
            }

            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });

        layoutAnatomicalGroup = (LinearLayout) findViewById(R.id.layoutActionAnatomical);
        layoutTherapeuticGroup = (LinearLayout) findViewById(R.id.layoutActionTherapeutic);

        borderTherapeuticGroup.addView(therapeuticGroup, borderTherapeuticGroup.getChildCount(), params);
        borderAnatomicalGroup.addView(anatomicalGroup, borderAnatomicalGroup.getChildCount(), params);

        layoutAnatomicalGroup.addView(borderAnatomicalGroup, layoutAnatomicalGroup.getChildCount());
        layoutTherapeuticGroup.addView(borderTherapeuticGroup, layoutTherapeuticGroup.getChildCount());

        //Generic Drug
        TextView headerGenericDrug = (TextView) findViewById(R.id.headerGenericDrug);
        headerGenericDrug.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
        boolean isAvalaible = false;
        if (isStoredInLocal)
            isAvalaible = helper.isAvalaible(drug_name);
        else
            isAvalaible = available.equals("Yes");
        if (isAvalaible) {
            ImageView genericDrug = new ImageView(this);
            genericDrug.setImageResource(R.drawable.tick_verde);
            LinearLayout layoutGenericDrug = (LinearLayout) findViewById(R.id.layoutGenericDrug);
            layoutGenericDrug.addView(genericDrug);
        } else {
            Typeface font = Typeface.createFromAsset(getAssets(), "Typoster_demo.otf");
            TextView genericDrug = new TextView(this);
            genericDrug.setTypeface(font);
            genericDrug.setText("Nd");
            genericDrug.setTextColor(getResources().getColor(R.color.maroon));
            genericDrug.setTextSize(20);
            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int size = metrics.widthPixels;
            int middle = size / 2;
            int quarter = size / 4;
            genericDrug.setTranslationX(middle - quarter);
            genericDrug.setTranslationY(-3);
            LinearLayout layoutGenericDrug = (LinearLayout) findViewById(R.id.layoutGenericDrug);
            layoutGenericDrug.addView(genericDrug);
        }

        //Licenses
        TextView headerLicense = (TextView) findViewById(R.id.headerLicense);
        headerLicense.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);

        TextView fdaLicense = (TextView) findViewById(R.id.license1);
        Typeface font = Typeface.createFromAsset(getAssets(), "Typoster_demo.otf");
        fdaLicense.setTypeface(font);

        String fda;
        if (isStoredInLocal)
            fda = helper.getLicense_FDA(drug_name);
        else
            fda = license_FDA;
        if (fda.equals("Yes")) {
            fdaLicense.setText("Yes");
            fdaLicense.setTextColor(getResources().getColor(R.color.lightGreen));
        } else {
            fdaLicense.setText("Nd");
            fdaLicense.setTextColor(getResources().getColor(R.color.maroon));
        }

        TextView emaLicense = (TextView) findViewById(R.id.license3);
        emaLicense.setTypeface(font);
        String ema;
        if (isStoredInLocal)
            ema = helper.getLicense_EMA(drug_name);
        else
            ema = license_EMA;
        if (ema.equals("Yes")) {
            emaLicense.setText("Yes");
            emaLicense.setTextColor(getResources().getColor(R.color.lightGreen));
        } else {
            emaLicense.setText("Nd");
            emaLicense.setTextColor(getResources().getColor(R.color.maroon));
        }

        TextView aempsLicense = (TextView) findViewById(R.id.license2);
        aempsLicense.setTypeface(font);
        String aemps;
        if (isStoredInLocal)
            aemps = helper.getLicense_AEMPS(drug_name);
        else
            aemps = license_AEMPS;
        if (aemps.equals("Yes")) {
            aempsLicense.setText("Yes");
            aempsLicense.setTextColor(getResources().getColor(R.color.lightGreen));
        } else {
            aempsLicense.setText("Nd");
            aempsLicense.setTextColor(getResources().getColor(R.color.maroon));
        }

        ImageButton food_and_drug = (ImageButton) findViewById(R.id.food_and_drug);
        food_and_drug.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(
                        "http://www.fda.gov/animalveterinary/products/approvedanimaldrugproducts/default.htm"));
                startActivity(intent);
            }
        });

        ImageButton european_medicines_agency = (ImageButton) findViewById(R.id.european_medicines_agency);
        european_medicines_agency.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(
                        "http://www.ema.europa.eu/ema/index.jsp?curl=pages/medicines/landing/vet_epar_search.jsp&mid=WC0b01ac058001fa1c"));
                startActivity(intent);
            }
        });

        ImageButton logo_aemps = (ImageButton) findViewById(R.id.logo_aemps);
        logo_aemps.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(
                        "http://www.aemps.gob.es/medicamentosVeterinarios/Med-Vet-autorizados/home.htm"));
                startActivity(intent);
            }

        });

        if (helper.existDrug(drug_name)) {
            int drug_priority = helper.getDrugPriority(drug_name);
            ArrayList<String> sorted_drugs = new ArrayList<String>();
            sorted_drugs.add(0, drug_name);
            for (int i = 1; i < drug_priority; i++) {
                String name = helper.getDrugName(i);
                sorted_drugs.add(i, name);
            }

            for (int i = 0; i < sorted_drugs.size(); i++)
                helper.setDrugPriority(sorted_drugs.get(i), i + 1);
        }

        if (!isStoredInLocal) {
            //Server code
            String[] urls = { "http://formmulary.tk/Android/getDoseInformation.php?drug_name=",
                    "http://formmulary.tk/Android/getGeneralNotesInformation.php?drug_name=" };
            new GetDoseInformation(this).execute(urls);
        }

        helper.close();
    }

}

From source file:com.mobicage.rogerthat.plugins.friends.ServiceActionMenuActivity.java

private void populateScreen(final ServiceMenu menu) {
    menuBrandingHash = menu.branding;/*from   ww  w  .  j a  v  a  2  s  .c om*/
    final FriendsPlugin friendsPlugin = mService.getPlugin(FriendsPlugin.class);
    final MessagingPlugin messagingPlugin = mService.getPlugin(MessagingPlugin.class);
    final FriendStore store = friendsPlugin.getStore();

    List<Cell> usedCells = new ArrayList<Cell>();
    if (page == 0) {
        addAboutHandler(usedCells, menu.aboutLabel);
        addHistoryHandler(usedCells, store, menu.messagesLabel);
        addCallHandler(menu, usedCells, menu.callLabel);
        if (CloudConstants.isYSAAA()) {
            addScanHandler(menu, usedCells, null);
        } else {
            addShareHandler(menu, usedCells, menu.shareLabel);
        }
    }
    boolean[] rows = new boolean[] { false, false, false };
    if (page == 0)
        rows[0] = true;
    for (final ServiceMenuItem item : menu.itemList) {
        rows[(int) item.coords[1]] = true;
        final Cell cell = cells[(int) item.coords[0]][(int) item.coords[1]];
        View.OnClickListener onClickListener = new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                pressMenuItem(menu, messagingPlugin, store, item);
            }
        };
        ((View) cell.icon.getParent()).setOnClickListener(onClickListener);
        cell.icon.setImageBitmap(BitmapFactory.decodeByteArray(item.icon, 0, item.icon.length));
        cell.icon.setVisibility(View.VISIBLE);
        cell.label.setText(item.label);
        cell.label.setVisibility(View.VISIBLE);
        usedCells.add(cell);
    }
    for (int i = 2; i >= 0; i--) {
        if (rows[i])
            break;
        tableRows[i].setVisibility(View.GONE);
    }
    boolean showBranded = false;
    boolean useDarkScheme = false;
    Integer menuItemColor = null;
    if (menu.branding != null) {
        try {
            BrandingMgr brandingMgr = messagingPlugin.getBrandingMgr();
            Friend friend = store.getExistingFriend(email);
            if (brandingMgr.isBrandingAvailable(menu.branding)) {
                BrandingResult br = brandingMgr.prepareBranding(menu.branding, friend, false);
                WebSettings settings = branding.getSettings();
                settings.setJavaScriptEnabled(false);
                settings.setBlockNetworkImage(false);
                branding.setVisibility(View.VISIBLE);
                branding.setVerticalScrollBarEnabled(false);

                final int displayWidth = UIUtils.getDisplayWidth(this);
                final int calculatedHeight = BrandingMgr.calculateHeight(br, displayWidth);
                final long start = System.currentTimeMillis();
                branding.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                    @Override
                    public boolean onPreDraw() {
                        int height = branding.getMeasuredHeight();
                        if (height > calculatedHeight * 90 / 100 || System.currentTimeMillis() - start > 3000) {
                            if (calculatedHeight > 0) {
                                setBrandingHeight(height);
                            } else {
                                mService.postDelayedOnUIHandler(new SafeRunnable() {
                                    @Override
                                    protected void safeRun() throws Exception {
                                        setBrandingHeight(branding.getMeasuredHeight());
                                    }
                                }, 100);
                            }
                            branding.getViewTreeObserver().removeOnPreDrawListener(this);
                        }
                        return false;
                    }
                });
                branding.loadUrl("file://" + br.file.getAbsolutePath());

                if (br.color != null) {
                    branding.setBackgroundColor(br.color);
                    activity.setBackgroundColor(br.color);
                }
                if (br.scheme == ColorScheme.dark) {
                    for (Cell cell : usedCells) {
                        cell.label.setTextColor(darkSchemeTextColor);
                        cell.label.setShadowLayer(2, 1, 1, Color.BLACK);
                    }
                    useDarkScheme = true;
                }
                menuItemColor = br.menuItemColor;

                final ImageView watermarkView = (ImageView) findViewById(R.id.watermark);
                if (br.watermark != null) {
                    BitmapDrawable watermark = new BitmapDrawable(getResources(),
                            BitmapFactory.decodeFile(br.watermark.getAbsolutePath()));
                    watermark.setGravity(Gravity.BOTTOM | Gravity.RIGHT);

                    watermarkView.setImageDrawable(watermark);
                    final LayoutParams layoutParams = watermarkView.getLayoutParams();
                    layoutParams.width = layoutParams.height = displayWidth;
                } else {
                    watermarkView.setImageDrawable(null);
                }

                showBranded = true;
            } else {
                friend.actionMenu = menu;
                friend.actionMenu.items = menu.itemList.toArray(new ServiceMenuItemTO[] {});
                brandingMgr.queue(friend);
            }
        } catch (BrandingFailureException e) {
            L.bug("Could not display service action menu with branding.", e);
        }
    }
    if (!showBranded) {
        setNavigationBarVisible(AppConstants.SHOW_NAV_HEADER);
        setNavigationBarTitle(menu.name);
        title.setVisibility(View.GONE);
        title.setText(menu.name);
    }

    for (final Cell cell : usedCells) {
        final View p = (View) cell.icon.getParent();
        final Drawable d = getResources().getDrawable(
                useDarkScheme ? R.drawable.mc_smi_background_light : R.drawable.mc_smi_background_dark);
        p.setBackgroundDrawable(d);
    }

    if (menuItemColor == null)
        menuItemColor = Color.parseColor("#646464");

    for (Cell cell : new Cell[] { cells[0][0], cells[1][0], cells[2][0], cells[3][0] })
        cell.faIcon.setTextColor(menuItemColor);

    if (menu.maxPage > 0) {
        for (int i = 0; i <= menu.maxPage; i++) {
            ImageView bolleke = (ImageView) getLayoutInflater().inflate(R.layout.page, pages, false);
            if (page == i) {
                if (useDarkScheme) {
                    bolleke.setImageResource(R.drawable.current_page_dark);
                } else {
                    bolleke.setImageResource(R.drawable.current_page_light);
                }
            } else {
                if (useDarkScheme) {
                    bolleke.setImageResource(R.drawable.other_page_dark);
                } else {
                    bolleke.setImageResource(R.drawable.other_page_light);
                }
            }
            pages.addView(bolleke);
        }
        pages.setVisibility(View.VISIBLE);
    }
    final int leftPage = page - 1;
    final int rightPage = page + 1;
    final String service = email;
    Slider instance = new Slider(this, this, page == menu.maxPage ? null : new Slider.Swiper() {
        @Override
        public Intent onSwipe() {
            return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class)
                    .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, rightPage);
        }
    }, page == 0 ? null : new Slider.Swiper() {
        @Override
        public Intent onSwipe() {
            return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class)
                    .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, leftPage);
        }
    });
    mGestureScanner = new GestureDetector(this, instance);
}

From source file:com.androidinspain.deskclock.timer.TimerFragment.java

private void updateFab(@NonNull ImageView fab, boolean animate) {
    if (mCurrentView == mTimersView) {
        final Timer timer = getTimer();
        if (timer == null) {
            fab.setVisibility(INVISIBLE);
            return;
        }/*from  www . ja v a 2  s  .c  o  m*/

        fab.setVisibility(VISIBLE);
        switch (timer.getState()) {
        case RUNNING:
            if (animate) {
                fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_play_pause_animation);
            } else {
                fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_play_pause);
            }
            fab.setContentDescription(
                    fab.getResources().getString(com.androidinspain.deskclock.R.string.timer_stop));
            break;
        case RESET:
            if (animate) {
                fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_stop_play_animation);
            } else {
                fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_pause_play);
            }
            fab.setContentDescription(
                    fab.getResources().getString(com.androidinspain.deskclock.R.string.timer_start));
            break;
        case PAUSED:
            if (animate) {
                fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_pause_play_animation);
            } else {
                fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_pause_play);
            }
            fab.setContentDescription(
                    fab.getResources().getString(com.androidinspain.deskclock.R.string.timer_start));
            break;
        case MISSED:
        case EXPIRED:
            fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_stop_white_24dp);
            fab.setContentDescription(
                    fab.getResources().getString(com.androidinspain.deskclock.R.string.timer_stop));
            break;
        }
    } else if (mCurrentView == mCreateTimerView) {
        if (mCreateTimerView.hasValidInput()) {
            fab.setImageResource(com.androidinspain.deskclock.R.drawable.ic_start_white_24dp);
            fab.setContentDescription(
                    fab.getResources().getString(com.androidinspain.deskclock.R.string.timer_start));
            fab.setVisibility(VISIBLE);
        } else {
            fab.setContentDescription(null);
            fab.setVisibility(INVISIBLE);
        }
    }
}

From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java

private View generateCircle(Context context, AttributeSet attrs, DisplayMetrics metrics) {
    ImageView view = new ImageView(context, attrs);
    GradientDrawable circle = (GradientDrawable) getResources().getDrawable(R.drawable.circle);
    circle.setColor(CIRCLE_DEFAULT_COLOR);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(circle);/*from   w ww.  j a  va2s  .  co  m*/
    } else {
        view.setBackgroundDrawable(circle);
    }
    int size = (int) (metrics.density * CIRCLE_SIZE);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(size, size);
    view.setLayoutParams(params);
    view.setImageResource(R.drawable.clip_random);
    view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    view.setRotation(90.0f);
    return view;
}

From source file:com.gimranov.zandy.app.AttachmentActivity.java

/** Called when the activity is first created. */
@Override//  w  w  w.j av a 2 s .  c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    tmpFiles = new ArrayList<File>();

    db = new Database(this);

    /* Get the incoming data from the calling activity */
    final String itemKey = getIntent().getStringExtra("com.gimranov.zandy.app.itemKey");
    Item item = Item.load(itemKey, db);
    this.item = item;

    if (item == null) {
        Log.e(TAG, "AttachmentActivity started without itemKey; finishing.");
        finish();
        return;
    }

    this.setTitle(getResources().getString(R.string.attachments_for_item, item.getTitle()));

    ArrayList<Attachment> rows = Attachment.forItem(item, db);

    /* 
     * We use the standard ArrayAdapter, passing in our data as a Attachment.
     * Since it's no longer a simple TextView, we need to override getView, but
     * we can do that anonymously.
     */
    setListAdapter(new ArrayAdapter<Attachment>(this, R.layout.list_attach, rows) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row;

            // We are reusing views, but we need to initialize it if null
            if (null == convertView) {
                LayoutInflater inflater = getLayoutInflater();
                row = inflater.inflate(R.layout.list_attach, null);
            } else {
                row = convertView;
            }

            ImageView tvType = (ImageView) row.findViewById(R.id.attachment_type);
            TextView tvSummary = (TextView) row.findViewById(R.id.attachment_summary);

            Attachment att = getItem(position);
            Log.d(TAG, "Have an attachment: " + att.title + " fn:" + att.filename + " status:" + att.status);

            tvType.setImageResource(Item.resourceForType(att.getType()));

            try {
                Log.d(TAG, att.content.toString(4));
            } catch (JSONException e) {
                Log.e(TAG, "JSON parse exception when reading attachment content", e);
            }

            if (att.getType().equals("note")) {
                String note = att.content.optString("note", "");
                if (note.length() > 40) {
                    note = note.substring(0, 40);
                }
                tvSummary.setText(note);
            } else {
                StringBuffer status = new StringBuffer(getResources().getString(R.string.status));
                if (att.status == Attachment.AVAILABLE)
                    status.append(getResources().getString(R.string.attachment_zfs_available));
                else if (att.status == Attachment.LOCAL)
                    status.append(getResources().getString(R.string.attachment_zfs_local));
                else
                    status.append(getResources().getString(R.string.attachment_unknown));
                tvSummary.setText(att.title + " " + status.toString());
            }
            return row;
        }
    });

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        // Warning here because Eclipse can't tell whether my ArrayAdapter is
        // being used with the correct parametrization.
        @SuppressWarnings("unchecked")
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // If we have a click on an entry, show its note
            ArrayAdapter<Attachment> adapter = (ArrayAdapter<Attachment>) parent.getAdapter();
            Attachment row = adapter.getItem(position);

            if (row.content.has("note")) {
                Log.d(TAG, "Trying to start note view activity for: " + row.key);
                Intent i = new Intent(getBaseContext(), NoteActivity.class);
                i.putExtra("com.gimranov.zandy.app.attKey", row.key);//row.content.optString("note", ""));
                startActivity(i);
            }
            return true;
        }
    });
    lv.setOnItemClickListener(new OnItemClickListener() {
        // Warning here because Eclipse can't tell whether my ArrayAdapter is
        // being used with the correct parametrization.
        @SuppressWarnings("unchecked")
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // If we have a long click on an entry, do something...
            ArrayAdapter<Attachment> adapter = (ArrayAdapter<Attachment>) parent.getAdapter();
            Attachment row = adapter.getItem(position);
            String url = (row.url != null && !row.url.equals("")) ? row.url : row.content.optString("url");

            if (!row.getType().equals("note")) {
                Bundle b = new Bundle();
                b.putString("title", row.title);
                b.putString("attachmentKey", row.key);
                b.putString("content", url);
                SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
                int linkMode = row.content.optInt("linkMode", Attachment.MODE_IMPORTED_URL);

                if (settings.getBoolean("webdav_enabled", false))
                    b.putString("mode", "webdav");
                else
                    b.putString("mode", "zfs");

                if (linkMode == Attachment.MODE_IMPORTED_FILE || linkMode == Attachment.MODE_IMPORTED_URL) {
                    loadFileAttachment(b);
                } else {
                    AttachmentActivity.this.b = b;
                    showDialog(DIALOG_CONFIRM_NAVIGATE);
                }
            }

            if (row.getType().equals("note")) {
                Bundle b = new Bundle();
                b.putString("attachmentKey", row.key);
                b.putString("itemKey", itemKey);
                b.putString("content", row.content.optString("note", ""));
                removeDialog(DIALOG_NOTE);
                AttachmentActivity.this.b = b;
                showDialog(DIALOG_NOTE);
            }
            return;
        }
    });
}