Java Code Examples for android.view.View.setOnFocusChangeListener()

The following are Jave code examples for showing how to use setOnFocusChangeListener() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: weex-3d-map   File: WXComponent.java   Source Code and License Vote up 7 votes
protected final void addFocusChangeListener(OnFocusChangeListener l){
  View view;
  if(l != null && (view = getRealView()) != null) {
    if( mFocusChangeListeners == null){
      mFocusChangeListeners = new ArrayList<>();
      view.setFocusable(true);
      view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
          for (OnFocusChangeListener listener : mFocusChangeListeners){
            if(listener != null){
              listener.onFocusChange(hasFocus);
            }
          }
        }
      });
    }
    mFocusChangeListeners.add(l);
  }
}
 
Example 2
Project: ucar-weex-core   File: WXComponent.java   Source Code and License Vote up 6 votes
protected final void addFocusChangeListener(OnFocusChangeListener l){
  View view;
  if(l != null && (view = getRealView()) != null) {
    if( mFocusChangeListeners == null){
      mFocusChangeListeners = new ArrayList<>();
      view.setFocusable(true);
      view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
          for (OnFocusChangeListener listener : mFocusChangeListeners){
            if(listener != null){
              listener.onFocusChange(hasFocus);
            }
          }
        }
      });
    }
    mFocusChangeListeners.add(l);
  }
}
 
Example 3
Project: weex-uikit   File: WXComponent.java   Source Code and License Vote up 6 votes
protected final void addFocusChangeListener(OnFocusChangeListener l){
  View view;
  if(l != null && (view = getRealView()) != null) {
    if( mFocusChangeListeners == null){
      mFocusChangeListeners = new ArrayList<>();
      view.setFocusable(true);
      view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
          for (OnFocusChangeListener listener : mFocusChangeListeners){
            if(listener != null){
              listener.onFocusChange(hasFocus);
            }
          }
        }
      });
    }
    mFocusChangeListeners.add(l);
  }
}
 
Example 4
Project: LaunchEnr   File: Workspace.java   Source Code and License Vote up 5 votes
public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks,
        String description) {
    if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) {
        throw new RuntimeException("Expected custom content screen to exist");
    }

    // Add the custom content to the full screen custom page
    CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID);
    int spanX = customScreen.getCountX();
    int spanY = customScreen.getCountY();
    CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);
    lp.canReorder  = false;
    lp.isFullscreen = true;
    if (customContent instanceof Insettable) {
        ((Insettable)customContent).setInsets(mInsets);
    }

    // Verify that the child is removed from any existing parent.
    if (customContent.getParent() instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) customContent.getParent();
        parent.removeView(customContent);
    }
    customScreen.removeAllViews();
    customContent.setFocusable(true);
    customContent.setOnKeyListener(new FullscreenKeyEventListener());
    customContent.setOnFocusChangeListener(mLauncher.mFocusHandler
            .getHideIndicatorOnFocusListener());
    customScreen.addViewToCellLayout(customContent, 0, 0, lp, true);
    mCustomContentDescription = description;

    mCustomContentCallbacks = callbacks;
}
 
Example 5
Project: mongol-library   File: MongolInputMethodManager.java   Source Code and License Vote up 5 votes
public void addEditor(View editor) {

        // editor must be MongolEditText or EditText
        if (!(editor instanceof EditText) && !(editor instanceof MongolEditText)) {
            throw new RuntimeException("MongolInputMethodManager " +
                    "only supports adding a MongolEditText or EditText " +
                    "at this time. You added: " + editor);
        }

        if (mRegisteredEditors == null) {
            mRegisteredEditors = new ArrayList<>();
        }

        // don't add the same view twice
        for (View view : mRegisteredEditors) {
            if (view == editor) return;
        }

        // give the editor's input connection to the keyboard when editor is focused
        editor.setOnFocusChangeListener(focusListener);
        // TODO if hiding the keyboard on back button then may need to add a touch listener to edit texts too

        // get extra updates from MongolEditText
        // TODO is there any way for us to get these updates from EditText?
        if (editor instanceof MongolEditText) {
            ((MongolEditText) editor).setOnMongolEditTextUpdateListener(mongolEditTextListener);
        }

        // TODO set allow system keyboard to show if hasn't been set

        // add editor
        mRegisteredEditors.add(editor);
        mCurrentEditor = editor;
    }
 
Example 6
Project: FlickLauncher   File: Workspace.java   Source Code and License Vote up 5 votes
public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks,
        String description) {
    if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) {
        throw new RuntimeException("Expected custom content screen to exist");
    }

    // Add the custom content to the full screen custom page
    CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID);
    int spanX = customScreen.getCountX();
    int spanY = customScreen.getCountY();
    CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);
    lp.canReorder  = false;
    lp.isFullscreen = true;
    if (customContent instanceof Insettable) {
        ((Insettable)customContent).setInsets(mInsets);
    }

    // Verify that the child is removed from any existing parent.
    if (customContent.getParent() instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) customContent.getParent();
        parent.removeView(customContent);
    }
    customScreen.removeAllViews();
    customContent.setFocusable(true);
    customContent.setOnKeyListener(new FullscreenKeyEventListener());
    customContent.setOnFocusChangeListener(mLauncher.mFocusHandler
            .getHideIndicatorOnFocusListener());
    customScreen.addViewToCellLayout(customContent, 0, 0, lp, true);
    mCustomContentDescription = description;

    mCustomContentCallbacks = callbacks;
}
 
Example 7
Project: SimpleUILauncher   File: Workspace.java   Source Code and License Vote up 5 votes
public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks,
        String description) {
    if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) {
        throw new RuntimeException("Expected custom content screen to exist");
    }

    // Add the custom content to the full screen custom page
    CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID);
    int spanX = customScreen.getCountX();
    int spanY = customScreen.getCountY();
    CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);
    lp.canReorder  = false;
    lp.isFullscreen = true;
    if (customContent instanceof Insettable) {
        ((Insettable)customContent).setInsets(mInsets);
    }

    // Verify that the child is removed from any existing parent.
    if (customContent.getParent() instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) customContent.getParent();
        parent.removeView(customContent);
    }
    customScreen.removeAllViews();
    customContent.setFocusable(true);
    customContent.setOnKeyListener(new FullscreenKeyEventListener());
    customContent.setOnFocusChangeListener(mLauncher.mFocusHandler
            .getHideIndicatorOnFocusListener());
    customScreen.addViewToCellLayout(customContent, 0, 0, lp, true);
    mCustomContentDescription = description;

    mCustomContentCallbacks = callbacks;
}
 
Example 8
Project: pius1   File: MaterialDialog.java   Source Code and License Vote up 4 votes
public void setView(View view)
{
           LinearLayout l = (LinearLayout) mAlertDialogWindow.findViewById(R.id.contentView);
           l.removeAllViews();
           ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
	ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
           view.setLayoutParams(layoutParams);

           view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
	    @Override public void onFocusChange(View v, boolean hasFocus)
	    {
		mAlertDialogWindow.setSoftInputMode(
                           WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
		// show imm
		InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
                           Context.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
				    InputMethodManager.HIDE_IMPLICIT_ONLY);
	    }
	});

           l.addView(view);

           if (view instanceof ViewGroup)
    {

               ViewGroup viewGroup = (ViewGroup) view;

               for (int i = 0; i < viewGroup.getChildCount(); i++)
	{
                   if (viewGroup.getChildAt(i) instanceof EditText)
	    {
                       EditText editText = (EditText) viewGroup.getChildAt(i);
                       editText.setFocusable(true);
                       editText.requestFocus();
                       editText.setFocusableInTouchMode(true);
                   }
               }
               for (int i = 0; i < viewGroup.getChildCount(); i++)
	{
                   if (viewGroup.getChildAt(i) instanceof AutoCompleteTextView)
	    {
                       AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewGroup
		    .getChildAt(i);
                       autoCompleteTextView.setFocusable(true);
                       autoCompleteTextView.requestFocus();
                       autoCompleteTextView.setFocusableInTouchMode(true);
                   }
               }
           }
       }
 
Example 9
Project: Android-Code-Demos   File: CustomPopupWindow.java   Source Code and License Vote up 4 votes
public void setOnFocusListener(int viewId, View.OnFocusChangeListener listener) {
    View view = findView(viewId);
    view.setOnFocusChangeListener(listener);
}
 
Example 10
Project: PartyBuildingStudies   File: CustomPopupWindow.java   Source Code and License Vote up 4 votes
public void setOnFocusListener(int viewId, View.OnFocusChangeListener listener) {
    View view = findView(viewId);
    view.setOnFocusChangeListener(listener);
}
 
Example 11
Project: JKApp   File: EventHelper.java   Source Code and License Vote up 4 votes
public static void focus(View.OnFocusChangeListener li, View...views) {
    if(views == null || views.length == 0) return;
    for(View v : views) v.setOnFocusChangeListener(li);
}
 
Example 12
Project: LeCatApp   File: EventHelper.java   Source Code and License Vote up 4 votes
public static void focus(View.OnFocusChangeListener li, View...views) {
    if(views == null || views.length == 0) return;
    for(View v : views) v.setOnFocusChangeListener(li);
}
 
Example 13
Project: FamilyBond   File: CustomPopupWindow.java   Source Code and License Vote up 4 votes
public void setOnFocusListener(int viewId, View.OnFocusChangeListener listener) {
    View view = findView(viewId);
    view.setOnFocusChangeListener(listener);
}