Skip to content

Commit

Permalink
Fix MediaPlayer and Keyboard issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenoid committed Apr 4, 2017
1 parent 07e1f2b commit c6e3a7b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 01 09:10:34 IRST 2016
#Tue Apr 04 10:33:05 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6 changes: 3 additions & 3 deletions utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "1.0.4"
version = "1.0.8"
group = "com.mirhoseini.utils"

def siteUrl = "http://mirhoseini.com/android-utils"
Expand All @@ -16,8 +16,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 5
versionName "1.0.4"
versionCode 9
versionName "1.0.8"
}
buildTypes {
release {
Expand Down
35 changes: 26 additions & 9 deletions utils/src/main/java/com/mirhoseini/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.os.Build;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.text.Spannable;
import android.text.SpannableString;
Expand Down Expand Up @@ -438,13 +439,25 @@ public static void changeLanguage(Context context, String language_code) {
res.updateConfiguration(conf, dm);
}

/**
* Show keyboard of a View
*
* @param context Application context
* @param view Edit text or another view that you want hide the keyboard
*/
public static void showKeyboard(Context context, @NonNull View view) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}


/**
* Hide keyboard of a View
*
* @param context Application context
* @param view Edit text or another view that you want hide the keyboard
*/
public static void hideKeyboard(Context context, View view) {
public static void hideKeyboard(Context context, @NonNull View view) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
Expand All @@ -456,7 +469,8 @@ public static void hideKeyboard(Context context, View view) {
*/
public static void hideKeyboard(Activity activity) {
View view = activity.getCurrentFocus();
hideKeyboard(activity, view);
if (null != view)
hideKeyboard(activity, view);
}

/**
Expand Down Expand Up @@ -523,6 +537,12 @@ public static int getDisplayHeight(Context context) {
*/
public static void playSound(Context context, int rawID) {
MediaPlayer mp = MediaPlayer.create(context, rawID);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}

Expand Down Expand Up @@ -919,7 +939,7 @@ public static boolean checkReadSMSPermission(Context context) {
* Checking if a string number or not
*
* @param value string value
* @return
* @return is Number
*/
public static boolean isNumber(String value) {
try {
Expand All @@ -933,8 +953,8 @@ public static boolean isNumber(String value) {
/**
* Getting all installed packages
*
* @param context
* @return
* @param context Application context
* @return all installed applications list
*/
public static List<PackageInfo> getAllInstalledApplication(Context context) {
final PackageManager pm = context.getPackageManager();
Expand All @@ -949,12 +969,9 @@ public static String getFrontPackageName(Context ctx) {

ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);

String str = "";
List<ActivityManager.RunningAppProcessInfo> processes = activityManager.getRunningAppProcesses();

str = processes.get(0).processName;

return str;
return processes.get(0).processName;
}

public static boolean isMyServiceRunning(Context ctx, String serviceClassName) {
Expand Down

0 comments on commit c6e3a7b

Please sign in to comment.