List of usage examples for android.content.res Resources getDimensionPixelSize
public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException
From source file:com.mukesh.OtpView.java
public OtpView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final Resources res = getResources(); paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); animatorTextPaint.set(getPaint());// www. j a va2 s . c om final Resources.Theme theme = context.getTheme(); TypedArray typedArray = theme.obtainStyledAttributes(attrs, R.styleable.OtpView, defStyleAttr, 0); viewType = typedArray.getInt(R.styleable.OtpView_viewType, VIEW_TYPE_RECTANGLE); otpViewItemCount = typedArray.getInt(R.styleable.OtpView_itemCount, DEFAULT_COUNT); otpViewItemHeight = (int) typedArray.getDimension(R.styleable.OtpView_itemHeight, res.getDimensionPixelSize(R.dimen.otp_view_item_size)); otpViewItemWidth = (int) typedArray.getDimension(R.styleable.OtpView_itemWidth, res.getDimensionPixelSize(R.dimen.otp_view_item_size)); otpViewItemSpacing = typedArray.getDimensionPixelSize(R.styleable.OtpView_itemSpacing, res.getDimensionPixelSize(R.dimen.otp_view_item_spacing)); otpViewItemRadius = (int) typedArray.getDimension(R.styleable.OtpView_itemRadius, 0); lineWidth = (int) typedArray.getDimension(R.styleable.OtpView_lineWidth, res.getDimensionPixelSize(R.dimen.otp_view_item_line_width)); lineColor = typedArray.getColorStateList(R.styleable.OtpView_lineColor); isCursorVisible = typedArray.getBoolean(R.styleable.OtpView_android_cursorVisible, true); cursorColor = typedArray.getColor(R.styleable.OtpView_cursorColor, getCurrentTextColor()); cursorWidth = typedArray.getDimensionPixelSize(R.styleable.OtpView_cursorWidth, res.getDimensionPixelSize(R.dimen.otp_view_cursor_width)); itemBackground = typedArray.getDrawable(R.styleable.OtpView_android_itemBackground); hideLineWhenFilled = typedArray.getBoolean(R.styleable.OtpView_hideLineWhenFilled, false); rtlTextDirection = typedArray.getBoolean(R.styleable.OtpView_rtlTextDirection, false); typedArray.recycle(); if (lineColor != null) { cursorLineColor = lineColor.getDefaultColor(); } updateCursorHeight(); checkItemRadius(); setMaxLength(otpViewItemCount); paint.setStrokeWidth(lineWidth); setupAnimator(); super.setCursorVisible(false); setTextIsSelectable(false); }
From source file:net.qiujuer.genius.ui.widget.GeniusAbsSeekBar.java
public GeniusAbsSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true);//from w w w . j a v a 2 s.c o m setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); // New final Resources resources = getResources(); final ColorStateList transparent = ColorStateList.valueOf(Color.TRANSPARENT); mAttributes = new SeekBarAttributes(this, resources); mRipple = new AlmostRippleDrawable(transparent); mRipple.setCallback(this); mSeekBarDrawable = new SeekBarDrawable(transparent, transparent, transparent); mSeekBarDrawable.setCallback(this); if (!isInEditMode()) { mIndicator = new GeniusPopupIndicator(context); mIndicator.setListener(mFloaterListener); } // Set Size setTrackStroke(resources.getDimensionPixelSize(R.dimen.genius_seekBar_trackStroke)); setScrubberStroke(resources.getDimensionPixelSize(R.dimen.genius_seekBar_scrubberStroke)); setThumbRadius(resources.getDimensionPixelSize(R.dimen.genius_seekBar_thumbSize)); setTouchRadius(resources.getDimensionPixelSize(R.dimen.genius_seekBar_touchSize)); setTickRadius(resources.getDimensionPixelSize(R.dimen.genius_seekBar_tickSize)); // Init init(attrs, defStyle); // End setNumericTransformer(new DefaultNumericTransformer()); isRtl(); if (attrs != null) setEnabled(attrs.getAttributeBooleanValue(GeniusUi.androidStyleNameSpace, "enabled", isEnabled())); else setEnabled(isEnabled()); }
From source file:net.qiujuer.genius.widget.GeniusAbsSeekBar.java
public GeniusAbsSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true);/*from w w w . j a va 2 s .com*/ setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); // New final Resources resources = getResources(); final ColorStateList transparent = ColorStateList.valueOf(Color.TRANSPARENT); mAttributes = new SeekBarAttributes(this, resources); mRipple = new AlmostRippleDrawable(transparent); mRipple.setCallback(this); mSeekBarDrawable = new SeekBarDrawable(transparent, transparent, transparent); mSeekBarDrawable.setCallback(this); if (!isInEditMode()) { mIndicator = new GeniusPopupIndicator(context); mIndicator.setListener(mFloaterListener); } // Set Size setTrackStroke(resources.getDimensionPixelSize(R.dimen.genius_seekBar_trackStroke)); setScrubberStroke(resources.getDimensionPixelSize(R.dimen.genius_seekBar_scrubberStroke)); setThumbRadius(resources.getDimensionPixelSize(R.dimen.genius_seekBar_thumbSize)); setTouchRadius(resources.getDimensionPixelSize(R.dimen.genius_seekBar_touchSize)); setTickRadius(resources.getDimensionPixelSize(R.dimen.genius_seekBar_tickSize)); // Init init(attrs, defStyle); // End setNumericTransformer(new DefaultNumericTransformer()); isRtl(); if (attrs != null) setEnabled(attrs.getAttributeBooleanValue(GeniusUI.androidStyleNameSpace, "enabled", isEnabled())); else setEnabled(isEnabled()); }
From source file:com.android.volley.ui.PhotoView.java
/** * Initializes the header and any static values *///from w w w. j a v a2 s.c o m private void initialize() { Context context = getContext(); if (!sInitialized) { sInitialized = true; Resources resources = context.getApplicationContext().getResources(); sCropSize = resources.getDimensionPixelSize(R.dimen.photo_crop_width); sCropDimPaint = new Paint(); sCropDimPaint.setAntiAlias(true); sCropDimPaint.setColor(resources.getColor(R.color.photo_crop_dim_color)); sCropDimPaint.setStyle(Style.FILL); sCropPaint = new Paint(); sCropPaint.setAntiAlias(true); sCropPaint.setColor(resources.getColor(R.color.photo_crop_highlight_color)); sCropPaint.setStyle(Style.STROKE); sCropPaint.setStrokeWidth(resources.getDimension(R.dimen.photo_crop_stroke_width)); final ViewConfiguration configuration = ViewConfiguration.get(context); final int touchSlop = configuration.getScaledTouchSlop(); sTouchSlopSquare = touchSlop * touchSlop; } mGestureDetector = new GestureDetectorCompat(context, this, null); mScaleGetureDetector = new ScaleGestureDetector(context, this); mQuickScaleEnabled = ScaleGestureDetectorCompat.isQuickScaleEnabled(mScaleGetureDetector); mScaleRunnable = new ScaleRunnable(this); mTranslateRunnable = new TranslateRunnable(this); mSnapRunnable = new SnapRunnable(this); mRotateRunnable = new RotateRunnable(this); }
From source file:com.htc.dotdesign.ToolBoxService.java
private void initToolBar() { if (mToolBarParent != null) { Resources res = getResources(); mToolBar = mToolBarParent.findViewById(R.id.tool_bar); mBtnPalette = (ImageButton) mToolBar.findViewById(R.id.btn_palette); mBtnEraser = (ImageButton) mToolBar.findViewById(R.id.btn_eraser); mBtnVirtualDot = (ImageButton) mToolBar.findViewById(R.id.btn_virtual_dot); mBtnMenu = (ImageButton) mToolBar.findViewById(R.id.btn_menu); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mBtnPalette.getLayoutParams(); int leftMargin = res.getDimensionPixelSize(R.dimen.drag_button_width) + res.getDimensionPixelSize(R.dimen.margin_xs_3); params.setMargins(leftMargin, 0, 0, 0); mBtnPalette.setLayoutParams(params); if (mButtonListener != null) { mBtnPalette.setOnClickListener(mButtonListener); mBtnEraser.setOnClickListener(mButtonListener); mBtnVirtualDot.setOnClickListener(mButtonListener); mBtnMenu.setOnClickListener(mButtonListener); }// w ww . ja va 2 s . c om updateToolBarFunIconColor(); } }
From source file:com.philliphsu.bottomsheetpickers.date.MonthView.java
public MonthView(Context context, AttributeSet attr) { super(context, attr); Resources res = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); mDayOfWeekTypeface = res.getString(R.string.bsp_day_of_week_label_typeface); mMonthTitleTypeface = res.getString(R.string.bsp_sans_serif); mDayTextColor = res.getColor(R.color.bsp_text_color_primary_light); // Same as background color mSelectedDayTextColor = getColor(context, R.color.bsp_date_picker_view_animator); mTodayNumberColor = Utils.getThemeAccentColor(context); mDisabledDayTextColor = res.getColor(R.color.bsp_text_color_disabled_light); mMonthTitleColor = res.getColor(android.R.color.white); mMonthTitleBGColor = res.getColor(R.color.bsp_circle_background); mMonthDayLabelTextColor = getColor(context, R.color.bsp_text_color_disabled_light); MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.bsp_day_number_size); MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.bsp_month_label_size); MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.bsp_month_day_label_text_size); MONTH_HEADER_SIZE = res.getDimensionPixelOffset(DRAW_TITLE ? R.dimen.bsp_month_list_item_header_height : R.dimen.bsp_month_list_item_header_height_no_title); DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.bsp_day_number_select_circle_radius); mRowHeight = (res.getDimensionPixelOffset(R.dimen.bsp_date_picker_view_animator_height) - getMonthHeaderSize() - getMonthNavigationBarSize()) / MAX_NUM_ROWS; mEdgePadding = res.getDimensionPixelSize(R.dimen.bsp_month_view_edge_padding); // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true;/*from w w w.j a va2 s.c o m*/ // Sets up any standard paints that will be used initView(); }
From source file:com.keylesspalace.tusky.ComposeActivity.java
private void addMediaToQueue(@Nullable String id, QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize, QueuedMedia.ReadyStage readyStage, @Nullable String description) { final QueuedMedia item = new QueuedMedia(type, uri, new ProgressImageView(this), mediaSize, description); item.id = id;/*w w w . j av a 2 s .c om*/ item.readyStage = readyStage; ImageView view = item.preview; Resources resources = getResources(); int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin); int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(thumbnailViewSize, thumbnailViewSize); layoutParams.setMargins(margin, 0, margin, marginBottom); view.setLayoutParams(layoutParams); view.setScaleType(ImageView.ScaleType.CENTER_CROP); view.setImageBitmap(preview); view.setOnClickListener(v -> onMediaClick(item, v)); view.setContentDescription(getString(R.string.action_delete)); mediaPreviewBar.addView(view); mediaQueued.add(item); int queuedCount = mediaQueued.size(); if (queuedCount == 1) { // If there's one video in the queue it is full, so disable the button to queue more. if (item.type == QueuedMedia.Type.VIDEO) { enableButton(pickButton, false, false); } } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) { // Limit the total media attachments, also. enableButton(pickButton, false, false); } updateHideMediaToggle(); if (item.readyStage != QueuedMedia.ReadyStage.UPLOADED) { waitForMediaLatch.countUp(); try { if (type == QueuedMedia.Type.IMAGE && (mediaSize > STATUS_MEDIA_SIZE_LIMIT || MediaUtils .getImageSquarePixels(getContentResolver(), item.uri) > STATUS_MEDIA_PIXEL_SIZE_LIMIT)) { downsizeMedia(item); } else { uploadMedia(item); } } catch (FileNotFoundException e) { onUploadFailure(item, false); } } }
From source file:com.concentriclivers.mms.com.android.mms.transaction.MessagingNotification.java
/** * updateNotification is *the* main function for building the actual notification handed to * the NotificationManager// w w w . j av a 2 s. c o m * @param context * @param isNew if we've got a new message, show the ticker * @param uniqueThreadCount */ private static void updateNotification(Context context, boolean isNew, int uniqueThreadCount) { // TDH Log.d("NotificationDebug", "updateNotification()"); // If the user has turned off notifications in settings, don't do any notifying. if (!MessagingPreferenceActivity.getNotificationEnabled(context)) { if (DEBUG) { Log.d(TAG, "updateNotification: notifications turned off in prefs, bailing"); } // TDH Log.d("NotificationDebug", "Notifications not enabled!"); return; } // Figure out what we've got -- whether all sms's, mms's, or a mixture of both. int messageCount = sNotificationSet.size(); // TDH: Log.d("NotificationDebug", "messageCount: " + messageCount); if (messageCount == 0) { Log.d("NotificationDebug", "WTF. Should have at least one message."); return; } NotificationInfo mostRecentNotification = sNotificationSet.first(); // TDH: Use NotificationCompat2 (and in other places but it is obvious where). final NotificationCompat2.Builder noti = new NotificationCompat2.Builder(context) .setWhen(mostRecentNotification.mTimeMillis); if (isNew) { noti.setTicker(mostRecentNotification.mTicker); } // TDH Log.d("NotificationDebug", "Creating TaskStackBuilder"); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); // TDH Log.d("NotificationDebug", "Created TaskStackBuilder. UniqueThreadCount: " + uniqueThreadCount); // If we have more than one unique thread, change the title (which would // normally be the contact who sent the message) to a generic one that // makes sense for multiple senders, and change the Intent to take the // user to the conversation list instead of the specific thread. // Cases: // 1) single message from single thread - intent goes to ComposeMessageActivity // 2) multiple messages from single thread - intent goes to ComposeMessageActivity // 3) messages from multiple threads - intent goes to ConversationList final Resources res = context.getResources(); String title = null; Bitmap avatar = null; if (uniqueThreadCount > 1) { // messages from multiple threads Intent mainActivityIntent = new Intent(Intent.ACTION_MAIN); mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); mainActivityIntent.setType("vnd.android-dir/mms-sms"); taskStackBuilder.addNextIntent(mainActivityIntent); title = context.getString(R.string.message_count_notification, messageCount); } else { // same thread, single or multiple messages title = mostRecentNotification.mTitle; BitmapDrawable contactDrawable = (BitmapDrawable) mostRecentNotification.mSender.getAvatar(context, null); if (contactDrawable != null) { // Show the sender's avatar as the big icon. Contact bitmaps are 96x96 so we // have to scale 'em up to 128x128 to fill the whole notification large icon. avatar = contactDrawable.getBitmap(); if (avatar != null) { final int idealIconHeight = res .getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res .getDimensionPixelSize(android.R.dimen.notification_large_icon_width); if (avatar.getHeight() < idealIconHeight) { // Scale this image to fit the intended size avatar = Bitmap.createScaledBitmap(avatar, idealIconWidth, idealIconHeight, true); } if (avatar != null) { noti.setLargeIcon(avatar); } } } taskStackBuilder.addParentStack(ComposeMessageActivity.class); taskStackBuilder.addNextIntent(mostRecentNotification.mClickIntent); } // TDH Log.d("NotificationDebug", "title: " + title); // Always have to set the small icon or the notification is ignored noti.setSmallIcon(R.drawable.stat_notify_sms); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Update the notification. noti.setContentTitle(title) .setContentIntent(taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); // TDH: Can't do these yet. // .addKind(Notification.KIND_MESSAGE) // .setPriority(Notification.PRIORITY_DEFAULT); // TODO: set based on contact coming // // from a favorite. int defaults = 0; if (isNew) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); String vibrateWhen; if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN)) { vibrateWhen = sp.getString(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN, null); } else if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE)) { vibrateWhen = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false) ? context.getString(R.string.prefDefault_vibrate_true) : context.getString(R.string.prefDefault_vibrate_false); } else { vibrateWhen = context.getString(R.string.prefDefault_vibrateWhen); } boolean vibrateAlways = vibrateWhen.equals("always"); boolean vibrateSilent = vibrateWhen.equals("silent"); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); boolean nowSilent = audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE; if (vibrateAlways || vibrateSilent && nowSilent) { defaults |= Notification.DEFAULT_VIBRATE; } String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null); noti.setSound(TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr)); if (DEBUG) { Log.d(TAG, "updateNotification: new message, adding sound to the notification"); } } defaults |= Notification.DEFAULT_LIGHTS; noti.setDefaults(defaults); // set up delete intent noti.setDeleteIntent(PendingIntent.getBroadcast(context, 0, sNotificationOnDeleteIntent, 0)); final Notification notification; if (messageCount == 1) { // We've got a single message // TDH Log.d("NotificationDebug", "Single message, with text: " + mostRecentNotification.formatBigMessage(context)); // This sets the text for the collapsed form: noti.setContentText(mostRecentNotification.formatBigMessage(context)); if (mostRecentNotification.mAttachmentBitmap != null) { // The message has a picture, show that notification = new NotificationCompat2.BigPictureStyle(noti) .bigPicture(mostRecentNotification.mAttachmentBitmap) // This sets the text for the expanded picture form: .setSummaryText(mostRecentNotification.formatPictureMessage(context)).build(); } else { // Show a single notification -- big style with the text of the whole message notification = new NotificationCompat2.BigTextStyle(noti) .bigText(mostRecentNotification.formatBigMessage(context)).build(); } } else { // We've got multiple messages if (uniqueThreadCount == 1) { // We've got multiple messages for the same thread. // Starting with the oldest new message, display the full text of each message. // Begin a line for each subsequent message. SpannableStringBuilder buf = new SpannableStringBuilder(); NotificationInfo infos[] = sNotificationSet.toArray(new NotificationInfo[sNotificationSet.size()]); int len = infos.length; for (int i = len - 1; i >= 0; i--) { NotificationInfo info = infos[i]; buf.append(info.formatBigMessage(context)); if (i != 0) { buf.append('\n'); } } noti.setContentText(context.getString(R.string.message_count_notification, messageCount)); // Show a single notification -- big style with the text of all the messages notification = new NotificationCompat2.BigTextStyle(noti).bigText(buf) // Forcibly show the last line, with the app's smallIcon in it, if we // kicked the smallIcon out with an avatar bitmap .setSummaryText((avatar == null) ? null : " ").build(); } else { // Build a set of the most recent notification per threadId. HashSet<Long> uniqueThreads = new HashSet<Long>(sNotificationSet.size()); ArrayList<NotificationInfo> mostRecentNotifPerThread = new ArrayList<NotificationInfo>(); Iterator<NotificationInfo> notifications = sNotificationSet.iterator(); while (notifications.hasNext()) { NotificationInfo notificationInfo = notifications.next(); if (!uniqueThreads.contains(notificationInfo.mThreadId)) { uniqueThreads.add(notificationInfo.mThreadId); mostRecentNotifPerThread.add(notificationInfo); } } // When collapsed, show all the senders like this: // Fred Flinstone, Barry Manilow, Pete... noti.setContentText(formatSenders(context, mostRecentNotifPerThread)); NotificationCompat2.InboxStyle inboxStyle = new NotificationCompat2.InboxStyle(noti); // We have to set the summary text to non-empty so the content text doesn't show // up when expanded. inboxStyle.setSummaryText(" "); // At this point we've got multiple messages in multiple threads. We only // want to show the most recent message per thread, which are in // mostRecentNotifPerThread. int uniqueThreadMessageCount = mostRecentNotifPerThread.size(); int maxMessages = Math.min(MAX_MESSAGES_TO_SHOW, uniqueThreadMessageCount); for (int i = 0; i < maxMessages; i++) { NotificationInfo info = mostRecentNotifPerThread.get(i); inboxStyle.addLine(info.formatInboxMessage(context)); } notification = inboxStyle.build(); if (DEBUG) { Log.d(TAG, "updateNotification: multi messages," + " showing inboxStyle notification"); } } } // TDH Log.d("NotificationDebug", "Showing notification: " + notification); nm.notify(NOTIFICATION_ID, notification); }
From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java
void showNotification(boolean custom) { final Resources res = getResources(); final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE);// www.ja v a 2 s. co m Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_stat_notify_example).setAutoCancel(true) .setTicker(getString(R.string.notification_text)) .setContentIntent(getDialogPendingIntent("Tapped the notification entry.")); if (custom) { // Sets a custom content view for the notification, including an image button. RemoteViews layout = new RemoteViews(getPackageName(), R.layout.notification); layout.setTextViewText(R.id.notification_title, getString(R.string.app_name)); layout.setOnClickPendingIntent(R.id.notification_button, getDialogPendingIntent("Tapped the 'dialog' button in the notification.")); builder.setContent(layout); // Notifications in Android 3.0 now have a standard mechanism for displaying large // bitmaps such as contact avatars. Here, we load an example image and resize it to the // appropriate size for large bitmaps in notifications. Bitmap largeIconTemp = BitmapFactory.decodeResource(res, R.drawable.notification_default_largeicon); Bitmap largeIcon = Bitmap.createScaledBitmap(largeIconTemp, res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width), res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height), false); largeIconTemp.recycle(); builder.setLargeIcon(largeIcon); } else { builder.setNumber(7) // An example number. .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_text)); } notificationManager.notify(NOTIFICATION_DEFAULT, builder.getNotification()); }
From source file:net.toload.main.hd.candidate.CandidateView.java
public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext = context;/*from w ww. j a v a2 s. c om*/ mCandidateView = this; embeddedComposing = null; // Jeremy '15,6,4 for embedded composing view in candidateView when floating candidateView (not fixed) mLIMEPref = new LIMEPreferenceManager(context); //Jeremy '16,7,24 get themed objects TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.LIMECandidateView, defStyle, R.style.LIMECandidateView); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.LIMECandidateView_suggestHighlight: mDrawableSuggestHighlight = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_voiceInputIcon: mDrawableVoiceInput = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_ExpandButtonIcon: mDrawableExpandButton = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_closeButtonIcon: mDrawableCloseButton = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_candidateBackground: mColorBackground = a.getColor(attr, ContextCompat.getColor(context, R.color.third_background_light)); break; case R.styleable.LIMECandidateView_composingTextColor: mColorComposingText = a.getColor(attr, ContextCompat.getColor(context, R.color.second_foreground_light)); break; case R.styleable.LIMECandidateView_composingBackgroundColor: mColorComposingBackground = a.getColor(attr, ContextCompat.getColor(context, R.color.composing_background_light)); break; case R.styleable.LIMECandidateView_candidateNormalTextColor: mColorNormalText = a.getColor(attr, ContextCompat.getColor(context, R.color.foreground_light)); break; case R.styleable.LIMECandidateView_candidateNormalTextHighlightColor: mColorNormalTextHighlight = a.getColor(attr, ContextCompat.getColor(context, R.color.foreground_light)); break; case R.styleable.LIMECandidateView_composingCodeColor: mColorComposingCode = a.getColor(attr, ContextCompat.getColor(context, R.color.color_common_green_hl)); break; case R.styleable.LIMECandidateView_composingCodeHighlightColor: mColorComposingCodeHighlight = a.getColor(attr, ContextCompat.getColor(context, R.color.third_background_light)); break; case R.styleable.LIMECandidateView_spacerColor: mColorSpacer = a.getColor(attr, ContextCompat.getColor(context, R.color.candidate_spacer)); break; case R.styleable.LIMECandidateView_selKeyColor: mColorSelKey = a.getColor(attr, ContextCompat.getColor(context, R.color.candidate_selection_keys)); break; case R.styleable.LIMECandidateView_selKeyShiftedColor: mColorSelKeyShifted = a.getColor(attr, ContextCompat.getColor(context, R.color.color_common_green_hl)); break; } } a.recycle(); final Resources r = context.getResources(); Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Point screenSize = new Point(); display.getSize(screenSize); mScreenWidth = screenSize.x; mScreenHeight = screenSize.y; mVerticalPadding = (int) (r.getDimensionPixelSize(R.dimen.candidate_vertical_padding) * mLIMEPref.getFontSize()); configHeight = (int) (r.getDimensionPixelSize(R.dimen.candidate_stripe_height) * mLIMEPref.getFontSize()); mHeight = configHeight + mVerticalPadding; mExpandButtonWidth = r.getDimensionPixelSize(R.dimen.candidate_expand_button_width);// *mLIMEPref.getFontSize()); mCandidatePaint = new Paint(); mCandidatePaint.setColor(mColorNormalText); mCandidatePaint.setAntiAlias(true); mCandidatePaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_size) * mLIMEPref.getFontSize()); mCandidatePaint.setStrokeWidth(0); mSelKeyPaint = new Paint(); mSelKeyPaint.setColor(mColorSelKey); mSelKeyPaint.setAntiAlias(true); mSelKeyPaint .setTextSize(r.getDimensionPixelSize(R.dimen.candidate_number_font_size) * mLIMEPref.getFontSize()); mSelKeyPaint.setStyle(Paint.Style.FILL_AND_STROKE); //final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); //Jeremy '12,4,23 add mContext parameter. The constructor without context is deprecated mGestureDetector = new GestureDetector(mContext, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (DEBUG) Log.i(TAG, "onScroll(): distanceX = " + distanceX + "; distanceY = " + distanceY); //Jeremy '12,4,8 filter out small scroll which is actually candidate selection. if (Math.abs(distanceX) < mHeight / 5 && Math.abs(distanceY) < mHeight / 5) return true; mScrolled = true; // Update full candidate list before scroll checkHasMoreRecords(); int sx = getScrollX(); sx += distanceX; if (sx < 0) { sx = 0; } if (sx + getWidth() > mTotalWidth) { sx -= distanceX; } if (mLIMEPref.getParameterBoolean("candidate_switch", false)) { hasSlide = true; mTargetScrollX = sx; scrollTo(sx, getScrollY()); currentX = getScrollX(); //Jeremy '12,7,6 set currentX to the left edge of current scrollview after scrolled } else { hasSlide = false; if (distanceX < 0) { goLeft = true; goRight = false; } else if (distanceX > 0) { goLeft = false; goRight = true; } else { mTargetScrollX = sx; } } return true; } }); }