I'm working on a custom ROM and I'm receiving this error while trying to compile it. I tried to add a custom battery selector.
com.android.settings.pcf.StatusBar is not abstract and does not override abstract method onPreferenceChange(android.preference.Preference,java.lang.Object) in android.preference.Preference.OnPreferenceChangeListener
This is the the com.android.settings.pcf.StatusBar file:
package com.android.settings.pcf;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;
public class StatusBar extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
private static final String PREF_BATT_ICON = "battery_icon_list";
ListPreference mBatteryIcon;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.prefs_statusbar);
mBatteryIcon = (ListPreference) findPreference(PREF_BATT_ICON);
mBatteryIcon.setOnPreferenceChangeListener(this);
mBatteryIcon.setValue((Settings.System.getInt(getActivity()
.getContentResolver(), Settings.System.STATUSBAR_BATTERY_ICON,
0))
+ "");
}
public boolean OnPreferenceChange(Preference preference, Object newValue) {
if (preference == mBatteryIcon) {
int val = Integer.parseInt((String) newValue);
return Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_BATTERY_ICON, val);
}
return false;
}
}
Can anyone help?
The error is telling you that you didn't fully implement the OnPreferenceChangeListener interface. In particular, the onPreferenceChange method is not implemented.
Either implement this method, or I'm actually guessing you meant OnPreferenceChange to be onPreferenceChange - note the lowercase "o" - (in which case I believe you will also need a #Override before it)
Related
Most of the search results I'm getting are for downloading cordova-plugin-camera and then calling it on the Javascript side, but is there a way to access the camera from the the java code of a custom plugin? Also is there relevant documentation for this? My code so far looks like this:
package com.ncr.cordova.camera;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
public class Camera extends CordovaPlugin{
#Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
// your init code here
}
private boolean openCamera(){
//open the camera?
}
private boolean takePicture(){
//take picture?
}
#Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
switch(action){
case "helloWorld":
callbackContext.success("helloWorld");
break;
}
return false; // Returning false results in a "MethodNotFound" error.
}
}
Is there a way to implement openCamera and takePicture, or some kind of relevant functionality?
This is a follow up to a question I asked here.
I have copied and pasted this code from this tutorial. When I paste it into Android Studio, the 'this' parameter of of content.getLoadManager.initLoader() is highlighted in red and shows the following error:
Wrong 3rd Argument Type. Found 'com.example.carl.loaderDemo.FooLoaderClient', requried: 'android.app.LoaderManager.LoaderCallBacks
I've ran into this previously (see first link). I was hoping this tutorial would help but I just seem to be going in endless circles!
Can anyone point me in the right direction?!
package com.example.carl.loaderdemo;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
public class FooLoader extends AsyncTaskLoader {
public FooLoader(Context context, Bundle args) {
super(context);
// do some initializations here
}
public String loadInBackground() {
String result = "";
// ...
// do long running tasks here
// ...
return result;
}
}
class FooLoaderClient implements LoaderManager.LoaderCallbacks {
Activity context;
// to be used for support library:
// FragmentActivity context2;
public Loader onCreateLoader(int id, Bundle args) {
// init loader depending on id
return new FooLoader(context, args);
}
#Override
public void onLoadFinished(Loader loader, Object data) {
}
public void onLoaderReset(Loader loader) {
// ...
}
public void useLoader() {
Bundle args = new Bundle();
// ...
// fill in args
// ...
Loader loader =
context.getLoaderManager().initLoader(0, args, this);
// with support library:
// Loader loader =
// context2.getSupportLoaderManager().initLoader(0, args, this);
// call forceLoad() to start processing
loader.forceLoad();
}
}
Screenshot of error message:
There is a mismatch in your imports:
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
But you need
import android.app.LoaderManager;
import android.content.AsyncTaskLoader;
import android.content.Loader;
You cannot mix the support library with the android framework. Alternatively you can subclass FragmentActivity and call getSupportLoaderManager() instead.
You're implementing android.support.v4.app.LoaderManager.LoaderCallbacks but the client is expecting android.app.LoaderManager.LoaderCallbacks. You need to be consistent in which loader API you're using.
I an trying to create an application thet will catch the incoming calls to the cellphone using a BroadcastReciver. From my BroadcastReciver i whould like to sent the number as an event to my JS file using this method.
I have checked that my Java code is working and is catching the calls and number but my application craches with the error that mentions that the react context is null. I am guessing that this is because the manifest (or something) is creating a new instance of the class when the event from the android system is catched and that the new instance does not have a ReactContext. Is there any way to access the ReactContext from the Java code or send a ReactContext to the BroadcastReciver through the manifest?
This is my BroadcastReciver:
package com.bridgetest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.JavaScriptModule;
import android.widget.Toast;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;
import javax.annotation.Nullable;
/**
* Created by Erik on 2016-04-06.
*/
public class BroadcastReceiverCustom extends BroadcastReceiver {
ReactContext reactContext;
public BroadcastReceiverCustom (){
}
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
// This code will execute when the phone has an incoming call
// get the phone number
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "Call from:" +incomingNumber, Toast.LENGTH_LONG).show();
sendCallEvent(incomingNumber);
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_IDLE)
|| intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_OFFHOOK)) {
// This code will execute when the call is disconnected
Toast.makeText(context, "Detected call hangup event", Toast.LENGTH_LONG).show();
}
}
public void sendCallEvent(String incomingNumber){
WritableMap params = Arguments.createMap();
params.putString("Number", incomingNumber);
sendEvent("CallRecevied", params);
}
private void sendEvent(String eventName,
#Nullable WritableMap params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
}
As Fury's solution did not work for me(got "cannot find symbol" for getApplication()) in the broadcast receiver, i tried applying a similar logic with what i knew is working. So:
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.ReactApplication;
...
// context - is the context you get from broadcastreceivers onReceive
ReactApplication rnApp = (ReactApplication) context.getApplicationContext();
rnApp.getReactNativeHost().getReactInstanceManager()
.getCurrentReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("test", Arguments.createMap());
This worked for me.
I faced a same problem and am using this.
((MainApplication)getApplication()).getReactNativeHost().getReactInstanceManager().getCurrentReactContext()
I solved the problem. I created a ReactContextBaseJavaModule with a singleton pattern and got access to ReactContext through it (This might be a huge "nono").
If there is another smarter way to solve this problem, please inform me.
You can access reactContext like this:
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
ReactInstanceManager reactInstanceManager = getReactNativeHost().getReactInstanceManager();
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if(reactContext != null) {
// Use reactContext here
} else {
reactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
#Override
public void onReactContextInitialized(ReactContext context) {
// Use context here
reactInstanceManager.removeReactInstanceEventListener(this);
}
});
}
Context
I have implemented a NatTable (v1.1.0.201405012245) - please consider this simplified example:
package testproject;
import java.util.ArrayList;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.config.EditableRule;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
import org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings;
import org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration;
import org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
public class ViewPart1 extends ViewPart
{
#Override
public void createPartControl(final Composite parent)
{
final ArrayList<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");
final IColumnAccessor<String> columnAccessor = new IColumnAccessor<String>()
{
#Override
public void setDataValue(final String rowObject, final int columnIndex, final Object newValue)
{
if (!(newValue instanceof String) || ((String) newValue).contains("x"))
{
MessageDialog.openError(getSite().getShell(), "Error", "Invalid Input");
return;
}
list.set(list.indexOf(rowObject), (String) newValue);
}
#Override
public Object getDataValue(final String rowObject, final int columnIndex)
{
return rowObject;
}
#Override
public int getColumnCount()
{
return 1;
}
};
final IDataProvider dataProvider = new ListDataProvider<>(list, columnAccessor);
final DataLayer dataLayer = new DataLayer(dataProvider);
final SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
final ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
final NatTable table = new NatTable(parent, viewportLayer, false);
GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
viewportLayer.addConfiguration(new DefaultEditConfiguration());
viewportLayer.addConfiguration(new DefaultEditBindings());
viewportLayer.setRegionName(GridRegion.BODY);
viewportLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator()
{
#Override
public void accumulateConfigLabels(final LabelStack configLabels, final int columnPosition, final int rowPosition)
{
configLabels.addLabel("myLabel");
}
});
table.setConfigRegistry(new ConfigRegistry());
table.addConfiguration(new DefaultNatTableStyleConfiguration());
table.addConfiguration(new DefaultSelectionStyleConfiguration());
table.addConfiguration(new AbstractRegistryConfiguration()
{
#Override
public void configureRegistry(final IConfigRegistry registry)
{
registry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true), DisplayMode.NORMAL, "myLabel");
registry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, "myLabel");
}
});
table.configure();
}
#Override
public void setFocus()
{
}
}
Of course, this is not the real code, but my issue can be demonstrated with this code as well.
The important part is that in my actual project, when the user modifies a value, I need to update a model (including a complex tree of dependencies) and if that fails (e.g. in a numerical calculation the change results in a division by zero), I need to show an error (and revert to the previous value).
To show my core problem, in the code shown here I check for a simple condition in IColumnAccessor#setDataValue (the input contains an 'x') and show the error accordingly.
Problem
My actual problem is that if you enter an x into the TextCellEditor, the error dialog pops up twice (in sequence - meaning that as soon as I click ok for the first one, the second one will show).
Analysis
My analysis shows that the reason is that setDataValue is called twice:
because the ENTER key is pressed - Stacktrace
TextCellEditor(AbstractCellEditor).commit(SelectionLayer$MoveDirectionEnum, boolean) line: 331
TextCellEditor(AbstractCellEditor).commit(SelectionLayer$MoveDirectionEnum) line: 326
TextCellEditor$1.keyPressed(KeyEvent) line: 246
because the TextCellEditor loses focus - Stacktrace
TextCellEditor(AbstractCellEditor).commit(SelectionLayer$MoveDirectionEnum, boolean, boolean) line: 341
TextCellEditor(AbstractCellEditor).commit(SelectionLayer$MoveDirectionEnum, boolean) line: 331
AbstractCellEditor$InlineFocusListener.focusLost(FocusEvent) line: 462
So, my main question is: how can I prevent (or at least detect) the second event?
The issue with your implementation is, that you are performing a conversion in the IColumnAccessor and open a dialog to inform the user about the error. But that is not the way to do this with NatTable because of various use cases.
If you need to perform conversion and/or validation you should register an appropriate IDisplayConverter and an IDataValidator. As you need a String you don't need to register a different converter, as the default converter that is registered via DefaultEditConfiguration is doing that already. So what you need is an IDataValidator that checks for the value x and throws a ValidationFailedException in that case. If you register the DialogErrorHandling as validation error handler, the error with the exception message will be shown in a dialog. And the checks for not opening the dialog twice is done internally.
This is explained in the (currently small) documentation http://www.eclipse.org/nattable/documentation.php?page=editing
BTW, I suggest to update to the latest NatTable release 1.3.0 as it also contains several bugfixes.
I'm trying to write a generic widget that takes a (any) enumset and pops up a simple form to allow the the individual enums to be turned on and off. Below is a minimal version of the class (actually set up to run on android), but eclipse is moaning that "The method add(Capture#-7 of ?) in the type AbstractCollection is not applicable for the arguments(T)".
A few lines earlier I have invoked remove (which has exactly the same signature) with no problems. Trying to turn the enum into a set first doesn't help either.
What is the magic syntax I need to fix this?
I may well not be using the best class definition either ;) I'm using the Android Developer Tools v21.1.0-569685, but the problem also shows up on Eclipse proper (Indigo)
package com.test.ui;
import java.util.EnumSet;
import android.util.Log;
import android.view.View;
import android.view.LayoutInflater;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
public class EnumSetSelector<T extends Enum<?>> implements OnClickListener{
Class<T> enumclass;
EnumSet<?> theset; // EnumSet<T> theset; fails
boolean haschanged;
public EnumSetSelector(Class<T> eclass) {
enumclass = eclass;
}
public ViewGroup prepareSet(EnumSet<?> esvals, ViewGroup vg, LayoutInflater li) {
theset = esvals;
T[] allvals = enumclass.getEnumConstants();
Log.d("XXXXXXZ","here are " + allvals.length);
ViewGroup grp = (ViewGroup)li.inflate(R.layout.ui_enum_selector,vg,false);
for (T av:allvals) {
Log.d("XXXXXXZ"," - " + av);
CheckBox cb = (CheckBox)li.inflate(R.layout.ui_enum_selector_entry,vg,false);
cb.setText(String.valueOf(av));
cb.setChecked(theset.contains(av));
cb.setTag(av);
grp.addView(cb);
esvals.remove(av);
}
vg.addView(grp);
return grp;
}
#Override
public void onClick(View v) {
final T thisenum = (T)v.getTag();
final boolean oldval = theset.contains(thisenum);
final CheckBox cb = (CheckBox)v;
if (cb.isChecked() != oldval) {
if (cb.isChecked()) {
cb.setChecked(false);
theset.remove(thisenum);
} else {
cb.setChecked(true);
theset.add(thisenum);
theset.add(EnumSet.of(thisenum));
}
Log.d("XXXXXXZ", "" + String.valueOf(v.getTag()) + " now "
+ (theset.contains(thisenum)));
}
}
}
Echoing JB Nizet's comment, you should declare your class as:
EnumSetSelector<T extends Enum<T>>
In other words, with the same recursive bounds that Enum and EnumSet declare.
Then make sure to type theset and esvals as EnumSet<T> instead of EnumSet<?>.