List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
@Deprecated
public BitmapDrawable(java.io.InputStream is)
From source file:com.huofu.RestaurantOS.ui.splash.activate.java
/** * ?//from www . j a v a 2 s.co m */ public void init() { MainApplication.setmActivity(this); rl_activate = (RelativeLayout) findViewById(R.id.rl_activate); rl_activate_input = (RelativeLayout) findViewById(R.id.rl_activate_code_input); rl_activate_qrscan_ready = (RelativeLayout) findViewById(R.id.rl_activate_qrcode_scan_ready); ctxt = getApplicationContext(); buttonActivate = (Button) findViewById(R.id.buttonActivate); buttonSwitchInputCode = (Button) findViewById(R.id.button_switch_acitvate_keyboard_way); buttonSwitchQrScan = (Button) findViewById(R.id.button_activate_switch_to_qrscan); textviewScanStauts = (TextView) findViewById(R.id.textview_activate_status); etActivteCode = (EditText) findViewById(R.id.editTextActivateCode); titanic = new Titanic(); ttv = new TitanicTextView(getApplicationContext()); bitmapUtils = new BitmapUtils(getApplicationContext(), pathAcitvateCache, 150 * 1024 * 1024, 150 * 1024 * 1024); bigPicDisplayConfig = new BitmapDisplayConfig(); bigPicDisplayConfig.setShowOriginal(true); // ,?, ???, OOM callback = new DefaultBitmapLoadCallBack<ImageView>() { public void onLoadCompleted(ImageView container, String uri, android.graphics.Bitmap bitmap, BitmapDisplayConfig config, com.lidroid.xutils.bitmap.callback.BitmapLoadFrom from) { CommonUtils.sendMsg("", HIDE_LOADING, mUiHandler); imageViewQrcode.setVisibility(View.VISIBLE); imageViewQrcode.setBackgroundDrawable(new BitmapDrawable(bitmap)); stopQrScanTimer(); timerQrcode = new Timer(); timerTaskQrcode = new TimerTask() { @Override public void run() { if (!flagActivate) { timerTaskQrcode.cancel(); timerQrcode.cancel(); return; } long qrcodeLastTime = System.currentTimeMillis() / 1000 - qrcodeCreateTime; CommonUtils.LogWuwei(tag, "qrcodeLastTime is " + qrcodeLastTime); if (qrcodeLastTime > 300) { timerTaskQrcode.cancel(); timerQrcode.cancel(); sendUIMessage(SHOW_QRCODE_REFRSH_AGAIN, ""); return; } // TODO Auto-generated method stub if (active) { ApisManager.ScanAuthQrcode(tokenQrcode, new ApiCallback() { @Override public void success(Object object) { sendUIMessage(HIDE_LOADING, ""); JSONObject oj = (JSONObject) object; if (Integer.parseInt(oj.getString("status")) != 1) { return; } String status = oj.getString("related_status"); if (status.equals("5") || status.equals("3") && activate.active)//? { if (activate.flagAuthSuccess) { return; } activate.flagAuthSuccess = true; if (activate.active) { CommonUtils.sendMsg(null, activate.STOP_SCAN_QRCODE_TIMER, mUiHandler); String master_key = oj.getString("master_key"); LocalDataDeal.writeToLocalMasterKey(master_key, ctxt); String client_id = oj.getString("client_id"); LocalDataDeal.writeToLocalClientId(client_id, ctxt); CommonUtils.sendMsg("", SCAN_QRCODE_SUCCESS, mUiHandler); } } else if (status.equals("1")) { CommonUtils.sendMsg("?", UPDATE_QRCODE_SCAN_STATUS, mUiHandler); } else if (status.equals("2")) { CommonUtils.sendMsg("", UPDATE_QRCODE_SCAN_STATUS, mUiHandler); } else if (status.equals("4")) { activate.flagWaitingCmd = true; CommonUtils.sendMsg("", UPDATE_QRCODE_SCAN_STATUS, mUiHandler); } else if (status.equals("6"))//????? { activate.flagWaitingCmd = false; activate.stopQrScanTimer(); CommonUtils.sendMsg("???", AUTH_FAILED, mUiHandler); } else if (status.equals("7")) { activate.flagWaitingCmd = false; activate.stopQrScanTimer(); CommonUtils.sendMsg("??", AUTH_FAILED, mUiHandler); } else if (status.equals("0")) { activate.flagWaitingCmd = false; activate.stopQrScanTimer(); CommonUtils.sendMsg("???", AUTH_FAILED, mUiHandler); } } @Override public void error(BaseApi.ApiResponse response) { sendUIMessage(HIDE_LOADING, ""); } }); } } }; timerQrcode.schedule(timerTaskQrcode, 0, 1000); } }; imageViewQrcode = (ImageView) findViewById(R.id.imageview_activate_qrcode_scan); PackageManager manager; PackageInfo info = null; manager = this.getPackageManager(); String versionName = null; try { info = manager.getPackageInfo(this.getPackageName(), 0); versionName = info.versionName; String version = CommonUtils.getSringAfterChar(versionName, 'V'); LocalDataDeal.writeToLocalVersionName(ctxt, version); } catch (NameNotFoundException e) { e.printStackTrace(); } }
From source file:com.android.mms.rcs.FavoriteDetailAdapter.java
private void initVcardMagView(LinearLayout linearLayout) { ImageView imageView = (ImageView) linearLayout.findViewById(R.id.image_view); String fileName = mCursor/*from w w w. ja v a 2 s . co m*/ .getString(mCursor.getColumnIndexOrThrow(FavoriteMessageProvider.FavoriteMessage.FILE_NAME)); String vcardFileName = fileName; ArrayList<PropertyNode> propList = RcsMessageOpenUtils.openRcsVcardDetail(mContext, vcardFileName); Bitmap bitmap = null; for (PropertyNode propertyNode : propList) { if ("PHOTO".equals(propertyNode.propName)) { if (propertyNode.propValue_bytes != null) { byte[] bytes = propertyNode.propValue_bytes; bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); bitmap = RcsUtils.decodeInSampleSizeBitmap(bitmap); break; } } } if (bitmap != null) { imageView.setBackgroundDrawable(new BitmapDrawable(bitmap)); } else { imageView.setBackgroundResource(R.drawable.ic_attach_vcard); } }
From source file:com.ibuildapp.romanblack.MultiContactsPlugin.ContactDetailsActivity.java
@Override public void create() { try {/* www . j a va2 s. c o m*/ setContentView(R.layout.grouped_contacts_details); Intent currentIntent = getIntent(); Bundle store = currentIntent.getExtras(); widget = (Widget) store.getSerializable("Widget"); if (widget == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } person = (Person) store.getSerializable("person"); if (person == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } setTopBarTitle(widget.getTitle()); Boolean single = currentIntent.getBooleanExtra("single", true); setTopBarLeftButtonTextAndColor( single ? getResources().getString(R.string.common_home_upper) : getResources().getString(R.string.common_back_upper), getResources().getColor(android.R.color.black), true, new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); setTopBarTitleColor(getResources().getColor(android.R.color.black)); setTopBarBackgroundColor(Statics.color1); if ((Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL))) || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS))) || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS)))) { ImageView shareButton = (ImageView) getLayoutInflater() .inflate(R.layout.grouped_contacts_share_button, null); shareButton.setLayoutParams( new LinearLayout.LayoutParams((int) (29 * getResources().getDisplayMetrics().density), (int) (39 * getResources().getDisplayMetrics().density))); shareButton.setColorFilter(Color.BLACK); setTopBarRightButton(shareButton, getString(R.string.multicontacts_list_share), new View.OnClickListener() { @Override public void onClick(View v) { DialogSharing.Configuration.Builder sharingDialogBuilder = new DialogSharing.Configuration.Builder(); if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL))) sharingDialogBuilder .setEmailSharingClickListener(new DialogSharing.Item.OnClickListener() { @Override public void onClick() { String message = getContactInfo(); Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_TEXT, message); email.setType("message/rfc822"); startActivity(Intent.createChooser(email, getString(R.string.choose_email_client))); } }); if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS))) sharingDialogBuilder .setSmsSharingClickListener(new DialogSharing.Item.OnClickListener() { @Override public void onClick() { String message = getContactInfo(); try { Utils.sendSms(ContactDetailsActivity.this, message); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); if (Boolean.TRUE.equals(widget.getParameter(PARAM_ADD_CONTACT))) sharingDialogBuilder.addCustomListener(R.string.multicontacts_add_to_phonebook, R.drawable.gc_add_to_contacts, true, new DialogSharing.Item.OnClickListener() { @Override public void onClick() { createNewContact(person.getName(), person.getPhone(), person.getEmail()); } }); showDialogSharing(sharingDialogBuilder.build()); } }); } boolean hasSchema = store.getBoolean("hasschema"); cachePath = widget.getCachePath() + "/contacts-" + widget.getOrder(); contacts = person.getContacts(); if (widget.getTitle().length() > 0) { setTitle(widget.getTitle()); } root = (LinearLayout) findViewById(R.id.grouped_contacts_details_root); if (hasSchema) { root.setBackgroundColor(Statics.color1); } else if (widget.isBackgroundURL()) { cacheBackgroundFile = cachePath + "/" + Utils.md5(widget.getBackgroundURL()); File backgroundFile = new File(cacheBackgroundFile); if (backgroundFile.exists()) { root.setBackgroundDrawable( new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(backgroundFile)))); } else { BackgroundDownloadTask dt = new BackgroundDownloadTask(); dt.execute(widget.getBackgroundURL()); } } else if (widget.isBackgroundInAssets()) { AssetManager am = this.getAssets(); root.setBackgroundDrawable(new BitmapDrawable(am.open(widget.getBackgroundURL()))); } if (contacts != null) { ImageView avatarImage = (ImageView) findViewById(R.id.grouped_contacts_details_avatar); avatarImage.setImageResource(R.drawable.gc_profile_avatar); if (person.hasAvatar() && NetworkUtils.isOnline(this)) { avatarImage.setVisibility(View.VISIBLE); Glide.with(this).load(person.getAvatarUrl()).placeholder(R.drawable.gc_profile_avatar) .dontAnimate().into(avatarImage); } else { avatarImage.setVisibility(View.VISIBLE); avatarImage.setImageResource(R.drawable.gc_profile_avatar); } String name = ""; neededContacts = new ArrayList<>(); for (Contact con : contacts) { if ((con.getType() == 5) || (con.getDescription().length() == 0)) { } else { if (con.getType() == 0) { name = con.getDescription(); } else neededContacts.add(con); } } if (neededContacts.isEmpty()) { handler.sendEmptyMessage(THERE_IS_NO_CONTACT_DATA); return; } headSeparator = findViewById(R.id.gc_head_separator); bottomSeparator = findViewById(R.id.gc_bottom_separator); imageBottom = findViewById(R.id.gc_image_bottom_layout); personName = (TextView) findViewById(R.id.gc_details_description); if ("".equals(name)) personName.setVisibility(View.GONE); else { personName.setVisibility(View.VISIBLE); personName.setText(name); personName.setTextColor(Statics.color3); } if (Statics.isLight) { headSeparator.setBackgroundColor(Color.parseColor("#4d000000")); bottomSeparator.setBackgroundColor(Color.parseColor("#4d000000")); } else { headSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF")); bottomSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF")); } ViewUtils.setBackgroundLikeHeader(imageBottom, Statics.color1); ListView list = (ListView) findViewById(R.id.grouped_contacts_details_list_view); list.setDivider(null); ContactDetailsAdapter adapter = new ContactDetailsAdapter(ContactDetailsActivity.this, R.layout.grouped_contacts_details_item, neededContacts, isChemeDark(Statics.color1)); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { listViewItemClick(position); } }); } if (widget.hasParameter("add_contact")) { HashMap<String, String> hm = new HashMap<>(); for (int i = 0; i < contacts.size(); i++) { switch (contacts.get(i).getType()) { case 0: { hm.put("contactName", contacts.get(i).getDescription()); } break; case 1: { hm.put("contactNumber", contacts.get(i).getDescription()); } break; case 2: { hm.put("contactEmail", contacts.get(i).getDescription()); } break; case 3: { hm.put("contactSite", contacts.get(i).getDescription()); } break; } } addNativeFeature(NATIVE_FEATURES.ADD_CONTACT, null, hm); } if (widget.hasParameter("send_sms")) { HashMap<String, String> hm = new HashMap<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < contacts.size(); i++) { sb.append(contacts.get(i).getDescription()); if (i < contacts.size() - 1) { sb.append(", "); } } hm.put("text", sb.toString()); addNativeFeature(NATIVE_FEATURES.SMS, null, hm); } if (widget.hasParameter("send_mail")) { HashMap<String, CharSequence> hm = new HashMap<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < contacts.size(); i++) { switch (contacts.get(i).getType()) { case 0: { sb.append("Name: "); } break; case 1: { sb.append("Phone: "); } break; case 2: { sb.append("Email: "); } break; case 3: { sb.append("Site: "); } break; case 4: { sb.append("Address: "); } break; } sb.append(contacts.get(i).getDescription()); sb.append("<br/>"); } if (widget.isHaveAdvertisement()) { sb.append("<br>\n (sent from <a href=\"http://ibuildapp.com\">iBuildApp</a>)"); } hm.put("text", sb.toString()); hm.put("subject", "Contacts"); addNativeFeature(NATIVE_FEATURES.EMAIL, null, hm); } } catch (Exception e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } }
From source file:com.ibuildapp.romanblack.MultiContactsPlugin.MultiContactsActivity.java
/** * Updates page background after background image was downloaded and decoded. *//* w w w .jav a2s .co m*/ private void updateBackground() { try { root.setBackgroundDrawable( new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(cacheBackgroundFile)))); backgroundLoadede = true; handler.sendEmptyMessage(SHOW_PERSONS); } catch (FileNotFoundException fNFEx) { } }
From source file:org.herrlado.websms.connector.smsge.ConnectorSmsge.java
/** * Load captcha and wait for user input to solve it. * //from w ww . jav a 2s. co m * @param context * {@link Context} * @param flow * _flowExecutionKey * @return true if captcha was solved * @throws IOException * IOException */ private String solveCaptcha(final ConnectorContext ctx) throws IOException { HttpGet cap = new HttpGet(URL_CAPTCHA); cap.addHeader("Referer", "http://www.sms.ge/ngeo/index.php"); cap.setHeader("User-Agent", FAKE_USER_AGENT); HttpResponse response = ctx.getClient().execute(cap); int resp = response.getStatusLine().getStatusCode(); if (resp != HttpURLConnection.HTTP_OK) { throw new WebSMSException(ctx.getContext(), R.string.error_http, "" + resp); } BitmapDrawable captcha = new BitmapDrawable(response.getEntity().getContent()); final Intent intent = new Intent(Connector.ACTION_CAPTCHA_REQUEST); intent.putExtra(Connector.EXTRA_CAPTCHA_DRAWABLE, captcha.getBitmap()); captcha = null; Context context = ctx.getContext(); this.getSpec(context).setToIntent(intent); context.sendBroadcast(intent); try { synchronized (CAPTCHA_SYNC) { CAPTCHA_SYNC.wait(CAPTCHA_TIMEOUT); } } catch (InterruptedException e) { Log.e(TAG, null, e); return null; } if (captchaSolve == null) { return captchaSolve; } // got user response, try to solve captcha Log.d(TAG, "got solved captcha: " + captchaSolve); return captchaSolve; }
From source file:com.box.myview.MyTopSnackBar.TSnackbar.java
/** * @param resource_id image id/* www . java2s . com*/ * @param width image width * @param height image height * @return */ public TSnackbar addIcon(int resource_id, int width, int height) { final TextView tv = mView.getMessageView(); if (width > 0 || height > 0) { tv.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(Bitmap.createScaledBitmap( ((BitmapDrawable) (mContext.getResources().getDrawable(resource_id))).getBitmap(), width, height, true)), null, null, null); } else { addIcon(resource_id); } return this; }
From source file:com.example.alyshia.customsimplelauncher.MainActivity.java
@Override protected void onResume() { super.onResume(); Log.d(TAG, "onresum"); if (exit) {/*w w w . j ava2 s. com*/ setkioskReceiver(); if (km == null) { km = KioskMode.getInstance(this); } if (km.isKioskModeEnabled()) { Log.d(TAG, "111Kioskmode being disabled bc it is enabled"); km.disableKioskMode(); } // if (pkm == null) { // if(cdm ==null){ // cdm = CustomDeviceManager.getInstance(); // } // pkm = cdm.getProKioskManager(); // } // // if(pkm.getProKioskState()){ // if (myPKManager == null) {myPKManager= new PKManager(this, MainActivity.this);} // Log.d(TAG, "quiting Prokiosk"); // myPKManager.quitKiosk(); // } // } else { if (f.exists()) { screen.setBackground(new BitmapDrawable(f.getAbsolutePath())); } mPagerAdapter.notifyDataSetChanged(); setStates(SAConstants.INITIAL_STATE); } }
From source file:org.herrlado.websms.connector.magtifunge.ConnectorMagtifun.java
/** * Load captcha and wait for user input to solve it. * /*from w w w . jav a 2s . c om*/ * @param second * * @param context * {@link Context} * @param flow * _flowExecutionKey * @return true if captcha was solved * @throws IOException * IOException */ private String solveCaptcha(final ConnectorContext ctx, String body) throws IOException { String url = URL_CAPTCHA; String num = findCaptchaNum(body); if (TextUtils.isEmpty(num) == false) { url = url + num; } else { url = url + DEFAULT_URL_CAPTCHA_PARAMETER; } HttpGet cap = new HttpGet(url); cap.addHeader("Referer", "http://www.magtifun.ge/index.php?page=2&lang=ge"); cap.setHeader("User-Agent", FAKE_USER_AGENT); HttpResponse response = ctx.getClient().execute(cap); int resp = response.getStatusLine().getStatusCode(); if (resp != HttpURLConnection.HTTP_OK) { throw new WebSMSException(ctx.getContext(), R.string.error_http, "" + resp); } BitmapDrawable captcha = new BitmapDrawable(response.getEntity().getContent()); final Intent intent = new Intent(Connector.ACTION_CAPTCHA_REQUEST); intent.putExtra(Connector.EXTRA_CAPTCHA_DRAWABLE, captcha.getBitmap()); captcha = null; Context context = ctx.getContext(); this.getSpec(context).setToIntent(intent); context.sendBroadcast(intent); try { synchronized (CAPTCHA_SYNC) { CAPTCHA_SYNC.wait(CAPTCHA_TIMEOUT); } } catch (InterruptedException e) { Log.e(TAG, null, e); return null; } if (captchaSolve == null) { return captchaSolve; } // got user response, try to solve captcha Log.d(TAG, "got solved captcha: " + captchaSolve); return captchaSolve; }
From source file:com.aapbd.utils.image.CacheImageDownloader.java
private void scaleImage1(ImageView view) { // Get the ImageView and its bitmap final Drawable drawing = view.getDrawable(); if (drawing == null) { return; // Checking for null & return, as suggested in comments }//from w ww.java 2 s. c om final Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap(); // Get current dimensions AND the desired bounding box int width = bitmap.getWidth(); int height = bitmap.getHeight(); final int bounding = dpToPx(view.getContext(), 300); Log.i("Test", "original width = " + Integer.toString(width)); Log.i("Test", "original height = " + Integer.toString(height)); Log.i("Test", "bounding = " + Integer.toString(bounding)); // Determine how much to scale: the dimension requiring less scaling is // closer to the its side. This way the image always stays inside your // bounding box AND either x/y axis touches it. final float xScale = ((float) bounding) / width; final float yScale = ((float) bounding) / height; final float scale = (xScale <= yScale) ? xScale : yScale; Log.i("Test", "xScale = " + Float.toString(xScale)); Log.i("Test", "yScale = " + Float.toString(yScale)); Log.i("Test", "scale = " + Float.toString(scale)); // Create a matrix for the scaling and add the scaling data final Matrix matrix = new Matrix(); matrix.postScale(scale, scale); // Create a new bitmap and convert it to a format understood by the // ImageView final Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); width = scaledBitmap.getWidth(); // re-use height = scaledBitmap.getHeight(); // re-use final BitmapDrawable result = new BitmapDrawable(scaledBitmap); Log.i("Test", "scaled width = " + Integer.toString(width)); Log.i("Test", "scaled height = " + Integer.toString(height)); // Apply the scaled bitmap view.setImageDrawable(result); // Now change ImageView's dimensions to match the scaled image final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); params.width = width; params.height = height; view.setLayoutParams(params); Log.i("Test", "done"); }
From source file:com.uzmap.pkg.uzmodules.UIListView.UIListView.java
@SuppressWarnings("deprecation") public void jsmethod_setRefreshHeader(UZModuleContext uzContext) { pullDownContext = uzContext;/* w w w. j a v a2s . com*/ if (mRefreshableList != null) { mRefreshableList.setMode(mRefreshableList.getMode() != Mode.DISABLED ? mRefreshableList.getMode() == Mode.PULL_FROM_START ? Mode.PULL_FROM_START : Mode.BOTH : Mode.PULL_FROM_START); String textDown = uzContext.optString("textDown"); if (TextUtils.isEmpty(textDown)) { textDown = TEXT_DOWN; } String textUp = uzContext.optString("textUp"); if (TextUtils.isEmpty(textUp)) { textUp = TEXT_UP; } String loadingImg = uzContext.optString("loadingImg"); if (!uzContext.isNull("showTime")) { showHeaderTime = uzContext.optBoolean("showTime"); } String bgColor = "#f5f5f5"; if (!uzContext.isNull("bgColor")) { bgColor = uzContext.optString("bgColor"); } String textColor = "#8e8e8e"; if (!uzContext.isNull("textColor")) { textColor = uzContext.optString("textColor"); } LoadingLayout loadingLayout = mRefreshableList.getHeaderLayout(); loadingLayout.setPullLabel(textDown); loadingLayout.setReleaseLabel(textUp); loadingLayout.setRefreshingLabel(REFRESH_LABEL); BitmapDrawable bitmapDrawable = new BitmapDrawable(getBitmap(loadingImg)); bitmapDrawable.setTargetDensity(mContext.getResources().getDisplayMetrics().densityDpi); loadingLayout.setLoadingDrawable(bitmapDrawable); loadingLayout.setBackgroundColor(UZUtility.parseCssColor(bgColor)); loadingLayout.getHeaderText().setTextColor(UZUtility.parseCssColor(textColor)); loadingLayout.getSubHeaderText().setTextColor(UZUtility.parseCssColor(textColor)); if (refreshListener == null) { refreshListener = new OnRefreshListener(); mRefreshableList.setOnRefreshListener(refreshListener); } } }