List of usage examples for android.graphics.drawable Drawable getIntrinsicHeight
public int getIntrinsicHeight()
From source file:com.userhook.view.UHMessageView.java
protected void loadMessage(Map<String, Object> params) { if (meta.getDisplayType().equals(UHMessageMeta.TYPE_IMAGE)) { if (meta.getButton1() != null && meta.getButton1().getImage() != null && meta.getButton1().getImage().getUrl() != null) { AsyncTask task = new AsyncTask<Object, Void, Drawable>() { @Override/*from www.j a va2s . c om*/ protected Drawable doInBackground(Object... params) { Drawable drawable = null; try { URL url = new URL((String) params[0]); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is = conn.getInputStream(); drawable = Drawable.createFromStream(is, "src"); int height = drawable.getIntrinsicHeight(); int width = drawable.getIntrinsicWidth(); drawable.setBounds(0, 0, width, height); } catch (Exception e) { Log.e(UserHook.TAG, "error download message image", e); } return drawable; } @Override protected void onPostExecute(Drawable result) { if (result != null) { // size image to fit inside the view int screenHeight = getResources().getDisplayMetrics().heightPixels; int screenWidth = getResources().getDisplayMetrics().widthPixels; int heightGutter = 40; int widthGutter = 40; int screenSpaceHeight = screenHeight - heightGutter * 2; int screenSpaceWidth = screenWidth - widthGutter * 2; float height = result.getIntrinsicHeight(); float width = result.getIntrinsicWidth(); float aspect = height / width; if (height > screenSpaceHeight) { height = screenHeight; width = height / aspect; } if (width > screenSpaceWidth) { width = screenSpaceWidth; height = width * aspect; } ImageView imageView = new ImageView(getContext()); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setImageDrawable(result); LayoutParams layoutParams = new LayoutParams((int) width, (int) height); layoutParams.addRule(CENTER_IN_PARENT); addView(imageView, layoutParams); // add click handler to image imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (meta.getButton1() != null) { clickedButton(meta.getButton1()); } } }); contentLoaded = true; if (showAfterLoad) { showDialog(); } } } }; task.execute(meta.getButton1().getImage().getUrl()); } } else if (UHMessageTemplate.getInstance().hasTemplate(meta.getDisplayType())) { String html = UHMessageTemplate.getInstance().renderTemplate(meta); loadWebViewContent(html); if (showAfterLoad) { showDialog(); } } else { UHPostAsyncTask asyncTask = new UHPostAsyncTask(params, new UHAsyncTask.UHAsyncTaskListener() { @Override public void onSuccess(String result) { if (result != null) { loadWebViewContent(result); } if (showAfterLoad) { showDialog(); } } }); asyncTask.execute(UserHook.UH_HOST_URL + UH_MESSAGE_PATH); } }
From source file:com.justwayward.reader.view.RVPIndicator.java
public RVPIndicator(Context context, AttributeSet attrs) { super(context, attrs); // /*from w w w . j ava 2 s. c o m*/ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RVPIndicator); mTabVisibleCount = a.getInt(R.styleable.RVPIndicator_item_count, D_TAB_COUNT); mTextColorNormal = a.getColor(R.styleable.RVPIndicator_text_color_normal, D_TEXT_COLOR_NORMAL); mTextColorHighlight = a.getColor(R.styleable.RVPIndicator_text_color_hightlight, D_TEXT_COLOR_HIGHLIGHT); mTextSize = a.getDimensionPixelSize(R.styleable.RVPIndicator_text_size, 16); mIndicatorColor = a.getColor(R.styleable.RVPIndicator_indicator_color, D_INDICATOR_COLOR); mIndicatorStyle = a.getInt(R.styleable.RVPIndicator_indicator_style, STYLE_LINE); Drawable drawable = a.getDrawable(R.styleable.RVPIndicator_indicator_src); if (drawable != null) { if (drawable instanceof BitmapDrawable) { mBitmap = ((BitmapDrawable) drawable).getBitmap(); } else if (drawable instanceof NinePatchDrawable) { // .9? Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); mBitmap = bitmap; } } else { mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.heart_love); } a.recycle(); /** * */ mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(mIndicatorColor); mPaint.setStyle(Style.FILL); }
From source file:tv.acfun.a63.CommentsActivity.java
@Override public void onResponse(Comments response) { isloading = false;//from w w w . j a v a 2 s. c o m mPtr.onRefreshComplete(); if (response.totalCount == 0) { mLoadingBar.setVisibility(View.GONE); mTimeOutText.setVisibility(View.VISIBLE); mList.setVisibility(View.GONE); Drawable drawable = getResources().getDrawable(R.drawable.ac_16); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); mTimeOutText.setCompoundDrawables(drawable, null, null, null); mTimeOutText.setText(R.string.no_comment_yet); return; } if (response.page == 1) { if (mAdapter != null) mAdapter.notifyDataSetInvalidated(); data.clear(); commentIdList.clear(); mLoadingBar.setVisibility(View.GONE); mList.setVisibility(View.VISIBLE); } ArrayUtil.putAll(response.commentArr, data); commentIdList.addAll(ArrayUtil.asList(response.commentList)); hasNextPage = response.nextPage > response.page; if (data != null && data.size() > 0) { mAdapter.setData(data, commentIdList); mAdapter.notifyDataSetChanged(); isreload = false; } }
From source file:tv.acfun.a63.CommentsActivity.java
private void initCommentsBar() { mCommentBar = findViewById(R.id.comments_bar); if (ActionBarUtil.hasSB() && getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { RelativeLayout.LayoutParams params = (LayoutParams) mCommentBar.getLayoutParams(); params.bottomMargin = getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); mCommentBar.setLayoutParams(params); }/*from www . j a v a 2s .c o m*/ mBtnSend = (ImageButton) findViewById(R.id.comments_send_btn); mCommentText = (EditText) findViewById(R.id.comments_edit); mBtnEmotion = findViewById(R.id.comments_emotion_btn); mEmotionGrid = (GridView) findViewById(R.id.emotions); mBtnSend.setOnClickListener(this); mBtnEmotion.setOnClickListener(this); mEmotionGrid.setAdapter(mEmotionAdapter); mEmotionGrid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int index = mCommentText.getSelectionEnd(); Editable text = mCommentText.getText(); String emotion = parent.getItemAtPosition(position).toString(); text.insert(index, emotion); EmotionView v = (EmotionView) parent.getAdapter().getView(position, null, null); Drawable drawable = TextViewUtils.convertViewToDrawable(v); drawable.setBounds(0, 0, drawable.getIntrinsicWidth() / 2, drawable.getIntrinsicHeight() / 2); text.setSpan(new ImageSpan(drawable), index, index + emotion.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }); }
From source file:net.globide.coloring_book.MainActivity.java
/** * private RelativeLayout mRlMainRight; private RelativeLayout mRlMainLeft; * Implements onCreate()./*from ww w .ja v a 2s . com*/ */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the activity to full screen mode. requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Add default content. setContentView(R.layout.activity_main); // Determine whether or not the current device is a tablet. MainActivity.sIsTablet = getResources().getBoolean(R.bool.isTablet); MainActivity.sIsSmall = getResources().getBoolean(R.bool.isSmall); MainActivity.sIsNormal = getResources().getBoolean(R.bool.isNormal); MainActivity.sIsLarge = getResources().getBoolean(R.bool.isLarge); MainActivity.sIsExtraLarge = getResources().getBoolean(R.bool.isExtraLarge); // Get stored preferences, if any. mSharedPreferences = getSharedPreferences(sFilename, 0); // Setup the editor in this function, so it can be used anywhere else if // needed. mEditor = mSharedPreferences.edit(); // If this activity continues playing the music, start the media player // if the phone is not muted AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // This should only run once at the start of the application. switch (audio.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: if (!MusicManager.sIsManualSound) { // Set the preferences to turn music off. mEditor.putBoolean("tbSettingsMusicIsChecked", false); mEditor.commit(); } break; } // This should only run once at the start of the application. if (!MusicManager.sIsManualSound) { // Set the preferences as early as possible in MusicManager. MusicManager.setPreferences(mSharedPreferences); // Update actual status MusicManager.updateVolume(); MusicManager.updateStatusFromPrefs(this); // This method can no longer be invoked to turn off the // sound once the user has manually turned sound on. MusicManager.sIsManualSound = true; } // Store the preference values in local variables. boolean tbSettingsMusicIsChecked = mSharedPreferences.getBoolean("tbSettingsMusicIsChecked", false); // Set whether music is on or not in the Music Manager if (tbSettingsMusicIsChecked) { MusicManager.start(this, MusicManager.MUSIC_A); } // Attach views to their corresponding resource ids. mIbPagerLeft = (ImageButton) findViewById(R.id.ibPagerLeft); mIbPagerRight = (ImageButton) findViewById(R.id.ibPagerRight); mIbMainHelp = (ImageButton) findViewById(R.id.ibMainHelp); mIbMainSettings = (ImageButton) findViewById(R.id.ibMainSettings); mRlMainLeftTop = (RelativeLayout) findViewById(R.id.rlMainLeftTop); mRlMainRightTop = (RelativeLayout) findViewById(R.id.rlMainRightTop); /* * This screen needs to be dynamically positioned to fit each screen * size fluidly. */ // Get the screen metrics. DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int screenHeight = dm.heightPixels; // Determine the floor section size Drawable image = this.getResources().getDrawable(R.drawable.floor); // Store the height locally int floorHeight = image.getIntrinsicHeight(); // Determine the title section size // Get the top spacing (THIS IS ALSO DEFINED EXACTLY AS IT IS HERE IN // EACH XML FILE. int topSpacing = 0; if (MainActivity.sIsTablet) { if (MainActivity.sIsSmall) { topSpacing = 18; } else if (MainActivity.sIsNormal) { topSpacing = 24; } else if (MainActivity.sIsLarge) { topSpacing = 27; } else if (MainActivity.sIsExtraLarge) { topSpacing = 30; } } else { topSpacing = 12; } Drawable imageTitle = this.getResources().getDrawable(R.drawable.main_title); // Store the height locally int titleHeight = imageTitle.getIntrinsicHeight() + topSpacing; // Resize the layout views to be centered in their proper positions // based on the sizes calculated. ViewGroup.LayoutParams paramsLeftTop = mRlMainLeftTop.getLayoutParams(); ViewGroup.LayoutParams paramsRightTop = mRlMainRightTop.getLayoutParams(); int resultHeight = (screenHeight - floorHeight) - titleHeight; paramsLeftTop.height = resultHeight; paramsRightTop.height = resultHeight; mRlMainLeftTop.setLayoutParams(paramsLeftTop); mRlMainRightTop.setLayoutParams(paramsRightTop); // TODO: See if there are better methods of retrieving the floor height // value from the xml layout. // Set listeners to objects that can receive user input. mIbPagerRight.setOnClickListener(this); mIbPagerLeft.setOnClickListener(this); mIbMainHelp.setOnClickListener(this); mIbMainSettings.setOnClickListener(this); // Database check! // Create our database access object. mDbNodeHelper = new NodeDatabase(this); // Call the create method right just in case the user has never run the // app before. If a database does not exist, the prepopulated one will // be copied from the assets folder. Else, a connection is established. mDbNodeHelper.createDatabase(); // Query the database for all purchased categories. // Set a conditional buffer. Internally, the orderby is set to _id ASC // (NodeDatabase.java). mDbNodeHelper.setConditions("isAvailable", "1"); // Execute the query. mCategoryData = mDbNodeHelper.getCategoryListData(); // Store the number of categories available. mCategoryLength = mCategoryData.length + 1; // Flush the buffer. mDbNodeHelper.flushQuery(); // This activity no longer needs the connection, so close it. mDbNodeHelper.close(); // Initialize the pager this.initializePaging(); }
From source file:net.globide.coloring_book_08.MainActivity.java
/** * private RelativeLayout mRlMainRight; private RelativeLayout mRlMainLeft; * Implements onCreate()./* w ww. j a va2s .c o m*/ */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the activity to full screen mode. requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Add default content. setContentView(R.layout.activity_main); // Determine whether or not the current device is a tablet. MainActivity.sIsTablet = getResources().getBoolean(R.bool.isTablet); MainActivity.sIsSmall = getResources().getBoolean(R.bool.isSmall); MainActivity.sIsNormal = getResources().getBoolean(R.bool.isNormal); MainActivity.sIsLarge = getResources().getBoolean(R.bool.isLarge); MainActivity.sIsExtraLarge = getResources().getBoolean(R.bool.isExtraLarge); // Get stored preferences, if any. mSharedPreferences = getSharedPreferences(sFilename, 0); // Setup the editor in this function, so it can be used anywhere else if // needed. mEditor = mSharedPreferences.edit(); // If this activity continues playing the music, start the media player // if the phone is not muted AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // This should only run once at the start of the application. switch (audio.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: if (!MusicManager.sIsManualSound) { // Set the preferences to turn music off. mEditor.putBoolean("tbSettingsMusicIsChecked", false); mEditor.commit(); } break; } // This should only run once at the start of the application. if (!MusicManager.sIsManualSound) { // Set the preferences as early as possible in MusicManager. MusicManager.setPreferences(mSharedPreferences); // Update actual status MusicManager.updateVolume(); MusicManager.updateStatusFromPrefs(this); // This method can no longer be invoked to turn off the // sound once the user has manually turned sound on. MusicManager.sIsManualSound = true; } // Store the preference values in local variables. boolean tbSettingsMusicIsChecked = mSharedPreferences.getBoolean("tbSettingsMusicIsChecked", false); // Set whether music is on or not in the Music Manager if (tbSettingsMusicIsChecked) { MusicManager.start(this, MusicManager.MUSIC_A); } // Attach views to their corresponding resource ids. mIbPagerLeft = (ImageButton) findViewById(R.id.ibPagerLeft); mIbPagerRight = (ImageButton) findViewById(R.id.ibPagerRight); mIbMainHelp = (ImageButton) findViewById(R.id.ibMainHelp); mIbMainSettings = (ImageButton) findViewById(R.id.ibMainSettings); mRlMainLeftTop = (RelativeLayout) findViewById(R.id.rlMainLeftTop); mRlMainRightTop = (RelativeLayout) findViewById(R.id.rlMainRightTop); /* * This screen needs to be dynamically positioned to fit each screen * size fluidly. */ // Get the screen metrics. DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int screenHeight = dm.heightPixels; // Determine the floor section size Drawable image = this.getResources().getDrawable(R.drawable.floor); // Store the height locally int floorHeight = image.getIntrinsicHeight(); // Determine the title section size // Get the top spacing (THIS IS ALSO DEFINED EXACTLY AS IT IS HERE IN // EACH XML FILE. int topSpacing = 0; if (MainActivity.sIsTablet) { if (MainActivity.sIsSmall) { topSpacing = 18; } else if (MainActivity.sIsNormal) { topSpacing = 24; } else if (MainActivity.sIsLarge) { topSpacing = 27; } else if (MainActivity.sIsExtraLarge) { topSpacing = 30; } } else { topSpacing = 12; } Drawable imageTitle = this.getResources().getDrawable(R.drawable.main_title); // Store the height locally int titleHeight = imageTitle.getIntrinsicHeight() + topSpacing; // Resize the layout views to be centered in their proper positions // based on the sizes calculated. ViewGroup.LayoutParams paramsLeftTop = mRlMainLeftTop.getLayoutParams(); ViewGroup.LayoutParams paramsRightTop = mRlMainRightTop.getLayoutParams(); int resultHeight = (screenHeight - floorHeight) - titleHeight; paramsLeftTop.height = resultHeight; paramsRightTop.height = resultHeight; mRlMainLeftTop.setLayoutParams(paramsLeftTop); mRlMainRightTop.setLayoutParams(paramsRightTop); // TODO: See if there are better methods of retrieving the floor height // value from the xml layout. // Set listeners to objects that can receive user input. mIbPagerRight.setOnClickListener(this); mIbPagerLeft.setOnClickListener(this); mIbMainHelp.setOnClickListener(this); mIbMainSettings.setOnClickListener(this); // Database check! // Create our database access object. mDbNodeHelper = new NodeDatabase(this); // Call the create method right just in case the user has never run the // app before. If a database does not exist, the prepopulated one will // be copied from the assets folder. Else, a connection is established. mDbNodeHelper.createDatabase(); // Query the database for all purchased categories. // Set a conditional buffer. Internally, the orderby is set to _id ASC // (NodeDatabase.java). mDbNodeHelper.setConditions("isAvailable", "1"); // Execute the query. mCategoryData = mDbNodeHelper.getCategoryListData(); // Store the number of categories available. mCategoryLength = mCategoryData.length; // Flush the buffer. mDbNodeHelper.flushQuery(); // This activity no longer needs the connection, so close it. mDbNodeHelper.close(); // Initialize the pager this.initializePaging(); }
From source file:com.shizhefei.view.largeimage.UpdateImageView.java
private void updateDrawable(Drawable d) { if (mDrawable != null) { mDrawable.setCallback(null);/* ww w . ja va 2 s.c o m*/ unscheduleDrawable(mDrawable); } mDrawable = d; if (d != null) { d.setCallback(this); DrawableCompat.setLayoutDirection(d, DrawableCompat.getLayoutDirection(d)); if (d.isStateful()) { d.setState(getDrawableState()); } d.setVisible(getVisibility() == VISIBLE, true); d.setLevel(mLevel); mDrawableWidth = d.getIntrinsicWidth(); mDrawableHeight = d.getIntrinsicHeight(); // applyImageTint(); // applyColorMod(); // // configureBounds(); } else { mDrawableWidth = mDrawableHeight = -1; } }
From source file:lewa.support.v7.internal.view.menu.ActionMenuItemView.java
public void setIcon(Drawable icon) { mIcon = icon;/*ww w.j a va 2s . c o m*/ if (icon != null) { // LEWA ADD BEGIN mColorfulIcon = null; mColorfulIcon = Injector.resetDrawableColor(this, icon); // LEWA ADD END int width = icon.getIntrinsicWidth(); int height = icon.getIntrinsicHeight(); if (width > mMaxIconSize) { final float scale = (float) mMaxIconSize / width; width = mMaxIconSize; height *= scale; } if (height > mMaxIconSize) { final float scale = (float) mMaxIconSize / height; height = mMaxIconSize; width *= scale; } // LEWA MODIFY BEGIN if (true) { mColorfulIcon.setBounds(0, 0, width, height); } else { icon.setBounds(0, 0, width, height); } // LEWA MODIFY END } // LEWA MODIFY BEGIN if (true) { // Set icon at top in Lewa OS setCompoundDrawables(null, mColorfulIcon, null, null); } else { setCompoundDrawables(icon, null, null, null); } // LEWA MODIFY END updateTextButtonVisibility(); }
From source file:com.frank.protean.photoview.PhotoViewAttacher.java
/** * Helper method that maps the supplied Matrix to the current Drawable * * @param matrix - Matrix to map Drawable against * @return RectF - Displayed Rectangle/*ww w . j av a 2 s . c om*/ */ private RectF getDisplayRect(Matrix matrix) { Drawable d = mImageView.getDrawable(); if (d != null) { mDisplayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); matrix.mapRect(mDisplayRect); return mDisplayRect; } return null; }
From source file:com.waz.zclient.controllers.notifications.NotificationsController.java
private Bitmap getAppIcon() { try {/*from w ww . j av a2 s. c o m*/ Drawable icon = context.getPackageManager().getApplicationIcon(context.getPackageName()); if (icon instanceof BitmapDrawable) { return ((BitmapDrawable) icon).getBitmap(); } Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); icon.draw(canvas); return bitmap; } catch (PackageManager.NameNotFoundException e) { return BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher_wire); } }