List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:com.google.android.apps.muzei.datalayer.ActivateMuzeiIntentService.java
public static void maybeShowActivateMuzeiNotification(Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (preferences.getBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, false)) { return;/*w w w. ja v a 2 s .c o m*/ } NotificationManager notificationManager = (NotificationManager) context .getSystemService(NOTIFICATION_SERVICE); StatusBarNotification[] notifications = notificationManager.getActiveNotifications(); boolean hasInstallNotification = false; boolean hasActivateNotification = false; for (StatusBarNotification notification : notifications) { if (notification.getId() == INSTALL_NOTIFICATION_ID) { hasInstallNotification = true; } else if (notification.getId() == ACTIVATE_NOTIFICATION_ID) { hasActivateNotification = true; } } NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_stat_muzei) .setColor(ContextCompat.getColor(context, R.color.notification)) .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_VIBRATE) .setAutoCancel(true).setContentTitle(context.getString(R.string.activate_title)); Intent deleteIntent = new Intent(context, ActivateMuzeiIntentService.class); deleteIntent.setAction(ACTION_MARK_NOTIFICATION_READ); builder.setDeleteIntent(PendingIntent.getService(context, 0, deleteIntent, 0)); // Check if the Muzei main app is installed GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).build(); ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS); Set<Node> nodes = new TreeSet<>(); if (connectionResult.isSuccess()) { nodes = Wearable.CapabilityApi .getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_ALL).await() .getCapability().getNodes(); googleApiClient.disconnect(); } if (nodes.isEmpty()) { if (hasInstallNotification) { // No need to repost the notification return; } // Send an install Muzei notification if (PlayStoreAvailability.getPlayStoreAvailabilityOnPhone( context) != PlayStoreAvailability.PLAY_STORE_ON_PHONE_AVAILABLE) { builder.setContentText(context.getString(R.string.activate_no_play_store)); FirebaseAnalytics.getInstance(context).logEvent("activate_notif_no_play_store", null); } else { builder.setContentText(context.getString(R.string.activate_install_muzei)); Intent installMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class); installMuzeiIntent.setAction(ACTION_REMOTE_INSTALL_MUZEI); PendingIntent pendingIntent = PendingIntent.getService(context, 0, installMuzeiIntent, 0); builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_install_action), pendingIntent) .extend(new NotificationCompat.Action.WearableExtender() .setHintDisplayActionInline(true).setAvailableOffline(false)) .build()); builder.extend(new NotificationCompat.WearableExtender().setContentAction(0)); FirebaseAnalytics.getInstance(context).logEvent("activate_notif_play_store", null); } notificationManager.notify(INSTALL_NOTIFICATION_ID, builder.build()); return; } // else, Muzei is installed on the phone/tablet, but not activated if (hasInstallNotification) { // Clear any install Muzei notification notificationManager.cancel(INSTALL_NOTIFICATION_ID); } if (hasActivateNotification) { // No need to repost the notification return; } String nodeName = nodes.iterator().next().getDisplayName(); builder.setContentText(context.getString(R.string.activate_enable_muzei, nodeName)); Intent launchMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class); PendingIntent pendingIntent = PendingIntent.getService(context, 0, launchMuzeiIntent, 0); builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_action, nodeName), pendingIntent) .extend(new NotificationCompat.Action.WearableExtender().setHintDisplayActionInline(true) .setAvailableOffline(false)) .build()); Bitmap background = null; try { background = BitmapFactory.decodeStream(context.getAssets().open("starrynight.jpg")); } catch (IOException e) { Log.e(TAG, "Error reading default background asset", e); } builder.extend(new NotificationCompat.WearableExtender().setContentAction(0).setBackground(background)); FirebaseAnalytics.getInstance(context).logEvent("activate_notif_installed", null); notificationManager.notify(ACTIVATE_NOTIFICATION_ID, builder.build()); }
From source file:io.teak.sdk.NotificationBuilder.java
public static Notification createNativeNotification(final Context context, Bundle bundle, TeakNotification teakNotificaton) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Rich text message Spanned richMessageText = Html.fromHtml(teakNotificaton.message); // Configure notification behavior builder.setPriority(NotificationCompat.PRIORITY_MAX); builder.setDefaults(NotificationCompat.DEFAULT_ALL); builder.setOnlyAlertOnce(true);// www . j a va 2 s . c o m builder.setAutoCancel(true); builder.setTicker(richMessageText); // Set small view image try { PackageManager pm = context.getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); builder.setSmallIcon(ai.icon); } catch (Exception e) { Log.e(LOG_TAG, "Unable to load icon resource for Notification."); return null; } Random rng = new Random(); // Create intent to fire if/when notification is cleared Intent pushClearedIntent = new Intent( context.getPackageName() + TeakNotification.TEAK_NOTIFICATION_CLEARED_INTENT_ACTION_SUFFIX); pushClearedIntent.putExtras(bundle); PendingIntent pushClearedPendingIntent = PendingIntent.getBroadcast(context, rng.nextInt(), pushClearedIntent, PendingIntent.FLAG_ONE_SHOT); builder.setDeleteIntent(pushClearedPendingIntent); // Create intent to fire if/when notification is opened, attach bundle info Intent pushOpenedIntent = new Intent( context.getPackageName() + TeakNotification.TEAK_NOTIFICATION_OPENED_INTENT_ACTION_SUFFIX); pushOpenedIntent.putExtras(bundle); PendingIntent pushOpenedPendingIntent = PendingIntent.getBroadcast(context, rng.nextInt(), pushOpenedIntent, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(pushOpenedPendingIntent); // Because we can't be certain that the R class will line up with what is at SDK build time // like in the case of Unity et. al. class IdHelper { public int id(String identifier) { int ret = context.getResources().getIdentifier(identifier, "id", context.getPackageName()); if (ret == 0) { throw new Resources.NotFoundException("Could not find R.id." + identifier); } return ret; } public int layout(String identifier) { int ret = context.getResources().getIdentifier(identifier, "layout", context.getPackageName()); if (ret == 0) { throw new Resources.NotFoundException("Could not find R.layout." + identifier); } return ret; } } IdHelper R = new IdHelper(); // Declaring local as 'R' ensures we don't accidentally use the other R // Configure notification small view RemoteViews smallView = new RemoteViews(context.getPackageName(), Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? R.layout("teak_notif_no_title_v21") : R.layout("teak_notif_no_title")); // Set small view image try { PackageManager pm = context.getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); smallView.setImageViewResource(R.id("left_image"), ai.icon); builder.setSmallIcon(ai.icon); } catch (Exception e) { Log.e(LOG_TAG, "Unable to load icon resource for Notification."); return null; } // Set small view text smallView.setTextViewText(R.id("text"), richMessageText); // Check for Jellybean (API 16, 4.1)+ for expanded view RemoteViews bigView = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && teakNotificaton.longText != null && !teakNotificaton.longText.isEmpty()) { bigView = new RemoteViews(context.getPackageName(), Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? R.layout("teak_big_notif_image_text_v21") : R.layout("teak_big_notif_image_text")); // Set big view text bigView.setTextViewText(R.id("text"), Html.fromHtml(teakNotificaton.longText)); URI imageAssetA = null; try { imageAssetA = new URI(teakNotificaton.imageAssetA); } catch (Exception ignored) { } Bitmap topImageBitmap = null; if (imageAssetA != null) { try { URL aURL = new URL(imageAssetA.toString()); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); topImageBitmap = BitmapFactory.decodeStream(bis); bis.close(); is.close(); } catch (Exception ignored) { } } if (topImageBitmap == null) { try { InputStream istr = context.getAssets().open("teak_notif_large_image_default.png"); topImageBitmap = BitmapFactory.decodeStream(istr); } catch (Exception ignored) { } } if (topImageBitmap != null) { // Set large bitmap bigView.setImageViewBitmap(R.id("top_image"), topImageBitmap); } else { Log.e(LOG_TAG, "Unable to load image asset for Notification."); // Hide pulldown smallView.setViewVisibility(R.id("pulldown_layout"), View.INVISIBLE); } } else { // Hide pulldown smallView.setViewVisibility(R.id("pulldown_layout"), View.INVISIBLE); } // Voodoo from http://stackoverflow.com/questions/28169474/notification-background-in-android-lollipop-is-white-can-we-change-it int topId = Resources.getSystem().getIdentifier("status_bar_latest_event_content", "id", "android"); int topBigLayout = Resources.getSystem().getIdentifier("notification_template_material_big_media_narrow", "layout", "android"); int topSmallLayout = Resources.getSystem().getIdentifier("notification_template_material_media", "layout", "android"); RemoteViews topBigView = null; if (bigView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // This is invisible inner view - to have media_actions in hierarchy RemoteViews innerTopView = new RemoteViews("android", topBigLayout); bigView.addView(android.R.id.empty, innerTopView); // This should be on top - we need status_bar_latest_event_content as top layout topBigView = new RemoteViews("android", topBigLayout); topBigView.removeAllViews(topId); topBigView.addView(topId, bigView); } else if (bigView != null) { topBigView = bigView; } // This should be on top - we need status_bar_latest_event_content as top layout RemoteViews topSmallView; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { topSmallView = new RemoteViews("android", topSmallLayout); topSmallView.removeAllViews(topId); topSmallView.addView(topId, smallView); } else { topSmallView = smallView; } builder.setContent(topSmallView); Notification n = builder.build(); if (topBigView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // Use reflection to avoid compile-time issues, we check minimum API version above try { Field bigContentViewField = n.getClass().getField("bigContentView"); bigContentViewField.set(n, topBigView); } catch (Exception ignored) { } } return n; }
From source file:com.appeaser.sublimenavigationviewlibrary.SublimeNavigationView.java
public SublimeNavigationView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SublimeNavigationView, defStyleAttr, R.style.SnvSublimeNavigationView); try {/*from w w w . java 2 s. c o m*/ // Used for creating default resources SublimeThemer.DefaultTheme defaultTheme = SublimeThemer.DefaultTheme.LIGHT; if (a.hasValue(R.styleable.SublimeNavigationView_snvDefaultTheme)) { defaultTheme = a.getInt(R.styleable.SublimeNavigationView_snvDefaultTheme, 0) == 0 ? SublimeThemer.DefaultTheme.LIGHT : SublimeThemer.DefaultTheme.DARK; } mThemer = new SublimeThemer(getContext(), defaultTheme); mThemer.setDrawerBackground(a.getDrawable(R.styleable.SublimeNavigationView_android_background)); if (a.hasValue(R.styleable.SublimeNavigationView_elevation)) { mThemer.setElevation( (float) a.getDimensionPixelSize(R.styleable.SublimeNavigationView_elevation, 0)); } ViewCompat.setFitsSystemWindows(this, a.getBoolean(R.styleable.SublimeNavigationView_android_fitsSystemWindows, false)); mMaxWidth = a.getDimensionPixelSize(R.styleable.SublimeNavigationView_android_maxWidth, 0); if (a.hasValue(R.styleable.SublimeNavigationView_snvItemIconTint)) { mThemer.setIconTintList(a.getColorStateList(R.styleable.SublimeNavigationView_snvItemIconTint)); } mThemer.setGroupExpandDrawable(a.getDrawable(R.styleable.SublimeNavigationView_snvGroupExpandDrawable)); mThemer.setGroupCollapseDrawable( a.getDrawable(R.styleable.SublimeNavigationView_snvGroupCollapseDrawable)); // Text style profiles for Item, Hint, SubheaderItem & SubheaderHint ColorStateList itemTextColor = null, hintTextColor = null, subheaderItemTextColor = null, subheaderHintTextColor = null, badgeTextColor = null; Typeface itemTypeface = null, hintTypeface = null, subheaderItemTypeface = null, subheaderHintTypeface = null, badgeTypeface = null; int itemTypefaceStyle = 0, hintTypefaceStyle = 0, subheaderItemTypefaceStyle = 0, subheaderHintTypefaceStyle = 0, badgeTypefaceStyle = 0; if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTextColor)) { itemTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvItemTextColor); } if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTextColor)) { hintTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvHintTextColor); } if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTextColor)) { subheaderItemTextColor = a .getColorStateList(R.styleable.SublimeNavigationView_snvSubheaderItemTextColor); } if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTextColor)) { subheaderHintTextColor = a .getColorStateList(R.styleable.SublimeNavigationView_snvSubheaderHintTextColor); } if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTextColor)) { badgeTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvBadgeTextColor); } try { // Catch the RuntimeException thrown if // the Typeface filename is incorrect if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTypefaceFilename)) { String itemTypefaceFilename = a .getString(R.styleable.SublimeNavigationView_snvItemTypefaceFilename); if (!TextUtils.isEmpty(itemTypefaceFilename)) { itemTypeface = Typeface.createFromAsset(context.getAssets(), itemTypefaceFilename); } } if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTypefaceFilename)) { String hintTypefaceFilename = a .getString(R.styleable.SublimeNavigationView_snvHintTypefaceFilename); if (!TextUtils.isEmpty(hintTypefaceFilename)) { hintTypeface = Typeface.createFromAsset(context.getAssets(), hintTypefaceFilename); } } if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceFilename)) { String subheaderItemTypefaceFilename = a .getString(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceFilename); if (!TextUtils.isEmpty(subheaderItemTypefaceFilename)) { subheaderItemTypeface = Typeface.createFromAsset(context.getAssets(), subheaderItemTypefaceFilename); } } if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceFilename)) { String subheaderHintTypefaceFilename = a .getString(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceFilename); if (!TextUtils.isEmpty(subheaderHintTypefaceFilename)) { subheaderHintTypeface = Typeface.createFromAsset(context.getAssets(), subheaderHintTypefaceFilename); } } if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTypefaceFilename)) { String badgeTypefaceFilename = a .getString(R.styleable.SublimeNavigationView_snvBadgeTypefaceFilename); if (!TextUtils.isEmpty(badgeTypefaceFilename)) { badgeTypeface = Typeface.createFromAsset(context.getAssets(), badgeTypefaceFilename); } } } catch (RuntimeException re) { Log.e(TAG, "Error loading Typeface from Assets. " + "Confirm that the Typeface filename is correct:\n" + " - filename should include the extension\n" + " - filename is case-sensitive"); } if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTypefaceStyle)) { itemTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvItemTypefaceStyle, Typeface.NORMAL); switch (itemTypefaceStyle) { case 1: itemTypefaceStyle = Typeface.BOLD; break; case 2: itemTypefaceStyle = Typeface.ITALIC; break; case 3: itemTypefaceStyle = Typeface.BOLD_ITALIC; break; default: // case 0: NORMAL itemTypefaceStyle = Typeface.NORMAL; break; } } if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTypefaceStyle)) { hintTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvHintTypefaceStyle, Typeface.NORMAL); switch (hintTypefaceStyle) { case 1: hintTypefaceStyle = Typeface.BOLD; break; case 2: hintTypefaceStyle = Typeface.ITALIC; break; case 3: hintTypefaceStyle = Typeface.BOLD_ITALIC; break; default: // case 0: NORMAL hintTypefaceStyle = Typeface.NORMAL; break; } } if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceStyle)) { subheaderItemTypefaceStyle = a .getInt(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceStyle, Typeface.NORMAL); switch (subheaderItemTypefaceStyle) { case 1: subheaderItemTypefaceStyle = Typeface.BOLD; break; case 2: subheaderItemTypefaceStyle = Typeface.ITALIC; break; case 3: subheaderItemTypefaceStyle = Typeface.BOLD_ITALIC; break; default: // case 0: NORMAL subheaderItemTypefaceStyle = Typeface.NORMAL; break; } } if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceStyle)) { subheaderHintTypefaceStyle = a .getInt(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceStyle, Typeface.NORMAL); switch (subheaderHintTypefaceStyle) { case 1: subheaderHintTypefaceStyle = Typeface.BOLD; break; case 2: subheaderHintTypefaceStyle = Typeface.ITALIC; break; case 3: subheaderHintTypefaceStyle = Typeface.BOLD_ITALIC; break; default: // case 0: NORMAL subheaderHintTypefaceStyle = Typeface.NORMAL; break; } } if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTypefaceStyle)) { badgeTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvBadgeTypefaceStyle, Typeface.NORMAL); switch (badgeTypefaceStyle) { case 1: badgeTypefaceStyle = Typeface.BOLD; break; case 2: badgeTypefaceStyle = Typeface.ITALIC; break; case 3: badgeTypefaceStyle = Typeface.BOLD_ITALIC; break; default: // case 0: NORMAL badgeTypefaceStyle = Typeface.NORMAL; break; } } // Item text styling TextViewStyleProfile itemStyleProfile = new TextViewStyleProfile(context, defaultTheme); itemStyleProfile.setTextColor(itemTextColor).setTypeface(itemTypeface) .setTypefaceStyle(itemTypefaceStyle); mThemer.setItemStyleProfile(itemStyleProfile); // Hint text styling TextViewStyleProfile hintStyleProfile = new TextViewStyleProfile(context, defaultTheme); hintStyleProfile.setTextColor(hintTextColor).setTypeface(hintTypeface) .setTypefaceStyle(hintTypefaceStyle); mThemer.setItemHintStyleProfile(hintStyleProfile); // Sub-header item text styling TextViewStyleProfile subheaderItemStyleProfile = new TextViewStyleProfile(context, defaultTheme); subheaderItemStyleProfile.setTextColor(subheaderItemTextColor).setTypeface(subheaderItemTypeface) .setTypefaceStyle(subheaderItemTypefaceStyle); mThemer.setSubheaderStyleProfile(subheaderItemStyleProfile); // Sub-header hint text styling TextViewStyleProfile subheaderHintStyleProfile = new TextViewStyleProfile(context, defaultTheme); subheaderHintStyleProfile.setTextColor(subheaderHintTextColor).setTypeface(subheaderHintTypeface) .setTypefaceStyle(subheaderHintTypefaceStyle); mThemer.setSubheaderHintStyleProfile(subheaderHintStyleProfile); // Badge text styling TextViewStyleProfile badgeStyleProfile = new TextViewStyleProfile(context, defaultTheme); badgeStyleProfile.setTextColor(badgeTextColor).setTypeface(badgeTypeface) .setTypefaceStyle(badgeTypefaceStyle); mThemer.setBadgeStyleProfile(badgeStyleProfile); mThemer.setItemBackground(a.getDrawable(R.styleable.SublimeNavigationView_snvItemBackground)); if (a.hasValue(R.styleable.SublimeNavigationView_snvMenu)) { int menuResId = a.getResourceId(R.styleable.SublimeNavigationView_snvMenu, -1); if (menuResId == -1) { throw new RuntimeException("Passed menuResId was not valid"); } mMenu = new SublimeMenu(menuResId); inflateMenu(menuResId); } mMenu.setCallback(new SublimeMenu.Callback() { public boolean onMenuItemSelected(SublimeMenu menu, SublimeBaseMenuItem item, OnNavigationMenuEventListener.Event event) { return SublimeNavigationView.this.mEventListener != null && SublimeNavigationView.this.mEventListener.onNavigationMenuEvent(event, item); } }); mPresenter = new SublimeMenuPresenter(); applyThemer(); mMenu.setMenuPresenter(getContext(), mPresenter); addView(mPresenter.getMenuView(this)); if (a.hasValue(R.styleable.SublimeNavigationView_snvHeaderLayout)) { inflateHeaderView(a.getResourceId(R.styleable.SublimeNavigationView_snvHeaderLayout, 0)); } } finally { a.recycle(); } // Upon creation, and until initializations are done, // SublimeMenuPresenter blocks all calls for invalidation. // We can now finalize the initialization phase to allow // invalidation of the menu when required. mPresenter.setInitializationDone(); }
From source file:org.akop.crosswords.view.CrosswordView.java
public CrosswordView(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode()) { setLayerType(View.LAYER_TYPE_HARDWARE, null); }//from www . j a va 2s . c o m // Set drawing defaults Resources r = context.getResources(); DisplayMetrics dm = r.getDisplayMetrics(); int cellFillColor = NORMAL_CELL_FILL_COLOR; int cheatedCellFillColor = CHEATED_CELL_FILL_COLOR; int mistakeCellFillColor = MISTAKE_CELL_FILL_COLOR; int selectedWordFillColor = SELECTED_WORD_FILL_COLOR; int selectedCellFillColor = SELECTED_CELL_FILL_COLOR; int textColor = TEXT_COLOR; int cellStrokeColor = CELL_STROKE_COLOR; int circleStrokeColor = CIRCLE_STROKE_COLOR; float numberTextSize = NUMBER_TEXT_SIZE * dm.scaledDensity; float answerTextSize = ANSWER_TEXT_SIZE * dm.scaledDensity; mCellSize = CELL_SIZE * dm.density; mNumberTextPadding = NUMBER_TEXT_PADDING * dm.density; mAnswerTextPadding = ANSWER_TEXT_PADDING * dm.density; // Read supplied attributes if (attrs != null) { Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.Crossword, 0, 0); mCellSize = a.getDimension(R.styleable.Crossword_cellSize, mCellSize); mNumberTextPadding = a.getDimension(R.styleable.Crossword_numberTextPadding, mNumberTextPadding); numberTextSize = a.getDimension(R.styleable.Crossword_numberTextSize, numberTextSize); mAnswerTextPadding = a.getDimension(R.styleable.Crossword_answerTextPadding, mAnswerTextPadding); answerTextSize = a.getDimension(R.styleable.Crossword_answerTextSize, answerTextSize); cellFillColor = a.getColor(R.styleable.Crossword_defaultCellFillColor, cellFillColor); cheatedCellFillColor = a.getColor(R.styleable.Crossword_cheatedCellFillColor, cheatedCellFillColor); mistakeCellFillColor = a.getColor(R.styleable.Crossword_mistakeCellFillColor, mistakeCellFillColor); selectedWordFillColor = a.getColor(R.styleable.Crossword_selectedWordFillColor, selectedWordFillColor); selectedCellFillColor = a.getColor(R.styleable.Crossword_selectedCellFillColor, selectedCellFillColor); cellStrokeColor = a.getColor(R.styleable.Crossword_cellStrokeColor, cellStrokeColor); circleStrokeColor = a.getColor(R.styleable.Crossword_circleStrokeColor, circleStrokeColor); textColor = a.getColor(R.styleable.Crossword_textColor, textColor); a.recycle(); } mMarkerSideLength = mCellSize * MARKER_TRIANGLE_LENGTH_FRACTION; // Init paints mCellFillPaint = new Paint(); mCellFillPaint.setColor(cellFillColor); mCellFillPaint.setStyle(Paint.Style.FILL); mCheatedCellFillPaint = new Paint(); mCheatedCellFillPaint.setColor(cheatedCellFillColor); mCheatedCellFillPaint.setStyle(Paint.Style.FILL); mMistakeCellFillPaint = new Paint(); mMistakeCellFillPaint.setColor(mistakeCellFillColor); mMistakeCellFillPaint.setStyle(Paint.Style.FILL); mSelectedWordFillPaint = new Paint(); mSelectedWordFillPaint.setColor(selectedWordFillColor); mSelectedWordFillPaint.setStyle(Paint.Style.FILL); mSelectedCellFillPaint = new Paint(); mSelectedCellFillPaint.setColor(selectedCellFillColor); mSelectedCellFillPaint.setStyle(Paint.Style.FILL); mCellStrokePaint = new Paint(); mCellStrokePaint.setColor(cellStrokeColor); mCellStrokePaint.setStyle(Paint.Style.STROKE); // mCellStrokePaint.setStrokeWidth(1); mCircleStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCircleStrokePaint.setColor(circleStrokeColor); mCircleStrokePaint.setStyle(Paint.Style.STROKE); mCircleStrokePaint.setStrokeWidth(1); mNumberTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberTextPaint.setColor(textColor); mNumberTextPaint.setTextAlign(Paint.Align.CENTER); mNumberTextPaint.setTextSize(numberTextSize); mNumberStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberStrokePaint.setColor(cellFillColor); mNumberStrokePaint.setTextAlign(Paint.Align.CENTER); mNumberStrokePaint.setTextSize(numberTextSize); mNumberStrokePaint.setStyle(Paint.Style.STROKE); mNumberStrokePaint.setStrokeWidth(NUMBER_TEXT_STROKE_WIDTH * dm.scaledDensity); mAnswerTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mAnswerTextPaint.setColor(textColor); mAnswerTextPaint.setTextSize(answerTextSize); mAnswerTextPaint.setTextAlign(Paint.Align.CENTER); // http://www.google.com/fonts/specimen/Kalam Typeface typeface = Typeface.createFromAsset(context.getAssets(), "kalam-regular.ttf"); mAnswerTextPaint.setTypeface(typeface); // Init rest of the values mCircleRadius = (mCellSize / 2) - mCircleStrokePaint.getStrokeWidth(); mPuzzleCells = EMPTY_CELLS; mPuzzleWidth = 0; mPuzzleHeight = 0; mAllowedChars = EMPTY_CHARS; mRenderScale = 0; mBitmapOffset = new PointF(); mCenteredOffset = new PointF(); mTranslationBounds = new RectF(); mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); mGestureDetector = new GestureDetector(context, new GestureListener()); mContentRect = new RectF(); mPuzzleRect = new RectF(); mBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG); mScroller = new Scroller(context, null, true); mZoomer = new Zoomer(context); setFocusableInTouchMode(true); setOnKeyListener(this); }