Skip to content

Commit

Permalink
增加工具类
Browse files Browse the repository at this point in the history
增加 TipsView;
增加输入法支持
  • Loading branch information
litesuits committed Jun 9, 2015
1 parent 43f608f commit 09a6557
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 3 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.litesuits.common"
android:versionCode="1"
android:versionName="1.0.0">
android:versionCode="110"
android:versionName="1.1.0">
<uses-sdk android:minSdkVersion="1"/>

<uses-permission android:name="android.permission.INTERNET"/>
Expand Down
137 changes: 137 additions & 0 deletions src/com/litesuits/android/view/TipsView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.litesuits.android.view;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

/**
* @author MaTianyu
* @date 2014-08-15
*/
public class TipsView extends LinearLayout {
protected View realView;
protected ViewGroup parentView;

protected Context context;
protected boolean isThisInLayout = false;

public TipsView(Context context) {
this(context, (AttributeSet) null);
}

public TipsView(Context context, AttributeSet attrs) {
this(context, attrs, 0, null, null);
}

public TipsView(Context context, AttributeSet attrs, int defStyle) {
this(context, attrs, defStyle, null, null);
}

public TipsView(Context context, View realView, View tipView) {
this(context, null, 0, realView, tipView);
}

public TipsView(Context context, View realView) {
this(context, null, 0, realView, null);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public TipsView(Context context, AttributeSet attrs, int defStyle, View realView, View tipView) {
super(context, attrs, defStyle);
this.context = context;
initSelf();
setRealView(realView);
setTipView(tipView);
}

public void initSelf() {
setOrientation(HORIZONTAL);
setGravity(Gravity.CENTER);
}

public TipsView setTipView(View tipView) {
if (tipView != null) {
removeAllViews();
addView(tipView);
}
return this;
}

public TipsView setTipView(int resID) {
removeAllViews();
LayoutInflater.from(context).inflate(resID, this, true);
return this;
}


public View getRealView() {
return realView;
}


public TipsView setRealView(View realView) {
if (realView != null) {
this.realView = realView;
parentView = (ViewGroup) realView.getParent();
setLayoutParams(realView.getLayoutParams());
}
return this;
}


public void showRealView() {
if (realView != null) {
if (isThisInLayout) {
for (int i = 0, size = parentView.getChildCount(); i < size; i++) {
if (parentView.getChildAt(i) == this) {
parentView.removeView(this);
//realView.setId(getId());
//setId(0);
parentView.addView(realView, i);
isThisInLayout = false;
break;
}
}
}
} else {
this.setVisibility(GONE);
}
}

public void showTipsView() {
if (realView != null) {
if (!isThisInLayout) {
for (int i = 0, size = parentView.getChildCount(); i < size; i++) {
if (parentView.getChildAt(i) == realView) {
parentView.removeView(realView);
//setId(realView.getId());
//realView.setId(0);
parentView.addView(this, i);
isThisInLayout = true;
break;
}
}
}
} else {
this.setVisibility(VISIBLE);
}
}

public void gone() {
setVisibility(GONE);
}

public void visible() {
setVisibility(VISIBLE);
}

public void inVisible() {
setVisibility(INVISIBLE);
}
}
28 changes: 27 additions & 1 deletion src/com/litesuits/common/assist/Toastor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ public Toast getSingletonToast(String text) {
return mToast;
}

public Toast getSingleLongToast(int resId) {
if (mToast == null) {
mToast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
}else{
mToast.setText(resId);
}
return mToast;
}

public Toast getSingleLongToast(String text) {
if (mToast == null) {
mToast = Toast.makeText(context, text, Toast.LENGTH_LONG);
}else{
mToast.setText(text);
}
return mToast;
}

public Toast getToast(int resId) {
return Toast.makeText(context, resId, Toast.LENGTH_SHORT);
}
Expand All @@ -50,7 +68,6 @@ public Toast getLongToast(String text) {
return Toast.makeText(context, text, Toast.LENGTH_LONG);
}


public void showSingletonToast(int resId) {
getSingletonToast(resId).show();
}
Expand All @@ -60,6 +77,15 @@ public void showSingletonToast(String text) {
getSingletonToast(text).show();
}

public void showSingleLongToast(int resId) {
getSingleLongToast(resId).show();
}


public void showSingleLongToast(String text) {
getSingleLongToast(text).show();
}

public void showToast(int resId) {
getToast(resId).show();
}
Expand Down
55 changes: 55 additions & 0 deletions src/com/litesuits/common/utils/InputMethodUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.litesuits.common.utils;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
* @author MaTianyu(http://litesuits.com) on 2015-06-01
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public class InputMethodUtils {

public static void toggleSoftInput(Context context) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}

public static boolean showSoftInput(View view) {
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
return imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}

public static boolean showSoftInput(Activity activity) {
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
return imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
return false;
}

public static boolean hideSoftInput(View view) {
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

public static boolean hideSoftInput(Activity activity) {
if (activity.getCurrentFocus() != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
return imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
return false;
}

public static boolean isActive(Context context) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
return imm.isActive();
}


}
8 changes: 8 additions & 0 deletions src/com/litesuits/common/utils/SdCardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
public class SdCardUtil {
private static final String TAG = SdCardUtil.class.getSimpleName();

/**
* is sd card available.
* @return true if available
*/
public boolean isSdCardAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

/**
* Get {@link android.os.StatFs}.
*/
Expand Down

0 comments on commit 09a6557

Please sign in to comment.