This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean isServiceRunning() { | |
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); | |
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { | |
if ("net.anandsingh.services.RefreshTokenService".equals(service.service.getClassName())) { | |
return true; | |
} | |
} | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapShader; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; | |
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Bitmap getDownsampledBitmap(Context ctx, Uri uri, int targetWidth, int targetHeight) { | |
Bitmap bitmap = null; | |
try { | |
BitmapFactory.Options outDimens = getBitmapDimensions(uri); | |
int sampleSize = calculateSampleSize(ctx, outDimens.outWidth, outDimens.outHeight, targetWidth, targetHeight); | |
bitmap = downsampleBitmap(uri, sampleSize); | |
} catch (Exception e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try{ | |
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.bubble_green); | |
//replace "R.drawable.bubble_green" with the image resource you want to share from drawable | |
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | |
largeIcon.compress(Bitmap.CompressFormat.JPEG, 40, bytes); | |
// you can create a new file name "test.jpg" in sdcard folder. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); | |
shareIntent.setType("image/jpeg"); | |
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hi"); //set your subject | |
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "How are you"); //set your message | |
String imagePath = Environment.getExternalStorageDirectory() + File.separator + "test.jpg"; | |
File imageFileToShare = new File(imagePath); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Read the log through the following code: | |
public class LogTest extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
try { | |
Process process = Runtime.getRuntime().exec("logcat -d"); | |
BufferedReader bufferedReader = new BufferedReader( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'me.tatarka.retrolambda' | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'me.tatarka:gradle-retrolambda:3.2.2' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.anandsingh.expensecalculator; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import android.widget.Toast; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" | |
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> | |
<TextView | |
android:layout_width="wrap_content" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReadChars { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
String text = scanner.nextLine(); | |
for (int i = 0; i < text.length(); ) { | |
int temp = 0; |
OlderNewer