forked from litesuits/android-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加 TipsView; 增加输入法支持
- Loading branch information
Showing
5 changed files
with
229 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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); | ||
} | ||
} |
This file contains 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
This file contains 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
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(); | ||
} | ||
|
||
|
||
} |
This file contains 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