Example usage for android.app Activity getResources

List of usage examples for android.app Activity getResources

Introduction

In this page you can find the example usage for android.app Activity getResources.

Prototype

@Override
    public Resources getResources() 

Source Link

Usage

From source file:org.xbmc.kore.utils.UIUtils.java

/**
 * Fills the standard cast info list, consisting of a {@link android.widget.GridLayout}
 * with actor images and a Textview with the name and the role of the additional cast.
 * The number of actor presented on the {@link android.widget.GridLayout} is controlled
 * through the global setting, and only actors with images are presented.
 * The rest are presented in the additionalCastView TextView
 *
 * @param activity Activity//from w  w w  .  j av a2s.  c om
 * @param castList Cast list
 * @param castListView GridLayout on which too show actors that have images
 */
public static void setupCastInfo(final Activity activity, List<VideoType.Cast> castList,
        GridLayout castListView, final Intent allCastActivityLaunchIntent) {
    HostManager hostManager = HostManager.getInstance(activity);
    Resources resources = activity.getResources();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(displayMetrics);

    View.OnClickListener castListClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openImdbForPerson(activity, (String) v.getTag());
        }
    };

    castListView.removeAllViews();
    int numColumns = castListView.getColumnCount();
    int numRows = resources.getInteger(R.integer.cast_grid_view_rows);
    int maxCastPictures = numColumns * numRows;

    int layoutMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.remote_content_hmargin);
    int imageMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.image_grid_margin);
    int imageWidth = (displayMetrics.widthPixels - layoutMarginPx - numColumns * imageMarginPx) / numColumns;
    int imageHeight = (int) (imageWidth * 1.5);

    for (int i = 0; i < Math.min(castList.size(), maxCastPictures); i++) {
        VideoType.Cast actor = castList.get(i);

        View castView = LayoutInflater.from(activity).inflate(R.layout.grid_item_cast, castListView, false);
        ImageView castPicture = (ImageView) castView.findViewById(R.id.picture);
        TextView castName = (TextView) castView.findViewById(R.id.name);
        TextView castRole = (TextView) castView.findViewById(R.id.role);

        castView.getLayoutParams().width = imageWidth;
        castView.getLayoutParams().height = imageHeight;
        castView.setTag(actor.name);

        UIUtils.loadImageWithCharacterAvatar(activity, hostManager, actor.thumbnail, actor.name, castPicture,
                imageWidth, imageHeight);

        if ((i == maxCastPictures - 1) && (castList.size() > i + 1)) {
            View castNameGroup = castView.findViewById(R.id.cast_name_group);
            View allCastGroup = castView.findViewById(R.id.all_cast_group);
            TextView remainingCastCount = (TextView) castView.findViewById(R.id.remaining_cast_count);

            castNameGroup.setVisibility(View.GONE);
            allCastGroup.setVisibility(View.VISIBLE);
            remainingCastCount.setText(String.format(activity.getString(R.string.remaining_cast_count),
                    castList.size() - maxCastPictures + 1));
            castView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.startActivity(allCastActivityLaunchIntent);
                    activity.overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
                }
            });
        } else {
            castName.setText(actor.name);
            castRole.setText(actor.role);
            castView.setOnClickListener(castListClickListener);
        }

        castListView.addView(castView);
    }
}

From source file:com.cw.litenote.util.video.UtilVideo.java

static BitmapDrawable getBitmapDrawableByPath(Activity mAct, String picPathStr) {
    String path = Uri.parse(picPathStr).getPath();
    Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(path,
            MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(mAct.getResources(), bmThumbnail);
    return bitmapDrawable;
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Sad workaround./* w w  w . j a v  a  2  s .c o m*/
 * 
 * See http://stackoverflow.com/a/7350315/1159164
 * 
 * @param input
 *            the EditText to set the error to
 * @param errorID
 *            the ID of the error in <tt>strings.xml</tt>
 * @param activity
 *            the enclosing activity
 */
private static void setError(EditText input, int errorID, Activity activity) {
    String errorMsg = activity.getResources().getString(errorID);
    if (Build.VERSION.SDK_INT < 11) {
        ForegroundColorSpan fgcspan = new ForegroundColorSpan(Color.BLACK);
        SpannableStringBuilder ssbuilder = new SpannableStringBuilder(errorMsg);
        ssbuilder.setSpan(fgcspan, 0, errorMsg.length(), 0);
        input.setError(ssbuilder);
    } else {
        input.setError(errorMsg);
    }
}

From source file:com.stockita.stockitapointofsales.utilities.Utility.java

/**
 * This method to will set the color of the statusbar to
 *//*w  w  w.  j  a v  a 2 s.c  o m*/
public static void changeTheStatusbarColor(Activity activity, int colorResource) {
    /**
     * Change the color of the status bar
     */
    Window window = activity.getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    if (Build.VERSION.SDK_INT >= 23) {
        window.setStatusBarColor(ContextCompat.getColor(activity, colorResource));
    } else {
        window.setStatusBarColor(activity.getResources().getColor(colorResource));
    }
}

From source file:fi.tuukka.weather.utils.Utils.java

public static void showImage(Activity activity, View view, Bitmap bmp) {
    final Dialog imageDialog = new Dialog(activity);
    imageDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    imageDialog.setContentView(R.layout.showimage);
    imageDialog.setCancelable(true);/*w  w w  .j a  va  2 s.c om*/

    ImageView imageView = (ImageView) imageDialog.findViewById(R.id.imageView);
    // Getting width & height of the given image.
    DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
    int wn = displayMetrics.widthPixels;
    int hn = displayMetrics.heightPixels;
    int wo = bmp.getWidth();
    int ho = bmp.getHeight();
    Matrix mtx = new Matrix();
    // Setting rotate to 90
    mtx.preRotate(90);
    // Setting resize
    mtx.postScale(((float) 1.3 * wn) / ho, ((float) 1.3 * hn) / wo);
    // Rotating Bitmap
    Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, wo, ho, mtx, true);
    BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);

    imageView.setImageDrawable(bmd);

    imageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View button) {
            imageDialog.dismiss();
        }
    });

    imageDialog.show();
}

From source file:Main.java

@SuppressLint("NewApi")
public static int getNBarHeight(@NonNull Activity activity) {
    //        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    //            DisplayMetrics metrics = new DisplayMetrics();
    //            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    //            int usableHeight = metrics.heightPixels;
    //            activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
    //            int realHeight = metrics.heightPixels;
    //            if (realHeight > usableHeight)
    //                return realHeight - usableHeight;
    //            else
    //                return 0;
    //        }//from  w w  w  .  j  a  v a 2  s  .c  om
    //        return 0;
    Resources resources = activity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}

From source file:com.android.purenexussettings.TinkerActivity.java

public static void lockCurrentOrientation(Activity activity) {
    int currentRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int orientation = activity.getResources().getConfiguration().orientation;
    int frozenRotation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    switch (currentRotation) {
    case Surface.ROTATION_0:
        frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
                ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        break;//from   w w  w  .  j  a v a2s.com
    case Surface.ROTATION_90:
        frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
                : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        break;
    case Surface.ROTATION_180:
        frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
                : ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
        break;
    case Surface.ROTATION_270:
        frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
                ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        break;
    }
    activity.setRequestedOrientation(frozenRotation);
}

From source file:com.github.fi3te.iliasdownloader.controller.Util.java

public static void openFile(File file, Activity forMessages) {
    if (file != null && forMessages != null && file.isFile()) {
        String extension = FilenameUtils.getExtension(file.getPath());
        if (extension.length() > 0) {
            try {
                extension = extension.toLowerCase();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(file),
                        MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                forMessages.startActivity(intent);
            } catch (ActivityNotFoundException anfe) {
                Toast.makeText(forMessages, forMessages.getResources().getString(R.string.unknown_type),
                        Toast.LENGTH_SHORT).show();
            }/* ww w .  ja  v a2 s  . co m*/
        }
    }
}

From source file:com.example.volunteerhandbook.MainActivity.java

public static String getCitizenId(Activity mAty) {
    String fileName = MainActivity.getFileHeader() + mAty.getResources().getString(R.string.login_page);
    SharedPreferences sharedPref = mAty.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    return sharedPref.getString(MainActivity.CITIZEN_ID, "--");
}

From source file:com.dunrite.xpaper.utility.Utils.java

/**
 * Gets device name and returns string for the intro activity
 *
 * @return finished sentence saying the recognized device
 *///from  w  w w. ja v a2 s .  co  m
public static String getDeviceNameString(Activity a) {
    String name = Build.MODEL;
    String s = "It looks like you have a ";
    String model; //String to provide color fragment

    //getting arrays of each model and it's associated model numbers
    String[] pure = a.getResources().getStringArray(R.array.pure_model_number_array);
    String[] style = a.getResources().getStringArray(R.array.style_model_number_array);
    String[] play = a.getResources().getStringArray(R.array.play_model_number_array);
    String[] force = a.getResources().getStringArray(R.array.force_model_number_array);
    String[] x13 = a.getResources().getStringArray(R.array.x13_model_number_array);
    String[] x14 = a.getResources().getStringArray(R.array.x14_model_number_array);
    Log.d("Model Number", name);

    if (Arrays.asList(pure).contains(name)) {
        model = "PURE";
        s = s.concat("Moto X Pure Edition");
    } else if (Arrays.asList(style).contains(name)) {
        model = "STYLE";
        s = s.concat("Moto X Style");
    } else if (Arrays.asList(play).contains(name)) {
        model = "PLAY";
        s = s.concat("Moto X Play");
    } else if (Arrays.asList(force).contains(name)) {
        model = "FORCE";
        s = s.concat("Moto X Force");
    } else if (Arrays.asList(x13).contains(name)) {
        model = "2013";
        s = s.concat("Moto X 2013");
    } else if (Arrays.asList(x14).contains(name)) {
        model = "2014";
        s = s.concat("Moto X 2014");
    } else {
        model = "PURE";
        s = "It looks like you don't have a Moto X. That is OK";
    }

    saveDeviceConfig(a, stringToModel(model), "model", "MODEL");
    s = s.concat(".\nContinue to configure your colors.\n\n");
    Log.d("Device Name", model);
    return s;
}