private Bitmap mask(Bitmap image, Bitmap mask) { // todo: image wiederholen und skalierung richtig Bitmap bitmapOut = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmapOut); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); if (tileImage) { BitmapDrawable background = new BitmapDrawable(image); // in this case, you want to tile the entire view background.setBounds(0, 0, mask.getWidth(), mask.getHeight()); background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); background.draw(canvas); } else { canvas.drawBitmap(image, (int) (mask.getWidth() * 0.5 - image.getWidth() * 0.5), 0, paint); } Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG); xferPaint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawBitmap(mask, 0, 0, xferPaint); xferPaint.setXfermode(null); return bitmapOut; }
public static BitmapDrawable createCheckerBoard(Resources res, int size) { size *= res.getDisplayMetrics().density; BitmapShader shader = new BitmapShader( Bitmap.createBitmap( new int[] {0xFFFFFFFF, 0xFFCCCCCC, 0xFFCCCCCC, 0xFFFFFFFF}, 2, 2, Bitmap.Config.RGB_565), BitmapShader.TileMode.REPEAT, BitmapShader.TileMode.REPEAT); Matrix matrix = new Matrix(); matrix.setScale(size, size); shader.setLocalMatrix(matrix); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setShader(shader); Bitmap bm2 = Bitmap.createBitmap(size * 2, size * 2, Bitmap.Config.RGB_565); new Canvas(bm2).drawPaint(paint); BitmapDrawable drawable = new BitmapDrawable(res, bm2); drawable.setTileModeXY(BitmapShader.TileMode.REPEAT, BitmapShader.TileMode.REPEAT); return drawable; }
private BitmapDrawable getDrawable(Resources resources) { BitmapDrawable background = (BitmapDrawable) resources.getDrawable(drawable); background.setTileModeXY(TileMode.REPEAT, isPreview ? TileMode.MIRROR : TileMode.REPEAT); background.setFilterBitmap(true); return background; }
/** * Converts the cropped bitmap to a BitmapDrawable and returns the same. * * @param view The view for which a background drawable is required. * @return Either the cropped bitmap as a Drawable or null. */ public Drawable getDrawable(View view) { Bitmap bitmap = getCroppedBitmap(view); if (bitmap == null) { return null; } BitmapDrawable drawable = new BitmapDrawable(view.getContext().getResources(), bitmap); drawable.setGravity(Gravity.TOP | Gravity.RIGHT); drawable.setTileModeXY(Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); return drawable; }
@Override public View getView(int position, View convertView, ViewGroup parent) { View itemView; if (convertView != null) itemView = convertView; else itemView = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.art_grid_item, null); // image and image properties if (covers[position] != null) { BitmapDrawable bmD = new BitmapDrawable(covers[position]); bmD.setDither(true); bmD.setAntiAlias(true); bmD.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); ((ImageView) itemView.findViewById(R.id.art_grid_item_image)).setImageDrawable(bmD); ((TextView) itemView.findViewById(R.id.art_grid_item_res)) .setText(covers[position].getWidth() + "x" + covers[position].getHeight()); } else { ((ImageView) itemView.findViewById(R.id.art_grid_item_image)).setImageBitmap(loadingBitmap); if (position == 0) ((TextView) itemView.findViewById(R.id.art_grid_item_res)) .setText(mContext.getString(R.string.manual_albumart_resolution_unavailable)); else ((TextView) itemView.findViewById(R.id.art_grid_item_res)) .setText(mContext.getString(R.string.manual_albumart_resolution_loading)); } // art source if (position == 0) ((TextView) itemView.findViewById(R.id.art_grid_item_source)) .setText( mContext.getString(R.string.manual_albumart_source) + ": " + mContext.getString(R.string.manual_albumart_source_local)); else ((TextView) itemView.findViewById(R.id.art_grid_item_source)) .setText( mContext.getString(R.string.manual_albumart_source) + ": " + mContext.getString(R.string.manual_albumart_source_internet)); Log.i(TAG, "loading: " + position); return itemView; }
private FrameLayout initializeCroutonViewGroup(Resources resources) { FrameLayout croutonView = new FrameLayout(this.activity); if (null != onClickListener) { croutonView.setOnClickListener(onClickListener); } final int height; if (this.style.heightDimensionResId > 0) { height = resources.getDimensionPixelSize(this.style.heightDimensionResId); } else { height = this.style.heightInPixels; } final int width; if (this.style.widthDimensionResId > 0) { width = resources.getDimensionPixelSize(this.style.widthDimensionResId); } else { width = this.style.widthInPixels; } croutonView.setLayoutParams( new FrameLayout.LayoutParams( width != 0 ? width : FrameLayout.LayoutParams.MATCH_PARENT, height)); // set background if (this.style.backgroundColorValue != Style.NOT_SET) { croutonView.setBackgroundColor(this.style.backgroundColorValue); } else { croutonView.setBackgroundColor(resources.getColor(this.style.backgroundColorResourceId)); } // set the background drawable if set. This will override the background // color. if (this.style.backgroundDrawableResourceId != 0) { Bitmap background = BitmapFactory.decodeResource(resources, this.style.backgroundDrawableResourceId); BitmapDrawable drawable = new BitmapDrawable(resources, background); if (this.style.isTileEnabled) { drawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); } croutonView.setBackgroundDrawable(drawable); } return croutonView; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { setTheme(SampleList.THEME); super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent it = getIntent(); if (it != null) { Bundle params = it.getExtras(); if (params != null) { titulo = params.getString("titulo"); } } getSupportActionBar().setTitle(titulo); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable(R.drawable.bg_striped_img); bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); getSupportActionBar().setBackgroundDrawable(bg); } else { ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable(Color.rgb(51, 51, 51))); } StaggeredGridView gridView = (StaggeredGridView) this.findViewById(R.id.staggeredGridView1); int margin = getResources().getDimensionPixelSize(R.dimen.margin); gridView.setItemMargin(margin); // set the GridView margin gridView.setPadding(margin, 0, margin, 0); // have the margin on the // sides as well StaggeredAdapter adapter = new StaggeredAdapter(MainDetails.this, R.id.imageView1, urls); gridView.setOnItemClickListener(this); gridView.setAdapter(adapter); adapter.notifyDataSetChanged(); }
public Bitmap generateWidgetPreview( ComponentName provider, int previewImage, int iconId, int cellHSpan, int cellVSpan, int maxPreviewWidth, int maxPreviewHeight, Bitmap preview, int[] preScaledWidthOut) { // Load the preview image if possible String packageName = provider.getPackageName(); if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE; if (maxPreviewHeight < 0) maxPreviewHeight = Integer.MAX_VALUE; Drawable drawable = null; if (previewImage != 0) { drawable = mPackageManager.getDrawable(packageName, previewImage, null); if (drawable == null) { Log.w( TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(previewImage) + " for provider: " + provider); } } int previewWidth; int previewHeight; Bitmap defaultPreview = null; boolean widgetPreviewExists = (drawable != null); if (widgetPreviewExists) { previewWidth = drawable.getIntrinsicWidth(); previewHeight = drawable.getIntrinsicHeight(); } else { // Generate a preview image if we couldn't load one if (cellHSpan < 1) cellHSpan = 1; if (cellVSpan < 1) cellVSpan = 1; BitmapDrawable previewDrawable = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.widget_tile); final int previewDrawableWidth = previewDrawable.getIntrinsicWidth(); final int previewDrawableHeight = previewDrawable.getIntrinsicHeight(); previewWidth = previewDrawableWidth * cellHSpan; previewHeight = previewDrawableHeight * cellVSpan; defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); final Canvas c = mCachedAppWidgetPreviewCanvas.get(); c.setBitmap(defaultPreview); previewDrawable.setBounds(0, 0, previewWidth, previewHeight); previewDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); previewDrawable.draw(c); c.setBitmap(null); // Draw the icon in the top left corner int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage); int smallestSide = Math.min(previewWidth, previewHeight); float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f); try { Drawable icon = null; int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2); int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2); if (iconId > 0) icon = mIconCache.getFullResIcon(packageName, iconId); if (icon != null) { renderDrawableToBitmap( icon, defaultPreview, hoffset, yoffset, (int) (mAppIconSize * iconScale), (int) (mAppIconSize * iconScale)); } } catch (Resources.NotFoundException e) { } } // Scale to fit width only - let the widget preview be clipped in the // vertical dimension float scale = 1f; if (preScaledWidthOut != null) { preScaledWidthOut[0] = previewWidth; } if (previewWidth > maxPreviewWidth) { scale = maxPreviewWidth / (float) previewWidth; } if (scale != 1f) { previewWidth = (int) (scale * previewWidth); previewHeight = (int) (scale * previewHeight); } // If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size if (preview == null) { preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); } // Draw the scaled preview into the final bitmap int x = (preview.getWidth() - previewWidth) / 2; if (widgetPreviewExists) { renderDrawableToBitmap(drawable, preview, x, 0, previewWidth, previewHeight); } else { final Canvas c = mCachedAppWidgetPreviewCanvas.get(); final Rect src = mCachedAppWidgetPreviewSrcRect.get(); final Rect dest = mCachedAppWidgetPreviewDestRect.get(); c.setBitmap(preview); src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight()); dest.set(x, 0, x + previewWidth, previewHeight); Paint p = mCachedAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setFilterBitmap(true); mCachedAppWidgetPreviewPaint.set(p); } c.drawBitmap(defaultPreview, src, dest, p); c.setBitmap(null); } return preview; }
@SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (isP(_P.secrecy) && !ENC) { setTitle("Initializing " + Main.name + "..."); return; } Intent caller = getIntent(); if (caller != null) { try { String tmp = caller.getStringExtra(_I.Main_setAbsoluteFolder.name()); if (tmp == null) { finish(); return; } setAbsoluteFolder(tmp); tmp = caller.getStringExtra(_I.Main_setFolderShowname.name()); if (tmp == null) { finish(); return; } setFolderShowname(tmp); } catch (Exception e) { e.printStackTrace(); return; } } WatchImpl.enable = false; l1 = new RelativeLayout(this); int xi = 0; while (true) { if (!checkFiles(xi)) break; xi++; } if (xi > max) max = xi; thetexts = new Vector<InnerEdit>(max + 5); ScrollView sv = new ScrollView(this); l1.addView(sv); RelativeLayout.LayoutParams sv_lp = (RelativeLayout.LayoutParams) sv.getLayoutParams(); sv_lp.width = RelativeLayout.LayoutParams.MATCH_PARENT; sv_lp.height = RelativeLayout.LayoutParams.WRAP_CONTENT; sv_lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); sv.setLayoutParams(sv_lp); l2 = new LinearLayout(this); l2.setOrientation(LinearLayout.VERTICAL); l2.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); sv.addView(l2); ArrayList<String> vals = null; ArrayList<Integer> ids = null; int newone = -1; int focusone = -1; if (caller != null) { if (caller.getBooleanExtra("OKAY", false)) { vals = caller.getStringArrayListExtra("vals"); ids = caller.getIntegerArrayListExtra("ids"); newone = caller.getIntExtra("newone", -1); focusone = caller.getIntExtra("curfocus", -1); } } if (newone > 0) max = newone + 1; setTitle(title(max)); for (int i = 0; i < max; i++) { EditText t2 = new EditText(this); t2.setId(i); t2.setOnFocusChangeListener( new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) curfocus = (EditText) v; } }); t2.setImeOptions(EditorInfo.IME_ACTION_DONE); t2.setOnEditorActionListener(one); InnerEdit in = new InnerEdit(t2); thetexts.add(in); t2.addTextChangedListener(new WatchImpl(in)); l2.addView(t2, 0); if (ids != null && ids.contains(i)) { String tmp = vals.get(ids.indexOf(i)); if (tmp != null) t2.setText(tmp); else t2.setText("err"); in.changed = true; } else { if (checkFiles(i)) { String x = loadFiles(i); t2.setText(x); } else { t2.setText(""); } } if (focusone >= 0) { if (i == focusone) t2.requestFocus(); } else { if (i == max - 1) t2.requestFocus(); } } WatchImpl.enable = true; Button b1 = new Button(this); b1.setText(" Save "); b1.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { int ctr = 0; for (int i = 0; i < max; i++) { if (thetexts.get(i).changed || !checkFiles(i)) { storeFiles(i, thetexts.get(i).edit.getText().toString()); ctr++; thetexts.get(i).changed = false; } } Toast.makeText(me, "Saved (" + ctr + ")", Toast.LENGTH_SHORT).show(); } }); Button b2 = new Button(this); b2.setText(" Add "); b2.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { EditText t2 = new EditText(me); t2.setOnFocusChangeListener( new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) curfocus = (EditText) v; } }); t2.setImeOptions(EditorInfo.IME_ACTION_DONE); t2.setOnEditorActionListener(one); l2.addView(t2, 0); t2.setId(max); max++; InnerEdit in = new InnerEdit(t2, true); thetexts.add(in); t2.addTextChangedListener(new WatchImpl(in)); setTitle(title(max)); t2.requestFocus(); } }); Button b3 = new Button(this); b3.setText("Save & Exit"); b3.setOnClickListener( new OnClickListener() { // TODO: reduce redundancy @Override public void onClick(View v) { int ctr = 0; for (int i = 0; i < max; i++) { if (thetexts.get(i).changed || !checkFiles(i)) { storeFiles(i, thetexts.get(i).edit.getText().toString()); ctr++; thetexts.get(i).changed = false; } } if (ctr > 0) Toast.makeText(me, "Saved (" + ctr + ")", Toast.LENGTH_SHORT).show(); else Toast.makeText(me, "Quick Exit", Toast.LENGTH_SHORT).show(); finish(); } }); Button b4 = new Button(this); b4.setText("Return"); b4.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < max; i++) { if (thetexts.get(i).changed || !checkFiles(i)) { Toast.makeText(me, "unsaved data", Toast.LENGTH_SHORT).show(); return; } } startActivity(new Intent(me, Startup.class)); finish(); } }); HorizontalScrollView hori = new HorizontalScrollView(this); LinearLayout ll_hori = new LinearLayout(this); ll_hori.setOrientation(LinearLayout.HORIZONTAL); ll_hori.addView(b1); ll_hori.addView(b3); ll_hori.addView(b2); ll_hori.addView(b4); hori.addView(ll_hori); l1.addView(hori); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); hori.setLayoutParams(lp); hori.setId(121232); sv_lp = (RelativeLayout.LayoutParams) sv.getLayoutParams(); sv_lp.addRule(RelativeLayout.ABOVE, hori.getId()); sv.setLayoutParams(sv_lp); BitmapDrawable bd = new BitmapDrawable( getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.back_base)); bd.setTileModeXY(TileMode.MIRROR, TileMode.REPEAT); l1.setBackgroundDrawable(bd); setContentView(l1); }
@Override public void onCreate() { super.onCreate(); running = true; MainActivity guiCopy = gui; if (guiCopy != null) { guiCopy.updateCheckbox(); } Log.d(LOG, "Service started"); Cfg.Init(this); windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); view = new ImageView(this); DisplayMetrics metrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(metrics); bmp = Bitmap.createBitmap(Grids.GridSideSize, Grids.GridSideSize, Bitmap.Config.ARGB_4444); updatePattern(); BitmapDrawable draw = new BitmapDrawable(bmp); draw.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); draw.setFilterBitmap(false); draw.setAntiAlias(false); view.setBackground(draw); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams .TYPE_SYSTEM_OVERLAY, // WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, // //WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, // //WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, PixelFormat.TRANSPARENT); params.buttonBrightness = 0.0f; params.dimAmount = 0.0f; windowManager.addView(view, params); final Handler handler = new Handler(); handler.postDelayed( new Runnable() { @Override public void run() { updatePattern(); view.invalidate(); if (!destroyed) { handler.postDelayed(this, Grids.ShiftTimeouts[Cfg.ShiftTimeoutIdx]); } } }, Grids.ShiftTimeouts[Cfg.ShiftTimeoutIdx]); if (Cfg.UseLightSensor) { sensors = (SensorManager) getSystemService(Context.SENSOR_SERVICE); lightSensor = sensors.getDefaultSensor(Sensor.TYPE_LIGHT); if (lightSensor != null) { StartSensor.get().registerListener(sensors, this, lightSensor, 1200000, 1000000); } IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); screenOffReceiver = new ScreenOffReceiver(); registerReceiver(screenOffReceiver, filter); } try { samsungBackLightValue = android.provider.Settings.System.getInt(getContentResolver(), SAMSUNG_BACK_LIGHT_SETTING); android.provider.Settings.System.putInt(getContentResolver(), SAMSUNG_BACK_LIGHT_SETTING, 0); } catch (Exception e) { } }