Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

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

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.cleanwiz.applock.ui.adapter.AppPagerAdapter.java

private View buildAppView(final CommLockInfo lockInfo) {

    View convertView = mInflater.inflate(R.layout.old_item_applock, null);
    ImageView ivLogo = (ImageView) convertView.findViewById(R.id.iv_app_logo);
    final ImageView ivTag = (ImageView) convertView.findViewById(R.id.iv_tag);
    View itemView = convertView.findViewById(R.id.rl_item);
    TextView tvName = (TextView) convertView.findViewById(R.id.tv_app_name);

    if (itemHeight > 0 && itemWidth > 0) {
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) itemView.getLayoutParams();
        lp.height = itemHeight;/*from  ww w . ja  v  a2  s  .c o  m*/
        lp.width = itemWidth;
    }

    ApplicationInfo appInfo = null;
    try {
        appInfo = pkgMgr.getApplicationInfo(lockInfo.getPackageName(), PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    if (appInfo != null) {
        ivLogo.setImageDrawable(pkgMgr.getApplicationIcon(appInfo));
        tvName.setText(pkgMgr.getApplicationLabel(appInfo));
    }
    ivLogo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (lockInfo.getIsLocked()) {
                appLocker.unlockApp(lockInfo.getPackageName());
                lockInfo.setIsLocked(false);
            } else {
                appLocker.lockApp(lockInfo.getPackageName());
                lockInfo.setIsLocked(true);
            }
            LogUtil.d("demo3", "lock:" + lockInfo.getIsLocked());
            if (lockInfo.getIsLocked()) {
                ivTag.setVisibility(View.VISIBLE);
            } else {
                ivTag.setVisibility(View.INVISIBLE);
            }
        }
    });

    if (lockInfo.getIsLocked()) {
        ivTag.setVisibility(View.VISIBLE);
    } else {
        ivTag.setVisibility(View.INVISIBLE);
    }

    return convertView;
}

From source file:com.openerp.support.listview.OEListViewAdapter.java

/**
 * Handle binary background.//from  w  w w .ja  v a  2  s  .c o m
 * 
 * @param row_id
 *            the row_id
 * @param key
 *            the key
 * @param resource
 *            the resource
 * @param viewRow
 *            the view row
 * @param position
 *            the position
 */
private void handleBinaryBackground(final int row_id, final String key, int resource, View viewRow,
        final int position) {
    final ImageView booleanView = (ImageView) viewRow.findViewById(resource);
    int flag = 0;
    String rowKeyVal = rows.get(position).getRow_data().get(key).toString();
    if (isFlagged.containsKey(String.valueOf(position))) {
        if (isFlagged.get(String.valueOf(position)).toString().equals("true")) {
            flag = 1;
        }
    } else {
        if (rowKeyVal.equals("true")) {
            isFlagged.put(String.valueOf(position), "true");
            flag = 1;
        }
    }

    booleanView.setImageResource(binary_flag[flag]);
    booleanView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            try {
                if (OpenERPServerConnection.isNetworkAvailable(context)) {
                    OEListViewRows newRow = callbacks.get(key).updateFlagValues(rows.get(position),
                            booleanView);
                    rowdata = newRow.getRow_data();
                    rows.get(position).setRow_data(newRow.getRow_data());

                    isFlagged.put(String.valueOf(position), rowdata.get(key).toString());

                } else {
                    Toast.makeText(context, "Please Check your connection to server.", Toast.LENGTH_LONG)
                            .show();
                }
            } catch (Exception e) {

            }
        }
    });

}

From source file:com.zhengde163.netguard.ActivityMain.java

private void menu_legend() {
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    int colorOn = tv.data;
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    int colorOff = tv.data;

    // Create view
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.legend, null, false);
    ImageView ivWifiOn = (ImageView) view.findViewById(R.id.ivWifiOn);
    ImageView ivWifiOff = (ImageView) view.findViewById(R.id.ivWifiOff);
    ImageView ivOtherOn = (ImageView) view.findViewById(R.id.ivOtherOn);
    ImageView ivOtherOff = (ImageView) view.findViewById(R.id.ivOtherOff);
    ImageView ivScreenOn = (ImageView) view.findViewById(R.id.ivScreenOn);
    ImageView ivHostAllowed = (ImageView) view.findViewById(R.id.ivHostAllowed);
    ImageView ivHostBlocked = (ImageView) view.findViewById(R.id.ivHostBlocked);
    ImageView ivClose = (ImageView) view.findViewById(R.id.ivClose);
    ivClose.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w  w.  j  a  v  a2 s . c om
        public void onClick(View v) {
            dialogLegend.dismiss();
        }
    });
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable());
        Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable());
        Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable());
        Drawable wrapOtherOff = DrawableCompat.wrap(ivOtherOff.getDrawable());
        Drawable wrapScreenOn = DrawableCompat.wrap(ivScreenOn.getDrawable());
        Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable());
        Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable());

        DrawableCompat.setTint(wrapWifiOn, colorOn);
        DrawableCompat.setTint(wrapWifiOff, colorOff);
        DrawableCompat.setTint(wrapOtherOn, colorOn);
        DrawableCompat.setTint(wrapOtherOff, colorOff);
        DrawableCompat.setTint(wrapScreenOn, colorOn);
        DrawableCompat.setTint(wrapHostAllowed, colorOn);
        DrawableCompat.setTint(wrapHostBlocked, colorOff);
    }

    // Show dialog
    dialogLegend = new AlertDialog.Builder(this).setView(view).setCancelable(true)
            .setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    dialogLegend = null;
                }
            }).create();
    dialogLegend.show();
}

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

@Override
protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK)
        return;//from  www. j  av  a 2  s.c o  m
    switch (requestCode) {
    case REQUEST_CHOOSE_MERCHANT: {

        mAgentId = mMerchantId = data.getIntExtra(AGENT_ID, 0);
        mAgentName = data.getStringExtra(AGENT_NAME);
        setItemValue(mMerchantKeys[0], mAgentName);

        getAgentInfo();

        break;
    }
    case REQUEST_CHOOSE_BANK: {

        mBankName = data.getStringExtra("bank_name");
        mBankNo = data.getStringExtra("bank_no");
        setItemValue(customTag, mBankName);
        setItemValue(mBankKeys[0], mBankName);

        //FIXME no 
        //                setItemValue(mBankKeys[1], mBankNo);

        break;
    }
    case REQUEST_CHOOSE_CITY: {
        mMerchantProvince = (Province) data.getSerializableExtra(SELECTED_PROVINCE);
        mMerchantCity = (City) data.getSerializableExtra(SELECTED_CITY);
        mCityId = mMerchantCity.getId();
        setItemValue(mMerchantKeys[8], mMerchantCity.getName());
        break;
    }
    case REQUEST_CHOOSE_CHANNEL: {
        mChannelId = data.getIntExtra("channelId", 0);
        mBillingId = data.getIntExtra("billId", 0);
        String channelName = data.getStringExtra("channelName");
        String billName = data.getStringExtra("billName");

        setItemValue(getString(R.string.apply_detail_channel), channelName + " " + billName);
        break;
    }
    case REQUEST_UPLOAD_IMAGE:
    case REQUEST_TAKE_PHOTO: {

        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                if (msg.what == 1) {
                    //                     CommonUtil.toastShort(ApplyDetailActivity.this, (String) msg.obj);
                    if (null != uploadingTextView) {
                        final String url = (String) msg.obj;
                        LinearLayout item = (LinearLayout) uploadingTextView.getParent().getParent();

                        updateCustomerDetails(item.getTag(), url);
                        uploadingTextView.setVisibility(View.GONE);

                        ImageView iv_view = (ImageView) item.findViewById(R.id.apply_detail_view);
                        iv_view.setVisibility(View.VISIBLE);
                        iv_view.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent i = new Intent(ApplyDetailActivity.this, ImageViewer.class);
                                i.putExtra("url", url);
                                i.putExtra("justviewer", true);
                                startActivity(i);
                            }
                        });
                    }
                } else {
                    CommonUtil.toastShort(ApplyDetailActivity.this, getString(R.string.toast_upload_failed));
                    if (null != uploadingTextView) {
                        uploadingTextView.setText(getString(R.string.apply_upload_again));
                        uploadingTextView.setClickable(true);
                    }
                }

            }
        };
        if (null != uploadingTextView) {
            uploadingTextView.setText(getString(R.string.apply_uploading));
            uploadingTextView.setClickable(false);
        }
        new Thread() {
            @Override
            public void run() {
                String realPath = "";
                if (requestCode == REQUEST_TAKE_PHOTO) {
                    realPath = photoPath;
                } else {
                    Uri uri = data.getData();
                    if (uri != null) {
                        realPath = getRealPathFromURI(uri);
                    }
                }
                if (TextUtils.isEmpty(realPath)) {
                    handler.sendEmptyMessage(0);
                    return;
                }
                CommonUtil.uploadFile(realPath, "img", new CommonUtil.OnUploadListener() {
                    @Override
                    public void onSuccess(String result) {
                        try {
                            JSONObject jo = new JSONObject(result);
                            String url = jo.getString("result");
                            Message msg = new Message();
                            msg.what = 1;
                            msg.obj = url;
                            handler.sendMessage(msg);
                        } catch (JSONException e) {
                            handler.sendEmptyMessage(0);
                        }
                    }

                    @Override
                    public void onFailed(String message) {
                        handler.sendEmptyMessage(0);
                    }
                });
            }
        }.start();
        break;
    }
    }
}

From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

/**
 * // www  . j a v  a2  s.  c o  m
 * @param view
 */
private void displayResult(View view, LayoutInflater inflater, ViewGroup vg) {
    /*
     final Button shareButton = (Button) view.findViewById(R.id.resultButtonShare);
     if (shareButton != null)
    shareButton.setEnabled(false);
    */

    //final LinearLayout measurementLayout = (LinearLayout) view.findViewById(R.id.resultMeasurementList);
    measurementLayout = (LinearLayout) view.findViewById(R.id.resultMeasurementList);
    measurementLayout.setVisibility(View.GONE);

    final LinearLayout resultLayout = (LinearLayout) view.findViewById(R.id.result_layout);
    resultLayout.setVisibility(View.INVISIBLE);

    final LinearLayout netLayout = (LinearLayout) view.findViewById(R.id.resultNetList);
    netLayout.setVisibility(View.GONE);

    final TextView measurementHeader = (TextView) view.findViewById(R.id.resultMeasurement);
    measurementHeader.setVisibility(View.GONE);

    final TextView netHeader = (TextView) view.findViewById(R.id.resultNet);
    netHeader.setVisibility(View.GONE);

    final TextView emptyView = (TextView) view.findViewById(R.id.infoText);
    emptyView.setVisibility(View.GONE);
    final float scale = activity.getResources().getDisplayMetrics().density;

    final ProgressBar progessBar = (ProgressBar) view.findViewById(R.id.progressBar);

    if (testResult != null && testResult.length() > 0) {

        JSONObject resultListItem;

        try {
            resultListItem = testResult.getJSONObject(0);

            openTestUuid = resultListItem.optString("open_test_uuid");
            if (graphView != null) {
                graphView.setOpenTestUuid(openTestUuid);
                graphView.initialize(graphViewEndTaskListener);
            }

            JSONObject testResultItem;
            try {
                testResultItem = testResult.getJSONObject(0);
                if (testResultItem.has("geo_lat") && testResultItem.has("geo_long") && !hasMap) {
                    hasMap = true;
                    if (dataChangedListener != null) {
                        dataChangedListener.onChange(false, true, "HAS_MAP");
                    }
                    notifyDataSetChanged();
                } else if (!testResultItem.has("geo_lat") && !testResultItem.has("geo_long") && hasMap) {
                    System.out.println("hasMap = " + hasMap);
                    hasMap = false;
                    if (dataChangedListener != null) {
                        dataChangedListener.onChange(true, false, "HAS_MAP");
                    }
                    notifyDataSetChanged();
                }
            } catch (JSONException e) {
                hasMap = false;
                e.printStackTrace();
            }

            if (completeListener != null) {
                completeListener.onComplete(OnCompleteListener.DATA_LOADED, this);
            }

            final JSONArray measurementArray = resultListItem.getJSONArray("measurement");

            final JSONArray netArray = resultListItem.getJSONArray("net");

            final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
            final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
            final int heightDiv = Helperfunctions.dpToPx(1, scale);

            for (int i = 0; i < measurementArray.length(); i++) {

                final View measurementItemView = inflater.inflate(R.layout.classification_list_item, vg, false);

                final JSONObject singleItem = measurementArray.getJSONObject(i);

                final TextView itemTitle = (TextView) measurementItemView
                        .findViewById(R.id.classification_item_title);
                itemTitle.setText(singleItem.getString("title"));

                final ImageView itemClassification = (ImageView) measurementItemView
                        .findViewById(R.id.classification_item_color);
                itemClassification.setImageResource(
                        Helperfunctions.getClassificationColor(singleItem.getInt("classification")));

                itemClassification.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        activity.showHelp(R.string.url_help_result, false);
                    }
                });

                final TextView itemValue = (TextView) measurementItemView
                        .findViewById(R.id.classification_item_value);
                itemValue.setText(singleItem.getString("value"));

                measurementLayout.addView(measurementItemView);

                final View divider = new View(activity);
                divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv, 1));
                divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                measurementLayout.addView(divider);

                measurementLayout.invalidate();
            }

            for (int i = 0; i < netArray.length(); i++) {

                final JSONObject singleItem = netArray.getJSONObject(i);

                addResultListItem(singleItem.getString("title"), singleItem.optString("value", null),
                        netLayout);
            }

            addQoSResultItem();

        } catch (final JSONException e) {
            e.printStackTrace();
        }

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);

        resultLayout.setVisibility(View.VISIBLE);
        measurementHeader.setVisibility(View.VISIBLE);
        netHeader.setVisibility(View.VISIBLE);

        measurementLayout.setVisibility(View.VISIBLE);
        netLayout.setVisibility(View.VISIBLE);

    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(activity.getString(R.string.error_no_data));
        emptyView.invalidate();
    }
}

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);//w w w  .  j  a  va  2s  . 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.htc.dotdesign.ToolBoxService.java

private void initBrushSize() {
    View extendView = null;/* w  w w. j a  va 2s  . com*/
    if (mCurrFun == FunType.Fun_Palette) {
        extendView = mPalette;
    } else {
        extendView = mEraser;
    }
    if (extendView != null) {
        ImageView button = null;
        button = (ImageView) extendView.findViewById(R.id.btn_1x1);
        if (button != null) {
            button.setOnClickListener(mButtonListener);
        }

        button = (ImageView) extendView.findViewById(R.id.btn_2x2);
        if (button != null) {
            button.setOnClickListener(mButtonListener);
        }

        updateBrushColor();
    }
}

From source file:de.schildbach.wallet.ui.TransactionFragment.java

public void update(final Transaction tx) {
    final Wallet wallet = ((WalletApplication) activity.getApplication()).getWallet();

    final byte[] serializedTx = tx.unsafeBitcoinSerialize();

    Address from = null;//from   w w w  .  j  a  v a 2  s  . c  o  m
    boolean fromMine = false;
    try {
        from = tx.getInputs().get(0).getFromAddress();
        fromMine = wallet.isPubKeyHashMine(from.getHash160());
    } catch (final ScriptException x) {
        x.printStackTrace();
    }

    Address to = null;
    boolean toMine = false;
    try {
        to = tx.getOutputs().get(0).getScriptPubKey().getToAddress();
        toMine = wallet.isPubKeyHashMine(to.getHash160());
    } catch (final ScriptException x) {
        x.printStackTrace();
    }

    final ContentResolver contentResolver = activity.getContentResolver();

    final View view = getView();

    final Date time = tx.getUpdateTime();
    view.findViewById(R.id.transaction_fragment_time_row)
            .setVisibility(time != null ? View.VISIBLE : View.GONE);
    if (time != null) {
        final TextView viewDate = (TextView) view.findViewById(R.id.transaction_fragment_time);
        viewDate.setText(
                (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time))
                        + ", " + timeFormat.format(time));
    }

    try {
        final BigInteger amountSent = tx.getValueSentFromMe(wallet);
        view.findViewById(R.id.transaction_fragment_amount_sent_row)
                .setVisibility(amountSent.signum() != 0 ? View.VISIBLE : View.GONE);
        if (amountSent.signum() != 0) {
            final TextView viewAmountSent = (TextView) view.findViewById(R.id.transaction_fragment_amount_sent);
            viewAmountSent.setText(Constants.CURRENCY_MINUS_SIGN + WalletUtils.formatValue(amountSent));
        }
    } catch (final ScriptException x) {
        x.printStackTrace();
    }

    final BigInteger amountReceived = tx.getValueSentToMe(wallet);
    view.findViewById(R.id.transaction_fragment_amount_received_row)
            .setVisibility(amountReceived.signum() != 0 ? View.VISIBLE : View.GONE);
    if (amountReceived.signum() != 0) {
        final TextView viewAmountReceived = (TextView) view
                .findViewById(R.id.transaction_fragment_amount_received);
        viewAmountReceived.setText(Constants.CURRENCY_PLUS_SIGN + WalletUtils.formatValue(amountReceived));
    }

    final View viewFromButton = view.findViewById(R.id.transaction_fragment_from_button);
    final TextView viewFromLabel = (TextView) view.findViewById(R.id.transaction_fragment_from_label);
    if (from != null) {
        final String label = AddressBookProvider.resolveLabel(contentResolver, from.toString());
        final StringBuilder builder = new StringBuilder();

        if (fromMine)
            builder.append(getString(R.string.transaction_fragment_you)).append(", ");

        if (label != null) {
            builder.append(label);
        } else {
            builder.append(from.toString());
            viewFromLabel.setTypeface(Typeface.MONOSPACE);
        }

        viewFromLabel.setText(builder.toString());

        final String addressStr = from.toString();
        viewFromButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr);
            }
        });
    } else {
        viewFromLabel.setText(null);
    }

    final View viewToButton = view.findViewById(R.id.transaction_fragment_to_button);
    final TextView viewToLabel = (TextView) view.findViewById(R.id.transaction_fragment_to_label);
    if (to != null) {
        final String label = AddressBookProvider.resolveLabel(contentResolver, to.toString());
        final StringBuilder builder = new StringBuilder();

        if (toMine)
            builder.append(getString(R.string.transaction_fragment_you)).append(", ");

        if (label != null) {
            builder.append(label);
        } else {
            builder.append(to.toString());
            viewToLabel.setTypeface(Typeface.MONOSPACE);
        }

        viewToLabel.setText(builder.toString());

        final String addressStr = to.toString();
        viewToButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr);
            }
        });
    } else {
        viewToLabel.setText(null);
    }

    final TextView viewStatus = (TextView) view.findViewById(R.id.transaction_fragment_status);
    final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType();
    if (confidenceType == ConfidenceType.DEAD || confidenceType == ConfidenceType.NOT_IN_BEST_CHAIN)
        viewStatus.setText(R.string.transaction_fragment_status_dead);
    else if (confidenceType == ConfidenceType.NOT_SEEN_IN_CHAIN)
        viewStatus.setText(R.string.transaction_fragment_status_pending);
    else if (confidenceType == ConfidenceType.BUILDING)
        viewStatus.setText(R.string.transaction_fragment_status_confirmed);
    else
        viewStatus.setText(R.string.transaction_fragment_status_unknown);

    final TextView viewHash = (TextView) view.findViewById(R.id.transaction_fragment_hash);
    viewHash.setText(tx.getHash().toString());

    final TextView viewLength = (TextView) view.findViewById(R.id.transaction_fragment_length);
    viewLength.setText(Integer.toString(serializedTx.length));

    final ImageView viewQr = (ImageView) view.findViewById(R.id.transaction_fragment_qr);

    try {
        // encode transaction URI
        final ByteArrayOutputStream bos = new ByteArrayOutputStream(serializedTx.length);
        final GZIPOutputStream gos = new GZIPOutputStream(bos);
        gos.write(serializedTx);
        gos.close();

        final byte[] gzippedSerializedTx = bos.toByteArray();
        final boolean useCompressioon = gzippedSerializedTx.length < serializedTx.length;

        final StringBuilder txStr = new StringBuilder("btctx:");
        txStr.append(useCompressioon ? 'Z' : '-');
        txStr.append(Base43.encode(useCompressioon ? gzippedSerializedTx : serializedTx));

        final Bitmap qrCodeBitmap = WalletUtils.getQRCodeBitmap(txStr.toString().toUpperCase(Locale.US), 512);
        viewQr.setImageBitmap(qrCodeBitmap);
        viewQr.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
            }
        });
    } catch (final IOException x) {
        throw new RuntimeException(x);
    }
}

From source file:com.provision.alarmemi.paper.fragments.SetAlarmFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    mActivity.setOnLifeCycleChangeListener(this);

    isChanged = isCloud = false;//from w  ww.j av  a  2 s  .c o m
    // Override the default content view.
    root = (ViewGroup) super.onCreateView(inflater, container, bundle);
    final ImageView moreAlarm = (ImageView) root.findViewById(R.id.more_alarm);
    FragmentChangeActivity.moreAlarm = moreAlarm;
    moreAlarm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (menu.isMenuShowing()) {
                menu.showContent();
            } else {
                menu.showMenu(true);
            }
        }
    });
    // Make the entire view selected when focused.
    moreAlarm.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            v.setSelected(hasFocus);
        }
    });

    addPreferencesFromResource(R.xml.alarm_prefs);
    myUUID = SplashActivity.myUUID;

    // Get each preference so we can retrieve the value later.
    mLabel = findPreference("label");
    mLabel.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            showEditTextPreference(mLabel.getKey(), mLabel.getTitle(), mLabelText);
            return true;
        }
    });

    Preference.OnPreferenceChangeListener preferceChangedListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference p, Object newValue) {
            isChanged = true;
            return true;
        }
    };

    mEnabledPref = (CheckBoxPreference) findPreference("enabled");
    mEnabledPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!isCloud) {
                isChanged = true;
                if ((Boolean) newValue)
                    showCategory();
                else
                    hideCategory();
                return true;
            }
            if ((Boolean) newValue) {
                try {
                    tempjson = new JSONArray("[]");
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                selectedDevice = "";
                for (int i = 0; i < json.length(); i++) {
                    if (UIDitems[i].toString().equals(myUUID))
                        checkedItems[i] = true;
                    if (checkedItems[i]) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("name", URLDecoder.decode(items[i].toString()));
                        map.put("uid", UIDitems[i].toString());
                        tempjson.put(map);
                        selectedDevice += items[i] + ", ";
                    }
                }
                if (!selectedDevice.equals(""))
                    selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2);
            } else {
                try {
                    tempjson = new JSONArray("[]");
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                selectedDevice = "";
                for (int i = 0; i < json.length(); i++) {
                    if (UIDitems[i].toString().equals(myUUID))
                        checkedItems[i] = false;
                    if (checkedItems[i]) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("name", URLDecoder.decode(items[i].toString()));
                        map.put("uid", UIDitems[i].toString());
                        tempjson.put(map);
                        selectedDevice += items[i] + ", ";
                    }
                }
                if (!selectedDevice.equals(""))
                    selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2);
            }
            mForest.setSummary(selectedDevice);
            isChanged = true;
            return true;
        }
    });
    mTimePref = findPreference("time");
    mVibratePref = (CheckBoxPreference) findPreference("vibrate");
    mVibratePref.setOnPreferenceChangeListener(preferceChangedListener);
    mRepeatPref = findPreference("setRepeat");
    mRepeatPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String[] values = new String[] {
                    DateUtils.getDayOfWeekString(Calendar.MONDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.TUESDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.WEDNESDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.THURSDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.FRIDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.SATURDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.SUNDAY, DateUtils.LENGTH_LONG) };
            Intent intent = new Intent(mActivity, RepeatListPreference.class);
            intent.putExtra("key", mRepeatPref.getKey());
            intent.putExtra("title", mRepeatPref.getTitle());
            intent.putExtra("lists", values);
            intent.putExtra("multi", true);
            startActivity(intent);
            return true;
        }
    });
    mForestName = findPreference("forest_name");
    mForest = findPreference("forest");
    mColorPref = (AmbilWarnaPreference) findPreference("color");
    prefs = mActivity.getSharedPreferences("forest", mActivity.MODE_PRIVATE);

    Intent i = mActivity.setAlarmGetIntent;
    mId = i.getIntExtra(Alarms.ALARM_ID, -1);

    alarm = null;
    if (mId == -1) {
        // No alarm id means create a new alarm.
        alarm = new Alarm();
        isChanged = true;
    } else {
        // * load alarm details from database
        alarm = Alarms.getAlarm(mActivity.getContentResolver(), mId);
        // Bad alarm, bail to avoid a NPE.
        if (alarm == null) {
            finish();
            return root;
        }
        isCloud = wasCloud = alarm.cloudEnabled;
    }
    mOriginalAlarm = alarm;

    if (wasCloud) {
        try {
            Log.e("url", " : " + alarm.cloudName);
            json = new JSONArray(prefs.getString(alarm.cloudName + "_registeredDevice", ""));
            String cloud_uid = alarm.cloudUID;
            if (cloud_uid.equals(""))
                cloud_uid = "[]";
            Log.e("url", cloud_uid);
            tempjson = new JSONArray(cloud_uid);
            items = new String[json.length()];
            UIDitems = new CharSequence[json.length()];
            checkedItems = new boolean[json.length()];
            for (int j = 0; j < json.length(); j++) {
                JSONObject jsonObj = json.getJSONObject(j);
                items[j] = jsonObj.getString("name");
                UIDitems[j] = jsonObj.getString("uid");
                checkedItems[j] = alarm.cloudUID.contains(jsonObj.getString("uid"));
            }
        } catch (Exception e) {
            Log.e("url", e.toString());
        }
        selectedDevice = alarm.cloudDevices;
        mForestName.setEnabled(false);
    } else {
        if (prefs.getString("name", "").length() > 0) {
            names = prefs.getString("name", "").substring(1).split("\\|");
            nameCheckedIndex = -1;
        } else
            mForestName.setEnabled(false);
        mForest.setEnabled(false);
    }
    memi_count = alarm.memiCount;
    snooze_strength = alarm.snoozeStrength;
    snooze_count = alarm.snoozeCount;

    updatePrefs(mOriginalAlarm);

    mTimePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            showTimePicker();
            return false;
        }

    });

    mForestName.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            showListPreference(mForestName.getKey(), mForestName.getTitle(), names,
                    String.valueOf(nameCheckedIndex), false);
            return true;
        }
    });

    mForest.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            showListPreference(mForest.getKey(), mForest.getTitle(), items, booleanArrayToString(checkedItems),
                    true);
            return true;
        }
    });
    mColorPref.setOnPreferenceChangeListener(preferceChangedListener);

    // We have to do this to get the save/cancel buttons to highlight on
    // their own.
    ((ListView) root.findViewById(android.R.id.list)).setItemsCanFocus(true);

    // Attach actions to each button.
    View.OnClickListener back_click = new View.OnClickListener() {
        public void onClick(View v) {
            DontSaveDialog(false, null, false);
        }
    };
    ImageView b = (ImageView) root.findViewById(R.id.back);
    b.setOnClickListener(back_click);

    b = (ImageView) root.findViewById(R.id.logo);
    b.setOnClickListener(back_click);

    b = (ImageView) root.findViewById(R.id.alarm_save);
    b.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            saveAlarm();
        }
    });
    b = (ImageView) root.findViewById(R.id.alarm_delete);
    if (mId == -1) {
        b.setEnabled(false);
    } else {
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                deleteAlarm();
            }
        });
    }

    // The last thing we do is pop the time picker if this is a new alarm.
    if (mId == -1) {
        // Assume the user hit cancel
        mTimePickerCancelled = true;
        showTimePicker();
    }

    if (!isCloud && !alarm.enabled)
        hideCategory();

    FragmentChangeActivity.OnNotifyArrived.sendEmptyMessage(0);
    return root;
}