Skip to content

Commit

Permalink
check for resource file before displaying preference pane apla#87 to …
Browse files Browse the repository at this point in the history
…avoid compilation error;

replace ANDROID_PACKAGE_NAME instead of strings generation;
added visual test
  • Loading branch information
apla committed Jul 27, 2016
1 parent e460b86 commit da10dc9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
10 changes: 7 additions & 3 deletions bin/lib/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ module.exports = function (context) {
projectXml = cordova_util.projectConfig(projectRoot),
projectConfig = new ConfigParser(projectXml);

return ('package me.apla.cordova;\n\n' +
'import ' + (projectConfig.android_packageName() || projectConfig.packageName()) + '.R;\n\n' +
tmpl);
var packageName = projectConfig.android_packageName() || projectConfig.packageName();

return (
//'package me.apla.cordova;\n\n' +
//'import ' + packageName + '.R;\n\n' +
tmpl.replace (/ANDROID_PACKAGE_NAME/g, packageName)
);
})
.then(function (data) {
var androidPackagePath = "me.apla.cordova".replace (/\./g, '/');
Expand Down
37 changes: 36 additions & 1 deletion src/android/AppPreferencesActivity.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package me.apla.cordova;

// import ANDROID_PACKAGE_NAME.R;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
Expand All @@ -16,11 +20,42 @@ public class AppPreferencesActivity extends PreferenceActivity {

public static class AppPFragment extends PreferenceFragment
{
Activity activity;
Context context;

@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.apppreferences);

if (this.context == null) {
this.context = this.activity.getApplicationContext();
}

String packageName = this.context.getPackageName();

int resId = this.context.getResources().getIdentifier("apppreferences", "xml", packageName);

if (resId > 0) {
addPreferencesFromResource(resId);
}

}

@Override
public void onAttach(Activity act) {
this.activity = act;
}

@Override
public void onAttach(Context ctx) {
this.context = ctx;
}

@Override
public void onDetach() {
this.context = null;
this.activity = null;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ function testPluginAndCallback () {
statusNode.className = 'event test';
statusNode.style.cssText = 'display: none';
deviceReadyNode.parentNode.appendChild (statusNode);

var showPrefsNode = document.createElement ('p');
showPrefsNode.className = 'event prefs';
showPrefsNode.style.cssText = 'display: block';
deviceReadyNode.parentNode.appendChild (showPrefsNode);


}

// end css fixes
Expand Down

0 comments on commit da10dc9

Please sign in to comment.