mirror of
https://github.com/gsantner/dandelion
synced 2025-09-10 18:59:42 +02:00
Update opoc
This commit is contained in:
parent
3ec8ab89c6
commit
a618da97d8
12 changed files with 701 additions and 39 deletions
|
@ -17,8 +17,11 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.TypedArray;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.CalendarContract;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -47,6 +50,12 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
|
|||
_activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void freeContextRef() {
|
||||
super.freeContextRef();
|
||||
_activity = null;
|
||||
}
|
||||
|
||||
//########################
|
||||
//## Methods
|
||||
//########################
|
||||
|
@ -85,9 +94,11 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
|
|||
}
|
||||
|
||||
|
||||
public void showSnackBar(@StringRes int stringResId, boolean showLong) {
|
||||
Snackbar.make(_activity.findViewById(android.R.id.content), stringResId,
|
||||
showLong ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT).show();
|
||||
public Snackbar showSnackBar(@StringRes int stringResId, boolean showLong) {
|
||||
Snackbar s = Snackbar.make(_activity.findViewById(android.R.id.content), stringResId,
|
||||
showLong ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT);
|
||||
s.show();
|
||||
return s;
|
||||
}
|
||||
|
||||
public void showSnackBar(@StringRes int stringResId, boolean showLong, @StringRes int actionResId, View.OnClickListener listener) {
|
||||
|
@ -97,18 +108,58 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
|
|||
.show();
|
||||
}
|
||||
|
||||
public void hideSoftKeyboard() {
|
||||
InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (imm != null && _activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) {
|
||||
imm.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(), 0);
|
||||
public ActivityUtils setSoftKeyboardVisibile(boolean visible, View... editView) {
|
||||
final Activity activity = _activity;
|
||||
if (activity != null) {
|
||||
final View v = (editView != null && editView.length > 0) ? (editView[0]) : (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null ? activity.getCurrentFocus() : null);
|
||||
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (v != null && imm != null) {
|
||||
Runnable r = () -> {
|
||||
if (visible) {
|
||||
v.requestFocus();
|
||||
imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);
|
||||
} else {
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
}
|
||||
};
|
||||
r.run();
|
||||
for (int d : new int[]{100, 350}) {
|
||||
v.postDelayed(r, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void showSoftKeyboard() {
|
||||
InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (imm != null && _activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) {
|
||||
imm.showSoftInput(_activity.getCurrentFocus(), InputMethodManager.SHOW_FORCED);
|
||||
public ActivityUtils hideSoftKeyboard() {
|
||||
if (_activity != null) {
|
||||
InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (imm != null && _activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) {
|
||||
imm.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActivityUtils showSoftKeyboard() {
|
||||
if (_activity != null) {
|
||||
InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (imm != null && _activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) {
|
||||
showSoftKeyboard(_activity.getCurrentFocus());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ActivityUtils showSoftKeyboard(View textInputView) {
|
||||
if (_activity != null) {
|
||||
InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (imm != null && textInputView != null) {
|
||||
imm.showSoftInput(textInputView, InputMethodManager.SHOW_FORCED);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void showDialogWithHtmlTextView(@StringRes int resTitleId, String html) {
|
||||
|
@ -142,7 +193,7 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
|
|||
}
|
||||
|
||||
// Toggle with no param, else set visibility according to first bool
|
||||
public void toggleStatusbarVisibility(boolean... optionalForceVisible) {
|
||||
public ActivityUtils toggleStatusbarVisibility(boolean... optionalForceVisible) {
|
||||
WindowManager.LayoutParams attrs = _activity.getWindow().getAttributes();
|
||||
int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||
if (optionalForceVisible.length == 0) {
|
||||
|
@ -153,9 +204,10 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
|
|||
attrs.flags |= flag;
|
||||
}
|
||||
_activity.getWindow().setAttributes(attrs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void showGooglePlayEntryForThisApp() {
|
||||
public ActivityUtils showGooglePlayEntryForThisApp() {
|
||||
String pkgId = "details?id=" + _activity.getPackageName();
|
||||
Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + pkgId));
|
||||
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
|
||||
|
@ -167,9 +219,10 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
|
|||
_activity.startActivity(new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse("https://play.google.com/store/apps/" + pkgId)));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setStatusbarColor(int color, boolean... fromRes) {
|
||||
public ActivityUtils setStatusbarColor(int color, boolean... fromRes) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (fromRes != null && fromRes.length > 0 && fromRes[0]) {
|
||||
color = ContextCompat.getColor(_context, color);
|
||||
|
@ -177,13 +230,55 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
|
|||
|
||||
_activity.getWindow().setStatusBarColor(color);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setLauncherActivityEnabled(Class activityClass, boolean enable) {
|
||||
public ActivityUtils setLauncherActivityEnabled(Class activityClass, boolean enable) {
|
||||
Context context = _context.getApplicationContext();
|
||||
PackageManager pkg = context.getPackageManager();
|
||||
ComponentName component = new ComponentName(context, activityClass);
|
||||
pkg.setComponentEnabledSetting(component, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||
, PackageManager.DONT_KILL_APP);
|
||||
pkg.setComponentEnabledSetting(component, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ColorInt
|
||||
public Integer getCurrentPrimaryColor() {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
_context.getTheme().resolveAttribute(getResId(ResType.ATTR, "colorPrimary"), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public Integer getCurrentPrimaryDarkColor() {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
_context.getTheme().resolveAttribute(getResId(ResType.ATTR, "colorPrimaryDark"), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public Integer getCurrentAccentColor() {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
_context.getTheme().resolveAttribute(getResId(ResType.ATTR, "colorAccent"), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public Integer getActivityBackgroundColor() {
|
||||
TypedArray array = _activity.getTheme().obtainStyledAttributes(new int[]{
|
||||
android.R.attr.colorBackground,
|
||||
});
|
||||
int c = array.getColor(0, 0xFF0000);
|
||||
array.recycle();
|
||||
return c;
|
||||
}
|
||||
|
||||
public ActivityUtils startCalendarApp() {
|
||||
Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
|
||||
builder.appendPath("time");
|
||||
builder.appendPath(Long.toString(System.currentTimeMillis()));
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
|
||||
_activity.startActivity(intent);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue