Skip to content

Instantly share code, notes, and snippets.

View farooqkhan003's full-sized avatar
🎯
Focusing

Farooq Khan farooqkhan003

🎯
Focusing
  • Lahore, Pakistan
View GitHub Profile
private void shareImage(Bitmap bitmap){
// save bitmap to cache directory
try {
File cachePath = new File(this.getCacheDir(), "images");
cachePath.mkdirs(); // don't forget to make the directory
FileOutputStream stream = new FileOutputStream(cachePath + "/image.png"); // overwrites this image every time
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
stream.close();
} catch (IOException e) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedFrame = inflater.inflate(R.layout.my_view, null);
Bitmap bitmap = loadBitmapFromView(inflatedFrame.findViewById(R.id.id_of_parent_layout));
public Bitmap createBitmapFromView(View v) {
v.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(),
v.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
<receiver
android:name=".WidgetProvider"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
package com.vd.androidwidget;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget"
android:minHeight="40dp"
android:minWidth="40dp"
android:resizeMode="horizontal"
android:updatePeriodMillis="1800000"
android:widgetCategory="home_screen|keyguard">
</appwidget-provider>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
package com.androidtechpoint.Util;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.EditText;
/**
* Created by farooq on 8/8/2017.
*/
<com.androidtechpoint.Util.SquareImage
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/you_image_name"/>
<com.vd.trainingtask2.Util.SquareImage
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/you_image_name"/>