Search in sources :

Example 81 with Resources

use of android.content.res.Resources in project android-betterpickers by code-troopers.

the class HmsPicker method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    View v1 = findViewById(R.id.first);
    View v2 = findViewById(R.id.second);
    View v3 = findViewById(R.id.third);
    View v4 = findViewById(R.id.fourth);
    mEnteredHms = (HmsView) findViewById(R.id.hms_text);
    mDelete = (ImageButton) findViewById(R.id.delete);
    mDelete.setOnClickListener(this);
    mDelete.setOnLongClickListener(this);
    mNumbers[1] = (Button) v1.findViewById(R.id.key_left);
    mNumbers[2] = (Button) v1.findViewById(R.id.key_middle);
    mNumbers[3] = (Button) v1.findViewById(R.id.key_right);
    mNumbers[4] = (Button) v2.findViewById(R.id.key_left);
    mNumbers[5] = (Button) v2.findViewById(R.id.key_middle);
    mNumbers[6] = (Button) v2.findViewById(R.id.key_right);
    mNumbers[7] = (Button) v3.findViewById(R.id.key_left);
    mNumbers[8] = (Button) v3.findViewById(R.id.key_middle);
    mNumbers[9] = (Button) v3.findViewById(R.id.key_right);
    mLeft = (Button) v4.findViewById(R.id.key_left);
    mNumbers[0] = (Button) v4.findViewById(R.id.key_middle);
    mRight = (Button) v4.findViewById(R.id.key_right);
    setRightEnabled(false);
    for (int i = 0; i < 10; i++) {
        mNumbers[i].setOnClickListener(this);
        mNumbers[i].setText(String.format("%d", i));
        mNumbers[i].setTag(R.id.numbers_key, new Integer(i));
    }
    updateHms();
    Resources res = mContext.getResources();
    mLeft.setText(res.getString(R.string.number_picker_plus_minus));
    mLeft.setOnClickListener(this);
    mHoursLabel = (TextView) findViewById(R.id.hours_label);
    mMinutesLabel = (TextView) findViewById(R.id.minutes_label);
    mSecondsLabel = (TextView) findViewById(R.id.seconds_label);
    mDivider = findViewById(R.id.divider);
    restyleViews();
    updateKeypad();
}
Also used : Resources(android.content.res.Resources) TextView(android.widget.TextView) View(android.view.View)

Example 82 with Resources

use of android.content.res.Resources in project phonegap-plugin-push by phonegap.

the class GCMIntentService method createNotification.

public void createNotification(Context context, Bundle extras) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);
    String packageName = context.getPackageName();
    Resources resources = context.getResources();
    int notId = parseInt(NOT_ID, extras);
    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra(PUSH_BUNDLE, extras);
    notificationIntent.putExtra(NOT_ID, notId);
    int requestCode = new Random().nextInt();
    PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent dismissedNotificationIntent = new Intent(notificationIntent);
    dismissedNotificationIntent.putExtra(DISMISSED, true);
    requestCode = new Random().nextInt();
    PendingIntent deleteIntent = PendingIntent.getActivity(this, requestCode, dismissedNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()).setContentTitle(fromHtml(extras.getString(TITLE))).setTicker(fromHtml(extras.getString(TITLE))).setContentIntent(contentIntent).setDeleteIntent(deleteIntent).setAutoCancel(true);
    SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
    String localIcon = prefs.getString(ICON, null);
    String localIconColor = prefs.getString(ICON_COLOR, null);
    boolean soundOption = prefs.getBoolean(SOUND, true);
    boolean vibrateOption = prefs.getBoolean(VIBRATE, true);
    Log.d(LOG_TAG, "stored icon=" + localIcon);
    Log.d(LOG_TAG, "stored iconColor=" + localIconColor);
    Log.d(LOG_TAG, "stored sound=" + soundOption);
    Log.d(LOG_TAG, "stored vibrate=" + vibrateOption);
    /*
         * Notification Vibration
         */
    setNotificationVibration(extras, vibrateOption, mBuilder);
    /*
         * Notification Icon Color
         *
         * Sets the small-icon background color of the notification.
         * To use, add the `iconColor` key to plugin android options
         *
         */
    setNotificationIconColor(extras.getString("color"), mBuilder, localIconColor);
    /*
         * Notification Icon
         *
         * Sets the small-icon of the notification.
         *
         * - checks the plugin options for `icon` key
         * - if none, uses the application icon
         *
         * The icon value must be a string that maps to a drawable resource.
         * If no resource is found, falls
         *
         */
    setNotificationSmallIcon(context, extras, packageName, resources, mBuilder, localIcon);
    /*
         * Notification Large-Icon
         *
         * Sets the large-icon of the notification
         *
         * - checks the gcm data for the `image` key
         * - checks to see if remote image, loads it.
         * - checks to see if assets image, Loads It.
         * - checks to see if resource image, LOADS IT!
         * - if none, we don't set the large icon
         *
         */
    setNotificationLargeIcon(extras, packageName, resources, mBuilder);
    /*
         * Notification Sound
         */
    if (soundOption) {
        setNotificationSound(context, extras, mBuilder);
    }
    /*
         *  LED Notification
         */
    setNotificationLedColor(extras, mBuilder);
    /*
         *  Priority Notification
         */
    setNotificationPriority(extras, mBuilder);
    /*
         * Notification message
         */
    setNotificationMessage(notId, extras, mBuilder);
    /*
         * Notification count
         */
    setNotificationCount(context, extras, mBuilder);
    /*
         * Notification count
         */
    setVisibility(context, extras, mBuilder);
    /*
         * Notification add actions
         */
    createActions(extras, mBuilder, resources, packageName, notId);
    mNotificationManager.notify(appName, notId, mBuilder.build());
}
Also used : NotificationManager(android.app.NotificationManager) Random(java.util.Random) SharedPreferences(android.content.SharedPreferences) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 83 with Resources

use of android.content.res.Resources in project plaid by nickbutcher.

the class PlayerActivity method bindPlayer.

void bindPlayer() {
    if (player == null)
        return;
    final Resources res = getResources();
    final NumberFormat nf = NumberFormat.getInstance();
    Glide.with(this).load(player.getHighQualityAvatarUrl()).placeholder(R.drawable.avatar_placeholder).transform(circleTransform).into(avatar);
    playerName.setText(player.name.toLowerCase());
    if (!TextUtils.isEmpty(player.bio)) {
        DribbbleUtils.parseAndSetText(bio, player.bio);
    } else {
        bio.setVisibility(View.GONE);
    }
    shotCount.setText(res.getQuantityString(R.plurals.shots, player.shots_count, nf.format(player.shots_count)));
    if (player.shots_count == 0) {
        shotCount.setCompoundDrawablesRelativeWithIntrinsicBounds(null, getDrawable(R.drawable.avd_no_shots), null, null);
    }
    setFollowerCount(player.followers_count);
    likesCount.setText(res.getQuantityString(R.plurals.likes, player.likes_count, nf.format(player.likes_count)));
    // load the users shots
    dataManager = new PlayerShotsDataManager(this, player) {

        @Override
        public void onDataLoaded(List<Shot> data) {
            if (data != null && data.size() > 0) {
                if (adapter.getDataItemCount() == 0) {
                    loading.setVisibility(View.GONE);
                    ViewUtils.setPaddingTop(shots, likesCount.getBottom());
                }
                adapter.addAndResort(data);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    shots.setAdapter(adapter);
    shots.setItemAnimator(new SlideInItemAnimator());
    shots.setVisibility(View.VISIBLE);
    layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    shots.setLayoutManager(layoutManager);
    shots.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadData();
        }
    });
    shots.setHasFixedSize(true);
    // forward on any clicks above the first item in the grid (i.e. in the paddingTop)
    // to 'pass through' to the view behind
    shots.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int firstVisible = layoutManager.findFirstVisibleItemPosition();
            if (firstVisible > 0)
                return false;
            // if no data loaded then pass through
            if (adapter.getDataItemCount() == 0) {
                return container.dispatchTouchEvent(event);
            }
            final RecyclerView.ViewHolder vh = shots.findViewHolderForAdapterPosition(0);
            if (vh == null)
                return false;
            final int firstTop = vh.itemView.getTop();
            if (event.getY() < firstTop) {
                return container.dispatchTouchEvent(event);
            }
            return false;
        }
    });
    // check if following
    if (dataManager.getDribbblePrefs().isLoggedIn()) {
        if (player.id == dataManager.getDribbblePrefs().getUserId()) {
            TransitionManager.beginDelayedTransition(container);
            follow.setVisibility(View.GONE);
            ViewUtils.setPaddingTop(shots, container.getHeight() - follow.getHeight() - ((ViewGroup.MarginLayoutParams) follow.getLayoutParams()).bottomMargin);
        } else {
            final Call<Void> followingCall = dataManager.getDribbbleApi().following(player.id);
            followingCall.enqueue(new Callback<Void>() {

                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                    following = response.isSuccessful();
                    if (!following)
                        return;
                    TransitionManager.beginDelayedTransition(container);
                    follow.setText(R.string.following);
                    follow.setActivated(true);
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                }
            });
        }
    }
    if (player.shots_count > 0) {
        // kick off initial load
        dataManager.loadData();
    } else {
        loading.setVisibility(View.GONE);
    }
}
Also used : PlayerShotsDataManager(io.plaidapp.data.api.dribbble.PlayerShotsDataManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) Resources(android.content.res.Resources) Shot(io.plaidapp.data.api.dribbble.model.Shot) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) NumberFormat(java.text.NumberFormat)

Example 84 with Resources

use of android.content.res.Resources in project superCleanMaster by joyoyao.

the class AppUtil method getDisplayMetrics.

/**
     * 获取屏幕尺寸与密度.
     *
     * @param context the context
     * @return mDisplayMetrics
     */
public static DisplayMetrics getDisplayMetrics(Context context) {
    Resources mResources;
    if (context == null) {
        mResources = Resources.getSystem();
    } else {
        mResources = context.getResources();
    }
    // DisplayMetrics{density=1.5, width=480, height=854, scaledDensity=1.5,
    // xdpi=160.421, ydpi=159.497}
    // DisplayMetrics{density=2.0, width=720, height=1280,
    // scaledDensity=2.0, xdpi=160.42105, ydpi=160.15764}
    DisplayMetrics mDisplayMetrics = mResources.getDisplayMetrics();
    return mDisplayMetrics;
}
Also used : Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 85 with Resources

use of android.content.res.Resources in project XobotOS by xamarin.

the class ScriptC method internalCreate.

private static synchronized int internalCreate(RenderScript rs, Resources resources, int resourceID) {
    byte[] pgm;
    int pgmLength;
    InputStream is = resources.openRawResource(resourceID);
    try {
        try {
            pgm = new byte[1024];
            pgmLength = 0;
            while (true) {
                int bytesLeft = pgm.length - pgmLength;
                if (bytesLeft == 0) {
                    byte[] buf2 = new byte[pgm.length * 2];
                    System.arraycopy(pgm, 0, buf2, 0, pgm.length);
                    pgm = buf2;
                    bytesLeft = pgm.length - pgmLength;
                }
                int bytesRead = is.read(pgm, pgmLength, bytesLeft);
                if (bytesRead <= 0) {
                    break;
                }
                pgmLength += bytesRead;
            }
        } finally {
            is.close();
        }
    } catch (IOException e) {
        throw new Resources.NotFoundException();
    }
    // E.g, /system/apps/Fountain.apk
    //String packageName = rs.getApplicationContext().getPackageResourcePath();
    // For res/raw/fountain.bc, it wil be /com.android.fountain:raw/fountain
    String resName = resources.getResourceEntryName(resourceID);
    String cacheDir = rs.getApplicationContext().getCacheDir().toString();
    Log.v(TAG, "Create script for resource = " + resName);
    return rs.nScriptCCreate(resName, cacheDir, pgm, pgmLength);
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Resources(android.content.res.Resources)

Aggregations

Resources (android.content.res.Resources)3268 Context (android.content.Context)304 Intent (android.content.Intent)286 View (android.view.View)239 TextView (android.widget.TextView)217 PackageManager (android.content.pm.PackageManager)216 IOException (java.io.IOException)212 Drawable (android.graphics.drawable.Drawable)199 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)179 Paint (android.graphics.Paint)179 DisplayMetrics (android.util.DisplayMetrics)175 Bitmap (android.graphics.Bitmap)174 Configuration (android.content.res.Configuration)154 Point (android.graphics.Point)153 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)139 ArrayList (java.util.ArrayList)137 XmlResourceParser (android.content.res.XmlResourceParser)133 TypedArray (android.content.res.TypedArray)132 Test (org.junit.Test)127 PendingIntent (android.app.PendingIntent)123