0
私はAndroidのcordovaカスタムレイアウトプラグインを開発中です。ユーザーがボタンをクリックすると、アプリケーションはアンドロイドプラグインを呼び出し、カスタムレイアウトを表示します。ユーザーはアンドロイドコード・プラグインのカスタムレイアウトでオブジェクトを移動できます。しかし、自分のJavaコードでxmlファイルを呼び出すと、プラグインに問題があります。以下は私のコードです。CordovaカスタムAndroidレイアウトプラグイン
のsrc /アンドロイド/ CustomLayout.java
public class CustomLayout extends CordovaPlugin {
private static final String LOG_TAG = "CustomNotification";
public CallbackContext callbackContext;
Context context;
Resources resources;
String packageName;
public CustomLayout(){
}
@Override
public boolean execute(String action, String rawArgs, CallbackContext callbackContext) throws JSONException {
this.callbackContext = callbackContext;
context = cordova.getActivity().getApplicationContext();
resources = context.getResources();
packageName = context.getPackageName();
if (action.equals("layout")) {
customLayout();
return true;
}
return false;
}
private void customLayout() {
Log.e(TAG, "show");
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
cordova.getActivity().setContentView(resources.getIdentifier("custom_layout", "layout", packageName));
ImageView motion = (ImageView) cordova.getActivity().findViewById(resources.getIdentifier("tvDragMe","id",packageName));
motion.setOnTouchListener(new MyTouchListener());
}
});
}
}
class MyTouchListener implements View.OnTouchListener {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
view.setVisibility(View.INVISIBLE);
return true;
} else {
return false;
}
}
}
WWW/customlayout.js
var exec = require('cordova/exec');
var platform = require('cordova/platform');
module.exports = {
alert: function(completeCallback) {
exec(completeCallback, null, "CustomLayout", "layout", []);
}
};
のres /レイアウト/ custom_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/tvDragMe"
android:src="@drawable/smiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginTop="35dp"
android:text="Drag Me" />
</RelativeLayout>
XMLファイル
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-custom_layout" version="1.0.0">
<name>Custom Layout</name>
<description>Cordova Custom Layout Plugin</description>
<keywords>cordova,layout</keywords>
<js-module src="www/customlayout.js" name="customlayout">
<merges target="customlayout" />
</js-module>
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="CustomLayout">
<param name="android-package" value="org.apache.cordova.dialogs.CustomLayout"/>
</feature>
</config-file>
<source-file src="res/layout/custom_layout.xml" target-dir="res/layout/custom_layout.xml" />
</platform>
</plugin>