Android KeyBoardView - Detect Modifier Keys are Pressed - android-softkeyboard

I am working on Customized Keyboard, I should operate the Pc using Android Keyboard, So For that I have implemented a keyboard. there is no edit text/text view in my activity to show keyboard. I am displaying the keyboard on button clicks.
Now I am unable to Detect the Modifer keys such as Ctrl/Alt are pressed .
I have Implemented Keyboard Action listener but there is no method for handling the Combination of keys like KeyDown/KeyUp
Here is My listener , Please check suggest.
public OnKeyboardActionListener mOnKeyboardActionListener = new OnKeyboardActionListener() {
public final static int CodeDelete = -5; // Keyboard.KEYCODE_DELETE
public final static int CodeCancel = -3; // Keyboar d.KEYCODE_CANCEL
public final static int CodePrev = 55000;
public final static int CodeAllLeft = 55001;
public final static int CodeLeft = 55002;
public final static int CodeRight = 55003;
public final static int CodeAllRight = 55004;
public final static int CodeNext = 55005;
public final static int CodeClear = 55006;
#Override
public void onKey(int primaryCode, int[] keyCodes) {
isAnimate = false;
Log.e("ON KEY METHOD", "KEY CODE IS " + primaryCode);
System.out.println("primaryCodeprimaryCode====>>>>>>>>>>"
+ primaryCode);
switch (primaryCode) {
case KeyEvent.KEYCODE_A:
System.out.println("********A PRESSED ******");
break;
case KeyEvent.KEYCODE_B:
System.out.println("********B PRESSED ******");
break;
case KeyEvent.KEYCODE_CTRL_LEFT:
Log.e("Control KEY PREES IN ON KEY", "" + primaryCode);
System.out.println("********Control KEy PRESSED ******");
break;
default:
break;
}
}
#Override
public void onPress(int arg0) {
Log.e("######ON PRESSS", "KEY CODE IS" + arg0);
System.out.println("on onPress" + arg0);
}
#Override
public void onRelease(int primaryCode) {
Log.e("*****ON onRelease", "KEY CODE IS " + primaryCode);
System.out.println("on Release" + primaryCode);
}
#Override
public void onText(CharSequence text) {
Log.e("*****ON onText", "KEY CODE IS " + text);
System.out.println("on text" + text);
}
#Override
public void swipeDown() {
}
#Override
public void swipeLeft() {
}
#Override
public void swipeRight() {
}
#Override
public void swipeUp() {
}
};
This is Code for displaying Custom keyboard in activity .
mKeyboardView = (KeyboardView) findViewById(R.id.keyboardview);
mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
mKeyboardView.setKeyboard(new Keyboard(
MainActivity.this, R.xml.qwerty));
mKeyboardView.setPreviewEnabled(true);

Related

Marshmallow does not show my custom analog clock widget

I have created custom analog clock which I want to display in the widget. This analog clock is visible in Api 16+ but not visible in Marshmallow (Api 23). Marshmallow allowing to create the widget but does not display my analog clock on the home screen.
Is there any permission in marshmallow to show my custom analog widget??
This is my Widget Class
'public class Widget extends AppWidgetProvider {
private Intent mUpdateService;
#Override
public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_DISABLED)) {
mUpdateService = new Intent();}else{
if (mUpdateService == null)
mUpdateService = new Intent(context, UpdateService.class);
context.startService(mUpdateService);
}
}
public static class UpdateService extends Service {
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
private boolean isScreenOn = true;
#Override
public void onReceive(Context context, Intent intent) {
String key = intent.getAction();
if (key.equals(Intent.ACTION_SCREEN_ON)) {
isScreenOn = true;
updateWidget();
} else if (key.equals(Intent.ACTION_SCREEN_OFF)) {
isScreenOn = false;
} else if (isScreenOn) {
updateWidget();
}
}
};
public RemoteViews mRemoteViews;
public WidgetAnalogClock widgetAnalogClock;
#Override
public void onCreate() {
mRemoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_layout);
widgetAnalogClock = new WidgetAnalogClock(getApplicationContext());
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
registerReceiver(mReceiver, filter);
}
#Override
public void onDestroy() {
unregisterReceiver(mReceiver);}
#Override
public void onStart(Intent intent, int startId) {
updateWidget();}
private void updateWidget(){
WidgetAnalogClock myView=new WidgetAnalogClock(getApplicationContext());
mRemoteViews=new RemoteViews(getApplicationContext().getPackageName(),R.layout.widget_layout);
myView.measure(150, 150);
myView.layout(0, 0, 750, 750);
myView.setDrawingCacheEnabled(true);
Bitmap bitmap = myView.getDrawingCache();
mRemoteViews.setImageViewBitmap(R.id.customClock, bitmap);
AppWidgetManager.getInstName(this, Widget.class), mRemoteViews);
bitmap = myView.getDrawingCache();
mRemoteViews.setImageViewBitmap(R.id.customClock, bitmap);}
#Override
public IBinder onBind(Intent arg0) {
return null;
}
}
}`

My AndEngine app does not show options menu

I'm using AndEngine to develop a simple test application. Everything is good, but the menu options does not show up. I don't know why I don't see the options menu button (the 3-dots touch button on bottom right). Help is much appreciated.
Here is the piece of code corresponding to the MenuScene:
public class MainActivity extends SimpleBaseGameActivity implements IOnMenuItemClickListener {
private static int CAMERA_WIDTH ;
private static int CAMERA_HEIGHT;
protected static final int MENU_ADD = 0;
protected static final int MENU_QUIT = MENU_ADD + 1;
private Font mFont,menuFont;
private MenuScene mMenuScene;
Camera camera;
Scene scene;
#Override
public EngineOptions onCreateEngineOptions() {
//default code
}
#Override
public void onCreateResources() throws IOException {
//some code
}
#Override
public Scene onCreateScene() {
//some code
}
#Override
public boolean onMenuItemClicked(final MenuScene pMenuScene, final IMenuItem pMenuItem, final float pMenuItemLocalX, final float pMenuItemLocalY) {
switch(pMenuItem.getID()) {
case MENU_ADD:
/* Restart the animation. */
Log.i("hello", "Menu ADD CLICKED");
return true;
case MENU_QUIT:
/* End Activity. */
this.finish();
return true;
default:
return false;
}
}
protected MenuScene createMenuScene() {
final MenuScene menuScene = new MenuScene(this.camera, new AlphaMenuSceneAnimator());
final IMenuItem resetMenuItem = new ColorMenuItemDecorator(new TextMenuItem(MENU_ADD, this.menuFont, "ADD ITEM", this.getVertexBufferObjectManager()), new Color(1,0,0), new Color(0,0,0));
menuScene.addMenuItem(resetMenuItem);
final IMenuItem quitMenuItem = new ColorMenuItemDecorator(new TextMenuItem(MENU_QUIT, this.menuFont, "QUIT", this.getVertexBufferObjectManager()), new Color(1,0,0), new Color(0,0,0));
menuScene.addMenuItem(quitMenuItem);
menuScene.buildAnimations();
menuScene.setBackgroundEnabled(false);
menuScene.setOnMenuItemClickListener(this);
return menuScene;
}
#Override
public boolean onKeyDown(final int pKeyCode, final KeyEvent pEvent) {
if(pKeyCode == KeyEvent.KEYCODE_MENU && pEvent.getAction() == KeyEvent.ACTION_DOWN) {
if(this.scene.hasChildScene()) {
/* Remove the menu and reset it. */
this.mMenuScene.back();
} else {
/* Attach the menu. */
this.scene.setChildScene(this.mMenuScene, false, true, true);
}
return true;
} else {
return super.onKeyDown(pKeyCode, pEvent);
}
}
}

Preference activity seekbar

I have created a custom android seek bar from lukehorvat tutorial
and added to my preference xml file as below
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto" >
<PreferenceCategory
android:title="Color RGB channels"
android:order="100">
<com.heroku.android.SeekBarDialogPreference
android:defaultValue="20"
android:id="#+id/redchannel"
android:key="redchannel"
android:dialogMessage="Please select red channel:"
android:max="50"
android:title="Red channel"
custom:progressTextSuffix="%"
custom:min="1" />
<com.heroku.android.SeekBarDialogPreference
android:defaultValue="20"
android:dialogMessage="Please select green channel:"
android:max="50"
android:title="Select green channel"
custom:progressTextSuffix="%"
custom:min="1" />
<com.heroku.android.SeekBarDialogPreference
android:defaultValue="20"
android:dialogMessage="Please select blue channel:"
android:max="50"
android:title="Select blue channel"
custom:progressTextSuffix="%"
custom:min="1" />
</PreferenceCategory>
</PreferenceScreen>
And I have added to my preference activity these three seekbars as below
package com.heroku.android;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.View;
import android.widget.SeekBar;
public class Preferences extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(com.yuldashev.android.R.xml.preferences);
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(
this);
}
#Override
protected void onResume() {
super.onResume();
}
#Override
protected void onDestroy() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
this);
super.onDestroy();
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
}
}
The problem is all of them refers to the same seekbardialog custom class and I cannot get the values for these three seekbars seperately. I have tried to seperate them by entitling #+id in xml file but it does not works for me by findviewbyID because the custom SeekBardialogPreference does not support such an option. For example if you adding and single SeekBar by id you do
SeekBar seek1=(SeekBar)findviewByID(resource)
and you get the progress value from seek1 object.
Is there any suggestion how to do the same with custom seekbardialog below
package com.heroku.android;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
/**
* A {#link DialogPreference} that provides a user with the means to select an integer from a {#link SeekBar}, and persist it.
*
* #author lukehorvat
*
*/
public class SeekBarDialogPreference extends DialogPreference
{
private static final int DEFAULT_MIN_PROGRESS = 0;
private static final int DEFAULT_MAX_PROGRESS = 100;
private static final int DEFAULT_PROGRESS = 0;
private int mMinProgress;
private int mMaxProgress;
private int mProgress;
private CharSequence mProgressTextSuffix;
private TextView mProgressText;
private SeekBar mSeekBar;
public SeekBarDialogPreference(Context context)
{
this(context, null);
}
public SeekBarDialogPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
// get attributes specified in XML
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, com.yuldashev.android.R.styleable.SeekBarDialogPreference, 0, 0);
try
{
setMinProgress(a.getInteger(com.yuldashev.android.R.styleable.SeekBarDialogPreference_min, DEFAULT_MIN_PROGRESS));
setMaxProgress(a.getInteger(com.yuldashev.android.R.styleable.SeekBarDialogPreference_android_max, DEFAULT_MAX_PROGRESS));
setProgressTextSuffix(a.getString(com.yuldashev.android.R.styleable.SeekBarDialogPreference_progressTextSuffix));
}
finally
{
a.recycle();
}
// set layout
setDialogLayoutResource(com.yuldashev.android.R.layout.preference_seek_bar_dialog);
setPositiveButtonText(android.R.string.ok);
setNegativeButtonText(android.R.string.cancel);
setDialogIcon(null);
}
#Override
protected void onSetInitialValue(boolean restore, Object defaultValue)
{
setProgress(restore ? getPersistedInt(DEFAULT_PROGRESS) : (Integer) defaultValue);
}
#Override
protected Object onGetDefaultValue(TypedArray a, int index)
{
return a.getInt(index, DEFAULT_PROGRESS);
}
#Override
protected void onBindDialogView(View view)
{
super.onBindDialogView(view);
TextView dialogMessageText = (TextView) view.findViewById(com.yuldashev.android.R.id.text_dialog_message);
dialogMessageText.setText(getDialogMessage());
mProgressText = (TextView) view.findViewById(com.yuldashev.android.R.id.text_progress);
mSeekBar = (SeekBar) view.findViewById(com.yuldashev.android.R.id.seek_bar);
mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}
#Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
// update text that displays the current SeekBar progress value
// note: this does not persist the progress value. that is only ever done in setProgress()
String progressStr = String.valueOf(progress + mMinProgress);
mProgressText.setText(mProgressTextSuffix == null ? progressStr : progressStr.concat(mProgressTextSuffix.toString()));
}
});
mSeekBar.setMax(mMaxProgress - mMinProgress);
mSeekBar.setProgress(mProgress - mMinProgress);
}
public int getMinProgress()
{
return mMinProgress;
}
public void setMinProgress(int minProgress)
{
mMinProgress = minProgress;
setProgress(Math.max(mProgress, mMinProgress));
}
public int getMaxProgress()
{
return mMaxProgress;
}
public void setMaxProgress(int maxProgress)
{
mMaxProgress = maxProgress;
setProgress(Math.min(mProgress, mMaxProgress));
}
public int getProgress()
{
return mProgress;
}
public void setProgress(int progress)
{
progress = Math.max(Math.min(progress, mMaxProgress), mMinProgress);
if (progress != mProgress)
{
mProgress = progress;
persistInt(progress);
notifyChanged();
}
}
public CharSequence getProgressTextSuffix()
{
return mProgressTextSuffix;
}
public void setProgressTextSuffix(CharSequence progressTextSuffix)
{
mProgressTextSuffix = progressTextSuffix;
}
#Override
protected void onDialogClosed(boolean positiveResult)
{
super.onDialogClosed(positiveResult);
// when the user selects "OK", persist the new value
if (positiveResult)
{
int seekBarProgress = mSeekBar.getProgress() + mMinProgress;
if (callChangeListener(seekBarProgress))
{
setProgress(seekBarProgress);
}
}
}
#Override
protected Parcelable onSaveInstanceState()
{
// save the instance state so that it will survive screen orientation changes and other events that may temporarily destroy it
final Parcelable superState = super.onSaveInstanceState();
// set the state's value with the class member that holds current setting value
final SavedState myState = new SavedState(superState);
myState.minProgress = getMinProgress();
myState.maxProgress = getMaxProgress();
myState.progress = getProgress();
return myState;
}
#Override
protected void onRestoreInstanceState(Parcelable state)
{
// check whether we saved the state in onSaveInstanceState()
if (state == null || !state.getClass().equals(SavedState.class))
{
// didn't save the state, so call superclass
super.onRestoreInstanceState(state);
return;
}
// restore the state
SavedState myState = (SavedState) state;
setMinProgress(myState.minProgress);
setMaxProgress(myState.maxProgress);
setProgress(myState.progress);
super.onRestoreInstanceState(myState.getSuperState());
}
private static class SavedState extends BaseSavedState
{
int minProgress;
int maxProgress;
int progress;
public SavedState(Parcelable superState)
{
super(superState);
}
public SavedState(Parcel source)
{
super(source);
minProgress = source.readInt();
maxProgress = source.readInt();
progress = source.readInt();
}
#Override
public void writeToParcel(Parcel dest, int flags)
{
super.writeToParcel(dest, flags);
dest.writeInt(minProgress);
dest.writeInt(maxProgress);
dest.writeInt(progress);
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>()
{
#Override
public SavedState createFromParcel(Parcel in)
{
return new SavedState(in);
}
#Override
public SavedState[] newArray(int size)
{
return new SavedState[size];
}
};
}
}
Thank you all!

GXT 3.x RowExpander with ButtonCell

I try to add button into rowExpander content:
so i have:
ButtonCell<Integer> viewButtonCell = new ButtonCell<Integer>();
and row expander
RowExpander<XX> expander = new RowExpander<XX>(identity, new AbstractCell<XX>() {
#Override
public void render(Context context, XX value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<span>");
viewButtonCell.render(context, value.getId(), sb);
sb.appendHtmlConstant("</span>");
}
ButtonCell is rendered OK i can see it BUT I cannot click it, no selecthandler from ButtonCell is call :(.
Any ideas how can I make selectHandlerActive for this button ?
Thanks
i created some new RowExpander :
public class MTPRowExpander<M> extends RowExpander<M> {
public static int id = 0;
public static interface WidgetFactory<M> {
public Widget createWidget(M model);
}
private WidgetFactory<M> wf;
private Set<Integer> expandedRows;
public MTPRowExpander(IdentityValueProvider<M> valueProvider,WidgetFactory<M> wf) {
this(valueProvider,GWT.<RowExpanderAppearance<M>> create(RowExpanderAppearance.class),wf);
}
public MTPRowExpander(IdentityValueProvider<M> valueProvider,final RowExpanderAppearance<M> appearance, WidgetFactory<M> wf) {
super(valueProvider, null, appearance);
this.wf = wf;
expandedRows = new HashSet<Integer>();
}
#Override
protected boolean beforeExpand(M model, Element body, XElement row,int rowIndex) {
if (expandedRows.contains(rowIndex)) {
return true;
} else {
expandedRows.add(rowIndex);
return super.beforeExpand(model, body, row, rowIndex);
}
}
#Override
protected String getBodyContent(final M model, int rowIndex) {
final int curentid = id++;
Scheduler.get().scheduleFinally(new ScheduledCommand() {
#Override
public void execute() {
Widget widget = wf.createWidget(model);
com.google.gwt.dom.client.Element item = grid.getElement().childElement(".widget" + curentid);
item.appendChild(widget.getElement());
ComponentHelper.setParent(grid, widget);
}
});
return "<div class='widget" + curentid + "'></div>";
}
}
I know that this solution is not perfect but I didnt know how to resolve problem at more proper way.

GXT: LayoutContainer does not respond to ESC Key or "X" button to close

I have a GXT 2.x application with a Menubar Item that renders a separate LayoutContainer.
Here's the hierarchy
MainUI.java -> MenuBar.java -> ReservationPopUp.java
I have replaced my contents of ReservationPopUp.java with KNOWN working examples of LayoutContainer implementations and they respond to the ESC key and "X" button.
Here's how the MenuItem renders the ReservationPopUp.java
MenuItem mntmReserve = new MenuItem("Reserve");
mntmReserve.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
RootPanel.get().add(new ReservationPopUp());
}
Here's a slimmed down version of my ReservationPopUp.java
public class ReservationPopUp extends LayoutContainer {
public ReservationPopUp() {
}
#Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
setSize("1024", "809");
final Window window = new Window();
window.setDraggable(false);
window.setSize(537, 399);
window.setPlain(true);
window.setModal(true);
window.setBlinkModal(true);
window.setHeading("Reserve A Server");
window.setClosable(true);
window.setOnEsc(true);
window.setSize("465", "345");
window.setLayout(new AbsoluteLayout());
LabelField lblfldUsers = new LabelField("Users");
window.add(lblfldUsers, new AbsoluteData(43, 218));
final ComboBox<AsyncUser> userList = new ComboBox<AsyncUser>();
window.add(userList, new AbsoluteData(81, 218));
userList.setEmptyText("Select a User...");
userList.setSize("347px", "24px");
LabelField labelServers = new LabelField("Servers");
window.add(labelServers, new AbsoluteData(32, 6));
final DualListField<AsyncServer> serverList = new DualListField<AsyncServer>();
....
window.add(serverList, new AbsoluteData(81, 6));
serverList.setSize("347px", "206px");
window.addButton(new Button("Cancel", new SelectionListener<ButtonEvent>() {
#Override
public void componentSelected(ButtonEvent ce) {
ReservationPopUp.this.hide();
}
}));
window.addButton(new Button("Reserve", new SelectionListener<ButtonEvent>() {
#Override
public void componentSelected(ButtonEvent ce) {
if (serverList.getToList().getListView().getItemCount() == 0 ) {
MessageBox.alert("Invalid Selection","No Server(s) Selected", null);
} else if ( userList.getValue() == null) {
} else {
// DO some stuff
ReservationPopUp.this.hide();
}
}
}));
window.addWindowListener(new WindowListener() {
#Override
public void windowHide(WindowEvent we) {
ReservationPopUp.this.hide();
}
});
window.setFocusWidget(window.getButtonBar().getItem(0));
add(window);
}
}
Window is a popup, it doesn't need to be (and shouldn't be) added to anything. Extend the Window class instead of the LayoutContainer, and instead of adding the ReservationPopup to the page, just call Window.show().