Example usage for android.widget LinearLayout findViewById

List of usage examples for android.widget LinearLayout findViewById

Introduction

In this page you can find the example usage for android.widget LinearLayout findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java

@SuppressWarnings("deprecation")
private void initData() {

    DisplayMetrics metric = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metric);
    mPref = getSharedPreferences("text", Context.MODE_PRIVATE);
    String text = mPref.getString("text", "");
    if (!TextUtils.isEmpty(text)) {
        mEditText.setText(text);/*  w w  w.ja v a 2 s . co  m*/
        mEditText.setSelection(text.length());
    }

    mNavigationLayout.setBackgroundColor(config.navBgColor);

    if (TextUtils.isEmpty(config.searchBoxBgImg)) {
        BitmapDrawable bitmapDrawable = new BitmapDrawable(BitmapFactory.decodeResource(getResources(),
                UZResourcesIDFinder.getResDrawableID("mo_searchbar_bg")));
        mRelativeLayout.setBackgroundDrawable(bitmapDrawable);
    } else {
        BitmapDrawable bitmapDrawable = new BitmapDrawable(generateBitmap(config.searchBoxBgImg));
        mRelativeLayout.setBackgroundDrawable(bitmapDrawable);
    }

    if (config.cancel_bg_bitmap != null) {
        mTextView.setBackgroundDrawable(new BitmapDrawable(config.cancel_bg_bitmap));
    } else {
        mTextView.setBackgroundColor(config.cancel_bg_color);
    }

    mTextView.setTextSize(config.cancel_size);
    mTextView.setTextColor(config.cancal_color);

    LayoutParams params = new LayoutParams(UZUtility.dipToPix(config.searchBoxWidth),
            UZUtility.dipToPix(config.searchBoxHeight));
    params.setMargins(UZUtility.dipToPix(10), 0, 0, 0);

    params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mEditText.setLayoutParams(params);

    WindowManager wm = this.getWindowManager();
    int width = wm.getDefaultDisplay().getWidth();

    double realWidth = width * 0.80;
    LayoutParams layoutParams = new LayoutParams((int) realWidth, UZUtility.dipToPix(config.searchBoxHeight));

    layoutParams.setMargins(UZUtility.dipToPix(5), 0, 0, 0);
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

    layoutParams.topMargin = UZUtility.dipToPix(8);
    layoutParams.bottomMargin = UZUtility.dipToPix(8);

    mRelativeLayout.setLayoutParams(layoutParams);

    double cancelRealWidth = width * 0.15;

    int space = (width - (int) realWidth - (int) cancelRealWidth - UZUtility.dipToPix(5)) / 2;

    LayoutParams cancalTxtParam = new LayoutParams((int) cancelRealWidth,
            UZUtility.dipToPix(config.searchBoxHeight));

    cancalTxtParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    cancalTxtParam.addRule(RelativeLayout.CENTER_VERTICAL);

    cancalTxtParam.rightMargin = space;
    cancalTxtParam.leftMargin = space;

    mTextView.setLayoutParams(cancalTxtParam);

    mListView.setBackgroundColor(config.list_bg_color);

    listSize = config.list_size;
    mCleanTextColor = config.clear_font_color;
    mCleanTextSize = config.clear_font_size;

    recordCount = config.historyCount;

    /**
     * add clean list item
     */
    int relativeLayoutCleanId = UZResourcesIDFinder.getResLayoutID("mo_searchbar_clean_item");
    relativeLayoutClean = (LinearLayout) View.inflate(getApplicationContext(), relativeLayoutCleanId, null);
    int tv_cleanId = UZResourcesIDFinder.getResIdID("tv_clean");
    mCleanTV = (TextView) relativeLayoutClean.findViewById(tv_cleanId);
    mCleanTV.setTextSize(mCleanTextSize);
    mCleanTV.setTextColor(mCleanTextColor);

    mCleanTV.setText(config.clearText);

    relativeLayoutClean
            .setBackgroundDrawable(addStateDrawable(config.clear_bg_color, config.clear_active_bg_color));
    list.clear();

    list.add(relativeLayoutClean);
    mPref = getSharedPreferences("history" + config.database, Context.MODE_PRIVATE);

    editor = mPref.edit();

    trimHistroyList(config.historyCount);

    @SuppressWarnings("unchecked")
    Map<String, String> map = (Map<String, String>) mPref.getAll();
    if (map != null) {
        if (map.size() != 0) {
            for (int i = 1; i <= map.size(); i++) {

                int listview_item = UZResourcesIDFinder.getResLayoutID("mo_searchbar_listview_item");
                LinearLayout linearLayout = (LinearLayout) View.inflate(SearchBarActivity.this, listview_item,
                        null);
                int tv_listId = UZResourcesIDFinder.getResIdID("tv_listview");
                TextView tv = (TextView) linearLayout.findViewById(tv_listId);
                tv.setTextSize(listSize);
                tv.setTextColor(config.list_color);

                linearLayout.setBackgroundDrawable(
                        addStateDrawable(config.list_bg_color, config.list_item_active_bg_color));

                int itemBorderLineId = UZResourcesIDFinder.getResIdID("item_border_line");
                linearLayout.findViewById(itemBorderLineId).setBackgroundColor(config.list_border_color);

                for (Entry<String, String> iterable_element : map.entrySet()) {
                    String key = iterable_element.getKey();
                    if ((i + "").equals(key)) {
                        tv.setText(iterable_element.getValue());
                    }
                }
                list.addFirst(linearLayout);
            }
            id = map.size();
        }
    }

    adapter = new MyAdapter();
    mListView.setAdapter(adapter);
}

From source file:br.com.mybaby.contatos.ContactDetailFragment.java

/**
  * Builds an address LinearLayout based on address information from the Contacts Provider.
  * Each address for the contact gets its own LinearLayout object; for example, if the contact
  * has three postal addresses, then 3 LinearLayouts are generated.
  *//from ww  w. j av  a 2  s .c o  m
  * @param addressType From
  * {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#TYPE}
  * @param addressTypeLabel From
  * {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#LABEL}
  * @param address From
  * {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#FORMATTED_ADDRESS}
  * @return A LinearLayout to add to the contact details layout,
  *         populated with the provided address details.
  */
private LinearLayout buildAddressLayout(int addressType, String addressTypeLabel, final String address) {

    // Inflates the address layout
    final LinearLayout addressLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contatos_detail_item, mDetailsLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) addressLayout.findViewById(R.id.contact_detail_header);
    final TextView addressTextView = (TextView) addressLayout.findViewById(R.id.contact_detail_item);
    final ImageButton viewAddressButton = (ImageButton) addressLayout.findViewById(R.id.button_view_address);

    // If there's no addresses for the contact, shows the empty view and message, and hides the
    // header and button.
    if (addressTypeLabel == null && addressType == 0) {
        headerTextView.setVisibility(View.GONE);
        viewAddressButton.setVisibility(View.GONE);
        addressTextView.setText(R.string.no_address);
    } else {
        // Gets postal address label type
        CharSequence label = StructuredPostal.getTypeLabel(getResources(), addressType, addressTypeLabel);

        // Sets TextView objects in the layout
        headerTextView.setText(label);
        addressTextView.setText(address);

        // Defines an onClickListener object for the address button
        viewAddressButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {

                final Intent viewIntent = new Intent(Intent.ACTION_VIEW, constructGeoUri(address));

                // A PackageManager instance is needed to verify that there's a default app
                // that handles ACTION_VIEW and a geo Uri.
                final PackageManager packageManager = getActivity().getPackageManager();

                // Checks for an activity that can handle this intent. Preferred in this
                // case over Intent.createChooser() as it will still let the user choose
                // a default (or use a previously set default) for geo Uris.
                if (packageManager.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    startActivity(viewIntent);
                } else {
                    // If no default is found, displays a message that no activity can handle
                    // the view button.
                    Toast.makeText(getActivity(), R.string.no_intent_found, Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
    return addressLayout;
}

From source file:br.com.mybaby.contatos.ContactDetailFragment.java

/**
 * Builds a phone  layout/*from   w  w w.  ja  v  a  2 s  .com*/
 *
 * @return A LinearLayout from phones
 */
private LinearLayout buildPhoneLayout(final Integer id, String number, boolean checked) {
    // Inflates the address layout
    final LinearLayout phoneLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contatos_phone_detail_item, mDetailsLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) phoneLayout.findViewById(R.id.contact_phone_detail_header);

    final TextView phoneTextView = (TextView) phoneLayout.findViewById(R.id.contact_phone_detail_item);

    final CheckBox phoneCheckBox = (CheckBox) phoneLayout.findViewById(R.id.checkbox_phone);

    phoneCheckBox.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            CheckBox cb = (CheckBox) v;

            Telefone _tel = new Telefone();
            _tel.setId(cb.getId());

            if (cb.isChecked()) {
                if (telefonesBase.size() == 4) {
                    Toast.makeText(getActivity(), "Mximo de telefones selecionados: 4", Toast.LENGTH_LONG)
                            .show();
                    cb.setChecked(false);
                } else {
                    int posicao = telefonesContatoAtual.indexOf(_tel);
                    contatoParaSalvar.getTelefones().add(telefonesContatoAtual.get(posicao));
                    telefonesBase.add(telefonesContatoAtual.get(posicao));
                }
            } else {
                int posicao = contatoParaSalvar.getTelefones().indexOf(_tel);
                contatoParaSalvar.getTelefones().remove(posicao);
                telefonesBase.remove(posicao);
            }
        }
    });

    if (phoneTextView == null) {
        headerTextView.setVisibility(View.GONE);
        phoneTextView.setText(R.string.no_address);
        phoneCheckBox.setVisibility(View.GONE);

    } else {
        phoneCheckBox.setId(id);
        phoneCheckBox.setChecked(checked);
        phoneTextView.setText(number);
    }

    return phoneLayout;
}

From source file:com.saulcintero.moveon.fragments.Summary1.java

@SuppressLint("Recycle")
@Override// w w  w  . j av  a  2 s  . c  o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout fragmentView = (LinearLayout) inflater.inflate(R.layout.summary1, container, false);
    layout1 = (LinearLayout) fragmentView.findViewById(R.id.linearLayout1);

    act = getActivity();
    mContext = act.getApplicationContext();
    res = getResources();

    prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    editor = prefs.edit();

    id = prefs.getInt("selected_practice", 0);

    isMetric = FunctionUtils.checkIfUnitsAreMetric(mContext);

    check1 = (CheckBox) fragmentView.findViewById(R.id.checkBox1);
    check2 = (CheckBox) fragmentView.findViewById(R.id.checkBox2);
    check3 = (CheckBox) fragmentView.findViewById(R.id.checkBox3);
    full_mapview = (ImageButton) fragmentView.findViewById(R.id.summary_mapview_fullscreen);
    label1 = (TextView) fragmentView.findViewById(R.id.summary_label_one);
    label2 = (TextView) fragmentView.findViewById(R.id.summary_label_two);
    label3 = (TextView) fragmentView.findViewById(R.id.summary_label_three);
    label4 = (TextView) fragmentView.findViewById(R.id.summary_label_four);
    label5 = (TextView) fragmentView.findViewById(R.id.summary_label_five);
    label6 = (TextView) fragmentView.findViewById(R.id.summary_label_six);
    label7 = (TextView) fragmentView.findViewById(R.id.summary_label_seven);
    label8 = (TextView) fragmentView.findViewById(R.id.summary_label_eight);
    label9 = (TextView) fragmentView.findViewById(R.id.summary_label_nine);
    label10 = (TextView) fragmentView.findViewById(R.id.summary_label_ten);
    label11 = (TextView) fragmentView.findViewById(R.id.summary_label_eleven);
    label12 = (TextView) fragmentView.findViewById(R.id.summary_label_twelve);
    label13 = (TextView) fragmentView.findViewById(R.id.summary_label_thirteen);
    label14 = (TextView) fragmentView.findViewById(R.id.summary_label_fourteen);
    label15 = (TextView) fragmentView.findViewById(R.id.summary_label_fifteen);
    label16 = (TextView) fragmentView.findViewById(R.id.summary_label_sixteen);
    label17 = (TextView) fragmentView.findViewById(R.id.summary_label_seventeen);
    text1 = (TextView) fragmentView.findViewById(R.id.summary_date);
    text2 = (TextView) fragmentView.findViewById(R.id.summary_text_one);
    text3 = (TextView) fragmentView.findViewById(R.id.summary_text_two);
    text4 = (TextView) fragmentView.findViewById(R.id.summary_text_three);
    text5 = (TextView) fragmentView.findViewById(R.id.summary_text_four);
    text6 = (TextView) fragmentView.findViewById(R.id.summary_text_five);
    text7 = (TextView) fragmentView.findViewById(R.id.summary_text_six);
    text8 = (TextView) fragmentView.findViewById(R.id.summary_text_seven);
    text9 = (TextView) fragmentView.findViewById(R.id.summary_text_eight);
    text10 = (TextView) fragmentView.findViewById(R.id.summary_text_nine);
    text11 = (TextView) fragmentView.findViewById(R.id.summary_text_ten);
    text12 = (TextView) fragmentView.findViewById(R.id.summary_text_eleven);
    text13 = (TextView) fragmentView.findViewById(R.id.summary_text_twelve);
    text14 = (TextView) fragmentView.findViewById(R.id.summary_text_thirteen);
    text15 = (TextView) fragmentView.findViewById(R.id.summary_text_fourteen);
    text16 = (TextView) fragmentView.findViewById(R.id.summary_text_fifteen);
    text17 = (TextView) fragmentView.findViewById(R.id.summary_text_sixteen);
    text18 = (TextView) fragmentView.findViewById(R.id.summary_text_seventeen);

    activity_image = (ImageView) fragmentView.findViewById(R.id.summary_activity);

    mGallery = (Gallery) fragmentView.findViewById(R.id.gallery);

    // set gallery to left side
    DisplayMetrics metrics = new DisplayMetrics();
    act.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    MarginLayoutParams mlp = (MarginLayoutParams) mGallery.getLayoutParams();
    mlp.setMargins(-(metrics.widthPixels / 2 + 75), mlp.topMargin, mlp.rightMargin, mlp.bottomMargin);

    String[] data = DataFunctionUtils.getRouteData(mContext, id, isMetric);

    label1.setText(getString(R.string.time_label).toUpperCase(Locale.getDefault()));
    label2.setText(getString(R.string.distance_label).toUpperCase(Locale.getDefault()));
    label3.setText(getString(R.string.avg_label).toUpperCase(Locale.getDefault()));
    label4.setText(getString(R.string.ritm_label).toUpperCase(Locale.getDefault()));
    label5.setText(getString(R.string.max_speed_label).toUpperCase(Locale.getDefault()));
    label6.setText(getString(R.string.max_altitude_label).toUpperCase(Locale.getDefault()));
    label7.setText(getString(R.string.min_altitude_label).toUpperCase(Locale.getDefault()));
    label8.setText(getString(R.string.calories_label).toUpperCase(Locale.getDefault()));
    label9.setText(getString(R.string.steps_label).toUpperCase(Locale.getDefault()));
    label10.setText(getString(R.string.beats_avg_label).toUpperCase(Locale.getDefault()));
    label11.setText(getString(R.string.max_beats_label).toUpperCase(Locale.getDefault()));
    label12.setText(getString(R.string.shoe).toUpperCase(Locale.getDefault()));
    label13.setText(getString(R.string.comments).toUpperCase(Locale.getDefault()));
    label14.setText(getString(R.string.accum_ascent).toUpperCase(Locale.getDefault()));
    label15.setText(getString(R.string.accum_descent).toUpperCase(Locale.getDefault()));
    label16.setText(getString(R.string.avg_cadence).toUpperCase(Locale.getDefault()));
    label17.setText(getString(R.string.max_cadence).toUpperCase(Locale.getDefault()));

    TypedArray activities_icons = res.obtainTypedArray(R.array.activities_icons);
    activity_image.setImageDrawable(activities_icons.getDrawable(Integer.valueOf(data[0]) - 1));

    metric_text1 = (isMetric ? getString(R.string.long_unit1_detail_1)
            : getString(R.string.long_unit2_detail_1));
    metric_text2 = (isMetric ? getString(R.string.long_unit1_detail_2)
            : getString(R.string.long_unit2_detail_2));
    metric_text3 = (isMetric ? getString(R.string.long_unit1_detail_3)
            : getString(R.string.long_unit2_detail_3));
    metric_text4 = (isMetric ? getString(R.string.long_unit1_detail_4)
            : getString(R.string.long_unit2_detail_4));

    text1.setText(data[1]);
    text2.setText(data[2]);
    text3.setText(FunctionUtils.customizedRound(Float.valueOf(data[3]), 2) + " " + metric_text1);
    text4.setText(FunctionUtils.customizedRound(Float.valueOf(data[4]), 2) + " " + metric_text2);
    text5.setText(data[5] + " " + metric_text3);
    text6.setText(data[6] + " " + metric_text2);
    text7.setText(data[7] + " " + metric_text4);
    text8.setText(data[8] + " " + metric_text4);
    text9.setText(data[9] + " " + getString(R.string.tell_calories_setting_details));
    text10.setText(data[10]);
    text11.setText(data[13] + " " + getString(R.string.beats_per_minute));
    text12.setText(data[14] + " " + getString(R.string.beats_per_minute));
    text13.setText(data[12]);
    text14.setText(data[11]);
    text15.setText(data[20] + " " + metric_text4);
    text16.setText(data[21] + " " + metric_text4);
    text17.setText(data[23] + " " + getString(R.string.revolutions_per_minute));
    text18.setText(data[24] + " " + getString(R.string.revolutions_per_minute));

    check1.setOnClickListener(this);
    check2.setOnClickListener(this);
    check3.setOnClickListener(this);

    checkboxStatus();

    populatesMap(fragmentView);

    intentFilter = new IntentFilter("android.intent.action.EXPAND_OR_RESTART_SUMMARY_MAPVIEW");
    intentFilter2 = new IntentFilter("android.intent.action.SUMMARY_GALLERY_SELECTED_IMAGE");
    act.registerReceiver(mReceiverExpandRestartMapview, intentFilter);
    act.registerReceiver(mReceiverSelectedPicture, intentFilter2);

    readImages();
    changeLayout1Margins();

    mGallery.setAdapter(new ImageAdapter(mContext));

    mGallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            position = arg2;

            if (folder.isDirectory()) {
                launchPhoto();
            } else {
                UIFunctionUtils.showMessage(mContext, true,
                        mContext.getString(R.string.image_resource_missing));
            }
        }
    });

    mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
            markChosenPicturePosition = position;
            markChosenPicture(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapter) {
        }
    });

    return fragmentView;
}

From source file:piuk.blockchain.android.ui.dialogs.TransactionSummaryDialog.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);

    final FragmentActivity activity = getActivity();

    final LayoutInflater inflater = LayoutInflater.from(activity);

    final Builder dialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.Theme_Dialog))
            .setTitle(R.string.transaction_summary_title);

    final LinearLayout view = (LinearLayout) inflater.inflate(R.layout.transaction_summary_fragment, null);

    dialog.setView(view);//from  w w  w  . j  a v  a 2s .  c  o  m

    try {
        final MyRemoteWallet wallet = application.getRemoteWallet();

        BigInteger totalOutputValue = BigInteger.ZERO;
        for (TransactionOutput output : tx.getOutputs()) {
            totalOutputValue = totalOutputValue.add(output.getValue());
        }

        final TextView resultDescriptionView = (TextView) view.findViewById(R.id.result_description);
        final TextView toView = (TextView) view.findViewById(R.id.transaction_to);
        final TextView toViewLabel = (TextView) view.findViewById(R.id.transaction_to_label);
        final View toViewContainer = (View) view.findViewById(R.id.transaction_to_container);
        final TextView hashView = (TextView) view.findViewById(R.id.transaction_hash);
        final TextView transactionTimeView = (TextView) view.findViewById(R.id.transaction_date);
        final TextView confirmationsView = (TextView) view.findViewById(R.id.transaction_confirmations);
        final TextView noteView = (TextView) view.findViewById(R.id.transaction_note);
        final Button addNoteButton = (Button) view.findViewById(R.id.add_note_button);
        final TextView feeView = (TextView) view.findViewById(R.id.transaction_fee);
        final View feeViewContainer = view.findViewById(R.id.transaction_fee_container);
        final TextView valueNowView = (TextView) view.findViewById(R.id.transaction_value);
        final View valueNowContainerView = view.findViewById(R.id.transaction_value_container);

        String to = null;
        for (TransactionOutput output : tx.getOutputs()) {
            try {
                String toAddress = output.getScriptPubKey().getToAddress().toString();
                if (!wallet.isAddressMine(toAddress)) {
                    to = toAddress;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String from = null;
        for (TransactionInput input : tx.getInputs()) {
            try {
                String fromAddress = input.getFromAddress().toString();
                if (!wallet.isAddressMine(fromAddress)) {
                    from = fromAddress;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        long realResult = 0;
        int confirmations = 0;

        if (tx instanceof MyTransaction) {
            MyTransaction myTx = (MyTransaction) tx;

            realResult = myTx.getResult().longValue();

            if (wallet.getLatestBlock() != null) {
                confirmations = wallet.getLatestBlock().getHeight() - myTx.getHeight() + 1;
            }

        } else if (application.isInP2PFallbackMode()) {
            realResult = tx.getValue(application.bitcoinjWallet).longValue();

            if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING)
                confirmations = tx.getConfidence().getDepthInBlocks();
        }

        final long finalResult = realResult;

        if (realResult <= 0) {
            toViewLabel.setText(R.string.transaction_fragment_to);

            if (to == null) {
                ((LinearLayout) toViewContainer.getParent()).removeView(toViewContainer);
            } else {
                toView.setText(to);
            }
        } else {
            toViewLabel.setText(R.string.transaction_fragment_from);

            if (from == null) {
                ((LinearLayout) toViewContainer.getParent()).removeView(toViewContainer);
            } else {
                toView.setText(from);
            }
        }

        //confirmations view
        if (confirmations > 0) {
            confirmationsView.setText("" + confirmations);
        } else {
            confirmationsView.setText("Unconfirmed");
        }

        //Hash String view
        final String hashString = new String(Hex.encode(tx.getHash().getBytes()), "UTF-8");

        hashView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("https:/" + Constants.BLOCKCHAIN_DOMAIN + "/tx/" + hashString));

                startActivity(browserIntent);
            }
        });

        //Notes View
        String note = wallet.getTxNotes().get(hashString);

        if (note == null) {
            addNoteButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();

                    AddNoteDialog.showDialog(getFragmentManager(), hashString);
                }
            });

            view.removeView(noteView);
        } else {
            view.removeView(addNoteButton);

            noteView.setText(note);

            noteView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();

                    AddNoteDialog.showDialog(getFragmentManager(), hashString);
                }
            });
        }

        addNoteButton.setEnabled(!application.isInP2PFallbackMode());

        SpannableString content = new SpannableString(hashString);
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        hashView.setText(content);

        if (realResult > 0 && from != null)
            resultDescriptionView.setText(this.getString(R.string.transaction_fragment_amount_you_received,
                    WalletUtils.formatValue(BigInteger.valueOf(realResult))));
        else if (realResult < 0 && to != null)
            resultDescriptionView.setText(this.getString(R.string.transaction_fragment_amount_you_sent,
                    WalletUtils.formatValue(BigInteger.valueOf(realResult))));
        else
            resultDescriptionView.setText(this.getString(R.string.transaction_fragment_amount_you_moved,
                    WalletUtils.formatValue(totalOutputValue)));

        final Date time = tx.getUpdateTime();

        transactionTimeView.setText(dateFormat.format(time));

        //These will be made visible again later once information is fetched from server
        feeViewContainer.setVisibility(View.GONE);
        valueNowContainerView.setVisibility(View.GONE);

        if (tx instanceof MyTransaction) {
            MyTransaction myTx = (MyTransaction) tx;

            final long txIndex = myTx.getTxIndex();

            final Handler handler = new Handler();

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        final JSONObject obj = getTransactionSummary(txIndex, wallet.getGUID(), finalResult);

                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    if (obj.get("fee") != null) {
                                        feeViewContainer.setVisibility(View.VISIBLE);

                                        feeView.setText(WalletUtils.formatValue(
                                                BigInteger.valueOf(Long.valueOf(obj.get("fee").toString())))
                                                + " BTC");
                                    }

                                    if (obj.get("confirmations") != null) {
                                        int confirmations = ((Number) obj.get("confirmations")).intValue();

                                        confirmationsView.setText("" + confirmations);
                                    }

                                    String result_local = (String) obj.get("result_local");
                                    String result_local_historical = (String) obj
                                            .get("result_local_historical");

                                    if (result_local != null && result_local.length() > 0) {
                                        valueNowContainerView.setVisibility(View.VISIBLE);

                                        if (result_local_historical == null
                                                || result_local_historical.length() == 0
                                                || result_local_historical.equals(result_local)) {
                                            valueNowView.setText(result_local);
                                        } else {
                                            valueNowView.setText(getString(R.string.value_now_ten, result_local,
                                                    result_local_historical));
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    Dialog d = dialog.create();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();

    lp.dimAmount = 0;
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

    d.show();

    d.getWindow().setAttributes(lp);

    d.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    return d;
}

From source file:com.frostwire.android.gui.fragments.SearchFragment.java

@Override
public View getHeader(Activity activity) {
    LayoutInflater inflater = LayoutInflater.from(activity);
    LinearLayout header = (LinearLayout) inflater.inflate(R.layout.view_search_header, null, false);
    TextView title = header.findViewById(R.id.view_search_header_text_title);
    title.setText(R.string.search);//from   ww  w.  j  a  va 2 s .  c om
    title.setOnClickListener(getHeaderClickListener());
    ImageButton filterButtonIcon = header.findViewById(R.id.view_search_header_search_filter_button);
    TextView filterCounter = header.findViewById(R.id.view_search_header_search_filter_counter);
    filterButton = new FilterToolbarButton(filterButtonIcon, filterCounter);
    filterButton.updateVisibility();
    return header;
}

From source file:com.example.zf_android.trade.ApplyDetailActivity.java

/**
 * firstly init the merchant category with item keys,
 * and after user select the merchant the values will be set
 *///from w  w w  .  j a v a2s.c om
private void initMerchantDetailKeys() {
    // the first category
    mMerchantKeys = getResources().getStringArray(R.array.apply_detail_merchant_keys);

    mMerchantContainer.addView(getDetailItem(ITEM_CHOOSE, mMerchantKeys[0], null));
    mMerchantContainer.addView(getDetailItem(ITEM_EDIT, mMerchantKeys[1], null));

    LinearLayout ll = getDetailItem(ITEM_EDIT, mMerchantKeys[2], null);
    etMerchantName = (EditText) ll.findViewById(R.id.apply_detail_value);
    etMerchantName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            etBankMerchantName.setText(s.toString());
        }

        @Override
        public void afterTextChanged(Editable s) {
            etBankMerchantName.setText(s.toString());
        }
    });
    mMerchantContainer.addView(ll);

    View merchantGender = getDetailItem(ITEM_CHOOSE, mMerchantKeys[3], null);
    merchantGender.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(ApplyDetailActivity.this);
            final String[] items = getResources().getStringArray(R.array.apply_detail_gender);
            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    setItemValue(mMerchantKeys[3], items[which]);
                }
            });
            builder.show();
        }
    });
    mMerchantContainer.addView(merchantGender);

    View merchantBirthday = getDetailItem(ITEM_CHOOSE, mMerchantKeys[4], null);
    merchantBirthday.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CommonUtil.showDatePicker(ApplyDetailActivity.this, mMerchantBirthday,
                    new CommonUtil.OnDateSetListener() {
                        @Override
                        public void onDateSet(String date) {
                            setItemValue(mMerchantKeys[4], date);
                        }
                    });
        }
    });
    mMerchantContainer.addView(merchantBirthday);
    mMerchantContainer.addView(getDetailItem(ITEM_EDIT, mMerchantKeys[5], null));
    mMerchantContainer.addView(getDetailItem(ITEM_EDIT, mMerchantKeys[6], null));
    mMerchantContainer.addView(getDetailItem(ITEM_EDIT, mMerchantKeys[7], null));

    View merchantCity = getDetailItem(ITEM_CHOOSE, mMerchantKeys[8], null);
    merchantCity.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(ApplyDetailActivity.this, CityProvinceActivity.class);
            intent.putExtra(SELECTED_PROVINCE, mMerchantProvince);
            intent.putExtra(SELECTED_CITY, mMerchantCity);
            startActivityForResult(intent, REQUEST_CHOOSE_CITY);
        }
    });
    mMerchantContainer.addView(merchantCity);

    // the second category
    mBankKeys = getResources().getStringArray(R.array.apply_detail_bank_keys);

    mCustomerContainer.addView(getDetailItem(ITEM_CHOOSE, mBankKeys[0], null));
    LinearLayout tmpll = (LinearLayout) mContainer.findViewWithTag(mBankKeys[0]);
    tmpll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            customTag = mBankKeys[0];
            Intent intent = new Intent(ApplyDetailActivity.this, BankList.class);
            intent.putExtra(AGENT_NAME, mBankName);
            intent.putExtra("terminalId", mTerminalId);
            startActivityForResult(intent, REQUEST_CHOOSE_BANK);
        }
    });

    View bankAccountName = getDetailItem(ITEM_EDIT, mBankKeys[1], null);
    etBankMerchantName = (EditText) bankAccountName.findViewById(R.id.apply_detail_value);
    etBankMerchantName.setEnabled(false);

    mCustomerContainer.addView(bankAccountName);
    mCustomerContainer.addView(getDetailItem(ITEM_EDIT, mBankKeys[2], null));
    mCustomerContainer.addView(getDetailItem(ITEM_EDIT, mBankKeys[3], null));
    mCustomerContainer.addView(getDetailItem(ITEM_EDIT, mBankKeys[4], null));

    View chooseChannel = getDetailItem(ITEM_CHOOSE, getString(R.string.apply_detail_channel), null);
    chooseChannel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(ApplyDetailActivity.this, ChannelSelecter.class);
            startActivityForResult(intent, REQUEST_CHOOSE_CHANNEL);

        }
    });
    mCustomerContainer.addView(chooseChannel);
}

From source file:es.example.contacts.ui.ContactDetailFragment.java

/**
 * Builds an address LinearLayout based on address information from the Contacts Provider.
 * Each address for the contact gets its own LinearLayout object; for example, if the contact
 * has three postal addresses, then 3 LinearLayouts are generated.
 *
 * @param addressType From/*from  ww  w  . j  av a  2 s. co  m*/
 * {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#TYPE}
 * @param addressTypeLabel From
 * {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#LABEL}
 * @param address From
 * {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#FORMATTED_ADDRESS}
 * @param phone From
 * {@link android.provider.ContactsContract.CommonDataKinds.Phone#NUMBER}
 * @param data1 From
 * {@link android.provider.ContactsContract.Data#DATA1}
 * @param _id From
 * {@link android.provider.ContactsContract#}
 * @return A LinearLayout to add to the contact details layout,
 *         populated with the provided address details.
 */
private LinearLayout buildAddressLayout(int addressType, String addressTypeLabel, final String address,
        final String phone, final String data1, final String _id, final String _name) {

    // Inflates the address layout
    final LinearLayout addressLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contact_detail_item, mDetailsLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) addressLayout.findViewById(R.id.contact_detail_header);
    final TextView addressTextView = (TextView) addressLayout.findViewById(R.id.contact_detail_item);
    final ImageButton viewAddressButton = (ImageButton) addressLayout.findViewById(R.id.button_view_address);
    final TextView phoneTextView = (TextView) addressLayout.findViewById(R.id.contact_phone);
    final SeekBar levelSeekBar = (SeekBar) addressLayout.findViewById(R.id.contact_level);
    final ImageButton saveButton = (ImageButton) addressLayout.findViewById(R.id.button_save);

    Integer prioridad = Integer.parseInt(data1 == null ? "4" : data1);
    // If there's no addresses for the contact, shows the empty view and message, and hides the
    // header and button.
    if (addressTypeLabel == null && addressType == 0 && phone == null) {
        headerTextView.setVisibility(View.GONE);
        viewAddressButton.setVisibility(View.GONE);
        addressTextView.setText(R.string.no_address);
    } else {
        // Gets postal address label type
        CharSequence label = StructuredPostal.getTypeLabel(getResources(), addressType, addressTypeLabel);

        // Sets TextView objects in the layout
        headerTextView.setText(label);
        addressTextView.setText(address);
        phoneTextView.setText(phone);
        levelSeekBar.setProgress(prioridad);

        // Defines an onClickListener object for the address button
        viewAddressButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {

                final Intent viewIntent = new Intent(Intent.ACTION_VIEW, constructGeoUri(address));

                // A PackageManager instance is needed to verify that there's a default app
                // that handles ACTION_VIEW and a geo Uri.
                final PackageManager packageManager = getActivity().getPackageManager();

                // Checks for an activity that can handle this intent. Preferred in this
                // case over Intent.createChooser() as it will still let the user choose
                // a default (or use a previously set default) for geo Uris.
                if (packageManager.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    startActivity(viewIntent);
                } else {
                    // If no default is found, displays a message that no activity can handle
                    // the view button.
                    Toast.makeText(getActivity(), R.string.no_intent_found, Toast.LENGTH_SHORT).show();
                }
            }
        });

        // Defines an onClickListener object for the save button
        saveButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {
                // Creates a new intent for sending to the device's contacts application
                // Creates a new array of ContentProviderOperation objects.
                ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

                Integer prioridad = levelSeekBar.getProgress();
                Log.d("ContactDetalFragment", _id);

                ContentProviderOperation.Builder op;
                if (data1 == null) {
                    Uri uri = addCallerIsSyncAdapterParameter(Data.CONTENT_URI, true);
                    ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
                            .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
                            .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null).build());

                    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
                            .withValue(ContactsContract.Data.MIMETYPE,
                                    ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, _name)
                            .build());

                    op = ContentProviderOperation.newInsert(Data.CONTENT_URI)
                            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
                            .withValue(Data.DATA1, prioridad).withValue(Data.MIMETYPE, LEVEL_MIME_TYPE);

                } else {
                    String where = Data.MIMETYPE + " = ? ";
                    String[] params = new String[] { LEVEL_MIME_TYPE, };

                    op = ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(where, params)
                            .withValue(Data.DATA1, prioridad);

                }
                ops.add(op.build());
                try {
                    ContentProviderResult[] results = view.getContext().getContentResolver()
                            .applyBatch(ContactsContract.AUTHORITY, ops);
                } catch (Exception e) {
                    CharSequence txt = getString(R.string.contactUpdateFailure);
                    int duration = Toast.LENGTH_SHORT;
                    Toast toast = Toast.makeText(view.getContext(), txt, duration);
                    toast.show();
                    // Log exception
                    Log.e(TAG, "Exception encountered while inserting contact: " + e);
                }
            }
        });

    }
    return addressLayout;
}

From source file:org.ohmage.activity.SurveyActivity.java

private void showSubmitScreen() {
    mNextButton.setText("Submit");
    mPrevButton.setText("Previous");
    mPrevButton.setVisibility(View.VISIBLE);
    mSkipButton.setVisibility(View.INVISIBLE);

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mPromptText.getWindowToken(), 0);

    mPromptText.setText("Survey Complete!");
    mProgressBar.setProgress(mProgressBar.getMax());

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.submit, null);
    TextView submitText = (TextView) layout.findViewById(R.id.submit_text);
    //submitText.setText("Thank you for completing the survey!");
    submitText.setText(mSurveySubmitText);

    mPromptFrame.removeAllViews();//from   ww  w . j  ava2  s .  c  om
    mPromptFrame.addView(layout);
}

From source file:de.da_sense.moses.client.FormFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    //============ HANDLING OF BUTTONS SHOWN IN FRAGMENT ========================
    LinearLayout formButtonContainer = (LinearLayout) mLayoutInflater.inflate(R.layout.form_button_container,
            generateQuestionContainer((ViewGroup) mRoot.findViewById(R.id.ll_quest)));
    final ViewPager viewPager = (ViewPager) mRoot.getParent().getParent();
    Button buttonPrevious = (Button) formButtonContainer.findViewById(R.id.button_form_previous);
    Button buttonNext = (Button) formButtonContainer.findViewById(R.id.button_form_next);

    if (mIsFirst)
        buttonPrevious.setVisibility(View.GONE);
    else/*from   w  ww. j  a  v  a  2  s.  co m*/
        buttonPrevious.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                int curPosition = viewPager.getCurrentItem();
                viewPager.setCurrentItem(curPosition - 1, true);
            }
        });

    if (mIsLast) {
        buttonNext.setText(getString(R.string.q_send));
        buttonNext.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // User clicked SEND button

                // special care for text questions
                Set<Question> questions = mQuestionEditTextMappings.keySet();
                for (Question question : questions) {
                    String finalAnswerOfUser = mQuestionEditTextMappings.get(question).getText().toString();
                    question.setAnswer(finalAnswerOfUser);
                }

                // ===== MANDATORY QUESTION FILLED CHECK ====== //

                Survey theSurvey = InstalledExternalApplicationsManager.getInstance().getAppForId(mAPKID)
                        .getSurvey();
                List<Form> forms = theSurvey.getForms();
                Collections.sort(forms);
                // iterate over all forms and the over all questions and check if there is
                // a mandatory question that is not filled
                boolean mayBeSent = true; // set to true only if the survey may be sent
                for (Form form : forms) {
                    boolean formWithUnansweredQuestionFound = false;
                    List<Question> questionsToCheck = form.getQuestions();
                    Collections.sort(questionsToCheck);
                    for (Question questionToCheck : questionsToCheck) {
                        if (questionToCheck.isMandatory()) {
                            // check if we have an answer
                            if (questionToCheck.getAnswer().equals(Question.ANSWER_UNANSWERED)) {
                                // the question is unanswered although mandatory, take action
                                mayBeSent = false;
                                int formPosition = forms.indexOf(form);
                                // go to the tab with containing the question
                                Toaster.showToast(getActivity(),
                                        getString(R.string.notification_mandatory_question_unanswered));
                                if (mPosition == formPosition) {
                                    // the unanswered mandatory question is in this FormFragment
                                    // just scroll to the question (EditText representing the title of the question)
                                    scrollToQuestion(questionToCheck);
                                    formWithUnansweredQuestionFound = true;
                                    break;
                                } else {
                                    // the question is not in this FormFragment
                                    // leave a message to this fragment and page to his position
                                    // that fragment should take care of scrolling
                                    Intent activityIntent = getActivity().getIntent();
                                    activityIntent.putExtra(KEY_POSITION_OF_FRAGMENT_WHICH_SHOULD_SCROLL,
                                            formPosition);
                                    activityIntent.putExtra(KEY_QUESTION_TO_SCROLL_TO, questionToCheck.getId());
                                    viewPager.setCurrentItem(formPosition, true);
                                    formWithUnansweredQuestionFound = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (formWithUnansweredQuestionFound)
                        break;

                }
                // ===== END MANDATORY QUESTION CHECK  END ========= //

                if (mayBeSent) {//  send to server only if all mandatory questions were filled

                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    // Add the buttons
                    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            sendAnswersToServer();
                        }
                    });
                    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // User cancelled the dialog
                            dialog.dismiss();
                        }
                    });

                    builder.setMessage(R.string.surveySendToServerMessage)
                            .setTitle(R.string.surveySendToServerTitle);

                    // Create the AlertDialog
                    AlertDialog dialog = builder.create();

                    dialog.show();
                }
            }
        });
        if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY)
            buttonNext.setVisibility(View.GONE); // disable sending button if we are viewing the survey from history tab
    } else
        buttonNext.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                int curPosition = viewPager.getCurrentItem();
                viewPager.setCurrentItem(curPosition + 1, true);
            }
        });

    //============ END HANDLING OF BUTTONS SHOWN IN FRAGMENT END ========================
}